more audio hacking
diff --git a/etc/audio.sdm845.xml b/etc/audio.sdm845.xml
index 4f76781..91bcba3 100644
--- a/etc/audio.sdm845.xml
+++ b/etc/audio.sdm845.xml
@@ -189,7 +189,7 @@
             </path>
         </device>
 
-        <device name="headphone">
+        <device name="headset">
             <!-- <path name="on">
                 <ctl name="SLIM RX2 MUX" val="AIF1_PB"/>
                 <ctl name="SLIM RX3 MUX" val="AIF1_PB"/>
@@ -219,10 +219,10 @@
 
 
             <path name="pcm_out_en">
-                <ctl name="SLIM RX2 MUX" val="AIF4_PB" />
+                <!-- <ctl name="SLIM RX2 MUX" val="AIF4_PB" />
                 <ctl name="SLIM RX3 MUX" val="AIF4_PB" />
                 <ctl name="RX INT1_2 MUX" val="RX2" />
-                <ctl name="RX INT2_2 MUX" val="RX3" />
+                <ctl name="RX INT2_2 MUX" val="RX3" /> -->
             </path>
 
             <path name="pcm_out_dis">
@@ -339,6 +339,8 @@
     </stream>
 
     <stream type="pcm" dir="out" card="0" device="1">
+        <enable path="pcm_out_en"/>
+        <disable path="pcm_out_dis"/>
     </stream>
 
     <!-- Example named stream, in this case for an FM radio path . This will not
diff --git a/etc/mixer_paths.xml b/etc/mixer_paths.xml
index 1f32bcb..a0c9421 100644
--- a/etc/mixer_paths.xml
+++ b/etc/mixer_paths.xml
@@ -65,38 +65,38 @@
 
 
 <!-- tinymix "QUAT_MI2S_RX Audio Mixer MultiMedia1" 1
-tinymix "SLIMBUS_0_RX Audio Mixer MultiMedia2" 1
-tinymix "MultiMedia3 Mixer SLIMBUS_0_TX" 1
-tinymix "AIF1_CAP Mixer SLIM TX7" 1
-tinymix "CDC_IF TX7 MUX" DEC7
-tinymix "SLIM RX0 MUX" AIF1_PB
-tinymix "SLIM RX1 MUX" AIF1_PB
-tinymix "SLIM RX2 MUX" AIF1_PB
-tinymix "SLIM RX3 MUX" AIF1_PB
-tinymix "SLIM RX4 MUX" ZERO
-tinymix "SLIM RX5 MUX" ZERO
-tinymix "SLIM RX6 MUX" ZERO
-tinymix "SLIM RX7 MUX" ZERO
-tinymix "RX INT7_1 MIX1 INP0" RX0
-tinymix "RX INT8_1 MIX1 INP0" RX1
-tinymix "RX INT1_2 MUX" RX0
-tinymix "RX INT2_2 MUX" RX1
+tinymix2 set "SLIMBUS_0_RX Audio Mixer MultiMedia2" 1
+tinymix2 set "MultiMedia3 Mixer SLIMBUS_0_TX" 1
+tinymix2 set "AIF1_CAP Mixer SLIM TX7" 1
+tinymix2 set "CDC_IF TX7 MUX" "DEC7"
+tinymix2 set "SLIM RX0 MUX" "AIF1_PB"
+tinymix2 set "SLIM RX1 MUX" "AIF1_PB"
+tinymix2 set "SLIM RX2 MUX" "AIF1_PB"
+tinymix2 set "SLIM RX3 MUX" "AIF1_PB"
+tinymix2 set "SLIM RX4 MUX" "ZERO"
+tinymix2 set "SLIM RX5 MUX" "ZERO"
+tinymix2 set "SLIM RX6 MUX" "ZERO"
+tinymix2 set "SLIM RX7 MUX" "ZERO"
+tinymix2 set "RX INT7_1 MIX1 INP0" "RX0"
+tinymix2 set "RX INT8_1 MIX1 INP0" "RX1"
+tinymix2 set "RX INT1_2 MUX" "RX0"
+tinymix2 set "RX INT2_2 MUX" "RX1"
 
 tinymix "Amp DSP Switch" 1 
 
 
 
 # headphones
