usb: typec: ucsi: add support for Cypress CCGx
PATCH v9 2/2 usb: typec: ucsi: add support for Cypress CCGx
Hi Peter,
Quoted 32 lines
Quoted 9 lines
Quoted 9 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+ memcpy(buf1, ((const void *)uc->ppm.data) + 0x20, sizeof(buf1)); + memcpy(buf2, ((const void *)uc->ppm.data) + 0x8, sizeof(buf2)); + + status = ccg_write(uc, *(u16 *)buf, buf1, sizeof(buf1));This seems to be endian-dependent. May I suggest that you do as suggested above for
ccg_read, and then somthing like#define
CCGX_I2C_RAB_USCI_DATA_BLOCK(xxx)(0xf000| ((xxx) &<mask>))
Quoted 11 lines
Quoted 10 lines
where you of course use an appropriate value for <mask> (perhaps
0xff, or0xfff, what do I know) and a better name for the field than xxx (perhaps len, what do I know), and then finally dostatus = ccg_write(uc, CCGX_I2C_RAB_USCI_DATA_BLOCK(0x20), ...Also, the
0x20and0x8are repeated and are some magic numbers that really should be given a name or some explanation. They appear to be data lengths, but again, what do I know?I will check on this.
From the below reference, it's
0x8isUSBC_CONTROLwithUSBC_CONTROL_SIZE0x8(64/8)0x20isUSBC_MESSAGE_OUTwithUSBC_MESSAGE_OUT_SIZE0x10(128/8)You could do
#defineUSBC_MESSAGE_OUTCCGX_I2C_RAB_USCI_DATA_BLOCK(0x20)#defineUSBC_MESSAGE_OUT_SIZE(128/8)
etc, so that it becomes
Quoted 4 lines
unsigned char buf1[USBC_MESSAGE_OUT_SIZE]; ... status =
ccg_write(uc, USBC_MESSAGE_OUT, buf1, sizeof(buf1));Which is a whole lot more readable IMHO.
Sure.
Quoted 27 lines
Quoted 20 lines
Quoted 12 lines
Quoted 12 lines
(quoted diff) +12
-0+ if (status < 0) + return status; + + return ccg_write(uc, *(u16 *)(buf + 2), buf2, sizeof(buf2)); } + +static int ucsi_ccg_recv_data(struct ucsi_ccg *uc) { + u8 *ppm = (u8 *)uc->ppm.data; + int status; + unsigned char buf[6] = { + 0x0, CCGX_I2C_RAB_UCSI_DATA_BLOCK >> 8, + 0x4, CCGX_I2C_RAB_UCSI_DATA_BLOCK >> 8, + 0x10, CCGX_I2C_RAB_UCSI_DATA_BLOCK >> 8,Quoted 8 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+ }; + + status = ccg_read(uc, *(u16 *)buf, ppm, 0x2);There are plenty magic numbers, but this call does not follow the pattern. Should perhaps buf[0] be
0x2, or should perhaps the last0x2argument be0x0? All other ...DATA_BLOCK calls seem to have the len in the other byte of the rab argument. Why does this call not follow the pattern?Quoted 3 lines
We are reading message IN data from Type-C controller in response to a UCSI command. You can find details at
https://www.intel.com/content/dam/www/public/us/en/documents/technica
lQuoted 1 line
-specifications/usb-type-c-ucsi-spec.pdf
Quoted 7 lines
So, according to table 3-1,
0x0isUCSI_VERSIONwithUCSI_VERSION_SIZE0x2(16/8)0x4isUSBC_CCI(connector change indication) withUSBC_CCI_SIZE0x4(32/8)0x10isUSBC_MESSAGE_INwithUSBC_MESSAGE_IN_SIZE0x10(128/8)The pattern for
0x4and0x10was a accidental, but again, *please* use defines for all these magic numbers.
Will fix in next version.
Thanks
Ajay
--
nvpublic