Skip to content

Commit

Permalink
ASoC: starfive: Add StarFive JH7100 audio drivers
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Yan <[email protected]>
Signed-off-by: Jenny Zhang <[email protected]>
Signed-off-by: Walker Chen <[email protected]>
Signed-off-by: Emil Renner Berthing <[email protected]>
  • Loading branch information
WalkerChenL authored and esmil committed Dec 27, 2021
1 parent 9ed64a0 commit ebcaa4f
Show file tree
Hide file tree
Showing 16 changed files with 4,257 additions and 0 deletions.
1 change: 1 addition & 0 deletions sound/soc/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ source "sound/soc/sh/Kconfig"
source "sound/soc/sof/Kconfig"
source "sound/soc/spear/Kconfig"
source "sound/soc/sprd/Kconfig"
source "sound/soc/starfive/Kconfig"
source "sound/soc/sti/Kconfig"
source "sound/soc/stm/Kconfig"
source "sound/soc/sunxi/Kconfig"
Expand Down
1 change: 1 addition & 0 deletions sound/soc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ obj-$(CONFIG_SND_SOC) += pxa/
obj-$(CONFIG_SND_SOC) += qcom/
obj-$(CONFIG_SND_SOC) += rockchip/
obj-$(CONFIG_SND_SOC) += samsung/
obj-$(CONFIG_SND_SOC) += starfive/
obj-$(CONFIG_SND_SOC) += sh/
obj-$(CONFIG_SND_SOC) += sof/
obj-$(CONFIG_SND_SOC) += spear/
Expand Down
55 changes: 55 additions & 0 deletions sound/soc/starfive/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2021 StarFive Technology Co., Ltd.

config SND_STARFIVE_SPDIF
tristate "starfive spdif"
select SND_SOC_GENERIC_DMAENGINE_PCM
select REGMAP_MMIO
help
Say Y or M if you want to add support for codecs attached to the
I2S interface on VIC vic_starlight board. You will also need to select
the drivers for the rest of VIC audio subsystem.

config SND_STARFIVE_SPDIF_PCM
bool "PCM PIO extension for spdif driver"
depends on SND_STARFIVE_SPDIF
help
Say Y or N if you want to add a custom ALSA extension that registers
a PCM and uses PIO to transfer data.

config SND_STARFIVE_PWMDAC
tristate "starfive pwmdac Device Driver"
select SND_SOC_GENERIC_DMAENGINE_PCM
help
Say Y or M if you want to add support for sf pwmdac driver.

config SND_STARFIVE_PWMDAC_PCM
bool "PCM PIO extension for pwmdac driver"
depends on SND_STARFIVE_PWMDAC
help
Say Y or N if you want to add a custom ALSA extension that registers
a PCM and uses PIO to transfer data.

config SND_STARFIVE_PDM
tristate "starfive pdm Device Driver"
select REGMAP_MMIO
help
Say Y or M if you want to add support for sf pdm driver.

config SND_STARFIVE_I2SVAD
tristate "starfive I2SVAD Device Driver"
select SND_SOC_GENERIC_DMAENGINE_PCM
help
Say Y or M if you want to add support for I2SVAD driver for
starfive I2SVAD device.

config SND_STARFIVE_I2SVAD_PCM
bool "PCM PIO extension for I2SVAD driver"
depends on SND_STARFIVE_I2SVAD
help
Say Y or N if you want to add a custom ALSA extension that registers
a PCM and uses PIO to transfer data.

This functionality is specially suited for I2SVAD devices that don't have
DMA support.

19 changes: 19 additions & 0 deletions sound/soc/starfive/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# SPDX-License-Identifier: GPL-2.0
#
# Copyright (C) 2021 StarFive Technology Co., Ltd.
#
obj-$(CONFIG_SND_STARFIVE_SPDIF) += spdif.o

spdif-y := starfive_spdif.o
spdif-$(CONFIG_SND_STARFIVE_SPDIF_PCM) += starfive_spdif_pcm.o

obj-$(CONFIG_SND_STARFIVE_PWMDAC) += pwmdac.o

pwmdac-y := starfive_pwmdac.o starfive_pwmdac_transmitter.o
pwmdac-$(CONFIG_SND_STARFIVE_PWMDAC_PCM) += starfive_pwmdac_pcm.o

obj-$(CONFIG_SND_STARFIVE_PDM) += starfive_pdm.o

obj-$(CONFIG_SND_STARFIVE_I2SVAD) += i2svad.o
i2svad-y := starfive_i2svad.o
i2svad-$(CONFIG_SND_STARFIVE_I2SVAD_PCM) += starfive_i2svad_pcm.o
153 changes: 153 additions & 0 deletions sound/soc/starfive/pwmdac.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2021 StarFive Technology Co., Ltd.
*/
#ifndef __STARFIVE_PWMDAC_LOCAL_H
#define __STARFIVE_PWMDAC_LOCAL_H

#include <linux/clk.h>
#include <linux/reset.h>
#include <linux/device.h>
#include <linux/types.h>
#include <sound/dmaengine_pcm.h>
#include <sound/pcm.h>

#define PWMDAC_WDATA 0 ///PWMDAC_BASE_ADDR
#define PWMDAC_CTRL 0x04 ///PWMDAC_BASE_ADDR + 0x04
#define PWMDAC_SATAE 0x08 ///PWMDAC_BASE_ADDR + 0x08
#define PWMDAC_RESERVED 0x0C ///PWMDAC_BASE_ADDR + 0x0C

