Skip to content

Commit 74db728

Browse files
pcercueithierryreding
authored andcommitted
pwm: jz4740: Add support for the JZ4725B
The PWM hardware in the JZ4725B works the same as in the JZ4740, but has only six channels available. Signed-off-by: Paul Cercueil <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
1 parent a020f22 commit 74db728

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

drivers/pwm/pwm-jz4740.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
#include <linux/pwm.h>
2121
#include <linux/regmap.h>
2222

23-
#define NUM_PWM 8
23+
struct soc_info {
24+
unsigned int num_pwms;
25+
};
2426

2527
struct jz4740_pwm_chip {
2628
struct pwm_chip chip;
@@ -36,7 +38,7 @@ static bool jz4740_pwm_can_use_chn(struct jz4740_pwm_chip *jz,
3638
unsigned int channel)
3739
{
3840
/* Enable all TCU channels for PWM use by default except channels 0/1 */
39-
u32 pwm_channels_mask = GENMASK(NUM_PWM - 1, 2);
41+
u32 pwm_channels_mask = GENMASK(jz->chip.npwm - 1, 2);
4042

4143
device_property_read_u32(jz->chip.dev->parent,
4244
"ingenic,pwm-channels-mask",
@@ -226,6 +228,11 @@ static int jz4740_pwm_probe(struct platform_device *pdev)
226228
{
227229
struct device *dev = &pdev->dev;
228230
struct jz4740_pwm_chip *jz4740;
231+
const struct soc_info *info;
232+
233+
info = device_get_match_data(dev);
234+
if (!info)
235+
return -EINVAL;
229236

230237
jz4740 = devm_kzalloc(dev, sizeof(*jz4740), GFP_KERNEL);
231238
if (!jz4740)
@@ -239,7 +246,7 @@ static int jz4740_pwm_probe(struct platform_device *pdev)
239246

240247
jz4740->chip.dev = dev;
241248
jz4740->chip.ops = &jz4740_pwm_ops;
242-
jz4740->chip.npwm = NUM_PWM;
249+
jz4740->chip.npwm = info->num_pwms;
243250
jz4740->chip.base = -1;
244251
jz4740->chip.of_xlate = of_pwm_xlate_with_flags;
245252
jz4740->chip.of_pwm_n_cells = 3;
@@ -256,9 +263,18 @@ static int jz4740_pwm_remove(struct platform_device *pdev)
256263
return pwmchip_remove(&jz4740->chip);
257264
}
258265

266+
static const struct soc_info __maybe_unused jz4740_soc_info = {
267+
.num_pwms = 8,
268+
};
269+
270+
static const struct soc_info __maybe_unused jz4725b_soc_info = {
271+
.num_pwms = 6,
272+
};
273+
259274
#ifdef CONFIG_OF
260275
static const struct of_device_id jz4740_pwm_dt_ids[] = {
261-
{ .compatible = "ingenic,jz4740-pwm", },
276+
{ .compatible = "ingenic,jz4740-pwm", .data = &jz4740_soc_info },
277+
{ .compatible = "ingenic,jz4725b-pwm", .data = &jz4725b_soc_info },
262278
{},
263279
};
264280
MODULE_DEVICE_TABLE(of, jz4740_pwm_dt_ids);

0 commit comments

Comments
 (0)