]>
Commit | Line | Data |
---|---|---|
2dec3ba8 YL |
1 | /* |
2 | * output.c - Display Output Switch driver | |
3 | * | |
4 | * Copyright (C) 2006 Luming Yu <[email protected]> | |
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 | ||
30 | MODULE_DESCRIPTION("Display Output Switcher Lowlevel Control Abstraction"); | |
31 | MODULE_LICENSE("GPL"); | |
32 | MODULE_AUTHOR("Luming Yu <[email protected]>"); | |
33 | ||
60043428 | 34 | static ssize_t video_output_show_state(struct device *dev, |
35 | struct device_attribute *attr, char *buf) | |
2dec3ba8 YL |
36 | { |
37 | ssize_t ret_size = 0; | |
38 | struct output_device *od = to_output_device(dev); | |
39 | if (od->props) | |
40 | ret_size = sprintf(buf,"%.8x\n",od->props->get_status(od)); | |
41 | return ret_size; | |
42 | } | |
43 | ||
60043428 | 44 | static ssize_t video_output_store_state(struct device *dev, |
45 | struct device_attribute *attr, | |
46 | const char *buf,size_t count) | |
2dec3ba8 YL |
47 | { |
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 | ||
53 | if (*endp && isspace(*endp)) | |
54 | 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 | } | |
64 | ||
60043428 | 65 | static void video_output_release(struct device *dev) |
2dec3ba8 YL |
66 | { |
67 | struct output_device *od = to_output_device(dev); | |
68 | kfree(od); | |
69 | } | |
70 | ||
60043428 | 71 | static struct device_attribute video_output_attributes[] = { |
2dec3ba8 YL |
72 | __ATTR(state, 0644, video_output_show_state, video_output_store_state), |
73 | __ATTR_NULL, | |
74 | }; | |
75 | ||
60043428 | 76 | |
2dec3ba8 YL |
77 | static struct class video_output_class = { |
78 | .name = "video_output", | |
60043428 | 79 | .dev_release = video_output_release, |
80 | .dev_attrs = video_output_attributes, | |
2dec3ba8 YL |
81 | }; |
82 | ||
83 | struct output_device *video_output_register(const char *name, | |
84 | struct device *dev, | |
85 | void *devdata, | |
86 | struct output_properties *op) | |
87 | { | |
88 | struct output_device *new_dev; | |
89 | int ret_code = 0; | |
90 | ||
91 | new_dev = kzalloc(sizeof(struct output_device),GFP_KERNEL); | |
92 | if (!new_dev) { | |
93 | ret_code = -ENOMEM; | |
94 | goto error_return; | |
95 | } | |
96 | new_dev->props = op; | |
60043428 | 97 | new_dev->dev.class = &video_output_class; |
98 | new_dev->dev.parent = dev; | |
64dba9a9 | 99 | dev_set_name(&new_dev->dev, name); |
60043428 | 100 | dev_set_drvdata(&new_dev->dev, devdata); |
101 | ret_code = device_register(&new_dev->dev); | |
2dec3ba8 YL |
102 | if (ret_code) { |
103 | kfree(new_dev); | |
104 | goto error_return; | |
105 | } | |
106 | return new_dev; | |
107 | ||
108 | error_return: | |
109 | return ERR_PTR(ret_code); | |
110 | } | |
111 | EXPORT_SYMBOL(video_output_register); | |
112 | ||
113 | void video_output_unregister(struct output_device *dev) | |
114 | { | |
115 | if (!dev) | |
116 | return; | |
60043428 | 117 | device_unregister(&dev->dev); |
2dec3ba8 YL |
118 | } |
119 | EXPORT_SYMBOL(video_output_unregister); | |
120 | ||
121 | static void __exit video_output_class_exit(void) | |
122 | { | |
123 | class_unregister(&video_output_class); | |
124 | } | |
125 | ||
126 | static int __init video_output_class_init(void) | |
127 | { | |
128 | return class_register(&video_output_class); | |
129 | } | |
130 | ||
131 | postcore_initcall(video_output_class_init); | |
132 | module_exit(video_output_class_exit); |