From patchwork Fri Dec 18 09:33:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Chen X-Patchwork-Id: 7881611 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 5DB24BEEE5 for ; Fri, 18 Dec 2015 09:41:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 52FC3204AB for ; Fri, 18 Dec 2015 09:41:02 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3E9E3204A2 for ; Fri, 18 Dec 2015 09:41:01 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1a9rVd-0003fi-6c; Fri, 18 Dec 2015 09:39:33 +0000 Received: from mail-by2on0112.outbound.protection.outlook.com ([207.46.100.112] helo=na01-by2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1a9rV5-00039v-6e for linux-arm-kernel@lists.infradead.org; Fri, 18 Dec 2015 09:39:01 +0000 Received: from BY2PR03CA059.namprd03.prod.outlook.com (10.141.249.32) by BY2PR0301MB1992.namprd03.prod.outlook.com (10.163.196.26) with Microsoft SMTP Server (TLS) id 15.1.355.16; Fri, 18 Dec 2015 09:38:37 +0000 Received: from BY2FFO11FD026.protection.gbl (2a01:111:f400:7c0c::105) by BY2PR03CA059.outlook.office365.com (2a01:111:e400:2c5d::32) with Microsoft SMTP Server (TLS) id 15.1.355.16 via Frontend Transport; Fri, 18 Dec 2015 09:38:37 +0000 Authentication-Results: spf=permerror (sender IP is 192.88.158.2) smtp.mailfrom=freescale.com; freescale.mail.onmicrosoft.com; dkim=none (message not signed) header.d=none; freescale.mail.onmicrosoft.com; dmarc=none action=none header.from=freescale.com; Received-SPF: PermError (protection.outlook.com: domain of freescale.com used an invalid SPF mechanism) Received: from az84smr01.freescale.net (192.88.158.2) by BY2FFO11FD026.mail.protection.outlook.com (10.1.15.215) with Microsoft SMTP Server (TLS) id 15.1.355.15 via Frontend Transport; Fri, 18 Dec 2015 09:38:37 +0000 Received: from shlinux2.ap.freescale.net (shlinux2.ap.freescale.net [10.192.224.44]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id tBI9cGKn020738; Fri, 18 Dec 2015 02:38:32 -0700 From: Peter Chen To: , , Subject: [RFC PATCH 3/5] usb: misc: generic_onboard_hub: add generic onboard USB device driver Date: Fri, 18 Dec 2015 17:33:57 +0800 Message-ID: <1450431239-16439-4-git-send-email-peter.chen@freescale.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1450431239-16439-1-git-send-email-peter.chen@freescale.com> References: <1450431239-16439-1-git-send-email-peter.chen@freescale.com> X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; BY2FFO11FD026; 1:xU3egs1kEnQXnvU1PpHXUtl3gVLQPO3bmA+KT+XVat15SlcENwJp3TF9ullhaCH2qGGtZVCrzUhvFCm1YLTqrZKRlz9KpALID7a5hTn/q/u36r+jJ0hxoHAqTWNRe5WDpEn1zewvSbvughBd3xgheVpZgS0rqMYSb2/esnWjbpN0+AY1e9mNQHfJ7h7Rilt5iIzGy/0kkmBK7NYDrpnNWrLC/g06BEwKTx2/KWDbc5kokecHKo8f6rCy1FU73x5NRrMA0XNVujKgf7a+pDNJ2el9VX2RlI1XVcBJtCn2OLRCURMkUBBekHk5rAxyRiaf0kEmWtJ5OI4KkVJErdGj8tfUmEZiMFoI6mA0zyZcXRl2Iz1+DwPduPyAROtxX+a5DrQ3/cYrPaOWyv7jA38NzhKCkcfqi4Q1bebp0d2Hu24/VgDi1SqhX3Wi1qFzBqbs X-Forefront-Antispam-Report: CIP:192.88.158.2; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(2980300002)(448002)(3190300001)(199003)(189002)(1096002)(106466001)(1220700001)(50466002)(586003)(47776003)(85326001)(48376002)(4001430100002)(11100500001)(229853001)(36756003)(50226001)(92566002)(33646002)(2171001)(189998001)(19580405001)(76176999)(107886002)(97736004)(69596002)(50986999)(87936001)(81156007)(5001960100002)(5001770100001)(19580395003)(104016004)(5003940100001)(15975445007)(77096005)(5008740100001)(2950100001)(2201001)(86362001)(6806005)(41533002)(2004002)(217873001); DIR:OUT; SFP:1102; SCL:1; SRVR:BY2PR0301MB1992; H:az84smr01.freescale.net; FPR:; SPF:PermError; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Exchange-Diagnostics: 1; BY2PR0301MB1992; 2:AAqwFdl2jR2ZevwaN7h76u+1+tqmDk0Ha8WCaQLbNaMrwJuV+MPEQHOuPUr+XGhRjiz52nCOJbAza62bKUiP1fOSdm2Ng4CdZE0H7DhsCE4VFMv8E20/3BHqCJNukmW71ntbNoQ3MFpllDoLjn/+fA==; 3:aqYhYPxxjw19JUUSUE2MXYOEtsf5OVvtkBqpfndGl2/eahr0wssuPyGY/pI1VRy2N6Fq93nYXPYF4W5kFcrQdzMGG91FMY8+2sdnjc+P2je/jw/7gn3vd/Ng33+k3nocsid+qcoKxls5zXHa6JVVU52HoaM0xOrQU+0EJDIjetxGhz/kCErzqfqEZEEz45iZHBH2rEcbqQBbdmLamHd/x21ZD1NuduTyucqHrjWYjXI=; 25:MZrzBUWsJBNCMhaYrdx+Dmtpf2Q+CVAGiDInNNcb1SGiXP68T09oU4kxpVaYsF32e35C3jZ7UTuwP8z3va+sVTxk7xdIPqBDSi8iG/AOO+yYIMiSJwVXtILRugOe4rJpc7tHdiCLvvSr9VT7UT8cfw8uolbQi0DLWoBInO6rAO+wU7JHWReD0gbXJm4oIOZFRuwXG2GsDx6yJCuoG5jAqFQxywJVitDg9dP4+OEcvlIL6q4kEeJMHAouu0leFfcqBbJqTIqDa/4lb40v93R/ig== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY2PR0301MB1992; X-Microsoft-Exchange-Diagnostics: 1; BY2PR0301MB1992; 20:Eu8QU32C7VjX7XovX59MRITgUUIdmpz0CpQV/C4XaoWgQTJZga/EatvDx1rWdmnhkDbrNDNc5TkY+35qnIrhneMA3ooMFUnX0jHvp859z6Mp1BOcCwAdeUjsQdwtUcbyIIk3L2ORnWXnztTDPH9esG07U1V7Y3ZIJWs7ESvxx2cXwCnT9xYzBt5GXnc5b/JOfmQwS8wbalU/9f59+BoDCcoZiY6jweiOLF6FjyMsPnWPTDtKZRWeTLzpP93466ugcRYuuU93XNRO+P3+bPDDRMusvAS1YVUHGMVpHV6hUIIMN9/sVy51r7HxBWJPnUhr4exRdclnsv5j9YtESGOtk2lRLiv0b/tQtyBseIvudzI=; 4:eBAlwbEqFtSDihAgU8OIY+riykyMENSuc+q+5F15AaLUx09y1a1mz2qXj9DEpCDIqioGlLn3JpFfL4K67qsWVV1AEwsINZaeazMGbAKV0xXXOPXWdpMsieXLCiMWXNVQbJ6H/y101xpUjME5woFkqNwMdkn47+kTHrE2EIOrlWU8HJySua695/4XaHX/26zHxPZSBAacFw8u3bH9p7wq1Mrq+b2OruUxFW8CKqXKY7rzQ7dOO18Q0+3QNBi0pvdWp5KoTM3YzdBS+AiYldqvyBCx0cEKIZLSBajDBe+1Rjfl2XcEELNtfgW+SeHZ9+1dinxFXHHnxzTrSkAjQ42geQz9nz+/TRBMAfawpm4J/ZzVD8OYTu5rmA4W+eUwMAbOTrijc3WHtliI/DT2SgZFpPfYnchn8yjkmSsZJPWlh491xr7SeQGGcOHD5UYs091S X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(101931422205132); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(520078)(8121501046)(5005006)(10201501046)(3002001); SRVR:BY2PR0301MB1992; BCL:0; PCL:0; RULEID:; SRVR:BY2PR0301MB1992; X-Forefront-PRVS: 07943272E1 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BY2PR0301MB1992; 23:xCeVgIK5GuVFHy1qcA6aKpV4xO14McpfWLC+PNy?= =?us-ascii?Q?oFA/YqrDdiYbfSsmX+iebFWSmPq0f9/kNP3MpoKN0r1RaRiUoqi282rHsnkb?= =?us-ascii?Q?h0zATDL3H9LuN6MIC5P2UPOBdrYcb02VcVNMDAqoSQuikQwKVjXX4Y0wqe4e?= =?us-ascii?Q?bvUUEUmoxNWO+EZ7OoDxaGIW/Q0AF/HcgHBhU1/RYtodecKxBXt1PjZYOgsL?= =?us-ascii?Q?ONNNb0RykUpQEMgJyoTu7VQ7y6fnl0/xzz3og31/TyH7ms0ZbwG7ZmCnnark?= =?us-ascii?Q?pyKGB/5CrpUmTP7rV1SikiUHF2Iy/LLZ85BZftlkbEFyUEg8Lj8a1x3PrkJa?= =?us-ascii?Q?wNUmgeIq90EXgawK6ScSVjrJDVqnBuvS43O70HpYoUz9y4jEbm3JE9z7KGwS?= =?us-ascii?Q?4LCHtzqABPnxanO1w6XGazSrJatjtBYSfPYEbA6xXSKUTPyrU94PWYvCpP5n?= =?us-ascii?Q?wExg7nnZJdxvgMr7X2++LxT/rByG1SNZsh4xAz50HeyCnVeNxoZC7S/NawjQ?= =?us-ascii?Q?JWg19azJzO5fy9LnWSphEteMgCRCINHN+1Rj6M2xLI23n3mSWlC9YjaPeTcm?= =?us-ascii?Q?2+pzp2dYGLKvKOKCaHKyZN2f5l9D7fyMcZJh1xuPf/8XBNvOPlTZr9xtm9gT?= =?us-ascii?Q?mLC8nT+JKeY3GkWk+OiT/p25wBRCD6KXCS0eDIeicFcvhr8OrRQl4vazPNAP?= =?us-ascii?Q?WjPuLrztHehPUas2Uqr15Ijukn7ys9w7Fjkr2tEkCV9engM5/8AOtYr3BzbB?= =?us-ascii?Q?m26+TItWIFPT+A3zFpNE3UuHfwQ8SyWUiXRWEU8AsbDMJgBG2+559Mffds8S?= =?us-ascii?Q?l1Xe1jJF77AJczP0PxocVgf7CDxSifTQVYAcv920oyciNCxAmjWasto7zV6J?= =?us-ascii?Q?M8hBxanZW+nok9gSfnCSvmz67bzIJJe5gBhKOVBcNI2FuOrXR2CtwVFWj3CF?= =?us-ascii?Q?dktJo4y+4en2ZAAiuBH0BeTd7ZmKu4Kwb4zQQYTgKgosc8pw5pRsTkhri4FH?= =?us-ascii?Q?UnybCa3zWRMszT12bvOuK8Y9XfnWVDKY+HPnsM2+8VbtVIuhE0YAdy7MWGBL?= =?us-ascii?Q?duus3PPw6fBBDp/dxxzoyEGYKO4FGGhNKrLb8Q50N3Dv9AmVzGDxqU/fNGos?= =?us-ascii?Q?+hG62tUgMN+YO8pgyBCI/9wPZuyl5BsXSlwv8+Sw6XaK0E9kPY0YnJL1Vgh2?= =?us-ascii?Q?7+gxiZqVe5JUPbAaCaiLD/TMiobjzNxwrOB9o?= X-Microsoft-Exchange-Diagnostics: 1; BY2PR0301MB1992; 5:9/CndVQPSwtpHMRT7QyLmHzIR0DVZn1swziEH9JU4ppi2g+/2Wveawu+HRFd5Z2M7gdygL+MM23gfLwSBUc1wqf5TK2MYjGSGXZ+4uDfHJEE9Ke7GwfwsLKtJuRXBl1EchuaXIYv5HvhmSY91gODMg==; 24:0cQTCy9RB9lO4dhWnDvFjhsMvQEDCCtbCp+5AacDaP6w6VFr8X2DzQaEJQ3UH+1qUrVFHIfzr8l34+kxcadk/zpE55GQ/EkfykVLusTqj/g= X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Dec 2015 09:38:37.0354 (UTC) X-MS-Exchange-CrossTenant-Id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=710a03f5-10f6-4d38-9ff4-a80b81da590d; Ip=[192.88.158.2]; Helo=[az84smr01.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR0301MB1992 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151218_013859_516186_FCDDA047 X-CRM114-Status: GOOD ( 23.30 ) X-Spam-Score: -1.9 (-) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, devicetree@vger.kernel.org, p.zabel@pengutronix.de, pawel.moll@arm.com, mathieu.poirier@linaro.org, linux-usb@vger.kernel.org, patryk@kowalczyk.ws, balbi@ti.com, robh+dt@kernel.org, arnd@arndb.de, Peter Chen , kernel@pengutronix.de, festevam@gmail.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAD_ENC_HEADER,BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Current USB device driver lacks of platform interfaces to configure external signal on HUB chip, eg, the PHY input clock and gpio reset pin for HUB, these kinds of devices are usually soldered at the board, and they are not hot-plug USB devices. With this patch, the user can configure the device's pins at device tree, and these configuration will be effective before the USB bus can be used, it can avoid unexpected signals at USB bus during this USB device hardware reset process, so we use subsys_initcall for this driver. Signed-off-by: Peter Chen --- MAINTAINERS | 7 ++ drivers/usb/misc/Kconfig | 10 +++ drivers/usb/misc/Makefile | 1 + drivers/usb/misc/generic_onboard_device.c | 144 ++++++++++++++++++++++++++++++ 4 files changed, 162 insertions(+) create mode 100644 drivers/usb/misc/generic_onboard_device.c diff --git a/MAINTAINERS b/MAINTAINERS index 9bff63c..9ea0955 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -11140,6 +11140,13 @@ S: Maintained F: Documentation/usb/ohci.txt F: drivers/usb/host/ohci* +USB Generic Onboard Device Driver +M: Peter Chen +T: git git://git.kernel.org/pub/scm/linux/kernel/git/peter.chen/usb.git +L: linux-usb@vger.kernel.org +S: Maintained +F: drivers/usb/misc/generic_onboard_device.c + USB OTG FSM (Finite State Machine) M: Peter Chen T: git git://git.kernel.org/pub/scm/linux/kernel/git/peter.chen/usb.git diff --git a/drivers/usb/misc/Kconfig b/drivers/usb/misc/Kconfig index f7a7fc2..089e2c4 100644 --- a/drivers/usb/misc/Kconfig +++ b/drivers/usb/misc/Kconfig @@ -268,3 +268,13 @@ config USB_CHAOSKEY To compile this driver as a module, choose M here: the module will be called chaoskey. + +config USB_ONBOARD_DEVICE + tristate "Generic USB Onboard Device" + help + depends on OF + Say Y here if your board has an onboard device, and this device + needs to control its PHY clock and reset pin through external + signals. If you are not sure, say N. + + To compile this driver as a module, choose M here. diff --git a/drivers/usb/misc/Makefile b/drivers/usb/misc/Makefile index 45fd4ac..60731bb 100644 --- a/drivers/usb/misc/Makefile +++ b/drivers/usb/misc/Makefile @@ -29,3 +29,4 @@ obj-$(CONFIG_USB_CHAOSKEY) += chaoskey.o obj-$(CONFIG_USB_SISUSBVGA) += sisusbvga/ obj-$(CONFIG_USB_LINK_LAYER_TEST) += lvstest.o +obj-$(CONFIG_USB_ONBOARD_DEVICE) += generic_onboard_device.o diff --git a/drivers/usb/misc/generic_onboard_device.c b/drivers/usb/misc/generic_onboard_device.c new file mode 100644 index 0000000..0111bd9 --- /dev/null +++ b/drivers/usb/misc/generic_onboard_device.c @@ -0,0 +1,144 @@ +/* + * generic_onboard_device.c The generic onboard USB device driver + * + * Copyright (C) 2015 Freescale Semiconductor, Inc. + * Author: Peter Chen + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 of + * the License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/* + * This driver is only for the USB HUB devices which need to control + * their external pins(clock, reset, etc), and these USB HUB devices + * are soldered at the board. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct usb_generic_onboard_data { + struct clk *clk; +}; + +static int usb_generic_onboard_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct usb_generic_onboard_data *hub_data; + int ret = -EINVAL; + struct gpio_desc *gpiod_reset = NULL; + struct device_node *node = dev->of_node; + u32 duration_us = 50, clk_rate = 0; + + /* Only support device tree now */ + if (!node) + return ret; + + hub_data = devm_kzalloc(dev, sizeof(*hub_data), GFP_KERNEL); + if (!hub_data) + return -ENOMEM; + + hub_data->clk = devm_clk_get(dev, NULL); + if (IS_ERR(hub_data->clk)) { + dev_dbg(dev, "Can't get clock: %ld\n", + PTR_ERR(hub_data->clk)); + hub_data->clk = NULL; + } else { + ret = clk_prepare_enable(hub_data->clk); + if (ret) { + dev_err(dev, + "Can't enable external clock: %d\n", + ret); + return ret; + } + + of_property_read_u32(node, "clock-frequency", &clk_rate); + if (clk_rate) { + ret = clk_set_rate(hub_data->clk, clk_rate); + if (ret) { + dev_err(dev, "Error setting clock rate\n"); + goto disable_clk; + } + } + } + + gpiod_reset = devm_gpiod_get_optional(dev, "reset", GPIOD_ASIS); + ret = PTR_ERR_OR_ZERO(gpiod_reset); + if (ret) { + dev_err(dev, "Failed to get reset gpio, err = %d\n", ret); + goto disable_clk; + } + + of_property_read_u32(node, "reset-duration-us", &duration_us); + + if (gpiod_reset) { + gpiod_direction_output(gpiod_reset, 1); + + gpiod_set_value(gpiod_reset, 1); + usleep_range(duration_us, duration_us + 10); + gpiod_set_value(gpiod_reset, 0); + } + + dev_set_drvdata(dev, hub_data); + return ret; + +disable_clk: + clk_disable_unprepare(hub_data->clk); + return ret; +} + +static int usb_generic_onboard_remove(struct platform_device *pdev) +{ + struct usb_generic_onboard_data *hub_data = platform_get_drvdata(pdev); + + clk_disable_unprepare(hub_data->clk); + return 0; +} + +static const struct of_device_id usb_generic_onboard_dt_ids[] = { + {.compatible = "generic-onboard-device"}, + { }, +}; +MODULE_DEVICE_TABLE(of, usb_generic_onboard_dt_ids); + +static struct platform_driver usb_generic_onboard_driver = { + .probe = usb_generic_onboard_probe, + .remove = usb_generic_onboard_remove, + .driver = { + .name = "usb_generic_onboard", + .of_match_table = usb_generic_onboard_dt_ids, + }, +}; + +static int __init usb_generic_onboard_init(void) +{ + return platform_driver_register(&usb_generic_onboard_driver); +} +subsys_initcall(usb_generic_onboard_init); + +static void __exit usb_generic_onboard_exit(void) +{ + platform_driver_unregister(&usb_generic_onboard_driver); +} +module_exit(usb_generic_onboard_exit); + +MODULE_AUTHOR("Peter Chen "); +MODULE_DESCRIPTION("Generic Onboard USB HUB driver"); +MODULE_LICENSE("GPL v2");