Lines Matching defs:i2c

10 #include <i2c.h>
64 static void meson_i2c_reset_tokens(struct meson_i2c *i2c)
66 i2c->tokens[0] = 0;
67 i2c->tokens[1] = 0;
68 i2c->num_tokens = 0;
71 static void meson_i2c_add_token(struct meson_i2c *i2c, int token)
73 if (i2c->num_tokens < 8)
74 i2c->tokens[0] |= (token & 0xf) << (i2c->num_tokens * 4);
76 i2c->tokens[1] |= (token & 0xf) << ((i2c->num_tokens % 8) * 4);
78 i2c->num_tokens++;
85 static void meson_i2c_get_data(struct meson_i2c *i2c, u8 *buf, int len)
90 rdata0 = readl(&i2c->regs->tok_rdata0);
91 rdata1 = readl(&i2c->regs->tok_rdata1);
93 debug("meson i2c: read data %08x %08x len %d\n", rdata0, rdata1, len);
106 static void meson_i2c_put_data(struct meson_i2c *i2c, u8 *buf, int len)
117 writel(wdata0, &i2c->regs->tok_wdata0);
118 writel(wdata1, &i2c->regs->tok_wdata1);
120 debug("meson i2c: write data %08x %08x len %d\n", wdata0, wdata1, len);
128 static void meson_i2c_prepare_xfer(struct meson_i2c *i2c)
130 bool write = !(i2c->msg->flags & I2C_M_RD);
133 i2c->count = min(i2c->msg->len - i2c->pos, 8u);
135 for (i = 0; i + 1 < i2c->count; i++)
136 meson_i2c_add_token(i2c, TOKEN_DATA);
138 if (i2c->count) {
139 if (write || i2c->pos + i2c->count < i2c->msg->len)
140 meson_i2c_add_token(i2c, TOKEN_DATA);
142 meson_i2c_add_token(i2c, TOKEN_DATA_LAST);
146 meson_i2c_put_data(i2c, i2c->msg->buf + i2c->pos, i2c->count);
148 if (i2c->last && i2c->pos + i2c->count >= i2c->msg->len)
149 meson_i2c_add_token(i2c, TOKEN_STOP);
151 writel(i2c->tokens[0], &i2c->regs->tok_list0);
152 writel(i2c->tokens[1], &i2c->regs->tok_list1);
155 static void meson_i2c_do_start(struct meson_i2c *i2c, struct i2c_msg *msg)
162 writel(msg->addr << 1, &i2c->regs->slave_addr);
163 meson_i2c_add_token(i2c, TOKEN_START);
164 meson_i2c_add_token(i2c, token);
167 static int meson_i2c_xfer_msg(struct meson_i2c *i2c, struct i2c_msg *msg,
172 debug("meson i2c: %s addr %u len %u\n",
176 i2c->msg = msg;
177 i2c->last = last;
178 i2c->pos = 0;
179 i2c->count = 0;
181 meson_i2c_reset_tokens(i2c);
182 meson_i2c_do_start(i2c, msg);
185 meson_i2c_prepare_xfer(i2c);
188 setbits_le32(&i2c->regs->ctrl, REG_CTRL_START);
190 while (readl(&i2c->regs->ctrl) & REG_CTRL_STATUS) {
192 clrbits_le32(&i2c->regs->ctrl, REG_CTRL_START);
193 debug("meson i2c: timeout\n");
198 meson_i2c_reset_tokens(i2c);
199 clrbits_le32(&i2c->regs->ctrl, REG_CTRL_START);
201 if (readl(&i2c->regs->ctrl) & REG_CTRL_ERROR) {
202 debug("meson i2c: error\n");
206 if ((msg->flags & I2C_M_RD) && i2c->count) {
207 meson_i2c_get_data(i2c, i2c->msg->buf + i2c->pos,
208 i2c->count);
210 i2c->pos += i2c->count;
211 } while (i2c->pos < msg->len);
219 struct meson_i2c *i2c = dev_get_priv(bus);
223 ret = meson_i2c_xfer_msg(i2c, msg + i, i == nmsgs - 1);
233 struct meson_i2c *i2c = dev_get_priv(bus);
237 clk_rate = clk_get_rate(&i2c->clk);
241 div = DIV_ROUND_UP(clk_rate, speed * i2c->data->div_factor);
245 debug("meson i2c: requested bus frequency too low\n");
249 clrsetbits_le32(&i2c->regs->ctrl, REG_CTRL_CLKDIV_MASK,
252 clrsetbits_le32(&i2c->regs->ctrl, REG_CTRL_CLKDIVEXT_MASK,
255 debug("meson i2c: set clk %u, src %lu, div %u\n", speed, clk_rate, div);
262 struct meson_i2c *i2c = dev_get_priv(bus);
265 i2c->data = (const struct meson_i2c_data *)dev_get_driver_data(bus);
267 ret = clk_get_by_index(bus, 0, &i2c->clk);
271 ret = clk_enable(&i2c->clk);
275 i2c->regs = dev_read_addr_ptr(bus);
276 clrbits_le32(&i2c->regs->ctrl, REG_CTRL_START);
299 {.compatible = "amlogic,meson6-i2c", .data = (ulong)&i2c_meson6_data},
300 {.compatible = "amlogic,meson-gx-i2c", .data = (ulong)&i2c_gxbb_data},
301 {.compatible = "amlogic,meson-gxbb-i2c", .data = (ulong)&i2c_gxbb_data},
302 {.compatible = "amlogic,meson-axg-i2c", .data = (ulong)&i2c_axg_data},