17aae816dSMark Brown /* 27aae816dSMark Brown * soc-util.c -- ALSA SoC Audio Layer utility functions 37aae816dSMark Brown * 47aae816dSMark Brown * Copyright 2009 Wolfson Microelectronics PLC. 57aae816dSMark Brown * 67aae816dSMark Brown * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> 77aae816dSMark Brown * Liam Girdwood <lrg@slimlogic.co.uk> 87aae816dSMark Brown * 97aae816dSMark Brown * 107aae816dSMark Brown * This program is free software; you can redistribute it and/or modify it 117aae816dSMark Brown * under the terms of the GNU General Public License as published by the 127aae816dSMark Brown * Free Software Foundation; either version 2 of the License, or (at your 137aae816dSMark Brown * option) any later version. 147aae816dSMark Brown */ 157aae816dSMark Brown 16848dd8beSMark Brown #include <linux/platform_device.h> 17*d81a6d71SPaul Gortmaker #include <linux/export.h> 187aae816dSMark Brown #include <sound/core.h> 197aae816dSMark Brown #include <sound/pcm.h> 207aae816dSMark Brown #include <sound/pcm_params.h> 217aae816dSMark Brown #include <sound/soc.h> 227aae816dSMark Brown 237aae816dSMark Brown int snd_soc_calc_frame_size(int sample_size, int channels, int tdm_slots) 247aae816dSMark Brown { 257aae816dSMark Brown return sample_size * channels * tdm_slots; 267aae816dSMark Brown } 277aae816dSMark Brown EXPORT_SYMBOL_GPL(snd_soc_calc_frame_size); 287aae816dSMark Brown 297aae816dSMark Brown int snd_soc_params_to_frame_size(struct snd_pcm_hw_params *params) 307aae816dSMark Brown { 317aae816dSMark Brown int sample_size; 327aae816dSMark Brown 333d8b2ce0SMark Brown sample_size = snd_pcm_format_width(params_format(params)); 343d8b2ce0SMark Brown if (sample_size < 0) 353d8b2ce0SMark Brown return sample_size; 367aae816dSMark Brown 377aae816dSMark Brown return snd_soc_calc_frame_size(sample_size, params_channels(params), 387aae816dSMark Brown 1); 397aae816dSMark Brown } 407aae816dSMark Brown EXPORT_SYMBOL_GPL(snd_soc_params_to_frame_size); 417aae816dSMark Brown 42c0fa59dfSMark Brown int snd_soc_calc_bclk(int fs, int sample_size, int channels, int tdm_slots) 43c0fa59dfSMark Brown { 44c0fa59dfSMark Brown return fs * snd_soc_calc_frame_size(sample_size, channels, tdm_slots); 45c0fa59dfSMark Brown } 46c0fa59dfSMark Brown EXPORT_SYMBOL_GPL(snd_soc_calc_bclk); 47c0fa59dfSMark Brown 487aae816dSMark Brown int snd_soc_params_to_bclk(struct snd_pcm_hw_params *params) 497aae816dSMark Brown { 507aae816dSMark Brown int ret; 517aae816dSMark Brown 527aae816dSMark Brown ret = snd_soc_params_to_frame_size(params); 537aae816dSMark Brown 547aae816dSMark Brown if (ret > 0) 557aae816dSMark Brown return ret * params_rate(params); 567aae816dSMark Brown else 577aae816dSMark Brown return ret; 587aae816dSMark Brown } 597aae816dSMark Brown EXPORT_SYMBOL_GPL(snd_soc_params_to_bclk); 60848dd8beSMark Brown 61848dd8beSMark Brown static struct snd_soc_platform_driver dummy_platform; 62848dd8beSMark Brown 63848dd8beSMark Brown static __devinit int snd_soc_dummy_probe(struct platform_device *pdev) 64848dd8beSMark Brown { 65848dd8beSMark Brown return snd_soc_register_platform(&pdev->dev, &dummy_platform); 66848dd8beSMark Brown } 67848dd8beSMark Brown 68848dd8beSMark Brown static __devexit int snd_soc_dummy_remove(struct platform_device *pdev) 69848dd8beSMark Brown { 70848dd8beSMark Brown snd_soc_unregister_platform(&pdev->dev); 71848dd8beSMark Brown 72848dd8beSMark Brown return 0; 73848dd8beSMark Brown } 74848dd8beSMark Brown 75848dd8beSMark Brown static struct platform_driver soc_dummy_driver = { 76848dd8beSMark Brown .driver = { 77848dd8beSMark Brown .name = "snd-soc-dummy", 78848dd8beSMark Brown .owner = THIS_MODULE, 79848dd8beSMark Brown }, 80848dd8beSMark Brown .probe = snd_soc_dummy_probe, 81848dd8beSMark Brown .remove = __devexit_p(snd_soc_dummy_remove), 82848dd8beSMark Brown }; 83848dd8beSMark Brown 84848dd8beSMark Brown static struct platform_device *soc_dummy_dev; 85848dd8beSMark Brown 86fb257897SMark Brown int __init snd_soc_util_init(void) 87848dd8beSMark Brown { 88848dd8beSMark Brown int ret; 89848dd8beSMark Brown 90848dd8beSMark Brown soc_dummy_dev = platform_device_alloc("snd-soc-dummy", -1); 91848dd8beSMark Brown if (!soc_dummy_dev) 92848dd8beSMark Brown return -ENOMEM; 93848dd8beSMark Brown 94848dd8beSMark Brown ret = platform_device_add(soc_dummy_dev); 95848dd8beSMark Brown if (ret != 0) { 96848dd8beSMark Brown platform_device_put(soc_dummy_dev); 97848dd8beSMark Brown return ret; 98848dd8beSMark Brown } 99848dd8beSMark Brown 100848dd8beSMark Brown ret = platform_driver_register(&soc_dummy_driver); 101848dd8beSMark Brown if (ret != 0) 102848dd8beSMark Brown platform_device_unregister(soc_dummy_dev); 103848dd8beSMark Brown 104848dd8beSMark Brown return ret; 105848dd8beSMark Brown } 106848dd8beSMark Brown 107fb257897SMark Brown void __exit snd_soc_util_exit(void) 108848dd8beSMark Brown { 109848dd8beSMark Brown platform_device_unregister(soc_dummy_dev); 110848dd8beSMark Brown platform_driver_unregister(&soc_dummy_driver); 111848dd8beSMark Brown } 112