blob: 1446c49fe6afff693797c08194e44bb377d6ae58 [file] [log] [blame]
Yu Luming2dec3ba2006-12-19 12:56:17 -08001/*
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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090026#include <linux/slab.h>
Yu Luming2dec3ba2006-12-19 12:56:17 -080027#include <linux/err.h>
28#include <linux/ctype.h>
29
30
31MODULE_DESCRIPTION("Display Output Switcher Lowlevel Control Abstraction");
32MODULE_LICENSE("GPL");
33MODULE_AUTHOR("Luming Yu <luming.yu@intel.com>");
34
Greg Kroah-Hartman5b1530d2013-07-24 15:05:32 -070035static ssize_t state_show(struct device *dev, struct device_attribute *attr,
36 char *buf)
Yu Luming2dec3ba2006-12-19 12:56:17 -080037{
38 ssize_t ret_size = 0;
39 struct output_device *od = to_output_device(dev);
40 if (od->props)
41 ret_size = sprintf(buf,"%.8x\n",od->props->get_status(od));
42 return ret_size;
43}
44
Greg Kroah-Hartman5b1530d2013-07-24 15:05:32 -070045static ssize_t state_store(struct device *dev, struct device_attribute *attr,
46 const char *buf,size_t count)
Yu Luming2dec3ba2006-12-19 12:56:17 -080047{
48 char *endp;
49 struct output_device *od = to_output_device(dev);
50 int request_state = simple_strtoul(buf,&endp,0);
51 size_t size = endp - buf;
52
André Goddard Rosae7d28602009-12-14 18:01:06 -080053 if (isspace(*endp))
Yu Luming2dec3ba2006-12-19 12:56:17 -080054 size++;
55 if (size != count)
56 return -EINVAL;
57
58 if (od->props) {
59 od->request_state = request_state;
60 od->props->set_state(od);
61 }
62 return count;
63}
Greg Kroah-Hartman5b1530d2013-07-24 15:05:32 -070064static DEVICE_ATTR_RW(state);
Yu Luming2dec3ba2006-12-19 12:56:17 -080065
tonyj@suse.de60043422007-08-07 22:28:47 -070066static void video_output_release(struct device *dev)
Yu Luming2dec3ba2006-12-19 12:56:17 -080067{
68 struct output_device *od = to_output_device(dev);
69 kfree(od);
70}
71
Greg Kroah-Hartman5b1530d2013-07-24 15:05:32 -070072static struct attribute *video_output_attrs[] = {
73 &dev_attr_state.attr,
74 NULL,
Yu Luming2dec3ba2006-12-19 12:56:17 -080075};
Greg Kroah-Hartman5b1530d2013-07-24 15:05:32 -070076ATTRIBUTE_GROUPS(video_output);
tonyj@suse.de60043422007-08-07 22:28:47 -070077
Yu Luming2dec3ba2006-12-19 12:56:17 -080078static struct class video_output_class = {
79 .name = "video_output",
tonyj@suse.de60043422007-08-07 22:28:47 -070080 .dev_release = video_output_release,
Greg Kroah-Hartman5b1530d2013-07-24 15:05:32 -070081 .dev_groups = video_output_groups,
Yu Luming2dec3ba2006-12-19 12:56:17 -080082};
83
84struct output_device *video_output_register(const char *name,
85 struct device *dev,
86 void *devdata,
87 struct output_properties *op)
88{
89 struct output_device *new_dev;
90 int ret_code = 0;
91
92 new_dev = kzalloc(sizeof(struct output_device),GFP_KERNEL);
93 if (!new_dev) {
94 ret_code = -ENOMEM;
95 goto error_return;
96 }
97 new_dev->props = op;
tonyj@suse.de60043422007-08-07 22:28:47 -070098 new_dev->dev.class = &video_output_class;
99 new_dev->dev.parent = dev;
Kees Cook02aa2a32013-07-03 15:04:56 -0700100 dev_set_name(&new_dev->dev, "%s", name);
tonyj@suse.de60043422007-08-07 22:28:47 -0700101 dev_set_drvdata(&new_dev->dev, devdata);
102 ret_code = device_register(&new_dev->dev);
Yu Luming2dec3ba2006-12-19 12:56:17 -0800103 if (ret_code) {
104 kfree(new_dev);
105 goto error_return;
106 }
107 return new_dev;
108
109error_return:
110 return ERR_PTR(ret_code);
111}
112EXPORT_SYMBOL(video_output_register);
113
114void video_output_unregister(struct output_device *dev)
115{
116 if (!dev)
117 return;
tonyj@suse.de60043422007-08-07 22:28:47 -0700118 device_unregister(&dev->dev);
Yu Luming2dec3ba2006-12-19 12:56:17 -0800119}
120EXPORT_SYMBOL(video_output_unregister);
121
122static void __exit video_output_class_exit(void)
123{
124 class_unregister(&video_output_class);
125}
126
127static int __init video_output_class_init(void)
128{
129 return class_register(&video_output_class);
130}
131
132postcore_initcall(video_output_class_init);
133module_exit(video_output_class_exit);