1 | /* |
---|
2 | * @brief socket.c |
---|
3 | * |
---|
4 | * @author konfetti |
---|
5 | * |
---|
6 | * @brief handling of mixed tuner's in one box. |
---|
7 | * |
---|
8 | * Copyright (C) 2011 duckbox project |
---|
9 | * |
---|
10 | * This program is free software; you can redistribute it and/or modify |
---|
11 | * it under the terms of the GNU General Public License as published by |
---|
12 | * the Free Software Foundation; either version 2 of the License, or |
---|
13 | * (at your option) any later version. |
---|
14 | * |
---|
15 | * This program is distributed in the hope that it will be useful, |
---|
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
18 | * GNU General Public License for more details. |
---|
19 | * |
---|
20 | * You should have received a copy of the GNU General Public License |
---|
21 | * along with this program; if not, write to the Free Software |
---|
22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
23 | */ |
---|
24 | |
---|
25 | #include <linux/slab.h> |
---|
26 | #include <linux/kernel.h> |
---|
27 | #include <linux/module.h> |
---|
28 | #include <linux/moduleparam.h> |
---|
29 | #include <linux/init.h> |
---|
30 | #include <linux/firmware.h> |
---|
31 | #include <linux/platform_device.h> |
---|
32 | #include <linux/dvb/version.h> |
---|
33 | #include <linux/version.h> |
---|
34 | |
---|
35 | #include "socket.h" |
---|
36 | |
---|
37 | static int numSockets = 0; |
---|
38 | struct socket_s* sockets = NULL; |
---|
39 | struct dvb_adapter* adapter = NULL; |
---|
40 | |
---|
41 | #define cMaxFrontends 8 |
---|
42 | |
---|
43 | static int numFrontends = 0; |
---|
44 | struct frontend_s frontends[cMaxFrontends]; |
---|
45 | |
---|
46 | void addFrontend(struct frontend_s* frontend) |
---|
47 | { |
---|
48 | frontends[numFrontends] = *frontend; |
---|
49 | numFrontends++; |
---|
50 | } |
---|
51 | |
---|
52 | /* ******************************* */ |
---|
53 | /* public functions */ |
---|
54 | /* ******************************* */ |
---|
55 | |
---|
56 | /* will be called from the demods/frontends device probe function */ |
---|
57 | int socket_register_frontend(struct frontend_s* frontend) |
---|
58 | { |
---|
59 | if (numFrontends + 1 == cMaxFrontends) |
---|
60 | { |
---|
61 | printk("maximum number frontends reached\n"); |
---|
62 | return -1; |
---|
63 | } |
---|
64 | |
---|
65 | addFrontend(frontend); |
---|
66 | return 0; |
---|
67 | } |
---|
68 | |
---|
69 | EXPORT_SYMBOL(socket_register_frontend); |
---|
70 | |
---|
71 | /* will be called from stmdvb.ko */ |
---|
72 | int socket_register_adapter(struct dvb_adapter* _adapter) |
---|
73 | { |
---|
74 | int i, j; |
---|
75 | |
---|
76 | if (adapter != NULL) |
---|
77 | { |
---|
78 | printk("%s: already in use\n", __func__); |
---|
79 | return -ENODEV; |
---|
80 | } |
---|
81 | |
---|
82 | adapter = _adapter; |
---|
83 | |
---|
84 | for (i = 0;i < numSockets; i++) |
---|
85 | { |
---|
86 | for (j = 0; j < numFrontends; j++) |
---|
87 | { |
---|
88 | if (frontends[j].demod_detect(&sockets[i], &frontends[j]) == 0) |
---|
89 | { |
---|
90 | printk("found %s on socket %s\n", frontends[j].name, sockets[i].name); |
---|
91 | |
---|
92 | frontends[j].demod_attach(adapter, &sockets[i], &frontends[j]); |
---|
93 | break; |
---|
94 | } |
---|
95 | } |
---|
96 | } |
---|
97 | |
---|
98 | return 0; |
---|
99 | } |
---|
100 | EXPORT_SYMBOL(socket_register_adapter); |
---|
101 | |
---|
102 | /* ******************************* */ |
---|
103 | /* driver functions */ |
---|
104 | /* ******************************* */ |
---|
105 | |
---|
106 | static int socket_probe (struct platform_device *pdev) |
---|
107 | { |
---|
108 | struct tunersocket_s *socket_config = pdev->dev.platform_data; |
---|
109 | int i; |
---|
110 | |
---|
111 | printk("%s >\n", __func__); |
---|
112 | |
---|
113 | numSockets = socket_config->numSockets; |
---|
114 | |
---|
115 | sockets = (struct socket_s*) kzalloc(sizeof(struct socket_s) * numSockets, GFP_KERNEL); |
---|
116 | |
---|
117 | if (sockets == NULL) |
---|
118 | { |
---|
119 | printk(KERN_ERR "%s: kzalloc failed.\n", __func__); |
---|
120 | return -ENOMEM; |
---|
121 | } |
---|
122 | |
---|
123 | for (i = 0; i < numSockets; i++) |
---|
124 | { |
---|
125 | sockets[i] = socket_config->socketList[i]; |
---|
126 | |
---|
127 | printk("***************************\n"); |
---|
128 | printk("socket %d\n", i + 1); |
---|
129 | printk("name %s\n", sockets[i].name); |
---|
130 | printk("pio port %d\n", sockets[i].tuner_enable[0]); |
---|
131 | printk("pio pin %d\n", sockets[i].tuner_enable[1]); |
---|
132 | printk("active l/h %d\n", sockets[i].tuner_enable[2]); |
---|
133 | printk("i2c_bus %d\n", sockets[i].i2c_bus); |
---|
134 | } |
---|
135 | |
---|
136 | printk("%s <\n", __func__); |
---|
137 | return 0; |
---|
138 | } |
---|
139 | |
---|
140 | static int socket_remove(struct device *dev) |
---|
141 | { |
---|
142 | return 0; |
---|
143 | } |
---|
144 | |
---|
145 | static struct platform_driver socket_driver = { |
---|
146 | .probe = socket_probe, |
---|
147 | .remove = socket_remove, |
---|
148 | .driver = { |
---|
149 | .name = "socket", |
---|
150 | .owner = THIS_MODULE, |
---|
151 | }, |
---|
152 | }; |
---|
153 | |
---|
154 | /* ******************************* */ |
---|
155 | /* module functions */ |
---|
156 | /* ******************************* */ |
---|
157 | |
---|
158 | int __init socket_init(void) |
---|
159 | { |
---|
160 | int ret; |
---|
161 | |
---|
162 | printk("%s >\n", __func__); |
---|
163 | |
---|
164 | ret = platform_driver_register (&socket_driver); |
---|
165 | |
---|
166 | printk("%s < %d\n", __func__, ret); |
---|
167 | return ret; |
---|
168 | } |
---|
169 | |
---|
170 | static void socket_cleanup(void) |
---|
171 | { |
---|
172 | printk("%s >\n", __func__); |
---|
173 | |
---|
174 | driver_unregister(&socket_driver); |
---|
175 | } |
---|
176 | |
---|
177 | MODULE_DESCRIPTION("Multituner Socket Handling"); |
---|
178 | |
---|
179 | MODULE_AUTHOR("konfetti"); |
---|
180 | MODULE_LICENSE("GPL"); |
---|
181 | |
---|
182 | module_init(socket_init); |
---|
183 | module_exit(socket_cleanup); |
---|
184 | |
---|