#ifndef _DEV_REGULATOR_H_
#define _DEV_REGULATOR_H_
#include "opt_platform.h"
#include <sys/kobj.h>
#include <sys/sysctl.h>
#ifdef FDT
#include <dev/ofw/ofw_bus.h>
#endif
#include "regnode_if.h"
SYSCTL_DECL(_hw_regulator);
#define REGULATOR_FLAGS_STATIC 0x00000001
#define REGULATOR_FLAGS_NOT_DISABLE 0x00000002
#define REGULATOR_STATUS_ENABLED 0x00000001
#define REGULATOR_STATUS_OVERCURRENT 0x00000002
typedef struct regulator *regulator_t;
struct regnode_std_param {
int min_uvolt;
int max_uvolt;
int min_uamp;
int max_uamp;
int ramp_delay;
int enable_delay;
bool boot_on;
bool always_on;
int enable_active_high;
};
struct regnode_init_def {
char *name;
char *parent_name;
struct regnode_std_param std_param;
intptr_t id;
int flags;
#ifdef FDT
phandle_t ofw_node;
#endif
};
struct regulator_range {
int min_uvolt;
int step_uvolt;
uint8_t min_sel;
uint8_t max_sel;
};
#define REG_RANGE_INIT(_min_sel, _max_sel, _min_uvolt, _step_uvolt) { \
.min_sel = _min_sel, \
.max_sel = _max_sel, \
.min_uvolt = _min_uvolt, \
.step_uvolt = _step_uvolt, \
}
#define REGNODEMETHOD KOBJMETHOD
#define REGNODEMETHOD_END KOBJMETHOD_END
#define regnode_method_t kobj_method_t
#define regnode_class_t kobj_class_t
DECLARE_CLASS(regnode_class);
struct regnode *regnode_create(device_t pdev, regnode_class_t regnode_class,
struct regnode_init_def *def);
struct regnode *regnode_register(struct regnode *regnode);
const char *regnode_get_name(struct regnode *regnode);
const char *regnode_get_parent_name(struct regnode *regnode);
struct regnode *regnode_get_parent(struct regnode *regnode);
int regnode_get_flags(struct regnode *regnode);
void *regnode_get_softc(struct regnode *regnode);
device_t regnode_get_device(struct regnode *regnode);
struct regnode_std_param *regnode_get_stdparam(struct regnode *regnode);
void regnode_topo_unlock(void);
void regnode_topo_xlock(void);
void regnode_topo_slock(void);
int regnode_enable(struct regnode *regnode);
int regnode_disable(struct regnode *regnode);
int regnode_stop(struct regnode *regnode, int depth);
int regnode_status(struct regnode *regnode, int *status);
int regnode_get_voltage(struct regnode *regnode, int *uvolt);
int regnode_set_voltage(struct regnode *regnode, int min_uvolt, int max_uvolt);
int regnode_set_constraint(struct regnode *regnode);
int regnode_method_check_voltage(struct regnode *regnode, int uvolt);
#ifdef FDT
phandle_t regnode_get_ofw_node(struct regnode *regnode);
#endif
int regulator_get_by_name(device_t cdev, const char *name,
regulator_t *regulator);
int regulator_get_by_id(device_t cdev, device_t pdev, intptr_t id,
regulator_t *regulator);
int regulator_release(regulator_t regulator);
const char *regulator_get_name(regulator_t regulator);
int regulator_enable(regulator_t reg);
int regulator_disable(regulator_t reg);
int regulator_stop(regulator_t reg);
int regulator_status(regulator_t reg, int *status);
int regulator_get_voltage(regulator_t reg, int *uvolt);
int regulator_set_voltage(regulator_t reg, int min_uvolt, int max_uvolt);
int regulator_check_voltage(regulator_t reg, int uvolt);
#ifdef FDT
int regulator_get_by_ofw_property(device_t dev, phandle_t node, char *name,
regulator_t *reg);
int regulator_parse_ofw_stdparam(device_t dev, phandle_t node,
struct regnode_init_def *def);
#endif
int regulator_range_volt_to_sel8(struct regulator_range *ranges, int nranges,
int min_uvolt, int max_uvolt, uint8_t *out_sel);
int regulator_range_sel8_to_volt(struct regulator_range *ranges, int nranges,
uint8_t sel, int *volt);
#endif