2 * Siano core API module
4 * This file contains implementation for the interface to sms core component
8 * Copyright (c), 2005-2008 Siano Mobile Silicon, Inc.
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 2 as
12 * published by the Free Software Foundation;
14 * Software distributed under the License is distributed on an "AS IS"
15 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
17 * See the GNU General Public License for more details.
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.
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>
31 #include <linux/slab.h>
33 #include <linux/firmware.h>
34 #include <linux/wait.h>
35 #include <asm/byteorder.h>
37 #include "smscoreapi.h"
38 #include "sms-cards.h"
40 #include "smsendian.h"
43 module_param_named(debug
, sms_dbg
, int, 0644);
44 MODULE_PARM_DESC(debug
, "set debug level (info=1, adv=2 (or-able))");
46 struct smscore_device_notifyee_t
{
47 struct list_head entry
;
51 struct smscore_idlist_t
{
52 struct list_head entry
;
57 struct smscore_client_t
{
58 struct list_head entry
;
59 struct smscore_device_t
*coredev
;
61 struct list_head idlist
;
62 onresponse_t onresponse_handler
;
63 onremove_t onremove_handler
;
66 void smscore_set_board_id(struct smscore_device_t
*core
, int id
)
71 int smscore_led_state(struct smscore_device_t
*core
, int led
)
74 core
->led_state
= led
;
75 return core
->led_state
;
77 EXPORT_SYMBOL_GPL(smscore_set_board_id
);
79 int smscore_get_board_id(struct smscore_device_t
*core
)
81 return core
->board_id
;
83 EXPORT_SYMBOL_GPL(smscore_get_board_id
);
85 struct smscore_registry_entry_t
{
86 struct list_head entry
;
89 enum sms_device_type_st type
;
92 static struct list_head g_smscore_notifyees
;
93 static struct list_head g_smscore_devices
;
94 static struct mutex g_smscore_deviceslock
;
96 static struct list_head g_smscore_registry
;
97 static struct mutex g_smscore_registrylock
;
99 static int default_mode
= 4;
101 module_param(default_mode
, int, 0644);
102 MODULE_PARM_DESC(default_mode
, "default firmware id (device mode)");
104 static struct smscore_registry_entry_t
*smscore_find_registry(char *devpath
)
106 struct smscore_registry_entry_t
*entry
;
107 struct list_head
*next
;
109 kmutex_lock(&g_smscore_registrylock
);
110 for (next
= g_smscore_registry
.next
;
111 next
!= &g_smscore_registry
;
113 entry
= (struct smscore_registry_entry_t
*) next
;
114 if (!strcmp(entry
->devpath
, devpath
)) {
115 kmutex_unlock(&g_smscore_registrylock
);
119 entry
= (struct smscore_registry_entry_t
*)
120 kmalloc(sizeof(struct smscore_registry_entry_t
),
123 entry
->mode
= default_mode
;
124 strcpy(entry
->devpath
, devpath
);
125 list_add(&entry
->entry
, &g_smscore_registry
);
127 sms_err("failed to create smscore_registry.");
128 kmutex_unlock(&g_smscore_registrylock
);
132 int smscore_registry_getmode(char *devpath
)
134 struct smscore_registry_entry_t
*entry
;
136 entry
= smscore_find_registry(devpath
);
140 sms_err("No registry found.");
144 EXPORT_SYMBOL_GPL(smscore_registry_getmode
);
146 static enum sms_device_type_st
smscore_registry_gettype(char *devpath
)
148 struct smscore_registry_entry_t
*entry
;
150 entry
= smscore_find_registry(devpath
);
154 sms_err("No registry found.");
159 void smscore_registry_setmode(char *devpath
, int mode
)
161 struct smscore_registry_entry_t
*entry
;
163 entry
= smscore_find_registry(devpath
);
167 sms_err("No registry found.");
170 static void smscore_registry_settype(char *devpath
,
171 enum sms_device_type_st type
)
173 struct smscore_registry_entry_t
*entry
;
175 entry
= smscore_find_registry(devpath
);
179 sms_err("No registry found.");
183 static void list_add_locked(struct list_head
*new, struct list_head
*head
,
188 spin_lock_irqsave(lock
, flags
);
192 spin_unlock_irqrestore(lock
, flags
);
196 * register a client callback that called when device plugged in/unplugged
197 * NOTE: if devices exist callback is called immediately for each device
199 * @param hotplug callback
201 * @return 0 on success, <0 on error.
203 int smscore_register_hotplug(hotplug_t hotplug
)
205 struct smscore_device_notifyee_t
*notifyee
;
206 struct list_head
*next
, *first
;
209 kmutex_lock(&g_smscore_deviceslock
);
211 notifyee
= kmalloc(sizeof(struct smscore_device_notifyee_t
),
214 /* now notify callback about existing devices */
215 first
= &g_smscore_devices
;
216 for (next
= first
->next
;
217 next
!= first
&& !rc
;
219 struct smscore_device_t
*coredev
=
220 (struct smscore_device_t
*) next
;
221 rc
= hotplug(coredev
, coredev
->device
, 1);
225 notifyee
->hotplug
= hotplug
;
226 list_add(¬ifyee
->entry
, &g_smscore_notifyees
);
232 kmutex_unlock(&g_smscore_deviceslock
);
236 EXPORT_SYMBOL_GPL(smscore_register_hotplug
);
239 * unregister a client callback that called when device plugged in/unplugged
241 * @param hotplug callback
244 void smscore_unregister_hotplug(hotplug_t hotplug
)
246 struct list_head
*next
, *first
;
248 kmutex_lock(&g_smscore_deviceslock
);
250 first
= &g_smscore_notifyees
;
252 for (next
= first
->next
; next
!= first
;) {
253 struct smscore_device_notifyee_t
*notifyee
=
254 (struct smscore_device_notifyee_t
*) next
;
257 if (notifyee
->hotplug
== hotplug
) {
258 list_del(¬ifyee
->entry
);
263 kmutex_unlock(&g_smscore_deviceslock
);
265 EXPORT_SYMBOL_GPL(smscore_unregister_hotplug
);
267 static void smscore_notify_clients(struct smscore_device_t
*coredev
)
269 struct smscore_client_t
*client
;
271 /* the client must call smscore_unregister_client from remove handler */
272 while (!list_empty(&coredev
->clients
)) {
273 client
= (struct smscore_client_t
*) coredev
->clients
.next
;
274 client
->onremove_handler(client
->context
);
278 static int smscore_notify_callbacks(struct smscore_device_t
*coredev
,
279 struct device
*device
, int arrival
)
281 struct list_head
*next
, *first
;
284 /* note: must be called under g_deviceslock */
286 first
= &g_smscore_notifyees
;
288 for (next
= first
->next
; next
!= first
; next
= next
->next
) {
289 rc
= ((struct smscore_device_notifyee_t
*) next
)->
290 hotplug(coredev
, device
, arrival
);
299 smscore_buffer_t
*smscore_createbuffer(u8
*buffer
, void *common_buffer
,
300 dma_addr_t common_buffer_phys
)
302 struct smscore_buffer_t
*cb
=
303 kmalloc(sizeof(struct smscore_buffer_t
), GFP_KERNEL
);
305 sms_info("kmalloc(...) failed");
310 cb
->offset_in_common
= buffer
- (u8
*) common_buffer
;
311 cb
->phys
= common_buffer_phys
+ cb
->offset_in_common
;
317 * creates coredev object for a device, prepares buffers,
318 * creates buffer mappings, notifies registered hotplugs about new device.
320 * @param params device pointer to struct with device specific parameters
322 * @param coredev pointer to a value that receives created coredev object
324 * @return 0 on success, <0 on error.
326 int smscore_register_device(struct smsdevice_params_t
*params
,
327 struct smscore_device_t
**coredev
)
329 struct smscore_device_t
*dev
;
332 dev
= kzalloc(sizeof(struct smscore_device_t
), GFP_KERNEL
);
334 sms_info("kzalloc(...) failed");
338 /* init list entry so it could be safe in smscore_unregister_device */
339 INIT_LIST_HEAD(&dev
->entry
);
342 INIT_LIST_HEAD(&dev
->clients
);
343 INIT_LIST_HEAD(&dev
->buffers
);
346 spin_lock_init(&dev
->clientslock
);
347 spin_lock_init(&dev
->bufferslock
);
349 /* init completion events */
350 init_completion(&dev
->version_ex_done
);
351 init_completion(&dev
->data_download_done
);
352 init_completion(&dev
->trigger_done
);
353 init_completion(&dev
->init_device_done
);
354 init_completion(&dev
->reload_start_done
);
355 init_completion(&dev
->resume_done
);
356 init_completion(&dev
->gpio_configuration_done
);
357 init_completion(&dev
->gpio_set_level_done
);
358 init_completion(&dev
->gpio_get_level_done
);
359 init_completion(&dev
->ir_init_done
);
361 /* Buffer management */
362 init_waitqueue_head(&dev
->buffer_mng_waitq
);
364 /* alloc common buffer */
365 dev
->common_buffer_size
= params
->buffer_size
* params
->num_buffers
;
366 dev
->common_buffer
= dma_alloc_coherent(NULL
, dev
->common_buffer_size
,
367 &dev
->common_buffer_phys
,
368 GFP_KERNEL
| GFP_DMA
);
369 if (!dev
->common_buffer
) {
370 smscore_unregister_device(dev
);
374 /* prepare dma buffers */
375 for (buffer
= dev
->common_buffer
;
376 dev
->num_buffers
< params
->num_buffers
;
377 dev
->num_buffers
++, buffer
+= params
->buffer_size
) {
378 struct smscore_buffer_t
*cb
=
379 smscore_createbuffer(buffer
, dev
->common_buffer
,
380 dev
->common_buffer_phys
);
382 smscore_unregister_device(dev
);
386 smscore_putbuffer(dev
, cb
);
389 sms_info("allocated %d buffers", dev
->num_buffers
);
391 dev
->mode
= DEVICE_MODE_NONE
;
392 dev
->context
= params
->context
;
393 dev
->device
= params
->device
;
394 dev
->setmode_handler
= params
->setmode_handler
;
395 dev
->detectmode_handler
= params
->detectmode_handler
;
396 dev
->sendrequest_handler
= params
->sendrequest_handler
;
397 dev
->preload_handler
= params
->preload_handler
;
398 dev
->postload_handler
= params
->postload_handler
;
400 dev
->device_flags
= params
->flags
;
401 strcpy(dev
->devpath
, params
->devpath
);
403 smscore_registry_settype(dev
->devpath
, params
->device_type
);
405 /* add device to devices list */
406 kmutex_lock(&g_smscore_deviceslock
);
407 list_add(&dev
->entry
, &g_smscore_devices
);
408 kmutex_unlock(&g_smscore_deviceslock
);
412 sms_info("device %p created", dev
);
416 EXPORT_SYMBOL_GPL(smscore_register_device
);
419 static int smscore_sendrequest_and_wait(struct smscore_device_t
*coredev
,
420 void *buffer
, size_t size
, struct completion
*completion
) {
421 int rc
= coredev
->sendrequest_handler(coredev
->context
, buffer
, size
);
423 sms_info("sendrequest returned error %d", rc
);
427 return wait_for_completion_timeout(completion
,
428 msecs_to_jiffies(SMS_PROTOCOL_MAX_RAOUNDTRIP_MS
)) ?
433 * Starts & enables IR operations
435 * @return 0 on success, < 0 on error.
437 static int smscore_init_ir(struct smscore_device_t
*coredev
)
443 coredev
->ir
.input_dev
= NULL
;
444 ir_io
= sms_get_board(smscore_get_board_id(coredev
))->board_cfg
.ir
;
445 if (ir_io
) {/* only if IR port exist we use IR sub-module */
446 sms_info("IR loading");
447 rc
= sms_ir_init(coredev
);
450 sms_err("Error initialization DTV IR sub-module");
452 buffer
= kmalloc(sizeof(struct SmsMsgData_ST2
) +
454 GFP_KERNEL
| GFP_DMA
);
456 struct SmsMsgData_ST2
*msg
=
457 (struct SmsMsgData_ST2
*)
458 SMS_ALIGN_ADDRESS(buffer
);
460 SMS_INIT_MSG(&msg
->xMsgHeader
,
461 MSG_SMS_START_IR_REQ
,
462 sizeof(struct SmsMsgData_ST2
));
463 msg
->msgData
[0] = coredev
->ir
.controller
;
464 msg
->msgData
[1] = coredev
->ir
.timeout
;
466 smsendian_handle_tx_message(
467 (struct SmsMsgHdr_ST2
*)msg
);
468 rc
= smscore_sendrequest_and_wait(coredev
, msg
,
469 msg
->xMsgHeader
. msgLength
,
470 &coredev
->ir_init_done
);
475 ("Sending IR initialization message failed");
478 sms_info("IR port has not been detected");
484 * sets initial device mode and notifies client hotplugs that device is ready
486 * @param coredev pointer to a coredev object returned by
487 * smscore_register_device
489 * @return 0 on success, <0 on error.
491 int smscore_start_device(struct smscore_device_t
*coredev
)
493 int rc
= smscore_set_device_mode(
494 coredev
, smscore_registry_getmode(coredev
->devpath
));
496 sms_info("set device mode faile , rc %d", rc
);
500 kmutex_lock(&g_smscore_deviceslock
);
502 rc
= smscore_notify_callbacks(coredev
, coredev
->device
, 1);
503 smscore_init_ir(coredev
);
505 sms_info("device %p started, rc %d", coredev
, rc
);
507 kmutex_unlock(&g_smscore_deviceslock
);
511 EXPORT_SYMBOL_GPL(smscore_start_device
);
514 static int smscore_load_firmware_family2(struct smscore_device_t
*coredev
,
515 void *buffer
, size_t size
)
517 struct SmsFirmware_ST
*firmware
= (struct SmsFirmware_ST
*) buffer
;
518 struct SmsMsgHdr_ST
*msg
;
520 u8
*payload
= firmware
->Payload
;
522 firmware
->StartAddress
= le32_to_cpu(firmware
->StartAddress
);
523 firmware
->Length
= le32_to_cpu(firmware
->Length
);
525 mem_address
= firmware
->StartAddress
;
527 sms_info("loading FW to addr 0x%x size %d",
528 mem_address
, firmware
->Length
);
529 if (coredev
->preload_handler
) {
530 rc
= coredev
->preload_handler(coredev
->context
);
535 /* PAGE_SIZE buffer shall be enough and dma aligned */
536 msg
= kmalloc(PAGE_SIZE
, GFP_KERNEL
| GFP_DMA
);
540 if (coredev
->mode
!= DEVICE_MODE_NONE
) {
541 sms_debug("sending reload command.");
542 SMS_INIT_MSG(msg
, MSG_SW_RELOAD_START_REQ
,
543 sizeof(struct SmsMsgHdr_ST
));
544 rc
= smscore_sendrequest_and_wait(coredev
, msg
,
546 &coredev
->reload_start_done
);
547 mem_address
= *(u32
*) &payload
[20];
550 while (size
&& rc
>= 0) {
551 struct SmsDataDownload_ST
*DataMsg
=
552 (struct SmsDataDownload_ST
*) msg
;
553 int payload_size
= min((int) size
, SMS_MAX_PAYLOAD_SIZE
);
555 SMS_INIT_MSG(msg
, MSG_SMS_DATA_DOWNLOAD_REQ
,
556 (u16
)(sizeof(struct SmsMsgHdr_ST
) +
557 sizeof(u32
) + payload_size
));
559 DataMsg
->MemAddr
= mem_address
;
560 memcpy(DataMsg
->Payload
, payload
, payload_size
);
562 if ((coredev
->device_flags
& SMS_ROM_NO_RESPONSE
) &&
563 (coredev
->mode
== DEVICE_MODE_NONE
))
564 rc
= coredev
->sendrequest_handler(
565 coredev
->context
, DataMsg
,
566 DataMsg
->xMsgHeader
.msgLength
);
568 rc
= smscore_sendrequest_and_wait(
570 DataMsg
->xMsgHeader
.msgLength
,
571 &coredev
->data_download_done
);
573 payload
+= payload_size
;
574 size
-= payload_size
;
575 mem_address
+= payload_size
;
579 if (coredev
->mode
== DEVICE_MODE_NONE
) {
580 struct SmsMsgData_ST
*TriggerMsg
=
581 (struct SmsMsgData_ST
*) msg
;
583 SMS_INIT_MSG(msg
, MSG_SMS_SWDOWNLOAD_TRIGGER_REQ
,
584 sizeof(struct SmsMsgHdr_ST
) +
587 TriggerMsg
->msgData
[0] = firmware
->StartAddress
;
589 TriggerMsg
->msgData
[1] = 5; /* Priority */
590 TriggerMsg
->msgData
[2] = 0x200; /* Stack size */
591 TriggerMsg
->msgData
[3] = 0; /* Parameter */
592 TriggerMsg
->msgData
[4] = 4; /* Task ID */
594 if (coredev
->device_flags
& SMS_ROM_NO_RESPONSE
) {
595 rc
= coredev
->sendrequest_handler(
596 coredev
->context
, TriggerMsg
,
597 TriggerMsg
->xMsgHeader
.msgLength
);
600 rc
= smscore_sendrequest_and_wait(
602 TriggerMsg
->xMsgHeader
.msgLength
,
603 &coredev
->trigger_done
);
605 SMS_INIT_MSG(msg
, MSG_SW_RELOAD_EXEC_REQ
,
606 sizeof(struct SmsMsgHdr_ST
));
608 rc
= coredev
->sendrequest_handler(coredev
->context
,
609 msg
, msg
->msgLength
);
614 sms_debug("rc=%d, postload=%p ", rc
,
615 coredev
->postload_handler
);
619 return ((rc
>= 0) && coredev
->postload_handler
) ?
620 coredev
->postload_handler(coredev
->context
) :
625 * loads specified firmware into a buffer and calls device loadfirmware_handler
627 * @param coredev pointer to a coredev object returned by
628 * smscore_register_device
629 * @param filename null-terminated string specifies firmware file name
630 * @param loadfirmware_handler device handler that loads firmware
632 * @return 0 on success, <0 on error.
634 static int smscore_load_firmware_from_file(struct smscore_device_t
*coredev
,
636 loadfirmware_t loadfirmware_handler
)
639 const struct firmware
*fw
;
642 if (loadfirmware_handler
== NULL
&& !(coredev
->device_flags
&
646 rc
= request_firmware(&fw
, filename
, coredev
->device
);
648 sms_info("failed to open \"%s\"", filename
);
651 sms_info("read FW %s, size=%zd", filename
, fw
->size
);
652 fw_buffer
= kmalloc(ALIGN(fw
->size
, SMS_ALLOC_ALIGNMENT
),
653 GFP_KERNEL
| GFP_DMA
);
655 memcpy(fw_buffer
, fw
->data
, fw
->size
);
657 rc
= (coredev
->device_flags
& SMS_DEVICE_FAMILY2
) ?
658 smscore_load_firmware_family2(coredev
,
661 loadfirmware_handler(coredev
->context
,
662 fw_buffer
, fw
->size
);
666 sms_info("failed to allocate firmware buffer");
670 release_firmware(fw
);
676 * notifies all clients registered with the device, notifies hotplugs,
677 * frees all buffers and coredev object
679 * @param coredev pointer to a coredev object returned by
680 * smscore_register_device
682 * @return 0 on success, <0 on error.
684 void smscore_unregister_device(struct smscore_device_t
*coredev
)
686 struct smscore_buffer_t
*cb
;
690 kmutex_lock(&g_smscore_deviceslock
);
692 /* Release input device (IR) resources */
693 sms_ir_exit(coredev
);
695 smscore_notify_clients(coredev
);
696 smscore_notify_callbacks(coredev
, NULL
, 0);
698 /* at this point all buffers should be back
699 * onresponse must no longer be called */
702 while (!list_empty(&coredev
->buffers
)) {
703 cb
= (struct smscore_buffer_t
*) coredev
->buffers
.next
;
704 list_del(&cb
->entry
);
708 if (num_buffers
== coredev
->num_buffers
)
711 sms_info("exiting although "
712 "not all buffers released.");
716 sms_info("waiting for %d buffer(s)",
717 coredev
->num_buffers
- num_buffers
);
721 sms_info("freed %d buffers", num_buffers
);
723 if (coredev
->common_buffer
)
724 dma_free_coherent(NULL
, coredev
->common_buffer_size
,
725 coredev
->common_buffer
, coredev
->common_buffer_phys
);
727 if (coredev
->fw_buf
!= NULL
)
728 kfree(coredev
->fw_buf
);
730 list_del(&coredev
->entry
);
733 kmutex_unlock(&g_smscore_deviceslock
);
735 sms_info("device %p destroyed", coredev
);
737 EXPORT_SYMBOL_GPL(smscore_unregister_device
);
739 static int smscore_detect_mode(struct smscore_device_t
*coredev
)
741 void *buffer
= kmalloc(sizeof(struct SmsMsgHdr_ST
) + SMS_DMA_ALIGNMENT
,
742 GFP_KERNEL
| GFP_DMA
);
743 struct SmsMsgHdr_ST
*msg
=
744 (struct SmsMsgHdr_ST
*) SMS_ALIGN_ADDRESS(buffer
);
750 SMS_INIT_MSG(msg
, MSG_SMS_GET_VERSION_EX_REQ
,
751 sizeof(struct SmsMsgHdr_ST
));
753 rc
= smscore_sendrequest_and_wait(coredev
, msg
, msg
->msgLength
,
754 &coredev
->version_ex_done
);
756 sms_err("MSG_SMS_GET_VERSION_EX_REQ failed first try");
758 if (wait_for_completion_timeout(&coredev
->resume_done
,
759 msecs_to_jiffies(5000))) {
760 rc
= smscore_sendrequest_and_wait(
761 coredev
, msg
, msg
->msgLength
,
762 &coredev
->version_ex_done
);
764 sms_err("MSG_SMS_GET_VERSION_EX_REQ failed "
765 "second try, rc %d", rc
);
775 static char *smscore_fw_lkup
[][SMS_NUM_OF_DEVICE_TYPES
] = {
776 /*Stellar NOVA A0 Nova B0 VEGA*/
778 {"none", "dvb_nova_12mhz.inp", "dvb_nova_12mhz_b0.inp", "none"},
780 {"none", "dvb_nova_12mhz.inp", "dvb_nova_12mhz_b0.inp", "none"},
782 {"none", "tdmb_nova_12mhz.inp", "tdmb_nova_12mhz_b0.inp", "none"},
784 {"none", "none", "none", "none"},
786 {"none", "dvb_nova_12mhz.inp", "dvb_nova_12mhz_b0.inp", "none"},
788 {"none", "isdbt_nova_12mhz.inp", "isdbt_nova_12mhz_b0.inp", "none"},
790 {"none", "isdbt_nova_12mhz.inp", "isdbt_nova_12mhz_b0.inp", "none"},
792 {"none", "none", "none", "cmmb_vega_12mhz.inp"}
795 static inline char *sms_get_fw_name(struct smscore_device_t
*coredev
,
796 int mode
, enum sms_device_type_st type
)
798 char **fw
= sms_get_board(smscore_get_board_id(coredev
))->fw
;
799 return (fw
&& fw
[mode
]) ? fw
[mode
] : smscore_fw_lkup
[mode
][type
];
803 * calls device handler to change mode of operation
804 * NOTE: stellar/usb may disconnect when changing mode
806 * @param coredev pointer to a coredev object returned by
807 * smscore_register_device
808 * @param mode requested mode of operation
810 * @return 0 on success, <0 on error.
812 int smscore_set_device_mode(struct smscore_device_t
*coredev
, int mode
)
816 enum sms_device_type_st type
;
818 sms_debug("set device mode to %d", mode
);
819 if (coredev
->device_flags
& SMS_DEVICE_FAMILY2
) {
820 if (mode
< DEVICE_MODE_DVBT
|| mode
>= DEVICE_MODE_RAW_TUNER
) {
821 sms_err("invalid mode specified %d", mode
);
825 smscore_registry_setmode(coredev
->devpath
, mode
);
827 if (!(coredev
->device_flags
& SMS_DEVICE_NOT_READY
)) {
828 rc
= smscore_detect_mode(coredev
);
830 sms_err("mode detect failed %d", rc
);
835 if (coredev
->mode
== mode
) {
836 sms_info("device mode %d already set", mode
);
840 if (!(coredev
->modes_supported
& (1 << mode
))) {
843 type
= smscore_registry_gettype(coredev
->devpath
);
844 fw_filename
= sms_get_fw_name(coredev
, mode
, type
);
846 rc
= smscore_load_firmware_from_file(coredev
,
849 sms_warn("error %d loading firmware: %s, "
850 "trying again with default firmware",
853 /* try again with the default firmware */
854 fw_filename
= smscore_fw_lkup
[mode
][type
];
855 rc
= smscore_load_firmware_from_file(coredev
,
859 sms_warn("error %d loading "
865 sms_log("firmware download success: %s", fw_filename
);
867 sms_info("mode %d supported by running "
870 buffer
= kmalloc(sizeof(struct SmsMsgData_ST
) +
871 SMS_DMA_ALIGNMENT
, GFP_KERNEL
| GFP_DMA
);
873 struct SmsMsgData_ST
*msg
=
874 (struct SmsMsgData_ST
*)
875 SMS_ALIGN_ADDRESS(buffer
);
877 SMS_INIT_MSG(&msg
->xMsgHeader
, MSG_SMS_INIT_DEVICE_REQ
,
878 sizeof(struct SmsMsgData_ST
));
879 msg
->msgData
[0] = mode
;
881 rc
= smscore_sendrequest_and_wait(
882 coredev
, msg
, msg
->xMsgHeader
.msgLength
,
883 &coredev
->init_device_done
);
887 sms_err("Could not allocate buffer for "
888 "init device message.");
892 if (mode
< DEVICE_MODE_DVBT
|| mode
> DEVICE_MODE_DVBT_BDA
) {
893 sms_err("invalid mode specified %d", mode
);
897 smscore_registry_setmode(coredev
->devpath
, mode
);
899 if (coredev
->detectmode_handler
)
900 coredev
->detectmode_handler(coredev
->context
,
903 if (coredev
->mode
!= mode
&& coredev
->setmode_handler
)
904 rc
= coredev
->setmode_handler(coredev
->context
, mode
);
908 coredev
->mode
= mode
;
909 coredev
->device_flags
&= ~SMS_DEVICE_NOT_READY
;
913 sms_err("return error code %d.", rc
);
918 * calls device handler to get current mode of operation
920 * @param coredev pointer to a coredev object returned by
921 * smscore_register_device
923 * @return current mode
925 int smscore_get_device_mode(struct smscore_device_t
*coredev
)
927 return coredev
->mode
;
929 EXPORT_SYMBOL_GPL(smscore_get_device_mode
);
932 * find client by response id & type within the clients list.
933 * return client handle or NULL.
935 * @param coredev pointer to a coredev object returned by
936 * smscore_register_device
937 * @param data_type client data type (SMS_DONT_CARE for all types)
938 * @param id client id (SMS_DONT_CARE for all id)
942 smscore_client_t
*smscore_find_client(struct smscore_device_t
*coredev
,
943 int data_type
, int id
)
945 struct smscore_client_t
*client
= NULL
;
946 struct list_head
*next
, *first
;
948 struct list_head
*firstid
, *nextid
;
951 spin_lock_irqsave(&coredev
->clientslock
, flags
);
952 first
= &coredev
->clients
;
953 for (next
= first
->next
;
954 (next
!= first
) && !client
;
956 firstid
= &((struct smscore_client_t
*)next
)->idlist
;
957 for (nextid
= firstid
->next
;
959 nextid
= nextid
->next
) {
960 if ((((struct smscore_idlist_t
*)nextid
)->id
== id
) &&
961 (((struct smscore_idlist_t
*)nextid
)->data_type
== data_type
||
962 (((struct smscore_idlist_t
*)nextid
)->data_type
== 0))) {
963 client
= (struct smscore_client_t
*) next
;
968 spin_unlock_irqrestore(&coredev
->clientslock
, flags
);
973 * find client by response id/type, call clients onresponse handler
974 * return buffer to pool on error
976 * @param coredev pointer to a coredev object returned by
977 * smscore_register_device
978 * @param cb pointer to response buffer descriptor
981 void smscore_onresponse(struct smscore_device_t
*coredev
,
982 struct smscore_buffer_t
*cb
) {
983 struct SmsMsgHdr_ST
*phdr
= (struct SmsMsgHdr_ST
*) ((u8
*) cb
->p
985 struct smscore_client_t
*client
;
987 static unsigned long last_sample_time
; /* = 0; */
988 static int data_total
; /* = 0; */
989 unsigned long time_now
= jiffies_to_msecs(jiffies
);
991 if (!last_sample_time
)
992 last_sample_time
= time_now
;
994 if (time_now
- last_sample_time
> 10000) {
995 sms_debug("\ndata rate %d bytes/secs",
996 (int)((data_total
* 1000) /
997 (time_now
- last_sample_time
)));
999 last_sample_time
= time_now
;
1003 data_total
+= cb
->size
;
1004 /* Do we need to re-route? */
1005 if ((phdr
->msgType
== MSG_SMS_HO_PER_SLICES_IND
) ||
1006 (phdr
->msgType
== MSG_SMS_TRANSMISSION_IND
)) {
1007 if (coredev
->mode
== DEVICE_MODE_DVBT_BDA
)
1008 phdr
->msgDstId
= DVBT_BDA_CONTROL_MSG_ID
;
1012 client
= smscore_find_client(coredev
, phdr
->msgType
, phdr
->msgDstId
);
1014 /* If no client registered for type & id,
1015 * check for control client where type is not registered */
1017 rc
= client
->onresponse_handler(client
->context
, cb
);
1020 switch (phdr
->msgType
) {
1021 case MSG_SMS_GET_VERSION_EX_RES
:
1023 struct SmsVersionRes_ST
*ver
=
1024 (struct SmsVersionRes_ST
*) phdr
;
1025 sms_debug("MSG_SMS_GET_VERSION_EX_RES "
1026 "id %d prots 0x%x ver %d.%d",
1027 ver
->FirmwareId
, ver
->SupportedProtocols
,
1028 ver
->RomVersionMajor
, ver
->RomVersionMinor
);
1030 coredev
->mode
= ver
->FirmwareId
== 255 ?
1031 DEVICE_MODE_NONE
: ver
->FirmwareId
;
1032 coredev
->modes_supported
= ver
->SupportedProtocols
;
1034 complete(&coredev
->version_ex_done
);
1037 case MSG_SMS_INIT_DEVICE_RES
:
1038 sms_debug("MSG_SMS_INIT_DEVICE_RES");
1039 complete(&coredev
->init_device_done
);
1041 case MSG_SW_RELOAD_START_RES
:
1042 sms_debug("MSG_SW_RELOAD_START_RES");
1043 complete(&coredev
->reload_start_done
);
1045 case MSG_SMS_DATA_DOWNLOAD_RES
:
1046 complete(&coredev
->data_download_done
);
1048 case MSG_SW_RELOAD_EXEC_RES
:
1049 sms_debug("MSG_SW_RELOAD_EXEC_RES");
1051 case MSG_SMS_SWDOWNLOAD_TRIGGER_RES
:
1052 sms_debug("MSG_SMS_SWDOWNLOAD_TRIGGER_RES");
1053 complete(&coredev
->trigger_done
);
1055 case MSG_SMS_SLEEP_RESUME_COMP_IND
:
1056 complete(&coredev
->resume_done
);
1058 case MSG_SMS_GPIO_CONFIG_EX_RES
:
1059 sms_debug("MSG_SMS_GPIO_CONFIG_EX_RES");
1060 complete(&coredev
->gpio_configuration_done
);
1062 case MSG_SMS_GPIO_SET_LEVEL_RES
:
1063 sms_debug("MSG_SMS_GPIO_SET_LEVEL_RES");
1064 complete(&coredev
->gpio_set_level_done
);
1066 case MSG_SMS_GPIO_GET_LEVEL_RES
:
1068 u32
*msgdata
= (u32
*) phdr
;
1069 coredev
->gpio_get_res
= msgdata
[1];
1070 sms_debug("MSG_SMS_GPIO_GET_LEVEL_RES gpio level %d",
1071 coredev
->gpio_get_res
);
1072 complete(&coredev
->gpio_get_level_done
);
1075 case MSG_SMS_START_IR_RES
:
1076 complete(&coredev
->ir_init_done
);
1078 case MSG_SMS_IR_SAMPLES_IND
:
1079 sms_ir_event(coredev
,
1082 + sizeof(struct SmsMsgHdr_ST
)),
1083 (int)phdr
->msgLength
1084 - sizeof(struct SmsMsgHdr_ST
));
1090 smscore_putbuffer(coredev
, cb
);
1093 EXPORT_SYMBOL_GPL(smscore_onresponse
);
1096 * return pointer to next free buffer descriptor from core pool
1098 * @param coredev pointer to a coredev object returned by
1099 * smscore_register_device
1101 * @return pointer to descriptor on success, NULL on error.
1103 struct smscore_buffer_t
*smscore_getbuffer(struct smscore_device_t
*coredev
)
1105 struct smscore_buffer_t
*cb
= NULL
;
1106 unsigned long flags
;
1110 spin_lock_irqsave(&coredev
->bufferslock
, flags
);
1112 /* This function must return a valid buffer, since the buffer list is
1113 * finite, we check that there is an available buffer, if not, we wait
1114 * until such buffer become available.
1117 prepare_to_wait(&coredev
->buffer_mng_waitq
, &wait
, TASK_INTERRUPTIBLE
);
1119 if (list_empty(&coredev
->buffers
))
1122 finish_wait(&coredev
->buffer_mng_waitq
, &wait
);
1124 cb
= (struct smscore_buffer_t
*) coredev
->buffers
.next
;
1125 list_del(&cb
->entry
);
1127 spin_unlock_irqrestore(&coredev
->bufferslock
, flags
);
1131 EXPORT_SYMBOL_GPL(smscore_getbuffer
);
1134 * return buffer descriptor to a pool
1136 * @param coredev pointer to a coredev object returned by
1137 * smscore_register_device
1138 * @param cb pointer buffer descriptor
1141 void smscore_putbuffer(struct smscore_device_t
*coredev
,
1142 struct smscore_buffer_t
*cb
) {
1143 wake_up_interruptible(&coredev
->buffer_mng_waitq
);
1144 list_add_locked(&cb
->entry
, &coredev
->buffers
, &coredev
->bufferslock
);
1146 EXPORT_SYMBOL_GPL(smscore_putbuffer
);
1148 static int smscore_validate_client(struct smscore_device_t
*coredev
,
1149 struct smscore_client_t
*client
,
1150 int data_type
, int id
)
1152 struct smscore_idlist_t
*listentry
;
1153 struct smscore_client_t
*registered_client
;
1156 sms_err("bad parameter.");
1159 registered_client
= smscore_find_client(coredev
, data_type
, id
);
1160 if (registered_client
== client
)
1163 if (registered_client
) {
1164 sms_err("The msg ID already registered to another client.");
1167 listentry
= kzalloc(sizeof(struct smscore_idlist_t
), GFP_KERNEL
);
1169 sms_err("Can't allocate memory for client id.");
1173 listentry
->data_type
= data_type
;
1174 list_add_locked(&listentry
->entry
, &client
->idlist
,
1175 &coredev
->clientslock
);
1180 * creates smsclient object, check that id is taken by another client
1182 * @param coredev pointer to a coredev object from clients hotplug
1183 * @param initial_id all messages with this id would be sent to this client
1184 * @param data_type all messages of this type would be sent to this client
1185 * @param onresponse_handler client handler that is called to
1186 * process incoming messages
1187 * @param onremove_handler client handler that is called when device is removed
1188 * @param context client-specific context
1189 * @param client pointer to a value that receives created smsclient object
1191 * @return 0 on success, <0 on error.
1193 int smscore_register_client(struct smscore_device_t
*coredev
,
1194 struct smsclient_params_t
*params
,
1195 struct smscore_client_t
**client
)
1197 struct smscore_client_t
*newclient
;
1198 /* check that no other channel with same parameters exists */
1199 if (smscore_find_client(coredev
, params
->data_type
,
1200 params
->initial_id
)) {
1201 sms_err("Client already exist.");
1205 newclient
= kzalloc(sizeof(struct smscore_client_t
), GFP_KERNEL
);
1207 sms_err("Failed to allocate memory for client.");
1211 INIT_LIST_HEAD(&newclient
->idlist
);
1212 newclient
->coredev
= coredev
;
1213 newclient
->onresponse_handler
= params
->onresponse_handler
;
1214 newclient
->onremove_handler
= params
->onremove_handler
;
1215 newclient
->context
= params
->context
;
1216 list_add_locked(&newclient
->entry
, &coredev
->clients
,
1217 &coredev
->clientslock
);
1218 smscore_validate_client(coredev
, newclient
, params
->data_type
,
1219 params
->initial_id
);
1220 *client
= newclient
;
1221 sms_debug("%p %d %d", params
->context
, params
->data_type
,
1222 params
->initial_id
);
1226 EXPORT_SYMBOL_GPL(smscore_register_client
);
1229 * frees smsclient object and all subclients associated with it
1231 * @param client pointer to smsclient object returned by
1232 * smscore_register_client
1235 void smscore_unregister_client(struct smscore_client_t
*client
)
1237 struct smscore_device_t
*coredev
= client
->coredev
;
1238 unsigned long flags
;
1240 spin_lock_irqsave(&coredev
->clientslock
, flags
);
1243 while (!list_empty(&client
->idlist
)) {
1244 struct smscore_idlist_t
*identry
=
1245 (struct smscore_idlist_t
*) client
->idlist
.next
;
1246 list_del(&identry
->entry
);
1250 sms_info("%p", client
->context
);
1252 list_del(&client
->entry
);
1255 spin_unlock_irqrestore(&coredev
->clientslock
, flags
);
1257 EXPORT_SYMBOL_GPL(smscore_unregister_client
);
1260 * verifies that source id is not taken by another client,
1261 * calls device handler to send requests to the device
1263 * @param client pointer to smsclient object returned by
1264 * smscore_register_client
1265 * @param buffer pointer to a request buffer
1266 * @param size size (in bytes) of request buffer
1268 * @return 0 on success, <0 on error.
1270 int smsclient_sendrequest(struct smscore_client_t
*client
,
1271 void *buffer
, size_t size
)
1273 struct smscore_device_t
*coredev
;
1274 struct SmsMsgHdr_ST
*phdr
= (struct SmsMsgHdr_ST
*) buffer
;
1277 if (client
== NULL
) {
1278 sms_err("Got NULL client");
1282 coredev
= client
->coredev
;
1284 /* check that no other channel with same id exists */
1285 if (coredev
== NULL
) {
1286 sms_err("Got NULL coredev");
1290 rc
= smscore_validate_client(client
->coredev
, client
, 0,
1295 return coredev
->sendrequest_handler(coredev
->context
, buffer
, size
);
1297 EXPORT_SYMBOL_GPL(smsclient_sendrequest
);
1300 /* old GPIO managments implementation */
1301 int smscore_configure_gpio(struct smscore_device_t
*coredev
, u32 pin
,
1302 struct smscore_config_gpio
*pinconfig
)
1305 struct SmsMsgHdr_ST hdr
;
1309 if (coredev
->device_flags
& SMS_DEVICE_FAMILY2
) {
1310 msg
.hdr
.msgSrcId
= DVBT_BDA_CONTROL_MSG_ID
;
1311 msg
.hdr
.msgDstId
= HIF_TASK
;
1312 msg
.hdr
.msgFlags
= 0;
1313 msg
.hdr
.msgType
= MSG_SMS_GPIO_CONFIG_EX_REQ
;
1314 msg
.hdr
.msgLength
= sizeof(msg
);
1317 msg
.data
[1] = pinconfig
->pullupdown
;
1319 /* Convert slew rate for Nova: Fast(0) = 3 / Slow(1) = 0; */
1320 msg
.data
[2] = pinconfig
->outputslewrate
== 0 ? 3 : 0;
1322 switch (pinconfig
->outputdriving
) {
1323 case SMS_GPIO_OUTPUTDRIVING_16mA
:
1324 msg
.data
[3] = 7; /* Nova - 16mA */
1326 case SMS_GPIO_OUTPUTDRIVING_12mA
:
1327 msg
.data
[3] = 5; /* Nova - 11mA */
1329 case SMS_GPIO_OUTPUTDRIVING_8mA
:
1330 msg
.data
[3] = 3; /* Nova - 7mA */
1332 case SMS_GPIO_OUTPUTDRIVING_4mA
:
1334 msg
.data
[3] = 2; /* Nova - 4mA */
1338 msg
.data
[4] = pinconfig
->direction
;
1340 } else /* TODO: SMS_DEVICE_FAMILY1 */
1343 return coredev
->sendrequest_handler(coredev
->context
,
1347 int smscore_set_gpio(struct smscore_device_t
*coredev
, u32 pin
, int level
)
1350 struct SmsMsgHdr_ST hdr
;
1354 if (pin
> MAX_GPIO_PIN_NUMBER
)
1357 msg
.hdr
.msgSrcId
= DVBT_BDA_CONTROL_MSG_ID
;
1358 msg
.hdr
.msgDstId
= HIF_TASK
;
1359 msg
.hdr
.msgFlags
= 0;
1360 msg
.hdr
.msgType
= MSG_SMS_GPIO_SET_LEVEL_REQ
;
1361 msg
.hdr
.msgLength
= sizeof(msg
);
1364 msg
.data
[1] = level
? 1 : 0;
1367 return coredev
->sendrequest_handler(coredev
->context
,
1371 /* new GPIO management implementation */
1372 static int GetGpioPinParams(u32 PinNum
, u32
*pTranslatedPinNum
,
1373 u32
*pGroupNum
, u32
*pGroupCfg
) {
1378 *pTranslatedPinNum
= 0;
1381 } else if (PinNum
>= 2 && PinNum
<= 6) {
1382 *pTranslatedPinNum
= 2;
1385 } else if (PinNum
>= 7 && PinNum
<= 11) {
1386 *pTranslatedPinNum
= 7;
1388 } else if (PinNum
>= 12 && PinNum
<= 15) {
1389 *pTranslatedPinNum
= 12;
1392 } else if (PinNum
== 16) {
1393 *pTranslatedPinNum
= 16;
1395 } else if (PinNum
>= 17 && PinNum
<= 24) {
1396 *pTranslatedPinNum
= 17;
1398 } else if (PinNum
== 25) {
1399 *pTranslatedPinNum
= 25;
1401 } else if (PinNum
>= 26 && PinNum
<= 28) {
1402 *pTranslatedPinNum
= 26;
1404 } else if (PinNum
== 29) {
1405 *pTranslatedPinNum
= 29;
1408 } else if (PinNum
== 30) {
1409 *pTranslatedPinNum
= 30;
1411 } else if (PinNum
== 31) {
1412 *pTranslatedPinNum
= 31;
1422 int smscore_gpio_configure(struct smscore_device_t
*coredev
, u8 PinNum
,
1423 struct smscore_gpio_config
*pGpioConfig
) {
1426 u32 TranslatedPinNum
= 0;
1434 struct SmsMsgHdr_ST xMsgHeader
;
1439 if (PinNum
> MAX_GPIO_PIN_NUMBER
)
1442 if (pGpioConfig
== NULL
)
1445 totalLen
= sizeof(struct SmsMsgHdr_ST
) + (sizeof(u32
) * 6);
1447 buffer
= kmalloc(totalLen
+ SMS_DMA_ALIGNMENT
,
1448 GFP_KERNEL
| GFP_DMA
);
1452 pMsg
= (struct SetGpioMsg
*) SMS_ALIGN_ADDRESS(buffer
);
1454 pMsg
->xMsgHeader
.msgSrcId
= DVBT_BDA_CONTROL_MSG_ID
;
1455 pMsg
->xMsgHeader
.msgDstId
= HIF_TASK
;
1456 pMsg
->xMsgHeader
.msgFlags
= 0;
1457 pMsg
->xMsgHeader
.msgLength
= (u16
) totalLen
;
1458 pMsg
->msgData
[0] = PinNum
;
1460 if (!(coredev
->device_flags
& SMS_DEVICE_FAMILY2
)) {
1461 pMsg
->xMsgHeader
.msgType
= MSG_SMS_GPIO_CONFIG_REQ
;
1462 if (GetGpioPinParams(PinNum
, &TranslatedPinNum
, &GroupNum
,
1468 pMsg
->msgData
[1] = TranslatedPinNum
;
1469 pMsg
->msgData
[2] = GroupNum
;
1470 ElectricChar
= (pGpioConfig
->PullUpDown
)
1471 | (pGpioConfig
->InputCharacteristics
<< 2)
1472 | (pGpioConfig
->OutputSlewRate
<< 3)
1473 | (pGpioConfig
->OutputDriving
<< 4);
1474 pMsg
->msgData
[3] = ElectricChar
;
1475 pMsg
->msgData
[4] = pGpioConfig
->Direction
;
1476 pMsg
->msgData
[5] = groupCfg
;
1478 pMsg
->xMsgHeader
.msgType
= MSG_SMS_GPIO_CONFIG_EX_REQ
;
1479 pMsg
->msgData
[1] = pGpioConfig
->PullUpDown
;
1480 pMsg
->msgData
[2] = pGpioConfig
->OutputSlewRate
;
1481 pMsg
->msgData
[3] = pGpioConfig
->OutputDriving
;
1482 pMsg
->msgData
[4] = pGpioConfig
->Direction
;
1483 pMsg
->msgData
[5] = 0;
1486 smsendian_handle_tx_message((struct SmsMsgHdr_ST
*)pMsg
);
1487 rc
= smscore_sendrequest_and_wait(coredev
, pMsg
, totalLen
,
1488 &coredev
->gpio_configuration_done
);
1492 sms_err("smscore_gpio_configure timeout");
1494 sms_err("smscore_gpio_configure error");
1502 int smscore_gpio_set_level(struct smscore_device_t
*coredev
, u8 PinNum
,
1510 struct SmsMsgHdr_ST xMsgHeader
;
1511 u32 msgData
[3]; /* keep it 3 ! */
1514 if ((NewLevel
> 1) || (PinNum
> MAX_GPIO_PIN_NUMBER
) ||
1515 (PinNum
> MAX_GPIO_PIN_NUMBER
))
1518 totalLen
= sizeof(struct SmsMsgHdr_ST
) +
1519 (3 * sizeof(u32
)); /* keep it 3 ! */
1521 buffer
= kmalloc(totalLen
+ SMS_DMA_ALIGNMENT
,
1522 GFP_KERNEL
| GFP_DMA
);
1526 pMsg
= (struct SetGpioMsg
*) SMS_ALIGN_ADDRESS(buffer
);
1528 pMsg
->xMsgHeader
.msgSrcId
= DVBT_BDA_CONTROL_MSG_ID
;
1529 pMsg
->xMsgHeader
.msgDstId
= HIF_TASK
;
1530 pMsg
->xMsgHeader
.msgFlags
= 0;
1531 pMsg
->xMsgHeader
.msgType
= MSG_SMS_GPIO_SET_LEVEL_REQ
;
1532 pMsg
->xMsgHeader
.msgLength
= (u16
) totalLen
;
1533 pMsg
->msgData
[0] = PinNum
;
1534 pMsg
->msgData
[1] = NewLevel
;
1536 /* Send message to SMS */
1537 smsendian_handle_tx_message((struct SmsMsgHdr_ST
*)pMsg
);
1538 rc
= smscore_sendrequest_and_wait(coredev
, pMsg
, totalLen
,
1539 &coredev
->gpio_set_level_done
);
1543 sms_err("smscore_gpio_set_level timeout");
1545 sms_err("smscore_gpio_set_level error");
1552 int smscore_gpio_get_level(struct smscore_device_t
*coredev
, u8 PinNum
,
1560 struct SmsMsgHdr_ST xMsgHeader
;
1565 if (PinNum
> MAX_GPIO_PIN_NUMBER
)
1568 totalLen
= sizeof(struct SmsMsgHdr_ST
) + (2 * sizeof(u32
));
1570 buffer
= kmalloc(totalLen
+ SMS_DMA_ALIGNMENT
,
1571 GFP_KERNEL
| GFP_DMA
);
1575 pMsg
= (struct SetGpioMsg
*) SMS_ALIGN_ADDRESS(buffer
);
1577 pMsg
->xMsgHeader
.msgSrcId
= DVBT_BDA_CONTROL_MSG_ID
;
1578 pMsg
->xMsgHeader
.msgDstId
= HIF_TASK
;
1579 pMsg
->xMsgHeader
.msgFlags
= 0;
1580 pMsg
->xMsgHeader
.msgType
= MSG_SMS_GPIO_GET_LEVEL_REQ
;
1581 pMsg
->xMsgHeader
.msgLength
= (u16
) totalLen
;
1582 pMsg
->msgData
[0] = PinNum
;
1583 pMsg
->msgData
[1] = 0;
1585 /* Send message to SMS */
1586 smsendian_handle_tx_message((struct SmsMsgHdr_ST
*)pMsg
);
1587 rc
= smscore_sendrequest_and_wait(coredev
, pMsg
, totalLen
,
1588 &coredev
->gpio_get_level_done
);
1592 sms_err("smscore_gpio_get_level timeout");
1594 sms_err("smscore_gpio_get_level error");
1598 /* Its a race between other gpio_get_level() and the copy of the single
1599 * global 'coredev->gpio_get_res' to the function's variable 'level'
1601 *level
= coredev
->gpio_get_res
;
1606 static int __init
smscore_module_init(void)
1610 INIT_LIST_HEAD(&g_smscore_notifyees
);
1611 INIT_LIST_HEAD(&g_smscore_devices
);
1612 kmutex_init(&g_smscore_deviceslock
);
1614 INIT_LIST_HEAD(&g_smscore_registry
);
1615 kmutex_init(&g_smscore_registrylock
);
1620 static void __exit
smscore_module_exit(void)
1622 kmutex_lock(&g_smscore_deviceslock
);
1623 while (!list_empty(&g_smscore_notifyees
)) {
1624 struct smscore_device_notifyee_t
*notifyee
=
1625 (struct smscore_device_notifyee_t
*)
1626 g_smscore_notifyees
.next
;
1628 list_del(¬ifyee
->entry
);
1631 kmutex_unlock(&g_smscore_deviceslock
);
1633 kmutex_lock(&g_smscore_registrylock
);
1634 while (!list_empty(&g_smscore_registry
)) {
1635 struct smscore_registry_entry_t
*entry
=
1636 (struct smscore_registry_entry_t
*)
1637 g_smscore_registry
.next
;
1639 list_del(&entry
->entry
);
1642 kmutex_unlock(&g_smscore_registrylock
);
1647 module_init(smscore_module_init
);
1648 module_exit(smscore_module_exit
);
1650 MODULE_DESCRIPTION("Siano MDTV Core module");
1651 MODULE_AUTHOR("Siano Mobile Silicon, Inc. (uris@siano-ms.com)");
1652 MODULE_LICENSE("GPL");