From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755887AbbE2MP1 (ORCPT ); Fri, 29 May 2015 08:15:27 -0400 Received: from mailout3.samsung.com ([203.254.224.33]:53952 "EHLO mailout3.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754759AbbE2MPT (ORCPT ); Fri, 29 May 2015 08:15:19 -0400 X-AuditID: cbfee691-f79ca6d00000456a-40-55685855b9b4 Message-id: <55685855.1040401@samsung.com> Date: Fri, 29 May 2015 21:15:17 +0900 From: Chanwoo Choi User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130106 Thunderbird/17.0.2 MIME-version: 1.0 To: Peter Chen , Roger Quadros , "Ivan T. Ivanov" Cc: Chanwoo Choi , balbi@ti.com, jun.li@freescale.com, linux-kernel@vger.kernel.org, r.baldyga@samsung.com, kishon@ti.com, myungjoo.ham@samsung.com Subject: Re: [PATCH v2 0/2] extcon: Inform the state of both ID and VBUS pin for USB References: <1432728910-10761-1-git-send-email-cw00.choi@samsung.com> <1432802731.2348.25.camel@mm-sol.com> <556724FD.2010606@ti.com> <20150529012226.GB14122@shlinux2> <5568452E.8050903@samsung.com> In-reply-to: <5568452E.8050903@samsung.com> Content-type: text/plain; charset=ISO-8859-1 Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrGIsWRmVeSWpSXmKPExsWyRsSkUDc0IiPU4NwjcYuD9+stnh3Vtng2 8SGjxdXZ29gsLjztYbO4vGsOm8XtxhVsFsdm/2WyeHB4J7tFzyMtBy6Pf4f7mTx2zrrL7rFp /zRmj74tqxg9jt/YzuTxeZNcAFsUl01Kak5mWWqRvl0CV0bDjB3sBb+MKmYs6mNrYLyi3sXI ySEhYCLxoe0EC4QtJnHh3nq2LkYuDiGBpYwSi5r/MsIUffl7lxnEFhKYzihxuzkYougBo8SK eXNZQRK8AloSNz42ghWxCKhKnD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k 9rdOY4Ow5SU2r3nLPIFRYBaSJbOQlM1CUraAkXkVo2hqQXJBcVJ6rqFecWJucWleul5yfu4m RnDsP5PawbiyweIQowAHoxIPb8eN9FAh1sSy4srcQ4wSHMxKIrzqoRmhQrwpiZVVqUX58UWl OanFhxhNgWEwkVlKNDkfmJbySuINjU3MjCyNzA0tjIzNlcR5T+b7hAoJpCeWpGanphakFsH0 MXFwSjUwzrDQj2x1l3m4rnxzt+b6NL+3rLrikQqXdu6YsO7XrMPTuL5m3LifdC35Z/0V7U61 BaF+MgVKLntCj/rNeTetIzD2eJJnxn4Ohc1Z0xQyrpxgaIqTbxQQ+bDQ/auA3uq/STIHHs4r mhhT0cKX9/9cUqfo2p0b7Cz3vCmdYKVVuvnjPsnbDoJflFiKMxINtZiLihMBcmL8khMDAAA= DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Dear all, On 05/29/2015 07:53 PM, Chanwoo Choi wrote: > Hi Peter, > > On 05/29/2015 10:22 AM, Peter Chen wrote: >> On Thu, May 28, 2015 at 05:23:57PM +0300, Roger Quadros wrote: >>> +Peter & Li, >>> >>> Ivan, >>> >>> On 28/05/15 11:45, Ivan T. Ivanov wrote: >>>> >>>> Hi Chanwoo, >>>> >>>> On Wed, 2015-05-27 at 21:15 +0900, Chanwoo Choi wrote: >>>>> Previously, I discussed how to inform the changed state of both ID >>>>> and VBUS pin for USB connector on patch-set[1]. >>>>> [1] https://lkml.org/lkml/2015/4/2/310 >>>>> >>>>> So, this patch adds the extcon_set_cable_line_state() function to inform >>>>> the additional state of external connectors without additional register/ >>>>> unregister functions. This function uses the existing notifier chain >>>>> which is registered by extcon_register_notifier() / extcon_register_interest(). >>>>> >>>>> The extcon_set_cable_line_state() can inform the new state of both >>>>> ID and VBUS pin state through extcon_set_cable_line_state(). >>>>> >>>>> For exmaple: >>>>> - On extcon-usb-gpio.c as extcon provider driver as following: >>>>> static void usb_extcon_detect_cable(struct work_struct *work) >>>>> { >>>>> ... >>>>> /* check ID and update cable state */ >>>>> id = gpiod_get_value_cansleep(info->id_gpiod); >>>>> if (id) { >>>>> extcon_set_cable_state_(info->edev, EXTCON_USB_HOST, false); >>>>> extcon_set_cable_state_(info->edev, EXTCON_USB, true); >>>>> >>>>> extcon_set_cable_line_state(info->edev, EXTCON_USB, >>>>> EXTCON_USB_ID_HIGH); >>>> >>>> I am getting more and more confused :-). Why EXTCON_USB is now used for ID notifications? >>>> It should be EXTCON_USB_HOST, no? Why we need another function, framework already have >>>> required information from the function one line above, do I miss something? >>> >>> This is because the existing EXTCON_USB_HOST and EXTCON_USB do not capture all >>> the 4 states of ID and VBUS pins that we need for a real USB driver to work. >>> >>> It looks like it was designed from user space users perspective where they are >>> only interested in USB role. i.e. host or peripheral. >>> >>> Right now we are mixing both ID/VBUS and HOST/Peripheral states. >>> This will break when we consider OTG role switching. >>> With role switching, the USB device might start as a peripheral but switch role to host >>> on the fly and the existing setup (including these patches) can't cater to that >>> if user space is relying on EXTCON_USB_HOST/EXTCON_USB events. >>> Because they are hard-wired to the ID pin state which doesn't change during >>> role switch without cable switch. >>> >>> The USB driver doesn't care about EXTCON_USB_HOST/peripheral states. >>> It just needs ID/VBUS states and should decide the Host/Peripheral state from >>> that and other inputs (like HNP/user request/etc). >>> >>> The flow could be like this >>> >>> (extcon-usb-driver) -> [ID/VBUS states] -> (USB driver) -> [HOST/Peripheral states] >> >> Agree. Chanwoo, USB driver knows better than extcon driver about USB >> role (host/peripheral), so the app should use USB interface to know it, >> in fact, I don't be aware any use case needs to know USB role? >> Are there any users for EXTCON_USB and EXTCON_USB_HOST currently? > > You're right. But, extcon can just distinguish the type of external connectors > and inform the type to the user-space and extcon consumer driver in kernel-space. > > When USB mouse or keyboard is attached, user-space can check the state of externel connector which is attaced to the H/W target as following: > - /sys/class/extcon/extconX/cable.0/name -> USB > - /sys/class/extcon/extconX/cable.0/state -> 0 > - /sys/class/extcon/extconX/cable.1/name -> USB-HOST > - /sys/class/extcon/extconX/cable.1/state -> 1 > On last month, Robert Baldyga sent the patch[1] for extcon-usb-gpio driver. [1] https://lkml.org/lkml/2015/4/2/311 - [PATCH v3 2/4] extcon: usb-gpio: add support for VBUS detection This patch[1] included a following table which show the type of external connectors according to both ID and VBUS pin state. State | ID | VBUS ---------------------------------------- [1] USB | H | H [2] none | H | L [3] USB & USB-HOST | L | H [4] USB-HOST | L | L So, I think that extcon-usb-gpio.c could set below two status with set: - the state of whether USB/USB-HOST are attached or detached -> send the state to both kernel-space and user-space. : extcon_set_cable_state_() - the h/w line state of both ID and VBUS pin state -> send the state to only kernel space. : extcon_set_cable_line_state() [1] State | ID | VBUS ---------------------------------------- [1] USB | H | H extcon_set_cable_state_(edev, EXTCON_USB, true); extcon_set_cable_state_(edev, EXTCON_USB_HOST, false); extcon_set_cable_line_state(edev, EXTCON_USB, EXTCON_USB_ID_HIGH); extcon_set_cable_line_state(edev, EXTCON_USB, EXTCON_USB_VBUS_HIGH); [2] State | ID | VBUS ---------------------------------------- [2] none | H | L extcon_set_cable_state_(edev, EXTCON_USB, false); extcon_set_cable_state_(edev, EXTCON_USB_HOST, false); extcon_set_cable_line_state(edev, EXTCON_USB, EXTCON_USB_ID_HIGH); extcon_set_cable_line_state(edev, EXTCON_USB, EXTCON_USB_VBUS_LOW); [3] State | ID | VBUS ---------------------------------------- [3] USB & USB-HOST | L | H extcon_set_cable_state_(edev, EXTCON_USB, false); extcon_set_cable_state_(edev, EXTCON_USB_HOST, true); extcon_set_cable_line_state(edev, EXTCON_USB, EXTCON_USB_ID_LOW); extcon_set_cable_line_state(edev, EXTCON_USB, EXTCON_USB_VBUS_HIGH); [4] State | ID | VBUS ---------------------------------------- [4] USB-HOST | L | L extcon_set_cable_state_(edev, EXTCON_USB, false); extcon_set_cable_state_(edev, EXTCON_USB_HOST, true); extcon_set_cable_line_state(edev, EXTCON_USB, EXTCON_USB_ID_LOW); extcon_set_cable_line_state(edev, EXTCON_USB, EXTCON_USB_VBUS_LOW); If I know the wrong knowledge, please let me know your comment and advice. Thanks, Chanwoo Choi