Linux-USB Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v2 0/3] usb: typec: Add typec_port_register_altmodes_from_fwnode()
@ 2021-04-08 20:31 Hans de Goede
  2021-04-08 20:31 ` [PATCH v2 1/3] " Hans de Goede
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Hans de Goede @ 2021-04-08 20:31 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Guenter Roeck, Heikki Krogerus
  Cc: Hans de Goede, Rob Herring, Zhen Lei, linux-usb

Hi All,

Here is v2 of my series to actually make it possible to use alt-modes
on tcpm managed Type-C ports. Sorry that it took so long.

Note this v2 series deliberately does not include devicetree bindings
documentation, as requested by Rob. ATM the fwnodes used to register
the altmodes are only used internally to pass platform info from a
drivers/platform/x86 driver to the type-c subsystem.

When a devicetree user of this functionally comes up and the dt-bindings
have been hashed out the internal use can be adjusted to match the
dt-bindings.

Changes in v2:
- Drop the DT bindings doc, as requested by Rob
- Drop unnecessary fwnode parameter from
  typec_port_register_altmodes_from_fwnode()

Greg, assuming there are no objections to merging this, then you hereby
have my ack for also taking the platform/x86/intel_cht_int33fe change
upstream through the USB tree.

Regards,

Hans



Hans de Goede (3):
  usb: typec: Add typec_port_register_altmodes_from_fwnode()
  usb: typec: tcpm: Add support for altmodes
  platform/x86/intel_cht_int33fe: Add displayport altmode fwnode to the
    connector fwnode

 .../platform/x86/intel_cht_int33fe_typec.c    | 19 +++++++
 drivers/usb/typec/class.c                     | 55 +++++++++++++++++++
 drivers/usb/typec/tcpm/tcpm.c                 |  5 ++
 include/linux/usb/typec.h                     |  6 ++
 4 files changed, 85 insertions(+)

-- 
2.30.2


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v2 1/3] usb: typec: Add typec_port_register_altmodes_from_fwnode()
  2021-04-08 20:31 [PATCH v2 0/3] usb: typec: Add typec_port_register_altmodes_from_fwnode() Hans de Goede
@ 2021-04-08 20:31 ` Hans de Goede
  2021-04-09 10:54   ` Heikki Krogerus
  2021-04-08 20:31 ` [PATCH v2 2/3] usb: typec: tcpm: Add support for altmodes Hans de Goede
  2021-04-08 20:31 ` [PATCH v2 3/3] platform/x86/intel_cht_int33fe: Add displayport altmode fwnode to the connector fwnode Hans de Goede
  2 siblings, 1 reply; 10+ messages in thread
From: Hans de Goede @ 2021-04-08 20:31 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Guenter Roeck, Heikki Krogerus
  Cc: Hans de Goede, Rob Herring, Zhen Lei, linux-usb

This can be used by Type-C controller drivers which use a standard
usb-connector fwnode, with altmodes sub-node, to describe the available
altmodes.

Note there are is no devicetree bindings documentation for the altmodes
node, this is deliberate. ATM the fwnodes used to register the altmodes
are only used internally to pass platform info from a drivers/platform/x86
driver to the type-c subsystem.

When a devicetree user of this functionally comes up and the dt-bindings
have been hashed out the internal use can be adjusted to match the
dt-bindings.

Currently the typec_port_register_altmodes_from_fwnode() function expects
an "altmodes" child fwnode on port->dev with this "altmodes" fwnode having
child fwnodes itself with each child containing 2 integer properties:

1. A "svid" property, which sets the id of the altmode, e.g. displayport
altmode has a svid of 0xff01.

2. A "vdo" property, typically used as a bitmask describing the
capabilities of the altmode, the bits in the vdo are specified in the
specification of the altmode.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
Changes in v2:
- Drop the unnecessary fwnode parameter from
  typec_port_register_altmodes_from_fwnode()
- Document the expected "altmodes" fwnode in the commit message for now
  as v2 of the patch-set drops the dt-bindings since there are not DT
  users for this yet
---
 drivers/usb/typec/class.c | 55 +++++++++++++++++++++++++++++++++++++++
 include/linux/usb/typec.h |  6 +++++
 2 files changed, 61 insertions(+)

diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
index 45f0bf65e9ab..a82344fe1650 100644
--- a/drivers/usb/typec/class.c
+++ b/drivers/usb/typec/class.c
@@ -1978,6 +1978,61 @@ typec_port_register_altmode(struct typec_port *port,
 }
 EXPORT_SYMBOL_GPL(typec_port_register_altmode);
 
+void typec_port_register_altmodes_from_fwnode(struct typec_port *port,
+	const struct typec_altmode_ops *ops, void *drvdata,
+	struct typec_altmode **altmodes, size_t n)
+{
+	struct fwnode_handle *altmodes_node, *child;
+	struct typec_altmode_desc desc;
+	struct typec_altmode *alt;
+	size_t index = 0;
+	u32 svid, vdo;
+	int ret;
+
+	altmodes_node = device_get_named_child_node(&port->dev, "altmodes");
+	if (!altmodes_node)
+		return; /* No altmodes specified */
+
+	child = NULL;
+	while ((child = fwnode_get_next_child_node(altmodes_node, child))) {
+		ret = fwnode_property_read_u32(child, "svid", &svid);
+		if (ret) {
+			dev_err(&port->dev, "Error reading svid for altmode %s\n",
+				fwnode_get_name(child));
+			continue;
+		}
+
+		ret = fwnode_property_read_u32(child, "vdo", &vdo);
+		if (ret) {
+			dev_err(&port->dev, "Error reading vdo for altmode %s\n",
+				fwnode_get_name(child));
+			continue;
+		}
+
+		if (index >= n) {
+			dev_err(&port->dev, "Error not enough space for altmode %s\n",
+				fwnode_get_name(child));
+			continue;
+		}
+
+		desc.svid = svid;
+		desc.vdo = vdo;
+		desc.mode = index + 1;
+		alt = typec_port_register_altmode(port, &desc);
+		if (IS_ERR(alt)) {
+			dev_err(&port->dev, "Error registering altmode %s\n",
+				fwnode_get_name(child));
+			continue;
+		}
+
+		alt->ops = ops;
+		typec_altmode_set_drvdata(alt, drvdata);
+		altmodes[index] = alt;
+		index++;
+	}
+}
+EXPORT_SYMBOL_GPL(typec_port_register_altmodes_from_fwnode);
+
 /**
  * typec_register_port - Register a USB Type-C Port
  * @parent: Parent device
diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h
index 91b4303ca305..75d54558f962 100644
--- a/include/linux/usb/typec.h
+++ b/include/linux/usb/typec.h
@@ -17,6 +17,7 @@ struct typec_partner;
 struct typec_cable;
 struct typec_plug;
 struct typec_port;
+struct typec_altmode_ops;
 
 struct fwnode_handle;
 struct device;
@@ -138,6 +139,11 @@ struct typec_altmode
 struct typec_altmode
 *typec_port_register_altmode(struct typec_port *port,
 			     const struct typec_altmode_desc *desc);
+
+void typec_port_register_altmodes_from_fwnode(struct typec_port *port,
+	const struct typec_altmode_ops *ops, void *drvdata,
+	struct typec_altmode **altmodes, size_t n);
+
 void typec_unregister_altmode(struct typec_altmode *altmode);
 
 struct typec_port *typec_altmode2port(struct typec_altmode *alt);
-- 
2.30.2


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v2 2/3] usb: typec: tcpm: Add support for altmodes
  2021-04-08 20:31 [PATCH v2 0/3] usb: typec: Add typec_port_register_altmodes_from_fwnode() Hans de Goede
  2021-04-08 20:31 ` [PATCH v2 1/3] " Hans de Goede
