diff options
author | Richard Purdie <rpurdie@rpsys.net> | 2007-07-09 07:17:24 -0400 |
---|---|---|
committer | Richard Purdie <rpurdie@rpsys.net> | 2007-07-15 20:20:23 -0400 |
commit | 655bfd7aebb12481ab9275284d9500bee5ba3e70 (patch) | |
tree | 54503eb59a03d94db77edca3388d36e3e5315dd8 | |
parent | fa9133c24c4115523c1381b67fdd74fd864ac0ea (diff) |
backlight: Convert from struct class_device to struct device
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>
-rw-r--r-- | drivers/acpi/video.c | 4 | ||||
-rw-r--r-- | drivers/usb/misc/appledisplay.c | 4 | ||||
-rw-r--r-- | drivers/video/aty/aty128fb.c | 2 | ||||
-rw-r--r-- | drivers/video/aty/atyfb_base.c | 2 | ||||
-rw-r--r-- | drivers/video/aty/radeon_backlight.c | 4 | ||||
-rw-r--r-- | drivers/video/backlight/backlight.c | 125 | ||||
-rw-r--r-- | drivers/video/backlight/cr_bllcd.c | 2 | ||||
-rw-r--r-- | drivers/video/backlight/lcd.c | 112 | ||||
-rw-r--r-- | drivers/video/nvidia/nv_backlight.c | 2 | ||||
-rw-r--r-- | drivers/video/riva/fbdev.c | 2 | ||||
-rw-r--r-- | include/linux/backlight.h | 11 | ||||
-rw-r--r-- | include/linux/lcd.h | 14 |
12 files changed, 132 insertions, 152 deletions
diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c index 00d25b347255..7fd672af33ba 100644 --- a/drivers/acpi/video.c +++ b/drivers/acpi/video.c | |||
@@ -278,7 +278,7 @@ static int acpi_video_get_brightness(struct backlight_device *bd) | |||
278 | { | 278 | { |
279 | unsigned long cur_level; | 279 | unsigned long cur_level; |
280 | struct acpi_video_device *vd = | 280 | struct acpi_video_device *vd = |
281 | (struct acpi_video_device *)class_get_devdata(&bd->class_dev); | 281 | (struct acpi_video_device *)bl_get_data(bd); |
282 | acpi_video_device_lcd_get_level_current(vd, &cur_level); | 282 | acpi_video_device_lcd_get_level_current(vd, &cur_level); |
283 | return (int) cur_level; | 283 | return (int) cur_level; |
284 | } | 284 | } |
@@ -287,7 +287,7 @@ static int acpi_video_set_brightness(struct backlight_device *bd) | |||
287 | { | 287 | { |
288 | int request_level = bd->props.brightness; | 288 | int request_level = bd->props.brightness; |
289 | struct acpi_video_device *vd = | 289 | struct acpi_video_device *vd = |
290 | (struct acpi_video_device *)class_get_devdata(&bd->class_dev); | 290 | (struct acpi_video_device *)bl_get_data(bd); |
291 | acpi_video_device_lcd_set_level(vd, request_level); | 291 | acpi_video_device_lcd_set_level(vd, request_level); |
292 | return 0; | 292 | return 0; |
293 | } | 293 | } |
diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c index cf70c16f0e3f..4e88553e1666 100644 --- a/drivers/usb/misc/appledisplay.c +++ b/drivers/usb/misc/appledisplay.c | |||
@@ -137,7 +137,7 @@ exit: | |||
137 | 137 | ||
138 | static int appledisplay_bl_update_status(struct backlight_device *bd) | 138 | static int appledisplay_bl_update_status(struct backlight_device *bd) |
139 | { | 139 | { |
140 | struct appledisplay *pdata = class_get_devdata(&bd->class_dev); | 140 | struct appledisplay *pdata = bl_get_data(bd); |
141 | int retval; | 141 | int retval; |
142 | 142 | ||
143 | pdata->msgdata[0] = 0x10; | 143 | pdata->msgdata[0] = 0x10; |
@@ -158,7 +158,7 @@ static int appledisplay_bl_update_status(struct backlight_device *bd) | |||
158 | 158 | ||
159 | static int appledisplay_bl_get_brightness(struct backlight_device *bd) | 159 | static int appledisplay_bl_get_brightness(struct backlight_device *bd) |
160 | { | 160 | { |
161 | struct appledisplay *pdata = class_get_devdata(&bd->class_dev); | 161 | struct appledisplay *pdata = bl_get_data(bd); |
162 | int retval; | 162 | int retval; |
163 | 163 | ||
164 | retval = usb_control_msg( | 164 | retval = usb_control_msg( |
diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c index 7fea4d8ae8e2..cfcbe37d2d70 100644 --- a/drivers/video/aty/aty128fb.c +++ b/drivers/video/aty/aty128fb.c | |||
@@ -1733,7 +1733,7 @@ static int aty128_bl_get_level_brightness(struct aty128fb_par *par, | |||
1733 | 1733 | ||
1734 | static int aty128_bl_update_status(struct backlight_device *bd) | 1734 | static int aty128_bl_update_status(struct backlight_device *bd) |
1735 | { | 1735 | { |
1736 | struct aty128fb_par *par = class_get_devdata(&bd->class_dev); | 1736 | struct aty128fb_par *par = bl_get_data(bd); |
1737 | unsigned int reg = aty_ld_le32(LVDS_GEN_CNTL); | 1737 | unsigned int reg = aty_ld_le32(LVDS_GEN_CNTL); |
1738 | int level; | 1738 | int level; |
1739 | 1739 | ||
diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c index 2fbff6317433..d2c68c3d8d76 100644 --- a/drivers/video/aty/atyfb_base.c +++ b/drivers/video/aty/atyfb_base.c | |||
@@ -2141,7 +2141,7 @@ static int aty_bl_get_level_brightness(struct atyfb_par *par, int level) | |||
2141 | 2141 | ||
2142 | static int aty_bl_update_status(struct backlight_device *bd) | 2142 | static int aty_bl_update_status(struct backlight_device *bd) |
2143 | { | 2143 | { |
2144 | struct atyfb_par *par = class_get_devdata(&bd->class_dev); | 2144 | struct atyfb_par *par = bl_get_data(bd); |
2145 | unsigned int reg = aty_ld_lcd(LCD_MISC_CNTL, par); | 2145 | unsigned int reg = aty_ld_lcd(LCD_MISC_CNTL, par); |
2146 | int level; | 2146 | int level; |
2147 | 2147 | ||
diff --git a/drivers/video/aty/radeon_backlight.c b/drivers/video/aty/radeon_backlight.c index 0be25fa5540c..1a056adb61c8 100644 --- a/drivers/video/aty/radeon_backlight.c +++ b/drivers/video/aty/radeon_backlight.c | |||
@@ -47,7 +47,7 @@ static int radeon_bl_get_level_brightness(struct radeon_bl_privdata *pdata, | |||
47 | 47 | ||
48 | static int radeon_bl_update_status(struct backlight_device *bd) | 48 | static int radeon_bl_update_status(struct backlight_device *bd) |
49 | { | 49 | { |
50 | struct radeon_bl_privdata *pdata = class_get_devdata(&bd->class_dev); | 50 | struct radeon_bl_privdata *pdata = bl_get_data(bd); |
51 | struct radeonfb_info *rinfo = pdata->rinfo; | 51 | struct radeonfb_info *rinfo = pdata->rinfo; |
52 | u32 lvds_gen_cntl, tmpPixclksCntl; | 52 | u32 lvds_gen_cntl, tmpPixclksCntl; |
53 | int level; | 53 | int level; |
@@ -206,7 +206,7 @@ void radeonfb_bl_exit(struct radeonfb_info *rinfo) | |||
206 | if (bd) { | 206 | if (bd) { |
207 | struct radeon_bl_privdata *pdata; | 207 | struct radeon_bl_privdata *pdata; |
208 | 208 | ||
209 | pdata = class_get_devdata(&bd->class_dev); | 209 | pdata = bl_get_data(bd); |
210 | backlight_device_unregister(bd); | 210 | backlight_device_unregister(bd); |
211 | kfree(pdata); | 211 | kfree(pdata); |
212 | rinfo->info->bl_dev = NULL; | 212 | rinfo->info->bl_dev = NULL; |
diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c index 7e06223bca94..b26de8cf3112 100644 --- a/drivers/video/backlight/backlight.c +++ b/drivers/video/backlight/backlight.c | |||
@@ -69,18 +69,20 @@ static inline void backlight_unregister_fb(struct backlight_device *bd) | |||
69 | } | 69 | } |
70 | #endif /* CONFIG_FB */ | 70 | #endif /* CONFIG_FB */ |
71 | 71 | ||
72 | static ssize_t backlight_show_power(struct class_device *cdev, char *buf) | 72 | static ssize_t backlight_show_power(struct device *dev, |
73 | struct device_attribute *attr,char *buf) | ||
73 | { | 74 | { |
74 | struct backlight_device *bd = to_backlight_device(cdev); | 75 | struct backlight_device *bd = to_backlight_device(dev); |
75 | 76 | ||
76 | return sprintf(buf, "%d\n", bd->props.power); | 77 | return sprintf(buf, "%d\n", bd->props.power); |
77 | } | 78 | } |
78 | 79 | ||
79 | static ssize_t backlight_store_power(struct class_device *cdev, const char *buf, size_t count) | 80 | static ssize_t backlight_store_power(struct device *dev, |
81 | struct device_attribute *attr, const char *buf, size_t count) | ||
80 | { | 82 | { |
81 | int rc = -ENXIO; | 83 | int rc = -ENXIO; |
82 | char *endp; | 84 | char *endp; |
83 | struct backlight_device *bd = to_backlight_device(cdev); | 85 | struct backlight_device *bd = to_backlight_device(dev); |
84 | int power = simple_strtoul(buf, &endp, 0); | 86 | int power = simple_strtoul(buf, &endp, 0); |
85 | size_t size = endp - buf; | 87 | size_t size = endp - buf; |
86 | 88 | ||
@@ -101,18 +103,20 @@ static ssize_t backlight_store_power(struct class_device *cdev, const char *buf, | |||
101 | return rc; | 103 | return rc; |
102 | } | 104 | } |
103 | 105 | ||
104 | static ssize_t backlight_show_brightness(struct class_device *cdev, char *buf) | 106 | static ssize_t backlight_show_brightness(struct device *dev, |
107 | struct device_attribute *attr, char *buf) | ||
105 | { | 108 | { |
106 | struct backlight_device *bd = to_backlight_device(cdev); | 109 | struct backlight_device *bd = to_backlight_device(dev); |
107 | 110 | ||
108 | return sprintf(buf, "%d\n", bd->props.brightness); | 111 | return sprintf(buf, "%d\n", bd->props.brightness); |
109 | } | 112 | } |
110 | 113 | ||
111 | static ssize_t backlight_store_brightness(struct class_device *cdev, const char *buf, size_t count) | 114 | static ssize_t backlight_store_brightness(struct device *dev, |
115 | struct device_attribute *attr, const char *buf, size_t count) | ||
112 | { | 116 | { |
113 | int rc = -ENXIO; | 117 | int rc = -ENXIO; |
114 | char *endp; | 118 | char *endp; |
115 | struct backlight_device *bd = to_backlight_device(cdev); | 119 | struct backlight_device *bd = to_backlight_device(dev); |
116 | int brightness = simple_strtoul(buf, &endp, 0); | 120 | int brightness = simple_strtoul(buf, &endp, 0); |
117 | size_t size = endp - buf; | 121 | size_t size = endp - buf; |
118 | 122 | ||
@@ -138,18 +142,19 @@ static ssize_t backlight_store_brightness(struct class_device *cdev, const char | |||
138 | return rc; | 142 | return rc; |
139 | } | 143 | } |
140 | 144 | ||
141 | static ssize_t backlight_show_max_brightness(struct class_device *cdev, char *buf) | 145 | static ssize_t backlight_show_max_brightness(struct device *dev, |
146 | struct device_attribute *attr, char *buf) | ||
142 | { | 147 | { |
143 | struct backlight_device *bd = to_backlight_device(cdev); | 148 | struct backlight_device *bd = to_backlight_device(dev); |
144 | 149 | ||
145 | return sprintf(buf, "%d\n", bd->props.max_brightness); | 150 | return sprintf(buf, "%d\n", bd->props.max_brightness); |
146 | } | 151 | } |
147 | 152 | ||
148 | static ssize_t backlight_show_actual_brightness(struct class_device *cdev, | 153 | static ssize_t backlight_show_actual_brightness(struct device *dev, |
149 | char *buf) | 154 | struct device_attribute *attr, char *buf) |
150 | { | 155 | { |
151 | int rc = -ENXIO; | 156 | int rc = -ENXIO; |
152 | struct backlight_device *bd = to_backlight_device(cdev); | 157 | struct backlight_device *bd = to_backlight_device(dev); |
153 | 158 | ||
154 | mutex_lock(&bd->ops_lock); | 159 | mutex_lock(&bd->ops_lock); |
155 | if (bd->ops && bd->ops->get_brightness) | 160 | if (bd->ops && bd->ops->get_brightness) |
@@ -159,31 +164,22 @@ static ssize_t backlight_show_actual_brightness(struct class_device *cdev, | |||
159 | return rc; | 164 | return rc; |
160 | } | 165 | } |
161 | 166 | ||
162 | static void backlight_class_release(struct class_device *dev) | 167 | struct class *backlight_class; |
168 | |||
169 | static void bl_device_release(struct device *dev) | ||
163 | { | 170 | { |
164 | struct backlight_device *bd = to_backlight_device(dev); | 171 | struct backlight_device *bd = to_backlight_device(dev); |
165 | kfree(bd); | 172 | kfree(bd); |
166 | } | 173 | } |
167 | 174 | ||
168 | static struct class backlight_class = { | 175 | static struct device_attribute bl_device_attributes[] = { |
169 | .name = "backlight", | 176 | __ATTR(bl_power, 0644, backlight_show_power, backlight_store_power), |
170 | .release = backlight_class_release, | 177 | __ATTR(brightness, 0644, backlight_show_brightness, |
171 | }; | ||
172 | |||
173 | #define DECLARE_ATTR(_name,_mode,_show,_store) \ | ||
174 | { \ | ||
175 | .attr = { .name = __stringify(_name), .mode = _mode }, \ | ||
176 | .show = _show, \ | ||
177 | .store = _store, \ | ||
178 | } | ||
179 | |||
180 | static const struct class_device_attribute bl_class_device_attributes[] = { | ||
181 | DECLARE_ATTR(power, 0644, backlight_show_power, backlight_store_power), | ||
182 | DECLARE_ATTR(brightness, 0644, backlight_show_brightness, | ||
183 | backlight_store_brightness), | 178 | backlight_store_brightness), |
184 | DECLARE_ATTR(actual_brightness, 0444, backlight_show_actual_brightness, | 179 | __ATTR(actual_brightness, 0444, backlight_show_actual_brightness, |
185 | NULL), | 180 | NULL), |
186 | DECLARE_ATTR(max_brightness, 0444, backlight_show_max_brightness, NULL), | 181 | __ATTR(max_brightness, 0444, backlight_show_max_brightness, NULL), |
182 | __ATTR_NULL, | ||
187 | }; | 183 | }; |
188 | 184 | ||
189 | /** | 185 | /** |
@@ -191,22 +187,20 @@ static const struct class_device_attribute bl_class_device_attributes[] = { | |||
191 | * backlight_device class. | 187 | * backlight_device class. |
192 | * @name: the name of the new object(must be the same as the name of the | 188 | * @name: the name of the new object(must be the same as the name of the |
193 | * respective framebuffer device). | 189 | * respective framebuffer device). |
194 | * @devdata: an optional pointer to be stored in the class_device. The | 190 | * @devdata: an optional pointer to be stored for private driver use. The |
195 | * methods may retrieve it by using class_get_devdata(&bd->class_dev). | 191 | * methods may retrieve it by using bl_get_data(bd). |
196 | * @ops: the backlight operations structure. | 192 | * @ops: the backlight operations structure. |
197 | * | 193 | * |
198 | * Creates and registers new backlight class_device. Returns either an | 194 | * Creates and registers new backlight device. Returns either an |
199 | * ERR_PTR() or a pointer to the newly allocated device. | 195 | * ERR_PTR() or a pointer to the newly allocated device. |
200 | */ | 196 | */ |
201 | struct backlight_device *backlight_device_register(const char *name, | 197 | struct backlight_device *backlight_device_register(const char *name, |
202 | struct device *dev, | 198 | struct device *parent, void *devdata, struct backlight_ops *ops) |
203 | void *devdata, | ||
204 | struct backlight_ops *ops) | ||
205 | { | 199 | { |
206 | int i, rc; | ||
207 | struct backlight_device *new_bd; | 200 | struct backlight_device *new_bd; |
201 | int rc; | ||
208 | 202 | ||
209 | pr_debug("backlight_device_alloc: name=%s\n", name); | 203 | pr_debug("backlight_device_register: name=%s\n", name); |
210 | 204 | ||
211 | new_bd = kzalloc(sizeof(struct backlight_device), GFP_KERNEL); | 205 | new_bd = kzalloc(sizeof(struct backlight_device), GFP_KERNEL); |
212 | if (!new_bd) | 206 | if (!new_bd) |
@@ -214,13 +208,14 @@ struct backlight_device *backlight_device_register(const char *name, | |||
214 | 208 | ||
215 | mutex_init(&new_bd->update_lock); | 209 | mutex_init(&new_bd->update_lock); |
216 | mutex_init(&new_bd->ops_lock); | 210 | mutex_init(&new_bd->ops_lock); |
217 | new_bd->ops = ops; | ||
218 | new_bd->class_dev.class = &backlight_class; | ||
219 | new_bd->class_dev.dev = dev; | ||
220 | strlcpy(new_bd->class_dev.class_id, name, KOBJ_NAME_LEN); | ||
221 | class_set_devdata(&new_bd->class_dev, devdata); | ||
222 | 211 | ||
223 | rc = class_device_register(&new_bd->class_dev); | 212 | new_bd->dev.class = backlight_class; |
213 | new_bd->dev.parent = parent; | ||
214 | new_bd->dev.release = bl_device_release; | ||
215 | strlcpy(new_bd->dev.bus_id, name, BUS_ID_SIZE); | ||
216 | dev_set_drvdata(&new_bd->dev, devdata); | ||
217 | |||
218 | rc = device_register(&new_bd->dev); | ||
224 | if (rc) { | 219 | if (rc) { |
225 | kfree(new_bd); | 220 | kfree(new_bd); |
226 | return ERR_PTR(rc); | 221 | return ERR_PTR(rc); |
@@ -228,23 +223,11 @@ struct backlight_device *backlight_device_register(const char *name, | |||
228 | 223 | ||
229 | rc = backlight_register_fb(new_bd); | 224 | rc = backlight_register_fb(new_bd); |
230 | if (rc) { | 225 | if (rc) { |
231 | class_device_unregister(&new_bd->class_dev); | 226 | device_unregister(&new_bd->dev); |
232 | return ERR_PTR(rc); | 227 | return ERR_PTR(rc); |
233 | } | 228 | } |
234 | 229 | ||
235 | 230 | new_bd->ops = ops; | |
236 | for (i = 0; i < ARRAY_SIZE(bl_class_device_attributes); i++) { | ||
237 | rc = class_device_create_file(&new_bd->class_dev, | ||
238 | &bl_class_device_attributes[i]); | ||
239 | if (rc) { | ||
240 | while (--i >= 0) | ||
241 | class_device_remove_file(&new_bd->class_dev, | ||
242 | &bl_class_device_attributes[i]); | ||
243 | class_device_unregister(&new_bd->class_dev); | ||
244 | /* No need to kfree(new_bd) since release() method was called */ | ||
245 | return ERR_PTR(rc); | ||
246 | } | ||
247 | } | ||
248 | 231 | ||
249 | #ifdef CONFIG_PMAC_BACKLIGHT | 232 | #ifdef CONFIG_PMAC_BACKLIGHT |
250 | mutex_lock(&pmac_backlight_mutex); | 233 | mutex_lock(&pmac_backlight_mutex); |
@@ -265,42 +248,40 @@ EXPORT_SYMBOL(backlight_device_register); | |||
265 | */ | 248 | */ |
266 | void backlight_device_unregister(struct backlight_device *bd) | 249 | void backlight_device_unregister(struct backlight_device *bd) |
267 | { | 250 | { |
268 | int i; | ||
269 | |||
270 | if (!bd) | 251 | if (!bd) |
271 | return; | 252 | return; |
272 | 253 | ||
273 | pr_debug("backlight_device_unregister: name=%s\n", bd->class_dev.class_id); | ||
274 | |||
275 | #ifdef CONFIG_PMAC_BACKLIGHT | 254 | #ifdef CONFIG_PMAC_BACKLIGHT |
276 | mutex_lock(&pmac_backlight_mutex); | 255 | mutex_lock(&pmac_backlight_mutex); |
277 | if (pmac_backlight == bd) | 256 | if (pmac_backlight == bd) |
278 | pmac_backlight = NULL; | 257 | pmac_backlight = NULL; |
279 | mutex_unlock(&pmac_backlight_mutex); | 258 | mutex_unlock(&pmac_backlight_mutex); |
280 | #endif | 259 | #endif |
281 | |||
282 | for (i = 0; i < ARRAY_SIZE(bl_class_device_attributes); i++) | ||
283 | class_device_remove_file(&bd->class_dev, | ||
284 | &bl_class_device_attributes[i]); | ||
285 | |||
286 | mutex_lock(&bd->ops_lock); | 260 | mutex_lock(&bd->ops_lock); |
287 | bd->ops = NULL; | 261 | bd->ops = NULL; |
288 | mutex_unlock(&bd->ops_lock); | 262 | mutex_unlock(&bd->ops_lock); |
289 | 263 | ||
290 | backlight_unregister_fb(bd); | 264 | backlight_unregister_fb(bd); |
291 | 265 | device_unregister(&bd->dev); | |
292 | class_device_unregister(&bd->class_dev); | ||
293 | } | 266 | } |
294 | EXPORT_SYMBOL(backlight_device_unregister); | 267 | EXPORT_SYMBOL(backlight_device_unregister); |
295 | 268 | ||
296 | static void __exit backlight_class_exit(void) | 269 | static void __exit backlight_class_exit(void) |
297 | { | 270 | { |
298 | class_unregister(&backlight_class); | 271 | class_destroy(backlight_class); |
299 | } | 272 | } |
300 | 273 | ||
301 | static int __init backlight_class_init(void) | 274 | static int __init backlight_class_init(void) |
302 | { | 275 | { |
303 | return class_register(&backlight_class); | 276 | backlight_class = class_create(THIS_MODULE, "backlight"); |
277 | if (IS_ERR(backlight_class)) { | ||
278 | printk(KERN_WARNING "Unable to create backlight class; errno = %ld\n", | ||
279 | PTR_ERR(backlight_class)); | ||
280 | return PTR_ERR(backlight_class); | ||
281 | } | ||
282 | |||
283 | backlight_class->dev_attrs = bl_device_attributes; | ||
284 | return 0; | ||
304 | } | 285 | } |
305 | 286 | ||
306 | /* | 287 | /* |
diff --git a/drivers/video/backlight/cr_bllcd.c b/drivers/video/backlight/cr_bllcd.c index e9bbc3455c94..3633b6e93e27 100644 --- a/drivers/video/backlight/cr_bllcd.c +++ b/drivers/video/backlight/cr_bllcd.c | |||
@@ -202,7 +202,7 @@ static int cr_backlight_probe(struct platform_device *pdev) | |||
202 | } | 202 | } |
203 | 203 | ||
204 | crp->cr_lcd_device = lcd_device_register("cr-lcd", | 204 | crp->cr_lcd_device = lcd_device_register("cr-lcd", |
205 | &pdev->dev, | 205 | &pdev->dev, NULL |
206 | &cr_lcd_ops); | 206 | &cr_lcd_ops); |
207 | 207 | ||
208 | if (IS_ERR(crp->cr_lcd_device)) { | 208 | if (IS_ERR(crp->cr_lcd_device)) { |
diff --git a/drivers/video/backlight/lcd.c b/drivers/video/backlight/lcd.c index 648b53c1fdea..6f652c65fae1 100644 --- a/drivers/video/backlight/lcd.c +++ b/drivers/video/backlight/lcd.c | |||
@@ -61,10 +61,11 @@ static inline void lcd_unregister_fb(struct lcd_device *ld) | |||
61 | } | 61 | } |
62 | #endif /* CONFIG_FB */ | 62 | #endif /* CONFIG_FB */ |
63 | 63 | ||
64 | static ssize_t lcd_show_power(struct class_device *cdev, char *buf) | 64 | static ssize_t lcd_show_power(struct device *dev, struct device_attribute *attr, |
65 | char *buf) | ||
65 | { | 66 | { |
66 | int rc; | 67 | int rc; |
67 | struct lcd_device *ld = to_lcd_device(cdev); | 68 | struct lcd_device *ld = to_lcd_device(dev); |
68 | 69 | ||
69 | mutex_lock(&ld->ops_lock); | 70 | mutex_lock(&ld->ops_lock); |
70 | if (ld->ops && ld->ops->get_power) | 71 | if (ld->ops && ld->ops->get_power) |
@@ -76,11 +77,12 @@ static ssize_t lcd_show_power(struct class_device *cdev, char *buf) | |||
76 | return rc; | 77 | return rc; |
77 | } | 78 | } |
78 | 79 | ||
79 | static ssize_t lcd_store_power(struct class_device *cdev, const char *buf, size_t count) | 80 | static ssize_t lcd_store_power(struct device *dev, |
81 | struct device_attribute *attr, const char *buf, size_t count) | ||
80 | { | 82 | { |
81 | int rc = -ENXIO; | 83 | int rc = -ENXIO; |
82 | char *endp; | 84 | char *endp; |
83 | struct lcd_device *ld = to_lcd_device(cdev); | 85 | struct lcd_device *ld = to_lcd_device(dev); |
84 | int power = simple_strtoul(buf, &endp, 0); | 86 | int power = simple_strtoul(buf, &endp, 0); |
85 | size_t size = endp - buf; | 87 | size_t size = endp - buf; |
86 | 88 | ||
@@ -100,10 +102,11 @@ static ssize_t lcd_store_power(struct class_device *cdev, const char *buf, size_ | |||
100 | return rc; | 102 | return rc; |
101 | } | 103 | } |
102 | 104 | ||
103 | static ssize_t lcd_show_contrast(struct class_device *cdev, char *buf) | 105 | static ssize_t lcd_show_contrast(struct device *dev, |
106 | struct device_attribute *attr, char *buf) | ||
104 | { | 107 | { |
105 | int rc = -ENXIO; | 108 | int rc = -ENXIO; |
106 | struct lcd_device *ld = to_lcd_device(cdev); | 109 | struct lcd_device *ld = to_lcd_device(dev); |
107 | 110 | ||
108 | mutex_lock(&ld->ops_lock); | 111 | mutex_lock(&ld->ops_lock); |
109 | if (ld->ops && ld->ops->get_contrast) | 112 | if (ld->ops && ld->ops->get_contrast) |
@@ -113,11 +116,12 @@ static ssize_t lcd_show_contrast(struct class_device *cdev, char *buf) | |||
113 | return rc; | 116 | return rc; |
114 | } | 117 | } |
115 | 118 | ||
116 | static ssize_t lcd_store_contrast(struct class_device *cdev, const char *buf, size_t count) | 119 | static ssize_t lcd_store_contrast(struct device *dev, |
120 | struct device_attribute *attr, const char *buf, size_t count) | ||
117 | { | 121 | { |
118 | int rc = -ENXIO; | 122 | int rc = -ENXIO; |
119 | char *endp; | 123 | char *endp; |
120 | struct lcd_device *ld = to_lcd_device(cdev); | 124 | struct lcd_device *ld = to_lcd_device(dev); |
121 | int contrast = simple_strtoul(buf, &endp, 0); | 125 | int contrast = simple_strtoul(buf, &endp, 0); |
122 | size_t size = endp - buf; | 126 | size_t size = endp - buf; |
123 | 127 | ||
@@ -137,53 +141,45 @@ static ssize_t lcd_store_contrast(struct class_device *cdev, const char *buf, si | |||
137 | return rc; | 141 | return rc; |
138 | } | 142 | } |
139 | 143 | ||
140 | static ssize_t lcd_show_max_contrast(struct class_device *cdev, char *buf) | 144 | static ssize_t lcd_show_max_contrast(struct device *dev, |
145 | struct device_attribute *attr, char *buf) | ||
141 | { | 146 | { |
142 | struct lcd_device *ld = to_lcd_device(cdev); | 147 | struct lcd_device *ld = to_lcd_device(dev); |
143 | 148 | ||
144 | return sprintf(buf, "%d\n", ld->props.max_contrast); | 149 | return sprintf(buf, "%d\n", ld->props.max_contrast); |
145 | } | 150 | } |
146 | 151 | ||
147 | static void lcd_class_release(struct class_device *dev) | 152 | struct class *lcd_class; |
153 | |||
154 | static void lcd_device_release(struct device *dev) | ||
148 | { | 155 | { |
149 | struct lcd_device *ld = to_lcd_device(dev); | 156 | struct lcd_device *ld = to_lcd_device(dev); |
150 | kfree(ld); | 157 | kfree(ld); |
151 | } | 158 | } |
152 | 159 | ||
153 | static struct class lcd_class = { | 160 | static struct device_attribute lcd_device_attributes[] = { |
154 | .name = "lcd", | 161 | __ATTR(lcd_power, 0644, lcd_show_power, lcd_store_power), |
155 | .release = lcd_class_release, | 162 | __ATTR(contrast, 0644, lcd_show_contrast, lcd_store_contrast), |
156 | }; | 163 | __ATTR(max_contrast, 0444, lcd_show_max_contrast, NULL), |
157 | 164 | __ATTR_NULL, | |
158 | #define DECLARE_ATTR(_name,_mode,_show,_store) \ | ||
159 | { \ | ||
160 | .attr = { .name = __stringify(_name), .mode = _mode }, \ | ||
161 | .show = _show, \ | ||
162 | .store = _store, \ | ||
163 | } | ||
164 | |||
165 | static const struct class_device_attribute lcd_class_device_attributes[] = { | ||
166 | DECLARE_ATTR(power, 0644, lcd_show_power, lcd_store_power), | ||
167 | DECLARE_ATTR(contrast, 0644, lcd_show_contrast, lcd_store_contrast), | ||
168 | DECLARE_ATTR(max_contrast, 0444, lcd_show_max_contrast, NULL), | ||
169 | }; | 165 | }; |
170 | 166 | ||
171 | /** | 167 | /** |
172 | * lcd_device_register - register a new object of lcd_device class. | 168 | * lcd_device_register - register a new object of lcd_device class. |
173 | * @name: the name of the new object(must be the same as the name of the | 169 | * @name: the name of the new object(must be the same as the name of the |
174 | * respective framebuffer device). | 170 | * respective framebuffer device). |
175 | * @devdata: an optional pointer to be stored in the class_device. The | 171 | * @devdata: an optional pointer to be stored in the device. The |
176 | * methods may retrieve it by using class_get_devdata(ld->class_dev). | 172 | * methods may retrieve it by using lcd_get_data(ld). |
177 | * @ops: the lcd operations structure. | 173 | * @ops: the lcd operations structure. |
178 | * | 174 | * |
179 | * Creates and registers a new lcd class_device. Returns either an ERR_PTR() | 175 | * Creates and registers a new lcd device. Returns either an ERR_PTR() |
180 | * or a pointer to the newly allocated device. | 176 | * or a pointer to the newly allocated device. |
181 | */ | 177 | */ |
182 | struct lcd_device *lcd_device_register(const char *name, void *devdata, | 178 | struct lcd_device *lcd_device_register(const char *name, struct device *parent, |
183 | struct lcd_ops *ops) | 179 | void *devdata, struct lcd_ops *ops) |
184 | { | 180 | { |
185 | int i, rc; | ||
186 | struct lcd_device *new_ld; | 181 | struct lcd_device *new_ld; |
182 | int rc; | ||
187 | 183 | ||
188 | pr_debug("lcd_device_register: name=%s\n", name); | 184 | pr_debug("lcd_device_register: name=%s\n", name); |
189 | 185 | ||
@@ -193,12 +189,14 @@ struct lcd_device *lcd_device_register(const char *name, void *devdata, | |||
193 | 189 | ||
194 | mutex_init(&new_ld->ops_lock); | 190 | mutex_init(&new_ld->ops_lock); |
195 | mutex_init(&new_ld->update_lock); | 191 | mutex_init(&new_ld->update_lock); |
196 | new_ld->ops = ops; | ||
197 | new_ld->class_dev.class = &lcd_class; | ||
198 | strlcpy(new_ld->class_dev.class_id, name, KOBJ_NAME_LEN); | ||
199 | class_set_devdata(&new_ld->class_dev, devdata); | ||
200 | 192 | ||
201 | rc = class_device_register(&new_ld->class_dev); | 193 | new_ld->dev.class = lcd_class; |
194 | new_ld->dev.parent = parent; | ||
195 | new_ld->dev.release = lcd_device_release; | ||
196 | strlcpy(new_ld->dev.bus_id, name, BUS_ID_SIZE); | ||
197 | dev_set_drvdata(&new_ld->dev, devdata); | ||
198 | |||
199 | rc = device_register(&new_ld->dev); | ||
202 | if (rc) { | 200 | if (rc) { |
203 | kfree(new_ld); | 201 | kfree(new_ld); |
204 | return ERR_PTR(rc); | 202 | return ERR_PTR(rc); |
@@ -206,22 +204,11 @@ struct lcd_device *lcd_device_register(const char *name, void *devdata, | |||
206 | 204 | ||
207 | rc = lcd_register_fb(new_ld); | 205 | rc = lcd_register_fb(new_ld); |
208 | if (rc) { | 206 | if (rc) { |
209 | class_device_unregister(&new_ld->class_dev); | 207 | device_unregister(&new_ld->dev); |
210 | return ERR_PTR(rc); | 208 | return ERR_PTR(rc); |
211 | } | 209 | } |
212 | 210 | ||
213 | for (i = 0; i < ARRAY_SIZE(lcd_class_device_attributes); i++) { | 211 | new_ld->ops = ops; |
214 | rc = class_device_create_file(&new_ld->class_dev, | ||
215 | &lcd_class_device_attributes[i]); | ||
216 | if (rc) { | ||
217 | while (--i >= 0) | ||
218 | class_device_remove_file(&new_ld->class_dev, | ||
219 | &lcd_class_device_attributes[i]); | ||
220 | class_device_unregister(&new_ld->class_dev); | ||
221 | /* No need to kfree(new_ld) since release() method was called */ | ||
222 | return ERR_PTR(rc); | ||
223 | } | ||
224 | } | ||
225 | 212 | ||
226 | return new_ld; | 213 | return new_ld; |
227 | } | 214 | } |
@@ -235,33 +222,34 @@ EXPORT_SYMBOL(lcd_device_register); | |||
235 | */ | 222 | */ |
236 | void lcd_device_unregister(struct lcd_device *ld) | 223 | void lcd_device_unregister(struct lcd_device *ld) |
237 | { | 224 | { |
238 | int i; | ||
239 | |||
240 | if (!ld) | 225 | if (!ld) |
241 | return; | 226 | return; |
242 | 227 | ||
243 | pr_debug("lcd_device_unregister: name=%s\n", ld->class_dev.class_id); | ||
244 | |||
245 | for (i = 0; i < ARRAY_SIZE(lcd_class_device_attributes); i++) | ||
246 | class_device_remove_file(&ld->class_dev, | ||
247 | &lcd_class_device_attributes[i]); | ||
248 | |||
249 | mutex_lock(&ld->ops_lock); | 228 | mutex_lock(&ld->ops_lock); |
250 | ld->ops = NULL; | 229 | ld->ops = NULL; |
251 | mutex_unlock(&ld->ops_lock); | 230 | mutex_unlock(&ld->ops_lock); |
252 | lcd_unregister_fb(ld); | 231 | lcd_unregister_fb(ld); |
253 | class_device_unregister(&ld->class_dev); | 232 | |
233 | device_unregister(&ld->dev); | ||
254 | } | 234 | } |
255 | EXPORT_SYMBOL(lcd_device_unregister); | 235 | EXPORT_SYMBOL(lcd_device_unregister); |
256 | 236 | ||
257 | static void __exit lcd_class_exit(void) | 237 | static void __exit lcd_class_exit(void) |
258 | { | 238 | { |
259 | class_unregister(&lcd_class); | 239 | class_destroy(lcd_class); |
260 | } | 240 | } |
261 | 241 | ||
262 | static int __init lcd_class_init(void) | 242 | static int __init lcd_class_init(void) |
263 | { | 243 | { |
264 | return class_register(&lcd_class); | 244 | lcd_class = class_create(THIS_MODULE, "lcd"); |
245 | if (IS_ERR(lcd_class)) { | ||
246 | printk(KERN_WARNING "Unable to create backlight class; errno = %ld\n", | ||
247 | PTR_ERR(lcd_class)); | ||
248 | return PTR_ERR(lcd_class); | ||
249 | } | ||
250 | |||
251 | lcd_class->dev_attrs = lcd_device_attributes; | ||
252 | return 0; | ||
265 | } | 253 | } |
266 | 254 | ||
267 | /* | 255 | /* |
diff --git a/drivers/video/nvidia/nv_backlight.c b/drivers/video/nvidia/nv_backlight.c index 43f62d8ee41d..443e3c85a9a0 100644 --- a/drivers/video/nvidia/nv_backlight.c +++ b/drivers/video/nvidia/nv_backlight.c | |||
@@ -50,7 +50,7 @@ static int nvidia_bl_get_level_brightness(struct nvidia_par *par, | |||
50 | 50 | ||
51 | static int nvidia_bl_update_status(struct backlight_device *bd) | 51 | static int nvidia_bl_update_status(struct backlight_device *bd) |
52 | { | 52 | { |
53 | struct nvidia_par *par = class_get_devdata(&bd->class_dev); | 53 | struct nvidia_par *par = bl_get_data(bd); |
54 | u32 tmp_pcrt, tmp_pmc, fpcontrol; | 54 | u32 tmp_pcrt, tmp_pmc, fpcontrol; |
55 | int level; | 55 | int level; |
56 | 56 | ||
diff --git a/drivers/video/riva/fbdev.c b/drivers/video/riva/fbdev.c index 0fe547842c64..d251174d8baa 100644 --- a/drivers/video/riva/fbdev.c +++ b/drivers/video/riva/fbdev.c | |||
@@ -307,7 +307,7 @@ static int riva_bl_get_level_brightness(struct riva_par *par, | |||
307 | 307 | ||
308 | static int riva_bl_update_status(struct backlight_device *bd) | 308 | static int riva_bl_update_status(struct backlight_device *bd) |
309 | { | 309 | { |
310 | struct riva_par *par = class_get_devdata(&bd->class_dev); | 310 | struct riva_par *par = bl_get_data(bd); |
311 | U032 tmp_pcrt, tmp_pmc; | 311 | U032 tmp_pcrt, tmp_pmc; |
312 | int level; | 312 | int level; |
313 | 313 | ||
diff --git a/include/linux/backlight.h b/include/linux/backlight.h index 1023ba0d6e55..c897c7b03858 100644 --- a/include/linux/backlight.h +++ b/include/linux/backlight.h | |||
@@ -69,8 +69,8 @@ struct backlight_device { | |||
69 | 69 | ||
70 | /* The framebuffer notifier block */ | 70 | /* The framebuffer notifier block */ |
71 | struct notifier_block fb_notif; | 71 | struct notifier_block fb_notif; |
72 | /* The class device structure */ | 72 | |
73 | struct class_device class_dev; | 73 | struct device dev; |
74 | }; | 74 | }; |
75 | 75 | ||
76 | static inline void backlight_update_status(struct backlight_device *bd) | 76 | static inline void backlight_update_status(struct backlight_device *bd) |
@@ -85,6 +85,11 @@ extern struct backlight_device *backlight_device_register(const char *name, | |||
85 | struct device *dev, void *devdata, struct backlight_ops *ops); | 85 | struct device *dev, void *devdata, struct backlight_ops *ops); |
86 | extern void backlight_device_unregister(struct backlight_device *bd); | 86 | extern void backlight_device_unregister(struct backlight_device *bd); |
87 | 87 | ||
88 | #define to_backlight_device(obj) container_of(obj, struct backlight_device, class_dev) | 88 | #define to_backlight_device(obj) container_of(obj, struct backlight_device, dev) |
89 | |||
90 | static inline void * bl_get_data(struct backlight_device *bl_dev) | ||
91 | { | ||
92 | return dev_get_drvdata(&bl_dev->dev); | ||
93 | } | ||
89 | 94 | ||
90 | #endif | 95 | #endif |
diff --git a/include/linux/lcd.h b/include/linux/lcd.h index 598793c0745b..1d379787f2e7 100644 --- a/include/linux/lcd.h +++ b/include/linux/lcd.h | |||
@@ -62,8 +62,8 @@ struct lcd_device { | |||
62 | struct mutex update_lock; | 62 | struct mutex update_lock; |
63 | /* The framebuffer notifier block */ | 63 | /* The framebuffer notifier block */ |
64 | struct notifier_block fb_notif; | 64 | struct notifier_block fb_notif; |
65 | /* The class device structure */ | 65 | |
66 | struct class_device class_dev; | 66 | struct device dev; |
67 | }; | 67 | }; |
68 | 68 | ||
69 | static inline void lcd_set_power(struct lcd_device *ld, int power) | 69 | static inline void lcd_set_power(struct lcd_device *ld, int power) |
@@ -75,9 +75,15 @@ static inline void lcd_set_power(struct lcd_device *ld, int power) | |||
75 | } | 75 | } |
76 | 76 | ||
77 | extern struct lcd_device *lcd_device_register(const char *name, | 77 | extern struct lcd_device *lcd_device_register(const char *name, |
78 | void *devdata, struct lcd_ops *ops); | 78 | struct device *parent, void *devdata, struct lcd_ops *ops); |
79 | extern void lcd_device_unregister(struct lcd_device *ld); | 79 | extern void lcd_device_unregister(struct lcd_device *ld); |
80 | 80 | ||
81 | #define to_lcd_device(obj) container_of(obj, struct lcd_device, class_dev) | 81 | #define to_lcd_device(obj) container_of(obj, struct lcd_device, dev) |
82 | |||
83 | static inline void * lcd_get_data(struct lcd_device *ld_dev) | ||
84 | { | ||
85 | return dev_get_drvdata(&ld_dev->dev); | ||
86 | } | ||
87 | |||
82 | 88 | ||
83 | #endif | 89 | #endif |