Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754878AbcJGRqa (ORCPT ); Fri, 7 Oct 2016 13:46:30 -0400 Received: from mail-ve1eur01on0100.outbound.protection.outlook.com ([104.47.1.100]:56832 "EHLO EUR01-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753136AbcJGRqU (ORCPT ); Fri, 7 Oct 2016 13:46:20 -0400 X-Greylist: delayed 26400 seconds by postgrey-1.27 at vger.kernel.org; Fri, 07 Oct 2016 13:46:19 EDT Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=bhuvanchandra.dv@toradex.com; From: Bhuvanchandra DV To: , CC: , , , , , , , , , , Lothar Wassmann , Bhuvanchandra DV Subject: [PATCH v3 3/6] pwm: imx: support output polarity inversion Date: Fri, 7 Oct 2016 20:41:26 +0530 Message-ID: <20161007151129.6043-4-bhuvanchandra.dv@toradex.com> X-Mailer: git-send-email 2.10.0 In-Reply-To: <20161007151129.6043-1-bhuvanchandra.dv@toradex.com> References: <20161007151129.6043-1-bhuvanchandra.dv@toradex.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [115.115.243.34] X-ClientProxiedBy: BM1PR01CA0062.INDPRD01.PROD.OUTLOOK.COM (10.163.199.34) To VI1PR05MB1407.eurprd05.prod.outlook.com (10.162.125.156) X-MS-Office365-Filtering-Correlation-Id: 858dd20b-50ed-4c17-d1a2-08d3eec49a70 X-Microsoft-Exchange-Diagnostics: 1;VI1PR05MB1407;2:mdKglPFQVXo/3w3mWmekuqAjXK9NY4tkb2w5NPj9ZKvMI2yFHJJH5hC4xPWI3ccxRazJQPdnFsCQ6grvw4+CqOxpY/zTv72OInwf/aOwm9oyG/SfhWj1IAX3sTJTTIEGAvOjDwNx5UXgORZ7c1tfM1XXOhUiwZegXmi7xoO/n2WzVarIn5Z+Btkh2HnrcDJo/yCLhHokvgrIgKQANEE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QEVkpcouk+n6fLubV8FuUoD5uAQsMiXINEXd7w37kPMxo9HWHPPOuFszodRpmYkpDvZVPEvcCctSsU6DFCiil4/NMXMhr2h2u203cRT/pQeS0zgsXOHGc4DtMyqTwooPT0ofb8cK8OPmO3jz3c9i7fmEK1mHrshsjfSKIaSWtfmUC3GOCvGkXzfMIQI5gwX/BDW/dkL69+M08TePOF30QDJkYsdyXHbTvrKGzgBGtHHWv;20:ixBBeNXDAjAeL5SvrMfsobcW0xZCyzrbv4ZPHWdWhujCllQD8gcC3EXZzJCIjuPmdxeqWiDkrL/qUQ2zx4y7+Z6VZVxAu4AzzoMDHV32ZzdkyeIuZQ1GXYuOk/HlTFYXMYf0KdI0H+fvvncb0/Tb8oHZAc2rPSx1H3lMlp2OVXQ/vldvXQh4hxjCXyfPWTMd5TOtsAhkQ8kXggSH5Ar3CsWJ3SGtOF2Shz8PshspvGe3h0q+LfczcYxZ4lChiK99+uqJoQ7+axq9NtzCo2rDjGrwg902/AuOc2ZacuY6S2aF4FD9j9kM3w6fEDvBWO4N4i237UvqzFPWY9PBSFGUuw== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(7411616537696); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040176)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001);SRVR:VI1PR05MB1407;BCL:0;PCL:0;RULEID:;SRVR:VI1PR05MB1407; X-Microsoft-Exchange-Diagnostics: 1;VI1PR05MB1407;4:JgvjNcge7hRyy+sT94tHDHMcB7NgjuMqnWFGCQNzvZSe0T14AO2fg+988nDR9/3aPo2UqxIt6dyTnOoaYKS7aTulRAvF4ZqugI9qsLQr1zkKAprYV4p/GM2dYSvKh+nYIoOOZQv06T33X6DNEDzNw5m7ZU8LithbssYqsguIdGsuKnuvk7axaD86VCRBUdoQQjHw6M1Zuw+XeuhH1RABuX6u/PLBsatLbpS3BLrZvd9hn6syRTJTiYAIk6bxZ3ZbO6CnRUpXAdIAGk4zQ2tuCyp8kqCtgegGn348lAWF7ZsSqUIEOA4Lfm9dSevymjrHGrXSbsa0ADOPWxIdFIeSBM+xQYXqGyfgxh75pGq562YHSRqaVAPssAufzNEEsmFq4QQ93tcZfh/B0y5wyRtOnfBsXFC4o/C6lDJp5aW9769vryd5MPsqf4T3dr0lCVvA X-Forefront-PRVS: 0088C92887 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6009001)(7916002)(199003)(189002)(4001430100002)(5001770100001)(97736004)(77096005)(68736007)(107886002)(86362001)(189998001)(4326007)(81166006)(81156014)(8676002)(36756003)(92566002)(2906002)(6116002)(50226002)(2870700001)(5820100001)(50466002)(69596002)(586003)(1076002)(3846002)(33646002)(76176999)(50986999)(101416001)(6666003)(2950100002)(47776003)(42186005)(66066001)(7416002)(8666005)(7736002)(305945005)(5660300001)(19580405001)(19580395003)(7846002)(53416004)(105586002)(229853001)(23676002)(106356001)(7059030);DIR:OUT;SFP:1102;SCL:1;SRVR:VI1PR05MB1407;H:tdx-in-nb-0014.toradex.int;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtWSTFQUjA1TUIxNDA3OzIzOjkwQ0E2WVBGWFdMSmQ3WUpNWTBsQXlqQ29t?= =?utf-8?B?NTNUbVVWRDhRQndkVEZYVGg1UU9UNFdDOUNkK3YwTWV1dXVUQmoycnJMemls?= =?utf-8?B?QlJBRVJCV2Jjck8wOWRsbm9HTnRMcUd5dm5rWUhhejRvZWNkUnNNRjdCazNo?= =?utf-8?B?SThUQ1lzSXpHTFlWMWl1QWxVZ3FlWmdpZEsza200WnJJUFJxNThDcmRmNG1w?= =?utf-8?B?Kys4UDNCTmc5Z0llVVFteFZCa2huNWVaeElKWTIrbkNtZlJLYkxySVhaOTdK?= =?utf-8?B?YmhYa0s0L2JGSE5od3pjdmVVcXRVdjNHTldZNDgvdnZiQ3NtWGJoTUpVZmxm?= =?ut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bNkqjuZqB3K/ki1VrRpaHsaOTF1nyWwbRcI0WkrDbGxpKpiYSngLuG6b04J9m+vVpjYTqO9ooEWqGLFVbFGCz00Mi5q91btjF3oZ8ibXNvA=;24:pfds3l3JWCvYTt67BYqqHKo8W3sv0Z1kdpCK+v+BPvS5pZy7etLKjh3r1OO9hfkaLwDZbKVw7wxYFDWUBhVDewk9sACar8HbyQAXyNyAJCY=;7:ZQxO9DSwmcwstnfCRLqHvH5rgqwHdvwl5B4cZ8Z2y0pv6Qb9TQ26QPmz7TMb+ehdqq+9UbXO/IGZ6+KESGQ2Aw4irFxW4tEA//6kv1lTexlIcrk35M09rqimDEC8rzvdmmCIEg2hnDliTJcMbmlKPJNlOiPAfNYP7CldWQuJkcS/p1yJGRpEj02zEWaqSaBQkKhaxa2wUkg6r30OR3UC/7UuOUI0TdML04Fh7lbTpSLTXBh+iyBEjPyKDWX8aQHQI74gT+KXtM78uni6MS38pRUJU4a53t5mzshdB2LkhComNTNjS9JBduMfi7hEa34RAM+dR7BPOuVeCRR89neBGA== SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: toradex.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Oct 2016 15:14:13.8789 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR05MB1407 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5141 Lines: 161 From: Lothar Wassmann The i.MX pwm unit on i.MX27 and newer SoCs provides a configurable output polarity. This patch adds support to utilize this feature where available. Signed-off-by: Lothar Waßmann Signed-off-by: Lukasz Majewski Signed-off-by: Bhuvanchandra DV Acked-by: Shawn Guo Reviewed-by: Sascha Hauer --- Documentation/devicetree/bindings/pwm/imx-pwm.txt | 6 +-- drivers/pwm/pwm-imx.c | 51 +++++++++++++++++++++-- 2 files changed, 51 insertions(+), 6 deletions(-) diff --git a/Documentation/devicetree/bindings/pwm/imx-pwm.txt b/Documentation/devicetree/bindings/pwm/imx-pwm.txt index e00c2e9..c61bdf8 100644 --- a/Documentation/devicetree/bindings/pwm/imx-pwm.txt +++ b/Documentation/devicetree/bindings/pwm/imx-pwm.txt @@ -6,8 +6,8 @@ Required properties: - "fsl,imx1-pwm" for PWM compatible with the one integrated on i.MX1 - "fsl,imx27-pwm" for PWM compatible with the one integrated on i.MX27 - reg: physical base address and length of the controller's registers -- #pwm-cells: should be 2. See pwm.txt in this directory for a description of - the cells format. +- #pwm-cells: 2 for i.MX1 and 3 for i.MX27 and newer SoCs. See pwm.txt + in this directory for a description of the cells format. - clocks : Clock specifiers for both ipg and per clocks. - clock-names : Clock names should include both "ipg" and "per" See the clock consumer binding, @@ -17,7 +17,7 @@ See the clock consumer binding, Example: pwm1: pwm@53fb4000 { - #pwm-cells = <2>; + #pwm-cells = <3>; compatible = "fsl,imx53-pwm", "fsl,imx27-pwm"; reg = <0x53fb4000 0x4000>; clocks = <&clks IMX5_CLK_PWM1_IPG_GATE>, diff --git a/drivers/pwm/pwm-imx.c b/drivers/pwm/pwm-imx.c index d600fd5..c37d223 100644 --- a/drivers/pwm/pwm-imx.c +++ b/drivers/pwm/pwm-imx.c @@ -38,6 +38,7 @@ #define MX3_PWMCR_DOZEEN (1 << 24) #define MX3_PWMCR_WAITEN (1 << 23) #define MX3_PWMCR_DBGEN (1 << 22) +#define MX3_PWMCR_POUTC (1 << 18) #define MX3_PWMCR_CLKSRC_IPG_HIGH (2 << 16) #define MX3_PWMCR_CLKSRC_IPG (1 << 16) #define MX3_PWMCR_SWR (1 << 3) @@ -180,6 +181,9 @@ static int imx_pwm_config_v2(struct pwm_chip *chip, if (enable) cr |= MX3_PWMCR_EN; + if (pwm->args.polarity == PWM_POLARITY_INVERSED) + cr |= MX3_PWMCR_POUTC; + writel(cr, imx->mmio_base + MX3_PWMCR); return 0; @@ -240,27 +244,62 @@ static void imx_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) clk_disable_unprepare(imx->clk_per); } -static struct pwm_ops imx_pwm_ops = { +static int imx_pwm_set_polarity(struct pwm_chip *chip, struct pwm_device *pwm, + enum pwm_polarity polarity) +{ + struct imx_chip *imx = to_imx_chip(chip); + u32 val; + + if (polarity == pwm->args.polarity) + return 0; + + val = readl(imx->mmio_base + MX3_PWMCR); + + if (polarity == PWM_POLARITY_INVERSED) + val |= MX3_PWMCR_POUTC; + else + val &= ~MX3_PWMCR_POUTC; + + writel(val, imx->mmio_base + MX3_PWMCR); + + dev_dbg(imx->chip.dev, "%s: polarity set to %s\n", __func__, + polarity == PWM_POLARITY_INVERSED ? "inverted" : "normal"); + + return 0; +} + +static struct pwm_ops imx_pwm_ops_v1 = { .enable = imx_pwm_enable, .disable = imx_pwm_disable, .config = imx_pwm_config, .owner = THIS_MODULE, }; +static struct pwm_ops imx_pwm_ops_v2 = { + .enable = imx_pwm_enable, + .disable = imx_pwm_disable, + .set_polarity = imx_pwm_set_polarity, + .config = imx_pwm_config, + .owner = THIS_MODULE, +}; + struct imx_pwm_data { int (*config)(struct pwm_chip *chip, struct pwm_device *pwm, int duty_ns, int period_ns); void (*set_enable)(struct pwm_chip *chip, bool enable); + struct pwm_ops *pwm_ops; }; static struct imx_pwm_data imx_pwm_data_v1 = { .config = imx_pwm_config_v1, .set_enable = imx_pwm_set_enable_v1, + .pwm_ops = &imx_pwm_ops_v1, }; static struct imx_pwm_data imx_pwm_data_v2 = { .config = imx_pwm_config_v2, .set_enable = imx_pwm_set_enable_v2, + .pwm_ops = &imx_pwm_ops_v2, }; static const struct of_device_id imx_pwm_dt_ids[] = { @@ -282,6 +321,8 @@ static int imx_pwm_probe(struct platform_device *pdev) if (!of_id) return -ENODEV; + data = of_id->data; + imx = devm_kzalloc(&pdev->dev, sizeof(*imx), GFP_KERNEL); if (imx == NULL) return -ENOMEM; @@ -300,18 +341,22 @@ static int imx_pwm_probe(struct platform_device *pdev) return PTR_ERR(imx->clk_ipg); } - imx->chip.ops = &imx_pwm_ops; + imx->chip.ops = data->pwm_ops; imx->chip.dev = &pdev->dev; imx->chip.base = -1; imx->chip.npwm = 1; imx->chip.can_sleep = true; + if (data->pwm_ops->set_polarity) { + dev_dbg(&pdev->dev, "PWM supports output inversion\n"); + imx->chip.of_xlate = of_pwm_xlate_with_flags; + imx->chip.of_pwm_n_cells = 3; + } r = platform_get_resource(pdev, IORESOURCE_MEM, 0); imx->mmio_base = devm_ioremap_resource(&pdev->dev, r); if (IS_ERR(imx->mmio_base)) return PTR_ERR(imx->mmio_base); - data = of_id->data; imx->config = data->config; imx->set_enable = data->set_enable; -- 2.10.0