Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
waveshare committed Apr 15, 2024
1 parent 8141dad commit 20559ed
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 12 deletions.
16 changes: 8 additions & 8 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ver="1.0"
marker="0.0.0"

apt update
apt-get -y install raspberrypi-kernel-headers raspberrypi-kernel
apt-get -y install raspberrypi-kernel-headers #raspberrypi-kernel
apt-get -y install dkms git i2c-tools libasound2-plugins

# locate currently installed kernels (may be different to running kernel if
Expand Down Expand Up @@ -62,15 +62,15 @@ grep -q "snd-soc-wm8960-soundcard" /etc/modules || \
echo "snd-soc-wm8960-soundcard" >> /etc/modules

#set dtoverlays
sed -i -e 's:#dtparam=i2c_arm=on:dtparam=i2c_arm=on:g' /boot/config.txt || true
grep -q "dtoverlay=i2s-mmap" /boot/config.txt || \
echo "dtoverlay=i2s-mmap" >> /boot/config.txt
sed -i -e 's:#dtparam=i2c_arm=on:dtparam=i2c_arm=on:g' /boot/firmware/config.txt || true
grep -q "dtoverlay=i2s-mmap" /boot/firmware/config.txt || \
echo "dtoverlay=i2s-mmap" >> /boot/firmware/config.txt

grep -q "dtparam=i2s=on" /boot/config.txt || \
echo "dtparam=i2s=on" >> /boot/config.txt
grep -q "dtparam=i2s=on" /boot/firmware/config.txt || \
echo "dtparam=i2s=on" >> /boot/firmware/config.txt

#grep -q "dtoverlay=wm8960-soundcard" /boot/config.txt || \
# echo "dtoverlay=wm8960-soundcard" >> /boot/config.txt
grep -q "dtoverlay=wm8960-soundcard" /boot/firmware/config.txt || \
echo "dtoverlay=wm8960-soundcard" >> /boot/firmware/config.txt

This comment has been minimized.

Copy link
@philboe86

philboe86 Nov 13, 2024

this does not work on systems < bookworm and breaks things


#install config files
mkdir /etc/wm8960-soundcard || true
Expand Down
148 changes: 148 additions & 0 deletions seed
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
#!/bin/bash
#
# Copyright (c) 2018 Baozhu Zuo <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

set -x
#exec 1>/var/log/$(basename $0).log 2>&1

export PATH=$PATH:/opt/vc/bin
OVERLAYS=/boot/overlays
[ -d /boot/firmware/overlays ] && OVERLAYS=/boot/firmware/overlays

#enable i2c interface
dtparam -d $OVERLAYS i2c_arm=on
modprobe i2c-dev

#enable spi interface
dtparam -d $OVERLAYS spi=on

_VER_RUN=
function get_kernel_version() {
local ZIMAGE IMG_OFFSET

_VER_RUN=""
[ -z "$_VER_RUN" ] && {
ZIMAGE=/boot/kernel.img
IMG_OFFSET=$(LC_ALL=C grep -abo $'\x1f\x8b\x08\x00' $ZIMAGE | head -n 1 | cut -d ':' -f 1)
# 64-bit-only kernel package
[ ! -f /boot/kernel.img ] && [ -f /boot/kernel8.img ] && ZIMAGE=/boot/kernel8.img
_VER_RUN=$(dd if=$ZIMAGE obs=64K ibs=4 skip=$(( IMG_OFFSET / 4)) 2>/dev/null | zcat | grep -a -m1 "Linux version" | LC_ALL=C sed -e 's/^.*Linux/Linux/' | strings | awk '{ print $3; }')
}
echo "$_VER_RUN"
return 0
}

CONFIG=/boot/config.txt
[ -f /boot/firmware/usercfg.txt ] && CONFIG=/boot/firmware/usercfg.txt

get_overlay() {
ov=$1
if grep -q -E "^dtoverlay=$ov" $CONFIG; then
echo 0
else
echo 1
fi
}

