Re: [PATCH v4 4/5] regulator: max14577: Add regulator driver for Maxim 14577

2013-11-27 Thread Lee Jones
> MAX14577 chip is a multi-function device which includes MUIC,
> charger and voltage regulator. The driver is located in drivers/mfd.
> 
> This patch adds regulator driver for MAX14577 chip. There are two
> regulators in this chip:
> 1. Safeout LDO with constant voltage output of 4.9V. It can be only
>enabled or disabled.
> 2. Current regulator for the charger. It provides current from 90mA up
>to 950mA.
> Driver supports Device Tree.
> 
> Signed-off-by: Krzysztof Kozlowski 
> Signed-off-by: Kyungmin Park 
> ---
>  drivers/mfd/max14577.c   |3 +-
>  drivers/regulator/Kconfig|7 ++
>  drivers/regulator/Makefile   |1 +
>  drivers/regulator/max14577.c |  268 
> ++
>  4 files changed, 278 insertions(+), 1 deletion(-)
>  create mode 100644 drivers/regulator/max14577.c
> 
> diff --git a/drivers/mfd/max14577.c b/drivers/mfd/max14577.c
> index 94b766d..d841f2a 100644
> --- a/drivers/mfd/max14577.c
> +++ b/drivers/mfd/max14577.c
> @@ -26,7 +26,8 @@
>  
>  static struct mfd_cell max14577_devs[] = {
>   { .name = "max14577-muic", },
> - { .name = "max14577-regulator", },
> + { .name = "max14577-regulator",
> + .of_compatible = "maxim,max14577-regulator", },
>   { .name = "max14577-charger", },
>  };

If you separate this patch out and make it look 'normal' i.e. sort out
the indenting, I'll apply it. Instead of this randomness, I expect to
see something like: 

> +  {
> + .name = "max14577-regulator",
> + .of_compatible = "maxim,max14577-regulator", 
> +  },


-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v4 4/5] regulator: max14577: Add regulator driver for Maxim 14577

2013-11-27 Thread Lee Jones
 MAX14577 chip is a multi-function device which includes MUIC,
 charger and voltage regulator. The driver is located in drivers/mfd.
 
 This patch adds regulator driver for MAX14577 chip. There are two
 regulators in this chip:
 1. Safeout LDO with constant voltage output of 4.9V. It can be only
enabled or disabled.
 2. Current regulator for the charger. It provides current from 90mA up
to 950mA.
 Driver supports Device Tree.
 
 Signed-off-by: Krzysztof Kozlowski k.kozlow...@samsung.com
 Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
 ---
  drivers/mfd/max14577.c   |3 +-
  drivers/regulator/Kconfig|7 ++
  drivers/regulator/Makefile   |1 +
  drivers/regulator/max14577.c |  268 
 ++
  4 files changed, 278 insertions(+), 1 deletion(-)
  create mode 100644 drivers/regulator/max14577.c
 
 diff --git a/drivers/mfd/max14577.c b/drivers/mfd/max14577.c
 index 94b766d..d841f2a 100644
 --- a/drivers/mfd/max14577.c
 +++ b/drivers/mfd/max14577.c
 @@ -26,7 +26,8 @@
  
  static struct mfd_cell max14577_devs[] = {
   { .name = max14577-muic, },
 - { .name = max14577-regulator, },
 + { .name = max14577-regulator,
 + .of_compatible = maxim,max14577-regulator, },
   { .name = max14577-charger, },
  };

If you separate this patch out and make it look 'normal' i.e. sort out
the indenting, I'll apply it. Instead of this randomness, I expect to
see something like: 

 +  {
 + .name = max14577-regulator,
 + .of_compatible = maxim,max14577-regulator, 
 +  },


-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4 4/5] regulator: max14577: Add regulator driver for Maxim 14577

2013-11-22 Thread Krzysztof Kozlowski
MAX14577 chip is a multi-function device which includes MUIC,
charger and voltage regulator. The driver is located in drivers/mfd.

This patch adds regulator driver for MAX14577 chip. There are two
regulators in this chip:
1. Safeout LDO with constant voltage output of 4.9V. It can be only
   enabled or disabled.
2. Current regulator for the charger. It provides current from 90mA up
   to 950mA.
Driver supports Device Tree.

Signed-off-by: Krzysztof Kozlowski 
Signed-off-by: Kyungmin Park 
---
 drivers/mfd/max14577.c   |3 +-
 drivers/regulator/Kconfig|7 ++
 drivers/regulator/Makefile   |1 +
 drivers/regulator/max14577.c |  268 ++
 4 files changed, 278 insertions(+), 1 deletion(-)
 create mode 100644 drivers/regulator/max14577.c

