Merge git://git.kernel.org/pub/scm/linux/kernel/git/cmetcalf/linux-tile
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / video / backlight / jornada720_bl.c
CommitLineData
13a7b5dc
KE
1/*
2 *
3 * Backlight driver for HP Jornada 700 series (710/720/728)
4 * Copyright (C) 2006-2009 Kristoffer Ericson <kristoffer.ericson@gmail.com>
5 *
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.
9 *
10 */
11
20c225cb
JH
12#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13
13a7b5dc
KE
14#include <linux/backlight.h>
15#include <linux/device.h>
16#include <linux/fb.h>
17#include <linux/kernel.h>
18#include <linux/module.h>
19#include <linux/platform_device.h>
20
21#include <mach/jornada720.h>
22#include <mach/hardware.h>
23
24#include <video/s1d13xxxfb.h>
25
26#define BL_MAX_BRIGHT 255
27#define BL_DEF_BRIGHT 25
28
29static int jornada_bl_get_brightness(struct backlight_device *bd)
30{
31 int ret;
32
33 /* check if backlight is on */
34 if (!(PPSR & PPC_LDD1))
35 return 0;
36
37 jornada_ssp_start();
38
39 /* cmd should return txdummy */
40 ret = jornada_ssp_byte(GETBRIGHTNESS);
41
42 if (jornada_ssp_byte(GETBRIGHTNESS) != TXDUMMY) {
20c225cb 43 pr_err("get brightness timeout\n");
13a7b5dc
KE
44 jornada_ssp_end();
45 return -ETIMEDOUT;
46 } else /* exchange txdummy for value */
47 ret = jornada_ssp_byte(TXDUMMY);
48
49 jornada_ssp_end();
50
0a75a568 51 return BL_MAX_BRIGHT - ret;
13a7b5dc
KE
52}
53
54static int jornada_bl_update_status(struct backlight_device *bd)
55{
56 int ret = 0;
57
58 jornada_ssp_start();
59
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) {
20c225cb 64 pr_info("brightness off timeout\n");
13a7b5dc
KE
65 /* turn off backlight */
66 PPSR &= ~PPC_LDD1;
67 PPDR |= PPC_LDD1;
68 ret = -ETIMEDOUT;
69 }
70 } else /* turn on backlight */
71 PPSR |= PPC_LDD1;
72
73 /* send command to our mcu */
74 if (jornada_ssp_byte(SETBRIGHTNESS) != TXDUMMY) {
20c225cb 75 pr_info("failed to set brightness\n");
13a7b5dc 76 ret = -ETIMEDOUT;
b317c833 77 goto out;
13a7b5dc
KE
78 }
79
0a75a568
JH
80 /*
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).
86 */
87 if (jornada_ssp_byte(BL_MAX_BRIGHT - bd->props.brightness)
88 != TXDUMMY) {
20c225cb 89 pr_err("set brightness failed\n");
13a7b5dc
KE
90 ret = -ETIMEDOUT;
91 }
92
0a75a568
JH
93 /*
94 * If infact we get an TXDUMMY as output we are happy and dont
95 * make any further comments about it
96 */
13a7b5dc
KE
97out:
98 jornada_ssp_end();
99
100 return ret;
101}
102
9905a43b 103static const struct backlight_ops jornada_bl_ops = {
13a7b5dc
KE
104 .get_brightness = jornada_bl_get_brightness,
105 .update_status = jornada_bl_update_status,
106 .options = BL_CORE_SUSPENDRESUME,
107};
108
109static int jornada_bl_probe(struct platform_device *pdev)
110{
a19a6ee6 111 struct backlight_properties props;
13a7b5dc
KE
112 int ret;
113 struct backlight_device *bd;
114
a19a6ee6 115 memset(&props, 0, sizeof(struct backlight_properties));
bb7ca747 116 props.type = BACKLIGHT_RAW;
a19a6ee6
MG
117 props.max_brightness = BL_MAX_BRIGHT;
118 bd = backlight_device_register(S1D_DEVICENAME, &pdev->dev, NULL,
119 &jornada_bl_ops, &props);
13a7b5dc
KE
120
121 if (IS_ERR(bd)) {
122 ret = PTR_ERR(bd);
20c225cb 123 pr_err("failed to register device, err=%x\n", ret);
13a7b5dc
KE
124 return ret;
125 }
126
127 bd->props.power = FB_BLANK_UNBLANK;
128 bd->props.brightness = BL_DEF_BRIGHT;
0a75a568
JH
129 /*
130 * note. make sure max brightness is set otherwise
131 * you will get seemingly non-related errors when
132 * trying to change brightness
133 */
13a7b5dc
KE
134 jornada_bl_update_status(bd);
135
136 platform_set_drvdata(pdev, bd);
20c225cb 137 pr_info("HP Jornada 700 series backlight driver\n");
13a7b5dc
KE
138
139 return 0;
140}
141
142static int jornada_bl_remove(struct platform_device *pdev)
143{
144 struct backlight_device *bd = platform_get_drvdata(pdev);
145
146 backlight_device_unregister(bd);
147
148 return 0;
149}
150
151static struct platform_driver jornada_bl_driver = {
152 .probe = jornada_bl_probe,
153 .remove = jornada_bl_remove,
154 .driver = {
155 .name = "jornada_bl",
156 },
157};
158
81178e02 159module_platform_driver(jornada_bl_driver);
13a7b5dc
KE
160
161MODULE_AUTHOR("Kristoffer Ericson <kristoffer.ericson>");
162MODULE_DESCRIPTION("HP Jornada 710/720/728 Backlight driver");
163MODULE_LICENSE("GPL");