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