Date:2010-04-24 12:20:56 (10 years 2 months ago)
Author:Lars C.
Commit:71ea5fd8c59c459111cde9c2e752d0db7a858541
Message:Add gpm940b0 lcd driver

Files: drivers/video/backlight/Kconfig (1 diff)
drivers/video/backlight/Makefile (1 diff)
drivers/video/backlight/gpm940b0.c (1 diff)

Change Details

drivers/video/backlight/Kconfig
107107      If you have an HP Jornada 700 series handheld (710/720/728)
108108      say Y to enable LCD control driver.
109109
110config LCD_GPM940B0
111    tristate "Giantplus GPM940B0 LCD and backlight driver"
112    depends on LCD_CLASS_DEVICE && SPI
113    default n
114    help
115      LCD and backlight driver for the Giantplus GPM940B0 LCD module.
116
110117#
111118# Backlight
112119#
drivers/video/backlight/Makefile
1111obj-$(CONFIG_LCD_VGG2432A4) += vgg2432a4.o
1212obj-$(CONFIG_LCD_TDO24M) += tdo24m.o
1313obj-$(CONFIG_LCD_TOSA) += tosa_lcd.o
14obj-$(CONFIG_LCD_GPM940B0) += gpm940b0.o
1415
1516obj-$(CONFIG_BACKLIGHT_CLASS_DEVICE) += backlight.o
1617obj-$(CONFIG_BACKLIGHT_ATMEL_PWM) += atmel-pwm-bl.o
drivers/video/backlight/gpm940b0.c
1/*
2 * Copyright (C) 2009-2010, Lars-Peter Clausen <lars@metafoo.de>
3 * Driver for Giantplus GPM940B0 LCD
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
9 *
10 * You should have received a copy of the GNU General Public License along
11 * with this program; if not, write to the Free Software Foundation, Inc.,
12 * 675 Mass Ave, Cambridge, MA 02139, USA.
13 *
14 */
15
16#include <linux/module.h>
17#include <linux/spi/spi.h>
18#include <linux/lcd.h>
19#include <linux/backlight.h>
20#include <linux/delay.h>
21
22struct gpm940b0 {
23    struct spi_device *spi;
24    struct lcd_device *lcd;
25    struct backlight_device *bl;
26    unsigned enabled:1;
27};
28
29static int gpm940b0_write_reg(struct spi_device *spi, uint8_t reg,
30                uint8_t data)
31{
32    uint8_t buf[2];
33    buf[0] = ((reg & 0x40) << 1) | (reg & 0x3f);
34    buf[1] = data;
35
36    return spi_write(spi, buf, sizeof(buf));
37}
38
39static void gpm940b0_power_disable(struct spi_device *spi)
40{
41    int ret = gpm940b0_write_reg(spi, 0x5, 0xc6) ;
42    if (ret < 0)
43        dev_err(&spi->dev, "Failed to disable power: %d\n", ret);
44}
45
46static void gpm940b0_power_enable(struct spi_device *spi)
47{
48    gpm940b0_write_reg(spi, 0x5, 0xc7);
49}
50
51
52static int gpm940b0_set_power(struct lcd_device *lcd, int power)
53{
54    struct gpm940b0 *gpm940b0 = lcd_get_data(lcd);
55
56    switch (power) {
57    case FB_BLANK_UNBLANK:
58        mdelay(20);
59        gpm940b0->enabled = 1;
60        gpm940b0_power_enable(gpm940b0->spi);
61        break;
62    default:
63        gpm940b0->enabled = 0;
64        gpm940b0_power_disable(gpm940b0->spi);
65        mdelay(20);
66        break;
67    }
68    return 0;
69}
70
71static int gpm940b0_set_contrast(struct lcd_device *lcd, int contrast)
72{
73    struct gpm940b0 *gpm940b0 = lcd_get_data(lcd);
74    gpm940b0_write_reg(gpm940b0->spi, 0x0d, contrast);
75    return 0;
76}
77
78static int gpm940b0_set_mode(struct lcd_device *lcd, struct fb_videomode *mode)
79{
80    if (mode->xres != 320 && mode->yres != 240)
81        return -EINVAL;
82
83    return 0;
84}
85
86static ssize_t reg_write(struct device *dev, struct device_attribute *attr,
87                        const char *buf, size_t count)
88{
89    char *buf2;
90    uint32_t reg = simple_strtoul(buf, &buf2, 10);
91    uint32_t val = simple_strtoul(buf2 + 1, NULL, 10);
92    struct gpm940b0 *gpm940b0 = dev_get_drvdata(dev);
93
94    if (reg < 0 || val < 0)
95        return -EINVAL;
96
97    gpm940b0_write_reg(gpm940b0->spi, reg, val);
98    return count;
99}
100
101static DEVICE_ATTR(reg, 0644, NULL, reg_write);
102
103static ssize_t gpm940b0_show_brightness(struct device *dev,
104        struct device_attribute *attr, char *buf)
105{
106    int rc = -ENXIO;
107
108    return rc;
109}
110
111static ssize_t gpm940b0_store_brightness(struct device *dev,
112        struct device_attribute *attr, const char *buf, size_t count)
113{
114    char *endp;
115    struct lcd_device *ld = to_lcd_device(dev);
116    struct gpm940b0 *gpm940b0 = lcd_get_data(ld);
117    int brightness = simple_strtoul(buf, &endp, 0);
118
119    if (brightness > 255 || brightness < 0)
120        return -EINVAL;
121
122    gpm940b0_write_reg(gpm940b0->spi, 0x3, brightness);
123
124    return count;
125}
126
127
128static DEVICE_ATTR(brightness, 0644, gpm940b0_show_brightness,
129    gpm940b0_store_brightness);
130
131static struct lcd_ops gpm940b0_lcd_ops = {
132    .set_power = gpm940b0_set_power,
133    .set_contrast = gpm940b0_set_contrast,
134    .set_mode = gpm940b0_set_mode,
135};
136
137static int __devinit gpm940b0_probe(struct spi_device *spi)
138{
139    int ret;
140    struct gpm940b0 *gpm940b0;
141
142    gpm940b0 = kmalloc(sizeof(*gpm940b0), GFP_KERNEL);
143
144    spi->bits_per_word = 8;
145    spi->mode = SPI_MODE_3 | SPI_3WIRE;
146
147    ret = spi_setup(spi);
148    if (ret) {
149        dev_err(&spi->dev, "Failed to setup spi\n");
150        goto err_free_gpm940b0;
151    }
152
153    gpm940b0->spi = spi;
154
155    gpm940b0->lcd = lcd_device_register("gpm940b0-lcd", &spi->dev, gpm940b0,
156                        &gpm940b0_lcd_ops);
157
158    if (IS_ERR(gpm940b0->lcd)) {
159        ret = PTR_ERR(gpm940b0->lcd);
160        dev_err(&spi->dev, "Failed to register lcd device: %d\n", ret);
161        goto err_free_gpm940b0;
162    }
163
164    gpm940b0->lcd->props.max_contrast = 255;
165
166    ret = device_create_file(&spi->dev, &dev_attr_reg);
167    if (ret)
168        goto err_unregister_lcd;
169
170    ret = device_create_file(&gpm940b0->lcd->dev, &dev_attr_brightness);
171    if (ret)
172        goto err_unregister_lcd;
173
174    gpm940b0->enabled = 1;
175    dev_set_drvdata(&spi->dev, gpm940b0);
176
177    gpm940b0_write_reg(spi, 0x13, 0x01);
178    gpm940b0_write_reg(spi, 0x5, 0xc7);
179    return 0;
180err_unregister_lcd:
181    lcd_device_unregister(gpm940b0->lcd);
182err_free_gpm940b0:
183    kfree(gpm940b0);
184    return ret;
185}
186
187static int __devexit gpm940b0_remove(struct spi_device *spi)
188{
189    struct gpm940b0 *gpm940b0 = spi_get_drvdata(spi);
190#if 0
191    if (gpm940b0->bl)
192        backlight_device_unregister(gpm940b0->bl);
193#endif
194
195    lcd_device_unregister(gpm940b0->lcd);
196
197    spi_set_drvdata(spi, NULL);
198    kfree(gpm940b0);
199    return 0;
200}
201
202#ifdef CONFIG_PM
203
204static int gpm940b0_suspend(struct spi_device *spi, pm_message_t state)
205{
206    struct gpm940b0 *gpm940b0 = spi_get_drvdata(spi);
207    if (gpm940b0->enabled) {
208        gpm940b0_power_disable(spi);
209        mdelay(10);
210    }
211    return 0;
212}
213
214static int gpm940b0_resume(struct spi_device *spi)
215{
216    struct gpm940b0 *gpm940b0 = spi_get_drvdata(spi);
217    if (gpm940b0->enabled)
218        gpm940b0_power_enable(spi);
219    return 0;
220}
221
222#else
223#define gpm940b0_suspend NULL
224#define gpm940b0_resume NULL
225#endif
226
227static struct spi_driver gpm940b0_driver = {
228    .driver = {
229        .name = "gpm940b0",
230        .owner = THIS_MODULE,
231    },
232    .probe = gpm940b0_probe,
233    .remove = __devexit_p(gpm940b0_remove),
234    .suspend = gpm940b0_suspend,
235    .resume = gpm940b0_resume,
236};
237
238static int __init gpm940b0_init(void)
239{
240    return spi_register_driver(&gpm940b0_driver);
241}
242module_init(gpm940b0_init);
243
244static void __exit gpm940b0_exit(void)
245{
246    return spi_unregister_driver(&gpm940b0_driver);
247}
248module_exit(gpm940b0_exit)
249
250MODULE_AUTHOR("Lars-Peter Clausen");
251MODULE_LICENSE("GPL v2");
252MODULE_DESCRIPTION("LCD and backlight controll for Giantplus GPM940B0");
253MODULE_ALIAS("spi:gpm940b0");

Archive Download the corresponding diff file



interactive