pata_ali.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. /*
  2. * pata_ali.c - ALI 15x3 PATA for new ATA layer
  3. * (C) 2005 Red Hat Inc
  4. *
  5. * based in part upon
  6. * linux/drivers/ide/pci/alim15x3.c Version 0.17 2003/01/02
  7. *
  8. * Copyright (C) 1998-2000 Michel Aubry, Maintainer
  9. * Copyright (C) 1998-2000 Andrzej Krzysztofowicz, Maintainer
  10. * Copyright (C) 1999-2000 CJ, cjtsai@ali.com.tw, Maintainer
  11. *
  12. * Copyright (C) 1998-2000 Andre Hedrick (andre@linux-ide.org)
  13. * May be copied or modified under the terms of the GNU General Public License
  14. * Copyright (C) 2002 Alan Cox <alan@redhat.com>
  15. * ALi (now ULi M5228) support by Clear Zhang <Clear.Zhang@ali.com.tw>
  16. *
  17. * Documentation
  18. * Chipset documentation available under NDA only
  19. *
  20. * TODO/CHECK
  21. * Cannot have ATAPI on both master & slave for rev < c2 (???) but
  22. * otherwise should do atapi DMA (For now for old we do PIO only for
  23. * ATAPI)
  24. * Review Sunblade workaround.
  25. */
  26. #include <linux/kernel.h>
  27. #include <linux/module.h>
  28. #include <linux/pci.h>
  29. #include <linux/init.h>
  30. #include <linux/blkdev.h>
  31. #include <linux/delay.h>
  32. #include <scsi/scsi_host.h>
  33. #include <linux/libata.h>
  34. #include <linux/dmi.h>
  35. #define DRV_NAME "pata_ali"
  36. #define DRV_VERSION "0.7.8"
  37. static int ali_atapi_dma = 0;
  38. module_param_named(atapi_dma, ali_atapi_dma, int, 0644);
  39. MODULE_PARM_DESC(atapi_dma, "Enable ATAPI DMA (0=disable, 1=enable)");
  40. static struct pci_dev *ali_isa_bridge;
  41. /*
  42. * Cable special cases
  43. */
  44. static const struct dmi_system_id cable_dmi_table[] = {
  45. {
  46. .ident = "HP Pavilion N5430",
  47. .matches = {
  48. DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
  49. DMI_MATCH(DMI_BOARD_VERSION, "OmniBook N32N-736"),
  50. },
  51. },
  52. {
  53. .ident = "Toshiba Satellite S1800-814",
  54. .matches = {
  55. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  56. DMI_MATCH(DMI_PRODUCT_NAME, "S1800-814"),
  57. },
  58. },
  59. { }
  60. };
  61. static int ali_cable_override(struct pci_dev *pdev)
  62. {
  63. /* Fujitsu P2000 */
  64. if (pdev->subsystem_vendor == 0x10CF && pdev->subsystem_device == 0x10AF)
  65. return 1;
  66. /* Mitac 8317 (Winbook-A) and relatives */
  67. if (pdev->subsystem_vendor == 0x1071 && pdev->subsystem_device == 0x8317)
  68. return 1;
  69. /* Systems by DMI */
  70. if (dmi_check_system(cable_dmi_table))
  71. return 1;
  72. return 0;
  73. }
  74. /**
  75. * ali_c2_cable_detect - cable detection
  76. * @ap: ATA port
  77. *
  78. * Perform cable detection for C2 and later revisions
  79. */
  80. static int ali_c2_cable_detect(struct ata_port *ap)
  81. {
  82. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  83. u8 ata66;
  84. /* Certain laptops use short but suitable cables and don't
  85. implement the detect logic */
  86. if (ali_cable_override(pdev))
  87. return ATA_CBL_PATA40_SHORT;
  88. /* Host view cable detect 0x4A bit 0 primary bit 1 secondary
  89. Bit set for 40 pin */
  90. pci_read_config_byte(pdev, 0x4A, &ata66);
  91. if (ata66 & (1 << ap->port_no))
  92. return ATA_CBL_PATA40;
  93. else
  94. return ATA_CBL_PATA80;
  95. }
  96. /**
  97. * ali_20_filter - filter for earlier ALI DMA
  98. * @ap: ALi ATA port
  99. * @adev: attached device
  100. *
  101. * Ensure that we do not do DMA on CD devices. We may be able to
  102. * fix that later on. Also ensure we do not do UDMA on WDC drives
  103. */
  104. static unsigned long ali_20_filter(struct ata_device *adev, unsigned long mask)
  105. {
  106. char model_num[ATA_ID_PROD_LEN + 1];
  107. /* No DMA on anything but a disk for now */
  108. if (adev->class != ATA_DEV_ATA)
  109. mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA);
  110. ata_id_c_string(adev->id, model_num, ATA_ID_PROD, sizeof(model_num));
  111. if (strstr(model_num, "WDC"))
  112. return mask &= ~ATA_MASK_UDMA;
  113. return mask;
  114. }
  115. /**
  116. * ali_fifo_control - FIFO manager
  117. * @ap: ALi channel to control
  118. * @adev: device for FIFO control
  119. * @on: 0 for off 1 for on
  120. *
  121. * Enable or disable the FIFO on a given device. Because of the way the
  122. * ALi FIFO works it provides a boost on ATA disk but can be confused by
  123. * ATAPI and we must therefore manage it.
  124. */
  125. static void ali_fifo_control(struct ata_port *ap, struct ata_device *adev, int on)
  126. {
  127. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  128. int pio_fifo = 0x54 + ap->port_no;
  129. u8 fifo;
  130. int shift = 4 * adev->devno;
  131. /* ATA - FIFO on set nibble to 0x05, ATAPI - FIFO off, set nibble to
  132. 0x00. Not all the docs agree but the behaviour we now use is the
  133. one stated in the BIOS Programming Guide */
  134. pci_read_config_byte(pdev, pio_fifo, &fifo);
  135. fifo &= ~(0x0F << shift);
  136. fifo |= (on << shift);
  137. pci_write_config_byte(pdev, pio_fifo, fifo);
  138. }
  139. /**
  140. * ali_program_modes - load mode registers
  141. * @ap: ALi channel to load
  142. * @adev: Device the timing is for
  143. * @t: timing data
  144. * @ultra: UDMA timing or zero for off
  145. *
  146. * Loads the timing registers for cmd/data and disable UDMA if
  147. * ultra is zero. If ultra is set then load and enable the UDMA
  148. * timing but do not touch the command/data timing.
  149. */
  150. static void ali_program_modes(struct ata_port *ap, struct ata_device *adev, struct ata_timing *t, u8 ultra)
  151. {
  152. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  153. int cas = 0x58 + 4 * ap->port_no; /* Command timing */
  154. int cbt = 0x59 + 4 * ap->port_no; /* Command timing */
  155. int drwt = 0x5A + 4 * ap->port_no + adev->devno; /* R/W timing */
  156. int udmat = 0x56 + ap->port_no; /* UDMA timing */
  157. int shift = 4 * adev->devno;
  158. u8 udma;
  159. if (t != NULL) {
  160. t->setup = clamp_val(t->setup, 1, 8) & 7;
  161. t->act8b = clamp_val(t->act8b, 1, 8) & 7;
  162. t->rec8b = clamp_val(t->rec8b, 1, 16) & 15;
  163. t->active = clamp_val(t->active, 1, 8) & 7;
  164. t->recover = clamp_val(t->recover, 1, 16) & 15;
  165. pci_write_config_byte(pdev, cas, t->setup);
  166. pci_write_config_byte(pdev, cbt, (t->act8b << 4) | t->rec8b);
  167. pci_write_config_byte(pdev, drwt, (t->active << 4) | t->recover);
  168. }
  169. /* Set up the UDMA enable */
  170. pci_read_config_byte(pdev, udmat, &udma);
  171. udma &= ~(0x0F << shift);
  172. udma |= ultra << shift;
  173. pci_write_config_byte(pdev, udmat, udma);
  174. }
  175. /**
  176. * ali_set_piomode - set initial PIO mode data
  177. * @ap: ATA interface
  178. * @adev: ATA device
  179. *
  180. * Program the ALi registers for PIO mode.
  181. */
  182. static void ali_set_piomode(struct ata_port *ap, struct ata_device *adev)
  183. {
  184. struct ata_device *pair = ata_dev_pair(adev);
  185. struct ata_timing t;
  186. unsigned long T = 1000000000 / 33333; /* PCI clock based */
  187. ata_timing_compute(adev, adev->pio_mode, &t, T, 1);
  188. if (pair) {
  189. struct ata_timing p;
  190. ata_timing_compute(pair, pair->pio_mode, &p, T, 1);
  191. ata_timing_merge(&p, &t, &t, ATA_TIMING_SETUP|ATA_TIMING_8BIT);
  192. if (pair->dma_mode) {
  193. ata_timing_compute(pair, pair->dma_mode, &p, T, 1);
  194. ata_timing_merge(&p, &t, &t, ATA_TIMING_SETUP|ATA_TIMING_8BIT);
  195. }
  196. }
  197. /* PIO FIFO is only permitted on ATA disk */
  198. if (adev->class != ATA_DEV_ATA)
  199. ali_fifo_control(ap, adev, 0x00);
  200. ali_program_modes(ap, adev, &t, 0);
  201. if (adev->class == ATA_DEV_ATA)
  202. ali_fifo_control(ap, adev, 0x05);
  203. }
  204. /**
  205. * ali_set_dmamode - set initial DMA mode data
  206. * @ap: ATA interface
  207. * @adev: ATA device
  208. *
  209. * Program the ALi registers for DMA mode.
  210. */
  211. static void ali_set_dmamode(struct ata_port *ap, struct ata_device *adev)
  212. {
  213. static u8 udma_timing[7] = { 0xC, 0xB, 0xA, 0x9, 0x8, 0xF, 0xD };
  214. struct ata_device *pair = ata_dev_pair(adev);
  215. struct ata_timing t;
  216. unsigned long T = 1000000000 / 33333; /* PCI clock based */
  217. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  218. if (adev->class == ATA_DEV_ATA)
  219. ali_fifo_control(ap, adev, 0x08);
  220. if (adev->dma_mode >= XFER_UDMA_0) {
  221. ali_program_modes(ap, adev, NULL, udma_timing[adev->dma_mode - XFER_UDMA_0]);
  222. if (adev->dma_mode >= XFER_UDMA_3) {
  223. u8 reg4b;
  224. pci_read_config_byte(pdev, 0x4B, &reg4b);
  225. reg4b |= 1;
  226. pci_write_config_byte(pdev, 0x4B, reg4b);
  227. }
  228. } else {
  229. ata_timing_compute(adev, adev->dma_mode, &t, T, 1);
  230. if (pair) {
  231. struct ata_timing p;
  232. ata_timing_compute(pair, pair->pio_mode, &p, T, 1);
  233. ata_timing_merge(&p, &t, &t, ATA_TIMING_SETUP|ATA_TIMING_8BIT);
  234. if (pair->dma_mode) {
  235. ata_timing_compute(pair, pair->dma_mode, &p, T, 1);
  236. ata_timing_merge(&p, &t, &t, ATA_TIMING_SETUP|ATA_TIMING_8BIT);
  237. }
  238. }
  239. ali_program_modes(ap, adev, &t, 0);
  240. }
  241. }
  242. /**
  243. * ali_warn_atapi_dma - Warn about ATAPI DMA disablement
  244. * @adev: Device
  245. *
  246. * Whine about ATAPI DMA disablement if @adev is an ATAPI device.
  247. * Can be used as ->dev_config.
  248. */
  249. static void ali_warn_atapi_dma(struct ata_device *adev)
  250. {
  251. struct ata_eh_context *ehc = &adev->link->eh_context;
  252. int print_info = ehc->i.flags & ATA_EHI_PRINTINFO;
  253. if (print_info && adev->class == ATA_DEV_ATAPI && !ali_atapi_dma) {
  254. ata_dev_warn(adev,
  255. "WARNING: ATAPI DMA disabled for reliability issues. It can be enabled\n");
  256. ata_dev_warn(adev,
  257. "WARNING: via pata_ali.atapi_dma modparam or corresponding sysfs node.\n");
  258. }
  259. }
  260. /**
  261. * ali_lock_sectors - Keep older devices to 255 sector mode
  262. * @adev: Device
  263. *
  264. * Called during the bus probe for each device that is found. We use
  265. * this call to lock the sector count of the device to 255 or less on
  266. * older ALi controllers. If we didn't do this then large I/O's would
  267. * require LBA48 commands which the older ALi requires are issued by
  268. * slower PIO methods
  269. */
  270. static void ali_lock_sectors(struct ata_device *adev)
  271. {
  272. adev->max_sectors = 255;
  273. ali_warn_atapi_dma(adev);
  274. }
  275. /**
  276. * ali_check_atapi_dma - DMA check for most ALi controllers
  277. * @adev: Device
  278. *
  279. * Called to decide whether commands should be sent by DMA or PIO
  280. */
  281. static int ali_check_atapi_dma(struct ata_queued_cmd *qc)
  282. {
  283. if (!ali_atapi_dma) {
  284. /* FIXME: pata_ali can't do ATAPI DMA reliably but the
  285. * IDE alim15x3 driver can. I tried lots of things
  286. * but couldn't find what the actual difference was.
  287. * If you got an idea, please write it to
  288. * linux-ide@vger.kernel.org and cc htejun@gmail.com.
  289. *
  290. * Disable ATAPI DMA for now.
  291. */
  292. return -EOPNOTSUPP;
  293. }
  294. /* If its not a media command, its not worth it */
  295. if (atapi_cmd_type(qc->cdb[0]) == ATAPI_MISC)
  296. return -EOPNOTSUPP;
  297. return 0;
  298. }
  299. static void ali_c2_c3_postreset(struct ata_link *link, unsigned int *classes)
  300. {
  301. u8 r;
  302. int port_bit = 4 << link->ap->port_no;
  303. /* If our bridge is an ALI 1533 then do the extra work */
  304. if (ali_isa_bridge) {
  305. /* Tristate and re-enable the bus signals */
  306. pci_read_config_byte(ali_isa_bridge, 0x58, &r);
  307. r &= ~port_bit;
  308. pci_write_config_byte(ali_isa_bridge, 0x58, r);
  309. r |= port_bit;
  310. pci_write_config_byte(ali_isa_bridge, 0x58, r);
  311. }
  312. ata_sff_postreset(link, classes);
  313. }
  314. static struct scsi_host_template ali_sht = {
  315. ATA_BMDMA_SHT(DRV_NAME),
  316. };
  317. /*
  318. * Port operations for PIO only ALi
  319. */
  320. static struct ata_port_operations ali_early_port_ops = {
  321. .inherits = &ata_sff_port_ops,
  322. .cable_detect = ata_cable_40wire,
  323. .set_piomode = ali_set_piomode,
  324. .sff_data_xfer = ata_sff_data_xfer32,
  325. };
  326. static const struct ata_port_operations ali_dma_base_ops = {
  327. .inherits = &ata_bmdma32_port_ops,
  328. .set_piomode = ali_set_piomode,
  329. .set_dmamode = ali_set_dmamode,
  330. };
  331. /*
  332. * Port operations for DMA capable ALi without cable
  333. * detect
  334. */
  335. static struct ata_port_operations ali_20_port_ops = {
  336. .inherits = &ali_dma_base_ops,
  337. .cable_detect = ata_cable_40wire,
  338. .mode_filter = ali_20_filter,
  339. .check_atapi_dma = ali_check_atapi_dma,
  340. .dev_config = ali_lock_sectors,
  341. };
  342. /*
  343. * Port operations for DMA capable ALi with cable detect
  344. */
  345. static struct ata_port_operations ali_c2_port_ops = {
  346. .inherits = &ali_dma_base_ops,
  347. .check_atapi_dma = ali_check_atapi_dma,
  348. .cable_detect = ali_c2_cable_detect,
  349. .dev_config = ali_lock_sectors,
  350. .postreset = ali_c2_c3_postreset,
  351. };
  352. /*
  353. * Port operations for DMA capable ALi with cable detect
  354. */
  355. static struct ata_port_operations ali_c4_port_ops = {
  356. .inherits = &ali_dma_base_ops,
  357. .check_atapi_dma = ali_check_atapi_dma,
  358. .cable_detect = ali_c2_cable_detect,
  359. .dev_config = ali_lock_sectors,
  360. };
  361. /*
  362. * Port operations for DMA capable ALi with cable detect and LBA48
  363. */
  364. static struct ata_port_operations ali_c5_port_ops = {
  365. .inherits = &ali_dma_base_ops,
  366. .check_atapi_dma = ali_check_atapi_dma,
  367. .dev_config = ali_warn_atapi_dma,
  368. .cable_detect = ali_c2_cable_detect,
  369. };
  370. /**
  371. * ali_init_chipset - chip setup function
  372. * @pdev: PCI device of ATA controller
  373. *
  374. * Perform the setup on the device that must be done both at boot
  375. * and at resume time.
  376. */
  377. static void ali_init_chipset(struct pci_dev *pdev)
  378. {
  379. u8 tmp;
  380. struct pci_dev *north;
  381. /*
  382. * The chipset revision selects the driver operations and
  383. * mode data.
  384. */
  385. if (pdev->revision <= 0x20) {
  386. pci_read_config_byte(pdev, 0x53, &tmp);
  387. tmp |= 0x03;
  388. pci_write_config_byte(pdev, 0x53, tmp);
  389. } else {
  390. pci_read_config_byte(pdev, 0x4a, &tmp);
  391. pci_write_config_byte(pdev, 0x4a, tmp | 0x20);
  392. pci_read_config_byte(pdev, 0x4B, &tmp);
  393. if (pdev->revision < 0xC2)
  394. /* 1543-E/F, 1543C-C, 1543C-D, 1543C-E */
  395. /* Clear CD-ROM DMA write bit */
  396. tmp &= 0x7F;
  397. /* Cable and UDMA */
  398. if (pdev->revision >= 0xc2)
  399. tmp |= 0x01;
  400. pci_write_config_byte(pdev, 0x4B, tmp | 0x08);
  401. /*
  402. * CD_ROM DMA on (0x53 bit 0). Enable this even if we want
  403. * to use PIO. 0x53 bit 1 (rev 20 only) - enable FIFO control
  404. * via 0x54/55.
  405. */
  406. pci_read_config_byte(pdev, 0x53, &tmp);
  407. if (pdev->revision >= 0xc7)
  408. tmp |= 0x03;
  409. else
  410. tmp |= 0x01; /* CD_ROM enable for DMA */
  411. pci_write_config_byte(pdev, 0x53, tmp);
  412. }
  413. north = pci_get_bus_and_slot(0, PCI_DEVFN(0,0));
  414. if (north && north->vendor == PCI_VENDOR_ID_AL && ali_isa_bridge) {
  415. /* Configure the ALi bridge logic. For non ALi rely on BIOS.
  416. Set the south bridge enable bit */
  417. pci_read_config_byte(ali_isa_bridge, 0x79, &tmp);
  418. if (pdev->revision == 0xC2)
  419. pci_write_config_byte(ali_isa_bridge, 0x79, tmp | 0x04);
  420. else if (pdev->revision > 0xC2 && pdev->revision < 0xC5)
  421. pci_write_config_byte(ali_isa_bridge, 0x79, tmp | 0x02);
  422. }
  423. pci_dev_put(north);
  424. ata_pci_bmdma_clear_simplex(pdev);
  425. }
  426. /**
  427. * ali_init_one - discovery callback
  428. * @pdev: PCI device ID
  429. * @id: PCI table info
  430. *
  431. * An ALi IDE interface has been discovered. Figure out what revision
  432. * and perform configuration work before handing it to the ATA layer
  433. */
  434. static int ali_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
  435. {
  436. static const struct ata_port_info info_early = {
  437. .flags = ATA_FLAG_SLAVE_POSS,
  438. .pio_mask = ATA_PIO4,
  439. .port_ops = &ali_early_port_ops
  440. };
  441. /* Revision 0x20 added DMA */
  442. static const struct ata_port_info info_20 = {
  443. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_PIO_LBA48 |
  444. ATA_FLAG_IGN_SIMPLEX,
  445. .pio_mask = ATA_PIO4,
  446. .mwdma_mask = ATA_MWDMA2,
  447. .port_ops = &ali_20_port_ops
  448. };
  449. /* Revision 0x20 with support logic added UDMA */
  450. static const struct ata_port_info info_20_udma = {
  451. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_PIO_LBA48 |
  452. ATA_FLAG_IGN_SIMPLEX,
  453. .pio_mask = ATA_PIO4,
  454. .mwdma_mask = ATA_MWDMA2,
  455. .udma_mask = ATA_UDMA2,
  456. .port_ops = &ali_20_port_ops
  457. };
  458. /* Revision 0xC2 adds UDMA66 */
  459. static const struct ata_port_info info_c2 = {
  460. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_PIO_LBA48 |
  461. ATA_FLAG_IGN_SIMPLEX,
  462. .pio_mask = ATA_PIO4,
  463. .mwdma_mask = ATA_MWDMA2,
  464. .udma_mask = ATA_UDMA4,
  465. .port_ops = &ali_c2_port_ops
  466. };
  467. /* Revision 0xC3 is UDMA66 for now */
  468. static const struct ata_port_info info_c3 = {
  469. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_PIO_LBA48 |
  470. ATA_FLAG_IGN_SIMPLEX,
  471. .pio_mask = ATA_PIO4,
  472. .mwdma_mask = ATA_MWDMA2,
  473. .udma_mask = ATA_UDMA4,
  474. .port_ops = &ali_c2_port_ops
  475. };
  476. /* Revision 0xC4 is UDMA100 */
  477. static const struct ata_port_info info_c4 = {
  478. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_PIO_LBA48 |
  479. ATA_FLAG_IGN_SIMPLEX,
  480. .pio_mask = ATA_PIO4,
  481. .mwdma_mask = ATA_MWDMA2,
  482. .udma_mask = ATA_UDMA5,
  483. .port_ops = &ali_c4_port_ops
  484. };
  485. /* Revision 0xC5 is UDMA133 with LBA48 DMA */
  486. static const struct ata_port_info info_c5 = {
  487. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_IGN_SIMPLEX,
  488. .pio_mask = ATA_PIO4,
  489. .mwdma_mask = ATA_MWDMA2,
  490. .udma_mask = ATA_UDMA6,
  491. .port_ops = &ali_c5_port_ops
  492. };
  493. const struct ata_port_info *ppi[] = { NULL, NULL };
  494. u8 tmp;
  495. int rc;
  496. rc = pcim_enable_device(pdev);
  497. if (rc)
  498. return rc;
  499. /*
  500. * The chipset revision selects the driver operations and
  501. * mode data.
  502. */
  503. if (pdev->revision < 0x20) {
  504. ppi[0] = &info_early;
  505. } else if (pdev->revision < 0xC2) {
  506. ppi[0] = &info_20;
  507. } else if (pdev->revision == 0xC2) {
  508. ppi[0] = &info_c2;
  509. } else if (pdev->revision == 0xC3) {
  510. ppi[0] = &info_c3;
  511. } else if (pdev->revision == 0xC4) {
  512. ppi[0] = &info_c4;
  513. } else
  514. ppi[0] = &info_c5;
  515. ali_init_chipset(pdev);
  516. if (ali_isa_bridge && pdev->revision >= 0x20 && pdev->revision < 0xC2) {
  517. /* Are we paired with a UDMA capable chip */
  518. pci_read_config_byte(ali_isa_bridge, 0x5E, &tmp);
  519. if ((tmp & 0x1E) == 0x12)
  520. ppi[0] = &info_20_udma;
  521. }
  522. if (!ppi[0]->mwdma_mask && !ppi[0]->udma_mask)
  523. return ata_pci_sff_init_one(pdev, ppi, &ali_sht, NULL, 0);
  524. else
  525. return ata_pci_bmdma_init_one(pdev, ppi, &ali_sht, NULL, 0);
  526. }
  527. #ifdef CONFIG_PM_SLEEP
  528. static int ali_reinit_one(struct pci_dev *pdev)
  529. {
  530. struct ata_host *host = pci_get_drvdata(pdev);
  531. int rc;
  532. rc = ata_pci_device_do_resume(pdev);
  533. if (rc)
  534. return rc;
  535. ali_init_chipset(pdev);
  536. ata_host_resume(host);
  537. return 0;
  538. }
  539. #endif
  540. static const struct pci_device_id ali[] = {
  541. { PCI_VDEVICE(AL, PCI_DEVICE_ID_AL_M5228), },
  542. { PCI_VDEVICE(AL, PCI_DEVICE_ID_AL_M5229), },
  543. { },
  544. };
  545. static struct pci_driver ali_pci_driver = {
  546. .name = DRV_NAME,
  547. .id_table = ali,
  548. .probe = ali_init_one,
  549. .remove = ata_pci_remove_one,
  550. #ifdef CONFIG_PM_SLEEP
  551. .suspend = ata_pci_device_suspend,
  552. .resume = ali_reinit_one,
  553. #endif
  554. };
  555. static int __init ali_init(void)
  556. {
  557. int ret;
  558. ali_isa_bridge = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533, NULL);
  559. ret = pci_register_driver(&ali_pci_driver);
  560. if (ret < 0)
  561. pci_dev_put(ali_isa_bridge);
  562. return ret;
  563. }
  564. static void __exit ali_exit(void)
  565. {
  566. pci_unregister_driver(&ali_pci_driver);
  567. pci_dev_put(ali_isa_bridge);
  568. }
  569. MODULE_AUTHOR("Alan Cox");
  570. MODULE_DESCRIPTION("low-level driver for ALi PATA");
  571. MODULE_LICENSE("GPL");
  572. MODULE_DEVICE_TABLE(pci, ali);
  573. MODULE_VERSION(DRV_VERSION);
  574. module_init(ali_init);
  575. module_exit(ali_exit);