diff options
Diffstat (limited to 'drivers/video/backlight/lcd.c')
-rw-r--r-- | drivers/video/backlight/lcd.c | 112 |
1 files changed, 50 insertions, 62 deletions
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 | /* |