pata_amd.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781
  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.10"
  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. if (at.udma)
  100. pci_write_config_byte(pdev, offset + 0x10 + (3 - dn), t);
  101. }
  102. /**
  103. * amd_pre_reset - perform reset handling
  104. * @link: ATA link
  105. * @deadline: deadline jiffies for the operation
  106. *
  107. * Reset sequence checking enable bits to see which ports are
  108. * active.
  109. */
  110. static int amd_pre_reset(struct ata_link *link, unsigned long deadline)
  111. {
  112. static const struct pci_bits amd_enable_bits[] = {
  113. { 0x40, 1, 0x02, 0x02 },
  114. { 0x40, 1, 0x01, 0x01 }
  115. };
  116. struct ata_port *ap = link->ap;
  117. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  118. if (!pci_test_config_bits(pdev, &amd_enable_bits[ap->port_no]))
  119. return -ENOENT;
  120. return ata_std_prereset(link, deadline);
  121. }
  122. static void amd_error_handler(struct ata_port *ap)
  123. {
  124. return ata_bmdma_drive_eh(ap, amd_pre_reset,
  125. ata_std_softreset, NULL,
  126. ata_std_postreset);
  127. }
  128. static int amd_cable_detect(struct ata_port *ap)
  129. {
  130. static const u32 bitmask[2] = {0x03, 0x0C};
  131. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  132. u8 ata66;
  133. pci_read_config_byte(pdev, 0x42, &ata66);
  134. if (ata66 & bitmask[ap->port_no])
  135. return ATA_CBL_PATA80;
  136. return ATA_CBL_PATA40;
  137. }
  138. /**
  139. * amd33_set_piomode - set initial PIO mode data
  140. * @ap: ATA interface
  141. * @adev: ATA device
  142. *
  143. * Program the AMD registers for PIO mode.
  144. */
  145. static void amd33_set_piomode(struct ata_port *ap, struct ata_device *adev)
  146. {
  147. timing_setup(ap, adev, 0x40, adev->pio_mode, 1);
  148. }
  149. static void amd66_set_piomode(struct ata_port *ap, struct ata_device *adev)
  150. {
  151. timing_setup(ap, adev, 0x40, adev->pio_mode, 2);
  152. }
  153. static void amd100_set_piomode(struct ata_port *ap, struct ata_device *adev)
  154. {
  155. timing_setup(ap, adev, 0x40, adev->pio_mode, 3);
  156. }
  157. static void amd133_set_piomode(struct ata_port *ap, struct ata_device *adev)
  158. {
  159. timing_setup(ap, adev, 0x40, adev->pio_mode, 4);
  160. }
  161. /**
  162. * amd33_set_dmamode - set initial DMA mode data
  163. * @ap: ATA interface
  164. * @adev: ATA device
  165. *
  166. * Program the MWDMA/UDMA modes for the AMD and Nvidia
  167. * chipset.
  168. */
  169. static void amd33_set_dmamode(struct ata_port *ap, struct ata_device *adev)
  170. {
  171. timing_setup(ap, adev, 0x40, adev->dma_mode, 1);
  172. }
  173. static void amd66_set_dmamode(struct ata_port *ap, struct ata_device *adev)
  174. {
  175. timing_setup(ap, adev, 0x40, adev->dma_mode, 2);
  176. }
  177. static void amd100_set_dmamode(struct ata_port *ap, struct ata_device *adev)
  178. {
  179. timing_setup(ap, adev, 0x40, adev->dma_mode, 3);
  180. }
  181. static void amd133_set_dmamode(struct ata_port *ap, struct ata_device *adev)
  182. {
  183. timing_setup(ap, adev, 0x40, adev->dma_mode, 4);
  184. }
  185. /* Both host-side and drive-side detection results are worthless on NV
  186. * PATAs. Ignore them and just follow what BIOS configured. Both the
  187. * current configuration in PCI config reg and ACPI GTM result are
  188. * cached during driver attach and are consulted to select transfer
  189. * mode.
  190. */
  191. static unsigned long nv_mode_filter(struct ata_device *dev,
  192. unsigned long xfer_mask)
  193. {
  194. static const unsigned int udma_mask_map[] =
  195. { ATA_UDMA2, ATA_UDMA1, ATA_UDMA0, 0,
  196. ATA_UDMA3, ATA_UDMA4, ATA_UDMA5, ATA_UDMA6 };
  197. struct ata_port *ap = dev->link->ap;
  198. char acpi_str[32] = "";
  199. u32 saved_udma, udma;
  200. const struct ata_acpi_gtm *gtm;
  201. unsigned long bios_limit = 0, acpi_limit = 0, limit;
  202. /* find out what BIOS configured */
  203. udma = saved_udma = (unsigned long)ap->host->private_data;
  204. if (ap->port_no == 0)
  205. udma >>= 16;
  206. if (dev->devno == 0)
  207. udma >>= 8;
  208. if ((udma & 0xc0) == 0xc0)
  209. bios_limit = ata_pack_xfermask(0, 0, udma_mask_map[udma & 0x7]);
  210. /* consult ACPI GTM too */
  211. gtm = ata_acpi_init_gtm(ap);
  212. if (gtm) {
  213. acpi_limit = ata_acpi_gtm_xfermask(dev, gtm);
  214. snprintf(acpi_str, sizeof(acpi_str), " (%u:%u:0x%x)",
  215. gtm->drive[0].dma, gtm->drive[1].dma, gtm->flags);
  216. }
  217. /* be optimistic, EH can take care of things if something goes wrong */
  218. limit = bios_limit | acpi_limit;
  219. /* If PIO or DMA isn't configured at all, don't limit. Let EH
  220. * handle it.
  221. */
  222. if (!(limit & ATA_MASK_PIO))
  223. limit |= ATA_MASK_PIO;
  224. if (!(limit & (ATA_MASK_MWDMA | ATA_MASK_UDMA)))
  225. limit |= ATA_MASK_MWDMA | ATA_MASK_UDMA;
  226. ata_port_printk(ap, KERN_DEBUG, "nv_mode_filter: 0x%lx&0x%lx->0x%lx, "
  227. "BIOS=0x%lx (0x%x) ACPI=0x%lx%s\n",
  228. xfer_mask, limit, xfer_mask & limit, bios_limit,
  229. saved_udma, acpi_limit, acpi_str);
  230. return xfer_mask & limit;
  231. }
  232. /**
  233. * nv_probe_init - cable detection
  234. * @lin: ATA link
  235. *
  236. * Perform cable detection. The BIOS stores this in PCI config
  237. * space for us.
  238. */
  239. static int nv_pre_reset(struct ata_link *link, unsigned long deadline)
  240. {
  241. static const struct pci_bits nv_enable_bits[] = {
  242. { 0x50, 1, 0x02, 0x02 },
  243. { 0x50, 1, 0x01, 0x01 }
  244. };
  245. struct ata_port *ap = link->ap;
  246. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  247. if (!pci_test_config_bits(pdev, &nv_enable_bits[ap->port_no]))
  248. return -ENOENT;
  249. return ata_std_prereset(link, deadline);
  250. }
  251. static void nv_error_handler(struct ata_port *ap)
  252. {
  253. ata_bmdma_drive_eh(ap, nv_pre_reset,
  254. ata_std_softreset, NULL,
  255. ata_std_postreset);
  256. }
  257. /**
  258. * nv100_set_piomode - set initial PIO mode data
  259. * @ap: ATA interface
  260. * @adev: ATA device
  261. *
  262. * Program the AMD registers for PIO mode.
  263. */
  264. static void nv100_set_piomode(struct ata_port *ap, struct ata_device *adev)
  265. {
  266. timing_setup(ap, adev, 0x50, adev->pio_mode, 3);
  267. }
  268. static void nv133_set_piomode(struct ata_port *ap, struct ata_device *adev)
  269. {
  270. timing_setup(ap, adev, 0x50, adev->pio_mode, 4);
  271. }
  272. /**
  273. * nv100_set_dmamode - set initial DMA mode data
  274. * @ap: ATA interface
  275. * @adev: ATA device
  276. *
  277. * Program the MWDMA/UDMA modes for the AMD and Nvidia
  278. * chipset.
  279. */
  280. static void nv100_set_dmamode(struct ata_port *ap, struct ata_device *adev)
  281. {
  282. timing_setup(ap, adev, 0x50, adev->dma_mode, 3);
  283. }
  284. static void nv133_set_dmamode(struct ata_port *ap, struct ata_device *adev)
  285. {
  286. timing_setup(ap, adev, 0x50, adev->dma_mode, 4);
  287. }
  288. static void nv_host_stop(struct ata_host *host)
  289. {
  290. u32 udma = (unsigned long)host->private_data;
  291. /* restore PCI config register 0x60 */
  292. pci_write_config_dword(to_pci_dev(host->dev), 0x60, udma);
  293. }
  294. static struct scsi_host_template amd_sht = {
  295. .module = THIS_MODULE,
  296. .name = DRV_NAME,
  297. .ioctl = ata_scsi_ioctl,
  298. .queuecommand = ata_scsi_queuecmd,
  299. .can_queue = ATA_DEF_QUEUE,
  300. .this_id = ATA_SHT_THIS_ID,
  301. .sg_tablesize = LIBATA_MAX_PRD,
  302. .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
  303. .emulated = ATA_SHT_EMULATED,
  304. .use_clustering = ATA_SHT_USE_CLUSTERING,
  305. .proc_name = DRV_NAME,
  306. .dma_boundary = ATA_DMA_BOUNDARY,
  307. .slave_configure = ata_scsi_slave_config,
  308. .slave_destroy = ata_scsi_slave_destroy,
  309. .bios_param = ata_std_bios_param,
  310. };
  311. static struct ata_port_operations amd33_port_ops = {
  312. .set_piomode = amd33_set_piomode,
  313. .set_dmamode = amd33_set_dmamode,
  314. .mode_filter = ata_pci_default_filter,
  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 = amd_error_handler,
  323. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  324. .cable_detect = ata_cable_40wire,
  325. .bmdma_setup = ata_bmdma_setup,
  326. .bmdma_start = ata_bmdma_start,
  327. .bmdma_stop = ata_bmdma_stop,
  328. .bmdma_status = ata_bmdma_status,
  329. .qc_prep = ata_qc_prep,
  330. .qc_issue = ata_qc_issue_prot,
  331. .data_xfer = ata_data_xfer,
  332. .irq_handler = ata_interrupt,
  333. .irq_clear = ata_bmdma_irq_clear,
  334. .irq_on = ata_irq_on,
  335. .port_start = ata_sff_port_start,
  336. };
  337. static struct ata_port_operations amd66_port_ops = {
  338. .set_piomode = amd66_set_piomode,
  339. .set_dmamode = amd66_set_dmamode,
  340. .mode_filter = ata_pci_default_filter,
  341. .tf_load = ata_tf_load,
  342. .tf_read = ata_tf_read,
  343. .check_status = ata_check_status,
  344. .exec_command = ata_exec_command,
  345. .dev_select = ata_std_dev_select,
  346. .freeze = ata_bmdma_freeze,
  347. .thaw = ata_bmdma_thaw,
  348. .error_handler = amd_error_handler,
  349. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  350. .cable_detect = ata_cable_unknown,
  351. .bmdma_setup = ata_bmdma_setup,
  352. .bmdma_start = ata_bmdma_start,
  353. .bmdma_stop = ata_bmdma_stop,
  354. .bmdma_status = ata_bmdma_status,
  355. .qc_prep = ata_qc_prep,
  356. .qc_issue = ata_qc_issue_prot,
  357. .data_xfer = ata_data_xfer,
  358. .irq_handler = ata_interrupt,
  359. .irq_clear = ata_bmdma_irq_clear,
  360. .irq_on = ata_irq_on,
  361. .port_start = ata_sff_port_start,
  362. };
  363. static struct ata_port_operations amd100_port_ops = {
  364. .set_piomode = amd100_set_piomode,
  365. .set_dmamode = amd100_set_dmamode,
  366. .mode_filter = ata_pci_default_filter,
  367. .tf_load = ata_tf_load,
  368. .tf_read = ata_tf_read,
  369. .check_status = ata_check_status,
  370. .exec_command = ata_exec_command,
  371. .dev_select = ata_std_dev_select,
  372. .freeze = ata_bmdma_freeze,
  373. .thaw = ata_bmdma_thaw,
  374. .error_handler = amd_error_handler,
  375. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  376. .cable_detect = ata_cable_unknown,
  377. .bmdma_setup = ata_bmdma_setup,
  378. .bmdma_start = ata_bmdma_start,
  379. .bmdma_stop = ata_bmdma_stop,
  380. .bmdma_status = ata_bmdma_status,
  381. .qc_prep = ata_qc_prep,
  382. .qc_issue = ata_qc_issue_prot,
  383. .data_xfer = ata_data_xfer,
  384. .irq_handler = ata_interrupt,
  385. .irq_clear = ata_bmdma_irq_clear,
  386. .irq_on = ata_irq_on,
  387. .port_start = ata_sff_port_start,
  388. };
  389. static struct ata_port_operations amd133_port_ops = {
  390. .set_piomode = amd133_set_piomode,
  391. .set_dmamode = amd133_set_dmamode,
  392. .mode_filter = ata_pci_default_filter,
  393. .tf_load = ata_tf_load,
  394. .tf_read = ata_tf_read,
  395. .check_status = ata_check_status,
  396. .exec_command = ata_exec_command,
  397. .dev_select = ata_std_dev_select,
  398. .freeze = ata_bmdma_freeze,
  399. .thaw = ata_bmdma_thaw,
  400. .error_handler = amd_error_handler,
  401. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  402. .cable_detect = amd_cable_detect,
  403. .bmdma_setup = ata_bmdma_setup,
  404. .bmdma_start = ata_bmdma_start,
  405. .bmdma_stop = ata_bmdma_stop,
  406. .bmdma_status = ata_bmdma_status,
  407. .qc_prep = ata_qc_prep,
  408. .qc_issue = ata_qc_issue_prot,
  409. .data_xfer = ata_data_xfer,
  410. .irq_handler = ata_interrupt,
  411. .irq_clear = ata_bmdma_irq_clear,
  412. .irq_on = ata_irq_on,
  413. .port_start = ata_sff_port_start,
  414. };
  415. static struct ata_port_operations nv100_port_ops = {
  416. .set_piomode = nv100_set_piomode,
  417. .set_dmamode = nv100_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 = ata_cable_ignore,
  429. .mode_filter = nv_mode_filter,
  430. .bmdma_setup = ata_bmdma_setup,
  431. .bmdma_start = ata_bmdma_start,
  432. .bmdma_stop = ata_bmdma_stop,
  433. .bmdma_status = ata_bmdma_status,
  434. .qc_prep = ata_qc_prep,
  435. .qc_issue = ata_qc_issue_prot,
  436. .data_xfer = ata_data_xfer,
  437. .irq_handler = ata_interrupt,
  438. .irq_clear = ata_bmdma_irq_clear,
  439. .irq_on = ata_irq_on,
  440. .port_start = ata_sff_port_start,
  441. .host_stop = nv_host_stop,
  442. };
  443. static struct ata_port_operations nv133_port_ops = {
  444. .set_piomode = nv133_set_piomode,
  445. .set_dmamode = nv133_set_dmamode,
  446. .mode_filter = ata_pci_default_filter,
  447. .tf_load = ata_tf_load,
  448. .tf_read = ata_tf_read,
  449. .check_status = ata_check_status,
  450. .exec_command = ata_exec_command,
  451. .dev_select = ata_std_dev_select,
  452. .freeze = ata_bmdma_freeze,
  453. .thaw = ata_bmdma_thaw,
  454. .error_handler = nv_error_handler,
  455. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  456. .cable_detect = ata_cable_ignore,
  457. .mode_filter = nv_mode_filter,
  458. .bmdma_setup = ata_bmdma_setup,
  459. .bmdma_start = ata_bmdma_start,
  460. .bmdma_stop = ata_bmdma_stop,
  461. .bmdma_status = ata_bmdma_status,
  462. .qc_prep = ata_qc_prep,
  463. .qc_issue = ata_qc_issue_prot,
  464. .data_xfer = ata_data_xfer,
  465. .irq_handler = ata_interrupt,
  466. .irq_clear = ata_bmdma_irq_clear,
  467. .irq_on = ata_irq_on,
  468. .port_start = ata_sff_port_start,
  469. .host_stop = nv_host_stop,
  470. };
  471. static int amd_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
  472. {
  473. static const struct ata_port_info info[10] = {
  474. { /* 0: AMD 7401 */
  475. .sht = &amd_sht,
  476. .flags = ATA_FLAG_SLAVE_POSS,
  477. .pio_mask = 0x1f,
  478. .mwdma_mask = 0x07, /* No SWDMA */
  479. .udma_mask = 0x07, /* UDMA 33 */
  480. .port_ops = &amd33_port_ops
  481. },
  482. { /* 1: Early AMD7409 - no swdma */
  483. .sht = &amd_sht,
  484. .flags = ATA_FLAG_SLAVE_POSS,
  485. .pio_mask = 0x1f,
  486. .mwdma_mask = 0x07,
  487. .udma_mask = ATA_UDMA4, /* UDMA 66 */
  488. .port_ops = &amd66_port_ops
  489. },
  490. { /* 2: AMD 7409, no swdma errata */
  491. .sht = &amd_sht,
  492. .flags = ATA_FLAG_SLAVE_POSS,
  493. .pio_mask = 0x1f,
  494. .mwdma_mask = 0x07,
  495. .udma_mask = ATA_UDMA4, /* UDMA 66 */
  496. .port_ops = &amd66_port_ops
  497. },
  498. { /* 3: AMD 7411 */
  499. .sht = &amd_sht,
  500. .flags = ATA_FLAG_SLAVE_POSS,
  501. .pio_mask = 0x1f,
  502. .mwdma_mask = 0x07,
  503. .udma_mask = ATA_UDMA5, /* UDMA 100 */
  504. .port_ops = &amd100_port_ops
  505. },
  506. { /* 4: AMD 7441 */
  507. .sht = &amd_sht,
  508. .flags = ATA_FLAG_SLAVE_POSS,
  509. .pio_mask = 0x1f,
  510. .mwdma_mask = 0x07,
  511. .udma_mask = ATA_UDMA5, /* UDMA 100 */
  512. .port_ops = &amd100_port_ops
  513. },
  514. { /* 5: AMD 8111*/
  515. .sht = &amd_sht,
  516. .flags = ATA_FLAG_SLAVE_POSS,
  517. .pio_mask = 0x1f,
  518. .mwdma_mask = 0x07,
  519. .udma_mask = ATA_UDMA6, /* UDMA 133, no swdma */
  520. .port_ops = &amd133_port_ops
  521. },
  522. { /* 6: AMD 8111 UDMA 100 (Serenade) */
  523. .sht = &amd_sht,
  524. .flags = ATA_FLAG_SLAVE_POSS,
  525. .pio_mask = 0x1f,
  526. .mwdma_mask = 0x07,
  527. .udma_mask = ATA_UDMA5, /* UDMA 100, no swdma */
  528. .port_ops = &amd133_port_ops
  529. },
  530. { /* 7: Nvidia Nforce */
  531. .sht = &amd_sht,
  532. .flags = ATA_FLAG_SLAVE_POSS,
  533. .pio_mask = 0x1f,
  534. .mwdma_mask = 0x07,
  535. .udma_mask = ATA_UDMA5, /* UDMA 100 */
  536. .port_ops = &nv100_port_ops
  537. },
  538. { /* 8: Nvidia Nforce2 and later */
  539. .sht = &amd_sht,
  540. .flags = ATA_FLAG_SLAVE_POSS,
  541. .pio_mask = 0x1f,
  542. .mwdma_mask = 0x07,
  543. .udma_mask = ATA_UDMA6, /* UDMA 133, no swdma */
  544. .port_ops = &nv133_port_ops
  545. },
  546. { /* 9: AMD CS5536 (Geode companion) */
  547. .sht = &amd_sht,
  548. .flags = ATA_FLAG_SLAVE_POSS,
  549. .pio_mask = 0x1f,
  550. .mwdma_mask = 0x07,
  551. .udma_mask = ATA_UDMA5, /* UDMA 100 */
  552. .port_ops = &amd100_port_ops
  553. }
  554. };
  555. struct ata_port_info pi;
  556. const struct ata_port_info *ppi[] = { &pi, NULL };
  557. static int printed_version;
  558. int type = id->driver_data;
  559. u8 fifo;
  560. if (!printed_version++)
  561. dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
  562. pci_read_config_byte(pdev, 0x41, &fifo);
  563. /* Check for AMD7409 without swdma errata and if found adjust type */
  564. if (type == 1 && pdev->revision > 0x7)
  565. type = 2;
  566. /* Serenade ? */
  567. if (type == 5 && pdev->subsystem_vendor == PCI_VENDOR_ID_AMD &&
  568. pdev->subsystem_device == PCI_DEVICE_ID_AMD_SERENADE)
  569. type = 6; /* UDMA 100 only */
  570. /*
  571. * Okay, type is determined now. Apply type-specific workarounds.
  572. */
  573. pi = info[type];
  574. if (type < 3)
  575. ata_pci_clear_simplex(pdev);
  576. /* Check for AMD7411 */
  577. if (type == 3)
  578. /* FIFO is broken */
  579. pci_write_config_byte(pdev, 0x41, fifo & 0x0F);
  580. else
  581. pci_write_config_byte(pdev, 0x41, fifo | 0xF0);
  582. /* Cable detection on Nvidia chips doesn't work too well,
  583. * cache BIOS programmed UDMA mode.
  584. */
  585. if (type == 7 || type == 8) {
  586. u32 udma;
  587. pci_read_config_dword(pdev, 0x60, &udma);
  588. pi.private_data = (void *)(unsigned long)udma;
  589. }
  590. /* And fire it up */
  591. return ata_pci_init_one(pdev, ppi);
  592. }
  593. #ifdef CONFIG_PM
  594. static int amd_reinit_one(struct pci_dev *pdev)
  595. {
  596. if (pdev->vendor == PCI_VENDOR_ID_AMD) {
  597. u8 fifo;
  598. pci_read_config_byte(pdev, 0x41, &fifo);
  599. if (pdev->device == PCI_DEVICE_ID_AMD_VIPER_7411)
  600. /* FIFO is broken */
  601. pci_write_config_byte(pdev, 0x41, fifo & 0x0F);
  602. else
  603. pci_write_config_byte(pdev, 0x41, fifo | 0xF0);
  604. if (pdev->device == PCI_DEVICE_ID_AMD_VIPER_7409 ||
  605. pdev->device == PCI_DEVICE_ID_AMD_COBRA_7401)
  606. ata_pci_clear_simplex(pdev);
  607. }
  608. return ata_pci_device_resume(pdev);
  609. }
  610. #endif
  611. static const struct pci_device_id amd[] = {
  612. { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_COBRA_7401), 0 },
  613. { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_VIPER_7409), 1 },
  614. { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_VIPER_7411), 3 },
  615. { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_OPUS_7441), 4 },
  616. { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_8111_IDE), 5 },
  617. { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_IDE), 7 },
  618. { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2_IDE), 8 },
  619. { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2S_IDE), 8 },
  620. { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3_IDE), 8 },
  621. { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3S_IDE), 8 },
  622. { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_CK804_IDE), 8 },
  623. { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP04_IDE), 8 },
  624. { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_IDE), 8 },
  625. { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_IDE), 8 },
  626. { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_IDE), 8 },
  627. { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP65_IDE), 8 },
  628. { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP67_IDE), 8 },
  629. { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP73_IDE), 8 },
  630. { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP77_IDE), 8 },
  631. { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_CS5536_IDE), 9 },
  632. { },
  633. };
  634. static struct pci_driver amd_pci_driver = {
  635. .name = DRV_NAME,
  636. .id_table = amd,
  637. .probe = amd_init_one,
  638. .remove = ata_pci_remove_one,
  639. #ifdef CONFIG_PM
  640. .suspend = ata_pci_device_suspend,
  641. .resume = amd_reinit_one,
  642. #endif
  643. };
  644. static int __init amd_init(void)
  645. {
  646. return pci_register_driver(&amd_pci_driver);
  647. }
  648. static void __exit amd_exit(void)
  649. {
  650. pci_unregister_driver(&amd_pci_driver);
  651. }
  652. MODULE_AUTHOR("Alan Cox");
  653. MODULE_DESCRIPTION("low-level driver for AMD PATA IDE");
  654. MODULE_LICENSE("GPL");
  655. MODULE_DEVICE_TABLE(pci, amd);
  656. MODULE_VERSION(DRV_VERSION);
  657. module_init(amd_init);
  658. module_exit(amd_exit);