X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=include%2Fpower%2Fregulator.h;h=74938dd61e49287e378902c5f4a20b2f2306023d;hb=87271ed8ebf0217471ea5f785402488f5fb7a26d;hp=6916660255d38b2ee141ae0c508b4bade222b8a0;hpb=1757df4693fcde9fb4d4de02a22cc74d6f5caec1;p=oweals%2Fu-boot.git diff --git a/include/power/regulator.h b/include/power/regulator.h index 6916660255..74938dd61e 100644 --- a/include/power/regulator.h +++ b/include/power/regulator.h @@ -1,8 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ /* * Copyright (C) 2014-2015 Samsung Electronics * Przemyslaw Marczak - * - * SPDX-License-Identifier: GPL-2.0+ */ #ifndef _INCLUDE_REGULATOR_H_ @@ -34,7 +33,7 @@ * regulator constraints, like in the example below: * * ldo1 { - * regulator-name = "VDD_MMC_1.8V"; (mandatory for bind) + * 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) @@ -43,19 +42,23 @@ * regulator-boot-on; (optional) * }; * - * Please take a notice, that for the proper operation at least name constraint - * is needed, e.g. for call the device_by_platname(...). + * 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. + * If regulator-name property is not provided, node name will be chosen. * * 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 do the scan on the device node, for the 'regulator-name' constraint. + * 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, + * dm_scan_fdt_dev() - 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 interesting regulator. Before return, the regulator is probed, + * 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. * @@ -104,6 +107,7 @@ enum regulator_type { REGULATOR_TYPE_BUCK, REGULATOR_TYPE_DVS, REGULATOR_TYPE_FIXED, + REGULATOR_TYPE_GPIO, REGULATOR_TYPE_OTHER, }; @@ -125,6 +129,11 @@ struct dm_regulator_mode { const char *name; }; +enum regulator_flag { + REGULATOR_FLAG_AUTOSET_UV = 1 << 0, + REGULATOR_FLAG_AUTOSET_UA = 1 << 1, +}; + /** * struct dm_regulator_uclass_platdata - pointed by dev->uclass_platdata, and * allocated on each regulator bind. This structure holds an information @@ -140,7 +149,12 @@ struct dm_regulator_mode { * @max_uA* - maximum amperage (micro Amps) * @always_on* - bool type, true or false * @boot_on* - bool type, true or false + * TODO(sjg@chromium.org): Consider putting the above two into @flags + * @ramp_delay - Time to settle down after voltage change (unit: uV/us) + * @flags: - flags value (see REGULATOR_FLAG_...) * @name** - fdt regulator name - should be taken from the device tree + * ctrl_reg: - Control register offset used to enable/disable regulator + * volt_reg: - register offset for writing voltage vsel values * * Note: * * - set automatically on device probe by the uclass's '.pre_probe' method. @@ -154,11 +168,18 @@ struct dm_regulator_uclass_platdata { int mode_count; int min_uV; int max_uV; + int init_uV; int min_uA; int max_uA; + unsigned int ramp_delay; bool always_on; bool boot_on; const char *name; + int flags; + u8 ctrl_reg; + u8 volt_reg; + bool suspend_on; + u32 suspend_uV; }; /* Regulator device operations */ @@ -175,6 +196,19 @@ struct dm_regulator_ops { int (*get_value)(struct udevice *dev); int (*set_value)(struct udevice *dev, int uV); + /** + * The regulator suspend output value function calls operates + * on a micro Volts. + * + * get/set_suspen_value - get/set suspend mode output value + * @dev - regulator device + * Sets: + * @uV - set the suspend output value [micro Volts] + * @return output value [uV] on success or negative errno if fail. + */ + int (*set_suspend_value)(struct udevice *dev, int uV); + int (*get_suspend_value)(struct udevice *dev); + /** * The regulator output current function calls operates on a micro Amps. * @@ -194,15 +228,28 @@ struct dm_regulator_ops { * @dev - regulator device * Sets: * @enable - set true - enable or false - disable - * @return true/false for get; or 0 / -errno for set. + * @return true/false for get or -errno if fail; 0 / -errno for set. */ - bool (*get_enable)(struct udevice *dev); + int (*get_enable)(struct udevice *dev); int (*set_enable)(struct udevice *dev, bool enable); + /** + * The most basic feature of the regulator output is its enable state + * in suspend mode. + * + * get/set_suspend_enable - get/set enable state of the suspend output + * @dev - regulator device + * Sets: + * @enable - set true - enable or false - disable + * @return true/false for get or -errno if fail; 0 / -errno for set. + */ + int (*set_suspend_enable)(struct udevice *dev, bool enable); + int (*get_suspend_enable)(struct udevice *dev); + /** * 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. + * 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 @@ -211,7 +258,7 @@ struct dm_regulator_ops { * @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. + * 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); @@ -243,6 +290,33 @@ int regulator_get_value(struct udevice *dev); */ int regulator_set_value(struct udevice *dev, int uV); +/** + * regulator_set_suspend_value: set the suspend microvoltage value of a given regulator. + * + * @dev - pointer to the regulator device + * @uV - the output suspend value to set [micro Volts] + * @return - 0 on success or -errno val if fails + */ +int regulator_set_suspend_value(struct udevice *dev, int uV); + +/** + * regulator_get_suspend_value: get the suspend microvoltage 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_suspend_value(struct udevice *dev); + +/** + * regulator_set_value_force: set the microvoltage value of a given regulator + * without any min-,max condition check + * + * @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_force(struct udevice *dev, int uV); + /** * regulator_get_current: get microampere value of a given regulator * @@ -264,9 +338,9 @@ 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 + * @return - true/false of enable state or -errno val if fails */ -bool regulator_get_enable(struct udevice *dev); +int regulator_get_enable(struct udevice *dev); /** * regulator_set_enable: set regulator enable state @@ -278,107 +352,177 @@ bool regulator_get_enable(struct udevice *dev); int regulator_set_enable(struct udevice *dev, bool enable); /** - * regulator_get_mode: get mode of a given device regulator + * regulator_set_enable_if_allowed: set regulator enable state if allowed by + * regulator + * + * @dev - pointer to the regulator device + * @enable - set true or false + * @return - 0 on success or if enabling is not supported + * -errno val if fails. + */ +int regulator_set_enable_if_allowed(struct udevice *dev, bool enable); + +/** + * regulator_set_suspend_enable: set regulator suspend enable state * * @dev - pointer to the regulator device - * @return - positive mode number on success or -errno val if fails + * @enable - set true or false + * @return - 0 on success or -errno val if fails + */ +int regulator_set_suspend_enable(struct udevice *dev, bool enable); + +/** + * regulator_get_suspend_enable: get regulator suspend enable state + * + * @dev - pointer to the regulator device + * @return - true/false of enable state or -errno val if fails + */ +int regulator_get_suspend_enable(struct udevice *dev); + +/** + * 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 regulator driver should return one of defined, mode number rather, than - * the raw register value. The struct type 'mode_desc' provides a field 'mode' - * for this purpose and register_value for a raw register value. + * 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 given regulator mode + * regulator_set_mode: set the given regulator's, active mode id * - * @dev - pointer to the regulator device - * @mode - mode type (field 'mode' of struct mode_desc) - * @return - 0 on success or -errno value if fails + * @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 regulator driver should take one of defined, mode number rather - * than a raw register value. The struct type 'regulator_mode_desc' has - * a mode field for this purpose and register_value for a raw register value. + * 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); + +/** + * regulators_enable_boot_on() - enable regulators needed for boot + * + * This enables all regulators which are marked to be on at boot time. This + * only works for regulators which don't have a range for voltage/current, + * since in that case it is not possible to know which value to use. + * + * This effectively calls regulator_autoset() for every regulator. + */ +int regulators_enable_boot_on(bool verbose); + +/** + * regulator_autoset: setup the voltage/current on a regulator + * + * 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 the first-encountered error. + * + * @platname - expected string for dm_regulator_uclass_platdata .name field + * @devp - returned pointer to the regulator device - if non-NULL passed + * @return: 0 on success or negative value of errno. */ -int regulator_set_mode(struct udevice *dev, int mode); +int regulator_autoset(struct udevice *dev); /** - * regulator_by_platname_autoset_and_enable: setup the regulator given by - * its uclass's platform data '.name'. The setup depends on constraints found - * in device's uclass's platform data (struct dm_regulator_uclass_platdata): + * regulator_autoset_by_name: 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 - * - 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 + * @devp - returned pointer to the regulator device - if non-NULL passed * @return: 0 on success or negative value of errno. * * The returned 'regulator' device can be used with: * - regulator_get/set_* - * For shorter call name, the below macro regulator_autoset() can be used. */ -int regulator_by_platname_autoset_and_enable(const char *platname, - struct udevice **devp, - bool verbose); - -#define regulator_autoset(platname, devp, verbose) \ - regulator_by_platname_autoset_and_enable(platname, devp, verbose) +int regulator_autoset_by_name(const char *platname, struct udevice **devp); /** - * regulator_by_platname_list_autoset_and_enable: setup the regulators given by - * list of its uclass's platform data '.name'. The setup depends on constraints - * found in device's uclass's platform data. The function loops with calls to: - * regulator_by_platname_autoset_and_enable() for each name of list. + * 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_by_name() for each name from the list. * * @list_platname - an array of expected strings for .name field of each * regulator's uclass platdata - * @list_entries - number of regulator's name list entries * @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 or 1 otwerwise. + * @return 0 on successfully setup of all list entries, otherwise first error. * * The returned 'regulator' devices can be used with: * - regulator_get/set_* - * For shorter call name, the below macro regulator_list_autoset() can be used. + * + * 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_by_platname_list_autoset_and_enable(const char *list_platname[], - int list_entries, - struct udevice *list_devp[], - bool verbose); - -#define regulator_list_autoset(namelist, entries, devlist, verbose) \ - regulator_by_platname_list_autoset_and_enable(namelist, entries, \ - devlist, verbose) +int regulator_list_autoset(const char *list_platname[], + struct udevice *list_devp[], + bool verbose); /** - * regulator_by_devname: returns the pointer to the pmic regulator device. - * Search by name, found in regulator device's name. + * 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 can be used with: + * The returned 'regulator' device is probed and can be used with: * - regulator_get/set_* */ -int regulator_by_devname(const char *devname, struct udevice **devp); +int regulator_get_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. + * 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 + * @devp - returns pointer to the regulator device or NULL on error * @return 0 on success or negative value of errno. * - * The returned 'regulator' device can be used with: + * The returned 'regulator' device is probed and can be used with: * - regulator_get/set_* */ -int regulator_by_platname(const char *platname, struct udevice **devp); +int regulator_get_by_platname(const char *platname, struct udevice **devp); + +/** + * device_get_supply_regulator: returns the pointer to the supply regulator. + * Search by phandle, found in device's node. + * + * Note: Please pay attention to proper order of device bind sequence. + * The regulator device searched by the phandle, must be binded before + * this function call. + * + * @dev - device with supply phandle + * @supply_name - phandle name of regulator + * @devp - returned pointer to the supply device + * @return 0 on success or negative value of errno. + */ +int device_get_supply_regulator(struct udevice *dev, const char *supply_name, + struct udevice **devp); #endif /* _INCLUDE_REGULATOR_H_ */