do_overlay() {
ov=$1
RET=$2
DEFAULT=--defaultno
CURRENT=0
if [ $(get_overlay $ov) -eq 0 ]; then
DEFAULT=
CURRENT=1
fi
if [ $RET -eq $CURRENT ]; then
ASK_TO_REBOOT=1
fi
if [ $RET -eq 0 ]; then
sed $CONFIG -i -e "s/^#dtoverlay=$ov/dtoverlay=$ov/"
if ! grep -q -E "^dtoverlay=$ov" $CONFIG; then
printf "dtoverlay=$ov\n" >> $CONFIG
fi
STATUS=enabled
elif [ $RET -eq 1 ]; then
sed $CONFIG -i -e "s/^dtoverlay=$ov/#dtoverlay=$ov/"
STATUS=disabled
else
return $RET
fi
}


is_1a=$(i2cdetect -y 1 0x1a 0x1a | egrep "(1a|UU)" | awk '{print $2}')

RPI_HATS="wm8960-soundcard"
overlay=""

if [ "x${is_1a}" != "x" ] && [ "x${is_35}" == "x" ] ; then
echo "install 2mic"
overlay=wm8960-soundcard
asound_conf=/etc/wm8960-soundcard/asound.conf
asound_state=/etc/wm8960-soundcard/wm8960_asound.state
fi

if [ "$overlay" ]; then
echo Install $overlay ...

# Remove old configuration
rm /etc/asound.conf
rm /var/lib/alsa/asound.state

kernel_ver=$(uname -r) # get_kernel_version)
# echo kernel_ver=$kernel_ver

# TODO: dynamic dtoverlay Bug of v4.19.x
# no DT node phandle inserted.
if [[ "$kernel_ver" =~ ^4\.19.*$ || "$kernel_ver" =~ ^5\.*$ ]]; then
for i in $RPI_HATS; do
if [ "$i" == "$overlay" ]; then
/bin/true #do_overlay $overlay 0
else
echo Uninstall $i ...
/bin/true #do_overlay $i 1
fi
done
fi
#make sure the driver loads correctly
dtoverlay -d $OVERLAYS $overlay || true


echo "create $overlay asound configure file"
ln -s $asound_conf /etc/asound.conf
echo "create $overlay asound status file"
ln -s $asound_state /var/lib/alsa/asound.state
fi

alsactl restore

#Force 3.5mm ('headphone') jack
# The Raspberry Pi 4, released on 24th Jun 2019, has two HDMI ports,
# and can drive two displays with audios for two users simultaneously,
# in a "multiseat" configuration. The earlier single virtual ALSA
# option for re-directing audio playback between headphone jack and HDMI
# via a 'Routing' mixer setting was turned off eventually to allow
# simultaneous usage of all 3 playback devices.
if aplay -l | grep -q "bcm2835 ALSA"; then
amixer cset numid=3 1 || true
fi

2 changes: 1 addition & 1 deletion wm8960-soundcard.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ static int asoc_simple_parse_dai(struct device_node *node,
* 2) user need to rebind Sound Card everytime
* if he unbinded CPU or Codec.
*/
ret = snd_soc_of_get_dai_name(node, &dlc->dai_name);
ret = snd_soc_of_get_dai_name(node, &dlc->dai_name,0);
if (ret < 0)
return ret;

Expand Down
5 changes: 2 additions & 3 deletions wm8960.c
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ static int wm8960_hw_params(struct snd_pcm_substream *substream,
iface |= 0x000c;
break;
}
/* fall through */
fallthrough;
default:
dev_err(component->dev, "unsupported width %d\n",
params_width(params));
Expand Down Expand Up @@ -1440,8 +1440,7 @@ static void wm8960_set_pdata_from_of(struct i2c_client *i2c,
pdata->shared_lrclk = true;
}

static int wm8960_i2c_probe(struct i2c_client *i2c,
const struct i2c_device_id *id)
static int wm8960_i2c_probe(struct i2c_client *i2c)
{
struct wm8960_data *pdata = dev_get_platdata(&i2c->dev);
struct wm8960_priv *wm8960;
Expand Down

0 comments on commit 20559ed

Please sign in to comment.