Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *  Shared Transport Line discipline driver Core
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *	Init Manager module responsible for GPIO control
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *	and firmware download
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *  Copyright (C) 2009-2010 Texas Instruments
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *  Author: Pavan Savoy <pavan_savoy@ti.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #define pr_fmt(fmt) "(stk) :" fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/jiffies.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/firmware.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/wait.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/gpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/debugfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/sysfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/tty.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/ti_wilink_st.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #define MAX_ST_DEVICES	3	/* Imagine 1 on each UART for now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) static struct platform_device *st_kim_devices[MAX_ST_DEVICES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) /**********************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) /* internal functions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  * st_get_plat_device -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  *	function which returns the reference to the platform device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  *	requested by id. As of now only 1 such device exists (id=0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  *	the context requesting for reference can get the id to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  *	requested by a. The protocol driver which is registering or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  *	b. the tty device which is opened.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) static struct platform_device *st_get_plat_device(int id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	return st_kim_devices[id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  * validate_firmware_response -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  *	function to return whether the firmware response was proper
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  *	in case of error don't complete so that waiting for proper
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  *	response times out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) static void validate_firmware_response(struct kim_data_s *kim_gdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	struct sk_buff *skb = kim_gdata->rx_skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	 * these magic numbers are the position in the response buffer which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	 * allows us to distinguish whether the response is for the read
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	 * version info. command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	if (skb->data[2] == 0x01 && skb->data[3] == 0x01 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 			skb->data[4] == 0x10 && skb->data[5] == 0x00) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		/* fw version response */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		memcpy(kim_gdata->resp_buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 				kim_gdata->rx_skb->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 				kim_gdata->rx_skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		kim_gdata->rx_state = ST_W4_PACKET_TYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		kim_gdata->rx_skb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		kim_gdata->rx_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	} else if (unlikely(skb->data[5] != 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		pr_err("no proper response during fw download");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		pr_err("data6 %x", skb->data[5]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		return;		/* keep waiting for the proper response */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	/* becos of all the script being downloaded */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	complete_all(&kim_gdata->kim_rcvd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84)  * check for data len received inside kim_int_recv
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85)  * most often hit the last case to update state to waiting for data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) static inline int kim_check_data_len(struct kim_data_s *kim_gdata, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	register int room = skb_tailroom(kim_gdata->rx_skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	pr_debug("len %d room %d", len, room);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	if (!len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		validate_firmware_response(kim_gdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	} else if (len > room) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		 * Received packet's payload length is larger.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		 * We can't accommodate it in created skb.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		pr_err("Data length is too large len %d room %d", len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 			   room);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		kfree_skb(kim_gdata->rx_skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		 * Packet header has non-zero payload length and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		 * we have enough space in created skb. Lets read
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		 * payload data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		kim_gdata->rx_state = ST_W4_DATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		kim_gdata->rx_count = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	 * Change ST LL state to continue to process next
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	 * packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	kim_gdata->rx_state = ST_W4_PACKET_TYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	kim_gdata->rx_skb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	kim_gdata->rx_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)  * kim_int_recv - receive function called during firmware download
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)  *	firmware download responses on different UART drivers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)  *	have been observed to come in bursts of different
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)  *	tty_receive and hence the logic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) static void kim_int_recv(struct kim_data_s *kim_gdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	const unsigned char *data, long count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	const unsigned char *ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	int len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	unsigned char *plen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	pr_debug("%s", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	/* Decode received bytes here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	ptr = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	if (unlikely(ptr == NULL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		pr_err(" received null from TTY ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	while (count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		if (kim_gdata->rx_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 			len = min_t(unsigned int, kim_gdata->rx_count, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 			skb_put_data(kim_gdata->rx_skb, ptr, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 			kim_gdata->rx_count -= len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 			count -= len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 			ptr += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 			if (kim_gdata->rx_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 			/* Check ST RX state machine , where are we? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 			switch (kim_gdata->rx_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 				/* Waiting for complete packet ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 			case ST_W4_DATA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 				pr_debug("Complete pkt received");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 				validate_firmware_response(kim_gdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 				kim_gdata->rx_state = ST_W4_PACKET_TYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 				kim_gdata->rx_skb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 				/* Waiting for Bluetooth event header ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 			case ST_W4_HEADER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 				plen =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 				(unsigned char *)&kim_gdata->rx_skb->data[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 				pr_debug("event hdr: plen 0x%02x\n", *plen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 				kim_check_data_len(kim_gdata, *plen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 			}	/* end of switch */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		}		/* end of if rx_state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		switch (*ptr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 			/* Bluetooth event packet? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		case 0x04:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 			kim_gdata->rx_state = ST_W4_HEADER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 			kim_gdata->rx_count = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 			pr_info("unknown packet");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 			ptr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 			count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		ptr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		kim_gdata->rx_skb =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 			alloc_skb(1024+8, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		if (!kim_gdata->rx_skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 			pr_err("can't allocate mem for new packet");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 			kim_gdata->rx_state = ST_W4_PACKET_TYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 			kim_gdata->rx_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		skb_reserve(kim_gdata->rx_skb, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		kim_gdata->rx_skb->cb[0] = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		kim_gdata->rx_skb->cb[1] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) static long read_local_version(struct kim_data_s *kim_gdata, char *bts_scr_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	unsigned short version = 0, chip = 0, min_ver = 0, maj_ver = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	static const char read_ver_cmd[] = { 0x01, 0x01, 0x10, 0x00 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	long timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	pr_debug("%s", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	reinit_completion(&kim_gdata->kim_rcvd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	if (4 != st_int_write(kim_gdata->core_data, read_ver_cmd, 4)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		pr_err("kim: couldn't write 4 bytes");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	timeout = wait_for_completion_interruptible_timeout(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		&kim_gdata->kim_rcvd, msecs_to_jiffies(CMD_RESP_TIME));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	if (timeout <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		pr_err(" waiting for ver info- timed out or received signal");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		return timeout ? -ERESTARTSYS : -ETIMEDOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	reinit_completion(&kim_gdata->kim_rcvd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	 * the positions 12 & 13 in the response buffer provide with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	 * chip, major & minor numbers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	version =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		MAKEWORD(kim_gdata->resp_buffer[12],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 				kim_gdata->resp_buffer[13]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	chip = (version & 0x7C00) >> 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	min_ver = (version & 0x007F);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	maj_ver = (version & 0x0380) >> 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	if (version & 0x8000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		maj_ver |= 0x0008;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	sprintf(bts_scr_name, "ti-connectivity/TIInit_%d.%d.%d.bts",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		chip, maj_ver, min_ver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	/* to be accessed later via sysfs entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	kim_gdata->version.full = version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	kim_gdata->version.chip = chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	kim_gdata->version.maj_ver = maj_ver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	kim_gdata->version.min_ver = min_ver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	pr_info("%s", bts_scr_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) static void skip_change_remote_baud(unsigned char **ptr, long *len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	unsigned char *nxt_action, *cur_action;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	cur_action = *ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	nxt_action = cur_action + sizeof(struct bts_action) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		((struct bts_action *) cur_action)->size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	if (((struct bts_action *) nxt_action)->type != ACTION_WAIT_EVENT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		pr_err("invalid action after change remote baud command");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		*ptr = *ptr + sizeof(struct bts_action) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 			((struct bts_action *)cur_action)->size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		*len = *len - (sizeof(struct bts_action) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 				((struct bts_action *)cur_action)->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		/* warn user on not commenting these in firmware */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		pr_warn("skipping the wait event of change remote baud");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)  * download_firmware -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)  *	internal function which parses through the .bts firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)  *	script file intreprets SEND, DELAY actions only as of now
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) static long download_firmware(struct kim_data_s *kim_gdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	long err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	long len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	unsigned char *ptr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	unsigned char *action_ptr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	unsigned char bts_scr_name[40] = { 0 };	/* 40 char long bts scr name? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	int wr_room_space;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	int cmd_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	unsigned long timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	err = read_local_version(kim_gdata, bts_scr_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	if (err != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		pr_err("kim: failed to read local ver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	err =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	    request_firmware(&kim_gdata->fw_entry, bts_scr_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 			     &kim_gdata->kim_pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	if (unlikely((err != 0) || (kim_gdata->fw_entry->data == NULL) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		     (kim_gdata->fw_entry->size == 0))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		pr_err(" request_firmware failed(errno %ld) for %s", err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 			   bts_scr_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	ptr = (void *)kim_gdata->fw_entry->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	len = kim_gdata->fw_entry->size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	 * bts_header to remove out magic number and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	 * version
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	ptr += sizeof(struct bts_header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	len -= sizeof(struct bts_header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	while (len > 0 && ptr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		pr_debug(" action size %d, type %d ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 			   ((struct bts_action *)ptr)->size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 			   ((struct bts_action *)ptr)->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		switch (((struct bts_action *)ptr)->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 		case ACTION_SEND_COMMAND:	/* action send */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 			pr_debug("S");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 			action_ptr = &(((struct bts_action *)ptr)->data[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 			if (unlikely
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 			    (((struct hci_command *)action_ptr)->opcode ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 			     0xFF36)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 				/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 				 * ignore remote change
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 				 * baud rate HCI VS command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 				pr_warn("change remote baud"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 				    " rate command in firmware");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 				skip_change_remote_baud(&ptr, &len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 			 * Make sure we have enough free space in uart
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 			 * tx buffer to write current firmware command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 			cmd_size = ((struct bts_action *)ptr)->size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 			timeout = jiffies + msecs_to_jiffies(CMD_WR_TIME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 			do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 				wr_room_space =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 					st_get_uart_wr_room(kim_gdata->core_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 				if (wr_room_space < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 					pr_err("Unable to get free "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 							"space info from uart tx buffer");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 					release_firmware(kim_gdata->fw_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 					return wr_room_space;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 				mdelay(1); /* wait 1ms before checking room */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 			} while ((wr_room_space < cmd_size) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 					time_before(jiffies, timeout));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 			/* Timeout happened ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 			if (time_after_eq(jiffies, timeout)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 				pr_err("Timeout while waiting for free "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 						"free space in uart tx buffer");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 				release_firmware(kim_gdata->fw_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 				return -ETIMEDOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 			 * reinit completion before sending for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 			 * relevant wait
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 			reinit_completion(&kim_gdata->kim_rcvd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 			 * Free space found in uart buffer, call st_int_write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 			 * to send current firmware command to the uart tx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 			 * buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 			err = st_int_write(kim_gdata->core_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 			((struct bts_action_send *)action_ptr)->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 					   ((struct bts_action *)ptr)->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 			if (unlikely(err < 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 				release_firmware(kim_gdata->fw_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 				return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 			 * Check number of bytes written to the uart tx buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 			 * and requested command write size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 			if (err != cmd_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 				pr_err("Number of bytes written to uart "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 						"tx buffer are not matching with "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 						"requested cmd write size");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 				release_firmware(kim_gdata->fw_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 				return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 		case ACTION_WAIT_EVENT:  /* wait */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 			pr_debug("W");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 			err = wait_for_completion_interruptible_timeout(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 					&kim_gdata->kim_rcvd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 					msecs_to_jiffies(CMD_RESP_TIME));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 			if (err <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 				pr_err("response timeout/signaled during fw download ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 				/* timed out */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 				release_firmware(kim_gdata->fw_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 				return err ? -ERESTARTSYS : -ETIMEDOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 			reinit_completion(&kim_gdata->kim_rcvd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 		case ACTION_DELAY:	/* sleep */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 			pr_info("sleep command in scr");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 			action_ptr = &(((struct bts_action *)ptr)->data[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 			mdelay(((struct bts_action_delay *)action_ptr)->msec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 		len =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 		    len - (sizeof(struct bts_action) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 			   ((struct bts_action *)ptr)->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 		ptr =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 		    ptr + sizeof(struct bts_action) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 		    ((struct bts_action *)ptr)->size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	/* fw download complete */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	release_firmware(kim_gdata->fw_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) /**********************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) /* functions called from ST core */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) /* called from ST Core, when REG_IN_PROGRESS (registration in progress)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)  * can be because of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)  * 1. response to read local version
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)  * 2. during send/recv's of firmware download
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) void st_kim_recv(void *disc_data, const unsigned char *data, long count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	struct st_data_s	*st_gdata = (struct st_data_s *)disc_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	struct kim_data_s	*kim_gdata = st_gdata->kim_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	 * proceed to gather all data and distinguish read fw version response
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	 * from other fw responses when data gathering is complete
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	kim_int_recv(kim_gdata, data, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)  * to signal completion of line discipline installation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442)  * called from ST Core, upon tty_open
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) void st_kim_complete(void *kim_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	struct kim_data_s	*kim_gdata = (struct kim_data_s *)kim_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	complete(&kim_gdata->ldisc_installed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)  * st_kim_start - called from ST Core upon 1st registration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452)  *	This involves toggling the chip enable gpio, reading
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)  *	the firmware version from chip, forming the fw file name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)  *	based on the chip version, requesting the fw, parsing it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)  *	and perform download(send/recv).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) long st_kim_start(void *kim_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	long err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	long retry = POR_RETRY_COUNT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	struct ti_st_plat_data	*pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	struct kim_data_s	*kim_gdata = (struct kim_data_s *)kim_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	pr_info(" %s", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	pdata = kim_gdata->kim_pdev->dev.platform_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 		/* platform specific enabling code here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 		if (pdata->chip_enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 			pdata->chip_enable(kim_gdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 		/* Configure BT nShutdown to HIGH state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 		gpio_set_value_cansleep(kim_gdata->nshutdown, GPIO_LOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 		mdelay(5);	/* FIXME: a proper toggle */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 		gpio_set_value_cansleep(kim_gdata->nshutdown, GPIO_HIGH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 		mdelay(100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 		/* re-initialize the completion */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 		reinit_completion(&kim_gdata->ldisc_installed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 		/* send notification to UIM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 		kim_gdata->ldisc_install = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 		pr_info("ldisc_install = 1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 		sysfs_notify(&kim_gdata->kim_pdev->dev.kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 				NULL, "install");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 		/* wait for ldisc to be installed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 		err = wait_for_completion_interruptible_timeout(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 			&kim_gdata->ldisc_installed, msecs_to_jiffies(LDISC_TIME));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 		if (!err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 			 * ldisc installation timeout,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 			 * flush uart, power cycle BT_EN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 			pr_err("ldisc installation timeout");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 			err = st_kim_stop(kim_gdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 			/* ldisc installed now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 			pr_info("line discipline installed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 			err = download_firmware(kim_gdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 			if (err != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 				/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 				 * ldisc installed but fw download failed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 				 * flush uart & power cycle BT_EN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 				pr_err("download firmware failed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 				err = st_kim_stop(kim_gdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 			} else {	/* on success don't retry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 	} while (retry--);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516)  * st_kim_stop - stop communication with chip.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517)  *	This can be called from ST Core/KIM, on the-
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518)  *	(a) last un-register when chip need not be powered there-after,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519)  *	(b) upon failure to either install ldisc or download firmware.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520)  *	The function is responsible to (a) notify UIM about un-installation,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521)  *	(b) flush UART if the ldisc was installed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522)  *	(c) reset BT_EN - pull down nshutdown at the end.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523)  *	(d) invoke platform's chip disabling routine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) long st_kim_stop(void *kim_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 	long err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 	struct kim_data_s	*kim_gdata = (struct kim_data_s *)kim_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 	struct ti_st_plat_data	*pdata =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 		kim_gdata->kim_pdev->dev.platform_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 	struct tty_struct	*tty = kim_gdata->core_data->tty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 	reinit_completion(&kim_gdata->ldisc_installed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	if (tty) {	/* can be called before ldisc is installed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 		/* Flush any pending characters in the driver and discipline. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 		tty_ldisc_flush(tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 		tty_driver_flush_buffer(tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 	/* send uninstall notification to UIM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 	pr_info("ldisc_install = 0");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 	kim_gdata->ldisc_install = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 	sysfs_notify(&kim_gdata->kim_pdev->dev.kobj, NULL, "install");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 	/* wait for ldisc to be un-installed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 	err = wait_for_completion_interruptible_timeout(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 		&kim_gdata->ldisc_installed, msecs_to_jiffies(LDISC_TIME));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 	if (!err) {		/* timeout */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 		pr_err(" timed out waiting for ldisc to be un-installed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 		err = -ETIMEDOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 	/* By default configure BT nShutdown to LOW state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 	gpio_set_value_cansleep(kim_gdata->nshutdown, GPIO_LOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	mdelay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 	gpio_set_value_cansleep(kim_gdata->nshutdown, GPIO_HIGH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 	mdelay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 	gpio_set_value_cansleep(kim_gdata->nshutdown, GPIO_LOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 	/* platform specific disable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 	if (pdata->chip_disable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 		pdata->chip_disable(kim_gdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) /**********************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) /* functions called from subsystems */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) /* called when debugfs entry is read from */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) static int version_show(struct seq_file *s, void *unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 	struct kim_data_s *kim_gdata = (struct kim_data_s *)s->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 	seq_printf(s, "%04X %d.%d.%d\n", kim_gdata->version.full,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 			kim_gdata->version.chip, kim_gdata->version.maj_ver,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 			kim_gdata->version.min_ver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) static int list_show(struct seq_file *s, void *unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 	struct kim_data_s *kim_gdata = (struct kim_data_s *)s->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 	kim_st_list_protocols(kim_gdata->core_data, s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) static ssize_t show_install(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 		struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 	struct kim_data_s *kim_data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 	return sprintf(buf, "%d\n", kim_data->ldisc_install);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) #ifdef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) static ssize_t store_dev_name(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 		struct device_attribute *attr, const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 	struct kim_data_s *kim_data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 	pr_debug("storing dev name >%s<", buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 	strncpy(kim_data->dev_name, buf, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 	pr_debug("stored dev name >%s<", kim_data->dev_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) static ssize_t store_baud_rate(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 		struct device_attribute *attr, const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 	struct kim_data_s *kim_data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 	pr_debug("storing baud rate >%s<", buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 	sscanf(buf, "%ld", &kim_data->baud_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 	pr_debug("stored baud rate >%ld<", kim_data->baud_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) #endif	/* if DEBUG */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) static ssize_t show_dev_name(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 		struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 	struct kim_data_s *kim_data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 	return sprintf(buf, "%s\n", kim_data->dev_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) static ssize_t show_baud_rate(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 		struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 	struct kim_data_s *kim_data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 	return sprintf(buf, "%d\n", kim_data->baud_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) static ssize_t show_flow_cntrl(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 		struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 	struct kim_data_s *kim_data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 	return sprintf(buf, "%d\n", kim_data->flow_cntrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) /* structures specific for sysfs entries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) static struct kobj_attribute ldisc_install =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) __ATTR(install, 0444, (void *)show_install, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) static struct kobj_attribute uart_dev_name =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) #ifdef DEBUG	/* TODO: move this to debug-fs if possible */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) __ATTR(dev_name, 0644, (void *)show_dev_name, (void *)store_dev_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) __ATTR(dev_name, 0444, (void *)show_dev_name, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) static struct kobj_attribute uart_baud_rate =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) #ifdef DEBUG	/* TODO: move to debugfs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) __ATTR(baud_rate, 0644, (void *)show_baud_rate, (void *)store_baud_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) __ATTR(baud_rate, 0444, (void *)show_baud_rate, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) static struct kobj_attribute uart_flow_cntrl =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) __ATTR(flow_cntrl, 0444, (void *)show_flow_cntrl, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) static struct attribute *uim_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 	&ldisc_install.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 	&uart_dev_name.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 	&uart_baud_rate.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 	&uart_flow_cntrl.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) static const struct attribute_group uim_attr_grp = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 	.attrs = uim_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671)  * st_kim_ref - reference the core's data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672)  *	This references the per-ST platform device in the arch/xx/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673)  *	board-xx.c file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674)  *	This would enable multiple such platform devices to exist
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675)  *	on a given platform
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) void st_kim_ref(struct st_data_s **core_data, int id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 	struct platform_device	*pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 	struct kim_data_s	*kim_gdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 	/* get kim_gdata reference from platform device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 	pdev = st_get_plat_device(id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 	if (!pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 	kim_gdata = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 	if (!kim_gdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 	*core_data = kim_gdata->core_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 	*core_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) DEFINE_SHOW_ATTRIBUTE(version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) DEFINE_SHOW_ATTRIBUTE(list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) /**********************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) /* functions called from platform device driver subsystem
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700)  * need to have a relevant platform device entry in the platform's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701)  * board-*.c file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) static struct dentry *kim_debugfs_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) static int kim_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 	struct kim_data_s	*kim_gdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) 	struct ti_st_plat_data	*pdata = pdev->dev.platform_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) 	if ((pdev->id != -1) && (pdev->id < MAX_ST_DEVICES)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 		/* multiple devices could exist */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 		st_kim_devices[pdev->id] = pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) 		/* platform's sure about existence of 1 device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) 		st_kim_devices[0] = pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) 	kim_gdata = kzalloc(sizeof(struct kim_data_s), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) 	if (!kim_gdata) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) 		pr_err("no mem to allocate");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) 	platform_set_drvdata(pdev, kim_gdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) 	err = st_core_init(&kim_gdata->core_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) 	if (err != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) 		pr_err(" ST core init failed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) 		err = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) 		goto err_core_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) 	/* refer to itself */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) 	kim_gdata->core_data->kim_data = kim_gdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) 	/* Claim the chip enable nShutdown gpio from the system */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) 	kim_gdata->nshutdown = pdata->nshutdown_gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) 	err = gpio_request(kim_gdata->nshutdown, "kim");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) 	if (unlikely(err)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) 		pr_err(" gpio %d request failed ", kim_gdata->nshutdown);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) 		goto err_sysfs_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) 	/* Configure nShutdown GPIO as output=0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) 	err = gpio_direction_output(kim_gdata->nshutdown, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) 	if (unlikely(err)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) 		pr_err(" unable to configure gpio %d", kim_gdata->nshutdown);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) 		goto err_sysfs_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) 	/* get reference of pdev for request_firmware */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) 	kim_gdata->kim_pdev = pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) 	init_completion(&kim_gdata->kim_rcvd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) 	init_completion(&kim_gdata->ldisc_installed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) 	err = sysfs_create_group(&pdev->dev.kobj, &uim_attr_grp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) 		pr_err("failed to create sysfs entries");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) 		goto err_sysfs_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) 	/* copying platform data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) 	strncpy(kim_gdata->dev_name, pdata->dev_name, UART_DEV_NAME_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) 	kim_gdata->flow_cntrl = pdata->flow_cntrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) 	kim_gdata->baud_rate = pdata->baud_rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) 	pr_info("sysfs entries created\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) 	kim_debugfs_dir = debugfs_create_dir("ti-st", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) 	debugfs_create_file("version", S_IRUGO, kim_debugfs_dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) 				kim_gdata, &version_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) 	debugfs_create_file("protocols", S_IRUGO, kim_debugfs_dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) 				kim_gdata, &list_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) err_sysfs_group:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) 	st_core_exit(kim_gdata->core_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) err_core_init:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) 	kfree(kim_gdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) static int kim_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) 	/* free the GPIOs requested */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) 	struct ti_st_plat_data	*pdata = pdev->dev.platform_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) 	struct kim_data_s	*kim_gdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) 	kim_gdata = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) 	 * Free the Bluetooth/FM/GPIO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) 	 * nShutdown gpio from the system
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) 	gpio_free(pdata->nshutdown_gpio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) 	pr_info("nshutdown GPIO Freed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) 	debugfs_remove_recursive(kim_debugfs_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) 	sysfs_remove_group(&pdev->dev.kobj, &uim_attr_grp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) 	pr_info("sysfs entries removed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) 	kim_gdata->kim_pdev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) 	st_core_exit(kim_gdata->core_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) 	kfree(kim_gdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) 	kim_gdata = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) static int kim_suspend(struct platform_device *pdev, pm_message_t state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) 	struct ti_st_plat_data	*pdata = pdev->dev.platform_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) 	if (pdata->suspend)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) 		return pdata->suspend(pdev, state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) static int kim_resume(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) 	struct ti_st_plat_data	*pdata = pdev->dev.platform_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) 	if (pdata->resume)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) 		return pdata->resume(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) /**********************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) /* entry point for ST KIM module, called in from ST Core */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) static struct platform_driver kim_platform_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) 	.probe = kim_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) 	.remove = kim_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) 	.suspend = kim_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) 	.resume = kim_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) 		.name = "kim",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) module_platform_driver(kim_platform_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) MODULE_AUTHOR("Pavan Savoy <pavan_savoy@ti.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) MODULE_DESCRIPTION("Shared Transport Driver for TI BT/FM/GPS combo chips ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) MODULE_LICENSE("GPL");