diff --git a/drivers/mfd/max14577.c b/drivers/mfd/max14577.c
index 94b766d..d841f2a 100644
--- a/drivers/mfd/max14577.c
+++ b/drivers/mfd/max14577.c
@@ -26,7 +26,8 @@
 
 static struct mfd_cell max14577_devs[] = {
{ .name = "max14577-muic", },
-   { .name = "max14577-regulator", },
+   { .name = "max14577-regulator",
+   .of_compatible = "maxim,max14577-regulator", },
{ .name = "max14577-charger", },
 };
 
diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index ce785f4..11ee053 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -249,6 +249,13 @@ config REGULATOR_LP8788
help
  This driver supports LP8788 voltage regulator chip.
 
+config REGULATOR_MAX14577
+   tristate "Maxim 14577 regulator"
+   depends on MFD_MAX14577
+   help
+ This driver controls a Maxim 14577 regulator via I2C bus.
+ The regulators include safeout LDO and current regulator 'CHARGER'.
+
 config REGULATOR_MAX1586
tristate "Maxim 1586/1587 voltage regulator"
depends on I2C
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index 01c597e..654bd43 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -35,6 +35,7 @@ obj-$(CONFIG_REGULATOR_LP872X) += lp872x.o
 obj-$(CONFIG_REGULATOR_LP8788) += lp8788-buck.o
 obj-$(CONFIG_REGULATOR_LP8788) += lp8788-ldo.o
 obj-$(CONFIG_REGULATOR_LP8755) += lp8755.o
+obj-$(CONFIG_REGULATOR_MAX14577) += max14577.o
 obj-$(CONFIG_REGULATOR_MAX1586) += max1586.o
 obj-$(CONFIG_REGULATOR_MAX8649)+= max8649.o
 obj-$(CONFIG_REGULATOR_MAX8660) += max8660.o
