23 #define pr_fmt(fmt) "(stk) :" fmt
28 #include <linux/wait.h>
32 #include <linux/sched.h>
34 #include <linux/tty.h>
38 #include <linux/module.h>
41 #define MAX_ST_DEVICES 3
57 return st_kim_devices[
id];
66 static void validate_firmware_response(
struct kim_data_s *kim_gdata)
76 if (skb->
data[2] == 0x01 && skb->
data[3] == 0x01 &&
77 skb->
data[4] == 0x10 && skb->
data[5] == 0x00) {
87 pr_err(
"no proper response during fw download");
100 static inline int kim_check_data_len(
struct kim_data_s *kim_gdata,
int len)
102 register int room = skb_tailroom(kim_gdata->
rx_skb);
104 pr_debug(
"len %d room %d", len, room);
107 validate_firmware_response(kim_gdata);
108 }
else if (len > room) {
112 pr_err(
"Data length is too large len %d room %d", len,
139 static void kim_int_recv(
struct kim_data_s *kim_gdata,
142 const unsigned char *
ptr;
143 int len = 0,
type = 0;
150 pr_err(
" received null from TTY ");
170 validate_firmware_response(kim_gdata);
177 (
unsigned char *)&kim_gdata->
rx_skb->data[1];
178 pr_debug(
"event hdr: plen 0x%02x\n", *plen);
179 kim_check_data_len(kim_gdata, *plen);
201 pr_err(
"can't allocate mem for new packet");
206 skb_reserve(kim_gdata->
rx_skb, 8);
207 kim_gdata->
rx_skb->cb[0] = 4;
208 kim_gdata->
rx_skb->cb[1] = 0;
214 static long read_local_version(
struct kim_data_s *kim_gdata,
char *bts_scr_name)
216 unsigned short version = 0,
chip = 0, min_ver = 0, maj_ver = 0;
217 const char read_ver_cmd[] = { 0x01, 0x01, 0x10, 0x00 };
223 pr_err(
"kim: couldn't write 4 bytes");
229 pr_err(
" waiting for ver info- timed out ");
240 chip = (version & 0x7C00) >> 10;
241 min_ver = (version & 0x007F);
242 maj_ver = (version & 0x0380) >> 7;
244 if (version & 0x8000)
247 sprintf(bts_scr_name,
"TIInit_%d.%d.%d.bts",
chip, maj_ver, min_ver);
252 kim_gdata->
version.maj_ver = maj_ver;
253 kim_gdata->
version.min_ver = min_ver;
259 static void skip_change_remote_baud(
unsigned char **ptr,
long *len)
261 unsigned char *nxt_action, *cur_action;
264 nxt_action = cur_action +
sizeof(
struct bts_action) +
268 pr_err(
"invalid action after change remote baud command");
275 pr_warn(
"skipping the wait event of change remote baud");
284 static long download_firmware(
struct kim_data_s *kim_gdata)
288 unsigned char *ptr =
NULL;
289 unsigned char *action_ptr =
NULL;
290 unsigned char bts_scr_name[30] = { 0 };
295 err = read_local_version(kim_gdata, bts_scr_name);
297 pr_err(
"kim: failed to read local ver");
304 (kim_gdata->
fw_entry->size == 0))) {
305 pr_err(
" request_firmware failed(errno %ld) for %s", err,
309 ptr = (
void *)kim_gdata->
fw_entry->data;
317 while (len > 0 && ptr) {
318 pr_debug(
" action size %d, type %d ",
325 action_ptr = &(((
struct bts_action *)ptr)->data[0]);
332 " rate command in firmware");
333 skip_change_remote_baud(&ptr, &len);
345 if (wr_room_space < 0) {
346 pr_err(
"Unable to get free "
347 "space info from uart tx buffer");
349 return wr_room_space;
352 }
while ((wr_room_space < cmd_size) &&
357 pr_err(
"Timeout while waiting for free "
358 "free space in uart tx buffer");
383 if (err != cmd_size) {
384 pr_err(
"Number of bytes written to uart "
385 "tx buffer are not matching with "
386 "requested cmd write size");
394 &kim_gdata->kim_rcvd,
396 pr_err(
"response timeout during fw download ");
404 pr_info(
"sleep command in scr");
405 action_ptr = &(((
struct bts_action *)ptr)->data[0]);
428 void st_kim_recv(
void *disc_data,
const unsigned char *data,
long count)
436 kim_int_recv(kim_gdata, data, count);
464 pdata = kim_gdata->
kim_pdev->dev.platform_data;
484 pr_err(
"ldisc installation timeout");
489 pr_info(
"line discipline installed");
490 err = download_firmware(kim_gdata);
494 pr_err(
"download firmware failed");
519 kim_gdata->
kim_pdev->dev.platform_data;
528 tty->
ops->flush_buffer(tty);
540 pr_err(
" timed out waiting for ldisc to be un-installed");
563 static int show_list(
struct seq_file *s,
void *unused)
582 pr_debug(
"storing dev name >%s<", buf);
592 pr_debug(
"storing baud rate >%s<", buf);
622 __ATTR(install, 0444, (
void *)show_install,
NULL);
626 __ATTR(dev_name, 0644, (
void *)show_dev_name, (
void *)store_dev_name);
628 __ATTR(dev_name, 0444, (
void *)show_dev_name,
NULL);
633 __ATTR(baud_rate, 0644, (
void *)show_baud_rate, (
void *)store_baud_rate);
635 __ATTR(baud_rate, 0444, (
void *)show_baud_rate,
NULL);
639 __ATTR(flow_cntrl, 0444, (
void *)show_flow_cntrl,
NULL);
644 &uart_baud_rate.
attr,
645 &uart_flow_cntrl.
attr,
665 pdev = st_get_plat_device(
id);
674 static int kim_version_open(
struct inode *
i,
struct file *
f)
679 static int kim_list_open(
struct inode *
i,
struct file *
f)
686 .open = kim_version_open,
693 .open = kim_list_open,
705 static struct dentry *kim_debugfs_dir;
714 st_kim_devices[pdev->
id] = pdev;
717 st_kim_devices[0] = pdev;
722 pr_err(
"no mem to allocate");
729 pr_err(
" ST core init failed");
733 kim_gdata->
core_data->kim_data = kim_gdata;
738 init_completion(&kim_gdata->kim_rcvd);
743 pr_err(
"failed to create sysfs entries");
751 pr_info(
"sysfs entries created\n");
754 if (IS_ERR(kim_debugfs_dir)) {
755 pr_err(
" debugfs entries creation failed ");
756 kim_debugfs_dir =
NULL;
761 kim_gdata, &version_debugfs_fops);
763 kim_gdata, &list_debugfs_fops);
764 pr_info(
" debugfs entries created ");
776 pr_info(
"sysfs entries removed");
791 return pdata->
suspend(pdev, state);
801 return pdata->
resume(pdev);
810 .remove = kim_remove,
811 .suspend = kim_suspend,
812 .resume = kim_resume,