From patchwork Tue Sep 18 08:16:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 146883 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp4736173ljw; Tue, 18 Sep 2018 01:17:31 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaR2+t7ufmvi4nL/F+g7GviK46/Gc3v4mG4a9amQqDyAvGFT8ItBIz7f1K7zVxgx1jJFBqr X-Received: by 2002:a65:5144:: with SMTP id g4-v6mr26260090pgq.21.1537258651515; Tue, 18 Sep 2018 01:17:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537258651; cv=none; d=google.com; s=arc-20160816; b=ij5QLwnF5apIFPPZTN4chGOEohVljAn4UcN2vUORtC6SMZT4Oi5zZSNlHM/OQTlYha xy1ouPAH0P4YQulyI+CY3VstExc32mk6qSEkuESwWnnaybMc4gQdXuxXKpH6EinYqXLC j6CwEvo2Jq9m233e46KK9iHPLpFIGa30Wnq1PW2zY4GmN1utg/g90tZbA7srUyW5WqJ4 pZsE0yOe0oaMNaq47LB+qWq5xfYSMvs26RfLvtuafdGzm1XoKnVP9xhXG8RbanDy6vki Kx7DJ9hLuuejELjJXt15IAEsq+k/cZfs88pVElBnexKCeOOekaPECNWY+TVFmWvyNuTR OnUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:cms-type:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:dkim-filter; bh=eoR6xCYPgnXFsAtjPHy54Ga2H2OkuXw5dnyP9JlKCFg=; b=tBzapBlXn1/WFg9nsZITzjkQi4/X2EKCR43NSUHIe78AaesFsUy9Sbn3vtZA2shbuS uNhwlv/moqTttQGNnxoUFXyUv0gxwsbX2Oiec+bo/aAiDVoii2EXcyHhatIyAOu4xMwS WS+wkLn+kDJQQH4bw2LeJcDOnqIkKJwQyNliJ1x/6P+e811QU+mEgNruFwZLp+CB9jME abOLJVnDM8pcIaNn3vaNQcKoMioBk7FCr+pjJXwS9oNsKTNzqwu0axoa2LBWUhootwfY yVFoGeNeju8Wg6287kz/6fEP2f+ZZHdBER/m6Jx9qPL1DYlA2EShZkaihrbjhUhVxdT3 y8fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=c+MuobOp; spf=pass (google.com: best guess record for domain of linux-usb-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-usb-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y15-v6si18364541pff.117.2018.09.18.01.17.30; Tue, 18 Sep 2018 01:17:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-usb-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=c+MuobOp; spf=pass (google.com: best guess record for domain of linux-usb-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-usb-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729176AbeIRNs6 (ORCPT + 5 others); Tue, 18 Sep 2018 09:48:58 -0400 Received: from mailout2.w1.samsung.com ([210.118.77.12]:36647 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729009AbeIRNsk (ORCPT ); Tue, 18 Sep 2018 09:48:40 -0400 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20180918081708euoutp029aeb895dbe99408a755896947c1466ef~VcJQELsVM2950829508euoutp02Q; Tue, 18 Sep 2018 08:17:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20180918081708euoutp029aeb895dbe99408a755896947c1466ef~VcJQELsVM2950829508euoutp02Q DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1537258628; bh=eoR6xCYPgnXFsAtjPHy54Ga2H2OkuXw5dnyP9JlKCFg=; h=From:To:Cc:Subject:Date:In-reply-to:References:From; b=c+MuobOpcp9M4wnkLDQrJsRXaS2k0G9I2DY/84N4RoLAx/LlOgnwEoaoWTAZdIsuH aYBhHrJu587968KdRgJW6+FsyTMcT6nWAiEt8u2vWd0lzGITqtf6WHqeJozFTfOos/ XAEhbOQJhSEkDwjnRubIzuDjzN5OjqTTWC9Q+nMo= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20180918081708eucas1p2ed1c0e53e42823746289f55cf9e073c0~VcJPgqYUM1987119871eucas1p22; Tue, 18 Sep 2018 08:17:08 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 34.4D.04294.384B0AB5; Tue, 18 Sep 2018 09:17:07 +0100 (BST) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20180918081707eucas1p11cf21da4c14282d927c0c93652af4ce0~VcJOvmN8H2688326883eucas1p1P; Tue, 18 Sep 2018 08:17:07 +0000 (GMT) X-AuditID: cbfec7f4-c77a99c0000010c6-65-5ba0b483ba54 Received: from eusync4.samsung.com ( [203.254.199.214]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 0B.6E.04284.384B0AB5; Tue, 18 Sep 2018 09:17:07 +0100 (BST) Received: from AMDC2765.digital.local ([106.116.147.25]) by eusync4.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0PF800C5KSCD4H70@eusync4.samsung.com>; Tue, 18 Sep 2018 09:17:07 +0100 (BST) From: Marek Szyprowski To: linux-usb@vger.kernel.org, linux-samsung-soc@vger.kernel.org Cc: Marek Szyprowski , Greg Kroah-Hartman , Felipe Balbi , Krzysztof Kozlowski , Bartlomiej Zolnierkiewicz Subject: [PATCH 2/4] usb: dwc3: exynos: Rework clock handling and prepare for new variants Date: Tue, 18 Sep 2018 10:16:51 +0200 Message-id: <20180918081653.314-3-m.szyprowski@samsung.com> X-Mailer: git-send-email 2.17.1 In-reply-to: <20180918081653.314-1-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrOIsWRmVeSWpSXmKPExsWy7djP87rNWxZEG5xrt7TYOGM9q8Wxtifs Fs2L17NZnD+/gd1ixvl9TBaLlrUyW6w9cpfdgd1j06pONo/9c9ewe/RtWcXo8XmTXABLFJdN SmpOZllqkb5dAlfGqS2/GAv2GlUsbLrJ2MB4RbOLkZNDQsBEorF9I3MXIxeHkMAKRomZbe/Y IJzPjBI7f85ihamafmIvC0RiGaPEh9kLoaoamCR2tj1mBKliEzCU6HrbxQZiiwg4SCxZeges iFngCaPE7s1fwIqEBWIkOk5NZwGxWQRUJRqnvAOzeQWsJS5dvAG1Tl5i9YYDzCA2p4CNxM6N j8BWSwg0skms2PyECaLIReJl5zqoBmGJV8e3sEPYMhKdHQeZIBqaGSXaZ8xih3B6GCW2ztnB BlFlLXH4+EWwbmYBPolJ26YDreMAivNKdLQJQZR4SFy9tA/q6X5GiWNXjzNPYJRcwMiwilE8 tbQ4Nz212CgvtVyvODG3uDQvXS85P3cTIzD6Tv87/mUH464/SYcYBTgYlXh4FyyYHy3EmlhW XJl7iFGCg1lJhJczZ0G0EG9KYmVValF+fFFpTmrxIUZpDhYlcV4+rbRoIYH0xJLU7NTUgtQi mCwTB6dUA2PhbcN5a/NK1+r4PJjKq5QS9+UMy6QJ2+b+/zCpSfVfjvuvgP13xLbbrtzwWsVl URHP9lgbhxiT9wUXBXeK2zzcHx28aOWMx4ca6nViTzVGej8p6zup/ezKgc38Rz9eW5M5Z2aS hcYUI7Hn4cuCPty5W1Eac51nmWdAwMLLx95NVJrZrr7Pe2m4EktxRqKhFnNRcSIAX/2tdLoC AAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpkluLIzCtJLcpLzFFi42I5/e/4Nd3mLQuiDaZuELHYOGM9q8Wxtifs Fs2L17NZnD+/gd1ixvl9TBaLlrUyW6w9cpfdgd1j06pONo/9c9ewe/RtWcXo8XmTXABLFJdN SmpOZllqkb5dAlfGqS2/GAv2GlUsbLrJ2MB4RbOLkZNDQsBEYvqJvSxdjFwcQgJLGCW+z3/C BpIQEmhiknhyLxTEZhMwlOh62wUWFxFwkFiy9A4bSAOzwBNGiRtX5gM5HBzCAjESv74Ug9Sw CKhKNE55xwJi8wpYS1y6eIMVYpm8xOoNB5hBbE4BG4mdGx+xQOyylljWdpl1AiPPAkaGVYwi qaXFuem5xYZ6xYm5xaV56XrJ+bmbGIEBs+3Yz807GC9tDD7EKMDBqMTDu2DB/Ggh1sSy4src Q4wSHMxKIrycOQuihXhTEiurUovy44tKc1KLDzFKc7AoifOeN6iMEhJITyxJzU5NLUgtgsky cXBKNTBK1Heaznof3lvWqBS28IjD8vLd90VPsu78vP/3L1dBu8fzL/ectel9mt9wrt9XejXH 0WfzPordu/T8obqjXN9f7fKZxSVBVto3psq/XhlUE+DUl75btdhFQJLjsUN9psDM6UdUxA42 PDi8ueXx4doG76aPlf6/hb0cSvzSXj/81Kr/ROZI1SolluKMREMt5qLiRAA43NM7FAIAAA== X-CMS-MailID: 20180918081707eucas1p11cf21da4c14282d927c0c93652af4ce0 X-Msg-Generator: CA CMS-TYPE: 201P X-CMS-RootMailID: 20180918081707eucas1p11cf21da4c14282d927c0c93652af4ce0 References: <20180918081653.314-1-m.szyprowski@samsung.com> Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Add per-variant list of clocks and manage them all together in the single array. This is a preparation for adding new variants of Exynos SoCs. No functional changes for existing Exynos SoCs. Signed-off-by: Marek Szyprowski --- drivers/usb/dwc3/dwc3-exynos.c | 128 ++++++++++++++++++++------------- 1 file changed, 80 insertions(+), 48 deletions(-) -- 2.17.1 diff --git a/drivers/usb/dwc3/dwc3-exynos.c b/drivers/usb/dwc3/dwc3-exynos.c index 0a946c66c3bb..3f434a53be8e 100644 --- a/drivers/usb/dwc3/dwc3-exynos.c +++ b/drivers/usb/dwc3/dwc3-exynos.c @@ -17,12 +17,21 @@ #include #include +#define DWC3_EXYNOS_MAX_CLOCKS 4 + +struct dwc3_exynos_driverdata { + const char *clk_names[DWC3_EXYNOS_MAX_CLOCKS]; + int num_clks; + int suspend_clk_idx; +}; + struct dwc3_exynos { struct device *dev; - struct clk *clk; - struct clk *susp_clk; - struct clk *axius_clk; + const char **clk_names; + struct clk *clks[DWC3_EXYNOS_MAX_CLOCKS]; + int num_clks; + int suspend_clk_idx; struct regulator *vdd33; struct regulator *vdd10; @@ -42,47 +51,42 @@ static int dwc3_exynos_probe(struct platform_device *pdev) struct dwc3_exynos *exynos; struct device *dev = &pdev->dev; struct device_node *node = dev->of_node; - - int ret; + const struct dwc3_exynos_driverdata *driver_data; + int i, ret; exynos = devm_kzalloc(dev, sizeof(*exynos), GFP_KERNEL); if (!exynos) return -ENOMEM; - platform_set_drvdata(pdev, exynos); + driver_data = of_device_get_match_data(dev); + exynos->dev = dev; + exynos->num_clks = driver_data->num_clks; + exynos->clk_names = (const char **)driver_data->clk_names; + exynos->suspend_clk_idx = driver_data->suspend_clk_idx; - exynos->dev = dev; + platform_set_drvdata(pdev, exynos); - exynos->clk = devm_clk_get(dev, "usbdrd30"); - if (IS_ERR(exynos->clk)) { - dev_err(dev, "couldn't get clock\n"); - return -EINVAL; + for (i = 0; i < exynos->num_clks; i++) { + exynos->clks[i] = devm_clk_get(dev, exynos->clk_names[i]); + if (IS_ERR(exynos->clks[i])) { + dev_err(dev, "failed to get clock: %s\n", + exynos->clk_names[i]); + return PTR_ERR(exynos->clks[i]); + } } - ret = clk_prepare_enable(exynos->clk); - if (ret) - return ret; - exynos->susp_clk = devm_clk_get(dev, "usbdrd30_susp_clk"); - if (IS_ERR(exynos->susp_clk)) - exynos->susp_clk = NULL; - ret = clk_prepare_enable(exynos->susp_clk); - if (ret) - goto susp_clk_err; - - if (of_device_is_compatible(node, "samsung,exynos7-dwusb3")) { - exynos->axius_clk = devm_clk_get(dev, "usbdrd30_axius_clk"); - if (IS_ERR(exynos->axius_clk)) { - dev_err(dev, "no AXI UpScaler clk specified\n"); - ret = -ENODEV; - goto axius_clk_err; + for (i = 0; i < exynos->num_clks; i++) { + ret = clk_prepare_enable(exynos->clks[i]); + if (ret) { + while (--i > 0) + clk_disable_unprepare(exynos->clks[i]); + return ret; } - ret = clk_prepare_enable(exynos->axius_clk); - if (ret) - goto axius_clk_err; - } else { - exynos->axius_clk = NULL; } + if (exynos->suspend_clk_idx >= 0) + clk_prepare_enable(exynos->clks[exynos->suspend_clk_idx]); + exynos->vdd33 = devm_regulator_get(dev, "vdd33"); if (IS_ERR(exynos->vdd33)) { ret = PTR_ERR(exynos->vdd33); @@ -124,23 +128,27 @@ static int dwc3_exynos_probe(struct platform_device *pdev) vdd10_err: regulator_disable(exynos->vdd33); vdd33_err: - clk_disable_unprepare(exynos->axius_clk); -axius_clk_err: - clk_disable_unprepare(exynos->susp_clk); -susp_clk_err: - clk_disable_unprepare(exynos->clk); + for (i = exynos->num_clks - 1; i >= 0; i--) + clk_disable_unprepare(exynos->clks[i]); + + if (exynos->suspend_clk_idx >= 0) + clk_disable_unprepare(exynos->clks[exynos->suspend_clk_idx]); + return ret; } static int dwc3_exynos_remove(struct platform_device *pdev) { struct dwc3_exynos *exynos = platform_get_drvdata(pdev); + int i; device_for_each_child(&pdev->dev, NULL, dwc3_exynos_remove_child); - clk_disable_unprepare(exynos->axius_clk); - clk_disable_unprepare(exynos->susp_clk); - clk_disable_unprepare(exynos->clk); + for (i = exynos->num_clks - 1; i >= 0; i--) + clk_disable_unprepare(exynos->clks[i]); + + if (exynos->suspend_clk_idx >= 0) + clk_disable_unprepare(exynos->clks[exynos->suspend_clk_idx]); regulator_disable(exynos->vdd33); regulator_disable(exynos->vdd10); @@ -148,10 +156,27 @@ static int dwc3_exynos_remove(struct platform_device *pdev) return 0; } +static const struct dwc3_exynos_driverdata exynos5250_drvdata = { + .clk_names = { "usbdrd30" }, + .num_clks = 1, + .suspend_clk_idx = -1, +}; + +static const struct dwc3_exynos_driverdata exynos7_drvdata = { + .clk_names = { "usbdrd30", "usbdrd30_susp_clk", "usbdrd30_axius_clk" }, + .num_clks = 3, + .suspend_clk_idx = 1, +}; + static const struct of_device_id exynos_dwc3_match[] = { - { .compatible = "samsung,exynos5250-dwusb3" }, - { .compatible = "samsung,exynos7-dwusb3" }, - {}, + { + .compatible = "samsung,exynos5250-dwusb3", + .data = &exynos5250_drvdata, + }, { + .compatible = "samsung,exynos7-dwusb3", + .data = &exynos7_drvdata, + }, { + } }; MODULE_DEVICE_TABLE(of, exynos_dwc3_match); @@ -159,9 +184,10 @@ MODULE_DEVICE_TABLE(of, exynos_dwc3_match); static int dwc3_exynos_suspend(struct device *dev) { struct dwc3_exynos *exynos = dev_get_drvdata(dev); + int i; - clk_disable(exynos->axius_clk); - clk_disable(exynos->clk); + for (i = exynos->num_clks - 1; i >= 0; i--) + clk_disable_unprepare(exynos->clks[i]); regulator_disable(exynos->vdd33); regulator_disable(exynos->vdd10); @@ -172,7 +198,7 @@ static int dwc3_exynos_suspend(struct device *dev) static int dwc3_exynos_resume(struct device *dev) { struct dwc3_exynos *exynos = dev_get_drvdata(dev); - int ret; + int i, ret; ret = regulator_enable(exynos->vdd33); if (ret) { @@ -185,8 +211,14 @@ static int dwc3_exynos_resume(struct device *dev) return ret; } - clk_enable(exynos->clk); - clk_enable(exynos->axius_clk); + for (i = 0; i < exynos->num_clks; i++) { + ret = clk_prepare_enable(exynos->clks[i]); + if (ret) { + while (--i > 0) + clk_disable_unprepare(exynos->clks[i]); + return ret; + } + } return 0; }