i2c-piix4.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  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, SB800
  21. AMD Hudson-2, CZ
  22. SMSC Victory66
  23. Note: we assume there can only be one device, with one SMBus interface.
  24. */
  25. #include <linux/module.h>
  26. #include <linux/moduleparam.h>
  27. #include <linux/pci.h>
  28. #include <linux/kernel.h>
  29. #include <linux/delay.h>
  30. #include <linux/stddef.h>
  31. #include <linux/ioport.h>
  32. #include <linux/i2c.h>
  33. #include <linux/init.h>
  34. #include <linux/dmi.h>
  35. #include <linux/acpi.h>
  36. #include <linux/io.h>
  37. /* PIIX4 SMBus address offsets */
  38. #define SMBHSTSTS (0 + piix4_smba)
  39. #define SMBHSLVSTS (1 + piix4_smba)
  40. #define SMBHSTCNT (2 + piix4_smba)
  41. #define SMBHSTCMD (3 + piix4_smba)
  42. #define SMBHSTADD (4 + piix4_smba)
  43. #define SMBHSTDAT0 (5 + piix4_smba)
  44. #define SMBHSTDAT1 (6 + piix4_smba)
  45. #define SMBBLKDAT (7 + piix4_smba)
  46. #define SMBSLVCNT (8 + piix4_smba)
  47. #define SMBSHDWCMD (9 + piix4_smba)
  48. #define SMBSLVEVT (0xA + piix4_smba)
  49. #define SMBSLVDAT (0xC + piix4_smba)
  50. /* count for request_region */
  51. #define SMBIOSIZE 8
  52. /* PCI Address Constants */
  53. #define SMBBA 0x090
  54. #define SMBHSTCFG 0x0D2
  55. #define SMBSLVC 0x0D3
  56. #define SMBSHDW1 0x0D4
  57. #define SMBSHDW2 0x0D5
  58. #define SMBREV 0x0D6
  59. /* Other settings */
  60. #define MAX_TIMEOUT 500
  61. #define ENABLE_INT9 0
  62. /* PIIX4 constants */
  63. #define PIIX4_QUICK 0x00
  64. #define PIIX4_BYTE 0x04
  65. #define PIIX4_BYTE_DATA 0x08
  66. #define PIIX4_WORD_DATA 0x0C
  67. #define PIIX4_BLOCK_DATA 0x14
  68. /* insmod parameters */
  69. /* If force is set to anything different from 0, we forcibly enable the
  70. PIIX4. DANGEROUS! */
  71. static int force;
  72. module_param (force, int, 0);
  73. MODULE_PARM_DESC(force, "Forcibly enable the PIIX4. DANGEROUS!");
  74. /* If force_addr is set to anything different from 0, we forcibly enable
  75. the PIIX4 at the given address. VERY DANGEROUS! */
  76. static int force_addr;
  77. module_param (force_addr, int, 0);
  78. MODULE_PARM_DESC(force_addr,
  79. "Forcibly enable the PIIX4 at the given address. "
  80. "EXTREMELY DANGEROUS!");
  81. static unsigned short piix4_smba;
  82. static int srvrworks_csb5_delay;
  83. static struct pci_driver piix4_driver;
  84. static struct i2c_adapter piix4_adapter;
  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. static int __devinit piix4_setup(struct pci_dev *PIIX4_dev,
  112. const struct pci_device_id *id)
  113. {
  114. unsigned char temp;
  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_printk(KERN_NOTICE, &PIIX4_dev->dev,
  176. "WARNING: SMBus interface has been "
  177. "FORCEFULLY ENABLED!\n");
  178. } else {
  179. dev_err(&PIIX4_dev->dev,
  180. "Host SMBus controller not enabled!\n");
  181. release_region(piix4_smba, SMBIOSIZE);
  182. piix4_smba = 0;
  183. return -ENODEV;
  184. }
  185. }
  186. if (((temp & 0x0E) == 8) || ((temp & 0x0E) == 2))
  187. dev_dbg(&PIIX4_dev->dev, "Using Interrupt 9 for SMBus.\n");
  188. else if ((temp & 0x0E) == 0)
  189. dev_dbg(&PIIX4_dev->dev, "Using Interrupt SMI# for SMBus.\n");
  190. else
  191. dev_err(&PIIX4_dev->dev, "Illegal Interrupt configuration "
  192. "(or code out of date)!\n");
  193. pci_read_config_byte(PIIX4_dev, SMBREV, &temp);
  194. dev_info(&PIIX4_dev->dev,
  195. "SMBus Host Controller at 0x%x, revision %d\n",
  196. piix4_smba, temp);
  197. return 0;
  198. }
  199. static int __devinit piix4_setup_sb800(struct pci_dev *PIIX4_dev,
  200. const struct pci_device_id *id)
  201. {
  202. unsigned short smba_idx = 0xcd6;
  203. u8 smba_en_lo, smba_en_hi, i2ccfg, i2ccfg_offset = 0x10, smb_en = 0x2c;
  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 (!request_region(smba_idx, 2, "smba_idx")) {
  212. dev_err(&PIIX4_dev->dev, "SMBus base address index region "
  213. "0x%x already in use!\n", smba_idx);
  214. return -EBUSY;
  215. }
  216. outb_p(smb_en, smba_idx);
  217. smba_en_lo = inb_p(smba_idx + 1);
  218. outb_p(smb_en + 1, smba_idx);
  219. smba_en_hi = inb_p(smba_idx + 1);
  220. release_region(smba_idx, 2);
  221. if ((smba_en_lo & 1) == 0) {
  222. dev_err(&PIIX4_dev->dev,
  223. "Host SMBus controller not enabled!\n");
  224. return -ENODEV;
  225. }
  226. piix4_smba = ((smba_en_hi << 8) | smba_en_lo) & 0xffe0;
  227. if (acpi_check_region(piix4_smba, SMBIOSIZE, piix4_driver.name))
  228. return -ENODEV;
  229. if (!request_region(piix4_smba, SMBIOSIZE, piix4_driver.name)) {
  230. dev_err(&PIIX4_dev->dev, "SMBus region 0x%x already in use!\n",
  231. piix4_smba);
  232. return -EBUSY;
  233. }
  234. /* Request the SMBus I2C bus config region */
  235. if (!request_region(piix4_smba + i2ccfg_offset, 1, "i2ccfg")) {
  236. dev_err(&PIIX4_dev->dev, "SMBus I2C bus config region "
  237. "0x%x already in use!\n", piix4_smba + i2ccfg_offset);
  238. release_region(piix4_smba, SMBIOSIZE);
  239. piix4_smba = 0;
  240. return -EBUSY;
  241. }
  242. i2ccfg = inb_p(piix4_smba + i2ccfg_offset);
  243. release_region(piix4_smba + i2ccfg_offset, 1);
  244. if (i2ccfg & 1)
  245. dev_dbg(&PIIX4_dev->dev, "Using IRQ for SMBus.\n");
  246. else
  247. dev_dbg(&PIIX4_dev->dev, "Using SMI# for SMBus.\n");
  248. dev_info(&PIIX4_dev->dev,
  249. "SMBus Host Controller at 0x%x, revision %d\n",
  250. piix4_smba, i2ccfg >> 4);
  251. return 0;
  252. }
  253. static int piix4_transaction(void)
  254. {
  255. int temp;
  256. int result = 0;
  257. int timeout = 0;
  258. dev_dbg(&piix4_adapter.dev, "Transaction (pre): CNT=%02x, CMD=%02x, "
  259. "ADD=%02x, DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTCNT),
  260. inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0),
  261. inb_p(SMBHSTDAT1));
  262. /* Make sure the SMBus host is ready to start transmitting */
  263. if ((temp = inb_p(SMBHSTSTS)) != 0x00) {
  264. dev_dbg(&piix4_adapter.dev, "SMBus busy (%02x). "
  265. "Resetting...\n", temp);
  266. outb_p(temp, SMBHSTSTS);
  267. if ((temp = inb_p(SMBHSTSTS)) != 0x00) {
  268. dev_err(&piix4_adapter.dev, "Failed! (%02x)\n", temp);
  269. return -EBUSY;
  270. } else {
  271. dev_dbg(&piix4_adapter.dev, "Successful!\n");
  272. }
  273. }
  274. /* start the transaction by setting bit 6 */
  275. outb_p(inb(SMBHSTCNT) | 0x040, SMBHSTCNT);
  276. /* We will always wait for a fraction of a second! (See PIIX4 docs errata) */
  277. if (srvrworks_csb5_delay) /* Extra delay for SERVERWORKS_CSB5 */
  278. msleep(2);
  279. else
  280. msleep(1);
  281. while ((++timeout < MAX_TIMEOUT) &&
  282. ((temp = inb_p(SMBHSTSTS)) & 0x01))
  283. msleep(1);
  284. /* If the SMBus is still busy, we give up */
  285. if (timeout == MAX_TIMEOUT) {
  286. dev_err(&piix4_adapter.dev, "SMBus Timeout!\n");
  287. result = -ETIMEDOUT;
  288. }
  289. if (temp & 0x10) {
  290. result = -EIO;
  291. dev_err(&piix4_adapter.dev, "Error: Failed bus transaction\n");
  292. }
  293. if (temp & 0x08) {
  294. result = -EIO;
  295. dev_dbg(&piix4_adapter.dev, "Bus collision! SMBus may be "
  296. "locked until next hard reset. (sorry!)\n");
  297. /* Clock stops and slave is stuck in mid-transmission */
  298. }
  299. if (temp & 0x04) {
  300. result = -ENXIO;
  301. dev_dbg(&piix4_adapter.dev, "Error: no response!\n");
  302. }
  303. if (inb_p(SMBHSTSTS) != 0x00)
  304. outb_p(inb(SMBHSTSTS), SMBHSTSTS);
  305. if ((temp = inb_p(SMBHSTSTS)) != 0x00) {
  306. dev_err(&piix4_adapter.dev, "Failed reset at end of "
  307. "transaction (%02x)\n", temp);
  308. }
  309. dev_dbg(&piix4_adapter.dev, "Transaction (post): CNT=%02x, CMD=%02x, "
  310. "ADD=%02x, DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTCNT),
  311. inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0),
  312. inb_p(SMBHSTDAT1));
  313. return result;
  314. }
  315. /* Return negative errno on error. */
  316. static s32 piix4_access(struct i2c_adapter * adap, u16 addr,
  317. unsigned short flags, char read_write,
  318. u8 command, int size, union i2c_smbus_data * data)
  319. {
  320. int i, len;
  321. int status;
  322. switch (size) {
  323. case I2C_SMBUS_QUICK:
  324. outb_p((addr << 1) | read_write,
  325. SMBHSTADD);
  326. size = PIIX4_QUICK;
  327. break;
  328. case I2C_SMBUS_BYTE:
  329. outb_p((addr << 1) | read_write,
  330. SMBHSTADD);
  331. if (read_write == I2C_SMBUS_WRITE)
  332. outb_p(command, SMBHSTCMD);
  333. size = PIIX4_BYTE;
  334. break;
  335. case I2C_SMBUS_BYTE_DATA:
  336. outb_p((addr << 1) | read_write,
  337. SMBHSTADD);
  338. outb_p(command, SMBHSTCMD);
  339. if (read_write == I2C_SMBUS_WRITE)
  340. outb_p(data->byte, SMBHSTDAT0);
  341. size = PIIX4_BYTE_DATA;
  342. break;
  343. case I2C_SMBUS_WORD_DATA:
  344. outb_p((addr << 1) | read_write,
  345. SMBHSTADD);
  346. outb_p(command, SMBHSTCMD);
  347. if (read_write == I2C_SMBUS_WRITE) {
  348. outb_p(data->word & 0xff, SMBHSTDAT0);
  349. outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1);
  350. }
  351. size = PIIX4_WORD_DATA;
  352. break;
  353. case I2C_SMBUS_BLOCK_DATA:
  354. outb_p((addr << 1) | read_write,
  355. SMBHSTADD);
  356. outb_p(command, SMBHSTCMD);
  357. if (read_write == I2C_SMBUS_WRITE) {
  358. len = data->block[0];
  359. if (len == 0 || len > I2C_SMBUS_BLOCK_MAX)
  360. return -EINVAL;
  361. outb_p(len, SMBHSTDAT0);
  362. i = inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */
  363. for (i = 1; i <= len; i++)
  364. outb_p(data->block[i], SMBBLKDAT);
  365. }
  366. size = PIIX4_BLOCK_DATA;
  367. break;
  368. default:
  369. dev_warn(&adap->dev, "Unsupported transaction %d\n", size);
  370. return -EOPNOTSUPP;
  371. }
  372. outb_p((size & 0x1C) + (ENABLE_INT9 & 1), SMBHSTCNT);
  373. status = piix4_transaction();
  374. if (status)
  375. return status;
  376. if ((read_write == I2C_SMBUS_WRITE) || (size == PIIX4_QUICK))
  377. return 0;
  378. switch (size) {
  379. case PIIX4_BYTE:
  380. case PIIX4_BYTE_DATA:
  381. data->byte = inb_p(SMBHSTDAT0);
  382. break;
  383. case PIIX4_WORD_DATA:
  384. data->word = inb_p(SMBHSTDAT0) + (inb_p(SMBHSTDAT1) << 8);
  385. break;
  386. case PIIX4_BLOCK_DATA:
  387. data->block[0] = inb_p(SMBHSTDAT0);
  388. if (data->block[0] == 0 || data->block[0] > I2C_SMBUS_BLOCK_MAX)
  389. return -EPROTO;
  390. i = inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */
  391. for (i = 1; i <= data->block[0]; i++)
  392. data->block[i] = inb_p(SMBBLKDAT);
  393. break;
  394. }
  395. return 0;
  396. }
  397. static u32 piix4_func(struct i2c_adapter *adapter)
  398. {
  399. return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
  400. I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
  401. I2C_FUNC_SMBUS_BLOCK_DATA;
  402. }
  403. static const struct i2c_algorithm smbus_algorithm = {
  404. .smbus_xfer = piix4_access,
  405. .functionality = piix4_func,
  406. };
  407. static struct i2c_adapter piix4_adapter = {
  408. .owner = THIS_MODULE,
  409. .class = I2C_CLASS_HWMON | I2C_CLASS_SPD,
  410. .algo = &smbus_algorithm,
  411. };
  412. static DEFINE_PCI_DEVICE_TABLE(piix4_ids) = {
  413. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_3) },
  414. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443MX_3) },
  415. { PCI_DEVICE(PCI_VENDOR_ID_EFAR, PCI_DEVICE_ID_EFAR_SLC90E66_3) },
  416. { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP200_SMBUS) },
  417. { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP300_SMBUS) },
  418. { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP400_SMBUS) },
  419. { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_SBX00_SMBUS) },
  420. { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_HUDSON2_SMBUS) },
  421. { PCI_DEVICE(PCI_VENDOR_ID_AMD, 0x790b) },
  422. { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS,
  423. PCI_DEVICE_ID_SERVERWORKS_OSB4) },
  424. { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS,
  425. PCI_DEVICE_ID_SERVERWORKS_CSB5) },
  426. { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS,
  427. PCI_DEVICE_ID_SERVERWORKS_CSB6) },
  428. { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS,
  429. PCI_DEVICE_ID_SERVERWORKS_HT1000SB) },
  430. { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS,
  431. PCI_DEVICE_ID_SERVERWORKS_HT1100LD) },
  432. { 0, }
  433. };
  434. MODULE_DEVICE_TABLE (pci, piix4_ids);
  435. static int __devinit piix4_probe(struct pci_dev *dev,
  436. const struct pci_device_id *id)
  437. {
  438. int retval;
  439. if ((dev->vendor == PCI_VENDOR_ID_ATI &&
  440. dev->device == PCI_DEVICE_ID_ATI_SBX00_SMBUS &&
  441. dev->revision >= 0x40) ||
  442. dev->vendor == PCI_VENDOR_ID_AMD)
  443. /* base address location etc changed in SB800 */
  444. retval = piix4_setup_sb800(dev, id);
  445. else
  446. retval = piix4_setup(dev, id);
  447. if (retval)
  448. return retval;
  449. /* set up the sysfs linkage to our parent device */
  450. piix4_adapter.dev.parent = &dev->dev;
  451. snprintf(piix4_adapter.name, sizeof(piix4_adapter.name),
  452. "SMBus PIIX4 adapter at %04x", piix4_smba);
  453. if ((retval = i2c_add_adapter(&piix4_adapter))) {
  454. dev_err(&dev->dev, "Couldn't register adapter!\n");
  455. release_region(piix4_smba, SMBIOSIZE);
  456. piix4_smba = 0;
  457. }
  458. return retval;
  459. }
  460. static void __devexit piix4_remove(struct pci_dev *dev)
  461. {
  462. if (piix4_smba) {
  463. i2c_del_adapter(&piix4_adapter);
  464. release_region(piix4_smba, SMBIOSIZE);
  465. piix4_smba = 0;
  466. }
  467. }
  468. static struct pci_driver piix4_driver = {
  469. .name = "piix4_smbus",
  470. .id_table = piix4_ids,
  471. .probe = piix4_probe,
  472. .remove = __devexit_p(piix4_remove),
  473. };
  474. static int __init i2c_piix4_init(void)
  475. {
  476. return pci_register_driver(&piix4_driver);
  477. }
  478. static void __exit i2c_piix4_exit(void)
  479. {
  480. pci_unregister_driver(&piix4_driver);
  481. }
  482. MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl> and "
  483. "Philip Edelbrock <phil@netroedge.com>");
  484. MODULE_DESCRIPTION("PIIX4 SMBus driver");
  485. MODULE_LICENSE("GPL");
  486. module_init(i2c_piix4_init);
  487. module_exit(i2c_piix4_exit);