@ 2021-04-08 20:31 ` Hans de Goede
  2021-04-08 20:31 ` [PATCH v2 3/3] platform/x86/intel_cht_int33fe: Add displayport altmode fwnode to the connector fwnode Hans de Goede
  2 siblings, 0 replies; 10+ messages in thread
From: Hans de Goede @ 2021-04-08 20:31 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Guenter Roeck, Heikki Krogerus
  Cc: Hans de Goede, Rob Herring, Zhen Lei, linux-usb

Add support for altmodes described in the usb-connector fwnode
associated with the Type-C controller by calling the new
typec_port_register_altmodes_from_fwnode() helper for this.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/usb/typec/tcpm/tcpm.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
index ce7af398c7c1..4aec8441772c 100644
--- a/drivers/usb/typec/tcpm/tcpm.c
+++ b/drivers/usb/typec/tcpm/tcpm.c
@@ -6072,6 +6072,11 @@ struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc)
 		goto out_role_sw_put;
 	}
 
+	typec_port_register_altmodes_from_fwnode(port->typec_port,
+						 &tcpm_altmode_ops, port,
+						 port->port_altmode,
+						 ALTMODE_DISCOVERY_MAX);
+
 	mutex_lock(&port->lock);
 	tcpm_init(port);
 	mutex_unlock(&port->lock);
-- 
2.30.2


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v2 3/3] platform/x86/intel_cht_int33fe: Add displayport altmode fwnode to the connector fwnode
  2021-04-08 20:31 [PATCH v2 0/3] usb: typec: Add typec_port_register_altmodes_from_fwnode() Hans de Goede
  2021-04-08 20:31 ` [PATCH v2 1/3] " Hans de Goede
  2021-04-08 20:31 ` [PATCH v2 2/3] usb: typec: tcpm: Add support for altmodes Hans de Goede
