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) struct dpn_attribute {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 	struct device_attribute	dev_attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 	int N;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 	int dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 	const char *format_string;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  * Since we can't use ARRAY_SIZE, hard-code number of dpN attributes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  * This needs to be updated when adding new attributes - an error will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  * flagged on a mismatch.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #define SDW_DPN_ATTRIBUTES 15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #define sdw_dpn_attribute_alloc(field)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) static int field##_attribute_alloc(struct device *dev,			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 				struct attribute **res,			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 				int N, int dir,				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 				const char *format_string)		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) {									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	struct dpn_attribute *dpn_attr;					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	dpn_attr = devm_kzalloc(dev, sizeof(*dpn_attr), GFP_KERNEL);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	if (!dpn_attr)							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 		return -ENOMEM;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	dpn_attr->N = N;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	dpn_attr->dir = dir;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	sysfs_attr_init(&dpn_attr->dev_attr.attr);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	dpn_attr->format_string = format_string;			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	dpn_attr->dev_attr.attr.name = __stringify(field);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	dpn_attr->dev_attr.attr.mode = 0444;				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	dpn_attr->dev_attr.show = field##_show;				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	*res = &dpn_attr->dev_attr.attr;				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	return 0;							\
^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) #define sdw_dpn_attr(field)						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) static ssize_t field##_dpn_show(struct sdw_slave *slave,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 				int N,					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 				int dir,				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 				const char *format_string,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 				char *buf)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) {									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	struct sdw_dpn_prop *dpn;					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	unsigned long mask;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	int bit;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	int i;								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	if (dir) {							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		dpn = slave->prop.src_dpn_prop;				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		mask = slave->prop.source_ports;			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	} else {							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		dpn = slave->prop.sink_dpn_prop;			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		mask = slave->prop.sink_ports;				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	}								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	i = 0;								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	for_each_set_bit(bit, &mask, 32) {				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		if (bit == N) {						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 			return sprintf(buf, format_string,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 				       dpn[i].field);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		}							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		i++;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	}								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	return -EINVAL;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) }									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) static ssize_t field##_show(struct device *dev,				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 			    struct device_attribute *attr,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 			    char *buf)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) {									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	struct sdw_slave *slave = dev_to_sdw_dev(dev);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	struct dpn_attribute *dpn_attr =				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		container_of(attr, struct dpn_attribute, dev_attr);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	return field##_dpn_show(slave,					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 				dpn_attr->N, dpn_attr->dir,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 				dpn_attr->format_string,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 				buf);					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) }									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) sdw_dpn_attribute_alloc(field)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) sdw_dpn_attr(imp_def_interrupts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) sdw_dpn_attr(max_word);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) sdw_dpn_attr(min_word);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) sdw_dpn_attr(type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) sdw_dpn_attr(max_grouping);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) sdw_dpn_attr(simple_ch_prep_sm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) sdw_dpn_attr(ch_prep_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) sdw_dpn_attr(max_ch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) sdw_dpn_attr(min_ch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) sdw_dpn_attr(max_async_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) sdw_dpn_attr(block_pack_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) sdw_dpn_attr(port_encoding);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) #define sdw_dpn_array_attr(field)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static ssize_t field##_dpn_show(struct sdw_slave *slave,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 				int N,					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 				int dir,				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 				const char *format_string,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 				char *buf)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) {									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	struct sdw_dpn_prop *dpn;					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	unsigned long mask;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	ssize_t size = 0;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	int bit;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	int i;								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	int j;								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	if (dir) {							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		dpn = slave->prop.src_dpn_prop;				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		mask = slave->prop.source_ports;			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	} else {							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		dpn = slave->prop.sink_dpn_prop;			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		mask = slave->prop.sink_ports;				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	}								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	i = 0;								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	for_each_set_bit(bit, &mask, 32) {				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		if (bit == N) {						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 			for (j = 0; j < dpn[i].num_##field; j++)	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 				size += sprintf(buf + size,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 						format_string,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 						dpn[i].field[j]);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 			size += sprintf(buf + size, "\n");		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 			return size;					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		}							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		i++;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	}								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	return -EINVAL;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) static ssize_t field##_show(struct device *dev,				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 			    struct device_attribute *attr,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 			    char *buf)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) {									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	struct sdw_slave *slave = dev_to_sdw_dev(dev);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	struct dpn_attribute *dpn_attr =				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		container_of(attr, struct dpn_attribute, dev_attr);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	return field##_dpn_show(slave,					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 				dpn_attr->N, dpn_attr->dir,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 				dpn_attr->format_string,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 				buf);					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) }									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) sdw_dpn_attribute_alloc(field)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) sdw_dpn_array_attr(words);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) sdw_dpn_array_attr(ch_combinations);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) sdw_dpn_array_attr(channels);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) static int add_all_attributes(struct device *dev, int N, int dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	struct attribute **dpn_attrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	struct attribute_group *dpn_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	/* allocate attributes, last one is NULL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	dpn_attrs = devm_kcalloc(dev, SDW_DPN_ATTRIBUTES + 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 				 sizeof(struct attribute *),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 				 GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	if (!dpn_attrs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	ret = max_word_attribute_alloc(dev, &dpn_attrs[i++],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 				       N, dir, "%d\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	ret = min_word_attribute_alloc(dev, &dpn_attrs[i++],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 				       N, dir, "%d\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	ret = words_attribute_alloc(dev, &dpn_attrs[i++],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 				    N, dir, "%d\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	ret = type_attribute_alloc(dev, &dpn_attrs[i++],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 				   N, dir, "%d\n");
^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 = max_grouping_attribute_alloc(dev, &dpn_attrs[i++],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 					   N, dir, "%d\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	ret = simple_ch_prep_sm_attribute_alloc(dev, &dpn_attrs[i++],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 						N, dir, "%d\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	ret = ch_prep_timeout_attribute_alloc(dev, &dpn_attrs[i++],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 					      N, dir, "%d\n");
^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) 	ret = imp_def_interrupts_attribute_alloc(dev, &dpn_attrs[i++],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 						 N, dir, "0x%x\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	ret = min_ch_attribute_alloc(dev, &dpn_attrs[i++],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 				     N, dir, "%d\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	ret = max_ch_attribute_alloc(dev, &dpn_attrs[i++],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 				     N, dir, "%d\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	ret = channels_attribute_alloc(dev, &dpn_attrs[i++],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 				       N, dir, "%d\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	ret = ch_combinations_attribute_alloc(dev, &dpn_attrs[i++],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 					      N, dir, "%d\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	ret = max_async_buffer_attribute_alloc(dev, &dpn_attrs[i++],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 					       N, dir, "%d\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	ret = block_pack_mode_attribute_alloc(dev, &dpn_attrs[i++],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 					      N, dir, "%d\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	ret = port_encoding_attribute_alloc(dev, &dpn_attrs[i++],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 					    N, dir, "%d\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	/* paranoia check for editing mistakes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	if (i != SDW_DPN_ATTRIBUTES) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		dev_err(dev, "mismatch in attributes, allocated %d got %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 			SDW_DPN_ATTRIBUTES, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	dpn_group = devm_kzalloc(dev, sizeof(*dpn_group), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	if (!dpn_group)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	dpn_group->attrs = dpn_attrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	dpn_group->name = devm_kasprintf(dev, GFP_KERNEL, "dp%d_%s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 					 N, dir ? "src" : "sink");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	if (!dpn_group->name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	ret = devm_device_add_group(dev, dpn_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) int sdw_slave_sysfs_dpn_init(struct sdw_slave *slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	unsigned long mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	mask = slave->prop.source_ports;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	for_each_set_bit(i, &mask, 32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		ret = add_all_attributes(&slave->dev, i, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 		if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	mask = slave->prop.sink_ports;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	for_each_set_bit(i, &mask, 32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		ret = add_all_attributes(&slave->dev, i, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) }