sound/soc/codecs/rt700.c

Source file repositories/reference/linux-study-clean/sound/soc/codecs/rt700.c

File Facts

System
Linux kernel
Corpus path
sound/soc/codecs/rt700.c
Extension
.c
Size
32676 bytes
Lines
1236
Domain
Driver Families
Bucket
sound/soc
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

if (rt700->jack_type == 0) {
			ret = rt700_headset_detect(rt700);
			if (ret < 0)
				return;
			if (rt700->jack_type == SND_JACK_HEADSET)
				btn_type = rt700_button_detect(rt700);
		} else if (rt700->jack_type == SND_JACK_HEADSET) {
			/* jack is already in, report button event */
			btn_type = rt700_button_detect(rt700);
		}
	} else {
		/* jack out */
		rt700->jack_type = 0;
	}

	dev_dbg(&rt700->slave->dev,
		"in %s, jack_type=0x%x\n", __func__, rt700->jack_type);
	dev_dbg(&rt700->slave->dev,
		"in %s, btn_type=0x%x\n", __func__, btn_type);

	snd_soc_jack_report(rt700->hs_jack, rt700->jack_type | btn_type,
			SND_JACK_HEADSET |
			SND_JACK_BTN_0 | SND_JACK_BTN_1 |
			SND_JACK_BTN_2 | SND_JACK_BTN_3);

	if (btn_type) {
		/* button released */
		snd_soc_jack_report(rt700->hs_jack, rt700->jack_type,
			SND_JACK_HEADSET |
			SND_JACK_BTN_0 | SND_JACK_BTN_1 |
			SND_JACK_BTN_2 | SND_JACK_BTN_3);

		mod_delayed_work(system_power_efficient_wq,
			&rt700->jack_btn_check_work, msecs_to_jiffies(200));
	}

	return;

io_error:
	pr_err_ratelimited("IO error in %s, ret %d\n", __func__, ret);
}

static void rt700_btn_check_handler(struct work_struct *work)
{
	struct rt700_priv *rt700 = container_of(work, struct rt700_priv,
		jack_btn_check_work.work);
	int btn_type = 0, ret;
	unsigned int jack_status = 0, reg;

	reg = RT700_VERB_GET_PIN_SENSE | RT700_HP_OUT;
	ret = regmap_read(rt700->regmap, reg, &jack_status);
	if (ret < 0)
		goto io_error;

	/* pin attached */
	if (jack_status & (1 << 31)) {
		if (rt700->jack_type == SND_JACK_HEADSET) {
			/* jack is already in, report button event */
			btn_type = rt700_button_detect(rt700);
		}
	} else {
		rt700->jack_type = 0;
	}

	/* cbj comparator */
	ret = rt700_index_read(rt700->regmap, RT700_COMBO_JACK_AUTO_CTL2, &reg);
	if (ret < 0)
		goto io_error;

	if ((reg & 0xf0) == 0xf0)
		btn_type = 0;

	dev_dbg(&rt700->slave->dev,
		"%s, btn_type=0x%x\n",	__func__, btn_type);
	snd_soc_jack_report(rt700->hs_jack, rt700->jack_type | btn_type,
			SND_JACK_HEADSET |
			SND_JACK_BTN_0 | SND_JACK_BTN_1 |
			SND_JACK_BTN_2 | SND_JACK_BTN_3);

	if (btn_type) {
		/* button released */
		snd_soc_jack_report(rt700->hs_jack, rt700->jack_type,
			SND_JACK_HEADSET |
			SND_JACK_BTN_0 | SND_JACK_BTN_1 |
			SND_JACK_BTN_2 | SND_JACK_BTN_3);

		mod_delayed_work(system_power_efficient_wq,
			&rt700->jack_btn_check_work, msecs_to_jiffies(200));
	}

Annotation

Implementation Notes