Lines Matching refs:codec

15 static void setup_fg_nodes(struct hdac_device *codec);
16 static int get_codec_vendor_name(struct hdac_device *codec);
37 int snd_hdac_device_init(struct hdac_device *codec, struct hdac_bus *bus, in snd_hdac_device_init() argument
44 dev = &codec->dev; in snd_hdac_device_init()
53 codec->bus = bus; in snd_hdac_device_init()
54 codec->addr = addr; in snd_hdac_device_init()
55 codec->type = HDA_DEV_CORE; in snd_hdac_device_init()
56 pm_runtime_set_active(&codec->dev); in snd_hdac_device_init()
57 pm_runtime_get_noresume(&codec->dev); in snd_hdac_device_init()
58 atomic_set(&codec->in_pm, 0); in snd_hdac_device_init()
60 err = snd_hdac_bus_add_device(bus, codec); in snd_hdac_device_init()
65 codec->vendor_id = snd_hdac_read_parm(codec, AC_NODE_ROOT, in snd_hdac_device_init()
67 if (codec->vendor_id == -1) { in snd_hdac_device_init()
71 codec->vendor_id = snd_hdac_read_parm(codec, AC_NODE_ROOT, in snd_hdac_device_init()
75 codec->subsystem_id = snd_hdac_read_parm(codec, AC_NODE_ROOT, in snd_hdac_device_init()
77 codec->revision_id = snd_hdac_read_parm(codec, AC_NODE_ROOT, in snd_hdac_device_init()
80 setup_fg_nodes(codec); in snd_hdac_device_init()
81 if (!codec->afg && !codec->mfg) { in snd_hdac_device_init()
87 fg = codec->afg ? codec->afg : codec->mfg; in snd_hdac_device_init()
89 err = snd_hdac_refresh_widgets(codec); in snd_hdac_device_init()
93 codec->power_caps = snd_hdac_read_parm(codec, fg, AC_PAR_POWER_STATE); in snd_hdac_device_init()
95 if (codec->subsystem_id == -1 || codec->subsystem_id == 0) in snd_hdac_device_init()
96 snd_hdac_read(codec, fg, AC_VERB_GET_SUBSYSTEM_ID, 0, in snd_hdac_device_init()
97 &codec->subsystem_id); in snd_hdac_device_init()
99 err = get_codec_vendor_name(codec); in snd_hdac_device_init()
103 codec->chip_name = kasprintf(GFP_KERNEL, "ID %x", in snd_hdac_device_init()
104 codec->vendor_id & 0xffff); in snd_hdac_device_init()
105 if (!codec->chip_name) { in snd_hdac_device_init()
113 put_device(&codec->dev); in snd_hdac_device_init()
122 void snd_hdac_device_exit(struct hdac_device *codec) in snd_hdac_device_exit() argument
124 pm_runtime_put_noidle(&codec->dev); in snd_hdac_device_exit()
125 snd_hdac_bus_remove_device(codec->bus, codec); in snd_hdac_device_exit()
126 kfree(codec->vendor_name); in snd_hdac_device_exit()
127 kfree(codec->chip_name); in snd_hdac_device_exit()
135 int snd_hdac_device_register(struct hdac_device *codec) in snd_hdac_device_register() argument
139 err = device_add(&codec->dev); in snd_hdac_device_register()
142 err = hda_widget_sysfs_init(codec); in snd_hdac_device_register()
144 device_del(&codec->dev); in snd_hdac_device_register()
156 void snd_hdac_device_unregister(struct hdac_device *codec) in snd_hdac_device_unregister() argument
158 if (device_is_registered(&codec->dev)) { in snd_hdac_device_unregister()
159 hda_widget_sysfs_exit(codec); in snd_hdac_device_unregister()
160 device_del(&codec->dev); in snd_hdac_device_unregister()
175 unsigned int snd_hdac_make_cmd(struct hdac_device *codec, hda_nid_t nid, in snd_hdac_make_cmd() argument
180 addr = codec->addr; in snd_hdac_make_cmd()
183 dev_err(&codec->dev, "out of range cmd %x:%x:%x:%x\n", in snd_hdac_make_cmd()
208 int snd_hdac_exec_verb(struct hdac_device *codec, unsigned int cmd, in snd_hdac_exec_verb() argument
211 if (codec->exec_verb) in snd_hdac_exec_verb()
212 return codec->exec_verb(codec, cmd, flags, res); in snd_hdac_exec_verb()
213 return snd_hdac_bus_exec_verb(codec->bus, codec->addr, cmd, res); in snd_hdac_exec_verb()
228 int snd_hdac_read(struct hdac_device *codec, hda_nid_t nid, in snd_hdac_read() argument
231 unsigned int cmd = snd_hdac_make_cmd(codec, nid, verb, parm); in snd_hdac_read()
233 return snd_hdac_exec_verb(codec, cmd, 0, res); in snd_hdac_read()
242 int _snd_hdac_read_parm(struct hdac_device *codec, hda_nid_t nid, int parm, in _snd_hdac_read_parm() argument
248 return snd_hdac_regmap_read_raw(codec, cmd, res); in _snd_hdac_read_parm()
261 int snd_hdac_read_parm_uncached(struct hdac_device *codec, hda_nid_t nid, in snd_hdac_read_parm_uncached() argument
266 if (codec->regmap) in snd_hdac_read_parm_uncached()
267 regcache_cache_bypass(codec->regmap, true); in snd_hdac_read_parm_uncached()
268 val = snd_hdac_read_parm(codec, nid, parm); in snd_hdac_read_parm_uncached()
269 if (codec->regmap) in snd_hdac_read_parm_uncached()
270 regcache_cache_bypass(codec->regmap, false); in snd_hdac_read_parm_uncached()
282 int snd_hdac_override_parm(struct hdac_device *codec, hda_nid_t nid, in snd_hdac_override_parm() argument
288 if (!codec->regmap) in snd_hdac_override_parm()
291 codec->caps_overwriting = true; in snd_hdac_override_parm()
292 err = snd_hdac_regmap_write_raw(codec, verb, val); in snd_hdac_override_parm()
293 codec->caps_overwriting = false; in snd_hdac_override_parm()
307 int snd_hdac_get_sub_nodes(struct hdac_device *codec, hda_nid_t nid, in snd_hdac_get_sub_nodes() argument
312 parm = snd_hdac_read_parm_uncached(codec, nid, AC_PAR_NODE_COUNT); in snd_hdac_get_sub_nodes()
325 static void setup_fg_nodes(struct hdac_device *codec) in setup_fg_nodes() argument
330 total_nodes = snd_hdac_get_sub_nodes(codec, AC_NODE_ROOT, &nid); in setup_fg_nodes()
332 function_id = snd_hdac_read_parm(codec, nid, in setup_fg_nodes()
336 codec->afg = nid; in setup_fg_nodes()
337 codec->afg_function_id = function_id & 0xff; in setup_fg_nodes()
338 codec->afg_unsol = (function_id >> 8) & 1; in setup_fg_nodes()
341 codec->mfg = nid; in setup_fg_nodes()
342 codec->mfg_function_id = function_id & 0xff; in setup_fg_nodes()
343 codec->mfg_unsol = (function_id >> 8) & 1; in setup_fg_nodes()
355 int snd_hdac_refresh_widgets(struct hdac_device *codec) in snd_hdac_refresh_widgets() argument
360 nums = snd_hdac_get_sub_nodes(codec, codec->afg, &start_nid); in snd_hdac_refresh_widgets()
362 dev_err(&codec->dev, "cannot read sub nodes for FG 0x%02x\n", in snd_hdac_refresh_widgets()
363 codec->afg); in snd_hdac_refresh_widgets()
367 codec->num_nodes = nums; in snd_hdac_refresh_widgets()
368 codec->start_nid = start_nid; in snd_hdac_refresh_widgets()
369 codec->end_nid = start_nid + nums; in snd_hdac_refresh_widgets()
375 static unsigned int get_num_conns(struct hdac_device *codec, hda_nid_t nid) in get_num_conns() argument
377 unsigned int wcaps = get_wcaps(codec, nid); in get_num_conns()
384 parm = snd_hdac_read_parm(codec, nid, AC_PAR_CONNLIST_LEN); in get_num_conns()
403 int snd_hdac_get_connections(struct hdac_device *codec, hda_nid_t nid, in snd_hdac_get_connections() argument
412 parm = get_num_conns(codec, nid); in snd_hdac_get_connections()
433 err = snd_hdac_read(codec, nid, AC_VERB_GET_CONNECT_LIST, 0, in snd_hdac_get_connections()
450 err = snd_hdac_read(codec, nid, in snd_hdac_get_connections()
459 dev_dbg(&codec->dev, in snd_hdac_get_connections()
468 dev_warn(&codec->dev, in snd_hdac_get_connections()
506 int snd_hdac_power_up(struct hdac_device *codec) in snd_hdac_power_up() argument
508 return pm_runtime_get_sync(&codec->dev); in snd_hdac_power_up()
518 int snd_hdac_power_down(struct hdac_device *codec) in snd_hdac_power_down() argument
520 struct device *dev = &codec->dev; in snd_hdac_power_down()
538 int snd_hdac_power_up_pm(struct hdac_device *codec) in snd_hdac_power_up_pm() argument
540 if (!atomic_inc_not_zero(&codec->in_pm)) in snd_hdac_power_up_pm()
541 return snd_hdac_power_up(codec); in snd_hdac_power_up_pm()
555 int snd_hdac_power_down_pm(struct hdac_device *codec) in snd_hdac_power_down_pm() argument
557 if (atomic_dec_if_positive(&codec->in_pm) < 0) in snd_hdac_power_down_pm()
558 return snd_hdac_power_down(codec); in snd_hdac_power_down_pm()
595 static int get_codec_vendor_name(struct hdac_device *codec) in get_codec_vendor_name() argument
598 u16 vendor_id = codec->vendor_id >> 16; in get_codec_vendor_name()
602 codec->vendor_name = kstrdup(c->name, GFP_KERNEL); in get_codec_vendor_name()
603 return codec->vendor_name ? 0 : -ENOMEM; in get_codec_vendor_name()
607 codec->vendor_name = kasprintf(GFP_KERNEL, "Generic %04x", vendor_id); in get_codec_vendor_name()
608 return codec->vendor_name ? 0 : -ENOMEM; in get_codec_vendor_name()