pata_ali.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711
  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.2"
  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(const struct ata_port *ap, 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(ap, 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_port *ap, 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. .resume = ata_scsi_device_resume,
  307. .suspend = ata_scsi_device_suspend,
  308. };
  309. /*
  310. * Port operations for PIO only ALi
  311. */
  312. static struct ata_port_operations ali_early_port_ops = {
  313. .port_disable = ata_port_disable,
  314. .set_piomode = ali_set_piomode,
  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. .freeze = ata_bmdma_freeze,
  321. .thaw = ata_bmdma_thaw,
  322. .error_handler = ali_early_error_handler,
  323. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  324. .qc_prep = ata_qc_prep,
  325. .qc_issue = ata_qc_issue_prot,
  326. .data_xfer = ata_data_xfer,
  327. .irq_handler = ata_interrupt,
  328. .irq_clear = ata_bmdma_irq_clear,
  329. .irq_on = ata_irq_on,
  330. .irq_ack = ata_irq_ack,
  331. .port_start = ata_port_start,
  332. };
  333. /*
  334. * Port operations for DMA capable ALi without cable
  335. * detect
  336. */
  337. static struct ata_port_operations ali_20_port_ops = {
  338. .port_disable = ata_port_disable,
  339. .set_piomode = ali_set_piomode,
  340. .set_dmamode = ali_set_dmamode,
  341. .mode_filter = ali_20_filter,
  342. .tf_load = ata_tf_load,
  343. .tf_read = ata_tf_read,
  344. .check_status = ata_check_status,
  345. .exec_command = ata_exec_command,
  346. .dev_select = ata_std_dev_select,
  347. .dev_config = ali_lock_sectors,
  348. .freeze = ata_bmdma_freeze,
  349. .thaw = ata_bmdma_thaw,
  350. .error_handler = ali_early_error_handler,
  351. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  352. .bmdma_setup = ata_bmdma_setup,
  353. .bmdma_start = ata_bmdma_start,
  354. .bmdma_stop = ata_bmdma_stop,
  355. .bmdma_status = ata_bmdma_status,
  356. .qc_prep = ata_qc_prep,
  357. .qc_issue = ata_qc_issue_prot,
  358. .data_xfer = ata_data_xfer,
  359. .irq_handler = ata_interrupt,
  360. .irq_clear = ata_bmdma_irq_clear,
  361. .irq_on = ata_irq_on,
  362. .irq_ack = ata_irq_ack,
  363. .port_start = ata_port_start,
  364. };
  365. /*
  366. * Port operations for DMA capable ALi with cable detect
  367. */
  368. static struct ata_port_operations ali_c2_port_ops = {
  369. .port_disable = ata_port_disable,
  370. .set_piomode = ali_set_piomode,
  371. .set_dmamode = ali_set_dmamode,
  372. .mode_filter = ata_pci_default_filter,
  373. .tf_load = ata_tf_load,
  374. .tf_read = ata_tf_read,
  375. .check_status = ata_check_status,
  376. .exec_command = ata_exec_command,
  377. .dev_select = ata_std_dev_select,
  378. .dev_config = ali_lock_sectors,
  379. .freeze = ata_bmdma_freeze,
  380. .thaw = ata_bmdma_thaw,
  381. .error_handler = ali_c2_error_handler,
  382. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  383. .bmdma_setup = ata_bmdma_setup,
  384. .bmdma_start = ata_bmdma_start,
  385. .bmdma_stop = ata_bmdma_stop,
  386. .bmdma_status = ata_bmdma_status,
  387. .qc_prep = ata_qc_prep,
  388. .qc_issue = ata_qc_issue_prot,
  389. .data_xfer = ata_data_xfer,
  390. .irq_handler = ata_interrupt,
  391. .irq_clear = ata_bmdma_irq_clear,
  392. .irq_on = ata_irq_on,
  393. .irq_ack = ata_irq_ack,
  394. .port_start = ata_port_start,
  395. };
  396. /*
  397. * Port operations for DMA capable ALi with cable detect and LBA48
  398. */
  399. static struct ata_port_operations ali_c5_port_ops = {
  400. .port_disable = ata_port_disable,
  401. .set_piomode = ali_set_piomode,
  402. .set_dmamode = ali_set_dmamode,
  403. .mode_filter = ata_pci_default_filter,
  404. .tf_load = ata_tf_load,
  405. .tf_read = ata_tf_read,
  406. .check_status = ata_check_status,
  407. .exec_command = ata_exec_command,
  408. .dev_select = ata_std_dev_select,
  409. .freeze = ata_bmdma_freeze,
  410. .thaw = ata_bmdma_thaw,
  411. .error_handler = ali_c2_error_handler,
  412. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  413. .bmdma_setup = ata_bmdma_setup,
  414. .bmdma_start = ata_bmdma_start,
  415. .bmdma_stop = ata_bmdma_stop,
  416. .bmdma_status = ata_bmdma_status,
  417. .qc_prep = ata_qc_prep,
  418. .qc_issue = ata_qc_issue_prot,
  419. .data_xfer = ata_data_xfer,
  420. .irq_handler = ata_interrupt,
  421. .irq_clear = ata_bmdma_irq_clear,
  422. .irq_on = ata_irq_on,
  423. .irq_ack = ata_irq_ack,
  424. .port_start = ata_port_start,
  425. };
  426. /**
  427. * ali_init_chipset - chip setup function
  428. * @pdev: PCI device of ATA controller
  429. *
  430. * Perform the setup on the device that must be done both at boot
  431. * and at resume time.
  432. */
  433. static void ali_init_chipset(struct pci_dev *pdev)
  434. {
  435. u8 rev, tmp;
  436. struct pci_dev *north, *isa_bridge;
  437. pci_read_config_byte(pdev, PCI_REVISION_ID, &rev);
  438. /*
  439. * The chipset revision selects the driver operations and
  440. * mode data.
  441. */
  442. if (rev >= 0x20 && rev < 0xC2) {
  443. /* 1543-E/F, 1543C-C, 1543C-D, 1543C-E */
  444. pci_read_config_byte(pdev, 0x4B, &tmp);
  445. /* Clear CD-ROM DMA write bit */
  446. tmp &= 0x7F;
  447. pci_write_config_byte(pdev, 0x4B, tmp);
  448. } else if (rev >= 0xC2) {
  449. /* Enable cable detection logic */
  450. pci_read_config_byte(pdev, 0x4B, &tmp);
  451. pci_write_config_byte(pdev, 0x4B, tmp | 0x08);
  452. }
  453. north = pci_get_bus_and_slot(0, PCI_DEVFN(0,0));
  454. isa_bridge = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533, NULL);
  455. if (north && north->vendor == PCI_VENDOR_ID_AL && isa_bridge) {
  456. /* Configure the ALi bridge logic. For non ALi rely on BIOS.
  457. Set the south bridge enable bit */
  458. pci_read_config_byte(isa_bridge, 0x79, &tmp);
  459. if (rev == 0xC2)
  460. pci_write_config_byte(isa_bridge, 0x79, tmp | 0x04);
  461. else if (rev > 0xC2 && rev < 0xC5)
  462. pci_write_config_byte(isa_bridge, 0x79, tmp | 0x02);
  463. }
  464. if (rev >= 0x20) {
  465. /*
  466. * CD_ROM DMA on (0x53 bit 0). Enable this even if we want
  467. * to use PIO. 0x53 bit 1 (rev 20 only) - enable FIFO control
  468. * via 0x54/55.
  469. */
  470. pci_read_config_byte(pdev, 0x53, &tmp);
  471. if (rev <= 0x20)
  472. tmp &= ~0x02;
  473. if (rev >= 0xc7)
  474. tmp |= 0x03;
  475. else
  476. tmp |= 0x01; /* CD_ROM enable for DMA */
  477. pci_write_config_byte(pdev, 0x53, tmp);
  478. }
  479. pci_dev_put(isa_bridge);
  480. pci_dev_put(north);
  481. ata_pci_clear_simplex(pdev);
  482. }
  483. /**
  484. * ali_init_one - discovery callback
  485. * @pdev: PCI device ID
  486. * @id: PCI table info
  487. *
  488. * An ALi IDE interface has been discovered. Figure out what revision
  489. * and perform configuration work before handing it to the ATA layer
  490. */
  491. static int ali_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
  492. {
  493. static struct ata_port_info info_early = {
  494. .sht = &ali_sht,
  495. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  496. .pio_mask = 0x1f,
  497. .port_ops = &ali_early_port_ops
  498. };
  499. /* Revision 0x20 added DMA */
  500. static struct ata_port_info info_20 = {
  501. .sht = &ali_sht,
  502. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST | ATA_FLAG_PIO_LBA48,
  503. .pio_mask = 0x1f,
  504. .mwdma_mask = 0x07,
  505. .port_ops = &ali_20_port_ops
  506. };
  507. /* Revision 0x20 with support logic added UDMA */
  508. static struct ata_port_info info_20_udma = {
  509. .sht = &ali_sht,
  510. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST | ATA_FLAG_PIO_LBA48,
  511. .pio_mask = 0x1f,
  512. .mwdma_mask = 0x07,
  513. .udma_mask = 0x07, /* UDMA33 */
  514. .port_ops = &ali_20_port_ops
  515. };
  516. /* Revision 0xC2 adds UDMA66 */
  517. static struct ata_port_info info_c2 = {
  518. .sht = &ali_sht,
  519. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST | ATA_FLAG_PIO_LBA48,
  520. .pio_mask = 0x1f,
  521. .mwdma_mask = 0x07,
  522. .udma_mask = 0x1f,
  523. .port_ops = &ali_c2_port_ops
  524. };
  525. /* Revision 0xC3 is UDMA100 */
  526. static struct ata_port_info info_c3 = {
  527. .sht = &ali_sht,
  528. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST | ATA_FLAG_PIO_LBA48,
  529. .pio_mask = 0x1f,
  530. .mwdma_mask = 0x07,
  531. .udma_mask = 0x3f,
  532. .port_ops = &ali_c2_port_ops
  533. };
  534. /* Revision 0xC4 is UDMA133 */
  535. static struct ata_port_info info_c4 = {
  536. .sht = &ali_sht,
  537. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST | ATA_FLAG_PIO_LBA48,
  538. .pio_mask = 0x1f,
  539. .mwdma_mask = 0x07,
  540. .udma_mask = 0x7f,
  541. .port_ops = &ali_c2_port_ops
  542. };
  543. /* Revision 0xC5 is UDMA133 with LBA48 DMA */
  544. static struct ata_port_info info_c5 = {
  545. .sht = &ali_sht,
  546. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  547. .pio_mask = 0x1f,
  548. .mwdma_mask = 0x07,
  549. .udma_mask = 0x7f,
  550. .port_ops = &ali_c5_port_ops
  551. };
  552. static struct ata_port_info *port_info[2];
  553. u8 rev, tmp;
  554. struct pci_dev *isa_bridge;
  555. pci_read_config_byte(pdev, PCI_REVISION_ID, &rev);
  556. /*
  557. * The chipset revision selects the driver operations and
  558. * mode data.
  559. */
  560. if (rev < 0x20) {
  561. port_info[0] = port_info[1] = &info_early;
  562. } else if (rev < 0xC2) {
  563. port_info[0] = port_info[1] = &info_20;
  564. } else if (rev == 0xC2) {
  565. port_info[0] = port_info[1] = &info_c2;
  566. } else if (rev == 0xC3) {
  567. port_info[0] = port_info[1] = &info_c3;
  568. } else if (rev == 0xC4) {
  569. port_info[0] = port_info[1] = &info_c4;
  570. } else
  571. port_info[0] = port_info[1] = &info_c5;
  572. ali_init_chipset(pdev);
  573. isa_bridge = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533, NULL);
  574. if (isa_bridge && rev >= 0x20 && rev < 0xC2) {
  575. /* Are we paired with a UDMA capable chip */
  576. pci_read_config_byte(isa_bridge, 0x5E, &tmp);
  577. if ((tmp & 0x1E) == 0x12)
  578. port_info[0] = port_info[1] = &info_20_udma;
  579. pci_dev_put(isa_bridge);
  580. }
  581. return ata_pci_init_one(pdev, port_info, 2);
  582. }
  583. static int ali_reinit_one(struct pci_dev *pdev)
  584. {
  585. ali_init_chipset(pdev);
  586. return ata_pci_device_resume(pdev);
  587. }
  588. static const struct pci_device_id ali[] = {
  589. { PCI_VDEVICE(AL, PCI_DEVICE_ID_AL_M5228), },
  590. { PCI_VDEVICE(AL, PCI_DEVICE_ID_AL_M5229), },
  591. { },
  592. };
  593. static struct pci_driver ali_pci_driver = {
  594. .name = DRV_NAME,
  595. .id_table = ali,
  596. .probe = ali_init_one,
  597. .remove = ata_pci_remove_one,
  598. .suspend = ata_pci_device_suspend,
  599. .resume = ali_reinit_one,
  600. };
  601. static int __init ali_init(void)
  602. {
  603. return pci_register_driver(&ali_pci_driver);
  604. }
  605. static void __exit ali_exit(void)
  606. {
  607. pci_unregister_driver(&ali_pci_driver);
  608. }
  609. MODULE_AUTHOR("Alan Cox");
  610. MODULE_DESCRIPTION("low-level driver for ALi PATA");
  611. MODULE_LICENSE("GPL");
  612. MODULE_DEVICE_TABLE(pci, ali);
  613. MODULE_VERSION(DRV_VERSION);
  614. module_init(ali_init);
  615. module_exit(ali_exit);