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