linux驱动 — regalator使用
Posted 超凡东皇
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux驱动 — regalator使用相关的知识,希望对你有一定的参考价值。
Regulator,即LDO(low dropout regulator),低压差 线性稳压器,简称稳压器。
本篇我们只讨论regalator api的使用,regalator 常用api如下:
/* regulator get and put */
struct regulator *__must_check regulator_get(struct device *dev, const char *id);
struct regulator *__must_check devm_regulator_get(struct device *dev, const char *id);
void regulator_put(struct regulator *regulator);
void devm_regulator_put(struct regulator *regulator);
/* regulator output control and status */
int __must_check regulator_enable(struct regulator *regulator);
int regulator_disable(struct regulator *regulator);
int regulator_force_disable(struct regulator *regulator);
int regulator_is_enabled(struct regulator *regulator);
int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV);
使用示例:
以lcm显示屏有一个电源引脚是由regalator控制的为例,即reg-lcm-supply = <&mt6323_vgp3_reg>;
设备树
&lcm {
reg-lcm-supply = <&mt6323_vgp3_reg>;
};
驱动代码
#include <linux/string.h>
#include <linux/wait.h>
#include <linux/platform_device.h>
#include <linux/pinctrl/consumer.h>
#include <linux/of_gpio.h>
#include <asm-generic/gpio.h>
#include <linux/kernel.h>
#include <linux/mm.h>
#include <linux/mm_types.h>
#include <linux/module.h>
#include <linux/types.h>
#include <linux/slab.h>
#include <linux/vmalloc.h>
#ifdef CONFIG_OF
#include <linux/of.h>
#include <linux/of_irq.h>
#include <linux/of_address.h>
#include <linux/of_device.h>
#include <linux/regulator/consumer.h>
#include <linux/clk.h>
#endif
static struct regulator *lcm_vgp;
/* get LDO supply */
static int lcm_get_vgp_supply(struct device *dev)
{
int ret;
struct regulator *lcm_vgp_ldo;
pr_debug("LCM: lcm_get_vgp_supply is going\\n");
//从设备树中获取regulator,相当于一个gpio
lcm_vgp_ldo = devm_regulator_get(dev, "reg-lcm");
if (IS_ERR(lcm_vgp_ldo)) {
ret = PTR_ERR(lcm_vgp_ldo);
dev_err(dev, "failed to get reg-lcm LDO, %d\\n", ret);
return ret;
}
pr_debug("LCM: lcm get supply ok.\\n");
/* get current voltage settings */
ret = regulator_get_voltage(lcm_vgp_ldo);
pr_debug("lcm LDO voltage = %d in LK stage\\n", ret);
lcm_vgp = lcm_vgp_ldo;
return ret;
}
int lcm_vgp_supply_enable(void)
{
int ret;
unsigned int volt;
pr_debug("LCM: lcm_vgp_supply_enable\\n");
if (NULL == lcm_vgp)
return 0;
pr_debug("LCM: set regulator voltage lcm_vgp voltage to 2.8V\\n");
/* 调节电压的最小和最大输出, set voltage to 1.8V */
ret = regulator_set_voltage(lcm_vgp, 1800000, 1800000);
if (ret != 0) {
pr_err("LCM: lcm failed to set lcm_vgp voltage: %d\\n", ret);
return ret;
}
/* 获取配置的输出电压, get voltage settings again */
volt = regulator_get_voltage(lcm_vgp);
if (volt == 1800000)
pr_err("LCM: check regulator voltage=2800000 pass!\\n");
else
pr_err("LCM: check regulator voltage=2800000 fail! (voltage: %d)\\n", volt);
//使能电源输出
ret = regulator_enable(lcm_vgp);
if (ret != 0) {
pr_err("LCM: Failed to enable lcm_vgp: %d\\n", ret);
return ret;
}
return ret;
}
int lcm_vgp_supply_disable(void)
{
int ret = 0;
unsigned int isenable;
if (NULL == lcm_vgp)
return 0;
//判断regulator是否使能,大于0表示已经使能
isenable = regulator_is_enabled(lcm_vgp);
pr_debug("LCM: lcm query regulator enable status[0x%d]\\n", isenable);
if (isenable) {
//关闭电源输出
ret = regulator_disable(lcm_vgp);
if (ret != 0) {
pr_err("LCM: lcm failed to disable lcm_vgp: %d\\n", ret);
return ret;
}
/* verify */
isenable = regulator_is_enabled(lcm_vgp);
if (!isenable)
pr_err("LCM: lcm regulator disable pass\\n");
}
return ret;
}
static int lcm_probe(struct device *dev)
{
lcm_get_vgp_supply(dev);
return 0;
}
static const struct of_device_id lcm_of_ids[] = {
{.compatible = "mediatek,lcm",},
{}
};
static struct platform_driver lcm_driver = {
.driver = {
.name = "mtk_lcm",
.owner = THIS_MODULE,
.probe = lcm_probe,
#ifdef CONFIG_OF
.of_match_table = lcm_of_ids,
#endif
},
};
static int __init lcm_init(void)
{
pr_debug("LCM: Register lcm driver\\n");
if (platform_driver_register(&lcm_driver)) {
pr_err("LCM: failed to register disp driver\\n");
return -ENODEV;
}
return 0;
}
static void __exit lcm_exit(void)
{
platform_driver_unregister(&lcm_driver);
pr_debug("LCM: Unregister lcm driver done\\n");
}
late_initcall(lcm_init);
module_exit(lcm_exit);
MODULE_AUTHOR("mediatek");
MODULE_DESCRIPTION("Display subsystem Driver");
MODULE_LICENSE("GPL");
参考链接:
https://blog.csdn.net/spongebob1912/article/details/109517707
以上是关于linux驱动 — regalator使用的主要内容,如果未能解决你的问题,请参考以下文章
关于mysql驱动版本报错解决,Cause: com.mysql.jdbc.exceptions.jdbc4Unknown system variable ‘query_cache_size(代码片段