From patchwork Mon Feb 20 08:51:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 94179 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp1241592obz; Mon, 20 Feb 2017 00:51:48 -0800 (PST) X-Received: by 10.99.51.76 with SMTP id z73mr26243655pgz.137.1487580708793; Mon, 20 Feb 2017 00:51:48 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j25si8252213pgn.210.2017.02.20.00.51.48; Mon, 20 Feb 2017 00:51:48 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752231AbdBTIvl (ORCPT + 25 others); Mon, 20 Feb 2017 03:51:41 -0500 Received: from mail-pg0-f52.google.com ([74.125.83.52]:32845 "EHLO mail-pg0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750885AbdBTIvj (ORCPT ); Mon, 20 Feb 2017 03:51:39 -0500 Received: by mail-pg0-f52.google.com with SMTP id a123so15079407pgc.0 for ; Mon, 20 Feb 2017 00:51:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=Di2C/8mPVQKGTgl22YjGn6dEK0A0mXpwe3FPIjM0KIo=; b=CWAgHlu9riZwLDyMjDLcGY2ocWyhrL9dqB0RVmXw0n8YULRavXO05w0mMtLnmgMfrU 3khTALQkydhmMM4Xpr8xUuZNBn9ul/hETVWJu3gnDErqBwQIrSRU/DhdHigTqRKA6LE4 Q1UjapGvxQWSOyyKZZZ6IirzmOPFG2wGwaJTU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Di2C/8mPVQKGTgl22YjGn6dEK0A0mXpwe3FPIjM0KIo=; b=p8eLD6XIDxdWN5O0r3vGux4Dc02aIhWnmKc+d1nMqSye2twNZ8GXQNaGL76nvwJmCH 3vkRGLNkTx2fgfVjMWTx5rtBM64pJsZwu2mFTB450p2hZ/Zm53pXCJaDVJSHrrYgaMXE 41jUTh2/fscO20BWUVV2eWUsd8+fv8s9bCDoha0X57wD2XCbLPUW+tmsUrwkW5D1Cav/ 4cnU3KYSDYkJQiwNCJFxL7jHoIGjvG2tJpq3qWevjDl+1o9gx/lrrFVaLWMk/biAQPqm cEJeQW3NUEsxKzwDJ/e2wJBrvKo1xhFploCoMvqDnBOr3rZcgM0gCjqT+tWrxKZAuMmw DdFw== X-Gm-Message-State: AMke39nl/UAKIL1v7n3Np/KYH8EXiGbrdTJ0mfkAS5yP/dryJaLjbszoS6lhvv/dzgUfGSJF X-Received: by 10.84.233.193 with SMTP id m1mr30480927pln.118.1487580698390; Mon, 20 Feb 2017 00:51:38 -0800 (PST) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id t184sm5102967pgb.11.2017.02.20.00.51.32 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 20 Feb 2017 00:51:37 -0800 (PST) From: Baolin Wang To: balbi@kernel.org, gregkh@linuxfoundation.org, sre@kernel.org, dbaryshkov@gmail.com, dwmw2@infradead.org Cc: robh@kernel.org, jun.li@nxp.com, m.szyprowski@samsung.com, ruslan.bilovol@gmail.com, peter.chen@freescale.com, stern@rowland.harvard.edu, grygorii.strashko@ti.com, yoshihiro.shimoda.uh@renesas.com, lee.jones@linaro.org, broonie@kernel.org, john.stultz@linaro.org, neilb@suse.com, ckeepax@opensource.wolfsonmicro.com, patches@opensource.wolfsonmicro.com, baolin.wang@linaro.org, linux-pm@vger.kernel.org, linux-usb@vger.kernel.org, device-mainlining@lists.linuxfoundation.org, linux-kernel@vger.kernel.org Subject: [PATCH v19 0/4] Introduce usb charger framework to deal with the usb gadget power negotation Date: Mon, 20 Feb 2017 16:51:06 +0800 Message-Id: X-Mailer: git-send-email 1.7.9.5 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently the Linux kernel does not provide any standard integration of this feature that integrates the USB subsystem with the system power regulation provided by PMICs meaning that either vendors must add this in their kernels or USB gadget devices based on Linux (such as mobile phones) may not behave as they should. Thus provide a standard framework for doing this in kernel. Now introduce one user with wm831x_power to support and test the usb charger. Another user introduced to support charger detection by Jun Li: https://www.spinics.net/lists/linux-usb/msg139425.html Moreover there may be other potential users will use it in future. 1. Before v19 patchset we've fixed below issues in extcon subsystem and usb phy driver, now all were merged. (Thanks for Neil's suggestion) (1) Have fixed the inconsistencies with USB connector types in extcon subsystem by following links: https://lkml.org/lkml/2016/12/21/13 https://lkml.org/lkml/2016/12/21/15 https://lkml.org/lkml/2016/12/21/79 https://lkml.org/lkml/2017/1/3/13 (2) Instead of using 'set_power' callback in phy drivers, we will introduce USB charger to set PMIC current drawn from USB configuration, moreover some 'set_power' callbacks did not implement anything to set PMIC current, thus remove them by following links: https://lkml.org/lkml/2017/1/18/436 https://lkml.org/lkml/2017/1/18/439 https://lkml.org/lkml/2017/1/18/438 Now only two phy drivers (phy-isp1301-omap.c and phy-gpio-vbus-usb.c) still used 'set_power' callback to set current, we can remove them in future. (I have no platform with enabling these two phy drivers, so I can not test them if I converted 'set_power' callback to USB charger.) 2. Some issues pointed by Neil Brown were sill kept in this v19 patchset, and I expalined each issue and may be need discuss again: (1) Change all usb phys to register an extcon and to send appropriate notifications. Firstly, now only 3 USB phy drivers (phy-qcom-8x16-usb.c, phy-omap-otg.c and phy-msm-usb.c) had registered an extcon, mostly did not. I can not change all usb phys to register an extcon, since there are no extcon device to register for these different phy drivers. Secondly, I also agreed with Peter's comments: Not only USB PHY to register an extcon, but also for the drivers which can detect USB charger type, it may be USB controller driver, USB type-c driver, pmic driver, and these drivers may not have an extcon device since the internal part can finish the vbus detect. (2) Change the notifier of usb_phy to be used consistently. Now only 3 phy drivers (phy-generic.c, phy-ab8500-usb.c and phy-gpio-vbus-usb.c) used the notifier of usb_phy. phy-generic.c and phy-gpio-vbus-usb.c were used to send out the connect events, and phy-ab8500-usb.c also was used to send out the MUSB connect events. There are no phy drivers will notify 'vbus_draw' information by the notifier of usb_phy, which was used consistently now. Moreover it is difficult to change the notifier of usb_phy to be used only to communicate the 'vbus_draw' information, since we need to refactor and test these related phy drivers, power drivers or some mfd drivers, which is a huge workload. (3) Still keep charger_type_show() API. Firstly I think we should combine all charger related information into one place for users, which is convenient. Secondly not only we get charger type from extcon, but also in some scenarios we can get charger type from USB controller driver, USB type-c driver, pmic driver, we should also need one place to export the charger type. Changes since v18: Other issues addressed in this patchset: - Modify the method of looking up one USB charger instance, we assume there is only one USB charger in the system. But leaving things there to avoid any need for future refactoring to touch the usb_charger_register() interface. - Remove usb_charger_set_current() API. - Rename usb charger state. - Remove ->get_charger_type() interface. - Add some documentation for ->charger_detect() interface explicitly. - Fix one issue: reset current to default values when cable was unplugged. - Only notify the max current to power users, but users can get the min current by usb_charger_get_current() if users want to use the min current. - Other small optimizations. Changes since v17: - Remove goto section in usb_charger_register() function. - Remove 'extern' in charger.h file. - Move the kfree() to usb_charger_exit() function. Changes since v16: - Modify the charger current range with introducing the maximum and minimum current. - Remove the getting charger type method from power supply. - Add the getting charger type method from extcon system. - Introduce new usb_charger_get_current() API for users to get the maximum and minimum current. - Rename some APIs and other optimization. Changes since v15: - Add charger state checking to avoid sending out duplicate notifies to users. - Add one work to notify power users the current has been changed. Changes since v14: - Add kernel documentation for struct usb_cahrger. - Remove some redundant WARN() functions. Changes since v13: - Remove the charger checking in usb_gadget_vbus_draw() function. - Rename some functions in charger.c file. - Rebase on git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git tags/usb-for-v4.8 Changes since v12: - Remove the class and device things. - Link usb charger to udc-core.ko. - Create one "charger" subdirectory which holds all charger-related attributes. Changes since v11: - Reviewed and tested by Li Jun. Changes since v10: - Introduce usb_charger_get_state() function to check charger state. - Remove the mutex lock in usb_charger_set_cur_limit_by_type() function in case will be issued in atomic context. Baolin Wang (4): usb: gadget: Introduce the usb charger framework usb: gadget: Support for the usb charger framework usb: gadget: Integrate with the usb gadget supporting for usb charger power: wm831x_power: Support USB charger current limit management drivers/power/supply/wm831x_power.c | 63 +++ drivers/usb/gadget/Kconfig | 8 + drivers/usb/gadget/udc/Makefile | 1 + drivers/usb/gadget/udc/charger.c | 865 +++++++++++++++++++++++++++++++++++ drivers/usb/gadget/udc/core.c | 19 +- include/linux/usb/charger.h | 176 +++++++ include/linux/usb/gadget.h | 3 + include/uapi/linux/usb/charger.h | 31 ++ 8 files changed, 1165 insertions(+), 1 deletion(-) create mode 100644 drivers/usb/gadget/udc/charger.c create mode 100644 include/linux/usb/charger.h create mode 100644 include/uapi/linux/usb/charger.h -- 1.7.9.5 Signed-off-by: Mark Brown Signed-off-by: Baolin Wang Acked-by: Lee Jones Acked-by: Charles Keepax Acked-by: Peter Chen Acked-by: Sebastian Reichel