#define SFC_PWMDAC_SHIFT BIT(1)
#define SFC_PWMDAC_DUTY_CYCLE BIT(2)
#define SFC_PWMDAC_CNT_N BIT(4)

#define SFC_PWMDAC_LEFT_RIGHT_DATA_CHANGE BIT(13)
#define SFC_PWMDAC_DATA_MODE BIT(14)

#define FIFO_UN_FULL 0
#define FIFO_FULL 1

enum pwmdac_lr_change{
NO_CHANGE = 0,
CHANGE,
};

enum pwmdac_d_mode{
UNSINGED_DATA = 0,
INVERTER_DATA_MSB,
};

enum pwmdac_shift_bit{
PWMDAC_SHIFT_8 = 8, /*pwmdac shift 8 bit*/
PWMDAC_SHIFT_10 = 10, /*pwmdac shift 10 bit*/
};

enum pwmdac_duty_cycle{
PWMDAC_CYCLE_LEFT = 0, /*pwmdac duty cycle left*/
PWMDAC_CYCLE_RIGHT = 1, /*pwmdac duty cycle right*/
PWMDAC_CYCLE_CENTER = 2, /*pwmdac duty cycle center*/
};

/*sample count [12:4] <511*/
enum pwmdac_sample_count{
PWMDAC_SAMPLE_CNT_1 = 1,
PWMDAC_SAMPLE_CNT_2,
PWMDAC_SAMPLE_CNT_3,
PWMDAC_SAMPLE_CNT_4,
PWMDAC_SAMPLE_CNT_5,
PWMDAC_SAMPLE_CNT_6,
PWMDAC_SAMPLE_CNT_7,
PWMDAC_SAMPLE_CNT_8 = 1, //(32.468/8) == (12.288/3) == 4.096
PWMDAC_SAMPLE_CNT_9,
PWMDAC_SAMPLE_CNT_10,
PWMDAC_SAMPLE_CNT_11,
PWMDAC_SAMPLE_CNT_12,
PWMDAC_SAMPLE_CNT_13,
PWMDAC_SAMPLE_CNT_14,
PWMDAC_SAMPLE_CNT_15,
PWMDAC_SAMPLE_CNT_16,
PWMDAC_SAMPLE_CNT_17,
PWMDAC_SAMPLE_CNT_18,
PWMDAC_SAMPLE_CNT_19,
PWMDAC_SAMPLE_CNT_20 = 20,
PWMDAC_SAMPLE_CNT_30 = 30,
PWMDAC_SAMPLE_CNT_511 = 511,
};


enum data_shift{
PWMDAC_DATA_LEFT_SHIFT_BIT_0 = 0,
PWMDAC_DATA_LEFT_SHIFT_BIT_1,
PWMDAC_DATA_LEFT_SHIFT_BIT_2,
PWMDAC_DATA_LEFT_SHIFT_BIT_3,
PWMDAC_DATA_LEFT_SHIFT_BIT_4,
PWMDAC_DATA_LEFT_SHIFT_BIT_5,
PWMDAC_DATA_LEFT_SHIFT_BIT_6,
PWMDAC_DATA_LEFT_SHIFT_BIT_7,
PWMDAC_DATA_LEFT_SHIFT_BIT_ALL,
};

enum pwmdac_config_list{
shift_8Bit_unsigned = 0,
shift_8Bit_unsigned_dataShift,
shift_10Bit_unsigned,
shift_10Bit_unsigned_dataShift,

shift_8Bit_inverter,
shift_8Bit_inverter_dataShift,
shift_10Bit_inverter,
shift_10Bit_inverter_dataShift,
};

struct sf_pwmdac_dev {
void __iomem *pwmdac_base;
resource_size_t mapbase;
u8 mode;
u8 shift_bit;
u8 duty_cycle;
u8 datan;
u8 data_mode;
u8 lr_change;
u8 shift;
u8 fifo_th;
bool use_pio;
spinlock_t lock;
int active;

struct clk *clk_audio_root;
struct clk *clk_audio_src;
struct clk *clk_audio_12288;
struct clk *clk_dma1p_ahb;
struct clk *clk_pwmdac_apb;
struct clk *clk_dac_mclk;
struct reset_control *rst_apb_bus;
struct reset_control *rst_dma1p_ahb;
struct reset_control *rst_apb_pwmdac;

struct device *dev;
struct snd_dmaengine_dai_dma_data play_dma_data;
struct snd_pcm_substream __rcu *tx_substream;
unsigned int (*tx_fn)(struct sf_pwmdac_dev *dev,
struct snd_pcm_runtime *runtime, unsigned int tx_ptr,
bool *period_elapsed);
unsigned int tx_ptr;
struct task_struct *tx_thread;
bool tx_thread_exit;
};



#if IS_ENABLED(CONFIG_SND_STARFIVE_PWMDAC_PCM)
void sf_pwmdac_pcm_push_tx(struct sf_pwmdac_dev *dev);
void sf_pwmdac_pcm_pop_rx(struct sf_pwmdac_dev *dev);
int sf_pwmdac_pcm_register(struct platform_device *pdev);
#else
void sf_pwmdac_pcm_push_tx(struct sf_pwmdac_dev *dev) { }
void sf_pwmdac_pcm_pop_rx(struct sf_pwmdac_dev *dev) { }
int sf_pwmdac_pcm_register(struct platform_device *pdev)
{
return -EINVAL;
}
#endif

#endif
Loading

0 comments on commit ebcaa4f

Please sign in to comment.