From patchwork Tue Jul 5 13:08:34 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 945132 Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p65DRZUj009490 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 5 Jul 2011 13:27:56 GMT Received: from canuck.infradead.org ([2001:4978:20e::1]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1Qe5bk-00044U-86; Tue, 05 Jul 2011 13:24:10 +0000 Received: from localhost ([127.0.0.1] helo=canuck.infradead.org) by canuck.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1Qe5On-0007uj-Km; Tue, 05 Jul 2011 13:10:45 +0000 Received: from mail-fx0-f43.google.com ([209.85.161.43]) by canuck.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1Qe5NX-0007X5-46 for linux-arm-kernel@lists.infradead.org; Tue, 05 Jul 2011 13:09:29 +0000 Received: by mail-fx0-f43.google.com with SMTP id 17so5321658fxg.16 for ; Tue, 05 Jul 2011 06:09:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=tUIAdrFelvkg4BjvrL3bK4lqc5gEv8b5QR4DdyABark=; b=puQagRG1iWRbd+AFcxqv3DTiEVzje1toNr5T4axUONSwC90DdbEnC3wae5RDEurOds BlecUW6D20dtAwqD0crejO7pVPhgJGFaK/DK+5m++SjtjN2FDljtIV/KP6DvRzGQVcRB kuQXkN1q647vGIb0L7jqVILqTju8ZgDwh6c50= Received: by 10.223.6.198 with SMTP id a6mr11232401faa.128.1309871366728; Tue, 05 Jul 2011 06:09:26 -0700 (PDT) Received: from doriath.ww600.siemens.net ([91.213.169.4]) by mx.google.com with ESMTPS id n20sm1952263fad.16.2011.07.05.06.09.22 (version=SSLv3 cipher=OTHER); Tue, 05 Jul 2011 06:09:25 -0700 (PDT) From: Dmitry Eremin-Solenikov To: linux-arm-kernel@lists.infradead.org, linux-usb@vger.kernel.org Subject: [PATCH 08/15] otg: add gpio_pullup OTG transceiver for devices with no VBUS sensing Date: Tue, 5 Jul 2011 17:08:34 +0400 Message-Id: <1309871321-11305-9-git-send-email-dbaryshkov@gmail.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1309871321-11305-1-git-send-email-dbaryshkov@gmail.com> References: <1309871321-11305-1-git-send-email-dbaryshkov@gmail.com> X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20110705_090927_409434_8FF73E25 X-CRM114-Status: GOOD ( 19.54 ) X-Spam-Score: -0.8 (/) X-Spam-Report: SpamAssassin version 3.3.1 on canuck.infradead.org summary: Content analysis details: (-0.8 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.161.43 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (dbaryshkov[at]gmail.com) -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.0 T_TO_NO_BRKTS_FREEMAIL To: misformatted and free email service Cc: Greg Kroah-Hartman , Eric Miao , Felipe Balbi X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Tue, 05 Jul 2011 13:27:56 +0000 (UTC) There are some devices which have D+ pullup GPIO, but no VBUS sensing support. As such they can't be supported by gpio-vbus transceiver but would benefit from OTG transceiver interface support. Provide simple driver that would just handle OTG API for gadgete drivers and provide a way to toggle D+ pullup. Signed-off-by: Dmitry Eremin-Solenikov --- drivers/usb/otg/Kconfig | 8 ++ drivers/usb/otg/Makefile | 1 + drivers/usb/otg/gpio_pullup.c | 159 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 168 insertions(+), 0 deletions(-) create mode 100644 drivers/usb/otg/gpio_pullup.c diff --git a/drivers/usb/otg/Kconfig b/drivers/usb/otg/Kconfig index cf3a245..18b9183 100644 --- a/drivers/usb/otg/Kconfig +++ b/drivers/usb/otg/Kconfig @@ -140,4 +140,12 @@ config FSL_USB2_OTG help Enable this to support Freescale USB OTG transceiver. +config USB_GPIO_PULLUP + tristate "GPIO based peripheral-only D+ pullup handling" + depends on GENERIC_GPIO + select USB_OTG_UTILS + help + Provides simple GPIO D+ pullup handling for controllers with + internal transceiver via the otg_transceiver interface. + endif # USB || OTG diff --git a/drivers/usb/otg/Makefile b/drivers/usb/otg/Makefile index 24d4e63..b482e79 100644 --- a/drivers/usb/otg/Makefile +++ b/drivers/usb/otg/Makefile @@ -22,3 +22,4 @@ obj-$(CONFIG_AB8500_USB) += ab8500-usb.o obj-$(CONFIG_LUBBOCK_USB) += lubbock-usb.o fsl_usb2_otg-objs := fsl_otg.o otg_fsm.o obj-$(CONFIG_FSL_USB2_OTG) += fsl_usb2_otg.o +obj-$(CONFIG_USB_GPIO_PULLUP) += gpio_pullup.o diff --git a/drivers/usb/otg/gpio_pullup.c b/drivers/usb/otg/gpio_pullup.c new file mode 100644 index 0000000..075d269 --- /dev/null +++ b/drivers/usb/otg/gpio_pullup.c @@ -0,0 +1,159 @@ +/* + * gpio_pullup.c - simple GPIO D+ pullup handling for B peripheral devices + * + * Copyright (c) 2011 Dmitry Eremin-Solenikov + * + * Heavily based on gpio_vbus driver: + * + * Copyright (c) 2008 Philipp Zabel + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include +#include +#include +#include + +#include +#include +#include + +struct gpio_pullup_data { + struct otg_transceiver otg; + struct device *dev; +}; + +/* OTG transceiver interface */ + +/* bind/unbind the peripheral controller */ +static int gpio_pullup_set_peripheral(struct otg_transceiver *otg, + struct usb_gadget *gadget) +{ + struct gpio_pullup_data *gpio_pullup; + struct gpio_vbus_mach_info *pdata; + struct platform_device *pdev; + int gpio; + + gpio_pullup = container_of(otg, struct gpio_pullup_data, otg); + pdev = to_platform_device(gpio_pullup->dev); + pdata = gpio_pullup->dev->platform_data; + gpio = pdata->gpio_pullup; + + if (!gadget) { + dev_dbg(&pdev->dev, "unregistering gadget '%s'\n", + otg->gadget->name); + + /* optionally disable D+ pullup */ + gpio_set_value(pdata->gpio_pullup, pdata->gpio_pullup_inverted); + + usb_gadget_vbus_disconnect(otg->gadget); + otg->state = OTG_STATE_UNDEFINED; + + otg->gadget = NULL; + return 0; + } + + otg->gadget = gadget; + dev_dbg(&pdev->dev, "registered gadget '%s'\n", gadget->name); + + /* initialize connection state */ + gpio_pullup->otg.state = OTG_STATE_B_PERIPHERAL; + usb_gadget_vbus_connect(gpio_pullup->otg.gadget); + + gpio_set_value(pdata->gpio_pullup, !pdata->gpio_pullup_inverted); + + return 0; +} + +/* platform driver interface */ + +static int __devinit gpio_pullup_probe(struct platform_device *pdev) +{ + struct gpio_vbus_mach_info *pdata = pdev->dev.platform_data; + struct gpio_pullup_data *gpio_pullup; + int err, gpio; + + if (!pdata || !gpio_is_valid(pdata->gpio_pullup)) + return -EINVAL; + + gpio_pullup = kzalloc(sizeof(struct gpio_pullup_data), GFP_KERNEL); + if (!gpio_pullup) + return -ENOMEM; + + platform_set_drvdata(pdev, gpio_pullup); + gpio_pullup->dev = &pdev->dev; + gpio_pullup->otg.label = "gpio-pullup"; + gpio_pullup->otg.state = OTG_STATE_UNDEFINED; + gpio_pullup->otg.set_peripheral = gpio_pullup_set_peripheral; + + /* if data line pullup is in use, initialize it to "not pulling up" */ + gpio = pdata->gpio_pullup; + err = gpio_request(gpio, "udc_pullup"); + if (err) { + dev_err(&pdev->dev, + "can't request pullup gpio %d, err: %d\n", + gpio, err); + gpio_free(pdata->gpio_pullup); + goto err_gpio; + } + gpio_direction_output(gpio, pdata->gpio_pullup_inverted); + + /* only active when a gadget is registered */ + err = otg_set_transceiver(&gpio_pullup->otg); + if (err) { + dev_err(&pdev->dev, "can't register transceiver, err: %d\n", + err); + goto err_otg; + } + + return 0; +err_otg: + gpio_free(pdata->gpio_pullup); +err_gpio: + platform_set_drvdata(pdev, NULL); + kfree(gpio_pullup); + return err; +} + +static int __devexit gpio_pullup_remove(struct platform_device *pdev) +{ + struct gpio_pullup_data *gpio_pullup = platform_get_drvdata(pdev); + struct gpio_vbus_mach_info *pdata = pdev->dev.platform_data; + + otg_set_transceiver(NULL); + + gpio_free(pdata->gpio_pullup); + platform_set_drvdata(pdev, NULL); + kfree(gpio_pullup); + + return 0; +} + +static struct platform_driver gpio_pullup_driver = { + .driver = { + .name = "gpio-pullup", + .owner = THIS_MODULE, + }, + .probe = gpio_pullup_probe, + .remove = __devexit_p(gpio_pullup_remove), +}; +MODULE_ALIAS("platform:gpio-pullup"); + +static int __init gpio_pullup_init(void) +{ + return platform_driver_register(&gpio_pullup_driver); +} +module_init(gpio_pullup_init); + +static void __exit gpio_pullup_exit(void) +{ + platform_driver_unregister(&gpio_pullup_driver); +} +module_exit(gpio_pullup_exit); + +MODULE_DESCRIPTION("simple GPIO D+ pulllup OTG transceiver driver"); +MODULE_AUTHOR("Dmitry Eremin-Solenikov"); +MODULE_LICENSE("GPL");