Re: [U-Boot] [PATCH v3 08/17] dm: regulator: add regulator command

2015-04-03 Thread Przemyslaw Marczak

Hello Simon,

On 03/29/2015 03:07 PM, Simon Glass wrote:

Hi Przemyslaw,

On 24 March 2015 at 14:30, Przemyslaw Marczak p.marc...@samsung.com wrote:

This command is based on driver model regulator api.
User interface features:
- list   - list UCLASS regulator devices
- regulator dev [id] - show or [set] operating regulator device
- regulator [info]   - print constraints info
- regulator [status] - print operating status
- regulator [value] [-f] - print/[set] voltage value [uV] (force)
- regulator [current]- print/[set] current value [uA]
- regulator [mode_id]- print/[set] operating mode id
- regulator [enable] - enable the regulator output
- regulator [disable]- disable the regulator output

The 'force' option can be used for setting the value which exceeds the limits,
which are found in device-tree and are keept in regulators info structure.

Signed-off-by: Przemyslaw Marczak p.marc...@samsung.com

---
Changes v3:
- new file
- Kconfig entry
---
  common/Kconfig |  22 +++
  common/Makefile|   1 +
  common/cmd_regulator.c | 385 +
  3 files changed, 408 insertions(+)
  create mode 100644 common/cmd_regulator.c

diff --git a/common/Kconfig b/common/Kconfig
index 1125e6d..48f360f 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -348,5 +348,27 @@ config DM_PMIC_CMD
   - pmic read address  - read byte of register at address
   - pmic write address - write byte to register at address
   The only one change for this command is 'dev' subcommand.
+
+config DM_REGULATOR_CMD


CMD_DM_REGULATOR



Ok


+   bool Enable Driver Model REGULATOR command
+   depends on DM_REGULATOR
+   help
+ This command is based on driver model regulator api.
+ User interface features:
+ - list   - list UCLASS regulator devices


Do you need 'UCLASS in there? What does it mean?



Right, it has no sense...


+ - regulator dev [id] - show or [set] operating regulator device
+ - regulator [info]   - print constraints info
+ - regulator [status] - print operating status
+ - regulator [value] [-f] - print/[set] voltage value [uV] (force)
+ - regulator [current]- print/[set] current value [uA]
+ - regulator [mode_id]- print/[set] operating mode id
+ - regulator [enable] - enable the regulator output
+ - regulator [disable]- disable the regulator output


I don't think the sub-commands should be in [].



Right, will fix it.


+
+ The 'force' option can be used for setting the value which exceeds
+ the limit which are found in device-tree and are keept in regulators
+ info structure.
+
  endmenu
+
  endmenu
diff --git a/common/Makefile b/common/Makefile
index d908851..d63fe12 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -211,6 +211,7 @@ obj-$(CONFIG_CMD_GPT) += cmd_gpt.o

  # Power
  obj-$(CONFIG_DM_PMIC_CMD) += cmd_pmic.o
+obj-$(CONFIG_DM_REGULATOR_CMD) += cmd_regulator.o
  endif

  ifdef CONFIG_SPL_BUILD
