/* Platform devices */
static struct platform_device *dcon_device;
-/* Backlight device */
-static struct backlight_device *dcon_bl_dev;
-
static DECLARE_WAIT_QUEUE_HEAD(dcon_wait_queue);
static unsigned short normal_i2c[] = { 0x0d, I2C_CLIENT_END };
return i2c_smbus_read_word_data(dcon->client, reg);
}
-/* The current backlight value - this saves us some smbus traffic */
-static int bl_val = -1;
-
/* ===== API functions - these are called by a variety of users ==== */
static int dcon_hw_init(struct dcon_priv *dcon, int is_init)
return 0;
}
-static int dcon_get_backlight(struct dcon_priv *dcon)
+static void dcon_set_backlight(struct dcon_priv *dcon, u8 level)
{
- if (!dcon || !dcon->client)
- return 0;
-
- if (bl_val == -1)
- bl_val = dcon_read(dcon, DCON_REG_BRIGHT) & 0x0F;
-
- return bl_val;
-}
-
-
-static void dcon_set_backlight_hw(struct dcon_priv *dcon, int level)
-{
- bl_val = level & 0x0F;
- dcon_write(dcon, DCON_REG_BRIGHT, bl_val);
+ dcon->bl_val = level;
+ dcon_write(dcon, DCON_REG_BRIGHT, dcon->bl_val);
/* Purposely turn off the backlight when we go to level 0 */
- if (bl_val == 0) {
+ if (dcon->bl_val == 0) {
dcon->disp_mode &= ~MODE_BL_ENABLE;
dcon_write(dcon, DCON_REG_MODE, dcon->disp_mode);
} else if (!(dcon->disp_mode & MODE_BL_ENABLE)) {
}
}
-static void dcon_set_backlight(struct dcon_priv *dcon, int level)
-{
- if (!dcon || !dcon->client)
- return;
-
- if (bl_val == (level & 0x0F))
- return;
-
- dcon_set_backlight_hw(dcon, level);
-}
-
/* Set the output type to either color or mono */
static int dcon_set_mono_mode(struct dcon_priv *dcon, bool enable_mono)
{
dcon->asleep = sleep;
} else {
/* Only re-enable the backlight if the backlight value is set */
- if (bl_val != 0)
+ if (dcon->bl_val != 0)
dcon->disp_mode |= MODE_BL_ENABLE;
x = dcon_bus_stabilize(dcon, 1);
if (x)
dcon->asleep = sleep;
/* Restore backlight */
- dcon_set_backlight_hw(dcon, bl_val);
+ dcon_set_backlight(dcon, dcon->bl_val);
}
/* We should turn off some stuff in the framebuffer - but what? */
flush_scheduled_work();
}
-static int dconbl_set(struct backlight_device *dev)
-{
- struct dcon_priv *dcon = bl_get_data(dev);
- int level = dev->props.brightness;
-
- if (dev->props.power != FB_BLANK_UNBLANK)
- level = 0;
-
- dcon_set_backlight(dcon, level);
- return 0;
-}
-
-static int dconbl_get(struct backlight_device *dev)
-{
- struct dcon_priv *dcon = bl_get_data(dev);
- return dcon_get_backlight(dcon);
-}
-
static ssize_t dcon_mode_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
__ATTR(resumeline, 0644, dcon_resumeline_show, dcon_resumeline_store),
};
+static int dcon_bl_update(struct backlight_device *dev)
+{
+ struct dcon_priv *dcon = bl_get_data(dev);
+ u8 level = dev->props.brightness & 0x0F;
+
+ if (dev->props.power != FB_BLANK_UNBLANK)
+ level = 0;
+
+ if (level != dcon->bl_val)
+ dcon_set_backlight(dcon, level);
+
+ return 0;
+}
+
+static int dcon_bl_get(struct backlight_device *dev)
+{
+ struct dcon_priv *dcon = bl_get_data(dev);
+ return dcon->bl_val;
+}
+
static const struct backlight_ops dcon_bl_ops = {
- .get_brightness = dconbl_get,
- .update_status = dconbl_set
+ .update_status = dcon_bl_update,
+ .get_brightness = dcon_bl_get,
};
+static struct backlight_properties dcon_bl_props = {
+ .max_brightness = 15,
+ .power = FB_BLANK_UNBLANK,
+};
static int dcon_reboot_notify(struct notifier_block *nb,
unsigned long foo, void *bar)
}
}
- /* Add the backlight device for the DCON */
- dcon_bl_dev = backlight_device_register("dcon-bl", &dcon_device->dev,
- dcon, &dcon_bl_ops, NULL);
-
- if (IS_ERR(dcon_bl_dev)) {
- printk(KERN_ERR "Cannot register the backlight device (%ld)\n",
- PTR_ERR(dcon_bl_dev));
- dcon_bl_dev = NULL;
- } else {
- dcon_bl_dev->props.max_brightness = 15;
- dcon_bl_dev->props.power = FB_BLANK_UNBLANK;
- dcon_bl_dev->props.brightness = dcon_get_backlight(dcon);
+ dcon->bl_val = dcon_read(dcon, DCON_REG_BRIGHT) & 0x0F;
- backlight_update_status(dcon_bl_dev);
+ /* Add the backlight device for the DCON */
+ dcon_bl_props.brightness = dcon->bl_val;
+ dcon->bl_dev = backlight_device_register("dcon-bl", &dcon_device->dev,
+ dcon, &dcon_bl_ops, &dcon_bl_props);
+ if (IS_ERR(dcon->bl_dev)) {
+ dev_err(&client->dev, "cannot register backlight dev (%ld)\n",
+ PTR_ERR(dcon->bl_dev));
+ dcon->bl_dev = NULL;
}
register_reboot_notifier(&dcon->reboot_nb);
free_irq(DCON_IRQ, dcon);
- if (dcon_bl_dev != NULL)
- backlight_device_unregister(dcon_bl_dev);
+ if (dcon->bl_dev)
+ backlight_device_unregister(dcon->bl_dev);
if (dcon_device != NULL)
platform_device_unregister(dcon_device);