devm_regulator_get功能参数返回值
时间: 2023-12-25 14:05:02 浏览: 65
devm_regulator_get函数用于从设备树中获取并返回一个指向regulator结构体的指针,该结构体表示所需的调节器。它的参数包括:
- dev:指向设备的指针;
- id:调节器的标识符字符串;
- config:调节器的配置信息,包括电压、电流等。
函数的返回值是一个指向regulator结构体的指针,如果获取失败则返回一个错误码。
相关问题
devm_regulator_get
devm_regulator_get is a function provided by the Linux kernel API that allows a device driver to obtain a reference to a regulator device. This function is a managed version of the regulator_get function, which means that it automatically handles the deallocation of the regulator device when the driver is unloaded from the system.
The devm_regulator_get function takes two arguments: a pointer to the device structure of the device that requires the regulator, and a string that specifies the name of the regulator device. The function returns a pointer to the regulator device structure if successful, or an error code if it fails.
Once a driver obtains a reference to a regulator device using devm_regulator_get, it can use the regulator API functions to control the voltage or current supplied to the device. The driver should release the reference to the regulator device when it is no longer needed, but this is handled automatically by devm_regulator_get.
devm_regulator_get()函数理解
在 Linux 内核中,devm_regulator_get() 函数用于获取一个设备的电压调节器(regulator)。
在嵌入式系统中,一些外围设备需要使用不同的电压供电,这就需要使用电压调节器来调节电压。而我们在驱动程序中需要操作这些电压调节器,就需要使用 devm_regulator_get() 函数获取对应的 regulator 对象。
devm_regulator_get() 函数的参数包括设备对象和电压调节器的名称,它会根据名称查找对应的电压调节器,如果找到了就返回一个 regulator 对象,否则返回一个错误指针。
需要注意的是,devm_regulator_get() 函数获取到的 regulator 对象是一种资源,使用完毕后需要及时释放,否则会导致资源泄露。为了方便资源管理,devm_regulator_get() 函数会自动将获取到的 regulator 对象与设备对象进行关联,当设备对象被释放时,相应的 regulator 对象也会被自动释放。