Skip to content

Commit 2740b57

Browse files
shin_linjamess-huang
authored andcommitted
DSI : Fix the kernel panic when system enter suspend mode with DSI panel
NOTE: Fine tune the commit "Add the backlight control node in /sys/class/backlight/rpi_backlight/brightness" Change-Id: I2a4e4814183048539be2f1c03046b53e845e5573 Reviewed-on: https://tp-biosrd-v02/gerrit/83831 Reviewed-by: Jamess Huang(黃以民) <[email protected]> Tested-by: Jamess Huang(黃以民) <[email protected]> (cherry picked from commit f4ccd11) Reviewed-on: https://tp-biosrd-v02/gerrit/83856
1 parent 1453937 commit 2740b57

File tree

3 files changed

+55
-24
lines changed

3 files changed

+55
-24
lines changed

drivers/misc/tinker_mcu.c

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
static struct tinker_mcu_data *g_mcu_data;
3030
static int connected = 0;
3131
static int lcd_bright_level = 0;
32-
static struct device *rpi_backlight_device;
3332

3433
static int is_hex(char num)
3534
{
@@ -168,6 +167,22 @@ int tinker_mcu_set_bright(int bright)
168167
}
169168
EXPORT_SYMBOL_GPL(tinker_mcu_set_bright);
170169

170+
int tinker_mcu_get_brightness(void)
171+
{
172+
return lcd_bright_level;
173+
}
174+
EXPORT_SYMBOL_GPL(tinker_mcu_get_brightness);
175+
176+
static int tinker_mcu_bl_get_brightness(struct backlight_device *bd)
177+
{
178+
return lcd_bright_level;
179+
}
180+
181+
static const struct backlight_ops tinker_mcu_bl_ops = {
182+
.get_brightness = tinker_mcu_bl_get_brightness,
183+
};
184+
185+
171186
static ssize_t tinker_mcu_bl_show(struct device *dev, struct device_attribute *attr, char *buf)
172187
{
173188
if(BL_DEBUG) LOG_INFO("get bright = 0x%x\n", lcd_bright_level);
@@ -189,7 +204,6 @@ static ssize_t tinker_mcu_bl_store(struct device *dev, struct device_attribute *
189204
return strnlen(buf, count);
190205
}
191206
static DEVICE_ATTR(tinker_mcu_bl, S_IRUGO | S_IWUSR, tinker_mcu_bl_show, tinker_mcu_bl_store);
192-
static DEVICE_ATTR(brightness, S_IRUGO | S_IWUSR, tinker_mcu_bl_show, tinker_mcu_bl_store);
193207

194208
int tinker_mcu_is_connected(void)
195209
{
@@ -202,6 +216,8 @@ static int tinker_mcu_probe(struct i2c_client *client,
202216
{
203217
struct tinker_mcu_data *mcu_data;
204218
int ret;
219+
struct backlight_properties props;
220+
struct backlight_device *bl;
205221

206222
LOG_INFO("address = 0x%x\n", client->addr);
207223

@@ -227,28 +243,22 @@ static int tinker_mcu_probe(struct i2c_client *client,
227243
}
228244
connected = 1;
229245

246+
memset(&props, 0, sizeof(props));
247+
props.type = BACKLIGHT_RAW;
248+
props.max_brightness = 255;
249+
250+
bl = backlight_device_register("rpi_backlight", NULL, NULL,
251+
&tinker_mcu_bl_ops, &props);
252+
if (IS_ERR(bl)) {
253+
pr_err("unable to register backlight device\n");
254+
}
255+
230256
ret = device_create_file(&client->dev, &dev_attr_tinker_mcu_bl);
231257
if (ret != 0) {
232258
dev_err(&client->dev, "Failed to create tinker_mcu_bl sysfs files %d\n", ret);
233259
return ret;
234260
}
235261

236-
rpi_backlight_device = device_create(backlight_class, NULL, MKDEV(0, 0), NULL,
237-
"rpi_backlight");
238-
if (IS_ERR(rpi_backlight_device)) {
239-
printk(KERN_WARNING "Unable to create device "
240-
"for rpi_backlight; errno = %ld\n",
241-
PTR_ERR(rpi_backlight_device));
242-
rpi_backlight_device = NULL;
243-
} else {
244-
//init_device
245-
ret = device_create_file(rpi_backlight_device, &dev_attr_brightness);
246-
if (ret != 0) {
247-
dev_err(&client->dev, "Failed to create brightness sysfs files %d\n", ret);
248-
return ret;
249-
}
250-
}
251-
252262
return 0;
253263

254264
error:

drivers/video/backlight/backlight.c

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ static void backlight_generate_event(struct backlight_device *bd,
124124
sysfs_notify(&bd->dev.kobj, NULL, "actual_brightness");
125125
}
126126

127-
#ifndef CONFIG_TINKER_MCU
128127
static ssize_t bl_power_show(struct device *dev, struct device_attribute *attr,
129128
char *buf)
130129
{
@@ -160,6 +159,7 @@ static ssize_t bl_power_store(struct device *dev, struct device_attribute *attr,
160159
}
161160
static DEVICE_ATTR_RW(bl_power);
162161

162+
#ifndef CONFIG_TINKER_MCU
163163
static ssize_t brightness_show(struct device *dev,
164164
struct device_attribute *attr, char *buf)
165165
{
@@ -207,6 +207,32 @@ static ssize_t brightness_store(struct device *dev,
207207

208208
return rc ? rc : count;
209209
}
210+
#else
211+
extern int tinker_mcu_set_bright(int bright);
212+
extern int tinker_mcu_get_brightness(void);
213+
static ssize_t brightness_show(struct device *dev, struct device_attribute *attr, char *buf)
214+
{
215+
int level;
216+
217+
level = tinker_mcu_get_brightness();
218+
219+
return sprintf(buf, "%d\n", level);
220+
}
221+
222+
static ssize_t brightness_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
223+
{
224+
int value;
225+
226+
value = simple_strtoul(buf, NULL, 0);
227+
228+
if((value < 0) || (value > 255)) {
229+
pr_err("Invalid value for backlight setting, value = %d\n", value);
230+
} else
231+
tinker_mcu_set_bright(value);
232+
233+
return strnlen(buf, count);
234+
}
235+
#endif
210236
static DEVICE_ATTR_RW(brightness);
211237

212238
static ssize_t type_show(struct device *dev, struct device_attribute *attr,
@@ -243,10 +269,8 @@ static ssize_t actual_brightness_show(struct device *dev,
243269
return rc;
244270
}
245271
static DEVICE_ATTR_RO(actual_brightness);
246-
#endif
247272

248273
struct class *backlight_class;
249-
EXPORT_SYMBOL(backlight_class);
250274

251275
#ifdef CONFIG_PM_SLEEP
252276
static int backlight_suspend(struct device *dev)
@@ -288,13 +312,11 @@ static void bl_device_release(struct device *dev)
288312
}
289313

290314
static struct attribute *bl_device_attrs[] = {
291-
#ifndef CONFIG_TINKER_MCU
292315
&dev_attr_bl_power.attr,
293316
&dev_attr_brightness.attr,
294317
&dev_attr_actual_brightness.attr,
295318
&dev_attr_max_brightness.attr,
296319
&dev_attr_type.attr,
297-
#endif
298320
NULL,
299321
};
300322
ATTRIBUTE_GROUPS(bl_device);

include/linux/backlight.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ enum backlight_notification {
4747

4848
struct backlight_device;
4949
struct fb_info;
50-
extern struct class *backlight_class;
5150

5251
struct backlight_ops {
5352
unsigned int options;

0 commit comments

Comments
 (0)