コード例 #1
0
static int snd_bcm2835_pcm_lib_ioctl(struct snd_pcm_substream *substream,
				     unsigned int cmd, void *arg)
{
	int ret = snd_pcm_lib_ioctl(substream, cmd, arg);
	audio_info(" .. substream=%p, cmd=%d, arg=%p (%x) ret=%d\n", substream,
		    cmd, arg, arg ? *(unsigned *)arg : 0, ret);
	return ret;
}
コード例 #2
0
ファイル: cx18-alsa-pcm.c プロジェクト: acton393/linux
static int snd_cx18_pcm_ioctl(struct snd_pcm_substream *substream,
		     unsigned int cmd, void *arg)
{
	struct snd_cx18_card *cxsc = snd_pcm_substream_chip(substream);
	int ret;

	snd_cx18_lock(cxsc);
	ret = snd_pcm_lib_ioctl(substream, cmd, arg);
	snd_cx18_unlock(cxsc);
	return ret;
}
コード例 #3
0
ファイル: ivtv-alsa-pcm.c プロジェクト: 168519/linux
static int snd_ivtv_pcm_ioctl(struct snd_pcm_substream *substream,
		     unsigned int cmd, void *arg)
{
	struct snd_ivtv_card *itvsc = snd_pcm_substream_chip(substream);
	int ret;

	snd_ivtv_lock(itvsc);
	ret = snd_pcm_lib_ioctl(substream, cmd, arg);
	snd_ivtv_unlock(itvsc);
	return ret;
}
コード例 #4
0
static int msm_pcm_ioctl(struct snd_pcm_substream *substream,
			 unsigned int cmd, void *arg)
{
	struct snd_pcm_runtime *runtime = substream->runtime;
	struct msm_voice *prtd = runtime->private_data;
	uint32_t session_id = get_session_id(prtd);
	enum voice_lch_mode lch_mode;
	int ret = 0;

	switch (cmd) {
	case SNDRV_VOICE_IOCTL_LCH:
		if (copy_from_user(&lch_mode, (void *)arg,
				   sizeof(enum voice_lch_mode))) {
			pr_err("%s: Copy from user failed, size %d\n", __func__,
			       sizeof(enum voice_lch_mode));

			ret = -EFAULT;
			break;
		}

		pr_debug("%s: %s lch_mode:%d\n",
			 __func__, substream->pcm->id, lch_mode);

		switch (lch_mode) {
		case VOICE_LCH_START:
		case VOICE_LCH_STOP:
			ret = voc_set_lch(session_id, lch_mode);
			break;

		default:
			pr_err("%s: Invalid LCH MODE %d\n", __func__, lch_mode);

			ret = -EFAULT;
		}

		break;
	default:
		pr_debug("%s: Falling into default snd_lib_ioctl cmd 0x%x\n",
			 __func__, cmd);

		ret = snd_pcm_lib_ioctl(substream, cmd, arg);
		break;
	}

	if (!ret)
		pr_debug("%s: ret %d\n", __func__, ret);
	else
		pr_err("%s: cmd 0x%x failed %d\n", __func__, cmd, ret);

	return ret;
}
コード例 #5
0
static int msm_lsm_ioctl_shared(struct snd_pcm_substream *substream,
			 unsigned int cmd, void *arg)
{
	unsigned long flags;
	int ret;
	struct snd_lsm_sound_model snd_model;
	struct snd_lsm_sound_model_v2 snd_model_v2;
	struct snd_lsm_session_data session_data;
	int rc = 0;
	int xchg = 0;
	u32 size = 0;
	struct snd_pcm_runtime *runtime = substream->runtime;
	struct lsm_priv *prtd = runtime->private_data;
	struct snd_lsm_event_status *user = arg;
	struct snd_lsm_detection_params det_params;
	uint8_t *confidence_level = NULL;

	pr_debug("%s: enter cmd %x\n", __func__, cmd);
	switch (cmd) {
	case SNDRV_LSM_SET_SESSION_DATA:
		pr_debug("%s: set Session data\n", __func__);
		memcpy(&session_data, arg,
		       sizeof(struct snd_lsm_session_data));
		if (prtd) {
			if (session_data.app_id <= LSM_VOICE_WAKEUP_APP_ID_V2
			    && session_data.app_id > 0)
				prtd->lsm_client->app_id = session_data.app_id;
			else {
				pr_err("%s:Invalid App id for Listen client\n",
				       __func__);
				rc = -EINVAL;
			}
		} else {
			pr_err("%s: LSM Priv data is NULL\n", __func__);
			rc = -EINVAL;
		}
		break;
	case SNDRV_LSM_REG_SND_MODEL_V2:
		pr_debug("%s: Registering sound model V2\n", __func__);
		memcpy(&snd_model_v2, arg,
		       sizeof(struct snd_lsm_sound_model_v2));
		if (snd_model_v2.num_confidence_levels >
		    MAX_NUM_CONFIDENCE) {
			pr_err("%s: Invalid conf_levels = %d, maximum allowed = %d\n",
				__func__, snd_model_v2.num_confidence_levels,
				MAX_NUM_CONFIDENCE);
			rc = -EINVAL;
			break;
		}

		prtd->lsm_client->snd_model_ver_inuse = SND_MODEL_IN_USE_V2;
		rc = q6lsm_snd_model_buf_alloc(prtd->lsm_client,
					       snd_model_v2.data_size);
		if (rc) {
			pr_err("%s: q6lsm buffer alloc failed V2, size %d\n",
			       __func__, snd_model_v2.data_size);
			break;
		}
		if (copy_from_user(prtd->lsm_client->sound_model.data,
			   snd_model_v2.data, snd_model_v2.data_size)) {
			pr_err("%s: copy from user data failed\n"
			       "data %p size %d\n", __func__,
			       snd_model_v2.data, snd_model_v2.data_size);
			rc = -EFAULT;
		}

		pr_debug("SND Model Magic no byte[0] %x,\n"
			 "byte[1] %x, byte[2] %x byte[3] %x\n",
			 snd_model_v2.data[0], snd_model_v2.data[1],
			 snd_model_v2.data[2], snd_model_v2.data[3]);

		prtd->lsm_client->num_confidence_levels =
			snd_model_v2.num_confidence_levels;

		rc = msm_lsm_get_conf_levels(prtd->lsm_client,
				snd_model_v2.confidence_level);
		if (rc) {
			pr_err("%s: get_conf_levels failed, err = %d\n",
				__func__, rc);
			break;
		}

		rc = q6lsm_register_sound_model(prtd->lsm_client,
					snd_model_v2.detection_mode,
					snd_model_v2.detect_failure);
		if (rc < 0) {
			pr_err("%s: Register snd Model v2 failed =%d\n",
			       __func__, rc);
			kfree(confidence_level);
			q6lsm_snd_model_buf_free(prtd->lsm_client);
		}

		kfree(prtd->lsm_client->confidence_levels);
		prtd->lsm_client->confidence_levels = NULL;
		break;

	case SNDRV_LSM_SET_PARAMS:
		if (!arg) {
			pr_err("%s: %s Invalid argument\n",
				__func__, "SNDRV_LSM_SET_PARAMS");
			return -EINVAL;
		}

		memcpy(&det_params, arg,
			sizeof(det_params));
		if (det_params.num_confidence_levels >
		    MAX_NUM_CONFIDENCE) {
			rc = -EINVAL;
			break;
		}

		prtd->lsm_client->num_confidence_levels =
			det_params.num_confidence_levels;

		rc = msm_lsm_get_conf_levels(prtd->lsm_client,
				det_params.conf_level);
		if (rc) {
			pr_err("%s: Failed to get conf_levels, err = %d\n",
				__func__, rc);
			break;
		}

		rc = q6lsm_set_data(prtd->lsm_client,
			       det_params.detect_mode,
			       det_params.detect_failure);
		if (rc)
			pr_err("%s: Failed to set params, err = %d\n",
				__func__, rc);

		kfree(prtd->lsm_client->confidence_levels);
		prtd->lsm_client->confidence_levels = NULL;

		break;

	case SNDRV_LSM_REG_SND_MODEL:
		pr_debug("%s: Registering sound model\n", __func__);
		memcpy(&snd_model, arg, sizeof(struct snd_lsm_sound_model));
		prtd->lsm_client->snd_model_ver_inuse = SND_MODEL_IN_USE_V1;
		rc = q6lsm_snd_model_buf_alloc(prtd->lsm_client,
					       snd_model.data_size);
		if (rc) {
			pr_err("%s: q6lsm buffer alloc failed, size %d\n",
			       __func__, snd_model.data_size);
			break;
		}

		if (copy_from_user(prtd->lsm_client->sound_model.data,
				   snd_model.data, snd_model.data_size)) {
			pr_err("%s: copy from user data failed data %p size %d\n",
			       __func__, snd_model.data, snd_model.data_size);
			rc = -EFAULT;
			break;
		}
		rc = q6lsm_set_kw_sensitivity_level(prtd->lsm_client,
						snd_model.min_keyw_confidence,
						snd_model.min_user_confidence);
		if (rc) {
			pr_err("%s: Error in KW sensitivity %x", __func__, rc);
			break;
		}

		rc = q6lsm_register_sound_model(prtd->lsm_client,
						snd_model.detection_mode,
						snd_model.detect_failure);
		if (rc < 0) {
			pr_err("%s: q6lsm_register_sound_model failed =%d\n",
			       __func__, rc);
			q6lsm_snd_model_buf_free(prtd->lsm_client);
		}

		break;

	case SNDRV_LSM_DEREG_SND_MODEL:
		pr_debug("%s: Deregistering sound model\n", __func__);
		rc = q6lsm_deregister_sound_model(prtd->lsm_client);
		break;

	case SNDRV_LSM_EVENT_STATUS:
		pr_debug("%s: Get event status\n", __func__);
		atomic_set(&prtd->event_wait_stop, 0);
		rc = wait_event_interruptible(prtd->event_wait,
				(cmpxchg(&prtd->event_avail, 1, 0) ||
				 (xchg = atomic_cmpxchg(&prtd->event_wait_stop,
							1, 0))));
		pr_debug("%s: wait_event_interruptible %d event_wait_stop %d\n",
			 __func__, rc, xchg);
		if (!rc && !xchg) {
			pr_debug("%s: New event available %ld\n", __func__,
				 prtd->event_avail);
			spin_lock_irqsave(&prtd->event_lock, flags);
			if (prtd->event_status)
				size = sizeof(*(prtd->event_status)) +
				prtd->event_status->payload_size;
			spin_unlock_irqrestore(&prtd->event_lock, flags);
			if (user->payload_size <
			    prtd->event_status->payload_size) {
				pr_debug("%s: provided %dbytes isn't enough, needs %dbytes\n",
					 __func__, user->payload_size,
					 prtd->event_status->payload_size);
				rc = -ENOMEM;
			} else
				memcpy(user, prtd->event_status, size);
		} else if (xchg) {
			pr_debug("%s: Wait aborted\n", __func__);
			rc = 0;
		}
		break;

	case SNDRV_LSM_ABORT_EVENT:
		pr_debug("%s: Aborting event status wait\n", __func__);
		atomic_set(&prtd->event_wait_stop, 1);
		wake_up(&prtd->event_wait);
		break;

	case SNDRV_LSM_START:
		pr_debug("%s: Starting LSM client session\n", __func__);
		if (!prtd->lsm_client->started) {
			ret = q6lsm_start(prtd->lsm_client, true);
			if (!ret) {
				prtd->lsm_client->started = true;
				pr_debug("%s: LSM client session started\n",
					 __func__);
			}
		}
		break;

	case SNDRV_LSM_STOP:
		pr_debug("%s: Stopping LSM client session\n", __func__);
		if (prtd->lsm_client->started) {
			ret = q6lsm_stop(prtd->lsm_client, true);
			if (!ret)
				pr_debug("%s: LSM client session stopped %d\n",
					 __func__, ret);
			prtd->lsm_client->started = false;
		}
		break;

	default:
		pr_debug("%s: Falling into default snd_lib_ioctl cmd 0x%x\n",
			 __func__, cmd);
		rc = snd_pcm_lib_ioctl(substream, cmd, arg);
		break;
	}

	if (!rc)
		pr_debug("%s: leave (%d)\n", __func__, rc);
	else
		pr_err("%s: cmd 0x%x failed %d\n", __func__, cmd, rc);

	return rc;
}
コード例 #6
0
ファイル: cobalt-alsa-pcm.c プロジェクト: AlexShiLucky/linux
static int snd_cobalt_pcm_ioctl(struct snd_pcm_substream *substream,
		     unsigned int cmd, void *arg)
{
	return snd_pcm_lib_ioctl(substream, cmd, arg);
}
コード例 #7
0
static int msm_lsm_ioctl(struct snd_pcm_substream *substream,
			 unsigned int cmd, void *arg)
{
	unsigned long flags;
	int ret;
	struct snd_lsm_sound_model snd_model;
	int rc = 0;
	int xchg = 0;
	int size = 0;
	struct snd_lsm_event_status *event_status = NULL;
	struct snd_pcm_runtime *runtime = substream->runtime;
	struct lsm_priv *prtd = runtime->private_data;
	struct snd_lsm_event_status *user = arg;

	pr_debug("%s: enter cmd %x\n", __func__, cmd);
	switch (cmd) {
	case SNDRV_LSM_REG_SND_MODEL:
		pr_debug("%s: Registering sound model\n", __func__);
		if (copy_from_user(&snd_model, (void *)arg,
				   sizeof(struct snd_lsm_sound_model))) {
			rc = -EFAULT;
			pr_err("%s: copy from user failed, size %d\n", __func__,
			       sizeof(struct snd_lsm_sound_model));
			break;
		}

		rc = q6lsm_snd_model_buf_alloc(prtd->lsm_client,
					       snd_model.data_size);
		if (rc) {
			pr_err("%s: q6lsm buffer alloc failed, size %d\n",
			       __func__, snd_model.data_size);
			break;
		}

		if (copy_from_user(prtd->lsm_client->sound_model.data,
				   snd_model.data, snd_model.data_size)) {
			pr_err("%s: copy from user data failed data %p size %d\n",
			       __func__, snd_model.data, snd_model.data_size);
			rc = -EFAULT;
			break;
		}

		rc = q6lsm_register_sound_model(prtd->lsm_client,
						snd_model.detection_mode,
						snd_model.min_keyw_confidence,
						snd_model.min_user_confidence,
						snd_model.detect_failure);
		if (rc < 0)
			pr_err("%s: q6lsm_register_sound_model failed =%d\n",
			       __func__, rc);
		break;

	case SNDRV_LSM_DEREG_SND_MODEL:
		pr_debug("%s: Deregistering sound model\n", __func__);
		rc = q6lsm_deregister_sound_model(prtd->lsm_client);
		break;

	case SNDRV_LSM_EVENT_STATUS:
		pr_debug("%s: Get event status\n", __func__);
		atomic_set(&prtd->event_wait_stop, 0);
		rc = wait_event_interruptible(prtd->event_wait,
				(cmpxchg(&prtd->event_avail, 1, 0) ||
				 (xchg = atomic_cmpxchg(&prtd->event_wait_stop,
							1, 0))));
		pr_debug("%s: wait_event_interruptible %d event_wait_stop %d\n",
			 __func__, rc, xchg);
		if (!rc && !xchg) {
			pr_debug("%s: New event available %ld\n", __func__,
				 prtd->event_avail);
			spin_lock_irqsave(&prtd->event_lock, flags);
			if (prtd->event_status) {
				size = sizeof(*event_status) +
				       prtd->event_status->payload_size;
				event_status = kmemdup(prtd->event_status, size,
						       GFP_ATOMIC);
			}
			spin_unlock_irqrestore(&prtd->event_lock, flags);
			if (!event_status) {
				pr_err("%s: Couldn't allocate %d bytes\n",
				       __func__, size);
				/*
				 * Don't use -ENOMEM as userspace will check
				 * it for increasing buffer
				 */
				rc = -EFAULT;
			} else {
				if (user->payload_size <
				    event_status->payload_size) {
					pr_debug("%s: provided %dbytes isn't enough, needs %dbytes\n",
						 __func__, user->payload_size,
						 size);
					rc = -ENOMEM;
				} else if (!access_ok(VERIFY_WRITE, arg,
						      size)) {
					rc = -EFAULT;
				} else {
					rc = copy_to_user(arg, event_status,
							  size);
					if (rc)
						pr_err("%s: copy to user failed %d\n",
						       __func__, rc);
				}
				kfree(event_status);
			}
		} else if (xchg) {
			pr_debug("%s: Wait aborted\n", __func__);
			rc = 0;
		}
		break;

	case SNDRV_LSM_ABORT_EVENT:
		pr_debug("%s: Aborting event status wait\n", __func__);
		atomic_set(&prtd->event_wait_stop, 1);
		wake_up(&prtd->event_wait);
		break;

	case SNDRV_LSM_START:
		pr_debug("%s: Starting LSM client session\n", __func__);
		if (!prtd->lsm_client->started) {
			ret = q6lsm_start(prtd->lsm_client, true);
			if (!ret) {
				prtd->lsm_client->started = true;
				pr_debug("%s: LSM client session started\n",
					 __func__);
			}
		}
		break;

	case SNDRV_LSM_STOP:
		pr_debug("%s: Stopping LSM client session\n", __func__);
		if (prtd->lsm_client->started) {
			ret = q6lsm_stop(prtd->lsm_client, true);
			if (!ret)
				pr_debug("%s: LSM client session stopped %d\n",
					 __func__, ret);
			prtd->lsm_client->started = false;
		}
		break;

	default:
		pr_debug("%s: Falling into default snd_lib_ioctl cmd 0x%x\n",
			 __func__, cmd);
		rc = snd_pcm_lib_ioctl(substream, cmd, arg);
		break;
	}

	if (!rc)
		pr_debug("%s: leave (%d)\n", __func__, rc);
	else
		pr_err("%s: cmd 0x%x failed %d\n", __func__, cmd, rc);

	return rc;
}
コード例 #8
0
ファイル: msm-lsm-client.c プロジェクト: MethHeadAlert/M9
static int msm_lsm_ioctl_shared(struct snd_pcm_substream *substream,
			 unsigned int cmd, void *arg)
{
	unsigned long flags;
	int ret;
	struct snd_lsm_sound_model snd_model;
	struct snd_lsm_sound_model_v2 snd_model_v2;
	struct snd_lsm_session_data session_data;
	int rc = 0;
	int xchg = 0;
	u32 size = 0;
	struct snd_pcm_runtime *runtime = substream->runtime;
	struct lsm_priv *prtd = runtime->private_data;
	struct snd_lsm_event_status *user = arg;
	struct snd_lsm_detection_params det_params;
	uint8_t *confidence_level = NULL;

	pr_debug("%s: enter cmd %x\n", __func__, cmd);
	switch (cmd) {
	case SNDRV_LSM_SET_SESSION_DATA:
		pr_debug("%s: set Session data\n", __func__);
		memcpy(&session_data, arg,
		       sizeof(struct snd_lsm_session_data));
		if (prtd) {
			if (session_data.app_id <= LSM_VOICE_WAKEUP_APP_ID_V2
			    && session_data.app_id > 0) {
				prtd->lsm_client->app_id = session_data.app_id;
				ret = q6lsm_open(prtd->lsm_client,
					prtd->lsm_client->app_id);
				if (ret < 0) {
					pr_err("%s: lsm open failed, %d\n",
								__func__, ret);
					q6lsm_client_free(prtd->lsm_client);
					kfree(prtd);
					return ret;
				}
				pr_debug("%s: Session ID %d\n", __func__,
					prtd->lsm_client->session);
			} else {
				pr_err("%s:Invalid App id for Listen client\n",
				       __func__);
				rc = -EINVAL;
			}
		} else {
			pr_err("%s: LSM Priv data is NULL\n", __func__);
			rc = -EINVAL;
		}
		break;
	case SNDRV_LSM_REG_SND_MODEL_V2:
		pr_debug("%s: Registering sound model V2\n", __func__);
		memcpy(&snd_model_v2, arg,
		       sizeof(struct snd_lsm_sound_model_v2));
		if (snd_model_v2.num_confidence_levels >
		    MAX_NUM_CONFIDENCE) {
			pr_err("%s: Invalid conf_levels = %d, maximum allowed = %d\n",
				__func__, snd_model_v2.num_confidence_levels,
				MAX_NUM_CONFIDENCE);
			rc = -EINVAL;
			break;
		}

		prtd->lsm_client->snd_model_ver_inuse = SND_MODEL_IN_USE_V2;
		rc = q6lsm_snd_model_buf_alloc(prtd->lsm_client,
					       snd_model_v2.data_size);
		if (rc) {
			pr_err("%s: q6lsm buffer alloc failed V2, size %d\n",
			       __func__, snd_model_v2.data_size);
			break;
		}
		if (copy_from_user(prtd->lsm_client->sound_model.data,
			   snd_model_v2.data, snd_model_v2.data_size)) {
			pr_err("%s: copy from user data failed\n"
			       "data %p size %d\n", __func__,
			       snd_model_v2.data, snd_model_v2.data_size);
			q6lsm_snd_model_buf_free(prtd->lsm_client);
			rc = -EFAULT;
			break;
		}

		pr_debug("SND Model Magic no byte[0] %x,\n"
			 "byte[1] %x, byte[2] %x byte[3] %x\n",
			 snd_model_v2.data[0], snd_model_v2.data[1],
			 snd_model_v2.data[2], snd_model_v2.data[3]);

		prtd->lsm_client->num_confidence_levels =
			snd_model_v2.num_confidence_levels;

		rc = msm_lsm_get_conf_levels(prtd->lsm_client,
				snd_model_v2.confidence_level);
		if (rc) {
			pr_err("%s: get_conf_levels failed, err = %d\n",
				__func__, rc);
			break;
		}

		rc = q6lsm_register_sound_model(prtd->lsm_client,
					snd_model_v2.detection_mode,
					snd_model_v2.detect_failure);
		if (rc < 0) {
			pr_err("%s: Register snd Model v2 failed =%d\n",
			       __func__, rc);
			kfree(confidence_level);
			q6lsm_snd_model_buf_free(prtd->lsm_client);
		}

		kfree(prtd->lsm_client->confidence_levels);
		prtd->lsm_client->confidence_levels = NULL;
		break;

	case SNDRV_LSM_SET_PARAMS:
		if (!arg) {
			pr_err("%s: %s Invalid argument\n",
				__func__, "SNDRV_LSM_SET_PARAMS");
			return -EINVAL;
		}

		memcpy(&det_params, arg,
			sizeof(det_params));
		if (det_params.num_confidence_levels >
		    MAX_NUM_CONFIDENCE) {
			rc = -EINVAL;
			break;
		}

		prtd->lsm_client->num_confidence_levels =
			det_params.num_confidence_levels;

		rc = msm_lsm_get_conf_levels(prtd->lsm_client,
				det_params.conf_level);
		if (rc) {
			pr_err("%s: Failed to get conf_levels, err = %d\n",
				__func__, rc);
			break;
		}

		rc = q6lsm_set_data(prtd->lsm_client,
			       det_params.detect_mode,
			       det_params.detect_failure);
		if (rc)
			pr_err("%s: Failed to set params, err = %d\n",
				__func__, rc);

		kfree(prtd->lsm_client->confidence_levels);
		prtd->lsm_client->confidence_levels = NULL;

		break;

	case SNDRV_LSM_REG_SND_MODEL:
		pr_debug("%s: Registering sound model\n", __func__);
		memcpy(&snd_model, arg, sizeof(struct snd_lsm_sound_model));
		prtd->lsm_client->snd_model_ver_inuse = SND_MODEL_IN_USE_V1;
		rc = q6lsm_snd_model_buf_alloc(prtd->lsm_client,
					       snd_model.data_size);
		if (rc) {
			pr_err("%s: q6lsm buffer alloc failed, size %d\n",
			       __func__, snd_model.data_size);
			break;
		}

		if (copy_from_user(prtd->lsm_client->sound_model.data,
				   snd_model.data, snd_model.data_size)) {
			pr_err("%s: copy from user data failed data %p size %d\n",
			       __func__, snd_model.data, snd_model.data_size);
			rc = -EFAULT;
			q6lsm_snd_model_buf_free(prtd->lsm_client);
			break;
		}
		rc = q6lsm_set_kw_sensitivity_level(prtd->lsm_client,
						snd_model.min_keyw_confidence,
						snd_model.min_user_confidence);
		if (rc) {
			pr_err("%s: Error in KW sensitivity %x", __func__, rc);
			q6lsm_snd_model_buf_free(prtd->lsm_client);
			break;
		}

		rc = q6lsm_register_sound_model(prtd->lsm_client,
						snd_model.detection_mode,
						snd_model.detect_failure);
		if (rc < 0) {
			pr_err("%s: q6lsm_register_sound_model failed =%d\n",
			       __func__, rc);
			q6lsm_snd_model_buf_free(prtd->lsm_client);
		}

		break;

	case SNDRV_LSM_DEREG_SND_MODEL:
		pr_debug("%s: Deregistering sound model\n", __func__);
		rc = q6lsm_deregister_sound_model(prtd->lsm_client);
		break;

	case SNDRV_LSM_EVENT_STATUS:
		pr_debug("%s: Get event status\n", __func__);
		atomic_set(&prtd->event_wait_stop, 0);
		rc = wait_event_freezable(prtd->event_wait,
				(cmpxchg(&prtd->event_avail, 1, 0) ||
				 (xchg = atomic_cmpxchg(&prtd->event_wait_stop,
							1, 0))));
		pr_debug("%s: wait_event_freezable %d event_wait_stop %d\n",
			 __func__, rc, xchg);
		if (!rc && !xchg) {
			pr_debug("%s: New event available %ld\n", __func__,
				 prtd->event_avail);
			spin_lock_irqsave(&prtd->event_lock, flags);
			if (prtd->event_status) {
				size = sizeof(*(prtd->event_status)) +
				prtd->event_status->payload_size;
				spin_unlock_irqrestore(&prtd->event_lock,
						       flags);
			} else {
				spin_unlock_irqrestore(&prtd->event_lock,
						       flags);
				rc = -EINVAL;
				pr_err("%s: prtd->event_status is NULL\n",
					__func__);
				break;
			}
			if (user->payload_size <
			    prtd->event_status->payload_size) {
				pr_debug("%s: provided %dbytes isn't enough, needs %dbytes\n",
					 __func__, user->payload_size,
					 prtd->event_status->payload_size);
				rc = -ENOMEM;
			} else {
				memcpy(user, prtd->event_status, size);
				if (prtd->lsm_client->lab_enable
					&& atomic_read(&prtd->read_abort)
					&& prtd->event_status->status ==
					LSM_VOICE_WAKEUP_STATUS_DETECTED) {
					atomic_set(&prtd->read_abort, 0);
					atomic_set(&prtd->buf_count, 0);
					prtd->appl_cnt = 0;
					prtd->dma_write = 0;
					rc = msm_lsm_queue_lab_buffer(prtd,
						0);
					if (rc)
						pr_err("%s: Queue buffer failed for lab rc = %d\n",
							__func__, rc);
					else
						prtd->lsm_client->lab_started
						= true;
				}
			}
		} else if (xchg) {
			pr_debug("%s: Wait aborted\n", __func__);
			rc = 0;
		}
		break;

	case SNDRV_LSM_ABORT_EVENT:
		pr_debug("%s: Aborting event status wait\n", __func__);
		atomic_set(&prtd->event_wait_stop, 1);
		wake_up(&prtd->event_wait);
		break;

	case SNDRV_LSM_START:
		pr_debug("%s: Starting LSM client session\n", __func__);
		if (!prtd->lsm_client->started) {
			if (prtd->lsm_client->lab_enable &&
				!prtd->lsm_client->lab_started) {
				atomic_set(&prtd->read_abort, 0);
				/* Push the first period buffer */
				ret = msm_lsm_queue_lab_buffer(prtd, 0);
				if (ret) {
					pr_err("%s: failed to queue buffers for LAB read %d\n"
					, __func__, ret);
					break;
				}
				prtd->lsm_client->lab_started = true;
			}
			ret = q6lsm_start(prtd->lsm_client, true);
			if (!ret) {
				prtd->lsm_client->started = true;
				pr_debug("%s: LSM client session started\n",
					 __func__);
			}
		}
		break;

	case SNDRV_LSM_STOP: {
		pr_debug("%s: Stopping LSM client session\n", __func__);
		if (prtd->lsm_client->started) {
			if (prtd->lsm_client->lab_enable) {
				atomic_set(&prtd->read_abort, 1);
				if (prtd->lsm_client->lab_started) {
					ret = q6lsm_stop_lab(prtd->lsm_client);
					if (ret)
						pr_err("%s: stop lab failed ret %d\n",
						__func__, ret);
					prtd->lsm_client->lab_started = false;
				}
				ret = msm_lsm_lab_buffer_alloc(prtd,
					LAB_BUFFER_DEALLOC);
				if (ret)
					pr_err("%s: lab buffer de-alloc failed rc %d",
					__func__, rc);
			}
			ret = q6lsm_stop(prtd->lsm_client, true);
			if (!ret)
				pr_debug("%s: LSM client session stopped %d\n",
					 __func__, ret);
			prtd->lsm_client->started = false;
		}
		break;
	}
	case SNDRV_LSM_LAB_CONTROL: {
		u32 *enable = NULL;
		pr_debug("%s: ioctl %s\n", __func__, "SNDRV_LSM_LAB_CONTROL");
		if (!arg) {
			pr_err("%s: Invalid param arg for ioctl %s session %d\n",
			__func__, "SNDRV_LSM_LAB_CONTROL",
			prtd->lsm_client->session);
			rc = -EINVAL;
			break;
		}
		enable = (int *)arg;
		if (!prtd->lsm_client->started) {
			if (prtd->lsm_client->lab_enable == *enable) {
				pr_info("%s: Lab for session %d already %s\n",
				 __func__, prtd->lsm_client->session,
				((*enable) ? "enabled" : "disabled"));
				rc = 0;
				break;
			}
			rc = q6lsm_lab_control(prtd->lsm_client, *enable);
			if (rc)
				pr_err("%s: ioctl %s failed rc %d to %s lab for session %d\n",
				__func__, "SNDRV_LAB_CONTROL", rc,
				((*enable) ? "enable" : "disable"),
				prtd->lsm_client->session);
			else {
				rc = msm_lsm_lab_buffer_alloc(prtd,
					((*enable) ? LAB_BUFFER_ALLOC
					: LAB_BUFFER_DEALLOC));
				if (rc)
					pr_err("%s: msm_lsm_lab_buffer_alloc failed rc %d for %s",
					__func__, rc,
					((*enable) ? "ALLOC" : "DEALLOC"));
				if (!rc)
					prtd->lsm_client->lab_enable = *enable;
			}
		} else {
			pr_err("%s: ioctl %s issued after start", __func__
			, "SNDRV_LSM_LAB_CONTROL");
			rc = -EINVAL;
		}
		break;
	}
	case SNDRV_LSM_STOP_LAB:
		if (prtd->lsm_client->lab_enable &&
			prtd->lsm_client->lab_started) {
			atomic_set(&prtd->read_abort, 1);
			rc = q6lsm_stop_lab(prtd->lsm_client);
			if (rc)
				pr_err("%s: Lab stop failed for session %d rc %d\n"
				, __func__, prtd->lsm_client->session, rc);
			prtd->lsm_client->lab_started = false;
		}
	break;
	default:
		pr_debug("%s: Falling into default snd_lib_ioctl cmd 0x%x\n",
			 __func__, cmd);
		rc = snd_pcm_lib_ioctl(substream, cmd, arg);
		break;
	}

	if (!rc)
		pr_debug("%s: leave (%d)\n", __func__, rc);
	else
		pr_err("%s: cmd 0x%x failed %d\n", __func__, cmd, rc);

	return rc;
}
コード例 #9
0
/*
 * msm_cpe_lsm_ioctl: IOCTL for this platform driver
 * @substream: ASoC substream for which the operation is invoked
 * @cmd: command for the ioctl
 * @arg: argument for the ioctl
 *
 * Perform dedicated listen functions like register sound model,
 * deregister sound model, etc
 */
