10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/slab.h>
16 #include <linux/errno.h>
17 #include <linux/i2c.h>
22 #define XLR_I2C_CFG 0x00
23 #define XLR_I2C_CLKDIV 0x01
24 #define XLR_I2C_DEVADDR 0x02
25 #define XLR_I2C_ADDR 0x03
26 #define XLR_I2C_DATAOUT 0x04
27 #define XLR_I2C_DATAIN 0x05
28 #define XLR_I2C_STATUS 0x06
29 #define XLR_I2C_STARTXFR 0x07
30 #define XLR_I2C_BYTECNT 0x08
31 #define XLR_I2C_HDSTATIM 0x09
34 #define XLR_I2C_BUS_BUSY 0x01
35 #define XLR_I2C_SDOEMPTY 0x02
36 #define XLR_I2C_RXRDY 0x04
37 #define XLR_I2C_ACK_ERR 0x08
38 #define XLR_I2C_ARB_STARTERR 0x30
41 #define XLR_I2C_CFG_ADDR 0xF8
42 #define XLR_I2C_CFG_NOADDR 0xFA
43 #define XLR_I2C_STARTXFR_ND 0x02
44 #define XLR_I2C_STARTXFR_RD 0x01
45 #define XLR_I2C_STARTXFR_WR 0x00
47 #define XLR_I2C_TIMEOUT 10
75 unsigned long timeout, stoptime, checktime;
107 byte = (pos < len) ? buf[pos] : 0;
127 dev_err(&adap->
dev,
"I2C transmit timeout\n");
135 unsigned long timeout, stoptime, checktime;
168 if (i2c_status & XLR_I2C_ARB_STARTERR) {
174 if (i2c_status & XLR_I2C_ACK_ERR)
193 for (i = 0; ret == 0 && i < num; i++) {
196 ret = xlr_i2c_rx(priv, msg->
len, &msg->
buf[0],
199 ret = xlr_i2c_tx(priv, msg->
len, &msg->
buf[0],
203 return (ret != 0) ? ret : num;
213 .master_xfer = xlr_i2c_xfer,
214 .functionality = xlr_func,
230 dev_err(&pdev->
dev,
"devm_request_and_ioremap failed\n");
234 priv->
adap.dev.parent = &pdev->
dev;
237 priv->
adap.algo = &xlr_i2c_algo;
242 i2c_set_adapdata(&priv->
adap, priv);
245 dev_err(&priv->
adap.dev,
"Failed to add i2c bus.\n");
249 platform_set_drvdata(pdev, priv);
258 priv = platform_get_drvdata(pdev);
260 platform_set_drvdata(pdev,
NULL);
265 .probe = xlr_i2c_probe,
268 .name =
"xlr-i2cbus",