pata_amd.c 19 KB

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