From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964796AbcFCSj4 (ORCPT ); Fri, 3 Jun 2016 14:39:56 -0400 Received: from bh-25.webhostbox.net ([208.91.199.152]:55053 "EHLO bh-25.webhostbox.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932299AbcFCSjy (ORCPT ); Fri, 3 Jun 2016 14:39:54 -0400 Date: Fri, 3 Jun 2016 11:39:27 -0700 From: Guenter Roeck To: Heikki Krogerus Cc: Oliver Neukum , Andy Shevchenko , Rajaram R , Felipe Balbi , Mathias Nyman , Greg KH , linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Subject: Re: [RFC PATCHv2] usb: USB Type-C Connector Class Message-ID: <20160603183927.GA12659@roeck-us.net> References: <1463661894-22820-1-git-send-email-heikki.krogerus@linux.intel.com> <1464773169.4051.8.camel@suse.com> <20160601232926.GA8463@roeck-us.net> <20160602101853.GC25305@kuha.fi.intel.com> <20160602161219.GA24772@roeck-us.net> <20160603132140.GB6305@kuha.fi.intel.com> <57518B7A.1030508@roeck-us.net> <20160603151746.GC6305@kuha.fi.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160603151746.GC6305@kuha.fi.intel.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-Authenticated_sender: guenter@roeck-us.net X-OutGoing-Spam-Status: No, score=-1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - bh-25.webhostbox.net X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - roeck-us.net X-Get-Message-Sender-Via: bh-25.webhostbox.net: authenticated_id: guenter@roeck-us.net X-Authenticated-Sender: bh-25.webhostbox.net: guenter@roeck-us.net X-Source: X-Source-Args: X-Source-Dir: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 03, 2016 at 06:17:46PM +0300, Heikki Krogerus wrote: [ ... ] > > > > > > > > In my test case, this gives me > > > > /sys/class/type-c/usbc0/ > > > > usbc0.svid:18d1 > > > > usbc0.svid:18d1/mode0 > > > > usbc0.svid:18d1/mode0/vdo > > > > usbc0.svid:18d1/mode0/description > > > > usbc0.svid:18d1/mode0/active > > > > ... > > > > usbc0.svid:ff01 > > > > usbc0.svid:ff01/mode0/vdo > > > > usbc0.svid:ff01/mode0/description > > > > usbc0.svid:ff01/mode0/active > > > > Side note: I didn't provide a description/name for the modes, because that > > would result in something like usbc0.DisplayPort/ instead of usbc0.svid:ff01/, > > and I prefer a consistent ABI. Since this _is_ part of the ABI, would it make > > sense to standardize on names for modes in sysfs ? For example, how should > > a "Display Port" mode directory be named ? It doesn't sound good if I > > use "usbc0.svid:ff01", someone else uses "usbc0.DisplayPort", and yet > > someone else uses "usbc0.displayport". > > Yeah, let's make them standard. > Any name preferences ? > > > > Also, do we at some point need to standardize the ABI for the standard > > alternate modes such as DisplayPort (if there are any - again I am not > > there yet) ? > > I don't have an answer to that. > Ok, I'll look into it as I proceed with my implementation. > > > > Sounds good to me. Many other subsystems do the same, ie create the subsystem > > device(s) during registration with the subsystem, so this is in line with other > > kernel code. > > > > Should I send you a follow-up patch on top of yours ? > > Sure. I'm a little bit stuck with an other tasks, so let's keep this > thing rolling. > See below. Thanks, Guenter --- >>From ab1f2d0671e3cda74b80c6d17d99cb3e386c0d08 Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Thu, 2 Jun 2016 10:09:50 -0700 Subject: [PATCH] usb: typec: Register supported alternate modes in typec_register_port() By registering supported alternate modes when registering the port, we automatically get the correct directory hierarchie in the class device. Change-Id: I543da5f4ce922ded0532e6b0a0fdb8bc55cb5a80 Signed-off-by: Guenter Roeck --- drivers/usb/type-c/typec.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/drivers/usb/type-c/typec.c b/drivers/usb/type-c/typec.c index 41ad955..22ee7eb 100644 --- a/drivers/usb/type-c/typec.c +++ b/drivers/usb/type-c/typec.c @@ -892,14 +892,22 @@ struct typec_port *typec_register_port(struct device *dev, typec_init_roles(port); ret = device_register(&port->dev); - if (ret) { - ida_simple_remove(&typec_index_ida, id); - put_device(&port->dev); - kfree(port); - return ERR_PTR(ret); - } + if (ret) + goto reg_err; + + ret = typec_register_altmodes(&port->dev, cap->alt_modes); + if (ret) + goto alt_err; return port; + +alt_err: + device_unregister(&port->dev); +reg_err: + ida_simple_remove(&typec_index_ida, id); + put_device(&port->dev); + kfree(port); + return ERR_PTR(ret); } EXPORT_SYMBOL_GPL(typec_register_port); @@ -908,6 +916,7 @@ void typec_unregister_port(struct typec_port *port) if (port->connected) typec_disconnect(port); + typec_unregister_altmodes(port->cap->alt_modes); device_unregister(&port->dev); } EXPORT_SYMBOL_GPL(typec_unregister_port); -- 2.1.2