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