Linux-USB Archive on lore.kernel.org
 help / color / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Hans de Goede <hdegoede@redhat.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Heikki Krogerus <heikki.krogerus@linux.intel.com>
Cc: Rob Herring <robh+dt@kernel.org>,
	Zhen Lei <thunder.leizhen@huawei.com>,
	linux-usb@vger.kernel.org
Subject: Re: [PATCH v2 1/3] usb: typec: Add typec_port_register_altmodes()
Date: Fri, 9 Apr 2021 19:12:22 -0700
Message-ID: <39a2076c-2df0-658b-26eb-78d763140140@roeck-us.net> (raw)
In-Reply-To: <20210409134033.105834-2-hdegoede@redhat.com>

On 4/9/21 6:40 AM, 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() 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.
> 
> Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>

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

> ---
> Changes in v3:
> - Rename typec_port_register_altmodes_from_fwnode() to
>   typec_port_register_altmodes()
> - Use fwnode_for_each_child_node()
> 
> 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 | 54 +++++++++++++++++++++++++++++++++++++++
>  include/linux/usb/typec.h |  6 +++++
>  2 files changed, 60 insertions(+)
> 
> diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
> index 45f0bf65e9ab..af4b5d91a7c7 100644
> --- a/drivers/usb/typec/class.c
> +++ b/drivers/usb/typec/class.c
> @@ -1978,6 +1978,60 @@ typec_port_register_altmode(struct typec_port *port,
>  }
>  EXPORT_SYMBOL_GPL(typec_port_register_altmode);
>  
> +void typec_port_register_altmodes(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 */
> +
> +	fwnode_for_each_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);
> +
>  /**
>   * 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..71b4dd6e63f1 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(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);
> 


  reply index

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-09 13:40 [PATCH v3 0/3] " Hans de Goede
2021-04-09 13:40 ` [PATCH v2 1/3] " Hans de Goede
2021-04-10  2:12   ` Guenter Roeck [this message]
2021-04-09 13:40 ` [PATCH v2 2/3] usb: typec: tcpm: Add support for altmodes Hans de Goede
2021-04-09 13:45   ` Heikki Krogerus
2021-04-10  2:12   ` Guenter Roeck
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=39a2076c-2df0-658b-26eb-78d763140140@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=hdegoede@redhat.com \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=thunder.leizhen@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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