i2c-i801.c 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580
  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 - 2014 Jean Delvare <jdelvare@suse.de>
  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. */
  17. /*
  18. * Supports the following Intel I/O Controller Hubs (ICH):
  19. *
  20. * I/O Block I2C
  21. * region SMBus Block proc. block
  22. * Chip name PCI ID size PEC buffer call read
  23. * ---------------------------------------------------------------------------
  24. * 82801AA (ICH) 0x2413 16 no no no no
  25. * 82801AB (ICH0) 0x2423 16 no no no no
  26. * 82801BA (ICH2) 0x2443 16 no no no no
  27. * 82801CA (ICH3) 0x2483 32 soft no no no
  28. * 82801DB (ICH4) 0x24c3 32 hard yes no no
  29. * 82801E (ICH5) 0x24d3 32 hard yes yes yes
  30. * 6300ESB 0x25a4 32 hard yes yes yes
  31. * 82801F (ICH6) 0x266a 32 hard yes yes yes
  32. * 6310ESB/6320ESB 0x269b 32 hard yes yes yes
  33. * 82801G (ICH7) 0x27da 32 hard yes yes yes
  34. * 82801H (ICH8) 0x283e 32 hard yes yes yes
  35. * 82801I (ICH9) 0x2930 32 hard yes yes yes
  36. * EP80579 (Tolapai) 0x5032 32 hard yes yes yes
  37. * ICH10 0x3a30 32 hard yes yes yes
  38. * ICH10 0x3a60 32 hard yes yes yes
  39. * 5/3400 Series (PCH) 0x3b30 32 hard yes yes yes
  40. * 6 Series (PCH) 0x1c22 32 hard yes yes yes
  41. * Patsburg (PCH) 0x1d22 32 hard yes yes yes
  42. * Patsburg (PCH) IDF 0x1d70 32 hard yes yes yes
  43. * Patsburg (PCH) IDF 0x1d71 32 hard yes yes yes
  44. * Patsburg (PCH) IDF 0x1d72 32 hard yes yes yes
  45. * DH89xxCC (PCH) 0x2330 32 hard yes yes yes
  46. * Panther Point (PCH) 0x1e22 32 hard yes yes yes
  47. * Lynx Point (PCH) 0x8c22 32 hard yes yes yes
  48. * Lynx Point-LP (PCH) 0x9c22 32 hard yes yes yes
  49. * Avoton (SOC) 0x1f3c 32 hard yes yes yes
  50. * Wellsburg (PCH) 0x8d22 32 hard yes yes yes
  51. * Wellsburg (PCH) MS 0x8d7d 32 hard yes yes yes
  52. * Wellsburg (PCH) MS 0x8d7e 32 hard yes yes yes
  53. * Wellsburg (PCH) MS 0x8d7f 32 hard yes yes yes
  54. * Coleto Creek (PCH) 0x23b0 32 hard yes yes yes
  55. * Wildcat Point (PCH) 0x8ca2 32 hard yes yes yes
  56. * Wildcat Point-LP (PCH) 0x9ca2 32 hard yes yes yes
  57. * BayTrail (SOC) 0x0f12 32 hard yes yes yes
  58. * Sunrise Point-H (PCH) 0xa123 32 hard yes yes yes
  59. * Sunrise Point-LP (PCH) 0x9d23 32 hard yes yes yes
  60. * DNV (SOC) 0x19df 32 hard yes yes yes
  61. * Broxton (SOC) 0x5ad4 32 hard yes yes yes
  62. * Lewisburg (PCH) 0xa1a3 32 hard yes yes yes
  63. * Lewisburg Supersku (PCH) 0xa223 32 hard yes yes yes
  64. *
  65. * Features supported by this driver:
  66. * Software PEC no
  67. * Hardware PEC yes
  68. * Block buffer yes
  69. * Block process call transaction no
  70. * I2C block read transaction yes (doesn't use the block buffer)
  71. * Slave mode no
  72. * Interrupt processing yes
  73. *
  74. * See the file Documentation/i2c/busses/i2c-i801 for details.
  75. */
  76. #include <linux/interrupt.h>
  77. #include <linux/module.h>
  78. #include <linux/pci.h>
  79. #include <linux/kernel.h>
  80. #include <linux/stddef.h>
  81. #include <linux/delay.h>
  82. #include <linux/ioport.h>
  83. #include <linux/init.h>
  84. #include <linux/i2c.h>
  85. #include <linux/acpi.h>
  86. #include <linux/io.h>
  87. #include <linux/dmi.h>
  88. #include <linux/slab.h>
  89. #include <linux/wait.h>
  90. #include <linux/err.h>
  91. #include <linux/platform_device.h>
  92. #include <linux/platform_data/itco_wdt.h>
  93. #if (defined CONFIG_I2C_MUX_GPIO || defined CONFIG_I2C_MUX_GPIO_MODULE) && \
  94. defined CONFIG_DMI
  95. #include <linux/gpio.h>
  96. #include <linux/i2c-mux-gpio.h>
  97. #endif
  98. /* I801 SMBus address offsets */
  99. #define SMBHSTSTS(p) (0 + (p)->smba)
  100. #define SMBHSTCNT(p) (2 + (p)->smba)
  101. #define SMBHSTCMD(p) (3 + (p)->smba)
  102. #define SMBHSTADD(p) (4 + (p)->smba)
  103. #define SMBHSTDAT0(p) (5 + (p)->smba)
  104. #define SMBHSTDAT1(p) (6 + (p)->smba)
  105. #define SMBBLKDAT(p) (7 + (p)->smba)
  106. #define SMBPEC(p) (8 + (p)->smba) /* ICH3 and later */
  107. #define SMBAUXSTS(p) (12 + (p)->smba) /* ICH4 and later */
  108. #define SMBAUXCTL(p) (13 + (p)->smba) /* ICH4 and later */
  109. /* PCI Address Constants */
  110. #define SMBBAR 4
  111. #define SMBPCICTL 0x004
  112. #define SMBPCISTS 0x006
  113. #define SMBHSTCFG 0x040
  114. #define TCOBASE 0x050
  115. #define TCOCTL 0x054
  116. #define ACPIBASE 0x040
  117. #define ACPIBASE_SMI_OFF 0x030
  118. #define ACPICTRL 0x044
  119. #define ACPICTRL_EN 0x080
  120. #define SBREG_BAR 0x10
  121. #define SBREG_SMBCTRL 0xc6000c
  122. #define SBREG_SMBCTRL_DNV 0xcf000c
  123. /* Host status bits for SMBPCISTS */
  124. #define SMBPCISTS_INTS 0x08
  125. /* Control bits for SMBPCICTL */
  126. #define SMBPCICTL_INTDIS 0x0400
  127. /* Host configuration bits for SMBHSTCFG */
  128. #define SMBHSTCFG_HST_EN 1
  129. #define SMBHSTCFG_SMB_SMI_EN 2
  130. #define SMBHSTCFG_I2C_EN 4
  131. /* TCO configuration bits for TCOCTL */
  132. #define TCOCTL_EN 0x0100
  133. /* Auxiliary control register bits, ICH4+ only */
  134. #define SMBAUXCTL_CRC 1
  135. #define SMBAUXCTL_E32B 2
  136. /* Other settings */
  137. #define MAX_RETRIES 400
  138. /* I801 command constants */
  139. #define I801_QUICK 0x00
  140. #define I801_BYTE 0x04
  141. #define I801_BYTE_DATA 0x08
  142. #define I801_WORD_DATA 0x0C
  143. #define I801_PROC_CALL 0x10 /* unimplemented */
  144. #define I801_BLOCK_DATA 0x14
  145. #define I801_I2C_BLOCK_DATA 0x18 /* ICH5 and later */
  146. /* I801 Host Control register bits */
  147. #define SMBHSTCNT_INTREN 0x01
  148. #define SMBHSTCNT_KILL 0x02
  149. #define SMBHSTCNT_LAST_BYTE 0x20
  150. #define SMBHSTCNT_START 0x40
  151. #define SMBHSTCNT_PEC_EN 0x80 /* ICH3 and later */
  152. /* I801 Hosts Status register bits */
  153. #define SMBHSTSTS_BYTE_DONE 0x80
  154. #define SMBHSTSTS_INUSE_STS 0x40
  155. #define SMBHSTSTS_SMBALERT_STS 0x20
  156. #define SMBHSTSTS_FAILED 0x10
  157. #define SMBHSTSTS_BUS_ERR 0x08
  158. #define SMBHSTSTS_DEV_ERR 0x04
  159. #define SMBHSTSTS_INTR 0x02
  160. #define SMBHSTSTS_HOST_BUSY 0x01
  161. #define STATUS_ERROR_FLAGS (SMBHSTSTS_FAILED | SMBHSTSTS_BUS_ERR | \
  162. SMBHSTSTS_DEV_ERR)
  163. #define STATUS_FLAGS (SMBHSTSTS_BYTE_DONE | SMBHSTSTS_INTR | \
  164. STATUS_ERROR_FLAGS)
  165. /* Older devices have their ID defined in <linux/pci_ids.h> */
  166. #define PCI_DEVICE_ID_INTEL_BAYTRAIL_SMBUS 0x0f12
  167. #define PCI_DEVICE_ID_INTEL_BRASWELL_SMBUS 0x2292
  168. #define PCI_DEVICE_ID_INTEL_COUGARPOINT_SMBUS 0x1c22
  169. #define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS 0x1d22
  170. /* Patsburg also has three 'Integrated Device Function' SMBus controllers */
  171. #define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF0 0x1d70
  172. #define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF1 0x1d71
  173. #define PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF2 0x1d72
  174. #define PCI_DEVICE_ID_INTEL_PANTHERPOINT_SMBUS 0x1e22
  175. #define PCI_DEVICE_ID_INTEL_AVOTON_SMBUS 0x1f3c
  176. #define PCI_DEVICE_ID_INTEL_DH89XXCC_SMBUS 0x2330
  177. #define PCI_DEVICE_ID_INTEL_COLETOCREEK_SMBUS 0x23b0
  178. #define PCI_DEVICE_ID_INTEL_5_3400_SERIES_SMBUS 0x3b30
  179. #define PCI_DEVICE_ID_INTEL_LYNXPOINT_SMBUS 0x8c22
  180. #define PCI_DEVICE_ID_INTEL_WILDCATPOINT_SMBUS 0x8ca2
  181. #define PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS 0x8d22
  182. #define PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS0 0x8d7d
  183. #define PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS1 0x8d7e
  184. #define PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS2 0x8d7f
  185. #define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_SMBUS 0x9c22
  186. #define PCI_DEVICE_ID_INTEL_WILDCATPOINT_LP_SMBUS 0x9ca2
  187. #define PCI_DEVICE_ID_INTEL_SUNRISEPOINT_H_SMBUS 0xa123
  188. #define PCI_DEVICE_ID_INTEL_SUNRISEPOINT_LP_SMBUS 0x9d23
  189. #define PCI_DEVICE_ID_INTEL_DNV_SMBUS 0x19df
  190. #define PCI_DEVICE_ID_INTEL_BROXTON_SMBUS 0x5ad4
  191. #define PCI_DEVICE_ID_INTEL_LEWISBURG_SMBUS 0xa1a3
  192. #define PCI_DEVICE_ID_INTEL_LEWISBURG_SSKU_SMBUS 0xa223
  193. struct i801_mux_config {
  194. char *gpio_chip;
  195. unsigned values[3];
  196. int n_values;
  197. unsigned classes[3];
  198. unsigned gpios[2]; /* Relative to gpio_chip->base */
  199. int n_gpios;
  200. };
  201. struct i801_priv {
  202. struct i2c_adapter adapter;
  203. unsigned long smba;
  204. unsigned char original_hstcfg;
  205. struct pci_dev *pci_dev;
  206. unsigned int features;
  207. /* isr processing */
  208. wait_queue_head_t waitq;
  209. u8 status;
  210. /* Command state used by isr for byte-by-byte block transactions */
  211. u8 cmd;
  212. bool is_read;
  213. int count;
  214. int len;
  215. u8 *data;
  216. #if (defined CONFIG_I2C_MUX_GPIO || defined CONFIG_I2C_MUX_GPIO_MODULE) && \
  217. defined CONFIG_DMI
  218. const struct i801_mux_config *mux_drvdata;
  219. struct platform_device *mux_pdev;
  220. #endif
  221. struct platform_device *tco_pdev;
  222. /*
  223. * If set to true the host controller registers are reserved for
  224. * ACPI AML use. Protected by acpi_lock.
  225. */
  226. bool acpi_reserved;
  227. struct mutex acpi_lock;
  228. };
  229. #define FEATURE_SMBUS_PEC (1 << 0)
  230. #define FEATURE_BLOCK_BUFFER (1 << 1)
  231. #define FEATURE_BLOCK_PROC (1 << 2)
  232. #define FEATURE_I2C_BLOCK_READ (1 << 3)
  233. #define FEATURE_IRQ (1 << 4)
  234. /* Not really a feature, but it's convenient to handle it as such */
  235. #define FEATURE_IDF (1 << 15)
  236. #define FEATURE_TCO (1 << 16)
  237. static const char *i801_feature_names[] = {
  238. "SMBus PEC",
  239. "Block buffer",
  240. "Block process call",
  241. "I2C block read",
  242. "Interrupt",
  243. };
  244. static unsigned int disable_features;
  245. module_param(disable_features, uint, S_IRUGO | S_IWUSR);
  246. MODULE_PARM_DESC(disable_features, "Disable selected driver features:\n"
  247. "\t\t 0x01 disable SMBus PEC\n"
  248. "\t\t 0x02 disable the block buffer\n"
  249. "\t\t 0x08 disable the I2C block read functionality\n"
  250. "\t\t 0x10 don't use interrupts ");
  251. /* Make sure the SMBus host is ready to start transmitting.
  252. Return 0 if it is, -EBUSY if it is not. */
  253. static int i801_check_pre(struct i801_priv *priv)
  254. {
  255. int status;
  256. status = inb_p(SMBHSTSTS(priv));
  257. if (status & SMBHSTSTS_HOST_BUSY) {
  258. dev_err(&priv->pci_dev->dev, "SMBus is busy, can't use it!\n");
  259. return -EBUSY;
  260. }
  261. status &= STATUS_FLAGS;
  262. if (status) {
  263. dev_dbg(&priv->pci_dev->dev, "Clearing status flags (%02x)\n",
  264. status);
  265. outb_p(status, SMBHSTSTS(priv));
  266. status = inb_p(SMBHSTSTS(priv)) & STATUS_FLAGS;
  267. if (status) {
  268. dev_err(&priv->pci_dev->dev,
  269. "Failed clearing status flags (%02x)\n",
  270. status);
  271. return -EBUSY;
  272. }
  273. }
  274. return 0;
  275. }
  276. /*
  277. * Convert the status register to an error code, and clear it.
  278. * Note that status only contains the bits we want to clear, not the
  279. * actual register value.
  280. */
  281. static int i801_check_post(struct i801_priv *priv, int status)
  282. {
  283. int result = 0;
  284. /*
  285. * If the SMBus is still busy, we give up
  286. * Note: This timeout condition only happens when using polling
  287. * transactions. For interrupt operation, NAK/timeout is indicated by
  288. * DEV_ERR.
  289. */
  290. if (unlikely(status < 0)) {
  291. dev_err(&priv->pci_dev->dev, "Transaction timeout\n");
  292. /* try to stop the current command */
  293. dev_dbg(&priv->pci_dev->dev, "Terminating the current operation\n");
  294. outb_p(inb_p(SMBHSTCNT(priv)) | SMBHSTCNT_KILL,
  295. SMBHSTCNT(priv));
  296. usleep_range(1000, 2000);
  297. outb_p(inb_p(SMBHSTCNT(priv)) & (~SMBHSTCNT_KILL),
  298. SMBHSTCNT(priv));
  299. /* Check if it worked */
  300. status = inb_p(SMBHSTSTS(priv));
  301. if ((status & SMBHSTSTS_HOST_BUSY) ||
  302. !(status & SMBHSTSTS_FAILED))
  303. dev_err(&priv->pci_dev->dev,
  304. "Failed terminating the transaction\n");
  305. outb_p(STATUS_FLAGS, SMBHSTSTS(priv));
  306. return -ETIMEDOUT;
  307. }
  308. if (status & SMBHSTSTS_FAILED) {
  309. result = -EIO;
  310. dev_err(&priv->pci_dev->dev, "Transaction failed\n");
  311. }
  312. if (status & SMBHSTSTS_DEV_ERR) {
  313. result = -ENXIO;
  314. dev_dbg(&priv->pci_dev->dev, "No response\n");
  315. }
  316. if (status & SMBHSTSTS_BUS_ERR) {
  317. result = -EAGAIN;
  318. dev_dbg(&priv->pci_dev->dev, "Lost arbitration\n");
  319. }
  320. /* Clear status flags except BYTE_DONE, to be cleared by caller */
  321. outb_p(status, SMBHSTSTS(priv));
  322. return result;
  323. }
  324. /* Wait for BUSY being cleared and either INTR or an error flag being set */
  325. static int i801_wait_intr(struct i801_priv *priv)
  326. {
  327. int timeout = 0;
  328. int status;
  329. /* We will always wait for a fraction of a second! */
  330. do {
  331. usleep_range(250, 500);
  332. status = inb_p(SMBHSTSTS(priv));
  333. } while (((status & SMBHSTSTS_HOST_BUSY) ||
  334. !(status & (STATUS_ERROR_FLAGS | SMBHSTSTS_INTR))) &&
  335. (timeout++ < MAX_RETRIES));
  336. if (timeout > MAX_RETRIES) {
  337. dev_dbg(&priv->pci_dev->dev, "INTR Timeout!\n");
  338. return -ETIMEDOUT;
  339. }
  340. return status & (STATUS_ERROR_FLAGS | SMBHSTSTS_INTR);
  341. }
  342. /* Wait for either BYTE_DONE or an error flag being set */
  343. static int i801_wait_byte_done(struct i801_priv *priv)
  344. {
  345. int timeout = 0;
  346. int status;
  347. /* We will always wait for a fraction of a second! */
  348. do {
  349. usleep_range(250, 500);
  350. status = inb_p(SMBHSTSTS(priv));
  351. } while (!(status & (STATUS_ERROR_FLAGS | SMBHSTSTS_BYTE_DONE)) &&
  352. (timeout++ < MAX_RETRIES));
  353. if (timeout > MAX_RETRIES) {
  354. dev_dbg(&priv->pci_dev->dev, "BYTE_DONE Timeout!\n");
  355. return -ETIMEDOUT;
  356. }
  357. return status & STATUS_ERROR_FLAGS;
  358. }
  359. static int i801_transaction(struct i801_priv *priv, int xact)
  360. {
  361. int status;
  362. int result;
  363. const struct i2c_adapter *adap = &priv->adapter;
  364. result = i801_check_pre(priv);
  365. if (result < 0)
  366. return result;
  367. if (priv->features & FEATURE_IRQ) {
  368. outb_p(xact | SMBHSTCNT_INTREN | SMBHSTCNT_START,
  369. SMBHSTCNT(priv));
  370. result = wait_event_timeout(priv->waitq,
  371. (status = priv->status),
  372. adap->timeout);
  373. if (!result) {
  374. status = -ETIMEDOUT;
  375. dev_warn(&priv->pci_dev->dev,
  376. "Timeout waiting for interrupt!\n");
  377. }
  378. priv->status = 0;
  379. return i801_check_post(priv, status);
  380. }
  381. /* the current contents of SMBHSTCNT can be overwritten, since PEC,
  382. * SMBSCMD are passed in xact */
  383. outb_p(xact | SMBHSTCNT_START, SMBHSTCNT(priv));
  384. status = i801_wait_intr(priv);
  385. return i801_check_post(priv, status);
  386. }
  387. static int i801_block_transaction_by_block(struct i801_priv *priv,
  388. union i2c_smbus_data *data,
  389. char read_write, int hwpec)
  390. {
  391. int i, len;
  392. int status;
  393. inb_p(SMBHSTCNT(priv)); /* reset the data buffer index */
  394. /* Use 32-byte buffer to process this transaction */
  395. if (read_write == I2C_SMBUS_WRITE) {
  396. len = data->block[0];
  397. outb_p(len, SMBHSTDAT0(priv));
  398. for (i = 0; i < len; i++)
  399. outb_p(data->block[i+1], SMBBLKDAT(priv));
  400. }
  401. status = i801_transaction(priv, I801_BLOCK_DATA |
  402. (hwpec ? SMBHSTCNT_PEC_EN : 0));
  403. if (status)
  404. return status;
  405. if (read_write == I2C_SMBUS_READ) {
  406. len = inb_p(SMBHSTDAT0(priv));
  407. if (len < 1 || len > I2C_SMBUS_BLOCK_MAX)
  408. return -EPROTO;
  409. data->block[0] = len;
  410. for (i = 0; i < len; i++)
  411. data->block[i + 1] = inb_p(SMBBLKDAT(priv));
  412. }
  413. return 0;
  414. }
  415. static void i801_isr_byte_done(struct i801_priv *priv)
  416. {
  417. if (priv->is_read) {
  418. /* For SMBus block reads, length is received with first byte */
  419. if (((priv->cmd & 0x1c) == I801_BLOCK_DATA) &&
  420. (priv->count == 0)) {
  421. priv->len = inb_p(SMBHSTDAT0(priv));
  422. if (priv->len < 1 || priv->len > I2C_SMBUS_BLOCK_MAX) {
  423. dev_err(&priv->pci_dev->dev,
  424. "Illegal SMBus block read size %d\n",
  425. priv->len);
  426. /* FIXME: Recover */
  427. priv->len = I2C_SMBUS_BLOCK_MAX;
  428. } else {
  429. dev_dbg(&priv->pci_dev->dev,
  430. "SMBus block read size is %d\n",
  431. priv->len);
  432. }
  433. priv->data[-1] = priv->len;
  434. }
  435. /* Read next byte */
  436. if (priv->count < priv->len)
  437. priv->data[priv->count++] = inb(SMBBLKDAT(priv));
  438. else
  439. dev_dbg(&priv->pci_dev->dev,
  440. "Discarding extra byte on block read\n");
  441. /* Set LAST_BYTE for last byte of read transaction */
  442. if (priv->count == priv->len - 1)
  443. outb_p(priv->cmd | SMBHSTCNT_LAST_BYTE,
  444. SMBHSTCNT(priv));
  445. } else if (priv->count < priv->len - 1) {
  446. /* Write next byte, except for IRQ after last byte */
  447. outb_p(priv->data[++priv->count], SMBBLKDAT(priv));
  448. }
  449. /* Clear BYTE_DONE to continue with next byte */
  450. outb_p(SMBHSTSTS_BYTE_DONE, SMBHSTSTS(priv));
  451. }
  452. /*
  453. * There are two kinds of interrupts:
  454. *
  455. * 1) i801 signals transaction completion with one of these interrupts:
  456. * INTR - Success
  457. * DEV_ERR - Invalid command, NAK or communication timeout
  458. * BUS_ERR - SMI# transaction collision
  459. * FAILED - transaction was canceled due to a KILL request
  460. * When any of these occur, update ->status and wake up the waitq.
  461. * ->status must be cleared before kicking off the next transaction.
  462. *
  463. * 2) For byte-by-byte (I2C read/write) transactions, one BYTE_DONE interrupt
  464. * occurs for each byte of a byte-by-byte to prepare the next byte.
  465. */
  466. static irqreturn_t i801_isr(int irq, void *dev_id)
  467. {
  468. struct i801_priv *priv = dev_id;
  469. u16 pcists;
  470. u8 status;
  471. /* Confirm this is our interrupt */
  472. pci_read_config_word(priv->pci_dev, SMBPCISTS, &pcists);
  473. if (!(pcists & SMBPCISTS_INTS))
  474. return IRQ_NONE;
  475. status = inb_p(SMBHSTSTS(priv));
  476. if (status & SMBHSTSTS_BYTE_DONE)
  477. i801_isr_byte_done(priv);
  478. /*
  479. * Clear irq sources and report transaction result.
  480. * ->status must be cleared before the next transaction is started.
  481. */
  482. status &= SMBHSTSTS_INTR | STATUS_ERROR_FLAGS;
  483. if (status) {
  484. outb_p(status, SMBHSTSTS(priv));
  485. priv->status |= status;
  486. wake_up(&priv->waitq);
  487. }
  488. return IRQ_HANDLED;
  489. }
  490. /*
  491. * For "byte-by-byte" block transactions:
  492. * I2C write uses cmd=I801_BLOCK_DATA, I2C_EN=1
  493. * I2C read uses cmd=I801_I2C_BLOCK_DATA
  494. */
  495. static int i801_block_transaction_byte_by_byte(struct i801_priv *priv,
  496. union i2c_smbus_data *data,
  497. char read_write, int command,
  498. int hwpec)
  499. {
  500. int i, len;
  501. int smbcmd;
  502. int status;
  503. int result;
  504. const struct i2c_adapter *adap = &priv->adapter;
  505. result = i801_check_pre(priv);
  506. if (result < 0)
  507. return result;
  508. len = data->block[0];
  509. if (read_write == I2C_SMBUS_WRITE) {
  510. outb_p(len, SMBHSTDAT0(priv));
  511. outb_p(data->block[1], SMBBLKDAT(priv));
  512. }
  513. if (command == I2C_SMBUS_I2C_BLOCK_DATA &&
  514. read_write == I2C_SMBUS_READ)
  515. smbcmd = I801_I2C_BLOCK_DATA;
  516. else
  517. smbcmd = I801_BLOCK_DATA;
  518. if (priv->features & FEATURE_IRQ) {
  519. priv->is_read = (read_write == I2C_SMBUS_READ);
  520. if (len == 1 && priv->is_read)
  521. smbcmd |= SMBHSTCNT_LAST_BYTE;
  522. priv->cmd = smbcmd | SMBHSTCNT_INTREN;
  523. priv->len = len;
  524. priv->count = 0;
  525. priv->data = &data->block[1];
  526. outb_p(priv->cmd | SMBHSTCNT_START, SMBHSTCNT(priv));
  527. result = wait_event_timeout(priv->waitq,
  528. (status = priv->status),
  529. adap->timeout);
  530. if (!result) {
  531. status = -ETIMEDOUT;
  532. dev_warn(&priv->pci_dev->dev,
  533. "Timeout waiting for interrupt!\n");
  534. }
  535. priv->status = 0;
  536. return i801_check_post(priv, status);
  537. }
  538. for (i = 1; i <= len; i++) {
  539. if (i == len && read_write == I2C_SMBUS_READ)
  540. smbcmd |= SMBHSTCNT_LAST_BYTE;
  541. outb_p(smbcmd, SMBHSTCNT(priv));
  542. if (i == 1)
  543. outb_p(inb(SMBHSTCNT(priv)) | SMBHSTCNT_START,
  544. SMBHSTCNT(priv));
  545. status = i801_wait_byte_done(priv);
  546. if (status)
  547. goto exit;
  548. if (i == 1 && read_write == I2C_SMBUS_READ
  549. && command != I2C_SMBUS_I2C_BLOCK_DATA) {
  550. len = inb_p(SMBHSTDAT0(priv));
  551. if (len < 1 || len > I2C_SMBUS_BLOCK_MAX) {
  552. dev_err(&priv->pci_dev->dev,
  553. "Illegal SMBus block read size %d\n",
  554. len);
  555. /* Recover */
  556. while (inb_p(SMBHSTSTS(priv)) &
  557. SMBHSTSTS_HOST_BUSY)
  558. outb_p(SMBHSTSTS_BYTE_DONE,
  559. SMBHSTSTS(priv));
  560. outb_p(SMBHSTSTS_INTR, SMBHSTSTS(priv));
  561. return -EPROTO;
  562. }
  563. data->block[0] = len;
  564. }
  565. /* Retrieve/store value in SMBBLKDAT */
  566. if (read_write == I2C_SMBUS_READ)
  567. data->block[i] = inb_p(SMBBLKDAT(priv));
  568. if (read_write == I2C_SMBUS_WRITE && i+1 <= len)
  569. outb_p(data->block[i+1], SMBBLKDAT(priv));
  570. /* signals SMBBLKDAT ready */
  571. outb_p(SMBHSTSTS_BYTE_DONE, SMBHSTSTS(priv));
  572. }
  573. status = i801_wait_intr(priv);
  574. exit:
  575. return i801_check_post(priv, status);
  576. }
  577. static int i801_set_block_buffer_mode(struct i801_priv *priv)
  578. {
  579. outb_p(inb_p(SMBAUXCTL(priv)) | SMBAUXCTL_E32B, SMBAUXCTL(priv));
  580. if ((inb_p(SMBAUXCTL(priv)) & SMBAUXCTL_E32B) == 0)
  581. return -EIO;
  582. return 0;
  583. }
  584. /* Block transaction function */
  585. static int i801_block_transaction(struct i801_priv *priv,
  586. union i2c_smbus_data *data, char read_write,
  587. int command, int hwpec)
  588. {
  589. int result = 0;
  590. unsigned char hostc;
  591. if (command == I2C_SMBUS_I2C_BLOCK_DATA) {
  592. if (read_write == I2C_SMBUS_WRITE) {
  593. /* set I2C_EN bit in configuration register */
  594. pci_read_config_byte(priv->pci_dev, SMBHSTCFG, &hostc);
  595. pci_write_config_byte(priv->pci_dev, SMBHSTCFG,
  596. hostc | SMBHSTCFG_I2C_EN);
  597. } else if (!(priv->features & FEATURE_I2C_BLOCK_READ)) {
  598. dev_err(&priv->pci_dev->dev,
  599. "I2C block read is unsupported!\n");
  600. return -EOPNOTSUPP;
  601. }
  602. }
  603. if (read_write == I2C_SMBUS_WRITE
  604. || command == I2C_SMBUS_I2C_BLOCK_DATA) {
  605. if (data->block[0] < 1)
  606. data->block[0] = 1;
  607. if (data->block[0] > I2C_SMBUS_BLOCK_MAX)
  608. data->block[0] = I2C_SMBUS_BLOCK_MAX;
  609. } else {
  610. data->block[0] = 32; /* max for SMBus block reads */
  611. }
  612. /* Experience has shown that the block buffer can only be used for
  613. SMBus (not I2C) block transactions, even though the datasheet
  614. doesn't mention this limitation. */
  615. if ((priv->features & FEATURE_BLOCK_BUFFER)
  616. && command != I2C_SMBUS_I2C_BLOCK_DATA
  617. && i801_set_block_buffer_mode(priv) == 0)
  618. result = i801_block_transaction_by_block(priv, data,
  619. read_write, hwpec);
  620. else
  621. result = i801_block_transaction_byte_by_byte(priv, data,
  622. read_write,
  623. command, hwpec);
  624. if (command == I2C_SMBUS_I2C_BLOCK_DATA
  625. && read_write == I2C_SMBUS_WRITE) {
  626. /* restore saved configuration register value */
  627. pci_write_config_byte(priv->pci_dev, SMBHSTCFG, hostc);
  628. }
  629. return result;
  630. }
  631. /* Return negative errno on error. */
  632. static s32 i801_access(struct i2c_adapter *adap, u16 addr,
  633. unsigned short flags, char read_write, u8 command,
  634. int size, union i2c_smbus_data *data)
  635. {
  636. int hwpec;
  637. int block = 0;
  638. int ret = 0, xact = 0;
  639. struct i801_priv *priv = i2c_get_adapdata(adap);
  640. mutex_lock(&priv->acpi_lock);
  641. if (priv->acpi_reserved) {
  642. mutex_unlock(&priv->acpi_lock);
  643. return -EBUSY;
  644. }
  645. hwpec = (priv->features & FEATURE_SMBUS_PEC) && (flags & I2C_CLIENT_PEC)
  646. && size != I2C_SMBUS_QUICK
  647. && size != I2C_SMBUS_I2C_BLOCK_DATA;
  648. switch (size) {
  649. case I2C_SMBUS_QUICK:
  650. outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
  651. SMBHSTADD(priv));
  652. xact = I801_QUICK;
  653. break;
  654. case I2C_SMBUS_BYTE:
  655. outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
  656. SMBHSTADD(priv));
  657. if (read_write == I2C_SMBUS_WRITE)
  658. outb_p(command, SMBHSTCMD(priv));
  659. xact = I801_BYTE;
  660. break;
  661. case I2C_SMBUS_BYTE_DATA:
  662. outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
  663. SMBHSTADD(priv));
  664. outb_p(command, SMBHSTCMD(priv));
  665. if (read_write == I2C_SMBUS_WRITE)
  666. outb_p(data->byte, SMBHSTDAT0(priv));
  667. xact = I801_BYTE_DATA;
  668. break;
  669. case I2C_SMBUS_WORD_DATA:
  670. outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
  671. SMBHSTADD(priv));
  672. outb_p(command, SMBHSTCMD(priv));
  673. if (read_write == I2C_SMBUS_WRITE) {
  674. outb_p(data->word & 0xff, SMBHSTDAT0(priv));
  675. outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1(priv));
  676. }
  677. xact = I801_WORD_DATA;
  678. break;
  679. case I2C_SMBUS_BLOCK_DATA:
  680. outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
  681. SMBHSTADD(priv));
  682. outb_p(command, SMBHSTCMD(priv));
  683. block = 1;
  684. break;
  685. case I2C_SMBUS_I2C_BLOCK_DATA:
  686. /* NB: page 240 of ICH5 datasheet shows that the R/#W
  687. * bit should be cleared here, even when reading */
  688. outb_p((addr & 0x7f) << 1, SMBHSTADD(priv));
  689. if (read_write == I2C_SMBUS_READ) {
  690. /* NB: page 240 of ICH5 datasheet also shows
  691. * that DATA1 is the cmd field when reading */
  692. outb_p(command, SMBHSTDAT1(priv));
  693. } else
  694. outb_p(command, SMBHSTCMD(priv));
  695. block = 1;
  696. break;
  697. default:
  698. dev_err(&priv->pci_dev->dev, "Unsupported transaction %d\n",
  699. size);
  700. ret = -EOPNOTSUPP;
  701. goto out;
  702. }
  703. if (hwpec) /* enable/disable hardware PEC */
  704. outb_p(inb_p(SMBAUXCTL(priv)) | SMBAUXCTL_CRC, SMBAUXCTL(priv));
  705. else
  706. outb_p(inb_p(SMBAUXCTL(priv)) & (~SMBAUXCTL_CRC),
  707. SMBAUXCTL(priv));
  708. if (block)
  709. ret = i801_block_transaction(priv, data, read_write, size,
  710. hwpec);
  711. else
  712. ret = i801_transaction(priv, xact);
  713. /* Some BIOSes don't like it when PEC is enabled at reboot or resume
  714. time, so we forcibly disable it after every transaction. Turn off
  715. E32B for the same reason. */
  716. if (hwpec || block)
  717. outb_p(inb_p(SMBAUXCTL(priv)) &
  718. ~(SMBAUXCTL_CRC | SMBAUXCTL_E32B), SMBAUXCTL(priv));
  719. if (block)
  720. goto out;
  721. if (ret)
  722. goto out;
  723. if ((read_write == I2C_SMBUS_WRITE) || (xact == I801_QUICK))
  724. goto out;
  725. switch (xact & 0x7f) {
  726. case I801_BYTE: /* Result put in SMBHSTDAT0 */
  727. case I801_BYTE_DATA:
  728. data->byte = inb_p(SMBHSTDAT0(priv));
  729. break;
  730. case I801_WORD_DATA:
  731. data->word = inb_p(SMBHSTDAT0(priv)) +
  732. (inb_p(SMBHSTDAT1(priv)) << 8);
  733. break;
  734. }
  735. out:
  736. mutex_unlock(&priv->acpi_lock);
  737. return ret;
  738. }
  739. static u32 i801_func(struct i2c_adapter *adapter)
  740. {
  741. struct i801_priv *priv = i2c_get_adapdata(adapter);
  742. return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
  743. I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
  744. I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_WRITE_I2C_BLOCK |
  745. ((priv->features & FEATURE_SMBUS_PEC) ? I2C_FUNC_SMBUS_PEC : 0) |
  746. ((priv->features & FEATURE_I2C_BLOCK_READ) ?
  747. I2C_FUNC_SMBUS_READ_I2C_BLOCK : 0);
  748. }
  749. static const struct i2c_algorithm smbus_algorithm = {
  750. .smbus_xfer = i801_access,
  751. .functionality = i801_func,
  752. };
  753. static const struct pci_device_id i801_ids[] = {
  754. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_3) },
  755. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_3) },
  756. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_2) },
  757. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_3) },
  758. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_3) },
  759. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_3) },
  760. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB_4) },
  761. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_16) },
  762. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_17) },
  763. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB2_17) },
  764. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8_5) },
  765. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH9_6) },
  766. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_EP80579_1) },
  767. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH10_4) },
  768. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH10_5) },
  769. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5_3400_SERIES_SMBUS) },
  770. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_COUGARPOINT_SMBUS) },
  771. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS) },
  772. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF0) },
  773. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF1) },
  774. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF2) },
  775. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_DH89XXCC_SMBUS) },
  776. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PANTHERPOINT_SMBUS) },
  777. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LYNXPOINT_SMBUS) },
  778. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_SMBUS) },
  779. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_AVOTON_SMBUS) },
  780. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS) },
  781. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS0) },
  782. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS1) },
  783. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS2) },
  784. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_COLETOCREEK_SMBUS) },
  785. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WILDCATPOINT_SMBUS) },
  786. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WILDCATPOINT_LP_SMBUS) },
  787. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BAYTRAIL_SMBUS) },
  788. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BRASWELL_SMBUS) },
  789. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SUNRISEPOINT_H_SMBUS) },
  790. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SUNRISEPOINT_LP_SMBUS) },
  791. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_DNV_SMBUS) },
  792. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BROXTON_SMBUS) },
  793. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LEWISBURG_SMBUS) },
  794. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LEWISBURG_SSKU_SMBUS) },
  795. { 0, }
  796. };
  797. MODULE_DEVICE_TABLE(pci, i801_ids);
  798. #if defined CONFIG_X86 && defined CONFIG_DMI
  799. static unsigned char apanel_addr;
  800. /* Scan the system ROM for the signature "FJKEYINF" */
  801. static __init const void __iomem *bios_signature(const void __iomem *bios)
  802. {
  803. ssize_t offset;
  804. const unsigned char signature[] = "FJKEYINF";
  805. for (offset = 0; offset < 0x10000; offset += 0x10) {
  806. if (check_signature(bios + offset, signature,
  807. sizeof(signature)-1))
  808. return bios + offset;
  809. }
  810. return NULL;
  811. }
  812. static void __init input_apanel_init(void)
  813. {
  814. void __iomem *bios;
  815. const void __iomem *p;
  816. bios = ioremap(0xF0000, 0x10000); /* Can't fail */
  817. p = bios_signature(bios);
  818. if (p) {
  819. /* just use the first address */
  820. apanel_addr = readb(p + 8 + 3) >> 1;
  821. }
  822. iounmap(bios);
  823. }
  824. struct dmi_onboard_device_info {
  825. const char *name;
  826. u8 type;
  827. unsigned short i2c_addr;
  828. const char *i2c_type;
  829. };
  830. static const struct dmi_onboard_device_info dmi_devices[] = {
  831. { "Syleus", DMI_DEV_TYPE_OTHER, 0x73, "fscsyl" },
  832. { "Hermes", DMI_DEV_TYPE_OTHER, 0x73, "fscher" },
  833. { "Hades", DMI_DEV_TYPE_OTHER, 0x73, "fschds" },
  834. };
  835. static void dmi_check_onboard_device(u8 type, const char *name,
  836. struct i2c_adapter *adap)
  837. {
  838. int i;
  839. struct i2c_board_info info;
  840. for (i = 0; i < ARRAY_SIZE(dmi_devices); i++) {
  841. /* & ~0x80, ignore enabled/disabled bit */
  842. if ((type & ~0x80) != dmi_devices[i].type)
  843. continue;
  844. if (strcasecmp(name, dmi_devices[i].name))
  845. continue;
  846. memset(&info, 0, sizeof(struct i2c_board_info));
  847. info.addr = dmi_devices[i].i2c_addr;
  848. strlcpy(info.type, dmi_devices[i].i2c_type, I2C_NAME_SIZE);
  849. i2c_new_device(adap, &info);
  850. break;
  851. }
  852. }
  853. /* We use our own function to check for onboard devices instead of
  854. dmi_find_device() as some buggy BIOS's have the devices we are interested
  855. in marked as disabled */
  856. static void dmi_check_onboard_devices(const struct dmi_header *dm, void *adap)
  857. {
  858. int i, count;
  859. if (dm->type != 10)
  860. return;
  861. count = (dm->length - sizeof(struct dmi_header)) / 2;
  862. for (i = 0; i < count; i++) {
  863. const u8 *d = (char *)(dm + 1) + (i * 2);
  864. const char *name = ((char *) dm) + dm->length;
  865. u8 type = d[0];
  866. u8 s = d[1];
  867. if (!s)
  868. continue;
  869. s--;
  870. while (s > 0 && name[0]) {
  871. name += strlen(name) + 1;
  872. s--;
  873. }
  874. if (name[0] == 0) /* Bogus string reference */
  875. continue;
  876. dmi_check_onboard_device(type, name, adap);
  877. }
  878. }
  879. /* Register optional slaves */
  880. static void i801_probe_optional_slaves(struct i801_priv *priv)
  881. {
  882. /* Only register slaves on main SMBus channel */
  883. if (priv->features & FEATURE_IDF)
  884. return;
  885. if (apanel_addr) {
  886. struct i2c_board_info info;
  887. memset(&info, 0, sizeof(struct i2c_board_info));
  888. info.addr = apanel_addr;
  889. strlcpy(info.type, "fujitsu_apanel", I2C_NAME_SIZE);
  890. i2c_new_device(&priv->adapter, &info);
  891. }
  892. if (dmi_name_in_vendors("FUJITSU"))
  893. dmi_walk(dmi_check_onboard_devices, &priv->adapter);
  894. }
  895. #else
  896. static void __init input_apanel_init(void) {}
  897. static void i801_probe_optional_slaves(struct i801_priv *priv) {}
  898. #endif /* CONFIG_X86 && CONFIG_DMI */
  899. #if (defined CONFIG_I2C_MUX_GPIO || defined CONFIG_I2C_MUX_GPIO_MODULE) && \
  900. defined CONFIG_DMI
  901. static struct i801_mux_config i801_mux_config_asus_z8_d12 = {
  902. .gpio_chip = "gpio_ich",
  903. .values = { 0x02, 0x03 },
  904. .n_values = 2,
  905. .classes = { I2C_CLASS_SPD, I2C_CLASS_SPD },
  906. .gpios = { 52, 53 },
  907. .n_gpios = 2,
  908. };
  909. static struct i801_mux_config i801_mux_config_asus_z8_d18 = {
  910. .gpio_chip = "gpio_ich",
  911. .values = { 0x02, 0x03, 0x01 },
  912. .n_values = 3,
  913. .classes = { I2C_CLASS_SPD, I2C_CLASS_SPD, I2C_CLASS_SPD },
  914. .gpios = { 52, 53 },
  915. .n_gpios = 2,
  916. };
  917. static const struct dmi_system_id mux_dmi_table[] = {
  918. {
  919. .matches = {
  920. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
  921. DMI_MATCH(DMI_BOARD_NAME, "Z8NA-D6(C)"),
  922. },
  923. .driver_data = &i801_mux_config_asus_z8_d12,
  924. },
  925. {
  926. .matches = {
  927. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
  928. DMI_MATCH(DMI_BOARD_NAME, "Z8P(N)E-D12(X)"),
  929. },
  930. .driver_data = &i801_mux_config_asus_z8_d12,
  931. },
  932. {
  933. .matches = {
  934. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
  935. DMI_MATCH(DMI_BOARD_NAME, "Z8NH-D12"),
  936. },
  937. .driver_data = &i801_mux_config_asus_z8_d12,
  938. },
  939. {
  940. .matches = {
  941. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
  942. DMI_MATCH(DMI_BOARD_NAME, "Z8PH-D12/IFB"),
  943. },
  944. .driver_data = &i801_mux_config_asus_z8_d12,
  945. },
  946. {
  947. .matches = {
  948. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
  949. DMI_MATCH(DMI_BOARD_NAME, "Z8NR-D12"),
  950. },
  951. .driver_data = &i801_mux_config_asus_z8_d12,
  952. },
  953. {
  954. .matches = {
  955. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
  956. DMI_MATCH(DMI_BOARD_NAME, "Z8P(N)H-D12"),
  957. },
  958. .driver_data = &i801_mux_config_asus_z8_d12,
  959. },
  960. {
  961. .matches = {
  962. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
  963. DMI_MATCH(DMI_BOARD_NAME, "Z8PG-D18"),
  964. },
  965. .driver_data = &i801_mux_config_asus_z8_d18,
  966. },
  967. {
  968. .matches = {
  969. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
  970. DMI_MATCH(DMI_BOARD_NAME, "Z8PE-D18"),
  971. },
  972. .driver_data = &i801_mux_config_asus_z8_d18,
  973. },
  974. {
  975. .matches = {
  976. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
  977. DMI_MATCH(DMI_BOARD_NAME, "Z8PS-D12"),
  978. },
  979. .driver_data = &i801_mux_config_asus_z8_d12,
  980. },
  981. { }
  982. };
  983. /* Setup multiplexing if needed */
  984. static int i801_add_mux(struct i801_priv *priv)
  985. {
  986. struct device *dev = &priv->adapter.dev;
  987. const struct i801_mux_config *mux_config;
  988. struct i2c_mux_gpio_platform_data gpio_data;
  989. int err;
  990. if (!priv->mux_drvdata)
  991. return 0;
  992. mux_config = priv->mux_drvdata;
  993. /* Prepare the platform data */
  994. memset(&gpio_data, 0, sizeof(struct i2c_mux_gpio_platform_data));
  995. gpio_data.parent = priv->adapter.nr;
  996. gpio_data.values = mux_config->values;
  997. gpio_data.n_values = mux_config->n_values;
  998. gpio_data.classes = mux_config->classes;
  999. gpio_data.gpio_chip = mux_config->gpio_chip;
  1000. gpio_data.gpios = mux_config->gpios;
  1001. gpio_data.n_gpios = mux_config->n_gpios;
  1002. gpio_data.idle = I2C_MUX_GPIO_NO_IDLE;
  1003. /* Register the mux device */
  1004. priv->mux_pdev = platform_device_register_data(dev, "i2c-mux-gpio",
  1005. PLATFORM_DEVID_AUTO, &gpio_data,
  1006. sizeof(struct i2c_mux_gpio_platform_data));
  1007. if (IS_ERR(priv->mux_pdev)) {
  1008. err = PTR_ERR(priv->mux_pdev);
  1009. priv->mux_pdev = NULL;
  1010. dev_err(dev, "Failed to register i2c-mux-gpio device\n");
  1011. return err;
  1012. }
  1013. return 0;
  1014. }
  1015. static void i801_del_mux(struct i801_priv *priv)
  1016. {
  1017. if (priv->mux_pdev)
  1018. platform_device_unregister(priv->mux_pdev);
  1019. }
  1020. static unsigned int i801_get_adapter_class(struct i801_priv *priv)
  1021. {
  1022. const struct dmi_system_id *id;
  1023. const struct i801_mux_config *mux_config;
  1024. unsigned int class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
  1025. int i;
  1026. id = dmi_first_match(mux_dmi_table);
  1027. if (id) {
  1028. /* Remove branch classes from trunk */
  1029. mux_config = id->driver_data;
  1030. for (i = 0; i < mux_config->n_values; i++)
  1031. class &= ~mux_config->classes[i];
  1032. /* Remember for later */
  1033. priv->mux_drvdata = mux_config;
  1034. }
  1035. return class;
  1036. }
  1037. #else
  1038. static inline int i801_add_mux(struct i801_priv *priv) { return 0; }
  1039. static inline void i801_del_mux(struct i801_priv *priv) { }
  1040. static inline unsigned int i801_get_adapter_class(struct i801_priv *priv)
  1041. {
  1042. return I2C_CLASS_HWMON | I2C_CLASS_SPD;
  1043. }
  1044. #endif
  1045. static const struct itco_wdt_platform_data tco_platform_data = {
  1046. .name = "Intel PCH",
  1047. .version = 4,
  1048. };
  1049. static DEFINE_SPINLOCK(p2sb_spinlock);
  1050. static void i801_add_tco(struct i801_priv *priv)
  1051. {
  1052. struct pci_dev *pci_dev = priv->pci_dev;
  1053. struct resource tco_res[3], *res;
  1054. struct platform_device *pdev;
  1055. unsigned int devfn;
  1056. u32 tco_base, tco_ctl;
  1057. u32 base_addr, ctrl_val;
  1058. u64 base64_addr;
  1059. if (!(priv->features & FEATURE_TCO))
  1060. return;
  1061. pci_read_config_dword(pci_dev, TCOBASE, &tco_base);
  1062. pci_read_config_dword(pci_dev, TCOCTL, &tco_ctl);
  1063. if (!(tco_ctl & TCOCTL_EN))
  1064. return;
  1065. memset(tco_res, 0, sizeof(tco_res));
  1066. res = &tco_res[ICH_RES_IO_TCO];
  1067. res->start = tco_base & ~1;
  1068. res->end = res->start + 32 - 1;
  1069. res->flags = IORESOURCE_IO;
  1070. /*
  1071. * Power Management registers.
  1072. */
  1073. devfn = PCI_DEVFN(PCI_SLOT(pci_dev->devfn), 2);
  1074. pci_bus_read_config_dword(pci_dev->bus, devfn, ACPIBASE, &base_addr);
  1075. res = &tco_res[ICH_RES_IO_SMI];
  1076. res->start = (base_addr & ~1) + ACPIBASE_SMI_OFF;
  1077. res->end = res->start + 3;
  1078. res->flags = IORESOURCE_IO;
  1079. /*
  1080. * Enable the ACPI I/O space.
  1081. */
  1082. pci_bus_read_config_dword(pci_dev->bus, devfn, ACPICTRL, &ctrl_val);
  1083. ctrl_val |= ACPICTRL_EN;
  1084. pci_bus_write_config_dword(pci_dev->bus, devfn, ACPICTRL, ctrl_val);
  1085. /*
  1086. * We must access the NO_REBOOT bit over the Primary to Sideband
  1087. * bridge (P2SB). The BIOS prevents the P2SB device from being
  1088. * enumerated by the PCI subsystem, so we need to unhide/hide it
  1089. * to lookup the P2SB BAR.
  1090. */
  1091. spin_lock(&p2sb_spinlock);
  1092. devfn = PCI_DEVFN(PCI_SLOT(pci_dev->devfn), 1);
  1093. /* Unhide the P2SB device */
  1094. pci_bus_write_config_byte(pci_dev->bus, devfn, 0xe1, 0x0);
  1095. pci_bus_read_config_dword(pci_dev->bus, devfn, SBREG_BAR, &base_addr);
  1096. base64_addr = base_addr & 0xfffffff0;
  1097. pci_bus_read_config_dword(pci_dev->bus, devfn, SBREG_BAR + 0x4, &base_addr);
  1098. base64_addr |= (u64)base_addr << 32;
  1099. /* Hide the P2SB device */
  1100. pci_bus_write_config_byte(pci_dev->bus, devfn, 0xe1, 0x1);
  1101. spin_unlock(&p2sb_spinlock);
  1102. res = &tco_res[ICH_RES_MEM_OFF];
  1103. if (pci_dev->device == PCI_DEVICE_ID_INTEL_DNV_SMBUS)
  1104. res->start = (resource_size_t)base64_addr + SBREG_SMBCTRL_DNV;
  1105. else
  1106. res->start = (resource_size_t)base64_addr + SBREG_SMBCTRL;
  1107. res->end = res->start + 3;
  1108. res->flags = IORESOURCE_MEM;
  1109. pdev = platform_device_register_resndata(&pci_dev->dev, "iTCO_wdt", -1,
  1110. tco_res, 3, &tco_platform_data,
  1111. sizeof(tco_platform_data));
  1112. if (IS_ERR(pdev)) {
  1113. dev_warn(&pci_dev->dev, "failed to create iTCO device\n");
  1114. return;
  1115. }
  1116. priv->tco_pdev = pdev;
  1117. }
  1118. #ifdef CONFIG_ACPI
  1119. static bool i801_acpi_is_smbus_ioport(const struct i801_priv *priv,
  1120. acpi_physical_address address)
  1121. {
  1122. return address >= priv->smba &&
  1123. address <= pci_resource_end(priv->pci_dev, SMBBAR);
  1124. }
  1125. static acpi_status
  1126. i801_acpi_io_handler(u32 function, acpi_physical_address address, u32 bits,
  1127. u64 *value, void *handler_context, void *region_context)
  1128. {
  1129. struct i801_priv *priv = handler_context;
  1130. struct pci_dev *pdev = priv->pci_dev;
  1131. acpi_status status;
  1132. /*
  1133. * Once BIOS AML code touches the OpRegion we warn and inhibit any
  1134. * further access from the driver itself. This device is now owned
  1135. * by the system firmware.
  1136. */
  1137. mutex_lock(&priv->acpi_lock);
  1138. if (!priv->acpi_reserved && i801_acpi_is_smbus_ioport(priv, address)) {
  1139. priv->acpi_reserved = true;
  1140. dev_warn(&pdev->dev, "BIOS is accessing SMBus registers\n");
  1141. dev_warn(&pdev->dev, "Driver SMBus register access inhibited\n");
  1142. }
  1143. if ((function & ACPI_IO_MASK) == ACPI_READ)
  1144. status = acpi_os_read_port(address, (u32 *)value, bits);
  1145. else
  1146. status = acpi_os_write_port(address, (u32)*value, bits);
  1147. mutex_unlock(&priv->acpi_lock);
  1148. return status;
  1149. }
  1150. static int i801_acpi_probe(struct i801_priv *priv)
  1151. {
  1152. struct acpi_device *adev;
  1153. acpi_status status;
  1154. adev = ACPI_COMPANION(&priv->pci_dev->dev);
  1155. if (adev) {
  1156. status = acpi_install_address_space_handler(adev->handle,
  1157. ACPI_ADR_SPACE_SYSTEM_IO, i801_acpi_io_handler,
  1158. NULL, priv);
  1159. if (ACPI_SUCCESS(status))
  1160. return 0;
  1161. }
  1162. return acpi_check_resource_conflict(&priv->pci_dev->resource[SMBBAR]);
  1163. }
  1164. static void i801_acpi_remove(struct i801_priv *priv)
  1165. {
  1166. struct acpi_device *adev;
  1167. adev = ACPI_COMPANION(&priv->pci_dev->dev);
  1168. if (!adev)
  1169. return;
  1170. acpi_remove_address_space_handler(adev->handle,
  1171. ACPI_ADR_SPACE_SYSTEM_IO, i801_acpi_io_handler);
  1172. }
  1173. #else
  1174. static inline int i801_acpi_probe(struct i801_priv *priv) { return 0; }
  1175. static inline void i801_acpi_remove(struct i801_priv *priv) { }
  1176. #endif
  1177. static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id)
  1178. {
  1179. unsigned char temp;
  1180. int err, i;
  1181. struct i801_priv *priv;
  1182. priv = devm_kzalloc(&dev->dev, sizeof(*priv), GFP_KERNEL);
  1183. if (!priv)
  1184. return -ENOMEM;
  1185. i2c_set_adapdata(&priv->adapter, priv);
  1186. priv->adapter.owner = THIS_MODULE;
  1187. priv->adapter.class = i801_get_adapter_class(priv);
  1188. priv->adapter.algo = &smbus_algorithm;
  1189. priv->adapter.dev.parent = &dev->dev;
  1190. ACPI_COMPANION_SET(&priv->adapter.dev, ACPI_COMPANION(&dev->dev));
  1191. priv->adapter.retries = 3;
  1192. mutex_init(&priv->acpi_lock);
  1193. priv->pci_dev = dev;
  1194. switch (dev->device) {
  1195. case PCI_DEVICE_ID_INTEL_SUNRISEPOINT_H_SMBUS:
  1196. case PCI_DEVICE_ID_INTEL_SUNRISEPOINT_LP_SMBUS:
  1197. case PCI_DEVICE_ID_INTEL_LEWISBURG_SMBUS:
  1198. case PCI_DEVICE_ID_INTEL_LEWISBURG_SSKU_SMBUS:
  1199. case PCI_DEVICE_ID_INTEL_DNV_SMBUS:
  1200. priv->features |= FEATURE_I2C_BLOCK_READ;
  1201. priv->features |= FEATURE_IRQ;
  1202. priv->features |= FEATURE_SMBUS_PEC;
  1203. priv->features |= FEATURE_BLOCK_BUFFER;
  1204. priv->features |= FEATURE_TCO;
  1205. break;
  1206. case PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF0:
  1207. case PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF1:
  1208. case PCI_DEVICE_ID_INTEL_PATSBURG_SMBUS_IDF2:
  1209. case PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS0:
  1210. case PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS1:
  1211. case PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS2:
  1212. priv->features |= FEATURE_IDF;
  1213. /* fall through */
  1214. default:
  1215. priv->features |= FEATURE_I2C_BLOCK_READ;
  1216. priv->features |= FEATURE_IRQ;
  1217. /* fall through */
  1218. case PCI_DEVICE_ID_INTEL_82801DB_3:
  1219. priv->features |= FEATURE_SMBUS_PEC;
  1220. priv->features |= FEATURE_BLOCK_BUFFER;
  1221. /* fall through */
  1222. case PCI_DEVICE_ID_INTEL_82801CA_3:
  1223. case PCI_DEVICE_ID_INTEL_82801BA_2:
  1224. case PCI_DEVICE_ID_INTEL_82801AB_3:
  1225. case PCI_DEVICE_ID_INTEL_82801AA_3:
  1226. break;
  1227. }
  1228. /* Disable features on user request */
  1229. for (i = 0; i < ARRAY_SIZE(i801_feature_names); i++) {
  1230. if (priv->features & disable_features & (1 << i))
  1231. dev_notice(&dev->dev, "%s disabled by user\n",
  1232. i801_feature_names[i]);
  1233. }
  1234. priv->features &= ~disable_features;
  1235. err = pcim_enable_device(dev);
  1236. if (err) {
  1237. dev_err(&dev->dev, "Failed to enable SMBus PCI device (%d)\n",
  1238. err);
  1239. return err;
  1240. }
  1241. pcim_pin_device(dev);
  1242. /* Determine the address of the SMBus area */
  1243. priv->smba = pci_resource_start(dev, SMBBAR);
  1244. if (!priv->smba) {
  1245. dev_err(&dev->dev,
  1246. "SMBus base address uninitialized, upgrade BIOS\n");
  1247. return -ENODEV;
  1248. }
  1249. if (i801_acpi_probe(priv))
  1250. return -ENODEV;
  1251. err = pcim_iomap_regions(dev, 1 << SMBBAR,
  1252. dev_driver_string(&dev->dev));
  1253. if (err) {
  1254. dev_err(&dev->dev,
  1255. "Failed to request SMBus region 0x%lx-0x%Lx\n",
  1256. priv->smba,
  1257. (unsigned long long)pci_resource_end(dev, SMBBAR));
  1258. i801_acpi_remove(priv);
  1259. return err;
  1260. }
  1261. pci_read_config_byte(priv->pci_dev, SMBHSTCFG, &temp);
  1262. priv->original_hstcfg = temp;
  1263. temp &= ~SMBHSTCFG_I2C_EN; /* SMBus timing */
  1264. if (!(temp & SMBHSTCFG_HST_EN)) {
  1265. dev_info(&dev->dev, "Enabling SMBus device\n");
  1266. temp |= SMBHSTCFG_HST_EN;
  1267. }
  1268. pci_write_config_byte(priv->pci_dev, SMBHSTCFG, temp);
  1269. if (temp & SMBHSTCFG_SMB_SMI_EN) {
  1270. dev_dbg(&dev->dev, "SMBus using interrupt SMI#\n");
  1271. /* Disable SMBus interrupt feature if SMBus using SMI# */
  1272. priv->features &= ~FEATURE_IRQ;
  1273. }
  1274. /* Clear special mode bits */
  1275. if (priv->features & (FEATURE_SMBUS_PEC | FEATURE_BLOCK_BUFFER))
  1276. outb_p(inb_p(SMBAUXCTL(priv)) &
  1277. ~(SMBAUXCTL_CRC | SMBAUXCTL_E32B), SMBAUXCTL(priv));
  1278. /* Default timeout in interrupt mode: 200 ms */
  1279. priv->adapter.timeout = HZ / 5;
  1280. if (priv->features & FEATURE_IRQ) {
  1281. u16 pcictl, pcists;
  1282. /* Complain if an interrupt is already pending */
  1283. pci_read_config_word(priv->pci_dev, SMBPCISTS, &pcists);
  1284. if (pcists & SMBPCISTS_INTS)
  1285. dev_warn(&dev->dev, "An interrupt is pending!\n");
  1286. /* Check if interrupts have been disabled */
  1287. pci_read_config_word(priv->pci_dev, SMBPCICTL, &pcictl);
  1288. if (pcictl & SMBPCICTL_INTDIS) {
  1289. dev_info(&dev->dev, "Interrupts are disabled\n");
  1290. priv->features &= ~FEATURE_IRQ;
  1291. }
  1292. }
  1293. if (priv->features & FEATURE_IRQ) {
  1294. init_waitqueue_head(&priv->waitq);
  1295. err = devm_request_irq(&dev->dev, dev->irq, i801_isr,
  1296. IRQF_SHARED,
  1297. dev_driver_string(&dev->dev), priv);
  1298. if (err) {
  1299. dev_err(&dev->dev, "Failed to allocate irq %d: %d\n",
  1300. dev->irq, err);
  1301. priv->features &= ~FEATURE_IRQ;
  1302. }
  1303. }
  1304. dev_info(&dev->dev, "SMBus using %s\n",
  1305. priv->features & FEATURE_IRQ ? "PCI interrupt" : "polling");
  1306. i801_add_tco(priv);
  1307. snprintf(priv->adapter.name, sizeof(priv->adapter.name),
  1308. "SMBus I801 adapter at %04lx", priv->smba);
  1309. err = i2c_add_adapter(&priv->adapter);
  1310. if (err) {
  1311. dev_err(&dev->dev, "Failed to add SMBus adapter\n");
  1312. i801_acpi_remove(priv);
  1313. return err;
  1314. }
  1315. i801_probe_optional_slaves(priv);
  1316. /* We ignore errors - multiplexing is optional */
  1317. i801_add_mux(priv);
  1318. pci_set_drvdata(dev, priv);
  1319. return 0;
  1320. }
  1321. static void i801_remove(struct pci_dev *dev)
  1322. {
  1323. struct i801_priv *priv = pci_get_drvdata(dev);
  1324. i801_del_mux(priv);
  1325. i2c_del_adapter(&priv->adapter);
  1326. i801_acpi_remove(priv);
  1327. pci_write_config_byte(dev, SMBHSTCFG, priv->original_hstcfg);
  1328. platform_device_unregister(priv->tco_pdev);
  1329. /*
  1330. * do not call pci_disable_device(dev) since it can cause hard hangs on
  1331. * some systems during power-off (eg. Fujitsu-Siemens Lifebook E8010)
  1332. */
  1333. }
  1334. #ifdef CONFIG_PM
  1335. static int i801_suspend(struct pci_dev *dev, pm_message_t mesg)
  1336. {
  1337. struct i801_priv *priv = pci_get_drvdata(dev);
  1338. pci_save_state(dev);
  1339. pci_write_config_byte(dev, SMBHSTCFG, priv->original_hstcfg);
  1340. pci_set_power_state(dev, pci_choose_state(dev, mesg));
  1341. return 0;
  1342. }
  1343. static int i801_resume(struct pci_dev *dev)
  1344. {
  1345. pci_set_power_state(dev, PCI_D0);
  1346. pci_restore_state(dev);
  1347. return 0;
  1348. }
  1349. #else
  1350. #define i801_suspend NULL
  1351. #define i801_resume NULL
  1352. #endif
  1353. static struct pci_driver i801_driver = {
  1354. .name = "i801_smbus",
  1355. .id_table = i801_ids,
  1356. .probe = i801_probe,
  1357. .remove = i801_remove,
  1358. .suspend = i801_suspend,
  1359. .resume = i801_resume,
  1360. };
  1361. static int __init i2c_i801_init(void)
  1362. {
  1363. if (dmi_name_in_vendors("FUJITSU"))
  1364. input_apanel_init();
  1365. return pci_register_driver(&i801_driver);
  1366. }
  1367. static void __exit i2c_i801_exit(void)
  1368. {
  1369. pci_unregister_driver(&i801_driver);
  1370. }
  1371. MODULE_AUTHOR("Mark D. Studebaker <mdsxyz123@yahoo.com>, Jean Delvare <jdelvare@suse.de>");
  1372. MODULE_DESCRIPTION("I801 SMBus driver");
  1373. MODULE_LICENSE("GPL");
  1374. module_init(i2c_i801_init);
  1375. module_exit(i2c_i801_exit);