Steven Toth | 8d4f9d0 | 2008-05-22 18:05:26 -0300 | [diff] [blame] | 1 | /* |
Michael Krufky | 8544706 | 2008-05-22 18:29:20 -0300 | [diff] [blame] | 2 | * Siano core API module |
Steven Toth | 8d4f9d0 | 2008-05-22 18:05:26 -0300 | [diff] [blame] | 3 | * |
Michael Krufky | 8544706 | 2008-05-22 18:29:20 -0300 | [diff] [blame] | 4 | * This file contains implementation for the interface to sms core component |
| 5 | * |
Uri Shkolnik | e0f14c2 | 2008-08-31 00:44:04 -0300 | [diff] [blame] | 6 | * author: Uri Shkolnik |
Michael Krufky | 8544706 | 2008-05-22 18:29:20 -0300 | [diff] [blame] | 7 | * |
| 8 | * Copyright (c), 2005-2008 Siano Mobile Silicon, Inc. |
Steven Toth | 8d4f9d0 | 2008-05-22 18:05:26 -0300 | [diff] [blame] | 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
Michael Krufky | 09a29b7 | 2008-09-03 16:48:17 -0300 | [diff] [blame] | 11 | * it under the terms of the GNU General Public License version 2 as |
Michael Krufky | 8544706 | 2008-05-22 18:29:20 -0300 | [diff] [blame] | 12 | * published by the Free Software Foundation; |
Steven Toth | 8d4f9d0 | 2008-05-22 18:05:26 -0300 | [diff] [blame] | 13 | * |
Michael Krufky | 8544706 | 2008-05-22 18:29:20 -0300 | [diff] [blame] | 14 | * Software distributed under the License is distributed on an "AS IS" |
| 15 | * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. |
Steven Toth | 8d4f9d0 | 2008-05-22 18:05:26 -0300 | [diff] [blame] | 16 | * |
Michael Krufky | 8544706 | 2008-05-22 18:29:20 -0300 | [diff] [blame] | 17 | * See the GNU General Public License for more details. |
Steven Toth | 8d4f9d0 | 2008-05-22 18:05:26 -0300 | [diff] [blame] | 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 | |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 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> |
Michael Krufky | f1f74aa | 2008-07-12 00:37:08 -0300 | [diff] [blame] | 30 | #include <linux/io.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 31 | #include <linux/slab.h> |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 32 | |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 33 | #include <linux/firmware.h> |
Uri Shkolnik | a934931 | 2009-05-17 05:59:37 -0300 | [diff] [blame] | 34 | #include <linux/wait.h> |
Uri Shkolnik | 01abc0b | 2009-05-17 06:01:03 -0300 | [diff] [blame] | 35 | #include <asm/byteorder.h> |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 36 | |
| 37 | #include "smscoreapi.h" |
Michael Krufky | 02aea4f | 2008-06-26 04:58:30 -0300 | [diff] [blame] | 38 | #include "sms-cards.h" |
Uri Shkolnik | a804800 | 2009-05-14 16:29:35 -0300 | [diff] [blame] | 39 | #include "smsir.h" |
| 40 | #include "smsendian.h" |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 41 | |
Michael Krufky | 0d02efe | 2009-02-27 02:42:16 -0300 | [diff] [blame] | 42 | static int sms_dbg; |
Michael Krufky | b9391f4 | 2008-08-31 16:08:15 -0300 | [diff] [blame] | 43 | module_param_named(debug, sms_dbg, int, 0644); |
Michael Krufky | f14d56a | 2008-06-19 20:59:08 -0300 | [diff] [blame] | 44 | MODULE_PARM_DESC(debug, "set debug level (info=1, adv=2 (or-able))"); |
| 45 | |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 46 | struct smscore_device_notifyee_t { |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 47 | struct list_head entry; |
| 48 | hotplug_t hotplug; |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 49 | }; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 50 | |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 51 | struct smscore_idlist_t { |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 52 | struct list_head entry; |
| 53 | int id; |
| 54 | int data_type; |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 55 | }; |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 56 | |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 57 | struct smscore_client_t { |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 58 | struct list_head entry; |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 59 | struct smscore_device_t *coredev; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 60 | void *context; |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 61 | struct list_head idlist; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 62 | onresponse_t onresponse_handler; |
| 63 | onremove_t onremove_handler; |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 64 | }; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 65 | |
Michael Krufky | 1c11d54 | 2008-06-18 22:09:55 -0300 | [diff] [blame] | 66 | void smscore_set_board_id(struct smscore_device_t *core, int id) |
| 67 | { |
| 68 | core->board_id = id; |
| 69 | } |
| 70 | |
Michael Krufky | 7b29e10 | 2008-11-22 15:32:19 -0300 | [diff] [blame] | 71 | int smscore_led_state(struct smscore_device_t *core, int led) |
| 72 | { |
| 73 | if (led >= 0) |
| 74 | core->led_state = led; |
| 75 | return core->led_state; |
| 76 | } |
Michael Krufky | a0beec8 | 2009-02-26 18:32:36 -0300 | [diff] [blame] | 77 | EXPORT_SYMBOL_GPL(smscore_set_board_id); |
Michael Krufky | 7b29e10 | 2008-11-22 15:32:19 -0300 | [diff] [blame] | 78 | |
Michael Krufky | 1c11d54 | 2008-06-18 22:09:55 -0300 | [diff] [blame] | 79 | int smscore_get_board_id(struct smscore_device_t *core) |
| 80 | { |
| 81 | return core->board_id; |
| 82 | } |
Michael Krufky | a0beec8 | 2009-02-26 18:32:36 -0300 | [diff] [blame] | 83 | EXPORT_SYMBOL_GPL(smscore_get_board_id); |
Michael Krufky | 1c11d54 | 2008-06-18 22:09:55 -0300 | [diff] [blame] | 84 | |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 85 | struct smscore_registry_entry_t { |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 86 | struct list_head entry; |
| 87 | char devpath[32]; |
| 88 | int mode; |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 89 | enum sms_device_type_st type; |
| 90 | }; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 91 | |
Adrian Bunk | c5e0bd1 | 2008-07-21 23:17:36 -0300 | [diff] [blame] | 92 | static struct list_head g_smscore_notifyees; |
| 93 | static struct list_head g_smscore_devices; |
| 94 | static struct mutex g_smscore_deviceslock; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 95 | |
Adrian Bunk | c5e0bd1 | 2008-07-21 23:17:36 -0300 | [diff] [blame] | 96 | static struct list_head g_smscore_registry; |
| 97 | static struct mutex g_smscore_registrylock; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 98 | |
Michael Krufky | dd5b2a5 | 2008-06-18 20:25:25 -0300 | [diff] [blame] | 99 | static int default_mode = 4; |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 100 | |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 101 | module_param(default_mode, int, 0644); |
| 102 | MODULE_PARM_DESC(default_mode, "default firmware id (device mode)"); |
| 103 | |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 104 | static struct smscore_registry_entry_t *smscore_find_registry(char *devpath) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 105 | { |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 106 | struct smscore_registry_entry_t *entry; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 107 | struct list_head *next; |
| 108 | |
| 109 | kmutex_lock(&g_smscore_registrylock); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 110 | for (next = g_smscore_registry.next; |
| 111 | next != &g_smscore_registry; |
| 112 | next = next->next) { |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 113 | entry = (struct smscore_registry_entry_t *) next; |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 114 | if (!strcmp(entry->devpath, devpath)) { |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 115 | kmutex_unlock(&g_smscore_registrylock); |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 116 | return entry; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 117 | } |
| 118 | } |
Joe Perches | 806ec0f | 2010-06-29 01:29:29 -0300 | [diff] [blame] | 119 | entry = kmalloc(sizeof(struct smscore_registry_entry_t), GFP_KERNEL); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 120 | if (entry) { |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 121 | entry->mode = default_mode; |
| 122 | strcpy(entry->devpath, devpath); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 123 | list_add(&entry->entry, &g_smscore_registry); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 124 | } else |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 125 | sms_err("failed to create smscore_registry."); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 126 | kmutex_unlock(&g_smscore_registrylock); |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 127 | return entry; |
| 128 | } |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 129 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 130 | int smscore_registry_getmode(char *devpath) |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 131 | { |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 132 | struct smscore_registry_entry_t *entry; |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 133 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 134 | entry = smscore_find_registry(devpath); |
| 135 | if (entry) |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 136 | return entry->mode; |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 137 | else |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 138 | sms_err("No registry found."); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 139 | |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 140 | return default_mode; |
| 141 | } |
Michael Krufky | a0beec8 | 2009-02-26 18:32:36 -0300 | [diff] [blame] | 142 | EXPORT_SYMBOL_GPL(smscore_registry_getmode); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 143 | |
Michael Krufky | 0c071f3 | 2008-06-21 02:44:02 -0300 | [diff] [blame] | 144 | static enum sms_device_type_st smscore_registry_gettype(char *devpath) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 145 | { |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 146 | struct smscore_registry_entry_t *entry; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 147 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 148 | entry = smscore_find_registry(devpath); |
| 149 | if (entry) |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 150 | return entry->type; |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 151 | else |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 152 | sms_err("No registry found."); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 153 | |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 154 | return -1; |
| 155 | } |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 156 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 157 | void smscore_registry_setmode(char *devpath, int mode) |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 158 | { |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 159 | struct smscore_registry_entry_t *entry; |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 160 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 161 | entry = smscore_find_registry(devpath); |
| 162 | if (entry) |
| 163 | entry->mode = mode; |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 164 | else |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 165 | sms_err("No registry found."); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 166 | } |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 167 | |
Michael Krufky | 0c071f3 | 2008-06-21 02:44:02 -0300 | [diff] [blame] | 168 | static void smscore_registry_settype(char *devpath, |
| 169 | enum sms_device_type_st type) |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 170 | { |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 171 | struct smscore_registry_entry_t *entry; |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 172 | |
| 173 | entry = smscore_find_registry(devpath); |
| 174 | if (entry) |
| 175 | entry->type = type; |
| 176 | else |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 177 | sms_err("No registry found."); |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 178 | } |
| 179 | |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 180 | |
Michael Krufky | 0c071f3 | 2008-06-21 02:44:02 -0300 | [diff] [blame] | 181 | static void list_add_locked(struct list_head *new, struct list_head *head, |
| 182 | spinlock_t *lock) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 183 | { |
| 184 | unsigned long flags; |
| 185 | |
| 186 | spin_lock_irqsave(lock, flags); |
| 187 | |
| 188 | list_add(new, head); |
| 189 | |
| 190 | spin_unlock_irqrestore(lock, flags); |
| 191 | } |
| 192 | |
| 193 | /** |
| 194 | * register a client callback that called when device plugged in/unplugged |
| 195 | * NOTE: if devices exist callback is called immediately for each device |
| 196 | * |
| 197 | * @param hotplug callback |
| 198 | * |
| 199 | * @return 0 on success, <0 on error. |
| 200 | */ |
| 201 | int smscore_register_hotplug(hotplug_t hotplug) |
| 202 | { |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 203 | struct smscore_device_notifyee_t *notifyee; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 204 | struct list_head *next, *first; |
| 205 | int rc = 0; |
| 206 | |
| 207 | kmutex_lock(&g_smscore_deviceslock); |
| 208 | |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 209 | notifyee = kmalloc(sizeof(struct smscore_device_notifyee_t), |
| 210 | GFP_KERNEL); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 211 | if (notifyee) { |
| 212 | /* now notify callback about existing devices */ |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 213 | first = &g_smscore_devices; |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 214 | for (next = first->next; |
| 215 | next != first && !rc; |
| 216 | next = next->next) { |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 217 | struct smscore_device_t *coredev = |
| 218 | (struct smscore_device_t *) next; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 219 | rc = hotplug(coredev, coredev->device, 1); |
| 220 | } |
| 221 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 222 | if (rc >= 0) { |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 223 | notifyee->hotplug = hotplug; |
| 224 | list_add(¬ifyee->entry, &g_smscore_notifyees); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 225 | } else |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 226 | kfree(notifyee); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 227 | } else |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 228 | rc = -ENOMEM; |
| 229 | |
| 230 | kmutex_unlock(&g_smscore_deviceslock); |
| 231 | |
| 232 | return rc; |
| 233 | } |
Michael Krufky | a0beec8 | 2009-02-26 18:32:36 -0300 | [diff] [blame] | 234 | EXPORT_SYMBOL_GPL(smscore_register_hotplug); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 235 | |
| 236 | /** |
| 237 | * unregister a client callback that called when device plugged in/unplugged |
| 238 | * |
| 239 | * @param hotplug callback |
| 240 | * |
| 241 | */ |
| 242 | void smscore_unregister_hotplug(hotplug_t hotplug) |
| 243 | { |
| 244 | struct list_head *next, *first; |
| 245 | |
| 246 | kmutex_lock(&g_smscore_deviceslock); |
| 247 | |
| 248 | first = &g_smscore_notifyees; |
| 249 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 250 | for (next = first->next; next != first;) { |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 251 | struct smscore_device_notifyee_t *notifyee = |
| 252 | (struct smscore_device_notifyee_t *) next; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 253 | next = next->next; |
| 254 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 255 | if (notifyee->hotplug == hotplug) { |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 256 | list_del(¬ifyee->entry); |
| 257 | kfree(notifyee); |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | kmutex_unlock(&g_smscore_deviceslock); |
| 262 | } |
Michael Krufky | a0beec8 | 2009-02-26 18:32:36 -0300 | [diff] [blame] | 263 | EXPORT_SYMBOL_GPL(smscore_unregister_hotplug); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 264 | |
Michael Krufky | 0c071f3 | 2008-06-21 02:44:02 -0300 | [diff] [blame] | 265 | static void smscore_notify_clients(struct smscore_device_t *coredev) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 266 | { |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 267 | struct smscore_client_t *client; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 268 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 269 | /* the client must call smscore_unregister_client from remove handler */ |
| 270 | while (!list_empty(&coredev->clients)) { |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 271 | client = (struct smscore_client_t *) coredev->clients.next; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 272 | client->onremove_handler(client->context); |
| 273 | } |
| 274 | } |
| 275 | |
Michael Krufky | 0c071f3 | 2008-06-21 02:44:02 -0300 | [diff] [blame] | 276 | static int smscore_notify_callbacks(struct smscore_device_t *coredev, |
| 277 | struct device *device, int arrival) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 278 | { |
| 279 | struct list_head *next, *first; |
| 280 | int rc = 0; |
| 281 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 282 | /* note: must be called under g_deviceslock */ |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 283 | |
| 284 | first = &g_smscore_notifyees; |
| 285 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 286 | for (next = first->next; next != first; next = next->next) { |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 287 | rc = ((struct smscore_device_notifyee_t *) next)-> |
Michael Krufky | 59bf6b8 | 2008-06-15 16:50:11 -0300 | [diff] [blame] | 288 | hotplug(coredev, device, arrival); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 289 | if (rc < 0) |
| 290 | break; |
| 291 | } |
| 292 | |
| 293 | return rc; |
| 294 | } |
| 295 | |
Michael Krufky | 0c071f3 | 2008-06-21 02:44:02 -0300 | [diff] [blame] | 296 | static struct |
| 297 | smscore_buffer_t *smscore_createbuffer(u8 *buffer, void *common_buffer, |
Michael Krufky | a83ccdd | 2008-05-06 03:11:51 -0300 | [diff] [blame] | 298 | dma_addr_t common_buffer_phys) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 299 | { |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 300 | struct smscore_buffer_t *cb = |
| 301 | kmalloc(sizeof(struct smscore_buffer_t), GFP_KERNEL); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 302 | if (!cb) { |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 303 | sms_info("kmalloc(...) failed"); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 304 | return NULL; |
| 305 | } |
| 306 | |
| 307 | cb->p = buffer; |
Michael Krufky | 494d24c | 2008-06-14 07:40:41 -0300 | [diff] [blame] | 308 | cb->offset_in_common = buffer - (u8 *) common_buffer; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 309 | cb->phys = common_buffer_phys + cb->offset_in_common; |
| 310 | |
| 311 | return cb; |
| 312 | } |
| 313 | |
| 314 | /** |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 315 | * creates coredev object for a device, prepares buffers, |
| 316 | * creates buffer mappings, notifies registered hotplugs about new device. |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 317 | * |
Michael Krufky | 59bf6b8 | 2008-06-15 16:50:11 -0300 | [diff] [blame] | 318 | * @param params device pointer to struct with device specific parameters |
| 319 | * and handlers |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 320 | * @param coredev pointer to a value that receives created coredev object |
| 321 | * |
| 322 | * @return 0 on success, <0 on error. |
| 323 | */ |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 324 | int smscore_register_device(struct smsdevice_params_t *params, |
| 325 | struct smscore_device_t **coredev) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 326 | { |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 327 | struct smscore_device_t *dev; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 328 | u8 *buffer; |
| 329 | |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 330 | dev = kzalloc(sizeof(struct smscore_device_t), GFP_KERNEL); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 331 | if (!dev) { |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 332 | sms_info("kzalloc(...) failed"); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 333 | return -ENOMEM; |
| 334 | } |
| 335 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 336 | /* init list entry so it could be safe in smscore_unregister_device */ |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 337 | INIT_LIST_HEAD(&dev->entry); |
| 338 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 339 | /* init queues */ |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 340 | INIT_LIST_HEAD(&dev->clients); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 341 | INIT_LIST_HEAD(&dev->buffers); |
| 342 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 343 | /* init locks */ |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 344 | spin_lock_init(&dev->clientslock); |
| 345 | spin_lock_init(&dev->bufferslock); |
| 346 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 347 | /* init completion events */ |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 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); |
Uri Shkolnik | 34601ca | 2009-05-19 12:52:58 -0300 | [diff] [blame] | 354 | init_completion(&dev->gpio_configuration_done); |
| 355 | init_completion(&dev->gpio_set_level_done); |
| 356 | init_completion(&dev->gpio_get_level_done); |
Uri Shkolnik | a804800 | 2009-05-14 16:29:35 -0300 | [diff] [blame] | 357 | init_completion(&dev->ir_init_done); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 358 | |
Uri Shkolnik | a934931 | 2009-05-17 05:59:37 -0300 | [diff] [blame] | 359 | /* Buffer management */ |
| 360 | init_waitqueue_head(&dev->buffer_mng_waitq); |
| 361 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 362 | /* alloc common buffer */ |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 363 | dev->common_buffer_size = params->buffer_size * params->num_buffers; |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 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) { |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 368 | smscore_unregister_device(dev); |
| 369 | return -ENOMEM; |
| 370 | } |
| 371 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 372 | /* prepare dma buffers */ |
| 373 | for (buffer = dev->common_buffer; |
| 374 | dev->num_buffers < params->num_buffers; |
Michael Krufky | fa830e8 | 2008-06-15 15:52:43 -0300 | [diff] [blame] | 375 | dev->num_buffers++, buffer += params->buffer_size) { |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 376 | struct smscore_buffer_t *cb = |
Michael Krufky | 59bf6b8 | 2008-06-15 16:50:11 -0300 | [diff] [blame] | 377 | smscore_createbuffer(buffer, dev->common_buffer, |
| 378 | dev->common_buffer_phys); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 379 | if (!cb) { |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 380 | smscore_unregister_device(dev); |
| 381 | return -ENOMEM; |
| 382 | } |
| 383 | |
| 384 | smscore_putbuffer(dev, cb); |
| 385 | } |
| 386 | |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 387 | sms_info("allocated %d buffers", dev->num_buffers); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 388 | |
| 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; |
| 397 | |
| 398 | dev->device_flags = params->flags; |
| 399 | strcpy(dev->devpath, params->devpath); |
| 400 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 401 | smscore_registry_settype(dev->devpath, params->device_type); |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 402 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 403 | /* add device to devices list */ |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 404 | kmutex_lock(&g_smscore_deviceslock); |
| 405 | list_add(&dev->entry, &g_smscore_devices); |
| 406 | kmutex_unlock(&g_smscore_deviceslock); |
| 407 | |
| 408 | *coredev = dev; |
| 409 | |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 410 | sms_info("device %p created", dev); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 411 | |
| 412 | return 0; |
| 413 | } |
Michael Krufky | a0beec8 | 2009-02-26 18:32:36 -0300 | [diff] [blame] | 414 | EXPORT_SYMBOL_GPL(smscore_register_device); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 415 | |
Uri Shkolnik | a804800 | 2009-05-14 16:29:35 -0300 | [diff] [blame] | 416 | |
| 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); |
| 420 | if (rc < 0) { |
| 421 | sms_info("sendrequest returned error %d", rc); |
| 422 | return rc; |
| 423 | } |
| 424 | |
| 425 | return wait_for_completion_timeout(completion, |
| 426 | msecs_to_jiffies(SMS_PROTOCOL_MAX_RAOUNDTRIP_MS)) ? |
| 427 | 0 : -ETIME; |
| 428 | } |
| 429 | |
| 430 | /** |
| 431 | * Starts & enables IR operations |
| 432 | * |
| 433 | * @return 0 on success, < 0 on error. |
| 434 | */ |
| 435 | static int smscore_init_ir(struct smscore_device_t *coredev) |
| 436 | { |
| 437 | int ir_io; |
| 438 | int rc; |
| 439 | void *buffer; |
| 440 | |
| 441 | coredev->ir.input_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); |
| 446 | |
| 447 | if (rc != 0) |
| 448 | sms_err("Error initialization DTV IR sub-module"); |
| 449 | else { |
| 450 | buffer = kmalloc(sizeof(struct SmsMsgData_ST2) + |
| 451 | SMS_DMA_ALIGNMENT, |
| 452 | GFP_KERNEL | GFP_DMA); |
| 453 | if (buffer) { |
| 454 | struct SmsMsgData_ST2 *msg = |
| 455 | (struct SmsMsgData_ST2 *) |
| 456 | SMS_ALIGN_ADDRESS(buffer); |
| 457 | |
| 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; |
| 463 | |
| 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); |
| 469 | |
| 470 | kfree(buffer); |
| 471 | } else |
| 472 | sms_err |
| 473 | ("Sending IR initialization message failed"); |
| 474 | } |
| 475 | } else |
| 476 | sms_info("IR port has not been detected"); |
| 477 | |
| 478 | return 0; |
| 479 | } |
| 480 | |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 481 | /** |
| 482 | * sets initial device mode and notifies client hotplugs that device is ready |
| 483 | * |
Michael Krufky | 59bf6b8 | 2008-06-15 16:50:11 -0300 | [diff] [blame] | 484 | * @param coredev pointer to a coredev object returned by |
| 485 | * smscore_register_device |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 486 | * |
| 487 | * @return 0 on success, <0 on error. |
| 488 | */ |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 489 | int smscore_start_device(struct smscore_device_t *coredev) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 490 | { |
Michael Krufky | 59bf6b8 | 2008-06-15 16:50:11 -0300 | [diff] [blame] | 491 | int rc = smscore_set_device_mode( |
| 492 | coredev, smscore_registry_getmode(coredev->devpath)); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 493 | if (rc < 0) { |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 494 | sms_info("set device mode faile , rc %d", rc); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 495 | return rc; |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 496 | } |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 497 | |
| 498 | kmutex_lock(&g_smscore_deviceslock); |
| 499 | |
| 500 | rc = smscore_notify_callbacks(coredev, coredev->device, 1); |
Uri Shkolnik | a804800 | 2009-05-14 16:29:35 -0300 | [diff] [blame] | 501 | smscore_init_ir(coredev); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 502 | |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 503 | sms_info("device %p started, rc %d", coredev, rc); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 504 | |
| 505 | kmutex_unlock(&g_smscore_deviceslock); |
| 506 | |
| 507 | return rc; |
| 508 | } |
Michael Krufky | a0beec8 | 2009-02-26 18:32:36 -0300 | [diff] [blame] | 509 | EXPORT_SYMBOL_GPL(smscore_start_device); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 510 | |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 511 | |
Michael Krufky | 0c071f3 | 2008-06-21 02:44:02 -0300 | [diff] [blame] | 512 | static int smscore_load_firmware_family2(struct smscore_device_t *coredev, |
| 513 | void *buffer, size_t size) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 514 | { |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 515 | struct SmsFirmware_ST *firmware = (struct SmsFirmware_ST *) buffer; |
| 516 | struct SmsMsgHdr_ST *msg; |
Uri Shkolnik | 01abc0b | 2009-05-17 06:01:03 -0300 | [diff] [blame] | 517 | u32 mem_address; |
Michael Krufky | a83ccdd | 2008-05-06 03:11:51 -0300 | [diff] [blame] | 518 | u8 *payload = firmware->Payload; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 519 | int rc = 0; |
Uri Shkolnik | 01abc0b | 2009-05-17 06:01:03 -0300 | [diff] [blame] | 520 | firmware->StartAddress = le32_to_cpu(firmware->StartAddress); |
| 521 | firmware->Length = le32_to_cpu(firmware->Length); |
| 522 | |
| 523 | mem_address = firmware->StartAddress; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 524 | |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 525 | sms_info("loading FW to addr 0x%x size %d", |
| 526 | mem_address, firmware->Length); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 527 | if (coredev->preload_handler) { |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 528 | rc = coredev->preload_handler(coredev->context); |
| 529 | if (rc < 0) |
| 530 | return rc; |
| 531 | } |
| 532 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 533 | /* PAGE_SIZE buffer shall be enough and dma aligned */ |
Michael Krufky | e080842 | 2008-06-15 19:11:37 -0300 | [diff] [blame] | 534 | msg = kmalloc(PAGE_SIZE, GFP_KERNEL | GFP_DMA); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 535 | if (!msg) |
| 536 | return -ENOMEM; |
| 537 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 538 | if (coredev->mode != DEVICE_MODE_NONE) { |
Michael Krufky | 2522dc1 | 2008-06-19 22:15:38 -0300 | [diff] [blame] | 539 | sms_debug("sending reload command."); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 540 | SMS_INIT_MSG(msg, MSG_SW_RELOAD_START_REQ, |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 541 | sizeof(struct SmsMsgHdr_ST)); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 542 | rc = smscore_sendrequest_and_wait(coredev, msg, |
| 543 | msg->msgLength, |
| 544 | &coredev->reload_start_done); |
Michael Krufky | f0333e3 | 2008-06-15 15:32:00 -0300 | [diff] [blame] | 545 | mem_address = *(u32 *) &payload[20]; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 546 | } |
| 547 | |
Michael Krufky | fa830e8 | 2008-06-15 15:52:43 -0300 | [diff] [blame] | 548 | while (size && rc >= 0) { |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 549 | struct SmsDataDownload_ST *DataMsg = |
| 550 | (struct SmsDataDownload_ST *) msg; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 551 | int payload_size = min((int) size, SMS_MAX_PAYLOAD_SIZE); |
| 552 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 553 | SMS_INIT_MSG(msg, MSG_SMS_DATA_DOWNLOAD_REQ, |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 554 | (u16)(sizeof(struct SmsMsgHdr_ST) + |
Michael Krufky | f0333e3 | 2008-06-15 15:32:00 -0300 | [diff] [blame] | 555 | sizeof(u32) + payload_size)); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 556 | |
| 557 | DataMsg->MemAddr = mem_address; |
| 558 | memcpy(DataMsg->Payload, payload, payload_size); |
| 559 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 560 | if ((coredev->device_flags & SMS_ROM_NO_RESPONSE) && |
| 561 | (coredev->mode == DEVICE_MODE_NONE)) |
Michael Krufky | 59bf6b8 | 2008-06-15 16:50:11 -0300 | [diff] [blame] | 562 | rc = coredev->sendrequest_handler( |
| 563 | coredev->context, DataMsg, |
| 564 | DataMsg->xMsgHeader.msgLength); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 565 | else |
Michael Krufky | 59bf6b8 | 2008-06-15 16:50:11 -0300 | [diff] [blame] | 566 | rc = smscore_sendrequest_and_wait( |
| 567 | coredev, DataMsg, |
| 568 | DataMsg->xMsgHeader.msgLength, |
| 569 | &coredev->data_download_done); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 570 | |
| 571 | payload += payload_size; |
| 572 | size -= payload_size; |
| 573 | mem_address += payload_size; |
| 574 | } |
| 575 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 576 | if (rc >= 0) { |
| 577 | if (coredev->mode == DEVICE_MODE_NONE) { |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 578 | struct SmsMsgData_ST *TriggerMsg = |
| 579 | (struct SmsMsgData_ST *) msg; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 580 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 581 | SMS_INIT_MSG(msg, MSG_SMS_SWDOWNLOAD_TRIGGER_REQ, |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 582 | sizeof(struct SmsMsgHdr_ST) + |
Michael Krufky | f0333e3 | 2008-06-15 15:32:00 -0300 | [diff] [blame] | 583 | sizeof(u32) * 5); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 584 | |
Michael Krufky | 59bf6b8 | 2008-06-15 16:50:11 -0300 | [diff] [blame] | 585 | TriggerMsg->msgData[0] = firmware->StartAddress; |
| 586 | /* Entry point */ |
Michael Krufky | fa830e8 | 2008-06-15 15:52:43 -0300 | [diff] [blame] | 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 */ |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 591 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 592 | if (coredev->device_flags & SMS_ROM_NO_RESPONSE) { |
Michael Krufky | 59bf6b8 | 2008-06-15 16:50:11 -0300 | [diff] [blame] | 593 | rc = coredev->sendrequest_handler( |
| 594 | coredev->context, TriggerMsg, |
| 595 | TriggerMsg->xMsgHeader.msgLength); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 596 | msleep(100); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 597 | } else |
Michael Krufky | 59bf6b8 | 2008-06-15 16:50:11 -0300 | [diff] [blame] | 598 | rc = smscore_sendrequest_and_wait( |
| 599 | coredev, TriggerMsg, |
| 600 | TriggerMsg->xMsgHeader.msgLength, |
| 601 | &coredev->trigger_done); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 602 | } else { |
| 603 | SMS_INIT_MSG(msg, MSG_SW_RELOAD_EXEC_REQ, |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 604 | sizeof(struct SmsMsgHdr_ST)); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 605 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 606 | rc = coredev->sendrequest_handler(coredev->context, |
| 607 | msg, msg->msgLength); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 608 | } |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 609 | msleep(500); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 610 | } |
| 611 | |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 612 | sms_debug("rc=%d, postload=%p ", rc, |
Michael Krufky | 068d6c0 | 2008-06-19 01:15:46 -0300 | [diff] [blame] | 613 | coredev->postload_handler); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 614 | |
| 615 | kfree(msg); |
| 616 | |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 617 | return ((rc >= 0) && coredev->postload_handler) ? |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 618 | coredev->postload_handler(coredev->context) : |
| 619 | rc; |
| 620 | } |
| 621 | |
| 622 | /** |
| 623 | * loads specified firmware into a buffer and calls device loadfirmware_handler |
| 624 | * |
Michael Krufky | 59bf6b8 | 2008-06-15 16:50:11 -0300 | [diff] [blame] | 625 | * @param coredev pointer to a coredev object returned by |
| 626 | * smscore_register_device |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 627 | * @param filename null-terminated string specifies firmware file name |
| 628 | * @param loadfirmware_handler device handler that loads firmware |
| 629 | * |
| 630 | * @return 0 on success, <0 on error. |
| 631 | */ |
Michael Krufky | 0c071f3 | 2008-06-21 02:44:02 -0300 | [diff] [blame] | 632 | static int smscore_load_firmware_from_file(struct smscore_device_t *coredev, |
| 633 | char *filename, |
| 634 | loadfirmware_t loadfirmware_handler) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 635 | { |
| 636 | int rc = -ENOENT; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 637 | const struct firmware *fw; |
Michael Krufky | a83ccdd | 2008-05-06 03:11:51 -0300 | [diff] [blame] | 638 | u8 *fw_buffer; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 639 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 640 | if (loadfirmware_handler == NULL && !(coredev->device_flags & |
| 641 | SMS_DEVICE_FAMILY2)) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 642 | return -EINVAL; |
| 643 | |
| 644 | rc = request_firmware(&fw, filename, coredev->device); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 645 | if (rc < 0) { |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 646 | sms_info("failed to open \"%s\"", filename); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 647 | return rc; |
| 648 | } |
Michael Krufky | 0f2a1ee | 2008-06-28 20:53:45 -0300 | [diff] [blame] | 649 | sms_info("read FW %s, size=%zd", filename, fw->size); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 650 | fw_buffer = kmalloc(ALIGN(fw->size, SMS_ALLOC_ALIGNMENT), |
| 651 | GFP_KERNEL | GFP_DMA); |
| 652 | if (fw_buffer) { |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 653 | memcpy(fw_buffer, fw->data, fw->size); |
| 654 | |
| 655 | rc = (coredev->device_flags & SMS_DEVICE_FAMILY2) ? |
Michael Krufky | 59bf6b8 | 2008-06-15 16:50:11 -0300 | [diff] [blame] | 656 | smscore_load_firmware_family2(coredev, |
| 657 | fw_buffer, |
| 658 | fw->size) : |
| 659 | loadfirmware_handler(coredev->context, |
| 660 | fw_buffer, fw->size); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 661 | |
| 662 | kfree(fw_buffer); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 663 | } else { |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 664 | sms_info("failed to allocate firmware buffer"); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 665 | rc = -ENOMEM; |
| 666 | } |
| 667 | |
| 668 | release_firmware(fw); |
| 669 | |
| 670 | return rc; |
| 671 | } |
| 672 | |
| 673 | /** |
Michael Krufky | 59bf6b8 | 2008-06-15 16:50:11 -0300 | [diff] [blame] | 674 | * notifies all clients registered with the device, notifies hotplugs, |
| 675 | * frees all buffers and coredev object |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 676 | * |
Michael Krufky | 59bf6b8 | 2008-06-15 16:50:11 -0300 | [diff] [blame] | 677 | * @param coredev pointer to a coredev object returned by |
| 678 | * smscore_register_device |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 679 | * |
| 680 | * @return 0 on success, <0 on error. |
| 681 | */ |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 682 | void smscore_unregister_device(struct smscore_device_t *coredev) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 683 | { |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 684 | struct smscore_buffer_t *cb; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 685 | int num_buffers = 0; |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 686 | int retry = 0; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 687 | |
| 688 | kmutex_lock(&g_smscore_deviceslock); |
| 689 | |
Uri Shkolnik | a804800 | 2009-05-14 16:29:35 -0300 | [diff] [blame] | 690 | /* Release input device (IR) resources */ |
| 691 | sms_ir_exit(coredev); |
| 692 | |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 693 | smscore_notify_clients(coredev); |
| 694 | smscore_notify_callbacks(coredev, NULL, 0); |
| 695 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 696 | /* at this point all buffers should be back |
| 697 | * onresponse must no longer be called */ |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 698 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 699 | while (1) { |
Uri Shkolnik | a934931 | 2009-05-17 05:59:37 -0300 | [diff] [blame] | 700 | while (!list_empty(&coredev->buffers)) { |
| 701 | cb = (struct smscore_buffer_t *) coredev->buffers.next; |
| 702 | list_del(&cb->entry); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 703 | kfree(cb); |
Michael Krufky | fa830e8 | 2008-06-15 15:52:43 -0300 | [diff] [blame] | 704 | num_buffers++; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 705 | } |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 706 | if (num_buffers == coredev->num_buffers) |
| 707 | break; |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 708 | if (++retry > 10) { |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 709 | sms_info("exiting although " |
| 710 | "not all buffers released."); |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 711 | break; |
| 712 | } |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 713 | |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 714 | sms_info("waiting for %d buffer(s)", |
Michael Krufky | 068d6c0 | 2008-06-19 01:15:46 -0300 | [diff] [blame] | 715 | coredev->num_buffers - num_buffers); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 716 | msleep(100); |
| 717 | } |
| 718 | |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 719 | sms_info("freed %d buffers", num_buffers); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 720 | |
| 721 | if (coredev->common_buffer) |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 722 | dma_free_coherent(NULL, coredev->common_buffer_size, |
Uri Shkolnik | a934931 | 2009-05-17 05:59:37 -0300 | [diff] [blame] | 723 | coredev->common_buffer, coredev->common_buffer_phys); |
| 724 | |
| 725 | if (coredev->fw_buf != NULL) |
| 726 | kfree(coredev->fw_buf); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 727 | |
| 728 | list_del(&coredev->entry); |
| 729 | kfree(coredev); |
| 730 | |
| 731 | kmutex_unlock(&g_smscore_deviceslock); |
| 732 | |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 733 | sms_info("device %p destroyed", coredev); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 734 | } |
Michael Krufky | a0beec8 | 2009-02-26 18:32:36 -0300 | [diff] [blame] | 735 | EXPORT_SYMBOL_GPL(smscore_unregister_device); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 736 | |
Michael Krufky | 0c071f3 | 2008-06-21 02:44:02 -0300 | [diff] [blame] | 737 | static int smscore_detect_mode(struct smscore_device_t *coredev) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 738 | { |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 739 | void *buffer = kmalloc(sizeof(struct SmsMsgHdr_ST) + SMS_DMA_ALIGNMENT, |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 740 | GFP_KERNEL | GFP_DMA); |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 741 | struct SmsMsgHdr_ST *msg = |
| 742 | (struct SmsMsgHdr_ST *) SMS_ALIGN_ADDRESS(buffer); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 743 | int rc; |
| 744 | |
| 745 | if (!buffer) |
| 746 | return -ENOMEM; |
| 747 | |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 748 | SMS_INIT_MSG(msg, MSG_SMS_GET_VERSION_EX_REQ, |
| 749 | sizeof(struct SmsMsgHdr_ST)); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 750 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 751 | rc = smscore_sendrequest_and_wait(coredev, msg, msg->msgLength, |
| 752 | &coredev->version_ex_done); |
| 753 | if (rc == -ETIME) { |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 754 | sms_err("MSG_SMS_GET_VERSION_EX_REQ failed first try"); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 755 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 756 | if (wait_for_completion_timeout(&coredev->resume_done, |
| 757 | msecs_to_jiffies(5000))) { |
Michael Krufky | 59bf6b8 | 2008-06-15 16:50:11 -0300 | [diff] [blame] | 758 | rc = smscore_sendrequest_and_wait( |
| 759 | coredev, msg, msg->msgLength, |
| 760 | &coredev->version_ex_done); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 761 | if (rc < 0) |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 762 | sms_err("MSG_SMS_GET_VERSION_EX_REQ failed " |
| 763 | "second try, rc %d", rc); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 764 | } else |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 765 | rc = -ETIME; |
| 766 | } |
| 767 | |
| 768 | kfree(buffer); |
| 769 | |
| 770 | return rc; |
| 771 | } |
| 772 | |
Michael Krufky | 0c071f3 | 2008-06-21 02:44:02 -0300 | [diff] [blame] | 773 | static char *smscore_fw_lkup[][SMS_NUM_OF_DEVICE_TYPES] = { |
Michael Krufky | fbd05c8 | 2008-06-15 19:27:35 -0300 | [diff] [blame] | 774 | /*Stellar NOVA A0 Nova B0 VEGA*/ |
| 775 | /*DVBT*/ |
| 776 | {"none", "dvb_nova_12mhz.inp", "dvb_nova_12mhz_b0.inp", "none"}, |
| 777 | /*DVBH*/ |
| 778 | {"none", "dvb_nova_12mhz.inp", "dvb_nova_12mhz_b0.inp", "none"}, |
| 779 | /*TDMB*/ |
Uri Shkolnik | e0f14c2 | 2008-08-31 00:44:04 -0300 | [diff] [blame] | 780 | {"none", "tdmb_nova_12mhz.inp", "tdmb_nova_12mhz_b0.inp", "none"}, |
Michael Krufky | fbd05c8 | 2008-06-15 19:27:35 -0300 | [diff] [blame] | 781 | /*DABIP*/ |
| 782 | {"none", "none", "none", "none"}, |
| 783 | /*BDA*/ |
| 784 | {"none", "dvb_nova_12mhz.inp", "dvb_nova_12mhz_b0.inp", "none"}, |
| 785 | /*ISDBT*/ |
Uri Shkolnik | 8cc8ef2 | 2009-05-17 06:01:55 -0300 | [diff] [blame] | 786 | {"none", "isdbt_nova_12mhz.inp", "isdbt_nova_12mhz_b0.inp", "none"}, |
Michael Krufky | fbd05c8 | 2008-06-15 19:27:35 -0300 | [diff] [blame] | 787 | /*ISDBTBDA*/ |
| 788 | {"none", "isdbt_nova_12mhz.inp", "isdbt_nova_12mhz_b0.inp", "none"}, |
| 789 | /*CMMB*/ |
| 790 | {"none", "none", "none", "cmmb_vega_12mhz.inp"} |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 791 | }; |
| 792 | |
Michael Krufky | 02aea4f | 2008-06-26 04:58:30 -0300 | [diff] [blame] | 793 | static inline char *sms_get_fw_name(struct smscore_device_t *coredev, |
| 794 | int mode, enum sms_device_type_st type) |
| 795 | { |
| 796 | char **fw = sms_get_board(smscore_get_board_id(coredev))->fw; |
| 797 | return (fw && fw[mode]) ? fw[mode] : smscore_fw_lkup[mode][type]; |
| 798 | } |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 799 | |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 800 | /** |
| 801 | * calls device handler to change mode of operation |
| 802 | * NOTE: stellar/usb may disconnect when changing mode |
| 803 | * |
Michael Krufky | 59bf6b8 | 2008-06-15 16:50:11 -0300 | [diff] [blame] | 804 | * @param coredev pointer to a coredev object returned by |
| 805 | * smscore_register_device |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 806 | * @param mode requested mode of operation |
| 807 | * |
| 808 | * @return 0 on success, <0 on error. |
| 809 | */ |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 810 | int smscore_set_device_mode(struct smscore_device_t *coredev, int mode) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 811 | { |
| 812 | void *buffer; |
| 813 | int rc = 0; |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 814 | enum sms_device_type_st type; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 815 | |
Michael Krufky | 2522dc1 | 2008-06-19 22:15:38 -0300 | [diff] [blame] | 816 | sms_debug("set device mode to %d", mode); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 817 | if (coredev->device_flags & SMS_DEVICE_FAMILY2) { |
Roel Kluin | 08b3964 | 2009-08-10 22:59:33 -0300 | [diff] [blame] | 818 | if (mode < DEVICE_MODE_DVBT || mode >= DEVICE_MODE_RAW_TUNER) { |
Michael Krufky | eb25094 | 2008-06-19 22:07:23 -0300 | [diff] [blame] | 819 | sms_err("invalid mode specified %d", mode); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 820 | return -EINVAL; |
| 821 | } |
| 822 | |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 823 | smscore_registry_setmode(coredev->devpath, mode); |
| 824 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 825 | if (!(coredev->device_flags & SMS_DEVICE_NOT_READY)) { |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 826 | rc = smscore_detect_mode(coredev); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 827 | if (rc < 0) { |
Michael Krufky | eb25094 | 2008-06-19 22:07:23 -0300 | [diff] [blame] | 828 | sms_err("mode detect failed %d", rc); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 829 | return rc; |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 830 | } |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 831 | } |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 832 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 833 | if (coredev->mode == mode) { |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 834 | sms_info("device mode %d already set", mode); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 835 | return 0; |
| 836 | } |
| 837 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 838 | if (!(coredev->modes_supported & (1 << mode))) { |
Michael Krufky | 02aea4f | 2008-06-26 04:58:30 -0300 | [diff] [blame] | 839 | char *fw_filename; |
| 840 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 841 | type = smscore_registry_gettype(coredev->devpath); |
Michael Krufky | 02aea4f | 2008-06-26 04:58:30 -0300 | [diff] [blame] | 842 | fw_filename = sms_get_fw_name(coredev, mode, type); |
| 843 | |
| 844 | rc = smscore_load_firmware_from_file(coredev, |
| 845 | fw_filename, NULL); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 846 | if (rc < 0) { |
Michael Krufky | 5068b7a | 2008-06-28 23:27:19 -0300 | [diff] [blame] | 847 | sms_warn("error %d loading firmware: %s, " |
| 848 | "trying again with default firmware", |
| 849 | rc, fw_filename); |
Michael Krufky | 02aea4f | 2008-06-26 04:58:30 -0300 | [diff] [blame] | 850 | |
| 851 | /* try again with the default firmware */ |
Michael Krufky | 5068b7a | 2008-06-28 23:27:19 -0300 | [diff] [blame] | 852 | fw_filename = smscore_fw_lkup[mode][type]; |
Michael Krufky | 02aea4f | 2008-06-26 04:58:30 -0300 | [diff] [blame] | 853 | rc = smscore_load_firmware_from_file(coredev, |
Michael Krufky | 5068b7a | 2008-06-28 23:27:19 -0300 | [diff] [blame] | 854 | fw_filename, NULL); |
Michael Krufky | 02aea4f | 2008-06-26 04:58:30 -0300 | [diff] [blame] | 855 | |
| 856 | if (rc < 0) { |
Michael Krufky | 5068b7a | 2008-06-28 23:27:19 -0300 | [diff] [blame] | 857 | sms_warn("error %d loading " |
| 858 | "firmware: %s", rc, |
| 859 | fw_filename); |
Michael Krufky | 02aea4f | 2008-06-26 04:58:30 -0300 | [diff] [blame] | 860 | return rc; |
| 861 | } |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 862 | } |
Michael Krufky | 5068b7a | 2008-06-28 23:27:19 -0300 | [diff] [blame] | 863 | sms_log("firmware download success: %s", fw_filename); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 864 | } else |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 865 | sms_info("mode %d supported by running " |
| 866 | "firmware", mode); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 867 | |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 868 | buffer = kmalloc(sizeof(struct SmsMsgData_ST) + |
| 869 | SMS_DMA_ALIGNMENT, GFP_KERNEL | GFP_DMA); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 870 | if (buffer) { |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 871 | struct SmsMsgData_ST *msg = |
| 872 | (struct SmsMsgData_ST *) |
| 873 | SMS_ALIGN_ADDRESS(buffer); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 874 | |
Michael Krufky | 59bf6b8 | 2008-06-15 16:50:11 -0300 | [diff] [blame] | 875 | SMS_INIT_MSG(&msg->xMsgHeader, MSG_SMS_INIT_DEVICE_REQ, |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 876 | sizeof(struct SmsMsgData_ST)); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 877 | msg->msgData[0] = mode; |
| 878 | |
Michael Krufky | 59bf6b8 | 2008-06-15 16:50:11 -0300 | [diff] [blame] | 879 | rc = smscore_sendrequest_and_wait( |
| 880 | coredev, msg, msg->xMsgHeader.msgLength, |
| 881 | &coredev->init_device_done); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 882 | |
| 883 | kfree(buffer); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 884 | } else { |
Michael Krufky | eb25094 | 2008-06-19 22:07:23 -0300 | [diff] [blame] | 885 | sms_err("Could not allocate buffer for " |
| 886 | "init device message."); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 887 | rc = -ENOMEM; |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 888 | } |
| 889 | } else { |
| 890 | if (mode < DEVICE_MODE_DVBT || mode > DEVICE_MODE_DVBT_BDA) { |
Michael Krufky | eb25094 | 2008-06-19 22:07:23 -0300 | [diff] [blame] | 891 | sms_err("invalid mode specified %d", mode); |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 892 | return -EINVAL; |
| 893 | } |
| 894 | |
| 895 | smscore_registry_setmode(coredev->devpath, mode); |
| 896 | |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 897 | if (coredev->detectmode_handler) |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 898 | coredev->detectmode_handler(coredev->context, |
| 899 | &coredev->mode); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 900 | |
| 901 | if (coredev->mode != mode && coredev->setmode_handler) |
| 902 | rc = coredev->setmode_handler(coredev->context, mode); |
| 903 | } |
| 904 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 905 | if (rc >= 0) { |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 906 | coredev->mode = mode; |
| 907 | coredev->device_flags &= ~SMS_DEVICE_NOT_READY; |
| 908 | } |
| 909 | |
Uri Shkolnik | 5d2387e | 2009-05-17 06:02:46 -0300 | [diff] [blame] | 910 | if (rc < 0) |
Michael Krufky | eb25094 | 2008-06-19 22:07:23 -0300 | [diff] [blame] | 911 | sms_err("return error code %d.", rc); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 912 | return rc; |
| 913 | } |
| 914 | |
| 915 | /** |
| 916 | * calls device handler to get current mode of operation |
| 917 | * |
Michael Krufky | 59bf6b8 | 2008-06-15 16:50:11 -0300 | [diff] [blame] | 918 | * @param coredev pointer to a coredev object returned by |
| 919 | * smscore_register_device |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 920 | * |
| 921 | * @return current mode |
| 922 | */ |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 923 | int smscore_get_device_mode(struct smscore_device_t *coredev) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 924 | { |
| 925 | return coredev->mode; |
| 926 | } |
Michael Krufky | a0beec8 | 2009-02-26 18:32:36 -0300 | [diff] [blame] | 927 | EXPORT_SYMBOL_GPL(smscore_get_device_mode); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 928 | |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 929 | /** |
| 930 | * find client by response id & type within the clients list. |
| 931 | * return client handle or NULL. |
| 932 | * |
Michael Krufky | 59bf6b8 | 2008-06-15 16:50:11 -0300 | [diff] [blame] | 933 | * @param coredev pointer to a coredev object returned by |
| 934 | * smscore_register_device |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 935 | * @param data_type client data type (SMS_DONT_CARE for all types) |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 936 | * @param id client id (SMS_DONT_CARE for all id) |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 937 | * |
| 938 | */ |
Michael Krufky | 0c071f3 | 2008-06-21 02:44:02 -0300 | [diff] [blame] | 939 | static struct |
| 940 | smscore_client_t *smscore_find_client(struct smscore_device_t *coredev, |
Michael Krufky | 59bf6b8 | 2008-06-15 16:50:11 -0300 | [diff] [blame] | 941 | int data_type, int id) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 942 | { |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 943 | struct smscore_client_t *client = NULL; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 944 | struct list_head *next, *first; |
| 945 | unsigned long flags; |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 946 | struct list_head *firstid, *nextid; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 947 | |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 948 | |
| 949 | spin_lock_irqsave(&coredev->clientslock, flags); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 950 | first = &coredev->clients; |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 951 | for (next = first->next; |
| 952 | (next != first) && !client; |
| 953 | next = next->next) { |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 954 | firstid = &((struct smscore_client_t *)next)->idlist; |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 955 | for (nextid = firstid->next; |
| 956 | nextid != firstid; |
| 957 | nextid = nextid->next) { |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 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; |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 962 | break; |
| 963 | } |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 964 | } |
| 965 | } |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 966 | spin_unlock_irqrestore(&coredev->clientslock, flags); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 967 | return client; |
| 968 | } |
| 969 | |
| 970 | /** |
| 971 | * find client by response id/type, call clients onresponse handler |
| 972 | * return buffer to pool on error |
| 973 | * |
Michael Krufky | 59bf6b8 | 2008-06-15 16:50:11 -0300 | [diff] [blame] | 974 | * @param coredev pointer to a coredev object returned by |
| 975 | * smscore_register_device |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 976 | * @param cb pointer to response buffer descriptor |
| 977 | * |
| 978 | */ |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 979 | void smscore_onresponse(struct smscore_device_t *coredev, |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 980 | struct smscore_buffer_t *cb) { |
| 981 | struct SmsMsgHdr_ST *phdr = (struct SmsMsgHdr_ST *) ((u8 *) cb->p |
| 982 | + cb->offset); |
| 983 | struct smscore_client_t *client; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 984 | int rc = -EBUSY; |
Michael Krufky | fbd05c8 | 2008-06-15 19:27:35 -0300 | [diff] [blame] | 985 | static unsigned long last_sample_time; /* = 0; */ |
| 986 | static int data_total; /* = 0; */ |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 987 | unsigned long time_now = jiffies_to_msecs(jiffies); |
| 988 | |
| 989 | if (!last_sample_time) |
| 990 | last_sample_time = time_now; |
| 991 | |
Michael Krufky | fa830e8 | 2008-06-15 15:52:43 -0300 | [diff] [blame] | 992 | if (time_now - last_sample_time > 10000) { |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 993 | sms_debug("\ndata rate %d bytes/secs", |
Michael Krufky | 068d6c0 | 2008-06-19 01:15:46 -0300 | [diff] [blame] | 994 | (int)((data_total * 1000) / |
| 995 | (time_now - last_sample_time))); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 996 | |
| 997 | last_sample_time = time_now; |
| 998 | data_total = 0; |
| 999 | } |
| 1000 | |
| 1001 | data_total += cb->size; |
Uri Shkolnik | 793786d | 2009-05-12 12:28:46 -0300 | [diff] [blame] | 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; |
| 1007 | } |
| 1008 | |
| 1009 | |
| 1010 | client = smscore_find_client(coredev, phdr->msgType, phdr->msgDstId); |
| 1011 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 1012 | /* If no client registered for type & id, |
| 1013 | * check for control client where type is not registered */ |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1014 | if (client) |
| 1015 | rc = client->onresponse_handler(client->context, cb); |
| 1016 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 1017 | if (rc < 0) { |
| 1018 | switch (phdr->msgType) { |
| 1019 | case MSG_SMS_GET_VERSION_EX_RES: |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1020 | { |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 1021 | struct SmsVersionRes_ST *ver = |
| 1022 | (struct SmsVersionRes_ST *) phdr; |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 1023 | sms_debug("MSG_SMS_GET_VERSION_EX_RES " |
| 1024 | "id %d prots 0x%x ver %d.%d", |
Michael Krufky | 068d6c0 | 2008-06-19 01:15:46 -0300 | [diff] [blame] | 1025 | ver->FirmwareId, ver->SupportedProtocols, |
| 1026 | ver->RomVersionMajor, ver->RomVersionMinor); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1027 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 1028 | coredev->mode = ver->FirmwareId == 255 ? |
| 1029 | DEVICE_MODE_NONE : ver->FirmwareId; |
| 1030 | coredev->modes_supported = ver->SupportedProtocols; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1031 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 1032 | complete(&coredev->version_ex_done); |
| 1033 | break; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1034 | } |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 1035 | case MSG_SMS_INIT_DEVICE_RES: |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 1036 | sms_debug("MSG_SMS_INIT_DEVICE_RES"); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 1037 | complete(&coredev->init_device_done); |
| 1038 | break; |
| 1039 | case MSG_SW_RELOAD_START_RES: |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 1040 | sms_debug("MSG_SW_RELOAD_START_RES"); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 1041 | complete(&coredev->reload_start_done); |
| 1042 | break; |
| 1043 | case MSG_SMS_DATA_DOWNLOAD_RES: |
| 1044 | complete(&coredev->data_download_done); |
| 1045 | break; |
| 1046 | case MSG_SW_RELOAD_EXEC_RES: |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 1047 | sms_debug("MSG_SW_RELOAD_EXEC_RES"); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 1048 | break; |
| 1049 | case MSG_SMS_SWDOWNLOAD_TRIGGER_RES: |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 1050 | sms_debug("MSG_SMS_SWDOWNLOAD_TRIGGER_RES"); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 1051 | complete(&coredev->trigger_done); |
| 1052 | break; |
| 1053 | case MSG_SMS_SLEEP_RESUME_COMP_IND: |
| 1054 | complete(&coredev->resume_done); |
| 1055 | break; |
Uri Shkolnik | 34601ca | 2009-05-19 12:52:58 -0300 | [diff] [blame] | 1056 | case MSG_SMS_GPIO_CONFIG_EX_RES: |
| 1057 | sms_debug("MSG_SMS_GPIO_CONFIG_EX_RES"); |
| 1058 | complete(&coredev->gpio_configuration_done); |
| 1059 | break; |
| 1060 | case MSG_SMS_GPIO_SET_LEVEL_RES: |
| 1061 | sms_debug("MSG_SMS_GPIO_SET_LEVEL_RES"); |
| 1062 | complete(&coredev->gpio_set_level_done); |
| 1063 | break; |
| 1064 | case MSG_SMS_GPIO_GET_LEVEL_RES: |
| 1065 | { |
| 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); |
| 1071 | break; |
| 1072 | } |
Uri Shkolnik | a804800 | 2009-05-14 16:29:35 -0300 | [diff] [blame] | 1073 | case MSG_SMS_START_IR_RES: |
| 1074 | complete(&coredev->ir_init_done); |
| 1075 | break; |
| 1076 | case MSG_SMS_IR_SAMPLES_IND: |
| 1077 | sms_ir_event(coredev, |
| 1078 | (const char *) |
| 1079 | ((char *)phdr |
| 1080 | + sizeof(struct SmsMsgHdr_ST)), |
| 1081 | (int)phdr->msgLength |
| 1082 | - sizeof(struct SmsMsgHdr_ST)); |
| 1083 | break; |
| 1084 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 1085 | default: |
| 1086 | break; |
| 1087 | } |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1088 | smscore_putbuffer(coredev, cb); |
| 1089 | } |
| 1090 | } |
Michael Krufky | a0beec8 | 2009-02-26 18:32:36 -0300 | [diff] [blame] | 1091 | EXPORT_SYMBOL_GPL(smscore_onresponse); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1092 | |
| 1093 | /** |
| 1094 | * return pointer to next free buffer descriptor from core pool |
| 1095 | * |
Michael Krufky | 59bf6b8 | 2008-06-15 16:50:11 -0300 | [diff] [blame] | 1096 | * @param coredev pointer to a coredev object returned by |
| 1097 | * smscore_register_device |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1098 | * |
| 1099 | * @return pointer to descriptor on success, NULL on error. |
| 1100 | */ |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 1101 | struct smscore_buffer_t *smscore_getbuffer(struct smscore_device_t *coredev) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1102 | { |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 1103 | struct smscore_buffer_t *cb = NULL; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1104 | unsigned long flags; |
| 1105 | |
Uri Shkolnik | a934931 | 2009-05-17 05:59:37 -0300 | [diff] [blame] | 1106 | DEFINE_WAIT(wait); |
| 1107 | |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1108 | spin_lock_irqsave(&coredev->bufferslock, flags); |
| 1109 | |
Uri Shkolnik | a934931 | 2009-05-17 05:59:37 -0300 | [diff] [blame] | 1110 | /* This function must return a valid buffer, since the buffer list is |
| 1111 | * finite, we check that there is an available buffer, if not, we wait |
| 1112 | * until such buffer become available. |
| 1113 | */ |
| 1114 | |
| 1115 | prepare_to_wait(&coredev->buffer_mng_waitq, &wait, TASK_INTERRUPTIBLE); |
Kulikov Vasiliy | d0a38ce | 2010-07-27 15:42:40 -0300 | [diff] [blame] | 1116 | if (list_empty(&coredev->buffers)) { |
| 1117 | spin_unlock_irqrestore(&coredev->bufferslock, flags); |
Uri Shkolnik | a934931 | 2009-05-17 05:59:37 -0300 | [diff] [blame] | 1118 | schedule(); |
Kulikov Vasiliy | d0a38ce | 2010-07-27 15:42:40 -0300 | [diff] [blame] | 1119 | spin_lock_irqsave(&coredev->bufferslock, flags); |
| 1120 | } |
Uri Shkolnik | a934931 | 2009-05-17 05:59:37 -0300 | [diff] [blame] | 1121 | |
| 1122 | finish_wait(&coredev->buffer_mng_waitq, &wait); |
| 1123 | |
| 1124 | cb = (struct smscore_buffer_t *) coredev->buffers.next; |
| 1125 | list_del(&cb->entry); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1126 | |
| 1127 | spin_unlock_irqrestore(&coredev->bufferslock, flags); |
| 1128 | |
| 1129 | return cb; |
| 1130 | } |
Michael Krufky | a0beec8 | 2009-02-26 18:32:36 -0300 | [diff] [blame] | 1131 | EXPORT_SYMBOL_GPL(smscore_getbuffer); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1132 | |
| 1133 | /** |
| 1134 | * return buffer descriptor to a pool |
| 1135 | * |
Michael Krufky | 59bf6b8 | 2008-06-15 16:50:11 -0300 | [diff] [blame] | 1136 | * @param coredev pointer to a coredev object returned by |
| 1137 | * smscore_register_device |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1138 | * @param cb pointer buffer descriptor |
| 1139 | * |
| 1140 | */ |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 1141 | void smscore_putbuffer(struct smscore_device_t *coredev, |
Uri Shkolnik | a934931 | 2009-05-17 05:59:37 -0300 | [diff] [blame] | 1142 | struct smscore_buffer_t *cb) { |
| 1143 | wake_up_interruptible(&coredev->buffer_mng_waitq); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1144 | list_add_locked(&cb->entry, &coredev->buffers, &coredev->bufferslock); |
| 1145 | } |
Michael Krufky | a0beec8 | 2009-02-26 18:32:36 -0300 | [diff] [blame] | 1146 | EXPORT_SYMBOL_GPL(smscore_putbuffer); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1147 | |
Michael Krufky | 0c071f3 | 2008-06-21 02:44:02 -0300 | [diff] [blame] | 1148 | static int smscore_validate_client(struct smscore_device_t *coredev, |
| 1149 | struct smscore_client_t *client, |
| 1150 | int data_type, int id) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1151 | { |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 1152 | struct smscore_idlist_t *listentry; |
| 1153 | struct smscore_client_t *registered_client; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1154 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 1155 | if (!client) { |
Michael Krufky | 2522dc1 | 2008-06-19 22:15:38 -0300 | [diff] [blame] | 1156 | sms_err("bad parameter."); |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 1157 | return -EFAULT; |
| 1158 | } |
| 1159 | registered_client = smscore_find_client(coredev, data_type, id); |
Michael Krufky | fa830e8 | 2008-06-15 15:52:43 -0300 | [diff] [blame] | 1160 | if (registered_client == client) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1161 | return 0; |
Michael Krufky | fa830e8 | 2008-06-15 15:52:43 -0300 | [diff] [blame] | 1162 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 1163 | if (registered_client) { |
Michael Krufky | 2522dc1 | 2008-06-19 22:15:38 -0300 | [diff] [blame] | 1164 | sms_err("The msg ID already registered to another client."); |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 1165 | return -EEXIST; |
| 1166 | } |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 1167 | listentry = kzalloc(sizeof(struct smscore_idlist_t), GFP_KERNEL); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 1168 | if (!listentry) { |
Michael Krufky | 2522dc1 | 2008-06-19 22:15:38 -0300 | [diff] [blame] | 1169 | sms_err("Can't allocate memory for client id."); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1170 | return -ENOMEM; |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 1171 | } |
| 1172 | listentry->id = id; |
| 1173 | listentry->data_type = data_type; |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 1174 | list_add_locked(&listentry->entry, &client->idlist, |
| 1175 | &coredev->clientslock); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1176 | return 0; |
| 1177 | } |
| 1178 | |
| 1179 | /** |
| 1180 | * creates smsclient object, check that id is taken by another client |
| 1181 | * |
| 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 |
Michael Krufky | ca78373 | 2008-06-15 17:36:00 -0300 | [diff] [blame] | 1185 | * @param onresponse_handler client handler that is called to |
| 1186 | * process incoming messages |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 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 |
| 1190 | * |
| 1191 | * @return 0 on success, <0 on error. |
| 1192 | */ |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 1193 | int smscore_register_client(struct smscore_device_t *coredev, |
| 1194 | struct smsclient_params_t *params, |
| 1195 | struct smscore_client_t **client) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1196 | { |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 1197 | struct smscore_client_t *newclient; |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 1198 | /* check that no other channel with same parameters exists */ |
| 1199 | if (smscore_find_client(coredev, params->data_type, |
| 1200 | params->initial_id)) { |
Michael Krufky | 2522dc1 | 2008-06-19 22:15:38 -0300 | [diff] [blame] | 1201 | sms_err("Client already exist."); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1202 | return -EEXIST; |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 1203 | } |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1204 | |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 1205 | newclient = kzalloc(sizeof(struct smscore_client_t), GFP_KERNEL); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 1206 | if (!newclient) { |
Michael Krufky | 2522dc1 | 2008-06-19 22:15:38 -0300 | [diff] [blame] | 1207 | sms_err("Failed to allocate memory for client."); |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 1208 | return -ENOMEM; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1209 | } |
| 1210 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 1211 | INIT_LIST_HEAD(&newclient->idlist); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1212 | newclient->coredev = coredev; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1213 | newclient->onresponse_handler = params->onresponse_handler; |
| 1214 | newclient->onremove_handler = params->onremove_handler; |
| 1215 | newclient->context = params->context; |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 1216 | list_add_locked(&newclient->entry, &coredev->clients, |
| 1217 | &coredev->clientslock); |
| 1218 | smscore_validate_client(coredev, newclient, params->data_type, |
| 1219 | params->initial_id); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1220 | *client = newclient; |
Michael Krufky | 2522dc1 | 2008-06-19 22:15:38 -0300 | [diff] [blame] | 1221 | sms_debug("%p %d %d", params->context, params->data_type, |
| 1222 | params->initial_id); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1223 | |
| 1224 | return 0; |
| 1225 | } |
Michael Krufky | a0beec8 | 2009-02-26 18:32:36 -0300 | [diff] [blame] | 1226 | EXPORT_SYMBOL_GPL(smscore_register_client); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1227 | |
| 1228 | /** |
| 1229 | * frees smsclient object and all subclients associated with it |
| 1230 | * |
Michael Krufky | 59bf6b8 | 2008-06-15 16:50:11 -0300 | [diff] [blame] | 1231 | * @param client pointer to smsclient object returned by |
| 1232 | * smscore_register_client |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1233 | * |
| 1234 | */ |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 1235 | void smscore_unregister_client(struct smscore_client_t *client) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1236 | { |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 1237 | struct smscore_device_t *coredev = client->coredev; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1238 | unsigned long flags; |
| 1239 | |
| 1240 | spin_lock_irqsave(&coredev->clientslock, flags); |
| 1241 | |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1242 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 1243 | while (!list_empty(&client->idlist)) { |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 1244 | struct smscore_idlist_t *identry = |
| 1245 | (struct smscore_idlist_t *) client->idlist.next; |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 1246 | list_del(&identry->entry); |
| 1247 | kfree(identry); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1248 | } |
| 1249 | |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 1250 | sms_info("%p", client->context); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1251 | |
| 1252 | list_del(&client->entry); |
| 1253 | kfree(client); |
| 1254 | |
| 1255 | spin_unlock_irqrestore(&coredev->clientslock, flags); |
| 1256 | } |
Michael Krufky | a0beec8 | 2009-02-26 18:32:36 -0300 | [diff] [blame] | 1257 | EXPORT_SYMBOL_GPL(smscore_unregister_client); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1258 | |
| 1259 | /** |
| 1260 | * verifies that source id is not taken by another client, |
| 1261 | * calls device handler to send requests to the device |
| 1262 | * |
Michael Krufky | 59bf6b8 | 2008-06-15 16:50:11 -0300 | [diff] [blame] | 1263 | * @param client pointer to smsclient object returned by |
| 1264 | * smscore_register_client |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1265 | * @param buffer pointer to a request buffer |
| 1266 | * @param size size (in bytes) of request buffer |
| 1267 | * |
| 1268 | * @return 0 on success, <0 on error. |
| 1269 | */ |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 1270 | int smsclient_sendrequest(struct smscore_client_t *client, |
| 1271 | void *buffer, size_t size) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1272 | { |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 1273 | struct smscore_device_t *coredev; |
| 1274 | struct SmsMsgHdr_ST *phdr = (struct SmsMsgHdr_ST *) buffer; |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 1275 | int rc; |
| 1276 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 1277 | if (client == NULL) { |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 1278 | sms_err("Got NULL client"); |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 1279 | return -EINVAL; |
| 1280 | } |
| 1281 | |
| 1282 | coredev = client->coredev; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1283 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 1284 | /* check that no other channel with same id exists */ |
| 1285 | if (coredev == NULL) { |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 1286 | sms_err("Got NULL coredev"); |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 1287 | return -EINVAL; |
| 1288 | } |
| 1289 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 1290 | rc = smscore_validate_client(client->coredev, client, 0, |
| 1291 | phdr->msgSrcId); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1292 | if (rc < 0) |
| 1293 | return rc; |
| 1294 | |
| 1295 | return coredev->sendrequest_handler(coredev->context, buffer, size); |
| 1296 | } |
Michael Krufky | a0beec8 | 2009-02-26 18:32:36 -0300 | [diff] [blame] | 1297 | EXPORT_SYMBOL_GPL(smsclient_sendrequest); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1298 | |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1299 | |
Uwe Kleine-König | 65155b3 | 2010-06-11 12:17:01 +0200 | [diff] [blame] | 1300 | /* old GPIO managements implementation */ |
Michael Krufky | 76052bc | 2008-11-16 18:01:58 -0300 | [diff] [blame] | 1301 | int smscore_configure_gpio(struct smscore_device_t *coredev, u32 pin, |
Uri Shkolnik | 7c4ca79 | 2009-05-19 11:49:19 -0300 | [diff] [blame] | 1302 | struct smscore_config_gpio *pinconfig) |
Michael Krufky | 76052bc | 2008-11-16 18:01:58 -0300 | [diff] [blame] | 1303 | { |
| 1304 | struct { |
| 1305 | struct SmsMsgHdr_ST hdr; |
| 1306 | u32 data[6]; |
| 1307 | } msg; |
| 1308 | |
| 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); |
| 1315 | |
| 1316 | msg.data[0] = pin; |
| 1317 | msg.data[1] = pinconfig->pullupdown; |
| 1318 | |
| 1319 | /* Convert slew rate for Nova: Fast(0) = 3 / Slow(1) = 0; */ |
| 1320 | msg.data[2] = pinconfig->outputslewrate == 0 ? 3 : 0; |
| 1321 | |
| 1322 | switch (pinconfig->outputdriving) { |
| 1323 | case SMS_GPIO_OUTPUTDRIVING_16mA: |
| 1324 | msg.data[3] = 7; /* Nova - 16mA */ |
| 1325 | break; |
| 1326 | case SMS_GPIO_OUTPUTDRIVING_12mA: |
| 1327 | msg.data[3] = 5; /* Nova - 11mA */ |
| 1328 | break; |
| 1329 | case SMS_GPIO_OUTPUTDRIVING_8mA: |
| 1330 | msg.data[3] = 3; /* Nova - 7mA */ |
| 1331 | break; |
| 1332 | case SMS_GPIO_OUTPUTDRIVING_4mA: |
| 1333 | default: |
| 1334 | msg.data[3] = 2; /* Nova - 4mA */ |
| 1335 | break; |
| 1336 | } |
| 1337 | |
| 1338 | msg.data[4] = pinconfig->direction; |
| 1339 | msg.data[5] = 0; |
| 1340 | } else /* TODO: SMS_DEVICE_FAMILY1 */ |
| 1341 | return -EINVAL; |
| 1342 | |
| 1343 | return coredev->sendrequest_handler(coredev->context, |
| 1344 | &msg, sizeof(msg)); |
| 1345 | } |
| 1346 | |
| 1347 | int smscore_set_gpio(struct smscore_device_t *coredev, u32 pin, int level) |
| 1348 | { |
| 1349 | struct { |
| 1350 | struct SmsMsgHdr_ST hdr; |
| 1351 | u32 data[3]; |
| 1352 | } msg; |
| 1353 | |
| 1354 | if (pin > MAX_GPIO_PIN_NUMBER) |
| 1355 | return -EINVAL; |
| 1356 | |
| 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); |
| 1362 | |
| 1363 | msg.data[0] = pin; |
| 1364 | msg.data[1] = level ? 1 : 0; |
| 1365 | msg.data[2] = 0; |
| 1366 | |
| 1367 | return coredev->sendrequest_handler(coredev->context, |
| 1368 | &msg, sizeof(msg)); |
| 1369 | } |
| 1370 | |
Uwe Kleine-Koenig | 3dbda77 | 2009-07-23 08:31:31 +0200 | [diff] [blame] | 1371 | /* new GPIO management implementation */ |
Uri Shkolnik | 7c4ca79 | 2009-05-19 11:49:19 -0300 | [diff] [blame] | 1372 | static int GetGpioPinParams(u32 PinNum, u32 *pTranslatedPinNum, |
| 1373 | u32 *pGroupNum, u32 *pGroupCfg) { |
| 1374 | |
| 1375 | *pGroupCfg = 1; |
| 1376 | |
Roel Kluin | f14a297 | 2009-10-23 07:59:42 -0300 | [diff] [blame] | 1377 | if (PinNum <= 1) { |
Uri Shkolnik | 7c4ca79 | 2009-05-19 11:49:19 -0300 | [diff] [blame] | 1378 | *pTranslatedPinNum = 0; |
| 1379 | *pGroupNum = 9; |
| 1380 | *pGroupCfg = 2; |
| 1381 | } else if (PinNum >= 2 && PinNum <= 6) { |
| 1382 | *pTranslatedPinNum = 2; |
| 1383 | *pGroupNum = 0; |
| 1384 | *pGroupCfg = 2; |
| 1385 | } else if (PinNum >= 7 && PinNum <= 11) { |
| 1386 | *pTranslatedPinNum = 7; |
| 1387 | *pGroupNum = 1; |
| 1388 | } else if (PinNum >= 12 && PinNum <= 15) { |
| 1389 | *pTranslatedPinNum = 12; |
| 1390 | *pGroupNum = 2; |
| 1391 | *pGroupCfg = 3; |
| 1392 | } else if (PinNum == 16) { |
| 1393 | *pTranslatedPinNum = 16; |
| 1394 | *pGroupNum = 23; |
| 1395 | } else if (PinNum >= 17 && PinNum <= 24) { |
| 1396 | *pTranslatedPinNum = 17; |
| 1397 | *pGroupNum = 3; |
| 1398 | } else if (PinNum == 25) { |
| 1399 | *pTranslatedPinNum = 25; |
| 1400 | *pGroupNum = 6; |
| 1401 | } else if (PinNum >= 26 && PinNum <= 28) { |
| 1402 | *pTranslatedPinNum = 26; |
| 1403 | *pGroupNum = 4; |
| 1404 | } else if (PinNum == 29) { |
| 1405 | *pTranslatedPinNum = 29; |
| 1406 | *pGroupNum = 5; |
| 1407 | *pGroupCfg = 2; |
| 1408 | } else if (PinNum == 30) { |
| 1409 | *pTranslatedPinNum = 30; |
| 1410 | *pGroupNum = 8; |
| 1411 | } else if (PinNum == 31) { |
| 1412 | *pTranslatedPinNum = 31; |
| 1413 | *pGroupNum = 17; |
| 1414 | } else |
| 1415 | return -1; |
| 1416 | |
| 1417 | *pGroupCfg <<= 24; |
| 1418 | |
| 1419 | return 0; |
| 1420 | } |
| 1421 | |
| 1422 | int smscore_gpio_configure(struct smscore_device_t *coredev, u8 PinNum, |
| 1423 | struct smscore_gpio_config *pGpioConfig) { |
| 1424 | |
| 1425 | u32 totalLen; |
Hans Verkuil | be5daa9 | 2009-06-14 06:47:35 -0300 | [diff] [blame] | 1426 | u32 TranslatedPinNum = 0; |
| 1427 | u32 GroupNum = 0; |
Uri Shkolnik | 7c4ca79 | 2009-05-19 11:49:19 -0300 | [diff] [blame] | 1428 | u32 ElectricChar; |
| 1429 | u32 groupCfg; |
| 1430 | void *buffer; |
| 1431 | int rc; |
| 1432 | |
| 1433 | struct SetGpioMsg { |
| 1434 | struct SmsMsgHdr_ST xMsgHeader; |
| 1435 | u32 msgData[6]; |
| 1436 | } *pMsg; |
| 1437 | |
| 1438 | |
| 1439 | if (PinNum > MAX_GPIO_PIN_NUMBER) |
| 1440 | return -EINVAL; |
| 1441 | |
| 1442 | if (pGpioConfig == NULL) |
| 1443 | return -EINVAL; |
| 1444 | |
| 1445 | totalLen = sizeof(struct SmsMsgHdr_ST) + (sizeof(u32) * 6); |
| 1446 | |
| 1447 | buffer = kmalloc(totalLen + SMS_DMA_ALIGNMENT, |
| 1448 | GFP_KERNEL | GFP_DMA); |
| 1449 | if (!buffer) |
| 1450 | return -ENOMEM; |
| 1451 | |
| 1452 | pMsg = (struct SetGpioMsg *) SMS_ALIGN_ADDRESS(buffer); |
| 1453 | |
| 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; |
| 1459 | |
| 1460 | if (!(coredev->device_flags & SMS_DEVICE_FAMILY2)) { |
| 1461 | pMsg->xMsgHeader.msgType = MSG_SMS_GPIO_CONFIG_REQ; |
| 1462 | if (GetGpioPinParams(PinNum, &TranslatedPinNum, &GroupNum, |
Jiri Slaby | b46d37e | 2010-01-06 13:45:27 -0300 | [diff] [blame] | 1463 | &groupCfg) != 0) { |
| 1464 | rc = -EINVAL; |
| 1465 | goto free; |
| 1466 | } |
Uri Shkolnik | 7c4ca79 | 2009-05-19 11:49:19 -0300 | [diff] [blame] | 1467 | |
| 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; |
| 1477 | } else { |
| 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; |
| 1484 | } |
| 1485 | |
| 1486 | smsendian_handle_tx_message((struct SmsMsgHdr_ST *)pMsg); |
| 1487 | rc = smscore_sendrequest_and_wait(coredev, pMsg, totalLen, |
| 1488 | &coredev->gpio_configuration_done); |
| 1489 | |
| 1490 | if (rc != 0) { |
| 1491 | if (rc == -ETIME) |
| 1492 | sms_err("smscore_gpio_configure timeout"); |
| 1493 | else |
| 1494 | sms_err("smscore_gpio_configure error"); |
| 1495 | } |
Jiri Slaby | b46d37e | 2010-01-06 13:45:27 -0300 | [diff] [blame] | 1496 | free: |
Uri Shkolnik | 7c4ca79 | 2009-05-19 11:49:19 -0300 | [diff] [blame] | 1497 | kfree(buffer); |
| 1498 | |
| 1499 | return rc; |
| 1500 | } |
| 1501 | |
| 1502 | int smscore_gpio_set_level(struct smscore_device_t *coredev, u8 PinNum, |
| 1503 | u8 NewLevel) { |
| 1504 | |
| 1505 | u32 totalLen; |
| 1506 | int rc; |
| 1507 | void *buffer; |
| 1508 | |
| 1509 | struct SetGpioMsg { |
| 1510 | struct SmsMsgHdr_ST xMsgHeader; |
| 1511 | u32 msgData[3]; /* keep it 3 ! */ |
| 1512 | } *pMsg; |
| 1513 | |
| 1514 | if ((NewLevel > 1) || (PinNum > MAX_GPIO_PIN_NUMBER) || |
| 1515 | (PinNum > MAX_GPIO_PIN_NUMBER)) |
| 1516 | return -EINVAL; |
| 1517 | |
| 1518 | totalLen = sizeof(struct SmsMsgHdr_ST) + |
| 1519 | (3 * sizeof(u32)); /* keep it 3 ! */ |
| 1520 | |
| 1521 | buffer = kmalloc(totalLen + SMS_DMA_ALIGNMENT, |
| 1522 | GFP_KERNEL | GFP_DMA); |
| 1523 | if (!buffer) |
| 1524 | return -ENOMEM; |
| 1525 | |
| 1526 | pMsg = (struct SetGpioMsg *) SMS_ALIGN_ADDRESS(buffer); |
| 1527 | |
| 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; |
| 1535 | |
| 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); |
| 1540 | |
| 1541 | if (rc != 0) { |
| 1542 | if (rc == -ETIME) |
| 1543 | sms_err("smscore_gpio_set_level timeout"); |
| 1544 | else |
| 1545 | sms_err("smscore_gpio_set_level error"); |
| 1546 | } |
| 1547 | kfree(buffer); |
| 1548 | |
| 1549 | return rc; |
| 1550 | } |
| 1551 | |
| 1552 | int smscore_gpio_get_level(struct smscore_device_t *coredev, u8 PinNum, |
| 1553 | u8 *level) { |
| 1554 | |
| 1555 | u32 totalLen; |
| 1556 | int rc; |
| 1557 | void *buffer; |
| 1558 | |
| 1559 | struct SetGpioMsg { |
| 1560 | struct SmsMsgHdr_ST xMsgHeader; |
| 1561 | u32 msgData[2]; |
| 1562 | } *pMsg; |
| 1563 | |
| 1564 | |
| 1565 | if (PinNum > MAX_GPIO_PIN_NUMBER) |
| 1566 | return -EINVAL; |
| 1567 | |
| 1568 | totalLen = sizeof(struct SmsMsgHdr_ST) + (2 * sizeof(u32)); |
| 1569 | |
| 1570 | buffer = kmalloc(totalLen + SMS_DMA_ALIGNMENT, |
| 1571 | GFP_KERNEL | GFP_DMA); |
| 1572 | if (!buffer) |
| 1573 | return -ENOMEM; |
| 1574 | |
| 1575 | pMsg = (struct SetGpioMsg *) SMS_ALIGN_ADDRESS(buffer); |
| 1576 | |
| 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; |
| 1584 | |
| 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); |
| 1589 | |
| 1590 | if (rc != 0) { |
| 1591 | if (rc == -ETIME) |
| 1592 | sms_err("smscore_gpio_get_level timeout"); |
| 1593 | else |
| 1594 | sms_err("smscore_gpio_get_level error"); |
| 1595 | } |
| 1596 | kfree(buffer); |
| 1597 | |
| 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' |
| 1600 | */ |
| 1601 | *level = coredev->gpio_get_res; |
| 1602 | |
| 1603 | return rc; |
| 1604 | } |
| 1605 | |
Adrian Bunk | c5e0bd1 | 2008-07-21 23:17:36 -0300 | [diff] [blame] | 1606 | static int __init smscore_module_init(void) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1607 | { |
Steven Toth | c646579 | 2008-05-19 19:09:21 -0300 | [diff] [blame] | 1608 | int rc = 0; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1609 | |
| 1610 | INIT_LIST_HEAD(&g_smscore_notifyees); |
| 1611 | INIT_LIST_HEAD(&g_smscore_devices); |
| 1612 | kmutex_init(&g_smscore_deviceslock); |
| 1613 | |
| 1614 | INIT_LIST_HEAD(&g_smscore_registry); |
| 1615 | kmutex_init(&g_smscore_registrylock); |
| 1616 | |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1617 | return rc; |
| 1618 | } |
| 1619 | |
Adrian Bunk | c5e0bd1 | 2008-07-21 23:17:36 -0300 | [diff] [blame] | 1620 | static void __exit smscore_module_exit(void) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1621 | { |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1622 | kmutex_lock(&g_smscore_deviceslock); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 1623 | while (!list_empty(&g_smscore_notifyees)) { |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 1624 | struct smscore_device_notifyee_t *notifyee = |
| 1625 | (struct smscore_device_notifyee_t *) |
| 1626 | g_smscore_notifyees.next; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1627 | |
| 1628 | list_del(¬ifyee->entry); |
| 1629 | kfree(notifyee); |
| 1630 | } |
| 1631 | kmutex_unlock(&g_smscore_deviceslock); |
| 1632 | |
| 1633 | kmutex_lock(&g_smscore_registrylock); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 1634 | while (!list_empty(&g_smscore_registry)) { |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 1635 | struct smscore_registry_entry_t *entry = |
| 1636 | (struct smscore_registry_entry_t *) |
| 1637 | g_smscore_registry.next; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1638 | |
| 1639 | list_del(&entry->entry); |
| 1640 | kfree(entry); |
| 1641 | } |
| 1642 | kmutex_unlock(&g_smscore_registrylock); |
| 1643 | |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 1644 | sms_debug(""); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1645 | } |
| 1646 | |
| 1647 | module_init(smscore_module_init); |
| 1648 | module_exit(smscore_module_exit); |
| 1649 | |
Uri Shkolnik | e0f14c2 | 2008-08-31 00:44:04 -0300 | [diff] [blame] | 1650 | MODULE_DESCRIPTION("Siano MDTV Core module"); |
| 1651 | MODULE_AUTHOR("Siano Mobile Silicon, Inc. (uris@siano-ms.com)"); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 1652 | MODULE_LICENSE("GPL"); |