예제 #1
0
/**
 * hdmi_audio_probe - to create sound card instance for HDMI audio playabck
 *
 *@haddata: pointer to HAD private data
 *@card_id: card for which probe is called
 *
 * This function is called when the hdmi cable is plugged in. This function
 * creates and registers the sound card with ALSA
 */
static int __devinit hdmi_audio_probe(struct platform_device *devptr)
{

	int retval;
	struct snd_pcm *pcm;
	struct snd_card *card;
	struct had_callback_ops ops_cb;
	struct snd_intelhad *intelhaddata;
	struct had_pvt_data *had_stream;

	pr_debug("Enter %s\n", __func__);

	/* allocate memory for saving internal context and working */
	intelhaddata = kzalloc(sizeof(*intelhaddata), GFP_KERNEL);
	if (!intelhaddata) {
		pr_err("mem alloc failed\n");
		return -ENOMEM;
	}

	had_stream = kzalloc(sizeof(*had_stream), GFP_KERNEL);
	if (!had_stream) {
		pr_err("mem alloc failed\n");
		retval = -ENOMEM;
		goto free_haddata;
	}

	had_data = intelhaddata;
	ops_cb.intel_had_event_call_back = had_event_handler;

	/* registering with display driver to get access to display APIs */

	retval = intel_hdmi_audio_query_capabilities(
			ops_cb.intel_had_event_call_back,
			&(intelhaddata->reg_ops),
			&(intelhaddata->query_ops));
	if (retval) {
		pr_err("querying display driver APIs failed %#x\n", retval);
		goto free_hadstream;
	}
	mutex_lock(&had_mutex);
	spin_lock_init(&intelhaddata->had_spinlock);
	intelhaddata->drv_status = HAD_DRV_DISCONNECTED;
	/* create a card instance with ALSA framework */
	retval = snd_card_create(hdmi_card_index, hdmi_card_id,
				THIS_MODULE, 0, &card);
	if (retval)
		goto unlock_mutex;
	intelhaddata->card = card;
	intelhaddata->card_id = hdmi_card_id;
	intelhaddata->card_index = card->number;
	intelhaddata->private_data = had_stream;
	intelhaddata->flag_underrun = 0;
	intelhaddata->aes_bits = SNDRV_PCM_DEFAULT_CON_SPDIF;
	strncpy(card->driver, INTEL_HAD, strlen(INTEL_HAD));
	strncpy(card->shortname, INTEL_HAD, strlen(INTEL_HAD));

	retval = snd_pcm_new(card, INTEL_HAD, PCM_INDEX, MAX_PB_STREAMS,
						MAX_CAP_STREAMS, &pcm);
	if (retval)
		goto err;

	/* setup private data which can be retrieved when required */
	pcm->private_data = intelhaddata;
	pcm->private_free = snd_intelhad_pcm_free;
	pcm->info_flags = 0;
	strncpy(pcm->name, card->shortname, strlen(card->shortname));
	/* setup the ops for palyabck */
	snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
			    &snd_intelhad_playback_ops);
	/* allocate dma pages for ALSA stream operations
	 * memory allocated is based on size, not max value
	 * thus using same argument for max & size
	 */
	retval = snd_pcm_lib_preallocate_pages_for_all(pcm,
			SNDRV_DMA_TYPE_DEV, card->dev,
			HAD_MAX_BUFFER, HAD_MAX_BUFFER);
	if (retval)
		goto err;

	/* internal function call to register device with ALSA */
	retval = snd_intelhad_create(intelhaddata, card);
	if (retval)
		goto err;

	card->private_data = &intelhaddata;
	retval = snd_card_register(card);
	if (retval)
		goto err;

	/* IEC958 controls */
	retval = snd_ctl_add(card, snd_ctl_new1(&had_control_iec958_mask,
						intelhaddata));
	if (retval < 0)
		goto err;
	retval = snd_ctl_add(card, snd_ctl_new1(&had_control_iec958,
						intelhaddata));
	if (retval < 0)
		goto err;

	/* Allocate memory for flat data */
	intelhaddata->flat_data = kzalloc((MAX_SZ_ZERO_BUF), GFP_KERNEL);
	if (!intelhaddata->flat_data) {
		retval = -ENOMEM;
		goto err;
	}

	mutex_unlock(&had_mutex);
	retval = display_register(&had_interface, intelhaddata);
	if (retval) {
		pr_err("registering with display driver failed %#x\n", retval);
		snd_card_free(card);
		goto free_hadstream;
	}

	return retval;
err:
	snd_card_free(card);
unlock_mutex:
	mutex_unlock(&had_mutex);
free_hadstream:
	kfree(had_stream);
free_haddata:
	kfree(intelhaddata);
	intelhaddata = NULL;
	pr_err("Error returned from %s api %#x\n", __func__, retval);
	return retval;
}
예제 #2
0
int display_incoming_messages(char *buffer, short length)
{
	if(*(buffer+1) == CMD_REPLY)
	{
		display_time();
		printf("Message from module: ");
		switch(*(buffer+2))
		{
			case REPLY_OK:
				printf("ok\n");
				break;
			case ERROR_CODE_UNKNOWN_CMD:
				printf("unknown command\n");
				break;
			case ERROR_CODE_IDLE:
				printf("idle\n");
				break;
			case ERROR_CODE_FAILED:
				printf("command failed\n");
				break;
			case ERROR_WRONG_PARAM:
				printf("wrong parameter\n");
				break;
			case ERROR_UNEXPECTD_ISR:
				printf("unexpected ISR from ADC\n");
				break;
			case ERROR_FLASH_KEY:
				printf("error reading from flash\n");
				break;
			case ERROR_ADC_ID:
				printf("wrong ADC ID\n");
				break;
			case PEAK_ACTIVE:
				printf("peak detection active\n");
				break;
			default:
				printf("unrecognized\n");
				return -1;
				break;
		}
	}
	else if(*(buffer+1) == CMD_CHECK_ADC)
	{
		display_time();
		printf("ADC check ID ");
		if(*(buffer+2))
		{
			printf("ok\n");
		}
		else
		{
			printf("failed\n");
		}
	}
	else if(*(buffer+1) == CMD_READ_REGISTER)
	{
		display_time();
		printf("Read register ");
		printf("addr %02x ",*(buffer+2));
		display_register((buffer+3), *(buffer)-2);
	}
	else return -1;
	return 0;
}