From patchwork Tue Oct 25 14:39:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Bailon X-Patchwork-Id: 9394615 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 9556F60231 for ; Tue, 25 Oct 2016 14:42:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 87AB6295DC for ; Tue, 25 Oct 2016 14:42:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7C4322961F; Tue, 25 Oct 2016 14:42:24 +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 99A4E29620 for ; Tue, 25 Oct 2016 14:42:20 +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 1bz2uH-00011r-UK; Tue, 25 Oct 2016 14:40:49 +0000 Received: from mail-wm0-x234.google.com ([2a00:1450:400c:c09::234]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bz2t8-0007Wy-5R for linux-arm-kernel@lists.infradead.org; Tue, 25 Oct 2016 14:39:43 +0000 Received: by mail-wm0-x234.google.com with SMTP id d128so31114533wmf.1 for ; Tue, 25 Oct 2016 07:39:17 -0700 (PDT) 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=RZSE2ztIVR0/DUDI+AHshsTQBCZZ80MQGXXWsErH86I=; b=YyOVy0m7nvkOfumrjd6sHFW/P/yuh6OLn3buNAwYcEmIoRG0Np57VAIoGMKOIrEiQx Wo7z5mhfLP+AcqXM2RckL01U+sGVdQVvnf1+kW9IJSy2XJ6Lo7S83U7yL6IArJt2JpAw 6FG/t0VbzJvvpQ+578F8Eqd2L34mlhjgSc0QYB2LfxM9aGUVj0EjndpI0p+9laVq3YX6 +VIzXy2ezb7NcvRC61poUPUBWRuj9twb6y1dqw0E59Hb7dvKfpOh9zbqqhEtXl629oVc gWDhsHEZgOy1Oc/AFhu8jifU+dSM8o+Ceizx0VjdGGM6ZKY+7g7dMxC5TCNUH6jNXgU5 QcMg== 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=RZSE2ztIVR0/DUDI+AHshsTQBCZZ80MQGXXWsErH86I=; b=OtjuN6R95nVYKu1ieDfWAYz3oOUzM0SRWdvXVnUP0uzbSyQfT1rCOzDn7KF0hRp4Em euoCT/5II+xnbrgrwYsJnZfZJMVL6MfjwZtdI4Ne7Wp9oX9bHpt1LrtnIaCwxy52boID n01B+9TvfYW35aBGUy5mUomfsJS3BG5PMEpKVBxmx02InxvDqCCVUgJXEHs6miHp6GFt x1ARSgtNLIyVBprTViRwImWj4BQfKZlBytGyE61XgKxlmt34uN8mFtaQTaWifyqaZbMN 2Gu7hMVuXR8mHBdpZEY0PxkgOBTpu6Pm9Nm5pK6AQrkl7BHLCQd/nu7KSDbNzTtbD6+3 UfMg== X-Gm-Message-State: ABUngvePnPa184XCGNOlKt4ZLiCGXoyCE44PZwP0Q5vh9CxmZOWEYCCn2gD9q9quiRcIyt27 X-Received: by 10.28.134.74 with SMTP id i71mr3445588wmd.100.1477406355959; Tue, 25 Oct 2016 07:39:15 -0700 (PDT) Received: from localhost.localdomain ([90.63.244.31]) by smtp.gmail.com with ESMTPSA id r72sm4030723wmd.21.2016.10.25.07.39.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 25 Oct 2016 07:39:15 -0700 (PDT) From: Alexandre Bailon To: khilman@baylibre.com, robh+dt@kernel.org, b-liu@ti.com Subject: [PATCH 3/4] usb: musb: da8xx: Add DT support for the DA8xx driver Date: Tue, 25 Oct 2016 16:39:04 +0200 Message-Id: <1477406345-27192-4-git-send-email-abailon@baylibre.com> X-Mailer: git-send-email 2.7.3 In-Reply-To: <1477406345-27192-1-git-send-email-abailon@baylibre.com> References: <1477406345-27192-1-git-send-email-abailon@baylibre.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161025_073938_534716_758B65CD X-CRM114-Status: GOOD ( 17.69 ) 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, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Petr Kulhavy , Alexandre Bailon , 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 From: Petr Kulhavy This adds DT support for TI DA8xx/OMAP-L1x/AM17xx/AM18xx MUSB driver Signed-off-by: Petr Kulhavy Signed-off-by: Alexandre Bailon --- drivers/usb/musb/da8xx.c | 76 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 67 insertions(+), 9 deletions(-) diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c index 210b7e4..d465087 100644 --- a/drivers/usb/musb/da8xx.c +++ b/drivers/usb/musb/da8xx.c @@ -6,6 +6,9 @@ * Based on the DaVinci "glue layer" code. * Copyright (C) 2005-2006 by Texas Instruments * + * DT support + * Copyright (c) 2016 Petr Kulhavy + * * This file is part of the Inventra Controller Driver for Linux. * * The Inventra Controller Driver for Linux is free software; you @@ -433,6 +436,21 @@ static int da8xx_musb_exit(struct musb *musb) return 0; } +static inline u8 get_vbus_power(struct device *dev) +{ + struct regulator *vbus_supply; + int current_uA; + + vbus_supply = regulator_get_optional(dev, "vbus"); + if (IS_ERR(vbus_supply)) + return 255; + current_uA = regulator_get_current_limit(vbus_supply); + regulator_put(vbus_supply); + if (current_uA <= 0 || current_uA > 510000) + return 255; + return current_uA / 1000 / 2; +} + static const struct musb_platform_ops da8xx_ops = { .quirks = MUSB_DMA_CPPI | MUSB_INDEXED_EP, .init = da8xx_musb_init, @@ -458,6 +476,12 @@ static const struct platform_device_info da8xx_dev_info = { .dma_mask = DMA_BIT_MASK(32), }; +static const struct musb_hdrc_config da8xx_config = { + .ram_bits = 10, + .num_eps = 5, + .multipoint = 1, +}; + static int da8xx_probe(struct platform_device *pdev) { struct resource musb_resources[2]; @@ -465,7 +489,9 @@ static int da8xx_probe(struct platform_device *pdev) struct da8xx_glue *glue; struct platform_device_info pinfo; struct clk *clk; + struct device_node *np = pdev->dev.of_node; int ret; + struct resource *res; glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL); if (!glue) @@ -486,6 +512,18 @@ static int da8xx_probe(struct platform_device *pdev) glue->dev = &pdev->dev; glue->clk = clk; + if (IS_ENABLED(CONFIG_OF) && np) { + pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); + if (!pdata) { + /* FIXME */ + return -ENOMEM; + } + + pdata->config = &da8xx_config; + pdata->mode = musb_get_mode(&pdev->dev); + pdata->power = get_vbus_power(&pdev->dev); + } + pdata->platform_ops = &da8xx_ops; glue->usb_phy = usb_phy_generic_register(); @@ -499,15 +537,21 @@ static int da8xx_probe(struct platform_device *pdev) memset(musb_resources, 0x00, sizeof(*musb_resources) * ARRAY_SIZE(musb_resources)); - musb_resources[0].name = pdev->resource[0].name; - musb_resources[0].start = pdev->resource[0].start; - musb_resources[0].end = pdev->resource[0].end; - musb_resources[0].flags = pdev->resource[0].flags; + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!res) { + dev_err(&pdev->dev, "failed to get memory.\n"); + ret = -EINVAL; + goto err_unregister_usb_phy; + } + musb_resources[0] = *res; - musb_resources[1].name = pdev->resource[1].name; - musb_resources[1].start = pdev->resource[1].start; - musb_resources[1].end = pdev->resource[1].end; - musb_resources[1].flags = pdev->resource[1].flags; + res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); + if (!res) { + dev_err(&pdev->dev, "failed to get irq.\n"); + ret = -EINVAL; + goto err_unregister_usb_phy; + } + musb_resources[1] = *res; pinfo = da8xx_dev_info; pinfo.parent = &pdev->dev; @@ -520,9 +564,14 @@ static int da8xx_probe(struct platform_device *pdev) ret = PTR_ERR_OR_ZERO(glue->musb); if (ret) { dev_err(&pdev->dev, "failed to register musb device: %d\n", ret); - usb_phy_generic_unregister(glue->usb_phy); + goto err_unregister_usb_phy; } + return 0; + +err_unregister_usb_phy: + usb_phy_generic_unregister(glue->usb_phy); + return ret; } @@ -536,11 +585,20 @@ static int da8xx_remove(struct platform_device *pdev) return 0; } +static const struct of_device_id da8xx_id_table[] = { + { + .compatible = "ti,da830-musb", + }, + {}, +}; +MODULE_DEVICE_TABLE(of, da8xx_id_table); + static struct platform_driver da8xx_driver = { .probe = da8xx_probe, .remove = da8xx_remove, .driver = { .name = "musb-da8xx", + .of_match_table = of_match_ptr(da8xx_id_table), }, };