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
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/debugfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/usb/ch9.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/usb/gadget.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/usb/phy.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/usb/otg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/usb/otg-fsm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/usb/chipidea.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include "ci.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include "udc.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include "bits.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include "otg.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  * ci_device_show: prints information about device capabilities and status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) static int ci_device_show(struct seq_file *s, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	struct ci_hdrc *ci = s->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	struct usb_gadget *gadget = &ci->gadget;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	seq_printf(s, "speed             = %d\n", gadget->speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	seq_printf(s, "max_speed         = %d\n", gadget->max_speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	seq_printf(s, "is_otg            = %d\n", gadget->is_otg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	seq_printf(s, "is_a_peripheral   = %d\n", gadget->is_a_peripheral);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	seq_printf(s, "b_hnp_enable      = %d\n", gadget->b_hnp_enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	seq_printf(s, "a_hnp_support     = %d\n", gadget->a_hnp_support);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	seq_printf(s, "a_alt_hnp_support = %d\n", gadget->a_alt_hnp_support);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	seq_printf(s, "name              = %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 		   (gadget->name ? gadget->name : ""));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	if (!ci->driver)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	seq_printf(s, "gadget function   = %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		       (ci->driver->function ? ci->driver->function : ""));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	seq_printf(s, "gadget max speed  = %d\n", ci->driver->max_speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) DEFINE_SHOW_ATTRIBUTE(ci_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  * ci_port_test_show: reads port test mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) static int ci_port_test_show(struct seq_file *s, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	struct ci_hdrc *ci = s->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	unsigned mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	pm_runtime_get_sync(ci->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	spin_lock_irqsave(&ci->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	mode = hw_port_test_get(ci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	spin_unlock_irqrestore(&ci->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	pm_runtime_put_sync(ci->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	seq_printf(s, "mode = %u\n", mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71)  * ci_port_test_write: writes port test mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) static ssize_t ci_port_test_write(struct file *file, const char __user *ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 				  size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	struct seq_file *s = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	struct ci_hdrc *ci = s->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	unsigned mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	char buf[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	count = min_t(size_t, sizeof(buf) - 1, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	if (copy_from_user(buf, ubuf, count))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	/* sscanf requires a zero terminated string */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	buf[count] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	if (sscanf(buf, "%u", &mode) != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	if (mode > 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		return -EBADRQC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	pm_runtime_get_sync(ci->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	spin_lock_irqsave(&ci->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	ret = hw_port_test_set(ci, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	spin_unlock_irqrestore(&ci->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	pm_runtime_put_sync(ci->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	return ret ? ret : count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) static int ci_port_test_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	return single_open(file, ci_port_test_show, inode->i_private);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) static const struct file_operations ci_port_test_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	.open		= ci_port_test_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	.write		= ci_port_test_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	.read		= seq_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	.llseek		= seq_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	.release	= single_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)  * ci_qheads_show: DMA contents of all queue heads
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) static int ci_qheads_show(struct seq_file *s, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	struct ci_hdrc *ci = s->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	unsigned i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	if (ci->role != CI_ROLE_GADGET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		seq_printf(s, "not in gadget mode\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	spin_lock_irqsave(&ci->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	for (i = 0; i < ci->hw_ep_max/2; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		struct ci_hw_ep *hweprx = &ci->ci_hw_ep[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		struct ci_hw_ep *hweptx =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 			&ci->ci_hw_ep[i + ci->hw_ep_max/2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		seq_printf(s, "EP=%02i: RX=%08X TX=%08X\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 			   i, (u32)hweprx->qh.dma, (u32)hweptx->qh.dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		for (j = 0; j < (sizeof(struct ci_hw_qh)/sizeof(u32)); j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 			seq_printf(s, " %04X:    %08X    %08X\n", j,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 				   *((u32 *)hweprx->qh.ptr + j),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 				   *((u32 *)hweptx->qh.ptr + j));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	spin_unlock_irqrestore(&ci->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) DEFINE_SHOW_ATTRIBUTE(ci_qheads);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)  * ci_requests_show: DMA contents of all requests currently queued (all endpts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) static int ci_requests_show(struct seq_file *s, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	struct ci_hdrc *ci = s->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	struct ci_hw_req *req = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	struct td_node *node, *tmpnode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	unsigned i, j, qsize = sizeof(struct ci_hw_td)/sizeof(u32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	if (ci->role != CI_ROLE_GADGET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		seq_printf(s, "not in gadget mode\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	spin_lock_irqsave(&ci->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	for (i = 0; i < ci->hw_ep_max; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		list_for_each_entry(req, &ci->ci_hw_ep[i].qh.queue, queue) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 			list_for_each_entry_safe(node, tmpnode, &req->tds, td) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 				seq_printf(s, "EP=%02i: TD=%08X %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 					   i % (ci->hw_ep_max / 2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 					   (u32)node->dma,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 					   ((i < ci->hw_ep_max/2) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 					   "RX" : "TX"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 				for (j = 0; j < qsize; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 					seq_printf(s, " %04X:    %08X\n", j,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 						   *((u32 *)node->ptr + j));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	spin_unlock_irqrestore(&ci->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) DEFINE_SHOW_ATTRIBUTE(ci_requests);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) static int ci_otg_show(struct seq_file *s, void *unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	struct ci_hdrc *ci = s->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	struct otg_fsm *fsm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	if (!ci || !ci_otg_is_fsm_mode(ci))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	fsm = &ci->fsm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	/* ------ State ----- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	seq_printf(s, "OTG state: %s\n\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 			usb_otg_state_string(ci->otg.state));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	/* ------ State Machine Variables ----- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	seq_printf(s, "a_bus_drop: %d\n", fsm->a_bus_drop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	seq_printf(s, "a_bus_req: %d\n", fsm->a_bus_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	seq_printf(s, "a_srp_det: %d\n", fsm->a_srp_det);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	seq_printf(s, "a_vbus_vld: %d\n", fsm->a_vbus_vld);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	seq_printf(s, "b_conn: %d\n", fsm->b_conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	seq_printf(s, "adp_change: %d\n", fsm->adp_change);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	seq_printf(s, "power_up: %d\n", fsm->power_up);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	seq_printf(s, "a_bus_resume: %d\n", fsm->a_bus_resume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	seq_printf(s, "a_bus_suspend: %d\n", fsm->a_bus_suspend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	seq_printf(s, "a_conn: %d\n", fsm->a_conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	seq_printf(s, "b_bus_req: %d\n", fsm->b_bus_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	seq_printf(s, "b_bus_suspend: %d\n", fsm->b_bus_suspend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	seq_printf(s, "b_se0_srp: %d\n", fsm->b_se0_srp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	seq_printf(s, "b_ssend_srp: %d\n", fsm->b_ssend_srp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	seq_printf(s, "b_sess_vld: %d\n", fsm->b_sess_vld);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	seq_printf(s, "b_srp_done: %d\n", fsm->b_srp_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	seq_printf(s, "drv_vbus: %d\n", fsm->drv_vbus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	seq_printf(s, "loc_conn: %d\n", fsm->loc_conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	seq_printf(s, "loc_sof: %d\n", fsm->loc_sof);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	seq_printf(s, "adp_prb: %d\n", fsm->adp_prb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	seq_printf(s, "id: %d\n", fsm->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	seq_printf(s, "protocol: %d\n", fsm->protocol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) DEFINE_SHOW_ATTRIBUTE(ci_otg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) static int ci_role_show(struct seq_file *s, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	struct ci_hdrc *ci = s->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	if (ci->role != CI_ROLE_END)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		seq_printf(s, "%s\n", ci_role(ci)->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) static ssize_t ci_role_write(struct file *file, const char __user *ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 			     size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	struct seq_file *s = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	struct ci_hdrc *ci = s->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	enum ci_role role;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	char buf[8];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	if (copy_from_user(buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	for (role = CI_ROLE_HOST; role < CI_ROLE_END; role++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		if (ci->roles[role] &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		    !strncmp(buf, ci->roles[role]->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 			     strlen(ci->roles[role]->name)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	if (role == CI_ROLE_END || role == ci->role)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	pm_runtime_get_sync(ci->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	disable_irq(ci->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	ci_role_stop(ci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	ret = ci_role_start(ci, role);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	enable_irq(ci->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	pm_runtime_put_sync(ci->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	return ret ? ret : count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) static int ci_role_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	return single_open(file, ci_role_show, inode->i_private);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) static const struct file_operations ci_role_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	.open		= ci_role_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	.write		= ci_role_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	.read		= seq_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	.llseek		= seq_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	.release	= single_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) static int ci_registers_show(struct seq_file *s, void *unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	struct ci_hdrc *ci = s->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	u32 tmp_reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	if (!ci || ci->in_lpm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 		return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	/* ------ Registers ----- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	tmp_reg = hw_read_intr_enable(ci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	seq_printf(s, "USBINTR reg: %08x\n", tmp_reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	tmp_reg = hw_read_intr_status(ci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	seq_printf(s, "USBSTS reg: %08x\n", tmp_reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	tmp_reg = hw_read(ci, OP_USBMODE, ~0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	seq_printf(s, "USBMODE reg: %08x\n", tmp_reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	tmp_reg = hw_read(ci, OP_USBCMD, ~0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	seq_printf(s, "USBCMD reg: %08x\n", tmp_reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	tmp_reg = hw_read(ci, OP_PORTSC, ~0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	seq_printf(s, "PORTSC reg: %08x\n", tmp_reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	if (ci->is_otg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 		tmp_reg = hw_read_otgsc(ci, ~0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 		seq_printf(s, "OTGSC reg: %08x\n", tmp_reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) DEFINE_SHOW_ATTRIBUTE(ci_registers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)  * dbg_create_files: initializes the attribute interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)  * @ci: device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)  * This function returns an error code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) void dbg_create_files(struct ci_hdrc *ci)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	ci->debugfs = debugfs_create_dir(dev_name(ci->dev), usb_debug_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	debugfs_create_file("device", S_IRUGO, ci->debugfs, ci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 			    &ci_device_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	debugfs_create_file("port_test", S_IRUGO | S_IWUSR, ci->debugfs, ci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 			    &ci_port_test_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	debugfs_create_file("qheads", S_IRUGO, ci->debugfs, ci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 			    &ci_qheads_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	debugfs_create_file("requests", S_IRUGO, ci->debugfs, ci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 			    &ci_requests_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	if (ci_otg_is_fsm_mode(ci)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 		debugfs_create_file("otg", S_IRUGO, ci->debugfs, ci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 				    &ci_otg_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	debugfs_create_file("role", S_IRUGO | S_IWUSR, ci->debugfs, ci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 			    &ci_role_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	debugfs_create_file("registers", S_IRUGO, ci->debugfs, ci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 			    &ci_registers_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)  * dbg_remove_files: destroys the attribute interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)  * @ci: device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) void dbg_remove_files(struct ci_hdrc *ci)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	debugfs_remove_recursive(ci->debugfs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) }