Re: [PATCH v6] usb: typec: Add a sysfs node to manage port type

2017-06-07 Thread Badhri Jagan Sridharan
Hi Heikki,

Greg has already picked the change.
I got emails on Jun 3rd saying it has been picked on usb-next branch.
I do see it there as well.
https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git/commit/?h=usb-next=bab3548078237706f53baafe43ae58257225549d
Happy to know that you are good with the CL as well :)

Thanks,
Badhri.

On Mon, Jun 5, 2017 at 2:56 AM, Heikki Krogerus
 wrote:
> Hi,
>
> Sorry for the late reply. I was unable to follow my email last week.
>
> On Tue, May 30, 2017 at 12:39:53PM -0700, Badhri Jagan Sridharan wrote:
>> User space applications in some cases have the need to enforce a
>> specific port type(DFP/UFP/DRP). This change allows userspace to
>> attempt setting the desired port type. Low level drivers can
>> however reject the request if the specific port type is not supported.
>>
>> Signed-off-by: Badhri Jagan Sridharan 
>> Reviewed-by: Guenter Roeck 
>
> It looks good to me. In case Greg has not yet picked this:
>
> Acked-by: Heikki Krogerus 
>
>
> Thanks,
>
> --
> heikki
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v6] usb: typec: Add a sysfs node to manage port type

2017-06-05 Thread Heikki Krogerus
Hi,

Sorry for the late reply. I was unable to follow my email last week.

On Tue, May 30, 2017 at 12:39:53PM -0700, Badhri Jagan Sridharan wrote:
> User space applications in some cases have the need to enforce a
> specific port type(DFP/UFP/DRP). This change allows userspace to
> attempt setting the desired port type. Low level drivers can
> however reject the request if the specific port type is not supported.
> 
> Signed-off-by: Badhri Jagan Sridharan 
> Reviewed-by: Guenter Roeck 

It looks good to me. In case Greg has not yet picked this:

Acked-by: Heikki Krogerus 


Thanks,

-- 
heikki
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v6] usb: typec: Add a sysfs node to manage port type

2017-05-30 Thread Badhri Jagan Sridharan
User space applications in some cases have the need to enforce a
specific port type(DFP/UFP/DRP). This change allows userspace to
attempt setting the desired port type. Low level drivers can
however reject the request if the specific port type is not supported.

Signed-off-by: Badhri Jagan Sridharan 
Reviewed-by: Guenter Roeck 
---
Changelog since v1:
- introduced a new variable port_type in struct typec_port to track
  the current port type instead of changing type member in
  typec_capability to address Heikki Krogerus comments.
- changed the output format and strings that would be displayed as
  suggested by Heikki Krogerus.

Changelog since v2:
- introduced a new mutex lock to protect port_type for addressing
  the race conditions identified by Guenter Roeck
- added typec_port_types_drp for printing port_type when cap->type
  is TYPE_PORT_DRP as suggested by Guenter Roeck
- Power role swap and data role swaps would be rejected unless
  port port_type == TYPE_PORT_DRP
- port_type_store would return immediately if the current port_type
  is same as the new port_type as suggested by Guenter Roeck

Changelog since v3:
- Moved as much as code outside port_type_lock as suggested by
  Guenter Roeck
- Removed Change-Id line from commit message identified by
  Greg Kroah-Hartman

Changelog since v4:
- Corrected return value and moved moved one more line of code
  outside port_type_lock in the port_type_store function as
  suggested by Guenter Roeck

Changelog since v6:
- Added back the ABI Documentation which was dropped accidentally
  during patch revisions.

 Documentation/ABI/testing/sysfs-class-typec |  15 
 drivers/usb/typec/typec.c   | 106 +---
 include/linux/usb/typec.h   |   4 ++
 3 files changed, 115 insertions(+), 10 deletions(-)

diff --git a/Documentation/ABI/testing/sysfs-class-typec 
b/Documentation/ABI/testing/sysfs-class-typec
index d4a3d23eb09c..5be552e255e9 100644
--- a/Documentation/ABI/testing/sysfs-class-typec
+++ b/Documentation/ABI/testing/sysfs-class-typec
@@ -30,6 +30,21 @@ Description:
 
Valid values: source, sink
 
+What:   /sys/class/typec//port_type
+Date:   May 2017
+Contact:   Badhri Jagan Sridharan 
+Description:
+   Indicates the type of the port. This attribute can be used for
+   requesting a change in the port type. Port type change is
+   supported as a synchronous operation, so write(2) to the
+   attribute will not return until the operation has finished.
+
+   Valid values:
+   - source (The port will behave as source only DFP port)
+   - sink (The port will behave as sink only UFP port)
+   - dual (The port will behave as dual-role-data and
+   dual-role-power port)
+
 What:  /sys/class/typec//vconn_source
 Date:  April 2017
 Contact:   Heikki Krogerus 
diff --git a/drivers/usb/typec/typec.c b/drivers/usb/typec/typec.c
index 89e540bb7ff3..63644785ce31 100644
--- a/drivers/usb/typec/typec.c
+++ b/drivers/usb/typec/typec.c
@@ -11,6 +11,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -69,6 +70,8 @@ struct typec_port {
enum typec_role pwr_role;
enum typec_role vconn_role;
enum typec_pwr_opmode   pwr_opmode;
+   enum typec_port_typeport_type;
+   struct mutexport_type_lock;
 
const struct typec_capability   *cap;
 };
@@ -789,6 +792,18 @@ static const char * const typec_data_roles[] = {
[TYPEC_HOST]= "host",
 };
 
+static const char * const typec_port_types[] = {
+   [TYPEC_PORT_DFP] = "source",
+   [TYPEC_PORT_UFP] = "sink",
+   [TYPEC_PORT_DRP] = "dual",
+};
+
+static const char * const typec_port_types_drp[] = {
+   [TYPEC_PORT_DFP] = "dual [source] sink",
+   [TYPEC_PORT_UFP] = "dual source [sink]",
+   [TYPEC_PORT_DRP] = "[dual] source sink",
+};
+
 static ssize_t
 preferred_role_store(struct device *dev, struct device_attribute *attr,
 const char *buf, size_t size)
@@ -846,11 +861,6 @@ static ssize_t data_role_store(struct device *dev,
struct typec_port *port = to_typec_port(dev);
int ret;
 
-   if (port->cap->type != TYPEC_PORT_DRP) {
-   dev_dbg(dev, "data role swap only supported with DRP ports\n");
-   return -EOPNOTSUPP;
-   }
-
if (!port->cap->dr_set) {
dev_dbg(dev, "data role swapping not supported\n");
return -EOPNOTSUPP;
@@ -860,11 +870,22 @@ static ssize_t data_role_store(struct device *dev,
if (ret < 0)
return ret;
 
+   mutex_lock(>port_type_lock);
+   if (port->port_type != TYPEC_PORT_DRP) {
+   dev_dbg(dev, "port type fixed at