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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * mtu3_debugfs.c - debugfs interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2019 MediaTek Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Author: Chunfeng Yun <chunfeng.yun@mediatek.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) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include "mtu3.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include "mtu3_dr.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include "mtu3_debug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #define dump_register(nm)		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) {					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 	.name = __stringify(nm),	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 	.offset = U3D_ ##nm,		\
^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) #define dump_prb_reg(nm, os)	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) {				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	.name = nm,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	.offset = os,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) static const struct debugfs_reg32 mtu3_ippc_regs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	dump_register(SSUSB_IP_PW_CTRL0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	dump_register(SSUSB_IP_PW_CTRL1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	dump_register(SSUSB_IP_PW_CTRL2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	dump_register(SSUSB_IP_PW_CTRL3),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	dump_register(SSUSB_OTG_STS),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	dump_register(SSUSB_IP_XHCI_CAP),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	dump_register(SSUSB_IP_DEV_CAP),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	dump_register(SSUSB_U3_CTRL_0P),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	dump_register(SSUSB_U2_CTRL_0P),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	dump_register(SSUSB_HW_ID),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	dump_register(SSUSB_HW_SUB_ID),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	dump_register(SSUSB_IP_SPARE0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) static const struct debugfs_reg32 mtu3_dev_regs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	dump_register(LV1ISR),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	dump_register(LV1IER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	dump_register(EPISR),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	dump_register(EPIER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	dump_register(EP0CSR),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	dump_register(RXCOUNT0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	dump_register(QISAR0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	dump_register(QIER0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	dump_register(QISAR1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	dump_register(QIER1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	dump_register(CAP_EPNTXFFSZ),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	dump_register(CAP_EPNRXFFSZ),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	dump_register(CAP_EPINFO),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	dump_register(MISC_CTRL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) static const struct debugfs_reg32 mtu3_csr_regs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	dump_register(DEVICE_CONF),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	dump_register(DEV_LINK_INTR_ENABLE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	dump_register(DEV_LINK_INTR),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	dump_register(LTSSM_CTRL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	dump_register(USB3_CONFIG),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	dump_register(LINK_STATE_MACHINE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	dump_register(LTSSM_INTR_ENABLE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	dump_register(LTSSM_INTR),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	dump_register(U3U2_SWITCH_CTRL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	dump_register(POWER_MANAGEMENT),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	dump_register(DEVICE_CONTROL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	dump_register(COMMON_USB_INTR_ENABLE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	dump_register(COMMON_USB_INTR),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	dump_register(USB20_MISC_CONTROL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	dump_register(USB20_OPSTATE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) static int mtu3_link_state_show(struct seq_file *sf, void *unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	struct mtu3 *mtu = sf->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	void __iomem *mbase = mtu->mac_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	seq_printf(sf, "opstate: %#x, ltssm: %#x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		   mtu3_readl(mbase, U3D_USB20_OPSTATE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		   LTSSM_STATE(mtu3_readl(mbase, U3D_LINK_STATE_MACHINE)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) static int mtu3_ep_used_show(struct seq_file *sf, void *unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	struct mtu3 *mtu = sf->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	struct mtu3_ep *mep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	int used = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	spin_lock_irqsave(&mtu->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	for (i = 0; i < mtu->num_eps; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		mep = mtu->in_eps + i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		if (mep->flags & MTU3_EP_ENABLED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 			seq_printf(sf, "%s - type: %d\n", mep->name, mep->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 			used++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		mep = mtu->out_eps + i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		if (mep->flags & MTU3_EP_ENABLED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 			seq_printf(sf, "%s - type: %d\n", mep->name, mep->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 			used++;
^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) 	seq_printf(sf, "total used: %d eps\n", used);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	spin_unlock_irqrestore(&mtu->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) DEFINE_SHOW_ATTRIBUTE(mtu3_link_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) DEFINE_SHOW_ATTRIBUTE(mtu3_ep_used);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) static void mtu3_debugfs_regset(struct mtu3 *mtu, void __iomem *base,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 				const struct debugfs_reg32 *regs, size_t nregs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 				const char *name, struct dentry *parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	struct debugfs_regset32 *regset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	struct mtu3_regset *mregs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	mregs = devm_kzalloc(mtu->dev, sizeof(*mregs), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	if (!mregs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	sprintf(mregs->name, "%s", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	regset = &mregs->regset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	regset->regs = regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	regset->nregs = nregs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	regset->base = base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	debugfs_create_regset32(mregs->name, 0444, parent, regset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) static void mtu3_debugfs_ep_regset(struct mtu3 *mtu, struct mtu3_ep *mep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 				   struct dentry *parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	struct debugfs_reg32 *regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	int epnum = mep->epnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	int in = mep->is_in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	regs = devm_kcalloc(mtu->dev, 7, sizeof(*regs), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	if (!regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	regs[0].name = in ? "TCR0" : "RCR0";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	regs[0].offset = in ? MU3D_EP_TXCR0(epnum) : MU3D_EP_RXCR0(epnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	regs[1].name = in ? "TCR1" : "RCR1";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	regs[1].offset = in ? MU3D_EP_TXCR1(epnum) : MU3D_EP_RXCR1(epnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	regs[2].name = in ? "TCR2" : "RCR2";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	regs[2].offset = in ? MU3D_EP_TXCR2(epnum) : MU3D_EP_RXCR2(epnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	regs[3].name = in ? "TQHIAR" : "RQHIAR";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	regs[3].offset = in ? USB_QMU_TQHIAR(epnum) : USB_QMU_RQHIAR(epnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	regs[4].name = in ? "TQCSR" : "RQCSR";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	regs[4].offset = in ? USB_QMU_TQCSR(epnum) : USB_QMU_RQCSR(epnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	regs[5].name = in ? "TQSAR" : "RQSAR";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	regs[5].offset = in ? USB_QMU_TQSAR(epnum) : USB_QMU_RQSAR(epnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	regs[6].name = in ? "TQCPR" : "RQCPR";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	regs[6].offset = in ? USB_QMU_TQCPR(epnum) : USB_QMU_RQCPR(epnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	mtu3_debugfs_regset(mtu, mtu->mac_base, regs, 7, "ep-regs", parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) static int mtu3_ep_info_show(struct seq_file *sf, void *unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	struct mtu3_ep *mep = sf->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	struct mtu3 *mtu = mep->mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	spin_lock_irqsave(&mtu->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	seq_printf(sf, "ep - type:%d, maxp:%d, slot:%d, flags:%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		   mep->type, mep->maxp, mep->slot, mep->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	spin_unlock_irqrestore(&mtu->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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) static int mtu3_fifo_show(struct seq_file *sf, void *unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	struct mtu3_ep *mep = sf->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	struct mtu3 *mtu = mep->mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	spin_lock_irqsave(&mtu->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	seq_printf(sf, "fifo - seg_size:%d, addr:%d, size:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		   mep->fifo_seg_size, mep->fifo_addr, mep->fifo_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	spin_unlock_irqrestore(&mtu->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) static int mtu3_qmu_ring_show(struct seq_file *sf, void *unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	struct mtu3_ep *mep = sf->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	struct mtu3 *mtu = mep->mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	struct mtu3_gpd_ring *ring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	ring = &mep->gpd_ring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	spin_lock_irqsave(&mtu->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	seq_printf(sf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		   "qmu-ring - dma:%pad, start:%p, end:%p, enq:%p, dep:%p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		   &ring->dma, ring->start, ring->end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		   ring->enqueue, ring->dequeue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	spin_unlock_irqrestore(&mtu->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	return 0;
^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) static int mtu3_qmu_gpd_show(struct seq_file *sf, void *unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	struct mtu3_ep *mep = sf->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	struct mtu3 *mtu = mep->mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	struct mtu3_gpd_ring *ring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	struct qmu_gpd *gpd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	dma_addr_t dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	spin_lock_irqsave(&mtu->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	ring = &mep->gpd_ring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	gpd = ring->start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	if (!gpd || !(mep->flags & MTU3_EP_ENABLED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		seq_puts(sf, "empty!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	for (i = 0; i < MAX_GPD_NUM; i++, gpd++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		dma = ring->dma + i * sizeof(*gpd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		seq_printf(sf, "gpd.%03d -> %pad, %p: %08x %08x %08x %08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 			   i, &dma, gpd, gpd->dw0_info, gpd->next_gpd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 			   gpd->buffer, gpd->dw3_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	spin_unlock_irqrestore(&mtu->lock, flags);
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) static const struct mtu3_file_map mtu3_ep_files[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	{"ep-info", mtu3_ep_info_show, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	{"fifo", mtu3_fifo_show, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	{"qmu-ring", mtu3_qmu_ring_show, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	{"qmu-gpd", mtu3_qmu_gpd_show, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) static int mtu3_ep_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	const char *file_name = file_dentry(file)->d_iname;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	const struct mtu3_file_map *f_map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	for (i = 0; i < ARRAY_SIZE(mtu3_ep_files); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		f_map = &mtu3_ep_files[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		if (strcmp(f_map->name, file_name) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	return single_open(file, f_map->show, inode->i_private);
^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) static const struct file_operations mtu3_ep_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	.open = mtu3_ep_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	.read = seq_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	.llseek = seq_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	.release = single_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) static const struct debugfs_reg32 mtu3_prb_regs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	dump_prb_reg("enable", U3D_SSUSB_PRB_CTRL0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	dump_prb_reg("byte-sell", U3D_SSUSB_PRB_CTRL1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	dump_prb_reg("byte-selh", U3D_SSUSB_PRB_CTRL2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	dump_prb_reg("module-sel", U3D_SSUSB_PRB_CTRL3),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	dump_prb_reg("sw-out", U3D_SSUSB_PRB_CTRL4),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	dump_prb_reg("data", U3D_SSUSB_PRB_CTRL5),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) static int mtu3_probe_show(struct seq_file *sf, void *unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	const char *file_name = file_dentry(sf->file)->d_iname;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	struct mtu3 *mtu = sf->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	const struct debugfs_reg32 *regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	for (i = 0; i < ARRAY_SIZE(mtu3_prb_regs); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		regs = &mtu3_prb_regs[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		if (strcmp(regs->name, file_name) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	seq_printf(sf, "0x%04x - 0x%08x\n", (u32)regs->offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		   mtu3_readl(mtu->ippc_base, (u32)regs->offset));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) static int mtu3_probe_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	return single_open(file, mtu3_probe_show, inode->i_private);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) static ssize_t mtu3_probe_write(struct file *file, const char __user *ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 				size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	const char *file_name = file_dentry(file)->d_iname;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	struct seq_file *sf = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	struct mtu3 *mtu = sf->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	const struct debugfs_reg32 *regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	char buf[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	u32 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	if (kstrtou32(buf, 0, &val))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	for (i = 0; i < ARRAY_SIZE(mtu3_prb_regs); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 		regs = &mtu3_prb_regs[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 		if (strcmp(regs->name, file_name) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	mtu3_writel(mtu->ippc_base, (u32)regs->offset, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) static const struct file_operations mtu3_probe_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	.open = mtu3_probe_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	.write = mtu3_probe_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	.read = seq_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	.llseek = seq_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	.release = single_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) static void mtu3_debugfs_create_prb_files(struct mtu3 *mtu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	struct ssusb_mtk *ssusb = mtu->ssusb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	const struct debugfs_reg32 *regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	struct dentry *dir_prb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	dir_prb = debugfs_create_dir("probe", ssusb->dbgfs_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	for (i = 0; i < ARRAY_SIZE(mtu3_prb_regs); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 		regs = &mtu3_prb_regs[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 		debugfs_create_file(regs->name, 0644, dir_prb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 				    mtu, &mtu3_probe_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	mtu3_debugfs_regset(mtu, mtu->ippc_base, mtu3_prb_regs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 			    ARRAY_SIZE(mtu3_prb_regs), "regs", dir_prb);
^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) static void mtu3_debugfs_create_ep_dir(struct mtu3_ep *mep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 				       struct dentry *parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	const struct mtu3_file_map *files;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	struct dentry *dir_ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	dir_ep = debugfs_create_dir(mep->name, parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	mtu3_debugfs_ep_regset(mep->mtu, mep, dir_ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	for (i = 0; i < ARRAY_SIZE(mtu3_ep_files); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 		files = &mtu3_ep_files[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 		debugfs_create_file(files->name, 0444, dir_ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 				    mep, &mtu3_ep_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) static void mtu3_debugfs_create_ep_dirs(struct mtu3 *mtu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	struct ssusb_mtk *ssusb = mtu->ssusb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	struct dentry *dir_eps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	dir_eps = debugfs_create_dir("eps", ssusb->dbgfs_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	for (i = 1; i < mtu->num_eps; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 		mtu3_debugfs_create_ep_dir(mtu->in_eps + i, dir_eps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 		mtu3_debugfs_create_ep_dir(mtu->out_eps + i, dir_eps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) void ssusb_dev_debugfs_init(struct ssusb_mtk *ssusb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	struct mtu3 *mtu = ssusb->u3d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	struct dentry *dir_regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	dir_regs = debugfs_create_dir("regs", ssusb->dbgfs_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	mtu3_debugfs_regset(mtu, mtu->ippc_base,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 			    mtu3_ippc_regs, ARRAY_SIZE(mtu3_ippc_regs),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 			    "reg-ippc", dir_regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	mtu3_debugfs_regset(mtu, mtu->mac_base,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 			    mtu3_dev_regs, ARRAY_SIZE(mtu3_dev_regs),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 			    "reg-dev", dir_regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	mtu3_debugfs_regset(mtu, mtu->mac_base,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 			    mtu3_csr_regs, ARRAY_SIZE(mtu3_csr_regs),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 			    "reg-csr", dir_regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	mtu3_debugfs_create_ep_dirs(mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	mtu3_debugfs_create_prb_files(mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	debugfs_create_file("link-state", 0444, ssusb->dbgfs_root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 			    mtu, &mtu3_link_state_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	debugfs_create_file("ep-used", 0444, ssusb->dbgfs_root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 			    mtu, &mtu3_ep_used_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) static int ssusb_mode_show(struct seq_file *sf, void *unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	struct ssusb_mtk *ssusb = sf->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	seq_printf(sf, "current mode: %s(%s drd)\n(echo device/host)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 		   ssusb->is_host ? "host" : "device",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 		   ssusb->otg_switch.manual_drd_enabled ? "manual" : "auto");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	return 0;
^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) static int ssusb_mode_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	return single_open(file, ssusb_mode_show, inode->i_private);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) static ssize_t ssusb_mode_write(struct file *file, const char __user *ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 				size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	struct seq_file *sf = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	struct ssusb_mtk *ssusb = sf->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	char buf[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	if (!strncmp(buf, "host", 4) && !ssusb->is_host) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 		ssusb_mode_switch(ssusb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	} else if (!strncmp(buf, "device", 6) && ssusb->is_host) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 		ssusb_mode_switch(ssusb, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 		dev_err(ssusb->dev, "wrong or duplicated setting\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) static const struct file_operations ssusb_mode_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	.open = ssusb_mode_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	.write = ssusb_mode_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	.read = seq_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	.llseek = seq_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	.release = single_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) static int ssusb_vbus_show(struct seq_file *sf, void *unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	struct ssusb_mtk *ssusb = sf->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	struct otg_switch_mtk *otg_sx = &ssusb->otg_switch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	seq_printf(sf, "vbus state: %s\n(echo on/off)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 		   regulator_is_enabled(otg_sx->vbus) ? "on" : "off");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) static int ssusb_vbus_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	return single_open(file, ssusb_vbus_show, inode->i_private);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) static ssize_t ssusb_vbus_write(struct file *file, const char __user *ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 				size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	struct seq_file *sf = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 	struct ssusb_mtk *ssusb = sf->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 	struct otg_switch_mtk *otg_sx = &ssusb->otg_switch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 	char buf[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 	bool enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	if (kstrtobool(buf, &enable)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 		dev_err(ssusb->dev, "wrong setting\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 	ssusb_set_vbus(otg_sx, enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) static const struct file_operations ssusb_vbus_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 	.open = ssusb_vbus_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 	.write = ssusb_vbus_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	.read = seq_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	.llseek = seq_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 	.release = single_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) void ssusb_dr_debugfs_init(struct ssusb_mtk *ssusb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 	struct dentry *root = ssusb->dbgfs_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	debugfs_create_file("mode", 0644, root, ssusb, &ssusb_mode_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 	debugfs_create_file("vbus", 0644, root, ssusb, &ssusb_vbus_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) void ssusb_debugfs_create_root(struct ssusb_mtk *ssusb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 	ssusb->dbgfs_root =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 		debugfs_create_dir(dev_name(ssusb->dev), usb_debug_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) void ssusb_debugfs_remove_root(struct ssusb_mtk *ssusb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 	debugfs_remove_recursive(ssusb->dbgfs_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 	ssusb->dbgfs_root = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) }