aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLen Brown <len.brown@intel.com>2007-02-03 01:39:22 -0500
committerLen Brown <len.brown@intel.com>2007-02-03 01:39:22 -0500
commit274ec7a8c07036bd02e8f2301456e443ef30b8a8 (patch)
tree1ed2159c6a9c18e78ac3d769f221fdb0f0237d59
parent6b259707d53f0f25f0b24318a0774f1ae7e7e92c (diff)
parentb03637b8863159a4518cb0a9ab90577460fe3417 (diff)
Pull output-switch into test branch
-rw-r--r--Documentation/video-output.txt34
-rw-r--r--drivers/video/output.c129
-rw-r--r--include/linux/video_output.h42
3 files changed, 205 insertions, 0 deletions
diff --git a/Documentation/video-output.txt b/Documentation/video-output.txt
new file mode 100644
index 000000000000..e517011be4f9
--- /dev/null
+++ b/Documentation/video-output.txt
@@ -0,0 +1,34 @@
1
2 Video Output Switcher Control
3 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 2006 luming.yu@intel.com
5
6The output sysfs class driver provides an abstract video output layer that
7can be used to hook platform specific methods to enable/disable video output
8device through common sysfs interface. For example, on my IBM ThinkPad T42
9laptop, The ACPI video driver registered its output devices and read/write
10method for 'state' with output sysfs class. The user interface under sysfs is:
11
12linux:/sys/class/video_output # tree .
13.
14|-- CRT0
15| |-- device -> ../../../devices/pci0000:00/0000:00:01.0
16| |-- state
17| |-- subsystem -> ../../../class/video_output
18| `-- uevent
19|-- DVI0
20| |-- device -> ../../../devices/pci0000:00/0000:00:01.0
21| |-- state
22| |-- subsystem -> ../../../class/video_output
23| `-- uevent
24|-- LCD0
25| |-- device -> ../../../devices/pci0000:00/0000:00:01.0
26| |-- state
27| |-- subsystem -> ../../../class/video_output
28| `-- uevent
29`-- TV0
30 |-- device -> ../../../devices/pci0000:00/0000:00:01.0
31 |-- state
32 |-- subsystem -> ../../../class/video_output
33 `-- uevent
34
diff --git a/drivers/video/output.c b/drivers/video/output.c
new file mode 100644
index 000000000000..1473f2c892d2
--- /dev/null
+++ b/drivers/video/output.c
@@ -0,0 +1,129 @@
1/*
2 * output.c - Display Output Switch driver
3 *
4 * Copyright (C) 2006 Luming Yu <luming.yu@intel.com>
5 *
6 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or (at
11 * your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 *
22 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23 */
24#include <linux/module.h>
25#include <linux/video_output.h>
26#include <linux/err.h>
27#include <linux/ctype.h>
28
29
30MODULE_DESCRIPTION("Display Output Switcher Lowlevel Control Abstraction");
31MODULE_LICENSE("GPL");
32MODULE_AUTHOR("Luming Yu <luming.yu@intel.com>");
33
34static ssize_t video_output_show_state(struct class_device *dev,char *buf)
35{
36 ssize_t ret_size = 0;
37 struct output_device *od = to_output_device(dev);
38 if (od->props)
39 ret_size = sprintf(buf,"%.8x\n",od->props->get_status(od));
40 return ret_size;
41}
42
43static ssize_t video_output_store_state(struct class_device *dev,
44 const char *buf,size_t count)
45{
46 char *endp;
47 struct output_device *od = to_output_device(dev);
48 int request_state = simple_strtoul(buf,&endp,0);
49 size_t size = endp - buf;
50
51 if (*endp && isspace(*endp))
52 size++;
53 if (size != count)
54 return -EINVAL;
55
56 if (od->props) {
57 od->request_state = request_state;
58 od->props->set_state(od);
59 }
60 return count;
61}
62
63static void video_output_class_release(struct class_device *dev)
64{
65 struct output_device *od = to_output_device(dev);
66 kfree(od);
67}
68
69static struct class_device_attribute video_output_attributes[] = {
70 __ATTR(state, 0644, video_output_show_state, video_output_store_state),
71 __ATTR_NULL,
72};
73
74static struct class video_output_class = {
75 .name = "video_output",
76 .release = video_output_class_release,
77 .class_dev_attrs = video_output_attributes,
78};
79
80struct output_device *video_output_register(const char *name,
81 struct device *dev,
82 void *devdata,
83 struct output_properties *op)
84{
85 struct output_device *new_dev;
86 int ret_code = 0;
87
88 new_dev = kzalloc(sizeof(struct output_device),GFP_KERNEL);
89 if (!new_dev) {
90 ret_code = -ENOMEM;
91 goto error_return;
92 }
93 new_dev->props = op;
94 new_dev->class_dev.class = &video_output_class;
95 new_dev->class_dev.dev = dev;
96 strlcpy(new_dev->class_dev.class_id,name,KOBJ_NAME_LEN);
97 class_set_devdata(&new_dev->class_dev,devdata);
98 ret_code = class_device_register(&new_dev->class_dev);
99 if (ret_code) {
100 kfree(new_dev);
101 goto error_return;
102 }
103 return new_dev;
104
105error_return:
106 return ERR_PTR(ret_code);
107}
108EXPORT_SYMBOL(video_output_register);
109
110void video_output_unregister(struct output_device *dev)
111{
112 if (!dev)
113 return;
114 class_device_unregister(&dev->class_dev);
115}
116EXPORT_SYMBOL(video_output_unregister);
117
118static void __exit video_output_class_exit(void)
119{
120 class_unregister(&video_output_class);
121}
122
123static int __init video_output_class_init(void)
124{
125 return class_register(&video_output_class);
126}
127
128postcore_initcall(video_output_class_init);
129module_exit(video_output_class_exit);
diff --git a/include/linux/video_output.h b/include/linux/video_output.h
new file mode 100644
index 000000000000..e63e0c03ee0d
--- /dev/null
+++ b/include/linux/video_output.h
@@ -0,0 +1,42 @@
1/*
2 *
3 * Copyright (C) 2006 Luming Yu <luming.yu@intel.com>
4 *
5 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or (at
10 * your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20 *
21 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
22 */
23#ifndef _LINUX_VIDEO_OUTPUT_H
24#define _LINUX_VIDEO_OUTPUT_H
25#include <linux/device.h>
26struct output_device;
27struct output_properties {
28 int (*set_state)(struct output_device *);
29 int (*get_status)(struct output_device *);
30};
31struct output_device {
32 int request_state;
33 struct output_properties *props;
34 struct class_device class_dev;
35};
36#define to_output_device(obj) container_of(obj, struct output_device, class_dev)
37struct output_device *video_output_register(const char *name,
38 struct device *dev,
39 void *devdata,
40 struct output_properties *op);
41void video_output_unregister(struct output_device *dev);
42#endif