Skip to content

Commit

Permalink
DSI : Fix the kernel panic when system enter suspend mode with DSI panel
Browse files Browse the repository at this point in the history
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
  • Loading branch information
shin_lin authored and jamess-huang committed Oct 11, 2018
1 parent 1453937 commit 2740b57
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 24 deletions.
46 changes: 28 additions & 18 deletions drivers/misc/tinker_mcu.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
static struct tinker_mcu_data *g_mcu_data;
static int connected = 0;
static int lcd_bright_level = 0;
static struct device *rpi_backlight_device;

static int is_hex(char num)
{
Expand Down Expand Up @@ -168,6 +167,22 @@ int tinker_mcu_set_bright(int bright)
}
EXPORT_SYMBOL_GPL(tinker_mcu_set_bright);

int tinker_mcu_get_brightness(void)
{
return lcd_bright_level;
}
EXPORT_SYMBOL_GPL(tinker_mcu_get_brightness);

static int tinker_mcu_bl_get_brightness(struct backlight_device *bd)
{
return lcd_bright_level;
}

static const struct backlight_ops tinker_mcu_bl_ops = {
.get_brightness = tinker_mcu_bl_get_brightness,
};


static ssize_t tinker_mcu_bl_show(struct device *dev, struct device_attribute *attr, char *buf)
{
if(BL_DEBUG) LOG_INFO("get bright = 0x%x\n", lcd_bright_level);
Expand All @@ -189,7 +204,6 @@ static ssize_t tinker_mcu_bl_store(struct device *dev, struct device_attribute *
return strnlen(buf, count);
}
static DEVICE_ATTR(tinker_mcu_bl, S_IRUGO | S_IWUSR, tinker_mcu_bl_show, tinker_mcu_bl_store);
static DEVICE_ATTR(brightness, S_IRUGO | S_IWUSR, tinker_mcu_bl_show, tinker_mcu_bl_store);

int tinker_mcu_is_connected(void)
{
Expand All @@ -202,6 +216,8 @@ static int tinker_mcu_probe(struct i2c_client *client,
{
struct tinker_mcu_data *mcu_data;
int ret;
struct backlight_properties props;
struct backlight_device *bl;

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

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

memset(&props, 0, sizeof(props));
props.type = BACKLIGHT_RAW;
props.max_brightness = 255;

bl = backlight_device_register("rpi_backlight", NULL, NULL,
&tinker_mcu_bl_ops, &props);
if (IS_ERR(bl)) {
pr_err("unable to register backlight device\n");
}

ret = device_create_file(&client->dev, &dev_attr_tinker_mcu_bl);
if (ret != 0) {
dev_err(&client->dev, "Failed to create tinker_mcu_bl sysfs files %d\n", ret);
return ret;
}

rpi_backlight_device = device_create(backlight_class, NULL, MKDEV(0, 0), NULL,
"rpi_backlight");
if (IS_ERR(rpi_backlight_device)) {
printk(KERN_WARNING "Unable to create device "
"for rpi_backlight; errno = %ld\n",
PTR_ERR(rpi_backlight_device));
rpi_backlight_device = NULL;
} else {
//init_device
ret = device_create_file(rpi_backlight_device, &dev_attr_brightness);
if (ret != 0) {
dev_err(&client->dev, "Failed to create brightness sysfs files %d\n", ret);
return ret;
}
}

return 0;

error:
Expand Down
32 changes: 27 additions & 5 deletions drivers/video/backlight/backlight.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ static void backlight_generate_event(struct backlight_device *bd,
sysfs_notify(&bd->dev.kobj, NULL, "actual_brightness");
}

#ifndef CONFIG_TINKER_MCU
static ssize_t bl_power_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
Expand Down Expand Up @@ -160,6 +159,7 @@ static ssize_t bl_power_store(struct device *dev, struct device_attribute *attr,
}
static DEVICE_ATTR_RW(bl_power);

#ifndef CONFIG_TINKER_MCU
static ssize_t brightness_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
Expand Down Expand Up @@ -207,6 +207,32 @@ static ssize_t brightness_store(struct device *dev,

return rc ? rc : count;
}
#else
extern int tinker_mcu_set_bright(int bright);
extern int tinker_mcu_get_brightness(void);
static ssize_t brightness_show(struct device *dev, struct device_attribute *attr, char *buf)
{
int level;

level = tinker_mcu_get_brightness();

return sprintf(buf, "%d\n", level);
}

static ssize_t brightness_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
int value;

value = simple_strtoul(buf, NULL, 0);

if((value < 0) || (value > 255)) {
pr_err("Invalid value for backlight setting, value = %d\n", value);
} else
tinker_mcu_set_bright(value);

return strnlen(buf, count);
}
#endif
static DEVICE_ATTR_RW(brightness);

static ssize_t type_show(struct device *dev, struct device_attribute *attr,
Expand Down Expand Up @@ -243,10 +269,8 @@ static ssize_t actual_brightness_show(struct device *dev,
return rc;
}
static DEVICE_ATTR_RO(actual_brightness);
#endif

struct class *backlight_class;
EXPORT_SYMBOL(backlight_class);

#ifdef CONFIG_PM_SLEEP
static int backlight_suspend(struct device *dev)
Expand Down Expand Up @@ -288,13 +312,11 @@ static void bl_device_release(struct device *dev)
}

static struct attribute *bl_device_attrs[] = {
#ifndef CONFIG_TINKER_MCU
&dev_attr_bl_power.attr,
&dev_attr_brightness.attr,
&dev_attr_actual_brightness.attr,
&dev_attr_max_brightness.attr,
&dev_attr_type.attr,
#endif
NULL,
};
ATTRIBUTE_GROUPS(bl_device);
Expand Down
1 change: 0 additions & 1 deletion include/linux/backlight.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ enum backlight_notification {

struct backlight_device;
struct fb_info;
extern struct class *backlight_class;

struct backlight_ops {
unsigned int options;
Expand Down

0 comments on commit 2740b57

Please sign in to comment.