Lines Matching +full:codec +full:- +full:0

1 // SPDX-License-Identifier: GPL-2.0-only
3 * sysfs interface for HD-audio codec
33 struct hda_codec *codec = dev_get_drvdata(dev); in power_on_acct_show() local
34 snd_hda_update_power_acct(codec); in power_on_acct_show()
35 return sysfs_emit(buf, "%u\n", jiffies_to_msecs(codec->power_on_acct)); in power_on_acct_show()
42 struct hda_codec *codec = dev_get_drvdata(dev); in power_off_acct_show() local
43 snd_hda_update_power_acct(codec); in power_off_acct_show()
44 return sysfs_emit(buf, "%u\n", jiffies_to_msecs(codec->power_off_acct)); in power_off_acct_show()
55 struct hda_codec *codec = dev_get_drvdata(dev); \
56 return sysfs_emit(buf, "0x%x\n", codec->field); \
64 struct hda_codec *codec = dev_get_drvdata(dev); \
66 codec->field ? codec->field : ""); \
78 static ssize_t pin_configs_show(struct hda_codec *codec, in pin_configs_show() argument
83 int i, len = 0; in pin_configs_show()
84 mutex_lock(&codec->user_mutex); in pin_configs_show()
86 len += sysfs_emit_at(buf, len, "0x%02x 0x%08x\n", in pin_configs_show()
87 pin->nid, pin->cfg); in pin_configs_show()
89 mutex_unlock(&codec->user_mutex); in pin_configs_show()
97 struct hda_codec *codec = dev_get_drvdata(dev); in init_pin_configs_show() local
98 return pin_configs_show(codec, &codec->init_pins, buf); in init_pin_configs_show()
105 struct hda_codec *codec = dev_get_drvdata(dev); in driver_pin_configs_show() local
106 return pin_configs_show(codec, &codec->driver_pins, buf); in driver_pin_configs_show()
115 static int clear_codec(struct hda_codec *codec) in clear_codec() argument
119 err = snd_hda_codec_reset(codec); in clear_codec()
120 if (err < 0) { in clear_codec()
121 codec_err(codec, "The codec is being used, can't free.\n"); in clear_codec()
124 snd_hda_sysfs_clear(codec); in clear_codec()
125 return 0; in clear_codec()
128 static int reconfig_codec(struct hda_codec *codec) in reconfig_codec() argument
132 snd_hda_power_up(codec); in reconfig_codec()
133 codec_info(codec, "hda-codec: reconfiguring\n"); in reconfig_codec()
134 err = snd_hda_codec_reset(codec); in reconfig_codec()
135 if (err < 0) { in reconfig_codec()
136 codec_err(codec, in reconfig_codec()
137 "The codec is being used, can't reconfigure.\n"); in reconfig_codec()
140 err = device_reprobe(hda_codec_dev(codec)); in reconfig_codec()
141 if (err < 0) in reconfig_codec()
143 err = snd_card_register(codec->card); in reconfig_codec()
145 snd_hda_power_down(codec); in reconfig_codec()
160 *p = 0; in kstrndup_noeol()
169 struct hda_codec *codec = dev_get_drvdata(dev); \
171 int err = kstrtoul(buf, 0, &val); \
172 if (err < 0) \
174 codec->field = val; \
183 struct hda_codec *codec = dev_get_drvdata(dev); \
186 return -ENOMEM; \
187 kfree(codec->field); \
188 codec->field = s; \
204 struct hda_codec *codec = dev_get_drvdata(dev); \
205 int err = 0; \
207 err = type##_codec(codec); \
208 return err < 0 ? err : count; \
218 struct hda_codec *codec = dev_get_drvdata(dev); in init_verbs_show() local
220 int i, len = 0; in init_verbs_show()
221 mutex_lock(&codec->user_mutex); in init_verbs_show()
222 snd_array_for_each(&codec->init_verbs, i, v) { in init_verbs_show()
223 len += sysfs_emit_at(buf, len, "0x%02x 0x%03x 0x%04x\n", in init_verbs_show()
224 v->nid, v->verb, v->param); in init_verbs_show()
226 mutex_unlock(&codec->user_mutex); in init_verbs_show()
230 static int parse_init_verbs(struct hda_codec *codec, const char *buf) in parse_init_verbs() argument
236 return -EINVAL; in parse_init_verbs()
238 return -EINVAL; in parse_init_verbs()
239 mutex_lock(&codec->user_mutex); in parse_init_verbs()
240 v = snd_array_new(&codec->init_verbs); in parse_init_verbs()
242 mutex_unlock(&codec->user_mutex); in parse_init_verbs()
243 return -ENOMEM; in parse_init_verbs()
245 v->nid = nid; in parse_init_verbs()
246 v->verb = verb; in parse_init_verbs()
247 v->param = param; in parse_init_verbs()
248 mutex_unlock(&codec->user_mutex); in parse_init_verbs()
249 return 0; in parse_init_verbs()
256 struct hda_codec *codec = dev_get_drvdata(dev); in init_verbs_store() local
257 int err = parse_init_verbs(codec, buf); in init_verbs_store()
258 if (err < 0) in init_verbs_store()
267 struct hda_codec *codec = dev_get_drvdata(dev); in hints_show() local
269 int i, len = 0; in hints_show()
270 mutex_lock(&codec->user_mutex); in hints_show()
271 snd_array_for_each(&codec->hints, i, hint) { in hints_show()
273 hint->key, hint->val); in hints_show()
275 mutex_unlock(&codec->user_mutex); in hints_show()
279 static struct hda_hint *get_hint(struct hda_codec *codec, const char *key) in get_hint() argument
284 snd_array_for_each(&codec->hints, i, hint) { in get_hint()
285 if (!strcmp(hint->key, key)) in get_hint()
296 p = str + strlen(str) - 1; in remove_trail_spaces()
297 for (; isspace(*p); p--) { in remove_trail_spaces()
298 *p = 0; in remove_trail_spaces()
306 static int parse_hints(struct hda_codec *codec, const char *buf) in parse_hints() argument
310 int err = 0; in parse_hints()
314 return 0; in parse_hints()
316 return -EINVAL; in parse_hints()
319 return -ENOMEM; in parse_hints()
324 return -EINVAL; in parse_hints()
326 *val++ = 0; in parse_hints()
330 mutex_lock(&codec->user_mutex); in parse_hints()
331 hint = get_hint(codec, key); in parse_hints()
334 kfree(hint->key); in parse_hints()
335 hint->key = key; in parse_hints()
336 hint->val = val; in parse_hints()
340 if (codec->hints.used >= MAX_HINTS) in parse_hints()
343 hint = snd_array_new(&codec->hints); in parse_hints()
345 hint->key = key; in parse_hints()
346 hint->val = val; in parse_hints()
348 err = -ENOMEM; in parse_hints()
351 mutex_unlock(&codec->user_mutex); in parse_hints()
361 struct hda_codec *codec = dev_get_drvdata(dev); in hints_store() local
362 int err = parse_hints(codec, buf); in hints_store()
363 if (err < 0) in hints_store()
372 struct hda_codec *codec = dev_get_drvdata(dev); in user_pin_configs_show() local
373 return pin_configs_show(codec, &codec->user_pins, buf); in user_pin_configs_show()
376 static int parse_user_pin_configs(struct hda_codec *codec, const char *buf) in parse_user_pin_configs() argument
381 return -EINVAL; in parse_user_pin_configs()
383 return -EINVAL; in parse_user_pin_configs()
384 mutex_lock(&codec->user_mutex); in parse_user_pin_configs()
385 err = snd_hda_add_pincfg(codec, &codec->user_pins, nid, cfg); in parse_user_pin_configs()
386 mutex_unlock(&codec->user_mutex); in parse_user_pin_configs()
394 struct hda_codec *codec = dev_get_drvdata(dev); in user_pin_configs_store() local
395 int err = parse_user_pin_configs(codec, buf); in user_pin_configs_store()
396 if (err < 0) in user_pin_configs_store()
409 * snd_hda_get_hint - Look for hint string
410 * @codec: the HDA codec
416 const char *snd_hda_get_hint(struct hda_codec *codec, const char *key) in snd_hda_get_hint() argument
418 struct hda_hint *hint = get_hint(codec, key); in snd_hda_get_hint()
419 return hint ? hint->val : NULL; in snd_hda_get_hint()
424 * snd_hda_get_bool_hint - Get a boolean hint value
425 * @codec: the HDA codec
432 int snd_hda_get_bool_hint(struct hda_codec *codec, const char *key) in snd_hda_get_bool_hint() argument
437 mutex_lock(&codec->user_mutex); in snd_hda_get_bool_hint()
438 p = snd_hda_get_hint(codec, key); in snd_hda_get_bool_hint()
440 ret = -ENOENT; in snd_hda_get_bool_hint()
449 ret = 0; in snd_hda_get_bool_hint()
453 mutex_unlock(&codec->user_mutex); in snd_hda_get_bool_hint()
459 * snd_hda_get_int_hint - Get an integer hint value
460 * @codec: the HDA codec
468 int snd_hda_get_int_hint(struct hda_codec *codec, const char *key, int *valp) in snd_hda_get_int_hint() argument
474 mutex_lock(&codec->user_mutex); in snd_hda_get_int_hint()
475 p = snd_hda_get_hint(codec, key); in snd_hda_get_int_hint()
477 ret = -ENOENT; in snd_hda_get_int_hint()
478 else if (kstrtoul(p, 0, &val)) in snd_hda_get_int_hint()
479 ret = -EINVAL; in snd_hda_get_int_hint()
482 ret = 0; in snd_hda_get_int_hint()
484 mutex_unlock(&codec->user_mutex); in snd_hda_get_int_hint()
529 return strncasecmp(a, b, strlen(b)) == 0; in strmatch()
532 /* parse the contents after the line "[codec]"
533 * accept only the line with three numbers, and assign the current codec
539 struct hda_codec *codec; in parse_codec_mode() local
543 list_for_each_codec(codec, bus) { in parse_codec_mode()
544 if ((vendorid <= 0 || codec->core.vendor_id == vendorid) && in parse_codec_mode()
545 (subid <= 0 || codec->core.subsystem_id == subid) && in parse_codec_mode()
546 codec->core.addr == caddr) { in parse_codec_mode()
547 *codecp = codec; in parse_codec_mode()
556 * just pass to the sysfs helper (only when any codec was specified)
579 kfree((*codecp)->modelname); in parse_model_mode()
580 (*codecp)->modelname = kstrdup(buf, GFP_KERNEL); in parse_model_mode()
594 if (!kstrtoul(buf, 0, &val)) \
595 (*codecp)->core.name = val; \
611 .tag = "[codec]",
651 /* check the line starting with '[' -- change the parser mode accordingly */
655 for (i = 0; i < ARRAY_SIZE(patch_items); i++) { in parse_line_mode()
667 * return zero if it reaches to the end of the buffer, or non-zero
681 fw_size--; in get_line_from_fw()
684 return 0; in get_line_from_fw()
686 for (len = 0; len < fw_size; len++) { in get_line_from_fw()
697 *buf = 0; in get_line_from_fw()
698 *fw_size_p = fw_size - len; in get_line_from_fw()
705 * snd_hda_load_patch - load a "patch" firmware file and parse it
706 * @bus: HD-audio bus
713 struct hda_codec *codec; in snd_hda_load_patch() local
717 codec = NULL; in snd_hda_load_patch()
718 while (get_line_from_fw(buf, sizeof(buf) - 1, &fw_size, &fw_buf)) { in snd_hda_load_patch()
724 (codec || line_mode <= LINE_MODE_CODEC)) in snd_hda_load_patch()
725 patch_items[line_mode].parser(buf, bus, &codec); in snd_hda_load_patch()
727 return 0; in snd_hda_load_patch()
767 void snd_hda_sysfs_init(struct hda_codec *codec) in snd_hda_sysfs_init() argument
769 mutex_init(&codec->user_mutex); in snd_hda_sysfs_init()
771 snd_array_init(&codec->init_verbs, sizeof(struct hda_verb), 32); in snd_hda_sysfs_init()
772 snd_array_init(&codec->hints, sizeof(struct hda_hint), 32); in snd_hda_sysfs_init()
773 snd_array_init(&codec->user_pins, sizeof(struct hda_pincfg), 16); in snd_hda_sysfs_init()
777 void snd_hda_sysfs_clear(struct hda_codec *codec) in snd_hda_sysfs_clear() argument
784 snd_array_free(&codec->init_verbs); in snd_hda_sysfs_clear()
786 snd_array_for_each(&codec->hints, i, hint) { in snd_hda_sysfs_clear()
787 kfree(hint->key); /* we don't need to free hint->val */ in snd_hda_sysfs_clear()
789 snd_array_free(&codec->hints); in snd_hda_sysfs_clear()
790 snd_array_free(&codec->user_pins); in snd_hda_sysfs_clear()