Lines Matching +full:i2c +full:- +full:0
1 // SPDX-License-Identifier: GPL-2.0
3 * ddbridge-i2c.c: Digital Devices bridge i2c driver
5 * Copyright (C) 2010-2017 Digital Devices GmbH
20 #include <linux/i2c.h>
25 #include "ddbridge-i2c.h"
26 #include "ddbridge-regs.h"
27 #include "ddbridge-io.h"
31 static int ddb_i2c_cmd(struct ddb_i2c *i2c, u32 adr, u32 cmd) in ddb_i2c_cmd() argument
33 struct ddb *dev = i2c->dev; in ddb_i2c_cmd()
37 ddbwritel(dev, (adr << 9) | cmd, i2c->regs + I2C_COMMAND); in ddb_i2c_cmd()
38 stat = wait_for_completion_timeout(&i2c->completion, HZ); in ddb_i2c_cmd()
39 val = ddbreadl(dev, i2c->regs + I2C_COMMAND); in ddb_i2c_cmd()
40 if (stat == 0) { in ddb_i2c_cmd()
41 dev_err(dev->dev, "I2C timeout, card %d, port %d, link %u\n", in ddb_i2c_cmd()
42 dev->nr, i2c->nr, i2c->link); in ddb_i2c_cmd()
46 dev_err(dev->dev, "DDBridge IRS %08x\n", istat); in ddb_i2c_cmd()
47 if (i2c->link) { in ddb_i2c_cmd()
49 DDB_LINK_TAG(i2c->link) | in ddb_i2c_cmd()
52 dev_err(dev->dev, "DDBridge link %u IRS %08x\n", in ddb_i2c_cmd()
53 i2c->link, listat); in ddb_i2c_cmd()
59 i2c->regs + I2C_MONITOR); in ddb_i2c_cmd()
61 dev_err(dev->dev, "I2C cmd=%08x mon=%08x\n", in ddb_i2c_cmd()
65 return -EIO; in ddb_i2c_cmd()
67 val &= 0x70000; in ddb_i2c_cmd()
68 if (val == 0x20000) in ddb_i2c_cmd()
69 dev_err(dev->dev, "I2C bus error\n"); in ddb_i2c_cmd()
71 return -EIO; in ddb_i2c_cmd()
72 return 0; in ddb_i2c_cmd()
78 struct ddb_i2c *i2c = (struct ddb_i2c *)i2c_get_adapdata(adapter); in ddb_i2c_master_xfer() local
79 struct ddb *dev = i2c->dev; in ddb_i2c_master_xfer()
80 u8 addr = 0; in ddb_i2c_master_xfer()
82 addr = msg[0].addr; in ddb_i2c_master_xfer()
83 if (msg[0].len > i2c->bsize) in ddb_i2c_master_xfer()
84 return -EIO; in ddb_i2c_master_xfer()
87 if (msg[0].flags & I2C_M_RD) { in ddb_i2c_master_xfer()
88 ddbwritel(dev, msg[0].len << 16, in ddb_i2c_master_xfer()
89 i2c->regs + I2C_TASKLENGTH); in ddb_i2c_master_xfer()
90 if (ddb_i2c_cmd(i2c, addr, 3)) in ddb_i2c_master_xfer()
92 ddbcpyfrom(dev, msg[0].buf, in ddb_i2c_master_xfer()
93 i2c->rbuf, msg[0].len); in ddb_i2c_master_xfer()
96 ddbcpyto(dev, i2c->wbuf, msg[0].buf, msg[0].len); in ddb_i2c_master_xfer()
97 ddbwritel(dev, msg[0].len, i2c->regs + I2C_TASKLENGTH); in ddb_i2c_master_xfer()
98 if (ddb_i2c_cmd(i2c, addr, 2)) in ddb_i2c_master_xfer()
102 if ((msg[0].flags & I2C_M_RD) == I2C_M_RD) in ddb_i2c_master_xfer()
106 if (msg[1].len > i2c->bsize) in ddb_i2c_master_xfer()
108 ddbcpyto(dev, i2c->wbuf, msg[0].buf, msg[0].len); in ddb_i2c_master_xfer()
109 ddbwritel(dev, msg[0].len | (msg[1].len << 16), in ddb_i2c_master_xfer()
110 i2c->regs + I2C_TASKLENGTH); in ddb_i2c_master_xfer()
111 if (ddb_i2c_cmd(i2c, addr, 1)) in ddb_i2c_master_xfer()
114 i2c->rbuf, in ddb_i2c_master_xfer()
120 return -EIO; in ddb_i2c_master_xfer()
136 struct ddb_i2c *i2c; in ddb_i2c_release() local
138 for (i = 0; i < dev->i2c_num; i++) { in ddb_i2c_release()
139 i2c = &dev->i2c[i]; in ddb_i2c_release()
140 i2c_del_adapter(&i2c->adap); in ddb_i2c_release()
146 struct ddb_i2c *i2c = (struct ddb_i2c *)priv; in i2c_handler() local
148 complete(&i2c->completion); in i2c_handler()
151 static int ddb_i2c_add(struct ddb *dev, struct ddb_i2c *i2c, in ddb_i2c_add() argument
157 i2c->nr = i; in ddb_i2c_add()
158 i2c->dev = dev; in ddb_i2c_add()
159 i2c->link = link; in ddb_i2c_add()
160 i2c->bsize = regmap->i2c_buf->size; in ddb_i2c_add()
161 i2c->wbuf = DDB_LINK_TAG(link) | in ddb_i2c_add()
162 (regmap->i2c_buf->base + i2c->bsize * i); in ddb_i2c_add()
163 i2c->rbuf = i2c->wbuf; /* + i2c->bsize / 2 */ in ddb_i2c_add()
164 i2c->regs = DDB_LINK_TAG(link) | in ddb_i2c_add()
165 (regmap->i2c->base + regmap->i2c->size * i); in ddb_i2c_add()
166 ddbwritel(dev, I2C_SPEED_100, i2c->regs + I2C_TIMING); in ddb_i2c_add()
167 ddbwritel(dev, ((i2c->rbuf & 0xffff) << 16) | (i2c->wbuf & 0xffff), in ddb_i2c_add()
168 i2c->regs + I2C_TASKADDRESS); in ddb_i2c_add()
169 init_completion(&i2c->completion); in ddb_i2c_add()
171 adap = &i2c->adap; in ddb_i2c_add()
172 i2c_set_adapdata(adap, i2c); in ddb_i2c_add()
174 adap->class = I2C_ADAP_CLASS_TV_DIGITAL | I2C_CLASS_TV_ANALOG; in ddb_i2c_add()
177 adap->class = I2C_CLASS_TV_ANALOG; in ddb_i2c_add()
180 snprintf(adap->name, I2C_NAME_SIZE, "ddbridge_%02x.%x.%x", in ddb_i2c_add()
181 dev->nr, i2c->link, i); in ddb_i2c_add()
182 adap->algo = &ddb_i2c_algo; in ddb_i2c_add()
183 adap->algo_data = (void *)i2c; in ddb_i2c_add()
184 adap->dev.parent = dev->dev; in ddb_i2c_add()
190 int stat = 0; in ddb_i2c_init()
191 u32 i, j, num = 0, l, base; in ddb_i2c_init()
192 struct ddb_i2c *i2c; in ddb_i2c_init() local
196 for (l = 0; l < DDB_MAX_LINK; l++) { in ddb_i2c_init()
197 if (!dev->link[l].info) in ddb_i2c_init()
199 regmap = dev->link[l].info->regmap; in ddb_i2c_init()
200 if (!regmap || !regmap->i2c) in ddb_i2c_init()
202 base = regmap->irq_base_i2c; in ddb_i2c_init()
203 for (i = 0; i < regmap->i2c->num; i++) { in ddb_i2c_init()
204 if (!(dev->link[l].info->i2c_mask & (1 << i))) in ddb_i2c_init()
206 i2c = &dev->i2c[num]; in ddb_i2c_init()
207 ddb_irq_set(dev, l, i + base, i2c_handler, i2c); in ddb_i2c_init()
208 stat = ddb_i2c_add(dev, i2c, regmap, l, i, num); in ddb_i2c_init()
215 for (j = 0; j < num; j++) { in ddb_i2c_init()
216 i2c = &dev->i2c[j]; in ddb_i2c_init()
217 adap = &i2c->adap; in ddb_i2c_init()
221 dev->i2c_num = num; in ddb_i2c_init()