mirror of
git://projects.qi-hardware.com/openwrt-xburst.git
synced 2024-11-28 16:54:03 +02:00
gpm940b0: Add suspend/resume support.
This commit is contained in:
parent
92e06e95a5
commit
0d3b54ed10
@ -17,11 +17,13 @@
|
|||||||
#include <linux/spi/spi.h>
|
#include <linux/spi/spi.h>
|
||||||
#include <linux/lcd.h>
|
#include <linux/lcd.h>
|
||||||
#include <linux/backlight.h>
|
#include <linux/backlight.h>
|
||||||
|
#include <linux/delay.h>
|
||||||
|
|
||||||
struct gpm940b0 {
|
struct gpm940b0 {
|
||||||
struct spi_device *spi;
|
struct spi_device *spi;
|
||||||
struct lcd_device *lcd;
|
struct lcd_device *lcd;
|
||||||
struct backlight_device *bl;
|
struct backlight_device *bl;
|
||||||
|
unsigned enabled:1;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int gpm940b0_write_reg(struct spi_device *spi, uint8_t reg,
|
static int gpm940b0_write_reg(struct spi_device *spi, uint8_t reg,
|
||||||
@ -34,16 +36,31 @@ static int gpm940b0_write_reg(struct spi_device *spi, uint8_t reg,
|
|||||||
return spi_write(spi, buf, sizeof(buf));
|
return spi_write(spi, buf, sizeof(buf));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void gpm940b0_power_disable(struct gpm940b0 *gpm940b0)
|
||||||
|
{
|
||||||
|
int ret = gpm940b0_write_reg(gpm940b0->spi, 0x5, 0xc6) ;
|
||||||
|
if (ret < 0)
|
||||||
|
printk("Failed to disable power: %d\n", ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void gpm940b0_power_enable(struct gpm940b0 *gpm940b0)
|
||||||
|
{
|
||||||
|
gpm940b0_write_reg(gpm940b0->spi, 0x5, 0xc7);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int gpm940b0_set_power(struct lcd_device *lcd, int power)
|
static int gpm940b0_set_power(struct lcd_device *lcd, int power)
|
||||||
{
|
{
|
||||||
struct gpm940b0 *gpm940b0 = lcd_get_data(lcd);
|
struct gpm940b0 *gpm940b0 = lcd_get_data(lcd);
|
||||||
|
|
||||||
switch (power) {
|
switch (power) {
|
||||||
case FB_BLANK_UNBLANK:
|
case FB_BLANK_UNBLANK:
|
||||||
gpm940b0_write_reg(gpm940b0->spi, 0x05, 0x5f);
|
gpm940b0->enabled = 1;
|
||||||
|
gpm940b0_power_enable(gpm940b0);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
gpm940b0_write_reg(gpm940b0->spi, 0x05, 0x5e);
|
gpm940b0->enabled = 0;
|
||||||
|
gpm940b0_power_disable(gpm940b0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -64,17 +81,20 @@ static int gpm940b0_set_mode(struct lcd_device *lcd, struct fb_videomode *mode)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
int gpm940b0_bl_update_status(struct backlight_device *bl)
|
int gpm940b0_bl_update_status(struct backlight_device *bl)
|
||||||
{
|
{
|
||||||
struct gpm940b0 *gpm940b0 = bl_get_data(bl);
|
struct gpm940b0 *gpm940b0 = bl_get_data(bl);
|
||||||
|
|
||||||
/* The datasheet suggest that this is not possible on the giantplus module
|
gpm940b0->reg5 &= ~0x38;
|
||||||
gpm940b0_write_reg(gpm940b0->spi, 21, bl->props.brightness);*/
|
gpm940b0->reg5 |= ((bl->props.brightness << 3) & 0x38);
|
||||||
|
|
||||||
|
gpm940b0_write_reg(gpm940b0->spi, 0x5, gpm940b0->reg5);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
static size_t reg_write(struct device *dev, struct device_attribute *attr,
|
static ssize_t reg_write(struct device *dev, struct device_attribute *attr,
|
||||||
const char *buf, size_t count)
|
const char *buf, size_t count)
|
||||||
{
|
{
|
||||||
char *buf2;
|
char *buf2;
|
||||||
@ -97,10 +117,12 @@ static struct lcd_ops gpm940b0_lcd_ops = {
|
|||||||
.set_mode = gpm940b0_set_mode,
|
.set_mode = gpm940b0_set_mode,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if 0
|
||||||
static struct backlight_ops gpm940b0_bl_ops = {
|
static struct backlight_ops gpm940b0_bl_ops = {
|
||||||
/* .get_brightness = gpm940b0_bl_get_brightness,*/
|
/* .get_brightness = gpm940b0_bl_get_brightness,*/
|
||||||
.update_status = gpm940b0_bl_update_status,
|
.update_status = gpm940b0_bl_update_status,
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
static int __devinit gpm940b0_probe(struct spi_device *spi)
|
static int __devinit gpm940b0_probe(struct spi_device *spi)
|
||||||
{
|
{
|
||||||
@ -130,6 +152,7 @@ static int __devinit gpm940b0_probe(struct spi_device *spi)
|
|||||||
|
|
||||||
gpm940b0->lcd->props.max_contrast = 255;
|
gpm940b0->lcd->props.max_contrast = 255;
|
||||||
|
|
||||||
|
#if 0
|
||||||
gpm940b0->bl = backlight_device_register("gpm940b0-bl", &spi->dev, gpm940b0,
|
gpm940b0->bl = backlight_device_register("gpm940b0-bl", &spi->dev, gpm940b0,
|
||||||
&gpm940b0_bl_ops);
|
&gpm940b0_bl_ops);
|
||||||
|
|
||||||
@ -138,26 +161,36 @@ static int __devinit gpm940b0_probe(struct spi_device *spi)
|
|||||||
dev_err(&spi->dev, "Failed to register backlight device: %d\n", ret);
|
dev_err(&spi->dev, "Failed to register backlight device: %d\n", ret);
|
||||||
gpm940b0->bl = NULL;
|
gpm940b0->bl = NULL;
|
||||||
} else {
|
} else {
|
||||||
gpm940b0->bl->props.max_brightness = 15;
|
gpm940b0->bl->props.max_brightness = 8;
|
||||||
gpm940b0->bl->props.brightness = 0;
|
gpm940b0->bl->props.brightness = 0;
|
||||||
gpm940b0->bl->props.power = FB_BLANK_UNBLANK;
|
gpm940b0->bl->props.power = FB_BLANK_UNBLANK;
|
||||||
}
|
}
|
||||||
device_create_file(&spi->dev, &dev_attr_reg);
|
#endif
|
||||||
|
|
||||||
|
ret = device_create_file(&spi->dev, &dev_attr_reg);
|
||||||
|
if (ret)
|
||||||
|
goto err_unregister_lcd;
|
||||||
|
|
||||||
|
gpm940b0->enabled = 1;
|
||||||
dev_set_drvdata(&spi->dev, gpm940b0);
|
dev_set_drvdata(&spi->dev, gpm940b0);
|
||||||
|
|
||||||
gpm940b0_write_reg(spi, 0x13, 0x01);
|
gpm940b0_write_reg(spi, 0x13, 0x01);
|
||||||
gpm940b0_write_reg(spi, 0x05, 0x5f);
|
gpm940b0_write_reg(spi, 0x5, 0xc7);
|
||||||
return 0;
|
return 0;
|
||||||
|
err_unregister_lcd:
|
||||||
|
lcd_device_unregister(gpm940b0->lcd);
|
||||||
err_free_gpm940b0:
|
err_free_gpm940b0:
|
||||||
|
kfree(gpm940b0);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int __devexit gpm940b0_remove(struct spi_device *spi)
|
static int __devexit gpm940b0_remove(struct spi_device *spi)
|
||||||
{
|
{
|
||||||
struct gpm940b0 *gpm940b0 = spi_get_drvdata(spi);
|
struct gpm940b0 *gpm940b0 = spi_get_drvdata(spi);
|
||||||
|
#if 0
|
||||||
if (gpm940b0->bl)
|
if (gpm940b0->bl)
|
||||||
backlight_device_unregister(gpm940b0->bl);
|
backlight_device_unregister(gpm940b0->bl);
|
||||||
|
#endif
|
||||||
|
|
||||||
lcd_device_unregister(gpm940b0->lcd);
|
lcd_device_unregister(gpm940b0->lcd);
|
||||||
|
|
||||||
@ -166,6 +199,31 @@ static int __devexit gpm940b0_remove(struct spi_device *spi)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef CONFIG_PM
|
||||||
|
|
||||||
|
static int gpm940b0_suspend(struct spi_device *spi, pm_message_t state)
|
||||||
|
{
|
||||||
|
struct gpm940b0 *gpm940b0 = spi_get_drvdata(spi);
|
||||||
|
if (gpm940b0->enabled) {
|
||||||
|
gpm940b0_power_disable(gpm940b0);
|
||||||
|
mdelay(10);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int gpm940b0_resume(struct spi_device *spi)
|
||||||
|
{
|
||||||
|
struct gpm940b0 *gpm940b0 = spi_get_drvdata(spi);
|
||||||
|
if (gpm940b0->enabled)
|
||||||
|
gpm940b0_power_enable(gpm940b0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
#define gpm940b0_suspend NULL
|
||||||
|
#define gpm940b0_resume NULL
|
||||||
|
#endif
|
||||||
|
|
||||||
static struct spi_driver gpm940b0_driver = {
|
static struct spi_driver gpm940b0_driver = {
|
||||||
.driver = {
|
.driver = {
|
||||||
.name = "gpm940b0",
|
.name = "gpm940b0",
|
||||||
@ -173,6 +231,8 @@ static struct spi_driver gpm940b0_driver = {
|
|||||||
},
|
},
|
||||||
.probe = gpm940b0_probe,
|
.probe = gpm940b0_probe,
|
||||||
.remove = __devexit_p(gpm940b0_remove),
|
.remove = __devexit_p(gpm940b0_remove),
|
||||||
|
.suspend = gpm940b0_suspend,
|
||||||
|
.resume = gpm940b0_resume,
|
||||||
};
|
};
|
||||||
|
|
||||||
static int __init gpm940b0_init(void)
|
static int __init gpm940b0_init(void)
|
||||||
@ -190,4 +250,4 @@ module_exit(gpm940b0_exit)
|
|||||||
MODULE_AUTHOR("Lars-Peter Clausen");
|
MODULE_AUTHOR("Lars-Peter Clausen");
|
||||||
MODULE_LICENSE("GPL v2");
|
MODULE_LICENSE("GPL v2");
|
||||||
MODULE_DESCRIPTION("LCD and backlight controll for Giantplus GPM940B0");
|
MODULE_DESCRIPTION("LCD and backlight controll for Giantplus GPM940B0");
|
||||||
MODULE_ALIAS("i2c:gpm940b0");
|
MODULE_ALIAS("spi:gpm940b0");
|
||||||
|
Loading…
Reference in New Issue
Block a user