icside.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835
  1. /*
  2. * linux/drivers/ide/arm/icside.c
  3. *
  4. * Copyright (c) 1996-2004 Russell King.
  5. *
  6. * Please note that this platform does not support 32-bit IDE IO.
  7. */
  8. #include <linux/string.h>
  9. #include <linux/module.h>
  10. #include <linux/ioport.h>
  11. #include <linux/slab.h>
  12. #include <linux/blkdev.h>
  13. #include <linux/errno.h>
  14. #include <linux/hdreg.h>
  15. #include <linux/ide.h>
  16. #include <linux/dma-mapping.h>
  17. #include <linux/device.h>
  18. #include <linux/init.h>
  19. #include <linux/scatterlist.h>
  20. #include <linux/io.h>
  21. #include <asm/dma.h>
  22. #include <asm/ecard.h>
  23. #define ICS_IDENT_OFFSET 0x2280
  24. #define ICS_ARCIN_V5_INTRSTAT 0x0000
  25. #define ICS_ARCIN_V5_INTROFFSET 0x0004
  26. #define ICS_ARCIN_V5_IDEOFFSET 0x2800
  27. #define ICS_ARCIN_V5_IDEALTOFFSET 0x2b80
  28. #define ICS_ARCIN_V5_IDESTEPPING 6
  29. #define ICS_ARCIN_V6_IDEOFFSET_1 0x2000
  30. #define ICS_ARCIN_V6_INTROFFSET_1 0x2200
  31. #define ICS_ARCIN_V6_INTRSTAT_1 0x2290
  32. #define ICS_ARCIN_V6_IDEALTOFFSET_1 0x2380
  33. #define ICS_ARCIN_V6_IDEOFFSET_2 0x3000
  34. #define ICS_ARCIN_V6_INTROFFSET_2 0x3200
  35. #define ICS_ARCIN_V6_INTRSTAT_2 0x3290
  36. #define ICS_ARCIN_V6_IDEALTOFFSET_2 0x3380
  37. #define ICS_ARCIN_V6_IDESTEPPING 6
  38. struct cardinfo {
  39. unsigned int dataoffset;
  40. unsigned int ctrloffset;
  41. unsigned int stepping;
  42. };
  43. static struct cardinfo icside_cardinfo_v5 = {
  44. .dataoffset = ICS_ARCIN_V5_IDEOFFSET,
  45. .ctrloffset = ICS_ARCIN_V5_IDEALTOFFSET,
  46. .stepping = ICS_ARCIN_V5_IDESTEPPING,
  47. };
  48. static struct cardinfo icside_cardinfo_v6_1 = {
  49. .dataoffset = ICS_ARCIN_V6_IDEOFFSET_1,
  50. .ctrloffset = ICS_ARCIN_V6_IDEALTOFFSET_1,
  51. .stepping = ICS_ARCIN_V6_IDESTEPPING,
  52. };
  53. static struct cardinfo icside_cardinfo_v6_2 = {
  54. .dataoffset = ICS_ARCIN_V6_IDEOFFSET_2,
  55. .ctrloffset = ICS_ARCIN_V6_IDEALTOFFSET_2,
  56. .stepping = ICS_ARCIN_V6_IDESTEPPING,
  57. };
  58. struct icside_state {
  59. unsigned int channel;
  60. unsigned int enabled;
  61. void __iomem *irq_port;
  62. void __iomem *ioc_base;
  63. unsigned int type;
  64. /* parent device... until the IDE core gets one of its own */
  65. struct device *dev;
  66. ide_hwif_t *hwif[2];
  67. };
  68. #define ICS_TYPE_A3IN 0
  69. #define ICS_TYPE_A3USER 1
  70. #define ICS_TYPE_V6 3
  71. #define ICS_TYPE_V5 15
  72. #define ICS_TYPE_NOTYPE ((unsigned int)-1)
  73. /* ---------------- Version 5 PCB Support Functions --------------------- */
  74. /* Prototype: icside_irqenable_arcin_v5 (struct expansion_card *ec, int irqnr)
  75. * Purpose : enable interrupts from card
  76. */
  77. static void icside_irqenable_arcin_v5 (struct expansion_card *ec, int irqnr)
  78. {
  79. struct icside_state *state = ec->irq_data;
  80. writeb(0, state->irq_port + ICS_ARCIN_V5_INTROFFSET);
  81. }
  82. /* Prototype: icside_irqdisable_arcin_v5 (struct expansion_card *ec, int irqnr)
  83. * Purpose : disable interrupts from card
  84. */
  85. static void icside_irqdisable_arcin_v5 (struct expansion_card *ec, int irqnr)
  86. {
  87. struct icside_state *state = ec->irq_data;
  88. readb(state->irq_port + ICS_ARCIN_V5_INTROFFSET);
  89. }
  90. static const expansioncard_ops_t icside_ops_arcin_v5 = {
  91. .irqenable = icside_irqenable_arcin_v5,
  92. .irqdisable = icside_irqdisable_arcin_v5,
  93. };
  94. /* ---------------- Version 6 PCB Support Functions --------------------- */
  95. /* Prototype: icside_irqenable_arcin_v6 (struct expansion_card *ec, int irqnr)
  96. * Purpose : enable interrupts from card
  97. */
  98. static void icside_irqenable_arcin_v6 (struct expansion_card *ec, int irqnr)
  99. {
  100. struct icside_state *state = ec->irq_data;
  101. void __iomem *base = state->irq_port;
  102. state->enabled = 1;
  103. switch (state->channel) {
  104. case 0:
  105. writeb(0, base + ICS_ARCIN_V6_INTROFFSET_1);
  106. readb(base + ICS_ARCIN_V6_INTROFFSET_2);
  107. break;
  108. case 1:
  109. writeb(0, base + ICS_ARCIN_V6_INTROFFSET_2);
  110. readb(base + ICS_ARCIN_V6_INTROFFSET_1);
  111. break;
  112. }
  113. }
  114. /* Prototype: icside_irqdisable_arcin_v6 (struct expansion_card *ec, int irqnr)
  115. * Purpose : disable interrupts from card
  116. */
  117. static void icside_irqdisable_arcin_v6 (struct expansion_card *ec, int irqnr)
  118. {
  119. struct icside_state *state = ec->irq_data;
  120. state->enabled = 0;
  121. readb(state->irq_port + ICS_ARCIN_V6_INTROFFSET_1);
  122. readb(state->irq_port + ICS_ARCIN_V6_INTROFFSET_2);
  123. }
  124. /* Prototype: icside_irqprobe(struct expansion_card *ec)
  125. * Purpose : detect an active interrupt from card
  126. */
  127. static int icside_irqpending_arcin_v6(struct expansion_card *ec)
  128. {
  129. struct icside_state *state = ec->irq_data;
  130. return readb(state->irq_port + ICS_ARCIN_V6_INTRSTAT_1) & 1 ||
  131. readb(state->irq_port + ICS_ARCIN_V6_INTRSTAT_2) & 1;
  132. }
  133. static const expansioncard_ops_t icside_ops_arcin_v6 = {
  134. .irqenable = icside_irqenable_arcin_v6,
  135. .irqdisable = icside_irqdisable_arcin_v6,
  136. .irqpending = icside_irqpending_arcin_v6,
  137. };
  138. /*
  139. * Handle routing of interrupts. This is called before
  140. * we write the command to the drive.
  141. */
  142. static void icside_maskproc(ide_drive_t *drive, int mask)
  143. {
  144. ide_hwif_t *hwif = HWIF(drive);
  145. struct icside_state *state = hwif->hwif_data;
  146. unsigned long flags;
  147. local_irq_save(flags);
  148. state->channel = hwif->channel;
  149. if (state->enabled && !mask) {
  150. switch (hwif->channel) {
  151. case 0:
  152. writeb(0, state->irq_port + ICS_ARCIN_V6_INTROFFSET_1);
  153. readb(state->irq_port + ICS_ARCIN_V6_INTROFFSET_2);
  154. break;
  155. case 1:
  156. writeb(0, state->irq_port + ICS_ARCIN_V6_INTROFFSET_2);
  157. readb(state->irq_port + ICS_ARCIN_V6_INTROFFSET_1);
  158. break;
  159. }
  160. } else {
  161. readb(state->irq_port + ICS_ARCIN_V6_INTROFFSET_2);
  162. readb(state->irq_port + ICS_ARCIN_V6_INTROFFSET_1);
  163. }
  164. local_irq_restore(flags);
  165. }
  166. #ifdef CONFIG_BLK_DEV_IDEDMA_ICS
  167. /*
  168. * SG-DMA support.
  169. *
  170. * Similar to the BM-DMA, but we use the RiscPCs IOMD DMA controllers.
  171. * There is only one DMA controller per card, which means that only
  172. * one drive can be accessed at one time. NOTE! We do not enforce that
  173. * here, but we rely on the main IDE driver spotting that both
  174. * interfaces use the same IRQ, which should guarantee this.
  175. */
  176. static void icside_build_sglist(ide_drive_t *drive, struct request *rq)
  177. {
  178. ide_hwif_t *hwif = drive->hwif;
  179. struct icside_state *state = hwif->hwif_data;
  180. struct scatterlist *sg = hwif->sg_table;
  181. ide_map_sg(drive, rq);
  182. if (rq_data_dir(rq) == READ)
  183. hwif->sg_dma_direction = DMA_FROM_DEVICE;
  184. else
  185. hwif->sg_dma_direction = DMA_TO_DEVICE;
  186. hwif->sg_nents = dma_map_sg(state->dev, sg, hwif->sg_nents,
  187. hwif->sg_dma_direction);
  188. }
  189. /*
  190. * Configure the IOMD to give the appropriate timings for the transfer
  191. * mode being requested. We take the advice of the ATA standards, and
  192. * calculate the cycle time based on the transfer mode, and the EIDE
  193. * MW DMA specs that the drive provides in the IDENTIFY command.
  194. *
  195. * We have the following IOMD DMA modes to choose from:
  196. *
  197. * Type Active Recovery Cycle
  198. * A 250 (250) 312 (550) 562 (800)
  199. * B 187 250 437
  200. * C 125 (125) 125 (375) 250 (500)
  201. * D 62 125 187
  202. *
  203. * (figures in brackets are actual measured timings)
  204. *
  205. * However, we also need to take care of the read/write active and
  206. * recovery timings:
  207. *
  208. * Read Write
  209. * Mode Active -- Recovery -- Cycle IOMD type
  210. * MW0 215 50 215 480 A
  211. * MW1 80 50 50 150 C
  212. * MW2 70 25 25 120 C
  213. */
  214. static int icside_set_speed(ide_drive_t *drive, u8 xfer_mode)
  215. {
  216. int on = 0, cycle_time = 0, use_dma_info = 0;
  217. /*
  218. * Limit the transfer speed to MW_DMA_2.
  219. */
  220. if (xfer_mode > XFER_MW_DMA_2)
  221. xfer_mode = XFER_MW_DMA_2;
  222. switch (xfer_mode) {
  223. case XFER_MW_DMA_2:
  224. cycle_time = 250;
  225. use_dma_info = 1;
  226. break;
  227. case XFER_MW_DMA_1:
  228. cycle_time = 250;
  229. use_dma_info = 1;
  230. break;
  231. case XFER_MW_DMA_0:
  232. cycle_time = 480;
  233. break;
  234. case XFER_SW_DMA_2:
  235. case XFER_SW_DMA_1:
  236. case XFER_SW_DMA_0:
  237. cycle_time = 480;
  238. break;
  239. }
  240. /*
  241. * If we're going to be doing MW_DMA_1 or MW_DMA_2, we should
  242. * take care to note the values in the ID...
  243. */
  244. if (use_dma_info && drive->id->eide_dma_time > cycle_time)
  245. cycle_time = drive->id->eide_dma_time;
  246. drive->drive_data = cycle_time;
  247. if (cycle_time && ide_config_drive_speed(drive, xfer_mode) == 0)
  248. on = 1;
  249. else
  250. drive->drive_data = 480;
  251. printk("%s: %s selected (peak %dMB/s)\n", drive->name,
  252. ide_xfer_verbose(xfer_mode), 2000 / drive->drive_data);
  253. drive->current_speed = xfer_mode;
  254. return on;
  255. }
  256. static void icside_dma_host_off(ide_drive_t *drive)
  257. {
  258. }
  259. static void icside_dma_off_quietly(ide_drive_t *drive)
  260. {
  261. drive->using_dma = 0;
  262. }
  263. static void icside_dma_host_on(ide_drive_t *drive)
  264. {
  265. }
  266. static int icside_dma_on(ide_drive_t *drive)
  267. {
  268. drive->using_dma = 1;
  269. return 0;
  270. }
  271. static int icside_dma_check(ide_drive_t *drive)
  272. {
  273. struct hd_driveid *id = drive->id;
  274. ide_hwif_t *hwif = HWIF(drive);
  275. int xfer_mode = XFER_PIO_2;
  276. int on;
  277. if (!(id->capability & 1) || !hwif->autodma)
  278. goto out;
  279. /*
  280. * Consult the list of known "bad" drives
  281. */
  282. if (__ide_dma_bad_drive(drive))
  283. goto out;
  284. /*
  285. * Enable DMA on any drive that has multiword DMA
  286. */
  287. if (id->field_valid & 2) {
  288. xfer_mode = ide_max_dma_mode(drive);
  289. goto out;
  290. }
  291. /*
  292. * Consult the list of known "good" drives
  293. */
  294. if (__ide_dma_good_drive(drive)) {
  295. if (id->eide_dma_time > 150)
  296. goto out;
  297. xfer_mode = XFER_MW_DMA_1;
  298. }
  299. out:
  300. on = icside_set_speed(drive, xfer_mode);
  301. return on ? 0 : -1;
  302. }
  303. static int icside_dma_end(ide_drive_t *drive)
  304. {
  305. ide_hwif_t *hwif = HWIF(drive);
  306. struct icside_state *state = hwif->hwif_data;
  307. drive->waiting_for_dma = 0;
  308. disable_dma(hwif->hw.dma);
  309. /* Teardown mappings after DMA has completed. */
  310. dma_unmap_sg(state->dev, hwif->sg_table, hwif->sg_nents,
  311. hwif->sg_dma_direction);
  312. return get_dma_residue(hwif->hw.dma) != 0;
  313. }
  314. static void icside_dma_start(ide_drive_t *drive)
  315. {
  316. ide_hwif_t *hwif = HWIF(drive);
  317. /* We can not enable DMA on both channels simultaneously. */
  318. BUG_ON(dma_channel_active(hwif->hw.dma));
  319. enable_dma(hwif->hw.dma);
  320. }
  321. static int icside_dma_setup(ide_drive_t *drive)
  322. {
  323. ide_hwif_t *hwif = HWIF(drive);
  324. struct request *rq = hwif->hwgroup->rq;
  325. unsigned int dma_mode;
  326. if (rq_data_dir(rq))
  327. dma_mode = DMA_MODE_WRITE;
  328. else
  329. dma_mode = DMA_MODE_READ;
  330. /*
  331. * We can not enable DMA on both channels.
  332. */
  333. BUG_ON(dma_channel_active(hwif->hw.dma));
  334. icside_build_sglist(drive, rq);
  335. /*
  336. * Ensure that we have the right interrupt routed.
  337. */
  338. icside_maskproc(drive, 0);
  339. /*
  340. * Route the DMA signals to the correct interface.
  341. */
  342. writeb(hwif->select_data, hwif->config_data);
  343. /*
  344. * Select the correct timing for this drive.
  345. */
  346. set_dma_speed(hwif->hw.dma, drive->drive_data);
  347. /*
  348. * Tell the DMA engine about the SG table and
  349. * data direction.
  350. */
  351. set_dma_sg(hwif->hw.dma, hwif->sg_table, hwif->sg_nents);
  352. set_dma_mode(hwif->hw.dma, dma_mode);
  353. drive->waiting_for_dma = 1;
  354. return 0;
  355. }
  356. static void icside_dma_exec_cmd(ide_drive_t *drive, u8 cmd)
  357. {
  358. /* issue cmd to drive */
  359. ide_execute_command(drive, cmd, ide_dma_intr, 2 * WAIT_CMD, NULL);
  360. }
  361. static int icside_dma_test_irq(ide_drive_t *drive)
  362. {
  363. ide_hwif_t *hwif = HWIF(drive);
  364. struct icside_state *state = hwif->hwif_data;
  365. return readb(state->irq_port +
  366. (hwif->channel ?
  367. ICS_ARCIN_V6_INTRSTAT_2 :
  368. ICS_ARCIN_V6_INTRSTAT_1)) & 1;
  369. }
  370. static void icside_dma_timeout(ide_drive_t *drive)
  371. {
  372. printk(KERN_ERR "%s: DMA timeout occurred: ", drive->name);
  373. if (icside_dma_test_irq(drive))
  374. return;
  375. ide_dump_status(drive, "DMA timeout", HWIF(drive)->INB(IDE_STATUS_REG));
  376. icside_dma_end(drive);
  377. }
  378. static void icside_dma_lost_irq(ide_drive_t *drive)
  379. {
  380. printk(KERN_ERR "%s: IRQ lost\n", drive->name);
  381. }
  382. static void icside_dma_init(ide_hwif_t *hwif)
  383. {
  384. printk(" %s: SG-DMA", hwif->name);
  385. hwif->atapi_dma = 1;
  386. hwif->mwdma_mask = 7; /* MW0..2 */
  387. hwif->swdma_mask = 7; /* SW0..2 */
  388. hwif->dmatable_cpu = NULL;
  389. hwif->dmatable_dma = 0;
  390. hwif->speedproc = icside_set_speed;
  391. hwif->autodma = 1;
  392. hwif->ide_dma_check = icside_dma_check;
  393. hwif->dma_host_off = icside_dma_host_off;
  394. hwif->dma_off_quietly = icside_dma_off_quietly;
  395. hwif->dma_host_on = icside_dma_host_on;
  396. hwif->ide_dma_on = icside_dma_on;
  397. hwif->dma_setup = icside_dma_setup;
  398. hwif->dma_exec_cmd = icside_dma_exec_cmd;
  399. hwif->dma_start = icside_dma_start;
  400. hwif->ide_dma_end = icside_dma_end;
  401. hwif->ide_dma_test_irq = icside_dma_test_irq;
  402. hwif->dma_timeout = icside_dma_timeout;
  403. hwif->dma_lost_irq = icside_dma_lost_irq;
  404. hwif->drives[0].autodma = hwif->autodma;
  405. hwif->drives[1].autodma = hwif->autodma;
  406. printk(" capable%s\n", hwif->autodma ? ", auto-enable" : "");
  407. }
  408. #else
  409. #define icside_dma_init(hwif) (0)
  410. #endif
  411. static ide_hwif_t *icside_find_hwif(unsigned long dataport)
  412. {
  413. ide_hwif_t *hwif;
  414. int index;
  415. for (index = 0; index < MAX_HWIFS; ++index) {
  416. hwif = &ide_hwifs[index];
  417. if (hwif->io_ports[IDE_DATA_OFFSET] == dataport)
  418. goto found;
  419. }
  420. for (index = 0; index < MAX_HWIFS; ++index) {
  421. hwif = &ide_hwifs[index];
  422. if (!hwif->io_ports[IDE_DATA_OFFSET])
  423. goto found;
  424. }
  425. hwif = NULL;
  426. found:
  427. return hwif;
  428. }
  429. static ide_hwif_t *
  430. icside_setup(void __iomem *base, struct cardinfo *info, struct expansion_card *ec)
  431. {
  432. unsigned long port = (unsigned long)base + info->dataoffset;
  433. ide_hwif_t *hwif;
  434. hwif = icside_find_hwif(port);
  435. if (hwif) {
  436. int i;
  437. memset(&hwif->hw, 0, sizeof(hw_regs_t));
  438. /*
  439. * Ensure we're using MMIO
  440. */
  441. default_hwif_mmiops(hwif);
  442. hwif->mmio = 1;
  443. for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) {
  444. hwif->hw.io_ports[i] = port;
  445. hwif->io_ports[i] = port;
  446. port += 1 << info->stepping;
  447. }
  448. hwif->hw.io_ports[IDE_CONTROL_OFFSET] = (unsigned long)base + info->ctrloffset;
  449. hwif->io_ports[IDE_CONTROL_OFFSET] = (unsigned long)base + info->ctrloffset;
  450. hwif->hw.irq = ec->irq;
  451. hwif->irq = ec->irq;
  452. hwif->noprobe = 0;
  453. hwif->chipset = ide_acorn;
  454. hwif->gendev.parent = &ec->dev;
  455. }
  456. return hwif;
  457. }
  458. static int __init
  459. icside_register_v5(struct icside_state *state, struct expansion_card *ec)
  460. {
  461. ide_hwif_t *hwif;
  462. void __iomem *base;
  463. base = ecardm_iomap(ec, ECARD_RES_MEMC, 0, 0);
  464. if (!base)
  465. return -ENOMEM;
  466. state->irq_port = base;
  467. ec->irqaddr = base + ICS_ARCIN_V5_INTRSTAT;
  468. ec->irqmask = 1;
  469. ecard_setirq(ec, &icside_ops_arcin_v5, state);
  470. /*
  471. * Be on the safe side - disable interrupts
  472. */
  473. icside_irqdisable_arcin_v5(ec, 0);
  474. hwif = icside_setup(base, &icside_cardinfo_v5, ec);
  475. if (!hwif)
  476. return -ENODEV;
  477. state->hwif[0] = hwif;
  478. probe_hwif_init(hwif);
  479. ide_proc_register_port(hwif);
  480. return 0;
  481. }
  482. static int __init
  483. icside_register_v6(struct icside_state *state, struct expansion_card *ec)
  484. {
  485. ide_hwif_t *hwif, *mate;
  486. void __iomem *ioc_base, *easi_base;
  487. unsigned int sel = 0;
  488. int ret;
  489. ioc_base = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, 0);
  490. if (!ioc_base) {
  491. ret = -ENOMEM;
  492. goto out;
  493. }
  494. easi_base = ioc_base;
  495. if (ecard_resource_flags(ec, ECARD_RES_EASI)) {
  496. easi_base = ecardm_iomap(ec, ECARD_RES_EASI, 0, 0);
  497. if (!easi_base) {
  498. ret = -ENOMEM;
  499. goto out;
  500. }
  501. /*
  502. * Enable access to the EASI region.
  503. */
  504. sel = 1 << 5;
  505. }
  506. writeb(sel, ioc_base);
  507. ecard_setirq(ec, &icside_ops_arcin_v6, state);
  508. state->irq_port = easi_base;
  509. state->ioc_base = ioc_base;
  510. /*
  511. * Be on the safe side - disable interrupts
  512. */
  513. icside_irqdisable_arcin_v6(ec, 0);
  514. /*
  515. * Find and register the interfaces.
  516. */
  517. hwif = icside_setup(easi_base, &icside_cardinfo_v6_1, ec);
  518. mate = icside_setup(easi_base, &icside_cardinfo_v6_2, ec);
  519. if (!hwif || !mate) {
  520. ret = -ENODEV;
  521. goto out;
  522. }
  523. state->hwif[0] = hwif;
  524. state->hwif[1] = mate;
  525. hwif->maskproc = icside_maskproc;
  526. hwif->channel = 0;
  527. hwif->hwif_data = state;
  528. hwif->mate = mate;
  529. hwif->serialized = 1;
  530. hwif->config_data = (unsigned long)ioc_base;
  531. hwif->select_data = sel;
  532. hwif->hw.dma = ec->dma;
  533. mate->maskproc = icside_maskproc;
  534. mate->channel = 1;
  535. mate->hwif_data = state;
  536. mate->mate = hwif;
  537. mate->serialized = 1;
  538. mate->config_data = (unsigned long)ioc_base;
  539. mate->select_data = sel | 1;
  540. mate->hw.dma = ec->dma;
  541. if (ec->dma != NO_DMA && !request_dma(ec->dma, hwif->name)) {
  542. icside_dma_init(hwif);
  543. icside_dma_init(mate);
  544. }
  545. probe_hwif_init(hwif);
  546. probe_hwif_init(mate);
  547. ide_proc_register_port(hwif);
  548. ide_proc_register_port(mate);
  549. return 0;
  550. out:
  551. return ret;
  552. }
  553. static int __devinit
  554. icside_probe(struct expansion_card *ec, const struct ecard_id *id)
  555. {
  556. struct icside_state *state;
  557. void __iomem *idmem;
  558. int ret;
  559. ret = ecard_request_resources(ec);
  560. if (ret)
  561. goto out;
  562. state = kmalloc(sizeof(struct icside_state), GFP_KERNEL);
  563. if (!state) {
  564. ret = -ENOMEM;
  565. goto release;
  566. }
  567. memset(state, 0, sizeof(state));
  568. state->type = ICS_TYPE_NOTYPE;
  569. state->dev = &ec->dev;
  570. idmem = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, 0);
  571. if (idmem) {
  572. unsigned int type;
  573. type = readb(idmem + ICS_IDENT_OFFSET) & 1;
  574. type |= (readb(idmem + ICS_IDENT_OFFSET + 4) & 1) << 1;
  575. type |= (readb(idmem + ICS_IDENT_OFFSET + 8) & 1) << 2;
  576. type |= (readb(idmem + ICS_IDENT_OFFSET + 12) & 1) << 3;
  577. ecardm_iounmap(ec, idmem);
  578. state->type = type;
  579. }
  580. switch (state->type) {
  581. case ICS_TYPE_A3IN:
  582. dev_warn(&ec->dev, "A3IN unsupported\n");
  583. ret = -ENODEV;
  584. break;
  585. case ICS_TYPE_A3USER:
  586. dev_warn(&ec->dev, "A3USER unsupported\n");
  587. ret = -ENODEV;
  588. break;
  589. case ICS_TYPE_V5:
  590. ret = icside_register_v5(state, ec);
  591. break;
  592. case ICS_TYPE_V6:
  593. ret = icside_register_v6(state, ec);
  594. break;
  595. default:
  596. dev_warn(&ec->dev, "unknown interface type\n");
  597. ret = -ENODEV;
  598. break;
  599. }
  600. if (ret == 0) {
  601. ecard_set_drvdata(ec, state);
  602. goto out;
  603. }
  604. kfree(state);
  605. release:
  606. ecard_release_resources(ec);
  607. out:
  608. return ret;
  609. }
  610. static void __devexit icside_remove(struct expansion_card *ec)
  611. {
  612. struct icside_state *state = ecard_get_drvdata(ec);
  613. switch (state->type) {
  614. case ICS_TYPE_V5:
  615. /* FIXME: tell IDE to stop using the interface */
  616. /* Disable interrupts */
  617. icside_irqdisable_arcin_v5(ec, 0);
  618. break;
  619. case ICS_TYPE_V6:
  620. /* FIXME: tell IDE to stop using the interface */
  621. if (ec->dma != NO_DMA)
  622. free_dma(ec->dma);
  623. /* Disable interrupts */
  624. icside_irqdisable_arcin_v6(ec, 0);
  625. /* Reset the ROM pointer/EASI selection */
  626. writeb(0, state->ioc_base);
  627. break;
  628. }
  629. ecard_set_drvdata(ec, NULL);
  630. kfree(state);
  631. ecard_release_resources(ec);
  632. }
  633. static void icside_shutdown(struct expansion_card *ec)
  634. {
  635. struct icside_state *state = ecard_get_drvdata(ec);
  636. unsigned long flags;
  637. /*
  638. * Disable interrupts from this card. We need to do
  639. * this before disabling EASI since we may be accessing
  640. * this register via that region.
  641. */
  642. local_irq_save(flags);
  643. ec->ops->irqdisable(ec, 0);
  644. local_irq_restore(flags);
  645. /*
  646. * Reset the ROM pointer so that we can read the ROM
  647. * after a soft reboot. This also disables access to
  648. * the IDE taskfile via the EASI region.
  649. */
  650. if (state->ioc_base)
  651. writeb(0, state->ioc_base);
  652. }
  653. static const struct ecard_id icside_ids[] = {
  654. { MANU_ICS, PROD_ICS_IDE },
  655. { MANU_ICS2, PROD_ICS2_IDE },
  656. { 0xffff, 0xffff }
  657. };
  658. static struct ecard_driver icside_driver = {
  659. .probe = icside_probe,
  660. .remove = __devexit_p(icside_remove),
  661. .shutdown = icside_shutdown,
  662. .id_table = icside_ids,
  663. .drv = {
  664. .name = "icside",
  665. },
  666. };
  667. static int __init icside_init(void)
  668. {
  669. return ecard_register_driver(&icside_driver);
  670. }
  671. MODULE_AUTHOR("Russell King <rmk@arm.linux.org.uk>");
  672. MODULE_LICENSE("GPL");
  673. MODULE_DESCRIPTION("ICS IDE driver");
  674. module_init(icside_init);