20
20
#include <linux/pwm.h>
21
21
#include <linux/regmap.h>
22
22
23
- #define NUM_PWM 8
23
+ struct soc_info {
24
+ unsigned int num_pwms ;
25
+ };
24
26
25
27
struct jz4740_pwm_chip {
26
28
struct pwm_chip chip ;
@@ -36,7 +38,7 @@ static bool jz4740_pwm_can_use_chn(struct jz4740_pwm_chip *jz,
36
38
unsigned int channel )
37
39
{
38
40
/* 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 );
40
42
41
43
device_property_read_u32 (jz -> chip .dev -> parent ,
42
44
"ingenic,pwm-channels-mask" ,
@@ -226,6 +228,11 @@ static int jz4740_pwm_probe(struct platform_device *pdev)
226
228
{
227
229
struct device * dev = & pdev -> dev ;
228
230
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 ;
229
236
230
237
jz4740 = devm_kzalloc (dev , sizeof (* jz4740 ), GFP_KERNEL );
231
238
if (!jz4740 )
@@ -239,7 +246,7 @@ static int jz4740_pwm_probe(struct platform_device *pdev)
239
246
240
247
jz4740 -> chip .dev = dev ;
241
248
jz4740 -> chip .ops = & jz4740_pwm_ops ;
242
- jz4740 -> chip .npwm = NUM_PWM ;
249
+ jz4740 -> chip .npwm = info -> num_pwms ;
243
250
jz4740 -> chip .base = -1 ;
244
251
jz4740 -> chip .of_xlate = of_pwm_xlate_with_flags ;
245
252
jz4740 -> chip .of_pwm_n_cells = 3 ;
@@ -256,9 +263,18 @@ static int jz4740_pwm_remove(struct platform_device *pdev)
256
263
return pwmchip_remove (& jz4740 -> chip );
257
264
}
258
265
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
+
259
274
#ifdef CONFIG_OF
260
275
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 },
262
278
{},
263
279
};
264
280
MODULE_DEVICE_TABLE (of , jz4740_pwm_dt_ids );
0 commit comments