aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/video/backlight/backlight.c
diff options
context:
space:
mode:
authorRichard Purdie <rpurdie@rpsys.net>2007-07-09 07:17:24 -0400
committerRichard Purdie <rpurdie@rpsys.net>2007-07-15 20:20:23 -0400
commit655bfd7aebb12481ab9275284d9500bee5ba3e70 (patch)
tree54503eb59a03d94db77edca3388d36e3e5315dd8 /drivers/video/backlight/backlight.c
parentfa9133c24c4115523c1381b67fdd74fd864ac0ea (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>
Diffstat (limited to 'drivers/video/backlight/backlight.c')
-rw-r--r--drivers/video/backlight/backlight.c125
1 files changed, 53 insertions, 72 deletions
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
72static ssize_t backlight_show_power(struct class_device *cdev, char *buf) 72static 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
79static ssize_t backlight_store_power(struct class_device *cdev, const char *buf, size_t count) 80static 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
104static ssize_t backlight_show_brightness(struct class_device *cdev, char *buf) 106static 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
111static ssize_t backlight_store_brightness(struct class_device *cdev, const char *buf, size_t count) 114static 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
141static ssize_t backlight_show_max_brightness(struct class_device *cdev, char *buf) 145static 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
148static ssize_t backlight_show_actual_brightness(struct class_device *cdev, 153static 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
162static void backlight_class_release(struct class_device *dev) 167struct class *backlight_class;
168
169static 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
168static struct class backlight_class = { 175static 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
180static 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 */
201struct backlight_device *backlight_device_register(const char *name, 197struct 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 */
266void backlight_device_unregister(struct backlight_device *bd) 249void 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}
294EXPORT_SYMBOL(backlight_device_unregister); 267EXPORT_SYMBOL(backlight_device_unregister);
295 268
296static void __exit backlight_class_exit(void) 269static void __exit backlight_class_exit(void)
297{ 270{
298 class_unregister(&backlight_class); 271 class_destroy(backlight_class);
299} 272}
300 273
301static int __init backlight_class_init(void) 274static 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/*