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