首页 > 系统相关 >01-[Linux][Regulator]使用LDO编程示例

01-[Linux][Regulator]使用LDO编程示例

时间:2023-08-01 16:46:17浏览次数:37  
标签:regulator 01 struct val 示例 ldo sample Linux include

1、在驱动代码中使用LDO供电操作的步骤如下:

  • 找到需要操作的LDO名字,如MTK平台:vio28
  • 在dts中找到相应的节点,如下所示:
mt_pmic_vio28_ldo_reg: ldo_vio28 {
	regulator-name = "vio28";
	regulator-min-microvolt = <2800000>;
	regulator-max-microvolt = <2800000>;
	regulator-enable-ramp-delay = <264>;
};
  • 在设备树中自己定义的节点中引用上述节点:
ldo_sample: ldo_sample {
	compatible = "mediatek,ldo_sample";
	ldo_sample-supply = <&mt_pmic_vio28_ldo_reg>;
	status = "okay";
};
  • 编写驱动代码,使用devm_regulator_get,regulator_enable,regulator_disable等接口来进行操作LDO

2、驱动示例代码如下:

#include <linux/init.h>
#include <linux/module.h>
#include <linux/ioctl.h>
#include <linux/fs.h>
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/err.h>
#include <linux/list.h>
#include <linux/errno.h>
#include <linux/mutex.h>
#include <linux/slab.h>
#include <linux/compat.h>
#include <linux/of.h>
#include <linux/of_device.h>
#include <linux/acpi.h>
#include <linux/regulator/consumer.h>

struct ldo_sample_dev {
	struct regulator *vcc;
};
struct ldo_sample_dev *pldo;


static ssize_t show_ldo_val(struct device *dev,
		struct device_attribute *attr, char *buf)
{
	return 0;
}

static ssize_t store_ldo_val(struct device *dev,
		struct device_attribute *attr, const char *buf, size_t count)
{
	int val = 0;
  
  	if (kstrtoint(buf, 10, &val))
  		return -EINVAL;

	pr_err("596 store_ldo_val val=%d\n", val);

	if (val == 1) {
		regulator_enable(pldo->vcc);
	} else {
		regulator_disable(pldo->vcc);
	}

	return count;
}

static DEVICE_ATTR(ldo_sample, 0664, show_ldo_val, store_ldo_val);

static int ldo_sample_probe(struct platform_device *pdev)
{
	int err = 0;

	pr_info("596 %s enter.\n", __func__);
	/* 1. alloc memory */
	pldo = devm_kzalloc(&pdev->dev, sizeof(*pldo), GFP_KERNEL);
	if (!pldo)
		return -ENOMEM;

	/* 2. get regulator */
	pldo->vcc = devm_regulator_get(&pdev->dev, "ldo_sample");
	if (IS_ERR(pldo->vcc)) {
		err = PTR_ERR(pldo->vcc);
		pr_err("596 regulator request failed (%d)\n", err);
		return err;
	}

	/* 3. create device attr */
	device_create_file(&(pdev->dev), &dev_attr_ldo_sample);

	pr_info("596 %s exit.\n", __func__);
	
	return 0;
}

static int ldo_sample_remove(struct platform_device *pdev)
{
	pr_info("596 %s enter\n", __func__);
	
	return 0;
}

const struct of_device_id ldo_sample_table[] = {
	{ .compatible = "mediatek,ldo_sample" },
	{}
};

static struct platform_driver ldo_sample_driver = {
	.probe = ldo_sample_probe,
	.remove = ldo_sample_remove,
	.driver = {
		.name = "ldo_sample",
		.of_match_table = ldo_sample_table,
	},
};

module_platform_driver(ldo_sample_driver);

MODULE_AUTHOR("596");
MODULE_DESCRIPTION("Mediatek LDO driver sample");
MODULE_LICENSE("GPL");

标签:regulator,01,struct,val,示例,ldo,sample,Linux,include
From: https://www.cnblogs.com/hkcs596/p/17596916.html

