[PATCH v6 16/24] pwm: jz4740: Add support for the JZ4725B

From: Paul Cercueil
Date: Thu Aug 09 2018 - 17:45:48 EST


The PWM in the JZ4725B works the same as in the JZ4740, except that it
only has 6 channels available instead of 8.

Signed-off-by: Paul Cercueil <paul@xxxxxxxxxxxxxxx>
---
drivers/pwm/pwm-jz4740.c | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)

v5: New patch

v6: - Move of_device_id structure back at the bottom (less noise in
patch)
- Use device_get_match_data() instead of of_* variant

diff --git a/drivers/pwm/pwm-jz4740.c b/drivers/pwm/pwm-jz4740.c
index 5814825d9bed..66a72bd7424f 100644
--- a/drivers/pwm/pwm-jz4740.c
+++ b/drivers/pwm/pwm-jz4740.c
@@ -25,6 +25,10 @@

#define NUM_PWM 8

+struct jz4740_soc_info {
+ unsigned int num_pwms;
+};
+
struct jz4740_pwm_chip {
struct pwm_chip chip;
struct clk *clks[NUM_PWM];
@@ -200,9 +204,14 @@ static const struct pwm_ops jz4740_pwm_ops = {

static int jz4740_pwm_probe(struct platform_device *pdev)
{
+ const struct jz4740_soc_info *soc_info;
struct jz4740_pwm_chip *jz4740;
struct device *dev = &pdev->dev;

+ soc_info = device_get_match_data(dev);
+ if (!soc_info)
+ return -EINVAL;
+
jz4740 = devm_kzalloc(dev, sizeof(*jz4740), GFP_KERNEL);
if (!jz4740)
return -ENOMEM;
@@ -215,7 +224,7 @@ static int jz4740_pwm_probe(struct platform_device *pdev)

jz4740->chip.dev = dev;
jz4740->chip.ops = &jz4740_pwm_ops;
- jz4740->chip.npwm = NUM_PWM;
+ jz4740->chip.npwm = soc_info->num_pwms;
jz4740->chip.base = -1;
jz4740->chip.of_xlate = of_pwm_xlate_with_flags;
jz4740->chip.of_pwm_n_cells = 3;
@@ -233,8 +242,17 @@ static int jz4740_pwm_remove(struct platform_device *pdev)
}

#ifdef CONFIG_OF
+static const struct jz4740_soc_info jz4740_soc_info = {
+ .num_pwms = 8,
+};
+
+static const struct jz4740_soc_info jz4725b_soc_info = {
+ .num_pwms = 6,
+};
+
static const struct of_device_id jz4740_pwm_dt_ids[] = {
- { .compatible = "ingenic,jz4740-pwm", },
+ { .compatible = "ingenic,jz4740-pwm", .data = &jz4740_soc_info },
+ { .compatible = "ingenic,jz4725b-pwm", .data = &jz4725b_soc_info },
{},
};
MODULE_DEVICE_TABLE(of, jz4740_pwm_dt_ids);
--
2.11.0