Skip to content

Commit a2005fc

Browse files
pcercueithierryreding
authored andcommitted
pwm: jz4740: Allow selection of PWM channels 0 and 1
The TCU channels 0 and 1 were previously reserved for system tasks, and thus unavailable for PWM. Signed-off-by: Paul Cercueil <[email protected]> Tested-by: Mathieu Malaterre <[email protected]> Tested-by: Artur Rojek <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
1 parent c269351 commit a2005fc

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

drivers/pwm/pwm-jz4740.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,27 @@ static inline struct jz4740_pwm_chip *to_jz4740(struct pwm_chip *chip)
3333
return container_of(chip, struct jz4740_pwm_chip, chip);
3434
}
3535

36+
static bool jz4740_pwm_can_use_chn(struct jz4740_pwm_chip *jz,
37+
unsigned int channel)
38+
{
39+
/* Enable all TCU channels for PWM use by default except channels 0/1 */
40+
u32 pwm_channels_mask = GENMASK(NUM_PWM - 1, 2);
41+
42+
device_property_read_u32(jz->chip.dev->parent,
43+
"ingenic,pwm-channels-mask",
44+
&pwm_channels_mask);
45+
46+
return !!(pwm_channels_mask & BIT(channel));
47+
}
48+
3649
static int jz4740_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)
3750
{
3851
struct jz4740_pwm_chip *jz = to_jz4740(chip);
3952
struct clk *clk;
4053
char name[16];
4154
int err;
4255

43-
/*
44-
* Timers 0 and 1 are used for system tasks, so they are unavailable
45-
* for use as PWMs.
46-
*/
47-
if (pwm->hwpwm < 2)
56+
if (!jz4740_pwm_can_use_chn(jz, pwm->hwpwm))
4857
return -EBUSY;
4958

5059
snprintf(name, sizeof(name), "timer%u", pwm->hwpwm);

0 commit comments

Comments
 (0)