8
8
* Andrzej Hajda <[email protected] >
9
9
*/
10
10
11
+ #include <linux/backlight.h>
11
12
#include <linux/delay.h>
12
13
#include <linux/gpio/consumer.h>
13
14
#include <linux/module.h>
@@ -310,8 +311,30 @@ static int ld9040_parse_dt(struct ld9040 *ctx)
310
311
return 0 ;
311
312
}
312
313
314
+ static int ld9040_bl_update_status (struct backlight_device * dev )
315
+ {
316
+ struct ld9040 * ctx = bl_get_data (dev );
317
+
318
+ ctx -> brightness = backlight_get_brightness (dev );
319
+ ld9040_brightness_set (ctx );
320
+
321
+ return 0 ;
322
+ }
323
+
324
+ static const struct backlight_ops ld9040_bl_ops = {
325
+ .update_status = ld9040_bl_update_status ,
326
+ };
327
+
328
+ static const struct backlight_properties ld9040_bl_props = {
329
+ .type = BACKLIGHT_RAW ,
330
+ .scale = BACKLIGHT_SCALE_NON_LINEAR ,
331
+ .max_brightness = ARRAY_SIZE (ld9040_gammas ) - 1 ,
332
+ .brightness = ARRAY_SIZE (ld9040_gammas ) - 1 ,
333
+ };
334
+
313
335
static int ld9040_probe (struct spi_device * spi )
314
336
{
337
+ struct backlight_device * bldev ;
315
338
struct device * dev = & spi -> dev ;
316
339
struct ld9040 * ctx ;
317
340
int ret ;
@@ -323,7 +346,7 @@ static int ld9040_probe(struct spi_device *spi)
323
346
spi_set_drvdata (spi , ctx );
324
347
325
348
ctx -> dev = dev ;
326
- ctx -> brightness = ARRAY_SIZE ( ld9040_gammas ) - 1 ;
349
+ ctx -> brightness = ld9040_bl_props . brightness ;
327
350
328
351
ret = ld9040_parse_dt (ctx );
329
352
if (ret < 0 )
@@ -353,6 +376,12 @@ static int ld9040_probe(struct spi_device *spi)
353
376
drm_panel_init (& ctx -> panel , dev , & ld9040_drm_funcs ,
354
377
DRM_MODE_CONNECTOR_DPI );
355
378
379
+ bldev = devm_backlight_device_register (dev , dev_name (dev ), dev ,
380
+ ctx , & ld9040_bl_ops ,
381
+ & ld9040_bl_props );
382
+ if (IS_ERR (bldev ))
383
+ return PTR_ERR (bldev );
384
+
356
385
drm_panel_add (& ctx -> panel );
357
386
358
387
return 0 ;
0 commit comments