blob: 85887d885b5f39054ba1459c903a84e21b79735c [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);
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 Brodowski7a96e872010-03-13 17:42:39 +0100119 sockets[i].socket.cb_dev = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 sockets[i].socket.owner = THIS_MODULE;
121
122 sockets[i].number = i;
Simon Geis48398792019-12-13 14:53:06 +0100123
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 if (card_present(i)) {
125 sockets[i].card_state = 3;
Simon Geis26a0a1042019-12-13 14:53:04 +0100126 dev_dbg(&dev->dev, "slot %i is occupied\n", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 } else {
Simon Geis26a0a1042019-12-13 14:53:04 +0100128 dev_dbg(&dev->dev, "slot %i is vacant\n", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 }
130 }
Simon Geis48398792019-12-13 14:53:06 +0100131
Simon Geis152b4bb2019-12-13 14:53:11 +0100132 /* 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 Torvalds1da177e2005-04-16 15:20:36 -0700139
140 /* Register the interrupt handler */
Adam Zerella836e9492019-08-25 15:35:10 +1000141 dev_dbg(&dev->dev, "Requesting interrupt %i\n", dev->irq);
Simon Geis90886462019-12-13 14:53:10 +0100142 ret = request_irq(dev->irq, i82092aa_interrupt, IRQF_SHARED,
143 "i82092aa", i82092aa_interrupt);
144 if (ret) {
Simon Geis26a0a1042019-12-13 14:53:04 +0100145 dev_err(&dev->dev, "Failed to register IRQ %d, aborting\n",
146 dev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 goto err_out_free_res;
148 }
149
Simon Geis48398792019-12-13 14:53:06 +0100150 for (i = 0; i < socket_count; i++) {
Greg Kroah-Hartman87373312006-09-12 17:00:10 +0200151 sockets[i].socket.dev.parent = &dev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 sockets[i].socket.ops = &i82092aa_operations;
153 sockets[i].socket.resource_ops = &pccard_nonstatic_ops;
154 ret = pcmcia_register_socket(&sockets[i].socket);
Simon Geisae1f62c2019-12-13 14:53:07 +0100155 if (ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 goto err_out_free_sockets;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 }
158
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 return 0;
160
161err_out_free_sockets:
162 if (i) {
Simon Geisae1f62c2019-12-13 14:53:07 +0100163 for (i--; i >= 0; i--)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 pcmcia_unregister_socket(&sockets[i].socket);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 }
166 free_irq(dev->irq, i82092aa_interrupt);
167err_out_free_res:
168 release_region(pci_resource_start(dev, 0), 2);
169err_out_disable:
170 pci_disable_device(dev);
Simon Geis48398792019-12-13 14:53:06 +0100171 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172}
173
Bill Pembertone765a022012-11-19 13:26:05 -0500174static void i82092aa_pci_remove(struct pci_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175{
Dan Carpenter36c286d2012-12-14 18:01:08 +0300176 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 free_irq(dev->irq, i82092aa_interrupt);
179
Dan Carpenter36c286d2012-12-14 18:01:08 +0300180 for (i = 0; i < socket_count; i++)
181 pcmcia_unregister_socket(&sockets[i].socket);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182}
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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203static void indirect_write(int socket, unsigned short reg, unsigned char value)
204{
205 unsigned short int port;
206 unsigned long flags;
Simon Geis4ae66dd2019-12-13 14:53:08 +0100207
Simon Geis48398792019-12-13 14:53:06 +0100208 spin_lock_irqsave(&port_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 reg = reg + socket * 0x40;
Simon Geis48398792019-12-13 14:53:06 +0100210 port = sockets[socket].io_base;
211 outb(reg, port);
212 outb(value, port+1);
213 spin_unlock_irqrestore(&port_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214}
215
216static void indirect_setbit(int socket, unsigned short reg, unsigned char mask)
217{
218 unsigned short int port;
219 unsigned char val;
220 unsigned long flags;
Simon Geis4ae66dd2019-12-13 14:53:08 +0100221
Simon Geis48398792019-12-13 14:53:06 +0100222 spin_lock_irqsave(&port_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 reg = reg + socket * 0x40;
Simon Geis48398792019-12-13 14:53:06 +0100224 port = sockets[socket].io_base;
225 outb(reg, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 val = inb(port+1);
227 val |= mask;
Simon Geis48398792019-12-13 14:53:06 +0100228 outb(reg, port);
229 outb(val, port+1);
230 spin_unlock_irqrestore(&port_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231}
232
233
Simon Geis152b4bb2019-12-13 14:53:11 +0100234static void indirect_resetbit(int socket,
235 unsigned short reg, unsigned char mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236{
237 unsigned short int port;
238 unsigned char val;
239 unsigned long flags;
Simon Geis4ae66dd2019-12-13 14:53:08 +0100240
Simon Geis48398792019-12-13 14:53:06 +0100241 spin_lock_irqsave(&port_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 reg = reg + socket * 0x40;
Simon Geis48398792019-12-13 14:53:06 +0100243 port = sockets[socket].io_base;
244 outb(reg, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 val = inb(port+1);
246 val &= ~mask;
Simon Geis48398792019-12-13 14:53:06 +0100247 outb(reg, port);
248 outb(val, port+1);
249 spin_unlock_irqrestore(&port_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250}
251
Simon Geis152b4bb2019-12-13 14:53:11 +0100252static void indirect_write16(int socket,
253 unsigned short reg, unsigned short value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254{
255 unsigned short int port;
256 unsigned char val;
257 unsigned long flags;
Simon Geis4ae66dd2019-12-13 14:53:08 +0100258
Simon Geis48398792019-12-13 14:53:06 +0100259 spin_lock_irqsave(&port_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 reg = reg + socket * 0x40;
Simon Geis48398792019-12-13 14:53:06 +0100261 port = sockets[socket].io_base;
262
263 outb(reg, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 val = value & 255;
Simon Geis48398792019-12-13 14:53:06 +0100265 outb(val, port+1);
266
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 reg++;
Simon Geis48398792019-12-13 14:53:06 +0100268
269 outb(reg, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 val = value>>8;
Simon Geis48398792019-12-13 14:53:06 +0100271 outb(val, port+1);
272 spin_unlock_irqrestore(&port_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273}
274
275/* simple helper functions */
276/* External clock time, in nanoseconds. 120 ns = 8.33 MHz */
277static int cycle_time = 120;
278
279static int to_cycles(int ns)
280{
Simon Geis48398792019-12-13 14:53:06 +0100281 if (cycle_time != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 return ns/cycle_time;
283 else
284 return 0;
285}
Simon Geis48398792019-12-13 14:53:06 +0100286
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
288/* Interrupt handler functionality */
289
David Howells7d12e782006-10-05 14:55:46 +0100290static irqreturn_t i82092aa_interrupt(int irq, void *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291{
292 int i;
293 int loopcount = 0;
294 int handled = 0;
295
Simon Geis48398792019-12-13 14:53:06 +0100296 unsigned int events, active = 0;
297
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 while (1) {
299 loopcount++;
Simon Geis48398792019-12-13 14:53:06 +0100300 if (loopcount > 20) {
Simon Geis26a0a1042019-12-13 14:53:04 +0100301 pr_err("i82092aa: infinite eventloop in interrupt\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 break;
303 }
Simon Geis48398792019-12-13 14:53:06 +0100304
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 active = 0;
Simon Geis48398792019-12-13 14:53:06 +0100306
307 for (i = 0; i < socket_count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 int csc;
Simon Geis4ae66dd2019-12-13 14:53:08 +0100309
Simon Geis152b4bb2019-12-13 14:53:11 +0100310 /* Inactive socket, should not happen */
311 if (sockets[i].card_state == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 continue;
Simon Geis48398792019-12-13 14:53:06 +0100313
Simon Geis152b4bb2019-12-13 14:53:11 +0100314 /* card status change register */
315 csc = indirect_read(i, I365_CSC);
Simon Geis48398792019-12-13 14:53:06 +0100316
317 if (csc == 0) /* no events on this socket */
318 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 handled = 1;
320 events = 0;
Simon Geis48398792019-12-13 14:53:06 +0100321
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 if (csc & I365_CSC_DETECT) {
323 events |= SS_DETECT;
Simon Geis26a0a1042019-12-13 14:53:04 +0100324 dev_info(&sockets[i].dev->dev,
325 "Card detected in socket %i!\n", i);
Simon Geis48398792019-12-13 14:53:06 +0100326 }
327
328 if (indirect_read(i, I365_INTCTL) & I365_PC_IOCARD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 /* For IO/CARDS, bit 0 means "read the card" */
Simon Geis152b4bb2019-12-13 14:53:11 +0100330 if (csc & I365_CSC_STSCHG)
331 events |= SS_STSCHG;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 } else {
333 /* Check for battery/ready events */
Simon Geis152b4bb2019-12-13 14:53:11 +0100334 if (csc & I365_CSC_BVD1)
335 events |= SS_BATDEAD;
336 if (csc & I365_CSC_BVD2)
337 events |= SS_BATWARN;
338 if (csc & I365_CSC_READY)
339 events |= SS_READY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 }
Simon Geis48398792019-12-13 14:53:06 +0100341
Simon Geisae1f62c2019-12-13 14:53:07 +0100342 if (events)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 pcmcia_parse_events(&sockets[i].socket, events);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 active |= events;
345 }
Simon Geis48398792019-12-13 14:53:06 +0100346
347 if (active == 0) /* no more events to handle */
348 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 }
350 return IRQ_RETVAL(handled);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351}
352
353
354
355/* socket functions */
356
357static int card_present(int socketno)
Simon Geis48398792019-12-13 14:53:06 +0100358{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 unsigned int val;
Simon Geis4ae66dd2019-12-13 14:53:08 +0100360
Simon Geis48398792019-12-13 14:53:06 +0100361 if ((socketno < 0) || (socketno >= MAX_SOCKETS))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 return 0;
363 if (sockets[socketno].io_base == 0)
364 return 0;
365
Simon Geis48398792019-12-13 14:53:06 +0100366
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 val = indirect_read(socketno, 1); /* Interface status register */
Simon Geis52739f02019-12-13 14:53:13 +0100368 if ((val&12) == 12)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 return 1;
Simon Geis48398792019-12-13 14:53:06 +0100370
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 return 0;
372}
373
374static void set_bridge_state(int sock)
375{
Simon Geis48398792019-12-13 14:53:06 +0100376 indirect_write(sock, I365_GBLCTL, 0x00);
377 indirect_write(sock, I365_GENCTL, 0x00);
378
379 indirect_setbit(sock, I365_INTCTL, 0x08);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380}
381
382
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383static int i82092aa_init(struct pcmcia_socket *sock)
384{
385 int i;
386 struct resource res = { .start = 0, .end = 0x0fff };
Simon Geis48398792019-12-13 14:53:06 +0100387 pccard_io_map io = { 0, 0, 0, 0, 1 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 pccard_mem_map mem = { .res = &res, };
Simon Geis48398792019-12-13 14:53:06 +0100389
Simon Geis48398792019-12-13 14:53:06 +0100390 for (i = 0; i < 2; i++) {
391 io.map = i;
392 i82092aa_set_io_map(sock, &io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 }
Simon Geis48398792019-12-13 14:53:06 +0100394 for (i = 0; i < 5; i++) {
395 mem.map = i;
396 i82092aa_set_mem_map(sock, &mem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 }
Simon Geis52739f02019-12-13 14:53:13 +0100398
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 return 0;
400}
Simon Geis48398792019-12-13 14:53:06 +0100401
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402static int i82092aa_get_status(struct pcmcia_socket *socket, u_int *value)
403{
Simon Geis152b4bb2019-12-13 14:53:11 +0100404 unsigned int sock = container_of(socket,
405 struct socket_info, socket)->number;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 unsigned int status;
Simon Geis152b4bb2019-12-13 14:53:11 +0100407
408 /* Interface Status Register */
409 status = indirect_read(sock, I365_STATUS);
410
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 *value = 0;
Simon Geis48398792019-12-13 14:53:06 +0100412
Simon Geisae1f62c2019-12-13 14:53:07 +0100413 if ((status & I365_CS_DETECT) == I365_CS_DETECT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 *value |= SS_DETECT;
Simon Geis48398792019-12-13 14:53:06 +0100415
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 /* IO cards have a different meaning of bits 0,1 */
417 /* Also notice the inverse-logic on the bits */
Simon Geis48398792019-12-13 14:53:06 +0100418 if (indirect_read(sock, I365_INTCTL) & I365_PC_IOCARD) {
Colin Ian King84182fc2018-10-31 16:46:02 +0000419 /* IO card */
420 if (!(status & I365_CS_STSCHG))
421 *value |= SS_STSCHG;
422 } else { /* non I/O card */
423 if (!(status & I365_CS_BVD1))
424 *value |= SS_BATDEAD;
425 if (!(status & I365_CS_BVD2))
426 *value |= SS_BATWARN;
427 }
Simon Geis48398792019-12-13 14:53:06 +0100428
Colin Ian King84182fc2018-10-31 16:46:02 +0000429 if (status & I365_CS_WRPROT)
430 (*value) |= SS_WRPROT; /* card is write protected */
Simon Geis48398792019-12-13 14:53:06 +0100431
Colin Ian King84182fc2018-10-31 16:46:02 +0000432 if (status & I365_CS_READY)
433 (*value) |= SS_READY; /* card is not busy */
Simon Geis48398792019-12-13 14:53:06 +0100434
Colin Ian King84182fc2018-10-31 16:46:02 +0000435 if (status & I365_CS_POWERON)
436 (*value) |= SS_POWERON; /* power is applied to the card */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 return 0;
439}
440
441
Simon Geis152b4bb2019-12-13 14:53:11 +0100442static int i82092aa_set_socket(struct pcmcia_socket *socket,
443 socket_state_t *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444{
Simon Geis26a0a1042019-12-13 14:53:04 +0100445 struct socket_info *sock_info = container_of(socket, struct socket_info,
446 socket);
447 unsigned int sock = sock_info->number;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 unsigned char reg;
Simon Geis48398792019-12-13 14:53:06 +0100449
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 /* First, set the global controller options */
Simon Geis48398792019-12-13 14:53:06 +0100451
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 set_bridge_state(sock);
Simon Geis48398792019-12-13 14:53:06 +0100453
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 /* Values for the IGENC register */
Simon Geis48398792019-12-13 14:53:06 +0100455
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 reg = 0;
Simon Geis152b4bb2019-12-13 14:53:11 +0100457
458 /* The reset bit has "inverse" logic */
459 if (!(state->flags & SS_RESET))
Simon Geis48398792019-12-13 14:53:06 +0100460 reg = reg | I365_PC_RESET;
461 if (state->flags & SS_IOCARD)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 reg = reg | I365_PC_IOCARD;
Simon Geis48398792019-12-13 14:53:06 +0100463
Simon Geis152b4bb2019-12-13 14:53:11 +0100464 /* IGENC, Interrupt and General Control Register */
465 indirect_write(sock, I365_INTCTL, reg);
Simon Geis48398792019-12-13 14:53:06 +0100466
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 /* Power registers */
Simon Geis48398792019-12-13 14:53:06 +0100468
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 reg = I365_PWR_NORESET; /* default: disable resetdrv on resume */
Simon Geis48398792019-12-13 14:53:06 +0100470
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 if (state->flags & SS_PWR_AUTO) {
Simon Geis26a0a1042019-12-13 14:53:04 +0100472 dev_info(&sock_info->dev->dev, "Auto power\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 reg |= I365_PWR_AUTO; /* automatic power mngmnt */
474 }
475 if (state->flags & SS_OUTPUT_ENA) {
Simon Geis26a0a1042019-12-13 14:53:04 +0100476 dev_info(&sock_info->dev->dev, "Power Enabled\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 reg |= I365_PWR_OUT; /* enable power */
478 }
Simon Geis48398792019-12-13 14:53:06 +0100479
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 switch (state->Vcc) {
Simon Geis6aaf8ff2019-12-13 14:53:09 +0100481 case 0:
482 break;
483 case 50:
484 dev_info(&sock_info->dev->dev,
485 "setting voltage to Vcc to 5V on socket %i\n",
486 sock);
487 reg |= I365_VCC_5V;
488 break;
489 default:
490 dev_err(&sock_info->dev->dev,
491 "%s called with invalid VCC power value: %i",
492 __func__, state->Vcc);
Simon Geis6aaf8ff2019-12-13 14:53:09 +0100493 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 }
Simon Geis48398792019-12-13 14:53:06 +0100495
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 switch (state->Vpp) {
Simon Geis6aaf8ff2019-12-13 14:53:09 +0100497 case 0:
498 dev_info(&sock_info->dev->dev,
499 "not setting Vpp on socket %i\n", sock);
500 break;
501 case 50:
502 dev_info(&sock_info->dev->dev,
503 "setting Vpp to 5.0 for socket %i\n", sock);
504 reg |= I365_VPP1_5V | I365_VPP2_5V;
505 break;
506 case 120:
507 dev_info(&sock_info->dev->dev, "setting Vpp to 12.0\n");
508 reg |= I365_VPP1_12V | I365_VPP2_12V;
509 break;
510 default:
511 dev_err(&sock_info->dev->dev,
512 "%s called with invalid VPP power value: %i",
513 __func__, state->Vcc);
Simon Geis6aaf8ff2019-12-13 14:53:09 +0100514 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 }
Simon Geis48398792019-12-13 14:53:06 +0100516
517 if (reg != indirect_read(sock, I365_POWER)) /* only write if changed */
518 indirect_write(sock, I365_POWER, reg);
519
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 /* Enable specific interrupt events */
Simon Geis48398792019-12-13 14:53:06 +0100521
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 reg = 0x00;
Simon Geisae1f62c2019-12-13 14:53:07 +0100523 if (state->csc_mask & SS_DETECT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 reg |= I365_CSC_DETECT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 if (state->flags & SS_IOCARD) {
526 if (state->csc_mask & SS_STSCHG)
527 reg |= I365_CSC_STSCHG;
528 } else {
Simon Geis48398792019-12-13 14:53:06 +0100529 if (state->csc_mask & SS_BATDEAD)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 reg |= I365_CSC_BVD1;
Simon Geis48398792019-12-13 14:53:06 +0100531 if (state->csc_mask & SS_BATWARN)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 reg |= I365_CSC_BVD2;
Simon Geis48398792019-12-13 14:53:06 +0100533 if (state->csc_mask & SS_READY)
534 reg |= I365_CSC_READY;
535
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 }
Simon Geis48398792019-12-13 14:53:06 +0100537
Simon Geis152b4bb2019-12-13 14:53:11 +0100538 /* now write the value and clear the (probably bogus) pending stuff
539 * by doing a dummy read
540 */
Simon Geis48398792019-12-13 14:53:06 +0100541
542 indirect_write(sock, I365_CSCINT, reg);
543 (void)indirect_read(sock, I365_CSC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 return 0;
546}
547
Simon Geis152b4bb2019-12-13 14:53:11 +0100548static int i82092aa_set_io_map(struct pcmcia_socket *socket,
549 struct pccard_io_map *io)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550{
Simon Geis26a0a1042019-12-13 14:53:04 +0100551 struct socket_info *sock_info = container_of(socket, struct socket_info,
552 socket);
553 unsigned int sock = sock_info->number;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 unsigned char map, ioctl;
Simon Geis48398792019-12-13 14:53:06 +0100555
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 map = io->map;
Simon Geis48398792019-12-13 14:53:06 +0100557
558 /* Check error conditions */
Simon Geis52739f02019-12-13 14:53:13 +0100559 if (map > 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 return -EINVAL;
Simon Geis52739f02019-12-13 14:53:13 +0100561
Simon Geis152b4bb2019-12-13 14:53:11 +0100562 if ((io->start > 0xffff) || (io->stop > 0xffff)
Simon Geis52739f02019-12-13 14:53:13 +0100563 || (io->stop < io->start))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565
Simon Geis48398792019-12-13 14:53:06 +0100566 /* Turn off the window before changing anything */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 if (indirect_read(sock, I365_ADDRWIN) & I365_ENA_IO(map))
568 indirect_resetbit(sock, I365_ADDRWIN, I365_ENA_IO(map));
569
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 /* write the new values */
Simon Geis48398792019-12-13 14:53:06 +0100571 indirect_write16(sock, I365_IO(map)+I365_W_START, io->start);
572 indirect_write16(sock, I365_IO(map)+I365_W_STOP, io->stop);
573
574 ioctl = indirect_read(sock, I365_IOCTL) & ~I365_IOCTL_MASK(map);
575
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 if (io->flags & (MAP_16BIT|MAP_AUTOSZ))
577 ioctl |= I365_IOCTL_16BIT(map);
Simon Geis48398792019-12-13 14:53:06 +0100578
579 indirect_write(sock, I365_IOCTL, ioctl);
580
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 /* Turn the window back on if needed */
582 if (io->flags & MAP_ACTIVE)
Simon Geis48398792019-12-13 14:53:06 +0100583 indirect_setbit(sock, I365_ADDRWIN, I365_ENA_IO(map));
584
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 return 0;
586}
587
Simon Geis152b4bb2019-12-13 14:53:11 +0100588static int i82092aa_set_mem_map(struct pcmcia_socket *socket,
589 struct pccard_mem_map *mem)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590{
Simon Geis152b4bb2019-12-13 14:53:11 +0100591 struct socket_info *sock_info = container_of(socket, struct socket_info,
592 socket);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 unsigned int sock = sock_info->number;
594 struct pci_bus_region region;
595 unsigned short base, i;
596 unsigned char map;
Simon Geis48398792019-12-13 14:53:06 +0100597
Yinghai Lufc279852013-12-09 22:54:40 -0800598 pcibios_resource_to_bus(sock_info->dev->bus, &region, mem->res);
Simon Geis48398792019-12-13 14:53:06 +0100599
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 map = mem->map;
Simon Geis52739f02019-12-13 14:53:13 +0100601 if (map > 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 return -EINVAL;
Simon Geis48398792019-12-13 14:53:06 +0100603
604 if ((mem->card_start > 0x3ffffff) || (region.start > region.end) ||
605 (mem->speed > 1000)) {
Simon Geis26a0a1042019-12-13 14:53:04 +0100606 dev_err(&sock_info->dev->dev,
Simon Geis152b4bb2019-12-13 14:53:11 +0100607 "invalid mem map for socket %i: %llx to %llx with a start of %x\n",
Andrew Mortonf96ee7a2008-02-04 23:35:48 -0800608 sock,
609 (unsigned long long)region.start,
610 (unsigned long long)region.end,
611 mem->card_start);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 return -EINVAL;
613 }
Simon Geis48398792019-12-13 14:53:06 +0100614
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 /* Turn off the window before changing anything */
616 if (indirect_read(sock, I365_ADDRWIN) & I365_ENA_MEM(map))
Simon Geis48398792019-12-13 14:53:06 +0100617 indirect_resetbit(sock, I365_ADDRWIN, I365_ENA_MEM(map));
618
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 /* write the start address */
620 base = I365_MEM(map);
621 i = (region.start >> 12) & 0x0fff;
Simon Geis48398792019-12-13 14:53:06 +0100622 if (mem->flags & MAP_16BIT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 i |= I365_MEM_16BIT;
624 if (mem->flags & MAP_0WS)
Simon Geis48398792019-12-13 14:53:06 +0100625 i |= I365_MEM_0WS;
626 indirect_write16(sock, base+I365_W_START, i);
627
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 /* write the stop address */
Simon Geis48398792019-12-13 14:53:06 +0100629
630 i = (region.end >> 12) & 0x0fff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 switch (to_cycles(mem->speed)) {
Simon Geis6aaf8ff2019-12-13 14:53:09 +0100632 case 0:
633 break;
634 case 1:
635 i |= I365_MEM_WS0;
636 break;
637 case 2:
638 i |= I365_MEM_WS1;
639 break;
640 default:
641 i |= I365_MEM_WS1 | I365_MEM_WS0;
642 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 }
Simon Geis48398792019-12-13 14:53:06 +0100644
645 indirect_write16(sock, base+I365_W_STOP, i);
646
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 /* card start */
Simon Geis48398792019-12-13 14:53:06 +0100648
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 i = ((mem->card_start - region.start) >> 12) & 0x3fff;
650 if (mem->flags & MAP_WRPROT)
651 i |= I365_MEM_WRPROT;
Simon Geis26a0a1042019-12-13 14:53:04 +0100652 if (mem->flags & MAP_ATTRIB)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 i |= I365_MEM_REG;
Simon Geis48398792019-12-13 14:53:06 +0100654 indirect_write16(sock, base+I365_W_OFF, i);
655
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 /* Enable the window if necessary */
657 if (mem->flags & MAP_ACTIVE)
658 indirect_setbit(sock, I365_ADDRWIN, I365_ENA_MEM(map));
Simon Geis48398792019-12-13 14:53:06 +0100659
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 return 0;
661}
662
663static int i82092aa_module_init(void)
664{
Sam Ravnborgba66ddf2008-05-01 04:34:51 -0700665 return pci_register_driver(&i82092aa_pci_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666}
667
668static void i82092aa_module_exit(void)
669{
Sam Ravnborgba66ddf2008-05-01 04:34:51 -0700670 pci_unregister_driver(&i82092aa_pci_driver);
Simon Geis48398792019-12-13 14:53:06 +0100671 if (sockets[0].io_base > 0)
Simon Geis6aaf8ff2019-12-13 14:53:09 +0100672 release_region(sockets[0].io_base, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673}
674
675module_init(i82092aa_module_init);
676module_exit(i82092aa_module_exit);
677