i2c-omap.c 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * TI OMAP I2C master mode driver
  4. *
  5. * Copyright (C) 2003 MontaVista Software, Inc.
  6. * Copyright (C) 2005 Nokia Corporation
  7. * Copyright (C) 2004 - 2007 Texas Instruments.
  8. *
  9. * Originally written by MontaVista Software, Inc.
  10. * Additional contributions by:
  11. * Tony Lindgren <tony@atomide.com>
  12. * Imre Deak <imre.deak@nokia.com>
  13. * Juha Yrjölä <juha.yrjola@solidboot.com>
  14. * Syed Khasim <x0khasim@ti.com>
  15. * Nishant Menon <nm@ti.com>
  16. */
  17. #include <linux/module.h>
  18. #include <linux/delay.h>
  19. #include <linux/i2c.h>
  20. #include <linux/err.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/completion.h>
  23. #include <linux/platform_device.h>
  24. #include <linux/clk.h>
  25. #include <linux/io.h>
  26. #include <linux/mux/consumer.h>
  27. #include <linux/of.h>
  28. #include <linux/slab.h>
  29. #include <linux/platform_data/i2c-omap.h>
  30. #include <linux/pm_runtime.h>
  31. #include <linux/pinctrl/consumer.h>
  32. #include <linux/property.h>
  33. /* I2C controller revisions */
  34. #define OMAP_I2C_OMAP1_REV_2 0x20
  35. /* I2C controller revisions present on specific hardware */
  36. #define OMAP_I2C_REV_ON_2430 0x00000036
  37. #define OMAP_I2C_REV_ON_3430_3530 0x0000003C
  38. #define OMAP_I2C_REV_ON_3630 0x00000040
  39. #define OMAP_I2C_REV_ON_4430_PLUS 0x50400002
  40. /* timeout waiting for the controller to respond */
  41. #define OMAP_I2C_TIMEOUT (msecs_to_jiffies(1000))
  42. /* timeout for pm runtime autosuspend */
  43. #define OMAP_I2C_PM_TIMEOUT 1000 /* ms */
  44. /* timeout for making decision on bus free status */
  45. #define OMAP_I2C_BUS_FREE_TIMEOUT (msecs_to_jiffies(10))
  46. /* For OMAP3 I2C_IV has changed to I2C_WE (wakeup enable) */
  47. enum {
  48. OMAP_I2C_REV_REG = 0,
  49. OMAP_I2C_IE_REG,
  50. OMAP_I2C_STAT_REG,
  51. OMAP_I2C_IV_REG,
  52. OMAP_I2C_WE_REG,
  53. OMAP_I2C_SYSS_REG,
  54. OMAP_I2C_BUF_REG,
  55. OMAP_I2C_CNT_REG,
  56. OMAP_I2C_DATA_REG,
  57. OMAP_I2C_SYSC_REG,
  58. OMAP_I2C_CON_REG,
  59. OMAP_I2C_OA_REG,
  60. OMAP_I2C_SA_REG,
  61. OMAP_I2C_PSC_REG,
  62. OMAP_I2C_SCLL_REG,
  63. OMAP_I2C_SCLH_REG,
  64. OMAP_I2C_SYSTEST_REG,
  65. OMAP_I2C_BUFSTAT_REG,
  66. /* only on OMAP4430 */
  67. OMAP_I2C_IP_V2_REVNB_LO,
  68. OMAP_I2C_IP_V2_REVNB_HI,
  69. OMAP_I2C_IP_V2_IRQSTATUS_RAW,
  70. OMAP_I2C_IP_V2_IRQENABLE_SET,
  71. OMAP_I2C_IP_V2_IRQENABLE_CLR,
  72. };
  73. /* I2C Interrupt Enable Register (OMAP_I2C_IE): */
  74. #define OMAP_I2C_IE_XDR (1 << 14) /* TX Buffer drain int enable */
  75. #define OMAP_I2C_IE_RDR (1 << 13) /* RX Buffer drain int enable */
  76. #define OMAP_I2C_IE_XRDY (1 << 4) /* TX data ready int enable */
  77. #define OMAP_I2C_IE_RRDY (1 << 3) /* RX data ready int enable */
  78. #define OMAP_I2C_IE_ARDY (1 << 2) /* Access ready int enable */
  79. #define OMAP_I2C_IE_NACK (1 << 1) /* No ack interrupt enable */
  80. #define OMAP_I2C_IE_AL (1 << 0) /* Arbitration lost int ena */
  81. /* I2C Status Register (OMAP_I2C_STAT): */
  82. #define OMAP_I2C_STAT_XDR (1 << 14) /* TX Buffer draining */
  83. #define OMAP_I2C_STAT_RDR (1 << 13) /* RX Buffer draining */
  84. #define OMAP_I2C_STAT_BB (1 << 12) /* Bus busy */
  85. #define OMAP_I2C_STAT_ROVR (1 << 11) /* Receive overrun */
  86. #define OMAP_I2C_STAT_XUDF (1 << 10) /* Transmit underflow */
  87. #define OMAP_I2C_STAT_AAS (1 << 9) /* Address as slave */
  88. #define OMAP_I2C_STAT_BF (1 << 8) /* Bus Free */
  89. #define OMAP_I2C_STAT_XRDY (1 << 4) /* Transmit data ready */
  90. #define OMAP_I2C_STAT_RRDY (1 << 3) /* Receive data ready */
  91. #define OMAP_I2C_STAT_ARDY (1 << 2) /* Register access ready */
  92. #define OMAP_I2C_STAT_NACK (1 << 1) /* No ack interrupt enable */
  93. #define OMAP_I2C_STAT_AL (1 << 0) /* Arbitration lost int ena */
  94. /* I2C WE wakeup enable register */
  95. #define OMAP_I2C_WE_XDR_WE (1 << 14) /* TX drain wakup */
  96. #define OMAP_I2C_WE_RDR_WE (1 << 13) /* RX drain wakeup */
  97. #define OMAP_I2C_WE_AAS_WE (1 << 9) /* Address as slave wakeup*/
  98. #define OMAP_I2C_WE_BF_WE (1 << 8) /* Bus free wakeup */
  99. #define OMAP_I2C_WE_STC_WE (1 << 6) /* Start condition wakeup */
  100. #define OMAP_I2C_WE_GC_WE (1 << 5) /* General call wakeup */
  101. #define OMAP_I2C_WE_DRDY_WE (1 << 3) /* TX/RX data ready wakeup */
  102. #define OMAP_I2C_WE_ARDY_WE (1 << 2) /* Reg access ready wakeup */
  103. #define OMAP_I2C_WE_NACK_WE (1 << 1) /* No acknowledgment wakeup */
  104. #define OMAP_I2C_WE_AL_WE (1 << 0) /* Arbitration lost wakeup */
  105. #define OMAP_I2C_WE_ALL (OMAP_I2C_WE_XDR_WE | OMAP_I2C_WE_RDR_WE | \
  106. OMAP_I2C_WE_AAS_WE | OMAP_I2C_WE_BF_WE | \
  107. OMAP_I2C_WE_STC_WE | OMAP_I2C_WE_GC_WE | \
  108. OMAP_I2C_WE_DRDY_WE | OMAP_I2C_WE_ARDY_WE | \
  109. OMAP_I2C_WE_NACK_WE | OMAP_I2C_WE_AL_WE)
  110. /* I2C Buffer Configuration Register (OMAP_I2C_BUF): */
  111. #define OMAP_I2C_BUF_RDMA_EN (1 << 15) /* RX DMA channel enable */
  112. #define OMAP_I2C_BUF_RXFIF_CLR (1 << 14) /* RX FIFO Clear */
  113. #define OMAP_I2C_BUF_XDMA_EN (1 << 7) /* TX DMA channel enable */
  114. #define OMAP_I2C_BUF_TXFIF_CLR (1 << 6) /* TX FIFO Clear */
  115. /* I2C Configuration Register (OMAP_I2C_CON): */
  116. #define OMAP_I2C_CON_EN (1 << 15) /* I2C module enable */
  117. #define OMAP_I2C_CON_BE (1 << 14) /* Big endian mode */
  118. #define OMAP_I2C_CON_OPMODE_HS (1 << 12) /* High Speed support */
  119. #define OMAP_I2C_CON_STB (1 << 11) /* Start byte mode (master) */
  120. #define OMAP_I2C_CON_MST (1 << 10) /* Master/slave mode */
  121. #define OMAP_I2C_CON_TRX (1 << 9) /* TX/RX mode (master only) */
  122. #define OMAP_I2C_CON_XA (1 << 8) /* Expand address */
  123. #define OMAP_I2C_CON_RM (1 << 2) /* Repeat mode (master only) */
  124. #define OMAP_I2C_CON_STP (1 << 1) /* Stop cond (master only) */
  125. #define OMAP_I2C_CON_STT (1 << 0) /* Start condition (master) */
  126. /* I2C SCL time value when Master */
  127. #define OMAP_I2C_SCLL_HSSCLL 8
  128. #define OMAP_I2C_SCLH_HSSCLH 8
  129. /* I2C System Test Register (OMAP_I2C_SYSTEST): */
  130. #define OMAP_I2C_SYSTEST_ST_EN (1 << 15) /* System test enable */
  131. #define OMAP_I2C_SYSTEST_FREE (1 << 14) /* Free running mode */
  132. #define OMAP_I2C_SYSTEST_TMODE_MASK (3 << 12) /* Test mode select */
  133. #define OMAP_I2C_SYSTEST_TMODE_SHIFT (12) /* Test mode select */
  134. /* Functional mode */
  135. #define OMAP_I2C_SYSTEST_SCL_I_FUNC (1 << 8) /* SCL line input value */
  136. #define OMAP_I2C_SYSTEST_SCL_O_FUNC (1 << 7) /* SCL line output value */
  137. #define OMAP_I2C_SYSTEST_SDA_I_FUNC (1 << 6) /* SDA line input value */
  138. #define OMAP_I2C_SYSTEST_SDA_O_FUNC (1 << 5) /* SDA line output value */
  139. /* SDA/SCL IO mode */
  140. #define OMAP_I2C_SYSTEST_SCL_I (1 << 3) /* SCL line sense in */
  141. #define OMAP_I2C_SYSTEST_SCL_O (1 << 2) /* SCL line drive out */
  142. #define OMAP_I2C_SYSTEST_SDA_I (1 << 1) /* SDA line sense in */
  143. #define OMAP_I2C_SYSTEST_SDA_O (1 << 0) /* SDA line drive out */
  144. /* OCP_SYSSTATUS bit definitions */
  145. #define SYSS_RESETDONE_MASK (1 << 0)
  146. /* OCP_SYSCONFIG bit definitions */
  147. #define SYSC_CLOCKACTIVITY_MASK (0x3 << 8)
  148. #define SYSC_SIDLEMODE_MASK (0x3 << 3)
  149. #define SYSC_ENAWAKEUP_MASK (1 << 2)
  150. #define SYSC_SOFTRESET_MASK (1 << 1)
  151. #define SYSC_AUTOIDLE_MASK (1 << 0)
  152. #define SYSC_IDLEMODE_SMART 0x2
  153. #define SYSC_CLOCKACTIVITY_FCLK 0x2
  154. /* Errata definitions */
  155. #define I2C_OMAP_ERRATA_I207 (1 << 0)
  156. #define I2C_OMAP_ERRATA_I462 (1 << 1)
  157. #define OMAP_I2C_IP_V2_INTERRUPTS_MASK 0x6FFF
  158. struct omap_i2c_dev {
  159. struct device *dev;
  160. void __iomem *base; /* virtual */
  161. int irq;
  162. int reg_shift; /* bit shift for I2C register addresses */
  163. struct completion cmd_complete;
  164. struct resource *ioarea;
  165. u32 latency; /* maximum mpu wkup latency */
  166. void (*set_mpu_wkup_lat)(struct device *dev,
  167. long latency);
  168. u32 speed; /* Speed of bus in kHz */
  169. u32 flags;
  170. u16 scheme;
  171. u16 cmd_err;
  172. u8 *buf;
  173. u8 *regs;
  174. size_t buf_len;
  175. struct i2c_adapter adapter;
  176. u8 threshold;
  177. u8 fifo_size; /* use as flag and value
  178. * fifo_size==0 implies no fifo
  179. * if set, should be trsh+1
  180. */
  181. u32 rev;
  182. unsigned b_hw:1; /* bad h/w fixes */
  183. unsigned bb_valid:1; /* true when BB-bit reflects
  184. * the I2C bus state
  185. */
  186. unsigned receiver:1; /* true when we're in receiver mode */
  187. u16 iestate; /* Saved interrupt register */
  188. u16 pscstate;
  189. u16 scllstate;
  190. u16 sclhstate;
  191. u16 syscstate;
  192. u16 westate;
  193. u16 errata;
  194. struct mux_state *mux_state;
  195. };
  196. static const u8 reg_map_ip_v1[] = {
  197. [OMAP_I2C_REV_REG] = 0x00,
  198. [OMAP_I2C_IE_REG] = 0x01,
  199. [OMAP_I2C_STAT_REG] = 0x02,
  200. [OMAP_I2C_IV_REG] = 0x03,
  201. [OMAP_I2C_WE_REG] = 0x03,
  202. [OMAP_I2C_SYSS_REG] = 0x04,
  203. [OMAP_I2C_BUF_REG] = 0x05,
  204. [OMAP_I2C_CNT_REG] = 0x06,
  205. [OMAP_I2C_DATA_REG] = 0x07,
  206. [OMAP_I2C_SYSC_REG] = 0x08,
  207. [OMAP_I2C_CON_REG] = 0x09,
  208. [OMAP_I2C_OA_REG] = 0x0a,
  209. [OMAP_I2C_SA_REG] = 0x0b,
  210. [OMAP_I2C_PSC_REG] = 0x0c,
  211. [OMAP_I2C_SCLL_REG] = 0x0d,
  212. [OMAP_I2C_SCLH_REG] = 0x0e,
  213. [OMAP_I2C_SYSTEST_REG] = 0x0f,
  214. [OMAP_I2C_BUFSTAT_REG] = 0x10,
  215. };
  216. static const u8 reg_map_ip_v2[] = {
  217. [OMAP_I2C_REV_REG] = 0x04,
  218. [OMAP_I2C_IE_REG] = 0x2c,
  219. [OMAP_I2C_STAT_REG] = 0x28,
  220. [OMAP_I2C_IV_REG] = 0x34,
  221. [OMAP_I2C_WE_REG] = 0x34,
  222. [OMAP_I2C_SYSS_REG] = 0x90,
  223. [OMAP_I2C_BUF_REG] = 0x94,
  224. [OMAP_I2C_CNT_REG] = 0x98,
  225. [OMAP_I2C_DATA_REG] = 0x9c,
  226. [OMAP_I2C_SYSC_REG] = 0x10,
  227. [OMAP_I2C_CON_REG] = 0xa4,
  228. [OMAP_I2C_OA_REG] = 0xa8,
  229. [OMAP_I2C_SA_REG] = 0xac,
  230. [OMAP_I2C_PSC_REG] = 0xb0,
  231. [OMAP_I2C_SCLL_REG] = 0xb4,
  232. [OMAP_I2C_SCLH_REG] = 0xb8,
  233. [OMAP_I2C_SYSTEST_REG] = 0xbC,
  234. [OMAP_I2C_BUFSTAT_REG] = 0xc0,
  235. [OMAP_I2C_IP_V2_REVNB_LO] = 0x00,
  236. [OMAP_I2C_IP_V2_REVNB_HI] = 0x04,
  237. [OMAP_I2C_IP_V2_IRQSTATUS_RAW] = 0x24,
  238. [OMAP_I2C_IP_V2_IRQENABLE_SET] = 0x2c,
  239. [OMAP_I2C_IP_V2_IRQENABLE_CLR] = 0x30,
  240. };
  241. static int omap_i2c_xfer_data(struct omap_i2c_dev *omap);
  242. static inline void omap_i2c_write_reg(struct omap_i2c_dev *omap,
  243. int reg, u16 val)
  244. {
  245. writew_relaxed(val, omap->base +
  246. (omap->regs[reg] << omap->reg_shift));
  247. }
  248. static inline u16 omap_i2c_read_reg(struct omap_i2c_dev *omap, int reg)
  249. {
  250. return readw_relaxed(omap->base +
  251. (omap->regs[reg] << omap->reg_shift));
  252. }
  253. static void __omap_i2c_init(struct omap_i2c_dev *omap)
  254. {
  255. omap_i2c_write_reg(omap, OMAP_I2C_CON_REG, 0);
  256. /* Setup clock prescaler to obtain approx 12MHz I2C module clock: */
  257. omap_i2c_write_reg(omap, OMAP_I2C_PSC_REG, omap->pscstate);
  258. /* SCL low and high time values */
  259. omap_i2c_write_reg(omap, OMAP_I2C_SCLL_REG, omap->scllstate);
  260. omap_i2c_write_reg(omap, OMAP_I2C_SCLH_REG, omap->sclhstate);
  261. if (omap->rev >= OMAP_I2C_REV_ON_3430_3530)
  262. omap_i2c_write_reg(omap, OMAP_I2C_WE_REG, omap->westate);
  263. /* Take the I2C module out of reset: */
  264. omap_i2c_write_reg(omap, OMAP_I2C_CON_REG, OMAP_I2C_CON_EN);
  265. /*
  266. * NOTE: right after setting CON_EN, STAT_BB could be 0 while the
  267. * bus is busy. It will be changed to 1 on the next IP FCLK clock.
  268. * udelay(1) will be enough to fix that.
  269. */
  270. /*
  271. * Don't write to this register if the IE state is 0 as it can
  272. * cause deadlock.
  273. */
  274. if (omap->iestate)
  275. omap_i2c_write_reg(omap, OMAP_I2C_IE_REG, omap->iestate);
  276. }
  277. static int omap_i2c_reset(struct omap_i2c_dev *omap)
  278. {
  279. unsigned long timeout;
  280. u16 sysc;
  281. if (omap->rev >= OMAP_I2C_OMAP1_REV_2) {
  282. sysc = omap_i2c_read_reg(omap, OMAP_I2C_SYSC_REG);
  283. /* Disable I2C controller before soft reset */
  284. omap_i2c_write_reg(omap, OMAP_I2C_CON_REG,
  285. omap_i2c_read_reg(omap, OMAP_I2C_CON_REG) &
  286. ~(OMAP_I2C_CON_EN));
  287. omap_i2c_write_reg(omap, OMAP_I2C_SYSC_REG, SYSC_SOFTRESET_MASK);
  288. /* For some reason we need to set the EN bit before the
  289. * reset done bit gets set. */
  290. timeout = jiffies + OMAP_I2C_TIMEOUT;
  291. omap_i2c_write_reg(omap, OMAP_I2C_CON_REG, OMAP_I2C_CON_EN);
  292. while (!(omap_i2c_read_reg(omap, OMAP_I2C_SYSS_REG) &
  293. SYSS_RESETDONE_MASK)) {
  294. if (time_after(jiffies, timeout)) {
  295. dev_warn(omap->dev, "timeout waiting "
  296. "for controller reset\n");
  297. return -ETIMEDOUT;
  298. }
  299. msleep(1);
  300. }
  301. /* SYSC register is cleared by the reset; rewrite it */
  302. omap_i2c_write_reg(omap, OMAP_I2C_SYSC_REG, sysc);
  303. if (omap->rev > OMAP_I2C_REV_ON_3430_3530) {
  304. /* Schedule I2C-bus monitoring on the next transfer */
  305. omap->bb_valid = 0;
  306. }
  307. }
  308. return 0;
  309. }
  310. static int omap_i2c_init(struct omap_i2c_dev *omap)
  311. {
  312. u16 psc = 0, scll = 0, sclh = 0;
  313. u16 fsscll = 0, fssclh = 0, hsscll = 0, hssclh = 0;
  314. unsigned long fclk_rate = 12000000;
  315. unsigned long internal_clk = 0;
  316. struct clk *fclk;
  317. int error;
  318. if (omap->rev >= OMAP_I2C_REV_ON_3430_3530) {
  319. /*
  320. * Enabling all wakup sources to stop I2C freezing on
  321. * WFI instruction.
  322. * REVISIT: Some wkup sources might not be needed.
  323. */
  324. omap->westate = OMAP_I2C_WE_ALL;
  325. }
  326. if (omap->flags & OMAP_I2C_FLAG_ALWAYS_ARMXOR_CLK) {
  327. /*
  328. * The I2C functional clock is the armxor_ck, so there's
  329. * no need to get "armxor_ck" separately. Now, if OMAP2420
  330. * always returns 12MHz for the functional clock, we can
  331. * do this bit unconditionally.
  332. */
  333. fclk = clk_get(omap->dev, "fck");
  334. if (IS_ERR(fclk)) {
  335. error = PTR_ERR(fclk);
  336. dev_err(omap->dev, "could not get fck: %i\n", error);
  337. return error;
  338. }
  339. fclk_rate = clk_get_rate(fclk);
  340. clk_put(fclk);
  341. /* TRM for 5912 says the I2C clock must be prescaled to be
  342. * between 7 - 12 MHz. The XOR input clock is typically
  343. * 12, 13 or 19.2 MHz. So we should have code that produces:
  344. *
  345. * XOR MHz Divider Prescaler
  346. * 12 1 0
  347. * 13 2 1
  348. * 19.2 2 1
  349. */
  350. if (fclk_rate > 12000000)
  351. psc = fclk_rate / 12000000;
  352. }
  353. if (!(omap->flags & OMAP_I2C_FLAG_SIMPLE_CLOCK)) {
  354. /*
  355. * HSI2C controller internal clk rate should be 19.2 Mhz for
  356. * HS and for all modes on 2430. On 34xx we can use lower rate
  357. * to get longer filter period for better noise suppression.
  358. * The filter is iclk (fclk for HS) period.
  359. */
  360. if (omap->speed > 400 ||
  361. omap->flags & OMAP_I2C_FLAG_FORCE_19200_INT_CLK)
  362. internal_clk = 19200;
  363. else if (omap->speed > 100)
  364. internal_clk = 9600;
  365. else
  366. internal_clk = 4000;
  367. fclk = clk_get(omap->dev, "fck");
  368. if (IS_ERR(fclk)) {
  369. error = PTR_ERR(fclk);
  370. dev_err(omap->dev, "could not get fck: %i\n", error);
  371. return error;
  372. }
  373. fclk_rate = clk_get_rate(fclk) / 1000;
  374. clk_put(fclk);
  375. /* Compute prescaler divisor */
  376. psc = fclk_rate / internal_clk;
  377. psc = psc - 1;
  378. /* If configured for High Speed */
  379. if (omap->speed > 400) {
  380. unsigned long scl;
  381. /* For first phase of HS mode */
  382. scl = internal_clk / 400;
  383. fsscll = scl - (scl / 3) - 7;
  384. fssclh = (scl / 3) - 5;
  385. /* For second phase of HS mode */
  386. scl = fclk_rate / omap->speed;
  387. hsscll = scl - (scl / 3) - 7;
  388. hssclh = (scl / 3) - 5;
  389. } else if (omap->speed > 100) {
  390. unsigned long scl;
  391. /* Fast mode */
  392. scl = internal_clk / omap->speed;
  393. fsscll = scl - (scl / 3) - 7;
  394. fssclh = (scl / 3) - 5;
  395. } else {
  396. /* Standard mode */
  397. fsscll = internal_clk / (omap->speed * 2) - 7;
  398. fssclh = internal_clk / (omap->speed * 2) - 5;
  399. }
  400. scll = (hsscll << OMAP_I2C_SCLL_HSSCLL) | fsscll;
  401. sclh = (hssclh << OMAP_I2C_SCLH_HSSCLH) | fssclh;
  402. } else {
  403. /* Program desired operating rate */
  404. fclk_rate /= (psc + 1) * 1000;
  405. if (psc > 2)
  406. psc = 2;
  407. scll = fclk_rate / (omap->speed * 2) - 7 + psc;
  408. sclh = fclk_rate / (omap->speed * 2) - 7 + psc;
  409. }
  410. omap->iestate = (OMAP_I2C_IE_XRDY | OMAP_I2C_IE_RRDY |
  411. OMAP_I2C_IE_ARDY | OMAP_I2C_IE_NACK |
  412. OMAP_I2C_IE_AL) | ((omap->fifo_size) ?
  413. (OMAP_I2C_IE_RDR | OMAP_I2C_IE_XDR) : 0);
  414. omap->pscstate = psc;
  415. omap->scllstate = scll;
  416. omap->sclhstate = sclh;
  417. if (omap->rev <= OMAP_I2C_REV_ON_3430_3530) {
  418. /* Not implemented */
  419. omap->bb_valid = 1;
  420. }
  421. __omap_i2c_init(omap);
  422. return 0;
  423. }
  424. /*
  425. * Try bus recovery, but only if SDA is actually low.
  426. */
  427. static int omap_i2c_recover_bus(struct omap_i2c_dev *omap)
  428. {
  429. u16 systest;
  430. systest = omap_i2c_read_reg(omap, OMAP_I2C_SYSTEST_REG);
  431. if ((systest & OMAP_I2C_SYSTEST_SCL_I_FUNC) &&
  432. (systest & OMAP_I2C_SYSTEST_SDA_I_FUNC))
  433. return 0; /* bus seems to already be fine */
  434. if (!(systest & OMAP_I2C_SYSTEST_SCL_I_FUNC))
  435. return -EBUSY; /* recovery would not fix SCL */
  436. return i2c_recover_bus(&omap->adapter);
  437. }
  438. /*
  439. * Waiting on Bus Busy
  440. */
  441. static int omap_i2c_wait_for_bb(struct omap_i2c_dev *omap)
  442. {
  443. unsigned long timeout;
  444. timeout = jiffies + OMAP_I2C_TIMEOUT;
  445. while (omap_i2c_read_reg(omap, OMAP_I2C_STAT_REG) & OMAP_I2C_STAT_BB) {
  446. if (time_after(jiffies, timeout))
  447. return omap_i2c_recover_bus(omap);
  448. msleep(1);
  449. }
  450. return 0;
  451. }
  452. /*
  453. * Wait while BB-bit doesn't reflect the I2C bus state
  454. *
  455. * In a multimaster environment, after IP software reset, BB-bit value doesn't
  456. * correspond to the current bus state. It may happen what BB-bit will be 0,
  457. * while the bus is busy due to another I2C master activity.
  458. * Here are BB-bit values after reset:
  459. * SDA SCL BB NOTES
  460. * 0 0 0 1, 2
  461. * 1 0 0 1, 2
  462. * 0 1 1
  463. * 1 1 0 3
  464. * Later, if IP detect SDA=0 and SCL=1 (ACK) or SDA 1->0 while SCL=1 (START)
  465. * combinations on the bus, it set BB-bit to 1.
  466. * If IP detect SDA 0->1 while SCL=1 (STOP) combination on the bus,
  467. * it set BB-bit to 0 and BF to 1.
  468. * BB and BF bits correctly tracks the bus state while IP is suspended
  469. * BB bit became valid on the next FCLK clock after CON_EN bit set
  470. *
  471. * NOTES:
  472. * 1. Any transfer started when BB=0 and bus is busy wouldn't be
  473. * completed by IP and results in controller timeout.
  474. * 2. Any transfer started when BB=0 and SCL=0 results in IP
  475. * starting to drive SDA low. In that case IP corrupt data
  476. * on the bus.
  477. * 3. Any transfer started in the middle of another master's transfer
  478. * results in unpredictable results and data corruption
  479. */
  480. static int omap_i2c_wait_for_bb_valid(struct omap_i2c_dev *omap)
  481. {
  482. unsigned long bus_free_timeout = 0;
  483. unsigned long timeout;
  484. int bus_free = 0;
  485. u16 stat, systest;
  486. if (omap->bb_valid)
  487. return 0;
  488. timeout = jiffies + OMAP_I2C_TIMEOUT;
  489. while (1) {
  490. stat = omap_i2c_read_reg(omap, OMAP_I2C_STAT_REG);
  491. /*
  492. * We will see BB or BF event in a case IP had detected any
  493. * activity on the I2C bus. Now IP correctly tracks the bus
  494. * state. BB-bit value is valid.
  495. */
  496. if (stat & (OMAP_I2C_STAT_BB | OMAP_I2C_STAT_BF))
  497. break;
  498. /*
  499. * Otherwise, we must look signals on the bus to make
  500. * the right decision.
  501. */
  502. systest = omap_i2c_read_reg(omap, OMAP_I2C_SYSTEST_REG);
  503. if ((systest & OMAP_I2C_SYSTEST_SCL_I_FUNC) &&
  504. (systest & OMAP_I2C_SYSTEST_SDA_I_FUNC)) {
  505. if (!bus_free) {
  506. bus_free_timeout = jiffies +
  507. OMAP_I2C_BUS_FREE_TIMEOUT;
  508. bus_free = 1;
  509. }
  510. /*
  511. * SDA and SCL lines was high for 10 ms without bus
  512. * activity detected. The bus is free. Consider
  513. * BB-bit value is valid.
  514. */
  515. if (time_after(jiffies, bus_free_timeout))
  516. break;
  517. } else {
  518. bus_free = 0;
  519. }
  520. if (time_after(jiffies, timeout)) {
  521. /*
  522. * SDA or SCL were low for the entire timeout without
  523. * any activity detected. Most likely, a slave is
  524. * locking up the bus with no master driving the clock.
  525. */
  526. dev_warn(omap->dev, "timeout waiting for bus ready\n");
  527. return omap_i2c_recover_bus(omap);
  528. }
  529. msleep(1);
  530. }
  531. omap->bb_valid = 1;
  532. return 0;
  533. }
  534. static void omap_i2c_resize_fifo(struct omap_i2c_dev *omap, u8 size, bool is_rx)
  535. {
  536. u16 buf;
  537. if (omap->flags & OMAP_I2C_FLAG_NO_FIFO)
  538. return;
  539. /*
  540. * Set up notification threshold based on message size. We're doing
  541. * this to try and avoid draining feature as much as possible. Whenever
  542. * we have big messages to transfer (bigger than our total fifo size)
  543. * then we might use draining feature to transfer the remaining bytes.
  544. */
  545. omap->threshold = clamp(size, (u8) 1, omap->fifo_size);
  546. buf = omap_i2c_read_reg(omap, OMAP_I2C_BUF_REG);
  547. if (is_rx) {
  548. /* Clear RX Threshold */
  549. buf &= ~(0x3f << 8);
  550. buf |= ((omap->threshold - 1) << 8) | OMAP_I2C_BUF_RXFIF_CLR;
  551. } else {
  552. /* Clear TX Threshold */
  553. buf &= ~0x3f;
  554. buf |= (omap->threshold - 1) | OMAP_I2C_BUF_TXFIF_CLR;
  555. }
  556. omap_i2c_write_reg(omap, OMAP_I2C_BUF_REG, buf);
  557. if (omap->rev < OMAP_I2C_REV_ON_3630)
  558. omap->b_hw = 1; /* Enable hardware fixes */
  559. /* calculate wakeup latency constraint for MPU */
  560. if (omap->set_mpu_wkup_lat != NULL)
  561. omap->latency = (1000000 * omap->threshold) /
  562. (1000 * omap->speed / 8);
  563. }
  564. static void omap_i2c_wait(struct omap_i2c_dev *omap)
  565. {
  566. u16 stat;
  567. u16 mask = omap_i2c_read_reg(omap, OMAP_I2C_IE_REG);
  568. int count = 0;
  569. do {
  570. stat = omap_i2c_read_reg(omap, OMAP_I2C_STAT_REG);
  571. count++;
  572. } while (!(stat & mask) && count < 5);
  573. }
  574. /*
  575. * Low level master read/write transaction.
  576. */
  577. static int omap_i2c_xfer_msg(struct i2c_adapter *adap,
  578. struct i2c_msg *msg, int stop, bool polling)
  579. {
  580. struct omap_i2c_dev *omap = i2c_get_adapdata(adap);
  581. unsigned long time_left;
  582. u16 w;
  583. int ret;
  584. dev_dbg(omap->dev, "addr: 0x%04x, len: %d, flags: 0x%x, stop: %d\n",
  585. msg->addr, msg->len, msg->flags, stop);
  586. omap->receiver = !!(msg->flags & I2C_M_RD);
  587. omap_i2c_resize_fifo(omap, msg->len, omap->receiver);
  588. omap_i2c_write_reg(omap, OMAP_I2C_SA_REG, msg->addr);
  589. /* REVISIT: Could the STB bit of I2C_CON be used with probing? */
  590. omap->buf = msg->buf;
  591. omap->buf_len = msg->len;
  592. /* make sure writes to omap->buf_len are ordered */
  593. barrier();
  594. omap_i2c_write_reg(omap, OMAP_I2C_CNT_REG, omap->buf_len);
  595. /* Clear the FIFO Buffers */
  596. w = omap_i2c_read_reg(omap, OMAP_I2C_BUF_REG);
  597. w |= OMAP_I2C_BUF_RXFIF_CLR | OMAP_I2C_BUF_TXFIF_CLR;
  598. omap_i2c_write_reg(omap, OMAP_I2C_BUF_REG, w);
  599. if (!polling)
  600. reinit_completion(&omap->cmd_complete);
  601. omap->cmd_err = 0;
  602. w = OMAP_I2C_CON_EN | OMAP_I2C_CON_MST | OMAP_I2C_CON_STT;
  603. /* High speed configuration */
  604. if (omap->speed > 400)
  605. w |= OMAP_I2C_CON_OPMODE_HS;
  606. if (msg->flags & I2C_M_STOP)
  607. stop = 1;
  608. if (msg->flags & I2C_M_TEN)
  609. w |= OMAP_I2C_CON_XA;
  610. if (!(msg->flags & I2C_M_RD))
  611. w |= OMAP_I2C_CON_TRX;
  612. if (!omap->b_hw && stop)
  613. w |= OMAP_I2C_CON_STP;
  614. /*
  615. * NOTE: STAT_BB bit could became 1 here if another master occupy
  616. * the bus. IP successfully complete transfer when the bus will be
  617. * free again (BB reset to 0).
  618. */
  619. omap_i2c_write_reg(omap, OMAP_I2C_CON_REG, w);
  620. /*
  621. * Don't write stt and stp together on some hardware.
  622. */
  623. if (omap->b_hw && stop) {
  624. unsigned long delay = jiffies + OMAP_I2C_TIMEOUT;
  625. u16 con = omap_i2c_read_reg(omap, OMAP_I2C_CON_REG);
  626. while (con & OMAP_I2C_CON_STT) {
  627. con = omap_i2c_read_reg(omap, OMAP_I2C_CON_REG);
  628. /* Let the user know if i2c is in a bad state */
  629. if (time_after(jiffies, delay)) {
  630. dev_err(omap->dev, "controller timed out "
  631. "waiting for start condition to finish\n");
  632. return -ETIMEDOUT;
  633. }
  634. cpu_relax();
  635. }
  636. w |= OMAP_I2C_CON_STP;
  637. w &= ~OMAP_I2C_CON_STT;
  638. omap_i2c_write_reg(omap, OMAP_I2C_CON_REG, w);
  639. }
  640. /*
  641. * REVISIT: We should abort the transfer on signals, but the bus goes
  642. * into arbitration and we're currently unable to recover from it.
  643. */
  644. if (!polling) {
  645. time_left = wait_for_completion_timeout(&omap->cmd_complete,
  646. OMAP_I2C_TIMEOUT);
  647. } else {
  648. do {
  649. omap_i2c_wait(omap);
  650. ret = omap_i2c_xfer_data(omap);
  651. } while (ret == -EAGAIN);
  652. time_left = !ret;
  653. }
  654. if (time_left == 0) {
  655. omap_i2c_reset(omap);
  656. __omap_i2c_init(omap);
  657. return -ETIMEDOUT;
  658. }
  659. if (likely(!omap->cmd_err))
  660. return 0;
  661. /* We have an error */
  662. if (omap->cmd_err & (OMAP_I2C_STAT_ROVR | OMAP_I2C_STAT_XUDF)) {
  663. omap_i2c_reset(omap);
  664. __omap_i2c_init(omap);
  665. return -EIO;
  666. }
  667. if (omap->cmd_err & OMAP_I2C_STAT_AL)
  668. return -EAGAIN;
  669. if (omap->cmd_err & OMAP_I2C_STAT_NACK) {
  670. if (msg->flags & I2C_M_IGNORE_NAK)
  671. return 0;
  672. w = omap_i2c_read_reg(omap, OMAP_I2C_CON_REG);
  673. w |= OMAP_I2C_CON_STP;
  674. omap_i2c_write_reg(omap, OMAP_I2C_CON_REG, w);
  675. return -EREMOTEIO;
  676. }
  677. return -EIO;
  678. }
  679. /*
  680. * Prepare controller for a transaction and call omap_i2c_xfer_msg
  681. * to do the work during IRQ processing.
  682. */
  683. static int
  684. omap_i2c_xfer_common(struct i2c_adapter *adap, struct i2c_msg msgs[], int num,
  685. bool polling)
  686. {
  687. struct omap_i2c_dev *omap = i2c_get_adapdata(adap);
  688. int i;
  689. int r;
  690. r = pm_runtime_get_sync(omap->dev);
  691. if (r < 0)
  692. goto out;
  693. r = omap_i2c_wait_for_bb_valid(omap);
  694. if (r < 0)
  695. goto out;
  696. r = omap_i2c_wait_for_bb(omap);
  697. if (r < 0)
  698. goto out;
  699. if (omap->set_mpu_wkup_lat != NULL)
  700. omap->set_mpu_wkup_lat(omap->dev, omap->latency);
  701. for (i = 0; i < num; i++) {
  702. r = omap_i2c_xfer_msg(adap, &msgs[i], (i == (num - 1)),
  703. polling);
  704. if (r != 0)
  705. break;
  706. }
  707. if (r == 0)
  708. r = num;
  709. omap_i2c_wait_for_bb(omap);
  710. if (omap->set_mpu_wkup_lat != NULL)
  711. omap->set_mpu_wkup_lat(omap->dev, -1);
  712. out:
  713. pm_runtime_mark_last_busy(omap->dev);
  714. pm_runtime_put_autosuspend(omap->dev);
  715. return r;
  716. }
  717. static int
  718. omap_i2c_xfer_irq(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
  719. {
  720. return omap_i2c_xfer_common(adap, msgs, num, false);
  721. }
  722. static int
  723. omap_i2c_xfer_polling(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
  724. {
  725. return omap_i2c_xfer_common(adap, msgs, num, true);
  726. }
  727. static u32
  728. omap_i2c_func(struct i2c_adapter *adap)
  729. {
  730. return I2C_FUNC_I2C | (I2C_FUNC_SMBUS_EMUL & ~I2C_FUNC_SMBUS_QUICK) |
  731. I2C_FUNC_PROTOCOL_MANGLING;
  732. }
  733. static inline void
  734. omap_i2c_complete_cmd(struct omap_i2c_dev *omap, u16 err)
  735. {
  736. omap->cmd_err |= err;
  737. complete(&omap->cmd_complete);
  738. }
  739. static inline void
  740. omap_i2c_ack_stat(struct omap_i2c_dev *omap, u16 stat)
  741. {
  742. omap_i2c_write_reg(omap, OMAP_I2C_STAT_REG, stat);
  743. }
  744. static inline void i2c_omap_errata_i207(struct omap_i2c_dev *omap, u16 stat)
  745. {
  746. /*
  747. * I2C Errata(Errata Nos. OMAP2: 1.67, OMAP3: 1.8)
  748. * Not applicable for OMAP4.
  749. * Under certain rare conditions, RDR could be set again
  750. * when the bus is busy, then ignore the interrupt and
  751. * clear the interrupt.
  752. */
  753. if (stat & OMAP_I2C_STAT_RDR) {
  754. /* Step 1: If RDR is set, clear it */
  755. omap_i2c_ack_stat(omap, OMAP_I2C_STAT_RDR);
  756. /* Step 2: */
  757. if (!(omap_i2c_read_reg(omap, OMAP_I2C_STAT_REG)
  758. & OMAP_I2C_STAT_BB)) {
  759. /* Step 3: */
  760. if (omap_i2c_read_reg(omap, OMAP_I2C_STAT_REG)
  761. & OMAP_I2C_STAT_RDR) {
  762. omap_i2c_ack_stat(omap, OMAP_I2C_STAT_RDR);
  763. dev_dbg(omap->dev, "RDR when bus is busy.\n");
  764. }
  765. }
  766. }
  767. }
  768. /* rev1 devices are apparently only on some 15xx */
  769. #ifdef CONFIG_ARCH_OMAP15XX
  770. static irqreturn_t
  771. omap_i2c_omap1_isr(int this_irq, void *dev_id)
  772. {
  773. struct omap_i2c_dev *omap = dev_id;
  774. u16 iv, w;
  775. if (pm_runtime_suspended(omap->dev))
  776. return IRQ_NONE;
  777. iv = omap_i2c_read_reg(omap, OMAP_I2C_IV_REG);
  778. switch (iv) {
  779. case 0x00: /* None */
  780. break;
  781. case 0x01: /* Arbitration lost */
  782. dev_err(omap->dev, "Arbitration lost\n");
  783. omap_i2c_complete_cmd(omap, OMAP_I2C_STAT_AL);
  784. break;
  785. case 0x02: /* No acknowledgement */
  786. omap_i2c_complete_cmd(omap, OMAP_I2C_STAT_NACK);
  787. omap_i2c_write_reg(omap, OMAP_I2C_CON_REG, OMAP_I2C_CON_STP);
  788. break;
  789. case 0x03: /* Register access ready */
  790. omap_i2c_complete_cmd(omap, 0);
  791. break;
  792. case 0x04: /* Receive data ready */
  793. if (omap->buf_len) {
  794. w = omap_i2c_read_reg(omap, OMAP_I2C_DATA_REG);
  795. *omap->buf++ = w;
  796. omap->buf_len--;
  797. if (omap->buf_len) {
  798. *omap->buf++ = w >> 8;
  799. omap->buf_len--;
  800. }
  801. } else
  802. dev_err(omap->dev, "RRDY IRQ while no data requested\n");
  803. break;
  804. case 0x05: /* Transmit data ready */
  805. if (omap->buf_len) {
  806. w = *omap->buf++;
  807. omap->buf_len--;
  808. if (omap->buf_len) {
  809. w |= *omap->buf++ << 8;
  810. omap->buf_len--;
  811. }
  812. omap_i2c_write_reg(omap, OMAP_I2C_DATA_REG, w);
  813. } else
  814. dev_err(omap->dev, "XRDY IRQ while no data to send\n");
  815. break;
  816. default:
  817. return IRQ_NONE;
  818. }
  819. return IRQ_HANDLED;
  820. }
  821. #else
  822. #define omap_i2c_omap1_isr NULL
  823. #endif
  824. /*
  825. * OMAP3430 Errata i462: When an XRDY/XDR is hit, wait for XUDF before writing
  826. * data to DATA_REG. Otherwise some data bytes can be lost while transferring
  827. * them from the memory to the I2C interface.
  828. */
  829. static int errata_omap3_i462(struct omap_i2c_dev *omap)
  830. {
  831. unsigned long timeout = 10000;
  832. u16 stat;
  833. do {
  834. stat = omap_i2c_read_reg(omap, OMAP_I2C_STAT_REG);
  835. if (stat & OMAP_I2C_STAT_XUDF)
  836. break;
  837. if (stat & (OMAP_I2C_STAT_NACK | OMAP_I2C_STAT_AL)) {
  838. omap_i2c_ack_stat(omap, (OMAP_I2C_STAT_XRDY |
  839. OMAP_I2C_STAT_XDR));
  840. if (stat & OMAP_I2C_STAT_NACK) {
  841. omap->cmd_err |= OMAP_I2C_STAT_NACK;
  842. omap_i2c_ack_stat(omap, OMAP_I2C_STAT_NACK);
  843. }
  844. if (stat & OMAP_I2C_STAT_AL) {
  845. dev_err(omap->dev, "Arbitration lost\n");
  846. omap->cmd_err |= OMAP_I2C_STAT_AL;
  847. omap_i2c_ack_stat(omap, OMAP_I2C_STAT_AL);
  848. }
  849. return -EIO;
  850. }
  851. cpu_relax();
  852. } while (--timeout);
  853. if (!timeout) {
  854. dev_err(omap->dev, "timeout waiting on XUDF bit\n");
  855. return 0;
  856. }
  857. return 0;
  858. }
  859. static void omap_i2c_receive_data(struct omap_i2c_dev *omap, u8 num_bytes,
  860. bool is_rdr)
  861. {
  862. u16 w;
  863. while (num_bytes--) {
  864. w = omap_i2c_read_reg(omap, OMAP_I2C_DATA_REG);
  865. *omap->buf++ = w;
  866. omap->buf_len--;
  867. /*
  868. * Data reg in 2430, omap3 and
  869. * omap4 is 8 bit wide
  870. */
  871. if (omap->flags & OMAP_I2C_FLAG_16BIT_DATA_REG) {
  872. *omap->buf++ = w >> 8;
  873. omap->buf_len--;
  874. }
  875. }
  876. }
  877. static int omap_i2c_transmit_data(struct omap_i2c_dev *omap, u8 num_bytes,
  878. bool is_xdr)
  879. {
  880. u16 w;
  881. while (num_bytes--) {
  882. w = *omap->buf++;
  883. omap->buf_len--;
  884. /*
  885. * Data reg in 2430, omap3 and
  886. * omap4 is 8 bit wide
  887. */
  888. if (omap->flags & OMAP_I2C_FLAG_16BIT_DATA_REG) {
  889. w |= *omap->buf++ << 8;
  890. omap->buf_len--;
  891. }
  892. if (omap->errata & I2C_OMAP_ERRATA_I462) {
  893. int ret;
  894. ret = errata_omap3_i462(omap);
  895. if (ret < 0)
  896. return ret;
  897. }
  898. omap_i2c_write_reg(omap, OMAP_I2C_DATA_REG, w);
  899. }
  900. return 0;
  901. }
  902. static int omap_i2c_xfer_data(struct omap_i2c_dev *omap)
  903. {
  904. u16 bits;
  905. u16 stat;
  906. int err = 0, count = 0;
  907. do {
  908. bits = omap_i2c_read_reg(omap, OMAP_I2C_IE_REG);
  909. stat = omap_i2c_read_reg(omap, OMAP_I2C_STAT_REG);
  910. stat &= bits;
  911. /* If we're in receiver mode, ignore XDR/XRDY */
  912. if (omap->receiver)
  913. stat &= ~(OMAP_I2C_STAT_XDR | OMAP_I2C_STAT_XRDY);
  914. else
  915. stat &= ~(OMAP_I2C_STAT_RDR | OMAP_I2C_STAT_RRDY);
  916. if (!stat) {
  917. /* my work here is done */
  918. err = -EAGAIN;
  919. break;
  920. }
  921. dev_dbg(omap->dev, "IRQ (ISR = 0x%04x)\n", stat);
  922. if (count++ == 100) {
  923. dev_warn(omap->dev, "Too much work in one IRQ\n");
  924. break;
  925. }
  926. if (stat & OMAP_I2C_STAT_NACK) {
  927. omap->cmd_err |= OMAP_I2C_STAT_NACK;
  928. omap_i2c_ack_stat(omap, OMAP_I2C_STAT_NACK);
  929. if (!(stat & ~OMAP_I2C_STAT_NACK)) {
  930. err = -EAGAIN;
  931. break;
  932. }
  933. }
  934. if (stat & OMAP_I2C_STAT_AL) {
  935. dev_err(omap->dev, "Arbitration lost\n");
  936. err |= OMAP_I2C_STAT_AL;
  937. omap_i2c_ack_stat(omap, OMAP_I2C_STAT_AL);
  938. }
  939. /*
  940. * ProDB0017052: Clear ARDY bit twice
  941. */
  942. if (stat & OMAP_I2C_STAT_ARDY)
  943. omap_i2c_ack_stat(omap, OMAP_I2C_STAT_ARDY);
  944. if (stat & (OMAP_I2C_STAT_ARDY | OMAP_I2C_STAT_NACK |
  945. OMAP_I2C_STAT_AL)) {
  946. omap_i2c_ack_stat(omap, (OMAP_I2C_STAT_RRDY |
  947. OMAP_I2C_STAT_RDR |
  948. OMAP_I2C_STAT_XRDY |
  949. OMAP_I2C_STAT_XDR |
  950. OMAP_I2C_STAT_ARDY));
  951. break;
  952. }
  953. if (stat & OMAP_I2C_STAT_RDR) {
  954. u8 num_bytes = 1;
  955. if (omap->fifo_size)
  956. num_bytes = omap->buf_len;
  957. if (omap->errata & I2C_OMAP_ERRATA_I207) {
  958. i2c_omap_errata_i207(omap, stat);
  959. num_bytes = (omap_i2c_read_reg(omap,
  960. OMAP_I2C_BUFSTAT_REG) >> 8) & 0x3F;
  961. }
  962. omap_i2c_receive_data(omap, num_bytes, true);
  963. omap_i2c_ack_stat(omap, OMAP_I2C_STAT_RDR);
  964. continue;
  965. }
  966. if (stat & OMAP_I2C_STAT_RRDY) {
  967. u8 num_bytes = 1;
  968. if (omap->threshold)
  969. num_bytes = omap->threshold;
  970. omap_i2c_receive_data(omap, num_bytes, false);
  971. omap_i2c_ack_stat(omap, OMAP_I2C_STAT_RRDY);
  972. continue;
  973. }
  974. if (stat & OMAP_I2C_STAT_XDR) {
  975. u8 num_bytes = 1;
  976. int ret;
  977. if (omap->fifo_size)
  978. num_bytes = omap->buf_len;
  979. ret = omap_i2c_transmit_data(omap, num_bytes, true);
  980. if (ret < 0)
  981. break;
  982. omap_i2c_ack_stat(omap, OMAP_I2C_STAT_XDR);
  983. continue;
  984. }
  985. if (stat & OMAP_I2C_STAT_XRDY) {
  986. u8 num_bytes = 1;
  987. int ret;
  988. if (omap->threshold)
  989. num_bytes = omap->threshold;
  990. ret = omap_i2c_transmit_data(omap, num_bytes, false);
  991. if (ret < 0)
  992. break;
  993. omap_i2c_ack_stat(omap, OMAP_I2C_STAT_XRDY);
  994. continue;
  995. }
  996. if (stat & OMAP_I2C_STAT_ROVR) {
  997. dev_err(omap->dev, "Receive overrun\n");
  998. err |= OMAP_I2C_STAT_ROVR;
  999. omap_i2c_ack_stat(omap, OMAP_I2C_STAT_ROVR);
  1000. break;
  1001. }
  1002. if (stat & OMAP_I2C_STAT_XUDF) {
  1003. dev_err(omap->dev, "Transmit underflow\n");
  1004. err |= OMAP_I2C_STAT_XUDF;
  1005. omap_i2c_ack_stat(omap, OMAP_I2C_STAT_XUDF);
  1006. break;
  1007. }
  1008. } while (stat);
  1009. return err;
  1010. }
  1011. static irqreturn_t
  1012. omap_i2c_isr_thread(int this_irq, void *dev_id)
  1013. {
  1014. int ret;
  1015. struct omap_i2c_dev *omap = dev_id;
  1016. ret = omap_i2c_xfer_data(omap);
  1017. if (ret != -EAGAIN)
  1018. omap_i2c_complete_cmd(omap, ret);
  1019. return IRQ_HANDLED;
  1020. }
  1021. static const struct i2c_algorithm omap_i2c_algo = {
  1022. .master_xfer = omap_i2c_xfer_irq,
  1023. .master_xfer_atomic = omap_i2c_xfer_polling,
  1024. .functionality = omap_i2c_func,
  1025. };
  1026. static const struct i2c_adapter_quirks omap_i2c_quirks = {
  1027. .flags = I2C_AQ_NO_ZERO_LEN,
  1028. };
  1029. #ifdef CONFIG_OF
  1030. static struct omap_i2c_bus_platform_data omap2420_pdata = {
  1031. .rev = OMAP_I2C_IP_VERSION_1,
  1032. .flags = OMAP_I2C_FLAG_NO_FIFO |
  1033. OMAP_I2C_FLAG_SIMPLE_CLOCK |
  1034. OMAP_I2C_FLAG_16BIT_DATA_REG |
  1035. OMAP_I2C_FLAG_BUS_SHIFT_2,
  1036. };
  1037. static struct omap_i2c_bus_platform_data omap2430_pdata = {
  1038. .rev = OMAP_I2C_IP_VERSION_1,
  1039. .flags = OMAP_I2C_FLAG_BUS_SHIFT_2 |
  1040. OMAP_I2C_FLAG_FORCE_19200_INT_CLK,
  1041. };
  1042. static struct omap_i2c_bus_platform_data omap3_pdata = {
  1043. .rev = OMAP_I2C_IP_VERSION_1,
  1044. .flags = OMAP_I2C_FLAG_BUS_SHIFT_2,
  1045. };
  1046. static struct omap_i2c_bus_platform_data omap4_pdata = {
  1047. .rev = OMAP_I2C_IP_VERSION_2,
  1048. };
  1049. static const struct of_device_id omap_i2c_of_match[] = {
  1050. {
  1051. .compatible = "ti,omap4-i2c",
  1052. .data = &omap4_pdata,
  1053. },
  1054. {
  1055. .compatible = "ti,omap3-i2c",
  1056. .data = &omap3_pdata,
  1057. },
  1058. {
  1059. .compatible = "ti,omap2430-i2c",
  1060. .data = &omap2430_pdata,
  1061. },
  1062. {
  1063. .compatible = "ti,omap2420-i2c",
  1064. .data = &omap2420_pdata,
  1065. },
  1066. { }
  1067. };
  1068. MODULE_DEVICE_TABLE(of, omap_i2c_of_match);
  1069. #endif
  1070. #define OMAP_I2C_SCHEME(rev) ((rev & 0xc000) >> 14)
  1071. #define OMAP_I2C_REV_SCHEME_0_MAJOR(rev) (rev >> 4)
  1072. #define OMAP_I2C_REV_SCHEME_0_MINOR(rev) (rev & 0xf)
  1073. #define OMAP_I2C_REV_SCHEME_1_MAJOR(rev) ((rev & 0x0700) >> 7)
  1074. #define OMAP_I2C_REV_SCHEME_1_MINOR(rev) (rev & 0x1f)
  1075. #define OMAP_I2C_SCHEME_0 0
  1076. #define OMAP_I2C_SCHEME_1 1
  1077. static int omap_i2c_get_scl(struct i2c_adapter *adap)
  1078. {
  1079. struct omap_i2c_dev *dev = i2c_get_adapdata(adap);
  1080. u32 reg;
  1081. reg = omap_i2c_read_reg(dev, OMAP_I2C_SYSTEST_REG);
  1082. return reg & OMAP_I2C_SYSTEST_SCL_I_FUNC;
  1083. }
  1084. static int omap_i2c_get_sda(struct i2c_adapter *adap)
  1085. {
  1086. struct omap_i2c_dev *dev = i2c_get_adapdata(adap);
  1087. u32 reg;
  1088. reg = omap_i2c_read_reg(dev, OMAP_I2C_SYSTEST_REG);
  1089. return reg & OMAP_I2C_SYSTEST_SDA_I_FUNC;
  1090. }
  1091. static void omap_i2c_set_scl(struct i2c_adapter *adap, int val)
  1092. {
  1093. struct omap_i2c_dev *dev = i2c_get_adapdata(adap);
  1094. u32 reg;
  1095. reg = omap_i2c_read_reg(dev, OMAP_I2C_SYSTEST_REG);
  1096. if (val)
  1097. reg |= OMAP_I2C_SYSTEST_SCL_O;
  1098. else
  1099. reg &= ~OMAP_I2C_SYSTEST_SCL_O;
  1100. omap_i2c_write_reg(dev, OMAP_I2C_SYSTEST_REG, reg);
  1101. }
  1102. static void omap_i2c_prepare_recovery(struct i2c_adapter *adap)
  1103. {
  1104. struct omap_i2c_dev *dev = i2c_get_adapdata(adap);
  1105. u32 reg;
  1106. reg = omap_i2c_read_reg(dev, OMAP_I2C_SYSTEST_REG);
  1107. /* enable test mode */
  1108. reg |= OMAP_I2C_SYSTEST_ST_EN;
  1109. /* select SDA/SCL IO mode */
  1110. reg |= 3 << OMAP_I2C_SYSTEST_TMODE_SHIFT;
  1111. /* set SCL to high-impedance state (reset value is 0) */
  1112. reg |= OMAP_I2C_SYSTEST_SCL_O;
  1113. /* set SDA to high-impedance state (reset value is 0) */
  1114. reg |= OMAP_I2C_SYSTEST_SDA_O;
  1115. omap_i2c_write_reg(dev, OMAP_I2C_SYSTEST_REG, reg);
  1116. }
  1117. static void omap_i2c_unprepare_recovery(struct i2c_adapter *adap)
  1118. {
  1119. struct omap_i2c_dev *dev = i2c_get_adapdata(adap);
  1120. u32 reg;
  1121. reg = omap_i2c_read_reg(dev, OMAP_I2C_SYSTEST_REG);
  1122. /* restore reset values */
  1123. reg &= ~OMAP_I2C_SYSTEST_ST_EN;
  1124. reg &= ~OMAP_I2C_SYSTEST_TMODE_MASK;
  1125. reg &= ~OMAP_I2C_SYSTEST_SCL_O;
  1126. reg &= ~OMAP_I2C_SYSTEST_SDA_O;
  1127. omap_i2c_write_reg(dev, OMAP_I2C_SYSTEST_REG, reg);
  1128. }
  1129. static struct i2c_bus_recovery_info omap_i2c_bus_recovery_info = {
  1130. .get_scl = omap_i2c_get_scl,
  1131. .get_sda = omap_i2c_get_sda,
  1132. .set_scl = omap_i2c_set_scl,
  1133. .prepare_recovery = omap_i2c_prepare_recovery,
  1134. .unprepare_recovery = omap_i2c_unprepare_recovery,
  1135. .recover_bus = i2c_generic_scl_recovery,
  1136. };
  1137. static int
  1138. omap_i2c_probe(struct platform_device *pdev)
  1139. {
  1140. struct omap_i2c_dev *omap;
  1141. struct i2c_adapter *adap;
  1142. const struct omap_i2c_bus_platform_data *pdata =
  1143. dev_get_platdata(&pdev->dev);
  1144. struct device_node *node = pdev->dev.of_node;
  1145. int irq;
  1146. int r;
  1147. u32 rev;
  1148. u16 minor, major;
  1149. irq = platform_get_irq(pdev, 0);
  1150. if (irq < 0)
  1151. return irq;
  1152. omap = devm_kzalloc(&pdev->dev, sizeof(struct omap_i2c_dev), GFP_KERNEL);
  1153. if (!omap)
  1154. return -ENOMEM;
  1155. omap->base = devm_platform_ioremap_resource(pdev, 0);
  1156. if (IS_ERR(omap->base))
  1157. return PTR_ERR(omap->base);
  1158. if (pdev->dev.of_node) {
  1159. u32 freq = I2C_MAX_STANDARD_MODE_FREQ;
  1160. pdata = device_get_match_data(&pdev->dev);
  1161. omap->flags = pdata->flags;
  1162. of_property_read_u32(node, "clock-frequency", &freq);
  1163. /* convert DT freq value in Hz into kHz for speed */
  1164. omap->speed = freq / 1000;
  1165. } else if (pdata != NULL) {
  1166. omap->speed = pdata->clkrate;
  1167. omap->flags = pdata->flags;
  1168. omap->set_mpu_wkup_lat = pdata->set_mpu_wkup_lat;
  1169. }
  1170. omap->dev = &pdev->dev;
  1171. omap->irq = irq;
  1172. platform_set_drvdata(pdev, omap);
  1173. init_completion(&omap->cmd_complete);
  1174. omap->reg_shift = (omap->flags >> OMAP_I2C_FLAG_BUS_SHIFT__SHIFT) & 3;
  1175. pm_runtime_enable(omap->dev);
  1176. pm_runtime_set_autosuspend_delay(omap->dev, OMAP_I2C_PM_TIMEOUT);
  1177. pm_runtime_use_autosuspend(omap->dev);
  1178. r = pm_runtime_resume_and_get(omap->dev);
  1179. if (r < 0)
  1180. goto err_disable_pm;
  1181. /*
  1182. * Read the Rev hi bit-[15:14] ie scheme this is 1 indicates ver2.
  1183. * On omap1/3/2 Offset 4 is IE Reg the bit [15:14] is 0 at reset.
  1184. * Also since the omap_i2c_read_reg uses reg_map_ip_* a
  1185. * readw_relaxed is done.
  1186. */
  1187. rev = readw_relaxed(omap->base + 0x04);
  1188. omap->scheme = OMAP_I2C_SCHEME(rev);
  1189. switch (omap->scheme) {
  1190. case OMAP_I2C_SCHEME_0:
  1191. omap->regs = (u8 *)reg_map_ip_v1;
  1192. omap->rev = omap_i2c_read_reg(omap, OMAP_I2C_REV_REG);
  1193. minor = OMAP_I2C_REV_SCHEME_0_MAJOR(omap->rev);
  1194. major = OMAP_I2C_REV_SCHEME_0_MAJOR(omap->rev);
  1195. break;
  1196. case OMAP_I2C_SCHEME_1:
  1197. default:
  1198. omap->regs = (u8 *)reg_map_ip_v2;
  1199. rev = (rev << 16) |
  1200. omap_i2c_read_reg(omap, OMAP_I2C_IP_V2_REVNB_LO);
  1201. minor = OMAP_I2C_REV_SCHEME_1_MINOR(rev);
  1202. major = OMAP_I2C_REV_SCHEME_1_MAJOR(rev);
  1203. omap->rev = rev;
  1204. }
  1205. omap->errata = 0;
  1206. if (omap->rev >= OMAP_I2C_REV_ON_2430 &&
  1207. omap->rev < OMAP_I2C_REV_ON_4430_PLUS)
  1208. omap->errata |= I2C_OMAP_ERRATA_I207;
  1209. if (omap->rev <= OMAP_I2C_REV_ON_3430_3530)
  1210. omap->errata |= I2C_OMAP_ERRATA_I462;
  1211. if (!(omap->flags & OMAP_I2C_FLAG_NO_FIFO)) {
  1212. u16 s;
  1213. /* Set up the fifo size - Get total size */
  1214. s = (omap_i2c_read_reg(omap, OMAP_I2C_BUFSTAT_REG) >> 14) & 0x3;
  1215. omap->fifo_size = 0x8 << s;
  1216. /*
  1217. * Set up notification threshold as half the total available
  1218. * size. This is to ensure that we can handle the status on int
  1219. * call back latencies.
  1220. */
  1221. omap->fifo_size = (omap->fifo_size / 2);
  1222. if (omap->rev < OMAP_I2C_REV_ON_3630)
  1223. omap->b_hw = 1; /* Enable hardware fixes */
  1224. /* calculate wakeup latency constraint for MPU */
  1225. if (omap->set_mpu_wkup_lat != NULL)
  1226. omap->latency = (1000000 * omap->fifo_size) /
  1227. (1000 * omap->speed / 8);
  1228. }
  1229. if (of_property_present(node, "mux-states")) {
  1230. struct mux_state *mux_state;
  1231. mux_state = devm_mux_state_get(&pdev->dev, NULL);
  1232. if (IS_ERR(mux_state)) {
  1233. r = PTR_ERR(mux_state);
  1234. dev_dbg(&pdev->dev, "failed to get I2C mux: %d\n", r);
  1235. goto err_put_pm;
  1236. }
  1237. omap->mux_state = mux_state;
  1238. r = mux_state_select(omap->mux_state);
  1239. if (r) {
  1240. dev_err(&pdev->dev, "failed to select I2C mux: %d\n", r);
  1241. goto err_put_pm;
  1242. }
  1243. }
  1244. /* reset ASAP, clearing any IRQs */
  1245. r = omap_i2c_init(omap);
  1246. if (r)
  1247. goto err_mux_state_deselect;
  1248. if (omap->rev < OMAP_I2C_OMAP1_REV_2)
  1249. r = devm_request_irq(&pdev->dev, omap->irq, omap_i2c_omap1_isr,
  1250. IRQF_NO_SUSPEND, pdev->name, omap);
  1251. else
  1252. r = devm_request_threaded_irq(&pdev->dev, omap->irq,
  1253. NULL, omap_i2c_isr_thread,
  1254. IRQF_NO_SUSPEND | IRQF_ONESHOT,
  1255. pdev->name, omap);
  1256. if (r) {
  1257. dev_err(omap->dev, "failure requesting irq %i\n", omap->irq);
  1258. goto err_unuse_clocks;
  1259. }
  1260. adap = &omap->adapter;
  1261. i2c_set_adapdata(adap, omap);
  1262. adap->owner = THIS_MODULE;
  1263. adap->class = I2C_CLASS_DEPRECATED;
  1264. strscpy(adap->name, "OMAP I2C adapter", sizeof(adap->name));
  1265. adap->algo = &omap_i2c_algo;
  1266. adap->quirks = &omap_i2c_quirks;
  1267. adap->dev.parent = &pdev->dev;
  1268. adap->dev.of_node = pdev->dev.of_node;
  1269. adap->bus_recovery_info = &omap_i2c_bus_recovery_info;
  1270. /* i2c device drivers may be active on return from add_adapter() */
  1271. adap->nr = pdev->id;
  1272. r = i2c_add_numbered_adapter(adap);
  1273. if (r)
  1274. goto err_unuse_clocks;
  1275. dev_info(omap->dev, "bus %d rev%d.%d at %d kHz\n", adap->nr,
  1276. major, minor, omap->speed);
  1277. pm_runtime_mark_last_busy(omap->dev);
  1278. pm_runtime_put_autosuspend(omap->dev);
  1279. return 0;
  1280. err_unuse_clocks:
  1281. omap_i2c_write_reg(omap, OMAP_I2C_CON_REG, 0);
  1282. err_mux_state_deselect:
  1283. if (omap->mux_state)
  1284. mux_state_deselect(omap->mux_state);
  1285. err_put_pm:
  1286. pm_runtime_dont_use_autosuspend(omap->dev);
  1287. pm_runtime_put_sync(omap->dev);
  1288. err_disable_pm:
  1289. pm_runtime_disable(&pdev->dev);
  1290. return r;
  1291. }
  1292. static void omap_i2c_remove(struct platform_device *pdev)
  1293. {
  1294. struct omap_i2c_dev *omap = platform_get_drvdata(pdev);
  1295. int ret;
  1296. i2c_del_adapter(&omap->adapter);
  1297. if (omap->mux_state)
  1298. mux_state_deselect(omap->mux_state);
  1299. ret = pm_runtime_get_sync(&pdev->dev);
  1300. if (ret < 0)
  1301. dev_err(omap->dev, "Failed to resume hardware, skip disable\n");
  1302. else
  1303. omap_i2c_write_reg(omap, OMAP_I2C_CON_REG, 0);
  1304. pm_runtime_dont_use_autosuspend(&pdev->dev);
  1305. pm_runtime_put_sync(&pdev->dev);
  1306. pm_runtime_disable(&pdev->dev);
  1307. }
  1308. static int omap_i2c_runtime_suspend(struct device *dev)
  1309. {
  1310. struct omap_i2c_dev *omap = dev_get_drvdata(dev);
  1311. omap->iestate = omap_i2c_read_reg(omap, OMAP_I2C_IE_REG);
  1312. if (omap->scheme == OMAP_I2C_SCHEME_0)
  1313. omap_i2c_write_reg(omap, OMAP_I2C_IE_REG, 0);
  1314. else
  1315. omap_i2c_write_reg(omap, OMAP_I2C_IP_V2_IRQENABLE_CLR,
  1316. OMAP_I2C_IP_V2_INTERRUPTS_MASK);
  1317. if (omap->rev < OMAP_I2C_OMAP1_REV_2) {
  1318. omap_i2c_read_reg(omap, OMAP_I2C_IV_REG); /* Read clears */
  1319. } else {
  1320. omap_i2c_write_reg(omap, OMAP_I2C_STAT_REG, omap->iestate);
  1321. /* Flush posted write */
  1322. omap_i2c_read_reg(omap, OMAP_I2C_STAT_REG);
  1323. }
  1324. pinctrl_pm_select_sleep_state(dev);
  1325. return 0;
  1326. }
  1327. static int omap_i2c_runtime_resume(struct device *dev)
  1328. {
  1329. struct omap_i2c_dev *omap = dev_get_drvdata(dev);
  1330. pinctrl_pm_select_default_state(dev);
  1331. if (!omap->regs)
  1332. return 0;
  1333. __omap_i2c_init(omap);
  1334. return 0;
  1335. }
  1336. static int omap_i2c_suspend(struct device *dev)
  1337. {
  1338. /*
  1339. * If the controller is autosuspended, there is no way to wakeup it once
  1340. * runtime pm is disabled (in suspend_late()).
  1341. * But a device may need the controller up during suspend_noirq() or
  1342. * resume_noirq().
  1343. * Wakeup the controller while runtime pm is enabled, so it is available
  1344. * until its suspend_noirq(), and from resume_noirq().
  1345. */
  1346. return pm_runtime_resume_and_get(dev);
  1347. }
  1348. static int omap_i2c_resume(struct device *dev)
  1349. {
  1350. pm_runtime_mark_last_busy(dev);
  1351. pm_runtime_put_autosuspend(dev);
  1352. return 0;
  1353. }
  1354. static const struct dev_pm_ops omap_i2c_pm_ops = {
  1355. NOIRQ_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
  1356. pm_runtime_force_resume)
  1357. SYSTEM_SLEEP_PM_OPS(omap_i2c_suspend, omap_i2c_resume)
  1358. RUNTIME_PM_OPS(omap_i2c_runtime_suspend,
  1359. omap_i2c_runtime_resume, NULL)
  1360. };
  1361. static struct platform_driver omap_i2c_driver = {
  1362. .probe = omap_i2c_probe,
  1363. .remove_new = omap_i2c_remove,
  1364. .driver = {
  1365. .name = "omap_i2c",
  1366. .pm = pm_ptr(&omap_i2c_pm_ops),
  1367. .of_match_table = of_match_ptr(omap_i2c_of_match),
  1368. },
  1369. };
  1370. /* I2C may be needed to bring up other drivers */
  1371. static int __init
  1372. omap_i2c_init_driver(void)
  1373. {
  1374. return platform_driver_register(&omap_i2c_driver);
  1375. }
  1376. subsys_initcall(omap_i2c_init_driver);
  1377. static void __exit omap_i2c_exit_driver(void)
  1378. {
  1379. platform_driver_unregister(&omap_i2c_driver);
  1380. }
  1381. module_exit(omap_i2c_exit_driver);
  1382. MODULE_AUTHOR("MontaVista Software, Inc. (and others)");
  1383. MODULE_DESCRIPTION("TI OMAP I2C bus adapter");
  1384. MODULE_LICENSE("GPL");
  1385. MODULE_ALIAS("platform:omap_i2c");