Skip to content

Commit

Permalink
backlight: Convert from struct class_device to struct device
Browse files Browse the repository at this point in the history
Convert the backlight and LCD classes from struct class_device
to struct device since class_device is scheduled for removal.

One nasty API break is the backlight power attribute has had to be
renamed to bl_power and the LCD power attribute has had to be renamed
to lcd_power since the original names clash with the core. I can't see
a way around this.

Signed-off-by: Richard Purdie <rpurdie@rpsys.net>
Acked-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Richard Purdie committed Jul 16, 2007
1 parent fa9133c commit 655bfd7
Show file tree
Hide file tree
Showing 12 changed files with 132 additions and 152 deletions.
4 changes: 2 additions & 2 deletions drivers/acpi/video.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ static int acpi_video_get_brightness(struct backlight_device *bd)
{
unsigned long cur_level;
struct acpi_video_device *vd =
(struct acpi_video_device *)class_get_devdata(&bd->class_dev);
(struct acpi_video_device *)bl_get_data(bd);
acpi_video_device_lcd_get_level_current(vd, &cur_level);
return (int) cur_level;
}
Expand All @@ -287,7 +287,7 @@ static int acpi_video_set_brightness(struct backlight_device *bd)
{
int request_level = bd->props.brightness;
struct acpi_video_device *vd =
(struct acpi_video_device *)class_get_devdata(&bd->class_dev);
(struct acpi_video_device *)bl_get_data(bd);
acpi_video_device_lcd_set_level(vd, request_level);
return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions drivers/usb/misc/appledisplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ static void appledisplay_complete(struct urb *urb)

static int appledisplay_bl_update_status(struct backlight_device *bd)
{
struct appledisplay *pdata = class_get_devdata(&bd->class_dev);
struct appledisplay *pdata = bl_get_data(bd);
int retval;

pdata->msgdata[0] = 0x10;
Expand All @@ -158,7 +158,7 @@ static int appledisplay_bl_update_status(struct backlight_device *bd)

static int appledisplay_bl_get_brightness(struct backlight_device *bd)
{
struct appledisplay *pdata = class_get_devdata(&bd->class_dev);
struct appledisplay *pdata = bl_get_data(bd);
int retval;

retval = usb_control_msg(
Expand Down
2 changes: 1 addition & 1 deletion drivers/video/aty/aty128fb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1733,7 +1733,7 @@ static int aty128_bl_get_level_brightness(struct aty128fb_par *par,

static int aty128_bl_update_status(struct backlight_device *bd)
{
struct aty128fb_par *par = class_get_devdata(&bd->class_dev);
struct aty128fb_par *par = bl_get_data(bd);
unsigned int reg = aty_ld_le32(LVDS_GEN_CNTL);
int level;

Expand Down
2 changes: 1 addition & 1 deletion drivers/video/aty/atyfb_base.c
Original file line number Diff line number Diff line change
Expand Up @@ -2141,7 +2141,7 @@ static int aty_bl_get_level_brightness(struct atyfb_par *par, int level)

static int aty_bl_update_status(struct backlight_device *bd)
{
struct atyfb_par *par = class_get_devdata(&bd->class_dev);
struct atyfb_par *par = bl_get_data(bd);
unsigned int reg = aty_ld_lcd(LCD_MISC_CNTL, par);
int level;

Expand Down
4 changes: 2 additions & 2 deletions drivers/video/aty/radeon_backlight.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static int radeon_bl_get_level_brightness(struct radeon_bl_privdata *pdata,

static int radeon_bl_update_status(struct backlight_device *bd)
{
struct radeon_bl_privdata *pdata = class_get_devdata(&bd->class_dev);
struct radeon_bl_privdata *pdata = bl_get_data(bd);
struct radeonfb_info *rinfo = pdata->rinfo;
u32 lvds_gen_cntl, tmpPixclksCntl;
int level;
Expand Down Expand Up @@ -206,7 +206,7 @@ void radeonfb_bl_exit(struct radeonfb_info *rinfo)
if (bd) {
struct radeon_bl_privdata *pdata;

pdata = class_get_devdata(&bd->class_dev);
pdata = bl_get_data(bd);
backlight_device_unregister(bd);
kfree(pdata);
rinfo->info->bl_dev = NULL;
Expand Down
125 changes: 53 additions & 72 deletions drivers/video/backlight/backlight.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,20 @@ static inline void backlight_unregister_fb(struct backlight_device *bd)
}
#endif /* CONFIG_FB */

static ssize_t backlight_show_power(struct class_device *cdev, char *buf)
static ssize_t backlight_show_power(struct device *dev,
struct device_attribute *attr,char *buf)
{
struct backlight_device *bd = to_backlight_device(cdev);
struct backlight_device *bd = to_backlight_device(dev);

return sprintf(buf, "%d\n", bd->props.power);
}

static ssize_t backlight_store_power(struct class_device *cdev, const char *buf, size_t count)
static ssize_t backlight_store_power(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
{
int rc = -ENXIO;
char *endp;
struct backlight_device *bd = to_backlight_device(cdev);
struct backlight_device *bd = to_backlight_device(dev);
int power = simple_strtoul(buf, &endp, 0);
size_t size = endp - buf;

Expand All @@ -101,18 +103,20 @@ static ssize_t backlight_store_power(struct class_device *cdev, const char *buf,
return rc;
}

static ssize_t backlight_show_brightness(struct class_device *cdev, char *buf)
static ssize_t backlight_show_brightness(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct backlight_device *bd = to_backlight_device(cdev);
struct backlight_device *bd = to_backlight_device(dev);

return sprintf(buf, "%d\n", bd->props.brightness);
}

static ssize_t backlight_store_brightness(struct class_device *cdev, const char *buf, size_t count)
static ssize_t backlight_store_brightness(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
{
int rc = -ENXIO;
char *endp;
struct backlight_device *bd = to_backlight_device(cdev);
struct backlight_device *bd = to_backlight_device(dev);
int brightness = simple_strtoul(buf, &endp, 0);
size_t size = endp - buf;

Expand All @@ -138,18 +142,19 @@ static ssize_t backlight_store_brightness(struct class_device *cdev, const char
return rc;
}

static ssize_t backlight_show_max_brightness(struct class_device *cdev, char *buf)
static ssize_t backlight_show_max_brightness(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct backlight_device *bd = to_backlight_device(cdev);
struct backlight_device *bd = to_backlight_device(dev);

return sprintf(buf, "%d\n", bd->props.max_brightness);
}

static ssize_t backlight_show_actual_brightness(struct class_device *cdev,
char *buf)
static ssize_t backlight_show_actual_brightness(struct device *dev,
struct device_attribute *attr, char *buf)
{
int rc = -ENXIO;
struct backlight_device *bd = to_backlight_device(cdev);
struct backlight_device *bd = to_backlight_device(dev);

mutex_lock(&bd->ops_lock);
if (bd->ops && bd->ops->get_brightness)
Expand All @@ -159,92 +164,70 @@ static ssize_t backlight_show_actual_brightness(struct class_device *cdev,
return rc;
}

static void backlight_class_release(struct class_device *dev)
struct class *backlight_class;

static void bl_device_release(struct device *dev)
{
struct backlight_device *bd = to_backlight_device(dev);
kfree(bd);
}

static struct class backlight_class = {
.name = "backlight",
.release = backlight_class_release,
};

#define DECLARE_ATTR(_name,_mode,_show,_store) \
{ \
.attr = { .name = __stringify(_name), .mode = _mode }, \
.show = _show, \
.store = _store, \
}

static const struct class_device_attribute bl_class_device_attributes[] = {
DECLARE_ATTR(power, 0644, backlight_show_power, backlight_store_power),
DECLARE_ATTR(brightness, 0644, backlight_show_brightness,
static struct device_attribute bl_device_attributes[] = {
__ATTR(bl_power, 0644, backlight_show_power, backlight_store_power),
__ATTR(brightness, 0644, backlight_show_brightness,
backlight_store_brightness),
DECLARE_ATTR(actual_brightness, 0444, backlight_show_actual_brightness,
__ATTR(actual_brightness, 0444, backlight_show_actual_brightness,
NULL),
DECLARE_ATTR(max_brightness, 0444, backlight_show_max_brightness, NULL),
__ATTR(max_brightness, 0444, backlight_show_max_brightness, NULL),
__ATTR_NULL,
};

/**
* backlight_device_register - create and register a new object of
* backlight_device class.
* @name: the name of the new object(must be the same as the name of the
* respective framebuffer device).
* @devdata: an optional pointer to be stored in the class_device. The
* methods may retrieve it by using class_get_devdata(&bd->class_dev).
* @devdata: an optional pointer to be stored for private driver use. The
* methods may retrieve it by using bl_get_data(bd).
* @ops: the backlight operations structure.
*
* Creates and registers new backlight class_device. Returns either an
* Creates and registers new backlight device. Returns either an
* ERR_PTR() or a pointer to the newly allocated device.
*/
struct backlight_device *backlight_device_register(const char *name,
struct device *dev,
void *devdata,
struct backlight_ops *ops)
struct device *parent, void *devdata, struct backlight_ops *ops)
{
int i, rc;
struct backlight_device *new_bd;
int rc;

pr_debug("backlight_device_alloc: name=%s\n", name);
pr_debug("backlight_device_register: name=%s\n", name);

new_bd = kzalloc(sizeof(struct backlight_device), GFP_KERNEL);
if (!new_bd)
return ERR_PTR(-ENOMEM);

mutex_init(&new_bd->update_lock);
mutex_init(&new_bd->ops_lock);
new_bd->ops = ops;
new_bd->class_dev.class = &backlight_class;
new_bd->class_dev.dev = dev;
strlcpy(new_bd->class_dev.class_id, name, KOBJ_NAME_LEN);
class_set_devdata(&new_bd->class_dev, devdata);

rc = class_device_register(&new_bd->class_dev);
new_bd->dev.class = backlight_class;
new_bd->dev.parent = parent;
new_bd->dev.release = bl_device_release;
strlcpy(new_bd->dev.bus_id, name, BUS_ID_SIZE);
dev_set_drvdata(&new_bd->dev, devdata);

rc = device_register(&new_bd->dev);
if (rc) {
kfree(new_bd);
return ERR_PTR(rc);
}

rc = backlight_register_fb(new_bd);
if (rc) {
class_device_unregister(&new_bd->class_dev);
device_unregister(&new_bd->dev);
return ERR_PTR(rc);
}


for (i = 0; i < ARRAY_SIZE(bl_class_device_attributes); i++) {
rc = class_device_create_file(&new_bd->class_dev,
&bl_class_device_attributes[i]);
if (rc) {
while (--i >= 0)
class_device_remove_file(&new_bd->class_dev,
&bl_class_device_attributes[i]);
class_device_unregister(&new_bd->class_dev);
/* No need to kfree(new_bd) since release() method was called */
return ERR_PTR(rc);
}
}
new_bd->ops = ops;

#ifdef CONFIG_PMAC_BACKLIGHT
mutex_lock(&pmac_backlight_mutex);
Expand All @@ -265,42 +248,40 @@ EXPORT_SYMBOL(backlight_device_register);
*/
void backlight_device_unregister(struct backlight_device *bd)
{
int i;

if (!bd)
return;

pr_debug("backlight_device_unregister: name=%s\n", bd->class_dev.class_id);

#ifdef CONFIG_PMAC_BACKLIGHT
mutex_lock(&pmac_backlight_mutex);
if (pmac_backlight == bd)
pmac_backlight = NULL;
mutex_unlock(&pmac_backlight_mutex);
#endif

for (i = 0; i < ARRAY_SIZE(bl_class_device_attributes); i++)
class_device_remove_file(&bd->class_dev,
&bl_class_device_attributes[i]);

mutex_lock(&bd->ops_lock);
bd->ops = NULL;
mutex_unlock(&bd->ops_lock);

backlight_unregister_fb(bd);

class_device_unregister(&bd->class_dev);
device_unregister(&bd->dev);
}
EXPORT_SYMBOL(backlight_device_unregister);

static void __exit backlight_class_exit(void)
{
class_unregister(&backlight_class);
class_destroy(backlight_class);
}

static int __init backlight_class_init(void)
{
return class_register(&backlight_class);
backlight_class = class_create(THIS_MODULE, "backlight");
if (IS_ERR(backlight_class)) {
printk(KERN_WARNING "Unable to create backlight class; errno = %ld\n",
PTR_ERR(backlight_class));
return PTR_ERR(backlight_class);
}

backlight_class->dev_attrs = bl_device_attributes;
return 0;
}

/*
Expand Down
2 changes: 1 addition & 1 deletion drivers/video/backlight/cr_bllcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ static int cr_backlight_probe(struct platform_device *pdev)
}

crp->cr_lcd_device = lcd_device_register("cr-lcd",
&pdev->dev,
&pdev->dev, NULL
&cr_lcd_ops);

if (IS_ERR(crp->cr_lcd_device)) {
Expand Down
Loading

0 comments on commit 655bfd7

Please sign in to comment.