aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/video/backlight/jornada56x_bllcd.c
blob: b9a609f613c519d2bcfb5f1ba9db0d50e29bd624 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/*
 *  drivers/video/backlight/jornada56x_bllcd.c
 *
 *  HP Jornada560 Series init code
 *
 *  Copyright 2008 Michael J Kaye <mjkaye@ippimail.com>
 *   Based on jornada56x.c from the Handhelds.org tree, copyright Alex Lange,
 *   and jornada720_bllcd.c, copyright Kristoffer Ericson.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License version 2 as
 *	published by the Free Software Foundation.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 */

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/backlight.h>
#include <linux/lcd.h>
#include <linux/delay.h>
#include <linux/platform_device.h>
#include <linux/fb.h>
#include <linux/device.h>
#include <asm/hardware.h>
#include <asm/arch/jornada56x.h>
#include <../drivers/video/sa1100fb.h>

MODULE_AUTHOR("Michael J Kaye <mjkaye@ippimail.com>");
MODULE_DESCRIPTION("HP Jornada 560 Series Backlight/LCD Driver");
MODULE_LICENSE("GPL");

/* Brightness */
#define BL_MAX_BRIGHT   0xbe
#define BL_DEF_BRIGHT   0x19

struct bllcd_device {
    struct backlight_device *bl_device;
    struct lcd_device *lcd_device;
};

/*
 * BACKLIGHT HANDLING ROUTINES
 */

static void jornada56x_backlight_power (int on)
{
        if (on)
                JORNADA_GPDPCR = JORNADA_BACKLIGHT;
        else
                JORNADA_GPDPSR = JORNADA_BACKLIGHT;
}

static int jornada56x_backlight_get_brightness (struct backlight_device *bd)
{
        return (JORNADA_PWM1_DATA - 0x40000000);
}

static int jornada56x_bl_update_status (struct backlight_device *bd)
{
    int value = bd->props.brightness;
    int brightness = 190 - value;

    if (bd->props.power != FB_BLANK_UNBLANK) {
        jornada56x_backlight_power(0);
        return 0;
    }
    if (bd->props.fb_blank != FB_BLANK_UNBLANK) {
        jornada56x_backlight_power(0);
        return 0;
    }

    jornada56x_backlight_power(1);

    JORNADA_PWM1_CKDR = 0;
    /* range is from 0 (brightest) to 255 (darkest)
     * although values > 190 are no good
     */
    JORNADA_PWM1_DATA = brightness;
    JORNADA_PWM_CTRL = 1; /* enable backlight control - 1=Enable ; 0=Disable */
    return 0;
}

/*
 * LCD HANDLING FUNCTIONS
 */
static void jornada56x_lcd_power(int on)
{
    if (on) {
        GPSR = GPIO_GPIO24;
    } else {
        GPCR = GPIO_GPIO24;
    }
}

static int jornada56x_lcd_get_power(struct lcd_device *ld)
{
    return (GPLR & GPIO_GPIO24) ? 0 : 4;
}

static int jornada56x_lcd_set_power(struct lcd_device *ld, int state)
{
    if (state==0)
        jornada56x_lcd_power(1);
    else
        jornada56x_lcd_power(0);
    
    return 0;
}

static struct backlight_ops jornada56x_bl_ops = {
    .get_brightness = jornada56x_backlight_get_brightness,
    .update_status = jornada56x_bl_update_status,
};

static struct lcd_ops jornada56x_lcd_ops = {
    .get_power = jornada56x_lcd_set_power,
    .set_power = jornada56x_lcd_get_power,
};

static int __init jornada56x_bl_probe(struct platform_device *pdev)
{
    struct bllcd_device *bllcd;
    int ret;

    bllcd = kzalloc(sizeof(*bllcd), GFP_KERNEL);
    if (bllcd == NULL)
        return -ENOMEM;

    /* bl driver - name must match fb driver name */
    bllcd->bl_device = backlight_device_register("sa1100fb", &pdev->dev, NULL,
                                                  &jornada56x_bl_ops);

    if (IS_ERR(bllcd->bl_device)) {
        ret = PTR_ERR(bllcd->bl_device);
        printk(KERN_ERR "bl :failed to register device\n");
        kfree(bllcd);
        return ret;
    }

    /* lcd driver */
    bllcd->lcd_device = lcd_device_register("sa1100fb", &pdev->dev, NULL,
                                             &jornada56x_lcd_ops);
    if (IS_ERR(bllcd->lcd_device)) {
        ret = PTR_ERR(bllcd->lcd_device);
        backlight_device_unregister(bllcd->bl_device);
        printk(KERN_ERR "lcd :failed to register device\n");
        kfree(bllcd);
        return ret;
    }

    jornada56x_lcd_set_power(bllcd->lcd_device, FB_BLANK_UNBLANK);

    msleep(100);

    bllcd->bl_device->props.power = FB_BLANK_UNBLANK;
    bllcd->bl_device->props.brightness = BL_DEF_BRIGHT;
    jornada56x_bl_update_status(bllcd->bl_device);

    platform_set_drvdata(pdev, bllcd);
    printk(KERN_INFO "HP Jornada 56x Backlight/LCD driver activated\n");

    return 0;
}

static int jornada56x_bl_remove(struct platform_device *pdev)
{
    struct bllcd_device *bllcd = platform_get_drvdata(pdev);

    bllcd->bl_device->props.power = FB_BLANK_POWERDOWN;
    bllcd->bl_device->props.brightness = 0;
    bllcd->bl_device->props.max_brightness = 0;

    backlight_device_unregister(bllcd->bl_device);
    lcd_device_unregister(bllcd->lcd_device);

    return 0;
}
static int jornada56x_bl_suspend(struct platform_device *pdev, pm_message_t state)
{
    struct bllcd_device *bllcd = platform_get_drvdata(pdev);

    bllcd->bl_device->props.power = FB_BLANK_POWERDOWN;
    bllcd->bl_device->props.brightness = 0;
    bllcd->bl_device->props.max_brightness = 0;
    jornada56x_bl_update_status(bllcd->bl_device);

    jornada56x_lcd_set_power(bllcd->lcd_device, FB_BLANK_POWERDOWN);

    return 0;
}

static int jornada56x_bl_resume(struct platform_device *pdev)
{
    struct bllcd_device *bllcd = platform_get_drvdata(pdev);

    bllcd->bl_device->props.power = FB_BLANK_UNBLANK;
    bllcd->bl_device->props.brightness = BL_DEF_BRIGHT;
    bllcd->bl_device->props.max_brightness = BL_MAX_BRIGHT;
    jornada56x_bl_update_status(bllcd->bl_device);

    jornada56x_lcd_set_power(bllcd->lcd_device, FB_BLANK_UNBLANK);

    return 0;
}

static struct platform_driver jornada56x_bl_driver = {
    .remove = jornada56x_bl_remove,
#ifdef CONFIG_PM
    .suspend    = jornada56x_bl_suspend,
    .resume     = jornada56x_bl_resume,
#endif
    .driver = {
        .name = "jornada56x_bllcd",
    },
};

static int __init jornada56x_bl_init(void)
{
    return platform_driver_probe(&jornada56x_bl_driver, jornada56x_bl_probe);
}

static void __exit jornada56x_bl_exit(void)
{
    platform_driver_unregister(&jornada56x_bl_driver);
}

module_init(jornada56x_bl_init);
module_exit(jornada56x_bl_exit);