pata_ali.c 18 KB

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