From dc09fa002077c60a2937febc1b639eaf367de461 Mon Sep 17 00:00:00 2001 From: August <2819763+Dangku@users.noreply.github.com> Date: Fri, 7 Jun 2024 20:47:20 +0800 Subject: [PATCH] bpi-m4berry support waveshare wm8960 hat and nxez pcm5122 hat --- arch/arm64/boot/dts/sunxi/overlay/Makefile | 5 ++ .../overlay/bpi-m4berry-nxez-pcm512x-hifi.dts | 37 +++++++++++ .../bpi-m4berry-waveshare-wm8960-hifi.dts | 66 +++++++++++++++++++ .../sunxi/sun50i-h616-bananapi-m4berry.dts | 9 --- arch/arm64/configs/bananapi_m4berry_defconfig | 5 +- sound/soc/codecs/wm8960.c | 17 +++++ 6 files changed, 128 insertions(+), 11 deletions(-) create mode 100755 arch/arm64/boot/dts/sunxi/overlay/bpi-m4berry-nxez-pcm512x-hifi.dts create mode 100755 arch/arm64/boot/dts/sunxi/overlay/bpi-m4berry-waveshare-wm8960-hifi.dts diff --git a/arch/arm64/boot/dts/sunxi/overlay/Makefile b/arch/arm64/boot/dts/sunxi/overlay/Makefile index d970e2c8f..392f47e5b 100755 --- a/arch/arm64/boot/dts/sunxi/overlay/Makefile +++ b/arch/arm64/boot/dts/sunxi/overlay/Makefile @@ -1,5 +1,10 @@ # SPDX-License-Identifier: GPL-2.0 +dtbo-$(CONFIG_ARCH_SUNXI) += \ + bpi-m4berry-i2c4.dtbo \ + bpi-m4berry-nxez-pcm512x-hifi.dtbo \ + bpi-m4berry-waveshare-wm8960-hifi.dtbo + targets += $(dtbo-y) $(scr-y) $(dtbotxt-y) always := $(dtbo-y) $(scr-y) $(dtbotxt-y) diff --git a/arch/arm64/boot/dts/sunxi/overlay/bpi-m4berry-nxez-pcm512x-hifi.dts b/arch/arm64/boot/dts/sunxi/overlay/bpi-m4berry-nxez-pcm512x-hifi.dts new file mode 100755 index 000000000..3268c23b7 --- /dev/null +++ b/arch/arm64/boot/dts/sunxi/overlay/bpi-m4berry-nxez-pcm512x-hifi.dts @@ -0,0 +1,37 @@ +/dts-v1/; +/plugin/; + +/ { + fragment@0 { + target = <&twi4>; + __overlay__ { + status = "okay"; + + pcm5122: pcm5122@4d { + compatible = "ti,pcm5122"; + reg = <0x4d>; + #sound-dai-cells = <0>; + status = "okay"; + }; + }; + }; + + fragment@1 { + target = <&ahub2_plat>; + __overlay__ { + status = "okay"; + }; + }; + + fragment@2 { + target = <&ahub2_mach>; + __overlay__ { + status = "okay"; + + soundcard-mach,playback-only; + soundcard-mach,codec { + sound-dai = <&pcm5122>; + }; + }; + }; +}; diff --git a/arch/arm64/boot/dts/sunxi/overlay/bpi-m4berry-waveshare-wm8960-hifi.dts b/arch/arm64/boot/dts/sunxi/overlay/bpi-m4berry-waveshare-wm8960-hifi.dts new file mode 100755 index 000000000..3d1c554bb --- /dev/null +++ b/arch/arm64/boot/dts/sunxi/overlay/bpi-m4berry-waveshare-wm8960-hifi.dts @@ -0,0 +1,66 @@ +/dts-v1/; +/plugin/; + +/ { + fragment@0 { + target-path = "/"; + + __overlay__ { + wm8960_mclk: wm8960_mclk { + compatible = "fixed-clock"; + status = "okay"; + #clock-cells = <0x0>; + clock-frequency = <0xbb8000>; + }; + }; + }; + + fragment@1 { + target = <&twi4>; + __overlay__ { + status = "okay"; + + wm8960: wm8960@1a { + #sound-dai-cells = <0>; + compatible = "wlf,wm8960"; + reg = <0x1a>; + status = "okay"; + clocks = <&wm8960_mclk>; + clock-names = "mclk"; + }; + }; + }; + + fragment@2 { + target = <&ahub2_plat>; + __overlay__ { + status = "okay"; + }; + }; + + fragment@3 { + target = <&ahub2_mach>; + __overlay__ { + status = "okay"; + + soundcard-mach,widgets = + "Microphone", "Mic Jack", + "Line", "Line In", + "Line", "Line Out", + "Speaker", "Speaker", + "Headphone", "Headphone Jack"; + soundcard-mach,routing = + "Headphone Jack", "HP_L", + "Headphone Jack", "HP_R", + "Speaker", "SPK_LP", + "Speaker", "SPK_LN", + "LINPUT1", "Mic Jack", + "LINPUT3", "Mic Jack", + "RINPUT1", "Mic Jack", + "RINPUT2", "Mic Jack"; + soundcard-mach,codec { + sound-dai = <&wm8960>; + }; + }; + }; +}; diff --git a/arch/arm64/boot/dts/sunxi/sun50i-h616-bananapi-m4berry.dts b/arch/arm64/boot/dts/sunxi/sun50i-h616-bananapi-m4berry.dts index 6d4a9e2a2..a7aa303da 100644 --- a/arch/arm64/boot/dts/sunxi/sun50i-h616-bananapi-m4berry.dts +++ b/arch/arm64/boot/dts/sunxi/sun50i-h616-bananapi-m4berry.dts @@ -2888,14 +2888,6 @@ pinctrl-1 = <0x77>; }; - wm8960_mclk { - compatible = "fixed-clock"; - status = "disabled"; - #clock-cells = <0x0>; - clock-frequency = <0xbb8000>; - phandle = <0x78>; - }; - __symbols__ { cpu0 = "/cpus/cpu@0"; CPU_SLEEP = "/cpus/idle-states/cpu-sleep"; @@ -3110,6 +3102,5 @@ cpu_threshold = "/thermal-zones/cpu_thermal_zone/trips/trip-point@0"; cpu_target = "/thermal-zones/cpu_thermal_zone/trips/trip-point@1"; cpu_crit = "/thermal-zones/cpu_thermal_zone/trips/cpu_crit@0"; - wm8960_mclk = "/wm8960_mclk"; }; }; diff --git a/arch/arm64/configs/bananapi_m4berry_defconfig b/arch/arm64/configs/bananapi_m4berry_defconfig index ae2aa04b2..8f54040b2 100644 --- a/arch/arm64/configs/bananapi_m4berry_defconfig +++ b/arch/arm64/configs/bananapi_m4berry_defconfig @@ -4347,7 +4347,8 @@ CONFIG_SND_SOC_I2C_AND_SPI=y # CONFIG_SND_SOC_PCM3060_SPI is not set # CONFIG_SND_SOC_PCM3168A_I2C is not set # CONFIG_SND_SOC_PCM3168A_SPI is not set -# CONFIG_SND_SOC_PCM512x_I2C is not set +CONFIG_SND_SOC_PCM512x=m +CONFIG_SND_SOC_PCM512x_I2C=m # CONFIG_SND_SOC_PCM512x_SPI is not set # CONFIG_SND_SOC_RK3328 is not set # CONFIG_SND_SOC_RT5616 is not set @@ -4398,7 +4399,7 @@ CONFIG_SND_SOC_I2C_AND_SPI=y # CONFIG_SND_SOC_WM8804_SPI is not set # CONFIG_SND_SOC_WM8903 is not set # CONFIG_SND_SOC_WM8904 is not set -# CONFIG_SND_SOC_WM8960 is not set +CONFIG_SND_SOC_WM8960=m # CONFIG_SND_SOC_WM8962 is not set # CONFIG_SND_SOC_WM8974 is not set # CONFIG_SND_SOC_WM8978 is not set diff --git a/sound/soc/codecs/wm8960.c b/sound/soc/codecs/wm8960.c index 708fc4ed5..994db7dab 100644 --- a/sound/soc/codecs/wm8960.c +++ b/sound/soc/codecs/wm8960.c @@ -1403,6 +1403,7 @@ static int wm8960_i2c_probe(struct i2c_client *i2c, struct wm8960_data *pdata = dev_get_platdata(&i2c->dev); struct wm8960_priv *wm8960; int ret; + u8 val; wm8960 = devm_kzalloc(&i2c->dev, sizeof(struct wm8960_priv), GFP_KERNEL); @@ -1413,6 +1414,14 @@ static int wm8960_i2c_probe(struct i2c_client *i2c, if (IS_ERR(wm8960->mclk)) { if (PTR_ERR(wm8960->mclk) == -EPROBE_DEFER) return -EPROBE_DEFER; + } else { + ret = clk_get_rate(wm8960->mclk); + if (ret >= 0) { + wm8960->freq_in = ret; + } else { + dev_err(&i2c->dev, "Failed to read MCLK rate: %d\n", + ret); + } } wm8960->regmap = devm_regmap_init_i2c(i2c, &wm8960_regmap); @@ -1424,6 +1433,12 @@ static int wm8960_i2c_probe(struct i2c_client *i2c, else if (i2c->dev.of_node) wm8960_set_pdata_from_of(i2c, &wm8960->pdata); + ret = i2c_master_recv(i2c, &val, sizeof(val)); + if (ret >= 0) { + dev_err(&i2c->dev, "Not wm8960, wm8960 reg can not read by i2c\n"); + return -EINVAL; + } + ret = wm8960_reset(wm8960->regmap); if (ret != 0) { dev_err(&i2c->dev, "Failed to issue reset\n"); @@ -1471,11 +1486,13 @@ static const struct i2c_device_id wm8960_i2c_id[] = { }; MODULE_DEVICE_TABLE(i2c, wm8960_i2c_id); +#if defined(CONFIG_OF) static const struct of_device_id wm8960_of_match[] = { { .compatible = "wlf,wm8960", }, { } }; MODULE_DEVICE_TABLE(of, wm8960_of_match); +#endif static struct i2c_driver wm8960_i2c_driver = { .driver = {