相关文章

  • Could not find server 'server name' in sys.servers. SQL Server 2014
    Couldnotfindserver'servername'insys.servers.SQLServer2014  Atfirstcheckoutthatyourlinkedserverisinthelistbythisqueryselectnamefromsys.serversIfitnotexiststhentrytoaddtothelinkedserverEXECsp_addl......
  • Windows Server 2016 OVF, updated Jul 2023 (sysin) - VMware 虚拟机模板
    WindowsServer2016OVF,updatedJul2023(sysin)-VMware虚拟机模板2023年6月版本更新,现在自动运行sysprep,支持ESXiHostClient部署请访问原文链接:https://sysin.org/blog/windows-server-2016-ovf/,查看最新版。原创作品,转载请保留出处。作者主页:sysin.org现在......
  • Windows Server 2016 中文版、英文版下载 (updated Jul 2023)
    WindowsServer2016中文版、英文版下载(updatedJul2023)WindowsServer2016Version1607,2023年7月更新请访问原文链接:https://sysin.org/blog/windows-server-2016/,查看最新版。原创作品,转载请保留出处。作者主页:sysin.org本站将不定期发布官方原版风格月度更新IS......
  • Windows Server 2019 OVF, updated Jul 2023 (sysin) - VMware 虚拟机模板
    WindowsServer2019OVF,updatedJul2023(sysin)-VMware虚拟机模板2023年7月版本更新,现在自动运行sysprep,支持ESXiHostClient部署更新日期:FriJul28202317:12:00GMT+0800,阅读量:6244请访问原文链接:https://sysin.org/blog/windows-server-2019-ovf/,查看最......
  • Windows Server 2019 中文版、英文版下载 (updated Jul 2023)
    WindowsServer2019中文版、英文版下载(updatedJul2023)WindowsServer2019Version1809,2023年7月更新请访问原文链接:https://sysin.org/blog/windows-server-2019/,查看最新版。原创作品,转载请保留出处。作者主页:sysin.org本站将不定期发布官方原版风格月度更新IS......
  • Linux KVM 网卡配置多队列
    网卡多队列查看系统是否支持lspci-vvv|grepEth-A30#有MSI-X说明系统支持查看网卡是否支持ethtool-leth0#Combined不为0说明支持设置网卡ethtool-Leth0combined<队列数量>确认是否生效ls/sys/class/net/eth0/queuesKVM虚拟机配置xml......
  • CS5801国产HDMI转DP/edp(4k60)转换器方案芯片 可替代LT6711
    CS5801是HDMI2.0b到DP1.4a转换器方案IC。CS5801有一个HDMI2.0b.输入,带宽高达18Gbps.它支持辨别率是4k@60Hz。对于DP1.4输出,由4条数据通道组成,支持1.62Gbps、2.7Gbps、5.4Gbps链路速率。内置可选SSC功能可降低EMI影响。嵌入式MCU基于32位RISC-V内核,带有内部串行闪存。CS5801参数......
  • 在 Linux 上使用 VirtualBox 的命令行管理界面
    VirtualBox拥有一套命令行工具,你可以使用VirtualBox的命令行界面(CLI)对远程无界面的服务器上的虚拟机进行管理操作。在这篇教程中,你将会学到如何在没有GUI的情况下使用VBoxManage创建、启动一个虚拟机。VBoxManage是VirtualBox的命令行界面,你可以在你的主机操作系统......
  • Linux服务器宕机原因有哪些可以通过那些命令详细排查
    dmesg:这个命令可以查看系统启动时内核产生的日志信息,可以通过检查日志来了解是否有硬件或内核问题。journalctl:这个命令可以查看系统日志,包括服务启动、停止、错误信息等,可以帮助找到服务是否出现问题。top和htop:这两个命令可以查看系统当前的进程状态和资源占用情况,可能可......
  • linux环境下重启Tomcat服务
    1、如何在Linux操作系统定时重启Tomcat服务?2、linux环境下重启Tomcat服务3、linux重启tomcat服务命令4、Linux设置tomcat开机自动启动5、如何在Linux操作系统定时重启Tomcat服务6、linux如何启动tomcat用什么命令如何在Linux操作系统定时重启Tomcat服务?使用当时部署to......