icside.c 20 KB

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