Skip to content

Commit b06204c

Browse files
Hans HuAndi Shyti
authored andcommitted
i2c: wmt: add platform type VIAI2C_PLAT_WMT
Enumeration variables are added to differentiate between different platforms. Acked-by: Wolfram Sang <wsa+renesas@sang-engineering.com> Signed-off-by: Hans Hu <hanshu-oc@zhaoxin.com> Signed-off-by: Andi Shyti <andi.shyti@kernel.org>
1 parent 2e829cc commit b06204c

3 files changed

Lines changed: 27 additions & 14 deletions

File tree

drivers/i2c/busses/i2c-viai2c-common.c

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static int viai2c_write(struct viai2c *i2c, struct i2c_msg *pmsg, int last)
3535
writew(pmsg->buf[0] & 0xFF, i2c->base + VIAI2C_REG_CDR);
3636
}
3737

38-
if (!(pmsg->flags & I2C_M_NOSTART)) {
38+
if (i2c->platform == VIAI2C_PLAT_WMT && !(pmsg->flags & I2C_M_NOSTART)) {
3939
val = readw(i2c->base + VIAI2C_REG_CR);
4040
val &= ~VIAI2C_CR_TX_END;
4141
val |= VIAI2C_CR_CPU_RDY;
@@ -48,7 +48,7 @@ static int viai2c_write(struct viai2c *i2c, struct i2c_msg *pmsg, int last)
4848

4949
writew(tcr_val, i2c->base + VIAI2C_REG_TCR);
5050

51-
if (pmsg->flags & I2C_M_NOSTART) {
51+
if (i2c->platform == VIAI2C_PLAT_WMT && pmsg->flags & I2C_M_NOSTART) {
5252
val = readw(i2c->base + VIAI2C_REG_CR);
5353
val |= VIAI2C_CR_CPU_RDY;
5454
writew(val, i2c->base + VIAI2C_REG_CR);
@@ -67,7 +67,7 @@ static int viai2c_read(struct viai2c *i2c, struct i2c_msg *pmsg)
6767
val = readw(i2c->base + VIAI2C_REG_CR);
6868
val &= ~(VIAI2C_CR_TX_END | VIAI2C_CR_RX_END);
6969

70-
if (!(pmsg->flags & I2C_M_NOSTART))
70+
if (i2c->platform == VIAI2C_PLAT_WMT && !(pmsg->flags & I2C_M_NOSTART))
7171
val |= VIAI2C_CR_CPU_RDY;
7272

7373
if (pmsg->len == 1)
@@ -81,7 +81,7 @@ static int viai2c_read(struct viai2c *i2c, struct i2c_msg *pmsg)
8181

8282
writew(tcr_val, i2c->base + VIAI2C_REG_TCR);
8383

84-
if (pmsg->flags & I2C_M_NOSTART) {
84+
if (i2c->platform == VIAI2C_PLAT_WMT && (pmsg->flags & I2C_M_NOSTART)) {
8585
val = readw(i2c->base + VIAI2C_REG_CR);
8686
val |= VIAI2C_CR_CPU_RDY;
8787
writew(val, i2c->base + VIAI2C_REG_CR);
@@ -102,7 +102,7 @@ int viai2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
102102

103103
for (i = 0; ret >= 0 && i < num; i++) {
104104
pmsg = &msgs[i];
105-
if (!(pmsg->flags & I2C_M_NOSTART)) {
105+
if (i2c->platform == VIAI2C_PLAT_WMT && !(pmsg->flags & I2C_M_NOSTART)) {
106106
ret = viai2c_wait_bus_not_busy(i2c);
107107
if (ret < 0)
108108
return ret;
@@ -155,7 +155,7 @@ static int viai2c_irq_xfer(struct viai2c *i2c)
155155
}
156156

157157
if ((i2c->xfered_len + 1) == msg->len) {
158-
if (!i2c->last)
158+
if (i2c->platform == VIAI2C_PLAT_WMT && !i2c->last)
159159
writew(VIAI2C_CR_ENABLE, base + VIAI2C_REG_CR);
160160
} else {
161161
writew(msg->buf[i2c->xfered_len + 1] & 0xFF, base + VIAI2C_REG_CDR);
@@ -181,7 +181,7 @@ static irqreturn_t viai2c_isr(int irq, void *data)
181181
if (status & VIAI2C_ISR_NACK_ADDR)
182182
i2c->ret = -EIO;
183183

184-
if (status & VIAI2C_ISR_SCL_TIMEOUT)
184+
if (i2c->platform == VIAI2C_PLAT_WMT && (status & VIAI2C_ISR_SCL_TIMEOUT))
185185
i2c->ret = -ETIMEDOUT;
186186

187187
if (!i2c->ret)
@@ -194,9 +194,10 @@ static irqreturn_t viai2c_isr(int irq, void *data)
194194
return IRQ_HANDLED;
195195
}
196196

197-
int viai2c_init(struct platform_device *pdev, struct viai2c **pi2c)
197+
int viai2c_init(struct platform_device *pdev, struct viai2c **pi2c, int plat)
198198
{
199199
int err;
200+
int irq_flags;
200201
struct viai2c *i2c;
201202
struct device_node *np = pdev->dev.of_node;
202203

@@ -208,12 +209,19 @@ int viai2c_init(struct platform_device *pdev, struct viai2c **pi2c)
208209
if (IS_ERR(i2c->base))
209210
return PTR_ERR(i2c->base);
210211

211-
i2c->irq = irq_of_parse_and_map(np, 0);
212-
if (!i2c->irq)
213-
return -EINVAL;
212+
if (plat == VIAI2C_PLAT_WMT) {
213+
irq_flags = 0;
214+
i2c->irq = irq_of_parse_and_map(np, 0);
215+
if (!i2c->irq)
216+
return -EINVAL;
217+
} else {
218+
return dev_err_probe(&pdev->dev, -EINVAL, "wrong platform type\n");
219+
}
220+
221+
i2c->platform = plat;
214222

215223
err = devm_request_irq(&pdev->dev, i2c->irq, viai2c_isr,
216-
0, pdev->name, i2c);
224+
irq_flags, pdev->name, i2c);
217225
if (err)
218226
return dev_err_probe(&pdev->dev, err,
219227
"failed to request irq %i\n", i2c->irq);

drivers/i2c/busses/i2c-viai2c-common.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@
5050

5151
#define VIAI2C_TIMEOUT (msecs_to_jiffies(1000))
5252

53+
enum {
54+
VIAI2C_PLAT_WMT,
55+
};
56+
5357
struct viai2c {
5458
struct i2c_adapter adapter;
5559
struct completion complete;
@@ -62,10 +66,11 @@ struct viai2c {
6266
struct i2c_msg *msg;
6367
int ret;
6468
bool last;
69+
unsigned int platform;
6570
};
6671

6772
int viai2c_wait_bus_not_busy(struct viai2c *i2c);
6873
int viai2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num);
69-
int viai2c_init(struct platform_device *pdev, struct viai2c **pi2c);
74+
int viai2c_init(struct platform_device *pdev, struct viai2c **pi2c, int plat);
7075

7176
#endif

drivers/i2c/busses/i2c-viai2c-wmt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ static int wmt_i2c_probe(struct platform_device *pdev)
8080
int err;
8181
u32 clk_rate;
8282

83-
err = viai2c_init(pdev, &i2c);
83+
err = viai2c_init(pdev, &i2c, VIAI2C_PLAT_WMT);
8484
if (err)
8585
return err;
8686

0 commit comments

Comments
 (0)