mbox series

[0/4] usb: typec: add drivers for TUSB320xA and TS5USBA224

Message ID 20220301132010.115258-1-alvin@pqrs.dk
Headers show
Series usb: typec: add drivers for TUSB320xA and TS5USBA224 | expand

Message

Alvin Šipraga March 1, 2022, 1:20 p.m. UTC
From: Alvin Šipraga <alsi@bang-olufsen.dk>

This series adds a new typec class driver for the TUSB320xA family of
Type-C port controllers and a typec_mux class driver for the TS5USBA224
switch mux.

This series was bourne out of frustration with the existing extcon
driver for the TUSB320, which did not offer a convenient driver model
for the Audio Accessory mode muxing offered by the TS5USBA224. I found
the typec subsystem to be more suitable.

I have tested this on my i.MX8MM platform with USB OTG support and it
works as desired. However I am not very familiar with this part of the
kernel, so I welcome your critical feedback to this series. Thanks in
advance.


Alvin Šipraga (4):
  dt-bindings: usb: add TUSB320xA Type-C port controller
  dt-bindings: usb: add TS5USBA224 USB/Audio switch mux
  usb: typec: add TUSB320xA driver
  usb: typec: mux: add TS5USBA224 driver

 .../bindings/usb/ti,ts5usba224.yaml           |  56 ++
 .../devicetree/bindings/usb/ti,tusb320xa.yaml |  78 +++
 drivers/usb/typec/Kconfig                     |  12 +
 drivers/usb/typec/Makefile                    |   1 +
 drivers/usb/typec/mux/Kconfig                 |  10 +
 drivers/usb/typec/mux/Makefile                |   1 +
 drivers/usb/typec/mux/ts5usba224.c            | 102 ++++
 drivers/usb/typec/tusb320xa.c                 | 517 ++++++++++++++++++
 8 files changed, 777 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/ti,ts5usba224.yaml
 create mode 100644 Documentation/devicetree/bindings/usb/ti,tusb320xa.yaml
 create mode 100644 drivers/usb/typec/mux/ts5usba224.c
 create mode 100644 drivers/usb/typec/tusb320xa.c

Comments

