From patchwork Wed Dec 10 23:28:38 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Shtylyov X-Patchwork-Id: 5472871 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id AF79F9F1CD for ; Wed, 10 Dec 2014 23:28:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 906DC2018E for ; Wed, 10 Dec 2014 23:28:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6073C2016C for ; Wed, 10 Dec 2014 23:28:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758276AbaLJX2n (ORCPT ); Wed, 10 Dec 2014 18:28:43 -0500 Received: from mail-la0-f54.google.com ([209.85.215.54]:55856 "EHLO mail-la0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756847AbaLJX2m (ORCPT ); Wed, 10 Dec 2014 18:28:42 -0500 Received: by mail-la0-f54.google.com with SMTP id pv20so3321479lab.27 for ; Wed, 10 Dec 2014 15:28:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:organization :user-agent:mime-version:content-transfer-encoding:content-type; bh=Jp8GweYeejnq1nFuAOSnTeK1vD8bMsWX89lJr3x/o5I=; b=m7Ldnr2fhOXF8wre2Y/pXV0bbmnlCFp5JEeLo/dhOS3ozC9CXhiv4TUiN0bqPrICOA /EA6HRw5Q0xzqQMg9P70fibLgfs0sZdLiu3Nr8mMCsUYxPiq08WWZywAGKWXNQ4sVxpn INHv4RUeDVgl2FHZ2e/Knmuv1PuH5WT19A2cGzPiOphcqvNHm26o93HpBVq5OpI5P5s4 eNEZ3/54pxK8GhgrKJ45D14BGPb2n1nJggNY1OR9NrVAIs8f9gxc5db5SE8Sd9+YZNeI rPPCE2ZMOMJchdr5YDWTQgcBPjA4uYrr9WOPv5eW/3WFL1afF2OFzEK5h7hsTG7bHu54 UVXA== X-Gm-Message-State: ALoCoQmu687cGfws4XFV6zHBa1+uXVlCwLzz4Cfzd88sR2QezBgZOx2mqmogFOPNyypMVh1FooO0 X-Received: by 10.152.20.98 with SMTP id m2mr4924007lae.49.1418254120834; Wed, 10 Dec 2014 15:28:40 -0800 (PST) Received: from wasted.cogentembedded.com (ppp83-237-248-248.pppoe.mtu-net.ru. [83.237.248.248]) by mx.google.com with ESMTPSA id pz3sm1604497lbb.27.2014.12.10.15.28.39 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Dec 2014 15:28:39 -0800 (PST) From: Sergei Shtylyov To: robh+dt@kernel.org, pawel.moll@arm.com, mark.rutland@arm.com, ijc+devicetree@hellion.org.uk, galak@codeaurora.org, myungjoo.ham@samsung.com, cw00.choi@samsung.com, grant.likely@linaro.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: linux-sh@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH] extcon: add MAX3355 driver Date: Thu, 11 Dec 2014 02:28:38 +0300 Message-ID: <14631865.01KLlU2iKL@wasted.cogentembedded.com> Organization: Cogent Embedded Inc. User-Agent: KMail/4.14.3 (Linux/3.17.4-200.fc20.x86_64; KDE/4.14.3; x86_64; ; ) MIME-Version: 1.0 Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 MAX3355E chip integrates a charge pump and comparators to enable a system with an integrated USB OTG dual-role transceiver to function as a USB OTG dual-role device. In addition to sensing/controlling Vbus, the chip also passes thru the ID signal from the USB OTG connector. On some Renesas boards, this signal is just fed into the SoC thru a GPIO pin -- there's no real OTG controller, only host and gadget USB controllers sharing the same USB bus; however, we'd like to allow host or gadget drivers to be loaded depending on the cable type, hence the need for the MAX3355 extcon driver. The Vbus status signals are also wired to GPIOs (however, we're not currently intested in them), the OFFVBUS# signal is controlled by the host controllers, there's also the SHDN# signal wired to GPIO, which should be high for normal operation. Signed-off-by: Sergei Shtylyov --- The patch is against the 'extcon-next' branch of the 'extcon.git' repo. Documentation/devicetree/bindings/extcon/extcon-max3355.txt | 21 ++ drivers/extcon/Kconfig | 6 drivers/extcon/Makefile | 1 drivers/extcon/extcon-max3355.c | 122 ++++++++++++ 4 files changed, 150 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe linux-sh" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Index: extcon/Documentation/devicetree/bindings/extcon/extcon-max3355.txt =================================================================== --- /dev/null +++ extcon/Documentation/devicetree/bindings/extcon/extcon-max3355.txt @@ -0,0 +1,21 @@ +MAX3355 USB OTG chip +-------------------- + +MAX3355 integrates a charge pump and comparators to enable a system with an +integrated USB OTG dual-role transceiver to function as a USB OTG dual-role +device. + +Required properties: +- compatible: should be "maxim,max3355"; +- maxim,shdn-gpio: should contain a phandle and GPIO specifier for the GPIO pin + connected to the MAX3355's SHDN# pin; +- maxim,id-gpio: should contain a phandle and GPIO specifier for the GPIO pin + connected to the MAX3355's ID_OUT pin. + +Example (Koelsch board): + + usb-otg { + compatible = "maxim,max3355"; + maxim,shdn-gpio = <&gpio2 4 GPIO_ACTIVE_LOW>; + maxim,id-gpio = <&gpio5 31 GPIO_ACTIVE_HIGH>; + }; Index: extcon/drivers/extcon/Kconfig =================================================================== --- extcon.orig/drivers/extcon/Kconfig +++ extcon/drivers/extcon/Kconfig @@ -45,6 +45,12 @@ config EXTCON_MAX14577 Maxim MAX14577/77836. The MAX14577/77836 MUIC is a USB port accessory detector and switch. +config EXTCON_MAX3355 + tristate "MAX3355 USB OTG EXTCON Support" + help + Say Y here to enable support for the USB host detection by MAX3355 + OTG USB chip. + config EXTCON_MAX77693 tristate "MAX77693 EXTCON Support" depends on MFD_MAX77693 && INPUT Index: extcon/drivers/extcon/Makefile =================================================================== --- extcon.orig/drivers/extcon/Makefile +++ extcon/drivers/extcon/Makefile @@ -7,6 +7,7 @@ obj-$(CONFIG_EXTCON_ADC_JACK) += extcon- obj-$(CONFIG_EXTCON_ARIZONA) += extcon-arizona.o obj-$(CONFIG_EXTCON_GPIO) += extcon-gpio.o obj-$(CONFIG_EXTCON_MAX14577) += extcon-max14577.o +obj-$(CONFIG_EXTCON_MAX3355) += extcon-max3355.o obj-$(CONFIG_EXTCON_MAX77693) += extcon-max77693.o obj-$(CONFIG_EXTCON_MAX8997) += extcon-max8997.o obj-$(CONFIG_EXTCON_PALMAS) += extcon-palmas.o Index: extcon/drivers/extcon/extcon-max3355.c =================================================================== --- /dev/null +++ extcon/drivers/extcon/extcon-max3355.c @@ -0,0 +1,122 @@ +/* + * MAX3355 USB OTG chip extcon driver + * + * Copyright (C) 2014 Cogent Embedded, Inc. + * Author: Sergei Shtylyov + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct max3355_data { + struct extcon_dev *edev; + int id_gpio; +}; + +static const char *max3355_cable[] = { + [0] = "USB-HOST", + NULL, +}; + +static irqreturn_t max3355_id_irq(int irq, void *dev_id) +{ + struct max3355_data *data = dev_id; + int id = gpio_get_value(data->id_gpio); + + extcon_set_cable_state(data->edev, "USB-HOST", !id); + + return IRQ_HANDLED; +} + +static int max3355_probe(struct platform_device *pdev) +{ + struct device_node *np = pdev->dev.of_node; + struct max3355_data *data; + int gpio, irq, ret; + + data = devm_kzalloc(&pdev->dev, sizeof(struct max3355_data), + GFP_KERNEL); + if (!data) + return -ENOMEM; + + data->edev = devm_extcon_dev_allocate(&pdev->dev, max3355_cable); + if (IS_ERR(data->edev)) { + dev_err(&pdev->dev, "failed to allocate extcon device\n"); + return PTR_ERR(data->edev); + } + data->edev->name = kstrdup(np->name, GFP_KERNEL); + + gpio = of_get_named_gpio(np, "maxim,id-gpio", 0); + if (gpio < 0) + return gpio; + data->id_gpio = gpio; + + gpio = of_get_named_gpio(np, "maxim,shdn-gpio", 0); + if (gpio < 0) + return gpio; + + ret = devm_gpio_request_one(&pdev->dev, gpio, GPIOF_DIR_OUT | + GPIOF_INIT_HIGH, pdev->name); + if (ret < 0) + return ret; + + ret = devm_gpio_request_one(&pdev->dev, data->id_gpio, GPIOF_DIR_IN, + pdev->name); + if (ret < 0) + return ret; + + ret = devm_extcon_dev_register(&pdev->dev, data->edev); + if (ret < 0) + return ret; + + irq = gpio_to_irq(data->id_gpio); + if (irq < 0) + return irq; + + ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, max3355_id_irq, + IRQF_TRIGGER_RISING | + IRQF_TRIGGER_FALLING | IRQF_ONESHOT, + pdev->name, data); + if (ret < 0) + return ret; + + platform_set_drvdata(pdev, data); + + /* Perform initial detection */ + max3355_id_irq(irq, data); + + return 0; +} + +static const struct of_device_id max3355_match_table[] = { + { .compatible = "maxim,max3355", }, + { } +}; +MODULE_DEVICE_TABLE(of, max3355_match_table); + +static struct platform_driver max3355_driver = { + .probe = max3355_probe, + .driver = { + .name = "extcon-max3355", + .of_match_table = max3355_match_table, + .owner = THIS_MODULE, + }, +}; + +module_platform_driver(max3355_driver); + +MODULE_AUTHOR("Sergei Shtylyov "); +MODULE_DESCRIPTION("MAX3355 extcon driver"); +MODULE_LICENSE("GPL v2");