2019-06-04 11:10:56 +03:00
// SPDX-License-Identifier: GPL-2.0-only
2017-03-06 20:44:50 +03:00
/*
* Copyright ( c ) 2017 BayLibre , SAS .
* Author : Jerome Brunet < jbrunet @ baylibre . com >
*/
# include <linux/gpio/consumer.h>
# include <linux/module.h>
2018-11-22 13:23:21 +03:00
# include <linux/regulator/consumer.h>
2017-03-06 20:44:50 +03:00
# include <sound/soc.h>
2018-06-26 15:11:27 +03:00
# define DRV_NAME "simple-amplifier"
2017-03-06 20:44:50 +03:00
2018-06-26 15:11:27 +03:00
struct simple_amp {
2017-03-06 20:44:50 +03:00
struct gpio_desc * gpiod_enable ;
} ;
static int drv_event ( struct snd_soc_dapm_widget * w ,
struct snd_kcontrol * control , int event )
{
struct snd_soc_component * c = snd_soc_dapm_to_component ( w - > dapm ) ;
2018-06-26 15:11:27 +03:00
struct simple_amp * priv = snd_soc_component_get_drvdata ( c ) ;
2017-03-06 20:44:50 +03:00
int val ;
switch ( event ) {
case SND_SOC_DAPM_POST_PMU :
val = 1 ;
break ;
case SND_SOC_DAPM_PRE_PMD :
val = 0 ;
break ;
default :
WARN ( 1 , " Unexpected event " ) ;
return - EINVAL ;
}
2017-03-07 16:12:22 +03:00
gpiod_set_value_cansleep ( priv - > gpiod_enable , val ) ;
2017-03-06 20:44:50 +03:00
return 0 ;
}
2018-06-26 15:11:27 +03:00
static const struct snd_soc_dapm_widget simple_amp_dapm_widgets [ ] = {
2017-03-06 20:44:50 +03:00
SND_SOC_DAPM_INPUT ( " INL " ) ,
SND_SOC_DAPM_INPUT ( " INR " ) ,
SND_SOC_DAPM_OUT_DRV_E ( " DRV " , SND_SOC_NOPM , 0 , 0 , NULL , 0 , drv_event ,
( SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD ) ) ,
SND_SOC_DAPM_OUTPUT ( " OUTL " ) ,
SND_SOC_DAPM_OUTPUT ( " OUTR " ) ,
2018-11-22 13:23:21 +03:00
SND_SOC_DAPM_REGULATOR_SUPPLY ( " VCC " , 20 , 0 ) ,
2017-03-06 20:44:50 +03:00
} ;
2018-06-26 15:11:27 +03:00
static const struct snd_soc_dapm_route simple_amp_dapm_routes [ ] = {
2017-03-06 20:44:50 +03:00
{ " DRV " , NULL , " INL " } ,
{ " DRV " , NULL , " INR " } ,
2018-11-22 13:23:21 +03:00
{ " OUTL " , NULL , " VCC " } ,
{ " OUTR " , NULL , " VCC " } ,
2017-03-06 20:44:50 +03:00
{ " OUTL " , NULL , " DRV " } ,
{ " OUTR " , NULL , " DRV " } ,
} ;
2018-06-26 15:11:27 +03:00
static const struct snd_soc_component_driver simple_amp_component_driver = {
. dapm_widgets = simple_amp_dapm_widgets ,
. num_dapm_widgets = ARRAY_SIZE ( simple_amp_dapm_widgets ) ,
. dapm_routes = simple_amp_dapm_routes ,
. num_dapm_routes = ARRAY_SIZE ( simple_amp_dapm_routes ) ,
2017-03-06 20:44:50 +03:00
} ;
2018-06-26 15:11:27 +03:00
static int simple_amp_probe ( struct platform_device * pdev )
2017-03-06 20:44:50 +03:00
{
struct device * dev = & pdev - > dev ;
2018-06-26 15:11:27 +03:00
struct simple_amp * priv ;
2017-03-06 20:44:50 +03:00
priv = devm_kzalloc ( dev , sizeof ( * priv ) , GFP_KERNEL ) ;
if ( priv = = NULL )
return - ENOMEM ;
platform_set_drvdata ( pdev , priv ) ;
2019-03-18 13:39:38 +03:00
priv - > gpiod_enable = devm_gpiod_get_optional ( dev , " enable " ,
GPIOD_OUT_LOW ) ;
2021-12-14 05:08:28 +03:00
if ( IS_ERR ( priv - > gpiod_enable ) )
return dev_err_probe ( dev , PTR_ERR ( priv - > gpiod_enable ) ,
" Failed to get 'enable' gpio " ) ;
2017-03-06 20:44:50 +03:00
2018-06-26 15:11:27 +03:00
return devm_snd_soc_register_component ( dev ,
& simple_amp_component_driver ,
2017-03-06 20:44:50 +03:00
NULL , 0 ) ;
}
# ifdef CONFIG_OF
2018-06-26 15:11:27 +03:00
static const struct of_device_id simple_amp_ids [ ] = {
2017-03-06 20:44:50 +03:00
{ . compatible = " dioo,dio2125 " , } ,
2018-06-26 15:11:28 +03:00
{ . compatible = " simple-audio-amplifier " , } ,
2017-03-06 20:44:50 +03:00
{ }
} ;
2018-06-26 15:11:27 +03:00
MODULE_DEVICE_TABLE ( of , simple_amp_ids ) ;
2017-03-06 20:44:50 +03:00
# endif
2018-06-26 15:11:27 +03:00
static struct platform_driver simple_amp_driver = {
2017-03-06 20:44:50 +03:00
. driver = {
. name = DRV_NAME ,
2018-06-26 15:11:27 +03:00
. of_match_table = of_match_ptr ( simple_amp_ids ) ,
2017-03-06 20:44:50 +03:00
} ,
2018-06-26 15:11:27 +03:00
. probe = simple_amp_probe ,
2017-03-06 20:44:50 +03:00
} ;
2018-06-26 15:11:27 +03:00
module_platform_driver ( simple_amp_driver ) ;
2017-03-06 20:44:50 +03:00
2018-06-26 15:11:27 +03:00
MODULE_DESCRIPTION ( " ASoC Simple Audio Amplifier driver " ) ;
2017-03-06 20:44:50 +03:00
MODULE_AUTHOR ( " Jerome Brunet <jbrunet@baylibre.com> " ) ;
MODULE_LICENSE ( " GPL " ) ;