cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

brownstone.c (3711B)


      1// SPDX-License-Identifier: GPL-2.0-or-later
      2/*
      3 * linux/sound/soc/pxa/brownstone.c
      4 *
      5 * Copyright (C) 2011 Marvell International Ltd.
      6 */
      7
      8#include <linux/module.h>
      9#include <sound/core.h>
     10#include <sound/pcm.h>
     11#include <sound/soc.h>
     12#include <sound/jack.h>
     13
     14#include "../codecs/wm8994.h"
     15#include "mmp-sspa.h"
     16
     17static const struct snd_kcontrol_new brownstone_dapm_control[] = {
     18	SOC_DAPM_PIN_SWITCH("Ext Spk"),
     19};
     20
     21static const struct snd_soc_dapm_widget brownstone_dapm_widgets[] = {
     22	SND_SOC_DAPM_SPK("Ext Spk", NULL),
     23	SND_SOC_DAPM_HP("Headset Stereophone", NULL),
     24	SND_SOC_DAPM_MIC("Headset Mic", NULL),
     25	SND_SOC_DAPM_MIC("Main Mic", NULL),
     26};
     27
     28static const struct snd_soc_dapm_route brownstone_audio_map[] = {
     29	{"Ext Spk", NULL, "SPKOUTLP"},
     30	{"Ext Spk", NULL, "SPKOUTLN"},
     31	{"Ext Spk", NULL, "SPKOUTRP"},
     32	{"Ext Spk", NULL, "SPKOUTRN"},
     33
     34	{"Headset Stereophone", NULL, "HPOUT1L"},
     35	{"Headset Stereophone", NULL, "HPOUT1R"},
     36
     37	{"IN1RN", NULL, "Headset Mic"},
     38
     39	{"DMIC1DAT", NULL, "MICBIAS1"},
     40	{"MICBIAS1", NULL, "Main Mic"},
     41};
     42
     43static int brownstone_wm8994_hw_params(struct snd_pcm_substream *substream,
     44				       struct snd_pcm_hw_params *params)
     45{
     46	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
     47	struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
     48	struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
     49	int freq_out, sspa_mclk, sysclk;
     50
     51	if (params_rate(params) > 11025) {
     52		freq_out  = params_rate(params) * 512;
     53		sysclk    = params_rate(params) * 256;
     54		sspa_mclk = params_rate(params) * 64;
     55	} else {
     56		freq_out  = params_rate(params) * 1024;
     57		sysclk    = params_rate(params) * 512;
     58		sspa_mclk = params_rate(params) * 64;
     59	}
     60
     61	snd_soc_dai_set_sysclk(cpu_dai, MMP_SSPA_CLK_AUDIO, freq_out, 0);
     62	snd_soc_dai_set_pll(cpu_dai, MMP_SYSCLK, 0, freq_out, sysclk);
     63	snd_soc_dai_set_pll(cpu_dai, MMP_SSPA_CLK, 0, freq_out, sspa_mclk);
     64
     65	/* set wm8994 sysclk */
     66	snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_MCLK1, sysclk, 0);
     67
     68	return 0;
     69}
     70
     71/* machine stream operations */
     72static const struct snd_soc_ops brownstone_ops = {
     73	.hw_params = brownstone_wm8994_hw_params,
     74};
     75
     76SND_SOC_DAILINK_DEFS(wm8994,
     77	DAILINK_COMP_ARRAY(COMP_CPU("mmp-sspa-dai.0")),
     78	DAILINK_COMP_ARRAY(COMP_CODEC("wm8994-codec", "wm8994-aif1")),
     79	DAILINK_COMP_ARRAY(COMP_PLATFORM("mmp-pcm-audio")));
     80
     81static struct snd_soc_dai_link brownstone_wm8994_dai[] = {
     82{
     83	.name		= "WM8994",
     84	.stream_name	= "WM8994 HiFi",
     85	.dai_fmt	= SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
     86				SND_SOC_DAIFMT_CBS_CFS,
     87	.ops		= &brownstone_ops,
     88	SND_SOC_DAILINK_REG(wm8994),
     89},
     90};
     91
     92/* audio machine driver */
     93static struct snd_soc_card brownstone = {
     94	.name         = "brownstone",
     95	.owner        = THIS_MODULE,
     96	.dai_link     = brownstone_wm8994_dai,
     97	.num_links    = ARRAY_SIZE(brownstone_wm8994_dai),
     98
     99	.controls = brownstone_dapm_control,
    100	.num_controls = ARRAY_SIZE(brownstone_dapm_control),
    101	.dapm_widgets = brownstone_dapm_widgets,
    102	.num_dapm_widgets = ARRAY_SIZE(brownstone_dapm_widgets),
    103	.dapm_routes = brownstone_audio_map,
    104	.num_dapm_routes = ARRAY_SIZE(brownstone_audio_map),
    105	.fully_routed = true,
    106};
    107
    108static int brownstone_probe(struct platform_device *pdev)
    109{
    110	int ret;
    111
    112	brownstone.dev = &pdev->dev;
    113	ret = devm_snd_soc_register_card(&pdev->dev, &brownstone);
    114	if (ret)
    115		dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
    116				ret);
    117	return ret;
    118}
    119
    120static struct platform_driver mmp_driver = {
    121	.driver		= {
    122		.name	= "brownstone-audio",
    123		.pm     = &snd_soc_pm_ops,
    124	},
    125	.probe		= brownstone_probe,
    126};
    127
    128module_platform_driver(mmp_driver);
    129
    130MODULE_AUTHOR("Leo Yan <leoy@marvell.com>");
    131MODULE_DESCRIPTION("ALSA SoC Brownstone");
    132MODULE_LICENSE("GPL");
    133MODULE_ALIAS("platform:brownstone-audio");