2 * LCD / Backlight control code for Sharp SL-6000x (tosa)
4 * Copyright (c) 2005 Dirk Opfer
5 * Copyright (c) 2007,2008 Dmitry Baryshkov
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
13 #include <linux/kernel.h>
14 #include <linux/module.h>
15 #include <linux/device.h>
16 #include <linux/spi/spi.h>
17 #include <linux/i2c.h>
18 #include <linux/gpio.h>
20 #include <linux/backlight.h>
21 #include <linux/slab.h>
23 #include <asm/mach/sharpsl_param.h>
25 #include <mach/tosa.h>
27 #define COMADJ_DEFAULT 97
33 struct i2c_client
*i2c
;
34 struct backlight_device
*bl
;
39 static void tosa_bl_set_backlight(struct tosa_bl_data
*data
, int brightness
)
41 struct spi_device
*spi
= dev_get_platdata(&data
->i2c
->dev
);
43 i2c_smbus_write_byte_data(data
->i2c
, DAC_CH1
, data
->comadj
);
45 /* SetBacklightDuty */
46 i2c_smbus_write_byte_data(data
->i2c
, DAC_CH2
, (u8
)(brightness
& 0xff));
49 gpio_set_value(TOSA_GPIO_BL_C20MA
, brightness
& 0x100);
51 tosa_bl_enable(spi
, brightness
);
54 static int tosa_bl_update_status(struct backlight_device
*dev
)
56 struct backlight_properties
*props
= &dev
->props
;
57 struct tosa_bl_data
*data
= bl_get_data(dev
);
58 int power
= max(props
->power
, props
->fb_blank
);
59 int brightness
= props
->brightness
;
64 tosa_bl_set_backlight(data
, brightness
);
69 static int tosa_bl_get_brightness(struct backlight_device
*dev
)
71 struct backlight_properties
*props
= &dev
->props
;
73 return props
->brightness
;
76 static const struct backlight_ops bl_ops
= {
77 .get_brightness
= tosa_bl_get_brightness
,
78 .update_status
= tosa_bl_update_status
,
81 static int tosa_bl_probe(struct i2c_client
*client
,
82 const struct i2c_device_id
*id
)
84 struct backlight_properties props
;
85 struct tosa_bl_data
*data
;
88 data
= devm_kzalloc(&client
->dev
, sizeof(struct tosa_bl_data
),
93 data
->comadj
= sharpsl_param
.comadj
== -1 ? COMADJ_DEFAULT
: sharpsl_param
.comadj
;
95 ret
= devm_gpio_request_one(&client
->dev
, TOSA_GPIO_BL_C20MA
,
96 GPIOF_OUT_INIT_LOW
, "backlight");
98 dev_dbg(&data
->bl
->dev
, "Unable to request gpio!\n");
102 i2c_set_clientdata(client
, data
);
105 memset(&props
, 0, sizeof(struct backlight_properties
));
106 props
.type
= BACKLIGHT_RAW
;
107 props
.max_brightness
= 512 - 1;
108 data
->bl
= devm_backlight_device_register(&client
->dev
, "tosa-bl",
109 &client
->dev
, data
, &bl_ops
,
111 if (IS_ERR(data
->bl
)) {
112 ret
= PTR_ERR(data
->bl
);
116 data
->bl
->props
.brightness
= 69;
117 data
->bl
->props
.power
= FB_BLANK_UNBLANK
;
119 backlight_update_status(data
->bl
);
128 static int tosa_bl_remove(struct i2c_client
*client
)
130 struct tosa_bl_data
*data
= i2c_get_clientdata(client
);
136 #ifdef CONFIG_PM_SLEEP
137 static int tosa_bl_suspend(struct device
*dev
)
139 struct tosa_bl_data
*data
= dev_get_drvdata(dev
);
141 tosa_bl_set_backlight(data
, 0);
146 static int tosa_bl_resume(struct device
*dev
)
148 struct tosa_bl_data
*data
= dev_get_drvdata(dev
);
150 backlight_update_status(data
->bl
);
155 static SIMPLE_DEV_PM_OPS(tosa_bl_pm_ops
, tosa_bl_suspend
, tosa_bl_resume
);
157 static const struct i2c_device_id tosa_bl_id
[] = {
161 MODULE_DEVICE_TABLE(i2c
, tosa_bl_id
);
163 static struct i2c_driver tosa_bl_driver
= {
166 .pm
= &tosa_bl_pm_ops
,
168 .probe
= tosa_bl_probe
,
169 .remove
= tosa_bl_remove
,
170 .id_table
= tosa_bl_id
,
173 module_i2c_driver(tosa_bl_driver
);
175 MODULE_AUTHOR("Dmitry Baryshkov");
176 MODULE_LICENSE("GPL v2");
177 MODULE_DESCRIPTION("LCD/Backlight control for Sharp SL-6000 PDA");