pata_ali.c 17 KB

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