drivers:misc: ti-st: fix error codes
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / misc / ti-st / st_kim.c
blobccc46a7b0abbb3b465f1d923bfe242af2cc5ea13
1 /*
2 * Shared Transport Line discipline driver Core
3 * Init Manager module responsible for GPIO control
4 * and firmware download
5 * Copyright (C) 2009-2010 Texas Instruments
6 * Author: Pavan Savoy <pavan_savoy@ti.com>
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.
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.
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
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>
30 #include <linux/debugfs.h>
31 #include <linux/seq_file.h>
32 #include <linux/sched.h>
33 #include <linux/tty.h>
35 #include <linux/skbuff.h>
36 #include <linux/ti_wilink_st.h>
39 #define MAX_ST_DEVICES 3 /* Imagine 1 on each UART for now */
40 static struct platform_device *st_kim_devices[MAX_ST_DEVICES];
42 /**********************************************************************/
43 /* internal functions */
45 /**
46 * st_get_plat_device -
47 * function which returns the reference to the platform device
48 * requested by id. As of now only 1 such device exists (id=0)
49 * the context requesting for reference can get the id to be
50 * requested by a. The protocol driver which is registering or
51 * b. the tty device which is opened.
53 static struct platform_device *st_get_plat_device(int id)
55 return st_kim_devices[id];
58 /**
59 * validate_firmware_response -
60 * function to return whether the firmware response was proper
61 * in case of error don't complete so that waiting for proper
62 * response times out
64 void validate_firmware_response(struct kim_data_s *kim_gdata)
66 struct sk_buff *skb = kim_gdata->rx_skb;
67 if (unlikely(skb->data[5] != 0)) {
68 pr_err("no proper response during fw download");
69 pr_err("data6 %x", skb->data[5]);
70 return; /* keep waiting for the proper response */
72 /* becos of all the script being downloaded */
73 complete_all(&kim_gdata->kim_rcvd);
74 kfree_skb(skb);
77 /* check for data len received inside kim_int_recv
78 * most often hit the last case to update state to waiting for data
80 static inline int kim_check_data_len(struct kim_data_s *kim_gdata, int len)
82 register int room = skb_tailroom(kim_gdata->rx_skb);
84 pr_debug("len %d room %d", len, room);
86 if (!len) {
87 validate_firmware_response(kim_gdata);
88 } else if (len > room) {
89 /* Received packet's payload length is larger.
90 * We can't accommodate it in created skb.
92 pr_err("Data length is too large len %d room %d", len,
93 room);
94 kfree_skb(kim_gdata->rx_skb);
95 } else {
96 /* Packet header has non-zero payload length and
97 * we have enough space in created skb. Lets read
98 * payload data */
99 kim_gdata->rx_state = ST_W4_DATA;
100 kim_gdata->rx_count = len;
101 return len;
104 /* Change ST LL state to continue to process next
105 * packet */
106 kim_gdata->rx_state = ST_W4_PACKET_TYPE;
107 kim_gdata->rx_skb = NULL;
108 kim_gdata->rx_count = 0;
110 return 0;
114 * kim_int_recv - receive function called during firmware download
115 * firmware download responses on different UART drivers
116 * have been observed to come in bursts of different
117 * tty_receive and hence the logic
119 void kim_int_recv(struct kim_data_s *kim_gdata,
120 const unsigned char *data, long count)
122 const unsigned char *ptr;
123 int len = 0, type = 0;
124 unsigned char *plen;
126 pr_debug("%s", __func__);
127 /* Decode received bytes here */
128 ptr = data;
129 if (unlikely(ptr == NULL)) {
130 pr_err(" received null from TTY ");
131 return;
134 while (count) {
135 if (kim_gdata->rx_count) {
136 len = min_t(unsigned int, kim_gdata->rx_count, count);
137 memcpy(skb_put(kim_gdata->rx_skb, len), ptr, len);
138 kim_gdata->rx_count -= len;
139 count -= len;
140 ptr += len;
142 if (kim_gdata->rx_count)
143 continue;
145 /* Check ST RX state machine , where are we? */
146 switch (kim_gdata->rx_state) {
147 /* Waiting for complete packet ? */
148 case ST_W4_DATA:
149 pr_debug("Complete pkt received");
150 validate_firmware_response(kim_gdata);
151 kim_gdata->rx_state = ST_W4_PACKET_TYPE;
152 kim_gdata->rx_skb = NULL;
153 continue;
154 /* Waiting for Bluetooth event header ? */
155 case ST_W4_HEADER:
156 plen =
157 (unsigned char *)&kim_gdata->rx_skb->data[1];
158 pr_debug("event hdr: plen 0x%02x\n", *plen);
159 kim_check_data_len(kim_gdata, *plen);
160 continue;
161 } /* end of switch */
162 } /* end of if rx_state */
163 switch (*ptr) {
164 /* Bluetooth event packet? */
165 case 0x04:
166 kim_gdata->rx_state = ST_W4_HEADER;
167 kim_gdata->rx_count = 2;
168 type = *ptr;
169 break;
170 default:
171 pr_info("unknown packet");
172 ptr++;
173 count--;
174 continue;
176 ptr++;
177 count--;
178 kim_gdata->rx_skb =
179 alloc_skb(1024+8, GFP_ATOMIC);
180 if (!kim_gdata->rx_skb) {
181 pr_err("can't allocate mem for new packet");
182 kim_gdata->rx_state = ST_W4_PACKET_TYPE;
183 kim_gdata->rx_count = 0;
184 return;
186 skb_reserve(kim_gdata->rx_skb, 8);
187 kim_gdata->rx_skb->cb[0] = 4;
188 kim_gdata->rx_skb->cb[1] = 0;
191 return;
194 static long read_local_version(struct kim_data_s *kim_gdata, char *bts_scr_name)
196 unsigned short version = 0, chip = 0, min_ver = 0, maj_ver = 0;
197 const char read_ver_cmd[] = { 0x01, 0x01, 0x10, 0x00 };
199 pr_debug("%s", __func__);
201 INIT_COMPLETION(kim_gdata->kim_rcvd);
202 if (4 != st_int_write(kim_gdata->core_data, read_ver_cmd, 4)) {
203 pr_err("kim: couldn't write 4 bytes");
204 return -EIO;
207 if (!wait_for_completion_timeout
208 (&kim_gdata->kim_rcvd, msecs_to_jiffies(CMD_RESP_TIME))) {
209 pr_err(" waiting for ver info- timed out ");
210 return -ETIMEDOUT;
213 version =
214 MAKEWORD(kim_gdata->resp_buffer[13],
215 kim_gdata->resp_buffer[14]);
216 chip = (version & 0x7C00) >> 10;
217 min_ver = (version & 0x007F);
218 maj_ver = (version & 0x0380) >> 7;
220 if (version & 0x8000)
221 maj_ver |= 0x0008;
223 sprintf(bts_scr_name, "TIInit_%d.%d.%d.bts", chip, maj_ver, min_ver);
225 /* to be accessed later via sysfs entry */
226 kim_gdata->version.full = version;
227 kim_gdata->version.chip = chip;
228 kim_gdata->version.maj_ver = maj_ver;
229 kim_gdata->version.min_ver = min_ver;
231 pr_info("%s", bts_scr_name);
232 return 0;
236 * download_firmware -
237 * internal function which parses through the .bts firmware
238 * script file intreprets SEND, DELAY actions only as of now
240 static long download_firmware(struct kim_data_s *kim_gdata)
242 long err = 0;
243 long len = 0;
244 unsigned char *ptr = NULL;
245 unsigned char *action_ptr = NULL;
246 unsigned char bts_scr_name[30] = { 0 }; /* 30 char long bts scr name? */
248 err = read_local_version(kim_gdata, bts_scr_name);
249 if (err != 0) {
250 pr_err("kim: failed to read local ver");
251 return err;
253 err =
254 request_firmware(&kim_gdata->fw_entry, bts_scr_name,
255 &kim_gdata->kim_pdev->dev);
256 if (unlikely((err != 0) || (kim_gdata->fw_entry->data == NULL) ||
257 (kim_gdata->fw_entry->size == 0))) {
258 pr_err(" request_firmware failed(errno %ld) for %s", err,
259 bts_scr_name);
260 return -EINVAL;
262 ptr = (void *)kim_gdata->fw_entry->data;
263 len = kim_gdata->fw_entry->size;
264 /* bts_header to remove out magic number and
265 * version
267 ptr += sizeof(struct bts_header);
268 len -= sizeof(struct bts_header);
270 while (len > 0 && ptr) {
271 pr_debug(" action size %d, type %d ",
272 ((struct bts_action *)ptr)->size,
273 ((struct bts_action *)ptr)->type);
275 switch (((struct bts_action *)ptr)->type) {
276 case ACTION_SEND_COMMAND: /* action send */
277 action_ptr = &(((struct bts_action *)ptr)->data[0]);
278 if (unlikely
279 (((struct hci_command *)action_ptr)->opcode ==
280 0xFF36)) {
281 /* ignore remote change
282 * baud rate HCI VS command */
283 pr_err
284 (" change remote baud"
285 " rate command in firmware");
286 break;
289 INIT_COMPLETION(kim_gdata->kim_rcvd);
290 err = st_int_write(kim_gdata->core_data,
291 ((struct bts_action_send *)action_ptr)->data,
292 ((struct bts_action *)ptr)->size);
293 if (unlikely(err < 0)) {
294 release_firmware(kim_gdata->fw_entry);
295 return err;
297 if (!wait_for_completion_timeout
298 (&kim_gdata->kim_rcvd,
299 msecs_to_jiffies(CMD_RESP_TIME))) {
300 pr_err
301 (" response timeout during fw download ");
302 /* timed out */
303 release_firmware(kim_gdata->fw_entry);
304 return -ETIMEDOUT;
306 break;
307 case ACTION_DELAY: /* sleep */
308 pr_info("sleep command in scr");
309 action_ptr = &(((struct bts_action *)ptr)->data[0]);
310 mdelay(((struct bts_action_delay *)action_ptr)->msec);
311 break;
313 len =
314 len - (sizeof(struct bts_action) +
315 ((struct bts_action *)ptr)->size);
316 ptr =
317 ptr + sizeof(struct bts_action) +
318 ((struct bts_action *)ptr)->size;
320 /* fw download complete */
321 release_firmware(kim_gdata->fw_entry);
322 return 0;
325 /**********************************************************************/
326 /* functions called from ST core */
327 /* function to toggle the GPIO
328 * needs to know whether the GPIO is active high or active low
330 void st_kim_chip_toggle(enum proto_type type, enum kim_gpio_state state)
332 struct platform_device *kim_pdev;
333 struct kim_data_s *kim_gdata;
334 pr_info(" %s ", __func__);
336 kim_pdev = st_get_plat_device(0);
337 kim_gdata = dev_get_drvdata(&kim_pdev->dev);
339 if (kim_gdata->gpios[type] == -1) {
340 pr_info("gpio not requested for protocol %d", type);
341 return;
343 switch (type) {
344 case ST_BT:
345 /*Do Nothing */
346 break;
348 case ST_FM:
349 if (state == KIM_GPIO_ACTIVE)
350 gpio_set_value(kim_gdata->gpios[ST_FM], GPIO_LOW);
351 else
352 gpio_set_value(kim_gdata->gpios[ST_FM], GPIO_HIGH);
353 break;
355 case ST_GPS:
356 if (state == KIM_GPIO_ACTIVE)
357 gpio_set_value(kim_gdata->gpios[ST_GPS], GPIO_HIGH);
358 else
359 gpio_set_value(kim_gdata->gpios[ST_GPS], GPIO_LOW);
360 break;
362 case ST_MAX_CHANNELS:
363 default:
364 break;
367 return;
370 /* called from ST Core, when REG_IN_PROGRESS (registration in progress)
371 * can be because of
372 * 1. response to read local version
373 * 2. during send/recv's of firmware download
375 void st_kim_recv(void *disc_data, const unsigned char *data, long count)
377 struct st_data_s *st_gdata = (struct st_data_s *)disc_data;
378 struct kim_data_s *kim_gdata = st_gdata->kim_data;
380 /* copy to local buffer */
381 if (unlikely(data[4] == 0x01 && data[5] == 0x10 && data[0] == 0x04)) {
382 /* must be the read_ver_cmd */
383 memcpy(kim_gdata->resp_buffer, data, count);
384 complete_all(&kim_gdata->kim_rcvd);
385 return;
386 } else {
387 kim_int_recv(kim_gdata, data, count);
388 /* either completes or times out */
390 return;
393 /* to signal completion of line discipline installation
394 * called from ST Core, upon tty_open
396 void st_kim_complete(void *kim_data)
398 struct kim_data_s *kim_gdata = (struct kim_data_s *)kim_data;
399 complete(&kim_gdata->ldisc_installed);
403 * st_kim_start - called from ST Core upon 1st registration
404 * This involves toggling the chip enable gpio, reading
405 * the firmware version from chip, forming the fw file name
406 * based on the chip version, requesting the fw, parsing it
407 * and perform download(send/recv).
409 long st_kim_start(void *kim_data)
411 long err = 0;
412 long retry = POR_RETRY_COUNT;
413 struct kim_data_s *kim_gdata = (struct kim_data_s *)kim_data;
415 pr_info(" %s", __func__);
417 do {
418 /* Configure BT nShutdown to HIGH state */
419 gpio_set_value(kim_gdata->gpios[ST_BT], GPIO_LOW);
420 mdelay(5); /* FIXME: a proper toggle */
421 gpio_set_value(kim_gdata->gpios[ST_BT], GPIO_HIGH);
422 mdelay(100);
423 /* re-initialize the completion */
424 INIT_COMPLETION(kim_gdata->ldisc_installed);
425 /* send notification to UIM */
426 kim_gdata->ldisc_install = 1;
427 pr_info("ldisc_install = 1");
428 sysfs_notify(&kim_gdata->kim_pdev->dev.kobj,
429 NULL, "install");
430 /* wait for ldisc to be installed */
431 err = wait_for_completion_timeout(&kim_gdata->ldisc_installed,
432 msecs_to_jiffies(LDISC_TIME));
433 if (!err) { /* timeout */
434 pr_err("line disc installation timed out ");
435 kim_gdata->ldisc_install = 0;
436 pr_info("ldisc_install = 0");
437 sysfs_notify(&kim_gdata->kim_pdev->dev.kobj,
438 NULL, "install");
439 err = -ETIMEDOUT;
440 continue;
441 } else {
442 /* ldisc installed now */
443 pr_info(" line discipline installed ");
444 err = download_firmware(kim_gdata);
445 if (err != 0) {
446 pr_err("download firmware failed");
447 kim_gdata->ldisc_install = 0;
448 pr_info("ldisc_install = 0");
449 sysfs_notify(&kim_gdata->kim_pdev->dev.kobj,
450 NULL, "install");
451 continue;
452 } else { /* on success don't retry */
453 break;
456 } while (retry--);
457 return err;
461 * st_kim_stop - called from ST Core, on the last un-registration
462 * toggle low the chip enable gpio
464 long st_kim_stop(void *kim_data)
466 long err = 0;
467 struct kim_data_s *kim_gdata = (struct kim_data_s *)kim_data;
469 INIT_COMPLETION(kim_gdata->ldisc_installed);
471 /* Flush any pending characters in the driver and discipline. */
472 tty_ldisc_flush(kim_gdata->core_data->tty);
473 tty_driver_flush_buffer(kim_gdata->core_data->tty);
475 /* send uninstall notification to UIM */
476 pr_info("ldisc_install = 0");
477 kim_gdata->ldisc_install = 0;
478 sysfs_notify(&kim_gdata->kim_pdev->dev.kobj, NULL, "install");
480 /* wait for ldisc to be un-installed */
481 err = wait_for_completion_timeout(&kim_gdata->ldisc_installed,
482 msecs_to_jiffies(LDISC_TIME));
483 if (!err) { /* timeout */
484 pr_err(" timed out waiting for ldisc to be un-installed");
485 return -ETIMEDOUT;
488 /* By default configure BT nShutdown to LOW state */
489 gpio_set_value(kim_gdata->gpios[ST_BT], GPIO_LOW);
490 mdelay(1);
491 gpio_set_value(kim_gdata->gpios[ST_BT], GPIO_HIGH);
492 mdelay(1);
493 gpio_set_value(kim_gdata->gpios[ST_BT], GPIO_LOW);
494 return err;
497 /**********************************************************************/
498 /* functions called from subsystems */
499 /* called when debugfs entry is read from */
501 static int show_version(struct seq_file *s, void *unused)
503 struct kim_data_s *kim_gdata = (struct kim_data_s *)s->private;
504 seq_printf(s, "%04X %d.%d.%d\n", kim_gdata->version.full,
505 kim_gdata->version.chip, kim_gdata->version.maj_ver,
506 kim_gdata->version.min_ver);
507 return 0;
510 static int show_list(struct seq_file *s, void *unused)
512 struct kim_data_s *kim_gdata = (struct kim_data_s *)s->private;
513 kim_st_list_protocols(kim_gdata->core_data, s);
514 return 0;
517 static ssize_t show_install(struct device *dev,
518 struct device_attribute *attr, char *buf)
520 struct kim_data_s *kim_data = dev_get_drvdata(dev);
521 return sprintf(buf, "%d\n", kim_data->ldisc_install);
524 static ssize_t show_dev_name(struct device *dev,
525 struct device_attribute *attr, char *buf)
527 struct kim_data_s *kim_data = dev_get_drvdata(dev);
528 return sprintf(buf, "%s\n", kim_data->dev_name);
531 static ssize_t show_baud_rate(struct device *dev,
532 struct device_attribute *attr, char *buf)
534 struct kim_data_s *kim_data = dev_get_drvdata(dev);
535 return sprintf(buf, "%ld\n", kim_data->baud_rate);
538 static ssize_t show_flow_cntrl(struct device *dev,
539 struct device_attribute *attr, char *buf)
541 struct kim_data_s *kim_data = dev_get_drvdata(dev);
542 return sprintf(buf, "%d\n", kim_data->flow_cntrl);
545 /* structures specific for sysfs entries */
546 static struct kobj_attribute ldisc_install =
547 __ATTR(install, 0444, (void *)show_install, NULL);
549 static struct kobj_attribute uart_dev_name =
550 __ATTR(dev_name, 0444, (void *)show_dev_name, NULL);
552 static struct kobj_attribute uart_baud_rate =
553 __ATTR(baud_rate, 0444, (void *)show_baud_rate, NULL);
555 static struct kobj_attribute uart_flow_cntrl =
556 __ATTR(flow_cntrl, 0444, (void *)show_flow_cntrl, NULL);
558 static struct attribute *uim_attrs[] = {
559 &ldisc_install.attr,
560 &uart_dev_name.attr,
561 &uart_baud_rate.attr,
562 &uart_flow_cntrl.attr,
563 NULL,
566 static struct attribute_group uim_attr_grp = {
567 .attrs = uim_attrs,
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
577 void st_kim_ref(struct st_data_s **core_data, int id)
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(id);
583 kim_gdata = dev_get_drvdata(&pdev->dev);
584 *core_data = kim_gdata->core_data;
587 static int kim_version_open(struct inode *i, struct file *f)
589 return single_open(f, show_version, i->i_private);
592 static int kim_list_open(struct inode *i, struct file *f)
594 return single_open(f, show_list, i->i_private);
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,
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,
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
618 struct dentry *kim_debugfs_dir;
619 static int kim_probe(struct platform_device *pdev)
621 long status;
622 long proto;
623 struct kim_data_s *kim_gdata;
624 struct ti_st_plat_data *pdata = pdev->dev.platform_data;
625 long *gpios = pdata->gpios;
627 if ((pdev->id != -1) && (pdev->id < MAX_ST_DEVICES)) {
628 /* multiple devices could exist */
629 st_kim_devices[pdev->id] = pdev;
630 } else {
631 /* platform's sure about existance of 1 device */
632 st_kim_devices[0] = pdev;
635 kim_gdata = kzalloc(sizeof(struct kim_data_s), GFP_ATOMIC);
636 if (!kim_gdata) {
637 pr_err("no mem to allocate");
638 return -ENOMEM;
640 dev_set_drvdata(&pdev->dev, kim_gdata);
642 status = st_core_init(&kim_gdata->core_data);
643 if (status != 0) {
644 pr_err(" ST core init failed");
645 return -EIO;
647 /* refer to itself */
648 kim_gdata->core_data->kim_data = kim_gdata;
650 for (proto = 0; proto < ST_MAX_CHANNELS; proto++) {
651 kim_gdata->gpios[proto] = gpios[proto];
652 pr_info(" %ld gpio to be requested", gpios[proto]);
655 for (proto = 0; (proto < ST_MAX_CHANNELS)
656 && (gpios[proto] != -1); proto++) {
657 /* Claim the Bluetooth/FM/GPIO
658 * nShutdown gpio from the system
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]);
668 return status;
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]);
682 return status;
685 /* get reference of pdev for request_firmware
687 kim_gdata->kim_pdev = pdev;
688 init_completion(&kim_gdata->kim_rcvd);
689 init_completion(&kim_gdata->ldisc_installed);
691 status = sysfs_create_group(&pdev->dev.kobj, &uim_attr_grp);
692 if (status) {
693 pr_err("failed to create sysfs entries");
694 return status;
697 /* copying platform data */
698 strncpy(kim_gdata->dev_name, pdata->dev_name, UART_DEV_NAME_LEN);
699 kim_gdata->flow_cntrl = pdata->flow_cntrl;
700 kim_gdata->baud_rate = pdata->baud_rate;
701 pr_info("sysfs entries created\n");
703 kim_debugfs_dir = debugfs_create_dir("ti-st", NULL);
704 if (IS_ERR(kim_debugfs_dir)) {
705 pr_err(" debugfs entries creation failed ");
706 kim_debugfs_dir = NULL;
707 return -EIO;
710 debugfs_create_file("version", S_IRUGO, kim_debugfs_dir,
711 kim_gdata, &version_debugfs_fops);
712 debugfs_create_file("protocols", S_IRUGO, kim_debugfs_dir,
713 kim_gdata, &list_debugfs_fops);
714 pr_info(" debugfs entries created ");
715 return 0;
718 static int kim_remove(struct platform_device *pdev)
720 /* free the GPIOs requested */
721 struct ti_st_plat_data *pdata = pdev->dev.platform_data;
722 long *gpios = pdata->gpios;
723 long proto;
724 struct kim_data_s *kim_gdata;
726 kim_gdata = dev_get_drvdata(&pdev->dev);
728 for (proto = 0; (proto < ST_MAX_CHANNELS)
729 && (gpios[proto] != -1); proto++) {
730 /* Claim the Bluetooth/FM/GPIO
731 * nShutdown gpio from the system
733 gpio_free(gpios[proto]);
735 pr_info("kim: GPIO Freed");
736 debugfs_remove_recursive(kim_debugfs_dir);
738 sysfs_remove_group(&pdev->dev.kobj, &uim_attr_grp);
739 kim_gdata->kim_pdev = NULL;
740 st_core_exit(kim_gdata->core_data);
742 kfree(kim_gdata);
743 kim_gdata = NULL;
744 return 0;
747 int kim_suspend(struct platform_device *pdev, pm_message_t state)
749 struct ti_st_plat_data *pdata = pdev->dev.platform_data;
751 if (pdata->suspend)
752 return pdata->suspend(pdev, state);
754 return -EOPNOTSUPP;
757 int kim_resume(struct platform_device *pdev)
759 struct ti_st_plat_data *pdata = pdev->dev.platform_data;
761 if (pdata->resume)
762 return pdata->resume(pdev);
764 return -EOPNOTSUPP;
767 /**********************************************************************/
768 /* entry point for ST KIM module, called in from ST Core */
769 static struct platform_driver kim_platform_driver = {
770 .probe = kim_probe,
771 .remove = kim_remove,
772 .suspend = kim_suspend,
773 .resume = kim_resume,
774 .driver = {
775 .name = "kim",
776 .owner = THIS_MODULE,
780 static int __init st_kim_init(void)
782 return platform_driver_register(&kim_platform_driver);
785 static void __exit st_kim_deinit(void)
787 platform_driver_unregister(&kim_platform_driver);
791 module_init(st_kim_init);
792 module_exit(st_kim_deinit);
793 MODULE_AUTHOR("Pavan Savoy <pavan_savoy@ti.com>");
794 MODULE_DESCRIPTION("Shared Transport Driver for TI BT/FM/GPS combo chips ");
795 MODULE_LICENSE("GPL");