Skip to contentSkip to conversation

usb: typec: ucsi: add support for Cypress CCGx

PATCH Superseded Ajay Gupta 1 participant 1 message Sep 11, 2018 USB

v10 of 13 Superseded Latest is v13 →

lore
Share & tools
lore

Ajay Gupta

author
#0 lore raw

PATCH v10 2/2 usb: typec: ucsi: add support for Cypress CCGx

Hi Peter,

Quoted 86 lines
Quoted 37 lines
Quoted 37 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Review

Quoted 7 lines
(quoted diff) +7 -0
+static int ucsi_ccg_send_data(struct ucsi_ccg *uc) {
+	unsigned char buf1[USBC_MSG_OUT_SIZE];
+	unsigned char buf2[USBC_CONTROL_SIZE];
+	int status;
+	u16 rab;
+
+	memcpy(buf1, (u8 *)(uc->ppm.data) +

USBC_MSG_OUT_OFFSET,

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

sizeof(buf1));

Review

Quoted 1 line
(quoted diff) +1 -0
+	memcpy(buf2, (u8 *)(uc->ppm.data) +

USBC_CONTROL_OFFSET,

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 1 line

+sizeof(buf2));

Hmm, now that I see what this function does, instead of just seeing a bunch of magic numbers, I wonder why you make copies instead of feeding the correct section of the ppm.data buffer directly to ccg_write, like you do below for recv?

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 1 line

Ok, will fix.

Hmm, now that I see this again, it makes me wonder why you complained about copying the buffer to fix the misunderstanding of the i2c_transfer interface, when you already copy the buffer in the first

place?

Quoted 4 lines
Quoted 4 lines

Copy is indeed not needed. I will fix it in next version. We will have to do copy in ccg_write()if we try to combine two write i2c_msg into one and I want to rather stay with two i2c_msg to avoid

copy.

Quoted 8 lines
Quoted 2 lines

Also master_xfer() will become tricky since rab write for read alsp has to go

first.

You are stuck with the construction of the extended buffer. See my mail in the
1/2 thread.

Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Review

Quoted 1 line
(quoted diff) +1 -0
+	rab =

CCGX_I2C_RAB_UCSI_DATA_BLOCK(USBC_VERSION_OFFSET);

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+	status = ccg_read(uc, rab, (u8 *)(uc->ppm.data) +

USBC_VERSION_OFFSET,

Review

Quoted 1 line
(quoted diff) +1 -0
+			  USBC_VERSION_SIZE);

E.g.
rab = CCGX_I2C_RAB_UCSI_DATA_BLOCK(offsetof(struct

ucsi_data,

Quoted 21 lines
Quoted 21 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
version));
	status = ccg_read(uc, rab, (u8 *)&uc->ppm.data->version,
			  sizeof(uc->ppm.data->version));
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 4 lines

Hmm, but this highlights that you are not doing any endian conversion of the fields in that struct as you read/write it.

Do you need to in case you have an endian mismatch?

Looks like don't need it. I have tested it and it works as is.

Yeah, but have you tested the driver on a machine with the other byte-

sex?

Quoted 8 lines
Quoted 1 line

No, I think better to convert to desired endian.

The device has a specific endianess. The host cpu has a specific endianess. You transfer data byte-by-byte to/from a struct that appears to have multi- byte integers, e.g. the 16-bit version. You do not do any conversion that I see and you report that it works. So, there are two cases. Either

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

1. your host cpu and the device has the same endianess, and it all just works by accident

or

2. whatever is consuming the ppm data does the endian conversion for

you

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

on "the other side", and it all just works by design.

I have no idea which it is since I know nothing about whatever handles the ppm data on the other side of that ucsi_register_ppm call. So,

I asked.

Quoted 5 lines
Quoted 5 lines

UCSI specification requires the ppm data to be in little-endian format.

Below is from the UCSI specification.
"All multiple byte fields in this specification are interpreted as and moved over the bus in little-endian order, i.e., LSB to MSB unless

otherwise specified"

Quoted 1 line
Quoted 7 lines
Quoted 3 lines

Do we still need any conversion here? The ppm data is now directly fed for read and write both and rab should be in little endian as per macro.
#define CCGX_RAB_UCSI_DATA_BLOCK(offset) (0xf000 | ((offset) & 0xff))

What do you mean by "in little endian as per macro"? Should not the non-offset 0xf0 byte of CCGX_RAB_UCSI_DATA_BLOCK be in the other byte of rab

Shouldn't it be always in bits D[8:15] of rab so that it gets written to buf[1] (2nd byte) in ccg_read/write() ?

Quoted 4 lines

compared to e.g. the 0x06 byte of CCGX_RAB_INTR_REG?

I assumed *all* CCGX_RAB_... defines to be in cpu-native endian. Are they not?

How to know/confirm this?

Thanks
Ajay

--nvpublic

Quoted 9 lines

In case they are, I think that no further conversion is needed. You feed rab to ccg_read/ccg_write as cpu-native, and ccg_read/ccg_write then converts to little-endian (with put_unaligned_le16).

And it's actually crucial that rab is cpu-native when ccg_read performs arithmetic on it, otherwise the result can turn out to be garbage...

Cheers,
Peter