1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * Backlight driver for HP Jornada 700 series (710/720/728)
5 * Copyright (C) 2006-2009 Kristoffer Ericson <kristoffer.ericson@gmail.com>
8 #include <linux/backlight.h>
9 #include <linux/device.h>
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/platform_device.h>
15 #include <mach/jornada720.h>
16 #include <mach/hardware.h>
18 #include <video/s1d13xxxfb.h>
20 #define BL_MAX_BRIGHT 255
21 #define BL_DEF_BRIGHT 25
23 static int jornada_bl_get_brightness(struct backlight_device
*bd
)
27 /* check if backlight is on */
28 if (!(PPSR
& PPC_LDD1
))
33 /* cmd should return txdummy */
34 ret
= jornada_ssp_byte(GETBRIGHTNESS
);
36 if (jornada_ssp_byte(GETBRIGHTNESS
) != TXDUMMY
) {
37 dev_err(&bd
->dev
, "get brightness timeout\n");
42 /* exchange txdummy for value */
43 ret
= jornada_ssp_byte(TXDUMMY
);
47 return BL_MAX_BRIGHT
- ret
;
50 static int jornada_bl_update_status(struct backlight_device
*bd
)
56 /* If backlight is off then really turn it off */
57 if ((bd
->props
.power
!= FB_BLANK_UNBLANK
) || (bd
->props
.fb_blank
!= FB_BLANK_UNBLANK
)) {
58 ret
= jornada_ssp_byte(BRIGHTNESSOFF
);
60 dev_info(&bd
->dev
, "brightness off timeout\n");
61 /* turn off backlight */
66 } else /* turn on backlight */
69 /* send command to our mcu */
70 if (jornada_ssp_byte(SETBRIGHTNESS
) != TXDUMMY
) {
71 dev_info(&bd
->dev
, "failed to set brightness\n");
77 * at this point we expect that the mcu has accepted
78 * our command and is waiting for our new value
79 * please note that maximum brightness is 255,
80 * but due to physical layout it is equal to 0, so we simply
81 * invert the value (MAX VALUE - NEW VALUE).
83 if (jornada_ssp_byte(BL_MAX_BRIGHT
- bd
->props
.brightness
)
85 dev_err(&bd
->dev
, "set brightness failed\n");
90 * If infact we get an TXDUMMY as output we are happy and dont
91 * make any further comments about it
99 static const struct backlight_ops jornada_bl_ops
= {
100 .get_brightness
= jornada_bl_get_brightness
,
101 .update_status
= jornada_bl_update_status
,
102 .options
= BL_CORE_SUSPENDRESUME
,
105 static int jornada_bl_probe(struct platform_device
*pdev
)
107 struct backlight_properties props
;
109 struct backlight_device
*bd
;
111 memset(&props
, 0, sizeof(struct backlight_properties
));
112 props
.type
= BACKLIGHT_RAW
;
113 props
.max_brightness
= BL_MAX_BRIGHT
;
115 bd
= devm_backlight_device_register(&pdev
->dev
, S1D_DEVICENAME
,
116 &pdev
->dev
, NULL
, &jornada_bl_ops
,
120 dev_err(&pdev
->dev
, "failed to register device, err=%x\n", ret
);
124 bd
->props
.power
= FB_BLANK_UNBLANK
;
125 bd
->props
.brightness
= BL_DEF_BRIGHT
;
127 * note. make sure max brightness is set otherwise
128 * you will get seemingly non-related errors when
129 * trying to change brightness
131 jornada_bl_update_status(bd
);
133 platform_set_drvdata(pdev
, bd
);
134 dev_info(&pdev
->dev
, "HP Jornada 700 series backlight driver\n");
139 static struct platform_driver jornada_bl_driver
= {
140 .probe
= jornada_bl_probe
,
142 .name
= "jornada_bl",
146 module_platform_driver(jornada_bl_driver
);
148 MODULE_AUTHOR("Kristoffer Ericson <kristoffer.ericson>");
149 MODULE_DESCRIPTION("HP Jornada 710/720/728 Backlight driver");
150 MODULE_LICENSE("GPL");