ata_piix.c 18 KB

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