pata_artop.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  1. /*
  2. * pata_artop.c - ARTOP ATA controller driver
  3. *
  4. * (C) 2006 Red Hat <alan@redhat.com>
  5. *
  6. * Based in part on drivers/ide/pci/aec62xx.c
  7. * Copyright (C) 1999-2002 Andre Hedrick <andre@linux-ide.org>
  8. * 865/865R fixes for Macintosh card version from a patch to the old
  9. * driver by Thibaut VARENE <varenet@parisc-linux.org>
  10. * When setting the PCI latency we must set 0x80 or higher for burst
  11. * performance Alessandro Zummo <alessandro.zummo@towertech.it>
  12. *
  13. * TODO
  14. * 850 serialization once the core supports it
  15. * Investigate no_dsc on 850R
  16. * Clock detect
  17. */
  18. #include <linux/kernel.h>
  19. #include <linux/module.h>
  20. #include <linux/pci.h>
  21. #include <linux/init.h>
  22. #include <linux/blkdev.h>
  23. #include <linux/delay.h>
  24. #include <linux/device.h>
  25. #include <scsi/scsi_host.h>
  26. #include <linux/libata.h>
  27. #include <linux/ata.h>
  28. #define DRV_NAME "pata_artop"
  29. #define DRV_VERSION "0.4.1"
  30. /*
  31. * The ARTOP has 33 Mhz and "over clocked" timing tables. Until we
  32. * get PCI bus speed functionality we leave this as 0. Its a variable
  33. * for when we get the functionality and also for folks wanting to
  34. * test stuff.
  35. */
  36. static int clock = 0;
  37. static int artop6210_pre_reset(struct ata_port *ap)
  38. {
  39. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  40. const struct pci_bits artop_enable_bits[] = {
  41. { 0x4AU, 1U, 0x02UL, 0x02UL }, /* port 0 */
  42. { 0x4AU, 1U, 0x04UL, 0x04UL }, /* port 1 */
  43. };
  44. if (!pci_test_config_bits(pdev, &artop_enable_bits[ap->port_no])) {
  45. ata_port_disable(ap);
  46. printk(KERN_INFO "ata%u: port disabled. ignoring.\n", ap->id);
  47. return 0;
  48. }
  49. ap->cbl = ATA_CBL_PATA40;
  50. return ata_std_prereset(ap);
  51. }
  52. /**
  53. * artop6210_error_handler - Probe specified port on PATA host controller
  54. * @ap: Port to probe
  55. *
  56. * LOCKING:
  57. * None (inherited from caller).
  58. */
  59. static void artop6210_error_handler(struct ata_port *ap)
  60. {
  61. ata_bmdma_drive_eh(ap, artop6210_pre_reset,
  62. ata_std_softreset, NULL,
  63. ata_std_postreset);
  64. }
  65. /**
  66. * artop6260_pre_reset - check for 40/80 pin
  67. * @ap: Port
  68. *
  69. * The ARTOP hardware reports the cable detect bits in register 0x49.
  70. * Nothing complicated needed here.
  71. */
  72. static int artop6260_pre_reset(struct ata_port *ap)
  73. {
  74. static const struct pci_bits artop_enable_bits[] = {
  75. { 0x4AU, 1U, 0x02UL, 0x02UL }, /* port 0 */
  76. { 0x4AU, 1U, 0x04UL, 0x04UL }, /* port 1 */
  77. };
  78. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  79. u8 tmp;
  80. /* Odd numbered device ids are the units with enable bits (the -R cards) */
  81. if (pdev->device % 1 && !pci_test_config_bits(pdev, &artop_enable_bits[ap->port_no])) {
  82. ata_port_disable(ap);
  83. printk(KERN_INFO "ata%u: port disabled. ignoring.\n", ap->id);
  84. return 0;
  85. }
  86. pci_read_config_byte(pdev, 0x49, &tmp);
  87. if (tmp & (1 >> ap->port_no))
  88. ap->cbl = ATA_CBL_PATA40;
  89. else
  90. ap->cbl = ATA_CBL_PATA80;
  91. return ata_std_prereset(ap);
  92. }
  93. /**
  94. * artop6260_error_handler - Probe specified port on PATA host controller
  95. * @ap: Port to probe
  96. *
  97. * LOCKING:
  98. * None (inherited from caller).
  99. */
  100. static void artop6260_error_handler(struct ata_port *ap)
  101. {
  102. ata_bmdma_drive_eh(ap, artop6260_pre_reset,
  103. ata_std_softreset, NULL,
  104. ata_std_postreset);
  105. }
  106. /**
  107. * artop6210_load_piomode - Load a set of PATA PIO timings
  108. * @ap: Port whose timings we are configuring
  109. * @adev: Device
  110. * @pio: PIO mode
  111. *
  112. * Set PIO mode for device, in host controller PCI config space. This
  113. * is used both to set PIO timings in PIO mode and also to set the
  114. * matching PIO clocking for UDMA, as well as the MWDMA timings.
  115. *
  116. * LOCKING:
  117. * None (inherited from caller).
  118. */
  119. static void artop6210_load_piomode(struct ata_port *ap, struct ata_device *adev, unsigned int pio)
  120. {
  121. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  122. int dn = adev->devno + 2 * ap->port_no;
  123. const u16 timing[2][5] = {
  124. { 0x0000, 0x000A, 0x0008, 0x0303, 0x0301 },
  125. { 0x0700, 0x070A, 0x0708, 0x0403, 0x0401 }
  126. };
  127. /* Load the PIO timing active/recovery bits */
  128. pci_write_config_word(pdev, 0x40 + 2 * dn, timing[clock][pio]);
  129. }
  130. /**
  131. * artop6210_set_piomode - Initialize host controller PATA PIO timings
  132. * @ap: Port whose timings we are configuring
  133. * @adev: Device we are configuring
  134. *
  135. * Set PIO mode for device, in host controller PCI config space. For
  136. * ARTOP we must also clear the UDMA bits if we are not doing UDMA. In
  137. * the event UDMA is used the later call to set_dmamode will set the
  138. * bits as required.
  139. *
  140. * LOCKING:
  141. * None (inherited from caller).
  142. */
  143. static void artop6210_set_piomode(struct ata_port *ap, struct ata_device *adev)
  144. {
  145. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  146. int dn = adev->devno + 2 * ap->port_no;
  147. u8 ultra;
  148. artop6210_load_piomode(ap, adev, adev->pio_mode - XFER_PIO_0);
  149. /* Clear the UDMA mode bits (set_dmamode will redo this if needed) */
  150. pci_read_config_byte(pdev, 0x54, &ultra);
  151. ultra &= ~(3 << (2 * dn));
  152. pci_write_config_byte(pdev, 0x54, ultra);
  153. }
  154. /**
  155. * artop6260_load_piomode - Initialize host controller PATA PIO timings
  156. * @ap: Port whose timings we are configuring
  157. * @adev: Device we are configuring
  158. * @pio: PIO mode
  159. *
  160. * Set PIO mode for device, in host controller PCI config space. The
  161. * ARTOP6260 and relatives store the timing data differently.
  162. *
  163. * LOCKING:
  164. * None (inherited from caller).
  165. */
  166. static void artop6260_load_piomode (struct ata_port *ap, struct ata_device *adev, unsigned int pio)
  167. {
  168. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  169. int dn = adev->devno + 2 * ap->port_no;
  170. const u8 timing[2][5] = {
  171. { 0x00, 0x0A, 0x08, 0x33, 0x31 },
  172. { 0x70, 0x7A, 0x78, 0x43, 0x41 }
  173. };
  174. /* Load the PIO timing active/recovery bits */
  175. pci_write_config_byte(pdev, 0x40 + dn, timing[clock][pio]);
  176. }
  177. /**
  178. * artop6260_set_piomode - Initialize host controller PATA PIO timings
  179. * @ap: Port whose timings we are configuring
  180. * @adev: Device we are configuring
  181. *
  182. * Set PIO mode for device, in host controller PCI config space. For
  183. * ARTOP we must also clear the UDMA bits if we are not doing UDMA. In
  184. * the event UDMA is used the later call to set_dmamode will set the
  185. * bits as required.
  186. *
  187. * LOCKING:
  188. * None (inherited from caller).
  189. */
  190. static void artop6260_set_piomode(struct ata_port *ap, struct ata_device *adev)
  191. {
  192. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  193. u8 ultra;
  194. artop6260_load_piomode(ap, adev, adev->pio_mode - XFER_PIO_0);
  195. /* Clear the UDMA mode bits (set_dmamode will redo this if needed) */
  196. pci_read_config_byte(pdev, 0x44 + ap->port_no, &ultra);
  197. ultra &= ~(7 << (4 * adev->devno)); /* One nibble per drive */
  198. pci_write_config_byte(pdev, 0x44 + ap->port_no, ultra);
  199. }
  200. /**
  201. * artop6210_set_dmamode - Initialize host controller PATA PIO timings
  202. * @ap: Port whose timings we are configuring
  203. * @adev: um
  204. *
  205. * Set DMA mode for device, in host controller PCI config space.
  206. *
  207. * LOCKING:
  208. * None (inherited from caller).
  209. */
  210. static void artop6210_set_dmamode (struct ata_port *ap, struct ata_device *adev)
  211. {
  212. unsigned int pio;
  213. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  214. int dn = adev->devno + 2 * ap->port_no;
  215. u8 ultra;
  216. if (adev->dma_mode == XFER_MW_DMA_0)
  217. pio = 1;
  218. else
  219. pio = 4;
  220. /* Load the PIO timing active/recovery bits */
  221. artop6210_load_piomode(ap, adev, pio);
  222. pci_read_config_byte(pdev, 0x54, &ultra);
  223. ultra &= ~(3 << (2 * dn));
  224. /* Add ultra DMA bits if in UDMA mode */
  225. if (adev->dma_mode >= XFER_UDMA_0) {
  226. u8 mode = (adev->dma_mode - XFER_UDMA_0) + 1 - clock;
  227. if (mode == 0)
  228. mode = 1;
  229. ultra |= (mode << (2 * dn));
  230. }
  231. pci_write_config_byte(pdev, 0x54, ultra);
  232. }
  233. /**
  234. * artop6260_set_dmamode - Initialize host controller PATA PIO timings
  235. * @ap: Port whose timings we are configuring
  236. * @adev: Device we are configuring
  237. *
  238. * Set DMA mode for device, in host controller PCI config space. The
  239. * ARTOP6260 and relatives store the timing data differently.
  240. *
  241. * LOCKING:
  242. * None (inherited from caller).
  243. */
  244. static void artop6260_set_dmamode (struct ata_port *ap, struct ata_device *adev)
  245. {
  246. unsigned int pio = adev->pio_mode - XFER_PIO_0;
  247. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  248. u8 ultra;
  249. if (adev->dma_mode == XFER_MW_DMA_0)
  250. pio = 1;
  251. else
  252. pio = 4;
  253. /* Load the PIO timing active/recovery bits */
  254. artop6260_load_piomode(ap, adev, pio);
  255. /* Add ultra DMA bits if in UDMA mode */
  256. pci_read_config_byte(pdev, 0x44 + ap->port_no, &ultra);
  257. ultra &= ~(7 << (4 * adev->devno)); /* One nibble per drive */
  258. if (adev->dma_mode >= XFER_UDMA_0) {
  259. u8 mode = adev->dma_mode - XFER_UDMA_0 + 1 - clock;
  260. if (mode == 0)
  261. mode = 1;
  262. ultra |= (mode << (4 * adev->devno));
  263. }
  264. pci_write_config_byte(pdev, 0x44 + ap->port_no, ultra);
  265. }
  266. static struct scsi_host_template artop_sht = {
  267. .module = THIS_MODULE,
  268. .name = DRV_NAME,
  269. .ioctl = ata_scsi_ioctl,
  270. .queuecommand = ata_scsi_queuecmd,
  271. .can_queue = ATA_DEF_QUEUE,
  272. .this_id = ATA_SHT_THIS_ID,
  273. .sg_tablesize = LIBATA_MAX_PRD,
  274. .max_sectors = ATA_MAX_SECTORS,
  275. .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
  276. .emulated = ATA_SHT_EMULATED,
  277. .use_clustering = ATA_SHT_USE_CLUSTERING,
  278. .proc_name = DRV_NAME,
  279. .dma_boundary = ATA_DMA_BOUNDARY,
  280. .slave_configure = ata_scsi_slave_config,
  281. .bios_param = ata_std_bios_param,
  282. };
  283. static const struct ata_port_operations artop6210_ops = {
  284. .port_disable = ata_port_disable,
  285. .set_piomode = artop6210_set_piomode,
  286. .set_dmamode = artop6210_set_dmamode,
  287. .mode_filter = ata_pci_default_filter,
  288. .tf_load = ata_tf_load,
  289. .tf_read = ata_tf_read,
  290. .check_status = ata_check_status,
  291. .exec_command = ata_exec_command,
  292. .dev_select = ata_std_dev_select,
  293. .freeze = ata_bmdma_freeze,
  294. .thaw = ata_bmdma_thaw,
  295. .error_handler = artop6210_error_handler,
  296. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  297. .bmdma_setup = ata_bmdma_setup,
  298. .bmdma_start = ata_bmdma_start,
  299. .bmdma_stop = ata_bmdma_stop,
  300. .bmdma_status = ata_bmdma_status,
  301. .qc_prep = ata_qc_prep,
  302. .qc_issue = ata_qc_issue_prot,
  303. .eng_timeout = ata_eng_timeout,
  304. .data_xfer = ata_pio_data_xfer,
  305. .irq_handler = ata_interrupt,
  306. .irq_clear = ata_bmdma_irq_clear,
  307. .port_start = ata_port_start,
  308. .port_stop = ata_port_stop,
  309. .host_stop = ata_host_stop,
  310. };
  311. static const struct ata_port_operations artop6260_ops = {
  312. .port_disable = ata_port_disable,
  313. .set_piomode = artop6260_set_piomode,
  314. .set_dmamode = artop6260_set_dmamode,
  315. .tf_load = ata_tf_load,
  316. .tf_read = ata_tf_read,
  317. .check_status = ata_check_status,
  318. .exec_command = ata_exec_command,
  319. .dev_select = ata_std_dev_select,
  320. .freeze = ata_bmdma_freeze,
  321. .thaw = ata_bmdma_thaw,
  322. .error_handler = artop6260_error_handler,
  323. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  324. .bmdma_setup = ata_bmdma_setup,
  325. .bmdma_start = ata_bmdma_start,
  326. .bmdma_stop = ata_bmdma_stop,
  327. .bmdma_status = ata_bmdma_status,
  328. .qc_prep = ata_qc_prep,
  329. .qc_issue = ata_qc_issue_prot,
  330. .data_xfer = ata_pio_data_xfer,
  331. .eng_timeout = ata_eng_timeout,
  332. .irq_handler = ata_interrupt,
  333. .irq_clear = ata_bmdma_irq_clear,
  334. .port_start = ata_port_start,
  335. .port_stop = ata_port_stop,
  336. .host_stop = ata_host_stop,
  337. };
  338. /**
  339. * artop_init_one - Register ARTOP ATA PCI device with kernel services
  340. * @pdev: PCI device to register
  341. * @ent: Entry in artop_pci_tbl matching with @pdev
  342. *
  343. * Called from kernel PCI layer.
  344. *
  345. * LOCKING:
  346. * Inherited from PCI layer (may sleep).
  347. *
  348. * RETURNS:
  349. * Zero on success, or -ERRNO value.
  350. */
  351. static int artop_init_one (struct pci_dev *pdev, const struct pci_device_id *id)
  352. {
  353. static int printed_version;
  354. static struct ata_port_info info_6210 = {
  355. .sht = &artop_sht,
  356. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  357. .pio_mask = 0x1f, /* pio0-4 */
  358. .mwdma_mask = 0x07, /* mwdma0-2 */
  359. .udma_mask = ATA_UDMA2,
  360. .port_ops = &artop6210_ops,
  361. };
  362. static struct ata_port_info info_626x = {
  363. .sht = &artop_sht,
  364. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  365. .pio_mask = 0x1f, /* pio0-4 */
  366. .mwdma_mask = 0x07, /* mwdma0-2 */
  367. .udma_mask = ATA_UDMA4,
  368. .port_ops = &artop6260_ops,
  369. };
  370. static struct ata_port_info info_626x_fast = {
  371. .sht = &artop_sht,
  372. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  373. .pio_mask = 0x1f, /* pio0-4 */
  374. .mwdma_mask = 0x07, /* mwdma0-2 */
  375. .udma_mask = ATA_UDMA5,
  376. .port_ops = &artop6260_ops,
  377. };
  378. struct ata_port_info *port_info[2];
  379. struct ata_port_info *info;
  380. int ports = 2;
  381. if (!printed_version++)
  382. dev_printk(KERN_DEBUG, &pdev->dev,
  383. "version " DRV_VERSION "\n");
  384. if (id->driver_data == 0) { /* 6210 variant */
  385. info = &info_6210;
  386. /* BIOS may have left us in UDMA, clear it before libata probe */
  387. pci_write_config_byte(pdev, 0x54, 0);
  388. /* For the moment (also lacks dsc) */
  389. printk(KERN_WARNING "ARTOP 6210 requires serialize functionality not yet supported by libata.\n");
  390. printk(KERN_WARNING "Secondary ATA ports will not be activated.\n");
  391. ports = 1;
  392. }
  393. else if (id->driver_data == 1) /* 6260 */
  394. info = &info_626x;
  395. else if (id->driver_data == 2) { /* 6260 or 6260 + fast */
  396. unsigned long io = pci_resource_start(pdev, 4);
  397. u8 reg;
  398. info = &info_626x;
  399. if (inb(io) & 0x10)
  400. info = &info_626x_fast;
  401. /* Mac systems come up with some registers not set as we
  402. will need them */
  403. /* Clear reset & test bits */
  404. pci_read_config_byte(pdev, 0x49, &reg);
  405. pci_write_config_byte(pdev, 0x49, reg & ~ 0x30);
  406. /* PCI latency must be > 0x80 for burst mode, tweak it
  407. * if required.
  408. */
  409. pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &reg);
  410. if (reg <= 0x80)
  411. pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x90);
  412. /* Enable IRQ output and burst mode */
  413. pci_read_config_byte(pdev, 0x4a, &reg);
  414. pci_write_config_byte(pdev, 0x4a, (reg & ~0x01) | 0x80);
  415. }
  416. port_info[0] = port_info[1] = info;
  417. return ata_pci_init_one(pdev, port_info, ports);
  418. }
  419. static const struct pci_device_id artop_pci_tbl[] = {
  420. { 0x1191, 0x0005, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  421. { 0x1191, 0x0006, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1},
  422. { 0x1191, 0x0007, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1},
  423. { 0x1191, 0x0008, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2},
  424. { 0x1191, 0x0009, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2},
  425. { } /* terminate list */
  426. };
  427. static struct pci_driver artop_pci_driver = {
  428. .name = DRV_NAME,
  429. .id_table = artop_pci_tbl,
  430. .probe = artop_init_one,
  431. .remove = ata_pci_remove_one,
  432. };
  433. static int __init artop_init(void)
  434. {
  435. return pci_register_driver(&artop_pci_driver);
  436. }
  437. static void __exit artop_exit(void)
  438. {
  439. pci_unregister_driver(&artop_pci_driver);
  440. }
  441. module_init(artop_init);
  442. module_exit(artop_exit);
  443. MODULE_AUTHOR("Alan Cox");
  444. MODULE_DESCRIPTION("SCSI low-level driver for ARTOP PATA");
  445. MODULE_LICENSE("GPL");
  446. MODULE_DEVICE_TABLE(pci, artop_pci_tbl);
  447. MODULE_VERSION(DRV_VERSION);