diff --git a/userspace/root/usr/comma/init.qcom.sh b/userspace/root/usr/comma/init.qcom.sh index f670c99..7aba08e 100755 --- a/userspace/root/usr/comma/init.qcom.sh +++ b/userspace/root/usr/comma/init.qcom.sh @@ -12,11 +12,24 @@ done echo 2649600 | sudo tee /sys/devices/system/cpu/cpufreq/policy0/scaling_max_freq echo 2649600 | sudo tee /sys/devices/system/cpu/cpufreq/policy4/scaling_max_freq +# setup firmware +echo -n "/firmware/image" > /sys/module/firmware_class/parameters/path +count=0 +while [ ! -s /firmware/image/adsp.mdt ]; do + # wait 10s for /firmware mounted + count=$(( $count + 1 )) + if [ $count -ge 100 ]; then + echo "[ERROR] /firmware not mounted" + fi + sleep 0.1 +done + # boot wifi -echo 1 | sudo tee /sys/kernel/boot_wlan/boot_wlan +echo 1 > /sys/kernel/boot_wlan/boot_wlan /usr/bin/irsc_util /etc/sec_config -# cdsp +# boot audio + compute DSPs +echo 1 > /sys/kernel/boot_adsp/boot echo 1 > /sys/kernel/boot_cdsp/boot # ipa diff --git a/userspace/root/usr/comma/sound/adsp-start.sh b/userspace/root/usr/comma/sound/adsp-start.sh deleted file mode 100755 index 675dbf9..0000000 --- a/userspace/root/usr/comma/sound/adsp-start.sh +++ /dev/null @@ -1,68 +0,0 @@ -#!/bin/sh -############################################################################### -# -# This script is used for administration of the Hexagon DSP -# -# Copyright (c) 2012-2016 Qualcomm Technologies, Inc. -# All Rights Reserved. -# Confidential and Proprietary - Qualcomm Technologies, Inc. -# -############################################################################### - -KEEP_ALIVE=0 -subsys_name="" - -echo -n "/firmware/image" > /sys/module/firmware_class/parameters/path - -# Wait for adsp.mdt to show up -count=0 -while [ ! -s /firmware/image/adsp.mdt ]; do - sleep 0.1 - # wait 10s for /firmware mounted - count=$(( $count + 1 )) - if [ $count -ge 100 ]; then - echo "[ERROR] Can not find the adsp's firmware" - exit 1 - fi -done - -for subsys in `ls /sys/bus/msm_subsys/devices`; do - name=`cat /sys/bus/msm_subsys/devices/${subsys}/name` - if [ "`cat /sys/bus/msm_subsys/devices/${subsys}/name`" = "adsp" ]; then - subsys_name="${subsys}" - break - fi -done - -if [ "$KEEP_ALIVE" = "1" ]; then - if [ -n "${subsys_name}" ]; then - sysctl -w kernel.panic=0 - echo 1 > /sys/bus/msm_subsys/devices/${subsys_name}/keep_alive - else - echo "[ERROR] Can not keep adsp alive" - fi -fi - -# FIXME: See ATL-3054 -echo 1 > /sys/module/subsystem_restart/parameters/enable_debug -# Bring adsp out of reset -echo "[INFO] Bringing adsp out of reset" -echo "${subsys_name}" -echo 1 > /sys/kernel/boot_adsp/boot - -# wait boot finished -if [ -n "${subsys_name}" ]; then - count=0 - state=`cat /sys/bus/msm_subsys/devices/${subsys_name}/state` - while [ "${state}" != "ONLINE" ]; do - # wait 2s for subsys boot finished - count=$(( $count + 1 )) - if [ $count -ge 200 ]; then - echo "[ERROR] adsp fail to boot" - exit 1 - fi - state=`cat /sys/bus/msm_subsys/devices/${subsys_name}/state` - sleep 0.1 - done -fi - diff --git a/userspace/root/usr/comma/sound/amplifier.py b/userspace/root/usr/comma/sound/amplifier.py deleted file mode 100755 index dbc7994..0000000 --- a/userspace/root/usr/comma/sound/amplifier.py +++ /dev/null @@ -1,161 +0,0 @@ -#!/usr/bin/env python3 -import time -from smbus2 import SMBus -from collections import namedtuple -from typing import List - -# https://datasheets.maximintegrated.com/en/ds/MAX98089.pdf - -AmpConfig = namedtuple('AmpConfig', ['name', 'value', 'register', 'offset', 'mask']) -EQParams = namedtuple('EQParams', ['K', 'k1', 'k2', 'c1', 'c2']) - -def configs_from_eq_params(base, eq_params): - return [ - AmpConfig("K (high)", (eq_params.K >> 8), base, 0, 0xFF), - AmpConfig("K (low)", (eq_params.K & 0xFF), base + 1, 0, 0xFF), - AmpConfig("k1 (high)", (eq_params.k1 >> 8), base + 2, 0, 0xFF), - AmpConfig("k1 (low)", (eq_params.k1 & 0xFF), base + 3, 0, 0xFF), - AmpConfig("k2 (high)", (eq_params.k2 >> 8), base + 4, 0, 0xFF), - AmpConfig("k2 (low)", (eq_params.k2 & 0xFF), base + 5, 0, 0xFF), - AmpConfig("c1 (high)", (eq_params.c1 >> 8), base + 6, 0, 0xFF), - AmpConfig("c1 (low)", (eq_params.c1 & 0xFF), base + 7, 0, 0xFF), - AmpConfig("c2 (high)", (eq_params.c2 >> 8), base + 8, 0, 0xFF), - AmpConfig("c2 (low)", (eq_params.c2 & 0xFF), base + 9, 0, 0xFF), - ] - -BASE_CONFIG = [ - AmpConfig("MCLK prescaler", 0b01, 0x10, 4, 0b00110000), - AmpConfig("PM: enable speakers", 0b11, 0x4D, 4, 0b00110000), - AmpConfig("PM: enable DACs", 0b11, 0x4D, 0, 0b00000011), - AmpConfig("Enable PLL1", 0b1, 0x12, 7, 0b10000000), - AmpConfig("Enable PLL2", 0b1, 0x1A, 7, 0b10000000), - AmpConfig("DAI1: I2S mode", 0b00100, 0x14, 2, 0b01111100), - AmpConfig("DAI2: I2S mode", 0b00100, 0x1C, 2, 0b01111100), - AmpConfig("DAI1 Passband filtering: music mode", 0b1, 0x18, 7, 0b10000000), - AmpConfig("DAI1 voice mode gain (DV1G)", 0b00, 0x2F, 4, 0b00110000), - AmpConfig("DAI1 attenuation (DV1)", 0x0, 0x2F, 0, 0b00001111), - AmpConfig("DAI2 attenuation (DV2)", 0x0, 0x31, 0, 0b00001111), - AmpConfig("DAI2: DC blocking", 0b1, 0x20, 0, 0b00000001), - AmpConfig("DAI2: High sample rate", 0b0, 0x20, 3, 0b00001000), - AmpConfig("ALC enable", 0b1, 0x43, 7, 0b10000000), - AmpConfig("ALC/excursion limiter release time", 0b101, 0x43, 4, 0b01110000), - AmpConfig("ALC multiband enable", 0b1, 0x43, 3, 0b00001000), - AmpConfig("DAI1 EQ enable", 0b0, 0x49, 0, 0b00000001), - AmpConfig("DAI2 EQ clip detection disabled", 0b1, 0x32, 4, 0b00010000), - AmpConfig("DAI2 EQ attenuation", 0x5, 0x32, 0, 0b00001111), - AmpConfig("Excursion limiter upper corner freq", 0b100, 0x41, 4, 0b01110000), - AmpConfig("Excursion limiter lower corner freq", 0b00, 0x41, 0, 0b00000011), - AmpConfig("Excursion limiter threshold", 0b000, 0x42, 0, 0b00001111), - AmpConfig("Distortion limit (THDCLP)", 0x6, 0x46, 4, 0b11110000), - AmpConfig("Distortion limiter release time constant", 0b0, 0x46, 0, 0b00000001), - AmpConfig("Right DAC input mixer: DAI1 left", 0b0, 0x22, 3, 0b00001000), - AmpConfig("Right DAC input mixer: DAI1 right", 0b0, 0x22, 2, 0b00000100), - AmpConfig("Right DAC input mixer: DAI2 left", 0b1, 0x22, 1, 0b00000010), - AmpConfig("Right DAC input mixer: DAI2 right", 0b0, 0x22, 0, 0b00000001), - AmpConfig("DAI1 audio port selector", 0b10, 0x16, 6, 0b11000000), - AmpConfig("DAI1 in/output enable", 0b11, 0x16, 0, 0b11), - AmpConfig("DAI2 audio port selector", 0b01, 0x1E, 6, 0b11000000), - AmpConfig("DAI2 in/output enable", 0b11, 0x1E, 0, 0b11), - AmpConfig("Enable left digital microphone", 0b1, 0x48, 5, 0b00100000), - AmpConfig("Enable right digital microphone", 0b1, 0x48, 4, 0b00010000), - AmpConfig("Enhanced volume smoothing disabled", 0b0, 0x49, 7, 0b10000000), - AmpConfig("Volume adjustment smoothing disabled", 0b0, 0x49, 6, 0b01000000), - AmpConfig("Zero-crossing detection disabled", 0b0, 0x49, 5, 0b00100000), -] - -CONFIGS = { - "tici": [ - AmpConfig("Right speaker output from right DAC", 0b1, 0x2C, 0, 0b11111111), - AmpConfig("Right Speaker Mixer Gain", 0b00, 0x2D, 2, 0b00001100), - AmpConfig("Right speaker output volume", 0x1c, 0x3E, 0, 0b00011111), - AmpConfig("DAI2 EQ enable", 0b1, 0x49, 1, 0b00000010), - - *configs_from_eq_params(0x84, EQParams(0x274F, 0xC0FF, 0x3BF9, 0x0B3C, 0x1656)), - *configs_from_eq_params(0x8E, EQParams(0x1009, 0xC6BF, 0x2952, 0x1C97, 0x30DF)), - *configs_from_eq_params(0x98, EQParams(0x0F75, 0xCBE5, 0x0ED2, 0x2528, 0x3E42)), - *configs_from_eq_params(0xA2, EQParams(0x091F, 0x3D4C, 0xCE11, 0x1266, 0x2807)), - *configs_from_eq_params(0xAC, EQParams(0x0A9E, 0x3F20, 0xE573, 0x0A8B, 0x3A3B)), - ], - "tizi": [ - AmpConfig("Left speaker output from left DAC", 0b1, 0x2B, 0, 0b11111111), - AmpConfig("Right speaker output from right DAC", 0b1, 0x2C, 0, 0b11111111), - AmpConfig("Left Speaker Mixer Gain", 0b00, 0x2D, 0, 0b00000011), - AmpConfig("Right Speaker Mixer Gain", 0b00, 0x2D, 2, 0b00001100), - AmpConfig("Left speaker output volume", 0x17, 0x3D, 0, 0b00011111), - AmpConfig("Right speaker output volume", 0x17, 0x3E, 0, 0b00011111), - - AmpConfig("DAI2 EQ enable", 0b0, 0x49, 1, 0b00000010), - AmpConfig("DAI2: DC blocking", 0b0, 0x20, 0, 0b00000001), - AmpConfig("ALC enable", 0b0, 0x43, 7, 0b10000000), - AmpConfig("DAI2 EQ attenuation", 0x2, 0x32, 0, 0b00001111), - AmpConfig("Excursion limiter upper corner freq", 0b001, 0x41, 4, 0b01110000), - AmpConfig("Excursion limiter threshold", 0b100, 0x42, 0, 0b00001111), - AmpConfig("Distortion limit (THDCLP)", 0x0, 0x46, 4, 0b11110000), - AmpConfig("Distortion limiter release time constant", 0b1, 0x46, 0, 0b00000001), - AmpConfig("Left DAC input mixer: DAI1 left", 0b0, 0x22, 7, 0b10000000), - AmpConfig("Left DAC input mixer: DAI1 right", 0b0, 0x22, 6, 0b01000000), - AmpConfig("Left DAC input mixer: DAI2 left", 0b1, 0x22, 5, 0b00100000), - AmpConfig("Left DAC input mixer: DAI2 right", 0b0, 0x22, 4, 0b00010000), - AmpConfig("Right DAC input mixer: DAI2 left", 0b0, 0x22, 1, 0b00000010), - AmpConfig("Right DAC input mixer: DAI2 right", 0b1, 0x22, 0, 0b00000001), - AmpConfig("Volume adjustment smoothing disabled", 0b1, 0x49, 6, 0b01000000), - ], -} - -class Amplifier: - AMP_I2C_BUS = 0 - AMP_ADDRESS = 0x10 - - def __init__(self, debug=False): - self.debug = debug - - def _get_shutdown_config(self, amp_disabled: bool) -> AmpConfig: - return AmpConfig("Global shutdown", 0b0 if amp_disabled else 0b1, 0x51, 7, 0b10000000) - - def _set_configs(self, configs: List[AmpConfig]) -> None: - with SMBus(self.AMP_I2C_BUS) as bus: - for config in configs: - if self.debug: - print(f"Setting \"{config.name}\" to {config.value}:") - - old_value = bus.read_byte_data(self.AMP_ADDRESS, config.register, force=True) - new_value = (old_value & (~config.mask)) | ((config.value << config.offset) & config.mask) - bus.write_byte_data(self.AMP_ADDRESS, config.register, new_value, force=True) - - if self.debug: - print(f" Changed {hex(config.register)}: {hex(old_value)} -> {hex(new_value)}") - - def set_configs(self, configs: List[AmpConfig]) -> bool: - # retry in case panda is using the amp - for _ in range(10): - try: - self._set_configs(configs) - return True - except OSError: - print("Failed to set amp config, retrying...") - time.sleep(0.02) - return False - - def set_global_shutdown(self, amp_disabled: bool) -> bool: - return self.set_configs([self._get_shutdown_config(amp_disabled), ]) - - def initialize_configuration(self, model: str) -> bool: - cfgs = [ - self._get_shutdown_config(True), - *BASE_CONFIG, - *CONFIGS[model], - self._get_shutdown_config(False), - ] - return self.set_configs(cfgs) - - -if __name__ == "__main__": - with open("/sys/firmware/devicetree/base/model") as f: - model = f.read().strip('\x00') - model = model.split('comma ')[-1] - - if model in CONFIGS: - amp = Amplifier() - amp.initialize_configuration(model) - else: - print(f"Skipping, no config for {model}") diff --git a/userspace/root/usr/comma/sound/sound_init.sh b/userspace/root/usr/comma/sound/sound_init.sh index 89a9325..7be30d0 100755 --- a/userspace/root/usr/comma/sound/sound_init.sh +++ b/userspace/root/usr/comma/sound/sound_init.sh @@ -1,7 +1,5 @@ #!/bin/bash -/usr/comma/sound/adsp-start.sh - echo "waiting for sound card to come online" while [ ! -d /proc/asound/sdm845tavilsndc ] || [ "$(cat /proc/asound/card0/state 2> /dev/null)" != "ONLINE" ] ; do sleep 0.01 @@ -20,6 +18,3 @@ else /usr/comma/sound/tinymix set "MultiMedia1 Mixer TERT_MI2S_TX" 1 /usr/comma/sound/tinymix set "TERT_MI2S_TX Channels" Two fi - -# setup the amplifier registers -/usr/local/venv/bin/python /usr/comma/sound/amplifier.py diff --git a/userspace/root/usr/lib/systemd/system/sound.service b/userspace/root/usr/lib/systemd/system/sound.service index fffb2ad..ce26350 100644 --- a/userspace/root/usr/lib/systemd/system/sound.service +++ b/userspace/root/usr/lib/systemd/system/sound.service @@ -1,5 +1,7 @@ [Unit] Description=Sound +Requires=init-qcom.service +After=init-qcom.service [Service] Type=oneshot