Re: [PATCH v1 4/4] usb: typec: maxim_contaminant: Implement check_contaminant callback

From: Guenter Roeck
Date: Tue Aug 30 2022 - 13:58:12 EST


On Fri, Aug 26, 2022 at 01:40:01AM -0700, Badhri Jagan Sridharan wrote:
> Maxim TCPC has additional ADCs and low current(1ua) current source
> to measure the impedance of CC and SBU pins. When tcpm invokes
> the check_contaminant callback, Maxim TCPC measures the impedance
> of the CC & SBU pins and when the impedance measured is less than
> 1MOhm, it is assumed that USB-C port is contaminated. CC comparators
> are also checked to differentiate between presence of sink and
> contaminant. Once USB-C is deemed to be contaminated, MAXIM TCPC
> has additional hardware to disable normal DRP toggling cycle and
> enable 1ua on CC pins once every 2.4secs/4.8secs. Maxim TCPC
> interrupts AP once the impedance on the CC pin is above the
> 1MOhm threshold. The Maxim tcpc driver then signals TCPM_PORT_CLEAN
> to restart toggling.
>
> Signed-off-by: Badhri Jagan Sridharan <badhri@xxxxxxxxxx>
> ---
> drivers/usb/typec/tcpm/Makefile | 2 +-
> drivers/usb/typec/tcpm/maxim_contaminant.c | 338 +++++++++++++++++++++
> drivers/usb/typec/tcpm/tcpci_maxim.c | 34 ++-
> drivers/usb/typec/tcpm/tcpci_maxim.h | 68 +++++
> 4 files changed, 429 insertions(+), 13 deletions(-)
> create mode 100644 drivers/usb/typec/tcpm/maxim_contaminant.c
> create mode 100644 drivers/usb/typec/tcpm/tcpci_maxim.h
>
> diff --git a/drivers/usb/typec/tcpm/Makefile b/drivers/usb/typec/tcpm/Makefile
> index 906d9dced8e7..81e4e9421fa0 100644
> --- a/drivers/usb/typec/tcpm/Makefile
> +++ b/drivers/usb/typec/tcpm/Makefile
> @@ -7,4 +7,4 @@ obj-$(CONFIG_TYPEC_TCPCI) += tcpci.o
> obj-$(CONFIG_TYPEC_RT1711H) += tcpci_rt1711h.o
> obj-$(CONFIG_TYPEC_MT6360) += tcpci_mt6360.o
> obj-$(CONFIG_TYPEC_TCPCI_MT6370) += tcpci_mt6370.o
> -obj-$(CONFIG_TYPEC_TCPCI_MAXIM) += tcpci_maxim.o
> +obj-$(CONFIG_TYPEC_TCPCI_MAXIM) += tcpci_maxim.o maxim_contaminant.o

This creates two separate modules, which doesn't really add any value.
I would suggest to adjust the file names and create a single module
named tcpci_maxim instead. Renaming tcpci_maxim.c to, say,
tcpci_maxim_core.c and

obj-$(CONFIG_TYPEC_TCPCI_MAXIM) += tcpci_maxim.o
tcpci_maxim-y := tcpci_maxim_core.o maxim_contaminant.o

should do. This would also avoid the need for exporting symbols
from tcpci_maxim.c.

Thanks,
Guenter