aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/video/backlight/backlight.c
diff options
context:
space:
mode:
authorRichard Purdie <rpurdie@rpsys.net>2007-02-10 18:07:48 -0500
committerRichard Purdie <rpurdie@rpsys.net>2007-02-20 04:26:53 -0500
commit599a52d12629394236d785615808845823875868 (patch)
tree4e2dfa3a25ce761be0ecc0490acabac553f77a67 /drivers/video/backlight/backlight.c
parent321709c5994f952b78d567fd7083dbebbdc381b7 (diff)
backlight: Separate backlight properties from backlight ops pointers
Per device data such as brightness belongs to the indivdual device and should therefore be separate from the the backlight operation function pointers. This patch splits the two types of data and allows simplifcation of some code. Signed-off-by: Richard Purdie <rpurdie@rpsys.net>
Diffstat (limited to 'drivers/video/backlight/backlight.c')
-rw-r--r--drivers/video/backlight/backlight.c79
1 files changed, 30 insertions, 49 deletions
diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c
index 822a373d3346..c65e81ff3578 100644
--- a/drivers/video/backlight/backlight.c
+++ b/drivers/video/backlight/backlight.c
@@ -35,14 +35,14 @@ static int fb_notifier_callback(struct notifier_block *self,
35 return 0; 35 return 0;
36 36
37 bd = container_of(self, struct backlight_device, fb_notif); 37 bd = container_of(self, struct backlight_device, fb_notif);
38 mutex_lock(&bd->props_lock); 38 mutex_lock(&bd->ops_lock);
39 if (bd->props) 39 if (bd->ops)
40 if (!bd->props->check_fb || 40 if (!bd->ops->check_fb ||
41 bd->props->check_fb(evdata->info)) { 41 bd->ops->check_fb(evdata->info)) {
42 bd->props->fb_blank = *(int *)evdata->data; 42 bd->props.fb_blank = *(int *)evdata->data;
43 backlight_update_status(bd); 43 backlight_update_status(bd);
44 } 44 }
45 mutex_unlock(&bd->props_lock); 45 mutex_unlock(&bd->ops_lock);
46 return 0; 46 return 0;
47} 47}
48 48
@@ -71,15 +71,9 @@ static inline void backlight_unregister_fb(struct backlight_device *bd)
71 71
72static ssize_t backlight_show_power(struct class_device *cdev, char *buf) 72static ssize_t backlight_show_power(struct class_device *cdev, char *buf)
73{ 73{
74 int rc = -ENXIO;
75 struct backlight_device *bd = to_backlight_device(cdev); 74 struct backlight_device *bd = to_backlight_device(cdev);
76 75
77 mutex_lock(&bd->props_lock); 76 return sprintf(buf, "%d\n", bd->props.power);
78 if (bd->props)
79 rc = sprintf(buf, "%d\n", bd->props->power);
80 mutex_unlock(&bd->props_lock);
81
82 return rc;
83} 77}
84 78
85static ssize_t backlight_store_power(struct class_device *cdev, const char *buf, size_t count) 79static ssize_t backlight_store_power(struct class_device *cdev, const char *buf, size_t count)
@@ -95,29 +89,23 @@ static ssize_t backlight_store_power(struct class_device *cdev, const char *buf,
95 if (size != count) 89 if (size != count)
96 return -EINVAL; 90 return -EINVAL;
97 91
98 mutex_lock(&bd->props_lock); 92 mutex_lock(&bd->ops_lock);
99 if (bd->props) { 93 if (bd->ops) {
100 pr_debug("backlight: set power to %d\n", power); 94 pr_debug("backlight: set power to %d\n", power);
101 bd->props->power = power; 95 bd->props.power = power;
102 backlight_update_status(bd); 96 backlight_update_status(bd);
103 rc = count; 97 rc = count;
104 } 98 }
105 mutex_unlock(&bd->props_lock); 99 mutex_unlock(&bd->ops_lock);
106 100
107 return rc; 101 return rc;
108} 102}
109 103
110static ssize_t backlight_show_brightness(struct class_device *cdev, char *buf) 104static ssize_t backlight_show_brightness(struct class_device *cdev, char *buf)
111{ 105{
112 int rc = -ENXIO;
113 struct backlight_device *bd = to_backlight_device(cdev); 106 struct backlight_device *bd = to_backlight_device(cdev);
114 107
115 mutex_lock(&bd->props_lock); 108 return sprintf(buf, "%d\n", bd->props.brightness);
116 if (bd->props)
117 rc = sprintf(buf, "%d\n", bd->props->brightness);
118 mutex_unlock(&bd->props_lock);
119
120 return rc;
121} 109}
122 110
123static ssize_t backlight_store_brightness(struct class_device *cdev, const char *buf, size_t count) 111static ssize_t backlight_store_brightness(struct class_device *cdev, const char *buf, size_t count)
@@ -133,34 +121,28 @@ static ssize_t backlight_store_brightness(struct class_device *cdev, const char
133 if (size != count) 121 if (size != count)
134 return -EINVAL; 122 return -EINVAL;
135 123
136 mutex_lock(&bd->props_lock); 124 mutex_lock(&bd->ops_lock);
137 if (bd->props) { 125 if (bd->ops) {
138 if (brightness > bd->props->max_brightness) 126 if (brightness > bd->props.max_brightness)
139 rc = -EINVAL; 127 rc = -EINVAL;
140 else { 128 else {
141 pr_debug("backlight: set brightness to %d\n", 129 pr_debug("backlight: set brightness to %d\n",
142 brightness); 130 brightness);
143 bd->props->brightness = brightness; 131 bd->props.brightness = brightness;
144 backlight_update_status(bd); 132 backlight_update_status(bd);
145 rc = count; 133 rc = count;
146 } 134 }
147 } 135 }
148 mutex_unlock(&bd->props_lock); 136 mutex_unlock(&bd->ops_lock);
149 137
150 return rc; 138 return rc;
151} 139}
152 140
153static ssize_t backlight_show_max_brightness(struct class_device *cdev, char *buf) 141static ssize_t backlight_show_max_brightness(struct class_device *cdev, char *buf)
154{ 142{
155 int rc = -ENXIO;
156 struct backlight_device *bd = to_backlight_device(cdev); 143 struct backlight_device *bd = to_backlight_device(cdev);
157 144
158 mutex_lock(&bd->props_lock); 145 return sprintf(buf, "%d\n", bd->props.max_brightness);
159 if (bd->props)
160 rc = sprintf(buf, "%d\n", bd->props->max_brightness);
161 mutex_unlock(&bd->props_lock);
162
163 return rc;
164} 146}
165 147
166static ssize_t backlight_show_actual_brightness(struct class_device *cdev, 148static ssize_t backlight_show_actual_brightness(struct class_device *cdev,
@@ -169,10 +151,10 @@ static ssize_t backlight_show_actual_brightness(struct class_device *cdev,
169 int rc = -ENXIO; 151 int rc = -ENXIO;
170 struct backlight_device *bd = to_backlight_device(cdev); 152 struct backlight_device *bd = to_backlight_device(cdev);
171 153
172 mutex_lock(&bd->props_lock); 154 mutex_lock(&bd->ops_lock);
173 if (bd->props && bd->props->get_brightness) 155 if (bd->ops && bd->ops->get_brightness)
174 rc = sprintf(buf, "%d\n", bd->props->get_brightness(bd)); 156 rc = sprintf(buf, "%d\n", bd->ops->get_brightness(bd));
175 mutex_unlock(&bd->props_lock); 157 mutex_unlock(&bd->ops_lock);
176 158
177 return rc; 159 return rc;
178} 160}
@@ -211,7 +193,7 @@ static const struct class_device_attribute bl_class_device_attributes[] = {
211 * respective framebuffer device). 193 * respective framebuffer device).
212 * @devdata: an optional pointer to be stored in the class_device. The 194 * @devdata: an optional pointer to be stored in the class_device. The
213 * methods may retrieve it by using class_get_devdata(&bd->class_dev). 195 * methods may retrieve it by using class_get_devdata(&bd->class_dev).
214 * @bp: the backlight properties structure. 196 * @ops: the backlight operations structure.
215 * 197 *
216 * Creates and registers new backlight class_device. Returns either an 198 * Creates and registers new backlight class_device. Returns either an
217 * ERR_PTR() or a pointer to the newly allocated device. 199 * ERR_PTR() or a pointer to the newly allocated device.
@@ -219,21 +201,20 @@ static const struct class_device_attribute bl_class_device_attributes[] = {
219struct backlight_device *backlight_device_register(const char *name, 201struct backlight_device *backlight_device_register(const char *name,
220 struct device *dev, 202 struct device *dev,
221 void *devdata, 203 void *devdata,
222 struct backlight_properties *bp) 204 struct backlight_ops *ops)
223{ 205{
224 int i, rc; 206 int i, rc;
225 struct backlight_device *new_bd; 207 struct backlight_device *new_bd;
226 208
227 pr_debug("backlight_device_alloc: name=%s\n", name); 209 pr_debug("backlight_device_alloc: name=%s\n", name);
228 210
229 new_bd = kmalloc(sizeof(struct backlight_device), GFP_KERNEL); 211 new_bd = kzalloc(sizeof(struct backlight_device), GFP_KERNEL);
230 if (!new_bd) 212 if (!new_bd)
231 return ERR_PTR(-ENOMEM); 213 return ERR_PTR(-ENOMEM);
232 214
233 mutex_init(&new_bd->update_lock); 215 mutex_init(&new_bd->update_lock);
234 mutex_init(&new_bd->props_lock); 216 mutex_init(&new_bd->ops_lock);
235 new_bd->props = bp; 217 new_bd->ops = ops;
236 memset(&new_bd->class_dev, 0, sizeof(new_bd->class_dev));
237 new_bd->class_dev.class = &backlight_class; 218 new_bd->class_dev.class = &backlight_class;
238 new_bd->class_dev.dev = dev; 219 new_bd->class_dev.dev = dev;
239 strlcpy(new_bd->class_dev.class_id, name, KOBJ_NAME_LEN); 220 strlcpy(new_bd->class_dev.class_id, name, KOBJ_NAME_LEN);
@@ -302,9 +283,9 @@ void backlight_device_unregister(struct backlight_device *bd)
302 class_device_remove_file(&bd->class_dev, 283 class_device_remove_file(&bd->class_dev,
303 &bl_class_device_attributes[i]); 284 &bl_class_device_attributes[i]);
304 285
305 mutex_lock(&bd->props_lock); 286 mutex_lock(&bd->ops_lock);
306 bd->props = NULL; 287 bd->ops = NULL;
307 mutex_unlock(&bd->props_lock); 288 mutex_unlock(&bd->ops_lock);
308 289
309 backlight_unregister_fb(bd); 290 backlight_unregister_fb(bd);
310 291