| 
									
										
										
										
											2009-11-10 16:08:04 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * soc-util.c  --  ALSA SoC Audio Layer utility functions | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copyright 2009 Wolfson Microelectronics PLC. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> | 
					
						
							|  |  |  |  *         Liam Girdwood <lrg@slimlogic.co.uk> | 
					
						
							|  |  |  |  *          | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *  This program is free software; you can redistribute  it and/or modify it | 
					
						
							|  |  |  |  *  under  the terms of  the GNU General  Public License as published by the | 
					
						
							|  |  |  |  *  Free Software Foundation;  either version 2 of the  License, or (at your | 
					
						
							|  |  |  |  *  option) any later version. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-27 18:16:32 +01:00
										 |  |  | #include <linux/platform_device.h>
 | 
					
						
							| 
									
										
										
										
											2011-09-22 09:34:58 -04:00
										 |  |  | #include <linux/export.h>
 | 
					
						
							| 
									
										
										
										
											2009-11-10 16:08:04 +00:00
										 |  |  | #include <sound/core.h>
 | 
					
						
							|  |  |  | #include <sound/pcm.h>
 | 
					
						
							|  |  |  | #include <sound/pcm_params.h>
 | 
					
						
							|  |  |  | #include <sound/soc.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int snd_soc_calc_frame_size(int sample_size, int channels, int tdm_slots) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return sample_size * channels * tdm_slots; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | EXPORT_SYMBOL_GPL(snd_soc_calc_frame_size); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int snd_soc_params_to_frame_size(struct snd_pcm_hw_params *params) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int sample_size; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-31 20:14:38 +00:00
										 |  |  | 	sample_size = snd_pcm_format_width(params_format(params)); | 
					
						
							|  |  |  | 	if (sample_size < 0) | 
					
						
							|  |  |  | 		return sample_size; | 
					
						
							| 
									
										
										
										
											2009-11-10 16:08:04 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return snd_soc_calc_frame_size(sample_size, params_channels(params), | 
					
						
							|  |  |  | 				       1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | EXPORT_SYMBOL_GPL(snd_soc_params_to_frame_size); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-19 11:36:10 +00:00
										 |  |  | int snd_soc_calc_bclk(int fs, int sample_size, int channels, int tdm_slots) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return fs * snd_soc_calc_frame_size(sample_size, channels, tdm_slots); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | EXPORT_SYMBOL_GPL(snd_soc_calc_bclk); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-10 16:08:04 +00:00
										 |  |  | int snd_soc_params_to_bclk(struct snd_pcm_hw_params *params) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int ret; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ret = snd_soc_params_to_frame_size(params); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (ret > 0) | 
					
						
							|  |  |  | 		return ret * params_rate(params); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | EXPORT_SYMBOL_GPL(snd_soc_params_to_bclk); | 
					
						
							| 
									
										
										
										
											2011-04-27 18:16:32 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-05 20:50:45 +00:00
										 |  |  | static const struct snd_pcm_hardware dummy_dma_hardware = { | 
					
						
							|  |  |  | 	.formats		= 0xffffffff, | 
					
						
							|  |  |  | 	.channels_min		= 1, | 
					
						
							|  |  |  | 	.channels_max		= UINT_MAX, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Random values to keep userspace happy when checking constraints */ | 
					
						
							|  |  |  | 	.info			= SNDRV_PCM_INFO_INTERLEAVED | | 
					
						
							|  |  |  | 				  SNDRV_PCM_INFO_BLOCK_TRANSFER, | 
					
						
							|  |  |  | 	.buffer_bytes_max	= 128*1024, | 
					
						
							|  |  |  | 	.period_bytes_min	= PAGE_SIZE, | 
					
						
							|  |  |  | 	.period_bytes_max	= PAGE_SIZE*2, | 
					
						
							|  |  |  | 	.periods_min		= 2, | 
					
						
							|  |  |  | 	.periods_max		= 128, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int dummy_dma_open(struct snd_pcm_substream *substream) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	snd_soc_set_runtime_hwparams(substream, &dummy_dma_hardware); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct snd_pcm_ops dummy_dma_ops = { | 
					
						
							|  |  |  | 	.open		= dummy_dma_open, | 
					
						
							|  |  |  | 	.ioctl		= snd_pcm_lib_ioctl, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct snd_soc_platform_driver dummy_platform = { | 
					
						
							|  |  |  | 	.ops = &dummy_dma_ops, | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2011-04-27 18:16:32 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | static __devinit int snd_soc_dummy_probe(struct platform_device *pdev) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return snd_soc_register_platform(&pdev->dev, &dummy_platform); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static __devexit int snd_soc_dummy_remove(struct platform_device *pdev) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	snd_soc_unregister_platform(&pdev->dev); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct platform_driver soc_dummy_driver = { | 
					
						
							|  |  |  | 	.driver = { | 
					
						
							|  |  |  | 		.name = "snd-soc-dummy", | 
					
						
							|  |  |  | 		.owner = THIS_MODULE, | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 	.probe = snd_soc_dummy_probe, | 
					
						
							|  |  |  | 	.remove = __devexit_p(snd_soc_dummy_remove), | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct platform_device *soc_dummy_dev; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-28 10:57:54 +01:00
										 |  |  | int __init snd_soc_util_init(void) | 
					
						
							| 
									
										
										
										
											2011-04-27 18:16:32 +01:00
										 |  |  | { | 
					
						
							|  |  |  | 	int ret; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	soc_dummy_dev = platform_device_alloc("snd-soc-dummy", -1); | 
					
						
							|  |  |  | 	if (!soc_dummy_dev) | 
					
						
							|  |  |  | 		return -ENOMEM; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ret = platform_device_add(soc_dummy_dev); | 
					
						
							|  |  |  | 	if (ret != 0) { | 
					
						
							|  |  |  | 		platform_device_put(soc_dummy_dev); | 
					
						
							|  |  |  | 		return ret; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ret = platform_driver_register(&soc_dummy_driver); | 
					
						
							|  |  |  | 	if (ret != 0) | 
					
						
							|  |  |  | 		platform_device_unregister(soc_dummy_dev); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-28 10:57:54 +01:00
										 |  |  | void __exit snd_soc_util_exit(void) | 
					
						
							| 
									
										
										
										
											2011-04-27 18:16:32 +01:00
										 |  |  | { | 
					
						
							|  |  |  | 	platform_device_unregister(soc_dummy_dev); | 
					
						
							|  |  |  | 	platform_driver_unregister(&soc_dummy_driver); | 
					
						
							|  |  |  | } |