blob: 192c9049d654fdd15275d4e7e3a465618564dbba [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
Simon Geisac5af872019-12-13 14:53:12 +010021#include <linux/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
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
Simon Geis152b4bb2019-12-13 14:53:11 +010073static int i82092aa_pci_probe(struct pci_dev *dev,
74 const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075{
76 unsigned char configbyte;
77 int i, ret;
Simon Geis48398792019-12-13 14:53:06 +010078
Simon Geis90886462019-12-13 14:53:10 +010079 ret = pci_enable_device(dev);
80 if (ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 return ret;
Simon Geis48398792019-12-13 14:53:06 +010082
Simon Geis152b4bb2019-12-13 14:53:11 +010083 /* PCI Configuration Control */
84 pci_read_config_byte(dev, 0x40, &configbyte);
85
Simon Geis48398792019-12-13 14:53:06 +010086 switch (configbyte&6) {
Simon Geis6aaf8ff2019-12-13 14:53:09 +010087 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 Geis48398792019-12-13 14:53:06 +010097
Simon Geis6aaf8ff2019-12-13 14:53:09 +010098 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 Torvalds1da177e2005-04-16 15:20:36 -0700103 }
Simon Geis26a0a1042019-12-13 14:53:04 +0100104 dev_info(&dev->dev, "configured as a %d socket device.\n",
105 socket_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
107 if (!request_region(pci_resource_start(dev, 0), 2, "i82092aa")) {
108 ret = -EBUSY;
109 goto err_out_disable;
110 }
Simon Geis48398792019-12-13 14:53:06 +0100111
112 for (i = 0; i < socket_count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 sockets[i].card_state = 1; /* 1 = present but empty */
114 sockets[i].io_base = pci_resource_start(dev, 0);
Zheyu Mae39cdac2021-06-22 07:11:31 +0000115 sockets[i].dev = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 sockets[i].socket.features |= SS_CAP_PCCARD;
117 sockets[i].socket.map_size = 0x1000;
118 sockets[i].socket.irq_mask = 0;
119 sockets[i].socket.pci_irq = dev->irq;
Dominik Brodowski7a96e872010-03-13 17:42:39 +0100120 sockets[i].socket.cb_dev = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 sockets[i].socket.owner = THIS_MODULE;
122
123 sockets[i].number = i;
Simon Geis48398792019-12-13 14:53:06 +0100124
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 if (card_present(i)) {
126 sockets[i].card_state = 3;
Simon Geis26a0a1042019-12-13 14:53:04 +0100127 dev_dbg(&dev->dev, "slot %i is occupied\n", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 } else {
Simon Geis26a0a1042019-12-13 14:53:04 +0100129 dev_dbg(&dev->dev, "slot %i is vacant\n", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 }
131 }
Simon Geis48398792019-12-13 14:53:06 +0100132
Simon Geis152b4bb2019-12-13 14:53:11 +0100133 /* Now, specifiy that all interrupts are to be done as PCI interrupts
134 * bitmask, one bit per event, 1 = PCI interrupt, 0 = ISA interrupt
135 */
136 configbyte = 0xFF;
137
138 /* PCI Interrupt Routing Register */
139 pci_write_config_byte(dev, 0x50, configbyte);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
141 /* Register the interrupt handler */
Adam Zerella836e9492019-08-25 15:35:10 +1000142 dev_dbg(&dev->dev, "Requesting interrupt %i\n", dev->irq);
Simon Geis90886462019-12-13 14:53:10 +0100143 ret = request_irq(dev->irq, i82092aa_interrupt, IRQF_SHARED,
144 "i82092aa", i82092aa_interrupt);
145 if (ret) {
Simon Geis26a0a1042019-12-13 14:53:04 +0100146 dev_err(&dev->dev, "Failed to register IRQ %d, aborting\n",
147 dev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 goto err_out_free_res;
149 }
150
Simon Geis48398792019-12-13 14:53:06 +0100151 for (i = 0; i < socket_count; i++) {
Greg Kroah-Hartman87373312006-09-12 17:00:10 +0200152 sockets[i].socket.dev.parent = &dev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 sockets[i].socket.ops = &i82092aa_operations;
154 sockets[i].socket.resource_ops = &pccard_nonstatic_ops;
155 ret = pcmcia_register_socket(&sockets[i].socket);
Simon Geisae1f62c2019-12-13 14:53:07 +0100156 if (ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 goto err_out_free_sockets;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 }
159
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 return 0;
161
162err_out_free_sockets:
163 if (i) {
Simon Geisae1f62c2019-12-13 14:53:07 +0100164 for (i--; i >= 0; i--)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 pcmcia_unregister_socket(&sockets[i].socket);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 }
167 free_irq(dev->irq, i82092aa_interrupt);
168err_out_free_res:
169 release_region(pci_resource_start(dev, 0), 2);
170err_out_disable:
171 pci_disable_device(dev);
Simon Geis48398792019-12-13 14:53:06 +0100172 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173}
174
Bill Pembertone765a022012-11-19 13:26:05 -0500175static void i82092aa_pci_remove(struct pci_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176{
Dan Carpenter36c286d2012-12-14 18:01:08 +0300177 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 free_irq(dev->irq, i82092aa_interrupt);
180
Dan Carpenter36c286d2012-12-14 18:01:08 +0300181 for (i = 0; i < socket_count; i++)
182 pcmcia_unregister_socket(&sockets[i].socket);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183}
184
185static DEFINE_SPINLOCK(port_lock);
186
187/* basic value read/write functions */
188
189static unsigned char indirect_read(int socket, unsigned short reg)
190{
191 unsigned short int port;
192 unsigned char val;
193 unsigned long flags;
Simon Geis4ae66dd2019-12-13 14:53:08 +0100194
Simon Geis48398792019-12-13 14:53:06 +0100195 spin_lock_irqsave(&port_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 reg += socket * 0x40;
197 port = sockets[socket].io_base;
Simon Geis48398792019-12-13 14:53:06 +0100198 outb(reg, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 val = inb(port+1);
Simon Geis48398792019-12-13 14:53:06 +0100200 spin_unlock_irqrestore(&port_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 return val;
202}
203
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204static void indirect_write(int socket, unsigned short reg, unsigned char value)
205{
206 unsigned short int port;
207 unsigned long flags;
Simon Geis4ae66dd2019-12-13 14:53:08 +0100208
Simon Geis48398792019-12-13 14:53:06 +0100209 spin_lock_irqsave(&port_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 reg = reg + socket * 0x40;
Simon Geis48398792019-12-13 14:53:06 +0100211 port = sockets[socket].io_base;
212 outb(reg, port);
213 outb(value, port+1);
214 spin_unlock_irqrestore(&port_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215}
216
217static void indirect_setbit(int socket, unsigned short reg, unsigned char mask)
218{
219 unsigned short int port;
220 unsigned char val;
221 unsigned long flags;
Simon Geis4ae66dd2019-12-13 14:53:08 +0100222
Simon Geis48398792019-12-13 14:53:06 +0100223 spin_lock_irqsave(&port_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 reg = reg + socket * 0x40;
Simon Geis48398792019-12-13 14:53:06 +0100225 port = sockets[socket].io_base;
226 outb(reg, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 val = inb(port+1);
228 val |= mask;
Simon Geis48398792019-12-13 14:53:06 +0100229 outb(reg, port);
230 outb(val, port+1);
231 spin_unlock_irqrestore(&port_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232}
233
234
Simon Geis152b4bb2019-12-13 14:53:11 +0100235static void indirect_resetbit(int socket,
236 unsigned short reg, unsigned char mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237{
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
Simon Geis152b4bb2019-12-13 14:53:11 +0100253static void indirect_write16(int socket,
254 unsigned short reg, unsigned short value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255{
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
264 outb(reg, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 val = value & 255;
Simon Geis48398792019-12-13 14:53:06 +0100266 outb(val, port+1);
267
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 reg++;
Simon Geis48398792019-12-13 14:53:06 +0100269
270 outb(reg, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 val = value>>8;
Simon Geis48398792019-12-13 14:53:06 +0100272 outb(val, port+1);
273 spin_unlock_irqrestore(&port_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274}
275
276/* simple helper functions */
277/* External clock time, in nanoseconds. 120 ns = 8.33 MHz */
278static int cycle_time = 120;
279
280static int to_cycles(int ns)
281{
Simon Geis48398792019-12-13 14:53:06 +0100282 if (cycle_time != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 return ns/cycle_time;
284 else
285 return 0;
286}
Simon Geis48398792019-12-13 14:53:06 +0100287
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
289/* Interrupt handler functionality */
290
David Howells7d12e782006-10-05 14:55:46 +0100291static irqreturn_t i82092aa_interrupt(int irq, void *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292{
293 int i;
294 int loopcount = 0;
295 int handled = 0;
296
Simon Geis48398792019-12-13 14:53:06 +0100297 unsigned int events, active = 0;
298
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 while (1) {
300 loopcount++;
Simon Geis48398792019-12-13 14:53:06 +0100301 if (loopcount > 20) {
Simon Geis26a0a1042019-12-13 14:53:04 +0100302 pr_err("i82092aa: infinite eventloop in interrupt\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 break;
304 }
Simon Geis48398792019-12-13 14:53:06 +0100305
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 active = 0;
Simon Geis48398792019-12-13 14:53:06 +0100307
308 for (i = 0; i < socket_count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 int csc;
Simon Geis4ae66dd2019-12-13 14:53:08 +0100310
Simon Geis152b4bb2019-12-13 14:53:11 +0100311 /* Inactive socket, should not happen */
312 if (sockets[i].card_state == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 continue;
Simon Geis48398792019-12-13 14:53:06 +0100314
Simon Geis152b4bb2019-12-13 14:53:11 +0100315 /* card status change register */
316 csc = indirect_read(i, I365_CSC);
Simon Geis48398792019-12-13 14:53:06 +0100317
318 if (csc == 0) /* no events on this socket */
319 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 handled = 1;
321 events = 0;
Simon Geis48398792019-12-13 14:53:06 +0100322
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 if (csc & I365_CSC_DETECT) {
324 events |= SS_DETECT;
Simon Geis26a0a1042019-12-13 14:53:04 +0100325 dev_info(&sockets[i].dev->dev,
326 "Card detected in socket %i!\n", i);
Simon Geis48398792019-12-13 14:53:06 +0100327 }
328
329 if (indirect_read(i, I365_INTCTL) & I365_PC_IOCARD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 /* For IO/CARDS, bit 0 means "read the card" */
Simon Geis152b4bb2019-12-13 14:53:11 +0100331 if (csc & I365_CSC_STSCHG)
332 events |= SS_STSCHG;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 } else {
334 /* Check for battery/ready events */
Simon Geis152b4bb2019-12-13 14:53:11 +0100335 if (csc & I365_CSC_BVD1)
336 events |= SS_BATDEAD;
337 if (csc & I365_CSC_BVD2)
338 events |= SS_BATWARN;
339 if (csc & I365_CSC_READY)
340 events |= SS_READY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 }
Simon Geis48398792019-12-13 14:53:06 +0100342
Simon Geisae1f62c2019-12-13 14:53:07 +0100343 if (events)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 pcmcia_parse_events(&sockets[i].socket, events);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 active |= events;
346 }
Simon Geis48398792019-12-13 14:53:06 +0100347
348 if (active == 0) /* no more events to handle */
349 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 }
351 return IRQ_RETVAL(handled);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352}
353
354
355
356/* socket functions */
357
358static int card_present(int socketno)
Simon Geis48398792019-12-13 14:53:06 +0100359{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 unsigned int val;
Simon Geis4ae66dd2019-12-13 14:53:08 +0100361
Simon Geis48398792019-12-13 14:53:06 +0100362 if ((socketno < 0) || (socketno >= MAX_SOCKETS))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 return 0;
364 if (sockets[socketno].io_base == 0)
365 return 0;
366
Simon Geis48398792019-12-13 14:53:06 +0100367
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 val = indirect_read(socketno, 1); /* Interface status register */
Simon Geis52739f02019-12-13 14:53:13 +0100369 if ((val&12) == 12)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 return 1;
Simon Geis48398792019-12-13 14:53:06 +0100371
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 return 0;
373}
374
375static void set_bridge_state(int sock)
376{
Simon Geis48398792019-12-13 14:53:06 +0100377 indirect_write(sock, I365_GBLCTL, 0x00);
378 indirect_write(sock, I365_GENCTL, 0x00);
379
380 indirect_setbit(sock, I365_INTCTL, 0x08);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381}
382
383
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384static int i82092aa_init(struct pcmcia_socket *sock)
385{
386 int i;
387 struct resource res = { .start = 0, .end = 0x0fff };
Simon Geis48398792019-12-13 14:53:06 +0100388 pccard_io_map io = { 0, 0, 0, 0, 1 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 pccard_mem_map mem = { .res = &res, };
Simon Geis48398792019-12-13 14:53:06 +0100390
Simon Geis48398792019-12-13 14:53:06 +0100391 for (i = 0; i < 2; i++) {
392 io.map = i;
393 i82092aa_set_io_map(sock, &io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 }
Simon Geis48398792019-12-13 14:53:06 +0100395 for (i = 0; i < 5; i++) {
396 mem.map = i;
397 i82092aa_set_mem_map(sock, &mem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 }
Simon Geis52739f02019-12-13 14:53:13 +0100399
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 return 0;
401}
Simon Geis48398792019-12-13 14:53:06 +0100402
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403static int i82092aa_get_status(struct pcmcia_socket *socket, u_int *value)
404{
Simon Geis152b4bb2019-12-13 14:53:11 +0100405 unsigned int sock = container_of(socket,
406 struct socket_info, socket)->number;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 unsigned int status;
Simon Geis152b4bb2019-12-13 14:53:11 +0100408
409 /* Interface Status Register */
410 status = indirect_read(sock, I365_STATUS);
411
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 *value = 0;
Simon Geis48398792019-12-13 14:53:06 +0100413
Simon Geisae1f62c2019-12-13 14:53:07 +0100414 if ((status & I365_CS_DETECT) == I365_CS_DETECT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 *value |= SS_DETECT;
Simon Geis48398792019-12-13 14:53:06 +0100416
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 /* IO cards have a different meaning of bits 0,1 */
418 /* Also notice the inverse-logic on the bits */
Simon Geis48398792019-12-13 14:53:06 +0100419 if (indirect_read(sock, I365_INTCTL) & I365_PC_IOCARD) {
Colin Ian King84182fc2018-10-31 16:46:02 +0000420 /* IO card */
421 if (!(status & I365_CS_STSCHG))
422 *value |= SS_STSCHG;
423 } else { /* non I/O card */
424 if (!(status & I365_CS_BVD1))
425 *value |= SS_BATDEAD;
426 if (!(status & I365_CS_BVD2))
427 *value |= SS_BATWARN;
428 }
Simon Geis48398792019-12-13 14:53:06 +0100429
Colin Ian King84182fc2018-10-31 16:46:02 +0000430 if (status & I365_CS_WRPROT)
431 (*value) |= SS_WRPROT; /* card is write protected */
Simon Geis48398792019-12-13 14:53:06 +0100432
Colin Ian King84182fc2018-10-31 16:46:02 +0000433 if (status & I365_CS_READY)
434 (*value) |= SS_READY; /* card is not busy */
Simon Geis48398792019-12-13 14:53:06 +0100435
Colin Ian King84182fc2018-10-31 16:46:02 +0000436 if (status & I365_CS_POWERON)
437 (*value) |= SS_POWERON; /* power is applied to the card */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 return 0;
440}
441
442
Simon Geis152b4bb2019-12-13 14:53:11 +0100443static int i82092aa_set_socket(struct pcmcia_socket *socket,
444 socket_state_t *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445{
Simon Geis26a0a1042019-12-13 14:53:04 +0100446 struct socket_info *sock_info = container_of(socket, struct socket_info,
447 socket);
448 unsigned int sock = sock_info->number;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 unsigned char reg;
Simon Geis48398792019-12-13 14:53:06 +0100450
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 /* First, set the global controller options */
Simon Geis48398792019-12-13 14:53:06 +0100452
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 set_bridge_state(sock);
Simon Geis48398792019-12-13 14:53:06 +0100454
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 /* Values for the IGENC register */
Simon Geis48398792019-12-13 14:53:06 +0100456
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 reg = 0;
Simon Geis152b4bb2019-12-13 14:53:11 +0100458
459 /* The reset bit has "inverse" logic */
460 if (!(state->flags & SS_RESET))
Simon Geis48398792019-12-13 14:53:06 +0100461 reg = reg | I365_PC_RESET;
462 if (state->flags & SS_IOCARD)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 reg = reg | I365_PC_IOCARD;
Simon Geis48398792019-12-13 14:53:06 +0100464
Simon Geis152b4bb2019-12-13 14:53:11 +0100465 /* IGENC, Interrupt and General Control Register */
466 indirect_write(sock, I365_INTCTL, reg);
Simon Geis48398792019-12-13 14:53:06 +0100467
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 /* Power registers */
Simon Geis48398792019-12-13 14:53:06 +0100469
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 reg = I365_PWR_NORESET; /* default: disable resetdrv on resume */
Simon Geis48398792019-12-13 14:53:06 +0100471
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 if (state->flags & SS_PWR_AUTO) {
Simon Geis26a0a1042019-12-13 14:53:04 +0100473 dev_info(&sock_info->dev->dev, "Auto power\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 reg |= I365_PWR_AUTO; /* automatic power mngmnt */
475 }
476 if (state->flags & SS_OUTPUT_ENA) {
Simon Geis26a0a1042019-12-13 14:53:04 +0100477 dev_info(&sock_info->dev->dev, "Power Enabled\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 reg |= I365_PWR_OUT; /* enable power */
479 }
Simon Geis48398792019-12-13 14:53:06 +0100480
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 switch (state->Vcc) {
Simon Geis6aaf8ff2019-12-13 14:53:09 +0100482 case 0:
483 break;
484 case 50:
485 dev_info(&sock_info->dev->dev,
486 "setting voltage to Vcc to 5V on socket %i\n",
487 sock);
488 reg |= I365_VCC_5V;
489 break;
490 default:
491 dev_err(&sock_info->dev->dev,
492 "%s called with invalid VCC power value: %i",
493 __func__, state->Vcc);
Simon Geis6aaf8ff2019-12-13 14:53:09 +0100494 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 }
Simon Geis48398792019-12-13 14:53:06 +0100496
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 switch (state->Vpp) {
Simon Geis6aaf8ff2019-12-13 14:53:09 +0100498 case 0:
499 dev_info(&sock_info->dev->dev,
500 "not setting Vpp on socket %i\n", sock);
501 break;
502 case 50:
503 dev_info(&sock_info->dev->dev,
504 "setting Vpp to 5.0 for socket %i\n", sock);
505 reg |= I365_VPP1_5V | I365_VPP2_5V;
506 break;
507 case 120:
508 dev_info(&sock_info->dev->dev, "setting Vpp to 12.0\n");
509 reg |= I365_VPP1_12V | I365_VPP2_12V;
510 break;
511 default:
512 dev_err(&sock_info->dev->dev,
513 "%s called with invalid VPP power value: %i",
514 __func__, state->Vcc);
Simon Geis6aaf8ff2019-12-13 14:53:09 +0100515 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 }
Simon Geis48398792019-12-13 14:53:06 +0100517
518 if (reg != indirect_read(sock, I365_POWER)) /* only write if changed */
519 indirect_write(sock, I365_POWER, reg);
520
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 /* Enable specific interrupt events */
Simon Geis48398792019-12-13 14:53:06 +0100522
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 reg = 0x00;
Simon Geisae1f62c2019-12-13 14:53:07 +0100524 if (state->csc_mask & SS_DETECT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 reg |= I365_CSC_DETECT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 if (state->flags & SS_IOCARD) {
527 if (state->csc_mask & SS_STSCHG)
528 reg |= I365_CSC_STSCHG;
529 } else {
Simon Geis48398792019-12-13 14:53:06 +0100530 if (state->csc_mask & SS_BATDEAD)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 reg |= I365_CSC_BVD1;
Simon Geis48398792019-12-13 14:53:06 +0100532 if (state->csc_mask & SS_BATWARN)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 reg |= I365_CSC_BVD2;
Simon Geis48398792019-12-13 14:53:06 +0100534 if (state->csc_mask & SS_READY)
535 reg |= I365_CSC_READY;
536
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 }
Simon Geis48398792019-12-13 14:53:06 +0100538
Simon Geis152b4bb2019-12-13 14:53:11 +0100539 /* now write the value and clear the (probably bogus) pending stuff
540 * by doing a dummy read
541 */
Simon Geis48398792019-12-13 14:53:06 +0100542
543 indirect_write(sock, I365_CSCINT, reg);
544 (void)indirect_read(sock, I365_CSC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 return 0;
547}
548
Simon Geis152b4bb2019-12-13 14:53:11 +0100549static int i82092aa_set_io_map(struct pcmcia_socket *socket,
550 struct pccard_io_map *io)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551{
Simon Geis26a0a1042019-12-13 14:53:04 +0100552 struct socket_info *sock_info = container_of(socket, struct socket_info,
553 socket);
554 unsigned int sock = sock_info->number;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 unsigned char map, ioctl;
Simon Geis48398792019-12-13 14:53:06 +0100556
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 map = io->map;
Simon Geis48398792019-12-13 14:53:06 +0100558
559 /* Check error conditions */
Simon Geis52739f02019-12-13 14:53:13 +0100560 if (map > 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 return -EINVAL;
Simon Geis52739f02019-12-13 14:53:13 +0100562
Simon Geis152b4bb2019-12-13 14:53:11 +0100563 if ((io->start > 0xffff) || (io->stop > 0xffff)
Simon Geis52739f02019-12-13 14:53:13 +0100564 || (io->stop < io->start))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566
Simon Geis48398792019-12-13 14:53:06 +0100567 /* Turn off the window before changing anything */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 if (indirect_read(sock, I365_ADDRWIN) & I365_ENA_IO(map))
569 indirect_resetbit(sock, I365_ADDRWIN, I365_ENA_IO(map));
570
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 /* write the new values */
Simon Geis48398792019-12-13 14:53:06 +0100572 indirect_write16(sock, I365_IO(map)+I365_W_START, io->start);
573 indirect_write16(sock, I365_IO(map)+I365_W_STOP, io->stop);
574
575 ioctl = indirect_read(sock, I365_IOCTL) & ~I365_IOCTL_MASK(map);
576
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 if (io->flags & (MAP_16BIT|MAP_AUTOSZ))
578 ioctl |= I365_IOCTL_16BIT(map);
Simon Geis48398792019-12-13 14:53:06 +0100579
580 indirect_write(sock, I365_IOCTL, ioctl);
581
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 /* Turn the window back on if needed */
583 if (io->flags & MAP_ACTIVE)
Simon Geis48398792019-12-13 14:53:06 +0100584 indirect_setbit(sock, I365_ADDRWIN, I365_ENA_IO(map));
585
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 return 0;
587}
588
Simon Geis152b4bb2019-12-13 14:53:11 +0100589static int i82092aa_set_mem_map(struct pcmcia_socket *socket,
590 struct pccard_mem_map *mem)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591{
Simon Geis152b4bb2019-12-13 14:53:11 +0100592 struct socket_info *sock_info = container_of(socket, struct socket_info,
593 socket);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 unsigned int sock = sock_info->number;
595 struct pci_bus_region region;
596 unsigned short base, i;
597 unsigned char map;
Simon Geis48398792019-12-13 14:53:06 +0100598
Yinghai Lufc279852013-12-09 22:54:40 -0800599 pcibios_resource_to_bus(sock_info->dev->bus, &region, mem->res);
Simon Geis48398792019-12-13 14:53:06 +0100600
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 map = mem->map;
Simon Geis52739f02019-12-13 14:53:13 +0100602 if (map > 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 return -EINVAL;
Simon Geis48398792019-12-13 14:53:06 +0100604
605 if ((mem->card_start > 0x3ffffff) || (region.start > region.end) ||
606 (mem->speed > 1000)) {
Simon Geis26a0a1042019-12-13 14:53:04 +0100607 dev_err(&sock_info->dev->dev,
Simon Geis152b4bb2019-12-13 14:53:11 +0100608 "invalid mem map for socket %i: %llx to %llx with a start of %x\n",
Andrew Mortonf96ee7a2008-02-04 23:35:48 -0800609 sock,
610 (unsigned long long)region.start,
611 (unsigned long long)region.end,
612 mem->card_start);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 return -EINVAL;
614 }
Simon Geis48398792019-12-13 14:53:06 +0100615
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 /* Turn off the window before changing anything */
617 if (indirect_read(sock, I365_ADDRWIN) & I365_ENA_MEM(map))
Simon Geis48398792019-12-13 14:53:06 +0100618 indirect_resetbit(sock, I365_ADDRWIN, I365_ENA_MEM(map));
619
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 /* write the start address */
621 base = I365_MEM(map);
622 i = (region.start >> 12) & 0x0fff;
Simon Geis48398792019-12-13 14:53:06 +0100623 if (mem->flags & MAP_16BIT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 i |= I365_MEM_16BIT;
625 if (mem->flags & MAP_0WS)
Simon Geis48398792019-12-13 14:53:06 +0100626 i |= I365_MEM_0WS;
627 indirect_write16(sock, base+I365_W_START, i);
628
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 /* write the stop address */
Simon Geis48398792019-12-13 14:53:06 +0100630
631 i = (region.end >> 12) & 0x0fff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 switch (to_cycles(mem->speed)) {
Simon Geis6aaf8ff2019-12-13 14:53:09 +0100633 case 0:
634 break;
635 case 1:
636 i |= I365_MEM_WS0;
637 break;
638 case 2:
639 i |= I365_MEM_WS1;
640 break;
641 default:
642 i |= I365_MEM_WS1 | I365_MEM_WS0;
643 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 }
Simon Geis48398792019-12-13 14:53:06 +0100645
646 indirect_write16(sock, base+I365_W_STOP, i);
647
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 /* card start */
Simon Geis48398792019-12-13 14:53:06 +0100649
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 i = ((mem->card_start - region.start) >> 12) & 0x3fff;
651 if (mem->flags & MAP_WRPROT)
652 i |= I365_MEM_WRPROT;
Simon Geis26a0a1042019-12-13 14:53:04 +0100653 if (mem->flags & MAP_ATTRIB)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 i |= I365_MEM_REG;
Simon Geis48398792019-12-13 14:53:06 +0100655 indirect_write16(sock, base+I365_W_OFF, i);
656
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 /* Enable the window if necessary */
658 if (mem->flags & MAP_ACTIVE)
659 indirect_setbit(sock, I365_ADDRWIN, I365_ENA_MEM(map));
Simon Geis48398792019-12-13 14:53:06 +0100660
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 return 0;
662}
663
664static int i82092aa_module_init(void)
665{
Sam Ravnborgba66ddf2008-05-01 04:34:51 -0700666 return pci_register_driver(&i82092aa_pci_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667}
668
669static void i82092aa_module_exit(void)
670{
Sam Ravnborgba66ddf2008-05-01 04:34:51 -0700671 pci_unregister_driver(&i82092aa_pci_driver);
Simon Geis48398792019-12-13 14:53:06 +0100672 if (sockets[0].io_base > 0)
Simon Geis6aaf8ff2019-12-13 14:53:09 +0100673 release_region(sockets[0].io_base, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674}
675
676module_init(i82092aa_module_init);
677module_exit(i82092aa_module_exit);
678