hc
2024-01-04 1543e317f1da31b75942316931e8f491a8920811
kernel/drivers/misc/ti-st/st_kim.c
....@@ -1,23 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Shared Transport Line discipline driver Core
34 * Init Manager module responsible for GPIO control
45 * and firmware download
56 * Copyright (C) 2009-2010 Texas Instruments
67 * Author: Pavan Savoy <pavan_savoy@ti.com>
7
- *
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.
11
- *
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.
16
- *
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
20
- *
218 */
229
2310 #define pr_fmt(fmt) "(stk) :" fmt
....@@ -43,7 +30,7 @@
4330 /**********************************************************************/
4431 /* internal functions */
4532
46
-/**
33
+/*
4734 * st_get_plat_device -
4835 * function which returns the reference to the platform device
4936 * requested by id. As of now only 1 such device exists (id=0)
....@@ -56,7 +43,7 @@
5643 return st_kim_devices[id];
5744 }
5845
59
-/**
46
+/*
6047 * validate_firmware_response -
6148 * function to return whether the firmware response was proper
6249 * in case of error don't complete so that waiting for proper
....@@ -68,7 +55,8 @@
6855 if (!skb)
6956 return;
7057
71
- /* these magic numbers are the position in the response buffer which
58
+ /*
59
+ * these magic numbers are the position in the response buffer which
7260 * allows us to distinguish whether the response is for the read
7361 * version info. command
7462 */
....@@ -92,7 +80,8 @@
9280 kfree_skb(skb);
9381 }
9482
95
-/* check for data len received inside kim_int_recv
83
+/*
84
+ * check for data len received inside kim_int_recv
9685 * most often hit the last case to update state to waiting for data
9786 */
9887 static inline int kim_check_data_len(struct kim_data_s *kim_gdata, int len)
....@@ -104,14 +93,16 @@
10493 if (!len) {
10594 validate_firmware_response(kim_gdata);
10695 } else if (len > room) {
107
- /* Received packet's payload length is larger.
96
+ /*
97
+ * Received packet's payload length is larger.
10898 * We can't accommodate it in created skb.
10999 */
110100 pr_err("Data length is too large len %d room %d", len,
111101 room);
112102 kfree_skb(kim_gdata->rx_skb);
113103 } else {
114
- /* Packet header has non-zero payload length and
104
+ /*
105
+ * Packet header has non-zero payload length and
115106 * we have enough space in created skb. Lets read
116107 * payload data */
117108 kim_gdata->rx_state = ST_W4_DATA;
....@@ -119,8 +110,10 @@
119110 return len;
120111 }
121112
122
- /* Change ST LL state to continue to process next
123
- * packet */
113
+ /*
114
+ * Change ST LL state to continue to process next
115
+ * packet
116
+ */
124117 kim_gdata->rx_state = ST_W4_PACKET_TYPE;
125118 kim_gdata->rx_skb = NULL;
126119 kim_gdata->rx_count = 0;
....@@ -128,7 +121,7 @@
128121 return 0;
129122 }
130123
131
-/**
124
+/*
132125 * kim_int_recv - receive function called during firmware download
133126 * firmware download responses on different UART drivers
134127 * have been observed to come in bursts of different
....@@ -211,7 +204,7 @@
211204 static long read_local_version(struct kim_data_s *kim_gdata, char *bts_scr_name)
212205 {
213206 unsigned short version = 0, chip = 0, min_ver = 0, maj_ver = 0;
214
- const char read_ver_cmd[] = { 0x01, 0x01, 0x10, 0x00 };
207
+ static const char read_ver_cmd[] = { 0x01, 0x01, 0x10, 0x00 };
215208 long timeout;
216209
217210 pr_debug("%s", __func__);
....@@ -229,7 +222,8 @@
229222 return timeout ? -ERESTARTSYS : -ETIMEDOUT;
230223 }
231224 reinit_completion(&kim_gdata->kim_rcvd);
232
- /* the positions 12 & 13 in the response buffer provide with the
225
+ /*
226
+ * the positions 12 & 13 in the response buffer provide with the
233227 * chip, major & minor numbers
234228 */
235229
....@@ -276,7 +270,7 @@
276270 }
277271 }
278272
279
-/**
273
+/*
280274 * download_firmware -
281275 * internal function which parses through the .bts firmware
282276 * script file intreprets SEND, DELAY actions only as of now
....@@ -308,7 +302,8 @@
308302 }
309303 ptr = (void *)kim_gdata->fw_entry->data;
310304 len = kim_gdata->fw_entry->size;
311
- /* bts_header to remove out magic number and
305
+ /*
306
+ * bts_header to remove out magic number and
312307 * version
313308 */
314309 ptr += sizeof(struct bts_header);
....@@ -326,8 +321,10 @@
326321 if (unlikely
327322 (((struct hci_command *)action_ptr)->opcode ==
328323 0xFF36)) {
329
- /* ignore remote change
330
- * baud rate HCI VS command */
324
+ /*
325
+ * ignore remote change
326
+ * baud rate HCI VS command
327
+ */
331328 pr_warn("change remote baud"
332329 " rate command in firmware");
333330 skip_change_remote_baud(&ptr, &len);
....@@ -359,7 +356,8 @@
359356 release_firmware(kim_gdata->fw_entry);
360357 return -ETIMEDOUT;
361358 }
362
- /* reinit completion before sending for the
359
+ /*
360
+ * reinit completion before sending for the
363361 * relevant wait
364362 */
365363 reinit_completion(&kim_gdata->kim_rcvd);
....@@ -431,14 +429,16 @@
431429 struct st_data_s *st_gdata = (struct st_data_s *)disc_data;
432430 struct kim_data_s *kim_gdata = st_gdata->kim_data;
433431
434
- /* proceed to gather all data and distinguish read fw version response
432
+ /*
433
+ * proceed to gather all data and distinguish read fw version response
435434 * from other fw responses when data gathering is complete
436435 */
437436 kim_int_recv(kim_gdata, data, count);
438437 return;
439438 }
440439
441
-/* to signal completion of line discipline installation
440
+/*
441
+ * to signal completion of line discipline installation
442442 * called from ST Core, upon tty_open
443443 */
444444 void st_kim_complete(void *kim_data)
....@@ -447,7 +447,7 @@
447447 complete(&kim_gdata->ldisc_installed);
448448 }
449449
450
-/**
450
+/*
451451 * st_kim_start - called from ST Core upon 1st registration
452452 * This involves toggling the chip enable gpio, reading
453453 * the firmware version from chip, forming the fw file name
....@@ -485,8 +485,10 @@
485485 err = wait_for_completion_interruptible_timeout(
486486 &kim_gdata->ldisc_installed, msecs_to_jiffies(LDISC_TIME));
487487 if (!err) {
488
- /* ldisc installation timeout,
489
- * flush uart, power cycle BT_EN */
488
+ /*
489
+ * ldisc installation timeout,
490
+ * flush uart, power cycle BT_EN
491
+ */
490492 pr_err("ldisc installation timeout");
491493 err = st_kim_stop(kim_gdata);
492494 continue;
....@@ -495,8 +497,10 @@
495497 pr_info("line discipline installed");
496498 err = download_firmware(kim_gdata);
497499 if (err != 0) {
498
- /* ldisc installed but fw download failed,
499
- * flush uart & power cycle BT_EN */
500
+ /*
501
+ * ldisc installed but fw download failed,
502
+ * flush uart & power cycle BT_EN
503
+ */
500504 pr_err("download firmware failed");
501505 err = st_kim_stop(kim_gdata);
502506 continue;
....@@ -508,7 +512,7 @@
508512 return err;
509513 }
510514
511
-/**
515
+/*
512516 * st_kim_stop - stop communication with chip.
513517 * This can be called from ST Core/KIM, on the-
514518 * (a) last un-register when chip need not be powered there-after,
....@@ -564,7 +568,7 @@
564568 /* functions called from subsystems */
565569 /* called when debugfs entry is read from */
566570
567
-static int show_version(struct seq_file *s, void *unused)
571
+static int version_show(struct seq_file *s, void *unused)
568572 {
569573 struct kim_data_s *kim_gdata = (struct kim_data_s *)s->private;
570574 seq_printf(s, "%04X %d.%d.%d\n", kim_gdata->version.full,
....@@ -573,7 +577,7 @@
573577 return 0;
574578 }
575579
576
-static int show_list(struct seq_file *s, void *unused)
580
+static int list_show(struct seq_file *s, void *unused)
577581 {
578582 struct kim_data_s *kim_gdata = (struct kim_data_s *)s->private;
579583 kim_st_list_protocols(kim_gdata->core_data, s);
....@@ -663,7 +667,7 @@
663667 .attrs = uim_attrs,
664668 };
665669
666
-/**
670
+/*
667671 * st_kim_ref - reference the core's data
668672 * This references the per-ST platform device in the arch/xx/
669673 * board-xx.c file.
....@@ -688,30 +692,8 @@
688692 *core_data = NULL;
689693 }
690694
691
-static int kim_version_open(struct inode *i, struct file *f)
692
-{
693
- return single_open(f, show_version, i->i_private);
694
-}
695
-
696
-static int kim_list_open(struct inode *i, struct file *f)
697
-{
698
- return single_open(f, show_list, i->i_private);
699
-}
700
-
701
-static const struct file_operations version_debugfs_fops = {
702
- /* version info */
703
- .open = kim_version_open,
704
- .read = seq_read,
705
- .llseek = seq_lseek,
706
- .release = single_release,
707
-};
708
-static const struct file_operations list_debugfs_fops = {
709
- /* protocols info */
710
- .open = kim_list_open,
711
- .read = seq_read,
712
- .llseek = seq_lseek,
713
- .release = single_release,
714
-};
695
+DEFINE_SHOW_ATTRIBUTE(version);
696
+DEFINE_SHOW_ATTRIBUTE(list);
715697
716698 /**********************************************************************/
717699 /* functions called from platform device driver subsystem
....@@ -764,8 +746,7 @@
764746 pr_err(" unable to configure gpio %d", kim_gdata->nshutdown);
765747 goto err_sysfs_group;
766748 }
767
- /* get reference of pdev for request_firmware
768
- */
749
+ /* get reference of pdev for request_firmware */
769750 kim_gdata->kim_pdev = pdev;
770751 init_completion(&kim_gdata->kim_rcvd);
771752 init_completion(&kim_gdata->ldisc_installed);
....@@ -783,15 +764,11 @@
783764 pr_info("sysfs entries created\n");
784765
785766 kim_debugfs_dir = debugfs_create_dir("ti-st", NULL);
786
- if (!kim_debugfs_dir) {
787
- pr_err(" debugfs entries creation failed ");
788
- return 0;
789
- }
790767
791768 debugfs_create_file("version", S_IRUGO, kim_debugfs_dir,
792
- kim_gdata, &version_debugfs_fops);
769
+ kim_gdata, &version_fops);
793770 debugfs_create_file("protocols", S_IRUGO, kim_debugfs_dir,
794
- kim_gdata, &list_debugfs_fops);
771
+ kim_gdata, &list_fops);
795772 return 0;
796773
797774 err_sysfs_group:
....@@ -811,7 +788,8 @@
811788
812789 kim_gdata = platform_get_drvdata(pdev);
813790
814
- /* Free the Bluetooth/FM/GPIO
791
+ /*
792
+ * Free the Bluetooth/FM/GPIO
815793 * nShutdown gpio from the system
816794 */
817795 gpio_free(pdata->nshutdown_gpio);