From patchwork Mon Dec 14 07:26:12 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Chen X-Patchwork-Id: 7841901 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 9B8CC9F1C2 for ; Mon, 14 Dec 2015 07:32:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 84D4E204DE for ; Mon, 14 Dec 2015 07:32:51 +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 6A4AE20375 for ; Mon, 14 Dec 2015 07:32:50 +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 1a8Nb6-0002JE-El; Mon, 14 Dec 2015 07:31:04 +0000 Received: from mail-bn1bbn0101.outbound.protection.outlook.com ([157.56.111.101] helo=na01-bn1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1a8Nax-0002FH-P9 for linux-arm-kernel@lists.infradead.org; Mon, 14 Dec 2015 07:30:57 +0000 Received: from CH1PR03CA006.namprd03.prod.outlook.com (10.255.156.151) by BY2PR0301MB1991.namprd03.prod.outlook.com (10.163.196.25) with Microsoft SMTP Server (TLS) id 15.1.355.16; Mon, 14 Dec 2015 07:30:32 +0000 Received: from BN1AFFO11FD022.protection.gbl (10.255.156.132) by CH1PR03CA006.outlook.office365.com (10.255.156.151) with Microsoft SMTP Server (TLS) id 15.1.355.16 via Frontend Transport; Mon, 14 Dec 2015 07:30:32 +0000 Authentication-Results: spf=permerror (sender IP is 192.88.168.50) 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 tx30smr01.am.freescale.net (192.88.168.50) by BN1AFFO11FD022.mail.protection.outlook.com (10.58.52.82) with Microsoft SMTP Server (TLS) id 15.1.346.13 via Frontend Transport; Mon, 14 Dec 2015 07:30:31 +0000 Received: from shlinux2.ap.freescale.net (shlinux2.ap.freescale.net [10.192.224.44]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id tBE7UI9a024346; Mon, 14 Dec 2015 00:30:26 -0700 From: Peter Chen To: , , Subject: [PATCH v2 1/3] usb: misc: generic_onboard_hub: add generic onboard USB HUB driver Date: Mon, 14 Dec 2015 15:26:12 +0800 Message-ID: <1450077974-22762-2-git-send-email-peter.chen@freescale.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1450077974-22762-1-git-send-email-peter.chen@freescale.com> References: <1450077974-22762-1-git-send-email-peter.chen@freescale.com> X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; BN1AFFO11FD022; 1:vSNXlduSDAFgHvHoC0BhrMkkE+0JurKKG8XDX809i6dEuryspgLG8duA13+UoPfMGCUYhIAt4bVs/eOPKvo9oJmFgAmdWe63hVW5srEjVFRLxgOQAI8Rk+2lTFZ6NVLmoV45A7hutDhA8xKTCSu46qqS/wUDMo6wsXrbWHohEmvd5dRB/nXzW22jZfZGIrGcCUtBC/31wJpqHqDQ18cB6eHv3um4zmKQFOVwJ5xY6lTX72tzhSODfPP7uk4qs1W8+rJwUEVHuFOPC6tbX99vahPd1mrfbS7/WcQe6KxvjcZaG2MYBIUJwieE8Gk1dpz6zVjdFRVOuPkJYsY7VBcFybo419J6cQ9pZdQ+Eh2I3Nv9l+xhs9r8GLONjL2fsxQmQ4JM3Bu0k1RqhribjI6FXE+P4usJABkDLiHVCkkcTkrr/+h1Jst6RJ9i3iSf36K6hR4BnvOAttCb50IR4H1SRA== X-Forefront-Antispam-Report: CIP:192.88.168.50; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(2980300002)(1060300003)(448002)(189002)(199003)(1096002)(110436001)(81156007)(4001430100002)(229853001)(5008740100001)(47776003)(2201001)(4290100001)(5001770100001)(2950100001)(86362001)(5001960100002)(107886002)(36756003)(33646002)(97736004)(50226001)(106466001)(92566002)(48376002)(104016004)(76176999)(50986999)(6806005)(1220700001)(19580405001)(50466002)(606003)(5003940100001)(19580395003)(15975445007)(11100500001)(87936001)(2171001)(85326001)(77096005)(41533002)(2004002)(217873001); DIR:OUT; SFP:1102; SCL:1; SRVR:BY2PR0301MB1991; H:tx30smr01.am.freescale.net; FPR:; SPF:PermError; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Exchange-Diagnostics: 1; BY2PR0301MB1991; 2:rzUMgzJKstFgsbjanSwVt0BmzdlruT1P+ZVCXghagrSqBsd5dZnDUhPxqy4ZEjY5NPrwGCwei8ihGDK7WY1CAdRx0jkdWfOgv5dYk+c42epx3zdbqVbCO//pjLI9iL/SEquKKbKvM3X+HVdSPi1KPg==; 3:oK2cLU74iaJX8/nyyPUVXm4gA47Fu4ihTK1Yqe/oAlWF47YKIO6D6jGAAcmRf+M/8i2BqEBNkvJMEFwUEI50fOPpy1ETOZxm0q5o60qjTqWBn28tp/lE7eJcjHynDHGkk3CC1XJcRHbLdSa3aRx1KIdHp/eRyfyM+++wPznP0UHnuztuJe6/c2ojyc3NulILxUnpLiDYT3nZrwvmhLh3SBM3LAskYC0a/onqUNDa20A=; 25:VNFwTtp1p/YK7kr8CIF7xFy8Q6qRj25Nw9hf8230kAIZnxfjfU0A5aKT02LJDKpdQtJlCzEgRMh/5Q5pdE1y8vU0qg5osUamU1sA2o3neEqv6k3UeALCg447z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soft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(101931422205132); X-Exchange-Antispam-Report-CFA-Test: BCL:1; PCL:0; RULEID:(601004)(2401047)(5005006)(520078)(8121501046)(1201001)(3002001)(10201501046); SRVR:BY2PR0301MB1991; BCL:1; PCL:0; RULEID:; SRVR:BY2PR0301MB1991; X-Forefront-PRVS: 0790FB1F33 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BY2PR0301MB1991; 23:FyBfmI4QP65hNuCVvJZRAl/LARWFWSndBTlJH65?= =?us-ascii?Q?FAaLpoVDK9as0rzbOM15Z4BKEChVSeKEBZPUpc/DrYAtpcgqJV+LQBULbN29?= =?us-ascii?Q?EEHXFbg+GPHWV5vkLlZeZlWuyh0zLw5XMrpNurBB9tqJ3f0xekQ7SZ5cf3Fc?= =?us-ascii?Q?jfVdnFTXqPmHZDf9MqzweCRUsakGnvF3PVc/9Z7f34tvlM5KM0NjwABdO1XD?= =?us-ascii?Q?Ttcq8ppfBiqnHCAAEaC5g1KZ/JV5euN401h1trK89yvPUSXw4aSTKi7o13g3?= =?us-ascii?Q?VeaSCFv2MGs2UENyUh4pOSxnfBO4yxMNDsSKegolu0MK59pQvDLRly22Yxo4?= =?us-ascii?Q?CkSAnE9rPFC7Y83xOIDSGGVWAsxLtrndrADeHO5tAXWs3cdfjHVxyF+TxoHR?= =?us-ascii?Q?3J6ydQj7GWzqaLqwLAiSXE8d7sNUVN6yUhviIzXQK8GBy1OBBZBHCyioaNW0?= =?us-ascii?Q?UJOT5xCV4EVkClOIqOkyY+rlPQ8Cc/R11A1zU97cHuzbQ3sQMReoQxFcPFk/?= =?us-ascii?Q?pEaQAadixvfOW9lwsZbYHih+OGVmLCdt6K1fqopFNwsna1NEvco0AqCU91tj?= =?us-ascii?Q?RzDOFcz92WCIoGhFCMILB0EvDd/OAvm+LnIJCTGnr8Fw3bSCjcbKILVdKwqb?= =?us-ascii?Q?xHB+f8itbj0uPVCE7gFE8DfCqkr4drUUPlTzpnK8q1PmYMKrJh6plhDRAJWC?= =?us-ascii?Q?Gsgnqy0JXx0bUh3h6nYoywNDXKnZvAZ4xhpYen4hB/E53h8O9zmy/edw5nbp?= =?us-ascii?Q?uhHI0DgrKo8mYuM+/qLtIuqKC3GBY8GCe/Bn9yG4Z2uDXfaVFjaeP+cb8S76?= =?us-ascii?Q?TcDpGQd8nS0hU5/RL20bSC2cunQc+lBNE8OSKfNDlUSxzagKqvteMGaGmgX+?= =?us-ascii?Q?zIrMbdHO7pa0xoRTkue92OHojFl+IBwYlmzim5QJfYEQslhsOXZSAcU4iNnQ?= =?us-ascii?Q?rLI0M1bDWbY7SjSlez7wlyilcOn6WuPBXJDp81SllerPWw169izmsvKH8U8/?= =?us-ascii?Q?ScvIorXsceYX3qUKjNinCjiryhKeFf+MVM9Buwr47/yqt67rGQrroPfxyLFO?= =?us-ascii?Q?PV3u8ySP9/HDD0Ub/9pPV6ss6AiR5gpOZaF6MWiVxM6QsRH19fCBCbo8B5ns?= =?us-ascii?Q?Ds+iauokptda8WIEQRd/gxhhzYkRsiGdKlpq9BGn4x4DtrDDEym8aVQ6aovW?= =?us-ascii?Q?dK7j3e0LQL4VlOJOSzErIKtbqPnh4c4yI0A+9?= X-Microsoft-Exchange-Diagnostics: 1; BY2PR0301MB1991; 5:gA4BOJ/yCSA+ZcTrq2Dld6Hl2xIiGe2isjGEAY4myROxt4dATDi79GKr8ARHxrCGPUWkPthEoGDWlttXf+NIMDkEG/v1acQ9kSFkWeAHi/8BXPnBSZzvXIkJR+AVBMrvse0TZdPrAgnU7lN9QSZjQA==; 24:GuK0hUf9bmkw3e0FUsp379NsRNC6J34u0PaBpZLgnwwzMd+1xMqu/1Vkq7+JNxqdgVXdKyHEzNFGzH4wUTZCOUDh5qn+ykFJbvqjDjDeVP8= X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Dec 2015 07:30:31.6026 (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.168.50]; Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR0301MB1991 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151213_233056_110004_10DCE795 X-CRM114-Status: GOOD ( 25.27 ) 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 HUB 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 HUBs are usually soldered at the board, and they are not hot-plug USB devices. With this patch, the user can configure the HUB'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 the USB HUB reset, 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_hub.c | 143 +++++++++++++++++++++++++++++++++ 4 files changed, 161 insertions(+) create mode 100644 drivers/usb/misc/generic_onboard_hub.c diff --git a/MAINTAINERS b/MAINTAINERS index e9caa4b..cc1981e 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -11121,6 +11121,13 @@ S: Maintained F: Documentation/usb/ohci.txt F: drivers/usb/host/ohci* +USB Generic Onboard HUB 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_hub.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..5ff74ff 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_HUB + tristate "Generic USB Onboard HUB" + help + depends on OF + Say Y here if your board has an onboard HUB, and this hub 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..da52e9a 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_HUB) += generic_onboard_hub.o diff --git a/drivers/usb/misc/generic_onboard_hub.c b/drivers/usb/misc/generic_onboard_hub.c new file mode 100644 index 0000000..7db5b78 --- /dev/null +++ b/drivers/usb/misc/generic_onboard_hub.c @@ -0,0 +1,143 @@ +/* + * usb_hub_generic.c The generic onboard USB HUB 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_hub_generic_data { + struct clk *clk; +}; + +static int usb_hub_generic_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct usb_hub_generic_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_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_hub_generic_remove(struct platform_device *pdev) +{ + struct usb_hub_generic_data *hub_data = platform_get_drvdata(pdev); + + clk_disable_unprepare(hub_data->clk); + + return 0; +} + +static const struct of_device_id usb_hub_generic_dt_ids[] = { + {.compatible = "generic-onboard-hub"}, + { }, +}; +MODULE_DEVICE_TABLE(of, usb_hub_generic_dt_ids); + +static struct platform_driver usb_hub_generic_driver = { + .probe = usb_hub_generic_probe, + .remove = usb_hub_generic_remove, + .driver = { + .name = "usb_hub_generic_onboard", + .of_match_table = usb_hub_generic_dt_ids, + }, +}; + +static int __init usb_hub_generic_init(void) +{ + return platform_driver_register(&usb_hub_generic_driver); +} +subsys_initcall(usb_hub_generic_init); + +static void __exit usb_hub_generic_exit(void) +{ + platform_driver_unregister(&usb_hub_generic_driver); +} +module_exit(usb_hub_generic_exit); + +MODULE_AUTHOR("Peter Chen "); +MODULE_DESCRIPTION("Generic Onboard USB HUB driver"); +MODULE_LICENSE("GPL v2");