16
16
17
17
struct gb_pwm_chip {
18
18
struct gb_connection * connection ;
19
- u8 pwm_max ; /* max pwm number */
20
-
21
19
struct pwm_chip chip ;
22
20
};
23
21
@@ -26,17 +24,21 @@ static inline struct gb_pwm_chip *pwm_chip_to_gb_pwm_chip(struct pwm_chip *chip)
26
24
return container_of (chip , struct gb_pwm_chip , chip );
27
25
}
28
26
29
- static int gb_pwm_count_operation (struct gb_pwm_chip * pwmc )
27
+ static int gb_pwm_get_npwm (struct gb_connection * connection )
30
28
{
31
29
struct gb_pwm_count_response response ;
32
30
int ret ;
33
31
34
- ret = gb_operation_sync (pwmc -> connection , GB_PWM_TYPE_PWM_COUNT ,
32
+ ret = gb_operation_sync (connection , GB_PWM_TYPE_PWM_COUNT ,
35
33
NULL , 0 , & response , sizeof (response ));
36
34
if (ret )
37
35
return ret ;
38
- pwmc -> pwm_max = response .count ;
39
- return 0 ;
36
+
37
+ /*
38
+ * The request returns the highest allowed PWM id parameter. So add one
39
+ * to get the number of PWMs.
40
+ */
41
+ return response .count + 1 ;
40
42
}
41
43
42
44
static int gb_pwm_activate_operation (struct pwm_chip * chip , u8 which )
@@ -245,7 +247,7 @@ static int gb_pwm_probe(struct gbphy_device *gbphy_dev,
245
247
struct gb_connection * connection ;
246
248
struct gb_pwm_chip * pwmc ;
247
249
struct pwm_chip * chip ;
248
- int ret ;
250
+ int ret , npwm ;
249
251
250
252
pwmc = kzalloc (sizeof (* pwmc ), GFP_KERNEL );
251
253
if (!pwmc )
@@ -267,15 +269,16 @@ static int gb_pwm_probe(struct gbphy_device *gbphy_dev,
267
269
goto exit_connection_destroy ;
268
270
269
271
/* Query number of pwms present */
270
- ret = gb_pwm_count_operation ( pwmc );
271
- if (ret )
272
+ ret = gb_pwm_get_npwm ( connection );
273
+ if (ret < 0 )
272
274
goto exit_connection_disable ;
275
+ npwm = ret ;
273
276
274
277
chip = & pwmc -> chip ;
275
278
276
279
chip -> dev = & gbphy_dev -> dev ;
277
280
chip -> ops = & gb_pwm_ops ;
278
- chip -> npwm = pwmc -> pwm_max + 1 ;
281
+ chip -> npwm = npwm ;
279
282
280
283
ret = pwmchip_add (chip );
281
284
if (ret ) {
0 commit comments