Lines Matching full:codec

3  * HD-audio codec core device
18 static void setup_fg_nodes(struct hdac_device *codec);
19 static int get_codec_vendor_name(struct hdac_device *codec);
27 * snd_hdac_device_init - initialize the HD-audio codec base device
28 * @codec: device to initialize
31 * @addr: codec address
40 int snd_hdac_device_init(struct hdac_device *codec, struct hdac_bus *bus, in snd_hdac_device_init() argument
47 dev = &codec->dev; in snd_hdac_device_init()
56 codec->bus = bus; in snd_hdac_device_init()
57 codec->addr = addr; in snd_hdac_device_init()
58 codec->type = HDA_DEV_CORE; in snd_hdac_device_init()
59 mutex_init(&codec->widget_lock); in snd_hdac_device_init()
60 pm_runtime_set_active(&codec->dev); in snd_hdac_device_init()
61 pm_runtime_get_noresume(&codec->dev); in snd_hdac_device_init()
62 atomic_set(&codec->in_pm, 0); in snd_hdac_device_init()
64 err = snd_hdac_bus_add_device(bus, codec); in snd_hdac_device_init()
69 codec->vendor_id = snd_hdac_read_parm(codec, AC_NODE_ROOT, in snd_hdac_device_init()
71 if (codec->vendor_id == -1) { in snd_hdac_device_init()
75 codec->vendor_id = snd_hdac_read_parm(codec, AC_NODE_ROOT, in snd_hdac_device_init()
79 codec->subsystem_id = snd_hdac_read_parm(codec, AC_NODE_ROOT, in snd_hdac_device_init()
81 codec->revision_id = snd_hdac_read_parm(codec, AC_NODE_ROOT, in snd_hdac_device_init()
84 setup_fg_nodes(codec); in snd_hdac_device_init()
85 if (!codec->afg && !codec->mfg) { in snd_hdac_device_init()
91 fg = codec->afg ? codec->afg : codec->mfg; in snd_hdac_device_init()
93 err = snd_hdac_refresh_widgets(codec); in snd_hdac_device_init()
97 codec->power_caps = snd_hdac_read_parm(codec, fg, AC_PAR_POWER_STATE); in snd_hdac_device_init()
99 if (codec->subsystem_id == -1 || codec->subsystem_id == 0) in snd_hdac_device_init()
100 snd_hdac_read(codec, fg, AC_VERB_GET_SUBSYSTEM_ID, 0, in snd_hdac_device_init()
101 &codec->subsystem_id); in snd_hdac_device_init()
103 err = get_codec_vendor_name(codec); in snd_hdac_device_init()
107 codec->chip_name = kasprintf(GFP_KERNEL, "ID %x", in snd_hdac_device_init()
108 codec->vendor_id & 0xffff); in snd_hdac_device_init()
109 if (!codec->chip_name) { in snd_hdac_device_init()
117 put_device(&codec->dev); in snd_hdac_device_init()
123 * snd_hdac_device_exit - clean up the HD-audio codec base device
124 * @codec: device to clean up
126 void snd_hdac_device_exit(struct hdac_device *codec) in snd_hdac_device_exit() argument
128 pm_runtime_put_noidle(&codec->dev); in snd_hdac_device_exit()
129 snd_hdac_bus_remove_device(codec->bus, codec); in snd_hdac_device_exit()
130 kfree(codec->vendor_name); in snd_hdac_device_exit()
131 kfree(codec->chip_name); in snd_hdac_device_exit()
136 * snd_hdac_device_register - register the hd-audio codec base device
137 * codec: the device to register
139 int snd_hdac_device_register(struct hdac_device *codec) in snd_hdac_device_register() argument
143 err = device_add(&codec->dev); in snd_hdac_device_register()
146 mutex_lock(&codec->widget_lock); in snd_hdac_device_register()
147 err = hda_widget_sysfs_init(codec); in snd_hdac_device_register()
148 mutex_unlock(&codec->widget_lock); in snd_hdac_device_register()
150 device_del(&codec->dev); in snd_hdac_device_register()
159 * snd_hdac_device_unregister - unregister the hd-audio codec base device
160 * codec: the device to unregister
162 void snd_hdac_device_unregister(struct hdac_device *codec) in snd_hdac_device_unregister() argument
164 if (device_is_registered(&codec->dev)) { in snd_hdac_device_unregister()
165 mutex_lock(&codec->widget_lock); in snd_hdac_device_unregister()
166 hda_widget_sysfs_exit(codec); in snd_hdac_device_unregister()
167 mutex_unlock(&codec->widget_lock); in snd_hdac_device_unregister()
168 device_del(&codec->dev); in snd_hdac_device_unregister()
169 snd_hdac_bus_remove_device(codec->bus, codec); in snd_hdac_device_unregister()
175 * snd_hdac_device_set_chip_name - set/update the codec name
176 * @codec: the HDAC device
181 int snd_hdac_device_set_chip_name(struct hdac_device *codec, const char *name) in snd_hdac_device_set_chip_name() argument
190 kfree(codec->chip_name); in snd_hdac_device_set_chip_name()
191 codec->chip_name = newname; in snd_hdac_device_set_chip_name()
198 * @codec: HDAC device
204 int snd_hdac_codec_modalias(struct hdac_device *codec, char *buf, size_t size) in snd_hdac_codec_modalias() argument
207 codec->vendor_id, codec->revision_id, codec->type); in snd_hdac_codec_modalias()
214 * @codec: the codec object
221 static unsigned int snd_hdac_make_cmd(struct hdac_device *codec, hda_nid_t nid, in snd_hdac_make_cmd() argument
226 addr = codec->addr; in snd_hdac_make_cmd()
229 dev_err(&codec->dev, "out of range cmd %x:%x:%x:%x\n", in snd_hdac_make_cmd()
243 * @codec: the codec object
253 int snd_hdac_exec_verb(struct hdac_device *codec, unsigned int cmd, in snd_hdac_exec_verb() argument
256 if (codec->exec_verb) in snd_hdac_exec_verb()
257 return codec->exec_verb(codec, cmd, flags, res); in snd_hdac_exec_verb()
258 return snd_hdac_bus_exec_verb(codec->bus, codec->addr, cmd, res); in snd_hdac_exec_verb()
264 * @codec: the codec object
272 int snd_hdac_read(struct hdac_device *codec, hda_nid_t nid, in snd_hdac_read() argument
275 unsigned int cmd = snd_hdac_make_cmd(codec, nid, verb, parm); in snd_hdac_read()
277 return snd_hdac_exec_verb(codec, cmd, 0, res); in snd_hdac_read()
286 int _snd_hdac_read_parm(struct hdac_device *codec, hda_nid_t nid, int parm, in _snd_hdac_read_parm() argument
292 return snd_hdac_regmap_read_raw(codec, cmd, res); in _snd_hdac_read_parm()
297 * snd_hdac_read_parm_uncached - read a codec parameter without caching
298 * @codec: the codec object
305 int snd_hdac_read_parm_uncached(struct hdac_device *codec, hda_nid_t nid, in snd_hdac_read_parm_uncached() argument
311 if (snd_hdac_regmap_read_raw_uncached(codec, cmd, &val) < 0) in snd_hdac_read_parm_uncached()
319 * @codec: the codec object
324 int snd_hdac_override_parm(struct hdac_device *codec, hda_nid_t nid, in snd_hdac_override_parm() argument
330 if (!codec->regmap) in snd_hdac_override_parm()
333 codec->caps_overwriting = true; in snd_hdac_override_parm()
334 err = snd_hdac_regmap_write_raw(codec, verb, val); in snd_hdac_override_parm()
335 codec->caps_overwriting = false; in snd_hdac_override_parm()
342 * @codec: the codec object
349 int snd_hdac_get_sub_nodes(struct hdac_device *codec, hda_nid_t nid, in snd_hdac_get_sub_nodes() argument
354 parm = snd_hdac_read_parm_uncached(codec, nid, AC_PAR_NODE_COUNT); in snd_hdac_get_sub_nodes()
367 static void setup_fg_nodes(struct hdac_device *codec) in setup_fg_nodes() argument
372 total_nodes = snd_hdac_get_sub_nodes(codec, AC_NODE_ROOT, &nid); in setup_fg_nodes()
374 function_id = snd_hdac_read_parm(codec, nid, in setup_fg_nodes()
378 codec->afg = nid; in setup_fg_nodes()
379 codec->afg_function_id = function_id & 0xff; in setup_fg_nodes()
380 codec->afg_unsol = (function_id >> 8) & 1; in setup_fg_nodes()
383 codec->mfg = nid; in setup_fg_nodes()
384 codec->mfg_function_id = function_id & 0xff; in setup_fg_nodes()
385 codec->mfg_unsol = (function_id >> 8) & 1; in setup_fg_nodes()
395 * @codec: the codec object
397 int snd_hdac_refresh_widgets(struct hdac_device *codec) in snd_hdac_refresh_widgets() argument
406 mutex_lock(&codec->widget_lock); in snd_hdac_refresh_widgets()
407 nums = snd_hdac_get_sub_nodes(codec, codec->afg, &start_nid); in snd_hdac_refresh_widgets()
409 dev_err(&codec->dev, "cannot read sub nodes for FG 0x%02x\n", in snd_hdac_refresh_widgets()
410 codec->afg); in snd_hdac_refresh_widgets()
415 err = hda_widget_sysfs_reinit(codec, start_nid, nums); in snd_hdac_refresh_widgets()
419 codec->num_nodes = nums; in snd_hdac_refresh_widgets()
420 codec->start_nid = start_nid; in snd_hdac_refresh_widgets()
421 codec->end_nid = start_nid + nums; in snd_hdac_refresh_widgets()
423 mutex_unlock(&codec->widget_lock); in snd_hdac_refresh_widgets()
429 static unsigned int get_num_conns(struct hdac_device *codec, hda_nid_t nid) in get_num_conns() argument
431 unsigned int wcaps = get_wcaps(codec, nid); in get_num_conns()
438 parm = snd_hdac_read_parm(codec, nid, AC_PAR_CONNLIST_LEN); in get_num_conns()
446 * @codec: the codec object
457 int snd_hdac_get_connections(struct hdac_device *codec, hda_nid_t nid, in snd_hdac_get_connections() argument
466 parm = get_num_conns(codec, nid); in snd_hdac_get_connections()
487 err = snd_hdac_read(codec, nid, AC_VERB_GET_CONNECT_LIST, 0, in snd_hdac_get_connections()
504 err = snd_hdac_read(codec, nid, in snd_hdac_get_connections()
513 dev_dbg(&codec->dev, in snd_hdac_get_connections()
522 dev_warn(&codec->dev, in snd_hdac_get_connections()
551 * snd_hdac_power_up - power up the codec
552 * @codec: the codec object
554 * This function calls the runtime PM helper to power up the given codec.
560 int snd_hdac_power_up(struct hdac_device *codec) in snd_hdac_power_up() argument
562 return pm_runtime_get_sync(&codec->dev); in snd_hdac_power_up()
567 * snd_hdac_power_down - power down the codec
568 * @codec: the codec object
572 int snd_hdac_power_down(struct hdac_device *codec) in snd_hdac_power_down() argument
574 struct device *dev = &codec->dev; in snd_hdac_power_down()
582 * snd_hdac_power_up_pm - power up the codec
583 * @codec: the codec object
592 int snd_hdac_power_up_pm(struct hdac_device *codec) in snd_hdac_power_up_pm() argument
594 if (!atomic_inc_not_zero(&codec->in_pm)) in snd_hdac_power_up_pm()
595 return snd_hdac_power_up(codec); in snd_hdac_power_up_pm()
604 int snd_hdac_keep_power_up(struct hdac_device *codec) in snd_hdac_keep_power_up() argument
606 if (!atomic_inc_not_zero(&codec->in_pm)) { in snd_hdac_keep_power_up()
607 int ret = pm_runtime_get_if_in_use(&codec->dev); in snd_hdac_keep_power_up()
617 * snd_hdac_power_down_pm - power down the codec
618 * @codec: the codec object
625 int snd_hdac_power_down_pm(struct hdac_device *codec) in snd_hdac_power_down_pm() argument
627 if (atomic_dec_if_positive(&codec->in_pm) < 0) in snd_hdac_power_down_pm()
628 return snd_hdac_power_down(codec); in snd_hdac_power_down_pm()
634 /* codec vendor labels */
664 /* store the codec vendor name */
665 static int get_codec_vendor_name(struct hdac_device *codec) in get_codec_vendor_name() argument
668 u16 vendor_id = codec->vendor_id >> 16; in get_codec_vendor_name()
672 codec->vendor_name = kstrdup(c->name, GFP_KERNEL); in get_codec_vendor_name()
673 return codec->vendor_name ? 0 : -ENOMEM; in get_codec_vendor_name()
677 codec->vendor_name = kasprintf(GFP_KERNEL, "Generic %04x", vendor_id); in get_codec_vendor_name()
678 return codec->vendor_name ? 0 : -ENOMEM; in get_codec_vendor_name()
780 static unsigned int query_pcm_param(struct hdac_device *codec, hda_nid_t nid) in query_pcm_param() argument
784 if (nid != codec->afg && in query_pcm_param()
785 (get_wcaps(codec, nid) & AC_WCAP_FORMAT_OVRD)) in query_pcm_param()
786 val = snd_hdac_read_parm(codec, nid, AC_PAR_PCM); in query_pcm_param()
788 val = snd_hdac_read_parm(codec, codec->afg, AC_PAR_PCM); in query_pcm_param()
794 static unsigned int query_stream_param(struct hdac_device *codec, hda_nid_t nid) in query_stream_param() argument
796 unsigned int streams = snd_hdac_read_parm(codec, nid, AC_PAR_STREAM); in query_stream_param()
799 streams = snd_hdac_read_parm(codec, codec->afg, AC_PAR_STREAM); in query_stream_param()
807 * @codec: the codec object
818 int snd_hdac_query_supported_pcm(struct hdac_device *codec, hda_nid_t nid, in snd_hdac_query_supported_pcm() argument
823 wcaps = get_wcaps(codec, nid); in snd_hdac_query_supported_pcm()
824 val = query_pcm_param(codec, nid); in snd_hdac_query_supported_pcm()
833 dev_err(&codec->dev, in snd_hdac_query_supported_pcm()
846 streams = query_stream_param(codec, nid); in snd_hdac_query_supported_pcm()
880 #if 0 /* FIXME: CS4206 doesn't work, which is the only codec supporting float */ in snd_hdac_query_supported_pcm()
896 dev_err(&codec->dev, in snd_hdac_query_supported_pcm()
915 * @codec: the codec object
923 bool snd_hdac_is_supported_format(struct hdac_device *codec, hda_nid_t nid, in snd_hdac_is_supported_format() argument
929 val = query_pcm_param(codec, nid); in snd_hdac_is_supported_format()
943 stream = query_stream_param(codec, nid); in snd_hdac_is_supported_format()
1068 * Return power state or PS_ERROR if codec rejects GET verb.
1070 unsigned int snd_hdac_sync_power_state(struct hdac_device *codec, in snd_hdac_sync_power_state() argument
1077 state = snd_hdac_codec_read(codec, nid, 0, in snd_hdac_sync_power_state()
1088 /* wait until the codec reachs to the target state */ in snd_hdac_sync_power_state()