diff --git a/drivers/regulator/max14577.c b/drivers/regulator/max14577.c
new file mode 100644
index 000..7126b96
--- /dev/null
+++ b/drivers/regulator/max14577.c
@@ -0,0 +1,268 @@
+/*
+ * max14577.c - Regulator driver for the Maxim 14577
+ *
+ * Copyright (C) 2013 Samsung Electronics
+ * Krzysztof Kozlowski 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct max14577_regulator {
+   struct device *dev;
+   struct max14577 *max14577;
+   struct regulator_dev **regulators;
+};
+
+static int max14577_reg_is_enabled(struct regulator_dev *rdev)
+{
+   int rid = rdev_get_id(rdev);
+   struct regmap *rmap = rdev->regmap;
+   u8 reg_data;
+
+   switch (rid) {
+   case MAX14577_CHARGER:
+   max14577_read_reg(rmap, MAX14577_CHG_REG_CHG_CTRL2, _data);
+   if ((reg_data & CHGCTRL2_MBCHOSTEN_MASK) == 0)
+   return 0;
+   max14577_read_reg(rmap, MAX14577_CHG_REG_STATUS3, _data);
+   if ((reg_data & STATUS3_CGMBC_MASK) == 0)
+   return 0;
+   /* MBCHOSTEN and CGMBC are on */
+   return 1;
+   default:
+   return -EINVAL;
+   }
+}
+
+static int max14577_reg_get_current_limit(struct regulator_dev *rdev)
+{
+   u8 reg_data;
+   struct regmap *rmap = rdev->regmap;
+
+   if (rdev_get_id(rdev) != MAX14577_CHARGER)
+   return -EINVAL;
+
+   max14577_read_reg(rmap, MAX14577_CHG_REG_CHG_CTRL4, _data);
+
+   if ((reg_data & CHGCTRL4_MBCICHWRCL_MASK) == 0)
+   return MAX14577_REGULATOR_CURRENT_LIMIT_MIN;
+
+   reg_data = ((reg_data & CHGCTRL4_MBCICHWRCH_MASK) >>
+   CHGCTRL4_MBCICHWRCH_SHIFT);
+   return MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_START +
+   reg_data * MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_STEP;
+}
+
+static int max14577_reg_set_current_limit(struct regulator_dev *rdev,
+   int min_uA, int max_uA)
+{
+   int i, 

[PATCH v4 4/5] regulator: max14577: Add regulator driver for Maxim 14577

2013-11-22 Thread Krzysztof Kozlowski
MAX14577 chip is a multi-function device which includes MUIC,
charger and voltage regulator. The driver is located in drivers/mfd.

This patch adds regulator driver for MAX14577 chip. There are two
regulators in this chip:
1. Safeout LDO with constant voltage output of 4.9V. It can be only
   enabled or disabled.
2. Current regulator for the charger. It provides current from 90mA up
   to 950mA.
Driver supports Device Tree.

Signed-off-by: Krzysztof Kozlowski k.kozlow...@samsung.com
Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
---
 drivers/mfd/max14577.c   |3 +-
 drivers/regulator/Kconfig|7 ++
 drivers/regulator/Makefile   |1 +
 drivers/regulator/max14577.c |  268 ++
 4 files changed, 278 insertions(+), 1 deletion(-)
 create mode 100644 drivers/regulator/max14577.c

diff --git a/drivers/mfd/max14577.c b/drivers/mfd/max14577.c
index 94b766d..d841f2a 100644
--- a/drivers/mfd/max14577.c
+++ b/drivers/mfd/max14577.c
@@ -26,7 +26,8 @@
 
 static struct mfd_cell max14577_devs[] = {
{ .name = max14577-muic, },
-   { .name = max14577-regulator, },
+   { .name = max14577-regulator,
+   .of_compatible = maxim,max14577-regulator, },
{ .name = max14577-charger, },
 };
 
diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index ce785f4..11ee053 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -249,6 +249,13 @@ config REGULATOR_LP8788
help
  This driver supports LP8788 voltage regulator chip.
 
+config REGULATOR_MAX14577
+   tristate Maxim 14577 regulator
+   depends on MFD_MAX14577
+   help
+ This driver controls a Maxim 14577 regulator via I2C bus.
+ The regulators include safeout LDO and current regulator 'CHARGER'.
+
 config REGULATOR_MAX1586
tristate Maxim 1586/1587 voltage regulator
depends on I2C
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index 01c597e..654bd43 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -35,6 +35,7 @@ obj-$(CONFIG_REGULATOR_LP872X) += lp872x.o
 obj-$(CONFIG_REGULATOR_LP8788) += lp8788-buck.o
 obj-$(CONFIG_REGULATOR_LP8788) += lp8788-ldo.o
 obj-$(CONFIG_REGULATOR_LP8755) += lp8755.o
+obj-$(CONFIG_REGULATOR_MAX14577) += max14577.o
 obj-$(CONFIG_REGULATOR_MAX1586) += max1586.o
 obj-$(CONFIG_REGULATOR_MAX8649)+= max8649.o
 obj-$(CONFIG_REGULATOR_MAX8660) += max8660.o
diff --git a/drivers/regulator/max14577.c b/drivers/regulator/max14577.c
new file mode 100644
index 000..7126b96
--- /dev/null
+++ b/drivers/regulator/max14577.c
@@ -0,0 +1,268 @@
+/*
+ * max14577.c - Regulator driver for the Maxim 14577
+ *
+ * Copyright (C) 2013 Samsung Electronics
+ * Krzysztof Kozlowski k.kozlow...@samsung.com
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include linux/module.h
+#include linux/platform_device.h
+#include linux/regulator/driver.h
+#include linux/mfd/max14577.h
+#include linux/mfd/max14577-private.h
+#include linux/regulator/of_regulator.h
+
+struct max14577_regulator {
+   struct device *dev;
+   struct max14577 *max14577;
+   struct regulator_dev **regulators;
+};
+
+static int max14577_reg_is_enabled(struct regulator_dev *rdev)
+{
+   int rid = rdev_get_id(rdev);
+   struct regmap *rmap = rdev-regmap;
+   u8 reg_data;
+
+   switch (rid) {
+   case MAX14577_CHARGER:
+   max14577_read_reg(rmap, MAX14577_CHG_REG_CHG_CTRL2, reg_data);
+   if ((reg_data  CHGCTRL2_MBCHOSTEN_MASK) == 0)
+   return 0;
+   max14577_read_reg(rmap, MAX14577_CHG_REG_STATUS3, reg_data);
+   if ((reg_data  STATUS3_CGMBC_MASK) == 0)
+   return 0;
+   /* MBCHOSTEN and CGMBC are on */
+   return 1;
+   default:
+   return -EINVAL;
+   }
+}
+
+static int max14577_reg_get_current_limit(struct regulator_dev *rdev)
+{
+   u8 reg_data;
+   struct regmap *rmap = rdev-regmap;
+
+   if (rdev_get_id(rdev) != MAX14577_CHARGER)
+   return -EINVAL;
+
+   max14577_read_reg(rmap, MAX14577_CHG_REG_CHG_CTRL4, reg_data);
+
+   if ((reg_data  CHGCTRL4_MBCICHWRCL_MASK) == 0)
+   return MAX14577_REGULATOR_CURRENT_LIMIT_MIN;
+
+   reg_data = ((reg_data  CHGCTRL4_MBCICHWRCH_MASK) 
+   CHGCTRL4_MBCICHWRCH_SHIFT);
+   return MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_START +
+