pata_ali.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. /*
  2. * pata_ali.c - ALI 15x3 PATA for new ATA layer
  3. * (C) 2005 Red Hat Inc
  4. * Alan Cox <alan@redhat.com>
  5. *
  6. * based in part upon
  7. * linux/drivers/ide/pci/alim15x3.c Version 0.17 2003/01/02
  8. *
  9. * Copyright (C) 1998-2000 Michel Aubry, Maintainer
  10. * Copyright (C) 1998-2000 Andrzej Krzysztofowicz, Maintainer
  11. * Copyright (C) 1999-2000 CJ, cjtsai@ali.com.tw, Maintainer
  12. *
  13. * Copyright (C) 1998-2000 Andre Hedrick (andre@linux-ide.org)
  14. * May be copied or modified under the terms of the GNU General Public License
  15. * Copyright (C) 2002 Alan Cox <alan@redhat.com>
  16. * ALi (now ULi M5228) support by Clear Zhang <Clear.Zhang@ali.com.tw>
  17. *
  18. * Documentation
  19. * Chipset documentation available under NDA only
  20. *
  21. * TODO/CHECK
  22. * Cannot have ATAPI on both master & slave for rev < c2 (???) but
  23. * otherwise should do atapi DMA.
  24. */
  25. #include <linux/kernel.h>
  26. #include <linux/module.h>
  27. #include <linux/pci.h>
  28. #include <linux/init.h>
  29. #include <linux/blkdev.h>
  30. #include <linux/delay.h>
  31. #include <scsi/scsi_host.h>
  32. #include <linux/libata.h>
  33. #include <linux/dmi.h>
  34. #define DRV_NAME "pata_ali"
  35. #define DRV_VERSION "0.7.5"
  36. static int ali_atapi_dma = 0;
  37. module_param_named(atapi_dma, ali_atapi_dma, int, 0644);
  38. MODULE_PARM_DESC(atapi_dma, "Enable ATAPI DMA (0=disable, 1=enable)");
  39. /*
  40. * Cable special cases
  41. */
  42. static const struct dmi_system_id cable_dmi_table[] = {
  43. {
  44. .ident = "HP Pavilion N5430",
  45. .matches = {
  46. DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
  47. DMI_MATCH(DMI_BOARD_VERSION, "OmniBook N32N-736"),
  48. },
  49. },
  50. {
  51. .ident = "Toshiba Satelite S1800-814",
  52. .matches = {
  53. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  54. DMI_MATCH(DMI_PRODUCT_NAME, "S1800-814"),
  55. },
  56. },
  57. { }
  58. };
  59. static int ali_cable_override(struct pci_dev *pdev)
  60. {
  61. /* Fujitsu P2000 */
  62. if (pdev->subsystem_vendor == 0x10CF && pdev->subsystem_device == 0x10AF)
  63. return 1;
  64. /* Mitac 8317 (Winbook-A) and relatives */
  65. if (pdev->subsystem_vendor == 0x1071 && pdev->subsystem_device == 0x8317)
  66. return 1;
  67. /* Systems by DMI */
  68. if (dmi_check_system(cable_dmi_table))
  69. return 1;
  70. return 0;
  71. }
  72. /**
  73. * ali_c2_cable_detect - cable detection
  74. * @ap: ATA port
  75. *
  76. * Perform cable detection for C2 and later revisions
  77. */
  78. static int ali_c2_cable_detect(struct ata_port *ap)
  79. {
  80. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  81. u8 ata66;
  82. /* Certain laptops use short but suitable cables and don't
  83. implement the detect logic */
  84. if (ali_cable_override(pdev))
  85. return ATA_CBL_PATA40_SHORT;
  86. /* Host view cable detect 0x4A bit 0 primary bit 1 secondary
  87. Bit set for 40 pin */
  88. pci_read_config_byte(pdev, 0x4A, &ata66);
  89. if (ata66 & (1 << ap->port_no))
  90. return ATA_CBL_PATA40;
  91. else
  92. return ATA_CBL_PATA80;
  93. }
  94. /**
  95. * ali_20_filter - filter for earlier ALI DMA
  96. * @ap: ALi ATA port
  97. * @adev: attached device
  98. *
  99. * Ensure that we do not do DMA on CD devices. We may be able to
  100. * fix that later on. Also ensure we do not do UDMA on WDC drives
  101. */
  102. static unsigned long ali_20_filter(struct ata_device *adev, unsigned long mask)
  103. {
  104. char model_num[ATA_ID_PROD_LEN + 1];
  105. /* No DMA on anything but a disk for now */
  106. if (adev->class != ATA_DEV_ATA)
  107. mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA);
  108. ata_id_c_string(adev->id, model_num, ATA_ID_PROD, sizeof(model_num));
  109. if (strstr(model_num, "WDC"))
  110. return mask &= ~ATA_MASK_UDMA;
  111. return ata_pci_default_filter(adev, mask);
  112. }
  113. /**
  114. * ali_fifo_control - FIFO manager
  115. * @ap: ALi channel to control
  116. * @adev: device for FIFO control
  117. * @on: 0 for off 1 for on
  118. *
  119. * Enable or disable the FIFO on a given device. Because of the way the
  120. * ALi FIFO works it provides a boost on ATA disk but can be confused by
  121. * ATAPI and we must therefore manage it.
  122. */
  123. static void ali_fifo_control(struct ata_port *ap, struct ata_device *adev, int on)
  124. {
  125. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  126. int pio_fifo = 0x54 + ap->port_no;
  127. u8 fifo;
  128. int shift = 4 * adev->devno;
  129. /* ATA - FIFO on set nibble to 0x05, ATAPI - FIFO off, set nibble to
  130. 0x00. Not all the docs agree but the behaviour we now use is the
  131. one stated in the BIOS Programming Guide */
  132. pci_read_config_byte(pdev, pio_fifo, &fifo);
  133. fifo &= ~(0x0F << shift);
  134. if (on)
  135. fifo |= (on << shift);
  136. pci_write_config_byte(pdev, pio_fifo, fifo);
  137. }
  138. /**
  139. * ali_program_modes - load mode registers
  140. * @ap: ALi channel to load
  141. * @adev: Device the timing is for
  142. * @cmd: Command timing
  143. * @data: Data timing
  144. * @ultra: UDMA timing or zero for off
  145. *
  146. * Loads the timing registers for cmd/data and disable UDMA if
  147. * ultra is zero. If ultra is set then load and enable the UDMA
  148. * timing but do not touch the command/data timing.
  149. */
  150. static void ali_program_modes(struct ata_port *ap, struct ata_device *adev, struct ata_timing *t, u8 ultra)
  151. {
  152. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  153. int cas = 0x58 + 4 * ap->port_no; /* Command timing */
  154. int cbt = 0x59 + 4 * ap->port_no; /* Command timing */
  155. int drwt = 0x5A + 4 * ap->port_no + adev->devno; /* R/W timing */
  156. int udmat = 0x56 + ap->port_no; /* UDMA timing */
  157. int shift = 4 * adev->devno;
  158. u8 udma;
  159. if (t != NULL) {
  160. t->setup = FIT(t->setup, 1, 8) & 7;
  161. t->act8b = FIT(t->act8b, 1, 8) & 7;
  162. t->rec8b = FIT(t->rec8b, 1, 16) & 15;
  163. t->active = FIT(t->active, 1, 8) & 7;
  164. t->recover = FIT(t->recover, 1, 16) & 15;
  165. pci_write_config_byte(pdev, cas, t->setup);
  166. pci_write_config_byte(pdev, cbt, (t->act8b << 4) | t->rec8b);
  167. pci_write_config_byte(pdev, drwt, (t->active << 4) | t->recover);
  168. }
  169. /* Set up the UDMA enable */
  170. pci_read_config_byte(pdev, udmat, &udma);
  171. udma &= ~(0x0F << shift);
  172. udma |= ultra << shift;
  173. pci_write_config_byte(pdev, udmat, udma);
  174. }
  175. /**
  176. * ali_set_piomode - set initial PIO mode data
  177. * @ap: ATA interface
  178. * @adev: ATA device
  179. *
  180. * Program the ALi registers for PIO mode. FIXME: add timings for
  181. * PIO5.
  182. */
  183. static void ali_set_piomode(struct ata_port *ap, struct ata_device *adev)
  184. {
  185. struct ata_device *pair = ata_dev_pair(adev);
  186. struct ata_timing t;
  187. unsigned long T = 1000000000 / 33333; /* PCI clock based */
  188. ata_timing_compute(adev, adev->pio_mode, &t, T, 1);
  189. if (pair) {
  190. struct ata_timing p;
  191. ata_timing_compute(pair, pair->pio_mode, &p, T, 1);
  192. ata_timing_merge(&p, &t, &t, ATA_TIMING_SETUP|ATA_TIMING_8BIT);
  193. if (pair->dma_mode) {
  194. ata_timing_compute(pair, pair->dma_mode, &p, T, 1);
  195. ata_timing_merge(&p, &t, &t, ATA_TIMING_SETUP|ATA_TIMING_8BIT);
  196. }
  197. }
  198. /* PIO FIFO is only permitted on ATA disk */
  199. if (adev->class != ATA_DEV_ATA)
  200. ali_fifo_control(ap, adev, 0x00);
  201. ali_program_modes(ap, adev, &t, 0);
  202. if (adev->class == ATA_DEV_ATA)
  203. ali_fifo_control(ap, adev, 0x05);
  204. }
  205. /**
  206. * ali_set_dmamode - set initial DMA mode data
  207. * @ap: ATA interface
  208. * @adev: ATA device
  209. *
  210. * FIXME: MWDMA timings
  211. */
  212. static void ali_set_dmamode(struct ata_port *ap, struct ata_device *adev)
  213. {
  214. static u8 udma_timing[7] = { 0xC, 0xB, 0xA, 0x9, 0x8, 0xF, 0xD };
  215. struct ata_device *pair = ata_dev_pair(adev);
  216. struct ata_timing t;
  217. unsigned long T = 1000000000 / 33333; /* PCI clock based */
  218. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  219. if (adev->class == ATA_DEV_ATA)
  220. ali_fifo_control(ap, adev, 0x08);
  221. if (adev->dma_mode >= XFER_UDMA_0) {
  222. ali_program_modes(ap, adev, NULL, udma_timing[adev->dma_mode - XFER_UDMA_0]);
  223. if (adev->dma_mode >= XFER_UDMA_3) {
  224. u8 reg4b;
  225. pci_read_config_byte(pdev, 0x4B, &reg4b);
  226. reg4b |= 1;
  227. pci_write_config_byte(pdev, 0x4B, reg4b);
  228. }
  229. } else {
  230. ata_timing_compute(adev, adev->dma_mode, &t, T, 1);
  231. if (pair) {
  232. struct ata_timing p;
  233. ata_timing_compute(pair, pair->pio_mode, &p, T, 1);
  234. ata_timing_merge(&p, &t, &t, ATA_TIMING_SETUP|ATA_TIMING_8BIT);
  235. if (pair->dma_mode) {
  236. ata_timing_compute(pair, pair->dma_mode, &p, T, 1);
  237. ata_timing_merge(&p, &t, &t, ATA_TIMING_SETUP|ATA_TIMING_8BIT);
  238. }
  239. }
  240. ali_program_modes(ap, adev, &t, 0);
  241. }
  242. }
  243. /**
  244. * ali_warn_atapi_dma - Warn about ATAPI DMA disablement
  245. * @adev: Device
  246. *
  247. * Whine about ATAPI DMA disablement if @adev is an ATAPI device.
  248. * Can be used as ->dev_config.
  249. */
  250. static void ali_warn_atapi_dma(struct ata_device *adev)
  251. {
  252. struct ata_eh_context *ehc = &adev->link->eh_context;
  253. int print_info = ehc->i.flags & ATA_EHI_PRINTINFO;
  254. if (print_info && adev->class == ATA_DEV_ATAPI && !ali_atapi_dma) {
  255. ata_dev_printk(adev, KERN_WARNING,
  256. "WARNING: ATAPI DMA disabled for reliablity issues. It can be enabled\n");
  257. ata_dev_printk(adev, KERN_WARNING,
  258. "WARNING: via pata_ali.atapi_dma modparam or corresponding sysfs node.\n");
  259. }
  260. }
  261. /**
  262. * ali_lock_sectors - Keep older devices to 255 sector mode
  263. * @adev: Device
  264. *
  265. * Called during the bus probe for each device that is found. We use
  266. * this call to lock the sector count of the device to 255 or less on
  267. * older ALi controllers. If we didn't do this then large I/O's would
  268. * require LBA48 commands which the older ALi requires are issued by
  269. * slower PIO methods
  270. */
  271. static void ali_lock_sectors(struct ata_device *adev)
  272. {
  273. adev->max_sectors = 255;
  274. ali_warn_atapi_dma(adev);
  275. }
  276. /**
  277. * ali_check_atapi_dma - DMA check for most ALi controllers
  278. * @adev: Device
  279. *
  280. * Called to decide whether commands should be sent by DMA or PIO
  281. */
  282. static int ali_check_atapi_dma(struct ata_queued_cmd *qc)
  283. {
  284. if (!ali_atapi_dma) {
  285. /* FIXME: pata_ali can't do ATAPI DMA reliably but the
  286. * IDE alim15x3 driver can. I tried lots of things
  287. * but couldn't find what the actual difference was.
  288. * If you got an idea, please write it to
  289. * linux-ide@vger.kernel.org and cc htejun@gmail.com.
  290. *
  291. * Disable ATAPI DMA for now.
  292. */
  293. return -EOPNOTSUPP;
  294. }
  295. /* If its not a media command, its not worth it */
  296. if (atapi_cmd_type(qc->cdb[0]) == ATAPI_MISC)
  297. return -EOPNOTSUPP;
  298. return 0;
  299. }
  300. static struct scsi_host_template ali_sht = {
  301. .module = THIS_MODULE,
  302. .name = DRV_NAME,
  303. .ioctl = ata_scsi_ioctl,
  304. .queuecommand = ata_scsi_queuecmd,
  305. .can_queue = ATA_DEF_QUEUE,
  306. .this_id = ATA_SHT_THIS_ID,
  307. .sg_tablesize = LIBATA_MAX_PRD,
  308. .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
  309. .emulated = ATA_SHT_EMULATED,
  310. .use_clustering = ATA_SHT_USE_CLUSTERING,
  311. .proc_name = DRV_NAME,
  312. .dma_boundary = ATA_DMA_BOUNDARY,
  313. .slave_configure = ata_scsi_slave_config,
  314. .slave_destroy = ata_scsi_slave_destroy,
  315. .bios_param = ata_std_bios_param,
  316. };
  317. /*
  318. * Port operations for PIO only ALi
  319. */
  320. static struct ata_port_operations ali_early_port_ops = {
  321. .set_piomode = ali_set_piomode,
  322. .tf_load = ata_tf_load,
  323. .tf_read = ata_tf_read,
  324. .check_status = ata_check_status,
  325. .exec_command = ata_exec_command,
  326. .dev_select = ata_std_dev_select,
  327. .freeze = ata_bmdma_freeze,
  328. .thaw = ata_bmdma_thaw,
  329. .error_handler = ata_bmdma_error_handler,
  330. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  331. .cable_detect = ata_cable_40wire,
  332. .qc_prep = ata_qc_prep,
  333. .qc_issue = ata_qc_issue_prot,
  334. .data_xfer = ata_data_xfer,
  335. .irq_handler = ata_interrupt,
  336. .irq_clear = ata_bmdma_irq_clear,
  337. .irq_on = ata_irq_on,
  338. .port_start = ata_sff_port_start,
  339. };
  340. /*
  341. * Port operations for DMA capable ALi without cable
  342. * detect
  343. */
  344. static struct ata_port_operations ali_20_port_ops = {
  345. .set_piomode = ali_set_piomode,
  346. .set_dmamode = ali_set_dmamode,
  347. .mode_filter = ali_20_filter,
  348. .tf_load = ata_tf_load,
  349. .tf_read = ata_tf_read,
  350. .check_atapi_dma = ali_check_atapi_dma,
  351. .check_status = ata_check_status,
  352. .exec_command = ata_exec_command,
  353. .dev_select = ata_std_dev_select,
  354. .dev_config = ali_lock_sectors,
  355. .freeze = ata_bmdma_freeze,
  356. .thaw = ata_bmdma_thaw,
  357. .error_handler = ata_bmdma_error_handler,
  358. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  359. .cable_detect = ata_cable_40wire,
  360. .bmdma_setup = ata_bmdma_setup,
  361. .bmdma_start = ata_bmdma_start,
  362. .bmdma_stop = ata_bmdma_stop,
  363. .bmdma_status = ata_bmdma_status,
  364. .qc_prep = ata_qc_prep,
  365. .qc_issue = ata_qc_issue_prot,
  366. .data_xfer = ata_data_xfer,
  367. .irq_handler = ata_interrupt,
  368. .irq_clear = ata_bmdma_irq_clear,
  369. .irq_on = ata_irq_on,
  370. .port_start = ata_sff_port_start,
  371. };
  372. /*
  373. * Port operations for DMA capable ALi with cable detect
  374. */
  375. static struct ata_port_operations ali_c2_port_ops = {
  376. .set_piomode = ali_set_piomode,
  377. .set_dmamode = ali_set_dmamode,
  378. .mode_filter = ata_pci_default_filter,
  379. .tf_load = ata_tf_load,
  380. .tf_read = ata_tf_read,
  381. .check_atapi_dma = ali_check_atapi_dma,
  382. .check_status = ata_check_status,
  383. .exec_command = ata_exec_command,
  384. .dev_select = ata_std_dev_select,
  385. .dev_config = ali_lock_sectors,
  386. .freeze = ata_bmdma_freeze,
  387. .thaw = ata_bmdma_thaw,
  388. .error_handler = ata_bmdma_error_handler,
  389. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  390. .cable_detect = ali_c2_cable_detect,
  391. .bmdma_setup = ata_bmdma_setup,
  392. .bmdma_start = ata_bmdma_start,
  393. .bmdma_stop = ata_bmdma_stop,
  394. .bmdma_status = ata_bmdma_status,
  395. .qc_prep = ata_qc_prep,
  396. .qc_issue = ata_qc_issue_prot,
  397. .data_xfer = ata_data_xfer,
  398. .irq_handler = ata_interrupt,
  399. .irq_clear = ata_bmdma_irq_clear,
  400. .irq_on = ata_irq_on,
  401. .port_start = ata_sff_port_start,
  402. };
  403. /*
  404. * Port operations for DMA capable ALi with cable detect and LBA48
  405. */
  406. static struct ata_port_operations ali_c5_port_ops = {
  407. .set_piomode = ali_set_piomode,
  408. .set_dmamode = ali_set_dmamode,
  409. .mode_filter = ata_pci_default_filter,
  410. .tf_load = ata_tf_load,
  411. .tf_read = ata_tf_read,
  412. .check_atapi_dma = ali_check_atapi_dma,
  413. .check_status = ata_check_status,
  414. .exec_command = ata_exec_command,
  415. .dev_select = ata_std_dev_select,
  416. .dev_config = ali_warn_atapi_dma,
  417. .freeze = ata_bmdma_freeze,
  418. .thaw = ata_bmdma_thaw,
  419. .error_handler = ata_bmdma_error_handler,
  420. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  421. .cable_detect = ali_c2_cable_detect,
  422. .bmdma_setup = ata_bmdma_setup,
  423. .bmdma_start = ata_bmdma_start,
  424. .bmdma_stop = ata_bmdma_stop,
  425. .bmdma_status = ata_bmdma_status,
  426. .qc_prep = ata_qc_prep,
  427. .qc_issue = ata_qc_issue_prot,
  428. .data_xfer = ata_data_xfer,
  429. .irq_handler = ata_interrupt,
  430. .irq_clear = ata_bmdma_irq_clear,
  431. .irq_on = ata_irq_on,
  432. .port_start = ata_sff_port_start,
  433. };
  434. /**
  435. * ali_init_chipset - chip setup function
  436. * @pdev: PCI device of ATA controller
  437. *
  438. * Perform the setup on the device that must be done both at boot
  439. * and at resume time.
  440. */
  441. static void ali_init_chipset(struct pci_dev *pdev)
  442. {
  443. u8 tmp;
  444. struct pci_dev *north, *isa_bridge;
  445. /*
  446. * The chipset revision selects the driver operations and
  447. * mode data.
  448. */
  449. if (pdev->revision >= 0x20 && pdev->revision < 0xC2) {
  450. /* 1543-E/F, 1543C-C, 1543C-D, 1543C-E */
  451. pci_read_config_byte(pdev, 0x4B, &tmp);
  452. /* Clear CD-ROM DMA write bit */
  453. tmp &= 0x7F;
  454. pci_write_config_byte(pdev, 0x4B, tmp);
  455. } else if (pdev->revision >= 0xC2) {
  456. /* Enable cable detection logic */
  457. pci_read_config_byte(pdev, 0x4B, &tmp);
  458. pci_write_config_byte(pdev, 0x4B, tmp | 0x08);
  459. }
  460. north = pci_get_bus_and_slot(0, PCI_DEVFN(0,0));
  461. isa_bridge = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533, NULL);
  462. if (north && north->vendor == PCI_VENDOR_ID_AL && isa_bridge) {
  463. /* Configure the ALi bridge logic. For non ALi rely on BIOS.
  464. Set the south bridge enable bit */
  465. pci_read_config_byte(isa_bridge, 0x79, &tmp);
  466. if (pdev->revision == 0xC2)
  467. pci_write_config_byte(isa_bridge, 0x79, tmp | 0x04);
  468. else if (pdev->revision > 0xC2 && pdev->revision < 0xC5)
  469. pci_write_config_byte(isa_bridge, 0x79, tmp | 0x02);
  470. }
  471. if (pdev->revision >= 0x20) {
  472. /*
  473. * CD_ROM DMA on (0x53 bit 0). Enable this even if we want
  474. * to use PIO. 0x53 bit 1 (rev 20 only) - enable FIFO control
  475. * via 0x54/55.
  476. */
  477. pci_read_config_byte(pdev, 0x53, &tmp);
  478. if (pdev->revision <= 0x20)
  479. tmp &= ~0x02;
  480. if (pdev->revision >= 0xc7)
  481. tmp |= 0x03;
  482. else
  483. tmp |= 0x01; /* CD_ROM enable for DMA */
  484. pci_write_config_byte(pdev, 0x53, tmp);
  485. }
  486. pci_dev_put(isa_bridge);
  487. pci_dev_put(north);
  488. ata_pci_clear_simplex(pdev);
  489. }
  490. /**
  491. * ali_init_one - discovery callback
  492. * @pdev: PCI device ID
  493. * @id: PCI table info
  494. *
  495. * An ALi IDE interface has been discovered. Figure out what revision
  496. * and perform configuration work before handing it to the ATA layer
  497. */
  498. static int ali_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
  499. {
  500. static const struct ata_port_info info_early = {
  501. .sht = &ali_sht,
  502. .flags = ATA_FLAG_SLAVE_POSS,
  503. .pio_mask = 0x1f,
  504. .port_ops = &ali_early_port_ops
  505. };
  506. /* Revision 0x20 added DMA */
  507. static const struct ata_port_info info_20 = {
  508. .sht = &ali_sht,
  509. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_PIO_LBA48,
  510. .pio_mask = 0x1f,
  511. .mwdma_mask = 0x07,
  512. .port_ops = &ali_20_port_ops
  513. };
  514. /* Revision 0x20 with support logic added UDMA */
  515. static const struct ata_port_info info_20_udma = {
  516. .sht = &ali_sht,
  517. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_PIO_LBA48,
  518. .pio_mask = 0x1f,
  519. .mwdma_mask = 0x07,
  520. .udma_mask = 0x07, /* UDMA33 */
  521. .port_ops = &ali_20_port_ops
  522. };
  523. /* Revision 0xC2 adds UDMA66 */
  524. static const struct ata_port_info info_c2 = {
  525. .sht = &ali_sht,
  526. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_PIO_LBA48,
  527. .pio_mask = 0x1f,
  528. .mwdma_mask = 0x07,
  529. .udma_mask = ATA_UDMA4,
  530. .port_ops = &ali_c2_port_ops
  531. };
  532. /* Revision 0xC3 is UDMA66 for now */
  533. static const struct ata_port_info info_c3 = {
  534. .sht = &ali_sht,
  535. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_PIO_LBA48,
  536. .pio_mask = 0x1f,
  537. .mwdma_mask = 0x07,
  538. .udma_mask = ATA_UDMA4,
  539. .port_ops = &ali_c2_port_ops
  540. };
  541. /* Revision 0xC4 is UDMA100 */
  542. static const struct ata_port_info info_c4 = {
  543. .sht = &ali_sht,
  544. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_PIO_LBA48,
  545. .pio_mask = 0x1f,
  546. .mwdma_mask = 0x07,
  547. .udma_mask = ATA_UDMA5,
  548. .port_ops = &ali_c2_port_ops
  549. };
  550. /* Revision 0xC5 is UDMA133 with LBA48 DMA */
  551. static const struct ata_port_info info_c5 = {
  552. .sht = &ali_sht,
  553. .flags = ATA_FLAG_SLAVE_POSS,
  554. .pio_mask = 0x1f,
  555. .mwdma_mask = 0x07,
  556. .udma_mask = ATA_UDMA6,
  557. .port_ops = &ali_c5_port_ops
  558. };
  559. const struct ata_port_info *ppi[] = { NULL, NULL };
  560. u8 tmp;
  561. struct pci_dev *isa_bridge;
  562. /*
  563. * The chipset revision selects the driver operations and
  564. * mode data.
  565. */
  566. if (pdev->revision < 0x20) {
  567. ppi[0] = &info_early;
  568. } else if (pdev->revision < 0xC2) {
  569. ppi[0] = &info_20;
  570. } else if (pdev->revision == 0xC2) {
  571. ppi[0] = &info_c2;
  572. } else if (pdev->revision == 0xC3) {
  573. ppi[0] = &info_c3;
  574. } else if (pdev->revision == 0xC4) {
  575. ppi[0] = &info_c4;
  576. } else
  577. ppi[0] = &info_c5;
  578. ali_init_chipset(pdev);
  579. isa_bridge = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533, NULL);
  580. if (isa_bridge && pdev->revision >= 0x20 && pdev->revision < 0xC2) {
  581. /* Are we paired with a UDMA capable chip */
  582. pci_read_config_byte(isa_bridge, 0x5E, &tmp);
  583. if ((tmp & 0x1E) == 0x12)
  584. ppi[0] = &info_20_udma;
  585. pci_dev_put(isa_bridge);
  586. }
  587. return ata_pci_init_one(pdev, ppi);
  588. }
  589. #ifdef CONFIG_PM
  590. static int ali_reinit_one(struct pci_dev *pdev)
  591. {
  592. ali_init_chipset(pdev);
  593. return ata_pci_device_resume(pdev);
  594. }
  595. #endif
  596. static const struct pci_device_id ali[] = {
  597. { PCI_VDEVICE(AL, PCI_DEVICE_ID_AL_M5228), },
  598. { PCI_VDEVICE(AL, PCI_DEVICE_ID_AL_M5229), },
  599. { },
  600. };
  601. static struct pci_driver ali_pci_driver = {
  602. .name = DRV_NAME,
  603. .id_table = ali,
  604. .probe = ali_init_one,
  605. .remove = ata_pci_remove_one,
  606. #ifdef CONFIG_PM
  607. .suspend = ata_pci_device_suspend,
  608. .resume = ali_reinit_one,
  609. #endif
  610. };
  611. static int __init ali_init(void)
  612. {
  613. return pci_register_driver(&ali_pci_driver);
  614. }
  615. static void __exit ali_exit(void)
  616. {
  617. pci_unregister_driver(&ali_pci_driver);
  618. }
  619. MODULE_AUTHOR("Alan Cox");
  620. MODULE_DESCRIPTION("low-level driver for ALi PATA");
  621. MODULE_LICENSE("GPL");
  622. MODULE_DEVICE_TABLE(pci, ali);
  623. MODULE_VERSION(DRV_VERSION);
  624. module_init(ali_init);
  625. module_exit(ali_exit);