icside.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869
  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 <asm/dma.h>
  21. #include <asm/ecard.h>
  22. #include <asm/io.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. #ifndef CONFIG_IDEDMA_ICS_AUTO
  168. #warning CONFIG_IDEDMA_ICS_AUTO=n support is obsolete, and will be removed soon.
  169. #endif
  170. /*
  171. * SG-DMA support.
  172. *
  173. * Similar to the BM-DMA, but we use the RiscPCs IOMD DMA controllers.
  174. * There is only one DMA controller per card, which means that only
  175. * one drive can be accessed at one time. NOTE! We do not enforce that
  176. * here, but we rely on the main IDE driver spotting that both
  177. * interfaces use the same IRQ, which should guarantee this.
  178. */
  179. static void icside_build_sglist(ide_drive_t *drive, struct request *rq)
  180. {
  181. ide_hwif_t *hwif = drive->hwif;
  182. struct icside_state *state = hwif->hwif_data;
  183. struct scatterlist *sg = hwif->sg_table;
  184. ide_map_sg(drive, rq);
  185. if (rq_data_dir(rq) == READ)
  186. hwif->sg_dma_direction = DMA_FROM_DEVICE;
  187. else
  188. hwif->sg_dma_direction = DMA_TO_DEVICE;
  189. hwif->sg_nents = dma_map_sg(state->dev, sg, hwif->sg_nents,
  190. hwif->sg_dma_direction);
  191. }
  192. /*
  193. * Configure the IOMD to give the appropriate timings for the transfer
  194. * mode being requested. We take the advice of the ATA standards, and
  195. * calculate the cycle time based on the transfer mode, and the EIDE
  196. * MW DMA specs that the drive provides in the IDENTIFY command.
  197. *
  198. * We have the following IOMD DMA modes to choose from:
  199. *
  200. * Type Active Recovery Cycle
  201. * A 250 (250) 312 (550) 562 (800)
  202. * B 187 250 437
  203. * C 125 (125) 125 (375) 250 (500)
  204. * D 62 125 187
  205. *
  206. * (figures in brackets are actual measured timings)
  207. *
  208. * However, we also need to take care of the read/write active and
  209. * recovery timings:
  210. *
  211. * Read Write
  212. * Mode Active -- Recovery -- Cycle IOMD type
  213. * MW0 215 50 215 480 A
  214. * MW1 80 50 50 150 C
  215. * MW2 70 25 25 120 C
  216. */
  217. static int icside_set_speed(ide_drive_t *drive, u8 xfer_mode)
  218. {
  219. int on = 0, cycle_time = 0, use_dma_info = 0;
  220. /*
  221. * Limit the transfer speed to MW_DMA_2.
  222. */
  223. if (xfer_mode > XFER_MW_DMA_2)
  224. xfer_mode = XFER_MW_DMA_2;
  225. switch (xfer_mode) {
  226. case XFER_MW_DMA_2:
  227. cycle_time = 250;
  228. use_dma_info = 1;
  229. break;
  230. case XFER_MW_DMA_1:
  231. cycle_time = 250;
  232. use_dma_info = 1;
  233. break;
  234. case XFER_MW_DMA_0:
  235. cycle_time = 480;
  236. break;
  237. case XFER_SW_DMA_2:
  238. case XFER_SW_DMA_1:
  239. case XFER_SW_DMA_0:
  240. cycle_time = 480;
  241. break;
  242. }
  243. /*
  244. * If we're going to be doing MW_DMA_1 or MW_DMA_2, we should
  245. * take care to note the values in the ID...
  246. */
  247. if (use_dma_info && drive->id->eide_dma_time > cycle_time)
  248. cycle_time = drive->id->eide_dma_time;
  249. drive->drive_data = cycle_time;
  250. if (cycle_time && ide_config_drive_speed(drive, xfer_mode) == 0)
  251. on = 1;
  252. else
  253. drive->drive_data = 480;
  254. printk("%s: %s selected (peak %dMB/s)\n", drive->name,
  255. ide_xfer_verbose(xfer_mode), 2000 / drive->drive_data);
  256. drive->current_speed = xfer_mode;
  257. return on;
  258. }
  259. static int icside_dma_host_off(ide_drive_t *drive)
  260. {
  261. return 0;
  262. }
  263. static int icside_dma_off_quietly(ide_drive_t *drive)
  264. {
  265. drive->using_dma = 0;
  266. return icside_dma_host_off(drive);
  267. }
  268. static int icside_dma_host_on(ide_drive_t *drive)
  269. {
  270. return 0;
  271. }
  272. static int icside_dma_on(ide_drive_t *drive)
  273. {
  274. drive->using_dma = 1;
  275. return icside_dma_host_on(drive);
  276. }
  277. static int icside_dma_check(ide_drive_t *drive)
  278. {
  279. struct hd_driveid *id = drive->id;
  280. ide_hwif_t *hwif = HWIF(drive);
  281. int xfer_mode = XFER_PIO_2;
  282. int on;
  283. if (!(id->capability & 1) || !hwif->autodma)
  284. goto out;
  285. /*
  286. * Consult the list of known "bad" drives
  287. */
  288. if (__ide_dma_bad_drive(drive))
  289. goto out;
  290. /*
  291. * Enable DMA on any drive that has multiword DMA
  292. */
  293. if (id->field_valid & 2) {
  294. xfer_mode = ide_dma_speed(drive, 0);
  295. goto out;
  296. }
  297. /*
  298. * Consult the list of known "good" drives
  299. */
  300. if (__ide_dma_good_drive(drive)) {
  301. if (id->eide_dma_time > 150)
  302. goto out;
  303. xfer_mode = XFER_MW_DMA_1;
  304. }
  305. out:
  306. on = icside_set_speed(drive, xfer_mode);
  307. if (on)
  308. return icside_dma_on(drive);
  309. else
  310. return icside_dma_off_quietly(drive);
  311. }
  312. static int icside_dma_end(ide_drive_t *drive)
  313. {
  314. ide_hwif_t *hwif = HWIF(drive);
  315. struct icside_state *state = hwif->hwif_data;
  316. drive->waiting_for_dma = 0;
  317. disable_dma(hwif->hw.dma);
  318. /* Teardown mappings after DMA has completed. */
  319. dma_unmap_sg(state->dev, hwif->sg_table, hwif->sg_nents,
  320. hwif->sg_dma_direction);
  321. return get_dma_residue(hwif->hw.dma) != 0;
  322. }
  323. static void icside_dma_start(ide_drive_t *drive)
  324. {
  325. ide_hwif_t *hwif = HWIF(drive);
  326. /* We can not enable DMA on both channels simultaneously. */
  327. BUG_ON(dma_channel_active(hwif->hw.dma));
  328. enable_dma(hwif->hw.dma);
  329. }
  330. static int icside_dma_setup(ide_drive_t *drive)
  331. {
  332. ide_hwif_t *hwif = HWIF(drive);
  333. struct request *rq = hwif->hwgroup->rq;
  334. unsigned int dma_mode;
  335. if (rq_data_dir(rq))
  336. dma_mode = DMA_MODE_WRITE;
  337. else
  338. dma_mode = DMA_MODE_READ;
  339. /*
  340. * We can not enable DMA on both channels.
  341. */
  342. BUG_ON(dma_channel_active(hwif->hw.dma));
  343. icside_build_sglist(drive, rq);
  344. /*
  345. * Ensure that we have the right interrupt routed.
  346. */
  347. icside_maskproc(drive, 0);
  348. /*
  349. * Route the DMA signals to the correct interface.
  350. */
  351. writeb(hwif->select_data, hwif->config_data);
  352. /*
  353. * Select the correct timing for this drive.
  354. */
  355. set_dma_speed(hwif->hw.dma, drive->drive_data);
  356. /*
  357. * Tell the DMA engine about the SG table and
  358. * data direction.
  359. */
  360. set_dma_sg(hwif->hw.dma, hwif->sg_table, hwif->sg_nents);
  361. set_dma_mode(hwif->hw.dma, dma_mode);
  362. drive->waiting_for_dma = 1;
  363. return 0;
  364. }
  365. static void icside_dma_exec_cmd(ide_drive_t *drive, u8 cmd)
  366. {
  367. /* issue cmd to drive */
  368. ide_execute_command(drive, cmd, ide_dma_intr, 2 * WAIT_CMD, NULL);
  369. }
  370. static int icside_dma_test_irq(ide_drive_t *drive)
  371. {
  372. ide_hwif_t *hwif = HWIF(drive);
  373. struct icside_state *state = hwif->hwif_data;
  374. return readb(state->irq_port +
  375. (hwif->channel ?
  376. ICS_ARCIN_V6_INTRSTAT_2 :
  377. ICS_ARCIN_V6_INTRSTAT_1)) & 1;
  378. }
  379. static int icside_dma_timeout(ide_drive_t *drive)
  380. {
  381. printk(KERN_ERR "%s: DMA timeout occurred: ", drive->name);
  382. if (icside_dma_test_irq(drive))
  383. return 0;
  384. ide_dump_status(drive, "DMA timeout",
  385. HWIF(drive)->INB(IDE_STATUS_REG));
  386. return icside_dma_end(drive);
  387. }
  388. static int icside_dma_lostirq(ide_drive_t *drive)
  389. {
  390. printk(KERN_ERR "%s: IRQ lost\n", drive->name);
  391. return 1;
  392. }
  393. static void icside_dma_init(ide_hwif_t *hwif)
  394. {
  395. int autodma = 0;
  396. #ifdef CONFIG_IDEDMA_ICS_AUTO
  397. autodma = 1;
  398. #endif
  399. printk(" %s: SG-DMA", hwif->name);
  400. hwif->atapi_dma = 1;
  401. hwif->mwdma_mask = 7; /* MW0..2 */
  402. hwif->swdma_mask = 7; /* SW0..2 */
  403. hwif->dmatable_cpu = NULL;
  404. hwif->dmatable_dma = 0;
  405. hwif->speedproc = icside_set_speed;
  406. hwif->autodma = autodma;
  407. hwif->ide_dma_check = icside_dma_check;
  408. hwif->ide_dma_host_off = icside_dma_host_off;
  409. hwif->ide_dma_off_quietly = icside_dma_off_quietly;
  410. hwif->ide_dma_host_on = icside_dma_host_on;
  411. hwif->ide_dma_on = icside_dma_on;
  412. hwif->dma_setup = icside_dma_setup;
  413. hwif->dma_exec_cmd = icside_dma_exec_cmd;
  414. hwif->dma_start = icside_dma_start;
  415. hwif->ide_dma_end = icside_dma_end;
  416. hwif->ide_dma_test_irq = icside_dma_test_irq;
  417. hwif->ide_dma_timeout = icside_dma_timeout;
  418. hwif->ide_dma_lostirq = icside_dma_lostirq;
  419. hwif->drives[0].autodma = hwif->autodma;
  420. hwif->drives[1].autodma = hwif->autodma;
  421. printk(" capable%s\n", hwif->autodma ? ", auto-enable" : "");
  422. }
  423. #else
  424. #define icside_dma_init(hwif) (0)
  425. #endif
  426. static ide_hwif_t *icside_find_hwif(unsigned long dataport)
  427. {
  428. ide_hwif_t *hwif;
  429. int index;
  430. for (index = 0; index < MAX_HWIFS; ++index) {
  431. hwif = &ide_hwifs[index];
  432. if (hwif->io_ports[IDE_DATA_OFFSET] == dataport)
  433. goto found;
  434. }
  435. for (index = 0; index < MAX_HWIFS; ++index) {
  436. hwif = &ide_hwifs[index];
  437. if (!hwif->io_ports[IDE_DATA_OFFSET])
  438. goto found;
  439. }
  440. hwif = NULL;
  441. found:
  442. return hwif;
  443. }
  444. static ide_hwif_t *
  445. icside_setup(void __iomem *base, struct cardinfo *info, struct expansion_card *ec)
  446. {
  447. unsigned long port = (unsigned long)base + info->dataoffset;
  448. ide_hwif_t *hwif;
  449. hwif = icside_find_hwif(port);
  450. if (hwif) {
  451. int i;
  452. memset(&hwif->hw, 0, sizeof(hw_regs_t));
  453. /*
  454. * Ensure we're using MMIO
  455. */
  456. default_hwif_mmiops(hwif);
  457. hwif->mmio = 2;
  458. for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) {
  459. hwif->hw.io_ports[i] = port;
  460. hwif->io_ports[i] = port;
  461. port += 1 << info->stepping;
  462. }
  463. hwif->hw.io_ports[IDE_CONTROL_OFFSET] = (unsigned long)base + info->ctrloffset;
  464. hwif->io_ports[IDE_CONTROL_OFFSET] = (unsigned long)base + info->ctrloffset;
  465. hwif->hw.irq = ec->irq;
  466. hwif->irq = ec->irq;
  467. hwif->noprobe = 0;
  468. hwif->chipset = ide_acorn;
  469. hwif->gendev.parent = &ec->dev;
  470. }
  471. return hwif;
  472. }
  473. static int __init
  474. icside_register_v5(struct icside_state *state, struct expansion_card *ec)
  475. {
  476. ide_hwif_t *hwif;
  477. void __iomem *base;
  478. base = ioremap(ecard_resource_start(ec, ECARD_RES_MEMC),
  479. ecard_resource_len(ec, ECARD_RES_MEMC));
  480. if (!base)
  481. return -ENOMEM;
  482. state->irq_port = base;
  483. ec->irqaddr = base + ICS_ARCIN_V5_INTRSTAT;
  484. ec->irqmask = 1;
  485. ec->irq_data = state;
  486. ec->ops = &icside_ops_arcin_v5;
  487. /*
  488. * Be on the safe side - disable interrupts
  489. */
  490. icside_irqdisable_arcin_v5(ec, 0);
  491. hwif = icside_setup(base, &icside_cardinfo_v5, ec);
  492. if (!hwif) {
  493. iounmap(base);
  494. return -ENODEV;
  495. }
  496. state->hwif[0] = hwif;
  497. probe_hwif_init(hwif);
  498. create_proc_ide_interfaces();
  499. return 0;
  500. }
  501. static int __init
  502. icside_register_v6(struct icside_state *state, struct expansion_card *ec)
  503. {
  504. ide_hwif_t *hwif, *mate;
  505. void __iomem *ioc_base, *easi_base;
  506. unsigned int sel = 0;
  507. int ret;
  508. ioc_base = ioremap(ecard_resource_start(ec, ECARD_RES_IOCFAST),
  509. ecard_resource_len(ec, ECARD_RES_IOCFAST));
  510. if (!ioc_base) {
  511. ret = -ENOMEM;
  512. goto out;
  513. }
  514. easi_base = ioc_base;
  515. if (ecard_resource_flags(ec, ECARD_RES_EASI)) {
  516. easi_base = ioremap(ecard_resource_start(ec, ECARD_RES_EASI),
  517. ecard_resource_len(ec, ECARD_RES_EASI));
  518. if (!easi_base) {
  519. ret = -ENOMEM;
  520. goto unmap_slot;
  521. }
  522. /*
  523. * Enable access to the EASI region.
  524. */
  525. sel = 1 << 5;
  526. }
  527. writeb(sel, ioc_base);
  528. ec->irq_data = state;
  529. ec->ops = &icside_ops_arcin_v6;
  530. state->irq_port = easi_base;
  531. state->ioc_base = ioc_base;
  532. /*
  533. * Be on the safe side - disable interrupts
  534. */
  535. icside_irqdisable_arcin_v6(ec, 0);
  536. /*
  537. * Find and register the interfaces.
  538. */
  539. hwif = icside_setup(easi_base, &icside_cardinfo_v6_1, ec);
  540. mate = icside_setup(easi_base, &icside_cardinfo_v6_2, ec);
  541. if (!hwif || !mate) {
  542. ret = -ENODEV;
  543. goto unmap_port;
  544. }
  545. state->hwif[0] = hwif;
  546. state->hwif[1] = mate;
  547. hwif->maskproc = icside_maskproc;
  548. hwif->channel = 0;
  549. hwif->hwif_data = state;
  550. hwif->mate = mate;
  551. hwif->serialized = 1;
  552. hwif->config_data = (unsigned long)ioc_base;
  553. hwif->select_data = sel;
  554. hwif->hw.dma = ec->dma;
  555. mate->maskproc = icside_maskproc;
  556. mate->channel = 1;
  557. mate->hwif_data = state;
  558. mate->mate = hwif;
  559. mate->serialized = 1;
  560. mate->config_data = (unsigned long)ioc_base;
  561. mate->select_data = sel | 1;
  562. mate->hw.dma = ec->dma;
  563. if (ec->dma != NO_DMA && !request_dma(ec->dma, hwif->name)) {
  564. icside_dma_init(hwif);
  565. icside_dma_init(mate);
  566. }
  567. probe_hwif_init(hwif);
  568. probe_hwif_init(mate);
  569. create_proc_ide_interfaces();
  570. return 0;
  571. unmap_port:
  572. if (easi_base != ioc_base)
  573. iounmap(easi_base);
  574. unmap_slot:
  575. iounmap(ioc_base);
  576. out:
  577. return ret;
  578. }
  579. static int __devinit
  580. icside_probe(struct expansion_card *ec, const struct ecard_id *id)
  581. {
  582. struct icside_state *state;
  583. void __iomem *idmem;
  584. int ret;
  585. ret = ecard_request_resources(ec);
  586. if (ret)
  587. goto out;
  588. state = kmalloc(sizeof(struct icside_state), GFP_KERNEL);
  589. if (!state) {
  590. ret = -ENOMEM;
  591. goto release;
  592. }
  593. memset(state, 0, sizeof(state));
  594. state->type = ICS_TYPE_NOTYPE;
  595. state->dev = &ec->dev;
  596. idmem = ioremap(ecard_resource_start(ec, ECARD_RES_IOCFAST),
  597. ecard_resource_len(ec, ECARD_RES_IOCFAST));
  598. if (idmem) {
  599. unsigned int type;
  600. type = readb(idmem + ICS_IDENT_OFFSET) & 1;
  601. type |= (readb(idmem + ICS_IDENT_OFFSET + 4) & 1) << 1;
  602. type |= (readb(idmem + ICS_IDENT_OFFSET + 8) & 1) << 2;
  603. type |= (readb(idmem + ICS_IDENT_OFFSET + 12) & 1) << 3;
  604. iounmap(idmem);
  605. state->type = type;
  606. }
  607. switch (state->type) {
  608. case ICS_TYPE_A3IN:
  609. dev_warn(&ec->dev, "A3IN unsupported\n");
  610. ret = -ENODEV;
  611. break;
  612. case ICS_TYPE_A3USER:
  613. dev_warn(&ec->dev, "A3USER unsupported\n");
  614. ret = -ENODEV;
  615. break;
  616. case ICS_TYPE_V5:
  617. ret = icside_register_v5(state, ec);
  618. break;
  619. case ICS_TYPE_V6:
  620. ret = icside_register_v6(state, ec);
  621. break;
  622. default:
  623. dev_warn(&ec->dev, "unknown interface type\n");
  624. ret = -ENODEV;
  625. break;
  626. }
  627. if (ret == 0) {
  628. ecard_set_drvdata(ec, state);
  629. goto out;
  630. }
  631. kfree(state);
  632. release:
  633. ecard_release_resources(ec);
  634. out:
  635. return ret;
  636. }
  637. static void __devexit icside_remove(struct expansion_card *ec)
  638. {
  639. struct icside_state *state = ecard_get_drvdata(ec);
  640. switch (state->type) {
  641. case ICS_TYPE_V5:
  642. /* FIXME: tell IDE to stop using the interface */
  643. /* Disable interrupts */
  644. icside_irqdisable_arcin_v5(ec, 0);
  645. break;
  646. case ICS_TYPE_V6:
  647. /* FIXME: tell IDE to stop using the interface */
  648. if (ec->dma != NO_DMA)
  649. free_dma(ec->dma);
  650. /* Disable interrupts */
  651. icside_irqdisable_arcin_v6(ec, 0);
  652. /* Reset the ROM pointer/EASI selection */
  653. writeb(0, state->ioc_base);
  654. break;
  655. }
  656. ecard_set_drvdata(ec, NULL);
  657. ec->ops = NULL;
  658. ec->irq_data = NULL;
  659. if (state->ioc_base)
  660. iounmap(state->ioc_base);
  661. if (state->ioc_base != state->irq_port)
  662. iounmap(state->irq_port);
  663. kfree(state);
  664. ecard_release_resources(ec);
  665. }
  666. static void icside_shutdown(struct expansion_card *ec)
  667. {
  668. struct icside_state *state = ecard_get_drvdata(ec);
  669. unsigned long flags;
  670. /*
  671. * Disable interrupts from this card. We need to do
  672. * this before disabling EASI since we may be accessing
  673. * this register via that region.
  674. */
  675. local_irq_save(flags);
  676. ec->ops->irqdisable(ec, 0);
  677. local_irq_restore(flags);
  678. /*
  679. * Reset the ROM pointer so that we can read the ROM
  680. * after a soft reboot. This also disables access to
  681. * the IDE taskfile via the EASI region.
  682. */
  683. if (state->ioc_base)
  684. writeb(0, state->ioc_base);
  685. }
  686. static const struct ecard_id icside_ids[] = {
  687. { MANU_ICS, PROD_ICS_IDE },
  688. { MANU_ICS2, PROD_ICS2_IDE },
  689. { 0xffff, 0xffff }
  690. };
  691. static struct ecard_driver icside_driver = {
  692. .probe = icside_probe,
  693. .remove = __devexit_p(icside_remove),
  694. .shutdown = icside_shutdown,
  695. .id_table = icside_ids,
  696. .drv = {
  697. .name = "icside",
  698. },
  699. };
  700. static int __init icside_init(void)
  701. {
  702. return ecard_register_driver(&icside_driver);
  703. }
  704. MODULE_AUTHOR("Russell King <rmk@arm.linux.org.uk>");
  705. MODULE_LICENSE("GPL");
  706. MODULE_DESCRIPTION("ICS IDE driver");
  707. module_init(icside_init);