pata_ali.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  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.6"
  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. .data_xfer = ata_pio_data_xfer,
  327. .irq_handler = ata_interrupt,
  328. .irq_clear = ata_bmdma_irq_clear,
  329. .port_start = ata_port_start,
  330. .port_stop = ata_port_stop,
  331. .host_stop = ata_host_stop
  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_pio_data_xfer,
  359. .irq_handler = ata_interrupt,
  360. .irq_clear = ata_bmdma_irq_clear,
  361. .port_start = ata_port_start,
  362. .port_stop = ata_port_stop,
  363. .host_stop = ata_host_stop
  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_pio_data_xfer,
  390. .irq_handler = ata_interrupt,
  391. .irq_clear = ata_bmdma_irq_clear,
  392. .port_start = ata_port_start,
  393. .port_stop = ata_port_stop,
  394. .host_stop = ata_host_stop
  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_pio_data_xfer,
  420. .irq_handler = ata_interrupt,
  421. .irq_clear = ata_bmdma_irq_clear,
  422. .port_start = ata_port_start,
  423. .port_stop = ata_port_stop,
  424. .host_stop = ata_host_stop
  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 struct ata_port_info info_early = {
  437. .sht = &ali_sht,
  438. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  439. .pio_mask = 0x1f,
  440. .port_ops = &ali_early_port_ops
  441. };
  442. /* Revision 0x20 added DMA */
  443. static struct ata_port_info info_20 = {
  444. .sht = &ali_sht,
  445. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST | ATA_FLAG_PIO_LBA48,
  446. .pio_mask = 0x1f,
  447. .mwdma_mask = 0x07,
  448. .port_ops = &ali_20_port_ops
  449. };
  450. /* Revision 0x20 with support logic added UDMA */
  451. static struct ata_port_info info_20_udma = {
  452. .sht = &ali_sht,
  453. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST | ATA_FLAG_PIO_LBA48,
  454. .pio_mask = 0x1f,
  455. .mwdma_mask = 0x07,
  456. .udma_mask = 0x07, /* UDMA33 */
  457. .port_ops = &ali_20_port_ops
  458. };
  459. /* Revision 0xC2 adds UDMA66 */
  460. static struct ata_port_info info_c2 = {
  461. .sht = &ali_sht,
  462. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST | ATA_FLAG_PIO_LBA48,
  463. .pio_mask = 0x1f,
  464. .mwdma_mask = 0x07,
  465. .udma_mask = 0x1f,
  466. .port_ops = &ali_c2_port_ops
  467. };
  468. /* Revision 0xC3 is UDMA100 */
  469. static struct ata_port_info info_c3 = {
  470. .sht = &ali_sht,
  471. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST | ATA_FLAG_PIO_LBA48,
  472. .pio_mask = 0x1f,
  473. .mwdma_mask = 0x07,
  474. .udma_mask = 0x3f,
  475. .port_ops = &ali_c2_port_ops
  476. };
  477. /* Revision 0xC4 is UDMA133 */
  478. static struct ata_port_info info_c4 = {
  479. .sht = &ali_sht,
  480. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST | ATA_FLAG_PIO_LBA48,
  481. .pio_mask = 0x1f,
  482. .mwdma_mask = 0x07,
  483. .udma_mask = 0x7f,
  484. .port_ops = &ali_c2_port_ops
  485. };
  486. /* Revision 0xC5 is UDMA133 with LBA48 DMA */
  487. static struct ata_port_info info_c5 = {
  488. .sht = &ali_sht,
  489. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  490. .pio_mask = 0x1f,
  491. .mwdma_mask = 0x07,
  492. .udma_mask = 0x7f,
  493. .port_ops = &ali_c5_port_ops
  494. };
  495. static struct ata_port_info *port_info[2];
  496. u8 rev, tmp;
  497. struct pci_dev *north, *isa_bridge;
  498. pci_read_config_byte(pdev, PCI_REVISION_ID, &rev);
  499. /*
  500. * The chipset revision selects the driver operations and
  501. * mode data.
  502. */
  503. if (rev < 0x20) {
  504. port_info[0] = port_info[1] = &info_early;
  505. } else if (rev < 0xC2) {
  506. /* 1543-E/F, 1543C-C, 1543C-D, 1543C-E */
  507. pci_read_config_byte(pdev, 0x4B, &tmp);
  508. /* Clear CD-ROM DMA write bit */
  509. tmp &= 0x7F;
  510. pci_write_config_byte(pdev, 0x4B, tmp);
  511. port_info[0] = port_info[1] = &info_20;
  512. } else if (rev == 0xC2) {
  513. port_info[0] = port_info[1] = &info_c2;
  514. } else if (rev == 0xC3) {
  515. port_info[0] = port_info[1] = &info_c3;
  516. } else if (rev == 0xC4) {
  517. port_info[0] = port_info[1] = &info_c4;
  518. } else
  519. port_info[0] = port_info[1] = &info_c5;
  520. if (rev >= 0xC2) {
  521. /* Enable cable detection logic */
  522. pci_read_config_byte(pdev, 0x4B, &tmp);
  523. pci_write_config_byte(pdev, 0x4B, tmp | 0x08);
  524. }
  525. north = pci_get_slot(pdev->bus, PCI_DEVFN(0,0));
  526. isa_bridge = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533, NULL);
  527. if (north && north->vendor == PCI_VENDOR_ID_AL) {
  528. /* Configure the ALi bridge logic. For non ALi rely on BIOS.
  529. Set the south bridge enable bit */
  530. pci_read_config_byte(isa_bridge, 0x79, &tmp);
  531. if (rev == 0xC2)
  532. pci_write_config_byte(isa_bridge, 0x79, tmp | 0x04);
  533. else if (rev > 0xC2)
  534. pci_write_config_byte(isa_bridge, 0x79, tmp | 0x02);
  535. }
  536. if (rev >= 0x20) {
  537. if (rev < 0xC2) {
  538. /* Are we paired with a UDMA capable chip */
  539. pci_read_config_byte(isa_bridge, 0x5E, &tmp);
  540. if ((tmp & 0x1E) == 0x12)
  541. port_info[0] = port_info[1] = &info_20_udma;
  542. }
  543. /*
  544. * CD_ROM DMA on (0x53 bit 0). Enable this even if we want
  545. * to use PIO. 0x53 bit 1 (rev 20 only) - enable FIFO control
  546. * via 0x54/55.
  547. */
  548. pci_read_config_byte(pdev, 0x53, &tmp);
  549. if (rev <= 0x20)
  550. tmp &= ~0x02;
  551. if (rev >= 0xc7)
  552. tmp |= 0x03;
  553. else
  554. tmp |= 0x01; /* CD_ROM enable for DMA */
  555. pci_write_config_byte(pdev, 0x53, tmp);
  556. }
  557. pci_dev_put(isa_bridge);
  558. pci_dev_put(north);
  559. ata_pci_clear_simplex(pdev);
  560. return ata_pci_init_one(pdev, port_info, 2);
  561. }
  562. static const struct pci_device_id ali[] = {
  563. { PCI_VDEVICE(AL, PCI_DEVICE_ID_AL_M5228), },
  564. { PCI_VDEVICE(AL, PCI_DEVICE_ID_AL_M5229), },
  565. { },
  566. };
  567. static struct pci_driver ali_pci_driver = {
  568. .name = DRV_NAME,
  569. .id_table = ali,
  570. .probe = ali_init_one,
  571. .remove = ata_pci_remove_one
  572. };
  573. static int __init ali_init(void)
  574. {
  575. return pci_register_driver(&ali_pci_driver);
  576. }
  577. static void __exit ali_exit(void)
  578. {
  579. pci_unregister_driver(&ali_pci_driver);
  580. }
  581. MODULE_AUTHOR("Alan Cox");
  582. MODULE_DESCRIPTION("low-level driver for ALi PATA");
  583. MODULE_LICENSE("GPL");
  584. MODULE_DEVICE_TABLE(pci, ali);
  585. MODULE_VERSION(DRV_VERSION);
  586. module_init(ali_init);
  587. module_exit(ali_exit);