~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to drivers/gpu/pvr/omaplfb/omaplfb-sysfs.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * omaplfb-sysfs.c
 
3
 *
 
4
 * Copyright (C) 2011 Texas Instruments.
 
5
 *
 
6
 * This file is licensed under the terms of the GNU General Public License
 
7
 * version 2. This program is licensed "as is" without any warranty of any
 
8
 * kind, whether express or implied.
 
9
 *
 
10
 * Author: Gustavo Diaz (gusdp@ti.com)
 
11
 *
 
12
 */
 
13
 
 
14
#include <linux/version.h>
 
15
#include <linux/module.h>
 
16
#include <linux/sysfs.h>
 
17
#include <linux/platform_device.h>
 
18
#include <linux/device.h>
 
19
#include <linux/uaccess.h>
 
20
 
 
21
#include "img_defs.h"
 
22
#include "servicesext.h"
 
23
#include "kerneldisplay.h"
 
24
#include "omaplfb.h"
 
25
 
 
26
static ssize_t show_ignore_sync(OMAPLFB_DEVINFO *display_info, char *buf)
 
27
{
 
28
        return snprintf(buf, PAGE_SIZE, "%d\n", display_info->ignore_sync);
 
29
}
 
30
 
 
31
static ssize_t store_ignore_sync(OMAPLFB_DEVINFO *display_info,
 
32
        const char *buf, size_t count)
 
33
{
 
34
        unsigned long new_value;
 
35
 
 
36
        if (strict_strtoul(buf, 10, &new_value))
 
37
                return -EINVAL;
 
38
 
 
39
        if (new_value == 0 || new_value == 1) {
 
40
                display_info->ignore_sync = new_value;
 
41
                return count;
 
42
        }
 
43
 
 
44
        return -EINVAL;
 
45
}
 
46
 
 
47
struct omaplfb_attribute {
 
48
        struct attribute attr;
 
49
        ssize_t (*show)(OMAPLFB_DEVINFO *, char *);
 
50
        ssize_t (*store)(OMAPLFB_DEVINFO *, const char *, size_t);
 
51
};
 
52
 
 
53
static ssize_t omaplfb_attr_show(struct kobject *kobj, struct attribute *attr,
 
54
                char *buf)
 
55
{
 
56
        OMAPLFB_DEVINFO *display_info;
 
57
        struct omaplfb_attribute *omaplfb_attr;
 
58
 
 
59
        display_info = container_of(kobj, OMAPLFB_DEVINFO, kobj);
 
60
        omaplfb_attr = container_of(attr, struct omaplfb_attribute, attr);
 
61
 
 
62
        if (!omaplfb_attr->show)
 
63
                return -ENOENT;
 
64
 
 
65
        return omaplfb_attr->show(display_info, buf);
 
66
}
 
67
 
 
68
static ssize_t omaplfb_attr_store(struct kobject *kobj, struct attribute *attr,
 
69
                const char *buf, size_t size)
 
70
{
 
71
        OMAPLFB_DEVINFO *display_info;
 
72
        struct omaplfb_attribute *omaplfb_attr;
 
73
 
 
74
        display_info = container_of(kobj, OMAPLFB_DEVINFO, kobj);
 
75
        omaplfb_attr = container_of(attr, struct omaplfb_attribute, attr);
 
76
 
 
77
        if (!omaplfb_attr->store)
 
78
                return -ENOENT;
 
79
 
 
80
        return omaplfb_attr->store(display_info, buf, size);
 
81
}
 
82
 
 
83
#define OMAPLFB_ATTR(_name, _mode, _show, _store) \
 
84
        struct omaplfb_attribute omaplfb_attr_##_name = \
 
85
        __ATTR(_name, _mode, _show, _store)
 
86
 
 
87
static OMAPLFB_ATTR(ignore_sync, S_IRUGO|S_IWUSR, show_ignore_sync,
 
88
        store_ignore_sync);
 
89
 
 
90
#undef OMAPLFB_ATTR
 
91
 
 
92
static struct attribute *omaplfb_sysfs_attrs[] = {
 
93
        &omaplfb_attr_ignore_sync.attr,
 
94
        NULL
 
95
};
 
96
 
 
97
static const struct sysfs_ops omaplfb_sysfs_ops = {
 
98
        .show = omaplfb_attr_show,
 
99
        .store = omaplfb_attr_store,
 
100
};
 
101
 
 
102
static struct kobj_type omaplfb_ktype = {
 
103
        .sysfs_ops = &omaplfb_sysfs_ops,
 
104
        .default_attrs = omaplfb_sysfs_attrs,
 
105
};
 
106
 
 
107
void omaplfb_create_sysfs(struct omaplfb_device *odev)
 
108
{
 
109
        int i, r;
 
110
 
 
111
        /* Create a sysfs entry for every display */
 
112
        for (i = 0; i < odev->display_count; i++) {
 
113
                OMAPLFB_DEVINFO *display_info = &odev->display_info_list[i];
 
114
                r = kobject_init_and_add(&display_info->kobj, &omaplfb_ktype,
 
115
                        &odev->dev->kobj, "display%d",
 
116
                        display_info->uDeviceID);
 
117
                if (r)
 
118
                        ERROR_PRINTK("failed to create sysfs file\n");
 
119
        }
 
120
}
 
121
 
 
122
void omaplfb_remove_sysfs(struct omaplfb_device *odev)
 
123
{
 
124
        int i;
 
125
        for (i = 0; i < odev->display_count; i++) {
 
126
                OMAPLFB_DEVINFO *display_info = &odev->display_info_list[i];
 
127
                kobject_del(&display_info->kobj);
 
128
                kobject_put(&display_info->kobj);
 
129
        }
 
130
}