Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751396AbdHFOH6 (ORCPT ); Sun, 6 Aug 2017 10:07:58 -0400 Received: from bh-25.webhostbox.net ([208.91.199.152]:54204 "EHLO bh-25.webhostbox.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751256AbdHFOHz (ORCPT ); Sun, 6 Aug 2017 10:07:55 -0400 Subject: Re: [PATCH 02/18] staging: typec: tcpm: Add extcon helper functions for USB2 current limit detect To: Hans de Goede , Darren Hart , Andy Shevchenko , Wolfram Sang , Sebastian Reichel , Greg Kroah-Hartman , Heikki Krogerus Cc: platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org, Liam Breck , Tony Lindgren , linux-pm@vger.kernel.org, devel@driverdev.osuosl.org References: <20170806123555.5124-1-hdegoede@redhat.com> <20170806123555.5124-3-hdegoede@redhat.com> From: Guenter Roeck Message-ID: Date: Sun, 6 Aug 2017 07:07:52 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <20170806123555.5124-3-hdegoede@redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Authenticated_sender: linux@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: linux@roeck-us.net X-Authenticated-Sender: bh-25.webhostbox.net: linux@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 Content-Length: 4041 Lines: 118 On 08/06/2017 05:35 AM, Hans de Goede wrote: > Some type-c port-controllers, such as the fusb302 port-controller, rely > on an external device doing USB2 charger-type detection. > > Existing PMIC (and charger) drivers already use extcon to communicate the > detected charger-type from the PMIC (extcon) driver to the charger driver. > > Rather then inventing a new API for USB2 charger-type detection > specifically for use with the tcpm code, lets simply re-use the existing > support. This will also allow re-using existing PMIC extcon drivers such > as the axp288 and Intel Whiskey Cove drivers as is on devices where these > are combined with a fusb302 (or in the future another port-controller > which relies on external USB2 charger-type detection). > > This commit adds a helper function which tcpc drivers can use to easily > hook into existing PMIC extcon drivers for USB2 charger-type detection: > > int tcpm_get_usb2_current_limit_extcon(struct tcpc_dev *tcpc); > > Signed-off-by: Hans de Goede > --- > drivers/staging/typec/tcpm.c | 40 ++++++++++++++++++++++++++++++++++++++++ > drivers/staging/typec/tcpm.h | 6 ++++++ > 2 files changed, 46 insertions(+) > > diff --git a/drivers/staging/typec/tcpm.c b/drivers/staging/typec/tcpm.c > index 9f5adace4309..06bb0e640bcf 100644 > --- a/drivers/staging/typec/tcpm.c > +++ b/drivers/staging/typec/tcpm.c > @@ -16,6 +16,7 @@ > > #include > #include > +#include > #include > #include > #include > @@ -3532,6 +3533,45 @@ void tcpm_unregister_port(struct tcpm_port *port) > } > EXPORT_SYMBOL_GPL(tcpm_unregister_port); > > +/* Generic (helper) implementations for some tcpc_dev callbacks */ > +int tcpm_get_usb2_current_limit_extcon(struct tcpc_dev *tcpc) > +{ > + struct extcon_dev *extcon = tcpc->usb2_extcon; > + int current_limit = 0; > + unsigned long timeout; > + > + if (!extcon) > + return 0; > + > + /* > + * USB2 Charger detection may still be in progress when we get here, > + * this can take upto 600ms, wait 800ms max. > + */ > + timeout = jiffies + msecs_to_jiffies(800); > + do { > + if (extcon_get_state(extcon, EXTCON_CHG_USB_SDP) == 1) { > + current_limit = 500; > + break; > + } > + > + if (extcon_get_state(extcon, EXTCON_CHG_USB_CDP) == 1 || > + extcon_get_state(extcon, EXTCON_CHG_USB_ACA) == 1) { > + current_limit = 1500; > + break; > + } > + > + if (extcon_get_state(extcon, EXTCON_CHG_USB_DCP) == 1) { > + current_limit = 2000; > + break; > + } > + > + msleep(50); > + } while (time_before(jiffies, timeout)); > + > + return current_limit; > +} > +EXPORT_SYMBOL_GPL(tcpm_get_usb2_current_limit_extcon); > + Not really sure about this one. Should it be part of low level drivers ? Guenter > MODULE_AUTHOR("Guenter Roeck "); > MODULE_DESCRIPTION("USB Type-C Port Manager"); > MODULE_LICENSE("GPL"); > diff --git a/drivers/staging/typec/tcpm.h b/drivers/staging/typec/tcpm.h > index 01b7d89379a3..35e8c1e7dba0 100644 > --- a/drivers/staging/typec/tcpm.h > +++ b/drivers/staging/typec/tcpm.h > @@ -16,6 +16,7 @@ > #define __LINUX_USB_TCPM_H > > #include > +#include > #include > #include "pd.h" > > @@ -126,6 +127,8 @@ struct tcpc_dev { > int (*pd_transmit)(struct tcpc_dev *dev, enum tcpm_transmit_type type, > const struct pd_message *msg); > struct tcpc_mux_dev *mux; > + /* Used by tcpm_get_usb2_current_limit_extcon helpers */ > + struct extcon_dev *usb2_extcon; > }; > > struct tcpm_port; > @@ -151,4 +154,7 @@ void tcpm_pd_transmit_complete(struct tcpm_port *port, > void tcpm_pd_hard_reset(struct tcpm_port *port); > void tcpm_tcpc_reset(struct tcpm_port *port); > > +/* Generic (helper) implementations for some tcpc_dev callbacks */ > +int tcpm_get_usb2_current_limit_extcon(struct tcpc_dev *tcpc); > + > #endif /* __LINUX_USB_TCPM_H */ >