i2c-i801.c 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313
  1. /*
  2. Copyright (c) 1998 - 2002 Frodo Looijaard <frodol@dds.nl>,
  3. Philip Edelbrock <phil@netroedge.com>, and Mark D. Studebaker
  4. <mdsxyz123@yahoo.com>
  5. Copyright (C) 2007 - 2012 Jean Delvare <khali@linux-fr.org>
  6. Copyright (C) 2010 Intel Corporation,
  7. David Woodhouse <dwmw2@infradead.org>
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2 of the License, or
  11. (at your option) any later version.
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20. /*
  21. Supports the following Intel I/O Controller Hubs (ICH):
  22. I/O Block I2C
  23. region SMBus Block proc. block
  24. Chip name PCI ID size PEC buffer call read
  25. ----------------------------------------------------------------------
  26. 82801AA (ICH) 0x2413 16 no no no no
  27. 82801AB (ICH0) 0x2423 16 no no no no
  28. 82801BA (ICH2) 0x2443 16 no no no no
  29. 82801CA (ICH3) 0x2483 32 soft no no no
  30. 82801DB (ICH4) 0x24c3 32 hard yes no no
  31. 82801E (ICH5) 0x24d3 32 hard yes yes yes
  32. 6300ESB 0x25a4 32 hard yes yes yes
  33. 82801F (ICH6) 0x266a 32 hard yes yes yes
  34. 6310ESB/6320ESB 0x269b 32 hard yes yes yes
  35. 82801G (ICH7) 0x27da 32 hard yes yes yes
  36. 82801H (ICH8) 0x283e 32 hard yes yes yes
  37. 82801I (ICH9) 0x2930 32 hard yes yes yes
  38. EP80579 (Tolapai) 0x5032 32 hard yes yes yes
  39. ICH10 0x3a30 32 hard yes yes yes
  40. ICH10 0x3a60 32 hard yes yes yes
  41. 5/3400 Series (PCH) 0x3b30 32 hard yes yes yes
  42. 6 Series (PCH) 0x1c22 32 hard yes yes yes
  43. Patsburg (PCH) 0x1d22 32 hard yes yes yes
  44. Patsburg (PCH) IDF 0x1d70 32 hard yes yes yes
  45. Patsburg (PCH) IDF 0x1d71 32 hard yes yes yes
  46. Patsburg (PCH) IDF 0x1d72 32 hard yes yes yes
  47. DH89xxCC (PCH) 0x2330 32 hard yes yes yes
  48. Panther Point (PCH) 0x1e22 32 hard yes yes yes
  49. Lynx Point (PCH) 0x8c22 32 hard yes yes yes
  50. Lynx Point-LP (PCH) 0x9c22 32 hard yes yes yes
  51. Avoton (SOC) 0x1f3c 32 hard yes yes yes
  52. Wellsburg (PCH) 0x8d22 32 hard yes yes yes
  53. Wellsburg (PCH) MS 0x8d7d 32 hard yes yes yes
  54. Wellsburg (PCH) MS 0x8d7e 32 hard yes yes yes
  55. Wellsburg (PCH) MS 0x8d7f 32 hard yes yes yes
  56. Features supported by this driver:
  57. Software PEC no
  58. Hardware PEC yes
  59. Block buffer yes
  60. Block process call transaction no
  61. I2C block read transaction yes (doesn't use the block buffer)
  62. Slave mode no
  63. Interrupt processing yes
  64. See the file Documentation/i2c/busses/i2c-i801 for details.
  65. */
  66. #include <linux/interrupt.h>
  67. #include <linux/module.h>
  68. #include <linux/pci.h>
  69. #include <linux/kernel.h>
  70. #include <linux/stddef.h>
  71. #include <linux/delay.h>
  72. #include <linux/ioport.h>
  73. #include <linux/init.h>
  74. #include <linux/i2c.h>
  75. #include <linux/acpi.h>
  76. #include <linux/io.h>
  77. #include <linux/dmi.h>
  78. #include <linux/slab.h>
  79. #include <linux/wait.h>
  80. #include <linux/err.h>
  81. #include <linux/of_i2c.h>
  82. #if (defined CONFIG_I2C_MUX_GPIO || defined CONFIG_I2C_MUX_GPIO_MODULE) && \
  83. defined CONFIG_DMI
  84. #include <linux/gpio.h>
  85. #include <linux/i2c-mux-gpio.h>
  86. #include <linux/platform_device.h>
  87. #endif
  88. /* I801 SMBus address offsets */
  89. #define SMBHSTSTS(p) (0 + (p)->smba)
  90. #define SMBHSTCNT(p) (2 + (p)->smba)
  91. #define SMBHSTCMD(p) (3 + (p)->smba)
  92. #define SMBHSTADD(p) (4 + (p)->smba)
  93. #define SMBHSTDAT0(p) (5 + (p)->smba)
  94. #define SMBHSTDAT1(p) (6 + (p)->smba)
  95. #define SMBBLKDAT(p) (7 + (p)->smba)
  96. #define SMBPEC(p) (8 + (p)->smba) /* ICH3 and later */
  97. #define SMBAUXSTS(p) (12 + (p)->smba) /* ICH4 and later */
  98. #define SMBAUXCTL(p) (13 + (p)->smba) /* ICH4 and later */
  99. /* PCI Address Constants */
  100. #define SMBBAR 4
  101. #define SMBPCISTS 0x006
  102. #define SMBHSTCFG 0x040
  103. /* Host status bits for SMBPCISTS */
  104. #define SMBPCISTS_INTS 0x08
  105. /* Host configuration bits for SMBHSTCFG */
  106. #define SMBHSTCFG_HST_EN 1
  107. #define SMBHSTCFG_SMB_SMI_EN 2
  108. #define SMBHSTCFG_I2C_EN 4
  109. /* Auxiliary control register bits, ICH4+ only */
  110. #define SMBAUXCTL_CRC 1
  111. #define SMBAUXCTL_E32B 2
  112. /* Other settings */
  113. #define MAX_RETRIES 400
  114. /* I801 command constants */
  115. #define I801_QUICK 0x00
  116. #define I801_BYTE 0x04
  117. #define I801_BYTE_DATA 0x08
  118. #define I801_WORD_DATA 0x0C
  119. #define I801_PROC_CALL 0x10 /* unimplemented */
  120. #define I801_BLOCK_DATA 0x14
  121. #define I801_I2C_BLOCK_DATA 0x18 /* ICH5 and later */
  122. /* I801 Host Control register bits */
  123. #define SMBHSTCNT_INTREN 0x01
  124. #define SMBHSTCNT_KILL 0x02
  125. #define SMBHSTCNT_LAST_BYTE 0x20
  126. #define SMBHSTCNT_START 0x40
  127. #define SMBHSTCNT_PEC_EN 0x80 /* ICH3 and later */
  128. /* I801 Hosts Status register bits */
  129. #define SMBHSTSTS_BYTE_DONE 0x80
  130. #define SMBHSTSTS_INUSE_STS 0x40
  131. #define SMBHSTSTS_SMBALERT_STS 0x20
  132. #define SMBHSTSTS_FAILED 0x10
  133. #define SMBHSTSTS_BUS_ERR 0x08
  134. #define SMBHSTSTS_DEV_ERR 0x04
  135. #define SMBHSTSTS_INTR 0x02
  136. #define SMBHSTSTS_HOST_BUSY 0x01
  137. #define STATUS_ERROR_FLAGS (SMBHSTSTS_FAILED | SMBHSTSTS_BUS_ERR | \
  138. SMBHSTSTS_DEV_ERR)
  139. #define STATUS_FLAGS (SMBHSTSTS_BYTE_DONE | SMBHSTSTS_INTR | \
  140. STATUS_ERROR_FLAGS)
  141. /* Older devices have their ID defined in <linux/pci_ids.h> */
  142. #define PCI_DEVICE_ID_INTEL_COUGARPOINT_SMBUS 0x1c22
  143. #define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS 0x1d22
  144. /* Patsburg also has three 'Integrated Device Function' SMBus controllers */
  145. #define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF0 0x1d70
  146. #define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF1 0x1d71
  147. #define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF2 0x1d72
  148. #define PCI_DEVICE_ID_INTEL_PANTHERPOINT_SMBUS 0x1e22
  149. #define PCI_DEVICE_ID_INTEL_AVOTON_SMBUS 0x1f3c
  150. #define PCI_DEVICE_ID_INTEL_DH89XXCC_SMBUS 0x2330
  151. #define PCI_DEVICE_ID_INTEL_5_3400_SERIES_SMBUS 0x3b30
  152. #define PCI_DEVICE_ID_INTEL_LYNXPOINT_SMBUS 0x8c22
  153. #define PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS 0x8d22
  154. #define PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS0 0x8d7d
  155. #define PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS1 0x8d7e
  156. #define PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS2 0x8d7f
  157. #define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_SMBUS 0x9c22
  158. struct i801_mux_config {
  159. char *gpio_chip;
  160. unsigned values[3];
  161. int n_values;
  162. unsigned classes[3];
  163. unsigned gpios[2]; /* Relative to gpio_chip->base */
  164. int n_gpios;
  165. };
  166. struct i801_priv {
  167. struct i2c_adapter adapter;
  168. unsigned long smba;
  169. unsigned char original_hstcfg;
  170. struct pci_dev *pci_dev;
  171. unsigned int features;
  172. /* isr processing */
  173. wait_queue_head_t waitq;
  174. u8 status;
  175. /* Command state used by isr for byte-by-byte block transactions */
  176. u8 cmd;
  177. bool is_read;
  178. int count;
  179. int len;
  180. u8 *data;
  181. #if (defined CONFIG_I2C_MUX_GPIO || defined CONFIG_I2C_MUX_GPIO_MODULE) && \
  182. defined CONFIG_DMI
  183. const struct i801_mux_config *mux_drvdata;
  184. struct platform_device *mux_pdev;
  185. #endif
  186. };
  187. static struct pci_driver i801_driver;
  188. #define FEATURE_SMBUS_PEC (1 << 0)
  189. #define FEATURE_BLOCK_BUFFER (1 << 1)
  190. #define FEATURE_BLOCK_PROC (1 << 2)
  191. #define FEATURE_I2C_BLOCK_READ (1 << 3)
  192. #define FEATURE_IRQ (1 << 4)
  193. /* Not really a feature, but it's convenient to handle it as such */
  194. #define FEATURE_IDF (1 << 15)
  195. static const char *i801_feature_names[] = {
  196. "SMBus PEC",
  197. "Block buffer",
  198. "Block process call",
  199. "I2C block read",
  200. "Interrupt",
  201. };
  202. static unsigned int disable_features;
  203. module_param(disable_features, uint, S_IRUGO | S_IWUSR);
  204. MODULE_PARM_DESC(disable_features, "Disable selected driver features");
  205. /* Make sure the SMBus host is ready to start transmitting.
  206. Return 0 if it is, -EBUSY if it is not. */
  207. static int i801_check_pre(struct i801_priv *priv)
  208. {
  209. int status;
  210. status = inb_p(SMBHSTSTS(priv));
  211. if (status & SMBHSTSTS_HOST_BUSY) {
  212. dev_err(&priv->pci_dev->dev, "SMBus is busy, can't use it!\n");
  213. return -EBUSY;
  214. }
  215. status &= STATUS_FLAGS;
  216. if (status) {
  217. dev_dbg(&priv->pci_dev->dev, "Clearing status flags (%02x)\n",
  218. status);
  219. outb_p(status, SMBHSTSTS(priv));
  220. status = inb_p(SMBHSTSTS(priv)) & STATUS_FLAGS;
  221. if (status) {
  222. dev_err(&priv->pci_dev->dev,
  223. "Failed clearing status flags (%02x)\n",
  224. status);
  225. return -EBUSY;
  226. }
  227. }
  228. return 0;
  229. }
  230. /*
  231. * Convert the status register to an error code, and clear it.
  232. * Note that status only contains the bits we want to clear, not the
  233. * actual register value.
  234. */
  235. static int i801_check_post(struct i801_priv *priv, int status)
  236. {
  237. int result = 0;
  238. /*
  239. * If the SMBus is still busy, we give up
  240. * Note: This timeout condition only happens when using polling
  241. * transactions. For interrupt operation, NAK/timeout is indicated by
  242. * DEV_ERR.
  243. */
  244. if (unlikely(status < 0)) {
  245. dev_err(&priv->pci_dev->dev, "Transaction timeout\n");
  246. /* try to stop the current command */
  247. dev_dbg(&priv->pci_dev->dev, "Terminating the current operation\n");
  248. outb_p(inb_p(SMBHSTCNT(priv)) | SMBHSTCNT_KILL,
  249. SMBHSTCNT(priv));
  250. usleep_range(1000, 2000);
  251. outb_p(inb_p(SMBHSTCNT(priv)) & (~SMBHSTCNT_KILL),
  252. SMBHSTCNT(priv));
  253. /* Check if it worked */
  254. status = inb_p(SMBHSTSTS(priv));
  255. if ((status & SMBHSTSTS_HOST_BUSY) ||
  256. !(status & SMBHSTSTS_FAILED))
  257. dev_err(&priv->pci_dev->dev,
  258. "Failed terminating the transaction\n");
  259. outb_p(STATUS_FLAGS, SMBHSTSTS(priv));
  260. return -ETIMEDOUT;
  261. }
  262. if (status & SMBHSTSTS_FAILED) {
  263. result = -EIO;
  264. dev_err(&priv->pci_dev->dev, "Transaction failed\n");
  265. }
  266. if (status & SMBHSTSTS_DEV_ERR) {
  267. result = -ENXIO;
  268. dev_dbg(&priv->pci_dev->dev, "No response\n");
  269. }
  270. if (status & SMBHSTSTS_BUS_ERR) {
  271. result = -EAGAIN;
  272. dev_dbg(&priv->pci_dev->dev, "Lost arbitration\n");
  273. }
  274. /* Clear status flags except BYTE_DONE, to be cleared by caller */
  275. outb_p(status, SMBHSTSTS(priv));
  276. return result;
  277. }
  278. /* Wait for BUSY being cleared and either INTR or an error flag being set */
  279. static int i801_wait_intr(struct i801_priv *priv)
  280. {
  281. int timeout = 0;
  282. int status;
  283. /* We will always wait for a fraction of a second! */
  284. do {
  285. usleep_range(250, 500);
  286. status = inb_p(SMBHSTSTS(priv));
  287. } while (((status & SMBHSTSTS_HOST_BUSY) ||
  288. !(status & (STATUS_ERROR_FLAGS | SMBHSTSTS_INTR))) &&
  289. (timeout++ < MAX_RETRIES));
  290. if (timeout > MAX_RETRIES) {
  291. dev_dbg(&priv->pci_dev->dev, "INTR Timeout!\n");
  292. return -ETIMEDOUT;
  293. }
  294. return status & (STATUS_ERROR_FLAGS | SMBHSTSTS_INTR);
  295. }
  296. /* Wait for either BYTE_DONE or an error flag being set */
  297. static int i801_wait_byte_done(struct i801_priv *priv)
  298. {
  299. int timeout = 0;
  300. int status;
  301. /* We will always wait for a fraction of a second! */
  302. do {
  303. usleep_range(250, 500);
  304. status = inb_p(SMBHSTSTS(priv));
  305. } while (!(status & (STATUS_ERROR_FLAGS | SMBHSTSTS_BYTE_DONE)) &&
  306. (timeout++ < MAX_RETRIES));
  307. if (timeout > MAX_RETRIES) {
  308. dev_dbg(&priv->pci_dev->dev, "BYTE_DONE Timeout!\n");
  309. return -ETIMEDOUT;
  310. }
  311. return status & STATUS_ERROR_FLAGS;
  312. }
  313. static int i801_transaction(struct i801_priv *priv, int xact)
  314. {
  315. int status;
  316. int result;
  317. result = i801_check_pre(priv);
  318. if (result < 0)
  319. return result;
  320. if (priv->features & FEATURE_IRQ) {
  321. outb_p(xact | SMBHSTCNT_INTREN | SMBHSTCNT_START,
  322. SMBHSTCNT(priv));
  323. wait_event(priv->waitq, (status = priv->status));
  324. priv->status = 0;
  325. return i801_check_post(priv, status);
  326. }
  327. /* the current contents of SMBHSTCNT can be overwritten, since PEC,
  328. * SMBSCMD are passed in xact */
  329. outb_p(xact | SMBHSTCNT_START, SMBHSTCNT(priv));
  330. status = i801_wait_intr(priv);
  331. return i801_check_post(priv, status);
  332. }
  333. static int i801_block_transaction_by_block(struct i801_priv *priv,
  334. union i2c_smbus_data *data,
  335. char read_write, int hwpec)
  336. {
  337. int i, len;
  338. int status;
  339. inb_p(SMBHSTCNT(priv)); /* reset the data buffer index */
  340. /* Use 32-byte buffer to process this transaction */
  341. if (read_write == I2C_SMBUS_WRITE) {
  342. len = data->block[0];
  343. outb_p(len, SMBHSTDAT0(priv));
  344. for (i = 0; i < len; i++)
  345. outb_p(data->block[i+1], SMBBLKDAT(priv));
  346. }
  347. status = i801_transaction(priv, I801_BLOCK_DATA |
  348. (hwpec ? SMBHSTCNT_PEC_EN : 0));
  349. if (status)
  350. return status;
  351. if (read_write == I2C_SMBUS_READ) {
  352. len = inb_p(SMBHSTDAT0(priv));
  353. if (len < 1 || len > I2C_SMBUS_BLOCK_MAX)
  354. return -EPROTO;
  355. data->block[0] = len;
  356. for (i = 0; i < len; i++)
  357. data->block[i + 1] = inb_p(SMBBLKDAT(priv));
  358. }
  359. return 0;
  360. }
  361. static void i801_isr_byte_done(struct i801_priv *priv)
  362. {
  363. if (priv->is_read) {
  364. /* For SMBus block reads, length is received with first byte */
  365. if (((priv->cmd & 0x1c) == I801_BLOCK_DATA) &&
  366. (priv->count == 0)) {
  367. priv->len = inb_p(SMBHSTDAT0(priv));
  368. if (priv->len < 1 || priv->len > I2C_SMBUS_BLOCK_MAX) {
  369. dev_err(&priv->pci_dev->dev,
  370. "Illegal SMBus block read size %d\n",
  371. priv->len);
  372. /* FIXME: Recover */
  373. priv->len = I2C_SMBUS_BLOCK_MAX;
  374. } else {
  375. dev_dbg(&priv->pci_dev->dev,
  376. "SMBus block read size is %d\n",
  377. priv->len);
  378. }
  379. priv->data[-1] = priv->len;
  380. }
  381. /* Read next byte */
  382. if (priv->count < priv->len)
  383. priv->data[priv->count++] = inb(SMBBLKDAT(priv));
  384. else
  385. dev_dbg(&priv->pci_dev->dev,
  386. "Discarding extra byte on block read\n");
  387. /* Set LAST_BYTE for last byte of read transaction */
  388. if (priv->count == priv->len - 1)
  389. outb_p(priv->cmd | SMBHSTCNT_LAST_BYTE,
  390. SMBHSTCNT(priv));
  391. } else if (priv->count < priv->len - 1) {
  392. /* Write next byte, except for IRQ after last byte */
  393. outb_p(priv->data[++priv->count], SMBBLKDAT(priv));
  394. }
  395. /* Clear BYTE_DONE to continue with next byte */
  396. outb_p(SMBHSTSTS_BYTE_DONE, SMBHSTSTS(priv));
  397. }
  398. /*
  399. * There are two kinds of interrupts:
  400. *
  401. * 1) i801 signals transaction completion with one of these interrupts:
  402. * INTR - Success
  403. * DEV_ERR - Invalid command, NAK or communication timeout
  404. * BUS_ERR - SMI# transaction collision
  405. * FAILED - transaction was canceled due to a KILL request
  406. * When any of these occur, update ->status and wake up the waitq.
  407. * ->status must be cleared before kicking off the next transaction.
  408. *
  409. * 2) For byte-by-byte (I2C read/write) transactions, one BYTE_DONE interrupt
  410. * occurs for each byte of a byte-by-byte to prepare the next byte.
  411. */
  412. static irqreturn_t i801_isr(int irq, void *dev_id)
  413. {
  414. struct i801_priv *priv = dev_id;
  415. u16 pcists;
  416. u8 status;
  417. /* Confirm this is our interrupt */
  418. pci_read_config_word(priv->pci_dev, SMBPCISTS, &pcists);
  419. if (!(pcists & SMBPCISTS_INTS))
  420. return IRQ_NONE;
  421. status = inb_p(SMBHSTSTS(priv));
  422. if (status != 0x42)
  423. dev_dbg(&priv->pci_dev->dev, "irq: status = %02x\n", status);
  424. if (status & SMBHSTSTS_BYTE_DONE)
  425. i801_isr_byte_done(priv);
  426. /*
  427. * Clear irq sources and report transaction result.
  428. * ->status must be cleared before the next transaction is started.
  429. */
  430. status &= SMBHSTSTS_INTR | STATUS_ERROR_FLAGS;
  431. if (status) {
  432. outb_p(status, SMBHSTSTS(priv));
  433. priv->status |= status;
  434. wake_up(&priv->waitq);
  435. }
  436. return IRQ_HANDLED;
  437. }
  438. /*
  439. * For "byte-by-byte" block transactions:
  440. * I2C write uses cmd=I801_BLOCK_DATA, I2C_EN=1
  441. * I2C read uses cmd=I801_I2C_BLOCK_DATA
  442. */
  443. static int i801_block_transaction_byte_by_byte(struct i801_priv *priv,
  444. union i2c_smbus_data *data,
  445. char read_write, int command,
  446. int hwpec)
  447. {
  448. int i, len;
  449. int smbcmd;
  450. int status;
  451. int result;
  452. result = i801_check_pre(priv);
  453. if (result < 0)
  454. return result;
  455. len = data->block[0];
  456. if (read_write == I2C_SMBUS_WRITE) {
  457. outb_p(len, SMBHSTDAT0(priv));
  458. outb_p(data->block[1], SMBBLKDAT(priv));
  459. }
  460. if (command == I2C_SMBUS_I2C_BLOCK_DATA &&
  461. read_write == I2C_SMBUS_READ)
  462. smbcmd = I801_I2C_BLOCK_DATA;
  463. else
  464. smbcmd = I801_BLOCK_DATA;
  465. if (priv->features & FEATURE_IRQ) {
  466. priv->is_read = (read_write == I2C_SMBUS_READ);
  467. if (len == 1 && priv->is_read)
  468. smbcmd |= SMBHSTCNT_LAST_BYTE;
  469. priv->cmd = smbcmd | SMBHSTCNT_INTREN;
  470. priv->len = len;
  471. priv->count = 0;
  472. priv->data = &data->block[1];
  473. outb_p(priv->cmd | SMBHSTCNT_START, SMBHSTCNT(priv));
  474. wait_event(priv->waitq, (status = priv->status));
  475. priv->status = 0;
  476. return i801_check_post(priv, status);
  477. }
  478. for (i = 1; i <= len; i++) {
  479. if (i == len && read_write == I2C_SMBUS_READ)
  480. smbcmd |= SMBHSTCNT_LAST_BYTE;
  481. outb_p(smbcmd, SMBHSTCNT(priv));
  482. if (i == 1)
  483. outb_p(inb(SMBHSTCNT(priv)) | SMBHSTCNT_START,
  484. SMBHSTCNT(priv));
  485. status = i801_wait_byte_done(priv);
  486. if (status)
  487. goto exit;
  488. if (i == 1 && read_write == I2C_SMBUS_READ
  489. && command != I2C_SMBUS_I2C_BLOCK_DATA) {
  490. len = inb_p(SMBHSTDAT0(priv));
  491. if (len < 1 || len > I2C_SMBUS_BLOCK_MAX) {
  492. dev_err(&priv->pci_dev->dev,
  493. "Illegal SMBus block read size %d\n",
  494. len);
  495. /* Recover */
  496. while (inb_p(SMBHSTSTS(priv)) &
  497. SMBHSTSTS_HOST_BUSY)
  498. outb_p(SMBHSTSTS_BYTE_DONE,
  499. SMBHSTSTS(priv));
  500. outb_p(SMBHSTSTS_INTR, SMBHSTSTS(priv));
  501. return -EPROTO;
  502. }
  503. data->block[0] = len;
  504. }
  505. /* Retrieve/store value in SMBBLKDAT */
  506. if (read_write == I2C_SMBUS_READ)
  507. data->block[i] = inb_p(SMBBLKDAT(priv));
  508. if (read_write == I2C_SMBUS_WRITE && i+1 <= len)
  509. outb_p(data->block[i+1], SMBBLKDAT(priv));
  510. /* signals SMBBLKDAT ready */
  511. outb_p(SMBHSTSTS_BYTE_DONE, SMBHSTSTS(priv));
  512. }
  513. status = i801_wait_intr(priv);
  514. exit:
  515. return i801_check_post(priv, status);
  516. }
  517. static int i801_set_block_buffer_mode(struct i801_priv *priv)
  518. {
  519. outb_p(inb_p(SMBAUXCTL(priv)) | SMBAUXCTL_E32B, SMBAUXCTL(priv));
  520. if ((inb_p(SMBAUXCTL(priv)) & SMBAUXCTL_E32B) == 0)
  521. return -EIO;
  522. return 0;
  523. }
  524. /* Block transaction function */
  525. static int i801_block_transaction(struct i801_priv *priv,
  526. union i2c_smbus_data *data, char read_write,
  527. int command, int hwpec)
  528. {
  529. int result = 0;
  530. unsigned char hostc;
  531. if (command == I2C_SMBUS_I2C_BLOCK_DATA) {
  532. if (read_write == I2C_SMBUS_WRITE) {
  533. /* set I2C_EN bit in configuration register */
  534. pci_read_config_byte(priv->pci_dev, SMBHSTCFG, &hostc);
  535. pci_write_config_byte(priv->pci_dev, SMBHSTCFG,
  536. hostc | SMBHSTCFG_I2C_EN);
  537. } else if (!(priv->features & FEATURE_I2C_BLOCK_READ)) {
  538. dev_err(&priv->pci_dev->dev,
  539. "I2C block read is unsupported!\n");
  540. return -EOPNOTSUPP;
  541. }
  542. }
  543. if (read_write == I2C_SMBUS_WRITE
  544. || command == I2C_SMBUS_I2C_BLOCK_DATA) {
  545. if (data->block[0] < 1)
  546. data->block[0] = 1;
  547. if (data->block[0] > I2C_SMBUS_BLOCK_MAX)
  548. data->block[0] = I2C_SMBUS_BLOCK_MAX;
  549. } else {
  550. data->block[0] = 32; /* max for SMBus block reads */
  551. }
  552. /* Experience has shown that the block buffer can only be used for
  553. SMBus (not I2C) block transactions, even though the datasheet
  554. doesn't mention this limitation. */
  555. if ((priv->features & FEATURE_BLOCK_BUFFER)
  556. && command != I2C_SMBUS_I2C_BLOCK_DATA
  557. && i801_set_block_buffer_mode(priv) == 0)
  558. result = i801_block_transaction_by_block(priv, data,
  559. read_write, hwpec);
  560. else
  561. result = i801_block_transaction_byte_by_byte(priv, data,
  562. read_write,
  563. command, hwpec);
  564. if (command == I2C_SMBUS_I2C_BLOCK_DATA
  565. && read_write == I2C_SMBUS_WRITE) {
  566. /* restore saved configuration register value */
  567. pci_write_config_byte(priv->pci_dev, SMBHSTCFG, hostc);
  568. }
  569. return result;
  570. }
  571. /* Return negative errno on error. */
  572. static s32 i801_access(struct i2c_adapter *adap, u16 addr,
  573. unsigned short flags, char read_write, u8 command,
  574. int size, union i2c_smbus_data *data)
  575. {
  576. int hwpec;
  577. int block = 0;
  578. int ret, xact = 0;
  579. struct i801_priv *priv = i2c_get_adapdata(adap);
  580. hwpec = (priv->features & FEATURE_SMBUS_PEC) && (flags & I2C_CLIENT_PEC)
  581. && size != I2C_SMBUS_QUICK
  582. && size != I2C_SMBUS_I2C_BLOCK_DATA;
  583. switch (size) {
  584. case I2C_SMBUS_QUICK:
  585. outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
  586. SMBHSTADD(priv));
  587. xact = I801_QUICK;
  588. break;
  589. case I2C_SMBUS_BYTE:
  590. outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
  591. SMBHSTADD(priv));
  592. if (read_write == I2C_SMBUS_WRITE)
  593. outb_p(command, SMBHSTCMD(priv));
  594. xact = I801_BYTE;
  595. break;
  596. case I2C_SMBUS_BYTE_DATA:
  597. outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
  598. SMBHSTADD(priv));
  599. outb_p(command, SMBHSTCMD(priv));
  600. if (read_write == I2C_SMBUS_WRITE)
  601. outb_p(data->byte, SMBHSTDAT0(priv));
  602. xact = I801_BYTE_DATA;
  603. break;
  604. case I2C_SMBUS_WORD_DATA:
  605. outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
  606. SMBHSTADD(priv));
  607. outb_p(command, SMBHSTCMD(priv));
  608. if (read_write == I2C_SMBUS_WRITE) {
  609. outb_p(data->word & 0xff, SMBHSTDAT0(priv));
  610. outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1(priv));
  611. }
  612. xact = I801_WORD_DATA;
  613. break;
  614. case I2C_SMBUS_BLOCK_DATA:
  615. outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
  616. SMBHSTADD(priv));
  617. outb_p(command, SMBHSTCMD(priv));
  618. block = 1;
  619. break;
  620. case I2C_SMBUS_I2C_BLOCK_DATA:
  621. /* NB: page 240 of ICH5 datasheet shows that the R/#W
  622. * bit should be cleared here, even when reading */
  623. outb_p((addr & 0x7f) << 1, SMBHSTADD(priv));
  624. if (read_write == I2C_SMBUS_READ) {
  625. /* NB: page 240 of ICH5 datasheet also shows
  626. * that DATA1 is the cmd field when reading */
  627. outb_p(command, SMBHSTDAT1(priv));
  628. } else
  629. outb_p(command, SMBHSTCMD(priv));
  630. block = 1;
  631. break;
  632. default:
  633. dev_err(&priv->pci_dev->dev, "Unsupported transaction %d\n",
  634. size);
  635. return -EOPNOTSUPP;
  636. }
  637. if (hwpec) /* enable/disable hardware PEC */
  638. outb_p(inb_p(SMBAUXCTL(priv)) | SMBAUXCTL_CRC, SMBAUXCTL(priv));
  639. else
  640. outb_p(inb_p(SMBAUXCTL(priv)) & (~SMBAUXCTL_CRC),
  641. SMBAUXCTL(priv));
  642. if (block)
  643. ret = i801_block_transaction(priv, data, read_write, size,
  644. hwpec);
  645. else
  646. ret = i801_transaction(priv, xact);
  647. /* Some BIOSes don't like it when PEC is enabled at reboot or resume
  648. time, so we forcibly disable it after every transaction. Turn off
  649. E32B for the same reason. */
  650. if (hwpec || block)
  651. outb_p(inb_p(SMBAUXCTL(priv)) &
  652. ~(SMBAUXCTL_CRC | SMBAUXCTL_E32B), SMBAUXCTL(priv));
  653. if (block)
  654. return ret;
  655. if (ret)
  656. return ret;
  657. if ((read_write == I2C_SMBUS_WRITE) || (xact == I801_QUICK))
  658. return 0;
  659. switch (xact & 0x7f) {
  660. case I801_BYTE: /* Result put in SMBHSTDAT0 */
  661. case I801_BYTE_DATA:
  662. data->byte = inb_p(SMBHSTDAT0(priv));
  663. break;
  664. case I801_WORD_DATA:
  665. data->word = inb_p(SMBHSTDAT0(priv)) +
  666. (inb_p(SMBHSTDAT1(priv)) << 8);
  667. break;
  668. }
  669. return 0;
  670. }
  671. static u32 i801_func(struct i2c_adapter *adapter)
  672. {
  673. struct i801_priv *priv = i2c_get_adapdata(adapter);
  674. return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
  675. I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
  676. I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_WRITE_I2C_BLOCK |
  677. ((priv->features & FEATURE_SMBUS_PEC) ? I2C_FUNC_SMBUS_PEC : 0) |
  678. ((priv->features & FEATURE_I2C_BLOCK_READ) ?
  679. I2C_FUNC_SMBUS_READ_I2C_BLOCK : 0);
  680. }
  681. static const struct i2c_algorithm smbus_algorithm = {
  682. .smbus_xfer = i801_access,
  683. .functionality = i801_func,
  684. };
  685. static DEFINE_PCI_DEVICE_TABLE(i801_ids) = {
  686. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_3) },
  687. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_3) },
  688. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_2) },
  689. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_3) },
  690. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_3) },
  691. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_3) },
  692. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB_4) },
  693. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_16) },
  694. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_17) },
  695. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB2_17) },
  696. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8_5) },
  697. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH9_6) },
  698. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_EP80579_1) },
  699. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH10_4) },
  700. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH10_5) },
  701. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5_3400_SERIES_SMBUS) },
  702. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_COUGARPOINT_SMBUS) },
  703. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS) },
  704. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF0) },
  705. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF1) },
  706. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF2) },
  707. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_DH89XXCC_SMBUS) },
  708. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PANTHERPOINT_SMBUS) },
  709. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LYNXPOINT_SMBUS) },
  710. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_SMBUS) },
  711. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_AVOTON_SMBUS) },
  712. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS) },
  713. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS0) },
  714. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS1) },
  715. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS2) },
  716. { 0, }
  717. };
  718. MODULE_DEVICE_TABLE(pci, i801_ids);
  719. #if defined CONFIG_X86 && defined CONFIG_DMI
  720. static unsigned char apanel_addr;
  721. /* Scan the system ROM for the signature "FJKEYINF" */
  722. static __init const void __iomem *bios_signature(const void __iomem *bios)
  723. {
  724. ssize_t offset;
  725. const unsigned char signature[] = "FJKEYINF";
  726. for (offset = 0; offset < 0x10000; offset += 0x10) {
  727. if (check_signature(bios + offset, signature,
  728. sizeof(signature)-1))
  729. return bios + offset;
  730. }
  731. return NULL;
  732. }
  733. static void __init input_apanel_init(void)
  734. {
  735. void __iomem *bios;
  736. const void __iomem *p;
  737. bios = ioremap(0xF0000, 0x10000); /* Can't fail */
  738. p = bios_signature(bios);
  739. if (p) {
  740. /* just use the first address */
  741. apanel_addr = readb(p + 8 + 3) >> 1;
  742. }
  743. iounmap(bios);
  744. }
  745. struct dmi_onboard_device_info {
  746. const char *name;
  747. u8 type;
  748. unsigned short i2c_addr;
  749. const char *i2c_type;
  750. };
  751. static const struct dmi_onboard_device_info dmi_devices[] = {
  752. { "Syleus", DMI_DEV_TYPE_OTHER, 0x73, "fscsyl" },
  753. { "Hermes", DMI_DEV_TYPE_OTHER, 0x73, "fscher" },
  754. { "Hades", DMI_DEV_TYPE_OTHER, 0x73, "fschds" },
  755. };
  756. static void dmi_check_onboard_device(u8 type, const char *name,
  757. struct i2c_adapter *adap)
  758. {
  759. int i;
  760. struct i2c_board_info info;
  761. for (i = 0; i < ARRAY_SIZE(dmi_devices); i++) {
  762. /* & ~0x80, ignore enabled/disabled bit */
  763. if ((type & ~0x80) != dmi_devices[i].type)
  764. continue;
  765. if (strcasecmp(name, dmi_devices[i].name))
  766. continue;
  767. memset(&info, 0, sizeof(struct i2c_board_info));
  768. info.addr = dmi_devices[i].i2c_addr;
  769. strlcpy(info.type, dmi_devices[i].i2c_type, I2C_NAME_SIZE);
  770. i2c_new_device(adap, &info);
  771. break;
  772. }
  773. }
  774. /* We use our own function to check for onboard devices instead of
  775. dmi_find_device() as some buggy BIOS's have the devices we are interested
  776. in marked as disabled */
  777. static void dmi_check_onboard_devices(const struct dmi_header *dm, void *adap)
  778. {
  779. int i, count;
  780. if (dm->type != 10)
  781. return;
  782. count = (dm->length - sizeof(struct dmi_header)) / 2;
  783. for (i = 0; i < count; i++) {
  784. const u8 *d = (char *)(dm + 1) + (i * 2);
  785. const char *name = ((char *) dm) + dm->length;
  786. u8 type = d[0];
  787. u8 s = d[1];
  788. if (!s)
  789. continue;
  790. s--;
  791. while (s > 0 && name[0]) {
  792. name += strlen(name) + 1;
  793. s--;
  794. }
  795. if (name[0] == 0) /* Bogus string reference */
  796. continue;
  797. dmi_check_onboard_device(type, name, adap);
  798. }
  799. }
  800. /* Register optional slaves */
  801. static void i801_probe_optional_slaves(struct i801_priv *priv)
  802. {
  803. /* Only register slaves on main SMBus channel */
  804. if (priv->features & FEATURE_IDF)
  805. return;
  806. if (apanel_addr) {
  807. struct i2c_board_info info;
  808. memset(&info, 0, sizeof(struct i2c_board_info));
  809. info.addr = apanel_addr;
  810. strlcpy(info.type, "fujitsu_apanel", I2C_NAME_SIZE);
  811. i2c_new_device(&priv->adapter, &info);
  812. }
  813. if (dmi_name_in_vendors("FUJITSU"))
  814. dmi_walk(dmi_check_onboard_devices, &priv->adapter);
  815. }
  816. #else
  817. static void __init input_apanel_init(void) {}
  818. static void i801_probe_optional_slaves(struct i801_priv *priv) {}
  819. #endif /* CONFIG_X86 && CONFIG_DMI */
  820. #if (defined CONFIG_I2C_MUX_GPIO || defined CONFIG_I2C_MUX_GPIO_MODULE) && \
  821. defined CONFIG_DMI
  822. static struct i801_mux_config i801_mux_config_asus_z8_d12 = {
  823. .gpio_chip = "gpio_ich",
  824. .values = { 0x02, 0x03 },
  825. .n_values = 2,
  826. .classes = { I2C_CLASS_SPD, I2C_CLASS_SPD },
  827. .gpios = { 52, 53 },
  828. .n_gpios = 2,
  829. };
  830. static struct i801_mux_config i801_mux_config_asus_z8_d18 = {
  831. .gpio_chip = "gpio_ich",
  832. .values = { 0x02, 0x03, 0x01 },
  833. .n_values = 3,
  834. .classes = { I2C_CLASS_SPD, I2C_CLASS_SPD, I2C_CLASS_SPD },
  835. .gpios = { 52, 53 },
  836. .n_gpios = 2,
  837. };
  838. static const struct dmi_system_id mux_dmi_table[] = {
  839. {
  840. .matches = {
  841. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
  842. DMI_MATCH(DMI_BOARD_NAME, "Z8NA-D6(C)"),
  843. },
  844. .driver_data = &i801_mux_config_asus_z8_d12,
  845. },
  846. {
  847. .matches = {
  848. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
  849. DMI_MATCH(DMI_BOARD_NAME, "Z8P(N)E-D12(X)"),
  850. },
  851. .driver_data = &i801_mux_config_asus_z8_d12,
  852. },
  853. {
  854. .matches = {
  855. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
  856. DMI_MATCH(DMI_BOARD_NAME, "Z8NH-D12"),
  857. },
  858. .driver_data = &i801_mux_config_asus_z8_d12,
  859. },
  860. {
  861. .matches = {
  862. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
  863. DMI_MATCH(DMI_BOARD_NAME, "Z8PH-D12/IFB"),
  864. },
  865. .driver_data = &i801_mux_config_asus_z8_d12,
  866. },
  867. {
  868. .matches = {
  869. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
  870. DMI_MATCH(DMI_BOARD_NAME, "Z8NR-D12"),
  871. },
  872. .driver_data = &i801_mux_config_asus_z8_d12,
  873. },
  874. {
  875. .matches = {
  876. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
  877. DMI_MATCH(DMI_BOARD_NAME, "Z8P(N)H-D12"),
  878. },
  879. .driver_data = &i801_mux_config_asus_z8_d12,
  880. },
  881. {
  882. .matches = {
  883. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
  884. DMI_MATCH(DMI_BOARD_NAME, "Z8PG-D18"),
  885. },
  886. .driver_data = &i801_mux_config_asus_z8_d18,
  887. },
  888. {
  889. .matches = {
  890. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
  891. DMI_MATCH(DMI_BOARD_NAME, "Z8PE-D18"),
  892. },
  893. .driver_data = &i801_mux_config_asus_z8_d18,
  894. },
  895. {
  896. .matches = {
  897. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
  898. DMI_MATCH(DMI_BOARD_NAME, "Z8PS-D12"),
  899. },
  900. .driver_data = &i801_mux_config_asus_z8_d12,
  901. },
  902. { }
  903. };
  904. /* Setup multiplexing if needed */
  905. static int i801_add_mux(struct i801_priv *priv)
  906. {
  907. struct device *dev = &priv->adapter.dev;
  908. const struct i801_mux_config *mux_config;
  909. struct i2c_mux_gpio_platform_data gpio_data;
  910. int err;
  911. if (!priv->mux_drvdata)
  912. return 0;
  913. mux_config = priv->mux_drvdata;
  914. /* Prepare the platform data */
  915. memset(&gpio_data, 0, sizeof(struct i2c_mux_gpio_platform_data));
  916. gpio_data.parent = priv->adapter.nr;
  917. gpio_data.values = mux_config->values;
  918. gpio_data.n_values = mux_config->n_values;
  919. gpio_data.classes = mux_config->classes;
  920. gpio_data.gpio_chip = mux_config->gpio_chip;
  921. gpio_data.gpios = mux_config->gpios;
  922. gpio_data.n_gpios = mux_config->n_gpios;
  923. gpio_data.idle = I2C_MUX_GPIO_NO_IDLE;
  924. /* Register the mux device */
  925. priv->mux_pdev = platform_device_register_data(dev, "i2c-mux-gpio",
  926. PLATFORM_DEVID_AUTO, &gpio_data,
  927. sizeof(struct i2c_mux_gpio_platform_data));
  928. if (IS_ERR(priv->mux_pdev)) {
  929. err = PTR_ERR(priv->mux_pdev);
  930. priv->mux_pdev = NULL;
  931. dev_err(dev, "Failed to register i2c-mux-gpio device\n");
  932. return err;
  933. }
  934. return 0;
  935. }
  936. static void i801_del_mux(struct i801_priv *priv)
  937. {
  938. if (priv->mux_pdev)
  939. platform_device_unregister(priv->mux_pdev);
  940. }
  941. static unsigned int i801_get_adapter_class(struct i801_priv *priv)
  942. {
  943. const struct dmi_system_id *id;
  944. const struct i801_mux_config *mux_config;
  945. unsigned int class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
  946. int i;
  947. id = dmi_first_match(mux_dmi_table);
  948. if (id) {
  949. /* Remove branch classes from trunk */
  950. mux_config = id->driver_data;
  951. for (i = 0; i < mux_config->n_values; i++)
  952. class &= ~mux_config->classes[i];
  953. /* Remember for later */
  954. priv->mux_drvdata = mux_config;
  955. }
  956. return class;
  957. }
  958. #else
  959. static inline int i801_add_mux(struct i801_priv *priv) { return 0; }
  960. static inline void i801_del_mux(struct i801_priv *priv) { }
  961. static inline unsigned int i801_get_adapter_class(struct i801_priv *priv)
  962. {
  963. return I2C_CLASS_HWMON | I2C_CLASS_SPD;
  964. }
  965. #endif
  966. static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id)
  967. {
  968. unsigned char temp;
  969. int err, i;
  970. struct i801_priv *priv;
  971. priv = kzalloc(sizeof(*priv), GFP_KERNEL);
  972. if (!priv)
  973. return -ENOMEM;
  974. i2c_set_adapdata(&priv->adapter, priv);
  975. priv->adapter.owner = THIS_MODULE;
  976. priv->adapter.class = i801_get_adapter_class(priv);
  977. priv->adapter.algo = &smbus_algorithm;
  978. priv->pci_dev = dev;
  979. switch (dev->device) {
  980. case PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF0:
  981. case PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF1:
  982. case PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF2:
  983. case PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS0:
  984. case PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS1:
  985. case PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS2:
  986. priv->features |= FEATURE_IDF;
  987. /* fall through */
  988. default:
  989. priv->features |= FEATURE_I2C_BLOCK_READ;
  990. priv->features |= FEATURE_IRQ;
  991. /* fall through */
  992. case PCI_DEVICE_ID_INTEL_82801DB_3:
  993. priv->features |= FEATURE_SMBUS_PEC;
  994. priv->features |= FEATURE_BLOCK_BUFFER;
  995. /* fall through */
  996. case PCI_DEVICE_ID_INTEL_82801CA_3:
  997. case PCI_DEVICE_ID_INTEL_82801BA_2:
  998. case PCI_DEVICE_ID_INTEL_82801AB_3:
  999. case PCI_DEVICE_ID_INTEL_82801AA_3:
  1000. break;
  1001. }
  1002. /* Disable features on user request */
  1003. for (i = 0; i < ARRAY_SIZE(i801_feature_names); i++) {
  1004. if (priv->features & disable_features & (1 << i))
  1005. dev_notice(&dev->dev, "%s disabled by user\n",
  1006. i801_feature_names[i]);
  1007. }
  1008. priv->features &= ~disable_features;
  1009. err = pci_enable_device(dev);
  1010. if (err) {
  1011. dev_err(&dev->dev, "Failed to enable SMBus PCI device (%d)\n",
  1012. err);
  1013. goto exit;
  1014. }
  1015. /* Determine the address of the SMBus area */
  1016. priv->smba = pci_resource_start(dev, SMBBAR);
  1017. if (!priv->smba) {
  1018. dev_err(&dev->dev, "SMBus base address uninitialized, "
  1019. "upgrade BIOS\n");
  1020. err = -ENODEV;
  1021. goto exit;
  1022. }
  1023. err = acpi_check_resource_conflict(&dev->resource[SMBBAR]);
  1024. if (err) {
  1025. err = -ENODEV;
  1026. goto exit;
  1027. }
  1028. err = pci_request_region(dev, SMBBAR, i801_driver.name);
  1029. if (err) {
  1030. dev_err(&dev->dev, "Failed to request SMBus region "
  1031. "0x%lx-0x%Lx\n", priv->smba,
  1032. (unsigned long long)pci_resource_end(dev, SMBBAR));
  1033. goto exit;
  1034. }
  1035. pci_read_config_byte(priv->pci_dev, SMBHSTCFG, &temp);
  1036. priv->original_hstcfg = temp;
  1037. temp &= ~SMBHSTCFG_I2C_EN; /* SMBus timing */
  1038. if (!(temp & SMBHSTCFG_HST_EN)) {
  1039. dev_info(&dev->dev, "Enabling SMBus device\n");
  1040. temp |= SMBHSTCFG_HST_EN;
  1041. }
  1042. pci_write_config_byte(priv->pci_dev, SMBHSTCFG, temp);
  1043. if (temp & SMBHSTCFG_SMB_SMI_EN) {
  1044. dev_dbg(&dev->dev, "SMBus using interrupt SMI#\n");
  1045. /* Disable SMBus interrupt feature if SMBus using SMI# */
  1046. priv->features &= ~FEATURE_IRQ;
  1047. }
  1048. /* Clear special mode bits */
  1049. if (priv->features & (FEATURE_SMBUS_PEC | FEATURE_BLOCK_BUFFER))
  1050. outb_p(inb_p(SMBAUXCTL(priv)) &
  1051. ~(SMBAUXCTL_CRC | SMBAUXCTL_E32B), SMBAUXCTL(priv));
  1052. if (priv->features & FEATURE_IRQ) {
  1053. init_waitqueue_head(&priv->waitq);
  1054. err = request_irq(dev->irq, i801_isr, IRQF_SHARED,
  1055. i801_driver.name, priv);
  1056. if (err) {
  1057. dev_err(&dev->dev, "Failed to allocate irq %d: %d\n",
  1058. dev->irq, err);
  1059. goto exit_release;
  1060. }
  1061. dev_info(&dev->dev, "SMBus using PCI Interrupt\n");
  1062. }
  1063. /* set up the sysfs linkage to our parent device */
  1064. priv->adapter.dev.parent = &dev->dev;
  1065. /* Retry up to 3 times on lost arbitration */
  1066. priv->adapter.retries = 3;
  1067. snprintf(priv->adapter.name, sizeof(priv->adapter.name),
  1068. "SMBus I801 adapter at %04lx", priv->smba);
  1069. err = i2c_add_adapter(&priv->adapter);
  1070. if (err) {
  1071. dev_err(&dev->dev, "Failed to add SMBus adapter\n");
  1072. goto exit_free_irq;
  1073. }
  1074. of_i2c_register_devices(&priv->adapter);
  1075. i801_probe_optional_slaves(priv);
  1076. /* We ignore errors - multiplexing is optional */
  1077. i801_add_mux(priv);
  1078. pci_set_drvdata(dev, priv);
  1079. return 0;
  1080. exit_free_irq:
  1081. if (priv->features & FEATURE_IRQ)
  1082. free_irq(dev->irq, priv);
  1083. exit_release:
  1084. pci_release_region(dev, SMBBAR);
  1085. exit:
  1086. kfree(priv);
  1087. return err;
  1088. }
  1089. static void i801_remove(struct pci_dev *dev)
  1090. {
  1091. struct i801_priv *priv = pci_get_drvdata(dev);
  1092. i801_del_mux(priv);
  1093. i2c_del_adapter(&priv->adapter);
  1094. pci_write_config_byte(dev, SMBHSTCFG, priv->original_hstcfg);
  1095. if (priv->features & FEATURE_IRQ)
  1096. free_irq(dev->irq, priv);
  1097. pci_release_region(dev, SMBBAR);
  1098. kfree(priv);
  1099. /*
  1100. * do not call pci_disable_device(dev) since it can cause hard hangs on
  1101. * some systems during power-off (eg. Fujitsu-Siemens Lifebook E8010)
  1102. */
  1103. }
  1104. #ifdef CONFIG_PM
  1105. static int i801_suspend(struct pci_dev *dev, pm_message_t mesg)
  1106. {
  1107. struct i801_priv *priv = pci_get_drvdata(dev);
  1108. pci_save_state(dev);
  1109. pci_write_config_byte(dev, SMBHSTCFG, priv->original_hstcfg);
  1110. pci_set_power_state(dev, pci_choose_state(dev, mesg));
  1111. return 0;
  1112. }
  1113. static int i801_resume(struct pci_dev *dev)
  1114. {
  1115. pci_set_power_state(dev, PCI_D0);
  1116. pci_restore_state(dev);
  1117. return pci_enable_device(dev);
  1118. }
  1119. #else
  1120. #define i801_suspend NULL
  1121. #define i801_resume NULL
  1122. #endif
  1123. static struct pci_driver i801_driver = {
  1124. .name = "i801_smbus",
  1125. .id_table = i801_ids,
  1126. .probe = i801_probe,
  1127. .remove = i801_remove,
  1128. .suspend = i801_suspend,
  1129. .resume = i801_resume,
  1130. };
  1131. static int __init i2c_i801_init(void)
  1132. {
  1133. if (dmi_name_in_vendors("FUJITSU"))
  1134. input_apanel_init();
  1135. return pci_register_driver(&i801_driver);
  1136. }
  1137. static void __exit i2c_i801_exit(void)
  1138. {
  1139. pci_unregister_driver(&i801_driver);
  1140. }
  1141. MODULE_AUTHOR("Mark D. Studebaker <mdsxyz123@yahoo.com>, "
  1142. "Jean Delvare <khali@linux-fr.org>");
  1143. MODULE_DESCRIPTION("I801 SMBus driver");
  1144. MODULE_LICENSE("GPL");
  1145. module_init(i2c_i801_init);
  1146. module_exit(i2c_i801_exit);