@ 2021-04-08 20:31 ` Hans de Goede
  2 siblings, 0 replies; 10+ messages in thread
From: Hans de Goede @ 2021-04-08 20:31 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Guenter Roeck, Heikki Krogerus
  Cc: Hans de Goede, Rob Herring, Zhen Lei, linux-usb

Add a displayport altmode fwnode to the usb-connector fwnode,
devices which use this driver support display-port altmode through
the PI3USB30532 USB switch, this enables support for this.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 .../platform/x86/intel_cht_int33fe_typec.c    | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/drivers/platform/x86/intel_cht_int33fe_typec.c b/drivers/platform/x86/intel_cht_int33fe_typec.c
index 48638d1c56e5..b61bad9cc8d2 100644
--- a/drivers/platform/x86/intel_cht_int33fe_typec.c
+++ b/drivers/platform/x86/intel_cht_int33fe_typec.c
@@ -124,12 +124,31 @@ static const struct software_node usb_connector_node = {
 	.properties = usb_connector_properties,
 };
 
+static const struct software_node altmodes_node = {
+	.name = "altmodes",
+	.parent = &usb_connector_node,
+};
+
+static const struct property_entry dp_altmode_properties[] = {
+	PROPERTY_ENTRY_U32("svid", 0xff01),
+	PROPERTY_ENTRY_U32("vdo", 0x0c0086),
+	{ }
+};
+
+static const struct software_node dp_altmode_node = {
+	.name = "displayport-altmode",
+	.parent = &altmodes_node,
+	.properties = dp_altmode_properties,
+};
+
 static const struct software_node *node_group[] = {
 	&fusb302_node,
 	&max17047_node,
 	&pi3usb30532_node,
 	&displayport_node,
 	&usb_connector_node,
+	&altmodes_node,
+	&dp_altmode_node,
 	NULL
 };
 
-- 
2.30.2


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 1/3] usb: typec: Add typec_port_register_altmodes_from_fwnode()
  2021-04-08 20:31 ` [PATCH v2 1/3] " Hans de Goede
@ 2021-04-09 10:54   ` Heikki Krogerus
  2021-04-09 12:49     ` Hans de Goede
  0 siblings, 1 reply; 10+ messages in thread
From: Heikki Krogerus @ 2021-04-09 10:54 UTC (permalink / raw)
  To: Hans de Goede
  Cc: Greg Kroah-Hartman, Guenter Roeck, Rob Herring, Zhen Lei, linux-usb

Hi Hans,

On Thu, Apr 08, 2021 at 10:31:27PM +0200, Hans de Goede wrote:
> This can be used by Type-C controller drivers which use a standard
> usb-connector fwnode, with altmodes sub-node, to describe the available
> altmodes.
> 
> Note there are is no devicetree bindings documentation for the altmodes
> node, this is deliberate. ATM the fwnodes used to register the altmodes
> are only used internally to pass platform info from a drivers/platform/x86
> driver to the type-c subsystem.
> 
> When a devicetree user of this functionally comes up and the dt-bindings
> have been hashed out the internal use can be adjusted to match the
> dt-bindings.
> 
> Currently the typec_port_register_altmodes_from_fwnode() function expects
> an "altmodes" child fwnode on port->dev with this "altmodes" fwnode having
> child fwnodes itself with each child containing 2 integer properties:
> 
> 1. A "svid" property, which sets the id of the altmode, e.g. displayport
> altmode has a svid of 0xff01.
> 
> 2. A "vdo" property, typically used as a bitmask describing the
> capabilities of the altmode, the bits in the vdo are specified in the
> specification of the altmode.
> 
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
> Changes in v2:
> - Drop the unnecessary fwnode parameter from
>   typec_port_register_altmodes_from_fwnode()
> - Document the expected "altmodes" fwnode in the commit message for now
>   as v2 of the patch-set drops the dt-bindings since there are not DT
>   users for this yet
> ---
>  drivers/usb/typec/class.c | 55 +++++++++++++++++++++++++++++++++++++++
>  include/linux/usb/typec.h |  6 +++++
>  2 files changed, 61 insertions(+)
> 
> diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
> index 45f0bf65e9ab..a82344fe1650 100644
> --- a/drivers/usb/typec/class.c
> +++ b/drivers/usb/typec/class.c
> @@ -1978,6 +1978,61 @@ typec_port_register_altmode(struct typec_port *port,
>  }
>  EXPORT_SYMBOL_GPL(typec_port_register_altmode);
>  
> +void typec_port_register_altmodes_from_fwnode(struct typec_port *port,
> +	const struct typec_altmode_ops *ops, void *drvdata,
> +	struct typec_altmode **altmodes, size_t n)

Couldn't we just call this typec_port_register_altmodes()?

