From patchwork Sun Oct 28 15:42:26 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasily Khoruzhick X-Patchwork-Id: 1657871 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id A436ADFABE for ; Sun, 28 Oct 2012 15:45:57 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TSV1z-0006lE-2i; Sun, 28 Oct 2012 15:44:07 +0000 Received: from mail-la0-f49.google.com ([209.85.215.49]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1TSV1t-0006kN-NE for linux-arm-kernel@lists.infradead.org; Sun, 28 Oct 2012 15:44:03 +0000 Received: by mail-la0-f49.google.com with SMTP id z14so3192098lag.36 for ; Sun, 28 Oct 2012 08:43:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=cCJEpqsrKdRNxQbDbW8yrbi0e1AUd/OmBJhwFnYtxRM=; b=DHKIvkCB4M8PjFDlL2Q+EAZHVDVz4jKMwO97OjXvTTGUgj3AA+J7VKDg03RCfNYBjC JhWvwasmGF/sdgHOJTQnuZ56FxkUFoOY8dW29mG7MEAZ8W5L8ojxY+uSkcQi/INj2khb 6j53Kgc1UyKb1DJc5EmYg8aimwkz7yZZfPQYsOHLVY5+ggWXLo5O/iVy2qME8EZAkz1E bCg0z9G45VRzulDIr+CSi7W6+pVGSkBwbasDkcF6ZmvE6oPDDZy4eFrjtt6Du9X/XliS f4PDSmaIvkPjsa5RJi3sy+AReajbXLGx4b18qXrGAW4Sus3l3GCQYfgCwfoKpC+pJaDc vYfg== Received: by 10.112.101.72 with SMTP id fe8mr11041806lbb.107.1351439038366; Sun, 28 Oct 2012 08:43:58 -0700 (PDT) Received: from localhost.localdomain ([80.249.90.60]) by mx.google.com with ESMTPS id i7sm2276573lbg.13.2012.10.28.08.43.56 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 28 Oct 2012 08:43:57 -0700 (PDT) From: Vasily Khoruzhick To: Eric Miao , Russell King , Haojian Zhuang , Marek Vasut , linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 1/5] ARM: PXA: Add z2-usb-switch driver Date: Sun, 28 Oct 2012 18:42:26 +0300 Message-Id: <1351438946-5331-1-git-send-email-anarsoul@gmail.com> X-Mailer: git-send-email 1.7.12.4 In-Reply-To: References: X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.215.49 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (anarsoul[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -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 Cc: Vasily Khoruzhick X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 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 This driver controls mode of USB port #2 pins - device or host. Signed-off-by: Vasily Khoruzhick --- arch/arm/mach-pxa/Kconfig | 7 +++ arch/arm/mach-pxa/Makefile | 1 + arch/arm/mach-pxa/z2-usb-switch.c | 100 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 arch/arm/mach-pxa/z2-usb-switch.c diff --git a/arch/arm/mach-pxa/Kconfig b/arch/arm/mach-pxa/Kconfig index 11aa739..5fffc4b 100644 --- a/arch/arm/mach-pxa/Kconfig +++ b/arch/arm/mach-pxa/Kconfig @@ -630,6 +630,13 @@ config MACH_ZIPIT2 bool "Zipit Z2 Handheld" select HAVE_PWM select PXA27x + +config Z2_USB_SWITCH + tristate "Control the state of USB port on Zipit Z2" + depends on MACH_ZIPIT2 + help + This is a simple driver that is able to control + usb mode of Zipit Z2 endif endmenu diff --git a/arch/arm/mach-pxa/Makefile b/arch/arm/mach-pxa/Makefile index ee88d6e..86a032f 100644 --- a/arch/arm/mach-pxa/Makefile +++ b/arch/arm/mach-pxa/Makefile @@ -99,3 +99,4 @@ obj-$(CONFIG_MACH_RAUMFELD_SPEAKER) += raumfeld.o obj-$(CONFIG_MACH_ZIPIT2) += z2.o obj-$(CONFIG_TOSA_BT) += tosa-bt.o +obj-$(CONFIG_Z2_USB_SWITCH) += z2-usb-switch.o diff --git a/arch/arm/mach-pxa/z2-usb-switch.c b/arch/arm/mach-pxa/z2-usb-switch.c new file mode 100644 index 0000000..9583092 --- /dev/null +++ b/arch/arm/mach-pxa/z2-usb-switch.c @@ -0,0 +1,100 @@ +/* + * USB mode switcher for Z2 + * + * Copyright (c) 2011 Vasily Khoruzhick + * + * 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 + +#define MIN(a, b) ((a) < (b) ? (a) : (b)) + +static ssize_t usb_mode_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + if (UP2OCR & UP2OCR_HXS) + return sprintf(buf, "host\n"); + else + return sprintf(buf, "device\n"); +} + +static ssize_t usb_mode_set(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + if (strncmp(buf, "host", MIN(count, 4)) == 0) { + UP2OCR = UP2OCR_HXS | UP2OCR_HXOE | UP2OCR_DPPDE | UP2OCR_DMPDE; + return count; + } else if (strncmp(buf, "device", MIN(count, 6)) == 0) { + UP2OCR = UP2OCR_HXOE | UP2OCR_DPPUE; + return count; + } + return -EINVAL; +} + +static DEVICE_ATTR(usb_mode, 0644, usb_mode_show, usb_mode_set); + +static const struct attribute *attrs[] = { + &dev_attr_usb_mode.attr, + NULL, +}; + +static const struct attribute_group attr_group = { + .attrs = (struct attribute **)attrs, +}; + +static int z2_usb_switch_probe(struct platform_device *dev) +{ + int res; + + res = sysfs_create_group(&dev->dev.kobj, &attr_group); + if (res) + return res; + + UP2OCR = UP2OCR_HXOE | UP2OCR_DPPUE; + + return 0; +} + +static int __devexit z2_usb_switch_remove(struct platform_device *dev) +{ + UP2OCR = UP2OCR_HXOE; + sysfs_remove_group(&dev->dev.kobj, &attr_group); + + return 0; +} + +static struct platform_driver z2_usb_switch_driver = { + .probe = z2_usb_switch_probe, + .remove = __devexit_p(z2_usb_switch_remove), + + .driver = { + .name = "z2-usb-switch", + .owner = THIS_MODULE, + }, +}; + + +static int __init z2_usb_switch_init(void) +{ + return platform_driver_register(&z2_usb_switch_driver); +} + +static void __exit z2_usb_switch_exit(void) +{ + platform_driver_unregister(&z2_usb_switch_driver); +} + +module_init(z2_usb_switch_init); +module_exit(z2_usb_switch_exit);