vrc4171_card.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  1. /*
  2. * vrc4171_card.c, NEC VRC4171 Card Controller driver for Socket Services.
  3. *
  4. * Copyright (C) 2003-2005 Yoichi Yuasa <yuasa@linux-mips.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #include <linux/init.h>
  21. #include <linux/ioport.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/module.h>
  24. #include <linux/spinlock.h>
  25. #include <linux/types.h>
  26. #include <linux/platform_device.h>
  27. #include <asm/io.h>
  28. #include <pcmcia/ss.h>
  29. #include "i82365.h"
  30. MODULE_DESCRIPTION("NEC VRC4171 Card Controllers driver for Socket Services");
  31. MODULE_AUTHOR("Yoichi Yuasa <yuasa@linux-mips.org>");
  32. MODULE_LICENSE("GPL");
  33. #define CARD_MAX_SLOTS 2
  34. #define CARD_SLOTA 0
  35. #define CARD_SLOTB 1
  36. #define CARD_SLOTB_OFFSET 0x40
  37. #define CARD_MEM_START 0x10000000
  38. #define CARD_MEM_END 0x13ffffff
  39. #define CARD_MAX_MEM_OFFSET 0x3ffffff
  40. #define CARD_MAX_MEM_SPEED 1000
  41. #define CARD_CONTROLLER_INDEX 0x03e0
  42. #define CARD_CONTROLLER_DATA 0x03e1
  43. /* Power register */
  44. #define VPP_GET_VCC 0x01
  45. #define POWER_ENABLE 0x10
  46. #define CARD_VOLTAGE_SENSE 0x1f
  47. #define VCC_3VORXV_CAPABLE 0x00
  48. #define VCC_XV_ONLY 0x01
  49. #define VCC_3V_CAPABLE 0x02
  50. #define VCC_5V_ONLY 0x03
  51. #define CARD_VOLTAGE_SELECT 0x2f
  52. #define VCC_3V 0x01
  53. #define VCC_5V 0x00
  54. #define VCC_XV 0x02
  55. #define VCC_STATUS_3V 0x02
  56. #define VCC_STATUS_5V 0x01
  57. #define VCC_STATUS_XV 0x03
  58. #define GLOBAL_CONTROL 0x1e
  59. #define EXWRBK 0x04
  60. #define IRQPM_EN 0x08
  61. #define CLRPMIRQ 0x10
  62. #define INTERRUPT_STATUS 0x05fa
  63. #define IRQ_A 0x02
  64. #define IRQ_B 0x04
  65. #define CONFIGURATION1 0x05fe
  66. #define SLOTB_CONFIG 0xc000
  67. #define SLOTB_NONE 0x0000
  68. #define SLOTB_PCCARD 0x4000
  69. #define SLOTB_CF 0x8000
  70. #define SLOTB_FLASHROM 0xc000
  71. #define CARD_CONTROLLER_START CARD_CONTROLLER_INDEX
  72. #define CARD_CONTROLLER_END CARD_CONTROLLER_DATA
  73. #define IO_MAX_MAPS 2
  74. #define MEM_MAX_MAPS 5
  75. typedef enum {
  76. SLOT_PROBE = 0,
  77. SLOT_NOPROBE_IO,
  78. SLOT_NOPROBE_MEM,
  79. SLOT_NOPROBE_ALL,
  80. SLOT_INITIALIZED,
  81. } vrc4171_slot_t;
  82. typedef enum {
  83. SLOTB_IS_NONE,
  84. SLOTB_IS_PCCARD,
  85. SLOTB_IS_CF,
  86. SLOTB_IS_FLASHROM,
  87. } vrc4171_slotb_t;
  88. typedef struct vrc4171_socket {
  89. vrc4171_slot_t slot;
  90. struct pcmcia_socket pcmcia_socket;
  91. char name[24];
  92. int csc_irq;
  93. int io_irq;
  94. spinlock_t lock;
  95. } vrc4171_socket_t;
  96. static vrc4171_socket_t vrc4171_sockets[CARD_MAX_SLOTS];
  97. static vrc4171_slotb_t vrc4171_slotb = SLOTB_IS_NONE;
  98. static char vrc4171_card_name[] = "NEC VRC4171 Card Controller";
  99. static unsigned int vrc4171_irq;
  100. static uint16_t vrc4171_irq_mask = 0xdeb8;
  101. static struct resource vrc4171_card_resource[3] = {
  102. { .name = vrc4171_card_name,
  103. .start = CARD_CONTROLLER_START,
  104. .end = CARD_CONTROLLER_END,
  105. .flags = IORESOURCE_IO, },
  106. { .name = vrc4171_card_name,
  107. .start = INTERRUPT_STATUS,
  108. .end = INTERRUPT_STATUS,
  109. .flags = IORESOURCE_IO, },
  110. { .name = vrc4171_card_name,
  111. .start = CONFIGURATION1,
  112. .end = CONFIGURATION1,
  113. .flags = IORESOURCE_IO, },
  114. };
  115. static struct platform_device vrc4171_card_device = {
  116. .name = vrc4171_card_name,
  117. .id = 0,
  118. .num_resources = 3,
  119. .resource = vrc4171_card_resource,
  120. };
  121. static inline uint16_t vrc4171_get_irq_status(void)
  122. {
  123. return inw(INTERRUPT_STATUS);
  124. }
  125. static inline void vrc4171_set_multifunction_pin(vrc4171_slotb_t config)
  126. {
  127. uint16_t config1;
  128. config1 = inw(CONFIGURATION1);
  129. config1 &= ~SLOTB_CONFIG;
  130. switch (config) {
  131. case SLOTB_IS_NONE:
  132. config1 |= SLOTB_NONE;
  133. break;
  134. case SLOTB_IS_PCCARD:
  135. config1 |= SLOTB_PCCARD;
  136. break;
  137. case SLOTB_IS_CF:
  138. config1 |= SLOTB_CF;
  139. break;
  140. case SLOTB_IS_FLASHROM:
  141. config1 |= SLOTB_FLASHROM;
  142. break;
  143. default:
  144. break;
  145. }
  146. outw(config1, CONFIGURATION1);
  147. }
  148. static inline uint8_t exca_read_byte(int slot, uint8_t index)
  149. {
  150. if (slot == CARD_SLOTB)
  151. index += CARD_SLOTB_OFFSET;
  152. outb(index, CARD_CONTROLLER_INDEX);
  153. return inb(CARD_CONTROLLER_DATA);
  154. }
  155. static inline uint16_t exca_read_word(int slot, uint8_t index)
  156. {
  157. uint16_t data;
  158. if (slot == CARD_SLOTB)
  159. index += CARD_SLOTB_OFFSET;
  160. outb(index++, CARD_CONTROLLER_INDEX);
  161. data = inb(CARD_CONTROLLER_DATA);
  162. outb(index, CARD_CONTROLLER_INDEX);
  163. data |= ((uint16_t)inb(CARD_CONTROLLER_DATA)) << 8;
  164. return data;
  165. }
  166. static inline uint8_t exca_write_byte(int slot, uint8_t index, uint8_t data)
  167. {
  168. if (slot == CARD_SLOTB)
  169. index += CARD_SLOTB_OFFSET;
  170. outb(index, CARD_CONTROLLER_INDEX);
  171. outb(data, CARD_CONTROLLER_DATA);
  172. return data;
  173. }
  174. static inline uint16_t exca_write_word(int slot, uint8_t index, uint16_t data)
  175. {
  176. if (slot == CARD_SLOTB)
  177. index += CARD_SLOTB_OFFSET;
  178. outb(index++, CARD_CONTROLLER_INDEX);
  179. outb(data, CARD_CONTROLLER_DATA);
  180. outb(index, CARD_CONTROLLER_INDEX);
  181. outb((uint8_t)(data >> 8), CARD_CONTROLLER_DATA);
  182. return data;
  183. }
  184. static inline int search_nonuse_irq(void)
  185. {
  186. int i;
  187. for (i = 0; i < 16; i++) {
  188. if (vrc4171_irq_mask & (1 << i)) {
  189. vrc4171_irq_mask &= ~(1 << i);
  190. return i;
  191. }
  192. }
  193. return -1;
  194. }
  195. static int pccard_init(struct pcmcia_socket *sock)
  196. {
  197. vrc4171_socket_t *socket;
  198. unsigned int slot;
  199. sock->features |= SS_CAP_PCCARD | SS_CAP_PAGE_REGS;
  200. sock->irq_mask = 0;
  201. sock->map_size = 0x1000;
  202. sock->pci_irq = vrc4171_irq;
  203. slot = sock->sock;
  204. socket = &vrc4171_sockets[slot];
  205. socket->csc_irq = search_nonuse_irq();
  206. socket->io_irq = search_nonuse_irq();
  207. return 0;
  208. }
  209. static int pccard_get_status(struct pcmcia_socket *sock, u_int *value)
  210. {
  211. unsigned int slot;
  212. uint8_t status, sense;
  213. u_int val = 0;
  214. if (sock == NULL || sock->sock >= CARD_MAX_SLOTS || value == NULL)
  215. return -EINVAL;
  216. slot = sock->sock;
  217. status = exca_read_byte(slot, I365_STATUS);
  218. if (exca_read_byte(slot, I365_INTCTL) & I365_PC_IOCARD) {
  219. if (status & I365_CS_STSCHG)
  220. val |= SS_STSCHG;
  221. } else {
  222. if (!(status & I365_CS_BVD1))
  223. val |= SS_BATDEAD;
  224. else if ((status & (I365_CS_BVD1 | I365_CS_BVD2)) == I365_CS_BVD1)
  225. val |= SS_BATWARN;
  226. }
  227. if ((status & I365_CS_DETECT) == I365_CS_DETECT)
  228. val |= SS_DETECT;
  229. if (status & I365_CS_WRPROT)
  230. val |= SS_WRPROT;
  231. if (status & I365_CS_READY)
  232. val |= SS_READY;
  233. if (status & I365_CS_POWERON)
  234. val |= SS_POWERON;
  235. sense = exca_read_byte(slot, CARD_VOLTAGE_SENSE);
  236. switch (sense) {
  237. case VCC_3VORXV_CAPABLE:
  238. val |= SS_3VCARD | SS_XVCARD;
  239. break;
  240. case VCC_XV_ONLY:
  241. val |= SS_XVCARD;
  242. break;
  243. case VCC_3V_CAPABLE:
  244. val |= SS_3VCARD;
  245. break;
  246. default:
  247. /* 5V only */
  248. break;
  249. }
  250. *value = val;
  251. return 0;
  252. }
  253. static inline uint8_t set_Vcc_value(u_char Vcc)
  254. {
  255. switch (Vcc) {
  256. case 33:
  257. return VCC_3V;
  258. case 50:
  259. return VCC_5V;
  260. }
  261. /* Small voltage is chosen for safety. */
  262. return VCC_3V;
  263. }
  264. static int pccard_set_socket(struct pcmcia_socket *sock, socket_state_t *state)
  265. {
  266. vrc4171_socket_t *socket;
  267. unsigned int slot;
  268. uint8_t voltage, power, control, cscint;
  269. if (sock == NULL || sock->sock >= CARD_MAX_SLOTS ||
  270. (state->Vpp != state->Vcc && state->Vpp != 0) ||
  271. (state->Vcc != 50 && state->Vcc != 33 && state->Vcc != 0))
  272. return -EINVAL;
  273. slot = sock->sock;
  274. socket = &vrc4171_sockets[slot];
  275. spin_lock_irq(&socket->lock);
  276. voltage = set_Vcc_value(state->Vcc);
  277. exca_write_byte(slot, CARD_VOLTAGE_SELECT, voltage);
  278. power = POWER_ENABLE;
  279. if (state->Vpp == state->Vcc)
  280. power |= VPP_GET_VCC;
  281. if (state->flags & SS_OUTPUT_ENA)
  282. power |= I365_PWR_OUT;
  283. exca_write_byte(slot, I365_POWER, power);
  284. control = 0;
  285. if (state->io_irq != 0)
  286. control |= socket->io_irq;
  287. if (state->flags & SS_IOCARD)
  288. control |= I365_PC_IOCARD;
  289. if (state->flags & SS_RESET)
  290. control &= ~I365_PC_RESET;
  291. else
  292. control |= I365_PC_RESET;
  293. exca_write_byte(slot, I365_INTCTL, control);
  294. cscint = 0;
  295. exca_write_byte(slot, I365_CSCINT, cscint);
  296. exca_read_byte(slot, I365_CSC); /* clear CardStatus change */
  297. if (state->csc_mask != 0)
  298. cscint |= socket->csc_irq << 8;
  299. if (state->flags & SS_IOCARD) {
  300. if (state->csc_mask & SS_STSCHG)
  301. cscint |= I365_CSC_STSCHG;
  302. } else {
  303. if (state->csc_mask & SS_BATDEAD)
  304. cscint |= I365_CSC_BVD1;
  305. if (state->csc_mask & SS_BATWARN)
  306. cscint |= I365_CSC_BVD2;
  307. }
  308. if (state->csc_mask & SS_READY)
  309. cscint |= I365_CSC_READY;
  310. if (state->csc_mask & SS_DETECT)
  311. cscint |= I365_CSC_DETECT;
  312. exca_write_byte(slot, I365_CSCINT, cscint);
  313. spin_unlock_irq(&socket->lock);
  314. return 0;
  315. }
  316. static int pccard_set_io_map(struct pcmcia_socket *sock, struct pccard_io_map *io)
  317. {
  318. unsigned int slot;
  319. uint8_t ioctl, addrwin;
  320. u_char map;
  321. if (sock == NULL || sock->sock >= CARD_MAX_SLOTS ||
  322. io == NULL || io->map >= IO_MAX_MAPS ||
  323. io->start > 0xffff || io->stop > 0xffff || io->start > io->stop)
  324. return -EINVAL;
  325. slot = sock->sock;
  326. map = io->map;
  327. addrwin = exca_read_byte(slot, I365_ADDRWIN);
  328. if (addrwin & I365_ENA_IO(map)) {
  329. addrwin &= ~I365_ENA_IO(map);
  330. exca_write_byte(slot, I365_ADDRWIN, addrwin);
  331. }
  332. exca_write_word(slot, I365_IO(map)+I365_W_START, io->start);
  333. exca_write_word(slot, I365_IO(map)+I365_W_STOP, io->stop);
  334. ioctl = 0;
  335. if (io->speed > 0)
  336. ioctl |= I365_IOCTL_WAIT(map);
  337. if (io->flags & MAP_16BIT)
  338. ioctl |= I365_IOCTL_16BIT(map);
  339. if (io->flags & MAP_AUTOSZ)
  340. ioctl |= I365_IOCTL_IOCS16(map);
  341. if (io->flags & MAP_0WS)
  342. ioctl |= I365_IOCTL_0WS(map);
  343. exca_write_byte(slot, I365_IOCTL, ioctl);
  344. if (io->flags & MAP_ACTIVE) {
  345. addrwin |= I365_ENA_IO(map);
  346. exca_write_byte(slot, I365_ADDRWIN, addrwin);
  347. }
  348. return 0;
  349. }
  350. static int pccard_set_mem_map(struct pcmcia_socket *sock, struct pccard_mem_map *mem)
  351. {
  352. unsigned int slot;
  353. uint16_t start, stop, offset;
  354. uint8_t addrwin;
  355. u_char map;
  356. if (sock == NULL || sock->sock >= CARD_MAX_SLOTS ||
  357. mem == NULL || mem->map >= MEM_MAX_MAPS ||
  358. mem->res->start < CARD_MEM_START || mem->res->start > CARD_MEM_END ||
  359. mem->res->end < CARD_MEM_START || mem->res->end > CARD_MEM_END ||
  360. mem->res->start > mem->res->end ||
  361. mem->card_start > CARD_MAX_MEM_OFFSET ||
  362. mem->speed > CARD_MAX_MEM_SPEED)
  363. return -EINVAL;
  364. slot = sock->sock;
  365. map = mem->map;
  366. addrwin = exca_read_byte(slot, I365_ADDRWIN);
  367. if (addrwin & I365_ENA_MEM(map)) {
  368. addrwin &= ~I365_ENA_MEM(map);
  369. exca_write_byte(slot, I365_ADDRWIN, addrwin);
  370. }
  371. start = (mem->res->start >> 12) & 0x3fff;
  372. if (mem->flags & MAP_16BIT)
  373. start |= I365_MEM_16BIT;
  374. exca_write_word(slot, I365_MEM(map)+I365_W_START, start);
  375. stop = (mem->res->end >> 12) & 0x3fff;
  376. switch (mem->speed) {
  377. case 0:
  378. break;
  379. case 1:
  380. stop |= I365_MEM_WS0;
  381. break;
  382. case 2:
  383. stop |= I365_MEM_WS1;
  384. break;
  385. default:
  386. stop |= I365_MEM_WS0 | I365_MEM_WS1;
  387. break;
  388. }
  389. exca_write_word(slot, I365_MEM(map)+I365_W_STOP, stop);
  390. offset = (mem->card_start >> 12) & 0x3fff;
  391. if (mem->flags & MAP_ATTRIB)
  392. offset |= I365_MEM_REG;
  393. if (mem->flags & MAP_WRPROT)
  394. offset |= I365_MEM_WRPROT;
  395. exca_write_word(slot, I365_MEM(map)+I365_W_OFF, offset);
  396. if (mem->flags & MAP_ACTIVE) {
  397. addrwin |= I365_ENA_MEM(map);
  398. exca_write_byte(slot, I365_ADDRWIN, addrwin);
  399. }
  400. return 0;
  401. }
  402. static struct pccard_operations vrc4171_pccard_operations = {
  403. .init = pccard_init,
  404. .get_status = pccard_get_status,
  405. .set_socket = pccard_set_socket,
  406. .set_io_map = pccard_set_io_map,
  407. .set_mem_map = pccard_set_mem_map,
  408. };
  409. static inline unsigned int get_events(int slot)
  410. {
  411. unsigned int events = 0;
  412. uint8_t status, csc;
  413. status = exca_read_byte(slot, I365_STATUS);
  414. csc = exca_read_byte(slot, I365_CSC);
  415. if (exca_read_byte(slot, I365_INTCTL) & I365_PC_IOCARD) {
  416. if ((csc & I365_CSC_STSCHG) && (status & I365_CS_STSCHG))
  417. events |= SS_STSCHG;
  418. } else {
  419. if (csc & (I365_CSC_BVD1 | I365_CSC_BVD2)) {
  420. if (!(status & I365_CS_BVD1))
  421. events |= SS_BATDEAD;
  422. else if ((status & (I365_CS_BVD1 | I365_CS_BVD2)) == I365_CS_BVD1)
  423. events |= SS_BATWARN;
  424. }
  425. }
  426. if ((csc & I365_CSC_READY) && (status & I365_CS_READY))
  427. events |= SS_READY;
  428. if ((csc & I365_CSC_DETECT) && ((status & I365_CS_DETECT) == I365_CS_DETECT))
  429. events |= SS_DETECT;
  430. return events;
  431. }
  432. static irqreturn_t pccard_interrupt(int irq, void *dev_id)
  433. {
  434. vrc4171_socket_t *socket;
  435. unsigned int events;
  436. irqreturn_t retval = IRQ_NONE;
  437. uint16_t status;
  438. status = vrc4171_get_irq_status();
  439. if (status & IRQ_A) {
  440. socket = &vrc4171_sockets[CARD_SLOTA];
  441. if (socket->slot == SLOT_INITIALIZED) {
  442. if (status & (1 << socket->csc_irq)) {
  443. events = get_events(CARD_SLOTA);
  444. if (events != 0) {
  445. pcmcia_parse_events(&socket->pcmcia_socket, events);
  446. retval = IRQ_HANDLED;
  447. }
  448. }
  449. }
  450. }
  451. if (status & IRQ_B) {
  452. socket = &vrc4171_sockets[CARD_SLOTB];
  453. if (socket->slot == SLOT_INITIALIZED) {
  454. if (status & (1 << socket->csc_irq)) {
  455. events = get_events(CARD_SLOTB);
  456. if (events != 0) {
  457. pcmcia_parse_events(&socket->pcmcia_socket, events);
  458. retval = IRQ_HANDLED;
  459. }
  460. }
  461. }
  462. }
  463. return retval;
  464. }
  465. static inline void reserve_using_irq(int slot)
  466. {
  467. unsigned int irq;
  468. irq = exca_read_byte(slot, I365_INTCTL);
  469. irq &= 0x0f;
  470. vrc4171_irq_mask &= ~(1 << irq);
  471. irq = exca_read_byte(slot, I365_CSCINT);
  472. irq = (irq & 0xf0) >> 4;
  473. vrc4171_irq_mask &= ~(1 << irq);
  474. }
  475. static int __devinit vrc4171_add_sockets(void)
  476. {
  477. vrc4171_socket_t *socket;
  478. int slot, retval;
  479. for (slot = 0; slot < CARD_MAX_SLOTS; slot++) {
  480. if (slot == CARD_SLOTB && vrc4171_slotb == SLOTB_IS_NONE)
  481. continue;
  482. socket = &vrc4171_sockets[slot];
  483. if (socket->slot != SLOT_PROBE) {
  484. uint8_t addrwin;
  485. switch (socket->slot) {
  486. case SLOT_NOPROBE_MEM:
  487. addrwin = exca_read_byte(slot, I365_ADDRWIN);
  488. addrwin &= 0x1f;
  489. exca_write_byte(slot, I365_ADDRWIN, addrwin);
  490. break;
  491. case SLOT_NOPROBE_IO:
  492. addrwin = exca_read_byte(slot, I365_ADDRWIN);
  493. addrwin &= 0xc0;
  494. exca_write_byte(slot, I365_ADDRWIN, addrwin);
  495. break;
  496. default:
  497. break;
  498. }
  499. reserve_using_irq(slot);
  500. continue;
  501. }
  502. sprintf(socket->name, "NEC VRC4171 Card Slot %1c", 'A' + slot);
  503. socket->pcmcia_socket.dev.parent = &vrc4171_card_device.dev;
  504. socket->pcmcia_socket.ops = &vrc4171_pccard_operations;
  505. socket->pcmcia_socket.owner = THIS_MODULE;
  506. retval = pcmcia_register_socket(&socket->pcmcia_socket);
  507. if (retval < 0)
  508. return retval;
  509. exca_write_byte(slot, I365_ADDRWIN, 0);
  510. exca_write_byte(slot, GLOBAL_CONTROL, 0);
  511. socket->slot = SLOT_INITIALIZED;
  512. }
  513. return 0;
  514. }
  515. static void vrc4171_remove_sockets(void)
  516. {
  517. vrc4171_socket_t *socket;
  518. int slot;
  519. for (slot = 0; slot < CARD_MAX_SLOTS; slot++) {
  520. if (slot == CARD_SLOTB && vrc4171_slotb == SLOTB_IS_NONE)
  521. continue;
  522. socket = &vrc4171_sockets[slot];
  523. if (socket->slot == SLOT_INITIALIZED)
  524. pcmcia_unregister_socket(&socket->pcmcia_socket);
  525. socket->slot = SLOT_PROBE;
  526. }
  527. }
  528. static int __devinit vrc4171_card_setup(char *options)
  529. {
  530. if (options == NULL || *options == '\0')
  531. return 1;
  532. if (strncmp(options, "irq:", 4) == 0) {
  533. int irq;
  534. options += 4;
  535. irq = simple_strtoul(options, &options, 0);
  536. if (irq >= 0 && irq < nr_irqs)
  537. vrc4171_irq = irq;
  538. if (*options != ',')
  539. return 1;
  540. options++;
  541. }
  542. if (strncmp(options, "slota:", 6) == 0) {
  543. options += 6;
  544. if (*options != '\0') {
  545. if (strncmp(options, "memnoprobe", 10) == 0) {
  546. vrc4171_sockets[CARD_SLOTA].slot = SLOT_NOPROBE_MEM;
  547. options += 10;
  548. } else if (strncmp(options, "ionoprobe", 9) == 0) {
  549. vrc4171_sockets[CARD_SLOTA].slot = SLOT_NOPROBE_IO;
  550. options += 9;
  551. } else if ( strncmp(options, "noprobe", 7) == 0) {
  552. vrc4171_sockets[CARD_SLOTA].slot = SLOT_NOPROBE_ALL;
  553. options += 7;
  554. }
  555. if (*options != ',')
  556. return 1;
  557. options++;
  558. } else
  559. return 1;
  560. }
  561. if (strncmp(options, "slotb:", 6) == 0) {
  562. options += 6;
  563. if (*options != '\0') {
  564. if (strncmp(options, "pccard", 6) == 0) {
  565. vrc4171_slotb = SLOTB_IS_PCCARD;
  566. options += 6;
  567. } else if (strncmp(options, "cf", 2) == 0) {
  568. vrc4171_slotb = SLOTB_IS_CF;
  569. options += 2;
  570. } else if (strncmp(options, "flashrom", 8) == 0) {
  571. vrc4171_slotb = SLOTB_IS_FLASHROM;
  572. options += 8;
  573. } else if (strncmp(options, "none", 4) == 0) {
  574. vrc4171_slotb = SLOTB_IS_NONE;
  575. options += 4;
  576. }
  577. if (*options != ',')
  578. return 1;
  579. options++;
  580. if (strncmp(options, "memnoprobe", 10) == 0)
  581. vrc4171_sockets[CARD_SLOTB].slot = SLOT_NOPROBE_MEM;
  582. if (strncmp(options, "ionoprobe", 9) == 0)
  583. vrc4171_sockets[CARD_SLOTB].slot = SLOT_NOPROBE_IO;
  584. if (strncmp(options, "noprobe", 7) == 0)
  585. vrc4171_sockets[CARD_SLOTB].slot = SLOT_NOPROBE_ALL;
  586. }
  587. }
  588. return 1;
  589. }
  590. __setup("vrc4171_card=", vrc4171_card_setup);
  591. static struct platform_driver vrc4171_card_driver = {
  592. .driver = {
  593. .name = vrc4171_card_name,
  594. .owner = THIS_MODULE,
  595. },
  596. };
  597. static int __devinit vrc4171_card_init(void)
  598. {
  599. int retval;
  600. retval = platform_driver_register(&vrc4171_card_driver);
  601. if (retval < 0)
  602. return retval;
  603. retval = platform_device_register(&vrc4171_card_device);
  604. if (retval < 0) {
  605. platform_driver_unregister(&vrc4171_card_driver);
  606. return retval;
  607. }
  608. vrc4171_set_multifunction_pin(vrc4171_slotb);
  609. retval = vrc4171_add_sockets();
  610. if (retval == 0)
  611. retval = request_irq(vrc4171_irq, pccard_interrupt, IRQF_SHARED,
  612. vrc4171_card_name, vrc4171_sockets);
  613. if (retval < 0) {
  614. vrc4171_remove_sockets();
  615. platform_device_unregister(&vrc4171_card_device);
  616. platform_driver_unregister(&vrc4171_card_driver);
  617. return retval;
  618. }
  619. printk(KERN_INFO "%s, connected to IRQ %d\n",
  620. vrc4171_card_driver.driver.name, vrc4171_irq);
  621. return 0;
  622. }
  623. static void __devexit vrc4171_card_exit(void)
  624. {
  625. free_irq(vrc4171_irq, vrc4171_sockets);
  626. vrc4171_remove_sockets();
  627. platform_device_unregister(&vrc4171_card_device);
  628. platform_driver_unregister(&vrc4171_card_driver);
  629. }
  630. module_init(vrc4171_card_init);
  631. module_exit(vrc4171_card_exit);