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-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) // Copyright(c) 2015-2020 Intel Corporation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #include <linux/mod_devicetable.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/sysfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/soundwire/sdw.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/soundwire/sdw_type.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include "bus.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include "sysfs_local.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * Slave sysfs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  * The sysfs for Slave reflects the MIPI description as given
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * in the MIPI DisCo spec.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  * status and device_number come directly from the MIPI SoundWire
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  * 1.x specification.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  * Base file is device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  *	|---- status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  *	|---- device_number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  *	|---- modalias
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  *	|---- dev-properties
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  *		|---- mipi_revision
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  *		|---- wake_capable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  *		|---- test_mode_capable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  *		|---- clk_stop_mode1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  *		|---- simple_clk_stop_capable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  *		|---- clk_stop_timeout
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  *		|---- ch_prep_timeout
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  *		|---- reset_behave
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  *		|---- high_PHY_capable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  *		|---- paging_support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  *		|---- bank_delay_support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  *		|---- p15_behave
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  *		|---- master_count
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  *		|---- source_ports
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  *		|---- sink_ports
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)  *	|---- dp0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)  *		|---- max_word
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  *		|---- min_word
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  *		|---- words
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  *		|---- BRA_flow_controlled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  *		|---- simple_ch_prep_sm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  *		|---- imp_def_interrupts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  *	|---- dpN_<sink/src>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  *		|---- max_word
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)  *		|---- min_word
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)  *		|---- words
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  *		|---- type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55)  *		|---- max_grouping
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)  *		|---- simple_ch_prep_sm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)  *		|---- ch_prep_timeout
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  *		|---- imp_def_interrupts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  *		|---- min_ch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  *		|---- max_ch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  *		|---- channels
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  *		|---- ch_combinations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63)  *		|---- max_async_buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64)  *		|---- block_pack_mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)  *		|---- port_encoding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) #define sdw_slave_attr(field, format_string)			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) static ssize_t field##_show(struct device *dev,			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 			    struct device_attribute *attr,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 			    char *buf)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) {								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	struct sdw_slave *slave = dev_to_sdw_dev(dev);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	return sprintf(buf, format_string, slave->prop.field);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) }								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) static DEVICE_ATTR_RO(field)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) sdw_slave_attr(mipi_revision, "0x%x\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) sdw_slave_attr(wake_capable, "%d\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) sdw_slave_attr(test_mode_capable, "%d\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) sdw_slave_attr(clk_stop_mode1, "%d\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) sdw_slave_attr(simple_clk_stop_capable, "%d\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) sdw_slave_attr(clk_stop_timeout, "%d\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) sdw_slave_attr(ch_prep_timeout, "%d\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) sdw_slave_attr(reset_behave, "%d\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) sdw_slave_attr(high_PHY_capable, "%d\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) sdw_slave_attr(paging_support, "%d\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) sdw_slave_attr(bank_delay_support, "%d\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) sdw_slave_attr(p15_behave, "%d\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) sdw_slave_attr(master_count, "%d\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) sdw_slave_attr(source_ports, "0x%x\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) sdw_slave_attr(sink_ports, "0x%x\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) static ssize_t modalias_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 			     struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	struct sdw_slave *slave = dev_to_sdw_dev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	return sdw_slave_modalias(slave, buf, 256);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) static DEVICE_ATTR_RO(modalias);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static struct attribute *slave_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	&dev_attr_modalias.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) ATTRIBUTE_GROUPS(slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) static struct attribute *slave_dev_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	&dev_attr_mipi_revision.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	&dev_attr_wake_capable.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	&dev_attr_test_mode_capable.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	&dev_attr_clk_stop_mode1.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	&dev_attr_simple_clk_stop_capable.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	&dev_attr_clk_stop_timeout.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	&dev_attr_ch_prep_timeout.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	&dev_attr_reset_behave.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	&dev_attr_high_PHY_capable.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	&dev_attr_paging_support.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	&dev_attr_bank_delay_support.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	&dev_attr_p15_behave.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	&dev_attr_master_count.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	&dev_attr_source_ports.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	&dev_attr_sink_ports.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)  * we don't use ATTRIBUTES_GROUP here since we want to add a subdirectory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)  * for device-level properties
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) static struct attribute_group sdw_slave_dev_attr_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	.attrs	= slave_dev_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	.name = "dev-properties",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)  * DP0 sysfs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) #define sdw_dp0_attr(field, format_string)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) static ssize_t field##_show(struct device *dev,				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 			    struct device_attribute *attr,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 			    char *buf)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) {									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	struct sdw_slave *slave = dev_to_sdw_dev(dev);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	return sprintf(buf, format_string, slave->prop.dp0_prop->field);\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) static DEVICE_ATTR_RO(field)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) sdw_dp0_attr(max_word, "%d\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) sdw_dp0_attr(min_word, "%d\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) sdw_dp0_attr(BRA_flow_controlled, "%d\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) sdw_dp0_attr(simple_ch_prep_sm, "%d\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) sdw_dp0_attr(imp_def_interrupts, "0x%x\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) static ssize_t words_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 			  struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	struct sdw_slave *slave = dev_to_sdw_dev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	ssize_t size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	for (i = 0; i < slave->prop.dp0_prop->num_words; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		size += sprintf(buf + size, "%d ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 				slave->prop.dp0_prop->words[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	size += sprintf(buf + size, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	return size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) static DEVICE_ATTR_RO(words);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) static struct attribute *dp0_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	&dev_attr_max_word.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	&dev_attr_min_word.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	&dev_attr_words.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	&dev_attr_BRA_flow_controlled.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	&dev_attr_simple_ch_prep_sm.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	&dev_attr_imp_def_interrupts.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)  * we don't use ATTRIBUTES_GROUP here since we want to add a subdirectory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)  * for dp0-level properties
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) static const struct attribute_group dp0_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	.attrs = dp0_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	.name = "dp0",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) int sdw_slave_sysfs_init(struct sdw_slave *slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	ret = devm_device_add_groups(&slave->dev, slave_groups);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	ret = devm_device_add_group(&slave->dev, &sdw_slave_dev_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	if (slave->prop.dp0_prop) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		ret = devm_device_add_group(&slave->dev, &dp0_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	if (slave->prop.source_ports || slave->prop.sink_ports) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		ret = sdw_slave_sysfs_dpn_init(slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)  * the status is shown in capital letters for UNATTACHED and RESERVED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)  * on purpose, to highligh users to the fact that these status values
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)  * are not expected.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) static const char *const slave_status[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	[SDW_SLAVE_UNATTACHED] =  "UNATTACHED",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	[SDW_SLAVE_ATTACHED] = "Attached",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	[SDW_SLAVE_ALERT] = "Alert",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	[SDW_SLAVE_RESERVED] = "RESERVED",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) static ssize_t status_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 			   struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	struct sdw_slave *slave = dev_to_sdw_dev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	return sprintf(buf, "%s\n", slave_status[slave->status]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) static DEVICE_ATTR_RO(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) static ssize_t device_number_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 				  struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	struct sdw_slave *slave = dev_to_sdw_dev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	if (slave->status == SDW_SLAVE_UNATTACHED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		return sprintf(buf, "%s", "N/A");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		return sprintf(buf, "%d", slave->dev_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) static DEVICE_ATTR_RO(device_number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) static struct attribute *slave_status_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	&dev_attr_status.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	&dev_attr_device_number.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) };
^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)  * we don't use ATTRIBUTES_GROUP here since the group is used in a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)  * separate file and can't be handled as a static.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) static const struct attribute_group sdw_slave_status_attr_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	.attrs	= slave_status_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) const struct attribute_group *sdw_slave_status_attr_groups[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	&sdw_slave_status_attr_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) };