| 1 |
// SPDX-License-Identifier: GPL-2.0-only |
| 2 |
// Copyright(c) 2023 Intel Corporation |
| 3 |
|
| 4 |
#include <linux/acpi.h> |
| 5 |
#include <linux/debugfs.h> |
| 6 |
#include <linux/delay.h> |
| 7 |
#include <linux/device.h> |
| 8 |
#include <linux/io.h> |
| 9 |
#include <linux/pm_runtime.h> |
| 10 |
#include <linux/soundwire/sdw.h> |
| 11 |
#include <linux/soundwire/sdw_intel.h> |
| 12 |
#include <linux/soundwire/sdw_registers.h> |
| 13 |
#include "bus.h" |
| 14 |
#include "cadence_master.h" |
| 15 |
#include "intel.h" |
| 16 |
|
| 17 |
/* |
| 18 |
* debugfs |
| 19 |
*/ |
| 20 |
#ifdef CONFIG_DEBUG_FS |
| 21 |
|
| 22 |
#define RD_BUF (2 * PAGE_SIZE) |
| 23 |
|
| 24 |
static ssize_t intel_sprintf(void __iomem *mem, bool l, |
| 25 |
char *buf, size_t pos, unsigned int reg) |
| 26 |
{ |
| 27 |
int value; |
| 28 |
|
| 29 |
if (l) |
| 30 |
value = intel_readl(mem, reg); |
| 31 |
else |
| 32 |
value = intel_readw(mem, reg); |
| 33 |
|
| 34 |
return scnprintf(buf + pos, RD_BUF - pos, "%4x\t%4x\n", reg, value); |
| 35 |
} |
| 36 |
|
| 37 |
static int intel_reg_show(struct seq_file *s_file, void *data) |
| 38 |
{ |
| 39 |
struct sdw_intel *sdw = s_file->private; |
| 40 |
void __iomem *s = sdw->link_res->shim; |
| 41 |
void __iomem *vs_s = sdw->link_res->shim_vs; |
| 42 |
ssize_t ret; |
| 43 |
u32 pcm_cap; |
| 44 |
int pcm_bd; |
| 45 |
char *buf; |
| 46 |
int j; |
| 47 |
|
| 48 |
buf = kzalloc(RD_BUF, GFP_KERNEL); |
| 49 |
if (!buf) |
| 50 |
return -ENOMEM; |
| 51 |
|
| 52 |
ret = scnprintf(buf, RD_BUF, "Register Value\n"); |
| 53 |
ret += scnprintf(buf + ret, RD_BUF - ret, "\nShim\n"); |
| 54 |
|
| 55 |
ret += intel_sprintf(s, true, buf, ret, SDW_SHIM2_LECAP); |
| 56 |
ret += intel_sprintf(s, false, buf, ret, SDW_SHIM2_PCMSCAP); |
| 57 |
|
| 58 |
pcm_cap = intel_readw(s, SDW_SHIM2_PCMSCAP); |
| 59 |
pcm_bd = FIELD_GET(SDW_SHIM2_PCMSCAP_BSS, pcm_cap); |
| 60 |
|
| 61 |
for (j = 0; j < pcm_bd; j++) { |
| 62 |
ret += intel_sprintf(s, false, buf, ret, |
| 63 |
SDW_SHIM2_PCMSYCHM(j)); |
| 64 |
ret += intel_sprintf(s, false, buf, ret, |
| 65 |
SDW_SHIM2_PCMSYCHC(j)); |
| 66 |
} |
| 67 |
|
| 68 |
ret += scnprintf(buf + ret, RD_BUF - ret, "\nVS CLK controls\n"); |
| 69 |
ret += intel_sprintf(vs_s, true, buf, ret, SDW_SHIM2_INTEL_VS_LVSCTL); |
| 70 |
|
| 71 |
ret += scnprintf(buf + ret, RD_BUF - ret, "\nVS Wake registers\n"); |
| 72 |
ret += intel_sprintf(vs_s, false, buf, ret, SDW_SHIM2_INTEL_VS_WAKEEN); |
| 73 |
ret += intel_sprintf(vs_s, false, buf, ret, SDW_SHIM2_INTEL_VS_WAKESTS); |
| 74 |
|
| 75 |
ret += scnprintf(buf + ret, RD_BUF - ret, "\nVS IOCTL, ACTMCTL\n"); |
| 76 |
ret += intel_sprintf(vs_s, false, buf, ret, SDW_SHIM2_INTEL_VS_IOCTL); |
| 77 |
ret += intel_sprintf(vs_s, false, buf, ret, SDW_SHIM2_INTEL_VS_ACTMCTL); |
| 78 |
|
| 79 |
if (sdw->link_res->mic_privacy) { |
| 80 |
ret += scnprintf(buf + ret, RD_BUF - ret, "\nVS PVCCS\n"); |
| 81 |
ret += intel_sprintf(vs_s, false, buf, ret, |
| 82 |
SDW_SHIM2_INTEL_VS_PVCCS); |
| 83 |
} |
| 84 |
|
| 85 |
seq_printf(s_file, "%s", buf); |
| 86 |
kfree(buf); |
| 87 |
|
| 88 |
return 0; |
| 89 |
} |
| 90 |
DEFINE_SHOW_ATTRIBUTE(intel_reg); |
| 91 |
|
| 92 |
static int intel_set_m_datamode(void *data, u64 value) |
| 93 |
{ |
| 94 |
struct sdw_intel *sdw = data; |
| 95 |
struct sdw_bus *bus = &sdw->cdns.bus; |
| 96 |
|
| 97 |
if (value > SDW_PORT_DATA_MODE_STATIC_1) |
| 98 |
return -EINVAL; |
| 99 |
|
| 100 |
/* Userspace changed the hardware state behind the kernel's back */ |
| 101 |
add_taint(TAINT_USER, LOCKDEP_STILL_OK); |
| 102 |
|
| 103 |
bus->params.m_data_mode = value; |
| 104 |
|
| 105 |
return 0; |
| 106 |
} |
| 107 |
DEFINE_DEBUGFS_ATTRIBUTE(intel_set_m_datamode_fops, NULL, |
| 108 |
intel_set_m_datamode, "%llu\n"); |
| 109 |
|
| 110 |
static int intel_set_s_datamode(void *data, u64 value) |
| 111 |
{ |
| 112 |
struct sdw_intel *sdw = data; |
| 113 |
struct sdw_bus *bus = &sdw->cdns.bus; |
| 114 |
|
| 115 |
if (value > SDW_PORT_DATA_MODE_STATIC_1) |
| 116 |
return -EINVAL; |
| 117 |
|
| 118 |
/* Userspace changed the hardware state behind the kernel's back */ |
| 119 |
add_taint(TAINT_USER, LOCKDEP_STILL_OK); |
| 120 |
|
| 121 |
bus->params.s_data_mode = value; |
| 122 |
|
| 123 |
return 0; |
| 124 |
} |
| 125 |
DEFINE_DEBUGFS_ATTRIBUTE(intel_set_s_datamode_fops, NULL, |
| 126 |
intel_set_s_datamode, "%llu\n"); |
| 127 |
|
| 128 |
void intel_ace2x_debugfs_init(struct sdw_intel *sdw) |
| 129 |
{ |
| 130 |
struct dentry *root = sdw->cdns.bus.debugfs; |
| 131 |
|
| 132 |
if (!root) |
| 133 |
return; |
| 134 |
|
| 135 |
sdw->debugfs = debugfs_create_dir("intel-sdw", root); |
| 136 |
|
| 137 |
debugfs_create_file("intel-registers", 0400, sdw->debugfs, sdw, |
| 138 |
&intel_reg_fops); |
| 139 |
|
| 140 |
debugfs_create_file("intel-m-datamode", 0200, sdw->debugfs, sdw, |
| 141 |
&intel_set_m_datamode_fops); |
| 142 |
|
| 143 |
debugfs_create_file("intel-s-datamode", 0200, sdw->debugfs, sdw, |
| 144 |
&intel_set_s_datamode_fops); |
| 145 |
|
| 146 |
sdw_cdns_debugfs_init(&sdw->cdns, sdw->debugfs); |
| 147 |
} |
| 148 |
|
| 149 |
void intel_ace2x_debugfs_exit(struct sdw_intel *sdw) |
| 150 |
{ |
| 151 |
debugfs_remove_recursive(sdw->debugfs); |
| 152 |
} |
| 153 |
#endif /* CONFIG_DEBUG_FS */ |