Commit 1757df46 authored by Przemyslaw Marczak's avatar Przemyslaw Marczak Committed by Simon Glass

dm: regulator: add max77686 regulator driver

This commit adds support to MAX77686 regulator driver,
based on a driver model regulator's API. It implements
almost all regulator operations, beside those for setting
and geting the Current value.
For proper bind and operation it requires the MAX77686 PMIC driver.

New file: drivers/power/regulator/max77686.c
New config: CONFIG_DM_REGULATOR_MAX77686
Signed-off-by: default avatarPrzemyslaw Marczak <p.marczak@samsung.com>
Acked-by: default avatarSimon Glass <sjg@chromium.org>
parent 52a3de5e
MAXIM, MAX77686 regulators
This device uses two drivers:
- drivers/power/pmic/max77686.c (as parent I/O device)
- drivers/power/regulator/max77686.c (for child regulators)
This file describes the binding info for the REGULATOR driver.
First, please read the binding info for the pmic:
- doc/device-tree-bindings/pmic/max77686.txt
Required subnode:
- voltage-regulators: required for the PMIC driver
Required properties:
- regulator-name: used for regulator uclass platform data '.name'
Optional:
- regulator-min-microvolt: minimum allowed Voltage to set
- regulator-max-microvolt: minimum allowed Voltage to set
- regulator-always-on: regulator should be never disabled
- regulator-boot-on: regulator should be enabled by the bootloader
Example:
(subnode of max77686 pmic node)
voltage-regulators {
ldo1 {
regulator-name = "VDD_ALIVE_1.0V";
regulator-min-microvolt = <1000000>;
regulator-max-microvolt = <1000000>;
regulator-always-on;
regulator-boot-on;
};
ldo2 {
regulator-name = "VDDQ_VM1M2_1.2V";
regulator-min-microvolt = <1200000>;
regulator-max-microvolt = <1200000>;
regulator-always-on;
regulator-boot-on;
};
.
.
.
ldo26 {
regulator-name = "nc";
regulator-min-microvolt = <3000000>;
regulator-max-microvolt = <3000000>;
regulator-always-on;
regulator-boot-on;
};
buck1 {
regulator-compatible = "BUCK1";
regulator-name = "VDD_MIF_1.0V";
regulator-min-microvolt = <8500000>;
regulator-max-microvolt = <1100000>;
regulator-always-on;
regulator-boot-on;
};
.
.
.
buck9 {
regulator-compatible = "BUCK9";
regulator-name = "nc";
regulator-min-microvolt = <1200000>;
regulator-max-microvolt = <1200000>;
};
};
......@@ -15,7 +15,6 @@ obj-$(CONFIG_TPS6586X_POWER) += tps6586x.o
obj-$(CONFIG_TWL4030_POWER) += twl4030.o
obj-$(CONFIG_TWL6030_POWER) += twl6030.o
obj-$(CONFIG_PALMAS_POWER) += palmas.o
obj-$(CONFIG_POWER) += power_core.o
obj-$(CONFIG_DIALOG_POWER) += power_dialog.o
obj-$(CONFIG_POWER_FSL) += power_fsl.o
......
......@@ -15,3 +15,11 @@ config DM_REGULATOR
when binding the regulator devices. The pmic_bind_childs() can be used
for this purpose if PMIC I/O driver is implemented or dm_scan_fdt_node()
otherwise. Detailed informations can be found in the header file.
config DM_REGULATOR_MAX77686
bool "Enable Driver Model for REGULATOR MAX77686"
depends on DM_REGULATOR && DM_PMIC_MAX77686
---help---
This config enables implementation of driver-model regulator uclass
features for REGULATOR MAX77686. The driver implements get/set api for:
value, enable and mode.
......@@ -6,3 +6,4 @@
#
obj-$(CONFIG_DM_REGULATOR) += regulator-uclass.o
obj-$(CONFIG_DM_REGULATOR_MAX77686) += max77686.o
This diff is collapsed.
......@@ -149,23 +149,29 @@ enum {
enum {
OPMODE_OFF = 0,
OPMODE_STANDBY,
OPMODE_LPM,
OPMODE_STANDBY,
OPMODE_STANDBY_LPM,
OPMODE_ON,
};
#ifdef CONFIG_POWER
int max77686_set_ldo_voltage(struct pmic *p, int ldo, ulong uV);
int max77686_set_ldo_mode(struct pmic *p, int ldo, char opmode);
int max77686_set_buck_voltage(struct pmic *p, int buck, ulong uV);
int max77686_set_buck_mode(struct pmic *p, int buck, char opmode);
#endif
#define MAX77686_LDO_VOLT_MAX_HEX 0x3f
#define MAX77686_LDO_VOLT_MASK 0x3f
#define MAX77686_LDO_MODE_MASK 0xc0
#define MAX77686_LDO_MODE_OFF (0x00 << 0x06)
#define MAX77686_LDO_MODE_LPM (0x01 << 0x06)
#define MAX77686_LDO_MODE_STANDBY (0x01 << 0x06)
#define MAX77686_LDO_MODE_LPM (0x02 << 0x06)
#define MAX77686_LDO_MODE_STANDBY_LPM (0x02 << 0x06)
#define MAX77686_LDO_MODE_ON (0x03 << 0x06)
#define MAX77686_BUCK234_VOLT_MAX_HEX 0xff
#define MAX77686_BUCK234_VOLT_MASK 0xff
#define MAX77686_BUCK_VOLT_MAX_HEX 0x3f
#define MAX77686_BUCK_VOLT_MASK 0x3f
#define MAX77686_BUCK_MODE_MASK 0x03
......@@ -176,6 +182,15 @@ int max77686_set_buck_mode(struct pmic *p, int buck, char opmode);
#define MAX77686_BUCK_MODE_LPM 0x02
#define MAX77686_BUCK_MODE_ON 0x03
/* For regulator hex<->volt conversion */
#define MAX77686_LDO_UV_MIN 800000 /* Minimum LDO uV value */
#define MAX77686_LDO_UV_LSTEP 25000 /* uV lower value step */
#define MAX77686_LDO_UV_HSTEP 50000 /* uV higher value step */
#define MAX77686_BUCK_UV_LMIN 600000 /* Lower minimun BUCK value */
#define MAX77686_BUCK_UV_HMIN 750000 /* Higher minimun BUCK value */
#define MAX77686_BUCK_UV_LSTEP 12500 /* uV lower value step */
#define MAX77686_BUCK_UV_HSTEP 50000 /* uV higher value step */
/* Buck1 1 volt value */
#define MAX77686_BUCK1OUT_1V 0x5
/* Buck1 1.05 volt value */
......
......@@ -170,7 +170,7 @@ struct dm_regulator_ops {
* @dev - regulator device
* Sets:
* @uV - set the output value [micro Volts]
* Returns: output value [uV] on success or negative errno if fail.
* @return output value [uV] on success or negative errno if fail.
*/
int (*get_value)(struct udevice *dev);
int (*set_value)(struct udevice *dev, int uV);
......@@ -182,7 +182,7 @@ struct dm_regulator_ops {
* @dev - regulator device
* Sets:
* @uA - set the output current [micro Amps]
* Returns: output value [uA] on success or negative errno if fail.
* @return output value [uA] on success or negative errno if fail.
*/
int (*get_current)(struct udevice *dev);
int (*set_current)(struct udevice *dev, int uA);
......@@ -194,13 +194,13 @@ struct dm_regulator_ops {
* @dev - regulator device
* Sets:
* @enable - set true - enable or false - disable
* Returns: true/false for get; or 0 / -errno for set.
* @return true/false for get; or 0 / -errno for set.
*/
bool (*get_enable)(struct udevice *dev);
int (*set_enable)(struct udevice *dev, bool enable);
/**
* The 'get/set_mode()' function calls should operate on a driver
* The 'get/set_mode()' function calls should operate on a driver-
* specific mode definitions, which should be found in:
* field 'mode' of struct mode_desc.
*
......@@ -208,7 +208,7 @@ struct dm_regulator_ops {
* @dev - regulator device
* Sets
* @mode_id - set output mode id (struct dm_regulator_mode->id)
* Returns: id/0 for get/set on success or negative errno if fail.
* @return id/0 for get/set on success or negative errno if fail.
* Note:
* The field 'id' of struct type 'dm_regulator_mode', should be always
* positive number, since the negative is reserved for the error.
......@@ -222,7 +222,7 @@ struct dm_regulator_ops {
*
* @dev - pointer to the regulator device
* @modep - pointer to the returned mode info array
* Returns - count of modep entries on success or negative errno if fail.
* @return - count of modep entries on success or negative errno if fail.
*/
int regulator_mode(struct udevice *dev, struct dm_regulator_mode **modep);
......@@ -230,7 +230,7 @@ int regulator_mode(struct udevice *dev, struct dm_regulator_mode **modep);
* regulator_get_value: get microvoltage voltage value of a given regulator
*
* @dev - pointer to the regulator device
* Returns - positive output value [uV] on success or negative errno if fail.
* @return - positive output value [uV] on success or negative errno if fail.
*/
int regulator_get_value(struct udevice *dev);
......@@ -239,7 +239,7 @@ int regulator_get_value(struct udevice *dev);
*
* @dev - pointer to the regulator device
* @uV - the output value to set [micro Volts]
* Returns - 0 on success or -errno val if fails
* @return - 0 on success or -errno val if fails
*/
int regulator_set_value(struct udevice *dev, int uV);
......@@ -247,7 +247,7 @@ int regulator_set_value(struct udevice *dev, int uV);
* regulator_get_current: get microampere value of a given regulator
*
* @dev - pointer to the regulator device
* Returns - positive output current [uA] on success or negative errno if fail.
* @return - positive output current [uA] on success or negative errno if fail.
*/
int regulator_get_current(struct udevice *dev);
......@@ -256,7 +256,7 @@ int regulator_get_current(struct udevice *dev);
*
* @dev - pointer to the regulator device
* @uA - set the output current [micro Amps]
* Returns - 0 on success or -errno val if fails
* @return - 0 on success or -errno val if fails
*/
int regulator_set_current(struct udevice *dev, int uA);
......@@ -264,7 +264,7 @@ int regulator_set_current(struct udevice *dev, int uA);
* regulator_get_enable: get regulator device enable state.
*
* @dev - pointer to the regulator device
* Returns - true/false of enable state
* @return - true/false of enable state
*/
bool regulator_get_enable(struct udevice *dev);
......@@ -273,7 +273,7 @@ bool regulator_get_enable(struct udevice *dev);
*
* @dev - pointer to the regulator device
* @enable - set true or false
* Returns - 0 on success or -errno val if fails
* @return - 0 on success or -errno val if fails
*/
int regulator_set_enable(struct udevice *dev, bool enable);
......@@ -281,7 +281,7 @@ int regulator_set_enable(struct udevice *dev, bool enable);
* regulator_get_mode: get mode of a given device regulator
*
* @dev - pointer to the regulator device
* Returns - positive mode number on success or -errno val if fails
* @return - positive mode number on success or -errno val if fails
* Note:
* The regulator driver should return one of defined, mode number rather, than
* the raw register value. The struct type 'mode_desc' provides a field 'mode'
......@@ -294,7 +294,7 @@ int regulator_get_mode(struct udevice *dev);
*
* @dev - pointer to the regulator device
* @mode - mode type (field 'mode' of struct mode_desc)
* Returns - 0 on success or -errno value if fails
* @return - 0 on success or -errno value if fails
* Note:
* The regulator driver should take one of defined, mode number rather
* than a raw register value. The struct type 'regulator_mode_desc' has
......@@ -308,14 +308,14 @@ int regulator_set_mode(struct udevice *dev, int mode);
* in device's uclass's platform data (struct dm_regulator_uclass_platdata):
* - Voltage value - will set - if '.min_uV' and '.max_uV' values are equal
* - Current limit - will set - if '.min_uA' and '.max_uA' values are equal
* - Enable - will set - if '.always_on' or '.boot_on' are set to true
* - Enable - will set - if any of: '.always_on' or '.boot_on', is set to true
*
* The function returns on first encountered error.
*
* @platname - expected string for dm_regulator_uclass_platdata .name field
* @devp - returned pointer to the regulator device - if non-NULL passed
* @verbose - (true/false) print regulator setup info, or be quiet
* Returns: 0 on success or negative value of errno.
* @return: 0 on success or negative value of errno.
*
* The returned 'regulator' device can be used with:
* - regulator_get/set_*
......@@ -340,7 +340,7 @@ int regulator_by_platname_autoset_and_enable(const char *platname,
* @list_devp - an array of returned pointers to the successfully setup
* regulator devices if non-NULL passed
* @verbose - (true/false) print each regulator setup info, or be quiet
* Returns: 0 on successfully setup of all list entries or 1 otwerwise.
* @return 0 on successfully setup of all list entries or 1 otwerwise.
*
* The returned 'regulator' devices can be used with:
* - regulator_get/set_*
......@@ -360,8 +360,8 @@ int regulator_by_platname_list_autoset_and_enable(const char *list_platname[],
* Search by name, found in regulator device's name.
*
* @devname - expected string for 'dev->name' of regulator device
* @devp - returned pointer to the regulator device
* Returns: 0 on success or negative value of errno.
* @devp - returned pointer to the regulator device
* @return 0 on success or negative value of errno.
*
* The returned 'regulator' device can be used with:
* - regulator_get/set_*
......@@ -372,9 +372,9 @@ int regulator_by_devname(const char *devname, struct udevice **devp);
* regulator_by_platname: returns the pointer to the pmic regulator device.
* Search by name, found in regulator uclass platdata.
*
* @platname - expected string for dm_regulator_uclass_platdata .name field
* @platname - expected string for uc_pdata->name of regulator uclass platdata
* @devp - returned pointer to the regulator device
* Returns: 0 on success or negative value of errno.
* @return 0 on success or negative value of errno.
*
* The returned 'regulator' device can be used with:
* - regulator_get/set_*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment