From patchwork Mon Nov 7 20:39:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Haslam X-Patchwork-Id: 9416047 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D78956022E for ; Mon, 7 Nov 2016 20:43:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C925328D24 for ; Mon, 7 Nov 2016 20:43:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BBBDD28E03; Mon, 7 Nov 2016 20:43:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=unavailable version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 2B65A28D24 for ; Mon, 7 Nov 2016 20:43:30 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1c3qk5-0001pd-Q5; Mon, 07 Nov 2016 20:42:09 +0000 Received: from mail-wm0-x22a.google.com ([2a00:1450:400c:c09::22a]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1c3qif-0001Il-Pt for linux-arm-kernel@lists.infradead.org; Mon, 07 Nov 2016 20:40:43 +0000 Received: by mail-wm0-x22a.google.com with SMTP id a197so206631985wmd.0 for ; Mon, 07 Nov 2016 12:40:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=x+NSflNPkSON3xFnyecU/m4ySpOxfE+FWpxQp7JAvgU=; b=CrcoKhjDZNUBlMv42r/72iH/oVtear7OPOAlmsaG4bL/LN8ftIx5FCoPDCNe/HaTug PId5v/OFqdV35qroSxtTTU8YbzVdq4BR+V87iGo1nIbeyNmu89Is/BeElOfH8QByRNjr IgkShZQjX1VS25pjN2K+QTLhMIE6yVwa971dxVyMda27AeuFU/ep+80ApBSCQhm1Syw/ d3zUGfiZo952PYWc3BPkBnLfAq7/ltzjznPyCQN5tHWZqkNmC4H+VhOxOv8kkjgajX4T Tt/vBjVQFxc/qtx/oZB99aoEy/vkyJBCEPXB2Pfan1J/ueJNa0VP0d6Bx1TxRCNMtX8o 77hw== 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:in-reply-to :references; bh=x+NSflNPkSON3xFnyecU/m4ySpOxfE+FWpxQp7JAvgU=; b=AYPbAgHuDekx+Kws6ug65X+3JeYEN/BXsx/ocW6KJmKLU13Xl49p1hnKwJ15kcX/+5 niNvkJl3L/Ajakf/vxKs9T1K+gHsCSolh5qKOd0oplM4RxGmbHhUiW30pkJiacxBPV6H 8+1Tnf9cFkHrmJB2acy4gFMMNn7Ksn+tPyNpNPPG9EnSyc048FCaLUBTFSk93Nlyc46B HNb1Lwt5//uMQhucc3lhPFqtj0h1aBCSQk8OQw4Xcsf5J/WFCsIHACHb4DxIU+m8K+wY LsHSpmhCBBJaqmtVXvhyxIxr6L9mn2QlRIZ0Nq7PayF9sPiOBHo4JQ1vJzV7wjzUAgyr 7Low== X-Gm-Message-State: ABUngveZYy14LHGrN2IwdJWMAuH9AnlNqYwmzqVMhHuxVy1JsLisk2cIFlJ7NuVruP/EKW/7 X-Received: by 10.28.67.69 with SMTP id q66mr5769992wma.22.1478551219955; Mon, 07 Nov 2016 12:40:19 -0800 (PST) Received: from localhost.localdomain (ANice-652-1-139-209.w83-201.abo.wanadoo.fr. [83.201.210.209]) by smtp.gmail.com with ESMTPSA id r7sm19626644wjp.43.2016.11.07.12.40.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 07 Nov 2016 12:40:19 -0800 (PST) From: Axel Haslam To: stern@rowland.harvard.edu, gregkh@linuxfoundation.org, nsekhar@ti.com, khilman@kernel.org, david@lechnology.com, robh+dt@kernel.org Subject: [PATCH v3 04/10] ARM: davinci: da830: Handle vbus with a regulator Date: Mon, 7 Nov 2016 21:39:42 +0100 Message-Id: <20161107203948.28324-5-ahaslam@baylibre.com> X-Mailer: git-send-email 2.10.1.502.g6598894 In-Reply-To: <20161107203948.28324-1-ahaslam@baylibre.com> References: <20161107203948.28324-1-ahaslam@baylibre.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161107_124042_085361_16185F14 X-CRM114-Status: GOOD ( 16.24 ) 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: devicetree@vger.kernel.org, Axel Haslam , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The usb driver can now take a regulator instead of the platform callbacks for vbus handling. Lets use a regulator so we can remove the callbacks in a later patch. Signed-off-by: Axel Haslam --- arch/arm/mach-davinci/board-da830-evm.c | 108 +++++++++++--------------------- 1 file changed, 38 insertions(+), 70 deletions(-) diff --git a/arch/arm/mach-davinci/board-da830-evm.c b/arch/arm/mach-davinci/board-da830-evm.c index 5db0901..16a401a 100644 --- a/arch/arm/mach-davinci/board-da830-evm.c +++ b/arch/arm/mach-davinci/board-da830-evm.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -28,6 +29,7 @@ #include #include #include +#include #include #include @@ -38,72 +40,48 @@ #include #define DA830_EVM_PHY_ID "" -/* - * USB1 VBUS is controlled by GPIO1[15], over-current is reported on GPIO2[4]. - */ -#define ON_BD_USB_DRV GPIO_TO_PIN(1, 15) -#define ON_BD_USB_OVC GPIO_TO_PIN(2, 4) static const short da830_evm_usb11_pins[] = { DA830_GPIO1_15, DA830_GPIO2_4, -1 }; -static da8xx_ocic_handler_t da830_evm_usb_ocic_handler; - -static int da830_evm_usb_set_power(unsigned port, int on) -{ - gpio_set_value(ON_BD_USB_DRV, on); - return 0; -} +static struct regulator_consumer_supply usb_ohci_consumer_supply = + REGULATOR_SUPPLY("vbus", "ohci-da8xx"); -static int da830_evm_usb_get_power(unsigned port) -{ - return gpio_get_value(ON_BD_USB_DRV); -} - -static int da830_evm_usb_get_oci(unsigned port) -{ - return !gpio_get_value(ON_BD_USB_OVC); -} - -static irqreturn_t da830_evm_usb_ocic_irq(int, void *); - -static int da830_evm_usb_ocic_notify(da8xx_ocic_handler_t handler) -{ - int irq = gpio_to_irq(ON_BD_USB_OVC); - int error = 0; - - if (handler != NULL) { - da830_evm_usb_ocic_handler = handler; - - error = request_irq(irq, da830_evm_usb_ocic_irq, - IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, - "OHCI over-current indicator", NULL); - if (error) - pr_err("%s: could not request IRQ to watch over-current indicator changes\n", - __func__); - } else - free_irq(irq, NULL); - - return error; -} +static struct regulator_init_data usb_ohci_initdata = { + .consumer_supplies = &usb_ohci_consumer_supply, + .num_consumer_supplies = 1, + .constraints = { + .valid_ops_mask = REGULATOR_CHANGE_STATUS, + }, +}; -static struct da8xx_ohci_root_hub da830_evm_usb11_pdata = { - .set_power = da830_evm_usb_set_power, - .get_power = da830_evm_usb_get_power, - .get_oci = da830_evm_usb_get_oci, - .ocic_notify = da830_evm_usb_ocic_notify, +static struct fixed_voltage_config usb_ohci_config = { + .supply_name = "vbus", + .microvolts = 5000000, + .gpio = GPIO_TO_PIN(1, 15), + .enable_high = 1, + .enabled_at_boot = 0, + .init_data = &usb_ohci_initdata, +}; - /* TPS2065 switch @ 5V */ - .potpgt = (3 + 1) / 2, /* 3 ms max */ +static struct platform_device da8xx_usb11_regulator = { + .name = "reg-fixed-voltage", + .id = 0, + .dev = { + .platform_data = &usb_ohci_config, + }, }; -static irqreturn_t da830_evm_usb_ocic_irq(int irq, void *dev_id) -{ - da830_evm_usb_ocic_handler(&da830_evm_usb11_pdata, 1); - return IRQ_HANDLED; -} +static struct gpiod_lookup_table usb11_gpios_table = { + .dev_id = "reg-fixed-voltage.0", + .table = { + /* gpio chip 1 contains gpio range 32-63 */ + GPIO_LOOKUP("davinci_gpio.1", 4, "over-current", + GPIO_ACTIVE_LOW), + }, +}; static __init void da830_evm_usb_init(void) { @@ -145,23 +123,13 @@ static __init void da830_evm_usb_init(void) return; } - ret = gpio_request(ON_BD_USB_DRV, "ON_BD_USB_DRV"); - if (ret) { - pr_err("%s: failed to request GPIO for USB 1.1 port power control: %d\n", - __func__, ret); - return; - } - gpio_direction_output(ON_BD_USB_DRV, 0); + gpiod_add_lookup_table(&usb11_gpios_table); - ret = gpio_request(ON_BD_USB_OVC, "ON_BD_USB_OVC"); - if (ret) { - pr_err("%s: failed to request GPIO for USB 1.1 port over-current indicator: %d\n", - __func__, ret); - return; - } - gpio_direction_input(ON_BD_USB_OVC); + ret = platform_device_register(&da8xx_usb11_regulator); + if (ret) + pr_warn("fail to add ohci regulator\n"); - ret = da8xx_register_usb11(&da830_evm_usb11_pdata); + ret = da8xx_register_usb11(NULL); if (ret) pr_warn("%s: USB 1.1 registration failed: %d\n", __func__, ret); }