OneNAND: Write oob area with aligned size, mtd->oobsize
[deliverable/linux.git] / drivers / video / fbsysfs.c
CommitLineData
1da177e4
LT
1/*
2 * fbsysfs.c - framebuffer device class and attributes
3 *
4 * Copyright (c) 2004 James Simmons <jsimmons@infradead.org>
5 *
6 * This program is free software you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11
12/*
13 * Note: currently there's only stubs for framebuffer_alloc and
14 * framebuffer_release here. The reson for that is that until all drivers
15 * are converted to use it a sysfsification will open OOPSable races.
16 */
17
18#include <linux/kernel.h>
19#include <linux/fb.h>
20#include <linux/console.h>
21
22/**
23 * framebuffer_alloc - creates a new frame buffer info structure
24 *
25 * @size: size of driver private data, can be zero
26 * @dev: pointer to the device for this fb, this can be NULL
27 *
28 * Creates a new frame buffer info structure. Also reserves @size bytes
29 * for driver private data (info->par). info->par (if any) will be
30 * aligned to sizeof(long).
31 *
32 * Returns the new structure, or NULL if an error occured.
33 *
34 */
35struct fb_info *framebuffer_alloc(size_t size, struct device *dev)
36{
37#define BYTES_PER_LONG (BITS_PER_LONG/8)
38#define PADDING (BYTES_PER_LONG - (sizeof(struct fb_info) % BYTES_PER_LONG))
39 int fb_info_size = sizeof(struct fb_info);
40 struct fb_info *info;
41 char *p;
42
43 if (size)
44 fb_info_size += PADDING;
45
def1eded
AD
46 p = kzalloc(fb_info_size + size, GFP_KERNEL);
47
1da177e4
LT
48 if (!p)
49 return NULL;
def1eded 50
1da177e4
LT
51 info = (struct fb_info *) p;
52
53 if (size)
54 info->par = p + fb_info_size;
55
56 info->device = dev;
57
58 return info;
59#undef PADDING
60#undef BYTES_PER_LONG
61}
62EXPORT_SYMBOL(framebuffer_alloc);
63
64/**
65 * framebuffer_release - marks the structure available for freeing
66 *
67 * @info: frame buffer info structure
68 *
69 * Drop the reference count of the class_device embedded in the
70 * framebuffer info structure.
71 *
72 */
73void framebuffer_release(struct fb_info *info)
74{
75 kfree(info);
76}
77EXPORT_SYMBOL(framebuffer_release);
78
79static int activate(struct fb_info *fb_info, struct fb_var_screeninfo *var)
80{
81 int err;
82
83 var->activate |= FB_ACTIVATE_FORCE;
84 acquire_console_sem();
85 fb_info->flags |= FBINFO_MISC_USEREVENT;
86 err = fb_set_var(fb_info, var);
87 fb_info->flags &= ~FBINFO_MISC_USEREVENT;
88 release_console_sem();
89 if (err)
90 return err;
91 return 0;
92}
93
94static int mode_string(char *buf, unsigned int offset,
95 const struct fb_videomode *mode)
96{
97 char m = 'U';
98 if (mode->flag & FB_MODE_IS_DETAILED)
99 m = 'D';
100 if (mode->flag & FB_MODE_IS_VESA)
101 m = 'V';
102 if (mode->flag & FB_MODE_IS_STANDARD)
103 m = 'S';
104 return snprintf(&buf[offset], PAGE_SIZE - offset, "%c:%dx%d-%d\n", m, mode->xres, mode->yres, mode->refresh);
105}
106
107static ssize_t store_mode(struct class_device *class_device, const char * buf,
108 size_t count)
109{
313e58ab 110 struct fb_info *fb_info = class_get_devdata(class_device);
1da177e4
LT
111 char mstr[100];
112 struct fb_var_screeninfo var;
113 struct fb_modelist *modelist;
114 struct fb_videomode *mode;
115 struct list_head *pos;
116 size_t i;
117 int err;
118
119 memset(&var, 0, sizeof(var));
120
121 list_for_each(pos, &fb_info->modelist) {
122 modelist = list_entry(pos, struct fb_modelist, list);
123 mode = &modelist->mode;
124 i = mode_string(mstr, 0, mode);
125 if (strncmp(mstr, buf, max(count, i)) == 0) {
126
127 var = fb_info->var;
128 fb_videomode_to_var(&var, mode);
129 if ((err = activate(fb_info, &var)))
130 return err;
131 fb_info->mode = mode;
132 return count;
133 }
134 }
135 return -EINVAL;
136}
137
138static ssize_t show_mode(struct class_device *class_device, char *buf)
139{
313e58ab 140 struct fb_info *fb_info = class_get_devdata(class_device);
1da177e4
LT
141
142 if (!fb_info->mode)
143 return 0;
144
145 return mode_string(buf, 0, fb_info->mode);
146}
147
148static ssize_t store_modes(struct class_device *class_device, const char * buf,
149 size_t count)
150{
313e58ab 151 struct fb_info *fb_info = class_get_devdata(class_device);
1da177e4
LT
152 LIST_HEAD(old_list);
153 int i = count / sizeof(struct fb_videomode);
154
155 if (i * sizeof(struct fb_videomode) != count)
156 return -EINVAL;
157
158 acquire_console_sem();
159 list_splice(&fb_info->modelist, &old_list);
160 fb_videomode_to_modelist((struct fb_videomode *)buf, i,
161 &fb_info->modelist);
162 if (fb_new_modelist(fb_info)) {
163 fb_destroy_modelist(&fb_info->modelist);
164 list_splice(&old_list, &fb_info->modelist);
165 } else
166 fb_destroy_modelist(&old_list);
167
168 release_console_sem();
169
170 return 0;
171}
172
173static ssize_t show_modes(struct class_device *class_device, char *buf)
174{
313e58ab 175 struct fb_info *fb_info = class_get_devdata(class_device);
1da177e4
LT
176 unsigned int i;
177 struct list_head *pos;
178 struct fb_modelist *modelist;
179 const struct fb_videomode *mode;
180
181 i = 0;
182 list_for_each(pos, &fb_info->modelist) {
183 modelist = list_entry(pos, struct fb_modelist, list);
184 mode = &modelist->mode;
185 i += mode_string(buf, i, mode);
186 }
187 return i;
188}
189
190static ssize_t store_bpp(struct class_device *class_device, const char * buf,
191 size_t count)
192{
313e58ab 193 struct fb_info *fb_info = class_get_devdata(class_device);
1da177e4
LT
194 struct fb_var_screeninfo var;
195 char ** last = NULL;
196 int err;
197
198 var = fb_info->var;
199 var.bits_per_pixel = simple_strtoul(buf, last, 0);
200 if ((err = activate(fb_info, &var)))
201 return err;
202 return count;
203}
204
205static ssize_t show_bpp(struct class_device *class_device, char *buf)
206{
313e58ab 207 struct fb_info *fb_info = class_get_devdata(class_device);
1da177e4
LT
208 return snprintf(buf, PAGE_SIZE, "%d\n", fb_info->var.bits_per_pixel);
209}
210
a812c94b
AD
211static ssize_t store_rotate(struct class_device *class_device, const char *buf,
212 size_t count)
213{
214 struct fb_info *fb_info = class_get_devdata(class_device);
215 struct fb_var_screeninfo var;
216 char **last = NULL;
217 int err;
218
219 var = fb_info->var;
220 var.rotate = simple_strtoul(buf, last, 0);
221
222 if ((err = activate(fb_info, &var)))
223 return err;
224
225 return count;
226}
227
228
229static ssize_t show_rotate(struct class_device *class_device, char *buf)
230{
231 struct fb_info *fb_info = class_get_devdata(class_device);
232
233 return snprintf(buf, PAGE_SIZE, "%d\n", fb_info->var.rotate);
234}
235
236static ssize_t store_con_rotate(struct class_device *class_device,
237 const char *buf, size_t count)
238{
239 struct fb_info *fb_info = class_get_devdata(class_device);
240 int rotate;
241 char **last = NULL;
242
243 acquire_console_sem();
244 rotate = simple_strtoul(buf, last, 0);
245 fb_con_duit(fb_info, FB_EVENT_SET_CON_ROTATE, &rotate);
246 release_console_sem();
247 return count;
248}
249
250static ssize_t store_con_rotate_all(struct class_device *class_device,
251 const char *buf, size_t count)
252{
253 struct fb_info *fb_info = class_get_devdata(class_device);
254 int rotate;
255 char **last = NULL;
256
257 acquire_console_sem();
258 rotate = simple_strtoul(buf, last, 0);
259 fb_con_duit(fb_info, FB_EVENT_SET_CON_ROTATE_ALL, &rotate);
260 release_console_sem();
261 return count;
262}
263
264static ssize_t show_con_rotate(struct class_device *class_device, char *buf)
265{
266 struct fb_info *fb_info = class_get_devdata(class_device);
267 int rotate;
268
269 acquire_console_sem();
270 rotate = fb_con_duit(fb_info, FB_EVENT_GET_CON_ROTATE, NULL);
271 release_console_sem();
272 return snprintf(buf, PAGE_SIZE, "%d\n", rotate);
273}
274
1da177e4
LT
275static ssize_t store_virtual(struct class_device *class_device,
276 const char * buf, size_t count)
277{
313e58ab 278 struct fb_info *fb_info = class_get_devdata(class_device);
1da177e4
LT
279 struct fb_var_screeninfo var;
280 char *last = NULL;
281 int err;
282
283 var = fb_info->var;
284 var.xres_virtual = simple_strtoul(buf, &last, 0);
285 last++;
286 if (last - buf >= count)
287 return -EINVAL;
288 var.yres_virtual = simple_strtoul(last, &last, 0);
1da177e4
LT
289
290 if ((err = activate(fb_info, &var)))
291 return err;
292 return count;
293}
294
295static ssize_t show_virtual(struct class_device *class_device, char *buf)
296{
313e58ab 297 struct fb_info *fb_info = class_get_devdata(class_device);
1da177e4 298 return snprintf(buf, PAGE_SIZE, "%d,%d\n", fb_info->var.xres_virtual,
e2c16499 299 fb_info->var.yres_virtual);
1da177e4
LT
300}
301
c14e2cfc
JS
302static ssize_t show_stride(struct class_device *class_device, char *buf)
303{
313e58ab 304 struct fb_info *fb_info = class_get_devdata(class_device);
c14e2cfc
JS
305 return snprintf(buf, PAGE_SIZE, "%d\n", fb_info->fix.line_length);
306}
307
1da177e4
LT
308static ssize_t store_blank(struct class_device *class_device, const char * buf,
309 size_t count)
310{
313e58ab 311 struct fb_info *fb_info = class_get_devdata(class_device);
1da177e4
LT
312 char *last = NULL;
313 int err;
314
315 acquire_console_sem();
316 fb_info->flags |= FBINFO_MISC_USEREVENT;
317 err = fb_blank(fb_info, simple_strtoul(buf, &last, 0));
318 fb_info->flags &= ~FBINFO_MISC_USEREVENT;
319 release_console_sem();
320 if (err < 0)
321 return err;
322 return count;
323}
324
325static ssize_t show_blank(struct class_device *class_device, char *buf)
326{
313e58ab 327// struct fb_info *fb_info = class_get_devdata(class_device);
1da177e4
LT
328 return 0;
329}
330
331static ssize_t store_console(struct class_device *class_device,
332 const char * buf, size_t count)
333{
313e58ab 334// struct fb_info *fb_info = class_get_devdata(class_device);
1da177e4
LT
335 return 0;
336}
337
338static ssize_t show_console(struct class_device *class_device, char *buf)
339{
313e58ab 340// struct fb_info *fb_info = class_get_devdata(class_device);
1da177e4
LT
341 return 0;
342}
343
344static ssize_t store_cursor(struct class_device *class_device,
345 const char * buf, size_t count)
346{
313e58ab 347// struct fb_info *fb_info = class_get_devdata(class_device);
1da177e4
LT
348 return 0;
349}
350
351static ssize_t show_cursor(struct class_device *class_device, char *buf)
352{
313e58ab 353// struct fb_info *fb_info = class_get_devdata(class_device);
1da177e4
LT
354 return 0;
355}
356
357static ssize_t store_pan(struct class_device *class_device, const char * buf,
358 size_t count)
359{
313e58ab 360 struct fb_info *fb_info = class_get_devdata(class_device);
1da177e4
LT
361 struct fb_var_screeninfo var;
362 char *last = NULL;
363 int err;
364
365 var = fb_info->var;
366 var.xoffset = simple_strtoul(buf, &last, 0);
367 last++;
368 if (last - buf >= count)
369 return -EINVAL;
370 var.yoffset = simple_strtoul(last, &last, 0);
371
372 acquire_console_sem();
373 err = fb_pan_display(fb_info, &var);
374 release_console_sem();
375
376 if (err < 0)
377 return err;
378 return count;
379}
380
381static ssize_t show_pan(struct class_device *class_device, char *buf)
382{
313e58ab 383 struct fb_info *fb_info = class_get_devdata(class_device);
1da177e4
LT
384 return snprintf(buf, PAGE_SIZE, "%d,%d\n", fb_info->var.xoffset,
385 fb_info->var.xoffset);
386}
387
02459eaa
JS
388static ssize_t show_name(struct class_device *class_device, char *buf)
389{
313e58ab 390 struct fb_info *fb_info = class_get_devdata(class_device);
02459eaa
JS
391
392 return snprintf(buf, PAGE_SIZE, "%s\n", fb_info->fix.id);
393}
394
30420f8f
MG
395static ssize_t store_fbstate(struct class_device *class_device,
396 const char *buf, size_t count)
397{
398 struct fb_info *fb_info = class_get_devdata(class_device);
399 u32 state;
400 char *last = NULL;
401
402 state = simple_strtoul(buf, &last, 0);
403
404 acquire_console_sem();
405 fb_set_suspend(fb_info, (int)state);
406 release_console_sem();
407
408 return count;
409}
410
411static ssize_t show_fbstate(struct class_device *class_device, char *buf)
412{
413 struct fb_info *fb_info = class_get_devdata(class_device);
414 return snprintf(buf, PAGE_SIZE, "%d\n", fb_info->state);
415}
416
913e7ec5
JS
417/* When cmap is added back in it should be a binary attribute
418 * not a text one. Consideration should also be given to converting
419 * fbdev to use configfs instead of sysfs */
75c96f85 420static struct class_device_attribute class_device_attrs[] = {
1da177e4
LT
421 __ATTR(bits_per_pixel, S_IRUGO|S_IWUSR, show_bpp, store_bpp),
422 __ATTR(blank, S_IRUGO|S_IWUSR, show_blank, store_blank),
1da177e4
LT
423 __ATTR(console, S_IRUGO|S_IWUSR, show_console, store_console),
424 __ATTR(cursor, S_IRUGO|S_IWUSR, show_cursor, store_cursor),
425 __ATTR(mode, S_IRUGO|S_IWUSR, show_mode, store_mode),
426 __ATTR(modes, S_IRUGO|S_IWUSR, show_modes, store_modes),
427 __ATTR(pan, S_IRUGO|S_IWUSR, show_pan, store_pan),
428 __ATTR(virtual_size, S_IRUGO|S_IWUSR, show_virtual, store_virtual),
02459eaa 429 __ATTR(name, S_IRUGO, show_name, NULL),
c14e2cfc 430 __ATTR(stride, S_IRUGO, show_stride, NULL),
a812c94b
AD
431 __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
432 __ATTR(con_rotate, S_IRUGO|S_IWUSR, show_con_rotate, store_con_rotate),
433 __ATTR(con_rotate_all, S_IWUSR, NULL, store_con_rotate_all),
30420f8f 434 __ATTR(state, S_IRUGO|S_IWUSR, show_fbstate, store_fbstate),
1da177e4
LT
435};
436
437int fb_init_class_device(struct fb_info *fb_info)
438{
439 unsigned int i;
440 class_set_devdata(fb_info->class_device, fb_info);
441
442 for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++)
443 class_device_create_file(fb_info->class_device,
444 &class_device_attrs[i]);
445 return 0;
446}
447
448void fb_cleanup_class_device(struct fb_info *fb_info)
449{
450 unsigned int i;
451
452 for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++)
453 class_device_remove_file(fb_info->class_device,
454 &class_device_attrs[i]);
455}
456
457
This page took 0.24623 seconds and 5 git commands to generate.