WIP FPC-III support
[linux/fpc-iii.git] / drivers / video / backlight / jornada720_bl.c
blob996f7ba3b373696d20ec9754a77a1eccd812e841
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
4 * Backlight driver for HP Jornada 700 series (710/720/728)
5 * Copyright (C) 2006-2009 Kristoffer Ericson <kristoffer.ericson@gmail.com>
6 */
8 #include <linux/backlight.h>
9 #include <linux/device.h>
10 #include <linux/fb.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)
25 int ret;
27 /* check if backlight is on */
28 if (!(PPSR & PPC_LDD1))
29 return 0;
31 jornada_ssp_start();
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");
38 jornada_ssp_end();
39 return -ETIMEDOUT;
42 /* exchange txdummy for value */
43 ret = jornada_ssp_byte(TXDUMMY);
45 jornada_ssp_end();
47 return BL_MAX_BRIGHT - ret;
50 static int jornada_bl_update_status(struct backlight_device *bd)
52 int ret = 0;
54 jornada_ssp_start();
56 /* If backlight is off then really turn it off */
57 if (backlight_is_blank(bd)) {
58 ret = jornada_ssp_byte(BRIGHTNESSOFF);
59 if (ret != TXDUMMY) {
60 dev_info(&bd->dev, "brightness off timeout\n");
61 /* turn off backlight */
62 PPSR &= ~PPC_LDD1;
63 PPDR |= PPC_LDD1;
64 ret = -ETIMEDOUT;
66 } else /* turn on backlight */
67 PPSR |= PPC_LDD1;
69 /* send command to our mcu */
70 if (jornada_ssp_byte(SETBRIGHTNESS) != TXDUMMY) {
71 dev_info(&bd->dev, "failed to set brightness\n");
72 ret = -ETIMEDOUT;
73 goto out;
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)
84 != TXDUMMY) {
85 dev_err(&bd->dev, "set brightness failed\n");
86 ret = -ETIMEDOUT;
90 * If infact we get an TXDUMMY as output we are happy and dont
91 * make any further comments about it
93 out:
94 jornada_ssp_end();
96 return ret;
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;
108 int ret;
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,
117 &props);
118 if (IS_ERR(bd)) {
119 ret = PTR_ERR(bd);
120 dev_err(&pdev->dev, "failed to register device, err=%x\n", ret);
121 return 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");
136 return 0;
139 static struct platform_driver jornada_bl_driver = {
140 .probe = jornada_bl_probe,
141 .driver = {
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");