i2c-piix4.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  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 const struct dmi_system_id 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 const struct dmi_system_id 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 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_notice(&PIIX4_dev->dev,
  180. "WARNING: SMBus interface has been FORCEFULLY ENABLED!\n");
  181. } else {
  182. dev_err(&PIIX4_dev->dev,
  183. "Host SMBus controller not enabled!\n");
  184. release_region(piix4_smba, SMBIOSIZE);
  185. return -ENODEV;
  186. }
  187. }
  188. if (((temp & 0x0E) == 8) || ((temp & 0x0E) == 2))
  189. dev_dbg(&PIIX4_dev->dev, "Using Interrupt 9 for SMBus.\n");
  190. else if ((temp & 0x0E) == 0)
  191. dev_dbg(&PIIX4_dev->dev, "Using Interrupt SMI# for SMBus.\n");
  192. else
  193. dev_err(&PIIX4_dev->dev, "Illegal Interrupt configuration "
  194. "(or code out of date)!\n");
  195. pci_read_config_byte(PIIX4_dev, SMBREV, &temp);
  196. dev_info(&PIIX4_dev->dev,
  197. "SMBus Host Controller at 0x%x, revision %d\n",
  198. piix4_smba, temp);
  199. return piix4_smba;
  200. }
  201. static int piix4_setup_sb800(struct pci_dev *PIIX4_dev,
  202. const struct pci_device_id *id)
  203. {
  204. unsigned short piix4_smba;
  205. unsigned short smba_idx = 0xcd6;
  206. u8 smba_en_lo, smba_en_hi, i2ccfg, i2ccfg_offset = 0x10, smb_en = 0x2c;
  207. /* SB800 and later SMBus does not support forcing address */
  208. if (force || force_addr) {
  209. dev_err(&PIIX4_dev->dev, "SMBus does not support "
  210. "forcing address!\n");
  211. return -EINVAL;
  212. }
  213. /* Determine the address of the SMBus areas */
  214. if (!request_region(smba_idx, 2, "smba_idx")) {
  215. dev_err(&PIIX4_dev->dev, "SMBus base address index region "
  216. "0x%x already in use!\n", smba_idx);
  217. return -EBUSY;
  218. }
  219. outb_p(smb_en, smba_idx);
  220. smba_en_lo = inb_p(smba_idx + 1);
  221. outb_p(smb_en + 1, smba_idx);
  222. smba_en_hi = inb_p(smba_idx + 1);
  223. release_region(smba_idx, 2);
  224. if ((smba_en_lo & 1) == 0) {
  225. dev_err(&PIIX4_dev->dev,
  226. "Host SMBus controller not enabled!\n");
  227. return -ENODEV;
  228. }
  229. piix4_smba = ((smba_en_hi << 8) | smba_en_lo) & 0xffe0;
  230. if (acpi_check_region(piix4_smba, SMBIOSIZE, piix4_driver.name))
  231. return -ENODEV;
  232. if (!request_region(piix4_smba, SMBIOSIZE, piix4_driver.name)) {
  233. dev_err(&PIIX4_dev->dev, "SMBus region 0x%x already in use!\n",
  234. piix4_smba);
  235. return -EBUSY;
  236. }
  237. /* Request the SMBus I2C bus config region */
  238. if (!request_region(piix4_smba + i2ccfg_offset, 1, "i2ccfg")) {
  239. dev_err(&PIIX4_dev->dev, "SMBus I2C bus config region "
  240. "0x%x already in use!\n", piix4_smba + i2ccfg_offset);
  241. release_region(piix4_smba, SMBIOSIZE);
  242. return -EBUSY;
  243. }
  244. i2ccfg = inb_p(piix4_smba + i2ccfg_offset);
  245. release_region(piix4_smba + i2ccfg_offset, 1);
  246. if (i2ccfg & 1)
  247. dev_dbg(&PIIX4_dev->dev, "Using IRQ for SMBus.\n");
  248. else
  249. dev_dbg(&PIIX4_dev->dev, "Using SMI# for SMBus.\n");
  250. dev_info(&PIIX4_dev->dev,
  251. "SMBus Host Controller at 0x%x, revision %d\n",
  252. piix4_smba, i2ccfg >> 4);
  253. return piix4_smba;
  254. }
  255. static int piix4_setup_aux(struct pci_dev *PIIX4_dev,
  256. const struct pci_device_id *id,
  257. unsigned short base_reg_addr)
  258. {
  259. /* Set up auxiliary SMBus controllers found on some
  260. * AMD chipsets e.g. SP5100 (SB700 derivative) */
  261. unsigned short piix4_smba;
  262. /* Read address of auxiliary SMBus controller */
  263. pci_read_config_word(PIIX4_dev, base_reg_addr, &piix4_smba);
  264. if ((piix4_smba & 1) == 0) {
  265. dev_dbg(&PIIX4_dev->dev,
  266. "Auxiliary SMBus controller not enabled\n");
  267. return -ENODEV;
  268. }
  269. piix4_smba &= 0xfff0;
  270. if (piix4_smba == 0) {
  271. dev_dbg(&PIIX4_dev->dev,
  272. "Auxiliary SMBus base address uninitialized\n");
  273. return -ENODEV;
  274. }
  275. if (acpi_check_region(piix4_smba, SMBIOSIZE, piix4_driver.name))
  276. return -ENODEV;
  277. if (!request_region(piix4_smba, SMBIOSIZE, piix4_driver.name)) {
  278. dev_err(&PIIX4_dev->dev, "Auxiliary SMBus region 0x%x "
  279. "already in use!\n", piix4_smba);
  280. return -EBUSY;
  281. }
  282. dev_info(&PIIX4_dev->dev,
  283. "Auxiliary SMBus Host Controller at 0x%x\n",
  284. piix4_smba);
  285. return piix4_smba;
  286. }
  287. static int piix4_transaction(struct i2c_adapter *piix4_adapter)
  288. {
  289. struct i2c_piix4_adapdata *adapdata = i2c_get_adapdata(piix4_adapter);
  290. unsigned short piix4_smba = adapdata->smba;
  291. int temp;
  292. int result = 0;
  293. int timeout = 0;
  294. dev_dbg(&piix4_adapter->dev, "Transaction (pre): CNT=%02x, CMD=%02x, "
  295. "ADD=%02x, DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTCNT),
  296. inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0),
  297. inb_p(SMBHSTDAT1));
  298. /* Make sure the SMBus host is ready to start transmitting */
  299. if ((temp = inb_p(SMBHSTSTS)) != 0x00) {
  300. dev_dbg(&piix4_adapter->dev, "SMBus busy (%02x). "
  301. "Resetting...\n", temp);
  302. outb_p(temp, SMBHSTSTS);
  303. if ((temp = inb_p(SMBHSTSTS)) != 0x00) {
  304. dev_err(&piix4_adapter->dev, "Failed! (%02x)\n", temp);
  305. return -EBUSY;
  306. } else {
  307. dev_dbg(&piix4_adapter->dev, "Successful!\n");
  308. }
  309. }
  310. /* start the transaction by setting bit 6 */
  311. outb_p(inb(SMBHSTCNT) | 0x040, SMBHSTCNT);
  312. /* We will always wait for a fraction of a second! (See PIIX4 docs errata) */
  313. if (srvrworks_csb5_delay) /* Extra delay for SERVERWORKS_CSB5 */
  314. msleep(2);
  315. else
  316. msleep(1);
  317. while ((++timeout < MAX_TIMEOUT) &&
  318. ((temp = inb_p(SMBHSTSTS)) & 0x01))
  319. msleep(1);
  320. /* If the SMBus is still busy, we give up */
  321. if (timeout == MAX_TIMEOUT) {
  322. dev_err(&piix4_adapter->dev, "SMBus Timeout!\n");
  323. result = -ETIMEDOUT;
  324. }
  325. if (temp & 0x10) {
  326. result = -EIO;
  327. dev_err(&piix4_adapter->dev, "Error: Failed bus transaction\n");
  328. }
  329. if (temp & 0x08) {
  330. result = -EIO;
  331. dev_dbg(&piix4_adapter->dev, "Bus collision! SMBus may be "
  332. "locked until next hard reset. (sorry!)\n");
  333. /* Clock stops and slave is stuck in mid-transmission */
  334. }
  335. if (temp & 0x04) {
  336. result = -ENXIO;
  337. dev_dbg(&piix4_adapter->dev, "Error: no response!\n");
  338. }
  339. if (inb_p(SMBHSTSTS) != 0x00)
  340. outb_p(inb(SMBHSTSTS), SMBHSTSTS);
  341. if ((temp = inb_p(SMBHSTSTS)) != 0x00) {
  342. dev_err(&piix4_adapter->dev, "Failed reset at end of "
  343. "transaction (%02x)\n", temp);
  344. }
  345. dev_dbg(&piix4_adapter->dev, "Transaction (post): CNT=%02x, CMD=%02x, "
  346. "ADD=%02x, DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTCNT),
  347. inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0),
  348. inb_p(SMBHSTDAT1));
  349. return result;
  350. }
  351. /* Return negative errno on error. */
  352. static s32 piix4_access(struct i2c_adapter * adap, u16 addr,
  353. unsigned short flags, char read_write,
  354. u8 command, int size, union i2c_smbus_data * data)
  355. {
  356. struct i2c_piix4_adapdata *adapdata = i2c_get_adapdata(adap);
  357. unsigned short piix4_smba = adapdata->smba;
  358. int i, len;
  359. int status;
  360. switch (size) {
  361. case I2C_SMBUS_QUICK:
  362. outb_p((addr << 1) | read_write,
  363. SMBHSTADD);
  364. size = PIIX4_QUICK;
  365. break;
  366. case I2C_SMBUS_BYTE:
  367. outb_p((addr << 1) | read_write,
  368. SMBHSTADD);
  369. if (read_write == I2C_SMBUS_WRITE)
  370. outb_p(command, SMBHSTCMD);
  371. size = PIIX4_BYTE;
  372. break;
  373. case I2C_SMBUS_BYTE_DATA:
  374. outb_p((addr << 1) | read_write,
  375. SMBHSTADD);
  376. outb_p(command, SMBHSTCMD);
  377. if (read_write == I2C_SMBUS_WRITE)
  378. outb_p(data->byte, SMBHSTDAT0);
  379. size = PIIX4_BYTE_DATA;
  380. break;
  381. case I2C_SMBUS_WORD_DATA:
  382. outb_p((addr << 1) | read_write,
  383. SMBHSTADD);
  384. outb_p(command, SMBHSTCMD);
  385. if (read_write == I2C_SMBUS_WRITE) {
  386. outb_p(data->word & 0xff, SMBHSTDAT0);
  387. outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1);
  388. }
  389. size = PIIX4_WORD_DATA;
  390. break;
  391. case I2C_SMBUS_BLOCK_DATA:
  392. outb_p((addr << 1) | read_write,
  393. SMBHSTADD);
  394. outb_p(command, SMBHSTCMD);
  395. if (read_write == I2C_SMBUS_WRITE) {
  396. len = data->block[0];
  397. if (len == 0 || len > I2C_SMBUS_BLOCK_MAX)
  398. return -EINVAL;
  399. outb_p(len, SMBHSTDAT0);
  400. i = inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */
  401. for (i = 1; i <= len; i++)
  402. outb_p(data->block[i], SMBBLKDAT);
  403. }
  404. size = PIIX4_BLOCK_DATA;
  405. break;
  406. default:
  407. dev_warn(&adap->dev, "Unsupported transaction %d\n", size);
  408. return -EOPNOTSUPP;
  409. }
  410. outb_p((size & 0x1C) + (ENABLE_INT9 & 1), SMBHSTCNT);
  411. status = piix4_transaction(adap);
  412. if (status)
  413. return status;
  414. if ((read_write == I2C_SMBUS_WRITE) || (size == PIIX4_QUICK))
  415. return 0;
  416. switch (size) {
  417. case PIIX4_BYTE:
  418. case PIIX4_BYTE_DATA:
  419. data->byte = inb_p(SMBHSTDAT0);
  420. break;
  421. case PIIX4_WORD_DATA:
  422. data->word = inb_p(SMBHSTDAT0) + (inb_p(SMBHSTDAT1) << 8);
  423. break;
  424. case PIIX4_BLOCK_DATA:
  425. data->block[0] = inb_p(SMBHSTDAT0);
  426. if (data->block[0] == 0 || data->block[0] > I2C_SMBUS_BLOCK_MAX)
  427. return -EPROTO;
  428. i = inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */
  429. for (i = 1; i <= data->block[0]; i++)
  430. data->block[i] = inb_p(SMBBLKDAT);
  431. break;
  432. }
  433. return 0;
  434. }
  435. static u32 piix4_func(struct i2c_adapter *adapter)
  436. {
  437. return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
  438. I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
  439. I2C_FUNC_SMBUS_BLOCK_DATA;
  440. }
  441. static const struct i2c_algorithm smbus_algorithm = {
  442. .smbus_xfer = piix4_access,
  443. .functionality = piix4_func,
  444. };
  445. static DEFINE_PCI_DEVICE_TABLE(piix4_ids) = {
  446. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_3) },
  447. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443MX_3) },
  448. { PCI_DEVICE(PCI_VENDOR_ID_EFAR, PCI_DEVICE_ID_EFAR_SLC90E66_3) },
  449. { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP200_SMBUS) },
  450. { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP300_SMBUS) },
  451. { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP400_SMBUS) },
  452. { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_SBX00_SMBUS) },
  453. { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_HUDSON2_SMBUS) },
  454. { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS,
  455. PCI_DEVICE_ID_SERVERWORKS_OSB4) },
  456. { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS,
  457. PCI_DEVICE_ID_SERVERWORKS_CSB5) },
  458. { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS,
  459. PCI_DEVICE_ID_SERVERWORKS_CSB6) },
  460. { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS,
  461. PCI_DEVICE_ID_SERVERWORKS_HT1000SB) },
  462. { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS,
  463. PCI_DEVICE_ID_SERVERWORKS_HT1100LD) },
  464. { 0, }
  465. };
  466. MODULE_DEVICE_TABLE (pci, piix4_ids);
  467. static struct i2c_adapter *piix4_main_adapter;
  468. static struct i2c_adapter *piix4_aux_adapter;
  469. static int piix4_add_adapter(struct pci_dev *dev, unsigned short smba,
  470. struct i2c_adapter **padap)
  471. {
  472. struct i2c_adapter *adap;
  473. struct i2c_piix4_adapdata *adapdata;
  474. int retval;
  475. adap = kzalloc(sizeof(*adap), GFP_KERNEL);
  476. if (adap == NULL) {
  477. release_region(smba, SMBIOSIZE);
  478. return -ENOMEM;
  479. }
  480. adap->owner = THIS_MODULE;
  481. adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
  482. adap->algo = &smbus_algorithm;
  483. adapdata = kzalloc(sizeof(*adapdata), GFP_KERNEL);
  484. if (adapdata == NULL) {
  485. kfree(adap);
  486. release_region(smba, SMBIOSIZE);
  487. return -ENOMEM;
  488. }
  489. adapdata->smba = smba;
  490. /* set up the sysfs linkage to our parent device */
  491. adap->dev.parent = &dev->dev;
  492. snprintf(adap->name, sizeof(adap->name),
  493. "SMBus PIIX4 adapter at %04x", smba);
  494. i2c_set_adapdata(adap, adapdata);
  495. retval = i2c_add_adapter(adap);
  496. if (retval) {
  497. dev_err(&dev->dev, "Couldn't register adapter!\n");
  498. kfree(adapdata);
  499. kfree(adap);
  500. release_region(smba, SMBIOSIZE);
  501. return retval;
  502. }
  503. *padap = adap;
  504. return 0;
  505. }
  506. static int piix4_probe(struct pci_dev *dev, const struct pci_device_id *id)
  507. {
  508. int retval;
  509. if ((dev->vendor == PCI_VENDOR_ID_ATI &&
  510. dev->device == PCI_DEVICE_ID_ATI_SBX00_SMBUS &&
  511. dev->revision >= 0x40) ||
  512. dev->vendor == PCI_VENDOR_ID_AMD)
  513. /* base address location etc changed in SB800 */
  514. retval = piix4_setup_sb800(dev, id);
  515. else
  516. retval = piix4_setup(dev, id);
  517. /* If no main SMBus found, give up */
  518. if (retval < 0)
  519. return retval;
  520. /* Try to register main SMBus adapter, give up if we can't */
  521. retval = piix4_add_adapter(dev, retval, &piix4_main_adapter);
  522. if (retval < 0)
  523. return retval;
  524. /* Check for auxiliary SMBus on some AMD chipsets */
  525. if (dev->vendor == PCI_VENDOR_ID_ATI &&
  526. dev->device == PCI_DEVICE_ID_ATI_SBX00_SMBUS &&
  527. dev->revision < 0x40) {
  528. retval = piix4_setup_aux(dev, id, 0x58);
  529. if (retval > 0) {
  530. /* Try to add the aux adapter if it exists,
  531. * piix4_add_adapter will clean up if this fails */
  532. piix4_add_adapter(dev, retval, &piix4_aux_adapter);
  533. }
  534. }
  535. return 0;
  536. }
  537. static void piix4_adap_remove(struct i2c_adapter *adap)
  538. {
  539. struct i2c_piix4_adapdata *adapdata = i2c_get_adapdata(adap);
  540. if (adapdata->smba) {
  541. i2c_del_adapter(adap);
  542. release_region(adapdata->smba, SMBIOSIZE);
  543. kfree(adapdata);
  544. kfree(adap);
  545. }
  546. }
  547. static void piix4_remove(struct pci_dev *dev)
  548. {
  549. if (piix4_main_adapter) {
  550. piix4_adap_remove(piix4_main_adapter);
  551. piix4_main_adapter = NULL;
  552. }
  553. if (piix4_aux_adapter) {
  554. piix4_adap_remove(piix4_aux_adapter);
  555. piix4_aux_adapter = NULL;
  556. }
  557. }
  558. static struct pci_driver piix4_driver = {
  559. .name = "piix4_smbus",
  560. .id_table = piix4_ids,
  561. .probe = piix4_probe,
  562. .remove = piix4_remove,
  563. };
  564. module_pci_driver(piix4_driver);
  565. MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl> and "
  566. "Philip Edelbrock <phil@netroedge.com>");
  567. MODULE_DESCRIPTION("PIIX4 SMBus driver");
  568. MODULE_LICENSE("GPL");