> +{
> +	struct fwnode_handle *altmodes_node, *child;
> +	struct typec_altmode_desc desc;
> +	struct typec_altmode *alt;
> +	size_t index = 0;
> +	u32 svid, vdo;
> +	int ret;
> +
> +	altmodes_node = device_get_named_child_node(&port->dev, "altmodes");
> +	if (!altmodes_node)
> +		return; /* No altmodes specified */
> +
> +	child = NULL;
> +	while ((child = fwnode_get_next_child_node(altmodes_node, child))) {

fwnode_for_each_child_node()?

> +		ret = fwnode_property_read_u32(child, "svid", &svid);
> +		if (ret) {
> +			dev_err(&port->dev, "Error reading svid for altmode %s\n",
> +				fwnode_get_name(child));
> +			continue;
> +		}
> +
> +		ret = fwnode_property_read_u32(child, "vdo", &vdo);
> +		if (ret) {
> +			dev_err(&port->dev, "Error reading vdo for altmode %s\n",
> +				fwnode_get_name(child));
> +			continue;
> +		}
> +
> +		if (index >= n) {
> +			dev_err(&port->dev, "Error not enough space for altmode %s\n",
> +				fwnode_get_name(child));
> +			continue;
> +		}
> +
> +		desc.svid = svid;
> +		desc.vdo = vdo;
> +		desc.mode = index + 1;
> +		alt = typec_port_register_altmode(port, &desc);
> +		if (IS_ERR(alt)) {
> +			dev_err(&port->dev, "Error registering altmode %s\n",
> +				fwnode_get_name(child));
> +			continue;
> +		}
> +
> +		alt->ops = ops;
> +		typec_altmode_set_drvdata(alt, drvdata);
> +		altmodes[index] = alt;
> +		index++;
> +	}
> +}
> +EXPORT_SYMBOL_GPL(typec_port_register_altmodes_from_fwnode);

This is OK by me, but I've been wondering if it would be more clear to
just have a function fwnode_for_each_altmode() (I don't know if the
name is good enough).

int fwnode_for_each_altmode(struct fwnode_handle *fwnode,
                            int (*fn)(struct typec_altmode_desc *, void *),
                            void *data)
{
        struct fwnode_handle *altmodes_node, *child;
        struct typec_altmode_desc desc;
	u32 svid, vdo;
	int ret;

	altmodes_node = fwnode_get_named_child_node(fwnode, "altmodes");
	if (!altmodes_node)
		return 0; /* No altmodes specified */

        fwnode_for_each_child_node(altmodes_node, child) {
                ...
                /* read the properties */
                ...

		desc.svid = svid;
		desc.vdo = vdo;
		desc.mode = index + 1;

                /* We need to add this member to struct typec_altmode_desc! */
                desc.fwnode = client;

                ret = fn(&desc, data);
                if (ret)
                        return ret;
        }

        return 0;
}

Something like that. It would leave the registration of the alternate
modes to the drivers, which I think would actually be better.

If there ever is need, this can be also used for other things besides
mode registration.

What do you think?

Br,

