public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Przemyslaw Marczak <p.marczak@samsung.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v3 36/54] dm: pmic: Split output from function
Date: Wed, 01 Jul 2015 11:44:20 +0200	[thread overview]
Message-ID: <5593B674.1010000@samsung.com> (raw)
In-Reply-To: <1435095556-15924-37-git-send-email-sjg@chromium.org>

Hello Simon,

On 06/23/2015 11:38 PM, Simon Glass wrote:
> The regulator_autoset() function mixes printf() output and PMIC adjustment
> code. It provides a boolean to control the output. It is better to avoid
> missing logic and output, and this permits a smaller SPL code size. So
> split the output into a separate function.
>
> Also rename the function to have a by_name() suffix, since we would like
> to be able to pass a device when we know it, and thus avoid the name
> search.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
> Changes in v3: None
> Changes in v2: None
>
>   drivers/power/regulator/regulator-uclass.c | 98 +++++++++++-------------------
>   include/power/regulator.h                  | 34 ++++++++---
>   include/power/sandbox_pmic.h               |  4 +-
>   test/dm/regulator.c                        |  2 +-
>   4 files changed, 63 insertions(+), 75 deletions(-)
>
> diff --git a/drivers/power/regulator/regulator-uclass.c b/drivers/power/regulator/regulator-uclass.c
> index 0f1ca77..687d3b1 100644
> --- a/drivers/power/regulator/regulator-uclass.c
> +++ b/drivers/power/regulator/regulator-uclass.c
> @@ -138,87 +138,57 @@ int regulator_get_by_devname(const char *devname, struct udevice **devp)
>   	return uclass_get_device_by_name(UCLASS_REGULATOR, devname, devp);
>   }
>
> -static int failed(int ret, bool verbose, const char *fmt, ...)
> +int regulator_autoset(struct udevice *dev)
>   {
> -	va_list args;
> -	char buf[64];
> -
> -	if (verbose == false)
> -		return ret;
> +	struct dm_regulator_uclass_platdata *uc_pdata;
> +	int ret = 0;
>
> -	va_start(args, fmt);
> -	vscnprintf(buf, sizeof(buf), fmt, args);
> -	va_end(args);
> +	uc_pdata = dev_get_uclass_platdata(dev);
> +	if (!uc_pdata->always_on && !uc_pdata->boot_on)
> +		return -EMEDIUMTYPE;
>
> -	printf(buf);
> +	if (uc_pdata->flags & REGULATOR_FLAG_AUTOSET_UV)
> +		ret = regulator_set_value(dev, uc_pdata->min_uV);
> +	if (!ret && (uc_pdata->flags & REGULATOR_FLAG_AUTOSET_UA))
> +		ret = regulator_set_current(dev, uc_pdata->min_uA);
>
>   	if (!ret)
> -		return 0;
> -
> -	printf(" (ret: %d)", ret);
> +		ret = regulator_set_enable(dev, true);
>
>   	return ret;
>   }
>
> -int regulator_autoset(const char *platname,
> -		      struct udevice **devp,
> -		      bool verbose)
> +static void regulator_show(struct udevice *dev, int ret)
>   {
>   	struct dm_regulator_uclass_platdata *uc_pdata;
> -	struct udevice *dev;
> -	int ret;
> -
> -	if (devp)
> -		*devp = NULL;
> -
> -	ret = regulator_get_by_platname(platname, &dev);
> -	if (ret) {
> -		error("Can get the regulator: %s!", platname);
> -		return ret;
> -	}
>
>   	uc_pdata = dev_get_uclass_platdata(dev);
> -	if (!uc_pdata) {
> -		error("Can get the regulator %s uclass platdata!", platname);
> -		return -ENXIO;
> -	}
> -
> -	if (!uc_pdata->always_on && !uc_pdata->boot_on)
> -		goto retdev;
>
> -	if (verbose)
> -		printf("%s@%s: ", dev->name, uc_pdata->name);
> -
> -	/* Those values are optional (-ENODATA if unset) */
> -	if ((uc_pdata->min_uV != -ENODATA) &&
> -	    (uc_pdata->max_uV != -ENODATA) &&
> -	    (uc_pdata->min_uV == uc_pdata->max_uV)) {
> -		ret = regulator_set_value(dev, uc_pdata->min_uV);
> -		if (failed(ret, verbose, "set %d uV", uc_pdata->min_uV))
> -			goto exit;
> -	}
> -
> -	/* Those values are optional (-ENODATA if unset) */
> -	if ((uc_pdata->min_uA != -ENODATA) &&
> -	    (uc_pdata->max_uA != -ENODATA) &&
> -	    (uc_pdata->min_uA == uc_pdata->max_uA)) {
> -		ret = regulator_set_current(dev, uc_pdata->min_uA);
> -		if (failed(ret, verbose, "; set %d uA", uc_pdata->min_uA))
> -			goto exit;
> -	}
> +	printf("%s@%s: ", dev->name, uc_pdata->name);
> +	if (uc_pdata->flags & REGULATOR_FLAG_AUTOSET_UV)
> +		printf("set %d uV", uc_pdata->min_uV);
> +	if (uc_pdata->flags & REGULATOR_FLAG_AUTOSET_UA)
> +		printf("; set %d uA", uc_pdata->min_uA);
> +	printf("; enabling");
> +	if (ret)
> +		printf(" (ret: %d)\n", ret);
> +	printf("\n");
> +}
>
> -	ret = regulator_set_enable(dev, true);
> -	if (failed(ret, verbose, "; enabling", uc_pdata->min_uA))
> -		goto exit;
> +int regulator_autoset_by_name(const char *platname, struct udevice **devp)
> +{
> +	struct udevice *dev;
> +	int ret;
>
> -retdev:
> +	ret = regulator_get_by_platname(platname, &dev);
>   	if (devp)
>   		*devp = dev;
> -exit:
> -	if (verbose)
> -		printf("\n");
> +	if (ret) {
> +		debug("Can get the regulator: %s!", platname);
> +		return ret;
> +	}
>
> -	return ret;
> +	return regulator_autoset(dev);
>   }
>
>   int regulator_list_autoset(const char *list_platname[],
> @@ -229,7 +199,9 @@ int regulator_list_autoset(const char *list_platname[],
>   	int error = 0, i = 0, ret;
>
>   	while (list_platname[i]) {
> -		ret = regulator_autoset(list_platname[i], &dev, verbose);
> +		ret = regulator_autoset_by_name(list_platname[i], &dev);
> +		if (ret != -EMEDIUMTYPE && verbose)
> +			regulator_show(dev, ret);
>   		if (ret & !error)
>   			error = ret;
>
> diff --git a/include/power/regulator.h b/include/power/regulator.h
> index 79ce0a4..86e9c3b 100644
> --- a/include/power/regulator.h
> +++ b/include/power/regulator.h
> @@ -316,9 +316,28 @@ int regulator_get_mode(struct udevice *dev);
>   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):
> + * regulator_autoset: setup the the voltage/current on a regulator

duplicated "the"

> + *
> + * 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_autoset(struct udevice *dev);
> +
> +/**
> + * 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
> @@ -328,21 +347,18 @@ int regulator_set_mode(struct udevice *dev, int mode_id);
>    *
>    * @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);
> +int regulator_autoset_by_name(const char *platname, struct udevice **devp);
>
>   /**
>    * 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.
> + * 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
> @@ -383,7 +399,7 @@ int regulator_get_by_devname(const char *devname, struct udevice **devp);
>    * 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 is probed and can be used with:
> diff --git a/include/power/sandbox_pmic.h b/include/power/sandbox_pmic.h
> index ae14292..8547674 100644
> --- a/include/power/sandbox_pmic.h
> +++ b/include/power/sandbox_pmic.h
> @@ -117,11 +117,11 @@ enum {
>
>   /*
>    * Expected regulators setup after call of:
> - * - regulator_autoset()
> + * - regulator_autoset_by_name()
>    * - regulator_list_autoset()
>    */
>
> -/* BUCK1: for testing regulator_autoset() */
> +/* BUCK1: for testing regulator_autoset_by_name() */
>   #define SANDBOX_BUCK1_AUTOSET_EXPECTED_UV	1200000
>   #define SANDBOX_BUCK1_AUTOSET_EXPECTED_UA	200000
>   #define SANDBOX_BUCK1_AUTOSET_EXPECTED_ENABLE	true
> diff --git a/test/dm/regulator.c b/test/dm/regulator.c
> index d279c04..3d0056f 100644
> --- a/test/dm/regulator.c
> +++ b/test/dm/regulator.c
> @@ -210,7 +210,7 @@ static int dm_test_power_regulator_autoset(struct unit_test_state *uts)
>   	 * Expected output state: uV=1200000; uA=200000; output enabled
>   	 */
>   	platname = regulator_names[BUCK1][PLATNAME];
> -	ut_assertok(regulator_autoset(platname, &dev_autoset, false));
> +	ut_assertok(regulator_autoset_by_name(platname, &dev_autoset));
>
>   	/* Check, that the returned device is proper */
>   	ut_assertok(regulator_get_by_platname(platname, &dev));
>

Tested on:
- Odroid U3 (odroid_defconfig)
- Sandbox - ut pmic/regulator

Tested-by: Przemyslaw Marczak <p.marczak@samsung.com>
Acked-by: Przemyslaw Marczak <p.marczak@samsung.com>

Best regards,
-- 
Przemyslaw Marczak
Samsung R&D Institute Poland
Samsung Electronics
p.marczak at samsung.com

  reply	other threads:[~2015-07-01  9:44 UTC|newest]

Thread overview: 133+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-23 21:38 [U-Boot] [PATCH v3 00/54] dm: Introduce new driver model uclasses Simon Glass
2015-06-23 21:38 ` [U-Boot] [PATCH v3 01/54] Add a dhrystone benchmark command Simon Glass
2015-07-17 23:56   ` Simon Glass
2015-06-23 21:38 ` [U-Boot] [PATCH v3 02/54] sandbox: Enable dhry command Simon Glass
2015-07-17 23:56   ` Simon Glass
2015-06-23 21:38 ` [U-Boot] [PATCH v3 03/54] mkimage: Display a better list of available image types Simon Glass
2015-07-17 23:56   ` Simon Glass
2015-06-23 21:38 ` [U-Boot] [PATCH v3 04/54] fdt: Add a function to remove unused strings from a device tree Simon Glass
2015-07-17 23:56   ` Simon Glass
2015-06-23 21:38 ` [U-Boot] [PATCH v3 05/54] fdt: Add fdt_first/next_region() functions Simon Glass
2015-07-17 23:56   ` Simon Glass
2015-06-23 21:38 ` [U-Boot] [PATCH v3 06/54] fdt: Add fdtgrep tool Simon Glass
2015-07-17 23:56   ` Simon Glass
2015-06-23 21:38 ` [U-Boot] [PATCH v3 07/54] dm: Reduce SPL device tree size Simon Glass
2015-07-17 23:56   ` Simon Glass
2015-06-23 21:38 ` [U-Boot] [PATCH v3 08/54] dm: arm: Put driver model I2C drivers before legacy ones Simon Glass
2015-07-17 23:56   ` Simon Glass
2015-06-23 21:38 ` [U-Boot] [PATCH v3 09/54] Add a way of checking the position of a structure member Simon Glass
2015-07-17 23:56   ` Simon Glass
2015-06-23 21:38 ` [U-Boot] [PATCH v3 10/54] debug_uart: Remove use of asmlinkage Simon Glass
2015-07-17 23:56   ` Simon Glass
2015-06-23 21:38 ` [U-Boot] [PATCH v3 11/54] dm: Allow debug UART to support an early console Simon Glass
2015-07-17 23:56   ` Simon Glass
2015-06-23 21:38 ` [U-Boot] [PATCH v3 12/54] sandbox: Drop special-case sandbox console code Simon Glass
2015-07-17 23:56   ` Simon Glass
2015-06-23 21:38 ` [U-Boot] [PATCH v3 13/54] dm: Move the tree/uclass dump code into its own file Simon Glass
2015-07-17 23:56   ` Simon Glass
2015-06-23 21:38 ` [U-Boot] [PATCH v3 14/54] dm: core: Use debug() instead of printf() for failures Simon Glass
2015-07-17 23:56   ` Simon Glass
2015-06-23 21:38 ` [U-Boot] [PATCH v3 15/54] dm: core: Add a function to find any device from device tree Simon Glass
2015-07-17 23:56   ` Simon Glass
2015-06-23 21:38 ` [U-Boot] [PATCH v3 16/54] dm: core: Correct device_get_child_by_of_offset() parameter Simon Glass
2015-07-17 23:56   ` Simon Glass
2015-06-23 21:38 ` [U-Boot] [PATCH v3 17/54] dm: gpio: Allow GPIO uclass to be used in SPL Simon Glass
2015-07-17 23:56   ` Simon Glass
2015-06-23 21:38 ` [U-Boot] [PATCH v3 18/54] dm: gpio: Add dm_gpio_lookup_name() to look up a GPIO name Simon Glass
2015-07-17 23:56   ` Simon Glass
2015-06-23 21:38 ` [U-Boot] [PATCH v3 19/54] dm: gpio: Add dm_gpio_request() to manually request a GPIO Simon Glass
2015-07-17 23:56   ` Simon Glass
2015-06-23 21:38 ` [U-Boot] [PATCH v3 20/54] dm: Add support for register maps (regmap) Simon Glass
2015-07-17 23:56   ` Simon Glass
2015-06-23 21:38 ` [U-Boot] [PATCH v3 21/54] dm: Add support for generic system controllers (syscon) Simon Glass
2015-07-17 23:56   ` Simon Glass
2015-06-23 21:38 ` [U-Boot] [PATCH v3 22/54] dm: Correct the missing method check in cpu_get_info() Simon Glass
2015-07-08 14:10   ` Simon Glass
2015-06-23 21:38 ` [U-Boot] [PATCH v3 23/54] dm: Add support for LEDs Simon Glass
2015-07-17 23:56   ` Simon Glass
2015-06-23 21:38 ` [U-Boot] [PATCH v3 24/54] dm: led: Add a driver for GPIO-controlled LEDs Simon Glass
2015-07-17 23:57   ` Simon Glass
2015-06-23 21:38 ` [U-Boot] [PATCH v3 25/54] spl: Add debugging info for spl_mmc boot Simon Glass
2015-07-17 23:57   ` Simon Glass
2015-06-23 21:38 ` [U-Boot] [PATCH v3 26/54] dm: mmc: Add an MMC uclass Simon Glass
2015-07-17 23:57   ` Simon Glass
2015-06-23 21:38 ` [U-Boot] [PATCH v3 27/54] mmc: Avoid using printf() for errors Simon Glass
2015-06-24  1:56   ` Chen-Yu Tsai
2015-06-23 21:38 ` [U-Boot] [PATCH v3 28/54] mmc: Add debug() output on read errors Simon Glass
2015-07-17 23:57   ` Simon Glass
2015-06-23 21:38 ` [U-Boot] [PATCH v3 29/54] dm: mmc: Allow driver model to be used for MMC in SPL Simon Glass
2015-07-17 23:57   ` Simon Glass
2015-06-23 21:38 ` [U-Boot] [PATCH v3 30/54] mmc: Add structure comments for dwmmc Simon Glass
2015-07-17 23:57   ` Simon Glass
2015-06-23 21:38 ` [U-Boot] [PATCH v3 31/54] mmc: Support bypass mode with the get_mmc_clk() method Simon Glass
2015-06-24  1:50   ` Chen-Yu Tsai
2015-06-25  1:58   ` Jaehoon Chung
2015-06-23 21:38 ` [U-Boot] [PATCH v3 32/54] mmc: Calculate dwmmc FIFO threshold size if not provided Simon Glass
2015-06-25  1:58   ` Jaehoon Chung
2015-06-25 19:26     ` Simon Glass
2015-06-26  4:49       ` Jaehoon Chung
2015-06-23 21:38 ` [U-Boot] [PATCH v3 33/54] dm: Add basic support for pin multiplexing (pinctrl) Simon Glass
2015-06-23 21:38 ` [U-Boot] [PATCH v3 34/54] dm: power: Avoid case-insensitve match for child names Simon Glass
2015-07-01  9:44   ` Przemyslaw Marczak
2015-07-17 23:57     ` Simon Glass
2015-06-23 21:38 ` [U-Boot] [PATCH v3 35/54] dm: power: Add regulator flags to centralise auto-set logic Simon Glass
2015-07-01  9:44   ` Przemyslaw Marczak
2015-07-17 23:57     ` Simon Glass
2015-06-23 21:38 ` [U-Boot] [PATCH v3 36/54] dm: pmic: Split output from function Simon Glass
2015-07-01  9:44   ` Przemyslaw Marczak [this message]
2015-07-17 23:57     ` Simon Glass
2015-06-23 21:38 ` [U-Boot] [PATCH v3 37/54] dm: power: Add a function to set up all regulators Simon Glass
2015-07-01  9:44   ` Przemyslaw Marczak
2015-07-17 23:57     ` Simon Glass
2015-06-23 21:39 ` [U-Boot] [PATCH v3 38/54] dm: power: Use debug() for errors in regulator uclass Simon Glass
2015-07-01  9:44   ` Przemyslaw Marczak
2015-07-17 23:57     ` Simon Glass
2015-06-23 21:39 ` [U-Boot] [PATCH v3 39/54] dm: pmic: Add functions to adjust PMIC registers Simon Glass
2015-07-01  9:44   ` Przemyslaw Marczak
2015-07-17 23:57     ` Simon Glass
2015-06-23 21:39 ` [U-Boot] [PATCH v3 40/54] dm: power: Allow use of regulators in SPL Simon Glass
2015-07-17 23:57   ` Simon Glass
2015-06-23 21:39 ` [U-Boot] [PATCH v3 41/54] Drop CONFIG_ERRNO_STR from SPL Simon Glass
2015-07-17 23:57   ` Simon Glass
2015-06-23 21:39 ` [U-Boot] [PATCH v3 42/54] dm: Add support for RAM drivers Simon Glass
2015-07-17 23:57   ` Simon Glass
2015-06-23 21:39 ` [U-Boot] [PATCH v3 43/54] dm: spi: Make local functions static Simon Glass
2015-07-17 23:57   ` Simon Glass
2015-06-23 21:39 ` [U-Boot] [PATCH v3 44/54] ns16550: Improve debug UART so it can work with 32-bit access Simon Glass
2015-07-17 23:57   ` Simon Glass
2015-06-23 21:39 ` [U-Boot] [PATCH v3 45/54] Add rivest cipher 4 (rc4) implementation Simon Glass
2015-07-17 23:57   ` Simon Glass
2015-06-23 21:39 ` [U-Boot] [PATCH v3 46/54] lib: Add function to extract a number from the end of a string Simon Glass
2015-07-17 23:58   ` Simon Glass
2015-06-23 21:39 ` [U-Boot] [PATCH v3 47/54] fdt: Provide debug info when a device tree cannot be found Simon Glass
2015-07-17 23:58   ` Simon Glass
2015-06-23 21:39 ` [U-Boot] [PATCH v3 48/54] dm: spl: Allow device tree/driver model in board_init_f() Simon Glass
2015-07-17 23:58   ` Simon Glass
2015-06-23 21:39 ` [U-Boot] [PATCH v3 49/54] spl: Add a debug string before the jump to U-Boot Simon Glass
2015-07-17 23:58   ` Simon Glass
2015-06-23 21:39 ` [U-Boot] [PATCH v3 50/54] mkimage: Set up a file size parameter and keep it updated Simon Glass
2015-06-25 22:51   ` Joe Hershberger
2015-07-17 23:58     ` Simon Glass
2015-08-10 23:43       ` Marek Vasut
2015-08-11  1:10         ` Marek Vasut
2015-06-23 21:39 ` [U-Boot] [PATCH v3 51/54] dm: Add a system reset uclass Simon Glass
2015-07-17 23:58   ` Simon Glass
2015-06-23 21:39 ` [U-Boot] [PATCH v3 52/54] zynq: Rename struct clk_ops to zynq_clk_ops Simon Glass
2015-07-17 23:58   ` Simon Glass
2015-06-23 21:39 ` [U-Boot] [PATCH v3 53/54] dm: Add a clock uclass Simon Glass
2015-07-17 23:58   ` Simon Glass
2015-06-23 21:39 ` [U-Boot] [PATCH v3 54/54] power: pmic: Use trailing_strtol() instead of a local function Simon Glass
2015-07-01  9:44   ` Przemyslaw Marczak
2015-07-17 23:58     ` Simon Glass
2015-06-30 16:08 ` [U-Boot] [PATCH v3 00/54] dm: Introduce new driver model uclasses York Sun
2015-06-30 18:33   ` Simon Glass
2015-06-30 18:42     ` York Sun
2015-06-30 19:01       ` Tom Rini
2015-06-30 20:10         ` York Sun
2015-06-30 20:31           ` Tom Rini
2015-06-30 21:08             ` Simon Glass
2015-07-02  7:03               ` Jagan Teki
2015-07-09 20:31                 ` Jagan Teki
2015-07-09 21:10                   ` Simon Glass
2015-06-30 19:01       ` Jagan Teki
2015-07-03  3:28 ` Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5593B674.1010000@samsung.com \
    --to=p.marczak@samsung.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox