pata_amd.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  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.3.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 - perform reset handling
  103. * @ap: ATA port
  104. * @deadline: deadline jiffies for the operation
  105. *
  106. * Reset sequence checking enable bits to see which ports are
  107. * active.
  108. */
  109. static int amd_pre_reset(struct ata_port *ap, unsigned long deadline)
  110. {
  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. if (!pci_test_config_bits(pdev, &amd_enable_bits[ap->port_no]))
  117. return -ENOENT;
  118. return ata_std_prereset(ap, deadline);
  119. }
  120. static void amd_error_handler(struct ata_port *ap)
  121. {
  122. return ata_bmdma_drive_eh(ap, amd_pre_reset,
  123. ata_std_softreset, NULL,
  124. ata_std_postreset);
  125. }
  126. static int amd_cable_detect(struct ata_port *ap)
  127. {
  128. static const u32 bitmask[2] = {0x03, 0x0C};
  129. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  130. u8 ata66;
  131. pci_read_config_byte(pdev, 0x42, &ata66);
  132. if (ata66 & bitmask[ap->port_no])
  133. return ATA_CBL_PATA80;
  134. return ATA_CBL_PATA40;
  135. }
  136. /**
  137. * amd33_set_piomode - set initial PIO mode data
  138. * @ap: ATA interface
  139. * @adev: ATA device
  140. *
  141. * Program the AMD registers for PIO mode.
  142. */
  143. static void amd33_set_piomode(struct ata_port *ap, struct ata_device *adev)
  144. {
  145. timing_setup(ap, adev, 0x40, adev->pio_mode, 1);
  146. }
  147. static void amd66_set_piomode(struct ata_port *ap, struct ata_device *adev)
  148. {
  149. timing_setup(ap, adev, 0x40, adev->pio_mode, 2);
  150. }
  151. static void amd100_set_piomode(struct ata_port *ap, struct ata_device *adev)
  152. {
  153. timing_setup(ap, adev, 0x40, adev->pio_mode, 3);
  154. }
  155. static void amd133_set_piomode(struct ata_port *ap, struct ata_device *adev)
  156. {
  157. timing_setup(ap, adev, 0x40, adev->pio_mode, 4);
  158. }
  159. /**
  160. * amd33_set_dmamode - set initial DMA mode data
  161. * @ap: ATA interface
  162. * @adev: ATA device
  163. *
  164. * Program the MWDMA/UDMA modes for the AMD and Nvidia
  165. * chipset.
  166. */
  167. static void amd33_set_dmamode(struct ata_port *ap, struct ata_device *adev)
  168. {
  169. timing_setup(ap, adev, 0x40, adev->dma_mode, 1);
  170. }
  171. static void amd66_set_dmamode(struct ata_port *ap, struct ata_device *adev)
  172. {
  173. timing_setup(ap, adev, 0x40, adev->dma_mode, 2);
  174. }
  175. static void amd100_set_dmamode(struct ata_port *ap, struct ata_device *adev)
  176. {
  177. timing_setup(ap, adev, 0x40, adev->dma_mode, 3);
  178. }
  179. static void amd133_set_dmamode(struct ata_port *ap, struct ata_device *adev)
  180. {
  181. timing_setup(ap, adev, 0x40, adev->dma_mode, 4);
  182. }
  183. /**
  184. * nv_probe_init - cable detection
  185. * @ap: ATA port
  186. *
  187. * Perform cable detection. The BIOS stores this in PCI config
  188. * space for us.
  189. */
  190. static int nv_pre_reset(struct ata_port *ap, unsigned long deadline)
  191. {
  192. static const struct pci_bits nv_enable_bits[] = {
  193. { 0x50, 1, 0x02, 0x02 },
  194. { 0x50, 1, 0x01, 0x01 }
  195. };
  196. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  197. if (!pci_test_config_bits(pdev, &nv_enable_bits[ap->port_no]))
  198. return -ENOENT;
  199. return ata_std_prereset(ap, deadline);
  200. }
  201. static void nv_error_handler(struct ata_port *ap)
  202. {
  203. ata_bmdma_drive_eh(ap, nv_pre_reset,
  204. ata_std_softreset, NULL,
  205. ata_std_postreset);
  206. }
  207. static int nv_cable_detect(struct ata_port *ap)
  208. {
  209. static const u8 bitmask[2] = {0x03, 0x0C};
  210. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  211. u8 ata66;
  212. u16 udma;
  213. int cbl;
  214. pci_read_config_byte(pdev, 0x52, &ata66);
  215. if (ata66 & bitmask[ap->port_no])
  216. cbl = ATA_CBL_PATA80;
  217. else
  218. cbl = ATA_CBL_PATA40;
  219. /* We now have to double check because the Nvidia boxes BIOS
  220. doesn't always set the cable bits but does set mode bits */
  221. pci_read_config_word(pdev, 0x62 - 2 * ap->port_no, &udma);
  222. if ((udma & 0xC4) == 0xC4 || (udma & 0xC400) == 0xC400)
  223. cbl = ATA_CBL_PATA80;
  224. return cbl;
  225. }
  226. /**
  227. * nv100_set_piomode - set initial PIO mode data
  228. * @ap: ATA interface
  229. * @adev: ATA device
  230. *
  231. * Program the AMD registers for PIO mode.
  232. */
  233. static void nv100_set_piomode(struct ata_port *ap, struct ata_device *adev)
  234. {
  235. timing_setup(ap, adev, 0x50, adev->pio_mode, 3);
  236. }
  237. static void nv133_set_piomode(struct ata_port *ap, struct ata_device *adev)
  238. {
  239. timing_setup(ap, adev, 0x50, adev->pio_mode, 4);
  240. }
  241. /**
  242. * nv100_set_dmamode - set initial DMA mode data
  243. * @ap: ATA interface
  244. * @adev: ATA device
  245. *
  246. * Program the MWDMA/UDMA modes for the AMD and Nvidia
  247. * chipset.
  248. */
  249. static void nv100_set_dmamode(struct ata_port *ap, struct ata_device *adev)
  250. {
  251. timing_setup(ap, adev, 0x50, adev->dma_mode, 3);
  252. }
  253. static void nv133_set_dmamode(struct ata_port *ap, struct ata_device *adev)
  254. {
  255. timing_setup(ap, adev, 0x50, adev->dma_mode, 4);
  256. }
  257. static struct scsi_host_template amd_sht = {
  258. .module = THIS_MODULE,
  259. .name = DRV_NAME,
  260. .ioctl = ata_scsi_ioctl,
  261. .queuecommand = ata_scsi_queuecmd,
  262. .can_queue = ATA_DEF_QUEUE,
  263. .this_id = ATA_SHT_THIS_ID,
  264. .sg_tablesize = LIBATA_MAX_PRD,
  265. .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
  266. .emulated = ATA_SHT_EMULATED,
  267. .use_clustering = ATA_SHT_USE_CLUSTERING,
  268. .proc_name = DRV_NAME,
  269. .dma_boundary = ATA_DMA_BOUNDARY,
  270. .slave_configure = ata_scsi_slave_config,
  271. .slave_destroy = ata_scsi_slave_destroy,
  272. .bios_param = ata_std_bios_param,
  273. };
  274. static struct ata_port_operations amd33_port_ops = {
  275. .port_disable = ata_port_disable,
  276. .set_piomode = amd33_set_piomode,
  277. .set_dmamode = amd33_set_dmamode,
  278. .mode_filter = ata_pci_default_filter,
  279. .tf_load = ata_tf_load,
  280. .tf_read = ata_tf_read,
  281. .check_status = ata_check_status,
  282. .exec_command = ata_exec_command,
  283. .dev_select = ata_std_dev_select,
  284. .freeze = ata_bmdma_freeze,
  285. .thaw = ata_bmdma_thaw,
  286. .error_handler = amd_error_handler,
  287. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  288. .cable_detect = ata_cable_40wire,
  289. .bmdma_setup = ata_bmdma_setup,
  290. .bmdma_start = ata_bmdma_start,
  291. .bmdma_stop = ata_bmdma_stop,
  292. .bmdma_status = ata_bmdma_status,
  293. .qc_prep = ata_qc_prep,
  294. .qc_issue = ata_qc_issue_prot,
  295. .data_xfer = ata_data_xfer,
  296. .irq_handler = ata_interrupt,
  297. .irq_clear = ata_bmdma_irq_clear,
  298. .irq_on = ata_irq_on,
  299. .irq_ack = ata_irq_ack,
  300. .port_start = ata_port_start,
  301. };
  302. static struct ata_port_operations amd66_port_ops = {
  303. .port_disable = ata_port_disable,
  304. .set_piomode = amd66_set_piomode,
  305. .set_dmamode = amd66_set_dmamode,
  306. .mode_filter = ata_pci_default_filter,
  307. .tf_load = ata_tf_load,
  308. .tf_read = ata_tf_read,
  309. .check_status = ata_check_status,
  310. .exec_command = ata_exec_command,
  311. .dev_select = ata_std_dev_select,
  312. .freeze = ata_bmdma_freeze,
  313. .thaw = ata_bmdma_thaw,
  314. .error_handler = amd_error_handler,
  315. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  316. .cable_detect = ata_cable_unknown,
  317. .bmdma_setup = ata_bmdma_setup,
  318. .bmdma_start = ata_bmdma_start,
  319. .bmdma_stop = ata_bmdma_stop,
  320. .bmdma_status = ata_bmdma_status,
  321. .qc_prep = ata_qc_prep,
  322. .qc_issue = ata_qc_issue_prot,
  323. .data_xfer = ata_data_xfer,
  324. .irq_handler = ata_interrupt,
  325. .irq_clear = ata_bmdma_irq_clear,
  326. .irq_on = ata_irq_on,
  327. .irq_ack = ata_irq_ack,
  328. .port_start = ata_port_start,
  329. };
  330. static struct ata_port_operations amd100_port_ops = {
  331. .port_disable = ata_port_disable,
  332. .set_piomode = amd100_set_piomode,
  333. .set_dmamode = amd100_set_dmamode,
  334. .mode_filter = ata_pci_default_filter,
  335. .tf_load = ata_tf_load,
  336. .tf_read = ata_tf_read,
  337. .check_status = ata_check_status,
  338. .exec_command = ata_exec_command,
  339. .dev_select = ata_std_dev_select,
  340. .freeze = ata_bmdma_freeze,
  341. .thaw = ata_bmdma_thaw,
  342. .error_handler = amd_error_handler,
  343. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  344. .cable_detect = ata_cable_unknown,
  345. .bmdma_setup = ata_bmdma_setup,
  346. .bmdma_start = ata_bmdma_start,
  347. .bmdma_stop = ata_bmdma_stop,
  348. .bmdma_status = ata_bmdma_status,
  349. .qc_prep = ata_qc_prep,
  350. .qc_issue = ata_qc_issue_prot,
  351. .data_xfer = ata_data_xfer,
  352. .irq_handler = ata_interrupt,
  353. .irq_clear = ata_bmdma_irq_clear,
  354. .irq_on = ata_irq_on,
  355. .irq_ack = ata_irq_ack,
  356. .port_start = ata_port_start,
  357. };
  358. static struct ata_port_operations amd133_port_ops = {
  359. .port_disable = ata_port_disable,
  360. .set_piomode = amd133_set_piomode,
  361. .set_dmamode = amd133_set_dmamode,
  362. .mode_filter = ata_pci_default_filter,
  363. .tf_load = ata_tf_load,
  364. .tf_read = ata_tf_read,
  365. .check_status = ata_check_status,
  366. .exec_command = ata_exec_command,
  367. .dev_select = ata_std_dev_select,
  368. .freeze = ata_bmdma_freeze,
  369. .thaw = ata_bmdma_thaw,
  370. .error_handler = amd_error_handler,
  371. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  372. .cable_detect = amd_cable_detect,
  373. .bmdma_setup = ata_bmdma_setup,
  374. .bmdma_start = ata_bmdma_start,
  375. .bmdma_stop = ata_bmdma_stop,
  376. .bmdma_status = ata_bmdma_status,
  377. .qc_prep = ata_qc_prep,
  378. .qc_issue = ata_qc_issue_prot,
  379. .data_xfer = ata_data_xfer,
  380. .irq_handler = ata_interrupt,
  381. .irq_clear = ata_bmdma_irq_clear,
  382. .irq_on = ata_irq_on,
  383. .irq_ack = ata_irq_ack,
  384. .port_start = ata_port_start,
  385. };
  386. static struct ata_port_operations nv100_port_ops = {
  387. .port_disable = ata_port_disable,
  388. .set_piomode = nv100_set_piomode,
  389. .set_dmamode = nv100_set_dmamode,
  390. .mode_filter = ata_pci_default_filter,
  391. .tf_load = ata_tf_load,
  392. .tf_read = ata_tf_read,
  393. .check_status = ata_check_status,
  394. .exec_command = ata_exec_command,
  395. .dev_select = ata_std_dev_select,
  396. .freeze = ata_bmdma_freeze,
  397. .thaw = ata_bmdma_thaw,
  398. .error_handler = nv_error_handler,
  399. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  400. .cable_detect = nv_cable_detect,
  401. .bmdma_setup = ata_bmdma_setup,
  402. .bmdma_start = ata_bmdma_start,
  403. .bmdma_stop = ata_bmdma_stop,
  404. .bmdma_status = ata_bmdma_status,
  405. .qc_prep = ata_qc_prep,
  406. .qc_issue = ata_qc_issue_prot,
  407. .data_xfer = ata_data_xfer,
  408. .irq_handler = ata_interrupt,
  409. .irq_clear = ata_bmdma_irq_clear,
  410. .irq_on = ata_irq_on,
  411. .irq_ack = ata_irq_ack,
  412. .port_start = ata_port_start,
  413. };
  414. static struct ata_port_operations nv133_port_ops = {
  415. .port_disable = ata_port_disable,
  416. .set_piomode = nv133_set_piomode,
  417. .set_dmamode = nv133_set_dmamode,
  418. .mode_filter = ata_pci_default_filter,
  419. .tf_load = ata_tf_load,
  420. .tf_read = ata_tf_read,
  421. .check_status = ata_check_status,
  422. .exec_command = ata_exec_command,
  423. .dev_select = ata_std_dev_select,
  424. .freeze = ata_bmdma_freeze,
  425. .thaw = ata_bmdma_thaw,
  426. .error_handler = nv_error_handler,
  427. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  428. .cable_detect = nv_cable_detect,
  429. .bmdma_setup = ata_bmdma_setup,
  430. .bmdma_start = ata_bmdma_start,
  431. .bmdma_stop = ata_bmdma_stop,
  432. .bmdma_status = ata_bmdma_status,
  433. .qc_prep = ata_qc_prep,
  434. .qc_issue = ata_qc_issue_prot,
  435. .data_xfer = ata_data_xfer,
  436. .irq_handler = ata_interrupt,
  437. .irq_clear = ata_bmdma_irq_clear,
  438. .irq_on = ata_irq_on,
  439. .irq_ack = ata_irq_ack,
  440. .port_start = ata_port_start,
  441. };
  442. static int amd_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
  443. {
  444. static const struct ata_port_info info[10] = {
  445. { /* 0: AMD 7401 */
  446. .sht = &amd_sht,
  447. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  448. .pio_mask = 0x1f,
  449. .mwdma_mask = 0x07, /* No SWDMA */
  450. .udma_mask = 0x07, /* UDMA 33 */
  451. .port_ops = &amd33_port_ops
  452. },
  453. { /* 1: Early AMD7409 - no swdma */
  454. .sht = &amd_sht,
  455. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  456. .pio_mask = 0x1f,
  457. .mwdma_mask = 0x07,
  458. .udma_mask = 0x1f, /* UDMA 66 */
  459. .port_ops = &amd66_port_ops
  460. },
  461. { /* 2: AMD 7409, no swdma errata */
  462. .sht = &amd_sht,
  463. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  464. .pio_mask = 0x1f,
  465. .mwdma_mask = 0x07,
  466. .udma_mask = 0x1f, /* UDMA 66 */
  467. .port_ops = &amd66_port_ops
  468. },
  469. { /* 3: AMD 7411 */
  470. .sht = &amd_sht,
  471. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  472. .pio_mask = 0x1f,
  473. .mwdma_mask = 0x07,
  474. .udma_mask = 0x3f, /* UDMA 100 */
  475. .port_ops = &amd100_port_ops
  476. },
  477. { /* 4: AMD 7441 */
  478. .sht = &amd_sht,
  479. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  480. .pio_mask = 0x1f,
  481. .mwdma_mask = 0x07,
  482. .udma_mask = 0x3f, /* UDMA 100 */
  483. .port_ops = &amd100_port_ops
  484. },
  485. { /* 5: AMD 8111*/
  486. .sht = &amd_sht,
  487. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  488. .pio_mask = 0x1f,
  489. .mwdma_mask = 0x07,
  490. .udma_mask = 0x7f, /* UDMA 133, no swdma */
  491. .port_ops = &amd133_port_ops
  492. },
  493. { /* 6: AMD 8111 UDMA 100 (Serenade) */
  494. .sht = &amd_sht,
  495. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  496. .pio_mask = 0x1f,
  497. .mwdma_mask = 0x07,
  498. .udma_mask = 0x3f, /* UDMA 100, no swdma */
  499. .port_ops = &amd133_port_ops
  500. },
  501. { /* 7: Nvidia Nforce */
  502. .sht = &amd_sht,
  503. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  504. .pio_mask = 0x1f,
  505. .mwdma_mask = 0x07,
  506. .udma_mask = 0x3f, /* UDMA 100 */
  507. .port_ops = &nv100_port_ops
  508. },
  509. { /* 8: Nvidia Nforce2 and later */
  510. .sht = &amd_sht,
  511. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  512. .pio_mask = 0x1f,
  513. .mwdma_mask = 0x07,
  514. .udma_mask = 0x7f, /* UDMA 133, no swdma */
  515. .port_ops = &nv133_port_ops
  516. },
  517. { /* 9: AMD CS5536 (Geode companion) */
  518. .sht = &amd_sht,
  519. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  520. .pio_mask = 0x1f,
  521. .mwdma_mask = 0x07,
  522. .udma_mask = 0x3f, /* UDMA 100 */
  523. .port_ops = &amd100_port_ops
  524. }
  525. };
  526. const struct ata_port_info *ppi[] = { NULL, NULL };
  527. static int printed_version;
  528. int type = id->driver_data;
  529. u8 rev;
  530. u8 fifo;
  531. if (!printed_version++)
  532. dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
  533. pci_read_config_byte(pdev, PCI_REVISION_ID, &rev);
  534. pci_read_config_byte(pdev, 0x41, &fifo);
  535. /* Check for AMD7409 without swdma errata and if found adjust type */
  536. if (type == 1 && rev > 0x7)
  537. type = 2;
  538. /* Check for AMD7411 */
  539. if (type == 3)
  540. /* FIFO is broken */
  541. pci_write_config_byte(pdev, 0x41, fifo & 0x0F);
  542. else
  543. pci_write_config_byte(pdev, 0x41, fifo | 0xF0);
  544. /* Serenade ? */
  545. if (type == 5 && pdev->subsystem_vendor == PCI_VENDOR_ID_AMD &&
  546. pdev->subsystem_device == PCI_DEVICE_ID_AMD_SERENADE)
  547. type = 6; /* UDMA 100 only */
  548. if (type < 3)
  549. ata_pci_clear_simplex(pdev);
  550. /* And fire it up */
  551. ppi[0] = &info[type];
  552. return ata_pci_init_one(pdev, ppi);
  553. }
  554. #ifdef CONFIG_PM
  555. static int amd_reinit_one(struct pci_dev *pdev)
  556. {
  557. if (pdev->vendor == PCI_VENDOR_ID_AMD) {
  558. u8 fifo;
  559. pci_read_config_byte(pdev, 0x41, &fifo);
  560. if (pdev->device == PCI_DEVICE_ID_AMD_VIPER_7411)
  561. /* FIFO is broken */
  562. pci_write_config_byte(pdev, 0x41, fifo & 0x0F);
  563. else
  564. pci_write_config_byte(pdev, 0x41, fifo | 0xF0);
  565. if (pdev->device == PCI_DEVICE_ID_AMD_VIPER_7409 ||
  566. pdev->device == PCI_DEVICE_ID_AMD_COBRA_7401)
  567. ata_pci_clear_simplex(pdev);
  568. }
  569. return ata_pci_device_resume(pdev);
  570. }
  571. #endif
  572. static const struct pci_device_id amd[] = {
  573. { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_COBRA_7401), 0 },
  574. { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_VIPER_7409), 1 },
  575. { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_VIPER_7411), 3 },
  576. { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_OPUS_7441), 4 },
  577. { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_8111_IDE), 5 },
  578. { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_IDE), 7 },
  579. { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2_IDE), 8 },
  580. { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2S_IDE), 8 },
  581. { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3_IDE), 8 },
  582. { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3S_IDE), 8 },
  583. { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_CK804_IDE), 8 },
  584. { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP04_IDE), 8 },
  585. { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_IDE), 8 },
  586. { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_IDE), 8 },
  587. { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_IDE), 8 },
  588. { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP65_IDE), 8 },
  589. { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP67_IDE), 8 },
  590. { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_CS5536_IDE), 9 },
  591. { },
  592. };
  593. static struct pci_driver amd_pci_driver = {
  594. .name = DRV_NAME,
  595. .id_table = amd,
  596. .probe = amd_init_one,
  597. .remove = ata_pci_remove_one,
  598. #ifdef CONFIG_PM
  599. .suspend = ata_pci_device_suspend,
  600. .resume = amd_reinit_one,
  601. #endif
  602. };
  603. static int __init amd_init(void)
  604. {
  605. return pci_register_driver(&amd_pci_driver);
  606. }
  607. static void __exit amd_exit(void)
  608. {
  609. pci_unregister_driver(&amd_pci_driver);
  610. }
  611. MODULE_AUTHOR("Alan Cox");
  612. MODULE_DESCRIPTION("low-level driver for AMD PATA IDE");
  613. MODULE_LICENSE("GPL");
  614. MODULE_DEVICE_TABLE(pci, amd);
  615. MODULE_VERSION(DRV_VERSION);
  616. module_init(amd_init);
  617. module_exit(amd_exit);