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