找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 32|回复: 0

regulator电源节点独立控制-vcamio

[复制链接]

2

主题

5

帖子

34

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
34
 楼主| 发表于 2024-10-29 16:12:28 | 显示全部楼层 |阅读模式
一、节点信息:
vcamio节点位置:
/sys/class/regulator/regulator.17


cat state 可以参看当前系统电源的使能情况:
PDA:/sys/class/regulator/regulator.17 # cat state
enabled

PDA:/sys/class/regulator/regulator.17 # cat state
disabled

二、dts配置:
  1. 1、mt6765.dts
  2.         kd_camera_hw1: kd_camera_hw1@1a040000 {
  3.                 compatible = "mediatek,camera_hw";

  4. 2、cust_mt6765_camera.dtsi
  5. &kd_camera_hw1 {
  6. ....
  7. cam0_vcamio-supply = <&mt_pmic_vcamio_ldo_reg>;
  8. ....
  9. };
  10. 3、mt6357.dtsi
  11.                 mt_pmic_vcamio_ldo_reg: ldo_vcamio {
  12.                         regulator-name = "vcamio";
  13.                         regulator-min-microvolt = <1800000>;
  14.                         regulator-max-microvolt = <1800000>;
  15.                         regulator-enable-ramp-delay = <264>;
  16.                 };
复制代码


三、定义:
  1. #include <linux/device.h>

  2. #if defined(CONFIG_LED_H196XO)
  3. extern struct device *gimgsensor_device;
  4. extern int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV);
  5. extern struct regulator *regulator_get(struct device *dev, const char *id);
  6. struct regulator *pregulator;
  7. #endif
复制代码


四、代码控制:
  1. #if defined(CONFIG_LED_H196XO)
  2.         struct device *pdevice = gimgsensor_device;
  3. #endif

  4.         pdevice->of_node = of_find_compatible_node(NULL, NULL, "mediatek,camera_hw");
  5.         pregulator = regulator_get(pdevice, "cam0_vcamio"); //cam0_vcamd,cam0_vcama 看相机对应的是pmic控制,就能控制到pmic对应电源
  6.        
  7.         if((strcmp(cust->name, "vcamio_test") == 0)){
  8.                 if (level == 0) {
  9.                         printk("huangxuan set vcamio to 0V\n");
  10.                    if (regulator_is_enabled(pregulator)){   //如果电源打开,再关闭。这里参考camera上电部分regulator.c
  11.                            if (regulator_disable(pregulator)) {
  12.                                         pr_err("[regulator]fail to regulator_disable!\n");
  13.                                 }
  14.                    }
  15.                        
  16.                 }else{
  17.                         printk("huangxuan set vcamio to 1.8V\n");
  18.                         if (regulator_set_voltage(pregulator, 1800000, 1800000))
  19.                                 pr_err("huangxuan [regulator]fail to regulator_set_voltage vcamio to 1.8V\n");
  20.                         regulator_enable(pregulator);
  21.                 }

  22.         }
复制代码


五、实例(新增vcamio控制节点):
简单的加在leds灯光系统架构里,引入的一个vcamio_test节点,写0关闭vcamio,非0打开。代码架构如下:
1、dts定义:arch/arm64/boot/dts/mediatek/AGN_H196XO_M110.dts
  1. +       led12:led@12 {
  2. +               compatible = "mediatek,vcamio_test";
  3. +               led_mode = <3>;         
  4. +               pwm_config = <0 0 0 0 0>;
  5. +       };
复制代码
2、drivers/misc/mediatek/leds/mt6765/Makefile
  1. ccflags-y += -I$(srctree)/drivers/misc/mediatek/video/include
  2. +ccflags-y += -I$(srctree)/drivers/misc/mediatek/imgsensor/src/common/v1
复制代码
3、drivers/misc/mediatek/leds/mt6765/mtk_leds.c
  1. @@ -14,6 +14,8 @@
  2. #include <linux/gpio.h>
  3. #include <linux/of_device.h>
  4. #include <linux/of_gpio.h>
  5. +#include <linux/regulator/consumer.h>
  6. +#include <linux/device.h>

  7. #ifdef CONFIG_OF
  8. #include <linux/of.h>
  9. @@ -101,6 +103,14 @@ void mt_pwm_disable(u32 pwm_no, u8 pmic_pad)

  10. struct wakeup_source leds_suspend_lock;

  11. +#if defined(CONFIG_LED_H196XO)
  12. +extern struct device *gimgsensor_device;
  13. +extern int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV);
  14. +extern struct regulator *regulator_get(struct device *dev, const char *id);
  15. +struct regulator *pregulator;
  16. +#endif
  17. +
  18. +
  19. char *leds_name[MT65XX_LED_TYPE_TOTAL] = {
  20.         "red",
  21.         "green",
  22. @@ -112,7 +122,9 @@ void mt_pwm_disable(u32 pwm_no, u8 pmic_pad)
  23. #if defined(CONFIG_LED_H170XO) || defined(CONFIG_LED_H196XO)
  24.         "red_scan",
  25.         "green_scan",
  26. -       "blue_scan"
  27. +       "blue_scan",
  28. +       "vcamio_test"
  29. +      
  30. #endif
  31. #if defined(CONFIG_LED_H188XO)
  32.         "red_scan",
  33. @@ -879,6 +891,9 @@ int mt_brightness_set_pmic_duty_store(u32 level, u32 div)
  34. int mt_mt65xx_led_set_cust(struct cust_mt65xx_led *cust, int level)
  35. {
  36.         struct nled_setting led_tmp_setting = { 0, 0, 0 };
  37. +#if defined(CONFIG_LED_H196XO)
  38. +       struct device *pdevice = gimgsensor_device;
  39. +#endif
  40.         int tmp_level = level;
  41.         static bool button_flag;
  42.         unsigned int BacklightLevelSupport =
  43. @@ -977,6 +992,23 @@ int mt_mt65xx_led_set_cust(struct cust_mt65xx_led *cust, int level)
  44.                                 button_flag = true;
  45.                         }
  46.                 }
  47. +               
  48. +      
  49. +       pdevice->of_node = of_find_compatible_node(NULL, NULL, "mediatek,camera_hw");
  50. +       pregulator = regulator_get(pdevice, "cam0_vcamio");
  51. +      
  52. +       if((strcmp(cust->name, "vcamio_test") == 0)){
  53. +               if (level == 0) {
  54. +                       printk("huangxuan set vcamio to 0V\n");
  55. +                       regulator_disable(pregulator);
  56. +               }else{
  57. +                       printk("huangxuan set vcamio to 1.8V\n");
  58. +                       if (regulator_set_voltage(pregulator, 1800000, 1800000))
  59. +                               pr_err("huangxuan [regulator]fail to regulator_set_voltage vcamio to 1.8V\n");
  60. +                       regulator_enable(pregulator);
  61. +               }
  62. +
  63. +       }
  64. #endif

  65.                 return mt_brightness_set_pmic(cust->data, level, bl_div_hal);
复制代码
4、drivers/misc/mediatek/leds/mt6765/mtk_leds_sw.h
  1. @@ -30,6 +30,8 @@ enum mt65xx_led_type {
  2.         MT65XX_LED_TYPE_RED_SCAN,
  3.         MT65XX_LED_TYPE_GREEN_SCAN,
  4.         MT65XX_LED_TYPE_BLUE_SCAN,
  5. +       MT65XX_LED_TYPE_VCAMIO_TEST,
  6. +      
  7. #endif
复制代码






回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|www.agenewtech.com

GMT+8, 2025-1-12 13:33 , Processed in 0.051594 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表