Lines Matching full:codec
3 * HD-audio codec core device
19 static void setup_fg_nodes(struct hdac_device *codec);
20 static int get_codec_vendor_name(struct hdac_device *codec);
28 * snd_hdac_device_init - initialize the HD-audio codec base device
29 * @codec: device to initialize
32 * @addr: codec address
41 int snd_hdac_device_init(struct hdac_device *codec, struct hdac_bus *bus,
48 dev = &codec->dev;
57 codec->bus = bus;
58 codec->addr = addr;
59 codec->type = HDA_DEV_CORE;
60 mutex_init(&codec->widget_lock);
61 mutex_init(&codec->regmap_lock);
62 pm_runtime_set_active(&codec->dev);
63 pm_runtime_get_noresume(&codec->dev);
64 atomic_set(&codec->in_pm, 0);
66 err = snd_hdac_bus_add_device(bus, codec);
71 codec->vendor_id = snd_hdac_read_parm(codec, AC_NODE_ROOT,
73 if (codec->vendor_id == -1) {
77 codec->vendor_id = snd_hdac_read_parm(codec, AC_NODE_ROOT,
81 codec->subsystem_id = snd_hdac_read_parm(codec, AC_NODE_ROOT,
83 codec->revision_id = snd_hdac_read_parm(codec, AC_NODE_ROOT,
86 setup_fg_nodes(codec);
87 if (!codec->afg && !codec->mfg) {
93 fg = codec->afg ? codec->afg : codec->mfg;
95 err = snd_hdac_refresh_widgets(codec);
99 codec->power_caps = snd_hdac_read_parm(codec, fg, AC_PAR_POWER_STATE);
101 if (codec->subsystem_id == -1 || codec->subsystem_id == 0)
102 snd_hdac_read(codec, fg, AC_VERB_GET_SUBSYSTEM_ID, 0,
103 &codec->subsystem_id);
105 err = get_codec_vendor_name(codec);
109 codec->chip_name = kasprintf(GFP_KERNEL, "ID %x",
110 codec->vendor_id & 0xffff);
111 if (!codec->chip_name) {
119 put_device(&codec->dev);
125 * snd_hdac_device_exit - clean up the HD-audio codec base device
126 * @codec: device to clean up
128 void snd_hdac_device_exit(struct hdac_device *codec)
130 pm_runtime_put_noidle(&codec->dev);
132 pm_runtime_set_suspended(&codec->dev);
133 snd_hdac_bus_remove_device(codec->bus, codec);
134 kfree(codec->vendor_name);
135 kfree(codec->chip_name);
140 * snd_hdac_device_register - register the hd-audio codec base device
141 * @codec: the device to register
143 int snd_hdac_device_register(struct hdac_device *codec)
147 err = device_add(&codec->dev);
150 scoped_guard(mutex, &codec->widget_lock) {
151 err = hda_widget_sysfs_init(codec);
154 device_del(&codec->dev);
163 * snd_hdac_device_unregister - unregister the hd-audio codec base device
164 * @codec: the device to unregister
166 void snd_hdac_device_unregister(struct hdac_device *codec)
168 if (device_is_registered(&codec->dev)) {
169 scoped_guard(mutex, &codec->widget_lock) {
170 hda_widget_sysfs_exit(codec);
172 device_del(&codec->dev);
173 snd_hdac_bus_remove_device(codec->bus, codec);
179 * snd_hdac_device_set_chip_name - set/update the codec name
180 * @codec: the HDAC device
185 int snd_hdac_device_set_chip_name(struct hdac_device *codec, const char *name)
194 kfree(codec->chip_name);
195 codec->chip_name = newname;
202 * @codec: HDAC device
208 int snd_hdac_codec_modalias(const struct hdac_device *codec, char *buf, size_t size)
211 codec->vendor_id, codec->revision_id, codec->type);
218 * @codec: the codec object
225 static unsigned int snd_hdac_make_cmd(struct hdac_device *codec, hda_nid_t nid,
230 addr = codec->addr;
233 dev_err(&codec->dev, "out of range cmd %x:%x:%x:%x\n",
247 * @codec: the codec object
257 int snd_hdac_exec_verb(struct hdac_device *codec, unsigned int cmd,
260 if (codec->exec_verb)
261 return codec->exec_verb(codec, cmd, flags, res);
262 return snd_hdac_bus_exec_verb(codec->bus, codec->addr, cmd, res);
268 * @codec: the codec object
276 int snd_hdac_read(struct hdac_device *codec, hda_nid_t nid,
279 unsigned int cmd = snd_hdac_make_cmd(codec, nid, verb, parm);
281 return snd_hdac_exec_verb(codec, cmd, 0, res);
287 * @codec: the codec object
294 int _snd_hdac_read_parm(struct hdac_device *codec, hda_nid_t nid, int parm,
300 return snd_hdac_regmap_read_raw(codec, cmd, res);
305 * snd_hdac_read_parm_uncached - read a codec parameter without caching
306 * @codec: the codec object
313 int snd_hdac_read_parm_uncached(struct hdac_device *codec, hda_nid_t nid,
319 if (snd_hdac_regmap_read_raw_uncached(codec, cmd, &val) < 0)
327 * @codec: the codec object
332 int snd_hdac_override_parm(struct hdac_device *codec, hda_nid_t nid,
338 if (!codec->regmap)
341 codec->caps_overwriting = true;
342 err = snd_hdac_regmap_write_raw(codec, verb, val);
343 codec->caps_overwriting = false;
350 * @codec: the codec object
357 int snd_hdac_get_sub_nodes(struct hdac_device *codec, hda_nid_t nid,
362 parm = snd_hdac_read_parm_uncached(codec, nid, AC_PAR_NODE_COUNT);
375 static void setup_fg_nodes(struct hdac_device *codec)
380 total_nodes = snd_hdac_get_sub_nodes(codec, AC_NODE_ROOT, &nid);
382 function_id = snd_hdac_read_parm(codec, nid,
386 codec->afg = nid;
387 codec->afg_function_id = function_id & 0xff;
388 codec->afg_unsol = (function_id >> 8) & 1;
391 codec->mfg = nid;
392 codec->mfg_function_id = function_id & 0xff;
393 codec->mfg_unsol = (function_id >> 8) & 1;
403 * @codec: the codec object
405 int snd_hdac_refresh_widgets(struct hdac_device *codec)
414 guard(mutex)(&codec->widget_lock);
415 nums = snd_hdac_get_sub_nodes(codec, codec->afg, &start_nid);
417 dev_err(&codec->dev, "cannot read sub nodes for FG 0x%02x\n",
418 codec->afg);
422 err = hda_widget_sysfs_reinit(codec, start_nid, nums);
426 codec->num_nodes = nums;
427 codec->start_nid = start_nid;
428 codec->end_nid = start_nid + nums;
434 static unsigned int get_num_conns(struct hdac_device *codec, hda_nid_t nid)
436 unsigned int wcaps = snd_hdac_get_wcaps(codec, nid);
443 parm = snd_hdac_read_parm(codec, nid, AC_PAR_CONNLIST_LEN);
451 * @codec: the codec object
462 int snd_hdac_get_connections(struct hdac_device *codec, hda_nid_t nid,
471 parm = get_num_conns(codec, nid);
492 err = snd_hdac_read(codec, nid, AC_VERB_GET_CONNECT_LIST, 0,
509 err = snd_hdac_read(codec, nid,
518 dev_dbg(&codec->dev,
527 dev_warn(&codec->dev,
556 * snd_hdac_power_up - power up the codec
557 * @codec: the codec object
559 * This function calls the runtime PM helper to power up the given codec.
565 int snd_hdac_power_up(struct hdac_device *codec)
567 return pm_runtime_get_sync(&codec->dev);
572 * snd_hdac_power_down - power down the codec
573 * @codec: the codec object
577 int snd_hdac_power_down(struct hdac_device *codec)
579 struct device *dev = &codec->dev;
586 * snd_hdac_power_up_pm - power up the codec
587 * @codec: the codec object
596 int snd_hdac_power_up_pm(struct hdac_device *codec)
598 if (!atomic_inc_not_zero(&codec->in_pm))
599 return snd_hdac_power_up(codec);
608 int snd_hdac_keep_power_up(struct hdac_device *codec)
610 if (!atomic_inc_not_zero(&codec->in_pm)) {
611 int ret = pm_runtime_get_if_active(&codec->dev);
621 * snd_hdac_power_down_pm - power down the codec
622 * @codec: the codec object
629 int snd_hdac_power_down_pm(struct hdac_device *codec)
631 if (atomic_dec_if_positive(&codec->in_pm) < 0)
632 return snd_hdac_power_down(codec);
638 /* codec vendor labels */
671 /* store the codec vendor name */
672 static int get_codec_vendor_name(struct hdac_device *codec)
675 u16 vendor_id = codec->vendor_id >> 16;
679 codec->vendor_name = kstrdup(c->name, GFP_KERNEL);
680 return codec->vendor_name ? 0 : -ENOMEM;
684 codec->vendor_name = kasprintf(GFP_KERNEL, "Generic %04x", vendor_id);
685 return codec->vendor_name ? 0 : -ENOMEM;
849 static unsigned int query_pcm_param(struct hdac_device *codec, hda_nid_t nid)
853 if (nid != codec->afg &&
854 (snd_hdac_get_wcaps(codec, nid) & AC_WCAP_FORMAT_OVRD))
855 val = snd_hdac_read_parm(codec, nid, AC_PAR_PCM);
857 val = snd_hdac_read_parm(codec, codec->afg, AC_PAR_PCM);
863 static unsigned int query_stream_param(struct hdac_device *codec, hda_nid_t nid)
865 unsigned int streams = snd_hdac_read_parm(codec, nid, AC_PAR_STREAM);
868 streams = snd_hdac_read_parm(codec, codec->afg, AC_PAR_STREAM);
876 * @codec: the codec object
888 int snd_hdac_query_supported_pcm(struct hdac_device *codec, hda_nid_t nid,
894 wcaps = snd_hdac_get_wcaps(codec, nid);
895 val = query_pcm_param(codec, nid);
904 dev_err(&codec->dev,
918 streams = query_stream_param(codec, nid);
952 #if 0 /* FIXME: CS4206 doesn't work, which is the only codec supporting float */
968 dev_err(&codec->dev,
989 * @codec: the codec object
997 bool snd_hdac_is_supported_format(struct hdac_device *codec, hda_nid_t nid,
1003 val = query_pcm_param(codec, nid);
1017 stream = query_stream_param(codec, nid);
1138 * @codec: the HDAC device
1142 * Return power state or PS_ERROR if codec rejects GET verb.
1144 unsigned int snd_hdac_sync_power_state(struct hdac_device *codec,
1151 state = snd_hdac_codec_read(codec, nid, 0,
1162 /* wait until the codec reachs to the target state */