pata_amd.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  1. /*
  2. * pata_amd.c - AMD PATA for new ATA layer
  3. * (C) 2005-2006 Red Hat Inc
  4. * Alan Cox <alan@redhat.com>
  5. *
  6. * Based on pata-sil680. Errata information is taken from data sheets
  7. * and the amd74xx.c driver by Vojtech Pavlik. Nvidia SATA devices are
  8. * claimed by sata-nv.c.
  9. *
  10. * TODO:
  11. * Variable system clock when/if it makes sense
  12. * Power management on ports
  13. *
  14. *
  15. * Documentation publically available.
  16. */
  17. #include <linux/kernel.h>
  18. #include <linux/module.h>
  19. #include <linux/pci.h>
  20. #include <linux/init.h>
  21. #include <linux/blkdev.h>
  22. #include <linux/delay.h>
  23. #include <scsi/scsi_host.h>
  24. #include <linux/libata.h>
  25. #define DRV_NAME "pata_amd"
  26. #define DRV_VERSION "0.2.8"
  27. /**
  28. * timing_setup - shared timing computation and load
  29. * @ap: ATA port being set up
  30. * @adev: drive being configured
  31. * @offset: port offset
  32. * @speed: target speed
  33. * @clock: clock multiplier (number of times 33MHz for this part)
  34. *
  35. * Perform the actual timing set up for Nvidia or AMD PATA devices.
  36. * The actual devices vary so they all call into this helper function
  37. * providing the clock multipler and offset (because AMD and Nvidia put
  38. * the ports at different locations).
  39. */
  40. static void timing_setup(struct ata_port *ap, struct ata_device *adev, int offset, int speed, int clock)
  41. {
  42. static const unsigned char amd_cyc2udma[] = {
  43. 6, 6, 5, 4, 0, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 7
  44. };
  45. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  46. struct ata_device *peer = ata_dev_pair(adev);
  47. int dn = ap->port_no * 2 + adev->devno;
  48. struct ata_timing at, apeer;
  49. int T, UT;
  50. const int amd_clock = 33333; /* KHz. */
  51. u8 t;
  52. T = 1000000000 / amd_clock;
  53. UT = T / min_t(int, max_t(int, clock, 1), 2);
  54. if (ata_timing_compute(adev, speed, &at, T, UT) < 0) {
  55. dev_printk(KERN_ERR, &pdev->dev, "unknown mode %d.\n", speed);
  56. return;
  57. }
  58. if (peer) {
  59. /* This may be over conservative */
  60. if (peer->dma_mode) {
  61. ata_timing_compute(peer, peer->dma_mode, &apeer, T, UT);
  62. ata_timing_merge(&apeer, &at, &at, ATA_TIMING_8BIT);
  63. }
  64. ata_timing_compute(peer, peer->pio_mode, &apeer, T, UT);
  65. ata_timing_merge(&apeer, &at, &at, ATA_TIMING_8BIT);
  66. }
  67. if (speed == XFER_UDMA_5 && amd_clock <= 33333) at.udma = 1;
  68. if (speed == XFER_UDMA_6 && amd_clock <= 33333) at.udma = 15;
  69. /*
  70. * Now do the setup work
  71. */
  72. /* Configure the address set up timing */
  73. pci_read_config_byte(pdev, offset + 0x0C, &t);
  74. t = (t & ~(3 << ((3 - dn) << 1))) | ((FIT(at.setup, 1, 4) - 1) << ((3 - dn) << 1));
  75. pci_write_config_byte(pdev, offset + 0x0C , t);
  76. /* Configure the 8bit I/O timing */
  77. pci_write_config_byte(pdev, offset + 0x0E + (1 - (dn >> 1)),
  78. ((FIT(at.act8b, 1, 16) - 1) << 4) | (FIT(at.rec8b, 1, 16) - 1));
  79. /* Drive timing */
  80. pci_write_config_byte(pdev, offset + 0x08 + (3 - dn),
  81. ((FIT(at.active, 1, 16) - 1) << 4) | (FIT(at.recover, 1, 16) - 1));
  82. switch (clock) {
  83. case 1:
  84. t = at.udma ? (0xc0 | (FIT(at.udma, 2, 5) - 2)) : 0x03;
  85. break;
  86. case 2:
  87. t = at.udma ? (0xc0 | amd_cyc2udma[FIT(at.udma, 2, 10)]) : 0x03;
  88. break;
  89. case 3:
  90. t = at.udma ? (0xc0 | amd_cyc2udma[FIT(at.udma, 1, 10)]) : 0x03;
  91. break;
  92. case 4:
  93. t = at.udma ? (0xc0 | amd_cyc2udma[FIT(at.udma, 1, 15)]) : 0x03;
  94. break;
  95. default:
  96. return;
  97. }
  98. /* UDMA timing */
  99. pci_write_config_byte(pdev, offset + 0x10 + (3 - dn), t);
  100. }
  101. /**
  102. * amd_probe_init - cable detection
  103. * @ap: ATA port
  104. *
  105. * Perform cable detection. The BIOS stores this in PCI config
  106. * space for us.
  107. */
  108. static int amd_pre_reset(struct ata_port *ap)
  109. {
  110. static const u32 bitmask[2] = {0x03, 0x0C};
  111. static const struct pci_bits amd_enable_bits[] = {
  112. { 0x40, 1, 0x02, 0x02 },
  113. { 0x40, 1, 0x01, 0x01 }
  114. };
  115. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  116. u8 ata66;
  117. if (!pci_test_config_bits(pdev, &amd_enable_bits[ap->port_no]))
  118. return -ENOENT;
  119. pci_read_config_byte(pdev, 0x42, &ata66);
  120. if (ata66 & bitmask[ap->port_no])
  121. ap->cbl = ATA_CBL_PATA80;
  122. else
  123. ap->cbl = ATA_CBL_PATA40;
  124. return ata_std_prereset(ap);
  125. }
  126. static void amd_error_handler(struct ata_port *ap)
  127. {
  128. return ata_bmdma_drive_eh(ap, amd_pre_reset,
  129. ata_std_softreset, NULL,
  130. ata_std_postreset);
  131. }
  132. static int amd_early_pre_reset(struct ata_port *ap)
  133. {
  134. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  135. static struct pci_bits amd_enable_bits[] = {
  136. { 0x40, 1, 0x02, 0x02 },
  137. { 0x40, 1, 0x01, 0x01 }
  138. };
  139. if (!pci_test_config_bits(pdev, &amd_enable_bits[ap->port_no]))
  140. return -ENOENT;
  141. /* No host side cable detection */
  142. ap->cbl = ATA_CBL_PATA80;
  143. return ata_std_prereset(ap);
  144. }
  145. static void amd_early_error_handler(struct ata_port *ap)
  146. {
  147. ata_bmdma_drive_eh(ap, amd_early_pre_reset,
  148. ata_std_softreset, NULL,
  149. ata_std_postreset);
  150. }
  151. /**
  152. * amd33_set_piomode - set initial PIO mode data
  153. * @ap: ATA interface
  154. * @adev: ATA device
  155. *
  156. * Program the AMD registers for PIO mode.
  157. */
  158. static void amd33_set_piomode(struct ata_port *ap, struct ata_device *adev)
  159. {
  160. timing_setup(ap, adev, 0x40, adev->pio_mode, 1);
  161. }
  162. static void amd66_set_piomode(struct ata_port *ap, struct ata_device *adev)
  163. {
  164. timing_setup(ap, adev, 0x40, adev->pio_mode, 2);
  165. }
  166. static void amd100_set_piomode(struct ata_port *ap, struct ata_device *adev)
  167. {
  168. timing_setup(ap, adev, 0x40, adev->pio_mode, 3);
  169. }
  170. static void amd133_set_piomode(struct ata_port *ap, struct ata_device *adev)
  171. {
  172. timing_setup(ap, adev, 0x40, adev->pio_mode, 4);
  173. }
  174. /**
  175. * amd33_set_dmamode - set initial DMA mode data
  176. * @ap: ATA interface
  177. * @adev: ATA device
  178. *
  179. * Program the MWDMA/UDMA modes for the AMD and Nvidia
  180. * chipset.
  181. */
  182. static void amd33_set_dmamode(struct ata_port *ap, struct ata_device *adev)
  183. {
  184. timing_setup(ap, adev, 0x40, adev->dma_mode, 1);
  185. }
  186. static void amd66_set_dmamode(struct ata_port *ap, struct ata_device *adev)
  187. {
  188. timing_setup(ap, adev, 0x40, adev->dma_mode, 2);
  189. }
  190. static void amd100_set_dmamode(struct ata_port *ap, struct ata_device *adev)
  191. {
  192. timing_setup(ap, adev, 0x40, adev->dma_mode, 3);
  193. }
  194. static void amd133_set_dmamode(struct ata_port *ap, struct ata_device *adev)
  195. {
  196. timing_setup(ap, adev, 0x40, adev->dma_mode, 4);
  197. }
  198. /**
  199. * nv_probe_init - cable detection
  200. * @ap: ATA port
  201. *
  202. * Perform cable detection. The BIOS stores this in PCI config
  203. * space for us.
  204. */
  205. static int nv_pre_reset(struct ata_port *ap) {
  206. static const u8 bitmask[2] = {0x03, 0x0C};
  207. static const struct pci_bits nv_enable_bits[] = {
  208. { 0x50, 1, 0x02, 0x02 },
  209. { 0x50, 1, 0x01, 0x01 }
  210. };
  211. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  212. u8 ata66;
  213. u16 udma;
  214. if (!pci_test_config_bits(pdev, &nv_enable_bits[ap->port_no]))
  215. return -ENOENT;
  216. pci_read_config_byte(pdev, 0x52, &ata66);
  217. if (ata66 & bitmask[ap->port_no])
  218. ap->cbl = ATA_CBL_PATA80;
  219. else
  220. ap->cbl = ATA_CBL_PATA40;
  221. /* We now have to double check because the Nvidia boxes BIOS
  222. doesn't always set the cable bits but does set mode bits */
  223. pci_read_config_word(pdev, 0x62 - 2 * ap->port_no, &udma);
  224. if ((udma & 0xC4) == 0xC4 || (udma & 0xC400) == 0xC400)
  225. ap->cbl = ATA_CBL_PATA80;
  226. return ata_std_prereset(ap);
  227. }
  228. static void nv_error_handler(struct ata_port *ap)
  229. {
  230. ata_bmdma_drive_eh(ap, nv_pre_reset,
  231. ata_std_softreset, NULL,
  232. ata_std_postreset);
  233. }
  234. /**
  235. * nv100_set_piomode - set initial PIO mode data
  236. * @ap: ATA interface
  237. * @adev: ATA device
  238. *
  239. * Program the AMD registers for PIO mode.
  240. */
  241. static void nv100_set_piomode(struct ata_port *ap, struct ata_device *adev)
  242. {
  243. timing_setup(ap, adev, 0x50, adev->pio_mode, 3);
  244. }
  245. static void nv133_set_piomode(struct ata_port *ap, struct ata_device *adev)
  246. {
  247. timing_setup(ap, adev, 0x50, adev->pio_mode, 4);
  248. }
  249. /**
  250. * nv100_set_dmamode - set initial DMA mode data
  251. * @ap: ATA interface
  252. * @adev: ATA device
  253. *
  254. * Program the MWDMA/UDMA modes for the AMD and Nvidia
  255. * chipset.
  256. */
  257. static void nv100_set_dmamode(struct ata_port *ap, struct ata_device *adev)
  258. {
  259. timing_setup(ap, adev, 0x50, adev->dma_mode, 3);
  260. }
  261. static void nv133_set_dmamode(struct ata_port *ap, struct ata_device *adev)
  262. {
  263. timing_setup(ap, adev, 0x50, adev->dma_mode, 4);
  264. }
  265. static struct scsi_host_template amd_sht = {
  266. .module = THIS_MODULE,
  267. .name = DRV_NAME,
  268. .ioctl = ata_scsi_ioctl,
  269. .queuecommand = ata_scsi_queuecmd,
  270. .can_queue = ATA_DEF_QUEUE,
  271. .this_id = ATA_SHT_THIS_ID,
  272. .sg_tablesize = LIBATA_MAX_PRD,
  273. .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
  274. .emulated = ATA_SHT_EMULATED,
  275. .use_clustering = ATA_SHT_USE_CLUSTERING,
  276. .proc_name = DRV_NAME,
  277. .dma_boundary = ATA_DMA_BOUNDARY,
  278. .slave_configure = ata_scsi_slave_config,
  279. .slave_destroy = ata_scsi_slave_destroy,
  280. .bios_param = ata_std_bios_param,
  281. #ifdef CONFIG_PM
  282. .resume = ata_scsi_device_resume,
  283. .suspend = ata_scsi_device_suspend,
  284. #endif
  285. };
  286. static struct ata_port_operations amd33_port_ops = {
  287. .port_disable = ata_port_disable,
  288. .set_piomode = amd33_set_piomode,
  289. .set_dmamode = amd33_set_dmamode,
  290. .mode_filter = ata_pci_default_filter,
  291. .tf_load = ata_tf_load,
  292. .tf_read = ata_tf_read,
  293. .check_status = ata_check_status,
  294. .exec_command = ata_exec_command,
  295. .dev_select = ata_std_dev_select,
  296. .freeze = ata_bmdma_freeze,
  297. .thaw = ata_bmdma_thaw,
  298. .error_handler = amd_early_error_handler,
  299. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  300. .bmdma_setup = ata_bmdma_setup,
  301. .bmdma_start = ata_bmdma_start,
  302. .bmdma_stop = ata_bmdma_stop,
  303. .bmdma_status = ata_bmdma_status,
  304. .qc_prep = ata_qc_prep,
  305. .qc_issue = ata_qc_issue_prot,
  306. .data_xfer = ata_data_xfer,
  307. .irq_handler = ata_interrupt,
  308. .irq_clear = ata_bmdma_irq_clear,
  309. .irq_on = ata_irq_on,
  310. .irq_ack = ata_irq_ack,
  311. .port_start = ata_port_start,
  312. };
  313. static struct ata_port_operations amd66_port_ops = {
  314. .port_disable = ata_port_disable,
  315. .set_piomode = amd66_set_piomode,
  316. .set_dmamode = amd66_set_dmamode,
  317. .mode_filter = ata_pci_default_filter,
  318. .tf_load = ata_tf_load,
  319. .tf_read = ata_tf_read,
  320. .check_status = ata_check_status,
  321. .exec_command = ata_exec_command,
  322. .dev_select = ata_std_dev_select,
  323. .freeze = ata_bmdma_freeze,
  324. .thaw = ata_bmdma_thaw,
  325. .error_handler = amd_early_error_handler,
  326. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  327. .bmdma_setup = ata_bmdma_setup,
  328. .bmdma_start = ata_bmdma_start,
  329. .bmdma_stop = ata_bmdma_stop,
  330. .bmdma_status = ata_bmdma_status,
  331. .qc_prep = ata_qc_prep,
  332. .qc_issue = ata_qc_issue_prot,
  333. .data_xfer = ata_data_xfer,
  334. .irq_handler = ata_interrupt,
  335. .irq_clear = ata_bmdma_irq_clear,
  336. .irq_on = ata_irq_on,
  337. .irq_ack = ata_irq_ack,
  338. .port_start = ata_port_start,
  339. };
  340. static struct ata_port_operations amd100_port_ops = {
  341. .port_disable = ata_port_disable,
  342. .set_piomode = amd100_set_piomode,
  343. .set_dmamode = amd100_set_dmamode,
  344. .mode_filter = ata_pci_default_filter,
  345. .tf_load = ata_tf_load,
  346. .tf_read = ata_tf_read,
  347. .check_status = ata_check_status,
  348. .exec_command = ata_exec_command,
  349. .dev_select = ata_std_dev_select,
  350. .freeze = ata_bmdma_freeze,
  351. .thaw = ata_bmdma_thaw,
  352. .error_handler = amd_error_handler,
  353. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  354. .bmdma_setup = ata_bmdma_setup,
  355. .bmdma_start = ata_bmdma_start,
  356. .bmdma_stop = ata_bmdma_stop,
  357. .bmdma_status = ata_bmdma_status,
  358. .qc_prep = ata_qc_prep,
  359. .qc_issue = ata_qc_issue_prot,
  360. .data_xfer = ata_data_xfer,
  361. .irq_handler = ata_interrupt,
  362. .irq_clear = ata_bmdma_irq_clear,
  363. .irq_on = ata_irq_on,
  364. .irq_ack = ata_irq_ack,
  365. .port_start = ata_port_start,
  366. };
  367. static struct ata_port_operations amd133_port_ops = {
  368. .port_disable = ata_port_disable,
  369. .set_piomode = amd133_set_piomode,
  370. .set_dmamode = amd133_set_dmamode,
  371. .mode_filter = ata_pci_default_filter,
  372. .tf_load = ata_tf_load,
  373. .tf_read = ata_tf_read,
  374. .check_status = ata_check_status,
  375. .exec_command = ata_exec_command,
  376. .dev_select = ata_std_dev_select,
  377. .freeze = ata_bmdma_freeze,
  378. .thaw = ata_bmdma_thaw,
  379. .error_handler = amd_error_handler,
  380. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  381. .bmdma_setup = ata_bmdma_setup,
  382. .bmdma_start = ata_bmdma_start,
  383. .bmdma_stop = ata_bmdma_stop,
  384. .bmdma_status = ata_bmdma_status,
  385. .qc_prep = ata_qc_prep,
  386. .qc_issue = ata_qc_issue_prot,
  387. .data_xfer = ata_data_xfer,
  388. .irq_handler = ata_interrupt,
  389. .irq_clear = ata_bmdma_irq_clear,
  390. .irq_on = ata_irq_on,
  391. .irq_ack = ata_irq_ack,
  392. .port_start = ata_port_start,
  393. };
  394. static struct ata_port_operations nv100_port_ops = {
  395. .port_disable = ata_port_disable,
  396. .set_piomode = nv100_set_piomode,
  397. .set_dmamode = nv100_set_dmamode,
  398. .mode_filter = ata_pci_default_filter,
  399. .tf_load = ata_tf_load,
  400. .tf_read = ata_tf_read,
  401. .check_status = ata_check_status,
  402. .exec_command = ata_exec_command,
  403. .dev_select = ata_std_dev_select,
  404. .freeze = ata_bmdma_freeze,
  405. .thaw = ata_bmdma_thaw,
  406. .error_handler = nv_error_handler,
  407. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  408. .bmdma_setup = ata_bmdma_setup,
  409. .bmdma_start = ata_bmdma_start,
  410. .bmdma_stop = ata_bmdma_stop,
  411. .bmdma_status = ata_bmdma_status,
  412. .qc_prep = ata_qc_prep,
  413. .qc_issue = ata_qc_issue_prot,
  414. .data_xfer = ata_data_xfer,
  415. .irq_handler = ata_interrupt,
  416. .irq_clear = ata_bmdma_irq_clear,
  417. .irq_on = ata_irq_on,
  418. .irq_ack = ata_irq_ack,
  419. .port_start = ata_port_start,
  420. };
  421. static struct ata_port_operations nv133_port_ops = {
  422. .port_disable = ata_port_disable,
  423. .set_piomode = nv133_set_piomode,
  424. .set_dmamode = nv133_set_dmamode,
  425. .mode_filter = ata_pci_default_filter,
  426. .tf_load = ata_tf_load,
  427. .tf_read = ata_tf_read,
  428. .check_status = ata_check_status,
  429. .exec_command = ata_exec_command,
  430. .dev_select = ata_std_dev_select,
  431. .freeze = ata_bmdma_freeze,
  432. .thaw = ata_bmdma_thaw,
  433. .error_handler = nv_error_handler,
  434. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  435. .bmdma_setup = ata_bmdma_setup,
  436. .bmdma_start = ata_bmdma_start,
  437. .bmdma_stop = ata_bmdma_stop,
  438. .bmdma_status = ata_bmdma_status,
  439. .qc_prep = ata_qc_prep,
  440. .qc_issue = ata_qc_issue_prot,
  441. .data_xfer = ata_data_xfer,
  442. .irq_handler = ata_interrupt,
  443. .irq_clear = ata_bmdma_irq_clear,
  444. .irq_on = ata_irq_on,
  445. .irq_ack = ata_irq_ack,
  446. .port_start = ata_port_start,
  447. };
  448. static int amd_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
  449. {
  450. static struct ata_port_info info[10] = {
  451. { /* 0: AMD 7401 */
  452. .sht = &amd_sht,
  453. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  454. .pio_mask = 0x1f,
  455. .mwdma_mask = 0x07, /* No SWDMA */
  456. .udma_mask = 0x07, /* UDMA 33 */
  457. .port_ops = &amd33_port_ops
  458. },
  459. { /* 1: Early AMD7409 - no swdma */
  460. .sht = &amd_sht,
  461. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  462. .pio_mask = 0x1f,
  463. .mwdma_mask = 0x07,
  464. .udma_mask = 0x1f, /* UDMA 66 */
  465. .port_ops = &amd66_port_ops
  466. },
  467. { /* 2: AMD 7409, no swdma errata */
  468. .sht = &amd_sht,
  469. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  470. .pio_mask = 0x1f,
  471. .mwdma_mask = 0x07,
  472. .udma_mask = 0x1f, /* UDMA 66 */
  473. .port_ops = &amd66_port_ops
  474. },
  475. { /* 3: AMD 7411 */
  476. .sht = &amd_sht,
  477. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  478. .pio_mask = 0x1f,
  479. .mwdma_mask = 0x07,
  480. .udma_mask = 0x3f, /* UDMA 100 */
  481. .port_ops = &amd100_port_ops
  482. },
  483. { /* 4: AMD 7441 */
  484. .sht = &amd_sht,
  485. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  486. .pio_mask = 0x1f,
  487. .mwdma_mask = 0x07,
  488. .udma_mask = 0x3f, /* UDMA 100 */
  489. .port_ops = &amd100_port_ops
  490. },
  491. { /* 5: AMD 8111*/
  492. .sht = &amd_sht,
  493. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  494. .pio_mask = 0x1f,
  495. .mwdma_mask = 0x07,
  496. .udma_mask = 0x7f, /* UDMA 133, no swdma */
  497. .port_ops = &amd133_port_ops
  498. },
  499. { /* 6: AMD 8111 UDMA 100 (Serenade) */
  500. .sht = &amd_sht,
  501. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  502. .pio_mask = 0x1f,
  503. .mwdma_mask = 0x07,
  504. .udma_mask = 0x3f, /* UDMA 100, no swdma */
  505. .port_ops = &amd133_port_ops
  506. },
  507. { /* 7: Nvidia Nforce */
  508. .sht = &amd_sht,
  509. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  510. .pio_mask = 0x1f,
  511. .mwdma_mask = 0x07,
  512. .udma_mask = 0x3f, /* UDMA 100 */
  513. .port_ops = &nv100_port_ops
  514. },
  515. { /* 8: Nvidia Nforce2 and later */
  516. .sht = &amd_sht,
  517. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  518. .pio_mask = 0x1f,
  519. .mwdma_mask = 0x07,
  520. .udma_mask = 0x7f, /* UDMA 133, no swdma */
  521. .port_ops = &nv133_port_ops
  522. },
  523. { /* 9: AMD CS5536 (Geode companion) */
  524. .sht = &amd_sht,
  525. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  526. .pio_mask = 0x1f,
  527. .mwdma_mask = 0x07,
  528. .udma_mask = 0x3f, /* UDMA 100 */
  529. .port_ops = &amd100_port_ops
  530. }
  531. };
  532. static struct ata_port_info *port_info[2];
  533. static int printed_version;
  534. int type = id->driver_data;
  535. u8 rev;
  536. u8 fifo;
  537. if (!printed_version++)
  538. dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
  539. pci_read_config_byte(pdev, PCI_REVISION_ID, &rev);
  540. pci_read_config_byte(pdev, 0x41, &fifo);
  541. /* Check for AMD7409 without swdma errata and if found adjust type */
  542. if (type == 1 && rev > 0x7)
  543. type = 2;
  544. /* Check for AMD7411 */
  545. if (type == 3)
  546. /* FIFO is broken */
  547. pci_write_config_byte(pdev, 0x41, fifo & 0x0F);
  548. else
  549. pci_write_config_byte(pdev, 0x41, fifo | 0xF0);
  550. /* Serenade ? */
  551. if (type == 5 && pdev->subsystem_vendor == PCI_VENDOR_ID_AMD &&
  552. pdev->subsystem_device == PCI_DEVICE_ID_AMD_SERENADE)
  553. type = 6; /* UDMA 100 only */
  554. if (type < 3)
  555. ata_pci_clear_simplex(pdev);
  556. /* And fire it up */
  557. port_info[0] = port_info[1] = &info[type];
  558. return ata_pci_init_one(pdev, port_info, 2);
  559. }
  560. #ifdef CONFIG_PM
  561. static int amd_reinit_one(struct pci_dev *pdev)
  562. {
  563. if (pdev->vendor == PCI_VENDOR_ID_AMD) {
  564. u8 fifo;
  565. pci_read_config_byte(pdev, 0x41, &fifo);
  566. if (pdev->device == PCI_DEVICE_ID_AMD_VIPER_7411)
  567. /* FIFO is broken */
  568. pci_write_config_byte(pdev, 0x41, fifo & 0x0F);
  569. else
  570. pci_write_config_byte(pdev, 0x41, fifo | 0xF0);
  571. if (pdev->device == PCI_DEVICE_ID_AMD_VIPER_7409 ||
  572. pdev->device == PCI_DEVICE_ID_AMD_COBRA_7401)
  573. ata_pci_clear_simplex(pdev);
  574. }
  575. return ata_pci_device_resume(pdev);
  576. }
  577. #endif
  578. static const struct pci_device_id amd[] = {
  579. { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_COBRA_7401), 0 },
  580. { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_VIPER_7409), 1 },
  581. { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_VIPER_7411), 3 },
  582. { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_OPUS_7441), 4 },
  583. { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_8111_IDE), 5 },
  584. { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_IDE), 7 },
  585. { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2_IDE), 8 },
  586. { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2S_IDE), 8 },
  587. { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3_IDE), 8 },
  588. { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3S_IDE), 8 },
  589. { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_CK804_IDE), 8 },
  590. { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP04_IDE), 8 },
  591. { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_IDE), 8 },
  592. { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_IDE), 8 },
  593. { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_IDE), 8 },
  594. { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP65_IDE), 8 },
  595. { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP67_IDE), 8 },
  596. { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_CS5536_IDE), 9 },
  597. { },
  598. };
  599. static struct pci_driver amd_pci_driver = {
  600. .name = DRV_NAME,
  601. .id_table = amd,
  602. .probe = amd_init_one,
  603. .remove = ata_pci_remove_one,
  604. #ifdef CONFIG_PM
  605. .suspend = ata_pci_device_suspend,
  606. .resume = amd_reinit_one,
  607. #endif
  608. };
  609. static int __init amd_init(void)
  610. {
  611. return pci_register_driver(&amd_pci_driver);
  612. }
  613. static void __exit amd_exit(void)
  614. {
  615. pci_unregister_driver(&amd_pci_driver);
  616. }
  617. MODULE_AUTHOR("Alan Cox");
  618. MODULE_DESCRIPTION("low-level driver for AMD PATA IDE");
  619. MODULE_LICENSE("GPL");
  620. MODULE_DEVICE_TABLE(pci, amd);
  621. MODULE_VERSION(DRV_VERSION);
  622. module_init(amd_init);
  623. module_exit(amd_exit);