Lines Matching refs: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,
47 dev = &codec->dev;
56 codec->bus = bus;
57 codec->addr = addr;
58 codec->type = HDA_DEV_CORE;
59 mutex_init(&codec->widget_lock);
60 mutex_init(&codec->regmap_lock);
61 pm_runtime_set_active(&codec->dev);
62 pm_runtime_get_noresume(&codec->dev);
63 atomic_set(&codec->in_pm, 0);
65 err = snd_hdac_bus_add_device(bus, codec);
70 codec->vendor_id = snd_hdac_read_parm(codec, AC_NODE_ROOT,
72 if (codec->vendor_id == -1) {
76 codec->vendor_id = snd_hdac_read_parm(codec, AC_NODE_ROOT,
80 codec->subsystem_id = snd_hdac_read_parm(codec, AC_NODE_ROOT,
82 codec->revision_id = snd_hdac_read_parm(codec, AC_NODE_ROOT,
85 setup_fg_nodes(codec);
86 if (!codec->afg && !codec->mfg) {
92 fg = codec->afg ? codec->afg : codec->mfg;
94 err = snd_hdac_refresh_widgets(codec);
98 codec->power_caps = snd_hdac_read_parm(codec, fg, AC_PAR_POWER_STATE);
100 if (codec->subsystem_id == -1 || codec->subsystem_id == 0)
101 snd_hdac_read(codec, fg, AC_VERB_GET_SUBSYSTEM_ID, 0,
102 &codec->subsystem_id);
104 err = get_codec_vendor_name(codec);
108 codec->chip_name = kasprintf(GFP_KERNEL, "ID %x",
109 codec->vendor_id & 0xffff);
110 if (!codec->chip_name) {
118 put_device(&codec->dev);
124 * snd_hdac_device_exit - clean up the HD-audio codec base device
125 * @codec: device to clean up
127 void snd_hdac_device_exit(struct hdac_device *codec)
129 pm_runtime_put_noidle(&codec->dev);
131 pm_runtime_set_suspended(&codec->dev);
132 snd_hdac_bus_remove_device(codec->bus, codec);
133 kfree(codec->vendor_name);
134 kfree(codec->chip_name);
139 * snd_hdac_device_register - register the hd-audio codec base device
140 * @codec: the device to register
142 int snd_hdac_device_register(struct hdac_device *codec)
146 err = device_add(&codec->dev);
149 mutex_lock(&codec->widget_lock);
150 err = hda_widget_sysfs_init(codec);
151 mutex_unlock(&codec->widget_lock);
153 device_del(&codec->dev);
162 * snd_hdac_device_unregister - unregister the hd-audio codec base device
163 * @codec: the device to unregister
165 void snd_hdac_device_unregister(struct hdac_device *codec)
167 if (device_is_registered(&codec->dev)) {
168 mutex_lock(&codec->widget_lock);
169 hda_widget_sysfs_exit(codec);
170 mutex_unlock(&codec->widget_lock);
171 device_del(&codec->dev);
172 snd_hdac_bus_remove_device(codec->bus, codec);
178 * snd_hdac_device_set_chip_name - set/update the codec name
179 * @codec: the HDAC device
184 int snd_hdac_device_set_chip_name(struct hdac_device *codec, const char *name)
193 kfree(codec->chip_name);
194 codec->chip_name = newname;
201 * @codec: HDAC device
207 int snd_hdac_codec_modalias(const struct hdac_device *codec, char *buf, size_t size)
210 codec->vendor_id, codec->revision_id, codec->type);
217 * @codec: the codec object
224 static unsigned int snd_hdac_make_cmd(struct hdac_device *codec, hda_nid_t nid,
229 addr = codec->addr;
232 dev_err(&codec->dev, "out of range cmd %x:%x:%x:%x\n",
246 * @codec: the codec object
256 int snd_hdac_exec_verb(struct hdac_device *codec, unsigned int cmd,
259 if (codec->exec_verb)
260 return codec->exec_verb(codec, cmd, flags, res);
261 return snd_hdac_bus_exec_verb(codec->bus, codec->addr, cmd, res);
267 * @codec: the codec object
275 int snd_hdac_read(struct hdac_device *codec, hda_nid_t nid,
278 unsigned int cmd = snd_hdac_make_cmd(codec, nid, verb, parm);
280 return snd_hdac_exec_verb(codec, cmd, 0, res);
286 * @codec: the codec object
293 int _snd_hdac_read_parm(struct hdac_device *codec, hda_nid_t nid, int parm,
299 return snd_hdac_regmap_read_raw(codec, cmd, res);
304 * snd_hdac_read_parm_uncached - read a codec parameter without caching
305 * @codec: the codec object
312 int snd_hdac_read_parm_uncached(struct hdac_device *codec, hda_nid_t nid,
318 if (snd_hdac_regmap_read_raw_uncached(codec, cmd, &val) < 0)
326 * @codec: the codec object
331 int snd_hdac_override_parm(struct hdac_device *codec, hda_nid_t nid,
337 if (!codec->regmap)
340 codec->caps_overwriting = true;
341 err = snd_hdac_regmap_write_raw(codec, verb, val);
342 codec->caps_overwriting = false;
349 * @codec: the codec object
356 int snd_hdac_get_sub_nodes(struct hdac_device *codec, hda_nid_t nid,
361 parm = snd_hdac_read_parm_uncached(codec, nid, AC_PAR_NODE_COUNT);
374 static void setup_fg_nodes(struct hdac_device *codec)
379 total_nodes = snd_hdac_get_sub_nodes(codec, AC_NODE_ROOT, &nid);
381 function_id = snd_hdac_read_parm(codec, nid,
385 codec->afg = nid;
386 codec->afg_function_id = function_id & 0xff;
387 codec->afg_unsol = (function_id >> 8) & 1;
390 codec->mfg = nid;
391 codec->mfg_function_id = function_id & 0xff;
392 codec->mfg_unsol = (function_id >> 8) & 1;
402 * @codec: the codec object
404 int snd_hdac_refresh_widgets(struct hdac_device *codec)
413 mutex_lock(&codec->widget_lock);
414 nums = snd_hdac_get_sub_nodes(codec, codec->afg, &start_nid);
416 dev_err(&codec->dev, "cannot read sub nodes for FG 0x%02x\n",
417 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;
430 mutex_unlock(&codec->widget_lock);
436 static unsigned int get_num_conns(struct hdac_device *codec, hda_nid_t nid)
438 unsigned int wcaps = get_wcaps(codec, nid);
445 parm = snd_hdac_read_parm(codec, nid, AC_PAR_CONNLIST_LEN);
453 * @codec: the codec object
464 int snd_hdac_get_connections(struct hdac_device *codec, hda_nid_t nid,
473 parm = get_num_conns(codec, nid);
494 err = snd_hdac_read(codec, nid, AC_VERB_GET_CONNECT_LIST, 0,
511 err = snd_hdac_read(codec, nid,
520 dev_dbg(&codec->dev,
529 dev_warn(&codec->dev,
558 * snd_hdac_power_up - power up the codec
559 * @codec: the codec object
561 * This function calls the runtime PM helper to power up the given codec.
567 int snd_hdac_power_up(struct hdac_device *codec)
569 return pm_runtime_get_sync(&codec->dev);
574 * snd_hdac_power_down - power down the codec
575 * @codec: the codec object
579 int snd_hdac_power_down(struct hdac_device *codec)
581 struct device *dev = &codec->dev;
589 * snd_hdac_power_up_pm - power up the codec
590 * @codec: the codec object
599 int snd_hdac_power_up_pm(struct hdac_device *codec)
601 if (!atomic_inc_not_zero(&codec->in_pm))
602 return snd_hdac_power_up(codec);
611 int snd_hdac_keep_power_up(struct hdac_device *codec)
613 if (!atomic_inc_not_zero(&codec->in_pm)) {
614 int ret = pm_runtime_get_if_active(&codec->dev, true);
624 * snd_hdac_power_down_pm - power down the codec
625 * @codec: the codec object
632 int snd_hdac_power_down_pm(struct hdac_device *codec)
634 if (atomic_dec_if_positive(&codec->in_pm) < 0)
635 return snd_hdac_power_down(codec);
641 /* codec vendor labels */
673 /* store the codec vendor name */
674 static int get_codec_vendor_name(struct hdac_device *codec)
677 u16 vendor_id = codec->vendor_id >> 16;
681 codec->vendor_name = kstrdup(c->name, GFP_KERNEL);
682 return codec->vendor_name ? 0 : -ENOMEM;
686 codec->vendor_name = kasprintf(GFP_KERNEL, "Generic %04x", vendor_id);
687 return codec->vendor_name ? 0 : -ENOMEM;
789 static unsigned int query_pcm_param(struct hdac_device *codec, hda_nid_t nid)
793 if (nid != codec->afg &&
794 (get_wcaps(codec, nid) & AC_WCAP_FORMAT_OVRD))
795 val = snd_hdac_read_parm(codec, nid, AC_PAR_PCM);
797 val = snd_hdac_read_parm(codec, codec->afg, AC_PAR_PCM);
803 static unsigned int query_stream_param(struct hdac_device *codec, hda_nid_t nid)
805 unsigned int streams = snd_hdac_read_parm(codec, nid, AC_PAR_STREAM);
808 streams = snd_hdac_read_parm(codec, codec->afg, AC_PAR_STREAM);
816 * @codec: the codec object
827 int snd_hdac_query_supported_pcm(struct hdac_device *codec, hda_nid_t nid,
832 wcaps = get_wcaps(codec, nid);
833 val = query_pcm_param(codec, nid);
842 dev_err(&codec->dev,
855 streams = query_stream_param(codec, nid);
889 #if 0 /* FIXME: CS4206 doesn't work, which is the only codec supporting float */
905 dev_err(&codec->dev,
924 * @codec: the codec object
932 bool snd_hdac_is_supported_format(struct hdac_device *codec, hda_nid_t nid,
938 val = query_pcm_param(codec, nid);
952 stream = query_stream_param(codec, nid);
1073 * @codec: the HDAC device
1077 * Return power state or PS_ERROR if codec rejects GET verb.
1079 unsigned int snd_hdac_sync_power_state(struct hdac_device *codec,
1086 state = snd_hdac_codec_read(codec, nid, 0,
1097 /* wait until the codec reachs to the target state */