diff --git a/common/cmd_regulator.c b/common/cmd_regulator.c
new file mode 100644
index 000..d388b14
--- /dev/null
+++ b/common/cmd_regulator.c
@@ -0,0 +1,385 @@
+/*
+ * Copyright (C) 2014-2015 Samsung Electronics
+ * Przemyslaw Marczak p.marc...@samsung.com
+ *
+ * SPDX-License-Identifier:GPL-2.0+
+ */
+#include common.h
+#include linux/types.h
+#include linux/ctype.h
+#include fdtdec.h
+#include dm.h
+#include power/pmic.h
+#include power/regulator.h
+#include dm/device-internal.h
+#include dm/uclass-internal.h
+#include dm/root.h
+#include dm/lists.h
+#include i2c.h
+#include compiler.h
+#include errno.h
+
+#define LIMIT_SEQ  3
+#define LIMIT_DEVNAME  20
+#define LIMIT_OFNAME   20
+#define LIMIT_INFO 12
+
+static struct udevice *reg_curr;
+
+static int failed(const char *getset, const char *thing,
+ const char *for_dev, int ret)
+{
+   printf(Can't %s %s %s.\nError: %d (%s)\n, getset, thing, for_dev,
+   ret, errno_str(ret));
+   return CMD_RET_FAILURE;
+}
+
+static int do_dev(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+   struct dm_regulator_info *info;
+   int seq, ret = CMD_RET_FAILURE;
+
+   switch (argc) {
+   case 2:
+   seq = simple_strtoul(argv[1], NULL, 0);
+   uclass_get_device_by_seq(UCLASS_REGULATOR, seq, reg_curr);


This can return an error.



Yes, but there is no case break, and the below regulator_info(), checks 
if reg_curr isn't NULL, and here the ret is returned.



+   case 1:
+   ret = regulator_info(reg_curr, info);
+   if (ret)
+   return failed(get, the, device, ret);
+
+   printf(dev: %d @ %s\n, reg_curr-seq, info-name);
+   }
+
+   return CMD_RET_SUCCESS;
+}
+
+static int 

Re: [U-Boot] [PATCH v3 08/17] dm: regulator: add regulator command

2015-03-29 Thread Simon Glass
Hi Przemyslaw,

On 24 March 2015 at 14:30, Przemyslaw Marczak p.marc...@samsung.com wrote:
 This command is based on driver model regulator api.
 User interface features:
 - list   - list UCLASS regulator devices
 - regulator dev [id] - show or [set] operating regulator device
 - regulator [info]   - print constraints info
 - regulator [status] - print operating status
 - regulator [value] [-f] - print/[set] voltage value [uV] (force)
 - regulator [current]- print/[set] current value [uA]
 - regulator [mode_id]- print/[set] operating mode id
 - regulator [enable] - enable the regulator output
 - regulator [disable]- disable the regulator output

 The 'force' option can be used for setting the value which exceeds the limits,
 which are found in device-tree and are keept in regulators info structure.

 Signed-off-by: Przemyslaw Marczak p.marc...@samsung.com

 ---
 Changes v3:
 - new file
 - Kconfig entry
 ---
  common/Kconfig |  22 +++
  common/Makefile|   1 +
  common/cmd_regulator.c | 385 
 +
  3 files changed, 408 insertions(+)
  create mode 100644 common/cmd_regulator.c

 diff --git a/common/Kconfig b/common/Kconfig
 index 1125e6d..48f360f 100644
 --- a/common/Kconfig
 +++ b/common/Kconfig
 @@ -348,5 +348,27 @@ config DM_PMIC_CMD
   - pmic read address  - read byte of register at address
   - pmic write address - write byte to register at address
   The only one change for this command is 'dev' subcommand.
 +
 +config DM_REGULATOR_CMD

CMD_DM_REGULATOR

 +   bool Enable Driver Model REGULATOR command
 +   depends on DM_REGULATOR
 +   help
 + This command is based on driver model regulator api.
 + User interface features:
 + - list   - list UCLASS regulator devices

Do you need 'UCLASS in there? What does it mean?

 + - regulator dev [id] - show or [set] operating regulator device
 + - regulator [info]   - print constraints info
 + - regulator [status] - print operating status
 + - regulator [value] [-f] - print/[set] voltage value [uV] (force)
 + - regulator [current]- print/[set] current value [uA]
 + - regulator [mode_id]- print/[set] operating mode id
 + - regulator [enable] - enable the regulator output
 + - regulator [disable]- disable the regulator output