static int msm_cpe_lsm_ioctl(struct snd_pcm_substream *substream,
			 unsigned int cmd, void *arg)
{
	struct snd_lsm_sound_model_v2 snd_model;
	struct snd_soc_pcm_runtime *rtd = substream->private_data;
	struct cpe_lsm_data *lsm_d = cpe_get_lsm_data(substream);
	struct cpe_priv *cpe = cpe_get_private_data(substream);
	struct cpe_lsm_session *session;
	struct wcd_cpe_lsm_ops *lsm_ops;
	struct snd_lsm_event_status *event_status = NULL;
	struct snd_lsm_event_status u_event_status;
	int rc = 0, u_pld_size = 0;

	if (!cpe || !cpe->core_handle) {
		dev_err(rtd->dev,
			"%s: Invalid private data\n",
			__func__);
		return -EINVAL;
	}

	if (!lsm_d || !lsm_d->lsm_session) {
		dev_err(rtd->dev,
			"%s: Invalid session data\n",
			__func__);
		return -EINVAL;
	}

	session = lsm_d->lsm_session;
	lsm_ops = &cpe->lsm_ops;

	dev_dbg(rtd->dev, "%s: cmd = %u\n",
		__func__, cmd);

	switch (cmd) {
	case SNDRV_LSM_REG_SND_MODEL_V2:

		if (copy_from_user(&snd_model, (void *)arg,
				   sizeof(struct snd_lsm_sound_model_v2))) {
			dev_err(rtd->dev,
				"%s: copy from user failed, size %zd\n",
				__func__,
				sizeof(struct snd_lsm_sound_model_v2));
			return -EFAULT;
		}

		if (snd_model.num_confidence_levels <= 0) {
			dev_err(rtd->dev,
				"%s: Invalid number of confidence levels %u\n",
				__func__, snd_model.num_confidence_levels);
			return -EINVAL;
		}

		session->conf_levels = kzalloc(snd_model.num_confidence_levels,
					       GFP_KERNEL);
		if (!session->conf_levels) {
			dev_err(rtd->dev,
				"%s: No memory for confidence levels %u\n",
				__func__, snd_model.num_confidence_levels);
			return -ENOMEM;
		}

		if (copy_from_user(session->conf_levels,
				  snd_model.confidence_level,
				  snd_model.num_confidence_levels)) {
			dev_err(rtd->dev,
				"%s: copy_from_user failed for confidence levels %u\n",
				__func__, snd_model.num_confidence_levels);
			kfree(session->conf_levels);
			return -EFAULT;
		}
		session->num_confidence_levels =
				snd_model.num_confidence_levels;

		session->snd_model_data = kzalloc(snd_model.data_size,
						  GFP_KERNEL);
		if (!session->snd_model_data) {
			dev_err(rtd->dev, "%s: No memory for sound model\n",
				__func__);
			kfree(session->conf_levels);
			return -ENOMEM;
		}
		session->snd_model_size = snd_model.data_size;

		if (copy_from_user(session->snd_model_data,
				   snd_model.data, snd_model.data_size)) {
			dev_err(rtd->dev,
				"%s: copy_from_user failed for snd_model\n",
				__func__);
			kfree(session->conf_levels);
			kfree(session->snd_model_data);
			return -EFAULT;
		}

		rc = lsm_ops->lsm_shmem_alloc(cpe->core_handle, session,
					       session->snd_model_size);
		if (rc != 0) {
			dev_err(rtd->dev,
				"%s: shared memory allocation failed, err = %d\n",
			       __func__, rc);
			kfree(session->snd_model_data);
			kfree(session->conf_levels);
			return rc;
		}

		rc = lsm_ops->lsm_register_snd_model(cpe->core_handle, session,
						snd_model.detection_mode,
						snd_model.detect_failure);
		if (rc != 0) {
			dev_err(rtd->dev,
				"%s: snd_model_reg failed, err = %d\n",
			       __func__, rc);
			lsm_ops->lsm_shmem_dealloc(cpe->core_handle, session);
			kfree(session->snd_model_data);
			kfree(session->conf_levels);
			return rc;
		}

		break;

	case SNDRV_LSM_DEREG_SND_MODEL:
		rc = lsm_ops->lsm_deregister_snd_model(
				cpe->core_handle, session);
		if (rc != 0) {
			dev_err(rtd->dev,
				"%s: snd_model de-reg failed, err = %d\n",
				__func__, rc);
			return rc;
		}

		kfree(session->snd_model_data);
		kfree(session->conf_levels);

		rc = lsm_ops->lsm_shmem_dealloc(cpe->core_handle, session);
		if (rc != 0) {
			dev_err(rtd->dev,
				"%s: LSM shared memory dealloc failed, err = %d\n",
				__func__, rc);
			return rc;
		}

		break;

	case SNDRV_LSM_EVENT_STATUS:

		if (copy_from_user(&u_event_status, (void *)arg,
				   sizeof(struct snd_lsm_event_status))) {
			dev_err(rtd->dev,
				"%s: event status copy from user failed, size %zd\n",
				__func__,
				sizeof(struct snd_lsm_event_status));
			return -EFAULT;
		}
		u_pld_size = sizeof(struct snd_lsm_event_status) +
				u_event_status.payload_size;

		event_status = kzalloc(u_pld_size, GFP_KERNEL);
		if (!event_status) {
			dev_err(rtd->dev,
				"%s: No memory for event status\n",
				__func__);
			return -ENOMEM;
		}

		rc = wait_event_interruptible(lsm_d->event_wait,
				(atomic_read(&lsm_d->event_avail) == 1) ||
				(atomic_read(&lsm_d->event_stop) == 1));

		if (!rc) {
			if (atomic_read(&lsm_d->event_avail) == 1) {
				rc = 0;
				atomic_set(&lsm_d->event_avail, 0);
				if (lsm_d->ev_det_pld_size >
					u_event_status.payload_size) {
					dev_err(rtd->dev,
						"%s: avail pld_bytes = %u, needed = %u\n",
						__func__,
						u_event_status.payload_size,
						lsm_d->ev_det_pld_size);
					kfree(event_status);
					return -EINVAL;
				}

				event_status->status = lsm_d->ev_det_status;
				event_status->payload_size =
						lsm_d->ev_det_pld_size;
				memcpy(event_status->payload,
				       lsm_d->ev_det_payload,
				       lsm_d->ev_det_pld_size);

				if (copy_to_user(arg, event_status,
						u_pld_size)) {
					dev_err(rtd->dev,
						"%s: copy to user failed\n",
						__func__);
					kfree(event_status);
					return -EFAULT;
				}
				msm_cpe_process_event_status_done(lsm_d);
			} else if (atomic_read(&lsm_d->event_stop) == 1) {
				dev_dbg(rtd->dev,
					"%s: wait_aborted\n", __func__);
				rc = 0;
			}
		}

		kfree(event_status);
		break;

	case SNDRV_LSM_ABORT_EVENT:
		atomic_set(&lsm_d->event_stop, 1);
		wake_up(&lsm_d->event_wait);
		break;

	case SNDRV_LSM_START:
		rc = lsm_ops->lsm_start(cpe->core_handle, session);
		if (rc != 0) {
			dev_err(rtd->dev,
				"%s: lsm_start fail, err = %d\n",
				__func__, rc);
			return rc;
		}
		break;

	case SNDRV_LSM_STOP:
		rc = lsm_ops->lsm_stop(cpe->core_handle, session);
		if (rc != 0) {
			dev_err(rtd->dev,
				"%s: lsm_stop fail err = %d\n",
				__func__, rc);

			return rc;
		}
		break;

	default:
		dev_dbg(rtd->dev, "%s: Default snd_lib_ioctl cmd 0x%x\n",
		       __func__, cmd);
		rc = snd_pcm_lib_ioctl(substream, cmd, arg);
	}

	return rc;
}