Skip to content

Commit

Permalink
[no ci] Sigmastar: add sensor autodetection
Browse files Browse the repository at this point in the history
  • Loading branch information
viktorxda committed Jul 28, 2023
1 parent 3fd4649 commit 18644a1
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,30 @@

PATH_MODULE=/lib/modules/4.9.84/sigmastar
PATH_FIRMWARE=/etc/sensors/venc_fw/chagall.bin

# Sensor
SENSOR=$(fw_printenv -n sensor)

detect_sensor() {
insmod ${PATH_MODULE}/sensor_rx_mipi.ko chmap=1
SENSOR=$(majestic | awk '/Autodetect/ {print $NF}')
rmmod drv_ms_cus_RX_MIPI
fw_setenv sensor ${SENSOR}
}

set_sensor() {
$(lsmod | grep -q ${SENSOR}) && rmmod drv_ms_cus_${SENSOR}_MIPI

case $SENSOR in
gc2053)
# Untested | The information is obtained from the Gospell firmware
insmod ${PATH_MODULE}/sensor_gc2053_mipi.ko chmap=1 lane_num=2 hdr_lane_num=2
gc4653|imx335|sc2239|sc3335)
insmod ${PATH_MODULE}/sensor_${SENSOR}_mipi.ko chmap=1
;;
gc4653)
# Untested | The information is obtained from the Anjoy firmware
insmod ${PATH_MODULE}/sensor_gc4653_mipi.ko chmap=1
gc2053|sc2335)
insmod ${PATH_MODULE}/sensor_${SENSOR}_mipi.ko chmap=1 lane_num=2 hdr_lane_num=2
;;
imx307)
# Untested | The information is obtained from the Anjoy and Brovotech (mclk=37.125M) firmware
insmod ${PATH_MODULE}/sensor_imx307_mipi.ko chmap=1 lane_num=2 hdr_lane_num=2 mclk=37.125M
;;
imx335)
# Untested | The information is obtained from the Anjoy firmware
insmod ${PATH_MODULE}/sensor_imx335_mipi.ko chmap=1
;;
sc2239)
# Untested | The information is obtained from the IMOU firmware
insmod ${PATH_MODULE}/sensor_sc2239_mipi.ko chmap=1
;;
sc2335)
# Untested | The information is obtained from the Tiandy firmware
insmod ${PATH_MODULE}/sensor_sc2335_mipi.ko chmap=1 lane_num=2 hdr_lane_num=2
;;
sc3335)
# Untested | The information is obtained from the Uniview firmware
insmod ${PATH_MODULE}/sensor_sc3335_mipi.ko chmap=1
;;
auto)
insmod ${PATH_MODULE}/sensor_imx307_mipi.ko chmap=1 lane_num=2 hdr_lane_num=2 mclk=37.125M
insmod ${PATH_MODULE}/sensor_gc2053_mipi.ko chmap=1 lane_num=2 hdr_lane_num=2
insmod ${PATH_MODULE}/sensor_sc2335_mipi.ko chmap=1 lane_num=2 hdr_lane_num=2
insmod ${PATH_MODULE}/sensor_${SENSOR}_mipi.ko chmap=1 lane_num=2 hdr_lane_num=2 mclk=37.125M
;;
*)
echo -e "\n\e[1;31mAn UNSUPPORTED sensor type is specified - ${SENSOR}\e[0m\n" | logger -s -t OpenIPC
echo -e "\n\e[1;31mUNSUPPORTED sensor found - ${SENSOR}\e[0m\n" | logger -s -t OpenIPC
;;
esac
}
Expand All @@ -63,7 +46,6 @@ insert_ko() {
insmod ${PATH_MODULE}/mi_vif.ko
insmod ${PATH_MODULE}/mi_vpe.ko
insmod ${PATH_MODULE}/mi_venc.ko fw_path=${PATH_FIRMWARE}
set_sensor

major=$(awk '$2=="mi_poll" {print $1}' /proc/devices)
mknod /dev/mi_poll c $major 0
Expand All @@ -72,16 +54,21 @@ insert_ko() {
mdev -s
}

if [ ! -e /dev/mi_poll ]; then
insert_ko
fi

if [ -z ${SENSOR} ]; then
echo -e "\n\e[1;31mThe sensor parameter is MISSING\e[0m\n" | logger -s -t OpenIPC
echo -e "\n\e[1;33mUsage: fw_setenv sensor [SENSOR]\e[0m\n" | logger -s -t OpenIPC
exit 1
else
echo -e "\n\e[1;32mThe sensor is assigned - ${SENSOR}\e[0m\n" | logger -s -t OpenIPC
echo -e "\n\e[1;33mAutodetect sensor\e[0m\n" | logger -s -t OpenIPC
detect_sensor
fi

if [ ! -e /dev/mi_poll ]; then
insert_ko
if [ -z ${SENSOR} ]; then
echo -e "\n\e[1;31mSensor parameter is MISSING\e[0m\n" | logger -s -t OpenIPC
exit 1
else
echo -e "\n\e[1;32mSensor is assigned - ${SENSOR}\e[0m\n" | logger -s -t OpenIPC
set_sensor
fi

exit 0
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,28 @@

PATH_MODULE=/lib/modules/4.9.84/sigmastar
PATH_FIRMWARE=/etc/sensors/venc_fw/chagall.bin

# Sensor
SENSOR=$(fw_printenv -n sensor)

detect_sensor() {
insmod ${PATH_MODULE}/sensor_rx_mipi.ko chmap=1
SENSOR=$(majestic | awk '/Autodetect/ {print $NF}')
rmmod drv_ms_cus_RX_MIPI
fw_setenv sensor ${SENSOR}
}

set_sensor() {
$(lsmod | grep -q ${SENSOR}) && rmmod drv_ms_cus_${SENSOR}_MIPI

case $SENSOR in
imx274|imx335|imx347|imx415|sc8235)
insmod ${PATH_MODULE}/sensor_${SENSOR}_mipi.ko chmap=1
;;
*)
echo -e "\n\e[1;31mUNSUPPORTED sensor found - ${SENSOR}\e[0m\n" | logger -s -t OpenIPC
;;
esac
}

