blob: 6c343072fb248299579e9a3b7d258d41b104f70b [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Peng Fan7ee3f142017-02-24 09:54:18 +08002/*
3 * Copyright 2016 Freescale Semiconductors, Inc.
Peng Fan7ee3f142017-02-24 09:54:18 +08004 */
5
6#include <common.h>
7#include <errno.h>
8#include <asm/io.h>
9#include <asm/arch/clock.h>
10#include <asm/arch/imx-regs.h>
Ye Li9b2ebcc2018-07-08 11:46:40 +080011#include <imx_lpi2c.h>
Peng Fan7ee3f142017-02-24 09:54:18 +080012#include <asm/arch/sys_proto.h>
13#include <dm.h>
14#include <fdtdec.h>
15#include <i2c.h>
16
Peng Fan7ee3f142017-02-24 09:54:18 +080017#define LPI2C_FIFO_SIZE 4
Gao Pana32effd2018-07-08 11:46:41 +080018#define LPI2C_NACK_TOUT_MS 1
Peng Fan7ee3f142017-02-24 09:54:18 +080019#define LPI2C_TIMEOUT_MS 100
20
Ye Li971490c2018-07-08 11:46:43 +080021static int bus_i2c_init(struct udevice *bus, int speed);
22
Peng Fan7ee3f142017-02-24 09:54:18 +080023/* Weak linked function for overridden by some SoC power function */
24int __weak init_i2c_power(unsigned i2c_num)
25{
26 return 0;
27}
28
Simon Glassa821c4a2017-05-17 17:18:05 -060029static int imx_lpci2c_check_busy_bus(const struct imx_lpi2c_reg *regs)
Peng Fan7ee3f142017-02-24 09:54:18 +080030{
Peng Fan7ee3f142017-02-24 09:54:18 +080031 lpi2c_status_t result = LPI2C_SUCESS;
32 u32 status;
33
34 status = readl(&regs->msr);
35
36 if ((status & LPI2C_MSR_BBF_MASK) && !(status & LPI2C_MSR_MBF_MASK))
37 result = LPI2C_BUSY;
38
39 return result;
40}
41
Simon Glassa821c4a2017-05-17 17:18:05 -060042static int imx_lpci2c_check_clear_error(struct imx_lpi2c_reg *regs)
Peng Fan7ee3f142017-02-24 09:54:18 +080043{
Peng Fan7ee3f142017-02-24 09:54:18 +080044 lpi2c_status_t result = LPI2C_SUCESS;
45 u32 val, status;
46
47 status = readl(&regs->msr);
48 /* errors to check for */
49 status &= LPI2C_MSR_NDF_MASK | LPI2C_MSR_ALF_MASK |
50 LPI2C_MSR_FEF_MASK | LPI2C_MSR_PLTF_MASK;
51
52 if (status) {
53 if (status & LPI2C_MSR_PLTF_MASK)
54 result = LPI2C_PIN_LOW_TIMEOUT_ERR;
55 else if (status & LPI2C_MSR_ALF_MASK)
56 result = LPI2C_ARB_LOST_ERR;
57 else if (status & LPI2C_MSR_NDF_MASK)
58 result = LPI2C_NAK_ERR;
59 else if (status & LPI2C_MSR_FEF_MASK)
60 result = LPI2C_FIFO_ERR;
61
62 /* clear status flags */
63 writel(0x7f00, &regs->msr);
64 /* reset fifos */
65 val = readl(&regs->mcr);
66 val |= LPI2C_MCR_RRF_MASK | LPI2C_MCR_RTF_MASK;
67 writel(val, &regs->mcr);
68 }
69
70 return result;
71}
72
Simon Glassa821c4a2017-05-17 17:18:05 -060073static int bus_i2c_wait_for_tx_ready(struct imx_lpi2c_reg *regs)
Peng Fan7ee3f142017-02-24 09:54:18 +080074{
Peng Fan7ee3f142017-02-24 09:54:18 +080075 lpi2c_status_t result = LPI2C_SUCESS;
76 u32 txcount = 0;
77 ulong start_time = get_timer(0);
78
79 do {
80 txcount = LPI2C_MFSR_TXCOUNT(readl(&regs->mfsr));
81 txcount = LPI2C_FIFO_SIZE - txcount;
Simon Glassa821c4a2017-05-17 17:18:05 -060082 result = imx_lpci2c_check_clear_error(regs);
Peng Fan7ee3f142017-02-24 09:54:18 +080083 if (result) {
84 debug("i2c: wait for tx ready: result 0x%x\n", result);
85 return result;
86 }
87 if (get_timer(start_time) > LPI2C_TIMEOUT_MS) {
88 debug("i2c: wait for tx ready: timeout\n");
89 return -1;
90 }
91 } while (!txcount);
92
93 return result;
94}
95
Ye Li971490c2018-07-08 11:46:43 +080096static int bus_i2c_send(struct udevice *bus, u8 *txbuf, int len)
Peng Fan7ee3f142017-02-24 09:54:18 +080097{
Ye Li971490c2018-07-08 11:46:43 +080098 struct imx_lpi2c_reg *regs = (struct imx_lpi2c_reg *)devfdt_get_addr(bus);
Peng Fan7ee3f142017-02-24 09:54:18 +080099 lpi2c_status_t result = LPI2C_SUCESS;
100
101 /* empty tx */
102 if (!len)
103 return result;
104
105 while (len--) {
Simon Glassa821c4a2017-05-17 17:18:05 -0600106 result = bus_i2c_wait_for_tx_ready(regs);
Peng Fan7ee3f142017-02-24 09:54:18 +0800107 if (result) {
108 debug("i2c: send wait fot tx ready: %d\n", result);
109 return result;
110 }
111 writel(*txbuf++, &regs->mtdr);
112 }
113
114 return result;
115}
116
Ye Li971490c2018-07-08 11:46:43 +0800117static int bus_i2c_receive(struct udevice *bus, u8 *rxbuf, int len)
Peng Fan7ee3f142017-02-24 09:54:18 +0800118{
Ye Li971490c2018-07-08 11:46:43 +0800119 struct imx_lpi2c_reg *regs = (struct imx_lpi2c_reg *)devfdt_get_addr(bus);
Peng Fan7ee3f142017-02-24 09:54:18 +0800120 lpi2c_status_t result = LPI2C_SUCESS;
121 u32 val;
122 ulong start_time = get_timer(0);
123
124 /* empty read */
125 if (!len)
126 return result;
127
Simon Glassa821c4a2017-05-17 17:18:05 -0600128 result = bus_i2c_wait_for_tx_ready(regs);
Peng Fan7ee3f142017-02-24 09:54:18 +0800129 if (result) {
130 debug("i2c: receive wait fot tx ready: %d\n", result);
131 return result;
132 }
133
134 /* clear all status flags */
135 writel(0x7f00, &regs->msr);
136 /* send receive command */
137 val = LPI2C_MTDR_CMD(0x1) | LPI2C_MTDR_DATA(len - 1);
138 writel(val, &regs->mtdr);
139
140 while (len--) {
141 do {
Simon Glassa821c4a2017-05-17 17:18:05 -0600142 result = imx_lpci2c_check_clear_error(regs);
Peng Fan7ee3f142017-02-24 09:54:18 +0800143 if (result) {
Simon Glassa821c4a2017-05-17 17:18:05 -0600144 debug("i2c: receive check clear error: %d\n",
145 result);
Peng Fan7ee3f142017-02-24 09:54:18 +0800146 return result;
147 }
148 if (get_timer(start_time) > LPI2C_TIMEOUT_MS) {
149 debug("i2c: receive mrdr: timeout\n");
150 return -1;
151 }
152 val = readl(&regs->mrdr);
153 } while (val & LPI2C_MRDR_RXEMPTY_MASK);
154 *rxbuf++ = LPI2C_MRDR_DATA(val);
155 }
156
157 return result;
158}
159
Ye Li971490c2018-07-08 11:46:43 +0800160static int bus_i2c_start(struct udevice *bus, u8 addr, u8 dir)
Peng Fan7ee3f142017-02-24 09:54:18 +0800161{
Heinrich Schuchardtd45c2f32018-03-18 11:14:56 +0100162 lpi2c_status_t result;
Ye Li971490c2018-07-08 11:46:43 +0800163 struct imx_lpi2c_reg *regs =
164 (struct imx_lpi2c_reg *)devfdt_get_addr(bus);
Peng Fan7ee3f142017-02-24 09:54:18 +0800165 u32 val;
166
Simon Glassa821c4a2017-05-17 17:18:05 -0600167 result = imx_lpci2c_check_busy_bus(regs);
Peng Fan7ee3f142017-02-24 09:54:18 +0800168 if (result) {
169 debug("i2c: start check busy bus: 0x%x\n", result);
Ye Li971490c2018-07-08 11:46:43 +0800170
171 /* Try to init the lpi2c then check the bus busy again */
172 bus_i2c_init(bus, 100000);
173 result = imx_lpci2c_check_busy_bus(regs);
174 if (result) {
175 printf("i2c: Error check busy bus: 0x%x\n", result);
176 return result;
177 }
Peng Fan7ee3f142017-02-24 09:54:18 +0800178 }
179 /* clear all status flags */
180 writel(0x7f00, &regs->msr);
181 /* turn off auto-stop condition */
182 val = readl(&regs->mcfgr1) & ~LPI2C_MCFGR1_AUTOSTOP_MASK;
183 writel(val, &regs->mcfgr1);
184 /* wait tx fifo ready */
Simon Glassa821c4a2017-05-17 17:18:05 -0600185 result = bus_i2c_wait_for_tx_ready(regs);
Peng Fan7ee3f142017-02-24 09:54:18 +0800186 if (result) {
187 debug("i2c: start wait for tx ready: 0x%x\n", result);
188 return result;
189 }
190 /* issue start command */
191 val = LPI2C_MTDR_CMD(0x4) | (addr << 0x1) | dir;
192 writel(val, &regs->mtdr);
193
194 return result;
195}
Simon Glassa821c4a2017-05-17 17:18:05 -0600196
Ye Li971490c2018-07-08 11:46:43 +0800197static int bus_i2c_stop(struct udevice *bus)
Peng Fan7ee3f142017-02-24 09:54:18 +0800198{
Heinrich Schuchardtd45c2f32018-03-18 11:14:56 +0100199 lpi2c_status_t result;
Ye Li971490c2018-07-08 11:46:43 +0800200 struct imx_lpi2c_reg *regs =
201 (struct imx_lpi2c_reg *)devfdt_get_addr(bus);
Peng Fan7ee3f142017-02-24 09:54:18 +0800202 u32 status;
Gao Pana32effd2018-07-08 11:46:41 +0800203 ulong start_time;
Peng Fan7ee3f142017-02-24 09:54:18 +0800204
Simon Glassa821c4a2017-05-17 17:18:05 -0600205 result = bus_i2c_wait_for_tx_ready(regs);
Peng Fan7ee3f142017-02-24 09:54:18 +0800206 if (result) {
207 debug("i2c: stop wait for tx ready: 0x%x\n", result);
208 return result;
209 }
210
211 /* send stop command */
212 writel(LPI2C_MTDR_CMD(0x2), &regs->mtdr);
213
Gao Pana32effd2018-07-08 11:46:41 +0800214 start_time = get_timer(0);
215 while (1) {
Peng Fan7ee3f142017-02-24 09:54:18 +0800216 status = readl(&regs->msr);
Simon Glassa821c4a2017-05-17 17:18:05 -0600217 result = imx_lpci2c_check_clear_error(regs);
Peng Fan7ee3f142017-02-24 09:54:18 +0800218 /* stop detect flag */
219 if (status & LPI2C_MSR_SDF_MASK) {
220 /* clear stop flag */
221 status &= LPI2C_MSR_SDF_MASK;
222 writel(status, &regs->msr);
223 break;
224 }
Gao Pana32effd2018-07-08 11:46:41 +0800225
226 if (get_timer(start_time) > LPI2C_NACK_TOUT_MS) {
227 debug("stop timeout\n");
228 return -ETIMEDOUT;
229 }
Peng Fan7ee3f142017-02-24 09:54:18 +0800230 }
231
232 return result;
233}
234
Ye Li971490c2018-07-08 11:46:43 +0800235static int bus_i2c_read(struct udevice *bus, u32 chip, u8 *buf, int len)
Peng Fan7ee3f142017-02-24 09:54:18 +0800236{
Heinrich Schuchardtd45c2f32018-03-18 11:14:56 +0100237 lpi2c_status_t result;
Peng Fan7ee3f142017-02-24 09:54:18 +0800238
Ye Li971490c2018-07-08 11:46:43 +0800239 result = bus_i2c_start(bus, chip, 1);
Peng Fan7ee3f142017-02-24 09:54:18 +0800240 if (result)
241 return result;
Ye Li971490c2018-07-08 11:46:43 +0800242 result = bus_i2c_receive(bus, buf, len);
Peng Fan7ee3f142017-02-24 09:54:18 +0800243 if (result)
244 return result;
Peng Fan7ee3f142017-02-24 09:54:18 +0800245
246 return result;
247}
248
Ye Li971490c2018-07-08 11:46:43 +0800249static int bus_i2c_write(struct udevice *bus, u32 chip, u8 *buf, int len)
Peng Fan7ee3f142017-02-24 09:54:18 +0800250{
Heinrich Schuchardtd45c2f32018-03-18 11:14:56 +0100251 lpi2c_status_t result;
Peng Fan7ee3f142017-02-24 09:54:18 +0800252
Ye Li971490c2018-07-08 11:46:43 +0800253 result = bus_i2c_start(bus, chip, 0);
Peng Fan7ee3f142017-02-24 09:54:18 +0800254 if (result)
255 return result;
Ye Li971490c2018-07-08 11:46:43 +0800256 result = bus_i2c_send(bus, buf, len);
Peng Fan7ee3f142017-02-24 09:54:18 +0800257 if (result)
258 return result;
Peng Fan7ee3f142017-02-24 09:54:18 +0800259
260 return result;
261}
262
263
Peng Fan3d7690a2018-07-17 20:38:33 +0800264u32 __weak imx_get_i2cclk(u32 i2c_num)
265{
266 return 0;
267}
268
Peng Fan7ee3f142017-02-24 09:54:18 +0800269static int bus_i2c_set_bus_speed(struct udevice *bus, int speed)
270{
Peng Fan3d7690a2018-07-17 20:38:33 +0800271 struct imx_lpi2c_bus *i2c_bus = dev_get_priv(bus);
Simon Glassa821c4a2017-05-17 17:18:05 -0600272 struct imx_lpi2c_reg *regs;
Peng Fan7ee3f142017-02-24 09:54:18 +0800273 u32 val;
274 u32 preescale = 0, best_pre = 0, clkhi = 0;
275 u32 best_clkhi = 0, abs_error = 0, rate;
276 u32 error = 0xffffffff;
277 u32 clock_rate;
278 bool mode;
279 int i;
280
Simon Glassa821c4a2017-05-17 17:18:05 -0600281 regs = (struct imx_lpi2c_reg *)devfdt_get_addr(bus);
Peng Fan3d7690a2018-07-17 20:38:33 +0800282
283 if (IS_ENABLED(CONFIG_CLK)) {
284 clock_rate = clk_get_rate(&i2c_bus->per_clk);
285 if (clock_rate <= 0) {
286 dev_err(bus, "Failed to get i2c clk: %d\n", clock_rate);
287 return clock_rate;
288 }
289 } else {
290 clock_rate = imx_get_i2cclk(bus->seq);
291 if (!clock_rate)
292 return -EPERM;
293 }
Peng Fan7ee3f142017-02-24 09:54:18 +0800294
295 mode = (readl(&regs->mcr) & LPI2C_MCR_MEN_MASK) >> LPI2C_MCR_MEN_SHIFT;
296 /* disable master mode */
297 val = readl(&regs->mcr) & ~LPI2C_MCR_MEN_MASK;
298 writel(val | LPI2C_MCR_MEN(0), &regs->mcr);
299
300 for (preescale = 1; (preescale <= 128) &&
301 (error != 0); preescale = 2 * preescale) {
302 for (clkhi = 1; clkhi < 32; clkhi++) {
303 if (clkhi == 1)
304 rate = (clock_rate / preescale) / (1 + 3 + 2 + 2 / preescale);
305 else
306 rate = (clock_rate / preescale / (3 * clkhi + 2 + 2 / preescale));
307
308 abs_error = speed > rate ? speed - rate : rate - speed;
309
310 if (abs_error < error) {
311 best_pre = preescale;
312 best_clkhi = clkhi;
313 error = abs_error;
314 if (abs_error == 0)
315 break;
316 }
317 }
318 }
319
320 /* Standard, fast, fast mode plus and ultra-fast transfers. */
321 val = LPI2C_MCCR0_CLKHI(best_clkhi);
322 if (best_clkhi < 2)
323 val |= LPI2C_MCCR0_CLKLO(3) | LPI2C_MCCR0_SETHOLD(2) | LPI2C_MCCR0_DATAVD(1);
324 else
325 val |= LPI2C_MCCR0_CLKLO(2 * best_clkhi) | LPI2C_MCCR0_SETHOLD(best_clkhi) |
326 LPI2C_MCCR0_DATAVD(best_clkhi / 2);
327 writel(val, &regs->mccr0);
328
329 for (i = 0; i < 8; i++) {
330 if (best_pre == (1 << i)) {
331 best_pre = i;
332 break;
333 }
334 }
335
336 val = readl(&regs->mcfgr1) & ~LPI2C_MCFGR1_PRESCALE_MASK;
337 writel(val | LPI2C_MCFGR1_PRESCALE(best_pre), &regs->mcfgr1);
338
339 if (mode) {
340 val = readl(&regs->mcr) & ~LPI2C_MCR_MEN_MASK;
341 writel(val | LPI2C_MCR_MEN(1), &regs->mcr);
342 }
343
344 return 0;
345}
346
347static int bus_i2c_init(struct udevice *bus, int speed)
348{
Simon Glassa821c4a2017-05-17 17:18:05 -0600349 struct imx_lpi2c_reg *regs;
Peng Fan7ee3f142017-02-24 09:54:18 +0800350 u32 val;
351 int ret;
352
Simon Glassa821c4a2017-05-17 17:18:05 -0600353 regs = (struct imx_lpi2c_reg *)devfdt_get_addr(bus);
Peng Fan7ee3f142017-02-24 09:54:18 +0800354 /* reset peripheral */
355 writel(LPI2C_MCR_RST_MASK, &regs->mcr);
356 writel(0x0, &regs->mcr);
357 /* Disable Dozen mode */
358 writel(LPI2C_MCR_DBGEN(0) | LPI2C_MCR_DOZEN(1), &regs->mcr);
359 /* host request disable, active high, external pin */
360 val = readl(&regs->mcfgr0);
361 val &= (~(LPI2C_MCFGR0_HREN_MASK | LPI2C_MCFGR0_HRPOL_MASK |
362 LPI2C_MCFGR0_HRSEL_MASK));
363 val |= LPI2C_MCFGR0_HRPOL(0x1);
364 writel(val, &regs->mcfgr0);
365 /* pincfg and ignore ack */
366 val = readl(&regs->mcfgr1);
367 val &= ~(LPI2C_MCFGR1_PINCFG_MASK | LPI2C_MCFGR1_IGNACK_MASK);
368 val |= LPI2C_MCFGR1_PINCFG(0x0); /* 2 pin open drain */
369 val |= LPI2C_MCFGR1_IGNACK(0x0); /* ignore nack */
370 writel(val, &regs->mcfgr1);
371
372 ret = bus_i2c_set_bus_speed(bus, speed);
373
374 /* enable lpi2c in master mode */
375 val = readl(&regs->mcr) & ~LPI2C_MCR_MEN_MASK;
376 writel(val | LPI2C_MCR_MEN(1), &regs->mcr);
377
378 debug("i2c : controller bus %d, speed %d:\n", bus->seq, speed);
379
380 return ret;
381}
382
383static int imx_lpi2c_probe_chip(struct udevice *bus, u32 chip,
384 u32 chip_flags)
385{
Heinrich Schuchardtd45c2f32018-03-18 11:14:56 +0100386 lpi2c_status_t result;
Peng Fan7ee3f142017-02-24 09:54:18 +0800387
Ye Li971490c2018-07-08 11:46:43 +0800388 result = bus_i2c_start(bus, chip, 0);
Peng Fan7ee3f142017-02-24 09:54:18 +0800389 if (result) {
Ye Li971490c2018-07-08 11:46:43 +0800390 bus_i2c_stop(bus);
Peng Fan7ee3f142017-02-24 09:54:18 +0800391 bus_i2c_init(bus, 100000);
392 return result;
393 }
394
Ye Li971490c2018-07-08 11:46:43 +0800395 result = bus_i2c_stop(bus);
Gao Pana32effd2018-07-08 11:46:41 +0800396 if (result)
Peng Fan7ee3f142017-02-24 09:54:18 +0800397 bus_i2c_init(bus, 100000);
Peng Fan7ee3f142017-02-24 09:54:18 +0800398
399 return result;
400}
401
402static int imx_lpi2c_xfer(struct udevice *bus, struct i2c_msg *msg, int nmsgs)
403{
Ye Lid144f612018-07-08 11:46:42 +0800404 int ret = 0, ret_stop;
Peng Fan7ee3f142017-02-24 09:54:18 +0800405
406 for (; nmsgs > 0; nmsgs--, msg++) {
407 debug("i2c_xfer: chip=0x%x, len=0x%x\n", msg->addr, msg->len);
408 if (msg->flags & I2C_M_RD)
Ye Li971490c2018-07-08 11:46:43 +0800409 ret = bus_i2c_read(bus, msg->addr, msg->buf, msg->len);
Peng Fan7ee3f142017-02-24 09:54:18 +0800410 else {
Ye Li971490c2018-07-08 11:46:43 +0800411 ret = bus_i2c_write(bus, msg->addr, msg->buf,
Peng Fan7ee3f142017-02-24 09:54:18 +0800412 msg->len);
413 if (ret)
414 break;
415 }
416 }
417
418 if (ret)
419 debug("i2c_write: error sending\n");
420
Ye Li971490c2018-07-08 11:46:43 +0800421 ret_stop = bus_i2c_stop(bus);
Ye Lid144f612018-07-08 11:46:42 +0800422 if (ret_stop)
423 debug("i2c_xfer: stop bus error\n");
424
425 ret |= ret_stop;
426
Peng Fan7ee3f142017-02-24 09:54:18 +0800427 return ret;
428}
429
430static int imx_lpi2c_set_bus_speed(struct udevice *bus, unsigned int speed)
431{
432 return bus_i2c_set_bus_speed(bus, speed);
433}
434
Peng Fan3d7690a2018-07-17 20:38:33 +0800435__weak int enable_i2c_clk(unsigned char enable, unsigned int i2c_num)
436{
437 return 0;
438}
439
Peng Fan7ee3f142017-02-24 09:54:18 +0800440static int imx_lpi2c_probe(struct udevice *bus)
441{
442 struct imx_lpi2c_bus *i2c_bus = dev_get_priv(bus);
443 fdt_addr_t addr;
444 int ret;
445
446 i2c_bus->driver_data = dev_get_driver_data(bus);
447
Simon Glassa821c4a2017-05-17 17:18:05 -0600448 addr = devfdt_get_addr(bus);
Peng Fan7ee3f142017-02-24 09:54:18 +0800449 if (addr == FDT_ADDR_T_NONE)
Simon Glass7c843192017-09-17 16:54:53 -0600450 return -EINVAL;
Peng Fan7ee3f142017-02-24 09:54:18 +0800451
452 i2c_bus->base = addr;
453 i2c_bus->index = bus->seq;
454 i2c_bus->bus = bus;
455
456 /* power up i2c resource */
Peng Fan0074d4b2018-01-02 15:41:52 +0800457 ret = init_i2c_power(bus->seq);
Peng Fan7ee3f142017-02-24 09:54:18 +0800458 if (ret) {
459 debug("init_i2c_power err = %d\n", ret);
460 return ret;
461 }
462
Peng Fan3d7690a2018-07-17 20:38:33 +0800463 if (IS_ENABLED(CONFIG_CLK)) {
464 ret = clk_get_by_name(bus, "per", &i2c_bus->per_clk);
465 if (ret) {
466 dev_err(bus, "Failed to get per clk\n");
467 return ret;
468 }
469 ret = clk_enable(&i2c_bus->per_clk);
470 if (ret) {
471 dev_err(bus, "Failed to enable per clk\n");
472 return ret;
473 }
474 } else {
475 /* To i.MX7ULP, only i2c4-7 can be handled by A7 core */
476 ret = enable_i2c_clk(1, bus->seq);
477 if (ret < 0)
478 return ret;
479 }
Peng Fan7ee3f142017-02-24 09:54:18 +0800480
481 ret = bus_i2c_init(bus, 100000);
482 if (ret < 0)
483 return ret;
484
485 debug("i2c : controller bus %d at %lu , speed %d: ",
486 bus->seq, i2c_bus->base,
487 i2c_bus->speed);
488
489 return 0;
490}
491
492static const struct dm_i2c_ops imx_lpi2c_ops = {
493 .xfer = imx_lpi2c_xfer,
494 .probe_chip = imx_lpi2c_probe_chip,
495 .set_bus_speed = imx_lpi2c_set_bus_speed,
496};
497
498static const struct udevice_id imx_lpi2c_ids[] = {
499 { .compatible = "fsl,imx7ulp-lpi2c", },
Ye Li9b2ebcc2018-07-08 11:46:40 +0800500 { .compatible = "fsl,imx8qm-lpi2c", },
Peng Fan7ee3f142017-02-24 09:54:18 +0800501 {}
502};
503
504U_BOOT_DRIVER(imx_lpi2c) = {
505 .name = "imx_lpi2c",
506 .id = UCLASS_I2C,
507 .of_match = imx_lpi2c_ids,
508 .probe = imx_lpi2c_probe,
509 .priv_auto_alloc_size = sizeof(struct imx_lpi2c_bus),
510 .ops = &imx_lpi2c_ops,
511};