redwood: Implement torch light control

Signed-off-by: rahul <rahul@aospa.co>
Co-Authored-By: rahul <rahul@aospa.co>
Co-Authored-By: John Galt <7730016+realjohngalt@users.noreply.github.com>
This commit is contained in:
Dhina17
2025-02-06 03:00:25 +08:00
committed by thepriyanshujangid
parent cdc4b99531
commit 8b66ff518e
7 changed files with 109 additions and 0 deletions

View File

@@ -50,6 +50,7 @@ TARGET_BOOTLOADER_BOARD_NAME := redwood
TARGET_NO_BOOTLOADER := true TARGET_NO_BOOTLOADER := true
# Camera # Camera
TARGET_CAMERA_SERVICE_EXT_LIB := //$(DEVICE_PATH):libcameraservice_extension.xiaomi_redwood
TARGET_CAMERA_OVERRIDE_FORMAT_FROM_RESERVED := true TARGET_CAMERA_OVERRIDE_FORMAT_FROM_RESERVED := true
TARGET_CAMERA_PACKAGE_NAME := com.android.camera TARGET_CAMERA_PACKAGE_NAME := com.android.camera

22
camera/Android.bp Normal file
View File

@@ -0,0 +1,22 @@
//
// Copyright (C) 2022 The LineageOS Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
cc_library_static {
name: "libcameraservice_extension.xiaomi_redwood",
srcs: ["CameraProviderExtension.cpp"],
include_dirs: [
"frameworks/av/services/camera/libcameraservice/common"
],
}

View File

@@ -0,0 +1,75 @@
/*
* Copyright (C) 2024 LibreMobileOS Foundation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "CameraProviderExtension.h"
#include <fstream>
#define TORCH_BRIGHTNESS "brightness"
#define TORCH_MAX_BRIGHTNESS "max_brightness"
#define TOGGLE_SWITCH "/sys/devices/platform/soc/c440000.qcom,spmi/spmi-0/spmi0-02/c440000.qcom,spmi:qcom,pm8350c@2:qcom,flash_led@ee00/leds/led:switch_0/brightness"
static std::string kTorchLedPath = "/sys/devices/platform/soc/c440000.qcom,spmi/spmi-0/spmi0-02/c440000.qcom,spmi:qcom,pm8350c@2:qcom,flash_led@ee00/leds/led:torch_0";
/**
* Write value to path and close file.
*/
template <typename T>
static void set(const std::string& path, const T& value) {
std::ofstream file(path);
file << value;
}
/**
* Read value from the path and close file.
*/
template <typename T>
static T get(const std::string& path, const T& def) {
std::ifstream file(path);
T result;
file >> result;
return file.fail() ? def : result;
}
bool supportsTorchStrengthControlExt() {
return true;
}
bool supportsSetTorchModeExt() {
return false;
}
int32_t getTorchDefaultStrengthLevelExt() {
// Our default value is 75. This corresponds to 15%.
// As we have changed the maximum value, 59% now corresponds to 75.
return 59;
}
int32_t getTorchMaxStrengthLevelExt() {
// 255 out of 500 is a sane brightness.
// Let's cap it to 255 as max, we can go much higher, but I don't want to test this.
return 255;
}
int32_t getTorchStrengthLevelExt() {
// We write same value in the both LEDs,
// so get from one.
auto node = kTorchLedPath + "/" + TORCH_BRIGHTNESS;
return get(node, 0);
}
void setTorchStrengthLevelExt(int32_t torchStrength, bool enabled) {
set(TOGGLE_SWITCH, 0);
auto node = kTorchLedPath + "/" + TORCH_BRIGHTNESS;
set(node, torchStrength);
if (enabled)
set(TOGGLE_SWITCH, 255);
}
void setTorchModeExt(bool enabled) {
int32_t strength = getTorchDefaultStrengthLevelExt();
setTorchStrengthLevelExt(enabled ? strength : 0, enabled);
}

View File

@@ -143,3 +143,7 @@ firmware_directories /vendor/firmware_mnt/image/
# Fingerprint # Fingerprint
/dev/goodix_fp 0660 system system /dev/goodix_fp 0660 system system
# Torch control
/sys/devices/platform/soc/c440000.qcom,spmi/spmi-0/spmi0-02/c440000.qcom,spmi:qcom,pm8350c@2:qcom,flash_led@ee00/leds/led:torch_0 brightness 0660 cameraserver camera
/sys/devices/platform/soc/c440000.qcom,spmi/spmi-0/spmi0-02/c440000.qcom,spmi:qcom,pm8350c@2:qcom,flash_led@ee00/leds/led:switch_0 0660 cameraserver camera

1
sepolicy/vendor/cameraserver.te vendored Normal file
View File

@@ -0,0 +1 @@
allow cameraserver sysfs_torch:file rw_file_perms;

View File

@@ -4,6 +4,11 @@ genfscon sysfs /devices/platform/soc/soc:qcom,dsi-display-primary u:object_r:ven
# USB # USB
genfscon sysfs /devices/platform/soc/soc:qcom,pmic_glink/soc:qcom,pmic_glink:qcom,ucsi/typec u:object_r:vendor_sysfs_usb_c:s0 genfscon sysfs /devices/platform/soc/soc:qcom,pmic_glink/soc:qcom,pmic_glink:qcom,ucsi/typec u:object_r:vendor_sysfs_usb_c:s0
# Torch control
genfscon sysfs /devices/platform/soc/c440000.qcom,spmi/spmi-0/spmi0-02/c440000.qcom,spmi:qcom,pm8350c@2:qcom,flash_led@ee00/leds/led:torch_0/brightness u:object_r:sysfs_torch:s0
genfscon sysfs /devices/platform/soc/c440000.qcom,spmi/spmi-0/spmi0-02/c440000.qcom,spmi:qcom,pm8350c@2:qcom,flash_led@ee00/leds/led:torch_0/max_brightness u:object_r:sysfs_torch:s0
genfscon sysfs /devices/platform/soc/c440000.qcom,spmi/spmi-0/spmi0-02/c440000.qcom,spmi:qcom,pm8350c@2:qcom,flash_led@ee00/leds/led:switch_0/brightness u:object_r:sysfs_torch:s0
# Wakeup nodes # Wakeup nodes
genfscon sysfs /devices/platform/goodix_ts.0/wakeup u:object_r:sysfs_wakeup:s0 genfscon sysfs /devices/platform/goodix_ts.0/wakeup u:object_r:sysfs_wakeup:s0
genfscon sysfs /devices/platform/soc/17300000.qcom,lpass/subsys6/wakeup u:object_r:sysfs_wakeup:s0 genfscon sysfs /devices/platform/soc/17300000.qcom,lpass/subsys6/wakeup u:object_r:sysfs_wakeup:s0

1
sepolicy/vendor/torch.te vendored Normal file
View File

@@ -0,0 +1 @@
type sysfs_torch, fs_type, sysfs_type;