i2c-piix4.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  1. /*
  2. Copyright (c) 1998 - 2002 Frodo Looijaard <frodol@dds.nl> and
  3. Philip Edelbrock <phil@netroedge.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. */
  13. /*
  14. Supports:
  15. Intel PIIX4, 440MX
  16. Serverworks OSB4, CSB5, CSB6, HT-1000, HT-1100
  17. ATI IXP200, IXP300, IXP400, SB600, SB700/SP5100, SB800
  18. AMD Hudson-2, ML, CZ
  19. SMSC Victory66
  20. Note: we assume there can only be one device, with one or more
  21. SMBus interfaces.
  22. */
  23. #include <linux/module.h>
  24. #include <linux/moduleparam.h>
  25. #include <linux/pci.h>
  26. #include <linux/kernel.h>
  27. #include <linux/delay.h>
  28. #include <linux/stddef.h>
  29. #include <linux/ioport.h>
  30. #include <linux/i2c.h>
  31. #include <linux/slab.h>
  32. #include <linux/dmi.h>
  33. #include <linux/acpi.h>
  34. #include <linux/io.h>
  35. /* PIIX4 SMBus address offsets */
  36. #define SMBHSTSTS (0 + piix4_smba)
  37. #define SMBHSLVSTS (1 + piix4_smba)
  38. #define SMBHSTCNT (2 + piix4_smba)
  39. #define SMBHSTCMD (3 + piix4_smba)
  40. #define SMBHSTADD (4 + piix4_smba)
  41. #define SMBHSTDAT0 (5 + piix4_smba)
  42. #define SMBHSTDAT1 (6 + piix4_smba)
  43. #define SMBBLKDAT (7 + piix4_smba)
  44. #define SMBSLVCNT (8 + piix4_smba)
  45. #define SMBSHDWCMD (9 + piix4_smba)
  46. #define SMBSLVEVT (0xA + piix4_smba)
  47. #define SMBSLVDAT (0xC + piix4_smba)
  48. /* count for request_region */
  49. #define SMBIOSIZE 9
  50. /* PCI Address Constants */
  51. #define SMBBA 0x090
  52. #define SMBHSTCFG 0x0D2
  53. #define SMBSLVC 0x0D3
  54. #define SMBSHDW1 0x0D4
  55. #define SMBSHDW2 0x0D5
  56. #define SMBREV 0x0D6
  57. /* Other settings */
  58. #define MAX_TIMEOUT 500
  59. #define ENABLE_INT9 0
  60. /* PIIX4 constants */
  61. #define PIIX4_QUICK 0x00
  62. #define PIIX4_BYTE 0x04
  63. #define PIIX4_BYTE_DATA 0x08
  64. #define PIIX4_WORD_DATA 0x0C
  65. #define PIIX4_BLOCK_DATA 0x14
  66. /* insmod parameters */
  67. /* If force is set to anything different from 0, we forcibly enable the
  68. PIIX4. DANGEROUS! */
  69. static int force;
  70. module_param (force, int, 0);
  71. MODULE_PARM_DESC(force, "Forcibly enable the PIIX4. DANGEROUS!");
  72. /* If force_addr is set to anything different from 0, we forcibly enable
  73. the PIIX4 at the given address. VERY DANGEROUS! */
  74. static int force_addr;
  75. module_param (force_addr, int, 0);
  76. MODULE_PARM_DESC(force_addr,
  77. "Forcibly enable the PIIX4 at the given address. "
  78. "EXTREMELY DANGEROUS!");
  79. static int srvrworks_csb5_delay;
  80. static struct pci_driver piix4_driver;
  81. static const struct dmi_system_id piix4_dmi_blacklist[] = {
  82. {
  83. .ident = "Sapphire AM2RD790",
  84. .matches = {
  85. DMI_MATCH(DMI_BOARD_VENDOR, "SAPPHIRE Inc."),
  86. DMI_MATCH(DMI_BOARD_NAME, "PC-AM2RD790"),
  87. },
  88. },
  89. {
  90. .ident = "DFI Lanparty UT 790FX",
  91. .matches = {
  92. DMI_MATCH(DMI_BOARD_VENDOR, "DFI Inc."),
  93. DMI_MATCH(DMI_BOARD_NAME, "LP UT 790FX"),
  94. },
  95. },
  96. { }
  97. };
  98. /* The IBM entry is in a separate table because we only check it
  99. on Intel-based systems */
  100. static const struct dmi_system_id piix4_dmi_ibm[] = {
  101. {
  102. .ident = "IBM",
  103. .matches = { DMI_MATCH(DMI_SYS_VENDOR, "IBM"), },
  104. },
  105. { },
  106. };
  107. struct i2c_piix4_adapdata {
  108. unsigned short smba;
  109. };
  110. static int piix4_setup(struct pci_dev *PIIX4_dev,
  111. const struct pci_device_id *id)
  112. {
  113. unsigned char temp;
  114. unsigned short piix4_smba;
  115. if ((PIIX4_dev->vendor == PCI_VENDOR_ID_SERVERWORKS) &&
  116. (PIIX4_dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB5))
  117. srvrworks_csb5_delay = 1;
  118. /* On some motherboards, it was reported that accessing the SMBus
  119. caused severe hardware problems */
  120. if (dmi_check_system(piix4_dmi_blacklist)) {
  121. dev_err(&PIIX4_dev->dev,
  122. "Accessing the SMBus on this system is unsafe!\n");
  123. return -EPERM;
  124. }
  125. /* Don't access SMBus on IBM systems which get corrupted eeproms */
  126. if (dmi_check_system(piix4_dmi_ibm) &&
  127. PIIX4_dev->vendor == PCI_VENDOR_ID_INTEL) {
  128. dev_err(&PIIX4_dev->dev, "IBM system detected; this module "
  129. "may corrupt your serial eeprom! Refusing to load "
  130. "module!\n");
  131. return -EPERM;
  132. }
  133. /* Determine the address of the SMBus areas */
  134. if (force_addr) {
  135. piix4_smba = force_addr & 0xfff0;
  136. force = 0;
  137. } else {
  138. pci_read_config_word(PIIX4_dev, SMBBA, &piix4_smba);
  139. piix4_smba &= 0xfff0;
  140. if(piix4_smba == 0) {
  141. dev_err(&PIIX4_dev->dev, "SMBus base address "
  142. "uninitialized - upgrade BIOS or use "
  143. "force_addr=0xaddr\n");
  144. return -ENODEV;
  145. }
  146. }
  147. if (acpi_check_region(piix4_smba, SMBIOSIZE, piix4_driver.name))
  148. return -ENODEV;
  149. if (!request_region(piix4_smba, SMBIOSIZE, piix4_driver.name)) {
  150. dev_err(&PIIX4_dev->dev, "SMBus region 0x%x already in use!\n",
  151. piix4_smba);
  152. return -EBUSY;
  153. }
  154. pci_read_config_byte(PIIX4_dev, SMBHSTCFG, &temp);
  155. /* If force_addr is set, we program the new address here. Just to make
  156. sure, we disable the PIIX4 first. */
  157. if (force_addr) {
  158. pci_write_config_byte(PIIX4_dev, SMBHSTCFG, temp & 0xfe);
  159. pci_write_config_word(PIIX4_dev, SMBBA, piix4_smba);
  160. pci_write_config_byte(PIIX4_dev, SMBHSTCFG, temp | 0x01);
  161. dev_info(&PIIX4_dev->dev, "WARNING: SMBus interface set to "
  162. "new address %04x!\n", piix4_smba);
  163. } else if ((temp & 1) == 0) {
  164. if (force) {
  165. /* This should never need to be done, but has been
  166. * noted that many Dell machines have the SMBus
  167. * interface on the PIIX4 disabled!? NOTE: This assumes
  168. * I/O space and other allocations WERE done by the
  169. * Bios! Don't complain if your hardware does weird
  170. * things after enabling this. :') Check for Bios
  171. * updates before resorting to this.
  172. */
  173. pci_write_config_byte(PIIX4_dev, SMBHSTCFG,
  174. temp | 1);
  175. dev_notice(&PIIX4_dev->dev,
  176. "WARNING: SMBus interface has been FORCEFULLY ENABLED!\n");
  177. } else {
  178. dev_err(&PIIX4_dev->dev,
  179. "SMBus Host Controller not enabled!\n");
  180. release_region(piix4_smba, SMBIOSIZE);
  181. return -ENODEV;
  182. }
  183. }
  184. if (((temp & 0x0E) == 8) || ((temp & 0x0E) == 2))
  185. dev_dbg(&PIIX4_dev->dev, "Using IRQ for SMBus\n");
  186. else if ((temp & 0x0E) == 0)
  187. dev_dbg(&PIIX4_dev->dev, "Using SMI# for SMBus\n");
  188. else
  189. dev_err(&PIIX4_dev->dev, "Illegal Interrupt configuration "
  190. "(or code out of date)!\n");
  191. pci_read_config_byte(PIIX4_dev, SMBREV, &temp);
  192. dev_info(&PIIX4_dev->dev,
  193. "SMBus Host Controller at 0x%x, revision %d\n",
  194. piix4_smba, temp);
  195. return piix4_smba;
  196. }
  197. static int piix4_setup_sb800(struct pci_dev *PIIX4_dev,
  198. const struct pci_device_id *id, u8 aux)
  199. {
  200. unsigned short piix4_smba;
  201. unsigned short smba_idx = 0xcd6;
  202. u8 smba_en_lo, smba_en_hi, smb_en, smb_en_status;
  203. u8 i2ccfg, i2ccfg_offset = 0x10;
  204. /* SB800 and later SMBus does not support forcing address */
  205. if (force || force_addr) {
  206. dev_err(&PIIX4_dev->dev, "SMBus does not support "
  207. "forcing address!\n");
  208. return -EINVAL;
  209. }
  210. /* Determine the address of the SMBus areas */
  211. if ((PIIX4_dev->vendor == PCI_VENDOR_ID_AMD &&
  212. PIIX4_dev->device == PCI_DEVICE_ID_AMD_HUDSON2_SMBUS &&
  213. PIIX4_dev->revision >= 0x41) ||
  214. (PIIX4_dev->vendor == PCI_VENDOR_ID_AMD &&
  215. PIIX4_dev->device == PCI_DEVICE_ID_AMD_KERNCZ_SMBUS &&
  216. PIIX4_dev->revision >= 0x49))
  217. smb_en = 0x00;
  218. else
  219. smb_en = (aux) ? 0x28 : 0x2c;
  220. if (!request_region(smba_idx, 2, "smba_idx")) {
  221. dev_err(&PIIX4_dev->dev, "SMBus base address index region "
  222. "0x%x already in use!\n", smba_idx);
  223. return -EBUSY;
  224. }
  225. outb_p(smb_en, smba_idx);
  226. smba_en_lo = inb_p(smba_idx + 1);
  227. outb_p(smb_en + 1, smba_idx);
  228. smba_en_hi = inb_p(smba_idx + 1);
  229. release_region(smba_idx, 2);
  230. if (!smb_en) {
  231. smb_en_status = smba_en_lo & 0x10;
  232. piix4_smba = smba_en_hi << 8;
  233. if (aux)
  234. piix4_smba |= 0x20;
  235. } else {
  236. smb_en_status = smba_en_lo & 0x01;
  237. piix4_smba = ((smba_en_hi << 8) | smba_en_lo) & 0xffe0;
  238. }
  239. if (!smb_en_status) {
  240. dev_err(&PIIX4_dev->dev,
  241. "SMBus Host Controller not enabled!\n");
  242. return -ENODEV;
  243. }
  244. if (acpi_check_region(piix4_smba, SMBIOSIZE, piix4_driver.name))
  245. return -ENODEV;
  246. if (!request_region(piix4_smba, SMBIOSIZE, piix4_driver.name)) {
  247. dev_err(&PIIX4_dev->dev, "SMBus region 0x%x already in use!\n",
  248. piix4_smba);
  249. return -EBUSY;
  250. }
  251. /* Aux SMBus does not support IRQ information */
  252. if (aux) {
  253. dev_info(&PIIX4_dev->dev,
  254. "Auxiliary SMBus Host Controller at 0x%x\n",
  255. piix4_smba);
  256. return piix4_smba;
  257. }
  258. /* Request the SMBus I2C bus config region */
  259. if (!request_region(piix4_smba + i2ccfg_offset, 1, "i2ccfg")) {
  260. dev_err(&PIIX4_dev->dev, "SMBus I2C bus config region "
  261. "0x%x already in use!\n", piix4_smba + i2ccfg_offset);
  262. release_region(piix4_smba, SMBIOSIZE);
  263. return -EBUSY;
  264. }
  265. i2ccfg = inb_p(piix4_smba + i2ccfg_offset);
  266. release_region(piix4_smba + i2ccfg_offset, 1);
  267. if (i2ccfg & 1)
  268. dev_dbg(&PIIX4_dev->dev, "Using IRQ for SMBus\n");
  269. else
  270. dev_dbg(&PIIX4_dev->dev, "Using SMI# for SMBus\n");
  271. dev_info(&PIIX4_dev->dev,
  272. "SMBus Host Controller at 0x%x, revision %d\n",
  273. piix4_smba, i2ccfg >> 4);
  274. return piix4_smba;
  275. }
  276. static int piix4_setup_aux(struct pci_dev *PIIX4_dev,
  277. const struct pci_device_id *id,
  278. unsigned short base_reg_addr)
  279. {
  280. /* Set up auxiliary SMBus controllers found on some
  281. * AMD chipsets e.g. SP5100 (SB700 derivative) */
  282. unsigned short piix4_smba;
  283. /* Read address of auxiliary SMBus controller */
  284. pci_read_config_word(PIIX4_dev, base_reg_addr, &piix4_smba);
  285. if ((piix4_smba & 1) == 0) {
  286. dev_dbg(&PIIX4_dev->dev,
  287. "Auxiliary SMBus controller not enabled\n");
  288. return -ENODEV;
  289. }
  290. piix4_smba &= 0xfff0;
  291. if (piix4_smba == 0) {
  292. dev_dbg(&PIIX4_dev->dev,
  293. "Auxiliary SMBus base address uninitialized\n");
  294. return -ENODEV;
  295. }
  296. if (acpi_check_region(piix4_smba, SMBIOSIZE, piix4_driver.name))
  297. return -ENODEV;
  298. if (!request_region(piix4_smba, SMBIOSIZE, piix4_driver.name)) {
  299. dev_err(&PIIX4_dev->dev, "Auxiliary SMBus region 0x%x "
  300. "already in use!\n", piix4_smba);
  301. return -EBUSY;
  302. }
  303. dev_info(&PIIX4_dev->dev,
  304. "Auxiliary SMBus Host Controller at 0x%x\n",
  305. piix4_smba);
  306. return piix4_smba;
  307. }
  308. static int piix4_transaction(struct i2c_adapter *piix4_adapter)
  309. {
  310. struct i2c_piix4_adapdata *adapdata = i2c_get_adapdata(piix4_adapter);
  311. unsigned short piix4_smba = adapdata->smba;
  312. int temp;
  313. int result = 0;
  314. int timeout = 0;
  315. dev_dbg(&piix4_adapter->dev, "Transaction (pre): CNT=%02x, CMD=%02x, "
  316. "ADD=%02x, DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTCNT),
  317. inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0),
  318. inb_p(SMBHSTDAT1));
  319. /* Make sure the SMBus host is ready to start transmitting */
  320. if ((temp = inb_p(SMBHSTSTS)) != 0x00) {
  321. dev_dbg(&piix4_adapter->dev, "SMBus busy (%02x). "
  322. "Resetting...\n", temp);
  323. outb_p(temp, SMBHSTSTS);
  324. if ((temp = inb_p(SMBHSTSTS)) != 0x00) {
  325. dev_err(&piix4_adapter->dev, "Failed! (%02x)\n", temp);
  326. return -EBUSY;
  327. } else {
  328. dev_dbg(&piix4_adapter->dev, "Successful!\n");
  329. }
  330. }
  331. /* start the transaction by setting bit 6 */
  332. outb_p(inb(SMBHSTCNT) | 0x040, SMBHSTCNT);
  333. /* We will always wait for a fraction of a second! (See PIIX4 docs errata) */
  334. if (srvrworks_csb5_delay) /* Extra delay for SERVERWORKS_CSB5 */
  335. msleep(2);
  336. else
  337. msleep(1);
  338. while ((++timeout < MAX_TIMEOUT) &&
  339. ((temp = inb_p(SMBHSTSTS)) & 0x01))
  340. msleep(1);
  341. /* If the SMBus is still busy, we give up */
  342. if (timeout == MAX_TIMEOUT) {
  343. dev_err(&piix4_adapter->dev, "SMBus Timeout!\n");
  344. result = -ETIMEDOUT;
  345. }
  346. if (temp & 0x10) {
  347. result = -EIO;
  348. dev_err(&piix4_adapter->dev, "Error: Failed bus transaction\n");
  349. }
  350. if (temp & 0x08) {
  351. result = -EIO;
  352. dev_dbg(&piix4_adapter->dev, "Bus collision! SMBus may be "
  353. "locked until next hard reset. (sorry!)\n");
  354. /* Clock stops and slave is stuck in mid-transmission */
  355. }
  356. if (temp & 0x04) {
  357. result = -ENXIO;
  358. dev_dbg(&piix4_adapter->dev, "Error: no response!\n");
  359. }
  360. if (inb_p(SMBHSTSTS) != 0x00)
  361. outb_p(inb(SMBHSTSTS), SMBHSTSTS);
  362. if ((temp = inb_p(SMBHSTSTS)) != 0x00) {
  363. dev_err(&piix4_adapter->dev, "Failed reset at end of "
  364. "transaction (%02x)\n", temp);
  365. }
  366. dev_dbg(&piix4_adapter->dev, "Transaction (post): CNT=%02x, CMD=%02x, "
  367. "ADD=%02x, DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTCNT),
  368. inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0),
  369. inb_p(SMBHSTDAT1));
  370. return result;
  371. }
  372. /* Return negative errno on error. */
  373. static s32 piix4_access(struct i2c_adapter * adap, u16 addr,
  374. unsigned short flags, char read_write,
  375. u8 command, int size, union i2c_smbus_data * data)
  376. {
  377. struct i2c_piix4_adapdata *adapdata = i2c_get_adapdata(adap);
  378. unsigned short piix4_smba = adapdata->smba;
  379. int i, len;
  380. int status;
  381. switch (size) {
  382. case I2C_SMBUS_QUICK:
  383. outb_p((addr << 1) | read_write,
  384. SMBHSTADD);
  385. size = PIIX4_QUICK;
  386. break;
  387. case I2C_SMBUS_BYTE:
  388. outb_p((addr << 1) | read_write,
  389. SMBHSTADD);
  390. if (read_write == I2C_SMBUS_WRITE)
  391. outb_p(command, SMBHSTCMD);
  392. size = PIIX4_BYTE;
  393. break;
  394. case I2C_SMBUS_BYTE_DATA:
  395. outb_p((addr << 1) | read_write,
  396. SMBHSTADD);
  397. outb_p(command, SMBHSTCMD);
  398. if (read_write == I2C_SMBUS_WRITE)
  399. outb_p(data->byte, SMBHSTDAT0);
  400. size = PIIX4_BYTE_DATA;
  401. break;
  402. case I2C_SMBUS_WORD_DATA:
  403. outb_p((addr << 1) | read_write,
  404. SMBHSTADD);
  405. outb_p(command, SMBHSTCMD);
  406. if (read_write == I2C_SMBUS_WRITE) {
  407. outb_p(data->word & 0xff, SMBHSTDAT0);
  408. outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1);
  409. }
  410. size = PIIX4_WORD_DATA;
  411. break;
  412. case I2C_SMBUS_BLOCK_DATA:
  413. outb_p((addr << 1) | read_write,
  414. SMBHSTADD);
  415. outb_p(command, SMBHSTCMD);
  416. if (read_write == I2C_SMBUS_WRITE) {
  417. len = data->block[0];
  418. if (len == 0 || len > I2C_SMBUS_BLOCK_MAX)
  419. return -EINVAL;
  420. outb_p(len, SMBHSTDAT0);
  421. i = inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */
  422. for (i = 1; i <= len; i++)
  423. outb_p(data->block[i], SMBBLKDAT);
  424. }
  425. size = PIIX4_BLOCK_DATA;
  426. break;
  427. default:
  428. dev_warn(&adap->dev, "Unsupported transaction %d\n", size);
  429. return -EOPNOTSUPP;
  430. }
  431. outb_p((size & 0x1C) + (ENABLE_INT9 & 1), SMBHSTCNT);
  432. status = piix4_transaction(adap);
  433. if (status)
  434. return status;
  435. if ((read_write == I2C_SMBUS_WRITE) || (size == PIIX4_QUICK))
  436. return 0;
  437. switch (size) {
  438. case PIIX4_BYTE:
  439. case PIIX4_BYTE_DATA:
  440. data->byte = inb_p(SMBHSTDAT0);
  441. break;
  442. case PIIX4_WORD_DATA:
  443. data->word = inb_p(SMBHSTDAT0) + (inb_p(SMBHSTDAT1) << 8);
  444. break;
  445. case PIIX4_BLOCK_DATA:
  446. data->block[0] = inb_p(SMBHSTDAT0);
  447. if (data->block[0] == 0 || data->block[0] > I2C_SMBUS_BLOCK_MAX)
  448. return -EPROTO;
  449. i = inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */
  450. for (i = 1; i <= data->block[0]; i++)
  451. data->block[i] = inb_p(SMBBLKDAT);
  452. break;
  453. }
  454. return 0;
  455. }
  456. static u32 piix4_func(struct i2c_adapter *adapter)
  457. {
  458. return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
  459. I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
  460. I2C_FUNC_SMBUS_BLOCK_DATA;
  461. }
  462. static const struct i2c_algorithm smbus_algorithm = {
  463. .smbus_xfer = piix4_access,
  464. .functionality = piix4_func,
  465. };
  466. static const struct pci_device_id piix4_ids[] = {
  467. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_3) },
  468. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443MX_3) },
  469. { PCI_DEVICE(PCI_VENDOR_ID_EFAR, PCI_DEVICE_ID_EFAR_SLC90E66_3) },
  470. { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP200_SMBUS) },
  471. { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP300_SMBUS) },
  472. { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP400_SMBUS) },
  473. { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_SBX00_SMBUS) },
  474. { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_HUDSON2_SMBUS) },
  475. { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_KERNCZ_SMBUS) },
  476. { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS,
  477. PCI_DEVICE_ID_SERVERWORKS_OSB4) },
  478. { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS,
  479. PCI_DEVICE_ID_SERVERWORKS_CSB5) },
  480. { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS,
  481. PCI_DEVICE_ID_SERVERWORKS_CSB6) },
  482. { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS,
  483. PCI_DEVICE_ID_SERVERWORKS_HT1000SB) },
  484. { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS,
  485. PCI_DEVICE_ID_SERVERWORKS_HT1100LD) },
  486. { 0, }
  487. };
  488. MODULE_DEVICE_TABLE (pci, piix4_ids);
  489. static struct i2c_adapter *piix4_main_adapter;
  490. static struct i2c_adapter *piix4_aux_adapter;
  491. static int piix4_add_adapter(struct pci_dev *dev, unsigned short smba,
  492. struct i2c_adapter **padap)
  493. {
  494. struct i2c_adapter *adap;
  495. struct i2c_piix4_adapdata *adapdata;
  496. int retval;
  497. adap = kzalloc(sizeof(*adap), GFP_KERNEL);
  498. if (adap == NULL) {
  499. release_region(smba, SMBIOSIZE);
  500. return -ENOMEM;
  501. }
  502. adap->owner = THIS_MODULE;
  503. adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
  504. adap->algo = &smbus_algorithm;
  505. adapdata = kzalloc(sizeof(*adapdata), GFP_KERNEL);
  506. if (adapdata == NULL) {
  507. kfree(adap);
  508. release_region(smba, SMBIOSIZE);
  509. return -ENOMEM;
  510. }
  511. adapdata->smba = smba;
  512. /* set up the sysfs linkage to our parent device */
  513. adap->dev.parent = &dev->dev;
  514. snprintf(adap->name, sizeof(adap->name),
  515. "SMBus PIIX4 adapter at %04x", smba);
  516. i2c_set_adapdata(adap, adapdata);
  517. retval = i2c_add_adapter(adap);
  518. if (retval) {
  519. dev_err(&dev->dev, "Couldn't register adapter!\n");
  520. kfree(adapdata);
  521. kfree(adap);
  522. release_region(smba, SMBIOSIZE);
  523. return retval;
  524. }
  525. *padap = adap;
  526. return 0;
  527. }
  528. static int piix4_probe(struct pci_dev *dev, const struct pci_device_id *id)
  529. {
  530. int retval;
  531. if ((dev->vendor == PCI_VENDOR_ID_ATI &&
  532. dev->device == PCI_DEVICE_ID_ATI_SBX00_SMBUS &&
  533. dev->revision >= 0x40) ||
  534. dev->vendor == PCI_VENDOR_ID_AMD)
  535. /* base address location etc changed in SB800 */
  536. retval = piix4_setup_sb800(dev, id, 0);
  537. else
  538. retval = piix4_setup(dev, id);
  539. /* If no main SMBus found, give up */
  540. if (retval < 0)
  541. return retval;
  542. /* Try to register main SMBus adapter, give up if we can't */
  543. retval = piix4_add_adapter(dev, retval, &piix4_main_adapter);
  544. if (retval < 0)
  545. return retval;
  546. /* Check for auxiliary SMBus on some AMD chipsets */
  547. retval = -ENODEV;
  548. if (dev->vendor == PCI_VENDOR_ID_ATI &&
  549. dev->device == PCI_DEVICE_ID_ATI_SBX00_SMBUS) {
  550. if (dev->revision < 0x40) {
  551. retval = piix4_setup_aux(dev, id, 0x58);
  552. } else {
  553. /* SB800 added aux bus too */
  554. retval = piix4_setup_sb800(dev, id, 1);
  555. }
  556. }
  557. if (dev->vendor == PCI_VENDOR_ID_AMD &&
  558. dev->device == PCI_DEVICE_ID_AMD_HUDSON2_SMBUS) {
  559. retval = piix4_setup_sb800(dev, id, 1);
  560. }
  561. if (retval > 0) {
  562. /* Try to add the aux adapter if it exists,
  563. * piix4_add_adapter will clean up if this fails */
  564. piix4_add_adapter(dev, retval, &piix4_aux_adapter);
  565. }
  566. return 0;
  567. }
  568. static void piix4_adap_remove(struct i2c_adapter *adap)
  569. {
  570. struct i2c_piix4_adapdata *adapdata = i2c_get_adapdata(adap);
  571. if (adapdata->smba) {
  572. i2c_del_adapter(adap);
  573. release_region(adapdata->smba, SMBIOSIZE);
  574. kfree(adapdata);
  575. kfree(adap);
  576. }
  577. }
  578. static void piix4_remove(struct pci_dev *dev)
  579. {
  580. if (piix4_main_adapter) {
  581. piix4_adap_remove(piix4_main_adapter);
  582. piix4_main_adapter = NULL;
  583. }
  584. if (piix4_aux_adapter) {
  585. piix4_adap_remove(piix4_aux_adapter);
  586. piix4_aux_adapter = NULL;
  587. }
  588. }
  589. static struct pci_driver piix4_driver = {
  590. .name = "piix4_smbus",
  591. .id_table = piix4_ids,
  592. .probe = piix4_probe,
  593. .remove = piix4_remove,
  594. };
  595. module_pci_driver(piix4_driver);
  596. MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl> and "
  597. "Philip Edelbrock <phil@netroedge.com>");
  598. MODULE_DESCRIPTION("PIIX4 SMBus driver");
  599. MODULE_LICENSE("GPL");