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