pata_ali.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  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.6.5"
  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_PATA80;
  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[40];
  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_string(adev->id, model_num, ATA_ID_PROD_OFS, 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. /* Keep LBA28 counts so large I/O's don't turn LBA48 and PIO
  299. with older controllers. Not locked so will grow on C5 or later */
  300. .max_sectors = 255,
  301. .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
  302. .emulated = ATA_SHT_EMULATED,
  303. .use_clustering = ATA_SHT_USE_CLUSTERING,
  304. .proc_name = DRV_NAME,
  305. .dma_boundary = ATA_DMA_BOUNDARY,
  306. .slave_configure = ata_scsi_slave_config,
  307. .bios_param = ata_std_bios_param,
  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. .eng_timeout = ata_eng_timeout,
  327. .data_xfer = ata_pio_data_xfer,
  328. .irq_handler = ata_interrupt,
  329. .irq_clear = ata_bmdma_irq_clear,
  330. .port_start = ata_port_start,
  331. .port_stop = ata_port_stop,
  332. .host_stop = ata_host_stop
  333. };
  334. /*
  335. * Port operations for DMA capable ALi without cable
  336. * detect
  337. */
  338. static struct ata_port_operations ali_20_port_ops = {
  339. .port_disable = ata_port_disable,
  340. .set_piomode = ali_set_piomode,
  341. .set_dmamode = ali_set_dmamode,
  342. .mode_filter = ali_20_filter,
  343. .tf_load = ata_tf_load,
  344. .tf_read = ata_tf_read,
  345. .check_status = ata_check_status,
  346. .exec_command = ata_exec_command,
  347. .dev_select = ata_std_dev_select,
  348. .dev_config = ali_lock_sectors,
  349. .freeze = ata_bmdma_freeze,
  350. .thaw = ata_bmdma_thaw,
  351. .error_handler = ali_early_error_handler,
  352. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  353. .bmdma_setup = ata_bmdma_setup,
  354. .bmdma_start = ata_bmdma_start,
  355. .bmdma_stop = ata_bmdma_stop,
  356. .bmdma_status = ata_bmdma_status,
  357. .qc_prep = ata_qc_prep,
  358. .qc_issue = ata_qc_issue_prot,
  359. .eng_timeout = ata_eng_timeout,
  360. .data_xfer = ata_pio_data_xfer,
  361. .irq_handler = ata_interrupt,
  362. .irq_clear = ata_bmdma_irq_clear,
  363. .port_start = ata_port_start,
  364. .port_stop = ata_port_stop,
  365. .host_stop = ata_host_stop
  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. .eng_timeout = ata_eng_timeout,
  392. .data_xfer = ata_pio_data_xfer,
  393. .irq_handler = ata_interrupt,
  394. .irq_clear = ata_bmdma_irq_clear,
  395. .port_start = ata_port_start,
  396. .port_stop = ata_port_stop,
  397. .host_stop = ata_host_stop
  398. };
  399. /*
  400. * Port operations for DMA capable ALi with cable detect and LBA48
  401. */
  402. static struct ata_port_operations ali_c5_port_ops = {
  403. .port_disable = ata_port_disable,
  404. .set_piomode = ali_set_piomode,
  405. .set_dmamode = ali_set_dmamode,
  406. .mode_filter = ata_pci_default_filter,
  407. .tf_load = ata_tf_load,
  408. .tf_read = ata_tf_read,
  409. .check_status = ata_check_status,
  410. .exec_command = ata_exec_command,
  411. .dev_select = ata_std_dev_select,
  412. .freeze = ata_bmdma_freeze,
  413. .thaw = ata_bmdma_thaw,
  414. .error_handler = ali_c2_error_handler,
  415. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  416. .bmdma_setup = ata_bmdma_setup,
  417. .bmdma_start = ata_bmdma_start,
  418. .bmdma_stop = ata_bmdma_stop,
  419. .bmdma_status = ata_bmdma_status,
  420. .qc_prep = ata_qc_prep,
  421. .qc_issue = ata_qc_issue_prot,
  422. .eng_timeout = ata_eng_timeout,
  423. .data_xfer = ata_pio_data_xfer,
  424. .irq_handler = ata_interrupt,
  425. .irq_clear = ata_bmdma_irq_clear,
  426. .port_start = ata_port_start,
  427. .port_stop = ata_port_stop,
  428. .host_stop = ata_host_stop
  429. };
  430. /**
  431. * ali_init_one - discovery callback
  432. * @pdev: PCI device ID
  433. * @id: PCI table info
  434. *
  435. * An ALi IDE interface has been discovered. Figure out what revision
  436. * and perform configuration work before handing it to the ATA layer
  437. */
  438. static int ali_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
  439. {
  440. static struct ata_port_info info_early = {
  441. .sht = &ali_sht,
  442. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  443. .pio_mask = 0x1f,
  444. .port_ops = &ali_early_port_ops
  445. };
  446. /* Revision 0x20 added DMA */
  447. static struct ata_port_info info_20 = {
  448. .sht = &ali_sht,
  449. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST | ATA_FLAG_PIO_LBA48,
  450. .pio_mask = 0x1f,
  451. .mwdma_mask = 0x07,
  452. .port_ops = &ali_20_port_ops
  453. };
  454. /* Revision 0x20 with support logic added UDMA */
  455. static struct ata_port_info info_20_udma = {
  456. .sht = &ali_sht,
  457. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST | ATA_FLAG_PIO_LBA48,
  458. .pio_mask = 0x1f,
  459. .mwdma_mask = 0x07,
  460. .udma_mask = 0x07, /* UDMA33 */
  461. .port_ops = &ali_20_port_ops
  462. };
  463. /* Revision 0xC2 adds UDMA66 */
  464. static struct ata_port_info info_c2 = {
  465. .sht = &ali_sht,
  466. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST | ATA_FLAG_PIO_LBA48,
  467. .pio_mask = 0x1f,
  468. .mwdma_mask = 0x07,
  469. .udma_mask = 0x1f,
  470. .port_ops = &ali_c2_port_ops
  471. };
  472. /* Revision 0xC3 is UDMA100 */
  473. static struct ata_port_info info_c3 = {
  474. .sht = &ali_sht,
  475. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST | ATA_FLAG_PIO_LBA48,
  476. .pio_mask = 0x1f,
  477. .mwdma_mask = 0x07,
  478. .udma_mask = 0x3f,
  479. .port_ops = &ali_c2_port_ops
  480. };
  481. /* Revision 0xC4 is UDMA133 */
  482. static struct ata_port_info info_c4 = {
  483. .sht = &ali_sht,
  484. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST | ATA_FLAG_PIO_LBA48,
  485. .pio_mask = 0x1f,
  486. .mwdma_mask = 0x07,
  487. .udma_mask = 0x7f,
  488. .port_ops = &ali_c2_port_ops
  489. };
  490. /* Revision 0xC5 is UDMA133 with LBA48 DMA */
  491. static struct ata_port_info info_c5 = {
  492. .sht = &ali_sht,
  493. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  494. .pio_mask = 0x1f,
  495. .mwdma_mask = 0x07,
  496. .udma_mask = 0x7f,
  497. .port_ops = &ali_c5_port_ops
  498. };
  499. static struct ata_port_info *port_info[2];
  500. u8 rev, tmp;
  501. struct pci_dev *north, *isa_bridge;
  502. pci_read_config_byte(pdev, PCI_REVISION_ID, &rev);
  503. /*
  504. * The chipset revision selects the driver operations and
  505. * mode data.
  506. */
  507. if (rev < 0x20) {
  508. port_info[0] = port_info[1] = &info_early;
  509. } else if (rev < 0xC2) {
  510. /* 1543-E/F, 1543C-C, 1543C-D, 1543C-E */
  511. pci_read_config_byte(pdev, 0x4B, &tmp);
  512. /* Clear CD-ROM DMA write bit */
  513. tmp &= 0x7F;
  514. pci_write_config_byte(pdev, 0x4B, tmp);
  515. port_info[0] = port_info[1] = &info_20;
  516. } else if (rev == 0xC2) {
  517. port_info[0] = port_info[1] = &info_c2;
  518. } else if (rev == 0xC3) {
  519. port_info[0] = port_info[1] = &info_c3;
  520. } else if (rev == 0xC4) {
  521. port_info[0] = port_info[1] = &info_c4;
  522. } else
  523. port_info[0] = port_info[1] = &info_c5;
  524. if (rev >= 0xC2) {
  525. /* Enable cable detection logic */
  526. pci_read_config_byte(pdev, 0x4B, &tmp);
  527. pci_write_config_byte(pdev, 0x4B, tmp | 0x08);
  528. }
  529. north = pci_get_slot(pdev->bus, PCI_DEVFN(0,0));
  530. isa_bridge = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533, NULL);
  531. if (north && north->vendor == PCI_VENDOR_ID_AL) {
  532. /* Configure the ALi bridge logic. For non ALi rely on BIOS.
  533. Set the south bridge enable bit */
  534. pci_read_config_byte(isa_bridge, 0x79, &tmp);
  535. if (rev == 0xC2)
  536. pci_write_config_byte(isa_bridge, 0x79, tmp | 0x04);
  537. else if (rev > 0xC2)
  538. pci_write_config_byte(isa_bridge, 0x79, tmp | 0x02);
  539. }
  540. if (rev >= 0x20) {
  541. if (rev < 0xC2) {
  542. /* Are we paired with a UDMA capable chip */
  543. pci_read_config_byte(isa_bridge, 0x5E, &tmp);
  544. if ((tmp & 0x1E) == 0x12)
  545. port_info[0] = port_info[1] = &info_20_udma;
  546. }
  547. /*
  548. * CD_ROM DMA on (0x53 bit 0). Enable this even if we want
  549. * to use PIO. 0x53 bit 1 (rev 20 only) - enable FIFO control
  550. * via 0x54/55.
  551. */
  552. pci_read_config_byte(pdev, 0x53, &tmp);
  553. if (rev <= 0x20)
  554. tmp &= ~0x02;
  555. if (rev == 0xc7)
  556. tmp |= 0x03;
  557. else
  558. tmp |= 0x01; /* CD_ROM enable for DMA */
  559. pci_write_config_byte(pdev, 0x53, tmp);
  560. }
  561. pci_dev_put(isa_bridge);
  562. pci_dev_put(north);
  563. ata_pci_clear_simplex(pdev);
  564. return ata_pci_init_one(pdev, port_info, 2);
  565. }
  566. static struct pci_device_id ali[] = {
  567. { PCI_DEVICE(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M5228), },
  568. { PCI_DEVICE(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M5229), },
  569. { 0, },
  570. };
  571. static struct pci_driver ali_pci_driver = {
  572. .name = DRV_NAME,
  573. .id_table = ali,
  574. .probe = ali_init_one,
  575. .remove = ata_pci_remove_one
  576. };
  577. static int __init ali_init(void)
  578. {
  579. return pci_register_driver(&ali_pci_driver);
  580. }
  581. static void __exit ali_exit(void)
  582. {
  583. pci_unregister_driver(&ali_pci_driver);
  584. }
  585. MODULE_AUTHOR("Alan Cox");
  586. MODULE_DESCRIPTION("low-level driver for ALi PATA");
  587. MODULE_LICENSE("GPL");
  588. MODULE_DEVICE_TABLE(pci, ali);
  589. MODULE_VERSION(DRV_VERSION);
  590. module_init(ali_init);
  591. module_exit(ali_exit);