usb: typec: ucsi: add support for Cypress CCGx
PATCH v5 2/2 usb: typec: ucsi: add support for Cypress CCGx
Hi Greg,
Quoted 13 lines
Quoted 13 lines
(quoted diff) +13
-0+static int ccg_read(struct ucsi_ccg *uc, u16 rab, u8 *data, u32 len) +{ + struct device *dev = uc->dev; + struct i2c_client *client = uc->client; + unsigned char buf[2]; + struct i2c_msg msgs[] = { + { + .addr = client->addr, + .flags = 0x0, + .len = 0x2, + .buf = buf, + }, + {
Quoted 8 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ .addr = client->addr, + .flags = I2C_M_RD, + .buf = data, + }, + };Are you sure you are allowed to do i2c messages off of the stack like this? Will that work on all platforms?
Most of the drivers in kernel today seem to use stack memory for i2c_transfer() but I will fix it in next version.
Quoted 7 lines
Quoted 7 lines
(quoted diff) +7
-0+ u32 rlen, rem_len = len; + int err; + + while (rem_len > 0) { + msgs[1].buf = &data[len - rem_len]; + rlen = min_t(u16, rem_len, 4); + msgs[1].len = rlen;
Quoted 8 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+ put_unaligned_le16(rab, buf); + err = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); + if (err < 0) { + dev_err(dev, "i2c_transfer failed, err %d\n", err);You are printing out an error here, no need to print out another error every time you call this function and it fails, right? Only do it in one place, otherwise it is extra noisy when things fail.
I will fix and add error print in only one location. I think better to keep it here only and remove error print line from all the caller of this function.
Quoted 36 lines
Quoted 23 lines
(quoted diff) +23
-0+ return err; + } + rab += rlen; + rem_len -= rlen; + } + + return 0; +} + +static int ccg_write(struct ucsi_ccg *uc, u16 rab, u8 *data, u32 len) +{ + struct device *dev = uc->dev; + struct i2c_client *client = uc->client; + unsigned char buf[2]; + struct i2c_msg msgs[] = { + { + .addr = client->addr, + .flags = 0x0, + .len = 0x2, + .buf = buf, + }, + { + .addr = client->addr,Review
Quoted 10 lines
(quoted diff) +10
-0+ .flags = 0x0, + .buf = data, + .len = len, + }, + { + .addr = client->addr, + .flags = I2C_M_STOP, + }, + }; + int err;Same question here, i2c message off of the stack?
Quoted 8 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+ + put_unaligned_le16(rab, buf); + err = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); + if (err < 0) { + dev_err(dev, "i2c_transfer failed, err %d\n", err); + return err;And again, only print an error in one place please.
Ok.
Quoted 2 lines
This can be simplified to just:
return i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); right?
Only issue is that i2c_transfer() return number of messages on success but ucsi APIs sync() and cmd() at drivers/usb/typec/ucsi/ucsi.h expects return value of '0' on success.
Quoted 15 lines
Quoted 4 lines
(quoted diff) +4
-0+ } + + return 0; +}Review
Quoted 10 lines
(quoted diff) +10
-0+ +static int ucsi_ccg_init(struct ucsi_ccg *uc) { + struct device *dev = uc->dev; + unsigned int count = 10; + u8 data[64]; + int err; + + /* + * Selectively issue device reset + * - if RESPONSE register is RESET_COMPLETE, do not issue devicereset
Quoted 9 lines
Review
Quoted 7 lines
(quoted diff) +7
-0+ * (will cause usb device disconnect / reconnect) + * - if RESPONSE register is not RESET_COMPLETE, issue device reset + * (causes PPC to resync device connect state by re-issuing + * set mux command) + */ + data[0] = 0x00; + data[1] = 0x00;Again, it's ok to do messages off of the stack?
Will fix.
Thanks
Ajay
---
nvpublic
--
Quoted 4 lines
thanks,
greg k-h