i2c-s3c2410.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300
  1. /* linux/drivers/i2c/busses/i2c-s3c2410.c
  2. *
  3. * Copyright (C) 2004,2005,2009 Simtec Electronics
  4. * Ben Dooks <ben@simtec.co.uk>
  5. *
  6. * S3C2410 I2C Controller
  7. *
  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. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #include <linux/kernel.h>
  23. #include <linux/module.h>
  24. #include <linux/i2c.h>
  25. #include <linux/init.h>
  26. #include <linux/time.h>
  27. #include <linux/interrupt.h>
  28. #include <linux/delay.h>
  29. #include <linux/errno.h>
  30. #include <linux/err.h>
  31. #include <linux/platform_device.h>
  32. #include <linux/pm_runtime.h>
  33. #include <linux/clk.h>
  34. #include <linux/cpufreq.h>
  35. #include <linux/slab.h>
  36. #include <linux/io.h>
  37. #include <linux/of.h>
  38. #include <linux/of_gpio.h>
  39. #include <linux/pinctrl/consumer.h>
  40. #include <asm/irq.h>
  41. #include <linux/platform_data/i2c-s3c2410.h>
  42. /* see s3c2410x user guide, v1.1, section 9 (p447) for more info */
  43. #define S3C2410_IICCON 0x00
  44. #define S3C2410_IICSTAT 0x04
  45. #define S3C2410_IICADD 0x08
  46. #define S3C2410_IICDS 0x0C
  47. #define S3C2440_IICLC 0x10
  48. #define S3C2410_IICCON_ACKEN (1 << 7)
  49. #define S3C2410_IICCON_TXDIV_16 (0 << 6)
  50. #define S3C2410_IICCON_TXDIV_512 (1 << 6)
  51. #define S3C2410_IICCON_IRQEN (1 << 5)
  52. #define S3C2410_IICCON_IRQPEND (1 << 4)
  53. #define S3C2410_IICCON_SCALE(x) ((x) & 0xf)
  54. #define S3C2410_IICCON_SCALEMASK (0xf)
  55. #define S3C2410_IICSTAT_MASTER_RX (2 << 6)
  56. #define S3C2410_IICSTAT_MASTER_TX (3 << 6)
  57. #define S3C2410_IICSTAT_SLAVE_RX (0 << 6)
  58. #define S3C2410_IICSTAT_SLAVE_TX (1 << 6)
  59. #define S3C2410_IICSTAT_MODEMASK (3 << 6)
  60. #define S3C2410_IICSTAT_START (1 << 5)
  61. #define S3C2410_IICSTAT_BUSBUSY (1 << 5)
  62. #define S3C2410_IICSTAT_TXRXEN (1 << 4)
  63. #define S3C2410_IICSTAT_ARBITR (1 << 3)
  64. #define S3C2410_IICSTAT_ASSLAVE (1 << 2)
  65. #define S3C2410_IICSTAT_ADDR0 (1 << 1)
  66. #define S3C2410_IICSTAT_LASTBIT (1 << 0)
  67. #define S3C2410_IICLC_SDA_DELAY0 (0 << 0)
  68. #define S3C2410_IICLC_SDA_DELAY5 (1 << 0)
  69. #define S3C2410_IICLC_SDA_DELAY10 (2 << 0)
  70. #define S3C2410_IICLC_SDA_DELAY15 (3 << 0)
  71. #define S3C2410_IICLC_SDA_DELAY_MASK (3 << 0)
  72. #define S3C2410_IICLC_FILTER_ON (1 << 2)
  73. /* Treat S3C2410 as baseline hardware, anything else is supported via quirks */
  74. #define QUIRK_S3C2440 (1 << 0)
  75. #define QUIRK_HDMIPHY (1 << 1)
  76. #define QUIRK_NO_GPIO (1 << 2)
  77. #define QUIRK_POLL (1 << 3)
  78. /* Max time to wait for bus to become idle after a xfer (in us) */
  79. #define S3C2410_IDLE_TIMEOUT 5000
  80. /* i2c controller state */
  81. enum s3c24xx_i2c_state {
  82. STATE_IDLE,
  83. STATE_START,
  84. STATE_READ,
  85. STATE_WRITE,
  86. STATE_STOP
  87. };
  88. struct s3c24xx_i2c {
  89. wait_queue_head_t wait;
  90. kernel_ulong_t quirks;
  91. unsigned int suspended:1;
  92. struct i2c_msg *msg;
  93. unsigned int msg_num;
  94. unsigned int msg_idx;
  95. unsigned int msg_ptr;
  96. unsigned int tx_setup;
  97. unsigned int irq;
  98. enum s3c24xx_i2c_state state;
  99. unsigned long clkrate;
  100. void __iomem *regs;
  101. struct clk *clk;
  102. struct device *dev;
  103. struct i2c_adapter adap;
  104. struct s3c2410_platform_i2c *pdata;
  105. int gpios[2];
  106. struct pinctrl *pctrl;
  107. #if defined(CONFIG_ARM_S3C24XX_CPUFREQ)
  108. struct notifier_block freq_transition;
  109. #endif
  110. };
  111. static struct platform_device_id s3c24xx_driver_ids[] = {
  112. {
  113. .name = "s3c2410-i2c",
  114. .driver_data = 0,
  115. }, {
  116. .name = "s3c2440-i2c",
  117. .driver_data = QUIRK_S3C2440,
  118. }, {
  119. .name = "s3c2440-hdmiphy-i2c",
  120. .driver_data = QUIRK_S3C2440 | QUIRK_HDMIPHY | QUIRK_NO_GPIO,
  121. }, { },
  122. };
  123. MODULE_DEVICE_TABLE(platform, s3c24xx_driver_ids);
  124. static int i2c_s3c_irq_nextbyte(struct s3c24xx_i2c *i2c, unsigned long iicstat);
  125. #ifdef CONFIG_OF
  126. static const struct of_device_id s3c24xx_i2c_match[] = {
  127. { .compatible = "samsung,s3c2410-i2c", .data = (void *)0 },
  128. { .compatible = "samsung,s3c2440-i2c", .data = (void *)QUIRK_S3C2440 },
  129. { .compatible = "samsung,s3c2440-hdmiphy-i2c",
  130. .data = (void *)(QUIRK_S3C2440 | QUIRK_HDMIPHY | QUIRK_NO_GPIO) },
  131. { .compatible = "samsung,exynos5440-i2c",
  132. .data = (void *)(QUIRK_S3C2440 | QUIRK_NO_GPIO) },
  133. { .compatible = "samsung,exynos5-sata-phy-i2c",
  134. .data = (void *)(QUIRK_S3C2440 | QUIRK_POLL | QUIRK_NO_GPIO) },
  135. {},
  136. };
  137. MODULE_DEVICE_TABLE(of, s3c24xx_i2c_match);
  138. #endif
  139. /* s3c24xx_get_device_quirks
  140. *
  141. * Get controller type either from device tree or platform device variant.
  142. */
  143. static inline kernel_ulong_t s3c24xx_get_device_quirks(struct platform_device *pdev)
  144. {
  145. if (pdev->dev.of_node) {
  146. const struct of_device_id *match;
  147. match = of_match_node(s3c24xx_i2c_match, pdev->dev.of_node);
  148. return (kernel_ulong_t)match->data;
  149. }
  150. return platform_get_device_id(pdev)->driver_data;
  151. }
  152. /* s3c24xx_i2c_master_complete
  153. *
  154. * complete the message and wake up the caller, using the given return code,
  155. * or zero to mean ok.
  156. */
  157. static inline void s3c24xx_i2c_master_complete(struct s3c24xx_i2c *i2c, int ret)
  158. {
  159. dev_dbg(i2c->dev, "master_complete %d\n", ret);
  160. i2c->msg_ptr = 0;
  161. i2c->msg = NULL;
  162. i2c->msg_idx++;
  163. i2c->msg_num = 0;
  164. if (ret)
  165. i2c->msg_idx = ret;
  166. if (!(i2c->quirks & QUIRK_POLL))
  167. wake_up(&i2c->wait);
  168. }
  169. static inline void s3c24xx_i2c_disable_ack(struct s3c24xx_i2c *i2c)
  170. {
  171. unsigned long tmp;
  172. tmp = readl(i2c->regs + S3C2410_IICCON);
  173. writel(tmp & ~S3C2410_IICCON_ACKEN, i2c->regs + S3C2410_IICCON);
  174. }
  175. static inline void s3c24xx_i2c_enable_ack(struct s3c24xx_i2c *i2c)
  176. {
  177. unsigned long tmp;
  178. tmp = readl(i2c->regs + S3C2410_IICCON);
  179. writel(tmp | S3C2410_IICCON_ACKEN, i2c->regs + S3C2410_IICCON);
  180. }
  181. /* irq enable/disable functions */
  182. static inline void s3c24xx_i2c_disable_irq(struct s3c24xx_i2c *i2c)
  183. {
  184. unsigned long tmp;
  185. tmp = readl(i2c->regs + S3C2410_IICCON);
  186. writel(tmp & ~S3C2410_IICCON_IRQEN, i2c->regs + S3C2410_IICCON);
  187. }
  188. static inline void s3c24xx_i2c_enable_irq(struct s3c24xx_i2c *i2c)
  189. {
  190. unsigned long tmp;
  191. tmp = readl(i2c->regs + S3C2410_IICCON);
  192. writel(tmp | S3C2410_IICCON_IRQEN, i2c->regs + S3C2410_IICCON);
  193. }
  194. static bool is_ack(struct s3c24xx_i2c *i2c)
  195. {
  196. int tries;
  197. for (tries = 50; tries; --tries) {
  198. if (readl(i2c->regs + S3C2410_IICCON)
  199. & S3C2410_IICCON_IRQPEND) {
  200. if (!(readl(i2c->regs + S3C2410_IICSTAT)
  201. & S3C2410_IICSTAT_LASTBIT))
  202. return true;
  203. }
  204. usleep_range(1000, 2000);
  205. }
  206. dev_err(i2c->dev, "ack was not recieved\n");
  207. return false;
  208. }
  209. /* s3c24xx_i2c_message_start
  210. *
  211. * put the start of a message onto the bus
  212. */
  213. static void s3c24xx_i2c_message_start(struct s3c24xx_i2c *i2c,
  214. struct i2c_msg *msg)
  215. {
  216. unsigned int addr = (msg->addr & 0x7f) << 1;
  217. unsigned long stat;
  218. unsigned long iiccon;
  219. stat = 0;
  220. stat |= S3C2410_IICSTAT_TXRXEN;
  221. if (msg->flags & I2C_M_RD) {
  222. stat |= S3C2410_IICSTAT_MASTER_RX;
  223. addr |= 1;
  224. } else
  225. stat |= S3C2410_IICSTAT_MASTER_TX;
  226. if (msg->flags & I2C_M_REV_DIR_ADDR)
  227. addr ^= 1;
  228. /* todo - check for whether ack wanted or not */
  229. s3c24xx_i2c_enable_ack(i2c);
  230. iiccon = readl(i2c->regs + S3C2410_IICCON);
  231. writel(stat, i2c->regs + S3C2410_IICSTAT);
  232. dev_dbg(i2c->dev, "START: %08lx to IICSTAT, %02x to DS\n", stat, addr);
  233. writeb(addr, i2c->regs + S3C2410_IICDS);
  234. /* delay here to ensure the data byte has gotten onto the bus
  235. * before the transaction is started */
  236. ndelay(i2c->tx_setup);
  237. dev_dbg(i2c->dev, "iiccon, %08lx\n", iiccon);
  238. writel(iiccon, i2c->regs + S3C2410_IICCON);
  239. stat |= S3C2410_IICSTAT_START;
  240. writel(stat, i2c->regs + S3C2410_IICSTAT);
  241. if (i2c->quirks & QUIRK_POLL) {
  242. while ((i2c->msg_num != 0) && is_ack(i2c)) {
  243. i2c_s3c_irq_nextbyte(i2c, stat);
  244. stat = readl(i2c->regs + S3C2410_IICSTAT);
  245. if (stat & S3C2410_IICSTAT_ARBITR)
  246. dev_err(i2c->dev, "deal with arbitration loss\n");
  247. }
  248. }
  249. }
  250. static inline void s3c24xx_i2c_stop(struct s3c24xx_i2c *i2c, int ret)
  251. {
  252. unsigned long iicstat = readl(i2c->regs + S3C2410_IICSTAT);
  253. dev_dbg(i2c->dev, "STOP\n");
  254. /*
  255. * The datasheet says that the STOP sequence should be:
  256. * 1) I2CSTAT.5 = 0 - Clear BUSY (or 'generate STOP')
  257. * 2) I2CCON.4 = 0 - Clear IRQPEND
  258. * 3) Wait until the stop condition takes effect.
  259. * 4*) I2CSTAT.4 = 0 - Clear TXRXEN
  260. *
  261. * Where, step "4*" is only for buses with the "HDMIPHY" quirk.
  262. *
  263. * However, after much experimentation, it appears that:
  264. * a) normal buses automatically clear BUSY and transition from
  265. * Master->Slave when they complete generating a STOP condition.
  266. * Therefore, step (3) can be done in doxfer() by polling I2CCON.4
  267. * after starting the STOP generation here.
  268. * b) HDMIPHY bus does neither, so there is no way to do step 3.
  269. * There is no indication when this bus has finished generating
  270. * STOP.
  271. *
  272. * In fact, we have found that as soon as the IRQPEND bit is cleared in
  273. * step 2, the HDMIPHY bus generates the STOP condition, and then
  274. * immediately starts transferring another data byte, even though the
  275. * bus is supposedly stopped. This is presumably because the bus is
  276. * still in "Master" mode, and its BUSY bit is still set.
  277. *
  278. * To avoid these extra post-STOP transactions on HDMI phy devices, we
  279. * just disable Serial Output on the bus (I2CSTAT.4 = 0) directly,
  280. * instead of first generating a proper STOP condition. This should
  281. * float SDA & SCK terminating the transfer. Subsequent transfers
  282. * start with a proper START condition, and proceed normally.
  283. *
  284. * The HDMIPHY bus is an internal bus that always has exactly two
  285. * devices, the host as Master and the HDMIPHY device as the slave.
  286. * Skipping the STOP condition has been tested on this bus and works.
  287. */
  288. if (i2c->quirks & QUIRK_HDMIPHY) {
  289. /* Stop driving the I2C pins */
  290. iicstat &= ~S3C2410_IICSTAT_TXRXEN;
  291. } else {
  292. /* stop the transfer */
  293. iicstat &= ~S3C2410_IICSTAT_START;
  294. }
  295. writel(iicstat, i2c->regs + S3C2410_IICSTAT);
  296. i2c->state = STATE_STOP;
  297. s3c24xx_i2c_master_complete(i2c, ret);
  298. s3c24xx_i2c_disable_irq(i2c);
  299. }
  300. /* helper functions to determine the current state in the set of
  301. * messages we are sending */
  302. /* is_lastmsg()
  303. *
  304. * returns TRUE if the current message is the last in the set
  305. */
  306. static inline int is_lastmsg(struct s3c24xx_i2c *i2c)
  307. {
  308. return i2c->msg_idx >= (i2c->msg_num - 1);
  309. }
  310. /* is_msglast
  311. *
  312. * returns TRUE if we this is the last byte in the current message
  313. */
  314. static inline int is_msglast(struct s3c24xx_i2c *i2c)
  315. {
  316. /* msg->len is always 1 for the first byte of smbus block read.
  317. * Actual length will be read from slave. More bytes will be
  318. * read according to the length then. */
  319. if (i2c->msg->flags & I2C_M_RECV_LEN && i2c->msg->len == 1)
  320. return 0;
  321. return i2c->msg_ptr == i2c->msg->len-1;
  322. }
  323. /* is_msgend
  324. *
  325. * returns TRUE if we reached the end of the current message
  326. */
  327. static inline int is_msgend(struct s3c24xx_i2c *i2c)
  328. {
  329. return i2c->msg_ptr >= i2c->msg->len;
  330. }
  331. /* i2c_s3c_irq_nextbyte
  332. *
  333. * process an interrupt and work out what to do
  334. */
  335. static int i2c_s3c_irq_nextbyte(struct s3c24xx_i2c *i2c, unsigned long iicstat)
  336. {
  337. unsigned long tmp;
  338. unsigned char byte;
  339. int ret = 0;
  340. switch (i2c->state) {
  341. case STATE_IDLE:
  342. dev_err(i2c->dev, "%s: called in STATE_IDLE\n", __func__);
  343. goto out;
  344. case STATE_STOP:
  345. dev_err(i2c->dev, "%s: called in STATE_STOP\n", __func__);
  346. s3c24xx_i2c_disable_irq(i2c);
  347. goto out_ack;
  348. case STATE_START:
  349. /* last thing we did was send a start condition on the
  350. * bus, or started a new i2c message
  351. */
  352. if (iicstat & S3C2410_IICSTAT_LASTBIT &&
  353. !(i2c->msg->flags & I2C_M_IGNORE_NAK)) {
  354. /* ack was not received... */
  355. dev_dbg(i2c->dev, "ack was not received\n");
  356. s3c24xx_i2c_stop(i2c, -ENXIO);
  357. goto out_ack;
  358. }
  359. if (i2c->msg->flags & I2C_M_RD)
  360. i2c->state = STATE_READ;
  361. else
  362. i2c->state = STATE_WRITE;
  363. /* terminate the transfer if there is nothing to do
  364. * as this is used by the i2c probe to find devices. */
  365. if (is_lastmsg(i2c) && i2c->msg->len == 0) {
  366. s3c24xx_i2c_stop(i2c, 0);
  367. goto out_ack;
  368. }
  369. if (i2c->state == STATE_READ)
  370. goto prepare_read;
  371. /* fall through to the write state, as we will need to
  372. * send a byte as well */
  373. case STATE_WRITE:
  374. /* we are writing data to the device... check for the
  375. * end of the message, and if so, work out what to do
  376. */
  377. if (!(i2c->msg->flags & I2C_M_IGNORE_NAK)) {
  378. if (iicstat & S3C2410_IICSTAT_LASTBIT) {
  379. dev_dbg(i2c->dev, "WRITE: No Ack\n");
  380. s3c24xx_i2c_stop(i2c, -ECONNREFUSED);
  381. goto out_ack;
  382. }
  383. }
  384. retry_write:
  385. if (!is_msgend(i2c)) {
  386. byte = i2c->msg->buf[i2c->msg_ptr++];
  387. writeb(byte, i2c->regs + S3C2410_IICDS);
  388. /* delay after writing the byte to allow the
  389. * data setup time on the bus, as writing the
  390. * data to the register causes the first bit
  391. * to appear on SDA, and SCL will change as
  392. * soon as the interrupt is acknowledged */
  393. ndelay(i2c->tx_setup);
  394. } else if (!is_lastmsg(i2c)) {
  395. /* we need to go to the next i2c message */
  396. dev_dbg(i2c->dev, "WRITE: Next Message\n");
  397. i2c->msg_ptr = 0;
  398. i2c->msg_idx++;
  399. i2c->msg++;
  400. /* check to see if we need to do another message */
  401. if (i2c->msg->flags & I2C_M_NOSTART) {
  402. if (i2c->msg->flags & I2C_M_RD) {
  403. /* cannot do this, the controller
  404. * forces us to send a new START
  405. * when we change direction */
  406. s3c24xx_i2c_stop(i2c, -EINVAL);
  407. }
  408. goto retry_write;
  409. } else {
  410. /* send the new start */
  411. s3c24xx_i2c_message_start(i2c, i2c->msg);
  412. i2c->state = STATE_START;
  413. }
  414. } else {
  415. /* send stop */
  416. s3c24xx_i2c_stop(i2c, 0);
  417. }
  418. break;
  419. case STATE_READ:
  420. /* we have a byte of data in the data register, do
  421. * something with it, and then work out whether we are
  422. * going to do any more read/write
  423. */
  424. byte = readb(i2c->regs + S3C2410_IICDS);
  425. i2c->msg->buf[i2c->msg_ptr++] = byte;
  426. /* Add actual length to read for smbus block read */
  427. if (i2c->msg->flags & I2C_M_RECV_LEN && i2c->msg->len == 1)
  428. i2c->msg->len += byte;
  429. prepare_read:
  430. if (is_msglast(i2c)) {
  431. /* last byte of buffer */
  432. if (is_lastmsg(i2c))
  433. s3c24xx_i2c_disable_ack(i2c);
  434. } else if (is_msgend(i2c)) {
  435. /* ok, we've read the entire buffer, see if there
  436. * is anything else we need to do */
  437. if (is_lastmsg(i2c)) {
  438. /* last message, send stop and complete */
  439. dev_dbg(i2c->dev, "READ: Send Stop\n");
  440. s3c24xx_i2c_stop(i2c, 0);
  441. } else {
  442. /* go to the next transfer */
  443. dev_dbg(i2c->dev, "READ: Next Transfer\n");
  444. i2c->msg_ptr = 0;
  445. i2c->msg_idx++;
  446. i2c->msg++;
  447. }
  448. }
  449. break;
  450. }
  451. /* acknowlegde the IRQ and get back on with the work */
  452. out_ack:
  453. tmp = readl(i2c->regs + S3C2410_IICCON);
  454. tmp &= ~S3C2410_IICCON_IRQPEND;
  455. writel(tmp, i2c->regs + S3C2410_IICCON);
  456. out:
  457. return ret;
  458. }
  459. /* s3c24xx_i2c_irq
  460. *
  461. * top level IRQ servicing routine
  462. */
  463. static irqreturn_t s3c24xx_i2c_irq(int irqno, void *dev_id)
  464. {
  465. struct s3c24xx_i2c *i2c = dev_id;
  466. unsigned long status;
  467. unsigned long tmp;
  468. status = readl(i2c->regs + S3C2410_IICSTAT);
  469. if (status & S3C2410_IICSTAT_ARBITR) {
  470. /* deal with arbitration loss */
  471. dev_err(i2c->dev, "deal with arbitration loss\n");
  472. }
  473. if (i2c->state == STATE_IDLE) {
  474. dev_dbg(i2c->dev, "IRQ: error i2c->state == IDLE\n");
  475. tmp = readl(i2c->regs + S3C2410_IICCON);
  476. tmp &= ~S3C2410_IICCON_IRQPEND;
  477. writel(tmp, i2c->regs + S3C2410_IICCON);
  478. goto out;
  479. }
  480. /* pretty much this leaves us with the fact that we've
  481. * transmitted or received whatever byte we last sent */
  482. i2c_s3c_irq_nextbyte(i2c, status);
  483. out:
  484. return IRQ_HANDLED;
  485. }
  486. /* s3c24xx_i2c_set_master
  487. *
  488. * get the i2c bus for a master transaction
  489. */
  490. static int s3c24xx_i2c_set_master(struct s3c24xx_i2c *i2c)
  491. {
  492. unsigned long iicstat;
  493. int timeout = 400;
  494. while (timeout-- > 0) {
  495. iicstat = readl(i2c->regs + S3C2410_IICSTAT);
  496. if (!(iicstat & S3C2410_IICSTAT_BUSBUSY))
  497. return 0;
  498. msleep(1);
  499. }
  500. return -ETIMEDOUT;
  501. }
  502. /* s3c24xx_i2c_wait_idle
  503. *
  504. * wait for the i2c bus to become idle.
  505. */
  506. static void s3c24xx_i2c_wait_idle(struct s3c24xx_i2c *i2c)
  507. {
  508. unsigned long iicstat;
  509. ktime_t start, now;
  510. unsigned long delay;
  511. int spins;
  512. /* ensure the stop has been through the bus */
  513. dev_dbg(i2c->dev, "waiting for bus idle\n");
  514. start = now = ktime_get();
  515. /*
  516. * Most of the time, the bus is already idle within a few usec of the
  517. * end of a transaction. However, really slow i2c devices can stretch
  518. * the clock, delaying STOP generation.
  519. *
  520. * On slower SoCs this typically happens within a very small number of
  521. * instructions so busy wait briefly to avoid scheduling overhead.
  522. */
  523. spins = 3;
  524. iicstat = readl(i2c->regs + S3C2410_IICSTAT);
  525. while ((iicstat & S3C2410_IICSTAT_START) && --spins) {
  526. cpu_relax();
  527. iicstat = readl(i2c->regs + S3C2410_IICSTAT);
  528. }
  529. /*
  530. * If we do get an appreciable delay as a compromise between idle
  531. * detection latency for the normal, fast case, and system load in the
  532. * slow device case, use an exponential back off in the polling loop,
  533. * up to 1/10th of the total timeout, then continue to poll at a
  534. * constant rate up to the timeout.
  535. */
  536. delay = 1;
  537. while ((iicstat & S3C2410_IICSTAT_START) &&
  538. ktime_us_delta(now, start) < S3C2410_IDLE_TIMEOUT) {
  539. usleep_range(delay, 2 * delay);
  540. if (delay < S3C2410_IDLE_TIMEOUT / 10)
  541. delay <<= 1;
  542. now = ktime_get();
  543. iicstat = readl(i2c->regs + S3C2410_IICSTAT);
  544. }
  545. if (iicstat & S3C2410_IICSTAT_START)
  546. dev_warn(i2c->dev, "timeout waiting for bus idle\n");
  547. }
  548. /* s3c24xx_i2c_doxfer
  549. *
  550. * this starts an i2c transfer
  551. */
  552. static int s3c24xx_i2c_doxfer(struct s3c24xx_i2c *i2c,
  553. struct i2c_msg *msgs, int num)
  554. {
  555. unsigned long timeout;
  556. int ret;
  557. if (i2c->suspended)
  558. return -EIO;
  559. ret = s3c24xx_i2c_set_master(i2c);
  560. if (ret != 0) {
  561. dev_err(i2c->dev, "cannot get bus (error %d)\n", ret);
  562. ret = -EAGAIN;
  563. goto out;
  564. }
  565. i2c->msg = msgs;
  566. i2c->msg_num = num;
  567. i2c->msg_ptr = 0;
  568. i2c->msg_idx = 0;
  569. i2c->state = STATE_START;
  570. s3c24xx_i2c_enable_irq(i2c);
  571. s3c24xx_i2c_message_start(i2c, msgs);
  572. if (i2c->quirks & QUIRK_POLL) {
  573. ret = i2c->msg_idx;
  574. if (ret != num)
  575. dev_dbg(i2c->dev, "incomplete xfer (%d)\n", ret);
  576. goto out;
  577. }
  578. timeout = wait_event_timeout(i2c->wait, i2c->msg_num == 0, HZ * 5);
  579. ret = i2c->msg_idx;
  580. /* having these next two as dev_err() makes life very
  581. * noisy when doing an i2cdetect */
  582. if (timeout == 0)
  583. dev_dbg(i2c->dev, "timeout\n");
  584. else if (ret != num)
  585. dev_dbg(i2c->dev, "incomplete xfer (%d)\n", ret);
  586. /* For QUIRK_HDMIPHY, bus is already disabled */
  587. if (i2c->quirks & QUIRK_HDMIPHY)
  588. goto out;
  589. s3c24xx_i2c_wait_idle(i2c);
  590. out:
  591. return ret;
  592. }
  593. /* s3c24xx_i2c_xfer
  594. *
  595. * first port of call from the i2c bus code when an message needs
  596. * transferring across the i2c bus.
  597. */
  598. static int s3c24xx_i2c_xfer(struct i2c_adapter *adap,
  599. struct i2c_msg *msgs, int num)
  600. {
  601. struct s3c24xx_i2c *i2c = (struct s3c24xx_i2c *)adap->algo_data;
  602. int retry;
  603. int ret;
  604. pm_runtime_get_sync(&adap->dev);
  605. clk_prepare_enable(i2c->clk);
  606. for (retry = 0; retry < adap->retries; retry++) {
  607. ret = s3c24xx_i2c_doxfer(i2c, msgs, num);
  608. if (ret != -EAGAIN) {
  609. clk_disable_unprepare(i2c->clk);
  610. pm_runtime_put(&adap->dev);
  611. return ret;
  612. }
  613. dev_dbg(i2c->dev, "Retrying transmission (%d)\n", retry);
  614. udelay(100);
  615. }
  616. clk_disable_unprepare(i2c->clk);
  617. pm_runtime_put(&adap->dev);
  618. return -EREMOTEIO;
  619. }
  620. /* declare our i2c functionality */
  621. static u32 s3c24xx_i2c_func(struct i2c_adapter *adap)
  622. {
  623. return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_NOSTART |
  624. I2C_FUNC_PROTOCOL_MANGLING;
  625. }
  626. /* i2c bus registration info */
  627. static const struct i2c_algorithm s3c24xx_i2c_algorithm = {
  628. .master_xfer = s3c24xx_i2c_xfer,
  629. .functionality = s3c24xx_i2c_func,
  630. };
  631. /* s3c24xx_i2c_calcdivisor
  632. *
  633. * return the divisor settings for a given frequency
  634. */
  635. static int s3c24xx_i2c_calcdivisor(unsigned long clkin, unsigned int wanted,
  636. unsigned int *div1, unsigned int *divs)
  637. {
  638. unsigned int calc_divs = clkin / wanted;
  639. unsigned int calc_div1;
  640. if (calc_divs > (16*16))
  641. calc_div1 = 512;
  642. else
  643. calc_div1 = 16;
  644. calc_divs += calc_div1-1;
  645. calc_divs /= calc_div1;
  646. if (calc_divs == 0)
  647. calc_divs = 1;
  648. if (calc_divs > 17)
  649. calc_divs = 17;
  650. *divs = calc_divs;
  651. *div1 = calc_div1;
  652. return clkin / (calc_divs * calc_div1);
  653. }
  654. /* s3c24xx_i2c_clockrate
  655. *
  656. * work out a divisor for the user requested frequency setting,
  657. * either by the requested frequency, or scanning the acceptable
  658. * range of frequencies until something is found
  659. */
  660. static int s3c24xx_i2c_clockrate(struct s3c24xx_i2c *i2c, unsigned int *got)
  661. {
  662. struct s3c2410_platform_i2c *pdata = i2c->pdata;
  663. unsigned long clkin = clk_get_rate(i2c->clk);
  664. unsigned int divs, div1;
  665. unsigned long target_frequency;
  666. u32 iiccon;
  667. int freq;
  668. i2c->clkrate = clkin;
  669. clkin /= 1000; /* clkin now in KHz */
  670. dev_dbg(i2c->dev, "pdata desired frequency %lu\n", pdata->frequency);
  671. target_frequency = pdata->frequency ? pdata->frequency : 100000;
  672. target_frequency /= 1000; /* Target frequency now in KHz */
  673. freq = s3c24xx_i2c_calcdivisor(clkin, target_frequency, &div1, &divs);
  674. if (freq > target_frequency) {
  675. dev_err(i2c->dev,
  676. "Unable to achieve desired frequency %luKHz." \
  677. " Lowest achievable %dKHz\n", target_frequency, freq);
  678. return -EINVAL;
  679. }
  680. *got = freq;
  681. iiccon = readl(i2c->regs + S3C2410_IICCON);
  682. iiccon &= ~(S3C2410_IICCON_SCALEMASK | S3C2410_IICCON_TXDIV_512);
  683. iiccon |= (divs-1);
  684. if (div1 == 512)
  685. iiccon |= S3C2410_IICCON_TXDIV_512;
  686. if (i2c->quirks & QUIRK_POLL)
  687. iiccon |= S3C2410_IICCON_SCALE(2);
  688. writel(iiccon, i2c->regs + S3C2410_IICCON);
  689. if (i2c->quirks & QUIRK_S3C2440) {
  690. unsigned long sda_delay;
  691. if (pdata->sda_delay) {
  692. sda_delay = clkin * pdata->sda_delay;
  693. sda_delay = DIV_ROUND_UP(sda_delay, 1000000);
  694. sda_delay = DIV_ROUND_UP(sda_delay, 5);
  695. if (sda_delay > 3)
  696. sda_delay = 3;
  697. sda_delay |= S3C2410_IICLC_FILTER_ON;
  698. } else
  699. sda_delay = 0;
  700. dev_dbg(i2c->dev, "IICLC=%08lx\n", sda_delay);
  701. writel(sda_delay, i2c->regs + S3C2440_IICLC);
  702. }
  703. return 0;
  704. }
  705. #if defined(CONFIG_ARM_S3C24XX_CPUFREQ)
  706. #define freq_to_i2c(_n) container_of(_n, struct s3c24xx_i2c, freq_transition)
  707. static int s3c24xx_i2c_cpufreq_transition(struct notifier_block *nb,
  708. unsigned long val, void *data)
  709. {
  710. struct s3c24xx_i2c *i2c = freq_to_i2c(nb);
  711. unsigned int got;
  712. int delta_f;
  713. int ret;
  714. delta_f = clk_get_rate(i2c->clk) - i2c->clkrate;
  715. /* if we're post-change and the input clock has slowed down
  716. * or at pre-change and the clock is about to speed up, then
  717. * adjust our clock rate. <0 is slow, >0 speedup.
  718. */
  719. if ((val == CPUFREQ_POSTCHANGE && delta_f < 0) ||
  720. (val == CPUFREQ_PRECHANGE && delta_f > 0)) {
  721. i2c_lock_adapter(&i2c->adap);
  722. ret = s3c24xx_i2c_clockrate(i2c, &got);
  723. i2c_unlock_adapter(&i2c->adap);
  724. if (ret < 0)
  725. dev_err(i2c->dev, "cannot find frequency\n");
  726. else
  727. dev_info(i2c->dev, "setting freq %d\n", got);
  728. }
  729. return 0;
  730. }
  731. static inline int s3c24xx_i2c_register_cpufreq(struct s3c24xx_i2c *i2c)
  732. {
  733. i2c->freq_transition.notifier_call = s3c24xx_i2c_cpufreq_transition;
  734. return cpufreq_register_notifier(&i2c->freq_transition,
  735. CPUFREQ_TRANSITION_NOTIFIER);
  736. }
  737. static inline void s3c24xx_i2c_deregister_cpufreq(struct s3c24xx_i2c *i2c)
  738. {
  739. cpufreq_unregister_notifier(&i2c->freq_transition,
  740. CPUFREQ_TRANSITION_NOTIFIER);
  741. }
  742. #else
  743. static inline int s3c24xx_i2c_register_cpufreq(struct s3c24xx_i2c *i2c)
  744. {
  745. return 0;
  746. }
  747. static inline void s3c24xx_i2c_deregister_cpufreq(struct s3c24xx_i2c *i2c)
  748. {
  749. }
  750. #endif
  751. #ifdef CONFIG_OF
  752. static int s3c24xx_i2c_parse_dt_gpio(struct s3c24xx_i2c *i2c)
  753. {
  754. int idx, gpio, ret;
  755. if (i2c->quirks & QUIRK_NO_GPIO)
  756. return 0;
  757. for (idx = 0; idx < 2; idx++) {
  758. gpio = of_get_gpio(i2c->dev->of_node, idx);
  759. if (!gpio_is_valid(gpio)) {
  760. dev_err(i2c->dev, "invalid gpio[%d]: %d\n", idx, gpio);
  761. goto free_gpio;
  762. }
  763. i2c->gpios[idx] = gpio;
  764. ret = gpio_request(gpio, "i2c-bus");
  765. if (ret) {
  766. dev_err(i2c->dev, "gpio [%d] request failed\n", gpio);
  767. goto free_gpio;
  768. }
  769. }
  770. return 0;
  771. free_gpio:
  772. while (--idx >= 0)
  773. gpio_free(i2c->gpios[idx]);
  774. return -EINVAL;
  775. }
  776. static void s3c24xx_i2c_dt_gpio_free(struct s3c24xx_i2c *i2c)
  777. {
  778. unsigned int idx;
  779. if (i2c->quirks & QUIRK_NO_GPIO)
  780. return;
  781. for (idx = 0; idx < 2; idx++)
  782. gpio_free(i2c->gpios[idx]);
  783. }
  784. #else
  785. static int s3c24xx_i2c_parse_dt_gpio(struct s3c24xx_i2c *i2c)
  786. {
  787. return 0;
  788. }
  789. static void s3c24xx_i2c_dt_gpio_free(struct s3c24xx_i2c *i2c)
  790. {
  791. }
  792. #endif
  793. /* s3c24xx_i2c_init
  794. *
  795. * initialise the controller, set the IO lines and frequency
  796. */
  797. static int s3c24xx_i2c_init(struct s3c24xx_i2c *i2c)
  798. {
  799. unsigned long iicon = S3C2410_IICCON_IRQEN | S3C2410_IICCON_ACKEN;
  800. struct s3c2410_platform_i2c *pdata;
  801. unsigned int freq;
  802. /* get the plafrom data */
  803. pdata = i2c->pdata;
  804. /* write slave address */
  805. writeb(pdata->slave_addr, i2c->regs + S3C2410_IICADD);
  806. dev_info(i2c->dev, "slave address 0x%02x\n", pdata->slave_addr);
  807. writel(iicon, i2c->regs + S3C2410_IICCON);
  808. /* we need to work out the divisors for the clock... */
  809. if (s3c24xx_i2c_clockrate(i2c, &freq) != 0) {
  810. writel(0, i2c->regs + S3C2410_IICCON);
  811. dev_err(i2c->dev, "cannot meet bus frequency required\n");
  812. return -EINVAL;
  813. }
  814. /* todo - check that the i2c lines aren't being dragged anywhere */
  815. dev_info(i2c->dev, "bus frequency set to %d KHz\n", freq);
  816. dev_dbg(i2c->dev, "S3C2410_IICCON=0x%02lx\n", iicon);
  817. return 0;
  818. }
  819. #ifdef CONFIG_OF
  820. /* s3c24xx_i2c_parse_dt
  821. *
  822. * Parse the device tree node and retreive the platform data.
  823. */
  824. static void
  825. s3c24xx_i2c_parse_dt(struct device_node *np, struct s3c24xx_i2c *i2c)
  826. {
  827. struct s3c2410_platform_i2c *pdata = i2c->pdata;
  828. if (!np)
  829. return;
  830. pdata->bus_num = -1; /* i2c bus number is dynamically assigned */
  831. of_property_read_u32(np, "samsung,i2c-sda-delay", &pdata->sda_delay);
  832. of_property_read_u32(np, "samsung,i2c-slave-addr", &pdata->slave_addr);
  833. of_property_read_u32(np, "samsung,i2c-max-bus-freq",
  834. (u32 *)&pdata->frequency);
  835. }
  836. #else
  837. static void
  838. s3c24xx_i2c_parse_dt(struct device_node *np, struct s3c24xx_i2c *i2c)
  839. {
  840. return;
  841. }
  842. #endif
  843. /* s3c24xx_i2c_probe
  844. *
  845. * called by the bus driver when a suitable device is found
  846. */
  847. static int s3c24xx_i2c_probe(struct platform_device *pdev)
  848. {
  849. struct s3c24xx_i2c *i2c;
  850. struct s3c2410_platform_i2c *pdata = NULL;
  851. struct resource *res;
  852. int ret;
  853. if (!pdev->dev.of_node) {
  854. pdata = dev_get_platdata(&pdev->dev);
  855. if (!pdata) {
  856. dev_err(&pdev->dev, "no platform data\n");
  857. return -EINVAL;
  858. }
  859. }
  860. i2c = devm_kzalloc(&pdev->dev, sizeof(struct s3c24xx_i2c), GFP_KERNEL);
  861. if (!i2c) {
  862. dev_err(&pdev->dev, "no memory for state\n");
  863. return -ENOMEM;
  864. }
  865. i2c->pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
  866. if (!i2c->pdata) {
  867. dev_err(&pdev->dev, "no memory for platform data\n");
  868. return -ENOMEM;
  869. }
  870. i2c->quirks = s3c24xx_get_device_quirks(pdev);
  871. if (pdata)
  872. memcpy(i2c->pdata, pdata, sizeof(*pdata));
  873. else
  874. s3c24xx_i2c_parse_dt(pdev->dev.of_node, i2c);
  875. strlcpy(i2c->adap.name, "s3c2410-i2c", sizeof(i2c->adap.name));
  876. i2c->adap.owner = THIS_MODULE;
  877. i2c->adap.algo = &s3c24xx_i2c_algorithm;
  878. i2c->adap.retries = 2;
  879. i2c->adap.class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
  880. i2c->tx_setup = 50;
  881. init_waitqueue_head(&i2c->wait);
  882. /* find the clock and enable it */
  883. i2c->dev = &pdev->dev;
  884. i2c->clk = devm_clk_get(&pdev->dev, "i2c");
  885. if (IS_ERR(i2c->clk)) {
  886. dev_err(&pdev->dev, "cannot get clock\n");
  887. return -ENOENT;
  888. }
  889. dev_dbg(&pdev->dev, "clock source %p\n", i2c->clk);
  890. /* map the registers */
  891. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  892. i2c->regs = devm_ioremap_resource(&pdev->dev, res);
  893. if (IS_ERR(i2c->regs))
  894. return PTR_ERR(i2c->regs);
  895. dev_dbg(&pdev->dev, "registers %p (%p)\n",
  896. i2c->regs, res);
  897. /* setup info block for the i2c core */
  898. i2c->adap.algo_data = i2c;
  899. i2c->adap.dev.parent = &pdev->dev;
  900. i2c->pctrl = devm_pinctrl_get_select_default(i2c->dev);
  901. /* inititalise the i2c gpio lines */
  902. if (i2c->pdata->cfg_gpio) {
  903. i2c->pdata->cfg_gpio(to_platform_device(i2c->dev));
  904. } else if (IS_ERR(i2c->pctrl) && s3c24xx_i2c_parse_dt_gpio(i2c)) {
  905. return -EINVAL;
  906. }
  907. /* initialise the i2c controller */
  908. clk_prepare_enable(i2c->clk);
  909. ret = s3c24xx_i2c_init(i2c);
  910. clk_disable_unprepare(i2c->clk);
  911. if (ret != 0) {
  912. dev_err(&pdev->dev, "I2C controller init failed\n");
  913. return ret;
  914. }
  915. /* find the IRQ for this unit (note, this relies on the init call to
  916. * ensure no current IRQs pending
  917. */
  918. if (!(i2c->quirks & QUIRK_POLL)) {
  919. i2c->irq = ret = platform_get_irq(pdev, 0);
  920. if (ret <= 0) {
  921. dev_err(&pdev->dev, "cannot find IRQ\n");
  922. return ret;
  923. }
  924. ret = devm_request_irq(&pdev->dev, i2c->irq, s3c24xx_i2c_irq, 0,
  925. dev_name(&pdev->dev), i2c);
  926. if (ret != 0) {
  927. dev_err(&pdev->dev, "cannot claim IRQ %d\n", i2c->irq);
  928. return ret;
  929. }
  930. }
  931. ret = s3c24xx_i2c_register_cpufreq(i2c);
  932. if (ret < 0) {
  933. dev_err(&pdev->dev, "failed to register cpufreq notifier\n");
  934. return ret;
  935. }
  936. /* Note, previous versions of the driver used i2c_add_adapter()
  937. * to add the bus at any number. We now pass the bus number via
  938. * the platform data, so if unset it will now default to always
  939. * being bus 0.
  940. */
  941. i2c->adap.nr = i2c->pdata->bus_num;
  942. i2c->adap.dev.of_node = pdev->dev.of_node;
  943. ret = i2c_add_numbered_adapter(&i2c->adap);
  944. if (ret < 0) {
  945. dev_err(&pdev->dev, "failed to add bus to i2c core\n");
  946. s3c24xx_i2c_deregister_cpufreq(i2c);
  947. return ret;
  948. }
  949. platform_set_drvdata(pdev, i2c);
  950. pm_runtime_enable(&pdev->dev);
  951. pm_runtime_enable(&i2c->adap.dev);
  952. dev_info(&pdev->dev, "%s: S3C I2C adapter\n", dev_name(&i2c->adap.dev));
  953. return 0;
  954. }
  955. /* s3c24xx_i2c_remove
  956. *
  957. * called when device is removed from the bus
  958. */
  959. static int s3c24xx_i2c_remove(struct platform_device *pdev)
  960. {
  961. struct s3c24xx_i2c *i2c = platform_get_drvdata(pdev);
  962. pm_runtime_disable(&i2c->adap.dev);
  963. pm_runtime_disable(&pdev->dev);
  964. s3c24xx_i2c_deregister_cpufreq(i2c);
  965. i2c_del_adapter(&i2c->adap);
  966. if (pdev->dev.of_node && IS_ERR(i2c->pctrl))
  967. s3c24xx_i2c_dt_gpio_free(i2c);
  968. return 0;
  969. }
  970. #ifdef CONFIG_PM_SLEEP
  971. static int s3c24xx_i2c_suspend_noirq(struct device *dev)
  972. {
  973. struct platform_device *pdev = to_platform_device(dev);
  974. struct s3c24xx_i2c *i2c = platform_get_drvdata(pdev);
  975. i2c->suspended = 1;
  976. return 0;
  977. }
  978. static int s3c24xx_i2c_resume(struct device *dev)
  979. {
  980. struct platform_device *pdev = to_platform_device(dev);
  981. struct s3c24xx_i2c *i2c = platform_get_drvdata(pdev);
  982. i2c->suspended = 0;
  983. clk_prepare_enable(i2c->clk);
  984. s3c24xx_i2c_init(i2c);
  985. clk_disable_unprepare(i2c->clk);
  986. return 0;
  987. }
  988. #endif
  989. #ifdef CONFIG_PM
  990. static const struct dev_pm_ops s3c24xx_i2c_dev_pm_ops = {
  991. #ifdef CONFIG_PM_SLEEP
  992. .suspend_noirq = s3c24xx_i2c_suspend_noirq,
  993. .resume = s3c24xx_i2c_resume,
  994. #endif
  995. };
  996. #define S3C24XX_DEV_PM_OPS (&s3c24xx_i2c_dev_pm_ops)
  997. #else
  998. #define S3C24XX_DEV_PM_OPS NULL
  999. #endif
  1000. /* device driver for platform bus bits */
  1001. static struct platform_driver s3c24xx_i2c_driver = {
  1002. .probe = s3c24xx_i2c_probe,
  1003. .remove = s3c24xx_i2c_remove,
  1004. .id_table = s3c24xx_driver_ids,
  1005. .driver = {
  1006. .owner = THIS_MODULE,
  1007. .name = "s3c-i2c",
  1008. .pm = S3C24XX_DEV_PM_OPS,
  1009. .of_match_table = of_match_ptr(s3c24xx_i2c_match),
  1010. },
  1011. };
  1012. static int __init i2c_adap_s3c_init(void)
  1013. {
  1014. return platform_driver_register(&s3c24xx_i2c_driver);
  1015. }
  1016. subsys_initcall(i2c_adap_s3c_init);
  1017. static void __exit i2c_adap_s3c_exit(void)
  1018. {
  1019. platform_driver_unregister(&s3c24xx_i2c_driver);
  1020. }
  1021. module_exit(i2c_adap_s3c_exit);
  1022. MODULE_DESCRIPTION("S3C24XX I2C Bus driver");
  1023. MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
  1024. MODULE_LICENSE("GPL");