@@ -233,6 +233,57 @@ static int pca955x_read_ls(struct i2c_client *client, int n, u8 *val)
233
233
return 0 ;
234
234
}
235
235
236
+ static int pca955x_read_pwm (struct i2c_client * client , int n , u8 * val )
237
+ {
238
+ struct pca955x * pca955x = i2c_get_clientdata (client );
239
+ u8 cmd = pca95xx_num_input_regs (pca955x -> chipdef -> bits ) + 1 + (2 * n );
240
+ int ret ;
241
+
242
+ ret = i2c_smbus_read_byte_data (client , cmd );
243
+ if (ret < 0 ) {
244
+ dev_err (& client -> dev , "%s: reg 0x%x, err %d\n" ,
245
+ __func__ , n , ret );
246
+ return ret ;
247
+ }
248
+ * val = (u8 )ret ;
249
+ return 0 ;
250
+ }
251
+
252
+ static enum led_brightness pca955x_led_get (struct led_classdev * led_cdev )
253
+ {
254
+ struct pca955x_led * pca955x_led = container_of (led_cdev ,
255
+ struct pca955x_led ,
256
+ led_cdev );
257
+ struct pca955x * pca955x = pca955x_led -> pca955x ;
258
+ u8 ls , pwm ;
259
+ int ret ;
260
+
261
+ ret = pca955x_read_ls (pca955x -> client , pca955x_led -> led_num / 4 , & ls );
262
+ if (ret )
263
+ return ret ;
264
+
265
+ ls = (ls >> ((pca955x_led -> led_num % 4 ) << 1 )) & 0x3 ;
266
+ switch (ls ) {
267
+ case PCA955X_LS_LED_ON :
268
+ ret = LED_FULL ;
269
+ break ;
270
+ case PCA955X_LS_LED_OFF :
271
+ ret = LED_OFF ;
272
+ break ;
273
+ case PCA955X_LS_BLINK0 :
274
+ ret = LED_HALF ;
275
+ break ;
276
+ case PCA955X_LS_BLINK1 :
277
+ ret = pca955x_read_pwm (pca955x -> client , 1 , & pwm );
278
+ if (ret )
279
+ return ret ;
280
+ ret = 255 - pwm ;
281
+ break ;
282
+ }
283
+
284
+ return ret ;
285
+ }
286
+
236
287
static int pca955x_led_set (struct led_classdev * led_cdev ,
237
288
enum led_brightness value )
238
289
{
@@ -512,6 +563,7 @@ static int pca955x_probe(struct i2c_client *client,
512
563
513
564
led -> name = pca955x_led -> name ;
514
565
led -> brightness_set_blocking = pca955x_led_set ;
566
+ led -> brightness_get = pca955x_led_get ;
515
567
516
568
err = devm_led_classdev_register (& client -> dev , led );
517
569
if (err )
0 commit comments