<commit_before>/**
 * Freescale MPC8610HPCD ALSA SoC Fabric driver
 *
 * Author: <NAME> <<EMAIL>>
 *
 * Copyright 2007-2008 Freescale Semiconductor, Inc.  This file is licensed
 * under the terms of the GNU General Public License version 2.  This
 * program is licensed "as is" without any warranty of any kind, whether
 * express or implied.
 */

#include <linux/module.h>
#include <linux/interrupt.h>
#include <linux/of_device.h>
#include <linux/of_platform.h>
#include <sound/soc.h>
#include <asm/immap_86xx.h>

#include "../codecs/cs4270.h"
#include "fsl_dma.h"
#include "fsl_ssi.h"

/**
 * mpc8610_hpcd_data: fabric-specific ASoC device data
 *
 * This structure contains data for a single sound platform device on an
 * MPC8610 HPCD.  Some of the data is taken from the device tree.
 */
struct mpc8610_hpcd_data {
	struct snd_soc_device sound_devdata;
	struct snd_soc_dai_link dai;
	struct snd_soc_machine machine;
	unsigned int dai_format;
	unsigned int codec_clk_direction;
	unsigned int cpu_clk_direction;
	unsigned int clk_frequency;
	struct ccsr_guts __iomem *guts;
	struct ccsr_ssi __iomem *ssi;
	unsigned int ssi_id;    	/* 0 = SSI1, 1 = SSI2, etc */
	unsigned int ssi_irq;
	unsigned int dma_id;    	/* 0 = DMA1, 1 = DMA2, etc */
	unsigned int dma_irq[2];
	struct ccsr_dma_channel __iomem *dma[2];
	unsigned int dma_channel_id[2]; /* 0 = ch 0, 1 = ch 1, etc*/
};

/**
 * mpc8610_hpcd_machine_probe: initalize the board
 *
 * This function is called when platform_device_add() is called.  It is used
 * to initialize the board-specific hardware.
 *
 * Here we program the DMACR and PMUXCR registers.
 */
static int mpc8610_hpcd_machine_probe(struct platform_device *sound_device)
{
	struct mpc8610_hpcd_data *machine_data =
		sound_device->dev.platform_data;

	/* Program the signal routing between the SSI and the DMA */
	guts_set_dmacr(machine_data->guts, machine_data->dma_id + 1,
		machine_data->dma_channel_id[0], CCSR_GUTS_DMACR_DEV_SSI);
	guts_set_dmacr(machine_data->guts, machine_data->dma_id + 1,
		machine_data->dma_channel_id[1], CCSR_GUTS_DMACR_DEV_SSI);

	guts_set_pmuxcr_dma(machine_data->guts, machine_data->dma_id,
		machine_data->dma_channel_id[0], 0);
	guts_set_pmuxcr_dma(machine_data->guts, machine_data->dma_id,
		machine_data->dma_channel_id[1], 0);

	guts_set_pmuxcr_dma(machine_data->guts, 1, 0, 0);
	guts_set_pmuxcr_dma(machine_data->guts, 1, 3, 0);
	guts_set_pmuxcr_dma(machine_data->guts, 0, 3, 0);

	switch (machine_data->ssi_id) {
	case 0:
		clrsetbits_be32(&machine_data->guts->pmuxcr,
			CCSR_GUTS_PMUXCR_SSI1_MASK, CCSR_GUTS_PMUXCR_SSI1_SSI);
		break;
	case 1:
		clrsetbits_be32(&machine_data->guts->pmuxcr,
			CCSR_GUTS_PMUXCR_SSI2_MASK, CCSR_GUTS_PMUXCR_SSI2_SSI);
		break;
	}

	return 0;
}

/**
 * mpc8610_hpcd_startup: program the board with various hardware parameters
 *
 * This function takes board-specific information, like clock frequencies
 * and serial data formats, and passes that information to the codec and
 * transport drivers.
 */
