From patchwork Sun Jun 9 22:40:05 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaro Koskinen X-Patchwork-Id: 2695351 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) by patchwork2.kernel.org (Postfix) with ESMTP id E0323DF2A1 for ; Sun, 9 Jun 2013 22:42:19 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UloIc-00053L-Be; Sun, 09 Jun 2013 22:41:22 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UloIN-0005KX-9c; Sun, 09 Jun 2013 22:41:07 +0000 Received: from filtteri1.pp.htv.fi ([213.243.153.184]) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UloHy-0005HU-1I for linux-arm-kernel@lists.infradead.org; Sun, 09 Jun 2013 22:40:44 +0000 Received: from localhost (localhost [127.0.0.1]) by filtteri1.pp.htv.fi (Postfix) with ESMTP id 6A04BC119; Mon, 10 Jun 2013 01:40:19 +0300 (EEST) X-Virus-Scanned: Debian amavisd-new at pp.htv.fi Received: from smtp6.welho.com ([213.243.153.40]) by localhost (filtteri1.pp.htv.fi [213.243.153.184]) (amavisd-new, port 10024) with ESMTP id 2tlmKmLb3VnT; Mon, 10 Jun 2013 01:40:14 +0300 (EEST) Received: from blackmetal.pp.htv.fi (cs181064211.pp.htv.fi [82.181.64.211]) by smtp6.welho.com (Postfix) with ESMTP id 6AD605BC005; Mon, 10 Jun 2013 01:40:14 +0300 (EEST) From: Aaro Koskinen To: linux-usb@vger.kernel.org, linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Felipe Balbi , Tony Lindgren Subject: [PATCH 2/3] USB: OMAP: add omap-otg Date: Mon, 10 Jun 2013 01:40:05 +0300 Message-Id: <1370817606-1008-3-git-send-email-aaro.koskinen@iki.fi> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1370817606-1008-1-git-send-email-aaro.koskinen@iki.fi> References: <1370817606-1008-1-git-send-email-aaro.koskinen@iki.fi> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130609_184042_498235_1DCCC40F X-CRM114-Status: GOOD ( 20.07 ) X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [213.243.153.184 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Aaro Koskinen X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Transceivers need to manage OTG controller state on OMAP1 to enable switching between peripheral and host modes. Provide a driver for that. Signed-off-by: Aaro Koskinen --- drivers/usb/phy/Kconfig | 10 ++++ drivers/usb/phy/Makefile | 1 + drivers/usb/phy/phy-omap-otg.c | 126 ++++++++++++++++++++++++++++++++++++++++ include/linux/usb/omap-otg.h | 19 ++++++ 4 files changed, 156 insertions(+) create mode 100644 drivers/usb/phy/phy-omap-otg.c create mode 100644 include/linux/usb/omap-otg.h diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig index 7ef3eb8..2d2cd5f 100644 --- a/drivers/usb/phy/Kconfig +++ b/drivers/usb/phy/Kconfig @@ -135,6 +135,16 @@ config USB_GPIO_VBUS optionally control of a D+ pullup GPIO as well as a VBUS current limit regulator. +config OMAP_OTG + tristate "OMAP USB OTG controller driver" + depends on ARCH_OMAP_OTG + help + Enable this to support some transceivers on OMAP1 platforms. OTG + controller is needed to switch between host and peripheral modes. + + This driver can also be built as a module. If so, the module + will be called omap-otg. + config USB_ISP1301 tristate "NXP ISP1301 USB transceiver support" depends on USB || USB_GADGET diff --git a/drivers/usb/phy/Makefile b/drivers/usb/phy/Makefile index a9169cb..c7f391b 100644 --- a/drivers/usb/phy/Makefile +++ b/drivers/usb/phy/Makefile @@ -15,6 +15,7 @@ obj-$(CONFIG_ISP1301_OMAP) += phy-isp1301-omap.o obj-$(CONFIG_MV_U3D_PHY) += phy-mv-u3d-usb.o obj-$(CONFIG_NOP_USB_XCEIV) += phy-nop.o obj-$(CONFIG_OMAP_CONTROL_USB) += phy-omap-control.o +obj-$(CONFIG_OMAP_OTG) += phy-omap-otg.o obj-$(CONFIG_OMAP_USB2) += phy-omap-usb2.o obj-$(CONFIG_OMAP_USB3) += phy-omap-usb3.o obj-$(CONFIG_SAMSUNG_USBPHY) += phy-samsung-usb.o diff --git a/drivers/usb/phy/phy-omap-otg.c b/drivers/usb/phy/phy-omap-otg.c new file mode 100644 index 0000000..cb00ffe --- /dev/null +++ b/drivers/usb/phy/phy-omap-otg.c @@ -0,0 +1,126 @@ +/* + * OMAP OTG controller driver + * + * Based on code from tahvo-usb.c and isp1301_omap.c drivers. + * + * Copyright (C) 2005-2006 Nokia Corporation + * Copyright (C) 2004 Texas Instruments + * Copyright (C) 2004 David Brownell + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * 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. + */ + +#include +#include +#include +#include +#include +#include +#include + +struct otg_device { + void __iomem *base; + struct mutex serialize; +}; +static struct otg_device *otg_dev; + +#define OMAP_OTG_CTRL (otg_dev->base + 0x0c) +#define OMAP_OTG_ASESSVLD (1 << 20) +#define OMAP_OTG_BSESSEND (1 << 19) +#define OMAP_OTG_BSESSVLD (1 << 18) +#define OMAP_OTG_VBUSVLD (1 << 17) +#define OMAP_OTG_ID (1 << 16) +#define OMAP_OTG_XCEIV_OUTPUTS \ + (OMAP_OTG_ASESSVLD | OMAP_OTG_BSESSEND | OMAP_OTG_BSESSVLD | \ + OMAP_OTG_VBUSVLD | OMAP_OTG_ID) + +static void omap_otg_ctrl(u32 outputs) +{ + u32 l; + + l = readl(OMAP_OTG_CTRL); + l &= ~OMAP_OTG_XCEIV_OUTPUTS; + l |= outputs; + writel(l, OMAP_OTG_CTRL); +} + +void omap_otg_set_mode(enum omap_otg_mode mode) +{ + if (!otg_dev) { + WARN(1, "%s: controller not present\n", __func__); + return; + } + mutex_lock(&otg_dev->serialize); + switch (mode) { + case OMAP_OTG_MODE_DEVICE: + /* + * Set B-session valid. + */ + omap_otg_ctrl(OMAP_OTG_ID | OMAP_OTG_BSESSVLD); + break; + case OMAP_OTG_MODE_HOST: + /* + * Set A-session valid. + */ + omap_otg_ctrl(OMAP_OTG_ASESSVLD); + break; + case OMAP_OTG_MODE_DISCONNECT: + /* + * Set B-session end to indicate no VBUS. + */ + omap_otg_ctrl(OMAP_OTG_ID | OMAP_OTG_BSESSEND); + break; + default: + WARN(1, "%s: unknown mode: %d\n", __func__, mode); + } + mutex_unlock(&otg_dev->serialize); +} +EXPORT_SYMBOL_GPL(omap_otg_set_mode); + +static int omap_otg_probe(struct platform_device *dev) +{ + struct otg_device *odev; + u32 rev; + + if (otg_dev) + return -EBUSY; + + odev = devm_kzalloc(&dev->dev, sizeof(*odev), GFP_KERNEL); + if (!odev) + return -ENOMEM; + + odev->base = devm_ioremap_resource(&dev->dev, &dev->resource[0]); + if (IS_ERR(odev->base)) + return PTR_ERR(odev->base); + + rev = readl(odev->base); + dev_info(&dev->dev, "OMAP USB OTG controller rev %d.%d\n", + (rev >> 4) & 0xf, rev & 0xf); + + mutex_init(&odev->serialize); + + otg_dev = odev; + + return 0; +} + +static struct platform_driver omap_otg_driver = { + .probe = omap_otg_probe, + .driver = { + .owner = THIS_MODULE, + .name = "omap_otg", + }, +}; +module_platform_driver(omap_otg_driver); + +MODULE_DESCRIPTION("OMAP USB OTG controller driver"); +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Aaro Koskinen "); diff --git a/include/linux/usb/omap-otg.h b/include/linux/usb/omap-otg.h new file mode 100644 index 0000000..fb3d7ab --- /dev/null +++ b/include/linux/usb/omap-otg.h @@ -0,0 +1,19 @@ +/* + * OMAP OTG driver + * + * This file is subject to the terms and conditions of the GNU General Public + * License. See the file "COPYING" in the main directory of this archive for + * more details. + */ +#ifndef __LINUX_OMAP_OTG_H +#define __LINUX_OMAP_OTG_H + +enum omap_otg_mode { + OMAP_OTG_MODE_DEVICE, + OMAP_OTG_MODE_HOST, + OMAP_OTG_MODE_DISCONNECT, +}; + +void omap_otg_set_mode(enum omap_otg_mode mode); + +#endif /* __LINUX_OMAP_OTG_H */