Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 19 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/fb.h> |
| 21 | #include <linux/console.h> |
Michael Hanselmann | 5474c12 | 2006-06-25 05:47:08 -0700 | [diff] [blame] | 22 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
Antonino A. Daplas | 1a6600b | 2006-10-03 01:14:50 -0700 | [diff] [blame] | 24 | #define FB_SYSFS_FLAG_ATTR 1 |
| 25 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | /** |
| 27 | * framebuffer_alloc - creates a new frame buffer info structure |
| 28 | * |
| 29 | * @size: size of driver private data, can be zero |
| 30 | * @dev: pointer to the device for this fb, this can be NULL |
| 31 | * |
| 32 | * Creates a new frame buffer info structure. Also reserves @size bytes |
| 33 | * for driver private data (info->par). info->par (if any) will be |
| 34 | * aligned to sizeof(long). |
| 35 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 36 | * Returns the new structure, or NULL if an error occurred. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | * |
| 38 | */ |
| 39 | struct fb_info *framebuffer_alloc(size_t size, struct device *dev) |
| 40 | { |
| 41 | #define BYTES_PER_LONG (BITS_PER_LONG/8) |
| 42 | #define PADDING (BYTES_PER_LONG - (sizeof(struct fb_info) % BYTES_PER_LONG)) |
| 43 | int fb_info_size = sizeof(struct fb_info); |
| 44 | struct fb_info *info; |
| 45 | char *p; |
| 46 | |
| 47 | if (size) |
| 48 | fb_info_size += PADDING; |
| 49 | |
Antonino A. Daplas | def1ede | 2006-01-09 20:53:45 -0800 | [diff] [blame] | 50 | p = kzalloc(fb_info_size + size, GFP_KERNEL); |
| 51 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | if (!p) |
| 53 | return NULL; |
Antonino A. Daplas | def1ede | 2006-01-09 20:53:45 -0800 | [diff] [blame] | 54 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | info = (struct fb_info *) p; |
| 56 | |
| 57 | if (size) |
| 58 | info->par = p + fb_info_size; |
| 59 | |
| 60 | info->device = dev; |
| 61 | |
Michael Hanselmann | 5474c12 | 2006-06-25 05:47:08 -0700 | [diff] [blame] | 62 | #ifdef CONFIG_FB_BACKLIGHT |
Richard Purdie | 37ce69a | 2007-02-10 14:10:33 +0000 | [diff] [blame] | 63 | mutex_init(&info->bl_curve_mutex); |
Michael Hanselmann | 5474c12 | 2006-06-25 05:47:08 -0700 | [diff] [blame] | 64 | #endif |
| 65 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | return info; |
| 67 | #undef PADDING |
| 68 | #undef BYTES_PER_LONG |
| 69 | } |
| 70 | EXPORT_SYMBOL(framebuffer_alloc); |
| 71 | |
| 72 | /** |
| 73 | * framebuffer_release - marks the structure available for freeing |
| 74 | * |
| 75 | * @info: frame buffer info structure |
| 76 | * |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 77 | * Drop the reference count of the device embedded in the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | * framebuffer info structure. |
| 79 | * |
| 80 | */ |
| 81 | void framebuffer_release(struct fb_info *info) |
| 82 | { |
Dan Carpenter | cc44011 | 2012-05-14 23:58:37 +0300 | [diff] [blame] | 83 | if (!info) |
| 84 | return; |
Marcin Slusarz | 1471ca9 | 2010-05-16 17:27:03 +0200 | [diff] [blame] | 85 | kfree(info->apertures); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | kfree(info); |
| 87 | } |
| 88 | EXPORT_SYMBOL(framebuffer_release); |
| 89 | |
| 90 | static int activate(struct fb_info *fb_info, struct fb_var_screeninfo *var) |
| 91 | { |
| 92 | int err; |
| 93 | |
| 94 | var->activate |= FB_ACTIVATE_FORCE; |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 95 | console_lock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | fb_info->flags |= FBINFO_MISC_USEREVENT; |
| 97 | err = fb_set_var(fb_info, var); |
| 98 | fb_info->flags &= ~FBINFO_MISC_USEREVENT; |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 99 | console_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | if (err) |
| 101 | return err; |
| 102 | return 0; |
| 103 | } |
| 104 | |
| 105 | static int mode_string(char *buf, unsigned int offset, |
| 106 | const struct fb_videomode *mode) |
| 107 | { |
| 108 | char m = 'U'; |
Daniel R Thompson | 9dac73a | 2006-06-26 00:27:00 -0700 | [diff] [blame] | 109 | char v = 'p'; |
| 110 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | if (mode->flag & FB_MODE_IS_DETAILED) |
| 112 | m = 'D'; |
| 113 | if (mode->flag & FB_MODE_IS_VESA) |
| 114 | m = 'V'; |
| 115 | if (mode->flag & FB_MODE_IS_STANDARD) |
| 116 | m = 'S'; |
Daniel R Thompson | 9dac73a | 2006-06-26 00:27:00 -0700 | [diff] [blame] | 117 | |
| 118 | if (mode->vmode & FB_VMODE_INTERLACED) |
| 119 | v = 'i'; |
| 120 | if (mode->vmode & FB_VMODE_DOUBLE) |
| 121 | v = 'd'; |
| 122 | |
| 123 | return snprintf(&buf[offset], PAGE_SIZE - offset, "%c:%dx%d%c-%d\n", |
| 124 | m, mode->xres, mode->yres, v, mode->refresh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | } |
| 126 | |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 127 | static ssize_t store_mode(struct device *device, struct device_attribute *attr, |
| 128 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | { |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 130 | struct fb_info *fb_info = dev_get_drvdata(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | char mstr[100]; |
| 132 | struct fb_var_screeninfo var; |
| 133 | struct fb_modelist *modelist; |
| 134 | struct fb_videomode *mode; |
| 135 | struct list_head *pos; |
| 136 | size_t i; |
| 137 | int err; |
| 138 | |
| 139 | memset(&var, 0, sizeof(var)); |
| 140 | |
| 141 | list_for_each(pos, &fb_info->modelist) { |
| 142 | modelist = list_entry(pos, struct fb_modelist, list); |
| 143 | mode = &modelist->mode; |
| 144 | i = mode_string(mstr, 0, mode); |
| 145 | if (strncmp(mstr, buf, max(count, i)) == 0) { |
| 146 | |
| 147 | var = fb_info->var; |
| 148 | fb_videomode_to_var(&var, mode); |
| 149 | if ((err = activate(fb_info, &var))) |
| 150 | return err; |
| 151 | fb_info->mode = mode; |
| 152 | return count; |
| 153 | } |
| 154 | } |
| 155 | return -EINVAL; |
| 156 | } |
| 157 | |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 158 | static ssize_t show_mode(struct device *device, struct device_attribute *attr, |
| 159 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | { |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 161 | struct fb_info *fb_info = dev_get_drvdata(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | |
| 163 | if (!fb_info->mode) |
| 164 | return 0; |
| 165 | |
| 166 | return mode_string(buf, 0, fb_info->mode); |
| 167 | } |
| 168 | |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 169 | static ssize_t store_modes(struct device *device, |
| 170 | struct device_attribute *attr, |
| 171 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | { |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 173 | struct fb_info *fb_info = dev_get_drvdata(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | LIST_HEAD(old_list); |
| 175 | int i = count / sizeof(struct fb_videomode); |
| 176 | |
| 177 | if (i * sizeof(struct fb_videomode) != count) |
| 178 | return -EINVAL; |
| 179 | |
Alan Cox | 50e244c | 2013-01-25 10:28:15 +1000 | [diff] [blame^] | 180 | if (!lock_fb_info(fb_info)) |
| 181 | return -ENODEV; |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 182 | console_lock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | list_splice(&fb_info->modelist, &old_list); |
Geert Uytterhoeven | 9791d76 | 2007-02-12 00:55:19 -0800 | [diff] [blame] | 184 | fb_videomode_to_modelist((const struct fb_videomode *)buf, i, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | &fb_info->modelist); |
| 186 | if (fb_new_modelist(fb_info)) { |
| 187 | fb_destroy_modelist(&fb_info->modelist); |
| 188 | list_splice(&old_list, &fb_info->modelist); |
| 189 | } else |
| 190 | fb_destroy_modelist(&old_list); |
| 191 | |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 192 | console_unlock(); |
Alan Cox | 50e244c | 2013-01-25 10:28:15 +1000 | [diff] [blame^] | 193 | unlock_fb_info(fb_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | |
| 195 | return 0; |
| 196 | } |
| 197 | |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 198 | static ssize_t show_modes(struct device *device, struct device_attribute *attr, |
| 199 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | { |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 201 | struct fb_info *fb_info = dev_get_drvdata(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | unsigned int i; |
| 203 | struct list_head *pos; |
| 204 | struct fb_modelist *modelist; |
| 205 | const struct fb_videomode *mode; |
| 206 | |
| 207 | i = 0; |
| 208 | list_for_each(pos, &fb_info->modelist) { |
| 209 | modelist = list_entry(pos, struct fb_modelist, list); |
| 210 | mode = &modelist->mode; |
| 211 | i += mode_string(buf, i, mode); |
| 212 | } |
| 213 | return i; |
| 214 | } |
| 215 | |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 216 | static ssize_t store_bpp(struct device *device, struct device_attribute *attr, |
| 217 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | { |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 219 | struct fb_info *fb_info = dev_get_drvdata(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | struct fb_var_screeninfo var; |
| 221 | char ** last = NULL; |
| 222 | int err; |
| 223 | |
| 224 | var = fb_info->var; |
| 225 | var.bits_per_pixel = simple_strtoul(buf, last, 0); |
| 226 | if ((err = activate(fb_info, &var))) |
| 227 | return err; |
| 228 | return count; |
| 229 | } |
| 230 | |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 231 | static ssize_t show_bpp(struct device *device, struct device_attribute *attr, |
| 232 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | { |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 234 | struct fb_info *fb_info = dev_get_drvdata(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | return snprintf(buf, PAGE_SIZE, "%d\n", fb_info->var.bits_per_pixel); |
| 236 | } |
| 237 | |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 238 | static ssize_t store_rotate(struct device *device, |
| 239 | struct device_attribute *attr, |
| 240 | const char *buf, size_t count) |
Antonino A. Daplas | a812c94 | 2005-11-08 21:39:15 -0800 | [diff] [blame] | 241 | { |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 242 | struct fb_info *fb_info = dev_get_drvdata(device); |
Antonino A. Daplas | a812c94 | 2005-11-08 21:39:15 -0800 | [diff] [blame] | 243 | struct fb_var_screeninfo var; |
| 244 | char **last = NULL; |
| 245 | int err; |
| 246 | |
| 247 | var = fb_info->var; |
| 248 | var.rotate = simple_strtoul(buf, last, 0); |
| 249 | |
| 250 | if ((err = activate(fb_info, &var))) |
| 251 | return err; |
| 252 | |
| 253 | return count; |
| 254 | } |
| 255 | |
| 256 | |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 257 | static ssize_t show_rotate(struct device *device, |
| 258 | struct device_attribute *attr, char *buf) |
Antonino A. Daplas | a812c94 | 2005-11-08 21:39:15 -0800 | [diff] [blame] | 259 | { |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 260 | struct fb_info *fb_info = dev_get_drvdata(device); |
Antonino A. Daplas | a812c94 | 2005-11-08 21:39:15 -0800 | [diff] [blame] | 261 | |
| 262 | return snprintf(buf, PAGE_SIZE, "%d\n", fb_info->var.rotate); |
| 263 | } |
| 264 | |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 265 | static ssize_t store_virtual(struct device *device, |
| 266 | struct device_attribute *attr, |
| 267 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | { |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 269 | struct fb_info *fb_info = dev_get_drvdata(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | struct fb_var_screeninfo var; |
| 271 | char *last = NULL; |
| 272 | int err; |
| 273 | |
| 274 | var = fb_info->var; |
| 275 | var.xres_virtual = simple_strtoul(buf, &last, 0); |
| 276 | last++; |
| 277 | if (last - buf >= count) |
| 278 | return -EINVAL; |
| 279 | var.yres_virtual = simple_strtoul(last, &last, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | |
| 281 | if ((err = activate(fb_info, &var))) |
| 282 | return err; |
| 283 | return count; |
| 284 | } |
| 285 | |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 286 | static ssize_t show_virtual(struct device *device, |
| 287 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | { |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 289 | struct fb_info *fb_info = dev_get_drvdata(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | return snprintf(buf, PAGE_SIZE, "%d,%d\n", fb_info->var.xres_virtual, |
Jon Smirl | e2c1649 | 2005-06-13 15:52:36 -0700 | [diff] [blame] | 291 | fb_info->var.yres_virtual); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | } |
| 293 | |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 294 | static ssize_t show_stride(struct device *device, |
| 295 | struct device_attribute *attr, char *buf) |
James Simmons | c14e2cf | 2005-10-24 21:46:21 +0100 | [diff] [blame] | 296 | { |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 297 | struct fb_info *fb_info = dev_get_drvdata(device); |
James Simmons | c14e2cf | 2005-10-24 21:46:21 +0100 | [diff] [blame] | 298 | return snprintf(buf, PAGE_SIZE, "%d\n", fb_info->fix.line_length); |
| 299 | } |
| 300 | |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 301 | static ssize_t store_blank(struct device *device, |
| 302 | struct device_attribute *attr, |
| 303 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | { |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 305 | struct fb_info *fb_info = dev_get_drvdata(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | char *last = NULL; |
| 307 | int err; |
| 308 | |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 309 | console_lock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | fb_info->flags |= FBINFO_MISC_USEREVENT; |
| 311 | err = fb_blank(fb_info, simple_strtoul(buf, &last, 0)); |
| 312 | fb_info->flags &= ~FBINFO_MISC_USEREVENT; |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 313 | console_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | if (err < 0) |
| 315 | return err; |
| 316 | return count; |
| 317 | } |
| 318 | |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 319 | static ssize_t show_blank(struct device *device, |
| 320 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | { |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 322 | // struct fb_info *fb_info = dev_get_drvdata(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | return 0; |
| 324 | } |
| 325 | |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 326 | static ssize_t store_console(struct device *device, |
| 327 | struct device_attribute *attr, |
| 328 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | { |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 330 | // struct fb_info *fb_info = dev_get_drvdata(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | return 0; |
| 332 | } |
| 333 | |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 334 | static ssize_t show_console(struct device *device, |
| 335 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | { |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 337 | // struct fb_info *fb_info = dev_get_drvdata(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | return 0; |
| 339 | } |
| 340 | |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 341 | static ssize_t store_cursor(struct device *device, |
| 342 | struct device_attribute *attr, |
| 343 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | { |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 345 | // struct fb_info *fb_info = dev_get_drvdata(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | return 0; |
| 347 | } |
| 348 | |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 349 | static ssize_t show_cursor(struct device *device, |
| 350 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | { |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 352 | // struct fb_info *fb_info = dev_get_drvdata(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | return 0; |
| 354 | } |
| 355 | |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 356 | static ssize_t store_pan(struct device *device, |
| 357 | struct device_attribute *attr, |
| 358 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | { |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 360 | struct fb_info *fb_info = dev_get_drvdata(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 372 | console_lock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | err = fb_pan_display(fb_info, &var); |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 374 | console_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | |
| 376 | if (err < 0) |
| 377 | return err; |
| 378 | return count; |
| 379 | } |
| 380 | |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 381 | static ssize_t show_pan(struct device *device, |
| 382 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | { |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 384 | struct fb_info *fb_info = dev_get_drvdata(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | return snprintf(buf, PAGE_SIZE, "%d,%d\n", fb_info->var.xoffset, |
Antonino A. Daplas | c427063 | 2007-05-08 00:37:30 -0700 | [diff] [blame] | 386 | fb_info->var.yoffset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | } |
| 388 | |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 389 | static ssize_t show_name(struct device *device, |
| 390 | struct device_attribute *attr, char *buf) |
James Simmons | 02459ea | 2005-07-30 23:49:54 +0100 | [diff] [blame] | 391 | { |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 392 | struct fb_info *fb_info = dev_get_drvdata(device); |
James Simmons | 02459ea | 2005-07-30 23:49:54 +0100 | [diff] [blame] | 393 | |
| 394 | return snprintf(buf, PAGE_SIZE, "%s\n", fb_info->fix.id); |
| 395 | } |
| 396 | |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 397 | static ssize_t store_fbstate(struct device *device, |
| 398 | struct device_attribute *attr, |
| 399 | const char *buf, size_t count) |
Matthew Garrett | 30420f8 | 2006-01-09 20:53:01 -0800 | [diff] [blame] | 400 | { |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 401 | struct fb_info *fb_info = dev_get_drvdata(device); |
Matthew Garrett | 30420f8 | 2006-01-09 20:53:01 -0800 | [diff] [blame] | 402 | u32 state; |
| 403 | char *last = NULL; |
| 404 | |
| 405 | state = simple_strtoul(buf, &last, 0); |
| 406 | |
Herton Ronaldo Krzesinski | 9e769ff | 2011-06-17 19:02:39 +0000 | [diff] [blame] | 407 | if (!lock_fb_info(fb_info)) |
| 408 | return -ENODEV; |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 409 | console_lock(); |
Matthew Garrett | 30420f8 | 2006-01-09 20:53:01 -0800 | [diff] [blame] | 410 | fb_set_suspend(fb_info, (int)state); |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 411 | console_unlock(); |
Herton Ronaldo Krzesinski | 9e769ff | 2011-06-17 19:02:39 +0000 | [diff] [blame] | 412 | unlock_fb_info(fb_info); |
Matthew Garrett | 30420f8 | 2006-01-09 20:53:01 -0800 | [diff] [blame] | 413 | |
| 414 | return count; |
| 415 | } |
| 416 | |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 417 | static ssize_t show_fbstate(struct device *device, |
| 418 | struct device_attribute *attr, char *buf) |
Matthew Garrett | 30420f8 | 2006-01-09 20:53:01 -0800 | [diff] [blame] | 419 | { |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 420 | struct fb_info *fb_info = dev_get_drvdata(device); |
Matthew Garrett | 30420f8 | 2006-01-09 20:53:01 -0800 | [diff] [blame] | 421 | return snprintf(buf, PAGE_SIZE, "%d\n", fb_info->state); |
| 422 | } |
| 423 | |
Michael Hanselmann | 5474c12 | 2006-06-25 05:47:08 -0700 | [diff] [blame] | 424 | #ifdef CONFIG_FB_BACKLIGHT |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 425 | static ssize_t store_bl_curve(struct device *device, |
| 426 | struct device_attribute *attr, |
| 427 | const char *buf, size_t count) |
Michael Hanselmann | 5474c12 | 2006-06-25 05:47:08 -0700 | [diff] [blame] | 428 | { |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 429 | struct fb_info *fb_info = dev_get_drvdata(device); |
Michael Hanselmann | 5474c12 | 2006-06-25 05:47:08 -0700 | [diff] [blame] | 430 | u8 tmp_curve[FB_BACKLIGHT_LEVELS]; |
| 431 | unsigned int i; |
| 432 | |
Michael Hanselmann | 25981de | 2006-09-25 16:25:07 -0700 | [diff] [blame] | 433 | /* Some drivers don't use framebuffer_alloc(), but those also |
| 434 | * don't have backlights. |
| 435 | */ |
| 436 | if (!fb_info || !fb_info->bl_dev) |
| 437 | return -ENODEV; |
| 438 | |
Michael Hanselmann | 5474c12 | 2006-06-25 05:47:08 -0700 | [diff] [blame] | 439 | if (count != (FB_BACKLIGHT_LEVELS / 8 * 24)) |
| 440 | return -EINVAL; |
| 441 | |
| 442 | for (i = 0; i < (FB_BACKLIGHT_LEVELS / 8); ++i) |
| 443 | if (sscanf(&buf[i * 24], |
| 444 | "%2hhx %2hhx %2hhx %2hhx %2hhx %2hhx %2hhx %2hhx\n", |
| 445 | &tmp_curve[i * 8 + 0], |
| 446 | &tmp_curve[i * 8 + 1], |
| 447 | &tmp_curve[i * 8 + 2], |
| 448 | &tmp_curve[i * 8 + 3], |
| 449 | &tmp_curve[i * 8 + 4], |
| 450 | &tmp_curve[i * 8 + 5], |
| 451 | &tmp_curve[i * 8 + 6], |
| 452 | &tmp_curve[i * 8 + 7]) != 8) |
| 453 | return -EINVAL; |
| 454 | |
| 455 | /* If there has been an error in the input data, we won't |
| 456 | * reach this loop. |
| 457 | */ |
Richard Purdie | 37ce69a | 2007-02-10 14:10:33 +0000 | [diff] [blame] | 458 | mutex_lock(&fb_info->bl_curve_mutex); |
Michael Hanselmann | 5474c12 | 2006-06-25 05:47:08 -0700 | [diff] [blame] | 459 | for (i = 0; i < FB_BACKLIGHT_LEVELS; ++i) |
| 460 | fb_info->bl_curve[i] = tmp_curve[i]; |
Richard Purdie | 37ce69a | 2007-02-10 14:10:33 +0000 | [diff] [blame] | 461 | mutex_unlock(&fb_info->bl_curve_mutex); |
Michael Hanselmann | 5474c12 | 2006-06-25 05:47:08 -0700 | [diff] [blame] | 462 | |
| 463 | return count; |
| 464 | } |
| 465 | |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 466 | static ssize_t show_bl_curve(struct device *device, |
| 467 | struct device_attribute *attr, char *buf) |
Michael Hanselmann | 5474c12 | 2006-06-25 05:47:08 -0700 | [diff] [blame] | 468 | { |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 469 | struct fb_info *fb_info = dev_get_drvdata(device); |
Michael Hanselmann | 5474c12 | 2006-06-25 05:47:08 -0700 | [diff] [blame] | 470 | ssize_t len = 0; |
| 471 | unsigned int i; |
| 472 | |
Michael Hanselmann | 25981de | 2006-09-25 16:25:07 -0700 | [diff] [blame] | 473 | /* Some drivers don't use framebuffer_alloc(), but those also |
| 474 | * don't have backlights. |
| 475 | */ |
| 476 | if (!fb_info || !fb_info->bl_dev) |
| 477 | return -ENODEV; |
| 478 | |
Richard Purdie | 37ce69a | 2007-02-10 14:10:33 +0000 | [diff] [blame] | 479 | mutex_lock(&fb_info->bl_curve_mutex); |
Michael Hanselmann | 5474c12 | 2006-06-25 05:47:08 -0700 | [diff] [blame] | 480 | for (i = 0; i < FB_BACKLIGHT_LEVELS; i += 8) |
| 481 | len += snprintf(&buf[len], PAGE_SIZE, |
| 482 | "%02x %02x %02x %02x %02x %02x %02x %02x\n", |
| 483 | fb_info->bl_curve[i + 0], |
| 484 | fb_info->bl_curve[i + 1], |
| 485 | fb_info->bl_curve[i + 2], |
| 486 | fb_info->bl_curve[i + 3], |
| 487 | fb_info->bl_curve[i + 4], |
| 488 | fb_info->bl_curve[i + 5], |
| 489 | fb_info->bl_curve[i + 6], |
| 490 | fb_info->bl_curve[i + 7]); |
Richard Purdie | 37ce69a | 2007-02-10 14:10:33 +0000 | [diff] [blame] | 491 | mutex_unlock(&fb_info->bl_curve_mutex); |
Michael Hanselmann | 5474c12 | 2006-06-25 05:47:08 -0700 | [diff] [blame] | 492 | |
| 493 | return len; |
| 494 | } |
| 495 | #endif |
| 496 | |
Jon Smirl | 913e7ec5 | 2006-04-12 19:43:35 -0400 | [diff] [blame] | 497 | /* When cmap is added back in it should be a binary attribute |
| 498 | * not a text one. Consideration should also be given to converting |
| 499 | * fbdev to use configfs instead of sysfs */ |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 500 | static struct device_attribute device_attrs[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | __ATTR(bits_per_pixel, S_IRUGO|S_IWUSR, show_bpp, store_bpp), |
| 502 | __ATTR(blank, S_IRUGO|S_IWUSR, show_blank, store_blank), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | __ATTR(console, S_IRUGO|S_IWUSR, show_console, store_console), |
| 504 | __ATTR(cursor, S_IRUGO|S_IWUSR, show_cursor, store_cursor), |
| 505 | __ATTR(mode, S_IRUGO|S_IWUSR, show_mode, store_mode), |
| 506 | __ATTR(modes, S_IRUGO|S_IWUSR, show_modes, store_modes), |
| 507 | __ATTR(pan, S_IRUGO|S_IWUSR, show_pan, store_pan), |
| 508 | __ATTR(virtual_size, S_IRUGO|S_IWUSR, show_virtual, store_virtual), |
James Simmons | 02459ea | 2005-07-30 23:49:54 +0100 | [diff] [blame] | 509 | __ATTR(name, S_IRUGO, show_name, NULL), |
James Simmons | c14e2cf | 2005-10-24 21:46:21 +0100 | [diff] [blame] | 510 | __ATTR(stride, S_IRUGO, show_stride, NULL), |
Antonino A. Daplas | a812c94 | 2005-11-08 21:39:15 -0800 | [diff] [blame] | 511 | __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate), |
Matthew Garrett | 30420f8 | 2006-01-09 20:53:01 -0800 | [diff] [blame] | 512 | __ATTR(state, S_IRUGO|S_IWUSR, show_fbstate, store_fbstate), |
Michael Hanselmann | 5474c12 | 2006-06-25 05:47:08 -0700 | [diff] [blame] | 513 | #ifdef CONFIG_FB_BACKLIGHT |
| 514 | __ATTR(bl_curve, S_IRUGO|S_IWUSR, show_bl_curve, store_bl_curve), |
| 515 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | }; |
| 517 | |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 518 | int fb_init_device(struct fb_info *fb_info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | { |
Antonino A. Daplas | 1a6600b | 2006-10-03 01:14:50 -0700 | [diff] [blame] | 520 | int i, error = 0; |
| 521 | |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 522 | dev_set_drvdata(fb_info->dev, fb_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | |
Antonino A. Daplas | 1a6600b | 2006-10-03 01:14:50 -0700 | [diff] [blame] | 524 | fb_info->class_flag |= FB_SYSFS_FLAG_ATTR; |
| 525 | |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 526 | for (i = 0; i < ARRAY_SIZE(device_attrs); i++) { |
| 527 | error = device_create_file(fb_info->dev, &device_attrs[i]); |
Antonino A. Daplas | 1a6600b | 2006-10-03 01:14:50 -0700 | [diff] [blame] | 528 | |
| 529 | if (error) |
| 530 | break; |
| 531 | } |
| 532 | |
| 533 | if (error) { |
| 534 | while (--i >= 0) |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 535 | device_remove_file(fb_info->dev, &device_attrs[i]); |
Antonino A. Daplas | 1a6600b | 2006-10-03 01:14:50 -0700 | [diff] [blame] | 536 | fb_info->class_flag &= ~FB_SYSFS_FLAG_ATTR; |
| 537 | } |
| 538 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | return 0; |
| 540 | } |
| 541 | |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 542 | void fb_cleanup_device(struct fb_info *fb_info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | { |
| 544 | unsigned int i; |
| 545 | |
Antonino A. Daplas | 1a6600b | 2006-10-03 01:14:50 -0700 | [diff] [blame] | 546 | if (fb_info->class_flag & FB_SYSFS_FLAG_ATTR) { |
Greg Kroah-Hartman | 78cde0887 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 547 | for (i = 0; i < ARRAY_SIZE(device_attrs); i++) |
| 548 | device_remove_file(fb_info->dev, &device_attrs[i]); |
Antonino A. Daplas | 1a6600b | 2006-10-03 01:14:50 -0700 | [diff] [blame] | 549 | |
| 550 | fb_info->class_flag &= ~FB_SYSFS_FLAG_ATTR; |
| 551 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | } |
| 553 | |
Michael Hanselmann | 5474c12 | 2006-06-25 05:47:08 -0700 | [diff] [blame] | 554 | #ifdef CONFIG_FB_BACKLIGHT |
| 555 | /* This function generates a linear backlight curve |
| 556 | * |
| 557 | * 0: off |
| 558 | * 1-7: min |
| 559 | * 8-127: linear from min to max |
| 560 | */ |
| 561 | void fb_bl_default_curve(struct fb_info *fb_info, u8 off, u8 min, u8 max) |
| 562 | { |
| 563 | unsigned int i, flat, count, range = (max - min); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | |
Richard Purdie | 37ce69a | 2007-02-10 14:10:33 +0000 | [diff] [blame] | 565 | mutex_lock(&fb_info->bl_curve_mutex); |
| 566 | |
Michael Hanselmann | 5474c12 | 2006-06-25 05:47:08 -0700 | [diff] [blame] | 567 | fb_info->bl_curve[0] = off; |
| 568 | |
| 569 | for (flat = 1; flat < (FB_BACKLIGHT_LEVELS / 16); ++flat) |
| 570 | fb_info->bl_curve[flat] = min; |
| 571 | |
| 572 | count = FB_BACKLIGHT_LEVELS * 15 / 16; |
| 573 | for (i = 0; i < count; ++i) |
| 574 | fb_info->bl_curve[flat + i] = min + (range * (i + 1) / count); |
Richard Purdie | 37ce69a | 2007-02-10 14:10:33 +0000 | [diff] [blame] | 575 | |
| 576 | mutex_unlock(&fb_info->bl_curve_mutex); |
Michael Hanselmann | 5474c12 | 2006-06-25 05:47:08 -0700 | [diff] [blame] | 577 | } |
| 578 | EXPORT_SYMBOL_GPL(fb_bl_default_curve); |
| 579 | #endif |