2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* fbsysfs.c - framebuffer device class and attributes
|
|
|
|
*
|
|
|
|
* Copyright (c) 2004 James Simmons <jsimmons@infradead.org>
|
|
|
|
*
|
|
|
|
* This program is free software you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version
|
|
|
|
* 2 of the License, or (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Note: currently there's only stubs for framebuffer_alloc and
|
|
|
|
* framebuffer_release here. The reson for that is that until all drivers
|
|
|
|
* are converted to use it a sysfsification will open OOPSable races.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 02:04:11 -06:00
|
|
|
#include <linux/slab.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
#include <linux/fb.h>
|
|
|
|
#include <linux/console.h>
|
2006-06-25 06:47:08 -06:00
|
|
|
#include <linux/module.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2006-10-03 02:14:50 -06:00
|
|
|
#define FB_SYSFS_FLAG_ATTR 1
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
/**
|
|
|
|
* framebuffer_alloc - creates a new frame buffer info structure
|
|
|
|
*
|
|
|
|
* @size: size of driver private data, can be zero
|
|
|
|
* @dev: pointer to the device for this fb, this can be NULL
|
|
|
|
*
|
|
|
|
* Creates a new frame buffer info structure. Also reserves @size bytes
|
|
|
|
* for driver private data (info->par). info->par (if any) will be
|
|
|
|
* aligned to sizeof(long).
|
|
|
|
*
|
|
|
|
* Returns the new structure, or NULL if an error occured.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
struct fb_info *framebuffer_alloc(size_t size, struct device *dev)
|
|
|
|
{
|
|
|
|
#define BYTES_PER_LONG (BITS_PER_LONG/8)
|
|
|
|
#define PADDING (BYTES_PER_LONG - (sizeof(struct fb_info) % BYTES_PER_LONG))
|
|
|
|
int fb_info_size = sizeof(struct fb_info);
|
|
|
|
struct fb_info *info;
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
if (size)
|
|
|
|
fb_info_size += PADDING;
|
|
|
|
|
2006-01-09 21:53:45 -07:00
|
|
|
p = kzalloc(fb_info_size + size, GFP_KERNEL);
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
if (!p)
|
|
|
|
return NULL;
|
2006-01-09 21:53:45 -07:00
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
info = (struct fb_info *) p;
|
|
|
|
|
|
|
|
if (size)
|
|
|
|
info->par = p + fb_info_size;
|
|
|
|
|
|
|
|
info->device = dev;
|
|
|
|
|
2006-06-25 06:47:08 -06:00
|
|
|
#ifdef CONFIG_FB_BACKLIGHT
|
2007-02-10 07:10:33 -07:00
|
|
|
mutex_init(&info->bl_curve_mutex);
|
2006-06-25 06:47:08 -06:00
|
|
|
#endif
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
return info;
|
|
|
|
#undef PADDING
|
|
|
|
#undef BYTES_PER_LONG
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(framebuffer_alloc);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* framebuffer_release - marks the structure available for freeing
|
|
|
|
*
|
|
|
|
* @info: frame buffer info structure
|
|
|
|
*
|
2006-09-14 08:30:59 -06:00
|
|
|
* Drop the reference count of the device embedded in the
|
2005-04-16 16:20:36 -06:00
|
|
|
* framebuffer info structure.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void framebuffer_release(struct fb_info *info)
|
|
|
|
{
|
2010-05-16 09:27:03 -06:00
|
|
|
kfree(info->apertures);
|
2005-04-16 16:20:36 -06:00
|
|
|
kfree(info);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(framebuffer_release);
|
|
|
|
|
|
|
|
static int activate(struct fb_info *fb_info, struct fb_var_screeninfo *var)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
var->activate |= FB_ACTIVATE_FORCE;
|
2011-01-25 16:07:35 -07:00
|
|
|
console_lock();
|
2005-04-16 16:20:36 -06:00
|
|
|
fb_info->flags |= FBINFO_MISC_USEREVENT;
|
|
|
|
err = fb_set_var(fb_info, var);
|
|
|
|
fb_info->flags &= ~FBINFO_MISC_USEREVENT;
|
2011-01-25 16:07:35 -07:00
|
|
|
console_unlock();
|
2005-04-16 16:20:36 -06:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mode_string(char *buf, unsigned int offset,
|
|
|
|
const struct fb_videomode *mode)
|
|
|
|
{
|
|
|
|
char m = 'U';
|
2006-06-26 01:27:00 -06:00
|
|
|
char v = 'p';
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
if (mode->flag & FB_MODE_IS_DETAILED)
|
|
|
|
m = 'D';
|
|
|
|
if (mode->flag & FB_MODE_IS_VESA)
|
|
|
|
m = 'V';
|
|
|
|
if (mode->flag & FB_MODE_IS_STANDARD)
|
|
|
|
m = 'S';
|
2006-06-26 01:27:00 -06:00
|
|
|
|
|
|
|
if (mode->vmode & FB_VMODE_INTERLACED)
|
|
|
|
v = 'i';
|
|
|
|
if (mode->vmode & FB_VMODE_DOUBLE)
|
|
|
|
v = 'd';
|
|
|
|
|
|
|
|
return snprintf(&buf[offset], PAGE_SIZE - offset, "%c:%dx%d%c-%d\n",
|
|
|
|
m, mode->xres, mode->yres, v, mode->refresh);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2006-09-14 08:30:59 -06:00
|
|
|
static ssize_t store_mode(struct device *device, struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2006-09-14 08:30:59 -06:00
|
|
|
struct fb_info *fb_info = dev_get_drvdata(device);
|
2005-04-16 16:20:36 -06:00
|
|
|
char mstr[100];
|
|
|
|
struct fb_var_screeninfo var;
|
|
|
|
struct fb_modelist *modelist;
|
|
|
|
struct fb_videomode *mode;
|
|
|
|
struct list_head *pos;
|
|
|
|
size_t i;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
memset(&var, 0, sizeof(var));
|
|
|
|
|
|
|
|
list_for_each(pos, &fb_info->modelist) {
|
|
|
|
modelist = list_entry(pos, struct fb_modelist, list);
|
|
|
|
mode = &modelist->mode;
|
|
|
|
i = mode_string(mstr, 0, mode);
|
|
|
|
if (strncmp(mstr, buf, max(count, i)) == 0) {
|
|
|
|
|
|
|
|
var = fb_info->var;
|
|
|
|
fb_videomode_to_var(&var, mode);
|
|
|
|
if ((err = activate(fb_info, &var)))
|
|
|
|
return err;
|
|
|
|
fb_info->mode = mode;
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2006-09-14 08:30:59 -06:00
|
|
|
static ssize_t show_mode(struct device *device, struct device_attribute *attr,
|
|
|
|
char *buf)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2006-09-14 08:30:59 -06:00
|
|
|
struct fb_info *fb_info = dev_get_drvdata(device);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
if (!fb_info->mode)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return mode_string(buf, 0, fb_info->mode);
|
|
|
|
}
|
|
|
|
|
2006-09-14 08:30:59 -06:00
|
|
|
static ssize_t store_modes(struct device *device,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2006-09-14 08:30:59 -06:00
|
|
|
struct fb_info *fb_info = dev_get_drvdata(device);
|
2005-04-16 16:20:36 -06:00
|
|
|
LIST_HEAD(old_list);
|
|
|
|
int i = count / sizeof(struct fb_videomode);
|
|
|
|
|
|
|
|
if (i * sizeof(struct fb_videomode) != count)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2011-01-25 16:07:35 -07:00
|
|
|
console_lock();
|
2005-04-16 16:20:36 -06:00
|
|
|
list_splice(&fb_info->modelist, &old_list);
|
2007-02-12 01:55:19 -07:00
|
|
|
fb_videomode_to_modelist((const struct fb_videomode *)buf, i,
|
2005-04-16 16:20:36 -06:00
|
|
|
&fb_info->modelist);
|
|
|
|
if (fb_new_modelist(fb_info)) {
|
|
|
|
fb_destroy_modelist(&fb_info->modelist);
|
|
|
|
list_splice(&old_list, &fb_info->modelist);
|
|
|
|
} else
|
|
|
|
fb_destroy_modelist(&old_list);
|
|
|
|
|
2011-01-25 16:07:35 -07:00
|
|
|
console_unlock();
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-09-14 08:30:59 -06:00
|
|
|
static ssize_t show_modes(struct device *device, struct device_attribute *attr,
|
|
|
|
char *buf)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2006-09-14 08:30:59 -06:00
|
|
|
struct fb_info *fb_info = dev_get_drvdata(device);
|
2005-04-16 16:20:36 -06:00
|
|
|
unsigned int i;
|
|
|
|
struct list_head *pos;
|
|
|
|
struct fb_modelist *modelist;
|
|
|
|
const struct fb_videomode *mode;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
list_for_each(pos, &fb_info->modelist) {
|
|
|
|
modelist = list_entry(pos, struct fb_modelist, list);
|
|
|
|
mode = &modelist->mode;
|
|
|
|
i += mode_string(buf, i, mode);
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2006-09-14 08:30:59 -06:00
|
|
|
static ssize_t store_bpp(struct device *device, struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2006-09-14 08:30:59 -06:00
|
|
|
struct fb_info *fb_info = dev_get_drvdata(device);
|
2005-04-16 16:20:36 -06:00
|
|
|
struct fb_var_screeninfo var;
|
|
|
|
char ** last = NULL;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
var = fb_info->var;
|
|
|
|
var.bits_per_pixel = simple_strtoul(buf, last, 0);
|
|
|
|
if ((err = activate(fb_info, &var)))
|
|
|
|
return err;
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2006-09-14 08:30:59 -06:00
|
|
|
static ssize_t show_bpp(struct device *device, struct device_attribute *attr,
|
|
|
|
char *buf)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2006-09-14 08:30:59 -06:00
|
|
|
struct fb_info *fb_info = dev_get_drvdata(device);
|
2005-04-16 16:20:36 -06:00
|
|
|
return snprintf(buf, PAGE_SIZE, "%d\n", fb_info->var.bits_per_pixel);
|
|
|
|
}
|
|
|
|
|
2006-09-14 08:30:59 -06:00
|
|
|
static ssize_t store_rotate(struct device *device,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
2005-11-08 22:39:15 -07:00
|
|
|
{
|
2006-09-14 08:30:59 -06:00
|
|
|
struct fb_info *fb_info = dev_get_drvdata(device);
|
2005-11-08 22:39:15 -07:00
|
|
|
struct fb_var_screeninfo var;
|
|
|
|
char **last = NULL;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
var = fb_info->var;
|
|
|
|
var.rotate = simple_strtoul(buf, last, 0);
|
|
|
|
|
|
|
|
if ((err = activate(fb_info, &var)))
|
|
|
|
return err;
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-14 08:30:59 -06:00
|
|
|
static ssize_t show_rotate(struct device *device,
|
|
|
|
struct device_attribute *attr, char *buf)
|
2005-11-08 22:39:15 -07:00
|
|
|
{
|
2006-09-14 08:30:59 -06:00
|
|
|
struct fb_info *fb_info = dev_get_drvdata(device);
|
2005-11-08 22:39:15 -07:00
|
|
|
|
|
|
|
return snprintf(buf, PAGE_SIZE, "%d\n", fb_info->var.rotate);
|
|
|
|
}
|
|
|
|
|
2006-09-14 08:30:59 -06:00
|
|
|
static ssize_t store_virtual(struct device *device,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2006-09-14 08:30:59 -06:00
|
|
|
struct fb_info *fb_info = dev_get_drvdata(device);
|
2005-04-16 16:20:36 -06:00
|
|
|
struct fb_var_screeninfo var;
|
|
|
|
char *last = NULL;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
var = fb_info->var;
|
|
|
|
var.xres_virtual = simple_strtoul(buf, &last, 0);
|
|
|
|
last++;
|
|
|
|
if (last - buf >= count)
|
|
|
|
return -EINVAL;
|
|
|
|
var.yres_virtual = simple_strtoul(last, &last, 0);
|
|
|
|
|
|
|
|
if ((err = activate(fb_info, &var)))
|
|
|
|
return err;
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2006-09-14 08:30:59 -06:00
|
|
|
static ssize_t show_virtual(struct device *device,
|
|
|
|
struct device_attribute *attr, char *buf)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2006-09-14 08:30:59 -06:00
|
|
|
struct fb_info *fb_info = dev_get_drvdata(device);
|
2005-04-16 16:20:36 -06:00
|
|
|
return snprintf(buf, PAGE_SIZE, "%d,%d\n", fb_info->var.xres_virtual,
|
2005-06-13 16:52:36 -06:00
|
|
|
fb_info->var.yres_virtual);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2006-09-14 08:30:59 -06:00
|
|
|
static ssize_t show_stride(struct device *device,
|
|
|
|
struct device_attribute *attr, char *buf)
|
2005-10-24 14:46:21 -06:00
|
|
|
{
|
2006-09-14 08:30:59 -06:00
|
|
|
struct fb_info *fb_info = dev_get_drvdata(device);
|
2005-10-24 14:46:21 -06:00
|
|
|
return snprintf(buf, PAGE_SIZE, "%d\n", fb_info->fix.line_length);
|
|
|
|
}
|
|
|
|
|
2006-09-14 08:30:59 -06:00
|
|
|
static ssize_t store_blank(struct device *device,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2006-09-14 08:30:59 -06:00
|
|
|
struct fb_info *fb_info = dev_get_drvdata(device);
|
2005-04-16 16:20:36 -06:00
|
|
|
char *last = NULL;
|
|
|
|
int err;
|
|
|
|
|
2011-01-25 16:07:35 -07:00
|
|
|
console_lock();
|
2005-04-16 16:20:36 -06:00
|
|
|
fb_info->flags |= FBINFO_MISC_USEREVENT;
|
|
|
|
err = fb_blank(fb_info, simple_strtoul(buf, &last, 0));
|
|
|
|
fb_info->flags &= ~FBINFO_MISC_USEREVENT;
|
2011-01-25 16:07:35 -07:00
|
|
|
console_unlock();
|
2005-04-16 16:20:36 -06:00
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2006-09-14 08:30:59 -06:00
|
|
|
static ssize_t show_blank(struct device *device,
|
|
|
|
struct device_attribute *attr, char *buf)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2006-09-14 08:30:59 -06:00
|
|
|
// struct fb_info *fb_info = dev_get_drvdata(device);
|
2005-04-16 16:20:36 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-09-14 08:30:59 -06:00
|
|
|
static ssize_t store_console(struct device *device,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2006-09-14 08:30:59 -06:00
|
|
|
// struct fb_info *fb_info = dev_get_drvdata(device);
|
2005-04-16 16:20:36 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-09-14 08:30:59 -06:00
|
|
|
static ssize_t show_console(struct device *device,
|
|
|
|
struct device_attribute *attr, char *buf)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2006-09-14 08:30:59 -06:00
|
|
|
// struct fb_info *fb_info = dev_get_drvdata(device);
|
2005-04-16 16:20:36 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-09-14 08:30:59 -06:00
|
|
|
static ssize_t store_cursor(struct device *device,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2006-09-14 08:30:59 -06:00
|
|
|
// struct fb_info *fb_info = dev_get_drvdata(device);
|
2005-04-16 16:20:36 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-09-14 08:30:59 -06:00
|
|
|
static ssize_t show_cursor(struct device *device,
|
|
|
|
struct device_attribute *attr, char *buf)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2006-09-14 08:30:59 -06:00
|
|
|
// struct fb_info *fb_info = dev_get_drvdata(device);
|
2005-04-16 16:20:36 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-09-14 08:30:59 -06:00
|
|
|
static ssize_t store_pan(struct device *device,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2006-09-14 08:30:59 -06:00
|
|
|
struct fb_info *fb_info = dev_get_drvdata(device);
|
2005-04-16 16:20:36 -06:00
|
|
|
struct fb_var_screeninfo var;
|
|
|
|
char *last = NULL;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
var = fb_info->var;
|
|
|
|
var.xoffset = simple_strtoul(buf, &last, 0);
|
|
|
|
last++;
|
|
|
|
if (last - buf >= count)
|
|
|
|
return -EINVAL;
|
|
|
|
var.yoffset = simple_strtoul(last, &last, 0);
|
|
|
|
|
2011-01-25 16:07:35 -07:00
|
|
|
console_lock();
|
2005-04-16 16:20:36 -06:00
|
|
|
err = fb_pan_display(fb_info, &var);
|
2011-01-25 16:07:35 -07:00
|
|
|
console_unlock();
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2006-09-14 08:30:59 -06:00
|
|
|
static ssize_t show_pan(struct device *device,
|
|
|
|
struct device_attribute *attr, char *buf)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2006-09-14 08:30:59 -06:00
|
|
|
struct fb_info *fb_info = dev_get_drvdata(device);
|
2005-04-16 16:20:36 -06:00
|
|
|
return snprintf(buf, PAGE_SIZE, "%d,%d\n", fb_info->var.xoffset,
|
2007-05-08 01:37:30 -06:00
|
|
|
fb_info->var.yoffset);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2006-09-14 08:30:59 -06:00
|
|
|
static ssize_t show_name(struct device *device,
|
|
|
|
struct device_attribute *attr, char *buf)
|
2005-07-30 16:49:54 -06:00
|
|
|
{
|
2006-09-14 08:30:59 -06:00
|
|
|
struct fb_info *fb_info = dev_get_drvdata(device);
|
2005-07-30 16:49:54 -06:00
|
|
|
|
|
|
|
return snprintf(buf, PAGE_SIZE, "%s\n", fb_info->fix.id);
|
|
|
|
}
|
|
|
|
|
2006-09-14 08:30:59 -06:00
|
|
|
static ssize_t store_fbstate(struct device *device,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
2006-01-09 21:53:01 -07:00
|
|
|
{
|
2006-09-14 08:30:59 -06:00
|
|
|
struct fb_info *fb_info = dev_get_drvdata(device);
|
2006-01-09 21:53:01 -07:00
|
|
|
u32 state;
|
|
|
|
char *last = NULL;
|
|
|
|
|
|
|
|
state = simple_strtoul(buf, &last, 0);
|
|
|
|
|
2011-01-25 16:07:35 -07:00
|
|
|
console_lock();
|
2006-01-09 21:53:01 -07:00
|
|
|
fb_set_suspend(fb_info, (int)state);
|
2011-01-25 16:07:35 -07:00
|
|
|
console_unlock();
|
2006-01-09 21:53:01 -07:00
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2006-09-14 08:30:59 -06:00
|
|
|
static ssize_t show_fbstate(struct device *device,
|
|
|
|
struct device_attribute *attr, char *buf)
|
2006-01-09 21:53:01 -07:00
|
|
|
{
|
2006-09-14 08:30:59 -06:00
|
|
|
struct fb_info *fb_info = dev_get_drvdata(device);
|
2006-01-09 21:53:01 -07:00
|
|
|
return snprintf(buf, PAGE_SIZE, "%d\n", fb_info->state);
|
|
|
|
}
|
|
|
|
|
2006-06-25 06:47:08 -06:00
|
|
|
#ifdef CONFIG_FB_BACKLIGHT
|
2006-09-14 08:30:59 -06:00
|
|
|
static ssize_t store_bl_curve(struct device *device,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
2006-06-25 06:47:08 -06:00
|
|
|
{
|
2006-09-14 08:30:59 -06:00
|
|
|
struct fb_info *fb_info = dev_get_drvdata(device);
|
2006-06-25 06:47:08 -06:00
|
|
|
u8 tmp_curve[FB_BACKLIGHT_LEVELS];
|
|
|
|
unsigned int i;
|
|
|
|
|
2006-09-25 17:25:07 -06:00
|
|
|
/* Some drivers don't use framebuffer_alloc(), but those also
|
|
|
|
* don't have backlights.
|
|
|
|
*/
|
|
|
|
if (!fb_info || !fb_info->bl_dev)
|
|
|
|
return -ENODEV;
|
|
|
|
|
2006-06-25 06:47:08 -06:00
|
|
|
if (count != (FB_BACKLIGHT_LEVELS / 8 * 24))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
for (i = 0; i < (FB_BACKLIGHT_LEVELS / 8); ++i)
|
|
|
|
if (sscanf(&buf[i * 24],
|
|
|
|
"%2hhx %2hhx %2hhx %2hhx %2hhx %2hhx %2hhx %2hhx\n",
|
|
|
|
&tmp_curve[i * 8 + 0],
|
|
|
|
&tmp_curve[i * 8 + 1],
|
|
|
|
&tmp_curve[i * 8 + 2],
|
|
|
|
&tmp_curve[i * 8 + 3],
|
|
|
|
&tmp_curve[i * 8 + 4],
|
|
|
|
&tmp_curve[i * 8 + 5],
|
|
|
|
&tmp_curve[i * 8 + 6],
|
|
|
|
&tmp_curve[i * 8 + 7]) != 8)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/* If there has been an error in the input data, we won't
|
|
|
|
* reach this loop.
|
|
|
|
*/
|
2007-02-10 07:10:33 -07:00
|
|
|
mutex_lock(&fb_info->bl_curve_mutex);
|
2006-06-25 06:47:08 -06:00
|
|
|
for (i = 0; i < FB_BACKLIGHT_LEVELS; ++i)
|
|
|
|
fb_info->bl_curve[i] = tmp_curve[i];
|
2007-02-10 07:10:33 -07:00
|
|
|
mutex_unlock(&fb_info->bl_curve_mutex);
|
2006-06-25 06:47:08 -06:00
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2006-09-14 08:30:59 -06:00
|
|
|
static ssize_t show_bl_curve(struct device *device,
|
|
|
|
struct device_attribute *attr, char *buf)
|
2006-06-25 06:47:08 -06:00
|
|
|
{
|
2006-09-14 08:30:59 -06:00
|
|
|
struct fb_info *fb_info = dev_get_drvdata(device);
|
2006-06-25 06:47:08 -06:00
|
|
|
ssize_t len = 0;
|
|
|
|
unsigned int i;
|
|
|
|
|
2006-09-25 17:25:07 -06:00
|
|
|
/* Some drivers don't use framebuffer_alloc(), but those also
|
|
|
|
* don't have backlights.
|
|
|
|
*/
|
|
|
|
if (!fb_info || !fb_info->bl_dev)
|
|
|
|
return -ENODEV;
|
|
|
|
|
2007-02-10 07:10:33 -07:00
|
|
|
mutex_lock(&fb_info->bl_curve_mutex);
|
2006-06-25 06:47:08 -06:00
|
|
|
for (i = 0; i < FB_BACKLIGHT_LEVELS; i += 8)
|
|
|
|
len += snprintf(&buf[len], PAGE_SIZE,
|
|
|
|
"%02x %02x %02x %02x %02x %02x %02x %02x\n",
|
|
|
|
fb_info->bl_curve[i + 0],
|
|
|
|
fb_info->bl_curve[i + 1],
|
|
|
|
fb_info->bl_curve[i + 2],
|
|
|
|
fb_info->bl_curve[i + 3],
|
|
|
|
fb_info->bl_curve[i + 4],
|
|
|
|
fb_info->bl_curve[i + 5],
|
|
|
|
fb_info->bl_curve[i + 6],
|
|
|
|
fb_info->bl_curve[i + 7]);
|
2007-02-10 07:10:33 -07:00
|
|
|
mutex_unlock(&fb_info->bl_curve_mutex);
|
2006-06-25 06:47:08 -06:00
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-04-12 17:43:35 -06:00
|
|
|
/* When cmap is added back in it should be a binary attribute
|
|
|
|
* not a text one. Consideration should also be given to converting
|
|
|
|
* fbdev to use configfs instead of sysfs */
|
2006-09-14 08:30:59 -06:00
|
|
|
static struct device_attribute device_attrs[] = {
|
2005-04-16 16:20:36 -06:00
|
|
|
__ATTR(bits_per_pixel, S_IRUGO|S_IWUSR, show_bpp, store_bpp),
|
|
|
|
__ATTR(blank, S_IRUGO|S_IWUSR, show_blank, store_blank),
|
|
|
|
__ATTR(console, S_IRUGO|S_IWUSR, show_console, store_console),
|
|
|
|
__ATTR(cursor, S_IRUGO|S_IWUSR, show_cursor, store_cursor),
|
|
|
|
__ATTR(mode, S_IRUGO|S_IWUSR, show_mode, store_mode),
|
|
|
|
__ATTR(modes, S_IRUGO|S_IWUSR, show_modes, store_modes),
|
|
|
|
__ATTR(pan, S_IRUGO|S_IWUSR, show_pan, store_pan),
|
|
|
|
__ATTR(virtual_size, S_IRUGO|S_IWUSR, show_virtual, store_virtual),
|
2005-07-30 16:49:54 -06:00
|
|
|
__ATTR(name, S_IRUGO, show_name, NULL),
|
2005-10-24 14:46:21 -06:00
|
|
|
__ATTR(stride, S_IRUGO, show_stride, NULL),
|
2005-11-08 22:39:15 -07:00
|
|
|
__ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
|
2006-01-09 21:53:01 -07:00
|
|
|
__ATTR(state, S_IRUGO|S_IWUSR, show_fbstate, store_fbstate),
|
2006-06-25 06:47:08 -06:00
|
|
|
#ifdef CONFIG_FB_BACKLIGHT
|
|
|
|
__ATTR(bl_curve, S_IRUGO|S_IWUSR, show_bl_curve, store_bl_curve),
|
|
|
|
#endif
|
2005-04-16 16:20:36 -06:00
|
|
|
};
|
|
|
|
|
2006-09-14 08:30:59 -06:00
|
|
|
int fb_init_device(struct fb_info *fb_info)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2006-10-03 02:14:50 -06:00
|
|
|
int i, error = 0;
|
|
|
|
|
2006-09-14 08:30:59 -06:00
|
|
|
dev_set_drvdata(fb_info->dev, fb_info);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2006-10-03 02:14:50 -06:00
|
|
|
fb_info->class_flag |= FB_SYSFS_FLAG_ATTR;
|
|
|
|
|
2006-09-14 08:30:59 -06:00
|
|
|
for (i = 0; i < ARRAY_SIZE(device_attrs); i++) {
|
|
|
|
error = device_create_file(fb_info->dev, &device_attrs[i]);
|
2006-10-03 02:14:50 -06:00
|
|
|
|
|
|
|
if (error)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
while (--i >= 0)
|
2006-09-14 08:30:59 -06:00
|
|
|
device_remove_file(fb_info->dev, &device_attrs[i]);
|
2006-10-03 02:14:50 -06:00
|
|
|
fb_info->class_flag &= ~FB_SYSFS_FLAG_ATTR;
|
|
|
|
}
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-09-14 08:30:59 -06:00
|
|
|
void fb_cleanup_device(struct fb_info *fb_info)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
2006-10-03 02:14:50 -06:00
|
|
|
if (fb_info->class_flag & FB_SYSFS_FLAG_ATTR) {
|
2006-09-14 08:30:59 -06:00
|
|
|
for (i = 0; i < ARRAY_SIZE(device_attrs); i++)
|
|
|
|
device_remove_file(fb_info->dev, &device_attrs[i]);
|
2006-10-03 02:14:50 -06:00
|
|
|
|
|
|
|
fb_info->class_flag &= ~FB_SYSFS_FLAG_ATTR;
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2006-06-25 06:47:08 -06:00
|
|
|
#ifdef CONFIG_FB_BACKLIGHT
|
|
|
|
/* This function generates a linear backlight curve
|
|
|
|
*
|
|
|
|
* 0: off
|
|
|
|
* 1-7: min
|
|
|
|
* 8-127: linear from min to max
|
|
|
|
*/
|
|
|
|
void fb_bl_default_curve(struct fb_info *fb_info, u8 off, u8 min, u8 max)
|
|
|
|
{
|
|
|
|
unsigned int i, flat, count, range = (max - min);
|
|
|
|
|
2007-02-10 07:10:33 -07:00
|
|
|
mutex_lock(&fb_info->bl_curve_mutex);
|
|
|
|
|
2006-06-25 06:47:08 -06:00
|
|
|
fb_info->bl_curve[0] = off;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2006-06-25 06:47:08 -06:00
|
|
|
for (flat = 1; flat < (FB_BACKLIGHT_LEVELS / 16); ++flat)
|
|
|
|
fb_info->bl_curve[flat] = min;
|
|
|
|
|
|
|
|
count = FB_BACKLIGHT_LEVELS * 15 / 16;
|
|
|
|
for (i = 0; i < count; ++i)
|
|
|
|
fb_info->bl_curve[flat + i] = min + (range * (i + 1) / count);
|
2007-02-10 07:10:33 -07:00
|
|
|
|
|
|
|
mutex_unlock(&fb_info->bl_curve_mutex);
|
2006-06-25 06:47:08 -06:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(fb_bl_default_curve);
|
|
|
|
#endif
|