I don't think the sub-commands should be in [].

 +
 + The 'force' option can be used for setting the value which exceeds
 + the limit which are found in device-tree and are keept in regulators
 + info structure.
 +
  endmenu
 +
  endmenu
 diff --git a/common/Makefile b/common/Makefile
 index d908851..d63fe12 100644
 --- a/common/Makefile
 +++ b/common/Makefile
 @@ -211,6 +211,7 @@ obj-$(CONFIG_CMD_GPT) += cmd_gpt.o

  # Power
  obj-$(CONFIG_DM_PMIC_CMD) += cmd_pmic.o
 +obj-$(CONFIG_DM_REGULATOR_CMD) += cmd_regulator.o
  endif

  ifdef CONFIG_SPL_BUILD
 diff --git a/common/cmd_regulator.c b/common/cmd_regulator.c
 new file mode 100644
 index 000..d388b14
 --- /dev/null
 +++ b/common/cmd_regulator.c
 @@ -0,0 +1,385 @@
 +/*
 + * Copyright (C) 2014-2015 Samsung Electronics
 + * Przemyslaw Marczak p.marc...@samsung.com
 + *
 + * SPDX-License-Identifier:GPL-2.0+
 + */
 +#include common.h
 +#include linux/types.h
 +#include linux/ctype.h
 +#include fdtdec.h
 +#include dm.h
 +#include power/pmic.h
 +#include power/regulator.h
 +#include dm/device-internal.h
 +#include dm/uclass-internal.h
 +#include dm/root.h
 +#include dm/lists.h
 +#include i2c.h
 +#include compiler.h
 +#include errno.h
 +
 +#define LIMIT_SEQ  3
 +#define LIMIT_DEVNAME  20
 +#define LIMIT_OFNAME   20
 +#define LIMIT_INFO 12
 +
 +static struct udevice *reg_curr;
 +
 +static int failed(const char *getset, const char *thing,
 + const char *for_dev, int ret)
 +{
 +   printf(Can't %s %s %s.\nError: %d (%s)\n, getset, thing, for_dev,
 +   ret, errno_str(ret));
 +   return CMD_RET_FAILURE;
 +}
 +
 +static int do_dev(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 +{
 +   struct dm_regulator_info *info;
 +   int seq, ret = CMD_RET_FAILURE;
 +
 +   switch (argc) {
 +   case 2:
 +   seq = simple_strtoul(argv[1], NULL, 0);
 +   uclass_get_device_by_seq(UCLASS_REGULATOR, seq, reg_curr);

This can return an error.

 +   case 1:
 +   ret = regulator_info(reg_curr, info);
 +   if (ret)
 +   return failed(get, the, device, ret);
 +
 +   printf(dev: %d @ %s\n, reg_curr-seq, info-name);
 +   }
 +
 +   return CMD_RET_SUCCESS;
 +}
 +
 +static int get_curr_dev_and_info(struct udevice **devp,
 +struct dm_regulator_info **infop)
 +{
 +   int ret = -ENODEV;
 +
 +   *devp 

[U-Boot] [PATCH v3 08/17] dm: regulator: add regulator command

2015-03-24 Thread Przemyslaw Marczak
This command is based on driver model regulator api.
User interface features:
- list   - list UCLASS regulator devices
- regulator dev [id] - show or [set] operating regulator device
- regulator [info]   - print constraints info
- regulator [status] - print operating status
- regulator [value] [-f] - print/[set] voltage value [uV] (force)
- regulator [current]- print/[set] current value [uA]
- regulator [mode_id]- print/[set] operating mode id
- regulator [enable] - enable the regulator output
- regulator [disable]- disable the regulator output

The 'force' option can be used for setting the value which exceeds the limits,
which are found in device-tree and are keept in regulators info structure.

Signed-off-by: Przemyslaw Marczak p.marc...@samsung.com

---
Changes v3:
- new file
- Kconfig entry
---
 common/Kconfig |  22 +++
 common/Makefile|   1 +
 common/cmd_regulator.c | 385 +
 3 files changed, 408 insertions(+)
 create mode 100644 common/cmd_regulator.c

diff --git a/common/Kconfig b/common/Kconfig
index 1125e6d..48f360f 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -348,5 +348,27 @@ config DM_PMIC_CMD
  - pmic read address  - read byte of register at address
  - pmic write address - write byte to register at address
  The only one change for this command is 'dev' subcommand.
+
+config DM_REGULATOR_CMD
+   bool Enable Driver Model REGULATOR command
+   depends on DM_REGULATOR
+   help
+ This command is based on driver model regulator api.
+ User interface features:
+ - list   - list UCLASS regulator devices
+ - regulator dev [id] - show or [set] operating regulator device
+ - regulator [info]   - print constraints info
+ - regulator [status] - print operating status
+ - regulator [value] [-f] - print/[set] voltage value [uV] (force)
+ - regulator [current]- print/[set] current value [uA]
+ - regulator [mode_id]- print/[set] operating mode id
+ - regulator [enable] - enable the regulator output
+ - regulator [disable]- disable the regulator output
+
+ The 'force' option can be used for setting the value which exceeds
+ the limit which are found in device-tree and are keept in regulators
+ info structure.
+
 endmenu
+
 endmenu
diff --git a/common/Makefile b/common/Makefile
index d908851..d63fe12 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -211,6 +211,7 @@ obj-$(CONFIG_CMD_GPT) += cmd_gpt.o
 
 # Power
 obj-$(CONFIG_DM_PMIC_CMD) += cmd_pmic.o
+obj-$(CONFIG_DM_REGULATOR_CMD) += cmd_regulator.o
 endif
 
 ifdef CONFIG_SPL_BUILD
diff --git a/common/cmd_regulator.c b/common/cmd_regulator.c
new file mode 100644
index 000..d388b14
--- /dev/null
+++ b/common/cmd_regulator.c
@@ -0,0 +1,385 @@
+/*
+ * Copyright (C) 2014-2015 Samsung Electronics
+ * Przemyslaw Marczak p.marc...@samsung.com
+ *
+ * SPDX-License-Identifier:GPL-2.0+
+ */
+#include common.h
+#include linux/types.h
+#include linux/ctype.h
+#include fdtdec.h
+#include dm.h
+#include power/pmic.h
+#include power/regulator.h
+#include dm/device-internal.h
+#include dm/uclass-internal.h
+#include dm/root.h
+#include dm/lists.h
+#include i2c.h
+#include compiler.h
+#include errno.h
+
+#define LIMIT_SEQ  3
+#define LIMIT_DEVNAME  20
+#define LIMIT_OFNAME   20
+#define LIMIT_INFO 12
+
+static struct udevice *reg_curr;
+
+static int failed(const char *getset, const char *thing,
+ const char *for_dev, int ret)
+{
+   printf(Can't %s %s %s.\nError: %d (%s)\n, getset, thing, for_dev,
+   ret, errno_str(ret));
+   return CMD_RET_FAILURE;
+}
+
+static int do_dev(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+   struct dm_regulator_info *info;
+   int seq, ret = CMD_RET_FAILURE;
+
+   switch (argc) {
+   case 2:
+   seq = simple_strtoul(argv[1], NULL, 0);
+   uclass_get_device_by_seq(UCLASS_REGULATOR, seq, reg_curr);
+   case 1:
+   ret = regulator_info(reg_curr, info);
+   if (ret)
+   return failed(get, the, device, ret);
+
+   printf(dev: %d @ %s\n, reg_curr-seq, info-name);
+   }
+
+   return CMD_RET_SUCCESS;
+}
+
+static int get_curr_dev_and_info(struct udevice **devp,
+struct dm_regulator_info **infop)
+{
+   int ret = -ENODEV;
+
+   *devp = reg_curr;
+   if (!*devp)
+   return failed(get, current, device, ret);
+
+   ret = regulator_info(*devp, infop);
+   if (ret)
+   return failed(get, reg_curr-name, info, ret);
+
+   return CMD_RET_SUCCESS;
+}
+
+static int do_list(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+   struct dm_regulator_info