s3c24x0_i2c.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249
  1. /*
  2. * (C) Copyright 2002
  3. * David Mueller, ELSOFT AG, d.mueller@elsoft.ch
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. /* This code should work for both the S3C2400 and the S3C2410
  8. * as they seem to have the same I2C controller inside.
  9. * The different address mapping is handled by the s3c24xx.h files below.
  10. */
  11. #include <common.h>
  12. #include <fdtdec.h>
  13. #if (defined CONFIG_EXYNOS4 || defined CONFIG_EXYNOS5)
  14. #include <asm/arch/clk.h>
  15. #include <asm/arch/cpu.h>
  16. #include <asm/arch/pinmux.h>
  17. #else
  18. #include <asm/arch/s3c24x0_cpu.h>
  19. #endif
  20. #include <asm/io.h>
  21. #include <i2c.h>
  22. #include "s3c24x0_i2c.h"
  23. #define I2C_WRITE 0
  24. #define I2C_READ 1
  25. #define I2C_OK 0
  26. #define I2C_NOK 1
  27. #define I2C_NACK 2
  28. #define I2C_NOK_LA 3 /* Lost arbitration */
  29. #define I2C_NOK_TOUT 4 /* time out */
  30. /* HSI2C specific register description */
  31. /* I2C_CTL Register bits */
  32. #define HSI2C_FUNC_MODE_I2C (1u << 0)
  33. #define HSI2C_MASTER (1u << 3)
  34. #define HSI2C_RXCHON (1u << 6) /* Write/Send */
  35. #define HSI2C_TXCHON (1u << 7) /* Read/Receive */
  36. #define HSI2C_SW_RST (1u << 31)
  37. /* I2C_FIFO_CTL Register bits */
  38. #define HSI2C_RXFIFO_EN (1u << 0)
  39. #define HSI2C_TXFIFO_EN (1u << 1)
  40. #define HSI2C_TXFIFO_TRIGGER_LEVEL (0x20 << 16)
  41. #define HSI2C_RXFIFO_TRIGGER_LEVEL (0x20 << 4)
  42. /* I2C_TRAILING_CTL Register bits */
  43. #define HSI2C_TRAILING_COUNT (0xff)
  44. /* I2C_INT_EN Register bits */
  45. #define HSI2C_TX_UNDERRUN_EN (1u << 2)
  46. #define HSI2C_TX_OVERRUN_EN (1u << 3)
  47. #define HSI2C_RX_UNDERRUN_EN (1u << 4)
  48. #define HSI2C_RX_OVERRUN_EN (1u << 5)
  49. #define HSI2C_INT_TRAILING_EN (1u << 6)
  50. #define HSI2C_INT_I2C_EN (1u << 9)
  51. #define HSI2C_INT_ERROR_MASK (HSI2C_TX_UNDERRUN_EN |\
  52. HSI2C_TX_OVERRUN_EN |\
  53. HSI2C_RX_UNDERRUN_EN |\
  54. HSI2C_RX_OVERRUN_EN |\
  55. HSI2C_INT_TRAILING_EN)
  56. /* I2C_CONF Register bits */
  57. #define HSI2C_AUTO_MODE (1u << 31)
  58. #define HSI2C_10BIT_ADDR_MODE (1u << 30)
  59. #define HSI2C_HS_MODE (1u << 29)
  60. /* I2C_AUTO_CONF Register bits */
  61. #define HSI2C_READ_WRITE (1u << 16)
  62. #define HSI2C_STOP_AFTER_TRANS (1u << 17)
  63. #define HSI2C_MASTER_RUN (1u << 31)
  64. /* I2C_TIMEOUT Register bits */
  65. #define HSI2C_TIMEOUT_EN (1u << 31)
  66. /* I2C_TRANS_STATUS register bits */
  67. #define HSI2C_MASTER_BUSY (1u << 17)
  68. #define HSI2C_SLAVE_BUSY (1u << 16)
  69. #define HSI2C_TIMEOUT_AUTO (1u << 4)
  70. #define HSI2C_NO_DEV (1u << 3)
  71. #define HSI2C_NO_DEV_ACK (1u << 2)
  72. #define HSI2C_TRANS_ABORT (1u << 1)
  73. #define HSI2C_TRANS_SUCCESS (1u << 0)
  74. #define HSI2C_TRANS_ERROR_MASK (HSI2C_TIMEOUT_AUTO |\
  75. HSI2C_NO_DEV | HSI2C_NO_DEV_ACK |\
  76. HSI2C_TRANS_ABORT)
  77. #define HSI2C_TRANS_FINISHED_MASK (HSI2C_TRANS_ERROR_MASK | HSI2C_TRANS_SUCCESS)
  78. /* I2C_FIFO_STAT Register bits */
  79. #define HSI2C_RX_FIFO_EMPTY (1u << 24)
  80. #define HSI2C_RX_FIFO_FULL (1u << 23)
  81. #define HSI2C_TX_FIFO_EMPTY (1u << 8)
  82. #define HSI2C_TX_FIFO_FULL (1u << 7)
  83. #define HSI2C_RX_FIFO_LEVEL(x) (((x) >> 16) & 0x7f)
  84. #define HSI2C_TX_FIFO_LEVEL(x) ((x) & 0x7f)
  85. #define HSI2C_SLV_ADDR_MAS(x) ((x & 0x3ff) << 10)
  86. /* S3C I2C Controller bits */
  87. #define I2CSTAT_BSY 0x20 /* Busy bit */
  88. #define I2CSTAT_NACK 0x01 /* Nack bit */
  89. #define I2CCON_ACKGEN 0x80 /* Acknowledge generation */
  90. #define I2CCON_IRPND 0x10 /* Interrupt pending bit */
  91. #define I2C_MODE_MT 0xC0 /* Master Transmit Mode */
  92. #define I2C_MODE_MR 0x80 /* Master Receive Mode */
  93. #define I2C_START_STOP 0x20 /* START / STOP */
  94. #define I2C_TXRX_ENA 0x10 /* I2C Tx/Rx enable */
  95. #define I2C_TIMEOUT_MS 1000 /* 1 second */
  96. #define HSI2C_TIMEOUT_US 100000 /* 100 ms, finer granularity */
  97. /* To support VCMA9 boards and other who dont define max_i2c_num */
  98. #ifndef CONFIG_MAX_I2C_NUM
  99. #define CONFIG_MAX_I2C_NUM 1
  100. #endif
  101. /*
  102. * For SPL boot some boards need i2c before SDRAM is initialised so force
  103. * variables to live in SRAM
  104. */
  105. static struct s3c24x0_i2c_bus i2c_bus[CONFIG_MAX_I2C_NUM]
  106. __attribute__((section(".data")));
  107. /**
  108. * Get a pointer to the given bus index
  109. *
  110. * @bus_idx: Bus index to look up
  111. * @return pointer to bus, or NULL if invalid or not available
  112. */
  113. static struct s3c24x0_i2c_bus *get_bus(unsigned int bus_idx)
  114. {
  115. if (bus_idx < ARRAY_SIZE(i2c_bus)) {
  116. struct s3c24x0_i2c_bus *bus;
  117. bus = &i2c_bus[bus_idx];
  118. if (bus->active)
  119. return bus;
  120. }
  121. debug("Undefined bus: %d\n", bus_idx);
  122. return NULL;
  123. }
  124. #if !(defined CONFIG_EXYNOS4 || defined CONFIG_EXYNOS5)
  125. static int GetI2CSDA(void)
  126. {
  127. struct s3c24x0_gpio *gpio = s3c24x0_get_base_gpio();
  128. #ifdef CONFIG_S3C2410
  129. return (readl(&gpio->gpedat) & 0x8000) >> 15;
  130. #endif
  131. #ifdef CONFIG_S3C2400
  132. return (readl(&gpio->pgdat) & 0x0020) >> 5;
  133. #endif
  134. }
  135. static void SetI2CSCL(int x)
  136. {
  137. struct s3c24x0_gpio *gpio = s3c24x0_get_base_gpio();
  138. #ifdef CONFIG_S3C2410
  139. writel((readl(&gpio->gpedat) & ~0x4000) |
  140. (x & 1) << 14, &gpio->gpedat);
  141. #endif
  142. #ifdef CONFIG_S3C2400
  143. writel((readl(&gpio->pgdat) & ~0x0040) | (x & 1) << 6, &gpio->pgdat);
  144. #endif
  145. }
  146. #endif
  147. /*
  148. * Wait til the byte transfer is completed.
  149. *
  150. * @param i2c- pointer to the appropriate i2c register bank.
  151. * @return I2C_OK, if transmission was ACKED
  152. * I2C_NACK, if transmission was NACKED
  153. * I2C_NOK_TIMEOUT, if transaction did not complete in I2C_TIMEOUT_MS
  154. */
  155. static int WaitForXfer(struct s3c24x0_i2c *i2c)
  156. {
  157. ulong start_time = get_timer(0);
  158. do {
  159. if (readl(&i2c->iiccon) & I2CCON_IRPND)
  160. return (readl(&i2c->iicstat) & I2CSTAT_NACK) ?
  161. I2C_NACK : I2C_OK;
  162. } while (get_timer(start_time) < I2C_TIMEOUT_MS);
  163. return I2C_NOK_TOUT;
  164. }
  165. /*
  166. * Wait for transfer completion.
  167. *
  168. * This function reads the interrupt status register waiting for the INT_I2C
  169. * bit to be set, which indicates copletion of a transaction.
  170. *
  171. * @param i2c: pointer to the appropriate register bank
  172. *
  173. * @return: I2C_OK in case of successful completion, I2C_NOK_TIMEOUT in case
  174. * the status bits do not get set in time, or an approrpiate error
  175. * value in case of transfer errors.
  176. */
  177. static int hsi2c_wait_for_trx(struct exynos5_hsi2c *i2c)
  178. {
  179. int i = HSI2C_TIMEOUT_US;
  180. while (i-- > 0) {
  181. u32 int_status = readl(&i2c->usi_int_stat);
  182. if (int_status & HSI2C_INT_I2C_EN) {
  183. u32 trans_status = readl(&i2c->usi_trans_status);
  184. /* Deassert pending interrupt. */
  185. writel(int_status, &i2c->usi_int_stat);
  186. if (trans_status & HSI2C_NO_DEV_ACK) {
  187. debug("%s: no ACK from device\n", __func__);
  188. return I2C_NACK;
  189. }
  190. if (trans_status & HSI2C_NO_DEV) {
  191. debug("%s: no device\n", __func__);
  192. return I2C_NOK;
  193. }
  194. if (trans_status & HSI2C_TRANS_ABORT) {
  195. debug("%s: arbitration lost\n", __func__);
  196. return I2C_NOK_LA;
  197. }
  198. if (trans_status & HSI2C_TIMEOUT_AUTO) {
  199. debug("%s: device timed out\n", __func__);
  200. return I2C_NOK_TOUT;
  201. }
  202. return I2C_OK;
  203. }
  204. udelay(1);
  205. }
  206. debug("%s: transaction timeout!\n", __func__);
  207. return I2C_NOK_TOUT;
  208. }
  209. static void ReadWriteByte(struct s3c24x0_i2c *i2c)
  210. {
  211. writel(readl(&i2c->iiccon) & ~I2CCON_IRPND, &i2c->iiccon);
  212. }
  213. static struct s3c24x0_i2c *get_base_i2c(int bus)
  214. {
  215. #ifdef CONFIG_EXYNOS4
  216. struct s3c24x0_i2c *i2c = (struct s3c24x0_i2c *)(samsung_get_base_i2c()
  217. + (EXYNOS4_I2C_SPACING
  218. * bus));
  219. return i2c;
  220. #elif defined CONFIG_EXYNOS5
  221. struct s3c24x0_i2c *i2c = (struct s3c24x0_i2c *)(samsung_get_base_i2c()
  222. + (EXYNOS5_I2C_SPACING
  223. * bus));
  224. return i2c;
  225. #else
  226. return s3c24x0_get_base_i2c();
  227. #endif
  228. }
  229. static void i2c_ch_init(struct s3c24x0_i2c *i2c, int speed, int slaveadd)
  230. {
  231. ulong freq, pres = 16, div;
  232. #if (defined CONFIG_EXYNOS4 || defined CONFIG_EXYNOS5)
  233. freq = get_i2c_clk();
  234. #else
  235. freq = get_PCLK();
  236. #endif
  237. /* calculate prescaler and divisor values */
  238. if ((freq / pres / (16 + 1)) > speed)
  239. /* set prescaler to 512 */
  240. pres = 512;
  241. div = 0;
  242. while ((freq / pres / (div + 1)) > speed)
  243. div++;
  244. /* set prescaler, divisor according to freq, also set ACKGEN, IRQ */
  245. writel((div & 0x0F) | 0xA0 | ((pres == 512) ? 0x40 : 0), &i2c->iiccon);
  246. /* init to SLAVE REVEIVE and set slaveaddr */
  247. writel(0, &i2c->iicstat);
  248. writel(slaveadd, &i2c->iicadd);
  249. /* program Master Transmit (and implicit STOP) */
  250. writel(I2C_MODE_MT | I2C_TXRX_ENA, &i2c->iicstat);
  251. }
  252. static int hsi2c_get_clk_details(struct s3c24x0_i2c_bus *i2c_bus)
  253. {
  254. struct exynos5_hsi2c *hsregs = i2c_bus->hsregs;
  255. ulong clkin;
  256. unsigned int op_clk = i2c_bus->clock_frequency;
  257. unsigned int i = 0, utemp0 = 0, utemp1 = 0;
  258. unsigned int t_ftl_cycle;
  259. #if (defined CONFIG_EXYNOS4 || defined CONFIG_EXYNOS5)
  260. clkin = get_i2c_clk();
  261. #else
  262. clkin = get_PCLK();
  263. #endif
  264. /* FPCLK / FI2C =
  265. * (CLK_DIV + 1) * (TSCLK_L + TSCLK_H + 2) + 8 + 2 * FLT_CYCLE
  266. * uTemp0 = (CLK_DIV + 1) * (TSCLK_L + TSCLK_H + 2)
  267. * uTemp1 = (TSCLK_L + TSCLK_H + 2)
  268. * uTemp2 = TSCLK_L + TSCLK_H
  269. */
  270. t_ftl_cycle = (readl(&hsregs->usi_conf) >> 16) & 0x7;
  271. utemp0 = (clkin / op_clk) - 8 - 2 * t_ftl_cycle;
  272. /* CLK_DIV max is 256 */
  273. for (i = 0; i < 256; i++) {
  274. utemp1 = utemp0 / (i + 1);
  275. if ((utemp1 < 512) && (utemp1 > 4)) {
  276. i2c_bus->clk_cycle = utemp1 - 2;
  277. i2c_bus->clk_div = i;
  278. return 0;
  279. }
  280. }
  281. return -1;
  282. }
  283. static void hsi2c_ch_init(struct s3c24x0_i2c_bus *i2c_bus)
  284. {
  285. struct exynos5_hsi2c *hsregs = i2c_bus->hsregs;
  286. unsigned int t_sr_release;
  287. unsigned int n_clkdiv;
  288. unsigned int t_start_su, t_start_hd;
  289. unsigned int t_stop_su;
  290. unsigned int t_data_su, t_data_hd;
  291. unsigned int t_scl_l, t_scl_h;
  292. u32 i2c_timing_s1;
  293. u32 i2c_timing_s2;
  294. u32 i2c_timing_s3;
  295. u32 i2c_timing_sla;
  296. n_clkdiv = i2c_bus->clk_div;
  297. t_scl_l = i2c_bus->clk_cycle / 2;
  298. t_scl_h = i2c_bus->clk_cycle / 2;
  299. t_start_su = t_scl_l;
  300. t_start_hd = t_scl_l;
  301. t_stop_su = t_scl_l;
  302. t_data_su = t_scl_l / 2;
  303. t_data_hd = t_scl_l / 2;
  304. t_sr_release = i2c_bus->clk_cycle;
  305. i2c_timing_s1 = t_start_su << 24 | t_start_hd << 16 | t_stop_su << 8;
  306. i2c_timing_s2 = t_data_su << 24 | t_scl_l << 8 | t_scl_h << 0;
  307. i2c_timing_s3 = n_clkdiv << 16 | t_sr_release << 0;
  308. i2c_timing_sla = t_data_hd << 0;
  309. writel(HSI2C_TRAILING_COUNT, &hsregs->usi_trailing_ctl);
  310. /* Clear to enable Timeout */
  311. clrsetbits_le32(&hsregs->usi_timeout, HSI2C_TIMEOUT_EN, 0);
  312. /* set AUTO mode */
  313. writel(readl(&hsregs->usi_conf) | HSI2C_AUTO_MODE, &hsregs->usi_conf);
  314. /* Enable completion conditions' reporting. */
  315. writel(HSI2C_INT_I2C_EN, &hsregs->usi_int_en);
  316. /* Enable FIFOs */
  317. writel(HSI2C_RXFIFO_EN | HSI2C_TXFIFO_EN, &hsregs->usi_fifo_ctl);
  318. /* Currently operating in Fast speed mode. */
  319. writel(i2c_timing_s1, &hsregs->usi_timing_fs1);
  320. writel(i2c_timing_s2, &hsregs->usi_timing_fs2);
  321. writel(i2c_timing_s3, &hsregs->usi_timing_fs3);
  322. writel(i2c_timing_sla, &hsregs->usi_timing_sla);
  323. }
  324. /* SW reset for the high speed bus */
  325. static void exynos5_i2c_reset(struct s3c24x0_i2c_bus *i2c_bus)
  326. {
  327. struct exynos5_hsi2c *i2c = i2c_bus->hsregs;
  328. u32 i2c_ctl;
  329. /* Set and clear the bit for reset */
  330. i2c_ctl = readl(&i2c->usi_ctl);
  331. i2c_ctl |= HSI2C_SW_RST;
  332. writel(i2c_ctl, &i2c->usi_ctl);
  333. i2c_ctl = readl(&i2c->usi_ctl);
  334. i2c_ctl &= ~HSI2C_SW_RST;
  335. writel(i2c_ctl, &i2c->usi_ctl);
  336. /* Initialize the configure registers */
  337. hsi2c_ch_init(i2c_bus);
  338. }
  339. static void s3c24x0_i2c_init(struct i2c_adapter *adap, int speed, int slaveadd)
  340. {
  341. struct s3c24x0_i2c *i2c;
  342. struct s3c24x0_i2c_bus *bus;
  343. #if !(defined CONFIG_EXYNOS4 || defined CONFIG_EXYNOS5)
  344. struct s3c24x0_gpio *gpio = s3c24x0_get_base_gpio();
  345. #endif
  346. ulong start_time = get_timer(0);
  347. /* By default i2c channel 0 is the current bus */
  348. i2c = get_base_i2c(adap->hwadapnr);
  349. /*
  350. * In case the previous transfer is still going, wait to give it a
  351. * chance to finish.
  352. */
  353. while (readl(&i2c->iicstat) & I2CSTAT_BSY) {
  354. if (get_timer(start_time) > I2C_TIMEOUT_MS) {
  355. printf("%s: I2C bus busy for %p\n", __func__,
  356. &i2c->iicstat);
  357. return;
  358. }
  359. }
  360. #if !(defined CONFIG_EXYNOS4 || defined CONFIG_EXYNOS5)
  361. int i;
  362. if ((readl(&i2c->iicstat) & I2CSTAT_BSY) || GetI2CSDA() == 0) {
  363. #ifdef CONFIG_S3C2410
  364. ulong old_gpecon = readl(&gpio->gpecon);
  365. #endif
  366. #ifdef CONFIG_S3C2400
  367. ulong old_gpecon = readl(&gpio->pgcon);
  368. #endif
  369. /* bus still busy probably by (most) previously interrupted
  370. transfer */
  371. #ifdef CONFIG_S3C2410
  372. /* set I2CSDA and I2CSCL (GPE15, GPE14) to GPIO */
  373. writel((readl(&gpio->gpecon) & ~0xF0000000) | 0x10000000,
  374. &gpio->gpecon);
  375. #endif
  376. #ifdef CONFIG_S3C2400
  377. /* set I2CSDA and I2CSCL (PG5, PG6) to GPIO */
  378. writel((readl(&gpio->pgcon) & ~0x00003c00) | 0x00001000,
  379. &gpio->pgcon);
  380. #endif
  381. /* toggle I2CSCL until bus idle */
  382. SetI2CSCL(0);
  383. udelay(1000);
  384. i = 10;
  385. while ((i > 0) && (GetI2CSDA() != 1)) {
  386. SetI2CSCL(1);
  387. udelay(1000);
  388. SetI2CSCL(0);
  389. udelay(1000);
  390. i--;
  391. }
  392. SetI2CSCL(1);
  393. udelay(1000);
  394. /* restore pin functions */
  395. #ifdef CONFIG_S3C2410
  396. writel(old_gpecon, &gpio->gpecon);
  397. #endif
  398. #ifdef CONFIG_S3C2400
  399. writel(old_gpecon, &gpio->pgcon);
  400. #endif
  401. }
  402. #endif /* #if !(defined CONFIG_EXYNOS4 || defined CONFIG_EXYNOS5) */
  403. i2c_ch_init(i2c, speed, slaveadd);
  404. bus = &i2c_bus[adap->hwadapnr];
  405. bus->active = true;
  406. bus->regs = i2c;
  407. }
  408. /*
  409. * Poll the appropriate bit of the fifo status register until the interface is
  410. * ready to process the next byte or timeout expires.
  411. *
  412. * In addition to the FIFO status register this function also polls the
  413. * interrupt status register to be able to detect unexpected transaction
  414. * completion.
  415. *
  416. * When FIFO is ready to process the next byte, this function returns I2C_OK.
  417. * If in course of polling the INT_I2C assertion is detected, the function
  418. * returns I2C_NOK. If timeout happens before any of the above conditions is
  419. * met - the function returns I2C_NOK_TOUT;
  420. * @param i2c: pointer to the appropriate i2c register bank.
  421. * @param rx_transfer: set to True if the receive transaction is in progress.
  422. * @return: as described above.
  423. */
  424. static unsigned hsi2c_poll_fifo(struct exynos5_hsi2c *i2c, bool rx_transfer)
  425. {
  426. u32 fifo_bit = rx_transfer ? HSI2C_RX_FIFO_EMPTY : HSI2C_TX_FIFO_FULL;
  427. int i = HSI2C_TIMEOUT_US;
  428. while (readl(&i2c->usi_fifo_stat) & fifo_bit) {
  429. if (readl(&i2c->usi_int_stat) & HSI2C_INT_I2C_EN) {
  430. /*
  431. * There is a chance that assertion of
  432. * HSI2C_INT_I2C_EN and deassertion of
  433. * HSI2C_RX_FIFO_EMPTY happen simultaneously. Let's
  434. * give FIFO status priority and check it one more
  435. * time before reporting interrupt. The interrupt will
  436. * be reported next time this function is called.
  437. */
  438. if (rx_transfer &&
  439. !(readl(&i2c->usi_fifo_stat) & fifo_bit))
  440. break;
  441. return I2C_NOK;
  442. }
  443. if (!i--) {
  444. debug("%s: FIFO polling timeout!\n", __func__);
  445. return I2C_NOK_TOUT;
  446. }
  447. udelay(1);
  448. }
  449. return I2C_OK;
  450. }
  451. /*
  452. * Preapre hsi2c transaction, either read or write.
  453. *
  454. * Set up transfer as described in section 27.5.1.2 'I2C Channel Auto Mode' of
  455. * the 5420 UM.
  456. *
  457. * @param i2c: pointer to the appropriate i2c register bank.
  458. * @param chip: slave address on the i2c bus (with read/write bit exlcuded)
  459. * @param len: number of bytes expected to be sent or received
  460. * @param rx_transfer: set to true for receive transactions
  461. * @param: issue_stop: set to true if i2c stop condition should be generated
  462. * after this transaction.
  463. * @return: I2C_NOK_TOUT in case the bus remained busy for HSI2C_TIMEOUT_US,
  464. * I2C_OK otherwise.
  465. */
  466. static int hsi2c_prepare_transaction(struct exynos5_hsi2c *i2c,
  467. u8 chip,
  468. u16 len,
  469. bool rx_transfer,
  470. bool issue_stop)
  471. {
  472. u32 conf;
  473. conf = len | HSI2C_MASTER_RUN;
  474. if (issue_stop)
  475. conf |= HSI2C_STOP_AFTER_TRANS;
  476. /* Clear to enable Timeout */
  477. writel(readl(&i2c->usi_timeout) & ~HSI2C_TIMEOUT_EN, &i2c->usi_timeout);
  478. /* Set slave address */
  479. writel(HSI2C_SLV_ADDR_MAS(chip), &i2c->i2c_addr);
  480. if (rx_transfer) {
  481. /* i2c master, read transaction */
  482. writel((HSI2C_RXCHON | HSI2C_FUNC_MODE_I2C | HSI2C_MASTER),
  483. &i2c->usi_ctl);
  484. /* read up to len bytes, stop after transaction is finished */
  485. writel(conf | HSI2C_READ_WRITE, &i2c->usi_auto_conf);
  486. } else {
  487. /* i2c master, write transaction */
  488. writel((HSI2C_TXCHON | HSI2C_FUNC_MODE_I2C | HSI2C_MASTER),
  489. &i2c->usi_ctl);
  490. /* write up to len bytes, stop after transaction is finished */
  491. writel(conf, &i2c->usi_auto_conf);
  492. }
  493. /* Reset all pending interrupt status bits we care about, if any */
  494. writel(HSI2C_INT_I2C_EN, &i2c->usi_int_stat);
  495. return I2C_OK;
  496. }
  497. /*
  498. * Wait while i2c bus is settling down (mostly stop gets completed).
  499. */
  500. static int hsi2c_wait_while_busy(struct exynos5_hsi2c *i2c)
  501. {
  502. int i = HSI2C_TIMEOUT_US;
  503. while (readl(&i2c->usi_trans_status) & HSI2C_MASTER_BUSY) {
  504. if (!i--) {
  505. debug("%s: bus busy\n", __func__);
  506. return I2C_NOK_TOUT;
  507. }
  508. udelay(1);
  509. }
  510. return I2C_OK;
  511. }
  512. static int hsi2c_write(struct exynos5_hsi2c *i2c,
  513. unsigned char chip,
  514. unsigned char addr[],
  515. unsigned char alen,
  516. unsigned char data[],
  517. unsigned short len,
  518. bool issue_stop)
  519. {
  520. int i, rv = 0;
  521. if (!(len + alen)) {
  522. /* Writes of zero length not supported in auto mode. */
  523. debug("%s: zero length writes not supported\n", __func__);
  524. return I2C_NOK;
  525. }
  526. rv = hsi2c_prepare_transaction
  527. (i2c, chip, len + alen, false, issue_stop);
  528. if (rv != I2C_OK)
  529. return rv;
  530. /* Move address, if any, and the data, if any, into the FIFO. */
  531. for (i = 0; i < alen; i++) {
  532. rv = hsi2c_poll_fifo(i2c, false);
  533. if (rv != I2C_OK) {
  534. debug("%s: address write failed\n", __func__);
  535. goto write_error;
  536. }
  537. writel(addr[i], &i2c->usi_txdata);
  538. }
  539. for (i = 0; i < len; i++) {
  540. rv = hsi2c_poll_fifo(i2c, false);
  541. if (rv != I2C_OK) {
  542. debug("%s: data write failed\n", __func__);
  543. goto write_error;
  544. }
  545. writel(data[i], &i2c->usi_txdata);
  546. }
  547. rv = hsi2c_wait_for_trx(i2c);
  548. write_error:
  549. if (issue_stop) {
  550. int tmp_ret = hsi2c_wait_while_busy(i2c);
  551. if (rv == I2C_OK)
  552. rv = tmp_ret;
  553. }
  554. writel(HSI2C_FUNC_MODE_I2C, &i2c->usi_ctl); /* done */
  555. return rv;
  556. }
  557. static int hsi2c_read(struct exynos5_hsi2c *i2c,
  558. unsigned char chip,
  559. unsigned char addr[],
  560. unsigned char alen,
  561. unsigned char data[],
  562. unsigned short len)
  563. {
  564. int i, rv, tmp_ret;
  565. bool drop_data = false;
  566. if (!len) {
  567. /* Reads of zero length not supported in auto mode. */
  568. debug("%s: zero length read adjusted\n", __func__);
  569. drop_data = true;
  570. len = 1;
  571. }
  572. if (alen) {
  573. /* Internal register adress needs to be written first. */
  574. rv = hsi2c_write(i2c, chip, addr, alen, NULL, 0, false);
  575. if (rv != I2C_OK)
  576. return rv;
  577. }
  578. rv = hsi2c_prepare_transaction(i2c, chip, len, true, true);
  579. if (rv != I2C_OK)
  580. return rv;
  581. for (i = 0; i < len; i++) {
  582. rv = hsi2c_poll_fifo(i2c, true);
  583. if (rv != I2C_OK)
  584. goto read_err;
  585. if (drop_data)
  586. continue;
  587. data[i] = readl(&i2c->usi_rxdata);
  588. }
  589. rv = hsi2c_wait_for_trx(i2c);
  590. read_err:
  591. tmp_ret = hsi2c_wait_while_busy(i2c);
  592. if (rv == I2C_OK)
  593. rv = tmp_ret;
  594. writel(HSI2C_FUNC_MODE_I2C, &i2c->usi_ctl); /* done */
  595. return rv;
  596. }
  597. static unsigned int s3c24x0_i2c_set_bus_speed(struct i2c_adapter *adap,
  598. unsigned int speed)
  599. {
  600. struct s3c24x0_i2c_bus *i2c_bus;
  601. i2c_bus = get_bus(adap->hwadapnr);
  602. if (!i2c_bus)
  603. return -1;
  604. i2c_bus->clock_frequency = speed;
  605. if (i2c_bus->is_highspeed) {
  606. if (hsi2c_get_clk_details(i2c_bus))
  607. return -1;
  608. hsi2c_ch_init(i2c_bus);
  609. } else {
  610. i2c_ch_init(i2c_bus->regs, i2c_bus->clock_frequency,
  611. CONFIG_SYS_I2C_S3C24X0_SLAVE);
  612. }
  613. return 0;
  614. }
  615. #ifdef CONFIG_EXYNOS5
  616. static void exynos_i2c_init(struct i2c_adapter *adap, int speed, int slaveaddr)
  617. {
  618. /* This will override the speed selected in the fdt for that port */
  619. debug("i2c_init(speed=%u, slaveaddr=0x%x)\n", speed, slaveaddr);
  620. if (i2c_set_bus_speed(speed))
  621. printf("i2c_init: failed to init bus %d for speed = %d\n",
  622. adap->hwadapnr, speed);
  623. }
  624. #endif
  625. /*
  626. * cmd_type is 0 for write, 1 for read.
  627. *
  628. * addr_len can take any value from 0-255, it is only limited
  629. * by the char, we could make it larger if needed. If it is
  630. * 0 we skip the address write cycle.
  631. */
  632. static int i2c_transfer(struct s3c24x0_i2c *i2c,
  633. unsigned char cmd_type,
  634. unsigned char chip,
  635. unsigned char addr[],
  636. unsigned char addr_len,
  637. unsigned char data[],
  638. unsigned short data_len)
  639. {
  640. int i = 0, result;
  641. ulong start_time = get_timer(0);
  642. if (data == 0 || data_len == 0) {
  643. /*Don't support data transfer of no length or to address 0 */
  644. debug("i2c_transfer: bad call\n");
  645. return I2C_NOK;
  646. }
  647. while (readl(&i2c->iicstat) & I2CSTAT_BSY) {
  648. if (get_timer(start_time) > I2C_TIMEOUT_MS)
  649. return I2C_NOK_TOUT;
  650. }
  651. writel(readl(&i2c->iiccon) | I2CCON_ACKGEN, &i2c->iiccon);
  652. /* Get the slave chip address going */
  653. writel(chip, &i2c->iicds);
  654. if ((cmd_type == I2C_WRITE) || (addr && addr_len))
  655. writel(I2C_MODE_MT | I2C_TXRX_ENA | I2C_START_STOP,
  656. &i2c->iicstat);
  657. else
  658. writel(I2C_MODE_MR | I2C_TXRX_ENA | I2C_START_STOP,
  659. &i2c->iicstat);
  660. /* Wait for chip address to transmit. */
  661. result = WaitForXfer(i2c);
  662. if (result != I2C_OK)
  663. goto bailout;
  664. /* If register address needs to be transmitted - do it now. */
  665. if (addr && addr_len) {
  666. while ((i < addr_len) && (result == I2C_OK)) {
  667. writel(addr[i++], &i2c->iicds);
  668. ReadWriteByte(i2c);
  669. result = WaitForXfer(i2c);
  670. }
  671. i = 0;
  672. if (result != I2C_OK)
  673. goto bailout;
  674. }
  675. switch (cmd_type) {
  676. case I2C_WRITE:
  677. while ((i < data_len) && (result == I2C_OK)) {
  678. writel(data[i++], &i2c->iicds);
  679. ReadWriteByte(i2c);
  680. result = WaitForXfer(i2c);
  681. }
  682. break;
  683. case I2C_READ:
  684. if (addr && addr_len) {
  685. /*
  686. * Register address has been sent, now send slave chip
  687. * address again to start the actual read transaction.
  688. */
  689. writel(chip, &i2c->iicds);
  690. /* Generate a re-START. */
  691. writel(I2C_MODE_MR | I2C_TXRX_ENA | I2C_START_STOP,
  692. &i2c->iicstat);
  693. ReadWriteByte(i2c);
  694. result = WaitForXfer(i2c);
  695. if (result != I2C_OK)
  696. goto bailout;
  697. }
  698. while ((i < data_len) && (result == I2C_OK)) {
  699. /* disable ACK for final READ */
  700. if (i == data_len - 1)
  701. writel(readl(&i2c->iiccon)
  702. & ~I2CCON_ACKGEN,
  703. &i2c->iiccon);
  704. ReadWriteByte(i2c);
  705. result = WaitForXfer(i2c);
  706. data[i++] = readl(&i2c->iicds);
  707. }
  708. if (result == I2C_NACK)
  709. result = I2C_OK; /* Normal terminated read. */
  710. break;
  711. default:
  712. debug("i2c_transfer: bad call\n");
  713. result = I2C_NOK;
  714. break;
  715. }
  716. bailout:
  717. /* Send STOP. */
  718. writel(I2C_MODE_MR | I2C_TXRX_ENA, &i2c->iicstat);
  719. ReadWriteByte(i2c);
  720. return result;
  721. }
  722. static int s3c24x0_i2c_probe(struct i2c_adapter *adap, uchar chip)
  723. {
  724. struct s3c24x0_i2c_bus *i2c_bus;
  725. uchar buf[1];
  726. int ret;
  727. i2c_bus = get_bus(adap->hwadapnr);
  728. if (!i2c_bus)
  729. return -1;
  730. buf[0] = 0;
  731. /*
  732. * What is needed is to send the chip address and verify that the
  733. * address was <ACK>ed (i.e. there was a chip at that address which
  734. * drove the data line low).
  735. */
  736. if (i2c_bus->is_highspeed) {
  737. ret = hsi2c_read(i2c_bus->hsregs,
  738. chip, 0, 0, buf, 1);
  739. } else {
  740. ret = i2c_transfer(i2c_bus->regs,
  741. I2C_READ, chip << 1, 0, 0, buf, 1);
  742. }
  743. return ret != I2C_OK;
  744. }
  745. static int s3c24x0_i2c_read(struct i2c_adapter *adap, uchar chip, uint addr,
  746. int alen, uchar *buffer, int len)
  747. {
  748. struct s3c24x0_i2c_bus *i2c_bus;
  749. uchar xaddr[4];
  750. int ret;
  751. if (alen > 4) {
  752. debug("I2C read: addr len %d not supported\n", alen);
  753. return 1;
  754. }
  755. if (alen > 0) {
  756. xaddr[0] = (addr >> 24) & 0xFF;
  757. xaddr[1] = (addr >> 16) & 0xFF;
  758. xaddr[2] = (addr >> 8) & 0xFF;
  759. xaddr[3] = addr & 0xFF;
  760. }
  761. #ifdef CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW
  762. /*
  763. * EEPROM chips that implement "address overflow" are ones
  764. * like Catalyst 24WC04/08/16 which has 9/10/11 bits of
  765. * address and the extra bits end up in the "chip address"
  766. * bit slots. This makes a 24WC08 (1Kbyte) chip look like
  767. * four 256 byte chips.
  768. *
  769. * Note that we consider the length of the address field to
  770. * still be one byte because the extra address bits are
  771. * hidden in the chip address.
  772. */
  773. if (alen > 0)
  774. chip |= ((addr >> (alen * 8)) &
  775. CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW);
  776. #endif
  777. i2c_bus = get_bus(adap->hwadapnr);
  778. if (!i2c_bus)
  779. return -1;
  780. if (i2c_bus->is_highspeed)
  781. ret = hsi2c_read(i2c_bus->hsregs, chip, &xaddr[4 - alen],
  782. alen, buffer, len);
  783. else
  784. ret = i2c_transfer(i2c_bus->regs, I2C_READ, chip << 1,
  785. &xaddr[4 - alen], alen, buffer, len);
  786. if (ret) {
  787. if (i2c_bus->is_highspeed)
  788. exynos5_i2c_reset(i2c_bus);
  789. debug("I2c read failed %d\n", ret);
  790. return 1;
  791. }
  792. return 0;
  793. }
  794. static int s3c24x0_i2c_write(struct i2c_adapter *adap, uchar chip, uint addr,
  795. int alen, uchar *buffer, int len)
  796. {
  797. struct s3c24x0_i2c_bus *i2c_bus;
  798. uchar xaddr[4];
  799. int ret;
  800. if (alen > 4) {
  801. debug("I2C write: addr len %d not supported\n", alen);
  802. return 1;
  803. }
  804. if (alen > 0) {
  805. xaddr[0] = (addr >> 24) & 0xFF;
  806. xaddr[1] = (addr >> 16) & 0xFF;
  807. xaddr[2] = (addr >> 8) & 0xFF;
  808. xaddr[3] = addr & 0xFF;
  809. }
  810. #ifdef CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW
  811. /*
  812. * EEPROM chips that implement "address overflow" are ones
  813. * like Catalyst 24WC04/08/16 which has 9/10/11 bits of
  814. * address and the extra bits end up in the "chip address"
  815. * bit slots. This makes a 24WC08 (1Kbyte) chip look like
  816. * four 256 byte chips.
  817. *
  818. * Note that we consider the length of the address field to
  819. * still be one byte because the extra address bits are
  820. * hidden in the chip address.
  821. */
  822. if (alen > 0)
  823. chip |= ((addr >> (alen * 8)) &
  824. CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW);
  825. #endif
  826. i2c_bus = get_bus(adap->hwadapnr);
  827. if (!i2c_bus)
  828. return -1;
  829. if (i2c_bus->is_highspeed)
  830. ret = hsi2c_write(i2c_bus->hsregs, chip, &xaddr[4 - alen],
  831. alen, buffer, len, true);
  832. else
  833. ret = i2c_transfer(i2c_bus->regs, I2C_WRITE, chip << 1,
  834. &xaddr[4 - alen], alen, buffer, len);
  835. if (ret != 0) {
  836. if (i2c_bus->is_highspeed)
  837. exynos5_i2c_reset(i2c_bus);
  838. return 1;
  839. } else {
  840. return 0;
  841. }
  842. }
  843. #ifdef CONFIG_OF_CONTROL
  844. static void process_nodes(const void *blob, int node_list[], int count,
  845. int is_highspeed)
  846. {
  847. struct s3c24x0_i2c_bus *bus;
  848. int i;
  849. for (i = 0; i < count; i++) {
  850. int node = node_list[i];
  851. if (node <= 0)
  852. continue;
  853. bus = &i2c_bus[i];
  854. bus->active = true;
  855. bus->is_highspeed = is_highspeed;
  856. if (is_highspeed)
  857. bus->hsregs = (struct exynos5_hsi2c *)
  858. fdtdec_get_addr(blob, node, "reg");
  859. else
  860. bus->regs = (struct s3c24x0_i2c *)
  861. fdtdec_get_addr(blob, node, "reg");
  862. bus->id = pinmux_decode_periph_id(blob, node);
  863. bus->clock_frequency = fdtdec_get_int(blob, node,
  864. "clock-frequency",
  865. CONFIG_SYS_I2C_S3C24X0_SPEED);
  866. bus->node = node;
  867. bus->bus_num = i;
  868. exynos_pinmux_config(bus->id, 0);
  869. /* Mark position as used */
  870. node_list[i] = -1;
  871. }
  872. }
  873. void board_i2c_init(const void *blob)
  874. {
  875. int node_list[CONFIG_MAX_I2C_NUM];
  876. int count;
  877. /* First get the normal i2c ports */
  878. count = fdtdec_find_aliases_for_id(blob, "i2c",
  879. COMPAT_SAMSUNG_S3C2440_I2C, node_list,
  880. CONFIG_MAX_I2C_NUM);
  881. process_nodes(blob, node_list, count, 0);
  882. /* Now look for high speed i2c ports */
  883. count = fdtdec_find_aliases_for_id(blob, "i2c",
  884. COMPAT_SAMSUNG_EXYNOS5_I2C, node_list,
  885. CONFIG_MAX_I2C_NUM);
  886. process_nodes(blob, node_list, count, 1);
  887. }
  888. int i2c_get_bus_num_fdt(int node)
  889. {
  890. int i;
  891. for (i = 0; i < ARRAY_SIZE(i2c_bus); i++) {
  892. if (node == i2c_bus[i].node)
  893. return i;
  894. }
  895. debug("%s: Can't find any matched I2C bus\n", __func__);
  896. return -1;
  897. }
  898. int i2c_reset_port_fdt(const void *blob, int node)
  899. {
  900. struct s3c24x0_i2c_bus *i2c_bus;
  901. int bus;
  902. bus = i2c_get_bus_num_fdt(node);
  903. if (bus < 0) {
  904. debug("could not get bus for node %d\n", node);
  905. return -1;
  906. }
  907. i2c_bus = get_bus(bus);
  908. if (!i2c_bus) {
  909. debug("get_bus() failed for node node %d\n", node);
  910. return -1;
  911. }
  912. if (i2c_bus->is_highspeed) {
  913. if (hsi2c_get_clk_details(i2c_bus))
  914. return -1;
  915. hsi2c_ch_init(i2c_bus);
  916. } else {
  917. i2c_ch_init(i2c_bus->regs, i2c_bus->clock_frequency,
  918. CONFIG_SYS_I2C_S3C24X0_SLAVE);
  919. }
  920. return 0;
  921. }
  922. #endif
  923. /*
  924. * Register s3c24x0 i2c adapters
  925. */
  926. #if defined(CONFIG_EXYNOS5420)
  927. U_BOOT_I2C_ADAP_COMPLETE(i2c00, s3c24x0_i2c_init, s3c24x0_i2c_probe,
  928. s3c24x0_i2c_read, s3c24x0_i2c_write,
  929. s3c24x0_i2c_set_bus_speed,
  930. CONFIG_SYS_I2C_S3C24X0_SPEED,
  931. CONFIG_SYS_I2C_S3C24X0_SLAVE, 0)
  932. U_BOOT_I2C_ADAP_COMPLETE(i2c01, s3c24x0_i2c_init, s3c24x0_i2c_probe,
  933. s3c24x0_i2c_read, s3c24x0_i2c_write,
  934. s3c24x0_i2c_set_bus_speed,
  935. CONFIG_SYS_I2C_S3C24X0_SPEED,
  936. CONFIG_SYS_I2C_S3C24X0_SLAVE, 1)
  937. U_BOOT_I2C_ADAP_COMPLETE(i2c02, s3c24x0_i2c_init, s3c24x0_i2c_probe,
  938. s3c24x0_i2c_read, s3c24x0_i2c_write,
  939. s3c24x0_i2c_set_bus_speed,
  940. CONFIG_SYS_I2C_S3C24X0_SPEED,
  941. CONFIG_SYS_I2C_S3C24X0_SLAVE, 2)
  942. U_BOOT_I2C_ADAP_COMPLETE(i2c03, exynos_i2c_init, s3c24x0_i2c_probe,
  943. s3c24x0_i2c_read, s3c24x0_i2c_write,
  944. s3c24x0_i2c_set_bus_speed,
  945. CONFIG_SYS_I2C_S3C24X0_SPEED,
  946. CONFIG_SYS_I2C_S3C24X0_SLAVE, 3)
  947. U_BOOT_I2C_ADAP_COMPLETE(i2c04, exynos_i2c_init, s3c24x0_i2c_probe,
  948. s3c24x0_i2c_read, s3c24x0_i2c_write,
  949. s3c24x0_i2c_set_bus_speed,
  950. CONFIG_SYS_I2C_S3C24X0_SPEED,
  951. CONFIG_SYS_I2C_S3C24X0_SLAVE, 4)
  952. U_BOOT_I2C_ADAP_COMPLETE(i2c05, exynos_i2c_init, s3c24x0_i2c_probe,
  953. s3c24x0_i2c_read, s3c24x0_i2c_write,
  954. s3c24x0_i2c_set_bus_speed,
  955. CONFIG_SYS_I2C_S3C24X0_SPEED,
  956. CONFIG_SYS_I2C_S3C24X0_SLAVE, 5)
  957. U_BOOT_I2C_ADAP_COMPLETE(i2c06, exynos_i2c_init, s3c24x0_i2c_probe,
  958. s3c24x0_i2c_read, s3c24x0_i2c_write,
  959. s3c24x0_i2c_set_bus_speed,
  960. CONFIG_SYS_I2C_S3C24X0_SPEED,
  961. CONFIG_SYS_I2C_S3C24X0_SLAVE, 6)
  962. U_BOOT_I2C_ADAP_COMPLETE(i2c07, exynos_i2c_init, s3c24x0_i2c_probe,
  963. s3c24x0_i2c_read, s3c24x0_i2c_write,
  964. s3c24x0_i2c_set_bus_speed,
  965. CONFIG_SYS_I2C_S3C24X0_SPEED,
  966. CONFIG_SYS_I2C_S3C24X0_SLAVE, 7)
  967. U_BOOT_I2C_ADAP_COMPLETE(i2c08, exynos_i2c_init, s3c24x0_i2c_probe,
  968. s3c24x0_i2c_read, s3c24x0_i2c_write,
  969. s3c24x0_i2c_set_bus_speed,
  970. CONFIG_SYS_I2C_S3C24X0_SPEED,
  971. CONFIG_SYS_I2C_S3C24X0_SLAVE, 8)
  972. U_BOOT_I2C_ADAP_COMPLETE(i2c09, exynos_i2c_init, s3c24x0_i2c_probe,
  973. s3c24x0_i2c_read, s3c24x0_i2c_write,
  974. s3c24x0_i2c_set_bus_speed,
  975. CONFIG_SYS_I2C_S3C24X0_SPEED,
  976. CONFIG_SYS_I2C_S3C24X0_SLAVE, 9)
  977. U_BOOT_I2C_ADAP_COMPLETE(i2c10, exynos_i2c_init, s3c24x0_i2c_probe,
  978. s3c24x0_i2c_read, s3c24x0_i2c_write,
  979. s3c24x0_i2c_set_bus_speed,
  980. CONFIG_SYS_I2C_S3C24X0_SPEED,
  981. CONFIG_SYS_I2C_S3C24X0_SLAVE, 10)
  982. #elif defined(CONFIG_EXYNOS5250)
  983. U_BOOT_I2C_ADAP_COMPLETE(i2c00, exynos_i2c_init, s3c24x0_i2c_probe,
  984. s3c24x0_i2c_read, s3c24x0_i2c_write,
  985. s3c24x0_i2c_set_bus_speed,
  986. CONFIG_SYS_I2C_S3C24X0_SPEED,
  987. CONFIG_SYS_I2C_S3C24X0_SLAVE, 0)
  988. U_BOOT_I2C_ADAP_COMPLETE(i2c01, exynos_i2c_init, s3c24x0_i2c_probe,
  989. s3c24x0_i2c_read, s3c24x0_i2c_write,
  990. s3c24x0_i2c_set_bus_speed,
  991. CONFIG_SYS_I2C_S3C24X0_SPEED,
  992. CONFIG_SYS_I2C_S3C24X0_SLAVE, 1)
  993. U_BOOT_I2C_ADAP_COMPLETE(i2c02, exynos_i2c_init, s3c24x0_i2c_probe,
  994. s3c24x0_i2c_read, s3c24x0_i2c_write,
  995. s3c24x0_i2c_set_bus_speed,
  996. CONFIG_SYS_I2C_S3C24X0_SPEED,
  997. CONFIG_SYS_I2C_S3C24X0_SLAVE, 2)
  998. U_BOOT_I2C_ADAP_COMPLETE(i2c03, exynos_i2c_init, s3c24x0_i2c_probe,
  999. s3c24x0_i2c_read, s3c24x0_i2c_write,
  1000. s3c24x0_i2c_set_bus_speed,
  1001. CONFIG_SYS_I2C_S3C24X0_SPEED,
  1002. CONFIG_SYS_I2C_S3C24X0_SLAVE, 3)
  1003. U_BOOT_I2C_ADAP_COMPLETE(i2c04, s3c24x0_i2c_init, s3c24x0_i2c_probe,
  1004. s3c24x0_i2c_read, s3c24x0_i2c_write,
  1005. s3c24x0_i2c_set_bus_speed,
  1006. CONFIG_SYS_I2C_S3C24X0_SPEED,
  1007. CONFIG_SYS_I2C_S3C24X0_SLAVE, 4)
  1008. U_BOOT_I2C_ADAP_COMPLETE(i2c05, s3c24x0_i2c_init, s3c24x0_i2c_probe,
  1009. s3c24x0_i2c_read, s3c24x0_i2c_write,
  1010. s3c24x0_i2c_set_bus_speed,
  1011. CONFIG_SYS_I2C_S3C24X0_SPEED,
  1012. CONFIG_SYS_I2C_S3C24X0_SLAVE, 5)
  1013. U_BOOT_I2C_ADAP_COMPLETE(i2c06, s3c24x0_i2c_init, s3c24x0_i2c_probe,
  1014. s3c24x0_i2c_read, s3c24x0_i2c_write,
  1015. s3c24x0_i2c_set_bus_speed,
  1016. CONFIG_SYS_I2C_S3C24X0_SPEED,
  1017. CONFIG_SYS_I2C_S3C24X0_SLAVE, 6)
  1018. U_BOOT_I2C_ADAP_COMPLETE(i2c07, s3c24x0_i2c_init, s3c24x0_i2c_probe,
  1019. s3c24x0_i2c_read, s3c24x0_i2c_write,
  1020. s3c24x0_i2c_set_bus_speed,
  1021. CONFIG_SYS_I2C_S3C24X0_SPEED,
  1022. CONFIG_SYS_I2C_S3C24X0_SLAVE, 7)
  1023. U_BOOT_I2C_ADAP_COMPLETE(i2c08, s3c24x0_i2c_init, s3c24x0_i2c_probe,
  1024. s3c24x0_i2c_read, s3c24x0_i2c_write,
  1025. s3c24x0_i2c_set_bus_speed,
  1026. CONFIG_SYS_I2C_S3C24X0_SPEED,
  1027. CONFIG_SYS_I2C_S3C24X0_SLAVE, 8)
  1028. U_BOOT_I2C_ADAP_COMPLETE(i2c09, s3c24x0_i2c_init, s3c24x0_i2c_probe,
  1029. s3c24x0_i2c_read, s3c24x0_i2c_write,
  1030. s3c24x0_i2c_set_bus_speed,
  1031. CONFIG_SYS_I2C_S3C24X0_SPEED,
  1032. CONFIG_SYS_I2C_S3C24X0_SLAVE, 9)
  1033. U_BOOT_I2C_ADAP_COMPLETE(s3c10, s3c24x0_i2c_init, s3c24x0_i2c_probe,
  1034. s3c24x0_i2c_read, s3c24x0_i2c_write,
  1035. s3c24x0_i2c_set_bus_speed,
  1036. CONFIG_SYS_I2C_S3C24X0_SPEED,
  1037. CONFIG_SYS_I2C_S3C24X0_SLAVE, 10)
  1038. #elif defined(CONFIG_EXYNOS4)
  1039. U_BOOT_I2C_ADAP_COMPLETE(i2c00, s3c24x0_i2c_init, s3c24x0_i2c_probe,
  1040. s3c24x0_i2c_read, s3c24x0_i2c_write,
  1041. s3c24x0_i2c_set_bus_speed,
  1042. CONFIG_SYS_I2C_S3C24X0_SPEED,
  1043. CONFIG_SYS_I2C_S3C24X0_SLAVE, 0)
  1044. U_BOOT_I2C_ADAP_COMPLETE(i2c01, s3c24x0_i2c_init, s3c24x0_i2c_probe,
  1045. s3c24x0_i2c_read, s3c24x0_i2c_write,
  1046. s3c24x0_i2c_set_bus_speed,
  1047. CONFIG_SYS_I2C_S3C24X0_SPEED,
  1048. CONFIG_SYS_I2C_S3C24X0_SLAVE, 1)
  1049. U_BOOT_I2C_ADAP_COMPLETE(i2c02, s3c24x0_i2c_init, s3c24x0_i2c_probe,
  1050. s3c24x0_i2c_read, s3c24x0_i2c_write,
  1051. s3c24x0_i2c_set_bus_speed,
  1052. CONFIG_SYS_I2C_S3C24X0_SPEED,
  1053. CONFIG_SYS_I2C_S3C24X0_SLAVE, 2)
  1054. U_BOOT_I2C_ADAP_COMPLETE(i2c03, s3c24x0_i2c_init, s3c24x0_i2c_probe,
  1055. s3c24x0_i2c_read, s3c24x0_i2c_write,
  1056. s3c24x0_i2c_set_bus_speed,
  1057. CONFIG_SYS_I2C_S3C24X0_SPEED,
  1058. CONFIG_SYS_I2C_S3C24X0_SLAVE, 3)
  1059. U_BOOT_I2C_ADAP_COMPLETE(i2c04, s3c24x0_i2c_init, s3c24x0_i2c_probe,
  1060. s3c24x0_i2c_read, s3c24x0_i2c_write,
  1061. s3c24x0_i2c_set_bus_speed,
  1062. CONFIG_SYS_I2C_S3C24X0_SPEED,
  1063. CONFIG_SYS_I2C_S3C24X0_SLAVE, 4)
  1064. U_BOOT_I2C_ADAP_COMPLETE(i2c05, s3c24x0_i2c_init, s3c24x0_i2c_probe,
  1065. s3c24x0_i2c_read, s3c24x0_i2c_write,
  1066. s3c24x0_i2c_set_bus_speed,
  1067. CONFIG_SYS_I2C_S3C24X0_SPEED,
  1068. CONFIG_SYS_I2C_S3C24X0_SLAVE, 5)
  1069. U_BOOT_I2C_ADAP_COMPLETE(i2c06, s3c24x0_i2c_init, s3c24x0_i2c_probe,
  1070. s3c24x0_i2c_read, s3c24x0_i2c_write,
  1071. s3c24x0_i2c_set_bus_speed,
  1072. CONFIG_SYS_I2C_S3C24X0_SPEED,
  1073. CONFIG_SYS_I2C_S3C24X0_SLAVE, 6)
  1074. U_BOOT_I2C_ADAP_COMPLETE(i2c07, s3c24x0_i2c_init, s3c24x0_i2c_probe,
  1075. s3c24x0_i2c_read, s3c24x0_i2c_write,
  1076. s3c24x0_i2c_set_bus_speed,
  1077. CONFIG_SYS_I2C_S3C24X0_SPEED,
  1078. CONFIG_SYS_I2C_S3C24X0_SLAVE, 7)
  1079. U_BOOT_I2C_ADAP_COMPLETE(i2c08, s3c24x0_i2c_init, s3c24x0_i2c_probe,
  1080. s3c24x0_i2c_read, s3c24x0_i2c_write,
  1081. s3c24x0_i2c_set_bus_speed,
  1082. CONFIG_SYS_I2C_S3C24X0_SPEED,
  1083. CONFIG_SYS_I2C_S3C24X0_SLAVE, 8)
  1084. #else
  1085. U_BOOT_I2C_ADAP_COMPLETE(s3c0, s3c24x0_i2c_init, s3c24x0_i2c_probe,
  1086. s3c24x0_i2c_read, s3c24x0_i2c_write,
  1087. s3c24x0_i2c_set_bus_speed,
  1088. CONFIG_SYS_I2C_S3C24X0_SPEED,
  1089. CONFIG_SYS_I2C_S3C24X0_SLAVE, 0)
  1090. #endif