From patchwork Wed Sep 30 08:47:53 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshihiro Shimoda X-Patchwork-Id: 7293611 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.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C52D29F32B for ; Wed, 30 Sep 2015 08:48:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 87D8F20664 for ; Wed, 30 Sep 2015 08:48:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7497A20693 for ; Wed, 30 Sep 2015 08:48:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755080AbbI3Isc (ORCPT ); Wed, 30 Sep 2015 04:48:32 -0400 Received: from relmlor4.renesas.com ([210.160.252.174]:21461 "EHLO relmlie3.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755018AbbI3IsO (ORCPT ); Wed, 30 Sep 2015 04:48:14 -0400 Received: from unknown (HELO relmlir4.idc.renesas.com) ([10.200.68.154]) by relmlie3.idc.renesas.com with ESMTP; 30 Sep 2015 17:48:12 +0900 Received: from relmlac4.idc.renesas.com (relmlac4.idc.renesas.com [10.200.69.24]) by relmlir4.idc.renesas.com (Postfix) with ESMTP id 2987B3E015; Wed, 30 Sep 2015 17:48:12 +0900 (JST) Received: by relmlac4.idc.renesas.com (Postfix, from userid 0) id 0C8E6480A3; Wed, 30 Sep 2015 17:48:12 +0900 (JST) Received: from relmlac4.idc.renesas.com (localhost [127.0.0.1]) by relmlac4.idc.renesas.com (Postfix) with ESMTP id 055C848014; Wed, 30 Sep 2015 17:48:12 +0900 (JST) Received: from relmlii2.idc.renesas.com [10.200.68.66] by relmlac4.idc.renesas.com with ESMTP id TAD23104; Wed, 30 Sep 2015 17:48:11 +0900 X-IronPort-AV: E=Sophos;i="5.17,611,1437404400"; d="scan'";a="196662398" Received: from mail-hk2apc01lp0209.outbound.protection.outlook.com (HELO APC01-HK2-obe.outbound.protection.outlook.com) ([65.55.88.209]) by relmlii2.idc.renesas.com with ESMTP/TLS/AES256-SHA; 30 Sep 2015 17:48:10 +0900 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=<>; Received: from localhost (211.11.155.144) by TY1PR06MB0927.apcprd06.prod.outlook.com (10.164.99.153) with Microsoft SMTP Server (TLS) id 15.1.280.20; Wed, 30 Sep 2015 08:48:08 +0000 From: Yoshihiro Shimoda To: , , , , , CC: , , , Yoshihiro Shimoda Subject: [PATCH v7 2/2] pwm: Add support for R-Car PWM Timer Date: Wed, 30 Sep 2015 17:47:53 +0900 Message-ID: <1443602873-4316-3-git-send-email-yoshihiro.shimoda.uh@renesas.com> X-Mailer: git-send-email 1.9.4.msysgit.1 In-Reply-To: <1443602873-4316-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> References: <1443602873-4316-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> MIME-Version: 1.0 X-Originating-IP: [211.11.155.144] X-ClientProxiedBy: OS1PR01CA0004.jpnprd01.prod.outlook.com (25.161.225.142) To TY1PR06MB0927.apcprd06.prod.outlook.com (25.164.99.153) X-Microsoft-Exchange-Diagnostics: 1; TY1PR06MB0927; 2:ZdFa7iX3p4I6EEtpZ9LWf53rL4izJK4qYDA9kvU1T0PRvugdvs52YYYnZKhD9wgrOYTdZ8KjR8fsvBb019RpSP+cBaMeAhjnPwk8wB/XQ3NT8/fnok7AyBbr0li7ZdxZ/oBH9AmYR5r7xjE3T5WOtScrTBgMpUXjyJTZA/G+0V0=; 3:yUbQcsm+WGcL1jnQ9Bbkwge+XdIcOT4mQbxLdBlrMaaSEkwiz0O3/nUA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407/tZilC92pSvZz5oMqmQKbYRbYzhtYIZgBSKzDhrQR8J3ztkAUG/PFzEYUEVb8fDiwUr6utfUhbnLenaf/I+au35C94zyyRfWP5hpRBnd2G4GFIdUM8Z11LWDb9cB0igOgPiBKE4/xRqCR0waGT4Ys7JIFQCJWwy6Rbo/6jzS+JVeKv3zn5TlIzP8Gdwmj3gBXTxZkJ2EVPhYrVxJb8uOlDFFzrlIiG3QRK3m+Sqi2hAGm/uPB24= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(520078)(5005006)(8121501046)(3002001); SRVR:TY1PR06MB0927; BCL:0; PCL:0; RULEID:; SRVR:TY1PR06MB0927; X-Forefront-PRVS: 071518EF63 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(6069001)(6009001)(189002)(199003)(50986999)(46102003)(76506005)(122386002)(107886002)(5003940100001)(47776003)(62966003)(5001830100001)(33646002)(81156007)(97736004)(77156002)(76176999)(105586002)(5001860100001)(101416001)(64706001)(66066001)(575784001)(5001960100002)(106356001)(5001770100001)(48376002)(50466002)(4001540100001)(229853001)(77096005)(50226001)(19580405001)(42186005)(40100003)(19580395003)(189998001)(92566002)(5007970100001)(68736005)(2950100001)(78352002)(42382002)(5004730100002)(36756003)(87976001)(5008740100001)(2004002)(4001430100001); DIR:OUT; SFP:1102; SCL:1; SRVR:TY1PR06MB0927; H:localhost; FPR:; SPF:None; PTR:InfoNoRecords; MX:0; A:0; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; TY1PR06MB0927; 23:G4MXdqBxe+go+0NiuPULbIqmzYzFE/b8P+tuW/UkR?= =?us-ascii?Q?HttzIFp1sUE98nQFpyAL7W+IHumFE4dqg7aWwHowI03lVNRESN00kMDyZl/W?= =?us-ascii?Q?/lOr0tkY6+kJ1qjkZhxbF9Vmt9wfRTf9/1FBIb4pCqgmLDdvvCF9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V3+FxP57bAdEsDQvGxPvHcwqaYVG6nfOTnLqvUW?= =?us-ascii?Q?1mJ/T7ZV+jXESpMH7jQnQpVadfrhhbprw8GUKbra9+YxhZHv59+Y7vH/2IkC?= =?us-ascii?Q?SE3drth3mTuIeFBWXET67c0+CPk6TJDxwpEEYtRC7zmzPUGZt4MDi0c1u5S5?= =?us-ascii?Q?uwY7dnvxj6PeysKs87RN8xTKVQxPw9ByMHt6xoeK5s6pn94sZhW/CtZpy/fJ?= =?us-ascii?Q?JMEqtoS1bdB7gcUUxZ0XMEbNMi3U7jyUU8nELObCVaKZ7lrIc2gXEsoEC9Af?= =?us-ascii?Q?0pAD+goRWYQTsbL24W2jw/GYVYsTd98Jp4W2XVZB95Xk3r+r9xRRLm0Ow4+G?= =?us-ascii?Q?NX87g=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; TY1PR06MB0927; 5:wg61Bc3V3XBZK1fIRpYutrGcilSisfJyCFJiwXR1avXDDFXLNYbjdHBbtb6Ln4SiG6KheqfiPz8KsHb+9lsAiEd8ymTW7eOdadimFYZ+N2PnibYKtVJHsQZK/OPfX0cNAnrG0Keo3KCClP7no5jS8Q==; 24:P3/Re1pcFamg7cV6WpTdSYaht0LaPVp1XrvEqWvvGJtgLVBq2lx6h7R5KGNwu0dnAyrcph8faXHfQasW7vEFDF3K1lHo+sMX9Ndz8kTZDLw=; 20:Y7UYbk1iDTR7f/9aeu4xts/yHsBAnfqTOx2TeqhpCEs+Zg6geUaCtR439CIhqvr7mpShEdfpD7AWWe/JlWCkDvG1/+EEi3jNHh+xqemp6ClxeePhQqf2bRLE3BriFkxhT7SZ5g7Ha0iJ8PCtwsL2KiEIvAa2sArx9zdJ549C7wc= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2015 08:48:08.8054 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: TY1PR06MB0927 Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Spam-Status: No, score=-4.1 required=5.0 tests=AXB_X_OUTLOOKPROT_ENVSDR, 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 This patch adds support for R-Car SoCs PWM Timer. The PWM timer of R-Car H2 has 7 channels. So, we can use the channels if we describe device tree nodes. Signed-off-by: Yoshihiro Shimoda Reviewed-by: Simon Horman --- drivers/pwm/Kconfig | 11 ++ drivers/pwm/Makefile | 1 + drivers/pwm/pwm-rcar.c | 266 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 278 insertions(+) create mode 100644 drivers/pwm/pwm-rcar.c diff --git a/drivers/pwm/Kconfig b/drivers/pwm/Kconfig index 062630a..5dac49f 100644 --- a/drivers/pwm/Kconfig +++ b/drivers/pwm/Kconfig @@ -268,6 +268,17 @@ config PWM_PXA To compile this driver as a module, choose M here: the module will be called pwm-pxa. +config PWM_RCAR + tristate "Renesas R-Car PWM support" + depends on ARCH_RCAR_GEN1 || ARCH_RCAR_GEN2 || COMPILE_TEST + depends on HAS_IOMEM + help + This driver exposes the PWM Timer controller found in Renesas + R-Car chips through the PWM API. + + To compile this driver as a module, choose M here: the module + will be called pwm-rcar. + config PWM_RENESAS_TPU tristate "Renesas TPU PWM support" depends on ARCH_SHMOBILE || COMPILE_TEST diff --git a/drivers/pwm/Makefile b/drivers/pwm/Makefile index a0e00c0..9107d65 100644 --- a/drivers/pwm/Makefile +++ b/drivers/pwm/Makefile @@ -24,6 +24,7 @@ obj-$(CONFIG_PWM_MXS) += pwm-mxs.o obj-$(CONFIG_PWM_PCA9685) += pwm-pca9685.o obj-$(CONFIG_PWM_PUV3) += pwm-puv3.o obj-$(CONFIG_PWM_PXA) += pwm-pxa.o +obj-$(CONFIG_PWM_RCAR) += pwm-rcar.o obj-$(CONFIG_PWM_RENESAS_TPU) += pwm-renesas-tpu.o obj-$(CONFIG_PWM_ROCKCHIP) += pwm-rockchip.o obj-$(CONFIG_PWM_SAMSUNG) += pwm-samsung.o diff --git a/drivers/pwm/pwm-rcar.c b/drivers/pwm/pwm-rcar.c new file mode 100644 index 0000000..b641701 --- /dev/null +++ b/drivers/pwm/pwm-rcar.c @@ -0,0 +1,266 @@ +/* + * R-Car PWM Timer driver + * + * Copyright (C) 2015 Renesas Electronics Corporation + * + * This is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define RCAR_PWM_MAX_DIVISION 24 +#define RCAR_PWM_MAX_CYCLE 1023 + +#define RCAR_PWMCR 0x00 +#define RCAR_PWMCNT 0x04 + +#define RCAR_PWMCR_CC0_MASK 0x000f0000 +#define RCAR_PWMCR_CC0_SHIFT 16 +#define RCAR_PWMCR_CCMD BIT(15) +#define RCAR_PWMCR_SYNC BIT(11) +#define RCAR_PWMCR_SS0 BIT(4) +#define RCAR_PWMCR_EN0 BIT(0) + +#define RCAR_PWMCNT_CYC0_MASK 0x03ff0000 +#define RCAR_PWMCNT_CYC0_SHIFT 16 +#define RCAR_PWMCNT_PH0_MASK 0x000003ff +#define RCAR_PWMCNT_PH0_SHIFT 0 + +struct rcar_pwm_chip { + struct pwm_chip chip; + void __iomem *base; + struct clk *clk; +}; + +static inline struct rcar_pwm_chip *to_rcar_pwm_chip(struct pwm_chip *chip) +{ + return container_of(chip, struct rcar_pwm_chip, chip); +} + +static void rcar_pwm_write(struct rcar_pwm_chip *rp, u32 data, u32 reg) +{ + writel(data, rp->base + reg); +} + +static u32 rcar_pwm_read(struct rcar_pwm_chip *rp, u32 reg) +{ + return readl(rp->base + reg); +} + +static void rcar_pwm_bit_modify(struct rcar_pwm_chip *rp, u32 mask, u32 data, + u32 reg) +{ + u32 val = rcar_pwm_read(rp, reg); + + val &= ~mask; + val |= data & mask; + rcar_pwm_write(rp, val, reg); +} + +static int rcar_pwm_get_clock_division(struct rcar_pwm_chip *rp, int period_ns) +{ + unsigned int div; + unsigned long clk_rate = clk_get_rate(rp->clk); + unsigned long long max; /* max cycle / nanoseconds */ + + if (clk_rate == 0) + return -EINVAL; + + for (div = 0; div <= RCAR_PWM_MAX_DIVISION; div++) { + max = (unsigned long long)NSEC_PER_SEC * RCAR_PWM_MAX_CYCLE * + (1 << div); + do_div(max, clk_rate); + if (period_ns < max) + break; + } + + return (div <= RCAR_PWM_MAX_DIVISION) ? div : -ERANGE; +} + +static void rcar_pwm_set_clock_control(struct rcar_pwm_chip *rp, int div) +{ + u32 val = rcar_pwm_read(rp, RCAR_PWMCR); + + val &= ~(RCAR_PWMCR_CCMD | RCAR_PWMCR_CC0_MASK); + if (div & 1) + val |= RCAR_PWMCR_CCMD; + div >>= 1; + val |= div << RCAR_PWMCR_CC0_SHIFT; + rcar_pwm_write(rp, val, RCAR_PWMCR); +} + +static int rcar_pwm_set_counter(struct rcar_pwm_chip *rp, int div, int duty_ns, + int period_ns) +{ + unsigned long long one_cycle, tmp; /* 0.01 nanoseconds */ + unsigned long clk_rate = clk_get_rate(rp->clk); + u32 cyc, ph; + + one_cycle = (unsigned long long)NSEC_PER_SEC * 100ULL * (1 << div); + do_div(one_cycle, clk_rate); + + tmp = period_ns * 100ULL; + do_div(tmp, one_cycle); + cyc = (tmp << RCAR_PWMCNT_CYC0_SHIFT) & RCAR_PWMCNT_CYC0_MASK; + + tmp = duty_ns * 100ULL; + do_div(tmp, one_cycle); + ph = tmp & RCAR_PWMCNT_PH0_MASK; + + /* Avoid prohibited setting */ + if (cyc == 0 || ph == 0) + return -EINVAL; + + rcar_pwm_write(rp, cyc | ph, RCAR_PWMCNT); + + return 0; +} + +static int rcar_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm) +{ + struct rcar_pwm_chip *rp = to_rcar_pwm_chip(chip); + + return clk_prepare_enable(rp->clk); +} + +static void rcar_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm) +{ + struct rcar_pwm_chip *rp = to_rcar_pwm_chip(chip); + + clk_disable_unprepare(rp->clk); +} + +static int rcar_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, + int duty_ns, int period_ns) +{ + struct rcar_pwm_chip *rp = to_rcar_pwm_chip(chip); + int div = rcar_pwm_get_clock_division(rp, period_ns); + int ret; + + if (div < 0) + return div; + + /* Let the core driver set pwm->period if disabled and duty_ns == 0 */ + if (!test_bit(PWMF_ENABLED, &pwm->flags) && !duty_ns) + return 0; + + rcar_pwm_bit_modify(rp, RCAR_PWMCR_SYNC, RCAR_PWMCR_SYNC, RCAR_PWMCR); + ret = rcar_pwm_set_counter(rp, div, duty_ns, period_ns); + if (!ret) + rcar_pwm_set_clock_control(rp, div); + /* The SYNC should be set to 0 even if rcar_pwm_set_counter failed */ + rcar_pwm_bit_modify(rp, RCAR_PWMCR_SYNC, 0, RCAR_PWMCR); + + return ret; +} + +static int rcar_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm) +{ + struct rcar_pwm_chip *rp = to_rcar_pwm_chip(chip); + u32 pwmcnt; + + /* Don't enable the PWM device if CYC0 or PH0 is 0 */ + pwmcnt = rcar_pwm_read(rp, RCAR_PWMCNT); + if ((pwmcnt & RCAR_PWMCNT_CYC0_MASK) == 0 || + (pwmcnt & RCAR_PWMCNT_PH0_MASK) == 0) + return -EINVAL; + + rcar_pwm_bit_modify(rp, RCAR_PWMCR_EN0, RCAR_PWMCR_EN0, RCAR_PWMCR); + + return 0; +} + +static void rcar_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) +{ + struct rcar_pwm_chip *rp = to_rcar_pwm_chip(chip); + + rcar_pwm_bit_modify(rp, RCAR_PWMCR_EN0, 0, RCAR_PWMCR); +} + +static const struct pwm_ops rcar_pwm_ops = { + .request = rcar_pwm_request, + .free = rcar_pwm_free, + .config = rcar_pwm_config, + .enable = rcar_pwm_enable, + .disable = rcar_pwm_disable, + .owner = THIS_MODULE, +}; + +static int rcar_pwm_probe(struct platform_device *pdev) +{ + struct rcar_pwm_chip *rcar_pwm; + struct resource *res; + int ret; + + rcar_pwm = devm_kzalloc(&pdev->dev, sizeof(*rcar_pwm), GFP_KERNEL); + if (rcar_pwm == NULL) + return -ENOMEM; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + rcar_pwm->base = devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(rcar_pwm->base)) + return PTR_ERR(rcar_pwm->base); + + rcar_pwm->clk = devm_clk_get(&pdev->dev, NULL); + if (IS_ERR(rcar_pwm->clk)) { + dev_err(&pdev->dev, "cannot get clock\n"); + return PTR_ERR(rcar_pwm->clk); + } + + platform_set_drvdata(pdev, rcar_pwm); + + rcar_pwm->chip.dev = &pdev->dev; + rcar_pwm->chip.ops = &rcar_pwm_ops; + rcar_pwm->chip.base = -1; + rcar_pwm->chip.npwm = 1; + + ret = pwmchip_add(&rcar_pwm->chip); + if (ret < 0) { + dev_err(&pdev->dev, "failed to register PWM chip\n"); + return ret; + } + + pm_runtime_enable(&pdev->dev); + + return 0; +} + +static int rcar_pwm_remove(struct platform_device *pdev) +{ + struct rcar_pwm_chip *rcar_pwm = platform_get_drvdata(pdev); + + pm_runtime_disable(&pdev->dev); + + return pwmchip_remove(&rcar_pwm->chip); +} + +static const struct of_device_id rcar_pwm_of_table[] = { + { .compatible = "renesas,pwm-rcar", }, + { }, +}; +MODULE_DEVICE_TABLE(of, rcar_pwm_of_table); + +static struct platform_driver rcar_pwm_driver = { + .probe = rcar_pwm_probe, + .remove = rcar_pwm_remove, + .driver = { + .name = "pwm-rcar", + .of_match_table = of_match_ptr(rcar_pwm_of_table), + } +}; +module_platform_driver(rcar_pwm_driver); + +MODULE_AUTHOR("Yoshihiro Shimoda "); +MODULE_DESCRIPTION("Renesas PWM Timer Driver"); +MODULE_LICENSE("GPL v2"); +MODULE_ALIAS("platform:pwm-rcar");