Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f1b5eee5 authored by qctecmdr's avatar qctecmdr Committed by Gerrit - the friendly Code Review server
Browse files

Merge "ASoC: core: add snd card power state entry"

parents 9ef40e89 6fdf7f1d
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -140,6 +140,7 @@ struct snd_card {
#ifdef CONFIG_PM
	unsigned int power_state;	/* power state */
	wait_queue_head_t power_sleep;
	unsigned long power_change;
#endif

#if IS_ENABLED(CONFIG_SND_MIXER_OSS)
@@ -159,6 +160,9 @@ static inline unsigned int snd_power_get_state(struct snd_card *card)
static inline void snd_power_change_state(struct snd_card *card, unsigned int state)
{
	card->power_state = state;
	/* make sure power is updated prior to wake up */
	wmb();
	xchg(&card->power_change, 1);
	wake_up(&card->power_sleep);
}

+62 −0
Original line number Diff line number Diff line
@@ -139,6 +139,55 @@ static struct snd_info_entry_ops snd_card_state_proc_ops = {
	.poll = snd_card_state_poll,
};

#ifdef CONFIG_PM
static ssize_t snd_card_power_read(struct snd_info_entry *entry,
			void *file_private_data, struct file *file,
			char __user *buf, size_t count, loff_t pos)
{
	int len, err;
	char buffer[SND_CARD_STATE_MAX_LEN];

	err = wait_event_interruptible(entry->card->power_sleep,
			xchg(&entry->card->power_change, 0));
	if (err == -ERESTARTSYS)
		return -EINTR;

	/* make sure power is updated prior to wake up */
	rmb();
	switch (entry->card->power_state) {
	case SNDRV_CTL_POWER_D0:
		len = scnprintf(buffer, sizeof(buffer),
				"%s\n", "D0");
		break;
	case SNDRV_CTL_POWER_D1:
		len = scnprintf(buffer, sizeof(buffer),
				"%s\n", "D1");
		break;
	case SNDRV_CTL_POWER_D2:
		len = scnprintf(buffer, sizeof(buffer),
				"%s\n", "D2");
		break;
	case SNDRV_CTL_POWER_D3hot:
		len = scnprintf(buffer, sizeof(buffer),
				"%s\n", "D3hot");
		break;
	case SNDRV_CTL_POWER_D3cold:
		len = scnprintf(buffer, sizeof(buffer),
				"%s\n", "D3cold");
		break;
	default:
		dev_dbg(entry->card->dev, "unknown power state: 0x%x\n",
				entry->card->power_state);
		return -EIO;
	}
	return simple_read_from_buffer(buf, count, &pos, buffer, len);
}

static struct snd_info_entry_ops snd_card_power_proc_ops = {
	.read = snd_card_power_read,
};
#endif

static int init_info_for_card(struct snd_card *card)
{
	struct snd_info_entry *entry, *entry_state;
@@ -162,6 +211,19 @@ static int init_info_for_card(struct snd_card *card)
	entry_state->content = SNDRV_INFO_CONTENT_DATA;
	entry_state->c.ops = &snd_card_state_proc_ops;

#ifdef CONFIG_PM
	entry_state = snd_info_create_card_entry(card, "power",
						 card->proc_root);
	if (!entry_state) {
		dev_dbg(card->dev, "unable to create card entry power\n");
		card->proc_id = NULL;
		return -ENOMEM;
	}
	entry_state->size = SND_CARD_STATE_MAX_LEN;
	entry_state->content = SNDRV_INFO_CONTENT_DATA;
	entry_state->c.ops = &snd_card_power_proc_ops;
#endif

	return snd_info_card_register(card);
}
#else /* !CONFIG_SND_PROC_FS */