i2c-piix4.c 19 KB

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