diff options
author | Michael Krufky <mkrufky@linuxtv.org> | 2008-05-22 17:29:20 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@infradead.org> | 2008-07-20 06:20:47 -0400 |
commit | 854470606070d91955f03a7dca3a8024fc2a2540 (patch) | |
tree | 858216ab89c0f23b1f6d23782b4275112550b499 /drivers/media/dvb/siano/smscoreapi.c | |
parent | 7d18d2e91b5495ed0b99c83d595a56e25521a111 (diff) |
V4L/DVB (8272): sms1xxx: move driver from media/mdtv/ to media/dvb/siano/
Signed-off-by: Michael Krufky <mkrufky@linuxtv.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'drivers/media/dvb/siano/smscoreapi.c')
-rw-r--r-- | drivers/media/dvb/siano/smscoreapi.c | 1158 |
1 files changed, 1158 insertions, 0 deletions
diff --git a/drivers/media/dvb/siano/smscoreapi.c b/drivers/media/dvb/siano/smscoreapi.c new file mode 100644 index 00000000000..d3ba1fcde54 --- /dev/null +++ b/drivers/media/dvb/siano/smscoreapi.c | |||
@@ -0,0 +1,1158 @@ | |||
1 | /* | ||
2 | * Siano core API module | ||
3 | * | ||
4 | * This file contains implementation for the interface to sms core component | ||
5 | * | ||
6 | * author: Anatoly Greenblat | ||
7 | * | ||
8 | * Copyright (c), 2005-2008 Siano Mobile Silicon, Inc. | ||
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 version 3 as | ||
12 | * published by the Free Software Foundation; | ||
13 | * | ||
14 | * Software distributed under the License is distributed on an "AS IS" | ||
15 | * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. | ||
16 | * | ||
17 | * See the GNU General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, write to the Free Software | ||
21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
22 | */ | ||
23 | |||
24 | #include <linux/kernel.h> | ||
25 | #include <linux/init.h> | ||
26 | #include <linux/module.h> | ||
27 | #include <linux/moduleparam.h> | ||
28 | #include <linux/dma-mapping.h> | ||
29 | #include <linux/delay.h> | ||
30 | #include <asm/io.h> | ||
31 | |||
32 | #include <linux/firmware.h> | ||
33 | |||
34 | #include "smscoreapi.h" | ||
35 | |||
36 | typedef struct _smscore_device_notifyee | ||
37 | { | ||
38 | struct list_head entry; | ||
39 | hotplug_t hotplug; | ||
40 | } smscore_device_notifyee_t; | ||
41 | |||
42 | typedef struct _smscore_client | ||
43 | { | ||
44 | struct list_head entry; | ||
45 | smscore_device_t *coredev; | ||
46 | |||
47 | void *context; | ||
48 | |||
49 | int data_type; | ||
50 | |||
51 | onresponse_t onresponse_handler; | ||
52 | onremove_t onremove_handler; | ||
53 | } *psmscore_client_t; | ||
54 | |||
55 | typedef struct _smscore_subclient | ||
56 | { | ||
57 | struct list_head entry; | ||
58 | smscore_client_t *client; | ||
59 | |||
60 | int id; | ||
61 | } smscore_subclient_t; | ||
62 | |||
63 | typedef struct _smscore_device | ||
64 | { | ||
65 | struct list_head entry; | ||
66 | |||
67 | struct list_head clients; | ||
68 | struct list_head subclients; | ||
69 | spinlock_t clientslock; | ||
70 | |||
71 | struct list_head buffers; | ||
72 | spinlock_t bufferslock; | ||
73 | int num_buffers; | ||
74 | |||
75 | void *common_buffer; | ||
76 | int common_buffer_size; | ||
77 | dma_addr_t common_buffer_phys; | ||
78 | |||
79 | void *context; | ||
80 | struct device *device; | ||
81 | |||
82 | char devpath[32]; | ||
83 | unsigned long device_flags; | ||
84 | |||
85 | setmode_t setmode_handler; | ||
86 | detectmode_t detectmode_handler; | ||
87 | sendrequest_t sendrequest_handler; | ||
88 | preload_t preload_handler; | ||
89 | postload_t postload_handler; | ||
90 | |||
91 | int mode, modes_supported; | ||
92 | |||
93 | struct completion version_ex_done, data_download_done, trigger_done; | ||
94 | struct completion init_device_done, reload_start_done, resume_done; | ||
95 | } *psmscore_device_t; | ||
96 | |||
97 | typedef struct _smscore_registry_entry | ||
98 | { | ||
99 | struct list_head entry; | ||
100 | char devpath[32]; | ||
101 | int mode; | ||
102 | } smscore_registry_entry_t; | ||
103 | |||
104 | struct list_head g_smscore_notifyees; | ||
105 | struct list_head g_smscore_devices; | ||
106 | kmutex_t g_smscore_deviceslock; | ||
107 | |||
108 | struct list_head g_smscore_registry; | ||
109 | kmutex_t g_smscore_registrylock; | ||
110 | |||
111 | static int default_mode = 1; | ||
112 | module_param(default_mode, int, 0644); | ||
113 | MODULE_PARM_DESC(default_mode, "default firmware id (device mode)"); | ||
114 | |||
115 | int smscore_registry_getmode(char* devpath) | ||
116 | { | ||
117 | smscore_registry_entry_t *entry; | ||
118 | struct list_head *next; | ||
119 | |||
120 | kmutex_lock(&g_smscore_registrylock); | ||
121 | |||
122 | for (next = g_smscore_registry.next; next != &g_smscore_registry; next = next->next) | ||
123 | { | ||
124 | entry = (smscore_registry_entry_t *) next; | ||
125 | |||
126 | if (!strcmp(entry->devpath, devpath)) | ||
127 | { | ||
128 | kmutex_unlock(&g_smscore_registrylock); | ||
129 | return entry->mode; | ||
130 | } | ||
131 | } | ||
132 | |||
133 | entry = (smscore_registry_entry_t *) kmalloc(sizeof(smscore_registry_entry_t), GFP_KERNEL); | ||
134 | if (entry) | ||
135 | { | ||
136 | entry->mode = default_mode; | ||
137 | strcpy(entry->devpath, devpath); | ||
138 | |||
139 | list_add(&entry->entry, &g_smscore_registry); | ||
140 | } | ||
141 | |||
142 | kmutex_unlock(&g_smscore_registrylock); | ||
143 | |||
144 | return default_mode; | ||
145 | } | ||
146 | |||
147 | void smscore_registry_setmode(char* devpath, int mode) | ||
148 | { | ||
149 | smscore_registry_entry_t *entry; | ||
150 | struct list_head *next; | ||
151 | |||
152 | kmutex_lock(&g_smscore_registrylock); | ||
153 | |||
154 | for (next = g_smscore_registry.next; next != &g_smscore_registry; next = next->next) | ||
155 | { | ||
156 | entry = (smscore_registry_entry_t *) next; | ||
157 | |||
158 | if (!strcmp(entry->devpath, devpath)) | ||
159 | { | ||
160 | entry->mode = mode; | ||
161 | break; | ||
162 | } | ||
163 | } | ||
164 | |||
165 | kmutex_unlock(&g_smscore_registrylock); | ||
166 | } | ||
167 | |||
168 | |||
169 | void list_add_locked(struct list_head *new, struct list_head *head, spinlock_t* lock) | ||
170 | { | ||
171 | unsigned long flags; | ||
172 | |||
173 | spin_lock_irqsave(lock, flags); | ||
174 | |||
175 | list_add(new, head); | ||
176 | |||
177 | spin_unlock_irqrestore(lock, flags); | ||
178 | } | ||
179 | |||
180 | /** | ||
181 | * register a client callback that called when device plugged in/unplugged | ||
182 | * NOTE: if devices exist callback is called immediately for each device | ||
183 | * | ||
184 | * @param hotplug callback | ||
185 | * | ||
186 | * @return 0 on success, <0 on error. | ||
187 | */ | ||
188 | int smscore_register_hotplug(hotplug_t hotplug) | ||
189 | { | ||
190 | smscore_device_notifyee_t *notifyee; | ||
191 | struct list_head *next, *first; | ||
192 | int rc = 0; | ||
193 | |||
194 | kmutex_lock(&g_smscore_deviceslock); | ||
195 | |||
196 | notifyee = kmalloc(sizeof(smscore_device_notifyee_t), GFP_KERNEL); | ||
197 | if (notifyee) | ||
198 | { | ||
199 | // now notify callback about existing devices | ||
200 | first = &g_smscore_devices; | ||
201 | for (next = first->next; next != first && !rc; next = next->next) | ||
202 | { | ||
203 | smscore_device_t *coredev = (smscore_device_t *) next; | ||
204 | rc = hotplug(coredev, coredev->device, 1); | ||
205 | } | ||
206 | |||
207 | if (rc >= 0) | ||
208 | { | ||
209 | notifyee->hotplug = hotplug; | ||
210 | list_add(¬ifyee->entry, &g_smscore_notifyees); | ||
211 | } | ||
212 | else | ||
213 | kfree(notifyee); | ||
214 | } | ||
215 | else | ||
216 | rc = -ENOMEM; | ||
217 | |||
218 | kmutex_unlock(&g_smscore_deviceslock); | ||
219 | |||
220 | return rc; | ||
221 | } | ||
222 | |||
223 | /** | ||
224 | * unregister a client callback that called when device plugged in/unplugged | ||
225 | * | ||
226 | * @param hotplug callback | ||
227 | * | ||
228 | */ | ||
229 | void smscore_unregister_hotplug(hotplug_t hotplug) | ||
230 | { | ||
231 | struct list_head *next, *first; | ||
232 | |||
233 | kmutex_lock(&g_smscore_deviceslock); | ||
234 | |||
235 | first = &g_smscore_notifyees; | ||
236 | |||
237 | for (next = first->next; next != first;) | ||
238 | { | ||
239 | smscore_device_notifyee_t *notifyee = (smscore_device_notifyee_t *) next; | ||
240 | next = next->next; | ||
241 | |||
242 | if (notifyee->hotplug == hotplug) | ||
243 | { | ||
244 | list_del(¬ifyee->entry); | ||
245 | kfree(notifyee); | ||
246 | } | ||
247 | } | ||
248 | |||
249 | kmutex_unlock(&g_smscore_deviceslock); | ||
250 | } | ||
251 | |||
252 | void smscore_notify_clients(smscore_device_t *coredev) | ||
253 | { | ||
254 | smscore_client_t* client; | ||
255 | |||
256 | // the client must call smscore_unregister_client from remove handler | ||
257 | while (!list_empty(&coredev->clients)) | ||
258 | { | ||
259 | client = (smscore_client_t *) coredev->clients.next; | ||
260 | client->onremove_handler(client->context); | ||
261 | } | ||
262 | } | ||
263 | |||
264 | int smscore_notify_callbacks(smscore_device_t *coredev, struct device *device, int arrival) | ||
265 | { | ||
266 | struct list_head *next, *first; | ||
267 | int rc = 0; | ||
268 | |||
269 | // note: must be called under g_deviceslock | ||
270 | |||
271 | first = &g_smscore_notifyees; | ||
272 | |||
273 | for (next = first->next; next != first; next = next->next) | ||
274 | { | ||
275 | rc = ((smscore_device_notifyee_t *) next)->hotplug(coredev, device, arrival); | ||
276 | if (rc < 0) | ||
277 | break; | ||
278 | } | ||
279 | |||
280 | return rc; | ||
281 | } | ||
282 | |||
283 | smscore_buffer_t *smscore_createbuffer(u8* buffer, void* common_buffer, dma_addr_t common_buffer_phys) | ||
284 | { | ||
285 | smscore_buffer_t *cb = kmalloc(sizeof(smscore_buffer_t), GFP_KERNEL); | ||
286 | if (!cb) | ||
287 | { | ||
288 | printk(KERN_INFO "%s kmalloc(...) failed\n", __FUNCTION__); | ||
289 | return NULL; | ||
290 | } | ||
291 | |||
292 | cb->p = buffer; | ||
293 | cb->offset_in_common = buffer - (u8*) common_buffer; | ||
294 | cb->phys = common_buffer_phys + cb->offset_in_common; | ||
295 | |||
296 | return cb; | ||
297 | } | ||
298 | |||
299 | /** | ||
300 | * creates coredev object for a device, prepares buffers, creates buffer mappings, notifies | ||
301 | * registered hotplugs about new device. | ||
302 | * | ||
303 | * @param params device pointer to struct with device specific parameters and handlers | ||
304 | * @param coredev pointer to a value that receives created coredev object | ||
305 | * | ||
306 | * @return 0 on success, <0 on error. | ||
307 | */ | ||
308 | int smscore_register_device(smsdevice_params_t *params, smscore_device_t **coredev) | ||
309 | { | ||
310 | smscore_device_t* dev; | ||
311 | u8 *buffer; | ||
312 | |||
313 | dev = kzalloc(sizeof(smscore_device_t), GFP_KERNEL); | ||
314 | if (!dev) | ||
315 | { | ||
316 | printk(KERN_INFO "%s kzalloc(...) failed\n", __FUNCTION__); | ||
317 | return -ENOMEM; | ||
318 | } | ||
319 | |||
320 | // init list entry so it could be safe in smscore_unregister_device | ||
321 | INIT_LIST_HEAD(&dev->entry); | ||
322 | |||
323 | // init queues | ||
324 | INIT_LIST_HEAD(&dev->clients); | ||
325 | INIT_LIST_HEAD(&dev->subclients); | ||
326 | INIT_LIST_HEAD(&dev->buffers); | ||
327 | |||
328 | // init locks | ||
329 | spin_lock_init(&dev->clientslock); | ||
330 | spin_lock_init(&dev->bufferslock); | ||
331 | |||
332 | // init completion events | ||
333 | init_completion(&dev->version_ex_done); | ||
334 | init_completion(&dev->data_download_done); | ||
335 | init_completion(&dev->trigger_done); | ||
336 | init_completion(&dev->init_device_done); | ||
337 | init_completion(&dev->reload_start_done); | ||
338 | init_completion(&dev->resume_done); | ||
339 | |||
340 | // alloc common buffer | ||
341 | dev->common_buffer_size = params->buffer_size * params->num_buffers; | ||
342 | dev->common_buffer = dma_alloc_coherent(NULL, dev->common_buffer_size, &dev->common_buffer_phys, GFP_KERNEL | GFP_DMA); | ||
343 | if (!dev->common_buffer) | ||
344 | { | ||
345 | smscore_unregister_device(dev); | ||
346 | return -ENOMEM; | ||
347 | } | ||
348 | |||
349 | // prepare dma buffers | ||
350 | for (buffer = dev->common_buffer; dev->num_buffers < params->num_buffers; dev->num_buffers ++, buffer += params->buffer_size) | ||
351 | { | ||
352 | smscore_buffer_t *cb = smscore_createbuffer(buffer, dev->common_buffer, dev->common_buffer_phys); | ||
353 | if (!cb) | ||
354 | { | ||
355 | smscore_unregister_device(dev); | ||
356 | return -ENOMEM; | ||
357 | } | ||
358 | |||
359 | smscore_putbuffer(dev, cb); | ||
360 | } | ||
361 | |||
362 | printk(KERN_INFO "%s allocated %d buffers\n", __FUNCTION__, dev->num_buffers); | ||
363 | |||
364 | dev->mode = DEVICE_MODE_NONE; | ||
365 | dev->context = params->context; | ||
366 | dev->device = params->device; | ||
367 | dev->setmode_handler = params->setmode_handler; | ||
368 | dev->detectmode_handler = params->detectmode_handler; | ||
369 | dev->sendrequest_handler = params->sendrequest_handler; | ||
370 | dev->preload_handler = params->preload_handler; | ||
371 | dev->postload_handler = params->postload_handler; | ||
372 | |||
373 | dev->device_flags = params->flags; | ||
374 | strcpy(dev->devpath, params->devpath); | ||
375 | |||
376 | // add device to devices list | ||
377 | kmutex_lock(&g_smscore_deviceslock); | ||
378 | list_add(&dev->entry, &g_smscore_devices); | ||
379 | kmutex_unlock(&g_smscore_deviceslock); | ||
380 | |||
381 | *coredev = dev; | ||
382 | |||
383 | printk(KERN_INFO "%s device %p created\n", __FUNCTION__, dev); | ||
384 | |||
385 | return 0; | ||
386 | } | ||
387 | |||
388 | /** | ||
389 | * sets initial device mode and notifies client hotplugs that device is ready | ||
390 | * | ||
391 | * @param coredev pointer to a coredev object returned by smscore_register_device | ||
392 | * | ||
393 | * @return 0 on success, <0 on error. | ||
394 | */ | ||
395 | int smscore_start_device(smscore_device_t *coredev) | ||
396 | { | ||
397 | int rc = smscore_set_device_mode(coredev, smscore_registry_getmode(coredev->devpath)); | ||
398 | if (rc < 0) | ||
399 | return rc; | ||
400 | |||
401 | kmutex_lock(&g_smscore_deviceslock); | ||
402 | |||
403 | rc = smscore_notify_callbacks(coredev, coredev->device, 1); | ||
404 | |||
405 | printk(KERN_INFO "%s device %p started, rc %d\n", __FUNCTION__, coredev, rc); | ||
406 | |||
407 | kmutex_unlock(&g_smscore_deviceslock); | ||
408 | |||
409 | return rc; | ||
410 | } | ||
411 | |||
412 | int smscore_sendrequest_and_wait(smscore_device_t *coredev, void* buffer, size_t size, struct completion *completion) | ||
413 | { | ||
414 | int rc = coredev->sendrequest_handler(coredev->context, buffer, size); | ||
415 | if (rc < 0) | ||
416 | return rc; | ||
417 | |||
418 | return wait_for_completion_timeout(completion, msecs_to_jiffies(1000)) ? 0 : -ETIME; | ||
419 | } | ||
420 | |||
421 | int smscore_load_firmware_family2(smscore_device_t *coredev, void *buffer, size_t size) | ||
422 | { | ||
423 | SmsFirmware_ST* firmware = (SmsFirmware_ST*) buffer; | ||
424 | SmsMsgHdr_ST *msg; | ||
425 | UINT32 mem_address = firmware->StartAddress; | ||
426 | u8* payload = firmware->Payload; | ||
427 | int rc = 0; | ||
428 | |||
429 | if (coredev->preload_handler) | ||
430 | { | ||
431 | rc = coredev->preload_handler(coredev->context); | ||
432 | if (rc < 0) | ||
433 | return rc; | ||
434 | } | ||
435 | |||
436 | // PAGE_SIZE buffer shall be enough and dma aligned | ||
437 | msg = (SmsMsgHdr_ST *) kmalloc(PAGE_SIZE, GFP_KERNEL | GFP_DMA); | ||
438 | if (!msg) | ||
439 | return -ENOMEM; | ||
440 | |||
441 | if (coredev->mode != DEVICE_MODE_NONE) | ||
442 | { | ||
443 | SMS_INIT_MSG(msg, MSG_SW_RELOAD_START_REQ, sizeof(SmsMsgHdr_ST)); | ||
444 | rc = smscore_sendrequest_and_wait(coredev, msg, msg->msgLength, &coredev->reload_start_done); | ||
445 | mem_address = *(UINT32*) &payload[20]; | ||
446 | } | ||
447 | |||
448 | while (size && rc >= 0) | ||
449 | { | ||
450 | SmsDataDownload_ST *DataMsg = (SmsDataDownload_ST *) msg; | ||
451 | int payload_size = min((int) size, SMS_MAX_PAYLOAD_SIZE); | ||
452 | |||
453 | SMS_INIT_MSG(msg, MSG_SMS_DATA_DOWNLOAD_REQ, (UINT16)(sizeof(SmsMsgHdr_ST) + sizeof(UINT32) + payload_size)); | ||
454 | |||
455 | DataMsg->MemAddr = mem_address; | ||
456 | memcpy(DataMsg->Payload, payload, payload_size); | ||
457 | |||
458 | if (coredev->device_flags & SMS_ROM_NO_RESPONSE && coredev->mode == DEVICE_MODE_NONE) | ||
459 | rc = coredev->sendrequest_handler(coredev->context, DataMsg, DataMsg->xMsgHeader.msgLength); | ||
460 | else | ||
461 | rc = smscore_sendrequest_and_wait(coredev, DataMsg, DataMsg->xMsgHeader.msgLength, &coredev->data_download_done); | ||
462 | |||
463 | payload += payload_size; | ||
464 | size -= payload_size; | ||
465 | mem_address += payload_size; | ||
466 | } | ||
467 | |||
468 | if (rc >= 0) | ||
469 | { | ||
470 | if (coredev->mode == DEVICE_MODE_NONE) | ||
471 | { | ||
472 | SmsMsgData_ST* TriggerMsg = (SmsMsgData_ST*) msg; | ||
473 | |||
474 | SMS_INIT_MSG(msg, MSG_SMS_SWDOWNLOAD_TRIGGER_REQ, sizeof(SmsMsgHdr_ST) + sizeof(UINT32) * 5); | ||
475 | |||
476 | TriggerMsg->msgData[0] = firmware->StartAddress; // Entry point | ||
477 | TriggerMsg->msgData[1] = 5; // Priority | ||
478 | TriggerMsg->msgData[2] = 0x200; // Stack size | ||
479 | TriggerMsg->msgData[3] = 0; // Parameter | ||
480 | TriggerMsg->msgData[4] = 4; // Task ID | ||
481 | |||
482 | if (coredev->device_flags & SMS_ROM_NO_RESPONSE) | ||
483 | { | ||
484 | rc = coredev->sendrequest_handler(coredev->context, TriggerMsg, TriggerMsg->xMsgHeader.msgLength); | ||
485 | msleep(100); | ||
486 | } | ||
487 | else | ||
488 | rc = smscore_sendrequest_and_wait(coredev, TriggerMsg, TriggerMsg->xMsgHeader.msgLength, &coredev->trigger_done); | ||
489 | } | ||
490 | else | ||
491 | { | ||
492 | SMS_INIT_MSG(msg, MSG_SW_RELOAD_EXEC_REQ, sizeof(SmsMsgHdr_ST)); | ||
493 | |||
494 | rc = coredev->sendrequest_handler(coredev->context, msg, msg->msgLength); | ||
495 | } | ||
496 | } | ||
497 | |||
498 | printk("%s %d \n", __func__, rc); | ||
499 | |||
500 | kfree(msg); | ||
501 | |||
502 | return (rc >= 0 && coredev->postload_handler) ? | ||
503 | coredev->postload_handler(coredev->context) : | ||
504 | rc; | ||
505 | } | ||
506 | |||
507 | /** | ||
508 | * loads specified firmware into a buffer and calls device loadfirmware_handler | ||
509 | * | ||
510 | * @param coredev pointer to a coredev object returned by smscore_register_device | ||
511 | * @param filename null-terminated string specifies firmware file name | ||
512 | * @param loadfirmware_handler device handler that loads firmware | ||
513 | * | ||
514 | * @return 0 on success, <0 on error. | ||
515 | */ | ||
516 | int smscore_load_firmware(smscore_device_t *coredev, char* filename, loadfirmware_t loadfirmware_handler) | ||
517 | { | ||
518 | int rc = -ENOENT; | ||
519 | |||
520 | const struct firmware *fw; | ||
521 | u8* fw_buffer; | ||
522 | |||
523 | if (loadfirmware_handler == NULL && !(coredev->device_flags & SMS_DEVICE_FAMILY2)) | ||
524 | return -EINVAL; | ||
525 | |||
526 | rc = request_firmware(&fw, filename, coredev->device); | ||
527 | if (rc < 0) | ||
528 | { | ||
529 | printk(KERN_INFO "%s failed to open \"%s\"\n", __FUNCTION__, filename); | ||
530 | return rc; | ||
531 | } | ||
532 | |||
533 | fw_buffer = kmalloc(ALIGN(fw->size, SMS_ALLOC_ALIGNMENT), GFP_KERNEL | GFP_DMA); | ||
534 | if (fw_buffer) | ||
535 | { | ||
536 | memcpy(fw_buffer, fw->data, fw->size); | ||
537 | |||
538 | rc = (coredev->device_flags & SMS_DEVICE_FAMILY2) ? | ||
539 | smscore_load_firmware_family2(coredev, fw_buffer, fw->size) : | ||
540 | loadfirmware_handler(coredev->context, fw_buffer, fw->size); | ||
541 | |||
542 | kfree(fw_buffer); | ||
543 | } | ||
544 | else | ||
545 | { | ||
546 | printk(KERN_INFO "%s failed to allocate firmware buffer\n", __FUNCTION__); | ||
547 | rc = -ENOMEM; | ||
548 | } | ||
549 | |||
550 | release_firmware(fw); | ||
551 | |||
552 | return rc; | ||
553 | } | ||
554 | |||
555 | /** | ||
556 | * notifies all clients registered with the device, notifies hotplugs, frees all buffers and coredev object | ||
557 | * | ||
558 | * @param coredev pointer to a coredev object returned by smscore_register_device | ||
559 | * | ||
560 | * @return 0 on success, <0 on error. | ||
561 | */ | ||
562 | void smscore_unregister_device(smscore_device_t *coredev) | ||
563 | { | ||
564 | smscore_buffer_t *cb; | ||
565 | int num_buffers = 0; | ||
566 | |||
567 | kmutex_lock(&g_smscore_deviceslock); | ||
568 | |||
569 | smscore_notify_clients(coredev); | ||
570 | smscore_notify_callbacks(coredev, NULL, 0); | ||
571 | |||
572 | // at this point all buffers should be back | ||
573 | // onresponse must no longer be called | ||
574 | |||
575 | while (1) | ||
576 | { | ||
577 | while ((cb = smscore_getbuffer(coredev))) | ||
578 | { | ||
579 | kfree(cb); | ||
580 | num_buffers ++; | ||
581 | } | ||
582 | |||
583 | if (num_buffers == coredev->num_buffers) | ||
584 | break; | ||
585 | |||
586 | printk(KERN_INFO "%s waiting for %d buffer(s)\n", __FUNCTION__, coredev->num_buffers - num_buffers); | ||
587 | msleep(100); | ||
588 | } | ||
589 | |||
590 | printk(KERN_INFO "%s freed %d buffers\n", __FUNCTION__, num_buffers); | ||
591 | |||
592 | if (coredev->common_buffer) | ||
593 | dma_free_coherent(NULL, coredev->common_buffer_size, coredev->common_buffer, coredev->common_buffer_phys); | ||
594 | |||
595 | list_del(&coredev->entry); | ||
596 | kfree(coredev); | ||
597 | |||
598 | kmutex_unlock(&g_smscore_deviceslock); | ||
599 | |||
600 | printk(KERN_INFO "%s device %p destroyed\n", __FUNCTION__, coredev); | ||
601 | } | ||
602 | |||
603 | int smscore_detect_mode(smscore_device_t *coredev) | ||
604 | { | ||
605 | void *buffer = kmalloc(sizeof(SmsMsgHdr_ST) + SMS_DMA_ALIGNMENT, GFP_KERNEL | GFP_DMA); | ||
606 | SmsMsgHdr_ST *msg = (SmsMsgHdr_ST *) SMS_ALIGN_ADDRESS(buffer); | ||
607 | int rc; | ||
608 | |||
609 | if (!buffer) | ||
610 | return -ENOMEM; | ||
611 | |||
612 | SMS_INIT_MSG(msg, MSG_SMS_GET_VERSION_EX_REQ, sizeof(SmsMsgHdr_ST)); | ||
613 | |||
614 | rc = smscore_sendrequest_and_wait(coredev, msg, msg->msgLength, &coredev->version_ex_done); | ||
615 | if (rc == -ETIME) | ||
616 | { | ||
617 | printk("%s: MSG_SMS_GET_VERSION_EX_REQ failed first try\n", __FUNCTION__); | ||
618 | |||
619 | if (wait_for_completion_timeout(&coredev->resume_done, msecs_to_jiffies(5000))) | ||
620 | { | ||
621 | rc = smscore_sendrequest_and_wait(coredev, msg, msg->msgLength, &coredev->version_ex_done); | ||
622 | if (rc < 0) | ||
623 | { | ||
624 | printk("%s: MSG_SMS_GET_VERSION_EX_REQ failed second try, rc %d\n", __FUNCTION__, rc); | ||
625 | } | ||
626 | } | ||
627 | else | ||
628 | rc = -ETIME; | ||
629 | } | ||
630 | |||
631 | kfree(buffer); | ||
632 | |||
633 | return rc; | ||
634 | } | ||
635 | |||
636 | char *smscore_fw_lkup[] = | ||
637 | { | ||
638 | "dvb_nova_12mhz.inp", | ||
639 | "dvb_nova_12mhz.inp", | ||
640 | "tdmb_nova.inp", | ||
641 | "none", | ||
642 | "dvb_nova_12mhz.inp", | ||
643 | "isdbt_nova_12mhz.inp", | ||
644 | "isdbt_nova_12mhz.inp", | ||
645 | "cmmb_nova_12mhz.inp", | ||
646 | "none", | ||
647 | }; | ||
648 | |||
649 | /** | ||
650 | * calls device handler to change mode of operation | ||
651 | * NOTE: stellar/usb may disconnect when changing mode | ||
652 | * | ||
653 | * @param coredev pointer to a coredev object returned by smscore_register_device | ||
654 | * @param mode requested mode of operation | ||
655 | * | ||
656 | * @return 0 on success, <0 on error. | ||
657 | */ | ||
658 | int smscore_set_device_mode(smscore_device_t *coredev, int mode) | ||
659 | { | ||
660 | void *buffer; | ||
661 | int rc = 0; | ||
662 | |||
663 | if (coredev->device_flags & SMS_DEVICE_FAMILY2) | ||
664 | { | ||
665 | if (mode < DEVICE_MODE_DVBT || mode > DEVICE_MODE_RAW_TUNER) | ||
666 | { | ||
667 | printk(KERN_INFO "%s invalid mode specified %d\n", __FUNCTION__, mode); | ||
668 | return -EINVAL; | ||
669 | } | ||
670 | |||
671 | if (!(coredev->device_flags & SMS_DEVICE_NOT_READY)) | ||
672 | { | ||
673 | rc = smscore_detect_mode(coredev); | ||
674 | if (rc < 0) | ||
675 | return rc; | ||
676 | } | ||
677 | |||
678 | if (coredev->mode == mode) | ||
679 | { | ||
680 | printk(KERN_INFO "%s device mode %d already set\n", __FUNCTION__, mode); | ||
681 | return 0; | ||
682 | } | ||
683 | |||
684 | if (!(coredev->modes_supported & (1 << mode))) | ||
685 | { | ||
686 | rc = smscore_load_firmware(coredev, smscore_fw_lkup[mode], NULL); | ||
687 | if (rc < 0) | ||
688 | return rc; | ||
689 | } | ||
690 | else | ||
691 | { | ||
692 | printk(KERN_INFO "%s mode %d supported by running firmware\n", __FUNCTION__, mode); | ||
693 | } | ||
694 | |||
695 | buffer = kmalloc(sizeof(SmsMsgData_ST) + SMS_DMA_ALIGNMENT, GFP_KERNEL | GFP_DMA); | ||
696 | if (buffer) | ||
697 | { | ||
698 | SmsMsgData_ST *msg = (SmsMsgData_ST *) SMS_ALIGN_ADDRESS(buffer); | ||
699 | |||
700 | SMS_INIT_MSG(&msg->xMsgHeader, MSG_SMS_INIT_DEVICE_REQ, sizeof(SmsMsgData_ST)); | ||
701 | msg->msgData[0] = mode; | ||
702 | |||
703 | rc = smscore_sendrequest_and_wait(coredev, msg, msg->xMsgHeader.msgLength, &coredev->init_device_done); | ||
704 | |||
705 | kfree(buffer); | ||
706 | } | ||
707 | else | ||
708 | rc = -ENOMEM; | ||
709 | } | ||
710 | else | ||
711 | { | ||
712 | if (coredev->detectmode_handler) | ||
713 | coredev->detectmode_handler(coredev->context, &coredev->mode); | ||
714 | |||
715 | if (coredev->mode != mode && coredev->setmode_handler) | ||
716 | rc = coredev->setmode_handler(coredev->context, mode); | ||
717 | } | ||
718 | |||
719 | smscore_registry_setmode(coredev->devpath, mode); | ||
720 | |||
721 | if (rc >= 0) | ||
722 | { | ||
723 | coredev->mode = mode; | ||
724 | coredev->device_flags &= ~SMS_DEVICE_NOT_READY; | ||
725 | } | ||
726 | |||
727 | return rc; | ||
728 | } | ||
729 | |||
730 | /** | ||
731 | * calls device handler to get current mode of operation | ||
732 | * | ||
733 | * @param coredev pointer to a coredev object returned by smscore_register_device | ||
734 | * | ||
735 | * @return current mode | ||
736 | */ | ||
737 | int smscore_get_device_mode(smscore_device_t *coredev) | ||
738 | { | ||
739 | return coredev->mode; | ||
740 | } | ||
741 | |||
742 | smscore_client_t* smscore_getclient_by_type(smscore_device_t *coredev, int data_type) | ||
743 | { | ||
744 | smscore_client_t *client = NULL; | ||
745 | struct list_head *next, *first; | ||
746 | unsigned long flags; | ||
747 | |||
748 | if (!data_type) | ||
749 | return NULL; | ||
750 | |||
751 | spin_lock_irqsave(&coredev->clientslock, flags); | ||
752 | |||
753 | first = &coredev->clients; | ||
754 | |||
755 | for (next = first->next; next != first; next = next->next) | ||
756 | { | ||
757 | if (((smscore_client_t*) next)->data_type == data_type) | ||
758 | { | ||
759 | client = (smscore_client_t*) next; | ||
760 | break; | ||
761 | } | ||
762 | } | ||
763 | |||
764 | spin_unlock_irqrestore(&coredev->clientslock, flags); | ||
765 | |||
766 | return client; | ||
767 | } | ||
768 | |||
769 | smscore_client_t* smscore_getclient_by_id(smscore_device_t *coredev, int id) | ||
770 | { | ||
771 | smscore_client_t *client = NULL; | ||
772 | struct list_head *next, *first; | ||
773 | unsigned long flags; | ||
774 | |||
775 | spin_lock_irqsave(&coredev->clientslock, flags); | ||
776 | |||
777 | first = &coredev->subclients; | ||
778 | |||
779 | for (next = first->next; next != first; next = next->next) | ||
780 | { | ||
781 | if (((smscore_subclient_t*) next)->id == id) | ||
782 | { | ||
783 | client = ((smscore_subclient_t*) next)->client; | ||
784 | break; | ||
785 | } | ||
786 | } | ||
787 | |||
788 | spin_unlock_irqrestore(&coredev->clientslock, flags); | ||
789 | |||
790 | return client; | ||
791 | } | ||
792 | |||
793 | /** | ||
794 | * find client by response id/type, call clients onresponse handler | ||
795 | * return buffer to pool on error | ||
796 | * | ||
797 | * @param coredev pointer to a coredev object returned by smscore_register_device | ||
798 | * @param cb pointer to response buffer descriptor | ||
799 | * | ||
800 | */ | ||
801 | void smscore_onresponse(smscore_device_t *coredev, smscore_buffer_t *cb) | ||
802 | { | ||
803 | SmsMsgHdr_ST *phdr = (SmsMsgHdr_ST *)((u8*) cb->p + cb->offset); | ||
804 | smscore_client_t * client = smscore_getclient_by_type(coredev, phdr->msgType); | ||
805 | int rc = -EBUSY; | ||
806 | |||
807 | static unsigned long last_sample_time = 0; | ||
808 | static int data_total = 0; | ||
809 | unsigned long time_now = jiffies_to_msecs(jiffies); | ||
810 | |||
811 | if (!last_sample_time) | ||
812 | last_sample_time = time_now; | ||
813 | |||
814 | if (time_now - last_sample_time > 10000) | ||
815 | { | ||
816 | printk("\n%s data rate %d bytes/secs\n", __func__, (int)((data_total * 1000) / (time_now - last_sample_time))); | ||
817 | |||
818 | last_sample_time = time_now; | ||
819 | data_total = 0; | ||
820 | } | ||
821 | |||
822 | data_total += cb->size; | ||
823 | |||
824 | if (!client) | ||
825 | client = smscore_getclient_by_id(coredev, phdr->msgDstId); | ||
826 | |||
827 | if (client) | ||
828 | rc = client->onresponse_handler(client->context, cb); | ||
829 | |||
830 | if (rc < 0) | ||
831 | { | ||
832 | switch (phdr->msgType) | ||
833 | { | ||
834 | case MSG_SMS_GET_VERSION_EX_RES: | ||
835 | { | ||
836 | SmsVersionRes_ST *ver = (SmsVersionRes_ST*) phdr; | ||
837 | printk("%s: MSG_SMS_GET_VERSION_EX_RES id %d prots 0x%x ver %d.%d\n", __FUNCTION__, ver->FirmwareId, ver->SupportedProtocols, ver->RomVersionMajor, ver->RomVersionMinor); | ||
838 | |||
839 | coredev->mode = ver->FirmwareId == 255 ? DEVICE_MODE_NONE : ver->FirmwareId; | ||
840 | coredev->modes_supported = ver->SupportedProtocols; | ||
841 | |||
842 | complete(&coredev->version_ex_done); | ||
843 | break; | ||
844 | } | ||
845 | |||
846 | case MSG_SMS_INIT_DEVICE_RES: | ||
847 | printk("%s: MSG_SMS_INIT_DEVICE_RES\n", __FUNCTION__); | ||
848 | complete(&coredev->init_device_done); | ||
849 | break; | ||
850 | |||
851 | case MSG_SW_RELOAD_START_RES: | ||
852 | printk("%s: MSG_SW_RELOAD_START_RES\n", __FUNCTION__); | ||
853 | complete(&coredev->reload_start_done); | ||
854 | break; | ||
855 | |||
856 | case MSG_SMS_DATA_DOWNLOAD_RES: | ||
857 | complete(&coredev->data_download_done); | ||
858 | break; | ||
859 | |||
860 | case MSG_SW_RELOAD_EXEC_RES: | ||
861 | printk("%s: MSG_SW_RELOAD_EXEC_RES\n", __FUNCTION__); | ||
862 | break; | ||
863 | |||
864 | case MSG_SMS_SWDOWNLOAD_TRIGGER_RES: | ||
865 | printk("%s: MSG_SMS_SWDOWNLOAD_TRIGGER_RES\n", __FUNCTION__); | ||
866 | complete(&coredev->trigger_done); | ||
867 | break; | ||
868 | |||
869 | case MSG_SMS_SLEEP_RESUME_COMP_IND: | ||
870 | complete(&coredev->resume_done); | ||
871 | break; | ||
872 | |||
873 | default: | ||
874 | printk(KERN_INFO "%s no client (%p) or error (%d), type:%d dstid:%d\n", __FUNCTION__, client, rc, phdr->msgType, phdr->msgDstId); | ||
875 | } | ||
876 | |||
877 | smscore_putbuffer(coredev, cb); | ||
878 | } | ||
879 | } | ||
880 | |||
881 | /** | ||
882 | * return pointer to next free buffer descriptor from core pool | ||
883 | * | ||
884 | * @param coredev pointer to a coredev object returned by smscore_register_device | ||
885 | * | ||
886 | * @return pointer to descriptor on success, NULL on error. | ||
887 | */ | ||
888 | smscore_buffer_t *smscore_getbuffer(smscore_device_t *coredev) | ||
889 | { | ||
890 | smscore_buffer_t *cb = NULL; | ||
891 | unsigned long flags; | ||
892 | |||
893 | spin_lock_irqsave(&coredev->bufferslock, flags); | ||
894 | |||
895 | if (!list_empty(&coredev->buffers)) | ||
896 | { | ||
897 | cb = (smscore_buffer_t *) coredev->buffers.next; | ||
898 | list_del(&cb->entry); | ||
899 | } | ||
900 | |||
901 | spin_unlock_irqrestore(&coredev->bufferslock, flags); | ||
902 | |||
903 | return cb; | ||
904 | } | ||
905 | |||
906 | /** | ||
907 | * return buffer descriptor to a pool | ||
908 | * | ||
909 | * @param coredev pointer to a coredev object returned by smscore_register_device | ||
910 | * @param cb pointer buffer descriptor | ||
911 | * | ||
912 | */ | ||
913 | void smscore_putbuffer(smscore_device_t *coredev, smscore_buffer_t *cb) | ||
914 | { | ||
915 | list_add_locked(&cb->entry, &coredev->buffers, &coredev->bufferslock); | ||
916 | } | ||
917 | |||
918 | int smscore_validate_client(smscore_device_t *coredev, smscore_client_t *client, int id) | ||
919 | { | ||
920 | smscore_client_t *existing_client; | ||
921 | smscore_subclient_t *subclient; | ||
922 | |||
923 | if (!id) | ||
924 | return 0; | ||
925 | |||
926 | existing_client = smscore_getclient_by_id(coredev, id); | ||
927 | if (existing_client == client) | ||
928 | return 0; | ||
929 | |||
930 | if (existing_client) | ||
931 | return -EBUSY; | ||
932 | |||
933 | subclient = kzalloc(sizeof(smscore_subclient_t), GFP_KERNEL); | ||
934 | if (!subclient) | ||
935 | return -ENOMEM; | ||
936 | |||
937 | subclient->client = client; | ||
938 | subclient->id = id; | ||
939 | |||
940 | list_add_locked(&subclient->entry, &coredev->subclients, &coredev->clientslock); | ||
941 | |||
942 | return 0; | ||
943 | } | ||
944 | |||
945 | /** | ||
946 | * creates smsclient object, check that id is taken by another client | ||
947 | * | ||
948 | * @param coredev pointer to a coredev object from clients hotplug | ||
949 | * @param initial_id all messages with this id would be sent to this client | ||
950 | * @param data_type all messages of this type would be sent to this client | ||
951 | * @param onresponse_handler client handler that is called to process incoming messages | ||
952 | * @param onremove_handler client handler that is called when device is removed | ||
953 | * @param context client-specific context | ||
954 | * @param client pointer to a value that receives created smsclient object | ||
955 | * | ||
956 | * @return 0 on success, <0 on error. | ||
957 | */ | ||
958 | int smscore_register_client(smscore_device_t *coredev, smsclient_params_t *params, smscore_client_t **client) | ||
959 | { | ||
960 | smscore_client_t* newclient; | ||
961 | int rc; | ||
962 | |||
963 | // check that no other channel with same data type exists | ||
964 | if (params->data_type && smscore_getclient_by_type(coredev, params->data_type)) | ||
965 | return -EEXIST; | ||
966 | |||
967 | newclient = kzalloc(sizeof(smscore_client_t), GFP_KERNEL); | ||
968 | if (!newclient) | ||
969 | return -ENOMEM; | ||
970 | |||
971 | // check that no other channel with same id exists | ||
972 | rc = smscore_validate_client(coredev, newclient, params->initial_id); | ||
973 | if (rc < 0) | ||
974 | { | ||
975 | kfree(newclient); | ||
976 | return rc; | ||
977 | } | ||
978 | |||
979 | newclient->coredev = coredev; | ||
980 | newclient->data_type = params->data_type; | ||
981 | newclient->onresponse_handler = params->onresponse_handler; | ||
982 | newclient->onremove_handler = params->onremove_handler; | ||
983 | newclient->context = params->context; | ||
984 | |||
985 | list_add_locked(&newclient->entry, &coredev->clients, &coredev->clientslock); | ||
986 | |||
987 | *client = newclient; | ||
988 | |||
989 | printk(KERN_INFO "%s %p %d %d\n", __FUNCTION__, params->context, params->data_type, params->initial_id); | ||
990 | |||
991 | return 0; | ||
992 | } | ||
993 | |||
994 | /** | ||
995 | * frees smsclient object and all subclients associated with it | ||
996 | * | ||
997 | * @param client pointer to smsclient object returned by smscore_register_client | ||
998 | * | ||
999 | */ | ||
1000 | void smscore_unregister_client(smscore_client_t *client) | ||
1001 | { | ||
1002 | smscore_device_t *coredev = client->coredev; | ||
1003 | struct list_head *next, *first; | ||
1004 | unsigned long flags; | ||
1005 | |||
1006 | spin_lock_irqsave(&coredev->clientslock, flags); | ||
1007 | |||
1008 | first = &coredev->subclients; | ||
1009 | |||
1010 | for (next = first->next; next != first;) | ||
1011 | { | ||
1012 | smscore_subclient_t *subclient = (smscore_subclient_t *) next; | ||
1013 | next = next->next; | ||
1014 | |||
1015 | if (subclient->client == client) | ||
1016 | { | ||
1017 | list_del(&subclient->entry); | ||
1018 | kfree(subclient); | ||
1019 | } | ||
1020 | } | ||
1021 | |||
1022 | printk(KERN_INFO "%s %p %d\n", __FUNCTION__, client->context, client->data_type); | ||
1023 | |||
1024 | list_del(&client->entry); | ||
1025 | kfree(client); | ||
1026 | |||
1027 | spin_unlock_irqrestore(&coredev->clientslock, flags); | ||
1028 | } | ||
1029 | |||
1030 | /** | ||
1031 | * verifies that source id is not taken by another client, | ||
1032 | * calls device handler to send requests to the device | ||
1033 | * | ||
1034 | * @param client pointer to smsclient object returned by smscore_register_client | ||
1035 | * @param buffer pointer to a request buffer | ||
1036 | * @param size size (in bytes) of request buffer | ||
1037 | * | ||
1038 | * @return 0 on success, <0 on error. | ||
1039 | */ | ||
1040 | int smsclient_sendrequest(smscore_client_t *client, void *buffer, size_t size) | ||
1041 | { | ||
1042 | smscore_device_t* coredev = client->coredev; | ||
1043 | SmsMsgHdr_ST* phdr = (SmsMsgHdr_ST*) buffer; | ||
1044 | |||
1045 | // check that no other channel with same id exists | ||
1046 | int rc = smscore_validate_client(client->coredev, client, phdr->msgSrcId); | ||
1047 | if (rc < 0) | ||
1048 | return rc; | ||
1049 | |||
1050 | return coredev->sendrequest_handler(coredev->context, buffer, size); | ||
1051 | } | ||
1052 | |||
1053 | /** | ||
1054 | * return the size of large (common) buffer | ||
1055 | * | ||
1056 | * @param coredev pointer to a coredev object from clients hotplug | ||
1057 | * | ||
1058 | * @return size (in bytes) of the buffer | ||
1059 | */ | ||
1060 | int smscore_get_common_buffer_size(smscore_device_t *coredev) | ||
1061 | { | ||
1062 | return coredev->common_buffer_size; | ||
1063 | } | ||
1064 | |||
1065 | /** | ||
1066 | * maps common buffer (if supported by platform) | ||
1067 | * | ||
1068 | * @param coredev pointer to a coredev object from clients hotplug | ||
1069 | * @param vma pointer to vma struct from mmap handler | ||
1070 | * | ||
1071 | * @return 0 on success, <0 on error. | ||
1072 | */ | ||
1073 | int smscore_map_common_buffer(smscore_device_t *coredev, struct vm_area_struct * vma) | ||
1074 | { | ||
1075 | unsigned long end = vma->vm_end, start = vma->vm_start, size = PAGE_ALIGN(coredev->common_buffer_size); | ||
1076 | |||
1077 | if (!(vma->vm_flags & (VM_READ | VM_SHARED)) || (vma->vm_flags & VM_WRITE)) | ||
1078 | { | ||
1079 | printk(KERN_INFO "%s invalid vm flags\n", __FUNCTION__); | ||
1080 | return -EINVAL; | ||
1081 | } | ||
1082 | |||
1083 | if ((end - start) != size) | ||
1084 | { | ||
1085 | printk(KERN_INFO "%s invalid size %d expected %d\n", __FUNCTION__, (int)(end - start), (int) size); | ||
1086 | return -EINVAL; | ||
1087 | } | ||
1088 | |||
1089 | if (remap_pfn_range(vma, start, coredev->common_buffer_phys >> PAGE_SHIFT, size, pgprot_noncached(vma->vm_page_prot))) | ||
1090 | { | ||
1091 | printk(KERN_INFO "%s remap_page_range failed\n", __FUNCTION__); | ||
1092 | return -EAGAIN; | ||
1093 | } | ||
1094 | |||
1095 | return 0; | ||
1096 | } | ||
1097 | |||
1098 | int smscore_module_init(void) | ||
1099 | { | ||
1100 | int rc = 0; | ||
1101 | |||
1102 | INIT_LIST_HEAD(&g_smscore_notifyees); | ||
1103 | INIT_LIST_HEAD(&g_smscore_devices); | ||
1104 | kmutex_init(&g_smscore_deviceslock); | ||
1105 | |||
1106 | INIT_LIST_HEAD(&g_smscore_registry); | ||
1107 | kmutex_init(&g_smscore_registrylock); | ||
1108 | |||
1109 | /* USB Register */ | ||
1110 | rc = smsusb_register(); | ||
1111 | |||
1112 | /* DVB Register */ | ||
1113 | rc = smsdvb_register(); | ||
1114 | |||
1115 | printk(KERN_INFO "%s, rc %d\n", __FUNCTION__, rc); | ||
1116 | |||
1117 | return rc; | ||
1118 | } | ||
1119 | |||
1120 | void smscore_module_exit(void) | ||
1121 | { | ||
1122 | |||
1123 | kmutex_lock(&g_smscore_deviceslock); | ||
1124 | while (!list_empty(&g_smscore_notifyees)) | ||
1125 | { | ||
1126 | smscore_device_notifyee_t *notifyee = (smscore_device_notifyee_t *) g_smscore_notifyees.next; | ||
1127 | |||
1128 | list_del(¬ifyee->entry); | ||
1129 | kfree(notifyee); | ||
1130 | } | ||
1131 | kmutex_unlock(&g_smscore_deviceslock); | ||
1132 | |||
1133 | kmutex_lock(&g_smscore_registrylock); | ||
1134 | while (!list_empty(&g_smscore_registry)) | ||
1135 | { | ||
1136 | smscore_registry_entry_t *entry = (smscore_registry_entry_t *) g_smscore_registry.next; | ||
1137 | |||
1138 | list_del(&entry->entry); | ||
1139 | kfree(entry); | ||
1140 | } | ||
1141 | kmutex_unlock(&g_smscore_registrylock); | ||
1142 | |||
1143 | /* DVB UnRegister */ | ||
1144 | smsdvb_unregister(); | ||
1145 | |||
1146 | /* Unregister USB */ | ||
1147 | smsusb_unregister(); | ||
1148 | |||
1149 | printk(KERN_INFO "%s\n", __FUNCTION__); | ||
1150 | } | ||
1151 | |||
1152 | module_init(smscore_module_init); | ||
1153 | module_exit(smscore_module_exit); | ||
1154 | |||
1155 | MODULE_DESCRIPTION("smscore"); | ||
1156 | MODULE_AUTHOR("Anatoly Greenblatt,,, (anatolyg@siano-ms.com)"); | ||
1157 | MODULE_LICENSE("GPL"); | ||
1158 | |||