^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) * sysfs support for HD-audio core device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^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/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <sound/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <sound/hdaudio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include "local.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) struct hdac_widget_tree {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) struct kobject *root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) struct kobject *afg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) struct kobject **nodes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define CODEC_ATTR(type) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) static ssize_t type##_show(struct device *dev, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) struct device_attribute *attr, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) char *buf) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) struct hdac_device *codec = dev_to_hdac_dev(dev); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) return sprintf(buf, "0x%x\n", codec->type); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) static DEVICE_ATTR_RO(type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define CODEC_ATTR_STR(type) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) static ssize_t type##_show(struct device *dev, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) struct device_attribute *attr, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) char *buf) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) struct hdac_device *codec = dev_to_hdac_dev(dev); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) return sprintf(buf, "%s\n", \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) codec->type ? codec->type : ""); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) static DEVICE_ATTR_RO(type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) CODEC_ATTR(type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) CODEC_ATTR(vendor_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) CODEC_ATTR(subsystem_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) CODEC_ATTR(revision_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) CODEC_ATTR(afg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) CODEC_ATTR(mfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) CODEC_ATTR_STR(vendor_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) CODEC_ATTR_STR(chip_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) return snd_hdac_codec_modalias(dev_to_hdac_dev(dev), buf, 256);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) static DEVICE_ATTR_RO(modalias);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) static struct attribute *hdac_dev_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) &dev_attr_type.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) &dev_attr_vendor_id.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) &dev_attr_subsystem_id.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) &dev_attr_revision_id.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) &dev_attr_afg.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) &dev_attr_mfg.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) &dev_attr_vendor_name.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) &dev_attr_chip_name.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) &dev_attr_modalias.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) NULL
^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) static struct attribute_group hdac_dev_attr_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) .attrs = hdac_dev_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) const struct attribute_group *hdac_dev_attr_groups[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) &hdac_dev_attr_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) NULL
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * Widget tree sysfs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * This is a tree showing the attributes of each widget. It appears like
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) * /sys/bus/hdaudioC0D0/widgets/04/caps
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) struct widget_attribute;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) struct widget_attribute {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) struct attribute attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) ssize_t (*show)(struct hdac_device *codec, hda_nid_t nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) struct widget_attribute *attr, char *buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) ssize_t (*store)(struct hdac_device *codec, hda_nid_t nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) struct widget_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) const char *buf, size_t count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) static int get_codec_nid(struct kobject *kobj, struct hdac_device **codecp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) struct device *dev = kobj_to_dev(kobj->parent->parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) int nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) ssize_t ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) ret = kstrtoint(kobj->name, 16, &nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) *codecp = dev_to_hdac_dev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) return nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) static ssize_t widget_attr_show(struct kobject *kobj, struct attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) struct widget_attribute *wid_attr =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) container_of(attr, struct widget_attribute, attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) struct hdac_device *codec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) int nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) if (!wid_attr->show)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) nid = get_codec_nid(kobj, &codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) if (nid < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) return nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) return wid_attr->show(codec, nid, wid_attr, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) static ssize_t widget_attr_store(struct kobject *kobj, struct attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) struct widget_attribute *wid_attr =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) container_of(attr, struct widget_attribute, attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) struct hdac_device *codec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) int nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) if (!wid_attr->store)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) nid = get_codec_nid(kobj, &codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) if (nid < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) return nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) return wid_attr->store(codec, nid, wid_attr, buf, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) static const struct sysfs_ops widget_sysfs_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) .show = widget_attr_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) .store = widget_attr_store,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) static void widget_release(struct kobject *kobj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) kfree(kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) static struct kobj_type widget_ktype = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) .release = widget_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) .sysfs_ops = &widget_sysfs_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) #define WIDGET_ATTR_RO(_name) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) struct widget_attribute wid_attr_##_name = __ATTR_RO(_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) #define WIDGET_ATTR_RW(_name) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) struct widget_attribute wid_attr_##_name = __ATTR_RW(_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) static ssize_t caps_show(struct hdac_device *codec, hda_nid_t nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) struct widget_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) return sprintf(buf, "0x%08x\n", get_wcaps(codec, nid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) static ssize_t pin_caps_show(struct hdac_device *codec, hda_nid_t nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) struct widget_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) return sprintf(buf, "0x%08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) snd_hdac_read_parm(codec, nid, AC_PAR_PIN_CAP));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) static ssize_t pin_cfg_show(struct hdac_device *codec, hda_nid_t nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) struct widget_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) unsigned int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) if (snd_hdac_read(codec, nid, AC_VERB_GET_CONFIG_DEFAULT, 0, &val))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) return sprintf(buf, "0x%08x\n", val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) static bool has_pcm_cap(struct hdac_device *codec, hda_nid_t nid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) if (nid == codec->afg || nid == codec->mfg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) switch (get_wcaps_type(get_wcaps(codec, nid))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) case AC_WID_AUD_OUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) case AC_WID_AUD_IN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) return false;
^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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) static ssize_t pcm_caps_show(struct hdac_device *codec, hda_nid_t nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) struct widget_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) if (!has_pcm_cap(codec, nid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) return sprintf(buf, "0x%08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) snd_hdac_read_parm(codec, nid, AC_PAR_PCM));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) static ssize_t pcm_formats_show(struct hdac_device *codec, hda_nid_t nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) struct widget_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) if (!has_pcm_cap(codec, nid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) return sprintf(buf, "0x%08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) snd_hdac_read_parm(codec, nid, AC_PAR_STREAM));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) static ssize_t amp_in_caps_show(struct hdac_device *codec, hda_nid_t nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) struct widget_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) if (nid != codec->afg && !(get_wcaps(codec, nid) & AC_WCAP_IN_AMP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) return sprintf(buf, "0x%08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) snd_hdac_read_parm(codec, nid, AC_PAR_AMP_IN_CAP));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) static ssize_t amp_out_caps_show(struct hdac_device *codec, hda_nid_t nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) struct widget_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) if (nid != codec->afg && !(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) return sprintf(buf, "0x%08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) snd_hdac_read_parm(codec, nid, AC_PAR_AMP_OUT_CAP));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) static ssize_t power_caps_show(struct hdac_device *codec, hda_nid_t nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) struct widget_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) if (nid != codec->afg && !(get_wcaps(codec, nid) & AC_WCAP_POWER))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) return sprintf(buf, "0x%08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) snd_hdac_read_parm(codec, nid, AC_PAR_POWER_STATE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) static ssize_t gpio_caps_show(struct hdac_device *codec, hda_nid_t nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) struct widget_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) return sprintf(buf, "0x%08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) snd_hdac_read_parm(codec, nid, AC_PAR_GPIO_CAP));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) static ssize_t connections_show(struct hdac_device *codec, hda_nid_t nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) struct widget_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) hda_nid_t list[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) int i, nconns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) ssize_t ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) nconns = snd_hdac_get_connections(codec, nid, list, ARRAY_SIZE(list));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) if (nconns <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) return nconns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) for (i = 0; i < nconns; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) ret += sprintf(buf + ret, "%s0x%02x", i ? " " : "", list[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) ret += sprintf(buf + ret, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) return ret;
^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) static WIDGET_ATTR_RO(caps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) static WIDGET_ATTR_RO(pin_caps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) static WIDGET_ATTR_RO(pin_cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) static WIDGET_ATTR_RO(pcm_caps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) static WIDGET_ATTR_RO(pcm_formats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) static WIDGET_ATTR_RO(amp_in_caps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) static WIDGET_ATTR_RO(amp_out_caps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) static WIDGET_ATTR_RO(power_caps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) static WIDGET_ATTR_RO(gpio_caps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) static WIDGET_ATTR_RO(connections);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) static struct attribute *widget_node_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) &wid_attr_caps.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) &wid_attr_pin_caps.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) &wid_attr_pin_cfg.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) &wid_attr_pcm_caps.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) &wid_attr_pcm_formats.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) &wid_attr_amp_in_caps.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) &wid_attr_amp_out_caps.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) &wid_attr_power_caps.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) &wid_attr_connections.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) NULL,
^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) static struct attribute *widget_afg_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) &wid_attr_pcm_caps.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) &wid_attr_pcm_formats.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) &wid_attr_amp_in_caps.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) &wid_attr_amp_out_caps.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) &wid_attr_power_caps.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) &wid_attr_gpio_caps.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) static const struct attribute_group widget_node_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) .attrs = widget_node_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) static const struct attribute_group widget_afg_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) .attrs = widget_afg_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) static void free_widget_node(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) const struct attribute_group *group)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) if (kobj) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) sysfs_remove_group(kobj, group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) kobject_put(kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) static void widget_tree_free(struct hdac_device *codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) struct hdac_widget_tree *tree = codec->widgets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) struct kobject **p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) if (!tree)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) free_widget_node(tree->afg, &widget_afg_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) if (tree->nodes) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) for (p = tree->nodes; *p; p++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) free_widget_node(*p, &widget_node_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) kfree(tree->nodes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) kobject_put(tree->root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) kfree(tree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) codec->widgets = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) static int add_widget_node(struct kobject *parent, hda_nid_t nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) const struct attribute_group *group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) struct kobject **res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) struct kobject *kobj = kzalloc(sizeof(*kobj), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) if (!kobj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) kobject_init(kobj, &widget_ktype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) err = kobject_add(kobj, parent, "%02x", nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) err = sysfs_create_group(kobj, group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) kobject_put(kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) *res = kobj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) static int widget_tree_create(struct hdac_device *codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) struct hdac_widget_tree *tree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) int i, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) hda_nid_t nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) tree = codec->widgets = kzalloc(sizeof(*tree), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) if (!tree)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) tree->root = kobject_create_and_add("widgets", &codec->dev.kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) if (!tree->root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) tree->nodes = kcalloc(codec->num_nodes + 1, sizeof(*tree->nodes),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) if (!tree->nodes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) for (i = 0, nid = codec->start_nid; i < codec->num_nodes; i++, nid++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) err = add_widget_node(tree->root, nid, &widget_node_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) &tree->nodes[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) if (codec->afg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) err = add_widget_node(tree->root, codec->afg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) &widget_afg_group, &tree->afg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) kobject_uevent(tree->root, KOBJ_CHANGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) /* call with codec->widget_lock held */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) int hda_widget_sysfs_init(struct hdac_device *codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) if (codec->widgets)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) return 0; /* already created */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) err = widget_tree_create(codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) widget_tree_free(codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) /* call with codec->widget_lock held */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) void hda_widget_sysfs_exit(struct hdac_device *codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) widget_tree_free(codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) /* call with codec->widget_lock held */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) int hda_widget_sysfs_reinit(struct hdac_device *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) hda_nid_t start_nid, int num_nodes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) struct hdac_widget_tree *tree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) hda_nid_t end_nid = start_nid + num_nodes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) hda_nid_t nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) if (!codec->widgets)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) tree = kmemdup(codec->widgets, sizeof(*tree), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) if (!tree)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) tree->nodes = kcalloc(num_nodes + 1, sizeof(*tree->nodes), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) if (!tree->nodes) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) kfree(tree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) /* prune non-existing nodes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) for (i = 0, nid = codec->start_nid; i < codec->num_nodes; i++, nid++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) if (nid < start_nid || nid >= end_nid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) free_widget_node(codec->widgets->nodes[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) &widget_node_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) /* add new nodes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) for (i = 0, nid = start_nid; i < num_nodes; i++, nid++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) if (nid < codec->start_nid || nid >= codec->end_nid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) add_widget_node(tree->root, nid, &widget_node_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) &tree->nodes[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) tree->nodes[i] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) codec->widgets->nodes[nid - codec->start_nid];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) /* replace with the new tree */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) kfree(codec->widgets->nodes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) kfree(codec->widgets);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) codec->widgets = tree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) kobject_uevent(tree->root, KOBJ_CHANGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) }