summaryrefslogtreecommitdiff
path: root/include/power
diff options
context:
space:
mode:
Diffstat (limited to 'include/power')
-rw-r--r--include/power/as3722.h3
-rw-r--r--include/power/max77686_pmic.h29
-rw-r--r--include/power/pmic.h192
-rw-r--r--include/power/regulator.h386
-rw-r--r--include/power/sandbox_pmic.h138
5 files changed, 743 insertions, 5 deletions
diff --git a/include/power/as3722.h b/include/power/as3722.h
index aa966d2cca1..0f22482ff70 100644
--- a/include/power/as3722.h
+++ b/include/power/as3722.h
@@ -23,5 +23,8 @@ int as3722_gpio_configure(struct udevice *pmic, unsigned int gpio,
unsigned long flags);
int as3722_gpio_direction_output(struct udevice *pmic, unsigned int gpio,
unsigned int level);
+int as3722_read(struct udevice *pmic, u8 reg, u8 *value);
+int as3722_write(struct udevice *pmic, u8 reg, u8 value);
+int as3722_get(struct udevice **devp);
#endif /* __POWER_AS3722_H__ */
diff --git a/include/power/max77686_pmic.h b/include/power/max77686_pmic.h
index b0e42550a2a..23003524962 100644
--- a/include/power/max77686_pmic.h
+++ b/include/power/max77686_pmic.h
@@ -122,11 +122,17 @@ enum {
MAX77686_REG_PMIC_BBAT = 0x7e,
MAX77686_REG_PMIC_32KHZ,
- PMIC_NUM_OF_REGS,
+ MAX77686_NUM_OF_REGS,
};
/* I2C device address for pmic max77686 */
-#define MAX77686_I2C_ADDR (0x12 >> 1)
+#define MAX77686_I2C_ADDR (0x12 >> 1)
+#define MAX77686_LDO_NUM 26
+#define MAX77686_BUCK_NUM 9
+
+/* Drivers name */
+#define MAX77686_LDO_DRIVER "max77686_ldo"
+#define MAX77686_BUCK_DRIVER "max77686_buck"
enum {
REG_DISABLE = 0,
@@ -143,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
@@ -170,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 */
diff --git a/include/power/pmic.h b/include/power/pmic.h
index afbc5aab7e2..eb152ef4926 100644
--- a/include/power/pmic.h
+++ b/include/power/pmic.h
@@ -1,4 +1,7 @@
/*
+ * Copyright (C) 2014-2015 Samsung Electronics
+ * Przemyslaw Marczak <p.marczak@samsung.com>
+ *
* Copyright (C) 2011-2012 Samsung Electronics
* Lukasz Majewski <l.majewski@samsung.com>
*
@@ -8,11 +11,14 @@
#ifndef __CORE_PMIC_H_
#define __CORE_PMIC_H_
-#include <linux/list.h>
#include <i2c.h>
+#include <spi.h>
+#include <linux/list.h>
#include <power/power_chrg.h>
enum { PMIC_I2C, PMIC_SPI, PMIC_NONE};
+
+#ifdef CONFIG_POWER
enum { I2C_PMIC, I2C_NUM, };
enum { PMIC_READ, PMIC_WRITE, };
enum { PMIC_SENSOR_BYTE_ORDER_LITTLE, PMIC_SENSOR_BYTE_ORDER_BIG, };
@@ -77,7 +83,190 @@ struct pmic {
struct pmic *parent;
struct list_head list;
};
+#endif /* CONFIG_POWER */
+
+#ifdef CONFIG_DM_PMIC
+/**
+ * U-Boot PMIC Framework
+ * =====================
+ *
+ * UCLASS_PMIC - This is designed to provide an I/O interface for PMIC devices.
+ *
+ * For the multi-function PMIC devices, this can be used as parent I/O device
+ * for each IC's interface. Then, each child uses its parent for read/write.
+ *
+ * The driver model tree could look like this:
+ *
+ *_ root device
+ * |_ BUS 0 device (e.g. I2C0) - UCLASS_I2C/SPI/...
+ * | |_ PMIC device (READ/WRITE ops) - UCLASS_PMIC
+ * | |_ REGULATOR device (ldo/buck/... ops) - UCLASS_REGULATOR
+ * | |_ CHARGER device (charger ops) - UCLASS_CHARGER (in the future)
+ * | |_ MUIC device (microUSB connector ops) - UCLASS_MUIC (in the future)
+ * | |_ ...
+ * |
+ * |_ BUS 1 device (e.g. I2C1) - UCLASS_I2C/SPI/...
+ * |_ PMIC device (READ/WRITE ops) - UCLASS_PMIC
+ * |_ RTC device (rtc ops) - UCLASS_RTC (in the future)
+ *
+ * We can find two PMIC cases in boards design:
+ * - single I/O interface
+ * - multiple I/O interfaces
+ * We bind a single PMIC device for each interface, to provide an I/O for
+ * its child devices. And each child usually implements a different function,
+ * controlled by the same interface.
+ *
+ * The binding should be done automatically. If device tree nodes/subnodes are
+ * proper defined, then:
+ *
+ * |_ the ROOT driver will bind the device for I2C/SPI node:
+ * |_ the I2C/SPI driver should bind a device for pmic node:
+ * |_ the PMIC driver should bind devices for its childs:
+ * |_ regulator (child)
+ * |_ charger (child)
+ * |_ other (child)
+ *
+ * The same for other device nodes, for multi-interface PMIC.
+ *
+ * Note:
+ * Each PMIC interface driver should use a different compatible string.
+ *
+ * If a PMIC child device driver needs access the PMIC-specific registers,
+ * it need know only the register address and the access can be done through
+ * the parent pmic driver. Like in the example:
+ *
+ *_ root driver
+ * |_ dev: bus I2C0 - UCLASS_I2C
+ * | |_ dev: my_pmic (read/write) (is parent) - UCLASS_PMIC
+ * | |_ dev: my_regulator (set value/etc..) (is child) - UCLASS_REGULATOR
+ *
+ * To ensure such device relationship, the pmic device driver should also bind
+ * all its child devices, like in the example below. It can be done by calling
+ * the 'pmic_bind_children()' - please refer to the function description, which
+ * can be found in this header file. This function, should be called inside the
+ * driver's bind() method.
+ *
+ * For the example driver, please refer the MAX77686 driver:
+ * - 'drivers/power/pmic/max77686.c'
+ */
+
+/**
+ * struct dm_pmic_ops - PMIC device I/O interface
+ *
+ * Should be implemented by UCLASS_PMIC device drivers. The standard
+ * device operations provides the I/O interface for it's childs.
+ *
+ * @reg_count: device's register count
+ * @read: read 'len' bytes at "reg" and store it into the 'buffer'
+ * @write: write 'len' bytes from the 'buffer' to the register at 'reg' address
+ */
+struct dm_pmic_ops {
+ int (*reg_count)(struct udevice *dev);
+ int (*read)(struct udevice *dev, uint reg, uint8_t *buffer, int len);
+ int (*write)(struct udevice *dev, uint reg, const uint8_t *buffer,
+ int len);
+};
+
+/**
+ * enum pmic_op_type - used for various pmic devices operation calls,
+ * for reduce a number of lines with the same code for read/write or get/set.
+ *
+ * @PMIC_OP_GET - get operation
+ * @PMIC_OP_SET - set operation
+*/
+enum pmic_op_type {
+ PMIC_OP_GET,
+ PMIC_OP_SET,
+};
+
+/**
+ * struct pmic_child_info - basic device's child info for bind child nodes with
+ * the driver by the node name prefix and driver name. This is a helper struct
+ * for function: pmic_bind_children().
+ *
+ * @prefix - child node name prefix (or its name if is unique or single)
+ * @driver - driver name for the sub-node with prefix
+ */
+struct pmic_child_info {
+ const char *prefix;
+ const char *driver;
+};
+
+/* drivers/power/pmic-uclass.c */
+
+/**
+ * pmic_bind_children() - bind drivers for given parent pmic, using child info
+ * found in 'child_info' array.
+ *
+ * @pmic - pmic device - the parent of found child's
+ * @child_info - N-childs info array
+ * @return a positive number of childs, or 0 if no child found (error)
+ *
+ * Note: For N-childs the child_info array should have N+1 entries and the last
+ * entry prefix should be NULL - the same as for drivers compatible.
+ *
+ * For example, a single prefix info (N=1):
+ * static const struct pmic_child_info bind_info[] = {
+ * { .prefix = "ldo", .driver = "ldo_driver" },
+ * { },
+ * };
+ *
+ * This function is useful for regulator sub-nodes:
+ * my_regulator@0xa {
+ * reg = <0xa>;
+ * (pmic - bind automatically by compatible)
+ * compatible = "my_pmic";
+ * ...
+ * (pmic's childs - bind by pmic_bind_children())
+ * (nodes prefix: "ldo", driver: "my_regulator_ldo")
+ * ldo1 { ... };
+ * ldo2 { ... };
+ *
+ * (nodes prefix: "buck", driver: "my_regulator_buck")
+ * buck1 { ... };
+ * buck2 { ... };
+ * };
+ */
+int pmic_bind_children(struct udevice *pmic, int offset,
+ const struct pmic_child_info *child_info);
+
+/**
+ * pmic_get: get the pmic device using its name
+ *
+ * @name - device name
+ * @devp - returned pointer to the pmic device
+ * @return 0 on success or negative value of errno.
+ *
+ * The returned devp device can be used with pmic_read/write calls
+ */
+int pmic_get(const char *name, struct udevice **devp);
+
+/**
+ * pmic_reg_count: get the pmic register count
+ *
+ * The required pmic device can be obtained by 'pmic_get()'
+ *
+ * @dev - pointer to the UCLASS_PMIC device
+ * @return register count value on success or negative value of errno.
+ */
+int pmic_reg_count(struct udevice *dev);
+
+/**
+ * pmic_read/write: read/write to the UCLASS_PMIC device
+ *
+ * The required pmic device can be obtained by 'pmic_get()'
+ *
+ * @pmic - pointer to the UCLASS_PMIC device
+ * @reg - device register offset
+ * @buffer - pointer to read/write buffer
+ * @len - byte count for read/write
+ * @return 0 on success or negative value of errno.
+ */
+int pmic_read(struct udevice *dev, uint reg, uint8_t *buffer, int len);
+int pmic_write(struct udevice *dev, uint reg, const uint8_t *buffer, int len);
+#endif /* CONFIG_DM_PMIC */
+#ifdef CONFIG_POWER
int pmic_init(unsigned char bus);
int power_init_board(void);
int pmic_dialog_init(unsigned char bus);
@@ -88,6 +277,7 @@ int pmic_probe(struct pmic *p);
int pmic_reg_read(struct pmic *p, u32 reg, u32 *val);
int pmic_reg_write(struct pmic *p, u32 reg, u32 val);
int pmic_set_output(struct pmic *p, u32 reg, int ldo, int on);
+#endif
#define pmic_i2c_addr (p->hw.i2c.addr)
#define pmic_i2c_tx_num (p->hw.i2c.tx_num)
diff --git a/include/power/regulator.h b/include/power/regulator.h
new file mode 100644
index 00000000000..03a2cefcd61
--- /dev/null
+++ b/include/power/regulator.h
@@ -0,0 +1,386 @@
+/*
+ * Copyright (C) 2014-2015 Samsung Electronics
+ * Przemyslaw Marczak <p.marczak@samsung.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#ifndef _INCLUDE_REGULATOR_H_
+#define _INCLUDE_REGULATOR_H_
+
+/**
+ * U-Boot Voltage/Current Regulator
+ * ================================
+ *
+ * The regulator API is based on a driver model, with the device tree support.
+ * And this header describes the functions and data types for the uclass id:
+ * 'UCLASS_REGULATOR' and the regulator driver API.
+ *
+ * The regulator uclass - is based on uclass platform data which is allocated,
+ * automatically for each regulator device on bind and 'dev->uclass_platdata'
+ * points to it. The data type is: 'struct dm_regulator_uclass_platdata'.
+ * The uclass file: 'drivers/power/regulator/regulator-uclass.c'
+ *
+ * The regulator device - is based on driver's model 'struct udevice'.
+ * The API can use regulator name in two meanings:
+ * - devname - the regulator device's name: 'dev->name'
+ * - platname - the device's platdata's name. So in the code it looks like:
+ * 'uc_pdata = dev->uclass_platdata'; 'name = uc_pdata->name'.
+ *
+ * The regulator device driver - provide an implementation of uclass operations
+ * pointed by 'dev->driver->ops' as a struct of type 'struct dm_regulator_ops'.
+ *
+ * To proper bind the regulator device, the device tree node should provide
+ * regulator constraints, like in the example below:
+ *
+ * ldo1 {
+ * regulator-name = "VDD_MMC_1.8V"; (must be unique for proper bind)
+ * regulator-min-microvolt = <1000000>; (optional)
+ * regulator-max-microvolt = <1000000>; (optional)
+ * regulator-min-microamp = <1000>; (optional)
+ * regulator-max-microamp = <1000>; (optional)
+ * regulator-always-on; (optional)
+ * regulator-boot-on; (optional)
+ * };
+ *
+ * Note: For the proper operation, at least name constraint is needed, since
+ * it can be used when calling regulator_get_by_platname(). And the mandatory
+ * rule for this name is, that it must be globally unique for the single dts.
+ *
+ * Regulator bind:
+ * For each regulator device, the device_bind() should be called with passed
+ * device tree offset. This is required for this uclass's '.post_bind' method,
+ * which does the scan on the device node, for the 'regulator-name' constraint.
+ * If the parent is not a PMIC device, and the child is not bind by function:
+ * 'pmic_bind_childs()', then it's recommended to bind the device by call to
+ * dm_scan_fdt_node() - this is usually done automatically for bus devices,
+ * as a post bind method.
+ *
+ * Regulator get:
+ * Having the device's name constraint, we can call regulator_by_platname(),
+ * to find the required regulator. Before return, the regulator is probed,
+ * and the rest of its constraints are put into the device's uclass platform
+ * data, by the uclass regulator '.pre_probe' method.
+ *
+ * For more info about PMIC bind, please refer to file: 'include/power/pmic.h'
+ *
+ * Note:
+ * Please do not use the device_bind_by_name() function, since it pass '-1' as
+ * device node offset - and the bind will fail on uclass .post_bind method,
+ * because of missing 'regulator-name' constraint.
+ *
+ *
+ * Fixed Voltage/Current Regulator
+ * ===============================
+ *
+ * When fixed voltage regulator is needed, then enable the config:
+ * - CONFIG_DM_REGULATOR_FIXED
+ *
+ * The driver file: 'drivers/power/regulator/fixed.c', provides basic support
+ * for control the GPIO, and return the device tree constraint values.
+ *
+ * To bind the fixed voltage regulator device, we usually use a 'simple-bus'
+ * node as a parent. And 'regulator-fixed' for the driver compatible. This is
+ * the same as in the kernel. The example node of fixed regulator:
+ *
+ * simple-bus {
+ * compatible = "simple-bus";
+ * #address-cells = <1>;
+ * #size-cells = <0>;
+ *
+ * blue_led {
+ * compatible = "regulator-fixed";
+ * regulator-name = "VDD_LED_3.3V";
+ * regulator-min-microvolt = <3300000>;
+ * regulator-max-microvolt = <3300000>;
+ * gpio = <&gpc1 0 GPIO_ACTIVE_LOW>;
+ * };
+ * };
+ *
+ * The fixed regulator devices also provide regulator uclass platform data. And
+ * devices bound from such node, can use the regulator drivers API.
+*/
+
+/* enum regulator_type - used for regulator_*() variant calls */
+enum regulator_type {
+ REGULATOR_TYPE_LDO = 0,
+ REGULATOR_TYPE_BUCK,
+ REGULATOR_TYPE_DVS,
+ REGULATOR_TYPE_FIXED,
+ REGULATOR_TYPE_OTHER,
+};
+
+/**
+ * struct dm_regulator_mode - this structure holds an information about
+ * each regulator operation mode. Probably in most cases - an array.
+ * This will be probably a driver-static data, since it is device-specific.
+ *
+ * @id - a driver-specific mode id
+ * @register_value - a driver-specific value for its mode id
+ * @name - the name of mode - used for regulator command
+ * Note:
+ * The field 'id', should be always a positive number, since the negative values
+ * are reserved for the errno numbers when returns the mode id.
+ */
+struct dm_regulator_mode {
+ int id; /* Set only as >= 0 (negative value is reserved for errno) */
+ int register_value;
+ const char *name;
+};
+
+/**
+ * struct dm_regulator_uclass_platdata - pointed by dev->uclass_platdata, and
+ * allocated on each regulator bind. This structure holds an information
+ * about each regulator's constraints and supported operation modes.
+ * There is no "step" voltage value - so driver should take care of this.
+ *
+ * @type - one of 'enum regulator_type'
+ * @mode - pointer to the regulator mode (array if more than one)
+ * @mode_count - number of '.mode' entries
+ * @min_uV* - minimum voltage (micro Volts)
+ * @max_uV* - maximum voltage (micro Volts)
+ * @min_uA* - minimum amperage (micro Amps)
+ * @max_uA* - maximum amperage (micro Amps)
+ * @always_on* - bool type, true or false
+ * @boot_on* - bool type, true or false
+ * @name** - fdt regulator name - should be taken from the device tree
+ *
+ * Note:
+ * * - set automatically on device probe by the uclass's '.pre_probe' method.
+ * ** - set automatically on device bind by the uclass's '.post_bind' method.
+ * The constraints: type, mode, mode_count, can be set by device driver, e.g.
+ * by the driver '.probe' method.
+ */
+struct dm_regulator_uclass_platdata {
+ enum regulator_type type;
+ struct dm_regulator_mode *mode;
+ int mode_count;
+ int min_uV;
+ int max_uV;
+ int min_uA;
+ int max_uA;
+ bool always_on;
+ bool boot_on;
+ const char *name;
+};
+
+/* Regulator device operations */
+struct dm_regulator_ops {
+ /**
+ * The regulator output value function calls operates on a micro Volts.
+ *
+ * get/set_value - get/set output value of the given output number
+ * @dev - regulator device
+ * Sets:
+ * @uV - set the output value [micro Volts]
+ * @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);
+
+ /**
+ * The regulator output current function calls operates on a micro Amps.
+ *
+ * get/set_current - get/set output current of the given output number
+ * @dev - regulator device
+ * Sets:
+ * @uA - set the output current [micro Amps]
+ * @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);
+
+ /**
+ * The most basic feature of the regulator output is its enable state.
+ *
+ * get/set_enable - get/set enable state of the given output number
+ * @dev - regulator device
+ * Sets:
+ * @enable - set true - enable or false - disable
+ * @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-
+ * specific mode id definitions, which should be found in:
+ * field 'id' of struct dm_regulator_mode.
+ *
+ * get/set_mode - get/set operation mode of the given output number
+ * @dev - regulator device
+ * Sets
+ * @mode_id - set output mode id (struct dm_regulator_mode->id)
+ * @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
+ * a positive number, since the negative is reserved for the error.
+ */
+ int (*get_mode)(struct udevice *dev);
+ int (*set_mode)(struct udevice *dev, int mode_id);
+};
+
+/**
+ * regulator_mode: returns a pointer to the array of regulator mode info
+ *
+ * @dev - pointer to the regulator device
+ * @modep - pointer to the returned mode info array
+ * @return - count of modep entries on success or negative errno if fail.
+ */
+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
+ * @return - positive output value [uV] on success or negative errno if fail.
+ */
+int regulator_get_value(struct udevice *dev);
+
+/**
+ * regulator_set_value: set the microvoltage value of a given regulator.
+ *
+ * @dev - pointer to the regulator device
+ * @uV - the output value to set [micro Volts]
+ * @return - 0 on success or -errno val if fails
+ */
+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
+ * @return - positive output current [uA] on success or negative errno if fail.
+ */
+int regulator_get_current(struct udevice *dev);
+
+/**
+ * regulator_set_current: set the microampere value of a given regulator.
+ *
+ * @dev - pointer to the regulator device
+ * @uA - set the output current [micro Amps]
+ * @return - 0 on success or -errno val if fails
+ */
+int regulator_set_current(struct udevice *dev, int uA);
+
+/**
+ * regulator_get_enable: get regulator device enable state.
+ *
+ * @dev - pointer to the regulator device
+ * @return - true/false of enable state
+ */
+bool regulator_get_enable(struct udevice *dev);
+
+/**
+ * regulator_set_enable: set regulator enable state
+ *
+ * @dev - pointer to the regulator device
+ * @enable - set true or false
+ * @return - 0 on success or -errno val if fails
+ */
+int regulator_set_enable(struct udevice *dev, bool enable);
+
+/**
+ * regulator_get_mode: get active operation mode id of a given regulator
+ *
+ * @dev - pointer to the regulator device
+ * @return - positive mode 'id' number on success or -errno val if fails
+ * Note:
+ * The device can provide an array of operating modes, which is type of struct
+ * dm_regulator_mode. Each mode has it's own 'id', which should be unique inside
+ * that array. By calling this function, the driver should return an active mode
+ * id of the given regulator device.
+ */
+int regulator_get_mode(struct udevice *dev);
+
+/**
+ * regulator_set_mode: set the given regulator's, active mode id
+ *
+ * @dev - pointer to the regulator device
+ * @mode_id - mode id to set ('id' field of struct type dm_regulator_mode)
+ * @return - 0 on success or -errno value if fails
+ * Note:
+ * The device can provide an array of operating modes, which is type of struct
+ * dm_regulator_mode. Each mode has it's own 'id', which should be unique inside
+ * that array. By calling this function, the driver should set the active mode
+ * of a given regulator to given by "mode_id" argument.
+ */
+int regulator_set_mode(struct udevice *dev, int mode_id);
+
+/**
+ * regulator_autoset: setup the regulator given by its uclass's platform data
+ * name field. The setup depends on constraints found in device's uclass's
+ * platform data (struct dm_regulator_uclass_platdata):
+ * - Enable - will set - if any of: 'always_on' or 'boot_on' is set to true,
+ * or if both are unset, then the function returns
+ * - 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
+ *
+ * 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
+ * @return: 0 on success or negative value of errno.
+ *
+ * The returned 'regulator' device can be used with:
+ * - regulator_get/set_*
+ */
+int regulator_autoset(const char *platname,
+ struct udevice **devp,
+ bool verbose);
+
+/**
+ * regulator_list_autoset: setup the regulators given by list of their uclass's
+ * platform data name field. The setup depends on constraints found in device's
+ * uclass's platform data. The function loops with calls to:
+ * regulator_autoset() for each name from the list.
+ *
+ * @list_platname - an array of expected strings for .name field of each
+ * regulator's uclass platdata
+ * @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
+ * @return 0 on successfully setup of all list entries, otherwise first error.
+ *
+ * The returned 'regulator' devices can be used with:
+ * - regulator_get/set_*
+ *
+ * Note: The list must ends with NULL entry, like in the "platname" list below:
+ * char *my_regulators[] = {
+ * "VCC_3.3V",
+ * "VCC_1.8V",
+ * NULL,
+ * };
+ */
+int regulator_list_autoset(const char *list_platname[],
+ struct udevice *list_devp[],
+ bool verbose);
+
+/**
+ * regulator_get_by_devname: returns the pointer to the pmic regulator device.
+ * 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
+ * @return 0 on success or negative value of errno.
+ *
+ * The returned 'regulator' device is probed and can be used with:
+ * - regulator_get/set_*
+ */
+int regulator_get_by_devname(const char *devname, struct udevice **devp);
+
+/**
+ * regulator_get_by_platname: returns the pointer to the pmic regulator device.
+ * Search by name, found in regulator uclass platdata.
+ *
+ * @platname - expected string for uc_pdata->name of regulator uclass platdata
+ * @devp - returned pointer to the regulator device
+ * @return 0 on success or negative value of errno.
+ *
+ * The returned 'regulator' device is probed and can be used with:
+ * - regulator_get/set_*
+ */
+int regulator_get_by_platname(const char *platname, struct udevice **devp);
+
+#endif /* _INCLUDE_REGULATOR_H_ */
diff --git a/include/power/sandbox_pmic.h b/include/power/sandbox_pmic.h
new file mode 100644
index 00000000000..ae142921e53
--- /dev/null
+++ b/include/power/sandbox_pmic.h
@@ -0,0 +1,138 @@
+/*
+ * Copyright (C) 2015 Samsung Electronics
+ * Przemyslaw Marczak <p.marczak@samsung.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#ifndef _SANDBOX_PMIC_H_
+#define _SANDBOX_PMIC_H_
+
+#define SANDBOX_LDO_DRIVER "sandbox_ldo"
+#define SANDBOX_OF_LDO_PREFIX "ldo"
+#define SANDBOX_BUCK_DRIVER "sandbox_buck"
+#define SANDBOX_OF_BUCK_PREFIX "buck"
+
+#define SANDBOX_BUCK_COUNT 2
+#define SANDBOX_LDO_COUNT 2
+/*
+ * Sandbox PMIC registers:
+ * We have only 12 significant registers, but we alloc 16 for padding.
+ */
+enum {
+ SANDBOX_PMIC_REG_BUCK1_UV = 0,
+ SANDBOX_PMIC_REG_BUCK1_UA,
+ SANDBOX_PMIC_REG_BUCK1_OM,
+
+ SANDBOX_PMIC_REG_BUCK2_UV,
+ SANDBOX_PMIC_REG_BUCK2_UA,
+ SANDBOX_PMIC_REG_BUCK2_OM,
+
+ SANDBOX_PMIC_REG_LDO_OFFSET,
+ SANDBOX_PMIC_REG_LDO1_UV = SANDBOX_PMIC_REG_LDO_OFFSET,
+ SANDBOX_PMIC_REG_LDO1_UA,
+ SANDBOX_PMIC_REG_LDO1_OM,
+
+ SANDBOX_PMIC_REG_LDO2_UV,
+ SANDBOX_PMIC_REG_LDO2_UA,
+ SANDBOX_PMIC_REG_LDO2_OM,
+
+ SANDBOX_PMIC_REG_COUNT = 16,
+};
+
+/* Register offset for output: micro Volts, micro Amps, Operation Mode */
+enum {
+ OUT_REG_UV = 0,
+ OUT_REG_UA,
+ OUT_REG_OM,
+ OUT_REG_COUNT,
+};
+
+/* Buck operation modes */
+enum {
+ BUCK_OM_OFF = 0,
+ BUCK_OM_ON,
+ BUCK_OM_PWM,
+ BUCK_OM_COUNT,
+};
+
+/* Ldo operation modes */
+enum {
+ LDO_OM_OFF = 0,
+ LDO_OM_ON,
+ LDO_OM_SLEEP,
+ LDO_OM_STANDBY,
+ LDO_OM_COUNT,
+};
+
+/* BUCK1 Voltage: min: 0.8V, step: 25mV, max 2.4V */
+#define OUT_BUCK1_UV_MIN 800000
+#define OUT_BUCK1_UV_MAX 2400000
+#define OUT_BUCK1_UV_STEP 25000
+
+/* BUCK1 Amperage: min: 150mA, step: 25mA, max: 250mA */
+#define OUT_BUCK1_UA_MIN 150000
+#define OUT_BUCK1_UA_MAX 250000
+#define OUT_BUCK1_UA_STEP 25000
+
+/* BUCK2 Voltage: min: 0.75V, step: 50mV, max 3.95V */
+#define OUT_BUCK2_UV_MIN 750000
+#define OUT_BUCK2_UV_MAX 3950000
+#define OUT_BUCK2_UV_STEP 50000
+
+/* LDO1 Voltage: min: 0.8V, step: 25mV, max 2.4V */
+#define OUT_LDO1_UV_MIN 800000
+#define OUT_LDO1_UV_MAX 2400000
+#define OUT_LDO1_UV_STEP 25000
+
+/* LDO1 Amperage: min: 100mA, step: 50mA, max: 200mA */
+#define OUT_LDO1_UA_MIN 100000
+#define OUT_LDO1_UA_MAX 200000
+#define OUT_LDO1_UA_STEP 50000
+
+/* LDO2 Voltage: min: 0.75V, step: 50mV, max 3.95V */
+#define OUT_LDO2_UV_MIN 750000
+#define OUT_LDO2_UV_MAX 3950000
+#define OUT_LDO2_UV_STEP 50000
+
+/* register <-> value conversion */
+#define REG2VAL(min, step, reg) ((min) + ((step) * (reg)))
+#define VAL2REG(min, step, val) (((val) - (min)) / (step))
+
+/* Operation mode id -> register value conversion */
+#define OM2REG(x) (x)
+
+/* Test data for: test/dm/power.c */
+
+/* BUCK names */
+#define SANDBOX_BUCK1_DEVNAME "buck1"
+#define SANDBOX_BUCK1_PLATNAME "SUPPLY_1.2V"
+#define SANDBOX_BUCK2_DEVNAME "buck2"
+#define SANDBOX_BUCK2_PLATNAME "SUPPLY_3.3V"
+/* LDO names */
+#define SANDBOX_LDO1_DEVNAME "ldo1"
+#define SANDBOX_LDO1_PLATNAME "VDD_EMMC_1.8V"
+#define SANDBOX_LDO2_DEVNAME "ldo2"
+#define SANDBOX_LDO2_PLATNAME "VDD_LCD_3.3V"
+
+/*
+ * Expected regulators setup after call of:
+ * - regulator_autoset()
+ * - regulator_list_autoset()
+ */
+
+/* BUCK1: for testing regulator_autoset() */
+#define SANDBOX_BUCK1_AUTOSET_EXPECTED_UV 1200000
+#define SANDBOX_BUCK1_AUTOSET_EXPECTED_UA 200000
+#define SANDBOX_BUCK1_AUTOSET_EXPECTED_ENABLE true
+
+/* LDO1/2 for testing regulator_list_autoset() */
+#define SANDBOX_LDO1_AUTOSET_EXPECTED_UV 1800000
+#define SANDBOX_LDO1_AUTOSET_EXPECTED_UA 100000
+#define SANDBOX_LDO1_AUTOSET_EXPECTED_ENABLE true
+
+#define SANDBOX_LDO2_AUTOSET_EXPECTED_UV 3000000
+#define SANDBOX_LDO2_AUTOSET_EXPECTED_UA -ENOSYS
+#define SANDBOX_LDO2_AUTOSET_EXPECTED_ENABLE false
+
+#endif