-- 
heikki

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 1/3] usb: typec: Add typec_port_register_altmodes_from_fwnode()
  2021-04-09 10:54   ` Heikki Krogerus
@ 2021-04-09 12:49     ` Hans de Goede
  2021-04-09 13:06       ` Heikki Krogerus
  0 siblings, 1 reply; 10+ messages in thread
From: Hans de Goede @ 2021-04-09 12:49 UTC (permalink / raw)
  To: Heikki Krogerus
  Cc: Greg Kroah-Hartman, Guenter Roeck, Rob Herring, Zhen Lei, linux-usb

Hi,

On 4/9/21 12:54 PM, Heikki Krogerus wrote:
> Hi Hans,
> 
> On Thu, Apr 08, 2021 at 10:31:27PM +0200, Hans de Goede wrote:
>> This can be used by Type-C controller drivers which use a standard
>> usb-connector fwnode, with altmodes sub-node, to describe the available
>> altmodes.
>>
>> Note there are is no devicetree bindings documentation for the altmodes
>> node, this is deliberate. ATM the fwnodes used to register the altmodes
>> are only used internally to pass platform info from a drivers/platform/x86
>> driver to the type-c subsystem.
>>
>> When a devicetree user of this functionally comes up and the dt-bindings
>> have been hashed out the internal use can be adjusted to match the
>> dt-bindings.
>>
>> Currently the typec_port_register_altmodes_from_fwnode() function expects
>> an "altmodes" child fwnode on port->dev with this "altmodes" fwnode having
>> child fwnodes itself with each child containing 2 integer properties:
>>
>> 1. A "svid" property, which sets the id of the altmode, e.g. displayport
>> altmode has a svid of 0xff01.
>>
>> 2. A "vdo" property, typically used as a bitmask describing the
>> capabilities of the altmode, the bits in the vdo are specified in the
>> specification of the altmode.
>>
>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>> ---
>> Changes in v2:
>> - Drop the unnecessary fwnode parameter from
>>   typec_port_register_altmodes_from_fwnode()
>> - Document the expected "altmodes" fwnode in the commit message for now
>>   as v2 of the patch-set drops the dt-bindings since there are not DT
>>   users for this yet
>> ---
>>  drivers/usb/typec/class.c | 55 +++++++++++++++++++++++++++++++++++++++
>>  include/linux/usb/typec.h |  6 +++++
>>  2 files changed, 61 insertions(+)
>>
>> diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
>> index 45f0bf65e9ab..a82344fe1650 100644
>> --- a/drivers/usb/typec/class.c
>> +++ b/drivers/usb/typec/class.c
>> @@ -1978,6 +1978,61 @@ typec_port_register_altmode(struct typec_port *port,
>>  }
>>  EXPORT_SYMBOL_GPL(typec_port_register_altmode);
>>  
>> +void typec_port_register_altmodes_from_fwnode(struct typec_port *port,
>> +	const struct typec_altmode_ops *ops, void *drvdata,
>> +	struct typec_altmode **altmodes, size_t n)
> 
> Couldn't we just call this typec_port_register_altmodes()?

Ack, will fix for v3.

>> +{
>> +	struct fwnode_handle *altmodes_node, *child;
>> +	struct typec_altmode_desc desc;
>> +	struct typec_altmode *alt;
>> +	size_t index = 0;
>> +	u32 svid, vdo;
>> +	int ret;
>> +
>> +	altmodes_node = device_get_named_child_node(&port->dev, "altmodes");
>> +	if (!altmodes_node)
>> +		return; /* No altmodes specified */
>> +
>> +	child = NULL;
>> +	while ((child = fwnode_get_next_child_node(altmodes_node, child))) {
> 
> fwnode_for_each_child_node()?

Ack, will fix for v3.

> 
>> +		ret = fwnode_property_read_u32(child, "svid", &svid);
>> +		if (ret) {
>> +			dev_err(&port->dev, "Error reading svid for altmode %s\n",
>> +				fwnode_get_name(child));
>> +			continue;
>> +		}
>> +
>> +		ret = fwnode_property_read_u32(child, "vdo", &vdo);
>> +		if (ret) {
>> +			dev_err(&port->dev, "Error reading vdo for altmode %s\n",
>> +				fwnode_get_name(child));
>> +			continue;
>> +		}
>> +
>> +		if (index >= n) {
>> +			dev_err(&port->dev, "Error not enough space for altmode %s\n",
>> +				fwnode_get_name(child));
>> +			continue;
>> +		}
>> +
>> +		desc.svid = svid;
>> +		desc.vdo = vdo;
>> +		desc.mode = index + 1;
>> +		alt = typec_port_register_altmode(port, &desc);
>> +		if (IS_ERR(alt)) {
>> +			dev_err(&port->dev, "Error registering altmode %s\n",
>> +				fwnode_get_name(child));
>> +			continue;
>> +		}
>> +
>> +		alt->ops = ops;
>> +		typec_altmode_set_drvdata(alt, drvdata);
>> +		altmodes[index] = alt;
>> +		index++;
>> +	}
>> +}
>> +EXPORT_SYMBOL_GPL(typec_port_register_altmodes_from_fwnode);
> 
> This is OK by me, but I've been wondering if it would be more clear to
> just have a function fwnode_for_each_altmode() (I don't know if the
> name is good enough).
> 
> int fwnode_for_each_altmode(struct fwnode_handle *fwnode,
>                             int (*fn)(struct typec_altmode_desc *, void *),
>                             void *data)
> {
>         struct fwnode_handle *altmodes_node, *child;
>         struct typec_altmode_desc desc;
> 	u32 svid, vdo;
> 	int ret;
> 
> 	altmodes_node = fwnode_get_named_child_node(fwnode, "altmodes");
> 	if (!altmodes_node)
> 		return 0; /* No altmodes specified */
> 
>         fwnode_for_each_child_node(altmodes_node, child) {
>                 ...
>                 /* read the properties */
>                 ...
> 
> 		desc.svid = svid;
> 		desc.vdo = vdo;
> 		desc.mode = index + 1;
> 
>                 /* We need to add this member to struct typec_altmode_desc! */
>                 desc.fwnode = client;
> 
>                 ret = fn(&desc, data);
>                 if (ret)
>                         return ret;
>         }
> 
>         return 0;
> }
> 
> Something like that. It would leave the registration of the alternate
> modes to the drivers, which I think would actually be better.
> 
> If there ever is need, this can be also used for other things besides
> mode registration.
> 
> What do you think?

I think adding such a helper might make sense once we actually have
a need for the doing "other things" for all altmodes in a fwnode beside
registering them.

And even then I think it would still make sense to have a
typec_port_register_altmodes() helper for drivers to use, but that
could then be a wrapper around fwnode_for_each_altmode().

Since ATM we have only 1 user for a fwnode_for_each_altmode()
helper adding it now seems premature to me.

But if you have a strong preference for adding it now, then I can
do that for v3.

If you let me know which way you want to go on this, then I'll
prepare a v3.

Regards,

Hans


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 1/3] usb: typec: Add typec_port_register_altmodes_from_fwnode()
  2021-04-09 12:49     ` Hans de Goede