Heikki Krogerus March 8, 2022, 11:49 a.m. UTC | #1
On Mon, Mar 07, 2022 at 10:17:04PM +0000, Alvin Šipraga wrote:
> Hi Heikki,
> 
> Heikki Krogerus <heikki.krogerus@linux.intel.com> writes:
> 
> > Hi,
> >
> > On Tue, Mar 01, 2022 at 02:20:07PM +0100, Alvin Šipraga wrote:
> >> From: Alvin Šipraga <alsi@bang-olufsen.dk>
> >> 
> >> The TUSB320LA and TUSB320HA (or LAI, HAI) chips are I2C controlled
> >> non-PD Type-C port controllers. They support detection of cable
> >> orientation, port attachment state, and role, including Audio Accessory
> >> and Debug Accessory modes. Add a typec class driver for this family.
> >> 
> >> Note that there already exists an extcon driver for the TUSB320 (a
> >> slightly older revision that does not support setting role preference or
> >> disabling the CC state machine). This driver is loosely based on that
> >> one.
> >
> > This looked mostly OK to me. There is one question below.
> >
> > <snip>
> >
> >> +static int tusb320xa_check_signature(struct tusb320xa *tusb)
> >> +{
> >> +	static const char sig[] = { '\0', 'T', 'U', 'S', 'B', '3', '2', '0' };
> >> +	unsigned int val;
> >> +	int i, ret;
> >> +
> >> +	mutex_lock(&tusb->lock);
> >> +
> >> +	for (i = 0; i < sizeof(sig); i++) {
> >> +		ret = regmap_read(tusb->regmap, sizeof(sig) - 1 - i, &val);
> >> +		if (ret)
> >> +			goto done;
> >> +
> >> +		if (val != sig[i]) {
> >> +			dev_err(tusb->dev, "signature mismatch!\n");
> >> +			ret = -ENODEV;
> >> +			goto done;
> >> +		}
> >> +	}
> >> +
> >> +done:
> >> +	mutex_unlock(&tusb->lock);
> >> +
> >> +	return ret;
> >> +}
> >
> > Couldn't that be done with a single read?
> >
> >         char sig[8];
> >         u64 val;
> >
> >         strcpy(sig, "TUSB320")
> >
> >         mutex_lock(&tusb->lock);
> >
> >         ret = regmap_raw_read(tusb->regmap, 0, &val, sizeof(val));
> >         ...
> >         if (val != cpu_to_le64(*(u64 *)sig)) {
> >         ...
> >
> > Something like that?
> 
> I think it's a bit cryptic - are you sure it's worth it just to save 8
> one-off regmap_read()s? I could also just remove this check... I see it
> mostly as a courtesy to the user in case the I2C address in his device
> tree mistakenly points to some other unsuspecting chip.
> 
> BTW, do you have any feedback on the device tree bindings of this
> series? Rob had some questions and I am not sure that my proposed
> bindings are fully aligned with the typec subsystem expectations. Any
> feedback would be welcome.

I don't think I understand DT well enough to comment. I'm not
completely sure what he's asking..

> I will wait for more comments and send a v2 in ~a week.

thanks,
Alvin Šipraga March 8, 2022, 12:30 p.m. UTC | #2
Heikki Krogerus <heikki.krogerus@linux.intel.com> writes:

> On Mon, Mar 07, 2022 at 10:17:04PM +0000, Alvin Šipraga wrote:
>> Hi Heikki,
>> 
>> Heikki Krogerus <heikki.krogerus@linux.intel.com> writes:
>> 
>> > Hi,
>> >
>> > On Tue, Mar 01, 2022 at 02:20:07PM +0100, Alvin Šipraga wrote:
>> >> From: Alvin Šipraga <alsi@bang-olufsen.dk>
>> >> 
>> >> The TUSB320LA and TUSB320HA (or LAI, HAI) chips are I2C controlled
>> >> non-PD Type-C port controllers. They support detection of cable
>> >> orientation, port attachment state, and role, including Audio Accessory
>> >> and Debug Accessory modes. Add a typec class driver for this family.
>> >> 
>> >> Note that there already exists an extcon driver for the TUSB320 (a
>> >> slightly older revision that does not support setting role preference or
>> >> disabling the CC state machine). This driver is loosely based on that
>> >> one.
>> >
>> > This looked mostly OK to me. There is one question below.
>> >
>> > <snip>
>> >
>> >> +static int tusb320xa_check_signature(struct tusb320xa *tusb)
>> >> +{
>> >> +	static const char sig[] = { '\0', 'T', 'U', 'S', 'B', '3', '2', '0' };
>> >> +	unsigned int val;
>> >> +	int i, ret;
>> >> +
>> >> +	mutex_lock(&tusb->lock);
>> >> +
>> >> +	for (i = 0; i < sizeof(sig); i++) {
>> >> +		ret = regmap_read(tusb->regmap, sizeof(sig) - 1 - i, &val);
>> >> +		if (ret)
>> >> +			goto done;
>> >> +
>> >> +		if (val != sig[i]) {
>> >> +			dev_err(tusb->dev, "signature mismatch!\n");
>> >> +			ret = -ENODEV;
>> >> +			goto done;
>> >> +		}
>> >> +	}
>> >> +
>> >> +done:
>> >> +	mutex_unlock(&tusb->lock);
>> >> +
>> >> +	return ret;
>> >> +}
>> >
>> > Couldn't that be done with a single read?
>> >
>> >         char sig[8];
>> >         u64 val;
>> >
>> >         strcpy(sig, "TUSB320")
>> >
>> >         mutex_lock(&tusb->lock);
>> >
>> >         ret = regmap_raw_read(tusb->regmap, 0, &val, sizeof(val));
>> >         ...
>> >         if (val != cpu_to_le64(*(u64 *)sig)) {
>> >         ...
>> >
>> > Something like that?
>> 
>> I think it's a bit cryptic - are you sure it's worth it just to save 8
>> one-off regmap_read()s? I could also just remove this check... I see it
>> mostly as a courtesy to the user in case the I2C address in his device
>> tree mistakenly points to some other unsuspecting chip.
>> 
>> BTW, do you have any feedback on the device tree bindings of this
>> series? Rob had some questions and I am not sure that my proposed
>> bindings are fully aligned with the typec subsystem expectations. Any
>> feedback would be welcome.
>
> I don't think I understand DT well enough to comment. I'm not
> completely sure what he's asking..

OK, no problem! Thanks for your reply.

Kind regards,
Alvin

>
>> I will wait for more comments and send a v2 in ~a week.
>
> thanks,