ata_piix.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. /*
  2. ata_piix.c - Intel PATA/SATA controllers
  3. Maintained by: Jeff Garzik <jgarzik@pobox.com>
  4. Please ALWAYS copy linux-ide@vger.kernel.org
  5. on emails.
  6. Copyright 2003-2004 Red Hat Inc
  7. Copyright 2003-2004 Jeff Garzik
  8. Copyright header from piix.c:
  9. Copyright (C) 1998-1999 Andrzej Krzysztofowicz, Author and Maintainer
  10. Copyright (C) 1998-2000 Andre Hedrick <andre@linux-ide.org>
  11. Copyright (C) 2003 Red Hat Inc <alan@redhat.com>
  12. May be copied or modified under the terms of the GNU General Public License
  13. */
  14. #include <linux/kernel.h>
  15. #include <linux/module.h>
  16. #include <linux/pci.h>
  17. #include <linux/init.h>
  18. #include <linux/blkdev.h>
  19. #include <linux/delay.h>
  20. #include "scsi.h"
  21. #include <scsi/scsi_host.h>
  22. #include <linux/libata.h>
  23. #define DRV_NAME "ata_piix"
  24. #define DRV_VERSION "1.03"
  25. enum {
  26. PIIX_IOCFG = 0x54, /* IDE I/O configuration register */
  27. ICH5_PMR = 0x90, /* port mapping register */
  28. ICH5_PCS = 0x92, /* port control and status */
  29. PIIX_FLAG_AHCI = (1 << 28), /* AHCI possible */
  30. PIIX_FLAG_CHECKINTR = (1 << 29), /* make sure PCI INTx enabled */
  31. PIIX_FLAG_COMBINED = (1 << 30), /* combined mode possible */
  32. /* combined mode. if set, PATA is channel 0.
  33. * if clear, PATA is channel 1.
  34. */
  35. PIIX_COMB_PATA_P0 = (1 << 1),
  36. PIIX_COMB = (1 << 2), /* combined mode enabled? */
  37. PIIX_PORT_PRESENT = (1 << 0),
  38. PIIX_PORT_ENABLED = (1 << 4),
  39. PIIX_80C_PRI = (1 << 5) | (1 << 4),
  40. PIIX_80C_SEC = (1 << 7) | (1 << 6),
  41. ich5_pata = 0,
  42. ich5_sata = 1,
  43. piix4_pata = 2,
  44. ich6_sata = 3,
  45. ich6_sata_rm = 4,
  46. ich7_sata = 5,
  47. esb2_sata = 6,
  48. };
  49. static int piix_init_one (struct pci_dev *pdev,
  50. const struct pci_device_id *ent);
  51. static void piix_pata_phy_reset(struct ata_port *ap);
  52. static void piix_sata_phy_reset(struct ata_port *ap);
  53. static void piix_set_piomode (struct ata_port *ap, struct ata_device *adev);
  54. static void piix_set_dmamode (struct ata_port *ap, struct ata_device *adev);
  55. static unsigned int in_module_init = 1;
  56. static struct pci_device_id piix_pci_tbl[] = {
  57. #ifdef ATA_ENABLE_PATA
  58. { 0x8086, 0x7111, PCI_ANY_ID, PCI_ANY_ID, 0, 0, piix4_pata },
  59. { 0x8086, 0x24db, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich5_pata },
  60. { 0x8086, 0x25a2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich5_pata },
  61. #endif
  62. /* NOTE: The following PCI ids must be kept in sync with the
  63. * list in drivers/pci/quirks.c.
  64. */
  65. { 0x8086, 0x24d1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich5_sata },
  66. { 0x8086, 0x24df, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich5_sata },
  67. { 0x8086, 0x25a3, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich5_sata },
  68. { 0x8086, 0x25b0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich5_sata },
  69. { 0x8086, 0x2651, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6_sata },
  70. { 0x8086, 0x2652, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6_sata_rm },
  71. { 0x8086, 0x2653, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6_sata_rm },
  72. { 0x8086, 0x27c0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich7_sata },
  73. { 0x8086, 0x27c4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich7_sata },
  74. { 0x8086, 0x2680, PCI_ANY_ID, PCI_ANY_ID, 0, 0, esb2_sata },
  75. { } /* terminate list */
  76. };
  77. static struct pci_driver piix_pci_driver = {
  78. .name = DRV_NAME,
  79. .id_table = piix_pci_tbl,
  80. .probe = piix_init_one,
  81. .remove = ata_pci_remove_one,
  82. };
  83. static Scsi_Host_Template piix_sht = {
  84. .module = THIS_MODULE,
  85. .name = DRV_NAME,
  86. .ioctl = ata_scsi_ioctl,
  87. .queuecommand = ata_scsi_queuecmd,
  88. .eh_strategy_handler = ata_scsi_error,
  89. .can_queue = ATA_DEF_QUEUE,
  90. .this_id = ATA_SHT_THIS_ID,
  91. .sg_tablesize = LIBATA_MAX_PRD,
  92. .max_sectors = ATA_MAX_SECTORS,
  93. .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
  94. .emulated = ATA_SHT_EMULATED,
  95. .use_clustering = ATA_SHT_USE_CLUSTERING,
  96. .proc_name = DRV_NAME,
  97. .dma_boundary = ATA_DMA_BOUNDARY,
  98. .slave_configure = ata_scsi_slave_config,
  99. .bios_param = ata_std_bios_param,
  100. .ordered_flush = 1,
  101. };
  102. static struct ata_port_operations piix_pata_ops = {
  103. .port_disable = ata_port_disable,
  104. .set_piomode = piix_set_piomode,
  105. .set_dmamode = piix_set_dmamode,
  106. .tf_load = ata_tf_load,
  107. .tf_read = ata_tf_read,
  108. .check_status = ata_check_status,
  109. .exec_command = ata_exec_command,
  110. .dev_select = ata_std_dev_select,
  111. .phy_reset = piix_pata_phy_reset,
  112. .bmdma_setup = ata_bmdma_setup,
  113. .bmdma_start = ata_bmdma_start,
  114. .bmdma_stop = ata_bmdma_stop,
  115. .bmdma_status = ata_bmdma_status,
  116. .qc_prep = ata_qc_prep,
  117. .qc_issue = ata_qc_issue_prot,
  118. .eng_timeout = ata_eng_timeout,
  119. .irq_handler = ata_interrupt,
  120. .irq_clear = ata_bmdma_irq_clear,
  121. .port_start = ata_port_start,
  122. .port_stop = ata_port_stop,
  123. };
  124. static struct ata_port_operations piix_sata_ops = {
  125. .port_disable = ata_port_disable,
  126. .tf_load = ata_tf_load,
  127. .tf_read = ata_tf_read,
  128. .check_status = ata_check_status,
  129. .exec_command = ata_exec_command,
  130. .dev_select = ata_std_dev_select,
  131. .phy_reset = piix_sata_phy_reset,
  132. .bmdma_setup = ata_bmdma_setup,
  133. .bmdma_start = ata_bmdma_start,
  134. .bmdma_stop = ata_bmdma_stop,
  135. .bmdma_status = ata_bmdma_status,
  136. .qc_prep = ata_qc_prep,
  137. .qc_issue = ata_qc_issue_prot,
  138. .eng_timeout = ata_eng_timeout,
  139. .irq_handler = ata_interrupt,
  140. .irq_clear = ata_bmdma_irq_clear,
  141. .port_start = ata_port_start,
  142. .port_stop = ata_port_stop,
  143. };
  144. static struct ata_port_info piix_port_info[] = {
  145. /* ich5_pata */
  146. {
  147. .sht = &piix_sht,
  148. .host_flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST |
  149. PIIX_FLAG_CHECKINTR,
  150. .pio_mask = 0x1f, /* pio0-4 */
  151. #if 0
  152. .mwdma_mask = 0x06, /* mwdma1-2 */
  153. #else
  154. .mwdma_mask = 0x00, /* mwdma broken */
  155. #endif
  156. .udma_mask = 0x3f, /* udma0-5 */
  157. .port_ops = &piix_pata_ops,
  158. },
  159. /* ich5_sata */
  160. {
  161. .sht = &piix_sht,
  162. .host_flags = ATA_FLAG_SATA | ATA_FLAG_SRST |
  163. PIIX_FLAG_COMBINED | PIIX_FLAG_CHECKINTR,
  164. .pio_mask = 0x1f, /* pio0-4 */
  165. .mwdma_mask = 0x07, /* mwdma0-2 */
  166. .udma_mask = 0x7f, /* udma0-6 */
  167. .port_ops = &piix_sata_ops,
  168. },
  169. /* piix4_pata */
  170. {
  171. .sht = &piix_sht,
  172. .host_flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  173. .pio_mask = 0x1f, /* pio0-4 */
  174. #if 0
  175. .mwdma_mask = 0x06, /* mwdma1-2 */
  176. #else
  177. .mwdma_mask = 0x00, /* mwdma broken */
  178. #endif
  179. .udma_mask = ATA_UDMA_MASK_40C,
  180. .port_ops = &piix_pata_ops,
  181. },
  182. /* ich6_sata */
  183. {
  184. .sht = &piix_sht,
  185. .host_flags = ATA_FLAG_SATA | ATA_FLAG_SRST |
  186. PIIX_FLAG_COMBINED | PIIX_FLAG_CHECKINTR |
  187. ATA_FLAG_SLAVE_POSS,
  188. .pio_mask = 0x1f, /* pio0-4 */
  189. .mwdma_mask = 0x07, /* mwdma0-2 */
  190. .udma_mask = 0x7f, /* udma0-6 */
  191. .port_ops = &piix_sata_ops,
  192. },
  193. /* ich6_sata_rm */
  194. {
  195. .sht = &piix_sht,
  196. .host_flags = ATA_FLAG_SATA | ATA_FLAG_SRST |
  197. PIIX_FLAG_COMBINED | PIIX_FLAG_CHECKINTR |
  198. ATA_FLAG_SLAVE_POSS | PIIX_FLAG_AHCI,
  199. .pio_mask = 0x1f, /* pio0-4 */
  200. .mwdma_mask = 0x07, /* mwdma0-2 */
  201. .udma_mask = 0x7f, /* udma0-6 */
  202. .port_ops = &piix_sata_ops,
  203. },
  204. /* ich7_sata */
  205. {
  206. .sht = &piix_sht,
  207. .host_flags = ATA_FLAG_SATA | ATA_FLAG_SRST |
  208. PIIX_FLAG_COMBINED | PIIX_FLAG_CHECKINTR |
  209. ATA_FLAG_SLAVE_POSS | PIIX_FLAG_AHCI,
  210. .pio_mask = 0x1f, /* pio0-4 */
  211. .mwdma_mask = 0x07, /* mwdma0-2 */
  212. .udma_mask = 0x7f, /* udma0-6 */
  213. .port_ops = &piix_sata_ops,
  214. },
  215. /* esb2_sata */
  216. {
  217. .sht = &piix_sht,
  218. .host_flags = ATA_FLAG_SATA | ATA_FLAG_SRST |
  219. PIIX_FLAG_COMBINED | PIIX_FLAG_CHECKINTR |
  220. ATA_FLAG_SLAVE_POSS | PIIX_FLAG_AHCI,
  221. .pio_mask = 0x1f, /* pio0-4 */
  222. .mwdma_mask = 0x07, /* mwdma0-2 */
  223. .udma_mask = 0x7f, /* udma0-6 */
  224. .port_ops = &piix_sata_ops,
  225. },
  226. };
  227. static struct pci_bits piix_enable_bits[] = {
  228. { 0x41U, 1U, 0x80UL, 0x80UL }, /* port 0 */
  229. { 0x43U, 1U, 0x80UL, 0x80UL }, /* port 1 */
  230. };
  231. MODULE_AUTHOR("Andre Hedrick, Alan Cox, Andrzej Krzysztofowicz, Jeff Garzik");
  232. MODULE_DESCRIPTION("SCSI low-level driver for Intel PIIX/ICH ATA controllers");
  233. MODULE_LICENSE("GPL");
  234. MODULE_DEVICE_TABLE(pci, piix_pci_tbl);
  235. MODULE_VERSION(DRV_VERSION);
  236. /**
  237. * piix_pata_cbl_detect - Probe host controller cable detect info
  238. * @ap: Port for which cable detect info is desired
  239. *
  240. * Read 80c cable indicator from ATA PCI device's PCI config
  241. * register. This register is normally set by firmware (BIOS).
  242. *
  243. * LOCKING:
  244. * None (inherited from caller).
  245. */
  246. static void piix_pata_cbl_detect(struct ata_port *ap)
  247. {
  248. struct pci_dev *pdev = to_pci_dev(ap->host_set->dev);
  249. u8 tmp, mask;
  250. /* no 80c support in host controller? */
  251. if ((ap->udma_mask & ~ATA_UDMA_MASK_40C) == 0)
  252. goto cbl40;
  253. /* check BIOS cable detect results */
  254. mask = ap->hard_port_no == 0 ? PIIX_80C_PRI : PIIX_80C_SEC;
  255. pci_read_config_byte(pdev, PIIX_IOCFG, &tmp);
  256. if ((tmp & mask) == 0)
  257. goto cbl40;
  258. ap->cbl = ATA_CBL_PATA80;
  259. return;
  260. cbl40:
  261. ap->cbl = ATA_CBL_PATA40;
  262. ap->udma_mask &= ATA_UDMA_MASK_40C;
  263. }
  264. /**
  265. * piix_pata_phy_reset - Probe specified port on PATA host controller
  266. * @ap: Port to probe
  267. *
  268. * Probe PATA phy.
  269. *
  270. * LOCKING:
  271. * None (inherited from caller).
  272. */
  273. static void piix_pata_phy_reset(struct ata_port *ap)
  274. {
  275. struct pci_dev *pdev = to_pci_dev(ap->host_set->dev);
  276. if (!pci_test_config_bits(pdev, &piix_enable_bits[ap->hard_port_no])) {
  277. ata_port_disable(ap);
  278. printk(KERN_INFO "ata%u: port disabled. ignoring.\n", ap->id);
  279. return;
  280. }
  281. piix_pata_cbl_detect(ap);
  282. ata_port_probe(ap);
  283. ata_bus_reset(ap);
  284. }
  285. /**
  286. * piix_sata_probe - Probe PCI device for present SATA devices
  287. * @ap: Port associated with the PCI device we wish to probe
  288. *
  289. * Reads SATA PCI device's PCI config register Port Configuration
  290. * and Status (PCS) to determine port and device availability.
  291. *
  292. * LOCKING:
  293. * None (inherited from caller).
  294. *
  295. * RETURNS:
  296. * Non-zero if device detected, zero otherwise.
  297. */
  298. static int piix_sata_probe (struct ata_port *ap)
  299. {
  300. struct pci_dev *pdev = to_pci_dev(ap->host_set->dev);
  301. int combined = (ap->flags & ATA_FLAG_SLAVE_POSS);
  302. int orig_mask, mask, i;
  303. u8 pcs;
  304. mask = (PIIX_PORT_PRESENT << ap->hard_port_no) |
  305. (PIIX_PORT_ENABLED << ap->hard_port_no);
  306. pci_read_config_byte(pdev, ICH5_PCS, &pcs);
  307. orig_mask = (int) pcs & 0xff;
  308. /* TODO: this is vaguely wrong for ICH6 combined mode,
  309. * where only two of the four SATA ports are mapped
  310. * onto a single ATA channel. It is also vaguely inaccurate
  311. * for ICH5, which has only two ports. However, this is ok,
  312. * as further device presence detection code will handle
  313. * any false positives produced here.
  314. */
  315. for (i = 0; i < 4; i++) {
  316. mask = (PIIX_PORT_PRESENT << i) | (PIIX_PORT_ENABLED << i);
  317. if ((orig_mask & mask) == mask)
  318. if (combined || (i == ap->hard_port_no))
  319. return 1;
  320. }
  321. return 0;
  322. }
  323. /**
  324. * piix_sata_phy_reset - Probe specified port on SATA host controller
  325. * @ap: Port to probe
  326. *
  327. * Probe SATA phy.
  328. *
  329. * LOCKING:
  330. * None (inherited from caller).
  331. */
  332. static void piix_sata_phy_reset(struct ata_port *ap)
  333. {
  334. if (!piix_sata_probe(ap)) {
  335. ata_port_disable(ap);
  336. printk(KERN_INFO "ata%u: SATA port has no device.\n", ap->id);
  337. return;
  338. }
  339. ap->cbl = ATA_CBL_SATA;
  340. ata_port_probe(ap);
  341. ata_bus_reset(ap);
  342. }
  343. /**
  344. * piix_set_piomode - Initialize host controller PATA PIO timings
  345. * @ap: Port whose timings we are configuring
  346. * @adev: um
  347. * @pio: PIO mode, 0 - 4
  348. *
  349. * Set PIO mode for device, in host controller PCI config space.
  350. *
  351. * LOCKING:
  352. * None (inherited from caller).
  353. */
  354. static void piix_set_piomode (struct ata_port *ap, struct ata_device *adev)
  355. {
  356. unsigned int pio = adev->pio_mode - XFER_PIO_0;
  357. struct pci_dev *dev = to_pci_dev(ap->host_set->dev);
  358. unsigned int is_slave = (adev->devno != 0);
  359. unsigned int master_port= ap->hard_port_no ? 0x42 : 0x40;
  360. unsigned int slave_port = 0x44;
  361. u16 master_data;
  362. u8 slave_data;
  363. static const /* ISP RTC */
  364. u8 timings[][2] = { { 0, 0 },
  365. { 0, 0 },
  366. { 1, 0 },
  367. { 2, 1 },
  368. { 2, 3 }, };
  369. pci_read_config_word(dev, master_port, &master_data);
  370. if (is_slave) {
  371. master_data |= 0x4000;
  372. /* enable PPE, IE and TIME */
  373. master_data |= 0x0070;
  374. pci_read_config_byte(dev, slave_port, &slave_data);
  375. slave_data &= (ap->hard_port_no ? 0x0f : 0xf0);
  376. slave_data |=
  377. (timings[pio][0] << 2) |
  378. (timings[pio][1] << (ap->hard_port_no ? 4 : 0));
  379. } else {
  380. master_data &= 0xccf8;
  381. /* enable PPE, IE and TIME */
  382. master_data |= 0x0007;
  383. master_data |=
  384. (timings[pio][0] << 12) |
  385. (timings[pio][1] << 8);
  386. }
  387. pci_write_config_word(dev, master_port, master_data);
  388. if (is_slave)
  389. pci_write_config_byte(dev, slave_port, slave_data);
  390. }
  391. /**
  392. * piix_set_dmamode - Initialize host controller PATA PIO timings
  393. * @ap: Port whose timings we are configuring
  394. * @adev: um
  395. * @udma: udma mode, 0 - 6
  396. *
  397. * Set UDMA mode for device, in host controller PCI config space.
  398. *
  399. * LOCKING:
  400. * None (inherited from caller).
  401. */
  402. static void piix_set_dmamode (struct ata_port *ap, struct ata_device *adev)
  403. {
  404. unsigned int udma = adev->dma_mode; /* FIXME: MWDMA too */
  405. struct pci_dev *dev = to_pci_dev(ap->host_set->dev);
  406. u8 maslave = ap->hard_port_no ? 0x42 : 0x40;
  407. u8 speed = udma;
  408. unsigned int drive_dn = (ap->hard_port_no ? 2 : 0) + adev->devno;
  409. int a_speed = 3 << (drive_dn * 4);
  410. int u_flag = 1 << drive_dn;
  411. int v_flag = 0x01 << drive_dn;
  412. int w_flag = 0x10 << drive_dn;
  413. int u_speed = 0;
  414. int sitre;
  415. u16 reg4042, reg4a;
  416. u8 reg48, reg54, reg55;
  417. pci_read_config_word(dev, maslave, &reg4042);
  418. DPRINTK("reg4042 = 0x%04x\n", reg4042);
  419. sitre = (reg4042 & 0x4000) ? 1 : 0;
  420. pci_read_config_byte(dev, 0x48, &reg48);
  421. pci_read_config_word(dev, 0x4a, &reg4a);
  422. pci_read_config_byte(dev, 0x54, &reg54);
  423. pci_read_config_byte(dev, 0x55, &reg55);
  424. switch(speed) {
  425. case XFER_UDMA_4:
  426. case XFER_UDMA_2: u_speed = 2 << (drive_dn * 4); break;
  427. case XFER_UDMA_6:
  428. case XFER_UDMA_5:
  429. case XFER_UDMA_3:
  430. case XFER_UDMA_1: u_speed = 1 << (drive_dn * 4); break;
  431. case XFER_UDMA_0: u_speed = 0 << (drive_dn * 4); break;
  432. case XFER_MW_DMA_2:
  433. case XFER_MW_DMA_1: break;
  434. default:
  435. BUG();
  436. return;
  437. }
  438. if (speed >= XFER_UDMA_0) {
  439. if (!(reg48 & u_flag))
  440. pci_write_config_byte(dev, 0x48, reg48 | u_flag);
  441. if (speed == XFER_UDMA_5) {
  442. pci_write_config_byte(dev, 0x55, (u8) reg55|w_flag);
  443. } else {
  444. pci_write_config_byte(dev, 0x55, (u8) reg55 & ~w_flag);
  445. }
  446. if ((reg4a & a_speed) != u_speed)
  447. pci_write_config_word(dev, 0x4a, (reg4a & ~a_speed) | u_speed);
  448. if (speed > XFER_UDMA_2) {
  449. if (!(reg54 & v_flag))
  450. pci_write_config_byte(dev, 0x54, reg54 | v_flag);
  451. } else
  452. pci_write_config_byte(dev, 0x54, reg54 & ~v_flag);
  453. } else {
  454. if (reg48 & u_flag)
  455. pci_write_config_byte(dev, 0x48, reg48 & ~u_flag);
  456. if (reg4a & a_speed)
  457. pci_write_config_word(dev, 0x4a, reg4a & ~a_speed);
  458. if (reg54 & v_flag)
  459. pci_write_config_byte(dev, 0x54, reg54 & ~v_flag);
  460. if (reg55 & w_flag)
  461. pci_write_config_byte(dev, 0x55, (u8) reg55 & ~w_flag);
  462. }
  463. }
  464. /* move to PCI layer, integrate w/ MSI stuff */
  465. static void pci_enable_intx(struct pci_dev *pdev)
  466. {
  467. u16 pci_command;
  468. pci_read_config_word(pdev, PCI_COMMAND, &pci_command);
  469. if (pci_command & PCI_COMMAND_INTX_DISABLE) {
  470. pci_command &= ~PCI_COMMAND_INTX_DISABLE;
  471. pci_write_config_word(pdev, PCI_COMMAND, pci_command);
  472. }
  473. }
  474. #define AHCI_PCI_BAR 5
  475. #define AHCI_GLOBAL_CTL 0x04
  476. #define AHCI_ENABLE (1 << 31)
  477. static int piix_disable_ahci(struct pci_dev *pdev)
  478. {
  479. void *mmio;
  480. unsigned long addr;
  481. u32 tmp;
  482. int rc = 0;
  483. /* BUG: pci_enable_device has not yet been called. This
  484. * works because this device is usually set up by BIOS.
  485. */
  486. addr = pci_resource_start(pdev, AHCI_PCI_BAR);
  487. if (!addr || !pci_resource_len(pdev, AHCI_PCI_BAR))
  488. return 0;
  489. mmio = ioremap(addr, 64);
  490. if (!mmio)
  491. return -ENOMEM;
  492. tmp = readl(mmio + AHCI_GLOBAL_CTL);
  493. if (tmp & AHCI_ENABLE) {
  494. tmp &= ~AHCI_ENABLE;
  495. writel(tmp, mmio + AHCI_GLOBAL_CTL);
  496. tmp = readl(mmio + AHCI_GLOBAL_CTL);
  497. if (tmp & AHCI_ENABLE)
  498. rc = -EIO;
  499. }
  500. iounmap(mmio);
  501. return rc;
  502. }
  503. /**
  504. * piix_init_one - Register PIIX ATA PCI device with kernel services
  505. * @pdev: PCI device to register
  506. * @ent: Entry in piix_pci_tbl matching with @pdev
  507. *
  508. * Called from kernel PCI layer. We probe for combined mode (sigh),
  509. * and then hand over control to libata, for it to do the rest.
  510. *
  511. * LOCKING:
  512. * Inherited from PCI layer (may sleep).
  513. *
  514. * RETURNS:
  515. * Zero on success, or -ERRNO value.
  516. */
  517. static int piix_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
  518. {
  519. static int printed_version;
  520. struct ata_port_info *port_info[2];
  521. unsigned int combined = 0, n_ports = 1;
  522. unsigned int pata_chan = 0, sata_chan = 0;
  523. if (!printed_version++)
  524. printk(KERN_DEBUG DRV_NAME " version " DRV_VERSION "\n");
  525. /* no hotplugging support (FIXME) */
  526. if (!in_module_init)
  527. return -ENODEV;
  528. port_info[0] = &piix_port_info[ent->driver_data];
  529. port_info[1] = NULL;
  530. if (port_info[0]->host_flags & PIIX_FLAG_AHCI) {
  531. int rc = piix_disable_ahci(pdev);
  532. if (rc)
  533. return rc;
  534. }
  535. if (port_info[0]->host_flags & PIIX_FLAG_COMBINED) {
  536. u8 tmp;
  537. pci_read_config_byte(pdev, ICH5_PMR, &tmp);
  538. if (tmp & PIIX_COMB) {
  539. combined = 1;
  540. if (tmp & PIIX_COMB_PATA_P0)
  541. sata_chan = 1;
  542. else
  543. pata_chan = 1;
  544. }
  545. }
  546. /* On ICH5, some BIOSen disable the interrupt using the
  547. * PCI_COMMAND_INTX_DISABLE bit added in PCI 2.3.
  548. * On ICH6, this bit has the same effect, but only when
  549. * MSI is disabled (and it is disabled, as we don't use
  550. * message-signalled interrupts currently).
  551. */
  552. if (port_info[0]->host_flags & PIIX_FLAG_CHECKINTR)
  553. pci_enable_intx(pdev);
  554. if (combined) {
  555. port_info[sata_chan] = &piix_port_info[ent->driver_data];
  556. port_info[sata_chan]->host_flags |= ATA_FLAG_SLAVE_POSS;
  557. port_info[pata_chan] = &piix_port_info[ich5_pata];
  558. n_ports++;
  559. printk(KERN_WARNING DRV_NAME ": combined mode detected\n");
  560. }
  561. return ata_pci_init_one(pdev, port_info, n_ports);
  562. }
  563. /**
  564. * piix_init -
  565. *
  566. * LOCKING:
  567. *
  568. * RETURNS:
  569. *
  570. */
  571. static int __init piix_init(void)
  572. {
  573. int rc;
  574. DPRINTK("pci_module_init\n");
  575. rc = pci_module_init(&piix_pci_driver);
  576. if (rc)
  577. return rc;
  578. in_module_init = 0;
  579. DPRINTK("done\n");
  580. return 0;
  581. }
  582. /**
  583. * piix_exit -
  584. *
  585. * LOCKING:
  586. *
  587. */
  588. static void __exit piix_exit(void)
  589. {
  590. pci_unregister_driver(&piix_pci_driver);
  591. }
  592. module_init(piix_init);
  593. module_exit(piix_exit);