* [2/8] usb: typec: Rationalize the API for the muxes
@ 2019-01-25 13:15 Heikki Krogerus
0 siblings, 0 replies; 3+ messages in thread
From: Heikki Krogerus @ 2019-01-25 13:15 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Chen Yu, Jun Li, Hans de Goede, linux-usb, linux-kernel
We can replace the second parameter that is passed to the
typec_mux_get() function with alt mode description
structure, and simply pass NULL with accessory modes.
With accessory modes there is no need for additional
identification (in practice the accessory mode can only be
Audio Accessory if muxing is needed), only with alternate
modes we need to identify the exact alternate mode.
Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
---
drivers/usb/typec/class.c | 7 ++-----
drivers/usb/typec/mux.c | 8 +++++---
include/linux/usb/typec_mux.h | 3 ++-
3 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
index 5db0593ca0bd..f50278dbef59 100644
--- a/drivers/usb/typec/class.c
+++ b/drivers/usb/typec/class.c
@@ -1496,11 +1496,8 @@ typec_port_register_altmode(struct typec_port *port,
{
struct typec_altmode *adev;
struct typec_mux *mux;
- char id[10];
- sprintf(id, "id%04xm%02x", desc->svid, desc->mode);
-
- mux = typec_mux_get(&port->dev, id);
+ mux = typec_mux_get(&port->dev, desc);
if (IS_ERR(mux))
return ERR_CAST(mux);
@@ -1593,7 +1590,7 @@ struct typec_port *typec_register_port(struct device *parent,
return ERR_CAST(port->sw);
}
- port->mux = typec_mux_get(&port->dev, "typec-mux");
+ port->mux = typec_mux_get(&port->dev, NULL);
if (IS_ERR(port->mux)) {
put_device(&port->dev);
return ERR_CAST(port->mux);
diff --git a/drivers/usb/typec/mux.c b/drivers/usb/typec/mux.c
index d990aa510fab..c7b09cbcd45e 100644
--- a/drivers/usb/typec/mux.c
+++ b/drivers/usb/typec/mux.c
@@ -128,19 +128,21 @@ static void *typec_mux_match(struct device_connection *con, int ep, void *data)
/**
* typec_mux_get - Find USB Type-C Multiplexer
* @dev: The caller device
- * @name: Mux identifier
+ * @desc: Alt Mode description
*
* Finds a mux linked to the caller. This function is primarily meant for the
* Type-C drivers. Returns a reference to the mux on success, NULL if no
* matching connection was found, or ERR_PTR(-EPROBE_DEFER) when a connection
* was found but the mux has not been enumerated yet.
*/
-struct typec_mux *typec_mux_get(struct device *dev, const char *name)
+struct typec_mux *typec_mux_get(struct device *dev,
+ const struct typec_altmode_desc *desc)
{
struct typec_mux *mux;
mutex_lock(&mux_lock);
- mux = device_connection_find_match(dev, name, NULL, typec_mux_match);
+ mux = device_connection_find_match(dev, "typec-mux", (void *)desc,
+ typec_mux_match);
if (!IS_ERR_OR_NULL(mux)) {
WARN_ON(!try_module_get(mux->dev->driver->owner));
get_device(mux->dev);
diff --git a/include/linux/usb/typec_mux.h b/include/linux/usb/typec_mux.h
index 79293f630ee1..43f40685e53c 100644
--- a/include/linux/usb/typec_mux.h
+++ b/include/linux/usb/typec_mux.h
@@ -47,7 +47,8 @@ void typec_switch_put(struct typec_switch *sw);
int typec_switch_register(struct typec_switch *sw);
void typec_switch_unregister(struct typec_switch *sw);
-struct typec_mux *typec_mux_get(struct device *dev, const char *name);
+struct typec_mux *
+typec_mux_get(struct device *dev, const struct typec_altmode_desc *desc);
void typec_mux_put(struct typec_mux *mux);
int typec_mux_register(struct typec_mux *mux);
void typec_mux_unregister(struct typec_mux *mux);
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [2/8] usb: typec: Rationalize the API for the muxes
@ 2019-01-28 9:50 Andy Shevchenko
0 siblings, 0 replies; 3+ messages in thread
From: Andy Shevchenko @ 2019-01-28 9:50 UTC (permalink / raw)
To: Heikki Krogerus
Cc: Greg Kroah-Hartman, Chen Yu, Jun Li, Hans de Goede, USB,
Linux Kernel Mailing List
On Fri, Jan 25, 2019 at 3:18 PM Heikki Krogerus
<heikki.krogerus@linux.intel.com> wrote:
>
> We can replace the second parameter that is passed to the
> typec_mux_get() function with alt mode description
> structure, and simply pass NULL with accessory modes.
>
> With accessory modes there is no need for additional
> identification (in practice the accessory mode can only be
> Audio Accessory if muxing is needed), only with alternate
> modes we need to identify the exact alternate mode.
> +struct typec_mux *typec_mux_get(struct device *dev,
> + const struct typec_altmode_desc *desc)
> {
> struct typec_mux *mux;
>
> mutex_lock(&mux_lock);
> - mux = device_connection_find_match(dev, name, NULL, typec_mux_match);
> + mux = device_connection_find_match(dev, "typec-mux", (void *)desc,
> + typec_mux_match);
Not related to this series, but shouldn't
device_connection_find_match() be improved to avoid dropping const
qualifier?
^ permalink raw reply [flat|nested] 3+ messages in thread
* [2/8] usb: typec: Rationalize the API for the muxes
@ 2019-01-28 15:28 Heikki Krogerus
0 siblings, 0 replies; 3+ messages in thread
From: Heikki Krogerus @ 2019-01-28 15:28 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Greg Kroah-Hartman, Chen Yu, Jun Li, Hans de Goede, USB,
Linux Kernel Mailing List
On Mon, Jan 28, 2019 at 11:50:31AM +0200, Andy Shevchenko wrote:
> On Fri, Jan 25, 2019 at 3:18 PM Heikki Krogerus
> <heikki.krogerus@linux.intel.com> wrote:
> >
> > We can replace the second parameter that is passed to the
> > typec_mux_get() function with alt mode description
> > structure, and simply pass NULL with accessory modes.
> >
> > With accessory modes there is no need for additional
> > identification (in practice the accessory mode can only be
> > Audio Accessory if muxing is needed), only with alternate
> > modes we need to identify the exact alternate mode.
>
> > +struct typec_mux *typec_mux_get(struct device *dev,
> > + const struct typec_altmode_desc *desc)
> > {
> > struct typec_mux *mux;
> >
> > mutex_lock(&mux_lock);
> > - mux = device_connection_find_match(dev, name, NULL, typec_mux_match);
> > + mux = device_connection_find_match(dev, "typec-mux", (void *)desc,
> > + typec_mux_match);
>
> Not related to this series, but shouldn't
> device_connection_find_match() be improved to avoid dropping const
> qualifier?
I'll see if we can do that already.
thanks,
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-01-28 15:28 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-01-28 15:28 [2/8] usb: typec: Rationalize the API for the muxes Heikki Krogerus
-- strict thread matches above, loose matches on Subject: below --
2019-01-28 9:50 Andy Shevchenko
2019-01-25 13:15 Heikki Krogerus
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).