* [PATCH v3 0/2] pwm: Add support for R-Car PWM Timer
@ 2015-05-21 2:50 ` Yoshihiro Shimoda
0 siblings, 0 replies; 14+ messages in thread
From: Yoshihiro Shimoda @ 2015-05-21 2:50 UTC (permalink / raw)
To: thierry.reding, robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak
Cc: linux-pwm, linux-sh, devicetree, Yoshihiro Shimoda
This patch set is based on the linux-pwm.git / for-next branch.
(commit id = efb0de55b6a2ec15fc424e660601f22ae2fa487a)
Changes from v2:
- Add compatible string "renesas,pwm-rcar".
- Remove compatible strings "renesas,pwm-r8a77xx" in rcar_pwm_of_table.
- Fix build error.
Changes from v1:
- Change compatible string to SoC-specific compatible values.
- Fix #pwm-call value to 2 in the device tree document.
- Fix "depends on" value in Kconfig.
- Fix help explanation in Kconfig.
- Remove an unnecessary member in rcar_pwm_chip.
- Remove hardcoded number of channels and change chip.npwm value to 1.
- Fix formulas for clock calculation to improve accuracy.
Yoshihiro Shimoda (2):
pwm: Add device tree binding document for R-Car PWM Timer
pwm: Add support for R-Car PWM Timer
.../devicetree/bindings/pwm/renesas,pwm-rcar.txt | 27 +++
drivers/pwm/Kconfig | 11 +
drivers/pwm/Makefile | 1 +
drivers/pwm/pwm-rcar.c | 262 +++++++++++++++++++++
4 files changed, 301 insertions(+)
create mode 100644 Documentation/devicetree/bindings/pwm/renesas,pwm-rcar.txt
create mode 100644 drivers/pwm/pwm-rcar.c
--
1.9.1
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v3 0/2] pwm: Add support for R-Car PWM Timer
@ 2015-05-21 2:50 ` Yoshihiro Shimoda
0 siblings, 0 replies; 14+ messages in thread
From: Yoshihiro Shimoda @ 2015-05-21 2:50 UTC (permalink / raw)
To: thierry.reding, robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak
Cc: linux-pwm, linux-sh, devicetree, Yoshihiro Shimoda
This patch set is based on the linux-pwm.git / for-next branch.
(commit id = efb0de55b6a2ec15fc424e660601f22ae2fa487a)
Changes from v2:
- Add compatible string "renesas,pwm-rcar".
- Remove compatible strings "renesas,pwm-r8a77xx" in rcar_pwm_of_table.
- Fix build error.
Changes from v1:
- Change compatible string to SoC-specific compatible values.
- Fix #pwm-call value to 2 in the device tree document.
- Fix "depends on" value in Kconfig.
- Fix help explanation in Kconfig.
- Remove an unnecessary member in rcar_pwm_chip.
- Remove hardcoded number of channels and change chip.npwm value to 1.
- Fix formulas for clock calculation to improve accuracy.
Yoshihiro Shimoda (2):
pwm: Add device tree binding document for R-Car PWM Timer
pwm: Add support for R-Car PWM Timer
.../devicetree/bindings/pwm/renesas,pwm-rcar.txt | 27 +++
drivers/pwm/Kconfig | 11 +
drivers/pwm/Makefile | 1 +
drivers/pwm/pwm-rcar.c | 262 +++++++++++++++++++++
4 files changed, 301 insertions(+)
create mode 100644 Documentation/devicetree/bindings/pwm/renesas,pwm-rcar.txt
create mode 100644 drivers/pwm/pwm-rcar.c
--
1.9.1
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v3 1/2] pwm: Add device tree binding document for R-Car PWM Timer
2015-05-21 2:50 ` Yoshihiro Shimoda
@ 2015-05-21 2:50 ` Yoshihiro Shimoda
-1 siblings, 0 replies; 14+ messages in thread
From: Yoshihiro Shimoda @ 2015-05-21 2:50 UTC (permalink / raw)
To: thierry.reding, robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak
Cc: linux-pwm, linux-sh, devicetree, Yoshihiro Shimoda
Add binding document for Renesas PWM Timer on R-Car SoCs.
Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
---
.../devicetree/bindings/pwm/renesas,pwm-rcar.txt | 27 ++++++++++++++++++++++
1 file changed, 27 insertions(+)
create mode 100644 Documentation/devicetree/bindings/pwm/renesas,pwm-rcar.txt
diff --git a/Documentation/devicetree/bindings/pwm/renesas,pwm-rcar.txt b/Documentation/devicetree/bindings/pwm/renesas,pwm-rcar.txt
new file mode 100644
index 0000000..c4ff798
--- /dev/null
+++ b/Documentation/devicetree/bindings/pwm/renesas,pwm-rcar.txt
@@ -0,0 +1,27 @@
+* Renesas R-Car PWM Timer Controller
+
+Required Properties:
+- compatible: should be one of the following.
+ - "renesas,pwm-rcar": for generic R-Car compatible PWM Timer
+ - "renesas,pwm-r8a7778": for R-Car M1A
+ - "renesas,pwm-r8a7779": for R-Car H1
+ - "renesas,pwm-r8a7790": for R-Car H2
+ - "renesas,pwm-r8a7791": for R-Car M2-W
+ - "renesas,pwm-r8a7794": for R-Car E2
+- reg: base address and length of the registers block for the PWM.
+- #pwm-cells: should be 2. See pwm.txt in this directory for a description of
+ the cells format.
+- clocks: clock phandle and specifier pair.
+- pinctrl-0: phandle, referring to a default pin configuration node.
+- pinctrl-names: Set to "default".
+
+Example: R8A7790 (R-Car H2) PWM Timer node
+
+ pwm0: pwm@e6e30000 {
+ compatible = "renesas,pwm-r8a7790", "renesas,pwm-rcar";
+ reg = <0 0xe6e30000 0 0x10>;
+ #pwm-cells = <2>;
+ clocks = <&mstp5_clks R8A7790_CLK_PWM>;
+ pinctrl-0 = <&pwm0_pins>;
+ pinctrl-names = "default";
+ };
--
1.9.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v3 1/2] pwm: Add device tree binding document for R-Car PWM Timer
@ 2015-05-21 2:50 ` Yoshihiro Shimoda
0 siblings, 0 replies; 14+ messages in thread
From: Yoshihiro Shimoda @ 2015-05-21 2:50 UTC (permalink / raw)
To: thierry.reding, robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak
Cc: linux-pwm, linux-sh, devicetree, Yoshihiro Shimoda
Add binding document for Renesas PWM Timer on R-Car SoCs.
Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
---
.../devicetree/bindings/pwm/renesas,pwm-rcar.txt | 27 ++++++++++++++++++++++
1 file changed, 27 insertions(+)
create mode 100644 Documentation/devicetree/bindings/pwm/renesas,pwm-rcar.txt
diff --git a/Documentation/devicetree/bindings/pwm/renesas,pwm-rcar.txt b/Documentation/devicetree/bindings/pwm/renesas,pwm-rcar.txt
new file mode 100644
index 0000000..c4ff798
--- /dev/null
+++ b/Documentation/devicetree/bindings/pwm/renesas,pwm-rcar.txt
@@ -0,0 +1,27 @@
+* Renesas R-Car PWM Timer Controller
+
+Required Properties:
+- compatible: should be one of the following.
+ - "renesas,pwm-rcar": for generic R-Car compatible PWM Timer
+ - "renesas,pwm-r8a7778": for R-Car M1A
+ - "renesas,pwm-r8a7779": for R-Car H1
+ - "renesas,pwm-r8a7790": for R-Car H2
+ - "renesas,pwm-r8a7791": for R-Car M2-W
+ - "renesas,pwm-r8a7794": for R-Car E2
+- reg: base address and length of the registers block for the PWM.
+- #pwm-cells: should be 2. See pwm.txt in this directory for a description of
+ the cells format.
+- clocks: clock phandle and specifier pair.
+- pinctrl-0: phandle, referring to a default pin configuration node.
+- pinctrl-names: Set to "default".
+
+Example: R8A7790 (R-Car H2) PWM Timer node
+
+ pwm0: pwm@e6e30000 {
+ compatible = "renesas,pwm-r8a7790", "renesas,pwm-rcar";
+ reg = <0 0xe6e30000 0 0x10>;
+ #pwm-cells = <2>;
+ clocks = <&mstp5_clks R8A7790_CLK_PWM>;
+ pinctrl-0 = <&pwm0_pins>;
+ pinctrl-names = "default";
+ };
--
1.9.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v3 2/2] pwm: Add support for R-Car PWM Timer
2015-05-21 2:50 ` Yoshihiro Shimoda
@ 2015-05-21 2:50 ` Yoshihiro Shimoda
-1 siblings, 0 replies; 14+ messages in thread
From: Yoshihiro Shimoda @ 2015-05-21 2:50 UTC (permalink / raw)
To: thierry.reding, robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak
Cc: linux-pwm, linux-sh, devicetree, Yoshihiro Shimoda
This patch adds support for R-Car SoCs PWM Timer.
Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
---
drivers/pwm/Kconfig | 11 +++
drivers/pwm/Makefile | 1 +
drivers/pwm/pwm-rcar.c | 262 +++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 274 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..579d91f
--- /dev/null
+++ b/drivers/pwm/pwm-rcar.c
@@ -0,0 +1,262 @@
+/*
+ * 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 <linux/clk.h>
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
+#include <linux/pwm.h>
+#include <linux/slab.h>
+
+#define RCAR_PWM_MAX_DIVISION 24
+#define RCAR_PWM_MAX_CYCLE 1023
+
+#define RCAR_PWMCR 0x00
+#define RCAR_PWMCNT 0x04
+#define RCAR_PWM_CH_OFFSET 0x1000
+
+#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;
+};
+
+#define to_rcar_pwm_chip(chip) container_of(chip, struct rcar_pwm_chip, chip)
+
+static void rcar_pwm_write(struct rcar_pwm_chip *rp, u32 data, u32 reg)
+{
+ iowrite32(data, rp->base + reg);
+}
+
+static u32 rcar_pwm_read(struct rcar_pwm_chip *rp, u32 reg)
+{
+ return ioread32(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_pwn_get_clock_division(struct rcar_pwm_chip *rp,
+ int period_ns)
+{
+ int div;
+ unsigned long clk_rate = clk_get_rate(rp->clk);
+ unsigned long long max; /* max cycle / nanoseconds */
+
+ 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;
+}
+
+static void rcar_pwm_set_clock_control(struct rcar_pwm_chip *rp, int div)
+{
+ u32 val = rcar_pwm_read(rp, RCAR_PWMCR);
+
+ if (div > RCAR_PWM_MAX_DIVISION)
+ return;
+
+ 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 void 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 * 100 * (1 << div);
+ do_div(one_cycle, clk_rate);
+
+ tmp = period_ns * 100;
+ do_div(tmp, one_cycle);
+ cyc = ((u32)tmp << RCAR_PWMCNT_CYC0_SHIFT) & RCAR_PWMCNT_CYC0_MASK;
+
+ tmp = duty_ns * 100;
+ do_div(tmp, one_cycle);
+ ph = (u32)tmp & RCAR_PWMCNT_PH0_MASK;
+
+ /* Avoid prohibited setting */
+ if (cyc && ph)
+ rcar_pwm_write(rp, cyc | ph, RCAR_PWMCNT);
+}
+
+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;
+
+ div = rcar_pwn_get_clock_division(rp, period_ns);
+
+ rcar_pwm_bit_modify(rp, RCAR_PWMCR_SYNC, RCAR_PWMCR_SYNC, RCAR_PWMCR);
+ 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 0;
+}
+
+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) ||
+ !(pwmcnt & RCAR_PWMCNT_PH0_MASK))
+ 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;
+ }
+
+ dev_info(&pdev->dev, "R-Car PWM Timer registered\n");
+
+ 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);
+ int ret;
+
+ ret = pwmchip_remove(&rcar_pwm->chip);
+ if (ret)
+ return ret;
+
+ pm_runtime_disable(&pdev->dev);
+
+ return 0;
+}
+
+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 <yoshihiro.shimoda.uh@renesas.com>");
+MODULE_DESCRIPTION("Renesas PWM Timer Driver");
+MODULE_LICENSE("GPL v2");
+MODULE_ALIAS("platform:pwm-rcar");
--
1.9.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v3 2/2] pwm: Add support for R-Car PWM Timer
@ 2015-05-21 2:50 ` Yoshihiro Shimoda
0 siblings, 0 replies; 14+ messages in thread
From: Yoshihiro Shimoda @ 2015-05-21 2:50 UTC (permalink / raw)
To: thierry.reding, robh+dt, pawel.moll, mark.rutland, ijc+devicetree, galak
Cc: linux-pwm, linux-sh, devicetree, Yoshihiro Shimoda
This patch adds support for R-Car SoCs PWM Timer.
Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
---
drivers/pwm/Kconfig | 11 +++
drivers/pwm/Makefile | 1 +
drivers/pwm/pwm-rcar.c | 262 +++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 274 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..579d91f
--- /dev/null
+++ b/drivers/pwm/pwm-rcar.c
@@ -0,0 +1,262 @@
+/*
+ * 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 <linux/clk.h>
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
+#include <linux/pwm.h>
+#include <linux/slab.h>
+
+#define RCAR_PWM_MAX_DIVISION 24
+#define RCAR_PWM_MAX_CYCLE 1023
+
+#define RCAR_PWMCR 0x00
+#define RCAR_PWMCNT 0x04
+#define RCAR_PWM_CH_OFFSET 0x1000
+
+#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;
+};
+
+#define to_rcar_pwm_chip(chip) container_of(chip, struct rcar_pwm_chip, chip)
+
+static void rcar_pwm_write(struct rcar_pwm_chip *rp, u32 data, u32 reg)
+{
+ iowrite32(data, rp->base + reg);
+}
+
+static u32 rcar_pwm_read(struct rcar_pwm_chip *rp, u32 reg)
+{
+ return ioread32(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_pwn_get_clock_division(struct rcar_pwm_chip *rp,
+ int period_ns)
+{
+ int div;
+ unsigned long clk_rate = clk_get_rate(rp->clk);
+ unsigned long long max; /* max cycle / nanoseconds */
+
+ 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;
+}
+
+static void rcar_pwm_set_clock_control(struct rcar_pwm_chip *rp, int div)
+{
+ u32 val = rcar_pwm_read(rp, RCAR_PWMCR);
+
+ if (div > RCAR_PWM_MAX_DIVISION)
+ return;
+
+ 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 void 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 * 100 * (1 << div);
+ do_div(one_cycle, clk_rate);
+
+ tmp = period_ns * 100;
+ do_div(tmp, one_cycle);
+ cyc = ((u32)tmp << RCAR_PWMCNT_CYC0_SHIFT) & RCAR_PWMCNT_CYC0_MASK;
+
+ tmp = duty_ns * 100;
+ do_div(tmp, one_cycle);
+ ph = (u32)tmp & RCAR_PWMCNT_PH0_MASK;
+
+ /* Avoid prohibited setting */
+ if (cyc && ph)
+ rcar_pwm_write(rp, cyc | ph, RCAR_PWMCNT);
+}
+
+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;
+
+ div = rcar_pwn_get_clock_division(rp, period_ns);
+
+ rcar_pwm_bit_modify(rp, RCAR_PWMCR_SYNC, RCAR_PWMCR_SYNC, RCAR_PWMCR);
+ 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 0;
+}
+
+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) ||
+ !(pwmcnt & RCAR_PWMCNT_PH0_MASK))
+ 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;
+ }
+
+ dev_info(&pdev->dev, "R-Car PWM Timer registered\n");
+
+ 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);
+ int ret;
+
+ ret = pwmchip_remove(&rcar_pwm->chip);
+ if (ret)
+ return ret;
+
+ pm_runtime_disable(&pdev->dev);
+
+ return 0;
+}
+
+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 <yoshihiro.shimoda.uh@renesas.com>");
+MODULE_DESCRIPTION("Renesas PWM Timer Driver");
+MODULE_LICENSE("GPL v2");
+MODULE_ALIAS("platform:pwm-rcar");
--
1.9.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH v3 2/2] pwm: Add support for R-Car PWM Timer
2015-05-21 2:50 ` Yoshihiro Shimoda
@ 2015-05-21 8:29 ` Geert Uytterhoeven
-1 siblings, 0 replies; 14+ messages in thread
From: Geert Uytterhoeven @ 2015-05-21 8:29 UTC (permalink / raw)
To: Yoshihiro Shimoda
Cc: Thierry Reding, Rob Herring, Pawel Moll, Mark Rutland,
Ian Campbell, Kumar Gala, linux-pwm, Linux-sh list, devicetree
Hi Shimoda-san,
On Thu, May 21, 2015 at 4:50 AM, Yoshihiro Shimoda
<yoshihiro.shimoda.uh@renesas.com> wrote:
> This patch adds support for R-Car SoCs PWM Timer.
Thanks for your patch!
> --- /dev/null
> +++ b/drivers/pwm/pwm-rcar.c
> +#define RCAR_PWM_CH_OFFSET 0x1000
This is no longer used, now each pwm instance has its own device node.
> +static void 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 * 100 * (1 << div);
> + do_div(one_cycle, clk_rate);
> +
> + tmp = period_ns * 100;
period_ns and the constant 100 are both int, hence the multiplication may
still overflow.
Please use e.g. "tmp = period_ns * 100ULL" instead.
> + do_div(tmp, one_cycle);
> + cyc = ((u32)tmp << RCAR_PWMCNT_CYC0_SHIFT) & RCAR_PWMCNT_CYC0_MASK;
I think the cast is not needed.
> +
> + tmp = duty_ns * 100;
Same here: "tmp = duty_ns * 100ULL;".
> + do_div(tmp, one_cycle);
> + ph = (u32)tmp & RCAR_PWMCNT_PH0_MASK;
I think the cast is not needed.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v3 2/2] pwm: Add support for R-Car PWM Timer
@ 2015-05-21 8:29 ` Geert Uytterhoeven
0 siblings, 0 replies; 14+ messages in thread
From: Geert Uytterhoeven @ 2015-05-21 8:29 UTC (permalink / raw)
To: Yoshihiro Shimoda
Cc: Thierry Reding, Rob Herring, Pawel Moll, Mark Rutland,
Ian Campbell, Kumar Gala, linux-pwm, Linux-sh list, devicetree
Hi Shimoda-san,
On Thu, May 21, 2015 at 4:50 AM, Yoshihiro Shimoda
<yoshihiro.shimoda.uh@renesas.com> wrote:
> This patch adds support for R-Car SoCs PWM Timer.
Thanks for your patch!
> --- /dev/null
> +++ b/drivers/pwm/pwm-rcar.c
> +#define RCAR_PWM_CH_OFFSET 0x1000
This is no longer used, now each pwm instance has its own device node.
> +static void 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 * 100 * (1 << div);
> + do_div(one_cycle, clk_rate);
> +
> + tmp = period_ns * 100;
period_ns and the constant 100 are both int, hence the multiplication may
still overflow.
Please use e.g. "tmp = period_ns * 100ULL" instead.
> + do_div(tmp, one_cycle);
> + cyc = ((u32)tmp << RCAR_PWMCNT_CYC0_SHIFT) & RCAR_PWMCNT_CYC0_MASK;
I think the cast is not needed.
> +
> + tmp = duty_ns * 100;
Same here: "tmp = duty_ns * 100ULL;".
> + do_div(tmp, one_cycle);
> + ph = (u32)tmp & RCAR_PWMCNT_PH0_MASK;
I think the cast is not needed.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v3 1/2] pwm: Add device tree binding document for R-Car PWM Timer
2015-05-21 2:50 ` Yoshihiro Shimoda
@ 2015-05-21 8:31 ` Geert Uytterhoeven
-1 siblings, 0 replies; 14+ messages in thread
From: Geert Uytterhoeven @ 2015-05-21 8:31 UTC (permalink / raw)
To: Yoshihiro Shimoda
Cc: Thierry Reding, Rob Herring, Pawel Moll, Mark Rutland,
Ian Campbell, Kumar Gala, linux-pwm, Linux-sh list, devicetree
Hi Shimoda-san,
On Thu, May 21, 2015 at 4:50 AM, Yoshihiro Shimoda
<yoshihiro.shimoda.uh@renesas.com> wrote:
> Add binding document for Renesas PWM Timer on R-Car SoCs.
Thanks for your patch!
> Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Acked-by: Geert Uytterhoeven <geert+renesas@glider.be>
with one minor nit below.
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/pwm/renesas,pwm-rcar.txt
> +Example: R8A7790 (R-Car H2) PWM Timer node
> +
> + pwm0: pwm@e6e30000 {
> + compatible = "renesas,pwm-r8a7790", "renesas,pwm-rcar";
> + reg = <0 0xe6e30000 0 0x10>;
Length 8 is sufficient, as there are only 2 32-bit registers.
> + #pwm-cells = <2>;
> + clocks = <&mstp5_clks R8A7790_CLK_PWM>;
> + pinctrl-0 = <&pwm0_pins>;
> + pinctrl-names = "default";
> + };
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v3 1/2] pwm: Add device tree binding document for R-Car PWM Timer
@ 2015-05-21 8:31 ` Geert Uytterhoeven
0 siblings, 0 replies; 14+ messages in thread
From: Geert Uytterhoeven @ 2015-05-21 8:31 UTC (permalink / raw)
To: Yoshihiro Shimoda
Cc: Thierry Reding, Rob Herring, Pawel Moll, Mark Rutland,
Ian Campbell, Kumar Gala, linux-pwm, Linux-sh list, devicetree
Hi Shimoda-san,
On Thu, May 21, 2015 at 4:50 AM, Yoshihiro Shimoda
<yoshihiro.shimoda.uh@renesas.com> wrote:
> Add binding document for Renesas PWM Timer on R-Car SoCs.
Thanks for your patch!
> Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Acked-by: Geert Uytterhoeven <geert+renesas@glider.be>
with one minor nit below.
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/pwm/renesas,pwm-rcar.txt
> +Example: R8A7790 (R-Car H2) PWM Timer node
> +
> + pwm0: pwm@e6e30000 {
> + compatible = "renesas,pwm-r8a7790", "renesas,pwm-rcar";
> + reg = <0 0xe6e30000 0 0x10>;
Length 8 is sufficient, as there are only 2 32-bit registers.
> + #pwm-cells = <2>;
> + clocks = <&mstp5_clks R8A7790_CLK_PWM>;
> + pinctrl-0 = <&pwm0_pins>;
> + pinctrl-names = "default";
> + };
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 14+ messages in thread
* RE: [PATCH v3 2/2] pwm: Add support for R-Car PWM Timer
2015-05-21 8:29 ` Geert Uytterhoeven
@ 2015-05-21 9:25 ` Yoshihiro Shimoda
-1 siblings, 0 replies; 14+ messages in thread
From: Yoshihiro Shimoda @ 2015-05-21 9:25 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Thierry Reding, Rob Herring, Pawel Moll, Mark Rutland,
Ian Campbell, Kumar Gala, linux-pwm, Linux-sh list, devicetree
SGkgR2VlcnQtc2FuLA0KDQpUaGFuayB5b3UgZm9yIHRoZSByZXZpZXchDQoNCj4gU2VudDogVGh1
cnNkYXksIE1heSAyMSwgMjAxNSA1OjMwIFBNDQo8IHNuaXAgPg0KPiA+IC0tLSAvZGV2L251bGwN
Cj4gPiArKysgYi9kcml2ZXJzL3B3bS9wd20tcmNhci5jDQo+IA0KPiA+ICsjZGVmaW5lIFJDQVJf
UFdNX0NIX09GRlNFVCAgICAgMHgxMDAwDQo+IA0KPiBUaGlzIGlzIG5vIGxvbmdlciB1c2VkLCBu
b3cgZWFjaCBwd20gaW5zdGFuY2UgaGFzIGl0cyBvd24gZGV2aWNlIG5vZGUuDQoNCk9vcHMuIEkg
d2lsbCByZW1vdmUgaXQuDQoNCj4gPiArc3RhdGljIHZvaWQgcmNhcl9wd21fc2V0X2NvdW50ZXIo
c3RydWN0IHJjYXJfcHdtX2NoaXAgKnJwLCBpbnQgZGl2LA0KPiA+ICsgICAgICAgICAgICAgICAg
ICAgICAgICAgICAgICAgIGludCBkdXR5X25zLCBpbnQgcGVyaW9kX25zKQ0KPiA+ICt7DQo+ID4g
KyAgICAgICB1bnNpZ25lZCBsb25nIGxvbmcgb25lX2N5Y2xlLCB0bXA7ICAgICAgLyogMC4wMSBu
YW5vc2Vjb25kcyAqLw0KPiA+ICsgICAgICAgdW5zaWduZWQgbG9uZyBjbGt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ICAgcGggPSAodTMyKXRtcCAmIFJDQVJf
UFdNQ05UX1BIMF9NQVNLOw0KPiANCj4gSSB0aGluayB0aGUgY2FzdCBpcyBub3QgbmVlZGVkLg0K
DQpUaGFuayB5b3UgYWdhaW4uDQoNCkJlc3QgcmVnYXJkcywNCllvc2hpaGlybyBTaGltb2RhDQoN
Cj4gR3J7b2V0amUsZWV0aW5nfXMsDQo+IA0KPiAgICAgICAgICAgICAgICAgICAgICAgICBHZWVy
dA0KPiANCj4gLS0NCj4gR2VlcnQgVXl0dGVyaG9ldmVuIC0tIFRoZXJlJ3MgbG90cyBvZiBMaW51
eCBiZXlvbmQgaWEzMiAtLSBnZWVydEBsaW51eC1tNjhrLm9yZw0KPiANCj4gSW4gcGVyc29uYWwg
Y29udmVyc2F0aW9ucyB3aXRoIHRlY2huaWNhbCBwZW9wbGUsIEkgY2FsbCBteXNlbGYgYSBoYWNr
ZXIuIEJ1dA0KPiB3aGVuIEknbSB0YWxraW5nIHRvIGpvdXJuYWxpc3RzIEkganVzdCBzYXkgInBy
b2dyYW1tZXIiIG9yIHNvbWV0aGluZyBsaWtlIHRoYXQuDQo+ICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgICAgLS0gTGludXMgVG9ydmFsZHMNCg=
^ permalink raw reply [flat|nested] 14+ messages in thread
* RE: [PATCH v3 2/2] pwm: Add support for R-Car PWM Timer
@ 2015-05-21 9:25 ` Yoshihiro Shimoda
0 siblings, 0 replies; 14+ messages in thread
From: Yoshihiro Shimoda @ 2015-05-21 9:25 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Thierry Reding, Rob Herring, Pawel Moll, Mark Rutland,
Ian Campbell, Kumar Gala, linux-pwm, Linux-sh list, devicetree
Hi Geert-san,
Thank you for the review!
> Sent: Thursday, May 21, 2015 5:30 PM
< snip >
> > --- /dev/null
> > +++ b/drivers/pwm/pwm-rcar.c
>
> > +#define RCAR_PWM_CH_OFFSET 0x1000
>
> This is no longer used, now each pwm instance has its own device node.
Oops. I will remove it.
> > +static void 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 * 100 * (1 << div);
> > + do_div(one_cycle, clk_rate);
> > +
> > + tmp = period_ns * 100;
>
> period_ns and the constant 100 are both int, hence the multiplication may
> still overflow.
> Please use e.g. "tmp = period_ns * 100ULL" instead.
Thank you for the point. I will use it.
> > + do_div(tmp, one_cycle);
> > + cyc = ((u32)tmp << RCAR_PWMCNT_CYC0_SHIFT) & RCAR_PWMCNT_CYC0_MASK;
>
> I think the cast is not needed.
Thank you for the point. I will remove it.
> > +
> > + tmp = duty_ns * 100;
>
> Same here: "tmp = duty_ns * 100ULL;".
Thank you again.
> > + do_div(tmp, one_cycle);
> > + ph = (u32)tmp & RCAR_PWMCNT_PH0_MASK;
>
> I think the cast is not needed.
Thank you again.
Best regards,
Yoshihiro Shimoda
> Gr{oetje,eeting}s,
>
> Geert
>
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
>
> In personal conversations with technical people, I call myself a hacker. But
> when I'm talking to journalists I just say "programmer" or something like that.
> -- Linus Torvalds
^ permalink raw reply [flat|nested] 14+ messages in thread
* RE: [PATCH v3 1/2] pwm: Add device tree binding document for R-Car PWM Timer
2015-05-21 8:31 ` Geert Uytterhoeven
@ 2015-05-21 9:27 ` Yoshihiro Shimoda
-1 siblings, 0 replies; 14+ messages in thread
From: Yoshihiro Shimoda @ 2015-05-21 9:27 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Thierry Reding, Rob Herring, Pawel Moll, Mark Rutland,
Ian Campbell, Kumar Gala, linux-pwm, Linux-sh list, devicetree
SGkgR2VlcnQtc2FuLA0KDQpUaGFuayB5b3UgZm9yIHRoZSByZXZpZXchDQoN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0KPiB0aGUgYm9keSBvZiBhIG1l
c3NhZ2UgdG8gbWFqb3Jkb21vQHZnZXIua2VybmVsLm9yZw0KPiBNb3JlIG1ham9yZG9tbyBpbmZv
IGF0ICBodHRwOi8vdmdlci5rZXJuZWwub3JnL21ham9yZG9tby1pbmZvLmh0bWwNCg=
^ permalink raw reply [flat|nested] 14+ messages in thread
* RE: [PATCH v3 1/2] pwm: Add device tree binding document for R-Car PWM Timer
@ 2015-05-21 9:27 ` Yoshihiro Shimoda
0 siblings, 0 replies; 14+ messages in thread
From: Yoshihiro Shimoda @ 2015-05-21 9:27 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Thierry Reding, Rob Herring, Pawel Moll, Mark Rutland,
Ian Campbell, Kumar Gala, linux-pwm, Linux-sh list, devicetree
Hi Geert-san,
Thank you for the review!
> Sent: Thursday, May 21, 2015 5:32 PM
>
> Hi Shimoda-san,
>
> On Thu, May 21, 2015 at 4:50 AM, Yoshihiro Shimoda
> <yoshihiro.shimoda.uh@renesas.com> wrote:
> > Add binding document for Renesas PWM Timer on R-Car SoCs.
>
> Thanks for your patch!
>
> > Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
>
> Acked-by: Geert Uytterhoeven <geert+renesas@glider.be>
> with one minor nit below.
Thank you for the Acked-by.
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/pwm/renesas,pwm-rcar.txt
>
> > +Example: R8A7790 (R-Car H2) PWM Timer node
> > +
> > + pwm0: pwm@e6e30000 {
> > + compatible = "renesas,pwm-r8a7790", "renesas,pwm-rcar";
> > + reg = <0 0xe6e30000 0 0x10>;
>
> Length 8 is sufficient, as there are only 2 32-bit registers.
Thank you for the point. I will fix it.
Best regards,
Yoshihiro Shimoda
> > + #pwm-cells = <2>;
> > + clocks = <&mstp5_clks R8A7790_CLK_PWM>;
> > + pinctrl-0 = <&pwm0_pins>;
> > + pinctrl-names = "default";
> > + };
>
> Gr{oetje,eeting}s,
>
> Geert
>
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
>
> In personal conversations with technical people, I call myself a hacker. But
> when I'm talking to journalists I just say "programmer" or something like that.
> -- Linus Torvalds
> --
> To unsubscribe from this list: send the line "unsubscribe devicetree" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2015-05-21 9:27 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-21 2:50 [PATCH v3 0/2] pwm: Add support for R-Car PWM Timer Yoshihiro Shimoda
2015-05-21 2:50 ` Yoshihiro Shimoda
2015-05-21 2:50 ` [PATCH v3 1/2] pwm: Add device tree binding document " Yoshihiro Shimoda
2015-05-21 2:50 ` Yoshihiro Shimoda
2015-05-21 8:31 ` Geert Uytterhoeven
2015-05-21 8:31 ` Geert Uytterhoeven
2015-05-21 9:27 ` Yoshihiro Shimoda
2015-05-21 9:27 ` Yoshihiro Shimoda
2015-05-21 2:50 ` [PATCH v3 2/2] pwm: Add support " Yoshihiro Shimoda
2015-05-21 2:50 ` Yoshihiro Shimoda
2015-05-21 8:29 ` Geert Uytterhoeven
2015-05-21 8:29 ` Geert Uytterhoeven
2015-05-21 9:25 ` Yoshihiro Shimoda
2015-05-21 9:25 ` Yoshihiro Shimoda
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.