Re: 回复: [PATCH] spi: disable chipselect after complete transfer

From: Yun Zhou
Date: Thu Feb 10 2022 - 12:01:45 EST


Hi Brown,

If there are multiple messages, and each message only has one xfer,
and the cs_change of each xfer is 1, during the transmission of the
messages, the CS will keep active even until at the end. This must be
unreasonable.
This is not something that most drivers are expected to use, cs_change
should only be being used at all for very unusual hardware and it should
be used even less frequently for the last transfer in a message. It is
fragile and anyone using it really needs to know what they're doing but
the feature is there.
Maybe it's not normal to set "cs_change" in the last xfer. However, in
most cases, SPI messages come from user space, and these messages may
come from multiple different applications. We can't make the whole
controller fail to work normally due to an inappropriate message of one
application.

I can't understand why it have to keep CS active after the
transmission is completed. Could you please explain this in detail?
The feature predates me working on the SPI stack, the obvious examples
would be a device that doesn't actually use chip select where you want
to avoid all chip select changes or if you need to do some other actions
in the middle of a SPI transaction for some reason (which would need a
bunch of system level considerations to actually be safe/sensible like
making sure you're not sharing the SPI bus).
At present, if "cs_change" is not set, CS will be changed back to inactive
after the transmission is completed. If "cs_change" is set, CS will not
be changed. This obviously violates the definition of "cs_change".

Therefore, I think my patch does not break the support of "cs_change",
but consolidates the support of "cs_change". It also ensures that the whole
SPI controller will not be abnormal due to a message from userspace.

Regards,

Yun