i2c-piix4.c 18 KB

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