struct dpn_attribute { struct device_attribute dev_attr; int N; int dir; constchar *format_string;
};
/* * Since we can't use ARRAY_SIZE, hard-code number of dpN attributes. * This needs to be updated when adding new attributes - an error will be * flagged on a mismatch.
*/ #define SDW_DPN_ATTRIBUTES 15
staticint add_all_attributes(struct device *dev, int N, int dir)
{ struct attribute **dpn_attrs; struct attribute_group *dpn_group; int i = 0; int ret;
/* allocate attributes, last one is NULL */
dpn_attrs = devm_kcalloc(dev, SDW_DPN_ATTRIBUTES + 1, sizeof(struct attribute *),
GFP_KERNEL); if (!dpn_attrs) return -ENOMEM;
ret = max_word_attribute_alloc(dev, &dpn_attrs[i++],
N, dir, "%d\n"); if (ret < 0) return ret;
ret = min_word_attribute_alloc(dev, &dpn_attrs[i++],
N, dir, "%d\n"); if (ret < 0) return ret;
ret = words_attribute_alloc(dev, &dpn_attrs[i++],
N, dir, "%d\n"); if (ret < 0) return ret;
ret = type_attribute_alloc(dev, &dpn_attrs[i++],
N, dir, "%d\n"); if (ret < 0) return ret;
ret = max_grouping_attribute_alloc(dev, &dpn_attrs[i++],
N, dir, "%d\n"); if (ret < 0) return ret;
ret = simple_ch_prep_sm_attribute_alloc(dev, &dpn_attrs[i++],
N, dir, "%d\n"); if (ret < 0) return ret;
ret = ch_prep_timeout_attribute_alloc(dev, &dpn_attrs[i++],
N, dir, "%d\n"); if (ret < 0) return ret;
ret = imp_def_interrupts_attribute_alloc(dev, &dpn_attrs[i++],
N, dir, "0x%x\n"); if (ret < 0) return ret;
ret = min_ch_attribute_alloc(dev, &dpn_attrs[i++],
N, dir, "%d\n"); if (ret < 0) return ret;
ret = max_ch_attribute_alloc(dev, &dpn_attrs[i++],
N, dir, "%d\n"); if (ret < 0) return ret;
ret = channels_attribute_alloc(dev, &dpn_attrs[i++],
N, dir, "%d\n"); if (ret < 0) return ret;
ret = ch_combinations_attribute_alloc(dev, &dpn_attrs[i++],
N, dir, "%d\n"); if (ret < 0) return ret;
ret = max_async_buffer_attribute_alloc(dev, &dpn_attrs[i++],
N, dir, "%d\n"); if (ret < 0) return ret;
ret = block_pack_mode_attribute_alloc(dev, &dpn_attrs[i++],
N, dir, "%d\n"); if (ret < 0) return ret;
ret = port_encoding_attribute_alloc(dev, &dpn_attrs[i++],
N, dir, "%d\n"); if (ret < 0) return ret;
/* paranoia check for editing mistakes */ if (i != SDW_DPN_ATTRIBUTES) {
dev_err(dev, "mismatch in attributes, allocated %d got %d\n",
SDW_DPN_ATTRIBUTES, i); return -EINVAL;
}
dpn_group = devm_kzalloc(dev, sizeof(*dpn_group), GFP_KERNEL); if (!dpn_group) return -ENOMEM;
dpn_group->attrs = dpn_attrs;
dpn_group->name = devm_kasprintf(dev, GFP_KERNEL, "dp%d_%s",
N, dir ? "src" : "sink"); if (!dpn_group->name) return -ENOMEM;
ret = devm_device_add_group(dev, dpn_group); if (ret < 0) return ret;
return 0;
}
int sdw_slave_sysfs_dpn_init(struct sdw_slave *slave)
{ unsignedlong mask; int ret; int i;
if (!slave->prop.source_ports && !slave->prop.sink_ports) return 0;
mask = slave->prop.source_ports;
for_each_set_bit(i, &mask, 32) {
ret = add_all_attributes(&slave->dev, i, 1); if (ret < 0) return ret;
}
mask = slave->prop.sink_ports;
for_each_set_bit(i, &mask, 32) {
ret = add_all_attributes(&slave->dev, i, 0); if (ret < 0) return ret;
}
return 0;
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.1 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.