blob: 2d31832fa43916b678e6603e740fbb7626ed068a [file] [log] [blame]
Thomas Gleixner09c434b2019-05-19 13:08:20 +01001// SPDX-License-Identifier: GPL-2.0-only
Simon Geis48398792019-12-13 14:53:06 +01002/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * 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 Torvalds1da177e2005-04-16 15:20:36 -07009 */
10
11#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#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 Torvalds1da177e2005-04-16 15:20:36 -070019#include <pcmcia/ss.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <asm/io.h>
22
23#include "i82092aa.h"
24#include "i82365.h"
25
26MODULE_LICENSE("GPL");
27
28/* PCI core routines */
Greg Kroah-Hartman0178a7a2014-07-18 16:58:07 -070029static const struct pci_device_id i82092aa_pci_ids[] = {
Axel Lin2b2c5d82011-12-27 16:17:46 +080030 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82092AA_0) },
31 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -070032};
33MODULE_DEVICE_TABLE(pci, i82092aa_pci_ids);
34
Sam Ravnborgba66ddf2008-05-01 04:34:51 -070035static struct pci_driver i82092aa_pci_driver = {
Simon Geis48398792019-12-13 14:53:06 +010036 .name = "i82092aa",
37 .id_table = i82092aa_pci_ids,
38 .probe = i82092aa_pci_probe,
39 .remove = i82092aa_pci_remove,
Linus Torvalds1da177e2005-04-16 15:20:36 -070040};
41
42
43/* the pccard structure and its functions */
44static struct pccard_operations i82092aa_operations = {
Simon Geis48398792019-12-13 14:53:06 +010045 .init = i82092aa_init,
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 .get_status = i82092aa_get_status,
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 .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 Marchi25985ed2011-03-30 22:57:33 -030052/* The card can do up to 4 sockets, allocate a structure for each of them */
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54struct socket_info {
55 int number;
Simon Geis48398792019-12-13 14:53:06 +010056 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 Torvalds1da177e2005-04-16 15:20:36 -070064 struct pcmcia_socket socket;
65 struct pci_dev *dev; /* The PCI device for the socket */
66};
67
68#define MAX_SOCKETS 4
69static struct socket_info sockets[MAX_SOCKETS];
Simon Geis48398792019-12-13 14:53:06 +010070static int socket_count; /* shortcut */
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
72
Bill Pemberton34cdf252012-11-19 13:23:12 -050073static int i82092aa_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074{
75 unsigned char configbyte;
76 int i, ret;
Simon Geis48398792019-12-13 14:53:06 +010077
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 enter("i82092aa_pci_probe");
Simon Geis48398792019-12-13 14:53:06 +010079
Simon Geis90886462019-12-13 14:53:10 +010080 ret = pci_enable_device(dev);
81 if (ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 return ret;
Simon Geis48398792019-12-13 14:53:06 +010083
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 pci_read_config_byte(dev, 0x40, &configbyte); /* PCI Configuration Control */
Simon Geis48398792019-12-13 14:53:06 +010085 switch (configbyte&6) {
Simon Geis6aaf8ff2019-12-13 14:53:09 +010086 case 0:
87 socket_count = 2;
88 break;
89 case 2:
90 socket_count = 1;
91 break;
92 case 4:
93 case 6:
94 socket_count = 4;
95 break;
Simon Geis48398792019-12-13 14:53:06 +010096
Simon Geis6aaf8ff2019-12-13 14:53:09 +010097 default:
98 dev_err(&dev->dev,
99 "Oops, you did something we didn't think of.\n");
100 ret = -EIO;
101 goto err_out_disable;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 }
Simon Geis26a0a1042019-12-13 14:53:04 +0100103 dev_info(&dev->dev, "configured as a %d socket device.\n",
104 socket_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
106 if (!request_region(pci_resource_start(dev, 0), 2, "i82092aa")) {
107 ret = -EBUSY;
108 goto err_out_disable;
109 }
Simon Geis48398792019-12-13 14:53:06 +0100110
111 for (i = 0; i < socket_count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 sockets[i].card_state = 1; /* 1 = present but empty */
113 sockets[i].io_base = pci_resource_start(dev, 0);
114 sockets[i].socket.features |= SS_CAP_PCCARD;
115 sockets[i].socket.map_size = 0x1000;
116 sockets[i].socket.irq_mask = 0;
117 sockets[i].socket.pci_irq = dev->irq;
Dominik Brodowski7a96e872010-03-13 17:42:39 +0100118 sockets[i].socket.cb_dev = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 sockets[i].socket.owner = THIS_MODULE;
120
121 sockets[i].number = i;
Simon Geis48398792019-12-13 14:53:06 +0100122
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 if (card_present(i)) {
124 sockets[i].card_state = 3;
Simon Geis26a0a1042019-12-13 14:53:04 +0100125 dev_dbg(&dev->dev, "slot %i is occupied\n", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 } else {
Simon Geis26a0a1042019-12-13 14:53:04 +0100127 dev_dbg(&dev->dev, "slot %i is vacant\n", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 }
129 }
Simon Geis48398792019-12-13 14:53:06 +0100130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 /* Now, specifiy that all interrupts are to be done as PCI interrupts */
132 configbyte = 0xFF; /* bitmask, one bit per event, 1 = PCI interrupt, 0 = ISA interrupt */
133 pci_write_config_byte(dev, 0x50, configbyte); /* PCI Interrupt Routing Register */
134
135 /* Register the interrupt handler */
Adam Zerella836e9492019-08-25 15:35:10 +1000136 dev_dbg(&dev->dev, "Requesting interrupt %i\n", dev->irq);
Simon Geis90886462019-12-13 14:53:10 +0100137 ret = request_irq(dev->irq, i82092aa_interrupt, IRQF_SHARED,
138 "i82092aa", i82092aa_interrupt);
139 if (ret) {
Simon Geis26a0a1042019-12-13 14:53:04 +0100140 dev_err(&dev->dev, "Failed to register IRQ %d, aborting\n",
141 dev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 goto err_out_free_res;
143 }
144
Simon Geis48398792019-12-13 14:53:06 +0100145 for (i = 0; i < socket_count; i++) {
Greg Kroah-Hartman87373312006-09-12 17:00:10 +0200146 sockets[i].socket.dev.parent = &dev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 sockets[i].socket.ops = &i82092aa_operations;
148 sockets[i].socket.resource_ops = &pccard_nonstatic_ops;
149 ret = pcmcia_register_socket(&sockets[i].socket);
Simon Geisae1f62c2019-12-13 14:53:07 +0100150 if (ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 goto err_out_free_sockets;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 }
153
154 leave("i82092aa_pci_probe");
155 return 0;
156
157err_out_free_sockets:
158 if (i) {
Simon Geisae1f62c2019-12-13 14:53:07 +0100159 for (i--; i >= 0; i--)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 pcmcia_unregister_socket(&sockets[i].socket);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 }
162 free_irq(dev->irq, i82092aa_interrupt);
163err_out_free_res:
164 release_region(pci_resource_start(dev, 0), 2);
165err_out_disable:
166 pci_disable_device(dev);
Simon Geis48398792019-12-13 14:53:06 +0100167 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168}
169
Bill Pembertone765a022012-11-19 13:26:05 -0500170static void i82092aa_pci_remove(struct pci_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171{
Dan Carpenter36c286d2012-12-14 18:01:08 +0300172 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173
174 enter("i82092aa_pci_remove");
Simon Geis48398792019-12-13 14:53:06 +0100175
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 free_irq(dev->irq, i82092aa_interrupt);
177
Dan Carpenter36c286d2012-12-14 18:01:08 +0300178 for (i = 0; i < socket_count; i++)
179 pcmcia_unregister_socket(&sockets[i].socket);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
181 leave("i82092aa_pci_remove");
182}
183
184static DEFINE_SPINLOCK(port_lock);
185
186/* basic value read/write functions */
187
188static unsigned char indirect_read(int socket, unsigned short reg)
189{
190 unsigned short int port;
191 unsigned char val;
192 unsigned long flags;
Simon Geis4ae66dd2019-12-13 14:53:08 +0100193
Simon Geis48398792019-12-13 14:53:06 +0100194 spin_lock_irqsave(&port_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 reg += socket * 0x40;
196 port = sockets[socket].io_base;
Simon Geis48398792019-12-13 14:53:06 +0100197 outb(reg, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 val = inb(port+1);
Simon Geis48398792019-12-13 14:53:06 +0100199 spin_unlock_irqrestore(&port_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 return val;
201}
202
203#if 0
204static unsigned short indirect_read16(int socket, unsigned short reg)
205{
206 unsigned short int port;
207 unsigned short tmp;
208 unsigned long flags;
Simon Geis4ae66dd2019-12-13 14:53:08 +0100209
Simon Geis48398792019-12-13 14:53:06 +0100210 spin_lock_irqsave(&port_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 reg = reg + socket * 0x40;
212 port = sockets[socket].io_base;
Simon Geis48398792019-12-13 14:53:06 +0100213 outb(reg, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 tmp = inb(port+1);
215 reg++;
Simon Geis48398792019-12-13 14:53:06 +0100216 outb(reg, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 tmp = tmp | (inb(port+1)<<8);
Simon Geis48398792019-12-13 14:53:06 +0100218 spin_unlock_irqrestore(&port_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 return tmp;
220}
221#endif
222
223static void indirect_write(int socket, unsigned short reg, unsigned char value)
224{
225 unsigned short int port;
226 unsigned long flags;
Simon Geis4ae66dd2019-12-13 14:53:08 +0100227
Simon Geis48398792019-12-13 14:53:06 +0100228 spin_lock_irqsave(&port_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 reg = reg + socket * 0x40;
Simon Geis48398792019-12-13 14:53:06 +0100230 port = sockets[socket].io_base;
231 outb(reg, port);
232 outb(value, port+1);
233 spin_unlock_irqrestore(&port_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234}
235
236static 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 Geis4ae66dd2019-12-13 14:53:08 +0100241
Simon Geis48398792019-12-13 14:53:06 +0100242 spin_lock_irqsave(&port_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 reg = reg + socket * 0x40;
Simon Geis48398792019-12-13 14:53:06 +0100244 port = sockets[socket].io_base;
245 outb(reg, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 val = inb(port+1);
247 val |= mask;
Simon Geis48398792019-12-13 14:53:06 +0100248 outb(reg, port);
249 outb(val, port+1);
250 spin_unlock_irqrestore(&port_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251}
252
253
254static void indirect_resetbit(int socket, unsigned short reg, unsigned char mask)
255{
256 unsigned short int port;
257 unsigned char val;
258 unsigned long flags;
Simon Geis4ae66dd2019-12-13 14:53:08 +0100259
Simon Geis48398792019-12-13 14:53:06 +0100260 spin_lock_irqsave(&port_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 reg = reg + socket * 0x40;
Simon Geis48398792019-12-13 14:53:06 +0100262 port = sockets[socket].io_base;
263 outb(reg, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 val = inb(port+1);
265 val &= ~mask;
Simon Geis48398792019-12-13 14:53:06 +0100266 outb(reg, port);
267 outb(val, port+1);
268 spin_unlock_irqrestore(&port_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269}
270
271static void indirect_write16(int socket, unsigned short reg, unsigned short value)
272{
273 unsigned short int port;
274 unsigned char val;
275 unsigned long flags;
Simon Geis4ae66dd2019-12-13 14:53:08 +0100276
Simon Geis48398792019-12-13 14:53:06 +0100277 spin_lock_irqsave(&port_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 reg = reg + socket * 0x40;
Simon Geis48398792019-12-13 14:53:06 +0100279 port = sockets[socket].io_base;
280
281 outb(reg, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 val = value & 255;
Simon Geis48398792019-12-13 14:53:06 +0100283 outb(val, port+1);
284
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 reg++;
Simon Geis48398792019-12-13 14:53:06 +0100286
287 outb(reg, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 val = value>>8;
Simon Geis48398792019-12-13 14:53:06 +0100289 outb(val, port+1);
290 spin_unlock_irqrestore(&port_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291}
292
293/* simple helper functions */
294/* External clock time, in nanoseconds. 120 ns = 8.33 MHz */
295static int cycle_time = 120;
296
297static int to_cycles(int ns)
298{
Simon Geis48398792019-12-13 14:53:06 +0100299 if (cycle_time != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 return ns/cycle_time;
301 else
302 return 0;
303}
Simon Geis48398792019-12-13 14:53:06 +0100304
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305
306/* Interrupt handler functionality */
307
David Howells7d12e782006-10-05 14:55:46 +0100308static irqreturn_t i82092aa_interrupt(int irq, void *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309{
310 int i;
311 int loopcount = 0;
312 int handled = 0;
313
Simon Geis48398792019-12-13 14:53:06 +0100314 unsigned int events, active = 0;
315
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316/* enter("i82092aa_interrupt");*/
Simon Geis48398792019-12-13 14:53:06 +0100317
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 while (1) {
319 loopcount++;
Simon Geis48398792019-12-13 14:53:06 +0100320 if (loopcount > 20) {
Simon Geis26a0a1042019-12-13 14:53:04 +0100321 pr_err("i82092aa: infinite eventloop in interrupt\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 break;
323 }
Simon Geis48398792019-12-13 14:53:06 +0100324
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 active = 0;
Simon Geis48398792019-12-13 14:53:06 +0100326
327 for (i = 0; i < socket_count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 int csc;
Simon Geis4ae66dd2019-12-13 14:53:08 +0100329
Simon Geis48398792019-12-13 14:53:06 +0100330 if (sockets[i].card_state == 0) /* Inactive socket, should not happen */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 continue;
Simon Geis48398792019-12-13 14:53:06 +0100332
333 csc = indirect_read(i, I365_CSC); /* card status change register */
334
335 if (csc == 0) /* no events on this socket */
336 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 handled = 1;
338 events = 0;
Simon Geis48398792019-12-13 14:53:06 +0100339
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 if (csc & I365_CSC_DETECT) {
341 events |= SS_DETECT;
Simon Geis26a0a1042019-12-13 14:53:04 +0100342 dev_info(&sockets[i].dev->dev,
343 "Card detected in socket %i!\n", i);
Simon Geis48398792019-12-13 14:53:06 +0100344 }
345
346 if (indirect_read(i, I365_INTCTL) & I365_PC_IOCARD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 /* For IO/CARDS, bit 0 means "read the card" */
Simon Geis48398792019-12-13 14:53:06 +0100348 events |= (csc & I365_CSC_STSCHG) ? SS_STSCHG : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 } else {
350 /* Check for battery/ready events */
351 events |= (csc & I365_CSC_BVD1) ? SS_BATDEAD : 0;
352 events |= (csc & I365_CSC_BVD2) ? SS_BATWARN : 0;
353 events |= (csc & I365_CSC_READY) ? SS_READY : 0;
354 }
Simon Geis48398792019-12-13 14:53:06 +0100355
Simon Geisae1f62c2019-12-13 14:53:07 +0100356 if (events)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 pcmcia_parse_events(&sockets[i].socket, events);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 active |= events;
359 }
Simon Geis48398792019-12-13 14:53:06 +0100360
361 if (active == 0) /* no more events to handle */
362 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 }
364 return IRQ_RETVAL(handled);
365/* leave("i82092aa_interrupt");*/
366}
367
368
369
370/* socket functions */
371
372static int card_present(int socketno)
Simon Geis48398792019-12-13 14:53:06 +0100373{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 unsigned int val;
Simon Geis4ae66dd2019-12-13 14:53:08 +0100375
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 enter("card_present");
Simon Geis48398792019-12-13 14:53:06 +0100377
378 if ((socketno < 0) || (socketno >= MAX_SOCKETS))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 return 0;
380 if (sockets[socketno].io_base == 0)
381 return 0;
382
Simon Geis48398792019-12-13 14:53:06 +0100383
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 val = indirect_read(socketno, 1); /* Interface status register */
Simon Geis48398792019-12-13 14:53:06 +0100385 if ((val&12) == 12) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 leave("card_present 1");
387 return 1;
388 }
Simon Geis48398792019-12-13 14:53:06 +0100389
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 leave("card_present 0");
391 return 0;
392}
393
394static void set_bridge_state(int sock)
395{
396 enter("set_bridge_state");
Simon Geis48398792019-12-13 14:53:06 +0100397 indirect_write(sock, I365_GBLCTL, 0x00);
398 indirect_write(sock, I365_GENCTL, 0x00);
399
400 indirect_setbit(sock, I365_INTCTL, 0x08);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 leave("set_bridge_state");
402}
403
404
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405static int i82092aa_init(struct pcmcia_socket *sock)
406{
407 int i;
408 struct resource res = { .start = 0, .end = 0x0fff };
Simon Geis48398792019-12-13 14:53:06 +0100409 pccard_io_map io = { 0, 0, 0, 0, 1 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 pccard_mem_map mem = { .res = &res, };
Simon Geis48398792019-12-13 14:53:06 +0100411
412 enter("i82092aa_init");
413
414 for (i = 0; i < 2; i++) {
415 io.map = i;
416 i82092aa_set_io_map(sock, &io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 }
Simon Geis48398792019-12-13 14:53:06 +0100418 for (i = 0; i < 5; i++) {
419 mem.map = i;
420 i82092aa_set_mem_map(sock, &mem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 }
422
423 leave("i82092aa_init");
424 return 0;
425}
Simon Geis48398792019-12-13 14:53:06 +0100426
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427static int i82092aa_get_status(struct pcmcia_socket *socket, u_int *value)
428{
429 unsigned int sock = container_of(socket, struct socket_info, socket)->number;
430 unsigned int status;
431
432 enter("i82092aa_get_status");
433
Simon Geis48398792019-12-13 14:53:06 +0100434 status = indirect_read(sock, I365_STATUS); /* Interface Status Register */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 *value = 0;
Simon Geis48398792019-12-13 14:53:06 +0100436
Simon Geisae1f62c2019-12-13 14:53:07 +0100437 if ((status & I365_CS_DETECT) == I365_CS_DETECT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 *value |= SS_DETECT;
Simon Geis48398792019-12-13 14:53:06 +0100439
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 /* IO cards have a different meaning of bits 0,1 */
441 /* Also notice the inverse-logic on the bits */
Simon Geis48398792019-12-13 14:53:06 +0100442 if (indirect_read(sock, I365_INTCTL) & I365_PC_IOCARD) {
Colin Ian King84182fc2018-10-31 16:46:02 +0000443 /* IO card */
444 if (!(status & I365_CS_STSCHG))
445 *value |= SS_STSCHG;
446 } else { /* non I/O card */
447 if (!(status & I365_CS_BVD1))
448 *value |= SS_BATDEAD;
449 if (!(status & I365_CS_BVD2))
450 *value |= SS_BATWARN;
451 }
Simon Geis48398792019-12-13 14:53:06 +0100452
Colin Ian King84182fc2018-10-31 16:46:02 +0000453 if (status & I365_CS_WRPROT)
454 (*value) |= SS_WRPROT; /* card is write protected */
Simon Geis48398792019-12-13 14:53:06 +0100455
Colin Ian King84182fc2018-10-31 16:46:02 +0000456 if (status & I365_CS_READY)
457 (*value) |= SS_READY; /* card is not busy */
Simon Geis48398792019-12-13 14:53:06 +0100458
Colin Ian King84182fc2018-10-31 16:46:02 +0000459 if (status & I365_CS_POWERON)
460 (*value) |= SS_POWERON; /* power is applied to the card */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461
462 leave("i82092aa_get_status");
463 return 0;
464}
465
466
Simon Geis48398792019-12-13 14:53:06 +0100467static int i82092aa_set_socket(struct pcmcia_socket *socket, socket_state_t *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468{
Simon Geis26a0a1042019-12-13 14:53:04 +0100469 struct socket_info *sock_info = container_of(socket, struct socket_info,
470 socket);
471 unsigned int sock = sock_info->number;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 unsigned char reg;
Simon Geis48398792019-12-13 14:53:06 +0100473
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 enter("i82092aa_set_socket");
Simon Geis48398792019-12-13 14:53:06 +0100475
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 /* First, set the global controller options */
Simon Geis48398792019-12-13 14:53:06 +0100477
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 set_bridge_state(sock);
Simon Geis48398792019-12-13 14:53:06 +0100479
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 /* Values for the IGENC register */
Simon Geis48398792019-12-13 14:53:06 +0100481
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 reg = 0;
Simon Geis48398792019-12-13 14:53:06 +0100483 if (!(state->flags & SS_RESET)) /* The reset bit has "inverse" logic */
484 reg = reg | I365_PC_RESET;
485 if (state->flags & SS_IOCARD)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 reg = reg | I365_PC_IOCARD;
Simon Geis48398792019-12-13 14:53:06 +0100487
488 indirect_write(sock, I365_INTCTL, reg); /* IGENC, Interrupt and General Control Register */
489
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 /* Power registers */
Simon Geis48398792019-12-13 14:53:06 +0100491
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 reg = I365_PWR_NORESET; /* default: disable resetdrv on resume */
Simon Geis48398792019-12-13 14:53:06 +0100493
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 if (state->flags & SS_PWR_AUTO) {
Simon Geis26a0a1042019-12-13 14:53:04 +0100495 dev_info(&sock_info->dev->dev, "Auto power\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 reg |= I365_PWR_AUTO; /* automatic power mngmnt */
497 }
498 if (state->flags & SS_OUTPUT_ENA) {
Simon Geis26a0a1042019-12-13 14:53:04 +0100499 dev_info(&sock_info->dev->dev, "Power Enabled\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 reg |= I365_PWR_OUT; /* enable power */
501 }
Simon Geis48398792019-12-13 14:53:06 +0100502
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 switch (state->Vcc) {
Simon Geis6aaf8ff2019-12-13 14:53:09 +0100504 case 0:
505 break;
506 case 50:
507 dev_info(&sock_info->dev->dev,
508 "setting voltage to Vcc to 5V on socket %i\n",
509 sock);
510 reg |= I365_VCC_5V;
511 break;
512 default:
513 dev_err(&sock_info->dev->dev,
514 "%s called with invalid VCC power value: %i",
515 __func__, state->Vcc);
516 leave("i82092aa_set_socket");
517 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 }
Simon Geis48398792019-12-13 14:53:06 +0100519
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 switch (state->Vpp) {
Simon Geis6aaf8ff2019-12-13 14:53:09 +0100521 case 0:
522 dev_info(&sock_info->dev->dev,
523 "not setting Vpp on socket %i\n", sock);
524 break;
525 case 50:
526 dev_info(&sock_info->dev->dev,
527 "setting Vpp to 5.0 for socket %i\n", sock);
528 reg |= I365_VPP1_5V | I365_VPP2_5V;
529 break;
530 case 120:
531 dev_info(&sock_info->dev->dev, "setting Vpp to 12.0\n");
532 reg |= I365_VPP1_12V | I365_VPP2_12V;
533 break;
534 default:
535 dev_err(&sock_info->dev->dev,
536 "%s called with invalid VPP power value: %i",
537 __func__, state->Vcc);
538 leave("i82092aa_set_socket");
539 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 }
Simon Geis48398792019-12-13 14:53:06 +0100541
542 if (reg != indirect_read(sock, I365_POWER)) /* only write if changed */
543 indirect_write(sock, I365_POWER, reg);
544
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 /* Enable specific interrupt events */
Simon Geis48398792019-12-13 14:53:06 +0100546
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 reg = 0x00;
Simon Geisae1f62c2019-12-13 14:53:07 +0100548 if (state->csc_mask & SS_DETECT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 reg |= I365_CSC_DETECT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 if (state->flags & SS_IOCARD) {
551 if (state->csc_mask & SS_STSCHG)
552 reg |= I365_CSC_STSCHG;
553 } else {
Simon Geis48398792019-12-13 14:53:06 +0100554 if (state->csc_mask & SS_BATDEAD)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 reg |= I365_CSC_BVD1;
Simon Geis48398792019-12-13 14:53:06 +0100556 if (state->csc_mask & SS_BATWARN)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 reg |= I365_CSC_BVD2;
Simon Geis48398792019-12-13 14:53:06 +0100558 if (state->csc_mask & SS_READY)
559 reg |= I365_CSC_READY;
560
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 }
Simon Geis48398792019-12-13 14:53:06 +0100562
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 /* now write the value and clear the (probably bogus) pending stuff by doing a dummy read*/
Simon Geis48398792019-12-13 14:53:06 +0100564
565 indirect_write(sock, I365_CSCINT, reg);
566 (void)indirect_read(sock, I365_CSC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567
568 leave("i82092aa_set_socket");
569 return 0;
570}
571
572static int i82092aa_set_io_map(struct pcmcia_socket *socket, struct pccard_io_map *io)
573{
Simon Geis26a0a1042019-12-13 14:53:04 +0100574 struct socket_info *sock_info = container_of(socket, struct socket_info,
575 socket);
576 unsigned int sock = sock_info->number;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 unsigned char map, ioctl;
Simon Geis48398792019-12-13 14:53:06 +0100578
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 enter("i82092aa_set_io_map");
Simon Geis48398792019-12-13 14:53:06 +0100580
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 map = io->map;
Simon Geis48398792019-12-13 14:53:06 +0100582
583 /* Check error conditions */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 if (map > 1) {
585 leave("i82092aa_set_io_map with invalid map");
586 return -EINVAL;
587 }
Simon Geis48398792019-12-13 14:53:06 +0100588 if ((io->start > 0xffff) || (io->stop > 0xffff) || (io->stop < io->start)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 leave("i82092aa_set_io_map with invalid io");
590 return -EINVAL;
591 }
592
Simon Geis48398792019-12-13 14:53:06 +0100593 /* Turn off the window before changing anything */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 if (indirect_read(sock, I365_ADDRWIN) & I365_ENA_IO(map))
595 indirect_resetbit(sock, I365_ADDRWIN, I365_ENA_IO(map));
596
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 /* write the new values */
Simon Geis48398792019-12-13 14:53:06 +0100598 indirect_write16(sock, I365_IO(map)+I365_W_START, io->start);
599 indirect_write16(sock, I365_IO(map)+I365_W_STOP, io->stop);
600
601 ioctl = indirect_read(sock, I365_IOCTL) & ~I365_IOCTL_MASK(map);
602
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 if (io->flags & (MAP_16BIT|MAP_AUTOSZ))
604 ioctl |= I365_IOCTL_16BIT(map);
Simon Geis48398792019-12-13 14:53:06 +0100605
606 indirect_write(sock, I365_IOCTL, ioctl);
607
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 /* Turn the window back on if needed */
609 if (io->flags & MAP_ACTIVE)
Simon Geis48398792019-12-13 14:53:06 +0100610 indirect_setbit(sock, I365_ADDRWIN, I365_ENA_IO(map));
611
612 leave("i82092aa_set_io_map");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 return 0;
614}
615
616static int i82092aa_set_mem_map(struct pcmcia_socket *socket, struct pccard_mem_map *mem)
617{
618 struct socket_info *sock_info = container_of(socket, struct socket_info, socket);
619 unsigned int sock = sock_info->number;
620 struct pci_bus_region region;
621 unsigned short base, i;
622 unsigned char map;
Simon Geis48398792019-12-13 14:53:06 +0100623
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 enter("i82092aa_set_mem_map");
625
Yinghai Lufc279852013-12-09 22:54:40 -0800626 pcibios_resource_to_bus(sock_info->dev->bus, &region, mem->res);
Simon Geis48398792019-12-13 14:53:06 +0100627
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 map = mem->map;
629 if (map > 4) {
630 leave("i82092aa_set_mem_map: invalid map");
631 return -EINVAL;
632 }
Simon Geis48398792019-12-13 14:53:06 +0100633
634
635 if ((mem->card_start > 0x3ffffff) || (region.start > region.end) ||
636 (mem->speed > 1000)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 leave("i82092aa_set_mem_map: invalid address / speed");
Simon Geis26a0a1042019-12-13 14:53:04 +0100638 dev_err(&sock_info->dev->dev,
639 "invalid mem map for socket %i: %llx to %llx with a "
Andrew Mortonf96ee7a2008-02-04 23:35:48 -0800640 "start of %x\n",
641 sock,
642 (unsigned long long)region.start,
643 (unsigned long long)region.end,
644 mem->card_start);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 return -EINVAL;
646 }
Simon Geis48398792019-12-13 14:53:06 +0100647
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 /* Turn off the window before changing anything */
649 if (indirect_read(sock, I365_ADDRWIN) & I365_ENA_MEM(map))
Simon Geis48398792019-12-13 14:53:06 +0100650 indirect_resetbit(sock, I365_ADDRWIN, I365_ENA_MEM(map));
651
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 /* write the start address */
653 base = I365_MEM(map);
654 i = (region.start >> 12) & 0x0fff;
Simon Geis48398792019-12-13 14:53:06 +0100655 if (mem->flags & MAP_16BIT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 i |= I365_MEM_16BIT;
657 if (mem->flags & MAP_0WS)
Simon Geis48398792019-12-13 14:53:06 +0100658 i |= I365_MEM_0WS;
659 indirect_write16(sock, base+I365_W_START, i);
660
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 /* write the stop address */
Simon Geis48398792019-12-13 14:53:06 +0100662
663 i = (region.end >> 12) & 0x0fff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 switch (to_cycles(mem->speed)) {
Simon Geis6aaf8ff2019-12-13 14:53:09 +0100665 case 0:
666 break;
667 case 1:
668 i |= I365_MEM_WS0;
669 break;
670 case 2:
671 i |= I365_MEM_WS1;
672 break;
673 default:
674 i |= I365_MEM_WS1 | I365_MEM_WS0;
675 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 }
Simon Geis48398792019-12-13 14:53:06 +0100677
678 indirect_write16(sock, base+I365_W_STOP, i);
679
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 /* card start */
Simon Geis48398792019-12-13 14:53:06 +0100681
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 i = ((mem->card_start - region.start) >> 12) & 0x3fff;
683 if (mem->flags & MAP_WRPROT)
684 i |= I365_MEM_WRPROT;
Simon Geis26a0a1042019-12-13 14:53:04 +0100685 if (mem->flags & MAP_ATTRIB)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 i |= I365_MEM_REG;
Simon Geis48398792019-12-13 14:53:06 +0100687 indirect_write16(sock, base+I365_W_OFF, i);
688
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 /* Enable the window if necessary */
690 if (mem->flags & MAP_ACTIVE)
691 indirect_setbit(sock, I365_ADDRWIN, I365_ENA_MEM(map));
Simon Geis48398792019-12-13 14:53:06 +0100692
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 leave("i82092aa_set_mem_map");
694 return 0;
695}
696
697static int i82092aa_module_init(void)
698{
Sam Ravnborgba66ddf2008-05-01 04:34:51 -0700699 return pci_register_driver(&i82092aa_pci_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700}
701
702static void i82092aa_module_exit(void)
703{
704 enter("i82092aa_module_exit");
Sam Ravnborgba66ddf2008-05-01 04:34:51 -0700705 pci_unregister_driver(&i82092aa_pci_driver);
Simon Geis48398792019-12-13 14:53:06 +0100706 if (sockets[0].io_base > 0)
Simon Geis6aaf8ff2019-12-13 14:53:09 +0100707 release_region(sockets[0].io_base, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 leave("i82092aa_module_exit");
709}
710
711module_init(i82092aa_module_init);
712module_exit(i82092aa_module_exit);
713