pata_ali.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  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. /**
  255. * ali_check_atapi_dma - DMA check for most ALi controllers
  256. * @adev: Device
  257. *
  258. * Called to decide whether commands should be sent by DMA or PIO
  259. */
  260. static int ali_check_atapi_dma(struct ata_queued_cmd *qc)
  261. {
  262. /* If its not a media command, its not worth it */
  263. if (qc->nbytes < 2048)
  264. return -EOPNOTSUPP;
  265. return 0;
  266. }
  267. static struct scsi_host_template ali_sht = {
  268. .module = THIS_MODULE,
  269. .name = DRV_NAME,
  270. .ioctl = ata_scsi_ioctl,
  271. .queuecommand = ata_scsi_queuecmd,
  272. .can_queue = ATA_DEF_QUEUE,
  273. .this_id = ATA_SHT_THIS_ID,
  274. .sg_tablesize = LIBATA_MAX_PRD,
  275. .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
  276. .emulated = ATA_SHT_EMULATED,
  277. .use_clustering = ATA_SHT_USE_CLUSTERING,
  278. .proc_name = DRV_NAME,
  279. .dma_boundary = ATA_DMA_BOUNDARY,
  280. .slave_configure = ata_scsi_slave_config,
  281. .slave_destroy = ata_scsi_slave_destroy,
  282. .bios_param = ata_std_bios_param,
  283. };
  284. /*
  285. * Port operations for PIO only ALi
  286. */
  287. static struct ata_port_operations ali_early_port_ops = {
  288. .set_piomode = ali_set_piomode,
  289. .tf_load = ata_tf_load,
  290. .tf_read = ata_tf_read,
  291. .check_status = ata_check_status,
  292. .exec_command = ata_exec_command,
  293. .dev_select = ata_std_dev_select,
  294. .freeze = ata_bmdma_freeze,
  295. .thaw = ata_bmdma_thaw,
  296. .error_handler = ata_bmdma_error_handler,
  297. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  298. .cable_detect = ata_cable_40wire,
  299. .qc_prep = ata_qc_prep,
  300. .qc_issue = ata_qc_issue_prot,
  301. .data_xfer = ata_data_xfer,
  302. .irq_handler = ata_interrupt,
  303. .irq_clear = ata_bmdma_irq_clear,
  304. .irq_on = ata_irq_on,
  305. .port_start = ata_sff_port_start,
  306. };
  307. /*
  308. * Port operations for DMA capable ALi without cable
  309. * detect
  310. */
  311. static struct ata_port_operations ali_20_port_ops = {
  312. .set_piomode = ali_set_piomode,
  313. .set_dmamode = ali_set_dmamode,
  314. .mode_filter = ali_20_filter,
  315. .tf_load = ata_tf_load,
  316. .tf_read = ata_tf_read,
  317. .check_status = ata_check_status,
  318. .exec_command = ata_exec_command,
  319. .dev_select = ata_std_dev_select,
  320. .dev_config = ali_lock_sectors,
  321. .freeze = ata_bmdma_freeze,
  322. .thaw = ata_bmdma_thaw,
  323. .error_handler = ata_bmdma_error_handler,
  324. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  325. .cable_detect = ata_cable_40wire,
  326. .bmdma_setup = ata_bmdma_setup,
  327. .bmdma_start = ata_bmdma_start,
  328. .bmdma_stop = ata_bmdma_stop,
  329. .bmdma_status = ata_bmdma_status,
  330. .qc_prep = ata_qc_prep,
  331. .qc_issue = ata_qc_issue_prot,
  332. .data_xfer = ata_data_xfer,
  333. .irq_handler = ata_interrupt,
  334. .irq_clear = ata_bmdma_irq_clear,
  335. .irq_on = ata_irq_on,
  336. .port_start = ata_sff_port_start,
  337. };
  338. /*
  339. * Port operations for DMA capable ALi with cable detect
  340. */
  341. static struct ata_port_operations ali_c2_port_ops = {
  342. .set_piomode = ali_set_piomode,
  343. .set_dmamode = ali_set_dmamode,
  344. .mode_filter = ata_pci_default_filter,
  345. .tf_load = ata_tf_load,
  346. .tf_read = ata_tf_read,
  347. .check_atapi_dma = ali_check_atapi_dma,
  348. .check_status = ata_check_status,
  349. .exec_command = ata_exec_command,
  350. .dev_select = ata_std_dev_select,
  351. .dev_config = ali_lock_sectors,
  352. .freeze = ata_bmdma_freeze,
  353. .thaw = ata_bmdma_thaw,
  354. .error_handler = ata_bmdma_error_handler,
  355. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  356. .cable_detect = ali_c2_cable_detect,
  357. .bmdma_setup = ata_bmdma_setup,
  358. .bmdma_start = ata_bmdma_start,
  359. .bmdma_stop = ata_bmdma_stop,
  360. .bmdma_status = ata_bmdma_status,
  361. .qc_prep = ata_qc_prep,
  362. .qc_issue = ata_qc_issue_prot,
  363. .data_xfer = ata_data_xfer,
  364. .irq_handler = ata_interrupt,
  365. .irq_clear = ata_bmdma_irq_clear,
  366. .irq_on = ata_irq_on,
  367. .port_start = ata_sff_port_start,
  368. };
  369. /*
  370. * Port operations for DMA capable ALi with cable detect and LBA48
  371. */
  372. static struct ata_port_operations ali_c5_port_ops = {
  373. .set_piomode = ali_set_piomode,
  374. .set_dmamode = ali_set_dmamode,
  375. .mode_filter = ata_pci_default_filter,
  376. .tf_load = ata_tf_load,
  377. .tf_read = ata_tf_read,
  378. .check_atapi_dma = ali_check_atapi_dma,
  379. .check_status = ata_check_status,
  380. .exec_command = ata_exec_command,
  381. .dev_select = ata_std_dev_select,
  382. .freeze = ata_bmdma_freeze,
  383. .thaw = ata_bmdma_thaw,
  384. .error_handler = ata_bmdma_error_handler,
  385. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  386. .cable_detect = ali_c2_cable_detect,
  387. .bmdma_setup = ata_bmdma_setup,
  388. .bmdma_start = ata_bmdma_start,
  389. .bmdma_stop = ata_bmdma_stop,
  390. .bmdma_status = ata_bmdma_status,
  391. .qc_prep = ata_qc_prep,
  392. .qc_issue = ata_qc_issue_prot,
  393. .data_xfer = ata_data_xfer,
  394. .irq_handler = ata_interrupt,
  395. .irq_clear = ata_bmdma_irq_clear,
  396. .irq_on = ata_irq_on,
  397. .port_start = ata_sff_port_start,
  398. };
  399. /**
  400. * ali_init_chipset - chip setup function
  401. * @pdev: PCI device of ATA controller
  402. *
  403. * Perform the setup on the device that must be done both at boot
  404. * and at resume time.
  405. */
  406. static void ali_init_chipset(struct pci_dev *pdev)
  407. {
  408. u8 tmp;
  409. struct pci_dev *north, *isa_bridge;
  410. /*
  411. * The chipset revision selects the driver operations and
  412. * mode data.
  413. */
  414. if (pdev->revision >= 0x20 && pdev->revision < 0xC2) {
  415. /* 1543-E/F, 1543C-C, 1543C-D, 1543C-E */
  416. pci_read_config_byte(pdev, 0x4B, &tmp);
  417. /* Clear CD-ROM DMA write bit */
  418. tmp &= 0x7F;
  419. pci_write_config_byte(pdev, 0x4B, tmp);
  420. } else if (pdev->revision >= 0xC2) {
  421. /* Enable cable detection logic */
  422. pci_read_config_byte(pdev, 0x4B, &tmp);
  423. pci_write_config_byte(pdev, 0x4B, tmp | 0x08);
  424. }
  425. north = pci_get_bus_and_slot(0, PCI_DEVFN(0,0));
  426. isa_bridge = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533, NULL);
  427. if (north && north->vendor == PCI_VENDOR_ID_AL && isa_bridge) {
  428. /* Configure the ALi bridge logic. For non ALi rely on BIOS.
  429. Set the south bridge enable bit */
  430. pci_read_config_byte(isa_bridge, 0x79, &tmp);
  431. if (pdev->revision == 0xC2)
  432. pci_write_config_byte(isa_bridge, 0x79, tmp | 0x04);
  433. else if (pdev->revision > 0xC2 && pdev->revision < 0xC5)
  434. pci_write_config_byte(isa_bridge, 0x79, tmp | 0x02);
  435. }
  436. if (pdev->revision >= 0x20) {
  437. /*
  438. * CD_ROM DMA on (0x53 bit 0). Enable this even if we want
  439. * to use PIO. 0x53 bit 1 (rev 20 only) - enable FIFO control
  440. * via 0x54/55.
  441. */
  442. pci_read_config_byte(pdev, 0x53, &tmp);
  443. if (pdev->revision <= 0x20)
  444. tmp &= ~0x02;
  445. if (pdev->revision >= 0xc7)
  446. tmp |= 0x03;
  447. else
  448. tmp |= 0x01; /* CD_ROM enable for DMA */
  449. pci_write_config_byte(pdev, 0x53, tmp);
  450. }
  451. pci_dev_put(isa_bridge);
  452. pci_dev_put(north);
  453. ata_pci_clear_simplex(pdev);
  454. }
  455. /**
  456. * ali_init_one - discovery callback
  457. * @pdev: PCI device ID
  458. * @id: PCI table info
  459. *
  460. * An ALi IDE interface has been discovered. Figure out what revision
  461. * and perform configuration work before handing it to the ATA layer
  462. */
  463. static int ali_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
  464. {
  465. static const struct ata_port_info info_early = {
  466. .sht = &ali_sht,
  467. .flags = ATA_FLAG_SLAVE_POSS,
  468. .pio_mask = 0x1f,
  469. .port_ops = &ali_early_port_ops
  470. };
  471. /* Revision 0x20 added DMA */
  472. static const struct ata_port_info info_20 = {
  473. .sht = &ali_sht,
  474. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_PIO_LBA48,
  475. .pio_mask = 0x1f,
  476. .mwdma_mask = 0x07,
  477. .port_ops = &ali_20_port_ops
  478. };
  479. /* Revision 0x20 with support logic added UDMA */
  480. static const struct ata_port_info info_20_udma = {
  481. .sht = &ali_sht,
  482. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_PIO_LBA48,
  483. .pio_mask = 0x1f,
  484. .mwdma_mask = 0x07,
  485. .udma_mask = 0x07, /* UDMA33 */
  486. .port_ops = &ali_20_port_ops
  487. };
  488. /* Revision 0xC2 adds UDMA66 */
  489. static const struct ata_port_info info_c2 = {
  490. .sht = &ali_sht,
  491. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_PIO_LBA48,
  492. .pio_mask = 0x1f,
  493. .mwdma_mask = 0x07,
  494. .udma_mask = ATA_UDMA4,
  495. .port_ops = &ali_c2_port_ops
  496. };
  497. /* Revision 0xC3 is UDMA66 for now */
  498. static const struct ata_port_info info_c3 = {
  499. .sht = &ali_sht,
  500. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_PIO_LBA48,
  501. .pio_mask = 0x1f,
  502. .mwdma_mask = 0x07,
  503. .udma_mask = ATA_UDMA4,
  504. .port_ops = &ali_c2_port_ops
  505. };
  506. /* Revision 0xC4 is UDMA100 */
  507. static const struct ata_port_info info_c4 = {
  508. .sht = &ali_sht,
  509. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_PIO_LBA48,
  510. .pio_mask = 0x1f,
  511. .mwdma_mask = 0x07,
  512. .udma_mask = ATA_UDMA5,
  513. .port_ops = &ali_c2_port_ops
  514. };
  515. /* Revision 0xC5 is UDMA133 with LBA48 DMA */
  516. static const struct ata_port_info info_c5 = {
  517. .sht = &ali_sht,
  518. .flags = ATA_FLAG_SLAVE_POSS,
  519. .pio_mask = 0x1f,
  520. .mwdma_mask = 0x07,
  521. .udma_mask = ATA_UDMA6,
  522. .port_ops = &ali_c5_port_ops
  523. };
  524. const struct ata_port_info *ppi[] = { NULL, NULL };
  525. u8 tmp;
  526. struct pci_dev *isa_bridge;
  527. /*
  528. * The chipset revision selects the driver operations and
  529. * mode data.
  530. */
  531. if (pdev->revision < 0x20) {
  532. ppi[0] = &info_early;
  533. } else if (pdev->revision < 0xC2) {
  534. ppi[0] = &info_20;
  535. } else if (pdev->revision == 0xC2) {
  536. ppi[0] = &info_c2;
  537. } else if (pdev->revision == 0xC3) {
  538. ppi[0] = &info_c3;
  539. } else if (pdev->revision == 0xC4) {
  540. ppi[0] = &info_c4;
  541. } else
  542. ppi[0] = &info_c5;
  543. ali_init_chipset(pdev);
  544. isa_bridge = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533, NULL);
  545. if (isa_bridge && pdev->revision >= 0x20 && pdev->revision < 0xC2) {
  546. /* Are we paired with a UDMA capable chip */
  547. pci_read_config_byte(isa_bridge, 0x5E, &tmp);
  548. if ((tmp & 0x1E) == 0x12)
  549. ppi[0] = &info_20_udma;
  550. pci_dev_put(isa_bridge);
  551. }
  552. return ata_pci_init_one(pdev, ppi);
  553. }
  554. #ifdef CONFIG_PM
  555. static int ali_reinit_one(struct pci_dev *pdev)
  556. {
  557. ali_init_chipset(pdev);
  558. return ata_pci_device_resume(pdev);
  559. }
  560. #endif
  561. static const struct pci_device_id ali[] = {
  562. { PCI_VDEVICE(AL, PCI_DEVICE_ID_AL_M5228), },
  563. { PCI_VDEVICE(AL, PCI_DEVICE_ID_AL_M5229), },
  564. { },
  565. };
  566. static struct pci_driver ali_pci_driver = {
  567. .name = DRV_NAME,
  568. .id_table = ali,
  569. .probe = ali_init_one,
  570. .remove = ata_pci_remove_one,
  571. #ifdef CONFIG_PM
  572. .suspend = ata_pci_device_suspend,
  573. .resume = ali_reinit_one,
  574. #endif
  575. };
  576. static int __init ali_init(void)
  577. {
  578. return pci_register_driver(&ali_pci_driver);
  579. }
  580. static void __exit ali_exit(void)
  581. {
  582. pci_unregister_driver(&ali_pci_driver);
  583. }
  584. MODULE_AUTHOR("Alan Cox");
  585. MODULE_DESCRIPTION("low-level driver for ALi PATA");
  586. MODULE_LICENSE("GPL");
  587. MODULE_DEVICE_TABLE(pci, ali);
  588. MODULE_VERSION(DRV_VERSION);
  589. module_init(ali_init);
  590. module_exit(ali_exit);