-tinymix "RX INT1_1 MIX1 INP0" RX0
-tinymix "RX INT2_1 MIX1 INP0" RX1
-tinymix "RX INT1_1 INTERP" RX INT1_1 MIX1
-tinymix "RX INT2_1 INTERP" RX INT2_1 MIX1
-tinymix "RX INT1 DEM MUX" CLSH_DSM_OUT
-tinymix "RX INT2 DEM MUX" CLSH_DSM_OUT
-tinymix "COMP1 Switch" 1
-tinymix "COMP2 Switch" 1
-tinymix "RX1 Digital Volume" 84
-tinymix "RX2 Digital Volume" 84
+tinymix2 set "RX INT1_1 MIX1 INP0" "RX0"
+tinymix2 set "RX INT2_1 MIX1 INP0" "RX1"
+tinymix2 set "RX INT1_1 INTERP" "RX INT1_1 MIX1"
+tinymix2 set "RX INT2_1 INTERP" "RX INT2_1 MIX1"
+tinymix2 set "RX INT1 DEM MUX" "CLSH_DSM_OUT"
+tinymix2 set "RX INT2 DEM MUX" "CLSH_DSM_OUT"
+tinymix2 set "COMP1 Switch" 1
+tinymix2 set "COMP2 Switch" 1
+tinymix2 set "RX1 Digital Volume" 84
+tinymix2 set "RX2 Digital Volume" 84
 
 tinymix2 set "SLIM RX2 MUX" "AIF4_PB"
 tinymix2 set "SLIM RX3 MUX" "AIF4_PB"
diff --git a/liblight/lights.c b/liblight/lights.c
index 4c97681..c62182f 100644
--- a/liblight/lights.c
+++ b/liblight/lights.c
@@ -16,14 +16,12 @@
  * limitations under the License.
  */
 
-
-// #define LOG_NDEBUG 0
-
 #include <log/log.h>
 #include <cutils/properties.h>
 
 #include <dirent.h>
 #include <fcntl.h>
+#include <linux/limits.h>
 #include <stdint.h>
 #include <stdlib.h>
 #include <stdio.h>
@@ -38,45 +36,16 @@
 
 #include <hardware/lights.h>
 
-#define CG_COLOR_ID_PROPERTY "ro.boot.hardware.color"
-
-/******************************************************************************/
-static pthread_once_t g_init = PTHREAD_ONCE_INIT;
-static pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER;
-static int rgb_brightness_ratio = 255;
-
-char const*const BACKLIGHT_CLASS
-        = "/sys/class/backlight";
-char const*const BACKLIGHT_CLASS_FSTRING
-        = "/sys/class/backlight/%s/brightness";
+#define BACKLIGHT_CLASS "/sys/class/backlight"
+#define BACKLIGHT_CLASS_FSTRING "/sys/class/backlight/%s/brightness"
 
 /**
  * device methods
  */
 
