From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933507AbcFIInO (ORCPT ); Thu, 9 Jun 2016 04:43:14 -0400 Received: from mailout2.w1.samsung.com ([210.118.77.12]:51086 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750789AbcFIInJ (ORCPT ); Thu, 9 Jun 2016 04:43:09 -0400 X-AuditID: cbfec7f5-f792a6d000001302-bb-57592c1a3cb3 Subject: Re: [RFC v4 4/7] extcon: usb-gpio: Add support for VBUS detection To: Roger Quadros , MyungJoo Ham , Chanwoo Choi , Rob Herring , Mark Rutland , Kukjin Kim , Marek Szyprowski , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org References: <1465393686-16644-1-git-send-email-k.kozlowski@samsung.com> <1465393686-16644-5-git-send-email-k.kozlowski@samsung.com> <57592B02.2070609@ti.com> Cc: Peter Chen , "Ivan T. Ivanov" , balbi@kernel.com, kishon@ti.com, Bartlomiej Zolnierkiewicz From: Krzysztof Kozlowski Message-id: <57592C18.8020609@samsung.com> Date: Thu, 09 Jun 2016 10:43:04 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.8.0 MIME-version: 1.0 In-reply-to: <57592B02.2070609@ti.com> Content-type: text/plain; charset=windows-1252 Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprPIsWRmVeSWpSXmKPExsVy+t/xq7pSOpHhBtemilpsnLGe1eJO7xM2 i+tfnrNazD9yjtXi2cSHjBavXxha9D9+zWxx4WkPm8Wmx9dYLS7vmsNmMeP8PiaLtUfuslss vX6RyeJ24wo2i2Oz/zJZtO49wm7R80jLQdBjzbw1jB7/DvczeRzr28fssWlVJ5vH5iX1Hpv2 T2P26NuyitHj+I3tTB6fN8kFcEZx2aSk5mSWpRbp2yVwZeyYn1/wUrzi+YsOtgbGScJdjJwc EgImEpvOTmOCsMUkLtxbz9bFyMUhJLCUUWLdv2usEM4zIGfODHaQKmEBL4lpt/4wgyREBCYw Syxa/waqaiGjxJqtJ8H6mQVWM0ocPLGBGaSFTcBYYvPyJWwgNq+AlsSeuTfAFrIIqEocODuZ BcQWFYiQmLX9BxNEjaDEj8n3wOKcAmoSZztnAq3mABqqJ3H/ohZImFlAXmLzmrfMExgFZiHp mIVQNQtJ1QJG5lWMoqmlyQXFSem5RnrFibnFpXnpesn5uZsYIdH2dQfj0mNWhxgFOBiVeHg1 UiLChVgTy4orcw8xSnAwK4nw7lCODBfiTUmsrEotyo8vKs1JLT7EKM3BoiTOO3PX+xAhgfTE ktTs1NSC1CKYLBMHp1QDY+QtR+9fXib1uiI/q48n7RcLO7iQ/+RlDt2psz7OZLb2spgmrsHL piZ6uHyu1ZFI5xivgosCHKY3NweHzdux8cfOA9uv/he1bU7vjua3S5rYWp/T+OCGqYN/wzpT r2b+J+I3tHrfaOzf8uPz6UvXDr395v8iWkm4kG3LUU7JAsMrsS4771tzKbEUZyQaajEXFScC ANXrxY+yAgAA Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 06/09/2016 10:38 AM, Roger Quadros wrote: > Hi, > > On 08/06/16 16:48, Krzysztof Kozlowski wrote: >> Add VBUS pin detection support to extcon-usb-gpio driver for boards >> which have both VBUS and ID pins, or only one of them. >> >> The logic behind reporting USB and USB-HOST extcon cables is not >> affected. The driver however will report extcon changes for USB-VBUS and >> USB-ID. >> >> Signed-off-by: Robert Baldyga >> Signed-off-by: Krzysztof Kozlowski >> >> --- >> >> Some parts base on old Robert's patchset. >> --- >> drivers/extcon/extcon-usb-gpio.c | 125 +++++++++++++++++++++++++++++++-------- >> 1 file changed, 99 insertions(+), 26 deletions(-) >> >> diff --git a/drivers/extcon/extcon-usb-gpio.c b/drivers/extcon/extcon-usb-gpio.c >> index a36aab007022..85b8a0ce5731 100644 >> --- a/drivers/extcon/extcon-usb-gpio.c >> +++ b/drivers/extcon/extcon-usb-gpio.c >> @@ -35,7 +35,9 @@ struct usb_extcon_info { >> struct extcon_dev *edev; >> >> struct gpio_desc *id_gpiod; >> + struct gpio_desc *vbus_gpiod; >> int id_irq; >> + int vbus_irq; >> >> unsigned long debounce_jiffies; >> struct delayed_work wq_detcable; >> @@ -44,6 +46,8 @@ struct usb_extcon_info { >> static const unsigned int usb_extcon_cable[] = { >> EXTCON_USB, >> EXTCON_USB_HOST, >> + EXTCON_USB_ID, >> + EXTCON_USB_VBUS, >> EXTCON_NONE, >> }; >> >> @@ -55,7 +59,8 @@ static void usb_extcon_detect_cable(struct work_struct *work) >> wq_detcable); >> >> /* check ID and update cable state */ >> - id = gpiod_get_value_cansleep(info->id_gpiod); >> + id = info->id_gpiod ? gpiod_get_value_cansleep(info->id_gpiod) : 1; >> + >> if (id) { >> /* >> * ID = 1 means USB HOST cable detached. >> @@ -73,6 +78,14 @@ static void usb_extcon_detect_cable(struct work_struct *work) >> extcon_set_cable_state_(info->edev, EXTCON_USB, false); >> extcon_set_cable_state_(info->edev, EXTCON_USB_HOST, true); >> } >> + >> + if (info->id_gpiod) >> + extcon_set_cable_state_(info->edev, EXTCON_USB_ID, id); >> + if (info->vbus_gpiod) { >> + int vbus = gpiod_get_value_cansleep(info->vbus_gpiod); >> + >> + extcon_set_cable_state_(info->edev, EXTCON_USB_VBUS, vbus); >> + } > > What happens if either id_gpiod or vbus_gpiod is present? > > As per the DT binding document > "In general we have three cases: > 1. If VBUS and ID gpios are present we pass them as is > USB-HOST = !ID, USB = VBUS > 2. If only VBUS gpio is present we assume that ID pin is always High. > USB-HOST = false, USB = VBUS. > 3. If only ID pin is available we infer the VBUS pin states based on ID. > USB-HOST = !ID, USB = ID" > > So do you want to be consistent and infer VBUS and ID states based on the other? Right, I couldn't make up my mind whether I want to change/improve existing logic or just add VBUS/ID raw notifying. Finally I left original code for USB/USB-HOST cables alone. Best regards, Krzysztof