sh_eth: fix EESIPR values for SH77{34|63}
[linux/fpc-iii.git] / drivers / video / backlight / jornada720_bl.c
blob7e6ff53468924bcb246a81ad018dcbb397e54ea4
1 /*
3 * Backlight driver for HP Jornada 700 series (710/720/728)
4 * Copyright (C) 2006-2009 Kristoffer Ericson <kristoffer.ericson@gmail.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License version
8 * 2 or any later version as published by the Free Software Foundation.
12 #include <linux/backlight.h>
13 #include <linux/device.h>
14 #include <linux/fb.h>
15 #include <linux/kernel.h>
16 #include <linux/module.h>
17 #include <linux/platform_device.h>
19 #include <mach/jornada720.h>
20 #include <mach/hardware.h>
22 #include <video/s1d13xxxfb.h>
24 #define BL_MAX_BRIGHT 255
25 #define BL_DEF_BRIGHT 25
27 static int jornada_bl_get_brightness(struct backlight_device *bd)
29 int ret;
31 /* check if backlight is on */
32 if (!(PPSR & PPC_LDD1))
33 return 0;
35 jornada_ssp_start();
37 /* cmd should return txdummy */
38 ret = jornada_ssp_byte(GETBRIGHTNESS);
40 if (jornada_ssp_byte(GETBRIGHTNESS) != TXDUMMY) {
41 dev_err(&bd->dev, "get brightness timeout\n");
42 jornada_ssp_end();
43 return -ETIMEDOUT;
46 /* exchange txdummy for value */
47 ret = jornada_ssp_byte(TXDUMMY);
49 jornada_ssp_end();
51 return BL_MAX_BRIGHT - ret;
54 static int jornada_bl_update_status(struct backlight_device *bd)
56 int ret = 0;
58 jornada_ssp_start();
60 /* If backlight is off then really turn it off */
61 if ((bd->props.power != FB_BLANK_UNBLANK) || (bd->props.fb_blank != FB_BLANK_UNBLANK)) {
62 ret = jornada_ssp_byte(BRIGHTNESSOFF);
63 if (ret != TXDUMMY) {
64 dev_info(&bd->dev, "brightness off timeout\n");
65 /* turn off backlight */
66 PPSR &= ~PPC_LDD1;
67 PPDR |= PPC_LDD1;
68 ret = -ETIMEDOUT;
70 } else /* turn on backlight */
71 PPSR |= PPC_LDD1;
73 /* send command to our mcu */
74 if (jornada_ssp_byte(SETBRIGHTNESS) != TXDUMMY) {
75 dev_info(&bd->dev, "failed to set brightness\n");
76 ret = -ETIMEDOUT;
77 goto out;
81 * at this point we expect that the mcu has accepted
82 * our command and is waiting for our new value
83 * please note that maximum brightness is 255,
84 * but due to physical layout it is equal to 0, so we simply
85 * invert the value (MAX VALUE - NEW VALUE).
87 if (jornada_ssp_byte(BL_MAX_BRIGHT - bd->props.brightness)
88 != TXDUMMY) {
89 dev_err(&bd->dev, "set brightness failed\n");
90 ret = -ETIMEDOUT;
94 * If infact we get an TXDUMMY as output we are happy and dont
95 * make any further comments about it
97 out:
98 jornada_ssp_end();
100 return ret;
103 static const struct backlight_ops jornada_bl_ops = {
104 .get_brightness = jornada_bl_get_brightness,
105 .update_status = jornada_bl_update_status,
106 .options = BL_CORE_SUSPENDRESUME,
109 static int jornada_bl_probe(struct platform_device *pdev)
111 struct backlight_properties props;
112 int ret;
113 struct backlight_device *bd;
115 memset(&props, 0, sizeof(struct backlight_properties));
116 props.type = BACKLIGHT_RAW;
117 props.max_brightness = BL_MAX_BRIGHT;
119 bd = devm_backlight_device_register(&pdev->dev, S1D_DEVICENAME,
120 &pdev->dev, NULL, &jornada_bl_ops,
121 &props);
122 if (IS_ERR(bd)) {
123 ret = PTR_ERR(bd);
124 dev_err(&pdev->dev, "failed to register device, err=%x\n", ret);
125 return ret;
128 bd->props.power = FB_BLANK_UNBLANK;
129 bd->props.brightness = BL_DEF_BRIGHT;
131 * note. make sure max brightness is set otherwise
132 * you will get seemingly non-related errors when
133 * trying to change brightness
135 jornada_bl_update_status(bd);
137 platform_set_drvdata(pdev, bd);
138 dev_info(&pdev->dev, "HP Jornada 700 series backlight driver\n");
140 return 0;
143 static struct platform_driver jornada_bl_driver = {
144 .probe = jornada_bl_probe,
145 .driver = {
146 .name = "jornada_bl",
150 module_platform_driver(jornada_bl_driver);
152 MODULE_AUTHOR("Kristoffer Ericson <kristoffer.ericson>");
153 MODULE_DESCRIPTION("HP Jornada 710/720/728 Backlight driver");
154 MODULE_LICENSE("GPL");