From patchwork Wed Aug 19 04:13:59 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshihiro Shimoda X-Patchwork-Id: 7034921 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 AE7099F373 for ; Wed, 19 Aug 2015 04:14:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6B42220824 for ; Wed, 19 Aug 2015 04:14:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 159F820820 for ; Wed, 19 Aug 2015 04:14:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750993AbbHSEOW (ORCPT ); Wed, 19 Aug 2015 00:14:22 -0400 Received: from relmlor4.renesas.com ([210.160.252.174]:28628 "EHLO relmlie3.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750978AbbHSEOV (ORCPT ); Wed, 19 Aug 2015 00:14:21 -0400 Received: from unknown (HELO relmlir1.idc.renesas.com) ([10.200.68.151]) by relmlie3.idc.renesas.com with ESMTP; 19 Aug 2015 13:14:20 +0900 Received: from relmlac2.idc.renesas.com (relmlac2.idc.renesas.com [10.200.69.22]) by relmlir1.idc.renesas.com (Postfix) with ESMTP id 3ACF94A3D1; Wed, 19 Aug 2015 13:14:20 +0900 (JST) Received: by relmlac2.idc.renesas.com (Postfix, from userid 0) id 364112806E; Wed, 19 Aug 2015 13:14:20 +0900 (JST) Received: from relmlac2.idc.renesas.com (localhost [127.0.0.1]) by relmlac2.idc.renesas.com (Postfix) with ESMTP id 30F8B2806D; Wed, 19 Aug 2015 13:14:20 +0900 (JST) Received: from relmlii1.idc.renesas.com [10.200.68.65] by relmlac2.idc.renesas.com with ESMTP id PAR00799; Wed, 19 Aug 2015 13:14:20 +0900 X-IronPort-AV: E=Sophos;i="5.15,706,1432566000"; d="scan'";a="192579046" Received: from mail-hk2apc01lp0212.outbound.protection.outlook.com (HELO APC01-HK2-obe.outbound.protection.outlook.com) ([65.55.88.212]) by relmlii1.idc.renesas.com with ESMTP/TLS/AES256-SHA; 19 Aug 2015 13:14:18 +0900 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=<>; Received: from localhost (211.11.155.144) by SIXPR06MB0921.apcprd06.prod.outlook.com (10.162.173.13) with Microsoft SMTP Server (TLS) id 15.1.231.21; Wed, 19 Aug 2015 04:14:16 +0000 From: Yoshihiro Shimoda To: , , , , , CC: , , , Yoshihiro Shimoda Subject: [PATCH v6 2/2] pwm: Add support for R-Car PWM Timer Date: Wed, 19 Aug 2015 13:13:59 +0900 Message-ID: <1439957639-4816-3-git-send-email-yoshihiro.shimoda.uh@renesas.com> X-Mailer: git-send-email 1.9.4.msysgit.1 In-Reply-To: <1439957639-4816-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> References: <1439957639-4816-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> MIME-Version: 1.0 X-Originating-IP: [211.11.155.144] X-ClientProxiedBy: TY1PR01CA0023.jpnprd01.prod.outlook.com (25.161.131.161) To SIXPR06MB0921.apcprd06.prod.outlook.com (25.162.173.13) X-Microsoft-Exchange-Diagnostics: 1; SIXPR06MB0921; 2:Oa9p+vwh4Fjj/agHZ4GdHvajZKdvlrhpo++5PXNv7cV6VEjqshwAv+041E7Hbtz9c2oytjONXsEgFaldd0k8dLtIdqRNJktKRb0Y3YMg18WOkfJjq8l/b1euTlehAp9mtyedctd9/6lcOmplCGD8Di1oMOwXEhgx/RgWPfZdy7E=; 3:KVA1FFoGmTMCjT7b/sM1jNTMGcmVJDFvggOcqmXQJDCRdU/dBC7FbMecjkiUyZ/EWV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mdzjICg5VOh6SMcHX6aUmw8NTWC+kZ4XSr8sqLMpmVZVXRlzfr1GHBl7PRy2VpfeRWEZwSXBt8P/IBwt1vc+dxBypSTdBqyIgvTejW1yfa/4/tWZ5h0uyACSg1qHKYtA3s7NopQfJNNUzE/u/hLhAI7DYaSj3ut1Lf2JEOJcphxB+6tt/C36hJfXiUGdlJqCrK7oCJwG6oJQ/JhCsrj4R3XUU/gxGwCRVLjCQb1ND6c+S2InyXouZL/A== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(8121501046)(5005006)(3002001); SRVR:SIXPR06MB0921; BCL:0; PCL:0; RULEID:; SRVR:SIXPR06MB0921; X-Forefront-PRVS: 0673F5BE31 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(6069001)(6009001)(189002)(199003)(77156002)(5001830100001)(5001960100002)(66066001)(47776003)(107886002)(62966003)(4001540100001)(189998001)(50226001)(50466002)(5001860100001)(97736004)(46102003)(5001770100001)(101416001)(122386002)(40100003)(81156007)(64706001)(229853001)(50986999)(42382002)(77096005)(87976001)(68736005)(36756003)(92566002)(106356001)(76176999)(2950100001)(5003940100001)(78352002)(42186005)(19580405001)(48376002)(105586002)(33646002)(19580395003)(76506005)(2004002)(4001430100001); DIR:OUT; SFP:1102; SCL:1; SRVR:SIXPR06MB0921; H:localhost; FPR:; SPF:None; PTR:InfoNoRecords; MX:0; A:0; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SIXPR06MB0921; 23:eKigU2JdUo+5LSdE50pZB7GUi70MjkupErxqBY0SL?= =?us-ascii?Q?3CzbyoUk5oo5DGoWXLruMaZO+IEpUf1HxkFNMFAtJNV2mEjI84LmsWYc0e9V?= =?us-ascii?Q?0dmXVhYmXzhUm5VwxlknsA7YP3MajAlyrwR8SGs39hKg2TcfsvFURIWblQdv?= =?us-ascii?Q?snt/RfA2YJK48bp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ii?Q?U9yfsXD4FLUoAuuZSzFcg2xaV+8MuXVMTI0Lc+4cPybTXiERV8R9sXePetMS?= =?us-ascii?Q?M4Ry1dq/K+djtcPuPM93/yjkvDTUhwMpLLy3pR30u4Q3PPKasPu7YqWQlZnh?= =?us-ascii?Q?+5f4pVGV0LehOavKzv3Nt1iU1WRi2kbCHNJ4dHbD3/oI7wqHjYJ7vW2BA=3D?= =?us-ascii?Q?=3D?= X-Microsoft-Exchange-Diagnostics: 1; SIXPR06MB0921; 5:oTCVhQfw9EyfC60GQ/AR+FK1yomZgzp0xxh3YnSD4uqDDCvCAEXvoi9aVzsSiObwoIjPst/mMBYe3347MdBkwR8ixsKIPOYazKqt2cxscDrttPcpRKNcyxgYwFb+inZZGphkJyxW6D5qSJ/EwRJJgA==; 24:J0QBLmBo2zD3OyaT6Vih3thb26exVjnX1lg60xndhSCuVlWWheOmfqu+zEi8a/2rtEQbMCz7p+iMb2Y4CYIxzWwBf0N40FOxTEHiGxYd01A=; 20:PhMpmlbuifAveD3QUfwoip5BajFzM8DXNbkSpkQtiNC0rf2RYJAs1g9TB6jtB0cqJ8j7pIMU3e79LEfw0PdHnANnLxJy94+rgOkOKk0w43GMaxEPWLhBNGoPemCBVjs+9BNI/6qsJTSt8BJ4Twq0AYtESNKUu+4x29A4a9f8Wn4= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Aug 2015 04:14:16.9911 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SIXPR06MB0921 Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 | 265 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 277 insertions(+) create mode 100644 drivers/pwm/pwm-rcar.c diff --git a/drivers/pwm/Kconfig b/drivers/pwm/Kconfig index b1541f4..3e58a68 100644 --- a/drivers/pwm/Kconfig +++ b/drivers/pwm/Kconfig @@ -249,6 +249,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 ec50eb5..79d3dc3 100644 --- a/drivers/pwm/Makefile +++ b/drivers/pwm/Makefile @@ -22,6 +22,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..a29fd78 --- /dev/null +++ b/drivers/pwm/pwm-rcar.c @@ -0,0 +1,265 @@ +/* + * 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) { + rcar_pwm_write(rp, cyc | ph, RCAR_PWMCNT); + return 0; + } else { + return -EINVAL; + } +} + +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); + rcar_pwm_set_clock_control(rp, div); + 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.of_xlate = of_pwm_xlate_with_flags; + 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");