Thomas Gleixner | 09c434b | 2019-05-19 13:08:20 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 2 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * Driver for Intel I82092AA PCI-PCMCIA bridge. |
| 4 | * |
| 5 | * (C) 2001 Red Hat, Inc. |
| 6 | * |
| 7 | * Author: Arjan Van De Ven <arjanv@redhat.com> |
| 8 | * Loosly based on i82365.c from the pcmcia-cs package |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/module.h> |
| 13 | #include <linux/pci.h> |
| 14 | #include <linux/init.h> |
| 15 | #include <linux/workqueue.h> |
| 16 | #include <linux/interrupt.h> |
| 17 | #include <linux/device.h> |
| 18 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <pcmcia/ss.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
Simon Geis | ac5af87 | 2019-12-13 14:53:12 +0100 | [diff] [blame] | 21 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
| 23 | #include "i82092aa.h" |
| 24 | #include "i82365.h" |
| 25 | |
| 26 | MODULE_LICENSE("GPL"); |
| 27 | |
| 28 | /* PCI core routines */ |
Greg Kroah-Hartman | 0178a7a | 2014-07-18 16:58:07 -0700 | [diff] [blame] | 29 | static const struct pci_device_id i82092aa_pci_ids[] = { |
Axel Lin | 2b2c5d8 | 2011-12-27 16:17:46 +0800 | [diff] [blame] | 30 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82092AA_0) }, |
| 31 | { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | }; |
| 33 | MODULE_DEVICE_TABLE(pci, i82092aa_pci_ids); |
| 34 | |
Sam Ravnborg | ba66ddf | 2008-05-01 04:34:51 -0700 | [diff] [blame] | 35 | static struct pci_driver i82092aa_pci_driver = { |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 36 | .name = "i82092aa", |
| 37 | .id_table = i82092aa_pci_ids, |
| 38 | .probe = i82092aa_pci_probe, |
| 39 | .remove = i82092aa_pci_remove, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | }; |
| 41 | |
| 42 | |
| 43 | /* the pccard structure and its functions */ |
| 44 | static struct pccard_operations i82092aa_operations = { |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 45 | .init = i82092aa_init, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | .get_status = i82092aa_get_status, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | .set_socket = i82092aa_set_socket, |
| 48 | .set_io_map = i82092aa_set_io_map, |
| 49 | .set_mem_map = i82092aa_set_mem_map, |
| 50 | }; |
| 51 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 52 | /* The card can do up to 4 sockets, allocate a structure for each of them */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
| 54 | struct socket_info { |
| 55 | int number; |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 56 | int card_state; |
| 57 | /* 0 = no socket, |
| 58 | * 1 = empty socket, |
| 59 | * 2 = card but not initialized, |
| 60 | * 3 = operational card |
| 61 | */ |
| 62 | unsigned int io_base; /* base io address of the socket */ |
| 63 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | struct pcmcia_socket socket; |
| 65 | struct pci_dev *dev; /* The PCI device for the socket */ |
| 66 | }; |
| 67 | |
| 68 | #define MAX_SOCKETS 4 |
| 69 | static struct socket_info sockets[MAX_SOCKETS]; |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 70 | static int socket_count; /* shortcut */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
| 72 | |
Simon Geis | 152b4bb | 2019-12-13 14:53:11 +0100 | [diff] [blame] | 73 | static int i82092aa_pci_probe(struct pci_dev *dev, |
| 74 | const struct pci_device_id *id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | { |
| 76 | unsigned char configbyte; |
| 77 | int i, ret; |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 78 | |
Simon Geis | 9088646 | 2019-12-13 14:53:10 +0100 | [diff] [blame] | 79 | ret = pci_enable_device(dev); |
| 80 | if (ret) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | return ret; |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 82 | |
Simon Geis | 152b4bb | 2019-12-13 14:53:11 +0100 | [diff] [blame] | 83 | /* PCI Configuration Control */ |
| 84 | pci_read_config_byte(dev, 0x40, &configbyte); |
| 85 | |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 86 | switch (configbyte&6) { |
Simon Geis | 6aaf8ff | 2019-12-13 14:53:09 +0100 | [diff] [blame] | 87 | case 0: |
| 88 | socket_count = 2; |
| 89 | break; |
| 90 | case 2: |
| 91 | socket_count = 1; |
| 92 | break; |
| 93 | case 4: |
| 94 | case 6: |
| 95 | socket_count = 4; |
| 96 | break; |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 97 | |
Simon Geis | 6aaf8ff | 2019-12-13 14:53:09 +0100 | [diff] [blame] | 98 | default: |
| 99 | dev_err(&dev->dev, |
| 100 | "Oops, you did something we didn't think of.\n"); |
| 101 | ret = -EIO; |
| 102 | goto err_out_disable; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | } |
Simon Geis | 26a0a104 | 2019-12-13 14:53:04 +0100 | [diff] [blame] | 104 | dev_info(&dev->dev, "configured as a %d socket device.\n", |
| 105 | socket_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | |
| 107 | if (!request_region(pci_resource_start(dev, 0), 2, "i82092aa")) { |
| 108 | ret = -EBUSY; |
| 109 | goto err_out_disable; |
| 110 | } |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 111 | |
| 112 | for (i = 0; i < socket_count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | sockets[i].card_state = 1; /* 1 = present but empty */ |
| 114 | sockets[i].io_base = pci_resource_start(dev, 0); |
| 115 | sockets[i].socket.features |= SS_CAP_PCCARD; |
| 116 | sockets[i].socket.map_size = 0x1000; |
| 117 | sockets[i].socket.irq_mask = 0; |
| 118 | sockets[i].socket.pci_irq = dev->irq; |
Dominik Brodowski | 7a96e87 | 2010-03-13 17:42:39 +0100 | [diff] [blame] | 119 | sockets[i].socket.cb_dev = dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | sockets[i].socket.owner = THIS_MODULE; |
| 121 | |
| 122 | sockets[i].number = i; |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 123 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | if (card_present(i)) { |
| 125 | sockets[i].card_state = 3; |
Simon Geis | 26a0a104 | 2019-12-13 14:53:04 +0100 | [diff] [blame] | 126 | dev_dbg(&dev->dev, "slot %i is occupied\n", i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | } else { |
Simon Geis | 26a0a104 | 2019-12-13 14:53:04 +0100 | [diff] [blame] | 128 | dev_dbg(&dev->dev, "slot %i is vacant\n", i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | } |
| 130 | } |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 131 | |
Simon Geis | 152b4bb | 2019-12-13 14:53:11 +0100 | [diff] [blame] | 132 | /* Now, specifiy that all interrupts are to be done as PCI interrupts |
| 133 | * bitmask, one bit per event, 1 = PCI interrupt, 0 = ISA interrupt |
| 134 | */ |
| 135 | configbyte = 0xFF; |
| 136 | |
| 137 | /* PCI Interrupt Routing Register */ |
| 138 | pci_write_config_byte(dev, 0x50, configbyte); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | |
| 140 | /* Register the interrupt handler */ |
Adam Zerella | 836e949 | 2019-08-25 15:35:10 +1000 | [diff] [blame] | 141 | dev_dbg(&dev->dev, "Requesting interrupt %i\n", dev->irq); |
Simon Geis | 9088646 | 2019-12-13 14:53:10 +0100 | [diff] [blame] | 142 | ret = request_irq(dev->irq, i82092aa_interrupt, IRQF_SHARED, |
| 143 | "i82092aa", i82092aa_interrupt); |
| 144 | if (ret) { |
Simon Geis | 26a0a104 | 2019-12-13 14:53:04 +0100 | [diff] [blame] | 145 | dev_err(&dev->dev, "Failed to register IRQ %d, aborting\n", |
| 146 | dev->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | goto err_out_free_res; |
| 148 | } |
| 149 | |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 150 | for (i = 0; i < socket_count; i++) { |
Greg Kroah-Hartman | 8737331 | 2006-09-12 17:00:10 +0200 | [diff] [blame] | 151 | sockets[i].socket.dev.parent = &dev->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | sockets[i].socket.ops = &i82092aa_operations; |
| 153 | sockets[i].socket.resource_ops = &pccard_nonstatic_ops; |
| 154 | ret = pcmcia_register_socket(&sockets[i].socket); |
Simon Geis | ae1f62c | 2019-12-13 14:53:07 +0100 | [diff] [blame] | 155 | if (ret) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | goto err_out_free_sockets; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | } |
| 158 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | return 0; |
| 160 | |
| 161 | err_out_free_sockets: |
| 162 | if (i) { |
Simon Geis | ae1f62c | 2019-12-13 14:53:07 +0100 | [diff] [blame] | 163 | for (i--; i >= 0; i--) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | pcmcia_unregister_socket(&sockets[i].socket); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | } |
| 166 | free_irq(dev->irq, i82092aa_interrupt); |
| 167 | err_out_free_res: |
| 168 | release_region(pci_resource_start(dev, 0), 2); |
| 169 | err_out_disable: |
| 170 | pci_disable_device(dev); |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 171 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | } |
| 173 | |
Bill Pemberton | e765a02 | 2012-11-19 13:26:05 -0500 | [diff] [blame] | 174 | static void i82092aa_pci_remove(struct pci_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | { |
Dan Carpenter | 36c286d | 2012-12-14 18:01:08 +0300 | [diff] [blame] | 176 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | free_irq(dev->irq, i82092aa_interrupt); |
| 179 | |
Dan Carpenter | 36c286d | 2012-12-14 18:01:08 +0300 | [diff] [blame] | 180 | for (i = 0; i < socket_count; i++) |
| 181 | pcmcia_unregister_socket(&sockets[i].socket); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | static DEFINE_SPINLOCK(port_lock); |
| 185 | |
| 186 | /* basic value read/write functions */ |
| 187 | |
| 188 | static unsigned char indirect_read(int socket, unsigned short reg) |
| 189 | { |
| 190 | unsigned short int port; |
| 191 | unsigned char val; |
| 192 | unsigned long flags; |
Simon Geis | 4ae66dd | 2019-12-13 14:53:08 +0100 | [diff] [blame] | 193 | |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 194 | spin_lock_irqsave(&port_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | reg += socket * 0x40; |
| 196 | port = sockets[socket].io_base; |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 197 | outb(reg, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | val = inb(port+1); |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 199 | spin_unlock_irqrestore(&port_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | return val; |
| 201 | } |
| 202 | |
| 203 | #if 0 |
| 204 | static unsigned short indirect_read16(int socket, unsigned short reg) |
| 205 | { |
| 206 | unsigned short int port; |
| 207 | unsigned short tmp; |
| 208 | unsigned long flags; |
Simon Geis | 4ae66dd | 2019-12-13 14:53:08 +0100 | [diff] [blame] | 209 | |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 210 | spin_lock_irqsave(&port_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | reg = reg + socket * 0x40; |
| 212 | port = sockets[socket].io_base; |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 213 | outb(reg, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | tmp = inb(port+1); |
| 215 | reg++; |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 216 | outb(reg, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | tmp = tmp | (inb(port+1)<<8); |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 218 | spin_unlock_irqrestore(&port_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | return tmp; |
| 220 | } |
| 221 | #endif |
| 222 | |
| 223 | static void indirect_write(int socket, unsigned short reg, unsigned char value) |
| 224 | { |
| 225 | unsigned short int port; |
| 226 | unsigned long flags; |
Simon Geis | 4ae66dd | 2019-12-13 14:53:08 +0100 | [diff] [blame] | 227 | |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 228 | spin_lock_irqsave(&port_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | reg = reg + socket * 0x40; |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 230 | port = sockets[socket].io_base; |
| 231 | outb(reg, port); |
| 232 | outb(value, port+1); |
| 233 | spin_unlock_irqrestore(&port_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | static void indirect_setbit(int socket, unsigned short reg, unsigned char mask) |
| 237 | { |
| 238 | unsigned short int port; |
| 239 | unsigned char val; |
| 240 | unsigned long flags; |
Simon Geis | 4ae66dd | 2019-12-13 14:53:08 +0100 | [diff] [blame] | 241 | |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 242 | spin_lock_irqsave(&port_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | reg = reg + socket * 0x40; |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 244 | port = sockets[socket].io_base; |
| 245 | outb(reg, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | val = inb(port+1); |
| 247 | val |= mask; |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 248 | outb(reg, port); |
| 249 | outb(val, port+1); |
| 250 | spin_unlock_irqrestore(&port_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | |
Simon Geis | 152b4bb | 2019-12-13 14:53:11 +0100 | [diff] [blame] | 254 | static void indirect_resetbit(int socket, |
| 255 | unsigned short reg, unsigned char mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | { |
| 257 | unsigned short int port; |
| 258 | unsigned char val; |
| 259 | unsigned long flags; |
Simon Geis | 4ae66dd | 2019-12-13 14:53:08 +0100 | [diff] [blame] | 260 | |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 261 | spin_lock_irqsave(&port_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | reg = reg + socket * 0x40; |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 263 | port = sockets[socket].io_base; |
| 264 | outb(reg, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | val = inb(port+1); |
| 266 | val &= ~mask; |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 267 | outb(reg, port); |
| 268 | outb(val, port+1); |
| 269 | spin_unlock_irqrestore(&port_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | } |
| 271 | |
Simon Geis | 152b4bb | 2019-12-13 14:53:11 +0100 | [diff] [blame] | 272 | static void indirect_write16(int socket, |
| 273 | unsigned short reg, unsigned short value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | { |
| 275 | unsigned short int port; |
| 276 | unsigned char val; |
| 277 | unsigned long flags; |
Simon Geis | 4ae66dd | 2019-12-13 14:53:08 +0100 | [diff] [blame] | 278 | |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 279 | spin_lock_irqsave(&port_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | reg = reg + socket * 0x40; |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 281 | port = sockets[socket].io_base; |
| 282 | |
| 283 | outb(reg, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | val = value & 255; |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 285 | outb(val, port+1); |
| 286 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | reg++; |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 288 | |
| 289 | outb(reg, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | val = value>>8; |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 291 | outb(val, port+1); |
| 292 | spin_unlock_irqrestore(&port_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | /* simple helper functions */ |
| 296 | /* External clock time, in nanoseconds. 120 ns = 8.33 MHz */ |
| 297 | static int cycle_time = 120; |
| 298 | |
| 299 | static int to_cycles(int ns) |
| 300 | { |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 301 | if (cycle_time != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | return ns/cycle_time; |
| 303 | else |
| 304 | return 0; |
| 305 | } |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 306 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | |
| 308 | /* Interrupt handler functionality */ |
| 309 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 310 | static irqreturn_t i82092aa_interrupt(int irq, void *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | { |
| 312 | int i; |
| 313 | int loopcount = 0; |
| 314 | int handled = 0; |
| 315 | |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 316 | unsigned int events, active = 0; |
| 317 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | while (1) { |
| 319 | loopcount++; |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 320 | if (loopcount > 20) { |
Simon Geis | 26a0a104 | 2019-12-13 14:53:04 +0100 | [diff] [blame] | 321 | pr_err("i82092aa: infinite eventloop in interrupt\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | break; |
| 323 | } |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 324 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | active = 0; |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 326 | |
| 327 | for (i = 0; i < socket_count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | int csc; |
Simon Geis | 4ae66dd | 2019-12-13 14:53:08 +0100 | [diff] [blame] | 329 | |
Simon Geis | 152b4bb | 2019-12-13 14:53:11 +0100 | [diff] [blame] | 330 | /* Inactive socket, should not happen */ |
| 331 | if (sockets[i].card_state == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | continue; |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 333 | |
Simon Geis | 152b4bb | 2019-12-13 14:53:11 +0100 | [diff] [blame] | 334 | /* card status change register */ |
| 335 | csc = indirect_read(i, I365_CSC); |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 336 | |
| 337 | if (csc == 0) /* no events on this socket */ |
| 338 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | handled = 1; |
| 340 | events = 0; |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 341 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | if (csc & I365_CSC_DETECT) { |
| 343 | events |= SS_DETECT; |
Simon Geis | 26a0a104 | 2019-12-13 14:53:04 +0100 | [diff] [blame] | 344 | dev_info(&sockets[i].dev->dev, |
| 345 | "Card detected in socket %i!\n", i); |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | if (indirect_read(i, I365_INTCTL) & I365_PC_IOCARD) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | /* For IO/CARDS, bit 0 means "read the card" */ |
Simon Geis | 152b4bb | 2019-12-13 14:53:11 +0100 | [diff] [blame] | 350 | if (csc & I365_CSC_STSCHG) |
| 351 | events |= SS_STSCHG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | } else { |
| 353 | /* Check for battery/ready events */ |
Simon Geis | 152b4bb | 2019-12-13 14:53:11 +0100 | [diff] [blame] | 354 | if (csc & I365_CSC_BVD1) |
| 355 | events |= SS_BATDEAD; |
| 356 | if (csc & I365_CSC_BVD2) |
| 357 | events |= SS_BATWARN; |
| 358 | if (csc & I365_CSC_READY) |
| 359 | events |= SS_READY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | } |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 361 | |
Simon Geis | ae1f62c | 2019-12-13 14:53:07 +0100 | [diff] [blame] | 362 | if (events) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | pcmcia_parse_events(&sockets[i].socket, events); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | active |= events; |
| 365 | } |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 366 | |
| 367 | if (active == 0) /* no more events to handle */ |
| 368 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | } |
| 370 | return IRQ_RETVAL(handled); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | |
| 374 | |
| 375 | /* socket functions */ |
| 376 | |
| 377 | static int card_present(int socketno) |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 378 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | unsigned int val; |
Simon Geis | 4ae66dd | 2019-12-13 14:53:08 +0100 | [diff] [blame] | 380 | |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 381 | if ((socketno < 0) || (socketno >= MAX_SOCKETS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | return 0; |
| 383 | if (sockets[socketno].io_base == 0) |
| 384 | return 0; |
| 385 | |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 386 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | val = indirect_read(socketno, 1); /* Interface status register */ |
Simon Geis | 52739f0 | 2019-12-13 14:53:13 +0100 | [diff] [blame^] | 388 | if ((val&12) == 12) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | return 1; |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 390 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | return 0; |
| 392 | } |
| 393 | |
| 394 | static void set_bridge_state(int sock) |
| 395 | { |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 396 | indirect_write(sock, I365_GBLCTL, 0x00); |
| 397 | indirect_write(sock, I365_GENCTL, 0x00); |
| 398 | |
| 399 | indirect_setbit(sock, I365_INTCTL, 0x08); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | static int i82092aa_init(struct pcmcia_socket *sock) |
| 404 | { |
| 405 | int i; |
| 406 | struct resource res = { .start = 0, .end = 0x0fff }; |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 407 | pccard_io_map io = { 0, 0, 0, 0, 1 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | pccard_mem_map mem = { .res = &res, }; |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 409 | |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 410 | for (i = 0; i < 2; i++) { |
| 411 | io.map = i; |
| 412 | i82092aa_set_io_map(sock, &io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | } |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 414 | for (i = 0; i < 5; i++) { |
| 415 | mem.map = i; |
| 416 | i82092aa_set_mem_map(sock, &mem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | } |
Simon Geis | 52739f0 | 2019-12-13 14:53:13 +0100 | [diff] [blame^] | 418 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | return 0; |
| 420 | } |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 421 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | static int i82092aa_get_status(struct pcmcia_socket *socket, u_int *value) |
| 423 | { |
Simon Geis | 152b4bb | 2019-12-13 14:53:11 +0100 | [diff] [blame] | 424 | unsigned int sock = container_of(socket, |
| 425 | struct socket_info, socket)->number; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | unsigned int status; |
Simon Geis | 152b4bb | 2019-12-13 14:53:11 +0100 | [diff] [blame] | 427 | |
| 428 | /* Interface Status Register */ |
| 429 | status = indirect_read(sock, I365_STATUS); |
| 430 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | *value = 0; |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 432 | |
Simon Geis | ae1f62c | 2019-12-13 14:53:07 +0100 | [diff] [blame] | 433 | if ((status & I365_CS_DETECT) == I365_CS_DETECT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | *value |= SS_DETECT; |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 435 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | /* IO cards have a different meaning of bits 0,1 */ |
| 437 | /* Also notice the inverse-logic on the bits */ |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 438 | if (indirect_read(sock, I365_INTCTL) & I365_PC_IOCARD) { |
Colin Ian King | 84182fc | 2018-10-31 16:46:02 +0000 | [diff] [blame] | 439 | /* IO card */ |
| 440 | if (!(status & I365_CS_STSCHG)) |
| 441 | *value |= SS_STSCHG; |
| 442 | } else { /* non I/O card */ |
| 443 | if (!(status & I365_CS_BVD1)) |
| 444 | *value |= SS_BATDEAD; |
| 445 | if (!(status & I365_CS_BVD2)) |
| 446 | *value |= SS_BATWARN; |
| 447 | } |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 448 | |
Colin Ian King | 84182fc | 2018-10-31 16:46:02 +0000 | [diff] [blame] | 449 | if (status & I365_CS_WRPROT) |
| 450 | (*value) |= SS_WRPROT; /* card is write protected */ |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 451 | |
Colin Ian King | 84182fc | 2018-10-31 16:46:02 +0000 | [diff] [blame] | 452 | if (status & I365_CS_READY) |
| 453 | (*value) |= SS_READY; /* card is not busy */ |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 454 | |
Colin Ian King | 84182fc | 2018-10-31 16:46:02 +0000 | [diff] [blame] | 455 | if (status & I365_CS_POWERON) |
| 456 | (*value) |= SS_POWERON; /* power is applied to the card */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | return 0; |
| 459 | } |
| 460 | |
| 461 | |
Simon Geis | 152b4bb | 2019-12-13 14:53:11 +0100 | [diff] [blame] | 462 | static int i82092aa_set_socket(struct pcmcia_socket *socket, |
| 463 | socket_state_t *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | { |
Simon Geis | 26a0a104 | 2019-12-13 14:53:04 +0100 | [diff] [blame] | 465 | struct socket_info *sock_info = container_of(socket, struct socket_info, |
| 466 | socket); |
| 467 | unsigned int sock = sock_info->number; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | unsigned char reg; |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 469 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | /* First, set the global controller options */ |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 471 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | set_bridge_state(sock); |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 473 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | /* Values for the IGENC register */ |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 475 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | reg = 0; |
Simon Geis | 152b4bb | 2019-12-13 14:53:11 +0100 | [diff] [blame] | 477 | |
| 478 | /* The reset bit has "inverse" logic */ |
| 479 | if (!(state->flags & SS_RESET)) |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 480 | reg = reg | I365_PC_RESET; |
| 481 | if (state->flags & SS_IOCARD) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | reg = reg | I365_PC_IOCARD; |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 483 | |
Simon Geis | 152b4bb | 2019-12-13 14:53:11 +0100 | [diff] [blame] | 484 | /* IGENC, Interrupt and General Control Register */ |
| 485 | indirect_write(sock, I365_INTCTL, reg); |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 486 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | /* Power registers */ |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 488 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | reg = I365_PWR_NORESET; /* default: disable resetdrv on resume */ |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 490 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | if (state->flags & SS_PWR_AUTO) { |
Simon Geis | 26a0a104 | 2019-12-13 14:53:04 +0100 | [diff] [blame] | 492 | dev_info(&sock_info->dev->dev, "Auto power\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | reg |= I365_PWR_AUTO; /* automatic power mngmnt */ |
| 494 | } |
| 495 | if (state->flags & SS_OUTPUT_ENA) { |
Simon Geis | 26a0a104 | 2019-12-13 14:53:04 +0100 | [diff] [blame] | 496 | dev_info(&sock_info->dev->dev, "Power Enabled\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | reg |= I365_PWR_OUT; /* enable power */ |
| 498 | } |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 499 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | switch (state->Vcc) { |
Simon Geis | 6aaf8ff | 2019-12-13 14:53:09 +0100 | [diff] [blame] | 501 | case 0: |
| 502 | break; |
| 503 | case 50: |
| 504 | dev_info(&sock_info->dev->dev, |
| 505 | "setting voltage to Vcc to 5V on socket %i\n", |
| 506 | sock); |
| 507 | reg |= I365_VCC_5V; |
| 508 | break; |
| 509 | default: |
| 510 | dev_err(&sock_info->dev->dev, |
| 511 | "%s called with invalid VCC power value: %i", |
| 512 | __func__, state->Vcc); |
Simon Geis | 6aaf8ff | 2019-12-13 14:53:09 +0100 | [diff] [blame] | 513 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | } |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 515 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | switch (state->Vpp) { |
Simon Geis | 6aaf8ff | 2019-12-13 14:53:09 +0100 | [diff] [blame] | 517 | case 0: |
| 518 | dev_info(&sock_info->dev->dev, |
| 519 | "not setting Vpp on socket %i\n", sock); |
| 520 | break; |
| 521 | case 50: |
| 522 | dev_info(&sock_info->dev->dev, |
| 523 | "setting Vpp to 5.0 for socket %i\n", sock); |
| 524 | reg |= I365_VPP1_5V | I365_VPP2_5V; |
| 525 | break; |
| 526 | case 120: |
| 527 | dev_info(&sock_info->dev->dev, "setting Vpp to 12.0\n"); |
| 528 | reg |= I365_VPP1_12V | I365_VPP2_12V; |
| 529 | break; |
| 530 | default: |
| 531 | dev_err(&sock_info->dev->dev, |
| 532 | "%s called with invalid VPP power value: %i", |
| 533 | __func__, state->Vcc); |
Simon Geis | 6aaf8ff | 2019-12-13 14:53:09 +0100 | [diff] [blame] | 534 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | } |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 536 | |
| 537 | if (reg != indirect_read(sock, I365_POWER)) /* only write if changed */ |
| 538 | indirect_write(sock, I365_POWER, reg); |
| 539 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | /* Enable specific interrupt events */ |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 541 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | reg = 0x00; |
Simon Geis | ae1f62c | 2019-12-13 14:53:07 +0100 | [diff] [blame] | 543 | if (state->csc_mask & SS_DETECT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | reg |= I365_CSC_DETECT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | if (state->flags & SS_IOCARD) { |
| 546 | if (state->csc_mask & SS_STSCHG) |
| 547 | reg |= I365_CSC_STSCHG; |
| 548 | } else { |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 549 | if (state->csc_mask & SS_BATDEAD) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | reg |= I365_CSC_BVD1; |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 551 | if (state->csc_mask & SS_BATWARN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | reg |= I365_CSC_BVD2; |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 553 | if (state->csc_mask & SS_READY) |
| 554 | reg |= I365_CSC_READY; |
| 555 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | } |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 557 | |
Simon Geis | 152b4bb | 2019-12-13 14:53:11 +0100 | [diff] [blame] | 558 | /* now write the value and clear the (probably bogus) pending stuff |
| 559 | * by doing a dummy read |
| 560 | */ |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 561 | |
| 562 | indirect_write(sock, I365_CSCINT, reg); |
| 563 | (void)indirect_read(sock, I365_CSC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | return 0; |
| 566 | } |
| 567 | |
Simon Geis | 152b4bb | 2019-12-13 14:53:11 +0100 | [diff] [blame] | 568 | static int i82092aa_set_io_map(struct pcmcia_socket *socket, |
| 569 | struct pccard_io_map *io) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | { |
Simon Geis | 26a0a104 | 2019-12-13 14:53:04 +0100 | [diff] [blame] | 571 | struct socket_info *sock_info = container_of(socket, struct socket_info, |
| 572 | socket); |
| 573 | unsigned int sock = sock_info->number; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | unsigned char map, ioctl; |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 575 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | map = io->map; |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 577 | |
| 578 | /* Check error conditions */ |
Simon Geis | 52739f0 | 2019-12-13 14:53:13 +0100 | [diff] [blame^] | 579 | if (map > 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | return -EINVAL; |
Simon Geis | 52739f0 | 2019-12-13 14:53:13 +0100 | [diff] [blame^] | 581 | |
Simon Geis | 152b4bb | 2019-12-13 14:53:11 +0100 | [diff] [blame] | 582 | if ((io->start > 0xffff) || (io->stop > 0xffff) |
Simon Geis | 52739f0 | 2019-12-13 14:53:13 +0100 | [diff] [blame^] | 583 | || (io->stop < io->start)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 586 | /* Turn off the window before changing anything */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | if (indirect_read(sock, I365_ADDRWIN) & I365_ENA_IO(map)) |
| 588 | indirect_resetbit(sock, I365_ADDRWIN, I365_ENA_IO(map)); |
| 589 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | /* write the new values */ |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 591 | indirect_write16(sock, I365_IO(map)+I365_W_START, io->start); |
| 592 | indirect_write16(sock, I365_IO(map)+I365_W_STOP, io->stop); |
| 593 | |
| 594 | ioctl = indirect_read(sock, I365_IOCTL) & ~I365_IOCTL_MASK(map); |
| 595 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | if (io->flags & (MAP_16BIT|MAP_AUTOSZ)) |
| 597 | ioctl |= I365_IOCTL_16BIT(map); |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 598 | |
| 599 | indirect_write(sock, I365_IOCTL, ioctl); |
| 600 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | /* Turn the window back on if needed */ |
| 602 | if (io->flags & MAP_ACTIVE) |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 603 | indirect_setbit(sock, I365_ADDRWIN, I365_ENA_IO(map)); |
| 604 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | return 0; |
| 606 | } |
| 607 | |
Simon Geis | 152b4bb | 2019-12-13 14:53:11 +0100 | [diff] [blame] | 608 | static int i82092aa_set_mem_map(struct pcmcia_socket *socket, |
| 609 | struct pccard_mem_map *mem) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | { |
Simon Geis | 152b4bb | 2019-12-13 14:53:11 +0100 | [diff] [blame] | 611 | struct socket_info *sock_info = container_of(socket, struct socket_info, |
| 612 | socket); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | unsigned int sock = sock_info->number; |
| 614 | struct pci_bus_region region; |
| 615 | unsigned short base, i; |
| 616 | unsigned char map; |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 617 | |
Yinghai Lu | fc27985 | 2013-12-09 22:54:40 -0800 | [diff] [blame] | 618 | pcibios_resource_to_bus(sock_info->dev->bus, ®ion, mem->res); |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 619 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | map = mem->map; |
Simon Geis | 52739f0 | 2019-12-13 14:53:13 +0100 | [diff] [blame^] | 621 | if (map > 4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | return -EINVAL; |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 623 | |
| 624 | if ((mem->card_start > 0x3ffffff) || (region.start > region.end) || |
| 625 | (mem->speed > 1000)) { |
Simon Geis | 26a0a104 | 2019-12-13 14:53:04 +0100 | [diff] [blame] | 626 | dev_err(&sock_info->dev->dev, |
Simon Geis | 152b4bb | 2019-12-13 14:53:11 +0100 | [diff] [blame] | 627 | "invalid mem map for socket %i: %llx to %llx with a start of %x\n", |
Andrew Morton | f96ee7a | 2008-02-04 23:35:48 -0800 | [diff] [blame] | 628 | sock, |
| 629 | (unsigned long long)region.start, |
| 630 | (unsigned long long)region.end, |
| 631 | mem->card_start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | return -EINVAL; |
| 633 | } |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 634 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | /* Turn off the window before changing anything */ |
| 636 | if (indirect_read(sock, I365_ADDRWIN) & I365_ENA_MEM(map)) |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 637 | indirect_resetbit(sock, I365_ADDRWIN, I365_ENA_MEM(map)); |
| 638 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | /* write the start address */ |
| 640 | base = I365_MEM(map); |
| 641 | i = (region.start >> 12) & 0x0fff; |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 642 | if (mem->flags & MAP_16BIT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | i |= I365_MEM_16BIT; |
| 644 | if (mem->flags & MAP_0WS) |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 645 | i |= I365_MEM_0WS; |
| 646 | indirect_write16(sock, base+I365_W_START, i); |
| 647 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | /* write the stop address */ |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 649 | |
| 650 | i = (region.end >> 12) & 0x0fff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | switch (to_cycles(mem->speed)) { |
Simon Geis | 6aaf8ff | 2019-12-13 14:53:09 +0100 | [diff] [blame] | 652 | case 0: |
| 653 | break; |
| 654 | case 1: |
| 655 | i |= I365_MEM_WS0; |
| 656 | break; |
| 657 | case 2: |
| 658 | i |= I365_MEM_WS1; |
| 659 | break; |
| 660 | default: |
| 661 | i |= I365_MEM_WS1 | I365_MEM_WS0; |
| 662 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | } |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 664 | |
| 665 | indirect_write16(sock, base+I365_W_STOP, i); |
| 666 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | /* card start */ |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 668 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | i = ((mem->card_start - region.start) >> 12) & 0x3fff; |
| 670 | if (mem->flags & MAP_WRPROT) |
| 671 | i |= I365_MEM_WRPROT; |
Simon Geis | 26a0a104 | 2019-12-13 14:53:04 +0100 | [diff] [blame] | 672 | if (mem->flags & MAP_ATTRIB) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | i |= I365_MEM_REG; |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 674 | indirect_write16(sock, base+I365_W_OFF, i); |
| 675 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | /* Enable the window if necessary */ |
| 677 | if (mem->flags & MAP_ACTIVE) |
| 678 | indirect_setbit(sock, I365_ADDRWIN, I365_ENA_MEM(map)); |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 679 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | return 0; |
| 681 | } |
| 682 | |
| 683 | static int i82092aa_module_init(void) |
| 684 | { |
Sam Ravnborg | ba66ddf | 2008-05-01 04:34:51 -0700 | [diff] [blame] | 685 | return pci_register_driver(&i82092aa_pci_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | } |
| 687 | |
| 688 | static void i82092aa_module_exit(void) |
| 689 | { |
Sam Ravnborg | ba66ddf | 2008-05-01 04:34:51 -0700 | [diff] [blame] | 690 | pci_unregister_driver(&i82092aa_pci_driver); |
Simon Geis | 4839879 | 2019-12-13 14:53:06 +0100 | [diff] [blame] | 691 | if (sockets[0].io_base > 0) |
Simon Geis | 6aaf8ff | 2019-12-13 14:53:09 +0100 | [diff] [blame] | 692 | release_region(sockets[0].io_base, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | module_init(i82092aa_module_init); |
| 696 | module_exit(i82092aa_module_exit); |
| 697 | |