@ 2021-04-09 13:06       ` Heikki Krogerus
  0 siblings, 0 replies; 10+ messages in thread
From: Heikki Krogerus @ 2021-04-09 13:06 UTC (permalink / raw)
  To: Hans de Goede
  Cc: Greg Kroah-Hartman, Guenter Roeck, Rob Herring, Zhen Lei, linux-usb

On Fri, Apr 09, 2021 at 02:49:05PM +0200, Hans de Goede wrote:
> Hi,
> 
> On 4/9/21 12:54 PM, Heikki Krogerus wrote:
> > Hi Hans,
> > 
> > On Thu, Apr 08, 2021 at 10:31:27PM +0200, Hans de Goede wrote:
> >> This can be used by Type-C controller drivers which use a standard
> >> usb-connector fwnode, with altmodes sub-node, to describe the available
> >> altmodes.
> >>
> >> Note there are is no devicetree bindings documentation for the altmodes
> >> node, this is deliberate. ATM the fwnodes used to register the altmodes
> >> are only used internally to pass platform info from a drivers/platform/x86
> >> driver to the type-c subsystem.
> >>
> >> When a devicetree user of this functionally comes up and the dt-bindings
> >> have been hashed out the internal use can be adjusted to match the
> >> dt-bindings.
> >>
> >> Currently the typec_port_register_altmodes_from_fwnode() function expects
> >> an "altmodes" child fwnode on port->dev with this "altmodes" fwnode having
> >> child fwnodes itself with each child containing 2 integer properties:
> >>
> >> 1. A "svid" property, which sets the id of the altmode, e.g. displayport
> >> altmode has a svid of 0xff01.
> >>
> >> 2. A "vdo" property, typically used as a bitmask describing the
> >> capabilities of the altmode, the bits in the vdo are specified in the
> >> specification of the altmode.
> >>
> >> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> >> ---
> >> Changes in v2:
> >> - Drop the unnecessary fwnode parameter from
> >>   typec_port_register_altmodes_from_fwnode()
> >> - Document the expected "altmodes" fwnode in the commit message for now
> >>   as v2 of the patch-set drops the dt-bindings since there are not DT
> >>   users for this yet
> >> ---
> >>  drivers/usb/typec/class.c | 55 +++++++++++++++++++++++++++++++++++++++
> >>  include/linux/usb/typec.h |  6 +++++
> >>  2 files changed, 61 insertions(+)
> >>
> >> diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
> >> index 45f0bf65e9ab..a82344fe1650 100644
> >> --- a/drivers/usb/typec/class.c
> >> +++ b/drivers/usb/typec/class.c
> >> @@ -1978,6 +1978,61 @@ typec_port_register_altmode(struct typec_port *port,
> >>  }
> >>  EXPORT_SYMBOL_GPL(typec_port_register_altmode);
> >>  
> >> +void typec_port_register_altmodes_from_fwnode(struct typec_port *port,
> >> +	const struct typec_altmode_ops *ops, void *drvdata,
> >> +	struct typec_altmode **altmodes, size_t n)
> > 
> > Couldn't we just call this typec_port_register_altmodes()?
> 
> Ack, will fix for v3.
> 
> >> +{
> >> +	struct fwnode_handle *altmodes_node, *child;
> >> +	struct typec_altmode_desc desc;
> >> +	struct typec_altmode *alt;
> >> +	size_t index = 0;
> >> +	u32 svid, vdo;
> >> +	int ret;
> >> +
> >> +	altmodes_node = device_get_named_child_node(&port->dev, "altmodes");
> >> +	if (!altmodes_node)
> >> +		return; /* No altmodes specified */
> >> +
> >> +	child = NULL;
> >> +	while ((child = fwnode_get_next_child_node(altmodes_node, child))) {
> > 
> > fwnode_for_each_child_node()?
> 
> Ack, will fix for v3.
> 
> > 
> >> +		ret = fwnode_property_read_u32(child, "svid", &svid);
> >> +		if (ret) {
> >> +			dev_err(&port->dev, "Error reading svid for altmode %s\n",
> >> +				fwnode_get_name(child));
> >> +			continue;
> >> +		}
> >> +
> >> +		ret = fwnode_property_read_u32(child, "vdo", &vdo);
> >> +		if (ret) {
> >> +			dev_err(&port->dev, "Error reading vdo for altmode %s\n",
> >> +				fwnode_get_name(child));
> >> +			continue;
> >> +		}
> >> +
> >> +		if (index >= n) {
> >> +			dev_err(&port->dev, "Error not enough space for altmode %s\n",
> >> +				fwnode_get_name(child));
> >> +			continue;
> >> +		}
> >> +
> >> +		desc.svid = svid;
> >> +		desc.vdo = vdo;
> >> +		desc.mode = index + 1;
> >> +		alt = typec_port_register_altmode(port, &desc);
> >> +		if (IS_ERR(alt)) {
> >> +			dev_err(&port->dev, "Error registering altmode %s\n",
> >> +				fwnode_get_name(child));
> >> +			continue;
> >> +		}
> >> +
> >> +		alt->ops = ops;
> >> +		typec_altmode_set_drvdata(alt, drvdata);
> >> +		altmodes[index] = alt;
> >> +		index++;
> >> +	}
> >> +}
> >> +EXPORT_SYMBOL_GPL(typec_port_register_altmodes_from_fwnode);
> > 
> > This is OK by me, but I've been wondering if it would be more clear to
> > just have a function fwnode_for_each_altmode() (I don't know if the
> > name is good enough).
> > 
> > int fwnode_for_each_altmode(struct fwnode_handle *fwnode,
> >                             int (*fn)(struct typec_altmode_desc *, void *),
> >                             void *data)
> > {
> >         struct fwnode_handle *altmodes_node, *child;
> >         struct typec_altmode_desc desc;
> > 	u32 svid, vdo;
> > 	int ret;
> > 
> > 	altmodes_node = fwnode_get_named_child_node(fwnode, "altmodes");
> > 	if (!altmodes_node)
> > 		return 0; /* No altmodes specified */
> > 
> >         fwnode_for_each_child_node(altmodes_node, child) {
> >                 ...
> >                 /* read the properties */
> >                 ...
> > 
> > 		desc.svid = svid;
> > 		desc.vdo = vdo;
> > 		desc.mode = index + 1;
> > 
> >                 /* We need to add this member to struct typec_altmode_desc! */
> >                 desc.fwnode = client;
> > 
> >                 ret = fn(&desc, data);
> >                 if (ret)
> >                         return ret;
> >         }
> > 
> >         return 0;
> > }
> > 
> > Something like that. It would leave the registration of the alternate
> > modes to the drivers, which I think would actually be better.
> > 
> > If there ever is need, this can be also used for other things besides
> > mode registration.
> > 
> > What do you think?
> 
> I think adding such a helper might make sense once we actually have
> a need for the doing "other things" for all altmodes in a fwnode beside
> registering them.
> 
> And even then I think it would still make sense to have a
> typec_port_register_altmodes() helper for drivers to use, but that
> could then be a wrapper around fwnode_for_each_altmode().
> 
> Since ATM we have only 1 user for a fwnode_for_each_altmode()
> helper adding it now seems premature to me.
> 
> But if you have a strong preference for adding it now, then I can
> do that for v3.
> 
> If you let me know which way you want to go on this, then I'll
> prepare a v3.

It's API so we can change it later. Let's go with your function
first.

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

thanks,

-- 
heikki

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 3/3] platform/x86/intel_cht_int33fe: Add displayport altmode fwnode to the connector fwnode
  2021-04-09 13:40 ` [PATCH v2 3/3] platform/x86/intel_cht_int33fe: Add displayport altmode fwnode to the connector fwnode Hans de Goede
  2021-04-09 13:46   ` Heikki Krogerus
@ 2021-04-10  2:13   ` Guenter Roeck
  1 sibling, 0 replies; 10+ messages in thread
