Lines Matching refs:codec

16 static void setup_fg_nodes(struct hdac_device *codec);
17 static int get_codec_vendor_name(struct hdac_device *codec);
38 int snd_hdac_device_init(struct hdac_device *codec, struct hdac_bus *bus, in snd_hdac_device_init() argument
45 dev = &codec->dev; in snd_hdac_device_init()
54 codec->bus = bus; in snd_hdac_device_init()
55 codec->addr = addr; in snd_hdac_device_init()
56 codec->type = HDA_DEV_CORE; in snd_hdac_device_init()
57 pm_runtime_set_active(&codec->dev); in snd_hdac_device_init()
58 pm_runtime_get_noresume(&codec->dev); in snd_hdac_device_init()
59 atomic_set(&codec->in_pm, 0); in snd_hdac_device_init()
61 err = snd_hdac_bus_add_device(bus, codec); in snd_hdac_device_init()
66 codec->vendor_id = snd_hdac_read_parm(codec, AC_NODE_ROOT, in snd_hdac_device_init()
68 if (codec->vendor_id == -1) { in snd_hdac_device_init()
72 codec->vendor_id = snd_hdac_read_parm(codec, AC_NODE_ROOT, in snd_hdac_device_init()
76 codec->subsystem_id = snd_hdac_read_parm(codec, AC_NODE_ROOT, in snd_hdac_device_init()
78 codec->revision_id = snd_hdac_read_parm(codec, AC_NODE_ROOT, in snd_hdac_device_init()
81 setup_fg_nodes(codec); in snd_hdac_device_init()
82 if (!codec->afg && !codec->mfg) { in snd_hdac_device_init()
88 fg = codec->afg ? codec->afg : codec->mfg; in snd_hdac_device_init()
90 err = snd_hdac_refresh_widgets(codec); in snd_hdac_device_init()
94 codec->power_caps = snd_hdac_read_parm(codec, fg, AC_PAR_POWER_STATE); in snd_hdac_device_init()
96 if (codec->subsystem_id == -1 || codec->subsystem_id == 0) in snd_hdac_device_init()
97 snd_hdac_read(codec, fg, AC_VERB_GET_SUBSYSTEM_ID, 0, in snd_hdac_device_init()
98 &codec->subsystem_id); in snd_hdac_device_init()
100 err = get_codec_vendor_name(codec); in snd_hdac_device_init()
104 codec->chip_name = kasprintf(GFP_KERNEL, "ID %x", in snd_hdac_device_init()
105 codec->vendor_id & 0xffff); in snd_hdac_device_init()
106 if (!codec->chip_name) { in snd_hdac_device_init()
114 put_device(&codec->dev); in snd_hdac_device_init()
123 void snd_hdac_device_exit(struct hdac_device *codec) in snd_hdac_device_exit() argument
125 pm_runtime_put_noidle(&codec->dev); in snd_hdac_device_exit()
126 snd_hdac_bus_remove_device(codec->bus, codec); in snd_hdac_device_exit()
127 kfree(codec->vendor_name); in snd_hdac_device_exit()
128 kfree(codec->chip_name); in snd_hdac_device_exit()
136 int snd_hdac_device_register(struct hdac_device *codec) in snd_hdac_device_register() argument
140 err = device_add(&codec->dev); in snd_hdac_device_register()
143 err = hda_widget_sysfs_init(codec); in snd_hdac_device_register()
145 device_del(&codec->dev); in snd_hdac_device_register()
157 void snd_hdac_device_unregister(struct hdac_device *codec) in snd_hdac_device_unregister() argument
159 if (device_is_registered(&codec->dev)) { in snd_hdac_device_unregister()
160 hda_widget_sysfs_exit(codec); in snd_hdac_device_unregister()
161 device_del(&codec->dev); in snd_hdac_device_unregister()
173 int snd_hdac_device_set_chip_name(struct hdac_device *codec, const char *name) in snd_hdac_device_set_chip_name() argument
182 kfree(codec->chip_name); in snd_hdac_device_set_chip_name()
183 codec->chip_name = newname; in snd_hdac_device_set_chip_name()
196 int snd_hdac_codec_modalias(struct hdac_device *codec, char *buf, size_t size) in snd_hdac_codec_modalias() argument
199 codec->vendor_id, codec->revision_id, codec->type); in snd_hdac_codec_modalias()
213 unsigned int snd_hdac_make_cmd(struct hdac_device *codec, hda_nid_t nid, in snd_hdac_make_cmd() argument
218 addr = codec->addr; in snd_hdac_make_cmd()
221 dev_err(&codec->dev, "out of range cmd %x:%x:%x:%x\n", in snd_hdac_make_cmd()
246 int snd_hdac_exec_verb(struct hdac_device *codec, unsigned int cmd, in snd_hdac_exec_verb() argument
249 if (codec->exec_verb) in snd_hdac_exec_verb()
250 return codec->exec_verb(codec, cmd, flags, res); in snd_hdac_exec_verb()
251 return snd_hdac_bus_exec_verb(codec->bus, codec->addr, cmd, res); in snd_hdac_exec_verb()
266 int snd_hdac_read(struct hdac_device *codec, hda_nid_t nid, in snd_hdac_read() argument
269 unsigned int cmd = snd_hdac_make_cmd(codec, nid, verb, parm); in snd_hdac_read()
271 return snd_hdac_exec_verb(codec, cmd, 0, res); in snd_hdac_read()
280 int _snd_hdac_read_parm(struct hdac_device *codec, hda_nid_t nid, int parm, in _snd_hdac_read_parm() argument
286 return snd_hdac_regmap_read_raw(codec, cmd, res); in _snd_hdac_read_parm()
299 int snd_hdac_read_parm_uncached(struct hdac_device *codec, hda_nid_t nid, in snd_hdac_read_parm_uncached() argument
304 if (codec->regmap) in snd_hdac_read_parm_uncached()
305 regcache_cache_bypass(codec->regmap, true); in snd_hdac_read_parm_uncached()
306 val = snd_hdac_read_parm(codec, nid, parm); in snd_hdac_read_parm_uncached()
307 if (codec->regmap) in snd_hdac_read_parm_uncached()
308 regcache_cache_bypass(codec->regmap, false); in snd_hdac_read_parm_uncached()
320 int snd_hdac_override_parm(struct hdac_device *codec, hda_nid_t nid, in snd_hdac_override_parm() argument
326 if (!codec->regmap) in snd_hdac_override_parm()
329 codec->caps_overwriting = true; in snd_hdac_override_parm()
330 err = snd_hdac_regmap_write_raw(codec, verb, val); in snd_hdac_override_parm()
331 codec->caps_overwriting = false; in snd_hdac_override_parm()
345 int snd_hdac_get_sub_nodes(struct hdac_device *codec, hda_nid_t nid, in snd_hdac_get_sub_nodes() argument
350 parm = snd_hdac_read_parm_uncached(codec, nid, AC_PAR_NODE_COUNT); in snd_hdac_get_sub_nodes()
363 static void setup_fg_nodes(struct hdac_device *codec) in setup_fg_nodes() argument
368 total_nodes = snd_hdac_get_sub_nodes(codec, AC_NODE_ROOT, &nid); in setup_fg_nodes()
370 function_id = snd_hdac_read_parm(codec, nid, in setup_fg_nodes()
374 codec->afg = nid; in setup_fg_nodes()
375 codec->afg_function_id = function_id & 0xff; in setup_fg_nodes()
376 codec->afg_unsol = (function_id >> 8) & 1; in setup_fg_nodes()
379 codec->mfg = nid; in setup_fg_nodes()
380 codec->mfg_function_id = function_id & 0xff; in setup_fg_nodes()
381 codec->mfg_unsol = (function_id >> 8) & 1; in setup_fg_nodes()
393 int snd_hdac_refresh_widgets(struct hdac_device *codec) in snd_hdac_refresh_widgets() argument
398 nums = snd_hdac_get_sub_nodes(codec, codec->afg, &start_nid); in snd_hdac_refresh_widgets()
400 dev_err(&codec->dev, "cannot read sub nodes for FG 0x%02x\n", in snd_hdac_refresh_widgets()
401 codec->afg); in snd_hdac_refresh_widgets()
405 codec->num_nodes = nums; in snd_hdac_refresh_widgets()
406 codec->start_nid = start_nid; in snd_hdac_refresh_widgets()
407 codec->end_nid = start_nid + nums; in snd_hdac_refresh_widgets()
420 int snd_hdac_refresh_widget_sysfs(struct hdac_device *codec) in snd_hdac_refresh_widget_sysfs() argument
424 if (device_is_registered(&codec->dev)) in snd_hdac_refresh_widget_sysfs()
425 hda_widget_sysfs_exit(codec); in snd_hdac_refresh_widget_sysfs()
426 ret = snd_hdac_refresh_widgets(codec); in snd_hdac_refresh_widget_sysfs()
428 dev_err(&codec->dev, "failed to refresh widget: %d\n", ret); in snd_hdac_refresh_widget_sysfs()
431 if (device_is_registered(&codec->dev)) { in snd_hdac_refresh_widget_sysfs()
432 ret = hda_widget_sysfs_init(codec); in snd_hdac_refresh_widget_sysfs()
434 dev_err(&codec->dev, "failed to init sysfs: %d\n", ret); in snd_hdac_refresh_widget_sysfs()
443 static unsigned int get_num_conns(struct hdac_device *codec, hda_nid_t nid) in get_num_conns() argument
445 unsigned int wcaps = get_wcaps(codec, nid); in get_num_conns()
452 parm = snd_hdac_read_parm(codec, nid, AC_PAR_CONNLIST_LEN); in get_num_conns()
471 int snd_hdac_get_connections(struct hdac_device *codec, hda_nid_t nid, in snd_hdac_get_connections() argument
480 parm = get_num_conns(codec, nid); in snd_hdac_get_connections()
501 err = snd_hdac_read(codec, nid, AC_VERB_GET_CONNECT_LIST, 0, in snd_hdac_get_connections()
518 err = snd_hdac_read(codec, nid, in snd_hdac_get_connections()
527 dev_dbg(&codec->dev, in snd_hdac_get_connections()
536 dev_warn(&codec->dev, in snd_hdac_get_connections()
574 int snd_hdac_power_up(struct hdac_device *codec) in snd_hdac_power_up() argument
576 return pm_runtime_get_sync(&codec->dev); in snd_hdac_power_up()
586 int snd_hdac_power_down(struct hdac_device *codec) in snd_hdac_power_down() argument
588 struct device *dev = &codec->dev; in snd_hdac_power_down()
606 int snd_hdac_power_up_pm(struct hdac_device *codec) in snd_hdac_power_up_pm() argument
608 if (!atomic_inc_not_zero(&codec->in_pm)) in snd_hdac_power_up_pm()
609 return snd_hdac_power_up(codec); in snd_hdac_power_up_pm()
623 int snd_hdac_power_down_pm(struct hdac_device *codec) in snd_hdac_power_down_pm() argument
625 if (atomic_dec_if_positive(&codec->in_pm) < 0) in snd_hdac_power_down_pm()
626 return snd_hdac_power_down(codec); in snd_hdac_power_down_pm()
637 int snd_hdac_link_power(struct hdac_device *codec, bool enable) in snd_hdac_link_power() argument
639 if (!codec->link_power_control) in snd_hdac_link_power()
642 if (codec->bus->ops->link_power) in snd_hdac_link_power()
643 return codec->bus->ops->link_power(codec->bus, enable); in snd_hdac_link_power()
680 static int get_codec_vendor_name(struct hdac_device *codec) in get_codec_vendor_name() argument
683 u16 vendor_id = codec->vendor_id >> 16; in get_codec_vendor_name()
687 codec->vendor_name = kstrdup(c->name, GFP_KERNEL); in get_codec_vendor_name()
688 return codec->vendor_name ? 0 : -ENOMEM; in get_codec_vendor_name()
692 codec->vendor_name = kasprintf(GFP_KERNEL, "Generic %04x", vendor_id); in get_codec_vendor_name()
693 return codec->vendor_name ? 0 : -ENOMEM; in get_codec_vendor_name()
795 static unsigned int query_pcm_param(struct hdac_device *codec, hda_nid_t nid) in query_pcm_param() argument
799 if (nid != codec->afg && in query_pcm_param()
800 (get_wcaps(codec, nid) & AC_WCAP_FORMAT_OVRD)) in query_pcm_param()
801 val = snd_hdac_read_parm(codec, nid, AC_PAR_PCM); in query_pcm_param()
803 val = snd_hdac_read_parm(codec, codec->afg, AC_PAR_PCM); in query_pcm_param()
809 static unsigned int query_stream_param(struct hdac_device *codec, hda_nid_t nid) in query_stream_param() argument
811 unsigned int streams = snd_hdac_read_parm(codec, nid, AC_PAR_STREAM); in query_stream_param()
814 streams = snd_hdac_read_parm(codec, codec->afg, AC_PAR_STREAM); in query_stream_param()
833 int snd_hdac_query_supported_pcm(struct hdac_device *codec, hda_nid_t nid, in snd_hdac_query_supported_pcm() argument
838 wcaps = get_wcaps(codec, nid); in snd_hdac_query_supported_pcm()
839 val = query_pcm_param(codec, nid); in snd_hdac_query_supported_pcm()
848 dev_err(&codec->dev, in snd_hdac_query_supported_pcm()
861 streams = query_stream_param(codec, nid); in snd_hdac_query_supported_pcm()
911 dev_err(&codec->dev, in snd_hdac_query_supported_pcm()
938 bool snd_hdac_is_supported_format(struct hdac_device *codec, hda_nid_t nid, in snd_hdac_is_supported_format() argument
944 val = query_pcm_param(codec, nid); in snd_hdac_is_supported_format()
958 stream = query_stream_param(codec, nid); in snd_hdac_is_supported_format()