-void init_globals(void)
-{
-    char color_id_prop[PROPERTY_VALUE_MAX] = {""};
-
-    // init the mutex
-    pthread_mutex_init(&g_lock, NULL);
-
-    // check CG color
-    property_get(CG_COLOR_ID_PROPERTY, color_id_prop, "DEF00");
-    if (strcmp(color_id_prop, "GRA00") == 0) {
-        rgb_brightness_ratio = 25;
-    } else if (strcmp(color_id_prop, "SLV00") == 0) {
-        rgb_brightness_ratio = 15;
-    } else if (strcmp(color_id_prop, "BLU00") == 0) {
-        rgb_brightness_ratio = 15;
-    } else {
-        rgb_brightness_ratio = 20;
-    }
-}
-
 static bool findFirstBacklightDevice(char *filename) {
     struct dirent *de;
-    DIR *dir = opendir("/sys/class/backlight");
+    DIR *dir = opendir(BACKLIGHT_CLASS);
     if (dir == NULL)
         return NULL;
     while((de = readdir(dir))) {
@@ -96,14 +65,15 @@
 write_brightness(int value)
 {
     int fd;
-    char brightness_path[4096];
-    char filename[256];
+    char brightness_path[PATH_MAX];
+    char filename[NAME_MAX];
     if (!findFirstBacklightDevice(filename)) {
-        ALOGE("CA:: Couldn't find backlight brightness path");
+        ALOGE("Couldn't find backlight brightness path");
         return -EINVAL;
     }
 
-    snprintf(brightness_path, 4096, BACKLIGHT_CLASS_FSTRING, filename);
+    ALOGI("Opening backlight device: %s", filename);
+    snprintf(brightness_path, PATH_MAX, BACKLIGHT_CLASS_FSTRING, filename);
     fd = open(brightness_path, O_WRONLY);
     if (fd >= 0) {
         char buffer[20];
@@ -139,7 +109,7 @@
         return -1;
     }
 
-    int brightness = rgb_to_brightness(state) << 4; // Scale up to 4095
+    int brightness = rgb_to_brightness(state) << 2; // Scale up to 1020
     write_brightness(brightness);
 
     return 0;
@@ -155,9 +125,6 @@
     return 0;
 }
 
-
-/******************************************************************************/
-
 /**
  * module methods
  */
@@ -167,7 +134,6 @@
         struct hw_device_t** device)
 {
     (void)name;
-    pthread_once(&g_init, init_globals);
 
     struct light_device_t *dev = malloc(sizeof(struct light_device_t));
 
diff --git a/prebuilt-kernel/android-mainline/Image.gz b/prebuilt-kernel/android-mainline/Image.gz
index e726342..b1a187b 100644
--- a/prebuilt-kernel/android-mainline/Image.gz
+++ b/prebuilt-kernel/android-mainline/Image.gz
Binary files differ
diff --git a/prebuilt-kernel/android-mainline/qcom-spmi-rradc.ko b/prebuilt-kernel/android-mainline/qcom-spmi-rradc.ko
new file mode 100644
index 0000000..2374d58
--- /dev/null
+++ b/prebuilt-kernel/android-mainline/qcom-spmi-rradc.ko
Binary files differ
diff --git a/prebuilt-kernel/android-mainline/sdm845-xiaomi-beryllium.dtb b/prebuilt-kernel/android-mainline/sdm845-xiaomi-beryllium.dtb
deleted file mode 100644
index 8170c58..0000000
--- a/prebuilt-kernel/android-mainline/sdm845-xiaomi-beryllium.dtb
+++ /dev/null
Binary files differ
diff --git a/qcom/init.qcom.rc b/qcom/init.qcom.rc
index 176f751..f97b502 100644
--- a/qcom/init.qcom.rc
+++ b/qcom/init.qcom.rc
@@ -32,9 +32,6 @@
 
 on post-fs
     start pd_mapper
-    exec - root -- /system/bin/sleep 1
-    exec - system audio -- /system/bin/tinymix "QUAT_MI2S_RX Audio Mixer MultiMedia1" 1
-    exec - system audio -- /system/bin/tinymix "SLIMBUS_0_RX Audio Mixer MultiMedia2" 1
 
 on post-fs-data
     mkdir /data/vendor
diff --git a/sdm845.mk b/sdm845.mk
index d3c8aee..7499cad 100644
--- a/sdm845.mk
+++ b/sdm845.mk
@@ -6,7 +6,7 @@
 
 # Following modules go to vendor partition
 # msm.ko is too big (31M) for ramdisk
-VENDOR_KERN_MODS := %/qcom_q6v5_adsp.ko %/qcom_q6v5_mss.ko %/qcom_q6v5_pas.ko
+VENDOR_KERN_MODS := %/qcom_q6v5_adsp.ko %/qcom_q6v5_mss.ko %/qcom_q6v5_pas.ko %/qcom-spmi-rradc.ko
 BOARD_VENDOR_KERNEL_MODULES := $(filter $(VENDOR_KERN_MODS),$(KERNEL_MODS))
 
 # All other modules go to ramdisk
diff --git a/sdm845/BoardConfig.mk b/sdm845/BoardConfig.mk
index cf14585..8da2bcd 100644
--- a/sdm845/BoardConfig.mk
+++ b/sdm845/BoardConfig.mk
@@ -10,7 +10,7 @@
 BOARD_KERNEL_PAGESIZE    := 4096
 BOARD_KERNEL_TAGS_OFFSET := 0x00000100
 BOARD_RAMDISK_OFFSET     := 0x01000000
-BOARD_KERNEL_CMDLINE     := earlycon console=ttyMSM0,115200n8 console=tty0 androidboot.console=ttyMSM0
+BOARD_KERNEL_CMDLINE     := console=ttyMSM0,115200n8 console=ttyGS0,115200 console=tty0 androidboot.console=ttyMSM0
 BOARD_KERNEL_CMDLINE     += androidboot.hardware=sdm845 androidboot.boot_devices=soc@0/1d84000.ufshc
 BOARD_KERNEL_CMDLINE     += firmware_class.path=/vendor/firmware/ init=/init printk.devkmsg=on
 BOARD_KERNEL_CMDLINE     += deferred_probe_timeout=30