insert_ko() {
insmod ${PATH_MODULE}/mhal.ko
insmod ${PATH_MODULE}/mi_common.ko
Expand All @@ -24,7 +42,6 @@ insert_ko() {
insmod ${PATH_MODULE}/mi_vif.ko
insmod ${PATH_MODULE}/mi_vpe.ko
insmod ${PATH_MODULE}/mi_venc.ko fw_path=${PATH_FIRMWARE}
insmod ${PATH_MODULE}/sensor_${SENSOR}_mipi.ko chmap=1

major=$(awk '$2=="mi_poll" {print $1}' /proc/devices)
mknod /dev/mi_poll c $major 0
Expand All @@ -33,16 +50,21 @@ insert_ko() {
mdev -s
}

if [ ! -e /dev/mi_poll ]; then
insert_ko
fi

if [ -z ${SENSOR} ]; then
echo -e "\n\e[1;31mThe sensor parameter is MISSING\e[0m\n" | logger -s -t OpenIPC
echo -e "\n\e[1;33mUsage: fw_setenv sensor [SENSOR]\e[0m\n" | logger -s -t OpenIPC
exit 1
else
echo -e "\n\e[1;32mThe sensor is assigned - ${SENSOR}\e[0m\n" | logger -s -t OpenIPC
echo -e "\n\e[1;33mAutodetect sensor\e[0m\n" | logger -s -t OpenIPC
detect_sensor
fi

if [ ! -e /dev/mi_poll ]; then
insert_ko
if [ -z ${SENSOR} ]; then
echo -e "\n\e[1;31mSensor parameter is MISSING\e[0m\n" | logger -s -t OpenIPC
exit 1
else
echo -e "\n\e[1;32mSensor is assigned - ${SENSOR}\e[0m\n" | logger -s -t OpenIPC
set_sensor
fi

exit 0
Binary file not shown.

0 comments on commit 18644a1

Please sign in to comment.