From patchwork Thu Sep 17 22:31:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nobuhiro Iwamatsu X-Patchwork-Id: 11783657 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EA5186CA for ; Thu, 17 Sep 2020 22:32:25 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BD1F62087D for ; Thu, 17 Sep 2020 22:32:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="2wyierdq" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BD1F62087D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=toshiba.co.jp Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Xu6e8i+7j63daL/ULl+wXRrdRsq32ANAXeCqwjGQwx4=; b=2wyierdqBbUnDLgz9iWzNkxn8 de8dCZEaYDJVeZXUGiWf+Pyr0Fl5zaenW9xjHw0ryfjVYwRlafR+2+2CpeKhSTU3b1SX6FcVGqa5I R7v9FLT42t9HxeXhYGAGga+3MqBNaAZ4+/0nydL1tM250kbZCt3coD8l52tDqzMhn71ddjgsqq9e6 P/aWfq5VO/sf/2qCkutvi7uFvHF2AuvZNQBMjq3zl+LaMX7fxmGDZxzngRQLLBDapB5cVM3R+x3Kl qoU8OnApSwav45KyDECQzKZNfQ4jcKQatO61AZAZSwfDW1dRkpeGP592HtDtF+g4DMc/Eej0IS2Cs 1FTA9GYhw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kJ2Rk-0004ga-0a; Thu, 17 Sep 2020 22:32:08 +0000 Received: from mo-csw1114.securemx.jp ([210.130.202.156] helo=mo-csw.securemx.jp) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kJ2Rg-0004er-Pc for linux-arm-kernel@lists.infradead.org; Thu, 17 Sep 2020 22:32:06 +0000 Received: by mo-csw.securemx.jp (mx-mo-csw1114) id 08HMVrUZ028547; Fri, 18 Sep 2020 07:31:53 +0900 X-Iguazu-Qid: 2wHHQUhUGtwWoYzwwK X-Iguazu-QSIG: v=2; s=0; t=1600381912; q=2wHHQUhUGtwWoYzwwK; m=34Ey3eTpq6hehLDZahwnAo6GyQxFbsIBnpA5/hux5FQ= Received: from imx2.toshiba.co.jp (imx2.toshiba.co.jp [106.186.93.51]) by relay.securemx.jp (mx-mr1111) id 08HMVpas022819; Fri, 18 Sep 2020 07:31:51 +0900 Received: from enc01.toshiba.co.jp ([106.186.93.100]) by imx2.toshiba.co.jp with ESMTP id 08HMVpsi025788; Fri, 18 Sep 2020 07:31:51 +0900 (JST) Received: from hop001.toshiba.co.jp ([133.199.164.63]) by enc01.toshiba.co.jp with ESMTP id 08HMVp9s000934; Fri, 18 Sep 2020 07:31:51 +0900 From: Nobuhiro Iwamatsu To: Rob Herring , Thierry Reding , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Lee Jones Subject: [PATCH 2/2] pwm: visconti: Add Toshiba Visconti SoC PWM support Date: Fri, 18 Sep 2020 07:31:40 +0900 X-TSB-HOP: ON Message-Id: <20200917223140.227542-3-nobuhiro1.iwamatsu@toshiba.co.jp> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200917223140.227542-1-nobuhiro1.iwamatsu@toshiba.co.jp> References: <20200917223140.227542-1-nobuhiro1.iwamatsu@toshiba.co.jp> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200917_183205_215882_7713D104 X-CRM114-Status: GOOD ( 22.18 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [210.130.202.156 listed in list.dnswl.org] 0.0 RCVD_IN_MSPIKE_H4 RBL: Very Good reputation (+4) [210.130.202.156 listed in wl.mailspike.net] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-pwm@vger.kernel.org, punit1.agrawal@toshiba.co.jp, Nobuhiro Iwamatsu , devicetree@vger.kernel.org, Nobuhiro Iwamatsu , yuji2.ishikawa@toshiba.co.jp, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Nobuhiro Iwamatsu Add a driver for the PWM controller on Toshiba Visconti ARM SoC. Signed-off-by: Nobuhiro Iwamatsu --- drivers/pwm/Kconfig | 9 +++ drivers/pwm/Makefile | 1 + drivers/pwm/pwm-visconti.c | 141 +++++++++++++++++++++++++++++++++++++ 3 files changed, 151 insertions(+) create mode 100644 drivers/pwm/pwm-visconti.c diff --git a/drivers/pwm/Kconfig b/drivers/pwm/Kconfig index cb8d739067d2..f99d48f74c76 100644 --- a/drivers/pwm/Kconfig +++ b/drivers/pwm/Kconfig @@ -533,6 +533,15 @@ config PWM_TIEHRPWM To compile this driver as a module, choose M here: the module will be called pwm-tiehrpwm. +config PWM_VISCONTI + tristate "Toshiba Visconti PWM support" + depends on ARCH_VISCONTI || COMPILE_TEST + help + PWM Subsystem driver support for Toshiba Visconti SoCs. + + To compile this driver as a module, choose M here: the module + will be called pwm-visconti. + config PWM_TWL tristate "TWL4030/6030 PWM support" depends on TWL4030_CORE diff --git a/drivers/pwm/Makefile b/drivers/pwm/Makefile index a59c710e98c7..ef6dc1af7c17 100644 --- a/drivers/pwm/Makefile +++ b/drivers/pwm/Makefile @@ -51,6 +51,7 @@ obj-$(CONFIG_PWM_SUN4I) += pwm-sun4i.o obj-$(CONFIG_PWM_TEGRA) += pwm-tegra.o obj-$(CONFIG_PWM_TIECAP) += pwm-tiecap.o obj-$(CONFIG_PWM_TIEHRPWM) += pwm-tiehrpwm.o +obj-$(CONFIG_PWM_VISCONTI) += pwm-visconti.o obj-$(CONFIG_PWM_TWL) += pwm-twl.o obj-$(CONFIG_PWM_TWL_LED) += pwm-twl-led.o obj-$(CONFIG_PWM_VT8500) += pwm-vt8500.o diff --git a/drivers/pwm/pwm-visconti.c b/drivers/pwm/pwm-visconti.c new file mode 100644 index 000000000000..601450111166 --- /dev/null +++ b/drivers/pwm/pwm-visconti.c @@ -0,0 +1,141 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Toshiba Visconti pulse-width-modulation controller driver + * + * Copyright (c) 2020 TOSHIBA CORPORATION + * Copyright (c) 2020 Toshiba Electronic Devices & Storage Corporation + * Copyright (c) 2020 Nobuhiro Iwamatsu + * + */ + +#include +#include +#include +#include +#include +#include + +#define PWMC0_PWMACT BIT(5) + +#define REG_PCSR(ch) (0x400 + 4 * (ch)) +#define REG_PDUT(ch) (0x420 + 4 * (ch)) +#define REG_PWM0(ch) (0x440 + 4 * (ch)) + +struct visconti_pwm_chip { + struct pwm_chip chip; + struct device *dev; + void __iomem *base; +}; + +#define to_visconti_chip(chip) \ + container_of(chip, struct visconti_pwm_chip, chip) + +static int visconti_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, + const struct pwm_state *state) +{ + struct visconti_pwm_chip *priv = to_visconti_chip(chip); + u32 period, duty, pwmc0; + + dev_dbg(priv->dev, "%s: ch = %d en = %d p = 0x%llx d = 0x%llx\n", __func__, + pwm->hwpwm, state->enabled, state->period, state->duty_cycle); + if (state->enabled) { + period = state->period / 1000; + duty = state->duty_cycle / 1000; + if (period < 0x10000) + pwmc0 = 0; + else if (period < 0x20000) + pwmc0 = 1; + else if (period < 0x40000) + pwmc0 = 2; + else if (period < 0x80000) + pwmc0 = 3; + else + return -EINVAL; + + if (pwmc0) { + period /= BIT(pwmc0); + duty /= BIT(pwmc0); + } + + if (state->polarity == PWM_POLARITY_INVERSED) + pwmc0 |= PWMC0_PWMACT; + + writel(pwmc0, priv->base + REG_PWM0(pwm->hwpwm)); + writel(duty, priv->base + REG_PDUT(pwm->hwpwm)); + writel(period, priv->base + REG_PCSR(pwm->hwpwm)); + } else { + writel(0, priv->base + REG_PCSR(pwm->hwpwm)); + } + + return 0; +} + +static const struct pwm_ops visconti_pwm_ops = { + .apply = visconti_pwm_apply, + .owner = THIS_MODULE, +}; + +static int visconti_pwm_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct visconti_pwm_chip *priv; + int ret; + + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + priv->dev = &pdev->dev; + + priv->base = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(priv->base)) { + dev_err(dev, "unable to map I/O space\n"); + return PTR_ERR(priv->base); + } + + platform_set_drvdata(pdev, priv); + + priv->chip.dev = dev; + priv->chip.ops = &visconti_pwm_ops; + priv->chip.base = -1; + priv->chip.npwm = 4; + + ret = pwmchip_add(&priv->chip); + if (ret < 0) { + dev_err(dev, "Cannot register visconti PWM: %d\n", ret); + return ret; + } + + dev_info(&pdev->dev, "visconti PWM registered\n"); + + return 0; +} + +static int visconti_pwm_remove(struct platform_device *pdev) +{ + struct visconti_pwm_chip *priv = platform_get_drvdata(pdev); + + return pwmchip_remove(&priv->chip); +} + +static const struct of_device_id visconti_pwm_of_match[] = { + { .compatible = "toshiba,pwm-visconti", }, + { } +}; + +MODULE_DEVICE_TABLE(of, visconti_pwm_of_match); + +static struct platform_driver visconti_pwm_driver = { + .driver = { + .name = "pwm-visconti", + .of_match_table = visconti_pwm_of_match, + }, + .probe = visconti_pwm_probe, + .remove = visconti_pwm_remove, +}; + +module_platform_driver(visconti_pwm_driver); + +MODULE_LICENSE("GPL v2"); +MODULE_AUTHOR("Toshiba"); +MODULE_ALIAS("platform:visconti-pwm");