Re: [PATCH v1 4/5] usb: typec: Implement alternate mode priority handling

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi again,

On Thu, Aug 21, 2025 at 01:09:57PM +0300, Heikki Krogerus wrote:
> > diff --git a/drivers/usb/typec/mode_selection.c b/drivers/usb/typec/mode_selection.c
> > new file mode 100644
> > index 000000000000..8a54639b86bf
> > --- /dev/null
> > +++ b/drivers/usb/typec/mode_selection.c
> > @@ -0,0 +1,127 @@
> > +// SPDX-License-Identifier: GPL-2.0-only
> > +/*
> > + * Copyright 2025 Google LLC.
> > + */
> > +
> > +#include <linux/usb/typec_altmode.h>
> > +#include <linux/slab.h>
> > +#include <linux/list.h>
> > +#include "mode_selection.h"
> > +#include "class.h"
> > +
> > +static const char * const mode_names[TYPEC_ALTMODE_MAX] = {
> > +	[TYPEC_ALTMODE_DP] = "DisplayPort",
> > +	[TYPEC_ALTMODE_TBT] = "Thunderbolt3",
> > +	[TYPEC_ALTMODE_USB4] = "USB4",
> > +};
> 
> You only need string for USB4. The altmode names come from the drivers.

Sorry, that won't work with port altmode. But you can still do the
lookup with just the sid.

<snip>

> > +/* -------------------------------------------------------------------------- */
> > +/* port 'mode_priorities' attribute */
> > +
> > +int typec_mode_set_priority(struct typec_altmode *adev, const int priority)
> > +{
> > +	struct typec_port *port = to_typec_port(adev->dev.parent);
> > +	const enum typec_mode_type mode = typec_svid_to_altmode(adev->svid);
> > +	struct mode_selection_state *ms_target = NULL;
> > +	struct mode_selection_state *ms, *tmp;
> > +
> > +	if (mode >= TYPEC_ALTMODE_MAX || !mode_names[mode])
> > +		return -EOPNOTSUPP;
> 
> Just support every altmode bind to a driver and USB4. USB4 you
> identify with a specific usb4 device type.

No driver so you would need to use the mode_names, but instead of
doing that, just don't limit this at all.

If there is no name for the mode, use the svid.

thanks,

-- 
heikki




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux