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