From: Guenter Roeck @ 2021-04-10  2:13 UTC (permalink / raw)
  To: Hans de Goede, Greg Kroah-Hartman, Heikki Krogerus
  Cc: Rob Herring, Zhen Lei, linux-usb

On 4/9/21 6:40 AM, Hans de Goede wrote:
> Add a displayport altmode fwnode to the usb-connector fwnode,
> devices which use this driver support display-port altmode through
> the PI3USB30532 USB switch, this enables support for this.
> 
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>

Reviewed-by: Guenter Roeck <linux@roeck-us.net>

> ---
>  .../platform/x86/intel_cht_int33fe_typec.c    | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
> 
> diff --git a/drivers/platform/x86/intel_cht_int33fe_typec.c b/drivers/platform/x86/intel_cht_int33fe_typec.c
> index 48638d1c56e5..b61bad9cc8d2 100644
> --- a/drivers/platform/x86/intel_cht_int33fe_typec.c
> +++ b/drivers/platform/x86/intel_cht_int33fe_typec.c
> @@ -124,12 +124,31 @@ static const struct software_node usb_connector_node = {
>  	.properties = usb_connector_properties,
>  };
>  
> +static const struct software_node altmodes_node = {
> +	.name = "altmodes",
> +	.parent = &usb_connector_node,
> +};
> +
> +static const struct property_entry dp_altmode_properties[] = {
> +	PROPERTY_ENTRY_U32("svid", 0xff01),
> +	PROPERTY_ENTRY_U32("vdo", 0x0c0086),
> +	{ }
> +};
> +
> +static const struct software_node dp_altmode_node = {
> +	.name = "displayport-altmode",
> +	.parent = &altmodes_node,
> +	.properties = dp_altmode_properties,
> +};
> +
>  static const struct software_node *node_group[] = {
>  	&fusb302_node,
>  	&max17047_node,
>  	&pi3usb30532_node,
>  	&displayport_node,
>  	&usb_connector_node,
> +	&altmodes_node,
> +	&dp_altmode_node,
>  	NULL
>  };
>  
> 


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 3/3] platform/x86/intel_cht_int33fe: Add displayport altmode fwnode to the connector fwnode
  2021-04-09 13:40 ` [PATCH v2 3/3] platform/x86/intel_cht_int33fe: Add displayport altmode fwnode to the connector fwnode Hans de Goede
@ 2021-04-09 13:46   ` Heikki Krogerus
  2021-04-10  2:13   ` Guenter Roeck
  1 sibling, 0 replies; 10+ messages in thread
From: Heikki Krogerus @ 2021-04-09 13:46 UTC (permalink / raw)
  To: Hans de Goede
  Cc: Greg Kroah-Hartman, Guenter Roeck, Rob Herring, Zhen Lei, linux-usb

On Fri, Apr 09, 2021 at 03:40:33PM +0200, Hans de Goede wrote:
> Add a displayport altmode fwnode to the usb-connector fwnode,
> devices which use this driver support display-port altmode through
> the PI3USB30532 USB switch, this enables support for this.
> 
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
>  .../platform/x86/intel_cht_int33fe_typec.c    | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
> 
> diff --git a/drivers/platform/x86/intel_cht_int33fe_typec.c b/drivers/platform/x86/intel_cht_int33fe_typec.c
> index 48638d1c56e5..b61bad9cc8d2 100644
> --- a/drivers/platform/x86/intel_cht_int33fe_typec.c
> +++ b/drivers/platform/x86/intel_cht_int33fe_typec.c
> @@ -124,12 +124,31 @@ static const struct software_node usb_connector_node = {
>  	.properties = usb_connector_properties,
>  };
>  
> +static const struct software_node altmodes_node = {
> +	.name = "altmodes",
> +	.parent = &usb_connector_node,
> +};
> +
> +static const struct property_entry dp_altmode_properties[] = {
> +	PROPERTY_ENTRY_U32("svid", 0xff01),
> +	PROPERTY_ENTRY_U32("vdo", 0x0c0086),
> +	{ }
> +};
> +
> +static const struct software_node dp_altmode_node = {
> +	.name = "displayport-altmode",
> +	.parent = &altmodes_node,
> +	.properties = dp_altmode_properties,
> +};
> +
>  static const struct software_node *node_group[] = {
>  	&fusb302_node,
>  	&max17047_node,
>  	&pi3usb30532_node,
>  	&displayport_node,
>  	&usb_connector_node,
> +	&altmodes_node,
> +	&dp_altmode_node,
>  	NULL
>  };

thanks,

-- 
heikki

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v2 3/3] platform/x86/intel_cht_int33fe: Add displayport altmode fwnode to the connector fwnode
  2021-04-09 13:40 [PATCH v3 0/3] usb: typec: Add typec_port_register_altmodes() Hans de Goede
@ 2021-04-09 13:40 ` Hans de Goede
  2021-04-09 13:46   ` Heikki Krogerus
  2021-04-10  2:13   ` Guenter Roeck
  0 siblings, 2 replies; 10+ messages in thread
