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
= kmalloc(sizeof(struct smscore_registry_entry_t
), GFP_KERNEL
);
121 entry
->mode
= default_mode
;
122 strcpy(entry
->devpath
, devpath
);
123 list_add(&entry
->entry
, &g_smscore_registry
);
125 sms_err("failed to create smscore_registry.");
126 kmutex_unlock(&g_smscore_registrylock
);
130 int smscore_registry_getmode(char *devpath
)
132 struct smscore_registry_entry_t
*entry
;
134 entry
= smscore_find_registry(devpath
);
138 sms_err("No registry found.");
142 EXPORT_SYMBOL_GPL(smscore_registry_getmode
);
144 static enum sms_device_type_st
smscore_registry_gettype(char *devpath
)
146 struct smscore_registry_entry_t
*entry
;
148 entry
= smscore_find_registry(devpath
);
152 sms_err("No registry found.");
157 void smscore_registry_setmode(char *devpath
, int mode
)
159 struct smscore_registry_entry_t
*entry
;
161 entry
= smscore_find_registry(devpath
);
165 sms_err("No registry found.");
168 static void smscore_registry_settype(char *devpath
,
169 enum sms_device_type_st type
)
171 struct smscore_registry_entry_t
*entry
;
173 entry
= smscore_find_registry(devpath
);
177 sms_err("No registry found.");
181 static void list_add_locked(struct list_head
*new, struct list_head
*head
,
186 spin_lock_irqsave(lock
, flags
);
190 spin_unlock_irqrestore(lock
, flags
);
194 * register a client callback that called when device plugged in/unplugged
195 * NOTE: if devices exist callback is called immediately for each device
197 * @param hotplug callback
199 * @return 0 on success, <0 on error.
201 int smscore_register_hotplug(hotplug_t hotplug
)
203 struct smscore_device_notifyee_t
*notifyee
;
204 struct list_head
*next
, *first
;
207 kmutex_lock(&g_smscore_deviceslock
);
209 notifyee
= kmalloc(sizeof(struct smscore_device_notifyee_t
),
212 /* now notify callback about existing devices */
213 first
= &g_smscore_devices
;
214 for (next
= first
->next
;
215 next
!= first
&& !rc
;
217 struct smscore_device_t
*coredev
=
218 (struct smscore_device_t
*) next
;
219 rc
= hotplug(coredev
, coredev
->device
, 1);
223 notifyee
->hotplug
= hotplug
;
224 list_add(¬ifyee
->entry
, &g_smscore_notifyees
);
230 kmutex_unlock(&g_smscore_deviceslock
);
234 EXPORT_SYMBOL_GPL(smscore_register_hotplug
);
237 * unregister a client callback that called when device plugged in/unplugged
239 * @param hotplug callback
242 void smscore_unregister_hotplug(hotplug_t hotplug
)
244 struct list_head
*next
, *first
;
246 kmutex_lock(&g_smscore_deviceslock
);
248 first
= &g_smscore_notifyees
;
250 for (next
= first
->next
; next
!= first
;) {
251 struct smscore_device_notifyee_t
*notifyee
=
252 (struct smscore_device_notifyee_t
*) next
;
255 if (notifyee
->hotplug
== hotplug
) {
256 list_del(¬ifyee
->entry
);
261 kmutex_unlock(&g_smscore_deviceslock
);
263 EXPORT_SYMBOL_GPL(smscore_unregister_hotplug
);
265 static void smscore_notify_clients(struct smscore_device_t
*coredev
)
267 struct smscore_client_t
*client
;
269 /* the client must call smscore_unregister_client from remove handler */
270 while (!list_empty(&coredev
->clients
)) {
271 client
= (struct smscore_client_t
*) coredev
->clients
.next
;
272 client
->onremove_handler(client
->context
);
276 static int smscore_notify_callbacks(struct smscore_device_t
*coredev
,
277 struct device
*device
, int arrival
)
279 struct list_head
*next
, *first
;
282 /* note: must be called under g_deviceslock */
284 first
= &g_smscore_notifyees
;
286 for (next
= first
->next
; next
!= first
; next
= next
->next
) {
287 rc
= ((struct smscore_device_notifyee_t
*) next
)->
288 hotplug(coredev
, device
, arrival
);
297 smscore_buffer_t
*smscore_createbuffer(u8
*buffer
, void *common_buffer
,
298 dma_addr_t common_buffer_phys
)
300 struct smscore_buffer_t
*cb
=
301 kmalloc(sizeof(struct smscore_buffer_t
), GFP_KERNEL
);
303 sms_info("kmalloc(...) failed");
308 cb
->offset_in_common
= buffer
- (u8
*) common_buffer
;
309 cb
->phys
= common_buffer_phys
+ cb
->offset_in_common
;
315 * creates coredev object for a device, prepares buffers,
316 * creates buffer mappings, notifies registered hotplugs about new device.
318 * @param params device pointer to struct with device specific parameters
320 * @param coredev pointer to a value that receives created coredev object
322 * @return 0 on success, <0 on error.
324 int smscore_register_device(struct smsdevice_params_t
*params
,
325 struct smscore_device_t
**coredev
)
327 struct smscore_device_t
*dev
;
330 dev
= kzalloc(sizeof(struct smscore_device_t
), GFP_KERNEL
);
332 sms_info("kzalloc(...) failed");
336 /* init list entry so it could be safe in smscore_unregister_device */
337 INIT_LIST_HEAD(&dev
->entry
);
340 INIT_LIST_HEAD(&dev
->clients
);
341 INIT_LIST_HEAD(&dev
->buffers
);
344 spin_lock_init(&dev
->clientslock
);
345 spin_lock_init(&dev
->bufferslock
);
347 /* init completion events */
348 init_completion(&dev
->version_ex_done
);
349 init_completion(&dev
->data_download_done
);
350 init_completion(&dev
->trigger_done
);
351 init_completion(&dev
->init_device_done
);
352 init_completion(&dev
->reload_start_done
);
353 init_completion(&dev
->resume_done
);
354 init_completion(&dev
->gpio_configuration_done
);
355 init_completion(&dev
->gpio_set_level_done
);
356 init_completion(&dev
->gpio_get_level_done
);
357 init_completion(&dev
->ir_init_done
);
359 /* Buffer management */
360 init_waitqueue_head(&dev
->buffer_mng_waitq
);
362 /* alloc common buffer */
363 dev
->common_buffer_size
= params
->buffer_size
* params
->num_buffers
;
364 dev
->common_buffer
= dma_alloc_coherent(NULL
, dev
->common_buffer_size
,
365 &dev
->common_buffer_phys
,
366 GFP_KERNEL
| GFP_DMA
);
367 if (!dev
->common_buffer
) {
368 smscore_unregister_device(dev
);
372 /* prepare dma buffers */
373 for (buffer
= dev
->common_buffer
;
374 dev
->num_buffers
< params
->num_buffers
;
375 dev
->num_buffers
++, buffer
+= params
->buffer_size
) {
376 struct smscore_buffer_t
*cb
=
377 smscore_createbuffer(buffer
, dev
->common_buffer
,
378 dev
->common_buffer_phys
);
380 smscore_unregister_device(dev
);
384 smscore_putbuffer(dev
, cb
);
387 sms_info("allocated %d buffers", dev
->num_buffers
);
389 dev
->mode
= DEVICE_MODE_NONE
;
390 dev
->context
= params
->context
;
391 dev
->device
= params
->device
;
392 dev
->setmode_handler
= params
->setmode_handler
;
393 dev
->detectmode_handler
= params
->detectmode_handler
;
394 dev
->sendrequest_handler
= params
->sendrequest_handler
;
395 dev
->preload_handler
= params
->preload_handler
;
396 dev
->postload_handler
= params
->postload_handler
;
398 dev
->device_flags
= params
->flags
;
399 strcpy(dev
->devpath
, params
->devpath
);
401 smscore_registry_settype(dev
->devpath
, params
->device_type
);
403 /* add device to devices list */
404 kmutex_lock(&g_smscore_deviceslock
);
405 list_add(&dev
->entry
, &g_smscore_devices
);
406 kmutex_unlock(&g_smscore_deviceslock
);
410 sms_info("device %p created", dev
);
414 EXPORT_SYMBOL_GPL(smscore_register_device
);
417 static int smscore_sendrequest_and_wait(struct smscore_device_t
*coredev
,
418 void *buffer
, size_t size
, struct completion
*completion
) {
419 int rc
= coredev
->sendrequest_handler(coredev
->context
, buffer
, size
);
421 sms_info("sendrequest returned error %d", rc
);
425 return wait_for_completion_timeout(completion
,
426 msecs_to_jiffies(SMS_PROTOCOL_MAX_RAOUNDTRIP_MS
)) ?
431 * Starts & enables IR operations
433 * @return 0 on success, < 0 on error.
435 static int smscore_init_ir(struct smscore_device_t
*coredev
)
441 coredev
->ir
.dev
= NULL
;
442 ir_io
= sms_get_board(smscore_get_board_id(coredev
))->board_cfg
.ir
;
443 if (ir_io
) {/* only if IR port exist we use IR sub-module */
444 sms_info("IR loading");
445 rc
= sms_ir_init(coredev
);
448 sms_err("Error initialization DTV IR sub-module");
450 buffer
= kmalloc(sizeof(struct SmsMsgData_ST2
) +
452 GFP_KERNEL
| GFP_DMA
);
454 struct SmsMsgData_ST2
*msg
=
455 (struct SmsMsgData_ST2
*)
456 SMS_ALIGN_ADDRESS(buffer
);
458 SMS_INIT_MSG(&msg
->xMsgHeader
,
459 MSG_SMS_START_IR_REQ
,
460 sizeof(struct SmsMsgData_ST2
));
461 msg
->msgData
[0] = coredev
->ir
.controller
;
462 msg
->msgData
[1] = coredev
->ir
.timeout
;
464 smsendian_handle_tx_message(
465 (struct SmsMsgHdr_ST2
*)msg
);
466 rc
= smscore_sendrequest_and_wait(coredev
, msg
,
467 msg
->xMsgHeader
. msgLength
,
468 &coredev
->ir_init_done
);
473 ("Sending IR initialization message failed");
476 sms_info("IR port has not been detected");
482 * sets initial device mode and notifies client hotplugs that device is ready
484 * @param coredev pointer to a coredev object returned by
485 * smscore_register_device
487 * @return 0 on success, <0 on error.
489 int smscore_start_device(struct smscore_device_t
*coredev
)
491 int rc
= smscore_set_device_mode(
492 coredev
, smscore_registry_getmode(coredev
->devpath
));
494 sms_info("set device mode faile , rc %d", rc
);
498 kmutex_lock(&g_smscore_deviceslock
);
500 rc
= smscore_notify_callbacks(coredev
, coredev
->device
, 1);
501 smscore_init_ir(coredev
);
503 sms_info("device %p started, rc %d", coredev
, rc
);
505 kmutex_unlock(&g_smscore_deviceslock
);
509 EXPORT_SYMBOL_GPL(smscore_start_device
);
512 static int smscore_load_firmware_family2(struct smscore_device_t
*coredev
,
513 void *buffer
, size_t size
)
515 struct SmsFirmware_ST
*firmware
= (struct SmsFirmware_ST
*) buffer
;
516 struct SmsMsgHdr_ST
*msg
;
518 u8
*payload
= firmware
->Payload
;
520 firmware
->StartAddress
= le32_to_cpu(firmware
->StartAddress
);
521 firmware
->Length
= le32_to_cpu(firmware
->Length
);
523 mem_address
= firmware
->StartAddress
;
525 sms_info("loading FW to addr 0x%x size %d",
526 mem_address
, firmware
->Length
);
527 if (coredev
->preload_handler
) {
528 rc
= coredev
->preload_handler(coredev
->context
);
533 /* PAGE_SIZE buffer shall be enough and dma aligned */
534 msg
= kmalloc(PAGE_SIZE
, GFP_KERNEL
| GFP_DMA
);
538 if (coredev
->mode
!= DEVICE_MODE_NONE
) {
539 sms_debug("sending reload command.");
540 SMS_INIT_MSG(msg
, MSG_SW_RELOAD_START_REQ
,
541 sizeof(struct SmsMsgHdr_ST
));
542 rc
= smscore_sendrequest_and_wait(coredev
, msg
,
544 &coredev
->reload_start_done
);
545 mem_address
= *(u32
*) &payload
[20];
548 while (size
&& rc
>= 0) {
549 struct SmsDataDownload_ST
*DataMsg
=
550 (struct SmsDataDownload_ST
*) msg
;
551 int payload_size
= min((int) size
, SMS_MAX_PAYLOAD_SIZE
);
553 SMS_INIT_MSG(msg
, MSG_SMS_DATA_DOWNLOAD_REQ
,
554 (u16
)(sizeof(struct SmsMsgHdr_ST
) +
555 sizeof(u32
) + payload_size
));
557 DataMsg
->MemAddr
= mem_address
;
558 memcpy(DataMsg
->Payload
, payload
, payload_size
);
560 if ((coredev
->device_flags
& SMS_ROM_NO_RESPONSE
) &&
561 (coredev
->mode
== DEVICE_MODE_NONE
))
562 rc
= coredev
->sendrequest_handler(
563 coredev
->context
, DataMsg
,
564 DataMsg
->xMsgHeader
.msgLength
);
566 rc
= smscore_sendrequest_and_wait(
568 DataMsg
->xMsgHeader
.msgLength
,
569 &coredev
->data_download_done
);
571 payload
+= payload_size
;
572 size
-= payload_size
;
573 mem_address
+= payload_size
;
577 if (coredev
->mode
== DEVICE_MODE_NONE
) {
578 struct SmsMsgData_ST
*TriggerMsg
=
579 (struct SmsMsgData_ST
*) msg
;
581 SMS_INIT_MSG(msg
, MSG_SMS_SWDOWNLOAD_TRIGGER_REQ
,
582 sizeof(struct SmsMsgHdr_ST
) +
585 TriggerMsg
->msgData
[0] = firmware
->StartAddress
;
587 TriggerMsg
->msgData
[1] = 5; /* Priority */
588 TriggerMsg
->msgData
[2] = 0x200; /* Stack size */
589 TriggerMsg
->msgData
[3] = 0; /* Parameter */
590 TriggerMsg
->msgData
[4] = 4; /* Task ID */
592 if (coredev
->device_flags
& SMS_ROM_NO_RESPONSE
) {
593 rc
= coredev
->sendrequest_handler(
594 coredev
->context
, TriggerMsg
,
595 TriggerMsg
->xMsgHeader
.msgLength
);
598 rc
= smscore_sendrequest_and_wait(
600 TriggerMsg
->xMsgHeader
.msgLength
,
601 &coredev
->trigger_done
);
603 SMS_INIT_MSG(msg
, MSG_SW_RELOAD_EXEC_REQ
,
604 sizeof(struct SmsMsgHdr_ST
));
606 rc
= coredev
->sendrequest_handler(coredev
->context
,
607 msg
, msg
->msgLength
);
612 sms_debug("rc=%d, postload=%p ", rc
,
613 coredev
->postload_handler
);
617 return ((rc
>= 0) && coredev
->postload_handler
) ?
618 coredev
->postload_handler(coredev
->context
) :
623 * loads specified firmware into a buffer and calls device loadfirmware_handler
625 * @param coredev pointer to a coredev object returned by
626 * smscore_register_device
627 * @param filename null-terminated string specifies firmware file name
628 * @param loadfirmware_handler device handler that loads firmware
630 * @return 0 on success, <0 on error.
632 static int smscore_load_firmware_from_file(struct smscore_device_t
*coredev
,
634 loadfirmware_t loadfirmware_handler
)
637 const struct firmware
*fw
;
640 if (loadfirmware_handler
== NULL
&& !(coredev
->device_flags
&
644 rc
= request_firmware(&fw
, filename
, coredev
->device
);
646 sms_info("failed to open \"%s\"", filename
);
649 sms_info("read FW %s, size=%zd", filename
, fw
->size
);
650 fw_buffer
= kmalloc(ALIGN(fw
->size
, SMS_ALLOC_ALIGNMENT
),
651 GFP_KERNEL
| GFP_DMA
);
653 memcpy(fw_buffer
, fw
->data
, fw
->size
);
655 rc
= (coredev
->device_flags
& SMS_DEVICE_FAMILY2
) ?
656 smscore_load_firmware_family2(coredev
,
659 loadfirmware_handler(coredev
->context
,
660 fw_buffer
, fw
->size
);
664 sms_info("failed to allocate firmware buffer");
668 release_firmware(fw
);
674 * notifies all clients registered with the device, notifies hotplugs,
675 * frees all buffers and coredev object
677 * @param coredev pointer to a coredev object returned by
678 * smscore_register_device
680 * @return 0 on success, <0 on error.
682 void smscore_unregister_device(struct smscore_device_t
*coredev
)
684 struct smscore_buffer_t
*cb
;
688 kmutex_lock(&g_smscore_deviceslock
);
690 /* Release input device (IR) resources */
691 sms_ir_exit(coredev
);
693 smscore_notify_clients(coredev
);
694 smscore_notify_callbacks(coredev
, NULL
, 0);
696 /* at this point all buffers should be back
697 * onresponse must no longer be called */
700 while (!list_empty(&coredev
->buffers
)) {
701 cb
= (struct smscore_buffer_t
*) coredev
->buffers
.next
;
702 list_del(&cb
->entry
);
706 if (num_buffers
== coredev
->num_buffers
)
709 sms_info("exiting although "
710 "not all buffers released.");
714 sms_info("waiting for %d buffer(s)",
715 coredev
->num_buffers
- num_buffers
);
719 sms_info("freed %d buffers", num_buffers
);
721 if (coredev
->common_buffer
)
722 dma_free_coherent(NULL
, coredev
->common_buffer_size
,
723 coredev
->common_buffer
, coredev
->common_buffer_phys
);
725 if (coredev
->fw_buf
!= NULL
)
726 kfree(coredev
->fw_buf
);
728 list_del(&coredev
->entry
);
731 kmutex_unlock(&g_smscore_deviceslock
);
733 sms_info("device %p destroyed", coredev
);
735 EXPORT_SYMBOL_GPL(smscore_unregister_device
);
737 static int smscore_detect_mode(struct smscore_device_t
*coredev
)
739 void *buffer
= kmalloc(sizeof(struct SmsMsgHdr_ST
) + SMS_DMA_ALIGNMENT
,
740 GFP_KERNEL
| GFP_DMA
);
741 struct SmsMsgHdr_ST
*msg
=
742 (struct SmsMsgHdr_ST
*) SMS_ALIGN_ADDRESS(buffer
);
748 SMS_INIT_MSG(msg
, MSG_SMS_GET_VERSION_EX_REQ
,
749 sizeof(struct SmsMsgHdr_ST
));
751 rc
= smscore_sendrequest_and_wait(coredev
, msg
, msg
->msgLength
,
752 &coredev
->version_ex_done
);
754 sms_err("MSG_SMS_GET_VERSION_EX_REQ failed first try");
756 if (wait_for_completion_timeout(&coredev
->resume_done
,
757 msecs_to_jiffies(5000))) {
758 rc
= smscore_sendrequest_and_wait(
759 coredev
, msg
, msg
->msgLength
,
760 &coredev
->version_ex_done
);
762 sms_err("MSG_SMS_GET_VERSION_EX_REQ failed "
763 "second try, rc %d", rc
);
773 static char *smscore_fw_lkup
[][SMS_NUM_OF_DEVICE_TYPES
] = {
774 /*Stellar NOVA A0 Nova B0 VEGA*/
776 {"none", "dvb_nova_12mhz.inp", "dvb_nova_12mhz_b0.inp", "none"},
778 {"none", "dvb_nova_12mhz.inp", "dvb_nova_12mhz_b0.inp", "none"},
780 {"none", "tdmb_nova_12mhz.inp", "tdmb_nova_12mhz_b0.inp", "none"},
782 {"none", "none", "none", "none"},
784 {"none", "dvb_nova_12mhz.inp", "dvb_nova_12mhz_b0.inp", "none"},
786 {"none", "isdbt_nova_12mhz.inp", "isdbt_nova_12mhz_b0.inp", "none"},
788 {"none", "isdbt_nova_12mhz.inp", "isdbt_nova_12mhz_b0.inp", "none"},
790 {"none", "none", "none", "cmmb_vega_12mhz.inp"}
793 static inline char *sms_get_fw_name(struct smscore_device_t
*coredev
,
794 int mode
, enum sms_device_type_st type
)
796 char **fw
= sms_get_board(smscore_get_board_id(coredev
))->fw
;
797 return (fw
&& fw
[mode
]) ? fw
[mode
] : smscore_fw_lkup
[mode
][type
];
801 * calls device handler to change mode of operation
802 * NOTE: stellar/usb may disconnect when changing mode
804 * @param coredev pointer to a coredev object returned by
805 * smscore_register_device
806 * @param mode requested mode of operation
808 * @return 0 on success, <0 on error.
810 int smscore_set_device_mode(struct smscore_device_t
*coredev
, int mode
)
814 enum sms_device_type_st type
;
816 sms_debug("set device mode to %d", mode
);
817 if (coredev
->device_flags
& SMS_DEVICE_FAMILY2
) {
818 if (mode
< DEVICE_MODE_DVBT
|| mode
>= DEVICE_MODE_RAW_TUNER
) {
819 sms_err("invalid mode specified %d", mode
);
823 smscore_registry_setmode(coredev
->devpath
, mode
);
825 if (!(coredev
->device_flags
& SMS_DEVICE_NOT_READY
)) {
826 rc
= smscore_detect_mode(coredev
);
828 sms_err("mode detect failed %d", rc
);
833 if (coredev
->mode
== mode
) {
834 sms_info("device mode %d already set", mode
);
838 if (!(coredev
->modes_supported
& (1 << mode
))) {
841 type
= smscore_registry_gettype(coredev
->devpath
);
842 fw_filename
= sms_get_fw_name(coredev
, mode
, type
);
844 rc
= smscore_load_firmware_from_file(coredev
,
847 sms_warn("error %d loading firmware: %s, "
848 "trying again with default firmware",
851 /* try again with the default firmware */
852 fw_filename
= smscore_fw_lkup
[mode
][type
];
853 rc
= smscore_load_firmware_from_file(coredev
,
857 sms_warn("error %d loading "
863 sms_log("firmware download success: %s", fw_filename
);
865 sms_info("mode %d supported by running "
868 buffer
= kmalloc(sizeof(struct SmsMsgData_ST
) +
869 SMS_DMA_ALIGNMENT
, GFP_KERNEL
| GFP_DMA
);
871 struct SmsMsgData_ST
*msg
=
872 (struct SmsMsgData_ST
*)
873 SMS_ALIGN_ADDRESS(buffer
);
875 SMS_INIT_MSG(&msg
->xMsgHeader
, MSG_SMS_INIT_DEVICE_REQ
,
876 sizeof(struct SmsMsgData_ST
));
877 msg
->msgData
[0] = mode
;
879 rc
= smscore_sendrequest_and_wait(
880 coredev
, msg
, msg
->xMsgHeader
.msgLength
,
881 &coredev
->init_device_done
);
885 sms_err("Could not allocate buffer for "
886 "init device message.");
890 if (mode
< DEVICE_MODE_DVBT
|| mode
> DEVICE_MODE_DVBT_BDA
) {
891 sms_err("invalid mode specified %d", mode
);
895 smscore_registry_setmode(coredev
->devpath
, mode
);
897 if (coredev
->detectmode_handler
)
898 coredev
->detectmode_handler(coredev
->context
,
901 if (coredev
->mode
!= mode
&& coredev
->setmode_handler
)
902 rc
= coredev
->setmode_handler(coredev
->context
, mode
);
906 coredev
->mode
= mode
;
907 coredev
->device_flags
&= ~SMS_DEVICE_NOT_READY
;
911 sms_err("return error code %d.", rc
);
916 * calls device handler to get current mode of operation
918 * @param coredev pointer to a coredev object returned by
919 * smscore_register_device
921 * @return current mode
923 int smscore_get_device_mode(struct smscore_device_t
*coredev
)
925 return coredev
->mode
;
927 EXPORT_SYMBOL_GPL(smscore_get_device_mode
);
930 * find client by response id & type within the clients list.
931 * return client handle or NULL.
933 * @param coredev pointer to a coredev object returned by
934 * smscore_register_device
935 * @param data_type client data type (SMS_DONT_CARE for all types)
936 * @param id client id (SMS_DONT_CARE for all id)
940 smscore_client_t
*smscore_find_client(struct smscore_device_t
*coredev
,
941 int data_type
, int id
)
943 struct smscore_client_t
*client
= NULL
;
944 struct list_head
*next
, *first
;
946 struct list_head
*firstid
, *nextid
;
949 spin_lock_irqsave(&coredev
->clientslock
, flags
);
950 first
= &coredev
->clients
;
951 for (next
= first
->next
;
952 (next
!= first
) && !client
;
954 firstid
= &((struct smscore_client_t
*)next
)->idlist
;
955 for (nextid
= firstid
->next
;
957 nextid
= nextid
->next
) {
958 if ((((struct smscore_idlist_t
*)nextid
)->id
== id
) &&
959 (((struct smscore_idlist_t
*)nextid
)->data_type
== data_type
||
960 (((struct smscore_idlist_t
*)nextid
)->data_type
== 0))) {
961 client
= (struct smscore_client_t
*) next
;
966 spin_unlock_irqrestore(&coredev
->clientslock
, flags
);
971 * find client by response id/type, call clients onresponse handler
972 * return buffer to pool on error
974 * @param coredev pointer to a coredev object returned by
975 * smscore_register_device
976 * @param cb pointer to response buffer descriptor
979 void smscore_onresponse(struct smscore_device_t
*coredev
,
980 struct smscore_buffer_t
*cb
) {
981 struct SmsMsgHdr_ST
*phdr
= (struct SmsMsgHdr_ST
*) ((u8
*) cb
->p
983 struct smscore_client_t
*client
;
985 static unsigned long last_sample_time
; /* = 0; */
986 static int data_total
; /* = 0; */
987 unsigned long time_now
= jiffies_to_msecs(jiffies
);
989 if (!last_sample_time
)
990 last_sample_time
= time_now
;
992 if (time_now
- last_sample_time
> 10000) {
993 sms_debug("\ndata rate %d bytes/secs",
994 (int)((data_total
* 1000) /
995 (time_now
- last_sample_time
)));
997 last_sample_time
= time_now
;
1001 data_total
+= cb
->size
;
1002 /* Do we need to re-route? */
1003 if ((phdr
->msgType
== MSG_SMS_HO_PER_SLICES_IND
) ||
1004 (phdr
->msgType
== MSG_SMS_TRANSMISSION_IND
)) {
1005 if (coredev
->mode
== DEVICE_MODE_DVBT_BDA
)
1006 phdr
->msgDstId
= DVBT_BDA_CONTROL_MSG_ID
;
1010 client
= smscore_find_client(coredev
, phdr
->msgType
, phdr
->msgDstId
);
1012 /* If no client registered for type & id,
1013 * check for control client where type is not registered */
1015 rc
= client
->onresponse_handler(client
->context
, cb
);
1018 switch (phdr
->msgType
) {
1019 case MSG_SMS_GET_VERSION_EX_RES
:
1021 struct SmsVersionRes_ST
*ver
=
1022 (struct SmsVersionRes_ST
*) phdr
;
1023 sms_debug("MSG_SMS_GET_VERSION_EX_RES "
1024 "id %d prots 0x%x ver %d.%d",
1025 ver
->FirmwareId
, ver
->SupportedProtocols
,
1026 ver
->RomVersionMajor
, ver
->RomVersionMinor
);
1028 coredev
->mode
= ver
->FirmwareId
== 255 ?
1029 DEVICE_MODE_NONE
: ver
->FirmwareId
;
1030 coredev
->modes_supported
= ver
->SupportedProtocols
;
1032 complete(&coredev
->version_ex_done
);
1035 case MSG_SMS_INIT_DEVICE_RES
:
1036 sms_debug("MSG_SMS_INIT_DEVICE_RES");
1037 complete(&coredev
->init_device_done
);
1039 case MSG_SW_RELOAD_START_RES
:
1040 sms_debug("MSG_SW_RELOAD_START_RES");
1041 complete(&coredev
->reload_start_done
);
1043 case MSG_SMS_DATA_DOWNLOAD_RES
:
1044 complete(&coredev
->data_download_done
);
1046 case MSG_SW_RELOAD_EXEC_RES
:
1047 sms_debug("MSG_SW_RELOAD_EXEC_RES");
1049 case MSG_SMS_SWDOWNLOAD_TRIGGER_RES
:
1050 sms_debug("MSG_SMS_SWDOWNLOAD_TRIGGER_RES");
1051 complete(&coredev
->trigger_done
);
1053 case MSG_SMS_SLEEP_RESUME_COMP_IND
:
1054 complete(&coredev
->resume_done
);
1056 case MSG_SMS_GPIO_CONFIG_EX_RES
:
1057 sms_debug("MSG_SMS_GPIO_CONFIG_EX_RES");
1058 complete(&coredev
->gpio_configuration_done
);
1060 case MSG_SMS_GPIO_SET_LEVEL_RES
:
1061 sms_debug("MSG_SMS_GPIO_SET_LEVEL_RES");
1062 complete(&coredev
->gpio_set_level_done
);
1064 case MSG_SMS_GPIO_GET_LEVEL_RES
:
1066 u32
*msgdata
= (u32
*) phdr
;
1067 coredev
->gpio_get_res
= msgdata
[1];
1068 sms_debug("MSG_SMS_GPIO_GET_LEVEL_RES gpio level %d",
1069 coredev
->gpio_get_res
);
1070 complete(&coredev
->gpio_get_level_done
);
1073 case MSG_SMS_START_IR_RES
:
1074 complete(&coredev
->ir_init_done
);
1076 case MSG_SMS_IR_SAMPLES_IND
:
1077 sms_ir_event(coredev
,
1080 + sizeof(struct SmsMsgHdr_ST
)),
1081 (int)phdr
->msgLength
1082 - sizeof(struct SmsMsgHdr_ST
));
1088 smscore_putbuffer(coredev
, cb
);
1091 EXPORT_SYMBOL_GPL(smscore_onresponse
);
1094 * return pointer to next free buffer descriptor from core pool
1096 * @param coredev pointer to a coredev object returned by
1097 * smscore_register_device
1099 * @return pointer to descriptor on success, NULL on error.
1102 struct smscore_buffer_t
*get_entry(struct smscore_device_t
*coredev
)
1104 struct smscore_buffer_t
*cb
= NULL
;
1105 unsigned long flags
;
1107 spin_lock_irqsave(&coredev
->bufferslock
, flags
);
1108 if (!list_empty(&coredev
->buffers
)) {
1109 cb
= (struct smscore_buffer_t
*) coredev
->buffers
.next
;
1110 list_del(&cb
->entry
);
1112 spin_unlock_irqrestore(&coredev
->bufferslock
, flags
);
1116 struct smscore_buffer_t
*smscore_getbuffer(struct smscore_device_t
*coredev
)
1118 struct smscore_buffer_t
*cb
= NULL
;
1120 wait_event(coredev
->buffer_mng_waitq
, (cb
= get_entry(coredev
)));
1124 EXPORT_SYMBOL_GPL(smscore_getbuffer
);
1127 * return buffer descriptor to a pool
1129 * @param coredev pointer to a coredev object returned by
1130 * smscore_register_device
1131 * @param cb pointer buffer descriptor
1134 void smscore_putbuffer(struct smscore_device_t
*coredev
,
1135 struct smscore_buffer_t
*cb
) {
1136 wake_up_interruptible(&coredev
->buffer_mng_waitq
);
1137 list_add_locked(&cb
->entry
, &coredev
->buffers
, &coredev
->bufferslock
);
1139 EXPORT_SYMBOL_GPL(smscore_putbuffer
);
1141 static int smscore_validate_client(struct smscore_device_t
*coredev
,
1142 struct smscore_client_t
*client
,
1143 int data_type
, int id
)
1145 struct smscore_idlist_t
*listentry
;
1146 struct smscore_client_t
*registered_client
;
1149 sms_err("bad parameter.");
1152 registered_client
= smscore_find_client(coredev
, data_type
, id
);
1153 if (registered_client
== client
)
1156 if (registered_client
) {
1157 sms_err("The msg ID already registered to another client.");
1160 listentry
= kzalloc(sizeof(struct smscore_idlist_t
), GFP_KERNEL
);
1162 sms_err("Can't allocate memory for client id.");
1166 listentry
->data_type
= data_type
;
1167 list_add_locked(&listentry
->entry
, &client
->idlist
,
1168 &coredev
->clientslock
);
1173 * creates smsclient object, check that id is taken by another client
1175 * @param coredev pointer to a coredev object from clients hotplug
1176 * @param initial_id all messages with this id would be sent to this client
1177 * @param data_type all messages of this type would be sent to this client
1178 * @param onresponse_handler client handler that is called to
1179 * process incoming messages
1180 * @param onremove_handler client handler that is called when device is removed
1181 * @param context client-specific context
1182 * @param client pointer to a value that receives created smsclient object
1184 * @return 0 on success, <0 on error.
1186 int smscore_register_client(struct smscore_device_t
*coredev
,
1187 struct smsclient_params_t
*params
,
1188 struct smscore_client_t
**client
)
1190 struct smscore_client_t
*newclient
;
1191 /* check that no other channel with same parameters exists */
1192 if (smscore_find_client(coredev
, params
->data_type
,
1193 params
->initial_id
)) {
1194 sms_err("Client already exist.");
1198 newclient
= kzalloc(sizeof(struct smscore_client_t
), GFP_KERNEL
);
1200 sms_err("Failed to allocate memory for client.");
1204 INIT_LIST_HEAD(&newclient
->idlist
);
1205 newclient
->coredev
= coredev
;
1206 newclient
->onresponse_handler
= params
->onresponse_handler
;
1207 newclient
->onremove_handler
= params
->onremove_handler
;
1208 newclient
->context
= params
->context
;
1209 list_add_locked(&newclient
->entry
, &coredev
->clients
,
1210 &coredev
->clientslock
);
1211 smscore_validate_client(coredev
, newclient
, params
->data_type
,
1212 params
->initial_id
);
1213 *client
= newclient
;
1214 sms_debug("%p %d %d", params
->context
, params
->data_type
,
1215 params
->initial_id
);
1219 EXPORT_SYMBOL_GPL(smscore_register_client
);
1222 * frees smsclient object and all subclients associated with it
1224 * @param client pointer to smsclient object returned by
1225 * smscore_register_client
1228 void smscore_unregister_client(struct smscore_client_t
*client
)
1230 struct smscore_device_t
*coredev
= client
->coredev
;
1231 unsigned long flags
;
1233 spin_lock_irqsave(&coredev
->clientslock
, flags
);
1236 while (!list_empty(&client
->idlist
)) {
1237 struct smscore_idlist_t
*identry
=
1238 (struct smscore_idlist_t
*) client
->idlist
.next
;
1239 list_del(&identry
->entry
);
1243 sms_info("%p", client
->context
);
1245 list_del(&client
->entry
);
1248 spin_unlock_irqrestore(&coredev
->clientslock
, flags
);
1250 EXPORT_SYMBOL_GPL(smscore_unregister_client
);
1253 * verifies that source id is not taken by another client,
1254 * calls device handler to send requests to the device
1256 * @param client pointer to smsclient object returned by
1257 * smscore_register_client
1258 * @param buffer pointer to a request buffer
1259 * @param size size (in bytes) of request buffer
1261 * @return 0 on success, <0 on error.
1263 int smsclient_sendrequest(struct smscore_client_t
*client
,
1264 void *buffer
, size_t size
)
1266 struct smscore_device_t
*coredev
;
1267 struct SmsMsgHdr_ST
*phdr
= (struct SmsMsgHdr_ST
*) buffer
;
1270 if (client
== NULL
) {
1271 sms_err("Got NULL client");
1275 coredev
= client
->coredev
;
1277 /* check that no other channel with same id exists */
1278 if (coredev
== NULL
) {
1279 sms_err("Got NULL coredev");
1283 rc
= smscore_validate_client(client
->coredev
, client
, 0,
1288 return coredev
->sendrequest_handler(coredev
->context
, buffer
, size
);
1290 EXPORT_SYMBOL_GPL(smsclient_sendrequest
);
1293 /* old GPIO managements implementation */
1294 int smscore_configure_gpio(struct smscore_device_t
*coredev
, u32 pin
,
1295 struct smscore_config_gpio
*pinconfig
)
1298 struct SmsMsgHdr_ST hdr
;
1302 if (coredev
->device_flags
& SMS_DEVICE_FAMILY2
) {
1303 msg
.hdr
.msgSrcId
= DVBT_BDA_CONTROL_MSG_ID
;
1304 msg
.hdr
.msgDstId
= HIF_TASK
;
1305 msg
.hdr
.msgFlags
= 0;
1306 msg
.hdr
.msgType
= MSG_SMS_GPIO_CONFIG_EX_REQ
;
1307 msg
.hdr
.msgLength
= sizeof(msg
);
1310 msg
.data
[1] = pinconfig
->pullupdown
;
1312 /* Convert slew rate for Nova: Fast(0) = 3 / Slow(1) = 0; */
1313 msg
.data
[2] = pinconfig
->outputslewrate
== 0 ? 3 : 0;
1315 switch (pinconfig
->outputdriving
) {
1316 case SMS_GPIO_OUTPUTDRIVING_16mA
:
1317 msg
.data
[3] = 7; /* Nova - 16mA */
1319 case SMS_GPIO_OUTPUTDRIVING_12mA
:
1320 msg
.data
[3] = 5; /* Nova - 11mA */
1322 case SMS_GPIO_OUTPUTDRIVING_8mA
:
1323 msg
.data
[3] = 3; /* Nova - 7mA */
1325 case SMS_GPIO_OUTPUTDRIVING_4mA
:
1327 msg
.data
[3] = 2; /* Nova - 4mA */
1331 msg
.data
[4] = pinconfig
->direction
;
1333 } else /* TODO: SMS_DEVICE_FAMILY1 */
1336 return coredev
->sendrequest_handler(coredev
->context
,
1340 int smscore_set_gpio(struct smscore_device_t
*coredev
, u32 pin
, int level
)
1343 struct SmsMsgHdr_ST hdr
;
1347 if (pin
> MAX_GPIO_PIN_NUMBER
)
1350 msg
.hdr
.msgSrcId
= DVBT_BDA_CONTROL_MSG_ID
;
1351 msg
.hdr
.msgDstId
= HIF_TASK
;
1352 msg
.hdr
.msgFlags
= 0;
1353 msg
.hdr
.msgType
= MSG_SMS_GPIO_SET_LEVEL_REQ
;
1354 msg
.hdr
.msgLength
= sizeof(msg
);
1357 msg
.data
[1] = level
? 1 : 0;
1360 return coredev
->sendrequest_handler(coredev
->context
,
1364 /* new GPIO management implementation */
1365 static int GetGpioPinParams(u32 PinNum
, u32
*pTranslatedPinNum
,
1366 u32
*pGroupNum
, u32
*pGroupCfg
) {
1371 *pTranslatedPinNum
= 0;
1374 } else if (PinNum
>= 2 && PinNum
<= 6) {
1375 *pTranslatedPinNum
= 2;
1378 } else if (PinNum
>= 7 && PinNum
<= 11) {
1379 *pTranslatedPinNum
= 7;
1381 } else if (PinNum
>= 12 && PinNum
<= 15) {
1382 *pTranslatedPinNum
= 12;
1385 } else if (PinNum
== 16) {
1386 *pTranslatedPinNum
= 16;
1388 } else if (PinNum
>= 17 && PinNum
<= 24) {
1389 *pTranslatedPinNum
= 17;
1391 } else if (PinNum
== 25) {
1392 *pTranslatedPinNum
= 25;
1394 } else if (PinNum
>= 26 && PinNum
<= 28) {
1395 *pTranslatedPinNum
= 26;
1397 } else if (PinNum
== 29) {
1398 *pTranslatedPinNum
= 29;
1401 } else if (PinNum
== 30) {
1402 *pTranslatedPinNum
= 30;
1404 } else if (PinNum
== 31) {
1405 *pTranslatedPinNum
= 31;
1415 int smscore_gpio_configure(struct smscore_device_t
*coredev
, u8 PinNum
,
1416 struct smscore_gpio_config
*pGpioConfig
) {
1419 u32 TranslatedPinNum
= 0;
1427 struct SmsMsgHdr_ST xMsgHeader
;
1432 if (PinNum
> MAX_GPIO_PIN_NUMBER
)
1435 if (pGpioConfig
== NULL
)
1438 totalLen
= sizeof(struct SmsMsgHdr_ST
) + (sizeof(u32
) * 6);
1440 buffer
= kmalloc(totalLen
+ SMS_DMA_ALIGNMENT
,
1441 GFP_KERNEL
| GFP_DMA
);
1445 pMsg
= (struct SetGpioMsg
*) SMS_ALIGN_ADDRESS(buffer
);
1447 pMsg
->xMsgHeader
.msgSrcId
= DVBT_BDA_CONTROL_MSG_ID
;
1448 pMsg
->xMsgHeader
.msgDstId
= HIF_TASK
;
1449 pMsg
->xMsgHeader
.msgFlags
= 0;
1450 pMsg
->xMsgHeader
.msgLength
= (u16
) totalLen
;
1451 pMsg
->msgData
[0] = PinNum
;
1453 if (!(coredev
->device_flags
& SMS_DEVICE_FAMILY2
)) {
1454 pMsg
->xMsgHeader
.msgType
= MSG_SMS_GPIO_CONFIG_REQ
;
1455 if (GetGpioPinParams(PinNum
, &TranslatedPinNum
, &GroupNum
,
1461 pMsg
->msgData
[1] = TranslatedPinNum
;
1462 pMsg
->msgData
[2] = GroupNum
;
1463 ElectricChar
= (pGpioConfig
->PullUpDown
)
1464 | (pGpioConfig
->InputCharacteristics
<< 2)
1465 | (pGpioConfig
->OutputSlewRate
<< 3)
1466 | (pGpioConfig
->OutputDriving
<< 4);
1467 pMsg
->msgData
[3] = ElectricChar
;
1468 pMsg
->msgData
[4] = pGpioConfig
->Direction
;
1469 pMsg
->msgData
[5] = groupCfg
;
1471 pMsg
->xMsgHeader
.msgType
= MSG_SMS_GPIO_CONFIG_EX_REQ
;
1472 pMsg
->msgData
[1] = pGpioConfig
->PullUpDown
;
1473 pMsg
->msgData
[2] = pGpioConfig
->OutputSlewRate
;
1474 pMsg
->msgData
[3] = pGpioConfig
->OutputDriving
;
1475 pMsg
->msgData
[4] = pGpioConfig
->Direction
;
1476 pMsg
->msgData
[5] = 0;
1479 smsendian_handle_tx_message((struct SmsMsgHdr_ST
*)pMsg
);
1480 rc
= smscore_sendrequest_and_wait(coredev
, pMsg
, totalLen
,
1481 &coredev
->gpio_configuration_done
);
1485 sms_err("smscore_gpio_configure timeout");
1487 sms_err("smscore_gpio_configure error");
1495 int smscore_gpio_set_level(struct smscore_device_t
*coredev
, u8 PinNum
,
1503 struct SmsMsgHdr_ST xMsgHeader
;
1504 u32 msgData
[3]; /* keep it 3 ! */
1507 if ((NewLevel
> 1) || (PinNum
> MAX_GPIO_PIN_NUMBER
))
1510 totalLen
= sizeof(struct SmsMsgHdr_ST
) +
1511 (3 * sizeof(u32
)); /* keep it 3 ! */
1513 buffer
= kmalloc(totalLen
+ SMS_DMA_ALIGNMENT
,
1514 GFP_KERNEL
| GFP_DMA
);
1518 pMsg
= (struct SetGpioMsg
*) SMS_ALIGN_ADDRESS(buffer
);
1520 pMsg
->xMsgHeader
.msgSrcId
= DVBT_BDA_CONTROL_MSG_ID
;
1521 pMsg
->xMsgHeader
.msgDstId
= HIF_TASK
;
1522 pMsg
->xMsgHeader
.msgFlags
= 0;
1523 pMsg
->xMsgHeader
.msgType
= MSG_SMS_GPIO_SET_LEVEL_REQ
;
1524 pMsg
->xMsgHeader
.msgLength
= (u16
) totalLen
;
1525 pMsg
->msgData
[0] = PinNum
;
1526 pMsg
->msgData
[1] = NewLevel
;
1528 /* Send message to SMS */
1529 smsendian_handle_tx_message((struct SmsMsgHdr_ST
*)pMsg
);
1530 rc
= smscore_sendrequest_and_wait(coredev
, pMsg
, totalLen
,
1531 &coredev
->gpio_set_level_done
);
1535 sms_err("smscore_gpio_set_level timeout");
1537 sms_err("smscore_gpio_set_level error");
1544 int smscore_gpio_get_level(struct smscore_device_t
*coredev
, u8 PinNum
,
1552 struct SmsMsgHdr_ST xMsgHeader
;
1557 if (PinNum
> MAX_GPIO_PIN_NUMBER
)
1560 totalLen
= sizeof(struct SmsMsgHdr_ST
) + (2 * sizeof(u32
));
1562 buffer
= kmalloc(totalLen
+ SMS_DMA_ALIGNMENT
,
1563 GFP_KERNEL
| GFP_DMA
);
1567 pMsg
= (struct SetGpioMsg
*) SMS_ALIGN_ADDRESS(buffer
);
1569 pMsg
->xMsgHeader
.msgSrcId
= DVBT_BDA_CONTROL_MSG_ID
;
1570 pMsg
->xMsgHeader
.msgDstId
= HIF_TASK
;
1571 pMsg
->xMsgHeader
.msgFlags
= 0;
1572 pMsg
->xMsgHeader
.msgType
= MSG_SMS_GPIO_GET_LEVEL_REQ
;
1573 pMsg
->xMsgHeader
.msgLength
= (u16
) totalLen
;
1574 pMsg
->msgData
[0] = PinNum
;
1575 pMsg
->msgData
[1] = 0;
1577 /* Send message to SMS */
1578 smsendian_handle_tx_message((struct SmsMsgHdr_ST
*)pMsg
);
1579 rc
= smscore_sendrequest_and_wait(coredev
, pMsg
, totalLen
,
1580 &coredev
->gpio_get_level_done
);
1584 sms_err("smscore_gpio_get_level timeout");
1586 sms_err("smscore_gpio_get_level error");
1590 /* Its a race between other gpio_get_level() and the copy of the single
1591 * global 'coredev->gpio_get_res' to the function's variable 'level'
1593 *level
= coredev
->gpio_get_res
;
1598 static int __init
smscore_module_init(void)
1602 INIT_LIST_HEAD(&g_smscore_notifyees
);
1603 INIT_LIST_HEAD(&g_smscore_devices
);
1604 kmutex_init(&g_smscore_deviceslock
);
1606 INIT_LIST_HEAD(&g_smscore_registry
);
1607 kmutex_init(&g_smscore_registrylock
);
1612 static void __exit
smscore_module_exit(void)
1614 kmutex_lock(&g_smscore_deviceslock
);
1615 while (!list_empty(&g_smscore_notifyees
)) {
1616 struct smscore_device_notifyee_t
*notifyee
=
1617 (struct smscore_device_notifyee_t
*)
1618 g_smscore_notifyees
.next
;
1620 list_del(¬ifyee
->entry
);
1623 kmutex_unlock(&g_smscore_deviceslock
);
1625 kmutex_lock(&g_smscore_registrylock
);
1626 while (!list_empty(&g_smscore_registry
)) {
1627 struct smscore_registry_entry_t
*entry
=
1628 (struct smscore_registry_entry_t
*)
1629 g_smscore_registry
.next
;
1631 list_del(&entry
->entry
);
1634 kmutex_unlock(&g_smscore_registrylock
);
1639 module_init(smscore_module_init
);
1640 module_exit(smscore_module_exit
);
1642 MODULE_DESCRIPTION("Siano MDTV Core module");
1643 MODULE_AUTHOR("Siano Mobile Silicon, Inc. (uris@siano-ms.com)");
1644 MODULE_LICENSE("GPL");