Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Shared Transport Line discipline driver Core |
| 3 | * Init Manager module responsible for GPIO control |
| 4 | * and firmware download |
Pavan Savoy | a0cc2f3 | 2010-10-06 12:18:14 -0400 | [diff] [blame] | 5 | * Copyright (C) 2009-2010 Texas Instruments |
| 6 | * Author: Pavan Savoy <pavan_savoy@ti.com> |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | #define pr_fmt(fmt) "(stk) :" fmt |
| 24 | #include <linux/platform_device.h> |
| 25 | #include <linux/jiffies.h> |
| 26 | #include <linux/firmware.h> |
| 27 | #include <linux/delay.h> |
| 28 | #include <linux/wait.h> |
| 29 | #include <linux/gpio.h> |
Pavan Savoy | c1afac1 | 2010-07-28 02:25:59 -0500 | [diff] [blame] | 30 | #include <linux/debugfs.h> |
| 31 | #include <linux/seq_file.h> |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 32 | #include <linux/sched.h> |
Pavan Savoy | 83ef41f | 2010-09-17 12:06:11 -0400 | [diff] [blame] | 33 | #include <linux/rfkill.h> |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 34 | |
Pavan Savoy | 5c88b02 | 2011-02-04 02:23:09 -0600 | [diff] [blame^] | 35 | #include <linux/skbuff.h> |
Pavan Savoy | e555867 | 2010-09-30 16:13:30 -0400 | [diff] [blame] | 36 | #include <linux/ti_wilink_st.h> |
Pavan Savoy | 83ef41f | 2010-09-17 12:06:11 -0400 | [diff] [blame] | 37 | |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 38 | |
| 39 | static int kim_probe(struct platform_device *pdev); |
| 40 | static int kim_remove(struct platform_device *pdev); |
| 41 | |
| 42 | /* KIM platform device driver structure */ |
| 43 | static struct platform_driver kim_platform_driver = { |
| 44 | .probe = kim_probe, |
| 45 | .remove = kim_remove, |
| 46 | /* TODO: ST driver power management during suspend/resume ? |
| 47 | */ |
| 48 | #if 0 |
| 49 | .suspend = kim_suspend, |
| 50 | .resume = kim_resume, |
| 51 | #endif |
| 52 | .driver = { |
| 53 | .name = "kim", |
| 54 | .owner = THIS_MODULE, |
| 55 | }, |
| 56 | }; |
| 57 | |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 58 | static int kim_toggle_radio(void*, bool); |
| 59 | static const struct rfkill_ops kim_rfkill_ops = { |
| 60 | .set_block = kim_toggle_radio, |
| 61 | }; |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 62 | |
| 63 | /* strings to be used for rfkill entries and by |
| 64 | * ST Core to be used for sysfs debug entry |
| 65 | */ |
| 66 | #define PROTO_ENTRY(type, name) name |
| 67 | const unsigned char *protocol_names[] = { |
| 68 | PROTO_ENTRY(ST_BT, "Bluetooth"), |
| 69 | PROTO_ENTRY(ST_FM, "FM"), |
| 70 | PROTO_ENTRY(ST_GPS, "GPS"), |
| 71 | }; |
| 72 | |
Pavan Savoy | dbd3a87 | 2010-08-19 14:08:51 -0400 | [diff] [blame] | 73 | #define MAX_ST_DEVICES 3 /* Imagine 1 on each UART for now */ |
Pavan Savoy | 73f12e8 | 2010-10-12 16:27:38 -0400 | [diff] [blame] | 74 | static struct platform_device *st_kim_devices[MAX_ST_DEVICES]; |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 75 | |
| 76 | /**********************************************************************/ |
| 77 | /* internal functions */ |
| 78 | |
Pavan Savoy | 36b5aee | 2010-07-22 05:32:06 -0500 | [diff] [blame] | 79 | /** |
Pavan Savoy | dbd3a87 | 2010-08-19 14:08:51 -0400 | [diff] [blame] | 80 | * st_get_plat_device - |
| 81 | * function which returns the reference to the platform device |
| 82 | * requested by id. As of now only 1 such device exists (id=0) |
| 83 | * the context requesting for reference can get the id to be |
| 84 | * requested by a. The protocol driver which is registering or |
| 85 | * b. the tty device which is opened. |
| 86 | */ |
| 87 | static struct platform_device *st_get_plat_device(int id) |
| 88 | { |
| 89 | return st_kim_devices[id]; |
| 90 | } |
| 91 | |
| 92 | /** |
Pavan Savoy | 36b5aee | 2010-07-22 05:32:06 -0500 | [diff] [blame] | 93 | * validate_firmware_response - |
| 94 | * function to return whether the firmware response was proper |
| 95 | * in case of error don't complete so that waiting for proper |
| 96 | * response times out |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 97 | */ |
Pavan Savoy | 38d9df4 | 2010-07-08 08:55:17 -0500 | [diff] [blame] | 98 | void validate_firmware_response(struct kim_data_s *kim_gdata) |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 99 | { |
Pavan Savoy | 38d9df4 | 2010-07-08 08:55:17 -0500 | [diff] [blame] | 100 | struct sk_buff *skb = kim_gdata->rx_skb; |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 101 | if (unlikely(skb->data[5] != 0)) { |
| 102 | pr_err("no proper response during fw download"); |
| 103 | pr_err("data6 %x", skb->data[5]); |
| 104 | return; /* keep waiting for the proper response */ |
| 105 | } |
| 106 | /* becos of all the script being downloaded */ |
| 107 | complete_all(&kim_gdata->kim_rcvd); |
| 108 | kfree_skb(skb); |
| 109 | } |
| 110 | |
| 111 | /* check for data len received inside kim_int_recv |
| 112 | * most often hit the last case to update state to waiting for data |
| 113 | */ |
Pavan Savoy | 38d9df4 | 2010-07-08 08:55:17 -0500 | [diff] [blame] | 114 | static inline int kim_check_data_len(struct kim_data_s *kim_gdata, int len) |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 115 | { |
| 116 | register int room = skb_tailroom(kim_gdata->rx_skb); |
| 117 | |
Pavan Savoy | e6d9e64 | 2010-07-22 05:32:05 -0500 | [diff] [blame] | 118 | pr_debug("len %d room %d", len, room); |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 119 | |
| 120 | if (!len) { |
Pavan Savoy | 38d9df4 | 2010-07-08 08:55:17 -0500 | [diff] [blame] | 121 | validate_firmware_response(kim_gdata); |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 122 | } else if (len > room) { |
| 123 | /* Received packet's payload length is larger. |
| 124 | * We can't accommodate it in created skb. |
| 125 | */ |
| 126 | pr_err("Data length is too large len %d room %d", len, |
| 127 | room); |
| 128 | kfree_skb(kim_gdata->rx_skb); |
| 129 | } else { |
| 130 | /* Packet header has non-zero payload length and |
| 131 | * we have enough space in created skb. Lets read |
| 132 | * payload data */ |
Pavan Savoy | 5c88b02 | 2011-02-04 02:23:09 -0600 | [diff] [blame^] | 133 | kim_gdata->rx_state = ST_W4_DATA; |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 134 | kim_gdata->rx_count = len; |
| 135 | return len; |
| 136 | } |
| 137 | |
| 138 | /* Change ST LL state to continue to process next |
| 139 | * packet */ |
| 140 | kim_gdata->rx_state = ST_W4_PACKET_TYPE; |
| 141 | kim_gdata->rx_skb = NULL; |
| 142 | kim_gdata->rx_count = 0; |
| 143 | |
| 144 | return 0; |
| 145 | } |
| 146 | |
Pavan Savoy | 36b5aee | 2010-07-22 05:32:06 -0500 | [diff] [blame] | 147 | /** |
| 148 | * kim_int_recv - receive function called during firmware download |
| 149 | * firmware download responses on different UART drivers |
| 150 | * have been observed to come in bursts of different |
| 151 | * tty_receive and hence the logic |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 152 | */ |
Pavan Savoy | 38d9df4 | 2010-07-08 08:55:17 -0500 | [diff] [blame] | 153 | void kim_int_recv(struct kim_data_s *kim_gdata, |
| 154 | const unsigned char *data, long count) |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 155 | { |
Pavan Savoy | 73f12e8 | 2010-10-12 16:27:38 -0400 | [diff] [blame] | 156 | const unsigned char *ptr; |
Pavan Savoy | 73f12e8 | 2010-10-12 16:27:38 -0400 | [diff] [blame] | 157 | int len = 0, type = 0; |
Pavan Savoy | 5c88b02 | 2011-02-04 02:23:09 -0600 | [diff] [blame^] | 158 | unsigned char *plen; |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 159 | |
Pavan Savoy | e6d9e64 | 2010-07-22 05:32:05 -0500 | [diff] [blame] | 160 | pr_debug("%s", __func__); |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 161 | /* Decode received bytes here */ |
Pavan Savoy | 73f12e8 | 2010-10-12 16:27:38 -0400 | [diff] [blame] | 162 | ptr = data; |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 163 | if (unlikely(ptr == NULL)) { |
| 164 | pr_err(" received null from TTY "); |
| 165 | return; |
| 166 | } |
Pavan Savoy | 73f12e8 | 2010-10-12 16:27:38 -0400 | [diff] [blame] | 167 | |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 168 | while (count) { |
| 169 | if (kim_gdata->rx_count) { |
| 170 | len = min_t(unsigned int, kim_gdata->rx_count, count); |
| 171 | memcpy(skb_put(kim_gdata->rx_skb, len), ptr, len); |
| 172 | kim_gdata->rx_count -= len; |
| 173 | count -= len; |
| 174 | ptr += len; |
| 175 | |
| 176 | if (kim_gdata->rx_count) |
| 177 | continue; |
| 178 | |
| 179 | /* Check ST RX state machine , where are we? */ |
| 180 | switch (kim_gdata->rx_state) { |
| 181 | /* Waiting for complete packet ? */ |
Pavan Savoy | 5c88b02 | 2011-02-04 02:23:09 -0600 | [diff] [blame^] | 182 | case ST_W4_DATA: |
Pavan Savoy | e6d9e64 | 2010-07-22 05:32:05 -0500 | [diff] [blame] | 183 | pr_debug("Complete pkt received"); |
Pavan Savoy | 38d9df4 | 2010-07-08 08:55:17 -0500 | [diff] [blame] | 184 | validate_firmware_response(kim_gdata); |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 185 | kim_gdata->rx_state = ST_W4_PACKET_TYPE; |
| 186 | kim_gdata->rx_skb = NULL; |
| 187 | continue; |
| 188 | /* Waiting for Bluetooth event header ? */ |
Pavan Savoy | 5c88b02 | 2011-02-04 02:23:09 -0600 | [diff] [blame^] | 189 | case ST_W4_HEADER: |
| 190 | plen = |
| 191 | (unsigned char *)&kim_gdata->rx_skb->data[1]; |
| 192 | pr_debug("event hdr: plen 0x%02x\n", *plen); |
| 193 | kim_check_data_len(kim_gdata, *plen); |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 194 | continue; |
| 195 | } /* end of switch */ |
| 196 | } /* end of if rx_state */ |
| 197 | switch (*ptr) { |
| 198 | /* Bluetooth event packet? */ |
Pavan Savoy | 5c88b02 | 2011-02-04 02:23:09 -0600 | [diff] [blame^] | 199 | case 0x04: |
| 200 | kim_gdata->rx_state = ST_W4_HEADER; |
| 201 | kim_gdata->rx_count = 2; |
| 202 | type = *ptr; |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 203 | break; |
| 204 | default: |
| 205 | pr_info("unknown packet"); |
| 206 | ptr++; |
| 207 | count--; |
| 208 | continue; |
Pavan Savoy | 36b5aee | 2010-07-22 05:32:06 -0500 | [diff] [blame] | 209 | } |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 210 | ptr++; |
| 211 | count--; |
| 212 | kim_gdata->rx_skb = |
Pavan Savoy | 5c88b02 | 2011-02-04 02:23:09 -0600 | [diff] [blame^] | 213 | alloc_skb(1024+8, GFP_ATOMIC); |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 214 | if (!kim_gdata->rx_skb) { |
| 215 | pr_err("can't allocate mem for new packet"); |
| 216 | kim_gdata->rx_state = ST_W4_PACKET_TYPE; |
| 217 | kim_gdata->rx_count = 0; |
| 218 | return; |
Pavan Savoy | 36b5aee | 2010-07-22 05:32:06 -0500 | [diff] [blame] | 219 | } |
Pavan Savoy | 5c88b02 | 2011-02-04 02:23:09 -0600 | [diff] [blame^] | 220 | skb_reserve(kim_gdata->rx_skb, 8); |
| 221 | kim_gdata->rx_skb->cb[0] = 4; |
| 222 | kim_gdata->rx_skb->cb[1] = 0; |
| 223 | |
Pavan Savoy | 36b5aee | 2010-07-22 05:32:06 -0500 | [diff] [blame] | 224 | } |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 225 | return; |
| 226 | } |
| 227 | |
Pavan Savoy | 38d9df4 | 2010-07-08 08:55:17 -0500 | [diff] [blame] | 228 | static long read_local_version(struct kim_data_s *kim_gdata, char *bts_scr_name) |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 229 | { |
| 230 | unsigned short version = 0, chip = 0, min_ver = 0, maj_ver = 0; |
Pavan Savoy | 73f12e8 | 2010-10-12 16:27:38 -0400 | [diff] [blame] | 231 | const char read_ver_cmd[] = { 0x01, 0x01, 0x10, 0x00 }; |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 232 | |
Pavan Savoy | e6d9e64 | 2010-07-22 05:32:05 -0500 | [diff] [blame] | 233 | pr_debug("%s", __func__); |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 234 | |
| 235 | INIT_COMPLETION(kim_gdata->kim_rcvd); |
| 236 | if (4 != st_int_write(kim_gdata->core_data, read_ver_cmd, 4)) { |
| 237 | pr_err("kim: couldn't write 4 bytes"); |
Pavan Savoy | 320920c | 2010-07-14 08:21:12 -0500 | [diff] [blame] | 238 | return -1; |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | if (!wait_for_completion_timeout |
| 242 | (&kim_gdata->kim_rcvd, msecs_to_jiffies(CMD_RESP_TIME))) { |
| 243 | pr_err(" waiting for ver info- timed out "); |
Pavan Savoy | 320920c | 2010-07-14 08:21:12 -0500 | [diff] [blame] | 244 | return -1; |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | version = |
Naveen Jain | e2a5328 | 2010-06-09 03:45:33 -0500 | [diff] [blame] | 248 | MAKEWORD(kim_gdata->resp_buffer[13], |
| 249 | kim_gdata->resp_buffer[14]); |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 250 | chip = (version & 0x7C00) >> 10; |
| 251 | min_ver = (version & 0x007F); |
| 252 | maj_ver = (version & 0x0380) >> 7; |
| 253 | |
| 254 | if (version & 0x8000) |
| 255 | maj_ver |= 0x0008; |
| 256 | |
| 257 | sprintf(bts_scr_name, "TIInit_%d.%d.%d.bts", chip, maj_ver, min_ver); |
Naveen Jain | e2a5328 | 2010-06-09 03:45:33 -0500 | [diff] [blame] | 258 | |
| 259 | /* to be accessed later via sysfs entry */ |
| 260 | kim_gdata->version.full = version; |
| 261 | kim_gdata->version.chip = chip; |
| 262 | kim_gdata->version.maj_ver = maj_ver; |
| 263 | kim_gdata->version.min_ver = min_ver; |
| 264 | |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 265 | pr_info("%s", bts_scr_name); |
Pavan Savoy | 320920c | 2010-07-14 08:21:12 -0500 | [diff] [blame] | 266 | return 0; |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 267 | } |
| 268 | |
Pavan Savoy | 36b5aee | 2010-07-22 05:32:06 -0500 | [diff] [blame] | 269 | /** |
| 270 | * download_firmware - |
| 271 | * internal function which parses through the .bts firmware |
| 272 | * script file intreprets SEND, DELAY actions only as of now |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 273 | */ |
Pavan Savoy | 38d9df4 | 2010-07-08 08:55:17 -0500 | [diff] [blame] | 274 | static long download_firmware(struct kim_data_s *kim_gdata) |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 275 | { |
Pavan Savoy | 320920c | 2010-07-14 08:21:12 -0500 | [diff] [blame] | 276 | long err = 0; |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 277 | long len = 0; |
Pavan Savoy | 73f12e8 | 2010-10-12 16:27:38 -0400 | [diff] [blame] | 278 | unsigned char *ptr = NULL; |
| 279 | unsigned char *action_ptr = NULL; |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 280 | unsigned char bts_scr_name[30] = { 0 }; /* 30 char long bts scr name? */ |
| 281 | |
Pavan Savoy | 38d9df4 | 2010-07-08 08:55:17 -0500 | [diff] [blame] | 282 | err = read_local_version(kim_gdata, bts_scr_name); |
Pavan Savoy | 320920c | 2010-07-14 08:21:12 -0500 | [diff] [blame] | 283 | if (err != 0) { |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 284 | pr_err("kim: failed to read local ver"); |
| 285 | return err; |
| 286 | } |
| 287 | err = |
| 288 | request_firmware(&kim_gdata->fw_entry, bts_scr_name, |
| 289 | &kim_gdata->kim_pdev->dev); |
| 290 | if (unlikely((err != 0) || (kim_gdata->fw_entry->data == NULL) || |
| 291 | (kim_gdata->fw_entry->size == 0))) { |
| 292 | pr_err(" request_firmware failed(errno %ld) for %s", err, |
| 293 | bts_scr_name); |
Pavan Savoy | 320920c | 2010-07-14 08:21:12 -0500 | [diff] [blame] | 294 | return -1; |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 295 | } |
| 296 | ptr = (void *)kim_gdata->fw_entry->data; |
| 297 | len = kim_gdata->fw_entry->size; |
| 298 | /* bts_header to remove out magic number and |
| 299 | * version |
| 300 | */ |
| 301 | ptr += sizeof(struct bts_header); |
| 302 | len -= sizeof(struct bts_header); |
| 303 | |
| 304 | while (len > 0 && ptr) { |
Pavan Savoy | e6d9e64 | 2010-07-22 05:32:05 -0500 | [diff] [blame] | 305 | pr_debug(" action size %d, type %d ", |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 306 | ((struct bts_action *)ptr)->size, |
| 307 | ((struct bts_action *)ptr)->type); |
| 308 | |
| 309 | switch (((struct bts_action *)ptr)->type) { |
| 310 | case ACTION_SEND_COMMAND: /* action send */ |
| 311 | action_ptr = &(((struct bts_action *)ptr)->data[0]); |
| 312 | if (unlikely |
| 313 | (((struct hci_command *)action_ptr)->opcode == |
| 314 | 0xFF36)) { |
| 315 | /* ignore remote change |
| 316 | * baud rate HCI VS command */ |
| 317 | pr_err |
Pavan Savoy | e6d9e64 | 2010-07-22 05:32:05 -0500 | [diff] [blame] | 318 | (" change remote baud" |
| 319 | " rate command in firmware"); |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 320 | break; |
| 321 | } |
| 322 | |
| 323 | INIT_COMPLETION(kim_gdata->kim_rcvd); |
| 324 | err = st_int_write(kim_gdata->core_data, |
| 325 | ((struct bts_action_send *)action_ptr)->data, |
| 326 | ((struct bts_action *)ptr)->size); |
| 327 | if (unlikely(err < 0)) { |
| 328 | release_firmware(kim_gdata->fw_entry); |
Pavan Savoy | 320920c | 2010-07-14 08:21:12 -0500 | [diff] [blame] | 329 | return -1; |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 330 | } |
| 331 | if (!wait_for_completion_timeout |
| 332 | (&kim_gdata->kim_rcvd, |
| 333 | msecs_to_jiffies(CMD_RESP_TIME))) { |
| 334 | pr_err |
| 335 | (" response timeout during fw download "); |
| 336 | /* timed out */ |
| 337 | release_firmware(kim_gdata->fw_entry); |
Pavan Savoy | 320920c | 2010-07-14 08:21:12 -0500 | [diff] [blame] | 338 | return -1; |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 339 | } |
| 340 | break; |
| 341 | case ACTION_DELAY: /* sleep */ |
| 342 | pr_info("sleep command in scr"); |
| 343 | action_ptr = &(((struct bts_action *)ptr)->data[0]); |
| 344 | mdelay(((struct bts_action_delay *)action_ptr)->msec); |
| 345 | break; |
| 346 | } |
| 347 | len = |
| 348 | len - (sizeof(struct bts_action) + |
| 349 | ((struct bts_action *)ptr)->size); |
| 350 | ptr = |
| 351 | ptr + sizeof(struct bts_action) + |
| 352 | ((struct bts_action *)ptr)->size; |
| 353 | } |
| 354 | /* fw download complete */ |
| 355 | release_firmware(kim_gdata->fw_entry); |
Pavan Savoy | 320920c | 2010-07-14 08:21:12 -0500 | [diff] [blame] | 356 | return 0; |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | /**********************************************************************/ |
| 360 | /* functions called from ST core */ |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 361 | /* function to toggle the GPIO |
| 362 | * needs to know whether the GPIO is active high or active low |
| 363 | */ |
| 364 | void st_kim_chip_toggle(enum proto_type type, enum kim_gpio_state state) |
| 365 | { |
Pavan Savoy | 38d9df4 | 2010-07-08 08:55:17 -0500 | [diff] [blame] | 366 | struct platform_device *kim_pdev; |
| 367 | struct kim_data_s *kim_gdata; |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 368 | pr_info(" %s ", __func__); |
| 369 | |
Pavan Savoy | dbd3a87 | 2010-08-19 14:08:51 -0400 | [diff] [blame] | 370 | kim_pdev = st_get_plat_device(0); |
Pavan Savoy | 38d9df4 | 2010-07-08 08:55:17 -0500 | [diff] [blame] | 371 | kim_gdata = dev_get_drvdata(&kim_pdev->dev); |
| 372 | |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 373 | if (kim_gdata->gpios[type] == -1) { |
| 374 | pr_info(" gpio not requested for protocol %s", |
| 375 | protocol_names[type]); |
| 376 | return; |
| 377 | } |
| 378 | switch (type) { |
| 379 | case ST_BT: |
| 380 | /*Do Nothing */ |
| 381 | break; |
| 382 | |
| 383 | case ST_FM: |
| 384 | if (state == KIM_GPIO_ACTIVE) |
| 385 | gpio_set_value(kim_gdata->gpios[ST_FM], GPIO_LOW); |
| 386 | else |
| 387 | gpio_set_value(kim_gdata->gpios[ST_FM], GPIO_HIGH); |
| 388 | break; |
| 389 | |
| 390 | case ST_GPS: |
| 391 | if (state == KIM_GPIO_ACTIVE) |
| 392 | gpio_set_value(kim_gdata->gpios[ST_GPS], GPIO_HIGH); |
| 393 | else |
| 394 | gpio_set_value(kim_gdata->gpios[ST_GPS], GPIO_LOW); |
| 395 | break; |
| 396 | |
Pavan Savoy | 5c88b02 | 2011-02-04 02:23:09 -0600 | [diff] [blame^] | 397 | case ST_MAX_CHANNELS: |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 398 | default: |
| 399 | break; |
| 400 | } |
| 401 | |
| 402 | return; |
| 403 | } |
| 404 | |
| 405 | /* called from ST Core, when REG_IN_PROGRESS (registration in progress) |
| 406 | * can be because of |
| 407 | * 1. response to read local version |
| 408 | * 2. during send/recv's of firmware download |
| 409 | */ |
| 410 | void st_kim_recv(void *disc_data, const unsigned char *data, long count) |
| 411 | { |
Pavan Savoy | 38d9df4 | 2010-07-08 08:55:17 -0500 | [diff] [blame] | 412 | struct st_data_s *st_gdata = (struct st_data_s *)disc_data; |
| 413 | struct kim_data_s *kim_gdata = st_gdata->kim_data; |
| 414 | |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 415 | /* copy to local buffer */ |
| 416 | if (unlikely(data[4] == 0x01 && data[5] == 0x10 && data[0] == 0x04)) { |
| 417 | /* must be the read_ver_cmd */ |
| 418 | memcpy(kim_gdata->resp_buffer, data, count); |
| 419 | complete_all(&kim_gdata->kim_rcvd); |
| 420 | return; |
| 421 | } else { |
Pavan Savoy | 38d9df4 | 2010-07-08 08:55:17 -0500 | [diff] [blame] | 422 | kim_int_recv(kim_gdata, data, count); |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 423 | /* either completes or times out */ |
| 424 | } |
| 425 | return; |
| 426 | } |
| 427 | |
| 428 | /* to signal completion of line discipline installation |
| 429 | * called from ST Core, upon tty_open |
| 430 | */ |
Pavan Savoy | 38d9df4 | 2010-07-08 08:55:17 -0500 | [diff] [blame] | 431 | void st_kim_complete(void *kim_data) |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 432 | { |
Pavan Savoy | 38d9df4 | 2010-07-08 08:55:17 -0500 | [diff] [blame] | 433 | struct kim_data_s *kim_gdata = (struct kim_data_s *)kim_data; |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 434 | complete(&kim_gdata->ldisc_installed); |
| 435 | } |
| 436 | |
Pavan Savoy | 36b5aee | 2010-07-22 05:32:06 -0500 | [diff] [blame] | 437 | /** |
| 438 | * st_kim_start - called from ST Core upon 1st registration |
| 439 | * This involves toggling the chip enable gpio, reading |
| 440 | * the firmware version from chip, forming the fw file name |
| 441 | * based on the chip version, requesting the fw, parsing it |
| 442 | * and perform download(send/recv). |
| 443 | */ |
Pavan Savoy | 38d9df4 | 2010-07-08 08:55:17 -0500 | [diff] [blame] | 444 | long st_kim_start(void *kim_data) |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 445 | { |
Pavan Savoy | 320920c | 2010-07-14 08:21:12 -0500 | [diff] [blame] | 446 | long err = 0; |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 447 | long retry = POR_RETRY_COUNT; |
Pavan Savoy | 38d9df4 | 2010-07-08 08:55:17 -0500 | [diff] [blame] | 448 | struct kim_data_s *kim_gdata = (struct kim_data_s *)kim_data; |
| 449 | |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 450 | pr_info(" %s", __func__); |
| 451 | |
| 452 | do { |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 453 | /* TODO: this is only because rfkill sub-system |
| 454 | * doesn't send events to user-space if the state |
| 455 | * isn't changed |
| 456 | */ |
| 457 | rfkill_set_hw_state(kim_gdata->rfkill[ST_BT], 1); |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 458 | /* Configure BT nShutdown to HIGH state */ |
| 459 | gpio_set_value(kim_gdata->gpios[ST_BT], GPIO_LOW); |
| 460 | mdelay(5); /* FIXME: a proper toggle */ |
| 461 | gpio_set_value(kim_gdata->gpios[ST_BT], GPIO_HIGH); |
| 462 | mdelay(100); |
| 463 | /* re-initialize the completion */ |
| 464 | INIT_COMPLETION(kim_gdata->ldisc_installed); |
Naveen Jain | b38fc2d | 2010-06-09 03:45:32 -0500 | [diff] [blame] | 465 | #if 0 /* older way of signalling user-space UIM */ |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 466 | /* send signal to UIM */ |
| 467 | err = kill_pid(find_get_pid(kim_gdata->uim_pid), SIGUSR2, 0); |
| 468 | if (err != 0) { |
| 469 | pr_info(" sending SIGUSR2 to uim failed %ld", err); |
Pavan Savoy | 320920c | 2010-07-14 08:21:12 -0500 | [diff] [blame] | 470 | err = -1; |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 471 | continue; |
| 472 | } |
Naveen Jain | b38fc2d | 2010-06-09 03:45:32 -0500 | [diff] [blame] | 473 | #endif |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 474 | /* unblock and send event to UIM via /dev/rfkill */ |
| 475 | rfkill_set_hw_state(kim_gdata->rfkill[ST_BT], 0); |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 476 | /* wait for ldisc to be installed */ |
| 477 | err = wait_for_completion_timeout(&kim_gdata->ldisc_installed, |
| 478 | msecs_to_jiffies(LDISC_TIME)); |
| 479 | if (!err) { /* timeout */ |
| 480 | pr_err("line disc installation timed out "); |
Pavan Savoy | 320920c | 2010-07-14 08:21:12 -0500 | [diff] [blame] | 481 | err = -1; |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 482 | continue; |
| 483 | } else { |
| 484 | /* ldisc installed now */ |
| 485 | pr_info(" line discipline installed "); |
Pavan Savoy | 38d9df4 | 2010-07-08 08:55:17 -0500 | [diff] [blame] | 486 | err = download_firmware(kim_gdata); |
Pavan Savoy | 320920c | 2010-07-14 08:21:12 -0500 | [diff] [blame] | 487 | if (err != 0) { |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 488 | pr_err("download firmware failed"); |
| 489 | continue; |
| 490 | } else { /* on success don't retry */ |
| 491 | break; |
| 492 | } |
| 493 | } |
| 494 | } while (retry--); |
| 495 | return err; |
| 496 | } |
| 497 | |
Pavan Savoy | 36b5aee | 2010-07-22 05:32:06 -0500 | [diff] [blame] | 498 | /** |
| 499 | * st_kim_stop - called from ST Core, on the last un-registration |
| 500 | * toggle low the chip enable gpio |
| 501 | */ |
Pavan Savoy | 38d9df4 | 2010-07-08 08:55:17 -0500 | [diff] [blame] | 502 | long st_kim_stop(void *kim_data) |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 503 | { |
Pavan Savoy | 320920c | 2010-07-14 08:21:12 -0500 | [diff] [blame] | 504 | long err = 0; |
Pavan Savoy | 38d9df4 | 2010-07-08 08:55:17 -0500 | [diff] [blame] | 505 | struct kim_data_s *kim_gdata = (struct kim_data_s *)kim_data; |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 506 | |
| 507 | INIT_COMPLETION(kim_gdata->ldisc_installed); |
Naveen Jain | b38fc2d | 2010-06-09 03:45:32 -0500 | [diff] [blame] | 508 | #if 0 /* older way of signalling user-space UIM */ |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 509 | /* send signal to UIM */ |
| 510 | err = kill_pid(find_get_pid(kim_gdata->uim_pid), SIGUSR2, 1); |
| 511 | if (err != 0) { |
| 512 | pr_err("sending SIGUSR2 to uim failed %ld", err); |
Pavan Savoy | 320920c | 2010-07-14 08:21:12 -0500 | [diff] [blame] | 513 | return -1; |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 514 | } |
Naveen Jain | b38fc2d | 2010-06-09 03:45:32 -0500 | [diff] [blame] | 515 | #endif |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 516 | /* set BT rfkill to be blocked */ |
| 517 | err = rfkill_set_hw_state(kim_gdata->rfkill[ST_BT], 1); |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 518 | |
| 519 | /* wait for ldisc to be un-installed */ |
| 520 | err = wait_for_completion_timeout(&kim_gdata->ldisc_installed, |
| 521 | msecs_to_jiffies(LDISC_TIME)); |
| 522 | if (!err) { /* timeout */ |
| 523 | pr_err(" timed out waiting for ldisc to be un-installed"); |
Pavan Savoy | 320920c | 2010-07-14 08:21:12 -0500 | [diff] [blame] | 524 | return -1; |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | /* By default configure BT nShutdown to LOW state */ |
| 528 | gpio_set_value(kim_gdata->gpios[ST_BT], GPIO_LOW); |
| 529 | mdelay(1); |
| 530 | gpio_set_value(kim_gdata->gpios[ST_BT], GPIO_HIGH); |
| 531 | mdelay(1); |
| 532 | gpio_set_value(kim_gdata->gpios[ST_BT], GPIO_LOW); |
| 533 | return err; |
| 534 | } |
| 535 | |
| 536 | /**********************************************************************/ |
| 537 | /* functions called from subsystems */ |
Pavan Savoy | c1afac1 | 2010-07-28 02:25:59 -0500 | [diff] [blame] | 538 | /* called when debugfs entry is read from */ |
Naveen Jain | e2a5328 | 2010-06-09 03:45:33 -0500 | [diff] [blame] | 539 | |
Pavan Savoy | c1afac1 | 2010-07-28 02:25:59 -0500 | [diff] [blame] | 540 | static int show_version(struct seq_file *s, void *unused) |
Naveen Jain | e2a5328 | 2010-06-09 03:45:33 -0500 | [diff] [blame] | 541 | { |
Pavan Savoy | c1afac1 | 2010-07-28 02:25:59 -0500 | [diff] [blame] | 542 | struct kim_data_s *kim_gdata = (struct kim_data_s *)s->private; |
| 543 | seq_printf(s, "%04X %d.%d.%d\n", kim_gdata->version.full, |
Naveen Jain | e2a5328 | 2010-06-09 03:45:33 -0500 | [diff] [blame] | 544 | kim_gdata->version.chip, kim_gdata->version.maj_ver, |
| 545 | kim_gdata->version.min_ver); |
Pavan Savoy | c1afac1 | 2010-07-28 02:25:59 -0500 | [diff] [blame] | 546 | return 0; |
Naveen Jain | e2a5328 | 2010-06-09 03:45:33 -0500 | [diff] [blame] | 547 | } |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 548 | |
Pavan Savoy | c1afac1 | 2010-07-28 02:25:59 -0500 | [diff] [blame] | 549 | static int show_list(struct seq_file *s, void *unused) |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 550 | { |
Pavan Savoy | c1afac1 | 2010-07-28 02:25:59 -0500 | [diff] [blame] | 551 | struct kim_data_s *kim_gdata = (struct kim_data_s *)s->private; |
| 552 | kim_st_list_protocols(kim_gdata->core_data, s); |
| 553 | return 0; |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 554 | } |
| 555 | |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 556 | /* function called from rfkill subsystem, when someone from |
| 557 | * user space would write 0/1 on the sysfs entry |
| 558 | * /sys/class/rfkill/rfkill0,1,3/state |
| 559 | */ |
| 560 | static int kim_toggle_radio(void *data, bool blocked) |
| 561 | { |
| 562 | enum proto_type type = *((enum proto_type *)data); |
Pavan Savoy | e6d9e64 | 2010-07-22 05:32:05 -0500 | [diff] [blame] | 563 | pr_debug(" %s: %d ", __func__, type); |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 564 | |
| 565 | switch (type) { |
| 566 | case ST_BT: |
| 567 | /* do nothing */ |
| 568 | break; |
| 569 | case ST_FM: |
| 570 | case ST_GPS: |
| 571 | if (blocked) |
| 572 | st_kim_chip_toggle(type, KIM_GPIO_INACTIVE); |
| 573 | else |
| 574 | st_kim_chip_toggle(type, KIM_GPIO_ACTIVE); |
| 575 | break; |
Pavan Savoy | 5c88b02 | 2011-02-04 02:23:09 -0600 | [diff] [blame^] | 576 | case ST_MAX_CHANNELS: |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 577 | pr_err(" wrong proto type "); |
| 578 | break; |
| 579 | } |
Pavan Savoy | 320920c | 2010-07-14 08:21:12 -0500 | [diff] [blame] | 580 | return 0; |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 581 | } |
| 582 | |
Pavan Savoy | 36b5aee | 2010-07-22 05:32:06 -0500 | [diff] [blame] | 583 | /** |
| 584 | * st_kim_ref - reference the core's data |
| 585 | * This references the per-ST platform device in the arch/xx/ |
| 586 | * board-xx.c file. |
| 587 | * This would enable multiple such platform devices to exist |
| 588 | * on a given platform |
| 589 | */ |
Pavan Savoy | dbd3a87 | 2010-08-19 14:08:51 -0400 | [diff] [blame] | 590 | void st_kim_ref(struct st_data_s **core_data, int id) |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 591 | { |
Pavan Savoy | 38d9df4 | 2010-07-08 08:55:17 -0500 | [diff] [blame] | 592 | struct platform_device *pdev; |
| 593 | struct kim_data_s *kim_gdata; |
| 594 | /* get kim_gdata reference from platform device */ |
Pavan Savoy | dbd3a87 | 2010-08-19 14:08:51 -0400 | [diff] [blame] | 595 | pdev = st_get_plat_device(id); |
Pavan Savoy | 38d9df4 | 2010-07-08 08:55:17 -0500 | [diff] [blame] | 596 | kim_gdata = dev_get_drvdata(&pdev->dev); |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 597 | *core_data = kim_gdata->core_data; |
| 598 | } |
| 599 | |
Pavan Savoy | c1afac1 | 2010-07-28 02:25:59 -0500 | [diff] [blame] | 600 | static int kim_version_open(struct inode *i, struct file *f) |
| 601 | { |
| 602 | return single_open(f, show_version, i->i_private); |
| 603 | } |
| 604 | |
| 605 | static int kim_list_open(struct inode *i, struct file *f) |
| 606 | { |
| 607 | return single_open(f, show_list, i->i_private); |
| 608 | } |
| 609 | |
| 610 | static const struct file_operations version_debugfs_fops = { |
| 611 | /* version info */ |
| 612 | .open = kim_version_open, |
| 613 | .read = seq_read, |
| 614 | .llseek = seq_lseek, |
| 615 | .release = single_release, |
| 616 | }; |
| 617 | static const struct file_operations list_debugfs_fops = { |
| 618 | /* protocols info */ |
| 619 | .open = kim_list_open, |
| 620 | .read = seq_read, |
| 621 | .llseek = seq_lseek, |
| 622 | .release = single_release, |
| 623 | }; |
| 624 | |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 625 | /**********************************************************************/ |
| 626 | /* functions called from platform device driver subsystem |
| 627 | * need to have a relevant platform device entry in the platform's |
| 628 | * board-*.c file |
| 629 | */ |
| 630 | |
Pavan Savoy | c1afac1 | 2010-07-28 02:25:59 -0500 | [diff] [blame] | 631 | struct dentry *kim_debugfs_dir; |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 632 | static int kim_probe(struct platform_device *pdev) |
| 633 | { |
| 634 | long status; |
| 635 | long proto; |
| 636 | long *gpios = pdev->dev.platform_data; |
Pavan Savoy | 38d9df4 | 2010-07-08 08:55:17 -0500 | [diff] [blame] | 637 | struct kim_data_s *kim_gdata; |
| 638 | |
Pavan Savoy | dfb7ef7 | 2010-09-10 15:58:55 -0400 | [diff] [blame] | 639 | if ((pdev->id != -1) && (pdev->id < MAX_ST_DEVICES)) { |
| 640 | /* multiple devices could exist */ |
| 641 | st_kim_devices[pdev->id] = pdev; |
| 642 | } else { |
| 643 | /* platform's sure about existance of 1 device */ |
| 644 | st_kim_devices[0] = pdev; |
| 645 | } |
| 646 | |
Pavan Savoy | 38d9df4 | 2010-07-08 08:55:17 -0500 | [diff] [blame] | 647 | kim_gdata = kzalloc(sizeof(struct kim_data_s), GFP_ATOMIC); |
| 648 | if (!kim_gdata) { |
| 649 | pr_err("no mem to allocate"); |
| 650 | return -ENOMEM; |
| 651 | } |
| 652 | dev_set_drvdata(&pdev->dev, kim_gdata); |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 653 | |
| 654 | status = st_core_init(&kim_gdata->core_data); |
| 655 | if (status != 0) { |
| 656 | pr_err(" ST core init failed"); |
Pavan Savoy | 320920c | 2010-07-14 08:21:12 -0500 | [diff] [blame] | 657 | return -1; |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 658 | } |
Pavan Savoy | 38d9df4 | 2010-07-08 08:55:17 -0500 | [diff] [blame] | 659 | /* refer to itself */ |
| 660 | kim_gdata->core_data->kim_data = kim_gdata; |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 661 | |
Pavan Savoy | 5c88b02 | 2011-02-04 02:23:09 -0600 | [diff] [blame^] | 662 | for (proto = 0; proto < ST_MAX_CHANNELS; proto++) { |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 663 | kim_gdata->gpios[proto] = gpios[proto]; |
| 664 | pr_info(" %ld gpio to be requested", gpios[proto]); |
| 665 | } |
| 666 | |
Pavan Savoy | 5c88b02 | 2011-02-04 02:23:09 -0600 | [diff] [blame^] | 667 | for (proto = 0; (proto < ST_MAX_CHANNELS) |
| 668 | && (gpios[proto] != -1); proto++) { |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 669 | /* Claim the Bluetooth/FM/GPIO |
| 670 | * nShutdown gpio from the system |
| 671 | */ |
| 672 | status = gpio_request(gpios[proto], "kim"); |
| 673 | if (unlikely(status)) { |
| 674 | pr_err(" gpio %ld request failed ", gpios[proto]); |
| 675 | proto -= 1; |
| 676 | while (proto >= 0) { |
| 677 | if (gpios[proto] != -1) |
| 678 | gpio_free(gpios[proto]); |
| 679 | } |
| 680 | return status; |
| 681 | } |
| 682 | |
| 683 | /* Configure nShutdown GPIO as output=0 */ |
| 684 | status = |
| 685 | gpio_direction_output(gpios[proto], 0); |
| 686 | if (unlikely(status)) { |
| 687 | pr_err(" unable to configure gpio %ld", |
| 688 | gpios[proto]); |
| 689 | proto -= 1; |
| 690 | while (proto >= 0) { |
| 691 | if (gpios[proto] != -1) |
| 692 | gpio_free(gpios[proto]); |
| 693 | } |
| 694 | return status; |
| 695 | } |
| 696 | } |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 697 | /* get reference of pdev for request_firmware |
| 698 | */ |
| 699 | kim_gdata->kim_pdev = pdev; |
| 700 | init_completion(&kim_gdata->kim_rcvd); |
| 701 | init_completion(&kim_gdata->ldisc_installed); |
Naveen Jain | b38fc2d | 2010-06-09 03:45:32 -0500 | [diff] [blame] | 702 | |
Pavan Savoy | 5c88b02 | 2011-02-04 02:23:09 -0600 | [diff] [blame^] | 703 | for (proto = 0; (proto < ST_MAX_CHANNELS) |
| 704 | && (gpios[proto] != -1); proto++) { |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 705 | /* TODO: should all types be rfkill_type_bt ? */ |
| 706 | kim_gdata->rf_protos[proto] = proto; |
| 707 | kim_gdata->rfkill[proto] = rfkill_alloc(protocol_names[proto], |
| 708 | &pdev->dev, RFKILL_TYPE_BLUETOOTH, |
| 709 | &kim_rfkill_ops, &kim_gdata->rf_protos[proto]); |
| 710 | if (kim_gdata->rfkill[proto] == NULL) { |
| 711 | pr_err("cannot create rfkill entry for gpio %ld", |
| 712 | gpios[proto]); |
| 713 | continue; |
| 714 | } |
| 715 | /* block upon creation */ |
| 716 | rfkill_init_sw_state(kim_gdata->rfkill[proto], 1); |
| 717 | status = rfkill_register(kim_gdata->rfkill[proto]); |
| 718 | if (unlikely(status)) { |
| 719 | pr_err("rfkill registration failed for gpio %ld", |
| 720 | gpios[proto]); |
| 721 | rfkill_unregister(kim_gdata->rfkill[proto]); |
| 722 | continue; |
| 723 | } |
| 724 | pr_info("rfkill entry created for %ld", gpios[proto]); |
| 725 | } |
Naveen Jain | e2a5328 | 2010-06-09 03:45:33 -0500 | [diff] [blame] | 726 | |
Pavan Savoy | c1afac1 | 2010-07-28 02:25:59 -0500 | [diff] [blame] | 727 | kim_debugfs_dir = debugfs_create_dir("ti-st", NULL); |
| 728 | if (IS_ERR(kim_debugfs_dir)) { |
| 729 | pr_err(" debugfs entries creation failed "); |
| 730 | kim_debugfs_dir = NULL; |
Naveen Jain | e2a5328 | 2010-06-09 03:45:33 -0500 | [diff] [blame] | 731 | return -1; |
| 732 | } |
Pavan Savoy | c1afac1 | 2010-07-28 02:25:59 -0500 | [diff] [blame] | 733 | |
| 734 | debugfs_create_file("version", S_IRUGO, kim_debugfs_dir, |
| 735 | kim_gdata, &version_debugfs_fops); |
| 736 | debugfs_create_file("protocols", S_IRUGO, kim_debugfs_dir, |
| 737 | kim_gdata, &list_debugfs_fops); |
| 738 | pr_info(" debugfs entries created "); |
Pavan Savoy | 320920c | 2010-07-14 08:21:12 -0500 | [diff] [blame] | 739 | return 0; |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | static int kim_remove(struct platform_device *pdev) |
| 743 | { |
| 744 | /* free the GPIOs requested |
| 745 | */ |
| 746 | long *gpios = pdev->dev.platform_data; |
| 747 | long proto; |
Pavan Savoy | 38d9df4 | 2010-07-08 08:55:17 -0500 | [diff] [blame] | 748 | struct kim_data_s *kim_gdata; |
| 749 | |
| 750 | kim_gdata = dev_get_drvdata(&pdev->dev); |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 751 | |
Pavan Savoy | 5c88b02 | 2011-02-04 02:23:09 -0600 | [diff] [blame^] | 752 | for (proto = 0; (proto < ST_MAX_CHANNELS) |
| 753 | && (gpios[proto] != -1); proto++) { |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 754 | /* Claim the Bluetooth/FM/GPIO |
| 755 | * nShutdown gpio from the system |
| 756 | */ |
| 757 | gpio_free(gpios[proto]); |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 758 | rfkill_unregister(kim_gdata->rfkill[proto]); |
| 759 | rfkill_destroy(kim_gdata->rfkill[proto]); |
| 760 | kim_gdata->rfkill[proto] = NULL; |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 761 | } |
| 762 | pr_info("kim: GPIO Freed"); |
Pavan Savoy | c1afac1 | 2010-07-28 02:25:59 -0500 | [diff] [blame] | 763 | debugfs_remove_recursive(kim_debugfs_dir); |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 764 | kim_gdata->kim_pdev = NULL; |
| 765 | st_core_exit(kim_gdata->core_data); |
Pavan Savoy | 38d9df4 | 2010-07-08 08:55:17 -0500 | [diff] [blame] | 766 | |
| 767 | kfree(kim_gdata); |
| 768 | kim_gdata = NULL; |
Pavan Savoy | 320920c | 2010-07-14 08:21:12 -0500 | [diff] [blame] | 769 | return 0; |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | /**********************************************************************/ |
| 773 | /* entry point for ST KIM module, called in from ST Core */ |
| 774 | |
| 775 | static int __init st_kim_init(void) |
| 776 | { |
Pavan Savoy | 320920c | 2010-07-14 08:21:12 -0500 | [diff] [blame] | 777 | long ret = 0; |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 778 | ret = platform_driver_register(&kim_platform_driver); |
| 779 | if (ret != 0) { |
| 780 | pr_err("platform drv registration failed"); |
Pavan Savoy | 320920c | 2010-07-14 08:21:12 -0500 | [diff] [blame] | 781 | return -1; |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 782 | } |
Pavan Savoy | 320920c | 2010-07-14 08:21:12 -0500 | [diff] [blame] | 783 | return 0; |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | static void __exit st_kim_deinit(void) |
| 787 | { |
| 788 | /* the following returns void */ |
| 789 | platform_driver_unregister(&kim_platform_driver); |
Pavan Savoy | d0088ce | 2010-04-08 13:16:54 -0500 | [diff] [blame] | 790 | } |
| 791 | |
| 792 | |
| 793 | module_init(st_kim_init); |
| 794 | module_exit(st_kim_deinit); |
| 795 | MODULE_AUTHOR("Pavan Savoy <pavan_savoy@ti.com>"); |
| 796 | MODULE_DESCRIPTION("Shared Transport Driver for TI BT/FM/GPS combo chips "); |
| 797 | MODULE_LICENSE("GPL"); |