static int mpc8610_hpcd_startup(struct snd_pcm_substream *substream)
{
	struct snd_soc_pcm_runtime *rtd = substream->private_data;
	struct snd_soc_codec_dai *codec_dai = rtd->dai->codec_dai;
	struct snd_soc_cpu_dai *cpu_dai = rtd->dai->cpu_dai;
	struct mpc8610_hpcd_data *machine_data =
		rtd->socdev->dev->platform_data;
	int ret = 0;

	/* Tell the CPU driver what the serial protocol is. */
	if (cpu_dai->dai_ops.set_fmt) {
		ret = cpu_dai->dai_ops.set_fmt(cpu_dai,
			machine_data->dai_format);
		if (ret < 0) {
			dev_err(substream->pcm->card->dev,
				"could not set CPU driver audio format\n");
			return ret;
		}
	}

	/* Tell the codec driver what the serial protocol is. */
	if (codec_dai->dai_ops.set_fmt) {
		ret = codec_dai->dai_ops.set_fmt(codec_dai,
			machine_data->dai_format);
		if (ret < 0) {
			dev_err(substream->pcm->card->dev,
				"could not set codec driver audio format\n");
			return ret;
		}
	}

	/*
	 * Tell the CPU driver what the clock frequency is, and whether it's a
	 * slave or master.
	 */
	if (cpu_dai->dai_ops.set_sysclk) {
		ret = cpu_dai->dai_ops.set_sysclk(cpu_dai, 0,
			machine_data->clk_frequency,
			machine_data->cpu_clk_direction);
		if (ret < 0) {
			dev_err(substream->pcm->card->dev,
				"could not set CPU driver clock parameters\n");
			return ret;
		}
	}

	/*
	 * Tell the codec driver what the MCLK frequency is, and whether it's
	 * a slave or master.
	 */
	if (codec_dai->dai_ops.set_sysclk) {
		ret = codec_dai->dai_ops.set_sysclk(codec_dai, 0,
			machine_data->clk_frequency,
			machine_data->codec_clk_direction);
		if (ret < 0) {
			dev_err(substream->pcm->card->dev,
				"could not set codec driver clock params\n");
			return ret;
		}
	}

	return 0;
}

/**
 * mpc8610_hpcd_machine_remove: Remove the sound device
 *
 * This function is called to remove the sound device for one SSI.  We
 * de-program the DMACR and PMUXCR register.
 */
int mpc8610_hpcd_machine_remove(struct platform_device *sound_device)
{
	struct mpc8610_hpcd_data *machine_data =
		sound_device->dev.platform_data;

	/* Restore the signal routing */

	guts_set_dmacr(machine_data->guts, machine_data->dma_id + 1,
		machine_data->dma_channel_id[0], 0);
	guts_set_dmacr(machine_data->guts, machine_data->dma_id + 1,
		machine_data->dma_channel_id[1], 0);

	switch (machine_data->ssi_id) {
	case 0:
		clrsetbits_be32(&machine_data->guts->pmuxcr,
			CCSR_GUTS_PMUXCR_SSI1_MASK, CCSR_GUTS_PMUXCR_SSI1_LA);
		break;
	case 1:
		clrsetbits_be32(&machine_data->guts->pmuxcr,
			CCSR_GUTS_PMUXCR_SSI2_MASK, CCSR_GUTS_PMUXCR_SSI1_LA);
		break;
	}

	return 0;
}

/**
 * mpc8610_hpcd_ops: ASoC fabric driver operations
 */
static struct snd_soc_ops mpc8610_hpcd_ops = {
	.startup = mpc8610_hpcd_startup,
};

/**
 * mpc8610_hpcd_machine: ASoC machine data
 */
