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>
This commit is contained in:
Hans Hu 2024-04-08 10:54:47 +08:00 committed by Andi Shyti
parent 2e829ccc27
commit b06204c7d4
3 changed files with 27 additions and 14 deletions

View File

@ -35,7 +35,7 @@ static int viai2c_write(struct viai2c *i2c, struct i2c_msg *pmsg, int last)
writew(pmsg->buf[0] & 0xFF, i2c->base + VIAI2C_REG_CDR); writew(pmsg->buf[0] & 0xFF, i2c->base + VIAI2C_REG_CDR);
} }
if (!(pmsg->flags & I2C_M_NOSTART)) { if (i2c->platform == VIAI2C_PLAT_WMT && !(pmsg->flags & I2C_M_NOSTART)) {
val = readw(i2c->base + VIAI2C_REG_CR); val = readw(i2c->base + VIAI2C_REG_CR);
val &= ~VIAI2C_CR_TX_END; val &= ~VIAI2C_CR_TX_END;
val |= VIAI2C_CR_CPU_RDY; val |= VIAI2C_CR_CPU_RDY;
@ -48,7 +48,7 @@ static int viai2c_write(struct viai2c *i2c, struct i2c_msg *pmsg, int last)
writew(tcr_val, i2c->base + VIAI2C_REG_TCR); writew(tcr_val, i2c->base + VIAI2C_REG_TCR);
if (pmsg->flags & I2C_M_NOSTART) { if (i2c->platform == VIAI2C_PLAT_WMT && pmsg->flags & I2C_M_NOSTART) {
val = readw(i2c->base + VIAI2C_REG_CR); val = readw(i2c->base + VIAI2C_REG_CR);
val |= VIAI2C_CR_CPU_RDY; val |= VIAI2C_CR_CPU_RDY;
writew(val, i2c->base + VIAI2C_REG_CR); writew(val, i2c->base + VIAI2C_REG_CR);
@ -67,7 +67,7 @@ static int viai2c_read(struct viai2c *i2c, struct i2c_msg *pmsg)
val = readw(i2c->base + VIAI2C_REG_CR); val = readw(i2c->base + VIAI2C_REG_CR);
val &= ~(VIAI2C_CR_TX_END | VIAI2C_CR_RX_END); val &= ~(VIAI2C_CR_TX_END | VIAI2C_CR_RX_END);
if (!(pmsg->flags & I2C_M_NOSTART)) if (i2c->platform == VIAI2C_PLAT_WMT && !(pmsg->flags & I2C_M_NOSTART))
val |= VIAI2C_CR_CPU_RDY; val |= VIAI2C_CR_CPU_RDY;
if (pmsg->len == 1) if (pmsg->len == 1)
@ -81,7 +81,7 @@ static int viai2c_read(struct viai2c *i2c, struct i2c_msg *pmsg)
writew(tcr_val, i2c->base + VIAI2C_REG_TCR); writew(tcr_val, i2c->base + VIAI2C_REG_TCR);
if (pmsg->flags & I2C_M_NOSTART) { if (i2c->platform == VIAI2C_PLAT_WMT && (pmsg->flags & I2C_M_NOSTART)) {
val = readw(i2c->base + VIAI2C_REG_CR); val = readw(i2c->base + VIAI2C_REG_CR);
val |= VIAI2C_CR_CPU_RDY; val |= VIAI2C_CR_CPU_RDY;
writew(val, i2c->base + VIAI2C_REG_CR); writew(val, i2c->base + VIAI2C_REG_CR);
@ -102,7 +102,7 @@ int viai2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
for (i = 0; ret >= 0 && i < num; i++) { for (i = 0; ret >= 0 && i < num; i++) {
pmsg = &msgs[i]; pmsg = &msgs[i];
if (!(pmsg->flags & I2C_M_NOSTART)) { if (i2c->platform == VIAI2C_PLAT_WMT && !(pmsg->flags & I2C_M_NOSTART)) {
ret = viai2c_wait_bus_not_busy(i2c); ret = viai2c_wait_bus_not_busy(i2c);
if (ret < 0) if (ret < 0)
return ret; return ret;
@ -155,7 +155,7 @@ static int viai2c_irq_xfer(struct viai2c *i2c)
} }
if ((i2c->xfered_len + 1) == msg->len) { if ((i2c->xfered_len + 1) == msg->len) {
if (!i2c->last) if (i2c->platform == VIAI2C_PLAT_WMT && !i2c->last)
writew(VIAI2C_CR_ENABLE, base + VIAI2C_REG_CR); writew(VIAI2C_CR_ENABLE, base + VIAI2C_REG_CR);
} else { } else {
writew(msg->buf[i2c->xfered_len + 1] & 0xFF, base + VIAI2C_REG_CDR); 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)
if (status & VIAI2C_ISR_NACK_ADDR) if (status & VIAI2C_ISR_NACK_ADDR)
i2c->ret = -EIO; i2c->ret = -EIO;
if (status & VIAI2C_ISR_SCL_TIMEOUT) if (i2c->platform == VIAI2C_PLAT_WMT && (status & VIAI2C_ISR_SCL_TIMEOUT))
i2c->ret = -ETIMEDOUT; i2c->ret = -ETIMEDOUT;
if (!i2c->ret) if (!i2c->ret)
@ -194,9 +194,10 @@ static irqreturn_t viai2c_isr(int irq, void *data)
return IRQ_HANDLED; return IRQ_HANDLED;
} }
int viai2c_init(struct platform_device *pdev, struct viai2c **pi2c) int viai2c_init(struct platform_device *pdev, struct viai2c **pi2c, int plat)
{ {
int err; int err;
int irq_flags;
struct viai2c *i2c; struct viai2c *i2c;
struct device_node *np = pdev->dev.of_node; struct device_node *np = pdev->dev.of_node;
@ -208,12 +209,19 @@ int viai2c_init(struct platform_device *pdev, struct viai2c **pi2c)
if (IS_ERR(i2c->base)) if (IS_ERR(i2c->base))
return PTR_ERR(i2c->base); return PTR_ERR(i2c->base);
i2c->irq = irq_of_parse_and_map(np, 0); if (plat == VIAI2C_PLAT_WMT) {
if (!i2c->irq) irq_flags = 0;
return -EINVAL; i2c->irq = irq_of_parse_and_map(np, 0);
if (!i2c->irq)
return -EINVAL;
} else {
return dev_err_probe(&pdev->dev, -EINVAL, "wrong platform type\n");
}
i2c->platform = plat;
err = devm_request_irq(&pdev->dev, i2c->irq, viai2c_isr, err = devm_request_irq(&pdev->dev, i2c->irq, viai2c_isr,
0, pdev->name, i2c); irq_flags, pdev->name, i2c);
if (err) if (err)
return dev_err_probe(&pdev->dev, err, return dev_err_probe(&pdev->dev, err,
"failed to request irq %i\n", i2c->irq); "failed to request irq %i\n", i2c->irq);

View File

@ -50,6 +50,10 @@
#define VIAI2C_TIMEOUT (msecs_to_jiffies(1000)) #define VIAI2C_TIMEOUT (msecs_to_jiffies(1000))
enum {
VIAI2C_PLAT_WMT,
};
struct viai2c { struct viai2c {
struct i2c_adapter adapter; struct i2c_adapter adapter;
struct completion complete; struct completion complete;
@ -62,10 +66,11 @@ struct viai2c {
struct i2c_msg *msg; struct i2c_msg *msg;
int ret; int ret;
bool last; bool last;
unsigned int platform;
}; };
int viai2c_wait_bus_not_busy(struct viai2c *i2c); int viai2c_wait_bus_not_busy(struct viai2c *i2c);
int viai2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num); int viai2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num);
int viai2c_init(struct platform_device *pdev, struct viai2c **pi2c); int viai2c_init(struct platform_device *pdev, struct viai2c **pi2c, int plat);
#endif #endif

View File

@ -80,7 +80,7 @@ static int wmt_i2c_probe(struct platform_device *pdev)
int err; int err;
u32 clk_rate; u32 clk_rate;
err = viai2c_init(pdev, &i2c); err = viai2c_init(pdev, &i2c, VIAI2C_PLAT_WMT);
if (err) if (err)
return err; return err;