From: Hans de Goede @ 2021-04-09 13:40 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Guenter Roeck, Heikki Krogerus
  Cc: Hans de Goede, Rob Herring, Zhen Lei, linux-usb

Add a displayport altmode fwnode to the usb-connector fwnode,
devices which use this driver support display-port altmode through
the PI3USB30532 USB switch, this enables support for this.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 .../platform/x86/intel_cht_int33fe_typec.c    | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/drivers/platform/x86/intel_cht_int33fe_typec.c b/drivers/platform/x86/intel_cht_int33fe_typec.c
index 48638d1c56e5..b61bad9cc8d2 100644
--- a/drivers/platform/x86/intel_cht_int33fe_typec.c
+++ b/drivers/platform/x86/intel_cht_int33fe_typec.c
@@ -124,12 +124,31 @@ static const struct software_node usb_connector_node = {
 	.properties = usb_connector_properties,
 };
 
+static const struct software_node altmodes_node = {
+	.name = "altmodes",
+	.parent = &usb_connector_node,
+};
+
+static const struct property_entry dp_altmode_properties[] = {
+	PROPERTY_ENTRY_U32("svid", 0xff01),
+	PROPERTY_ENTRY_U32("vdo", 0x0c0086),
+	{ }
+};
+
+static const struct software_node dp_altmode_node = {
+	.name = "displayport-altmode",
+	.parent = &altmodes_node,
+	.properties = dp_altmode_properties,
+};
+
 static const struct software_node *node_group[] = {
 	&fusb302_node,
 	&max17047_node,
 	&pi3usb30532_node,
 	&displayport_node,
 	&usb_connector_node,
+	&altmodes_node,
+	&dp_altmode_node,
 	NULL
 };
 
-- 
2.30.2


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, back to index

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-08 20:31 [PATCH v2 0/3] usb: typec: Add typec_port_register_altmodes_from_fwnode() Hans de Goede
2021-04-08 20:31 ` [PATCH v2 1/3] " Hans de Goede
2021-04-09 10:54   ` Heikki Krogerus
2021-04-09 12:49     ` Hans de Goede
2021-04-09 13:06       ` Heikki Krogerus
2021-04-08 20:31 ` [PATCH v2 2/3] usb: typec: tcpm: Add support for altmodes Hans de Goede
2021-04-08 20:31 ` [PATCH v2 3/3] platform/x86/intel_cht_int33fe: Add displayport altmode fwnode to the connector fwnode Hans de Goede
2021-04-09 13:40 [PATCH v3 0/3] usb: typec: Add typec_port_register_altmodes() Hans de Goede
2021-04-09 13:40 ` [PATCH v2 3/3] platform/x86/intel_cht_int33fe: Add displayport altmode fwnode to the connector fwnode Hans de Goede
2021-04-09 13:46   ` Heikki Krogerus
2021-04-10  2:13   ` Guenter Roeck

Linux-USB Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-usb/0 linux-usb/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-usb linux-usb/ https://lore.kernel.org/linux-usb \
		linux-usb@vger.kernel.org
	public-inbox-index linux-usb

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-usb


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git