pata_ali.c 17 KB

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