static struct snd_soc_machine mpc8610_hpcd_machine = {
	.probe = mpc8610_hpcd_machine_probe,<commit_msg>ALSA: Fix register programming in Freescale MPC8610 HPCD sound driver<commit_after>/**
 * Freescale MPC8610HPCD ALSA SoC Fabric driver
 *
 * Author: <NAME> <<EMAIL>>
 *
 * Copyright 2007-2008 Freescale Semiconductor, Inc.  This file is licensed
 * under the terms of the GNU General Public License version 2.  This
 * program is licensed "as is" without any warranty of any kind, whether
 * express or implied.
 */

#include <linux/module.h>
#include <linux/interrupt.h>
#include <linux/of_device.h>
#include <linux/of_platform.h>
#include <sound/soc.h>
#include <asm/immap_86xx.h>

#include "../codecs/cs4270.h"
#include "fsl_dma.h"
#include "fsl_ssi.h"

/**
 * mpc8610_hpcd_data: fabric-specific ASoC device data
 *
 * This structure contains data for a single sound platform device on an
 * MPC8610 HPCD.  Some of the data is taken from the device tree.
 */
struct mpc8610_hpcd_data {
	struct snd_soc_device sound_devdata;
	struct snd_soc_dai_link dai;
	struct snd_soc_machine machine;
	unsigned int dai_format;
	unsigned int codec_clk_direction;
	unsigned int cpu_clk_direction;
	unsigned int clk_frequency;
	struct ccsr_guts __iomem *guts;
	struct ccsr_ssi __iomem *ssi;
	unsigned int ssi_id;    	/* 0 = SSI1, 1 = SSI2, etc */
	unsigned int ssi_irq;
	unsigned int dma_id;    	/* 0 = DMA1, 1 = DMA2, etc */
	unsigned int dma_irq[2];
	struct ccsr_dma_channel __iomem *dma[2];
	unsigned int dma_channel_id[2]; /* 0 = ch 0, 1 = ch 1, etc*/
};

/**
 * mpc8610_hpcd_machine_probe: initalize the board
 *
 * This function is called when platform_device_add() is called.  It is used
 * to initialize the board-specific hardware.
 *
 * Here we program the DMACR and PMUXCR registers.
 */
static int mpc8610_hpcd_machine_probe(struct platform_device *sound_device)
{
	struct mpc8610_hpcd_data *machine_data =
		sound_device->dev.platform_data;

	/* Program the signal routing between the SSI and the DMA */
	guts_set_dmacr(machine_data->guts, machine_data->dma_id,
		machine_data->dma_channel_id[0], CCSR_GUTS_DMACR_DEV_SSI);
	guts_set_dmacr(machine_data->guts, machine_data->dma_id,
		machine_data->dma_channel_id[1], CCSR_GUTS_DMACR_DEV_SSI);

	guts_set_pmuxcr_dma(machine_data->guts, machine_data->dma_id,
		machine_data->dma_channel_id[0], 0);
	guts_set_pmuxcr_dma(machine_data->guts, machine_data->dma_id,
		machine_data->dma_channel_id[1], 0);

	guts_set_pmuxcr_dma(machine_data->guts, 1, 0, 0);
	guts_set_pmuxcr_dma(machine_data->guts, 1, 3, 0);
	guts_set_pmuxcr_dma(machine_data->guts, 0, 3, 0);

	switch (machine_data->ssi_id) {
	case 0:
		clrsetbits_be32(&machine_data->guts->pmuxcr,
			CCSR_GUTS_PMUXCR_SSI1_MASK, CCSR_GUTS_PMUXCR_SSI1_SSI);
		break;
	case 1:
		clrsetbits_be32(&machine_data->guts->pmuxcr,
			CCSR_GUTS_PMUXCR_SSI2_MASK, CCSR_GUTS_PMUXCR_SSI2_SSI);
		break;
	}

	return 0;
}

/**
 * mpc8610_hpcd_startup: program the board with various hardware parameters
 *
 * This function takes board-specific information, like clock frequencies
 * and serial data formats, and passes that information to the codec and
 * transport drivers.
 */
static int mpc8610_hpcd_startup(struct snd_pcm_substream *substream)
{
	struct snd_soc_pcm_runtime *rtd = substream->private_data;
	struct snd_soc_codec_dai *codec_dai = rtd->dai->codec_dai;
	struct snd_soc_cpu_dai *cpu_dai = rtd->dai->cpu_dai;
	struct mpc8610_hpcd_data *machine_data =
		rtd->socdev->dev->platform_data;
	int ret = 0;

	/* Tell the CPU driver what the serial protocol is. */
	if (cpu_dai->dai_ops.set_fmt) {
		ret = cpu_dai->dai_ops.set_fmt(cpu_dai,
			machine_data->dai_format);
		if (ret < 0) {
			dev_err(substream->pcm->card->dev,
				"could not set CPU driver audio format\n");
			return ret;
		}
	}

	/* Tell the codec driver what the serial protocol is. */
	if (codec_dai->dai_ops.set_fmt) {
		ret = codec_dai->dai_ops.set_fmt(codec_dai,
			machine_data->dai_format);
		if (ret < 0) {
			dev_err(substream->pcm->card->dev,
				"could not set codec driver audio format\n");
			return ret;
		}
	}

	/*
	 * Tell the CPU driver what the clock frequency is, and whether it's a
	 * slave or master.
	 */
	if (cpu_dai->dai_ops.set_sysclk) {
		ret = cpu_dai->dai_ops.set_sysclk(cpu_dai, 0,
			machine_data->clk_frequency,
			machine_data->cpu_clk_direction);
		if (ret < 0) {
			dev_err(substream->pcm->card->dev,
				"could not set CPU driver clock parameters\n");
			return ret;
		}
	}

	/*
	 * Tell the codec driver what the MCLK frequency is, and whether it's
	 * a slave or master.
	 */
	if (codec_dai->dai_ops.set_sysclk) {
		ret = codec_dai->dai_ops.set_sysclk(codec_dai, 0,
			machine_data->clk_frequency,
			machine_data->codec_clk_direction);
		if (ret < 0) {
			dev_err(substream->pcm->card->dev,
				"could not set codec driver clock params\n");
			return ret;
		}
	}

	return 0;
}

/**
 * mpc8610_hpcd_machine_remove: Remove the sound device
 *
 * This function is called to remove the sound device for one SSI.  We
 * de-program the DMACR and PMUXCR register.
 */
int mpc8610_hpcd_machine_remove(struct platform_device *sound_device)
{
	struct mpc8610_hpcd_data *machine_data =
		sound_device->dev.platform_data;

	/* Restore the signal routing */

	guts_set_dmacr(machine_data->guts, machine_data->dma_id,
		machine_data->dma_channel_id[0], 0);
	guts_set_dmacr(machine_data->guts, machine_data->dma_id,
		machine_data->dma_channel_id[1], 0);

	switch (machine_data->ssi_id) {
	case 0:
		clrsetbits_be32(&machine_data->guts->pmuxcr,
			CCSR_GUTS_PMUXCR_SSI1_MASK, CCSR_GUTS_PMUXCR_SSI1_LA);
		break;
	case 1:
		clrsetbits_be32(&machine_data->guts->pmuxcr,
			CCSR_GUTS_PMUXCR_SSI2_MASK, CCSR_GUTS_PMUXCR_SSI2_LA);
		break;
	}

	return 0;
}

/**
 * mpc8610_hpcd_ops: ASoC fabric driver operations
 */
static struct snd_soc_ops mpc8610_hpcd_ops = {
	.startup = mpc8610_hpcd_startup,
};

/**
 * mpc8610_hpcd_machine: ASoC machine data
 */
static struct snd_soc_machine mpc8610_hpcd_machine = {
	.probe = mpc8610_hpcd_machine_probe,
{'fraction_non_alphanumeric': 0.10714285714285714, 'fraction_numerical': 0.026976586359009163, 'mean_word_length': 4.539943609022556, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 155, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1527067', 'n_tokens_mistral': 4963, 'n_tokens_neox': 4613, 'n_words': 1040}