All of lore.kernel.org
 help / color / mirror / Atom feed
From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Mats Karrman <mats.dev.list@gmail.com>
Cc: Hans de Goede <hdegoede@redhat.com>,
	Andrzej Hajda <a.hajda@samsung.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-usb@vger.kernel.org, devicetree@vger.kernel.org
Subject: Re: USB role switches, usb-connector, typec and device trees
Date: Mon, 18 Jun 2018 15:00:49 +0300	[thread overview]
Message-ID: <20180618120049.GD2847@kuha.fi.intel.com> (raw)
In-Reply-To: <fbf681c1-da6b-943c-ddee-48f95861a363@gmail.com>

Hi Mats,

On Fri, Jun 15, 2018 at 11:51:17PM +0200, Mats Karrman wrote:
> I hacked away to see if I could make some sense of this but I didn't get far.
> Do you mean that the device_connection_find_match() function should be
> extended with code for finding matches in devicetrees as well?

Yes.

> I tried and ended up creating temporary device_connection instances just
> to try to satisfy the match function you supply from usb_role_switch_get(),

That's how I planned to use it.

> only the OF graph connection does not have a name to compare with.

I think this is about the problem I explained below. So let's just add the
fwnode member to the struct device_connection.

> > > (Ugh, just realized that the "reg" numeric value of the endpoint node is
> > > put in the "id" field of the endpoint struct, bad luck...).
> > Isn't the "compatible" property the one that should be used in this
> > case? The remote endpoint just has to have compatible property
> > matching the con_id, no?
> 
> By endpoint you mean the OF node named "endpoint" as described by graph
> documentation or something else?
> I have not seen or heard of any "endpoint" nodes having "compatible" properties,
> only the nodes containing the "port(s)" nodes. The USB controller node
> won't have compatible set to "usb-role-switch" so which node do you mean?

"compatible" was just a suggestion, but why couldn't for example USB
controller have the "compatible" set also to "usb-role-switch" if it
really acts as the role switch on your system?

        compatible = "<your_platform>-dwc3", "usb-role-switch"

> > My worry is that currently there is no function to convert a fwnode
> > to device. With ACPI it is possible already, but only to the first
> > device bind to the node (ACPI device node can be bind to multiple
> > devices). I don't think there is a function to convert OF node to
> > device.
> > 
> > We could of course workaround this problem and add fwnode member(s) to
> > the device_lookup structure. The callers would then have to check is
> > fwnode or the endpoint (device) name being used, which is not ideal
> > IMO.
> 
> "device_connection" structure?

Yes, sorry about that.

You know, I'm not completely sure what is the benefit in using device
graph with USB connectors? I don't think we need to describe a real
device graph where we could have multiple levels, or do we?

In any case, I guess we are stuck with it since it's used in
Documentation/devicetree/bindings/connector/usb-connector.txt, but I
think in device_connection_find_match() we should still first simply
try to find a named reference (so in case of device tree call
of_parse_phandle(node, con_id, 0)), if that fails try to parse the
graph, and finally if that also fails, check if we have a build-in
description of the connection. Something like this:

void *device_connection_find_match(struct device *dev, const char *con_id,
...
        struct fwnode_handle *fwnode = dev_fwnode(dev);
        struct device_connection connection = { };
        struct fwnode_handle *endpoint = NULL;
        struct fwnode_referece_args args;
        ...
        /* First let's check if there is a named reference. */
        if (!fwnode_property_get_reference_args(fwnode, con_id, NULL, 0, 0,
                                                &args) {
                connection.fwnode = args.fwnode;
                ret = match(&connection, 0, data);
                ...
        }

        /* Let's try device graph */
        while ((endpoint = fwnode_graph_get_next_endpoint(fwnode, endpoint))) {
                struct fwnode_handle *remote;

                remote = fwnode_graph_get_remote_port_parent(endpoint);
                if (!remote)
                        break;

                /* In this example I'm using "compatible" */
                if (!fwnode_property_match_string(remote, "compatible",
                                                  con_id)) {
                        connection.fwnode = remote;
                        ret = match(&connection, 0, data);
                        ...
                }
        }

        /* Finally check if there is a build-in connection description */
        ...


Thanks,

-- 
heikki

  reply	other threads:[~2018-06-18 12:00 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20180606213655epcas1p3e3f704633baa3100e28ff7e02ed85eab@epcas1p3.samsung.com>
2018-06-06 21:36 ` USB role switches, usb-connector, typec and device trees Mats Karrman
2018-06-07  7:22   ` Hans de Goede
2018-06-07 12:01     ` Heikki Krogerus
2018-06-12 17:16       ` Mats Karrman
2018-06-13 13:51         ` Heikki Krogerus
2018-06-15 21:51           ` Mats Karrman
2018-06-18 12:00             ` Heikki Krogerus [this message]
2018-06-07 11:40   ` Andrzej Hajda
2018-06-12 17:33     ` Mats Karrman
2018-06-13  7:06       ` Andrzej Hajda
2018-06-14 17:25         ` Mats Karrman

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=20180618120049.GD2847@kuha.fi.intel.com \
    --to=heikki.krogerus@linux.intel.com \
    --cc=a.hajda@samsung.com \
    --cc=devicetree@vger.kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=hdegoede@redhat.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=mats.dev.list@gmail.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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.