[PATCH v6 19/23] regulator: Add driver for Maxim 77802 PMIC regulators

2014-07-04 Thread Javier Martinez Canillas
The MAX77802 PMIC has 10 high-efficiency Buck and 32 Low-dropout
(LDO) regulators. This patch adds support for all these regulators
found on the MAX77802 PMIC and is based on a driver added by Simon
Glass to the Chrome OS kernel 3.8 tree.

Signed-off-by: Javier Martinez Canillas 
Tested-by: Naveen Krishna Chatradhi 
---

Changes since v5:
 - Take out the mfd changes from v4 that were squashed by mistake.
   Suggested by Lee Jones.

Changes since v4: None

Changes since v3:
 - Set the supply_name for regulators to lookup their parent supply node.
   Suggested by Mark Brown.
 - Change Exyno5 for Exynos5420/Exynos5800 in regulator driver Kconfig.
   Suggested by Doug Anderson.
---
 drivers/regulator/Kconfig|   9 +
 drivers/regulator/Makefile   |   1 +
 drivers/regulator/max77802.c | 609 +++
 3 files changed, 619 insertions(+)
 create mode 100644 drivers/regulator/max77802.c

diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index 789eb46..96d1c68 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -377,6 +377,15 @@ config REGULATOR_MAX77693
  and one current regulator 'CHARGER'. This is suitable for
  Exynos-4x12 chips.
 
+config REGULATOR_MAX77802
+   tristate "Maxim 77802 regulator"
+   depends on MFD_MAX77686
+   help
+ This driver controls a Maxim 77802 regulator
+ via I2C bus. The provided regulator is suitable for
+ Exynos5420/Exynos5800 SoCs to control various voltages.
+ It includes support for control of voltage and ramp speed.
+
 config REGULATOR_MC13XXX_CORE
tristate
 
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index d461110..2aea4b6 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -51,6 +51,7 @@ obj-$(CONFIG_REGULATOR_MAX8997) += max8997.o
 obj-$(CONFIG_REGULATOR_MAX8998) += max8998.o
 obj-$(CONFIG_REGULATOR_MAX77686) += max77686.o
 obj-$(CONFIG_REGULATOR_MAX77693) += max77693.o
+obj-$(CONFIG_REGULATOR_MAX77802) += max77802.o
 obj-$(CONFIG_REGULATOR_MC13783) += mc13783-regulator.o
 obj-$(CONFIG_REGULATOR_MC13892) += mc13892-regulator.o
 obj-$(CONFIG_REGULATOR_MC13XXX_CORE) +=  mc13xxx-regulator-core.o
diff --git a/drivers/regulator/max77802.c b/drivers/regulator/max77802.c
new file mode 100644
index 000..23b2488
--- /dev/null
+++ b/drivers/regulator/max77802.c
@@ -0,0 +1,609 @@
+/*
+ * max77802.c - Regulator driver for the Maxim 77802
+ *
+ * Copyright (C) 2013-2014 Google, Inc
+ * Simon Glass 
+ *
+ * Copyright (C) 2012 Samsung Electronics
+ * Chiwoong Byun 
+ * Jonghwa Lee 
+ *
+ * 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.
+ *
+ * This driver is based on max8997.c
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* Default ramp delay in case it is not manually set */
+#define MAX77802_RAMP_DELAY10  /* uV/us */
+
+#define MAX77802_OPMODE_SHIFT_LDO  6
+#define MAX77802_OPMODE_BUCK234_SHIFT  4
+#define MAX77802_OPMODE_MASK   0x3
+
+#define MAX77802_VSEL_MASK 0x3F
+#define MAX77802_DVS_VSEL_MASK 0xFF
+
+#define MAX77802_RAMP_RATE_MASK_2BIT   0xC0
+#define MAX77802_RAMP_RATE_SHIFT_2BIT  6
+#define MAX77802_RAMP_RATE_MASK_4BIT   0xF0
+#define MAX77802_RAMP_RATE_SHIFT_4BIT  4
+
+/* MAX77802 has two register formats: 2-bit and 4-bit */
+static const unsigned int ramp_table_77802_2bit[] = {
+   12500,
+   25000,
+   5,
+   10,
+};
+
+static unsigned int ramp_table_77802_4bit[] = {
+   1000,   2000,   3030,   4000,
+   5000,   5880,   7140,   8330,
+   9090,   1,  0,  12500,
+   16670,  25000,  5,  10,
+};
+
+struct max77802_regulator_prv {
+   int num_regulators;
+   struct regulator_dev *rdev[MAX77802_REG_MAX];
+   unsigned int opmode[MAX77802_REG_MAX];
+};
+
+static int max77802_get_opmode_shift(int id)
+{
+   if (id >= MAX77802_LDO1 && id <= MAX77802_LDO35)
+   return MAX77802_OPMODE_SHIFT_LDO;
+   else if (id == MAX77802_BUCK1 || (id >= MAX77802_BUCK5 &&
+ id <= MAX77802_BUCK10))
+   return 0;
+   else if (id >= MAX77802_BUCK2 && id <= MAX77802_BUCK4)
+   return MAX77802_OPMODE_BUCK234_SHIFT;
+   else
+   return -EINVAL;
+}
+
+/*
+ * Some BUCKS supports Normal[ON

[PATCH v6 18/23] mfd: max77802: Add DT binding documentation

2014-07-04 Thread Javier Martinez Canillas
Add Device Tree binding documentation for Maxim 77802 PMIC.

Signed-off-by: Javier Martinez Canillas 
---

Changes since v5:
 - Use max77686,* properties instead of max77802,* since the support is
   now in the max77686 driver and that IP defined the properties first.
 - Fix issues in DT binding documentation. Suggested by Andreas Farber.

Changes since v4: None

Changes since v3: None

Changes since v2:
 - Explain better the Dynamic Voltage Scaling (DVS) support in some Buck
   regulators and the max77802,pmic-buck-{dvs,selb}-gpios properties.
   Suggested by Mark Brown.
---
 Documentation/devicetree/bindings/mfd/max77802.txt | 95 ++
 1 file changed, 95 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/max77802.txt

diff --git a/Documentation/devicetree/bindings/mfd/max77802.txt 
b/Documentation/devicetree/bindings/mfd/max77802.txt
new file mode 100644
index 000..5460e20
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/max77802.txt
@@ -0,0 +1,95 @@
+Maxim MAX77802 multi-function device
+
+MAX77802 is a Multifunction device with PMIC, RTC and Charger on chip. It is
+interfaced to host controller using i2c interface. PMIC, Charger and RTC
+submodules are addressed using same i2c slave address.
+
+Buck regulators 1, 2, 3, 4 and 6 include Dynamic Voltage Scaling (DVS) that
+allows each output voltage to change dynamically. Each Buck output voltage
+is selected using a set of external inputs: DVS1-3 and SELB1, 2, 3, 4 and 6.
+
+There are 8 DVS registers that can be used to configure the output voltage
+for each Buck regulator and which one is active is controled by DVSx lines.
+
+SELBx lines are used to control if individual Buck lines are ON or OFF.
+
+This document describes the binding for mfd device and PMIC submodule.
+
+Binding for the built-in 32k clock generator block is defined separately
+in bindings/clk/maxim,max77802.txt file.
+
+Required properties:
+- compatible : Must be "maxim,max77802";
+- reg : Specifies the i2c slave address of PMIC block.
+- interrupts : This i2c device has an IRQ line connected to the main SoC.
+- interrupt-parent : The parent interrupt controller.
+
+Optional properties:
+- max77686,pmic-buck-default-dvs-idx: We'll always write this DVS index in the
+  PMIC for Bucks with DVS.
+  NOTE: at the moment these bindings don't include enough details for actual
+  GPIO-DVS--this just lets you choose which single slot to use.
+
+- max77686,pmic-buck-dvs-gpios: A GPIO array where each GPIO is connected to a
+  DVS line. We'll try to set these GPIOs to match pmic-buck-default-dvs-idx at
+  probe time if they are defined. If some or all of these GPIOs are not defined
+  it's assumed that the board has any missing GPIOs hardwired to match
+  pmic-buck-default-dvs-idx.
+
+- max77686,pmic-buck-selb-gpios: A GPIO array where each GPIO is connected to a
+  SELBx line. Should be five values: 1, 2, 3, 4, 6. It is strongly suggested to
+  include these GPIOs if there's any chance that changing DVS GPIOs one line at
+  a time might glitch your DVS values.
+
+Optional node:
+- regulators : The regulators of max77802 have to be instantiated
+  under subnode named "regulators" using the following format.
+
+   regulator-name {
+   standard regulator constraints
+   };
+   refer Documentation/devicetree/bindings/regulator/regulator.txt
+
+  The regulator node name should be initialized with a string
+to get matched with their hardware counterparts as follow. The valid names are:
+
+   -LDOn   :   for LDOs, where n can lie in range 1 to 35.
+   example: LDO1, LDO2, LDO35.
+   -BUCKn  :   for BUCKs, where n can lie in range 1 to 10.
+   example: BUCK1, BUCK5, BUCK10.
+Example:
+
+   max77802@09 {
+   compatible = "maxim,max77802";
+   interrupt-parent = <&wakeup_eint>;
+   interrupts = <26 0>;
+   reg = <0x09>;
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   max77686,pmic-buck-default-dvs-idx = <1>;
+   max77686,pmic-buck-dvs-gpios = <&gpy7 6 0>,
+  <&gpj4 2 0>,
+  <&gpj4 3 0>;
+   max77686,pmic-buck-selb-gpios = <&gph0 2 0>,
+   <&gph0 3 0>,
+   <&gph0 4 0>,
+   <&gph0 5 0>,
+   <&gph0 6 0>;
+
+   regulators {
+   ldo11_reg: LDO11 {
+   regulator-name = "vdd_ldo11";
+   regulator-min-microvolt = <190>;

[PATCH v6 20/23] clk: Add driver for Maxim 77802 PMIC clocks

2014-07-04 Thread Javier Martinez Canillas
The MAX77802 PMIC has two 32.768kHz Buffered Clock Outputs with
Low Jitter Mode. This patch adds support for these two clocks.

Signed-off-by: Javier Martinez Canillas 
Reviewed-by: Krzysztof Kozlowski 
---

Changes since v5: None

Changes since v4: None

Changes since v3: None

Changes since v2: None

Changes since v1:
 - Use module_platform_driver() instead of having init/exit functions.
   Suggested by Mark Brown.
 - Use the generic maxim clock driver to reduce code duplication with
   clk-max77686.c driver.
---
 drivers/clk/Kconfig|  7 +++
 drivers/clk/Makefile   |  1 +
 drivers/clk/clk-max77802.c | 98 ++
 include/dt-bindings/clock/maxim,max77802.h | 22 +++
 4 files changed, 128 insertions(+)
 create mode 100644 drivers/clk/clk-max77802.c
 create mode 100644 include/dt-bindings/clock/maxim,max77802.h

diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
index 3fd4270..8808f2a 100644
--- a/drivers/clk/Kconfig
+++ b/drivers/clk/Kconfig
@@ -42,6 +42,13 @@ config COMMON_CLK_MAX77686
---help---
  This driver supports Maxim 77686 crystal oscillator clock. 
 
+config COMMON_CLK_MAX77802
+   tristate "Clock driver for Maxim 77802 PMIC"
+   depends on MFD_MAX77686
+   select COMMON_CLK_MAX_GEN
+   ---help---
+ This driver supports Maxim 77802 crystal oscillator clock.
+
 config COMMON_CLK_SI5351
tristate "Clock driver for SiLabs 5351A/B/C"
depends on I2C
diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
index 6c1aff6..520ff76 100644
--- a/drivers/clk/Makefile
+++ b/drivers/clk/Makefile
@@ -20,6 +20,7 @@ obj-$(CONFIG_ARCH_HIGHBANK)   += clk-highbank.o
 obj-$(CONFIG_MACH_LOONGSON1)   += clk-ls1x.o
 obj-$(CONFIG_COMMON_CLK_MAX_GEN)   += clk-max-gen.o
 obj-$(CONFIG_COMMON_CLK_MAX77686)  += clk-max77686.o
+obj-$(CONFIG_COMMON_CLK_MAX77802)  += clk-max77802.o
 obj-$(CONFIG_ARCH_MOXART)  += clk-moxart.o
 obj-$(CONFIG_ARCH_NOMADIK) += clk-nomadik.o
 obj-$(CONFIG_ARCH_NSPIRE)  += clk-nspire.o
diff --git a/drivers/clk/clk-max77802.c b/drivers/clk/clk-max77802.c
new file mode 100644
index 000..8e480c5
--- /dev/null
+++ b/drivers/clk/clk-max77802.c
@@ -0,0 +1,98 @@
+/*
+ * clk-max77802.c - Clock driver for Maxim 77802
+ *
+ * Copyright (C) 2014 Google, Inc
+ *
+ * Copyright (C) 2012 Samsung Electornics
+ * Jonghwa Lee 
+ *
+ * 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.
+ *
+ * This driver is based on clk-max77686.c
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include "clk-max-gen.h"
+
+#define MAX77802_CLOCK_OPMODE_MASK 0x1
+#define MAX77802_CLOCK_LOW_JITTER_SHIFT 0x3
+
+static struct clk_init_data max77802_clks_init[MAX77802_CLKS_NUM] = {
+   [MAX77802_CLK_32K_AP] = {
+   .name = "32khz_ap",
+   .ops = &max_gen_clk_ops,
+   .flags = CLK_IS_ROOT,
+   },
+   [MAX77802_CLK_32K_CP] = {
+   .name = "32khz_cp",
+   .ops = &max_gen_clk_ops,
+   .flags = CLK_IS_ROOT,
+   },
+};
+
+static int max77802_clk_probe(struct platform_device *pdev)
+{
+   struct max77686_dev *iodev = dev_get_drvdata(pdev->dev.parent);
+   int ret;
+
+   ret = max_gen_clk_probe(pdev, iodev->regmap, MAX77802_REG_32KHZ,
+   max77802_clks_init, MAX77802_CLKS_NUM);
+
+   if (ret) {
+   dev_err(&pdev->dev, "generic probe failed %d\n", ret);
+   return ret;
+   }
+
+   /* Enable low-jitter mode on the 32khz clocks. */
+   ret = regmap_update_bits(iodev->regmap, MAX77802_REG_32KHZ,
+1 << MAX77802_CLOCK_LOW_JITTER_SHIFT,
+1 << MAX77802_CLOCK_LOW_JITTER_SHIFT);
+   if (ret < 0)
+   dev_err(&pdev->dev, "failed to enable low-jitter mode\n");
+
+   return ret;
+}
+
+static int max77802_clk_remove(struct platform_device *pdev)
+{
+   return max_gen_clk_remove(pdev, MAX77802_CLKS_NUM);
+}
+
+static const struct platform_device_id max77802_clk_id[] = {
+   { "max77802-clk", 0},
+   { },
+};
+MODULE_DEVICE_TABLE(platform, max77802_clk_id);
+
+static struct platform_driver max77802_clk_driver = {
+   .driver = {
+   

[PATCH v6 17/23] mfd: max77686: Add Maxim 77802 PMIC support

2014-07-04 Thread Javier Martinez Canillas
Maxim MAX77802 is a power management chip that contains 10 high
efficiency Buck regulators, 32 Low-dropout (LDO) regulators used
to power up application processors and peripherals, a 2-channel
32kHz clock outputs, a Real-Time-Clock (RTC) and a I2C interface
to program the individual regulators, clocks outputs and the RTC.

This patch adds support for MAX77802 to the MAX77686 driver and is
based on a driver added to the Chrome OS kernel 3.8 by Simon Glass.

Signed-off-by: Javier Martinez Canillas 
---

NOTE: I didn't carry previous {Review,Acked,Tested}-by tags since
this patch extending MAX77686 is quite different than the old one
adding a new mfd driver. So review and test is highly appreciated.

Changes since v5:
 - Extend the 77686 driver to support 77802 instead of adding a new driver.
   Suggested by Lee Jones.

Changes since v4:
 - Use consistent expressions when checking for NULL values.
   Suggested by Krzysztof Kozlowski.
 - Remove unused defines. Suggested by Krzysztof Kozlowski.
 - Explain why IRQ is disabled on suspend. Suggested by Krzysztof Kozlowski.

Changes since v3:
 - Remove unnecessary OOM error message since the mm subsystem already logs 
it.

Changes since v2:
 - Split the DT binding docs in a separate patch and improve the 
documentation.
   Suggested by Mark Brown.
 - Add all the devices in the MFD driver instead of doing in separate 
patches.
   Suggested by Mark Brown.

Changes since v1:
 - Convert max77{686,802} to regmap irq API and get rid of 
max77{686,802}-irq.c
   Suggested by Krzysztof Kozlowski.
 - Don't protect max77802 mfd_cells using Kconfig options since mfd core 
omits
   devices that don't match. Suggested by Lee Jones.
 - Change mfd driver to be tristate instead of boolean. Suggested by Mark 
Brown.
 - Change binding "voltage-regulators" property to "regulators" to be 
consistent
   with other PMIC drivers. Suggested by Mark Brown.
 - Use regulators node names instead of the deprecated 
"regulator-compatible"
   property. Suggested by Mark Brown.
 - Use the new descriptor-based GPIO interface instead of the deprecated
---
 drivers/mfd/Kconfig  |   6 +-
 drivers/mfd/max77686.c   | 187 ++-
 include/linux/mfd/max77686-private.h | 208 ++-
 include/linux/mfd/max77686.h |  60 +-
 4 files changed, 428 insertions(+), 33 deletions(-)

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 3010204..de5abf2 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -380,15 +380,15 @@ config MFD_MAX14577
  of the device.
 
 config MFD_MAX77686
-   bool "Maxim Semiconductor MAX77686 PMIC Support"
+   bool "Maxim Semiconductor MAX77686/802 PMIC Support"
depends on I2C=y
select MFD_CORE
select REGMAP_I2C
select REGMAP_IRQ
select IRQ_DOMAIN
help
- Say yes here to add support for Maxim Semiconductor MAX77686.
- This is a Power Management IC with RTC on chip.
+ Say yes here to add support for Maxim Semiconductor MAX77686 and
+ MAX77802 which are Power Management IC with an RTC on chip.
  This driver provides common support for accessing the device;
  additional drivers must be enabled in order to use the functionality
  of the device.
diff --git a/drivers/mfd/max77686.c b/drivers/mfd/max77686.c
index 648d564..c0db750 100644
--- a/drivers/mfd/max77686.c
+++ b/drivers/mfd/max77686.c
@@ -1,5 +1,5 @@
 /*
- * max77686.c - mfd core driver for the Maxim 77686
+ * max77686.c - mfd core driver for the Maxim 77686/802
  *
  * Copyright (C) 2012 Samsung Electronics
  * Chiwoong Byun 
@@ -45,6 +45,74 @@ static const struct mfd_cell max77686_devs[] = {
{ .name = "max77686-clk", },
 };
 
+static const struct mfd_cell max77802_devs[] = {
+   { .name = "max77802-pmic", },
+   { .name = "max77802-clk", },
+   { .name = "max77802-rtc", },
+};
+
+static bool max77802_pmic_is_accessible_reg(struct device *dev,
+   unsigned int reg)
+{
+   return (reg >= MAX77802_REG_DEVICE_ID && reg < MAX77802_REG_PMIC_END);
+}
+
+static bool max77802_rtc_is_accessible_reg(struct device *dev,
+  unsigned int reg)
+{
+   return (reg >= MAX77802_RTC_INT && reg < MAX77802_RTC_END);
+}
+
+static bool max77802_is_accessible_reg(struct device *dev, unsigned int reg)
+{
+   return (max77802_pmic_is_accessible_reg(dev, reg) ||
+   max77802_rtc_is_accessible_reg(dev, reg));
+}
+
+static bool max77802_pmic_is_precious_reg(struct device *dev, unsigned int reg)
+{
+   return (reg == MAX77802_REG_INTSRC || reg == MAX77802_REG_I

[PATCH v6 16/23] mfd: max77686: Add documentation for DVS bindings

2014-07-04 Thread Javier Martinez Canillas
The MAX77686 PMIC submodule has Dynamic Voltage Scaling (DVS)
support on some regulators. Now that the regulator driver has
bindings to configure it, these bindings have to be documented.

Signed-off-by: Javier Martinez Canillas 
---
 Documentation/devicetree/bindings/mfd/max77686.txt | 34 ++
 1 file changed, 34 insertions(+)

diff --git a/Documentation/devicetree/bindings/mfd/max77686.txt 
b/Documentation/devicetree/bindings/mfd/max77686.txt
index 678f3cf..daf1c07 100644
--- a/Documentation/devicetree/bindings/mfd/max77686.txt
+++ b/Documentation/devicetree/bindings/mfd/max77686.txt
@@ -10,12 +10,38 @@ PMIC submodule.
 Binding for the built-in 32k clock generator block is defined separately
 in bindings/clk/maxim,max77686.txt file.
 
+Buck regulators 2, 3 and 4 include Dynamic Voltage Scaling (DVS) that allows
+each output voltage to change dynamically. Each Buck output voltage is selected
+using a set of external inputs: DVS1-3 and SELB2, 3 and 4.
+
+There are 8 DVS registers that can be used to configure the output voltage
+for each Buck regulator and which one is active is controled by DVSx lines.
+
+SELBx lines are used to control if individual Buck lines are ON or OFF.
+
 Required properties:
 - compatible : Must be "maxim,max77686";
 - reg : Specifies the i2c slave address of PMIC block.
 - interrupts : This i2c device has an IRQ line connected to the main SoC.
 - interrupt-parent : The parent interrupt controller.
 
+Optional properties:
+- max77686,pmic-buck-default-dvs-idx: We'll always write this DVS index in the
+  PMIC for Bucks with DVS.
+  NOTE: at the moment these bindings don't include enough details for actual
+  GPIO-DVS--this just lets you choose which single slot to use.
+
+- max77686,pmic-buck-dvs-gpios: A GPIO array where each GPIO is connected to a
+  DVS line. We'll try to set these GPIOs to match pmic-buck-default-dvs-idx at
+  probe time if they are defined. If some or all of these GPIOs are not defined
+  it's assumed that the board has any missing GPIOs hardwired to match
+  pmic-buck-default-dvs-idx.
+
+- max77686,pmic-buck-selb-gpios: A GPIO array where each GPIO is connected to a
+  SELBx line. Should be three values: 2, 3 and 4. It is strongly suggested to
+  include these GPIOs if there's any chance that changing DVS GPIOs one line at
+  a time might glitch your DVS values.
+
 Optional node:
 - voltage-regulators : The regulators of max77686 have to be instantiated
   under subnode named "voltage-regulators" using the following format.
@@ -42,6 +68,14 @@ Example:
interrupts = <26 0>;
reg = <0x09>;
 
+   max77686,pmic-buck-default-dvs-idx = <1>;
+   max77686,pmic-buck-dvs-gpios = <&gpy7 6 0>,
+  <&gpj4 2 0>,
+  <&gpj4 3 0>;
+   max77686,pmic-buck-selb-gpios = <&gph0 1 0>,
+   <&gph0 2 0>,
+   <&gph0 3 0>,
+
voltage-regulators {
ldo11_reg {
regulator-compatible = "LDO11";
-- 
2.0.0.rc2

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v6 22/23] rtc: Add driver for Maxim 77802 PMIC Real-Time-Clock

2014-07-04 Thread Javier Martinez Canillas
The MAX7802 PMIC has a Real-Time-Clock (RTC) with two alarms.
This patch adds support for the RTC and is based on a driver
added by Simon Glass to the Chrome OS kernel 3.8 tree.

Signed-off-by: Javier Martinez Canillas 
---

Changes since v5: None

Changes since v4: None

Changes since v3: None
---
 drivers/rtc/Kconfig|  10 +
 drivers/rtc/Makefile   |   1 +
 drivers/rtc/rtc-max77802.c | 637 +
 3 files changed, 648 insertions(+)
 create mode 100644 drivers/rtc/rtc-max77802.c

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index a672dd1..243ac72 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -288,6 +288,16 @@ config RTC_DRV_MAX77686
  This driver can also be built as a module. If so, the module
  will be called rtc-max77686.
 
+config RTC_DRV_MAX77802
+   tristate "Maxim 77802 RTC"
+   depends on MFD_MAX77686
+   help
+ If you say yes here you will get support for the
+ RTC of Maxim MAX77802 PMIC.
+
+ This driver can also be built as a module. If so, the module
+ will be called rtc-max77802.
+
 config RTC_DRV_RS5C372
tristate "Ricoh R2025S/D, RS5C372A/B, RV5C386, RV5C387A"
help
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 70347d0..247de78 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -81,6 +81,7 @@ obj-$(CONFIG_RTC_DRV_MAX8998) += rtc-max8998.o
 obj-$(CONFIG_RTC_DRV_MAX8997)  += rtc-max8997.o
 obj-$(CONFIG_RTC_DRV_MAX6902)  += rtc-max6902.o
 obj-$(CONFIG_RTC_DRV_MAX77686) += rtc-max77686.o
+obj-$(CONFIG_RTC_DRV_MAX77802)  += rtc-max77802.o
 obj-$(CONFIG_RTC_DRV_MC13XXX)  += rtc-mc13xxx.o
 obj-$(CONFIG_RTC_DRV_MCP795)   += rtc-mcp795.o
 obj-$(CONFIG_RTC_DRV_MSM6242)  += rtc-msm6242.o
diff --git a/drivers/rtc/rtc-max77802.c b/drivers/rtc/rtc-max77802.c
new file mode 100644
index 000..2f4fc2e
--- /dev/null
+++ b/drivers/rtc/rtc-max77802.c
@@ -0,0 +1,637 @@
+/*
+ * RTC driver for Maxim MAX77802
+ *
+ * Copyright (C) 2013 Google, Inc
+ *
+ * Copyright (C) 2012 Samsung Electronics Co.Ltd
+ *
+ *  based on rtc-max8997.c
+ *
+ *  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.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* RTC Control Register */
+#define BCD_EN_SHIFT   0
+#define BCD_EN_MASK(1 << BCD_EN_SHIFT)
+#define MODEL24_SHIFT  1
+#define MODEL24_MASK   (1 << MODEL24_SHIFT)
+/* RTC Update Register1 */
+#define RTC_UDR_SHIFT  0
+#define RTC_UDR_MASK   (1 << RTC_UDR_SHIFT)
+#define RTC_RBUDR_SHIFT4
+#define RTC_RBUDR_MASK (1 << RTC_RBUDR_SHIFT)
+/* WTSR and SMPL Register */
+#define WTSRT_SHIFT0
+#define SMPLT_SHIFT2
+#define WTSR_EN_SHIFT  6
+#define SMPL_EN_SHIFT  7
+#define WTSRT_MASK (3 << WTSRT_SHIFT)
+#define SMPLT_MASK (3 << SMPLT_SHIFT)
+#define WTSR_EN_MASK   (1 << WTSR_EN_SHIFT)
+#define SMPL_EN_MASK   (1 << SMPL_EN_SHIFT)
+/* RTC Hour register */
+#define HOUR_PM_SHIFT  6
+#define HOUR_PM_MASK   (1 << HOUR_PM_SHIFT)
+/* RTC Alarm Enable */
+#define ALARM_ENABLE_SHIFT 7
+#define ALARM_ENABLE_MASK  (1 << ALARM_ENABLE_SHIFT)
+
+/* For the RTCAE1 register, we write this value to enable the alarm */
+#define ALARM_ENABLE_VALUE 0x77
+
+#define MAX77802_RTC_UPDATE_DELAY_US   200
+#undef MAX77802_RTC_WTSR_SMPL
+
+enum {
+   RTC_SEC = 0,
+   RTC_MIN,
+   RTC_HOUR,
+   RTC_WEEKDAY,
+   RTC_MONTH,
+   RTC_YEAR,
+   RTC_DATE,
+   RTC_NR_TIME
+};
+
+struct max77802_rtc_info {
+   struct device   *dev;
+   struct max77686_dev *max77802;
+   struct i2c_client   *rtc;
+   struct rtc_device   *rtc_dev;
+   struct mutexlock;
+
+   struct regmap   *regmap;
+
+   int virq;
+   int rtc_24hr_mode;
+};
+
+enum MAX77802_RTC_OP {
+   MAX77802_RTC_WRITE,
+   MAX77802_RTC_READ,
+};
+
+static inline int max77802_rtc_calculate_wday(u8 shifted)
+{
+   int counter = -1;
+
+   while (shifted) {
+   shifted >>= 1;
+   counter++;
+   }
+
+   return counter;
+}
+
+static void max77802_rtc_data_to_tm(u8 *data, struct rtc_time *tm,
+  int rtc_24hr_mode)
+{
+   tm->tm_sec = data[RTC_SEC] & 0xff;
+   tm->tm_min = data[RTC_MIN] &

[PATCH v6 23/23] ARM: dts: Add max77802 to exynos5420-peach-pit and exynos5800-peach-pi

2014-07-04 Thread Javier Martinez Canillas
Peach pit and pi boards uses a Maxim 77802 power management
IC to drive regulators and its Real Time Clock. This patch
adds support for this chip.

These are the device nodes and pinctrl configuration that
are present on the Peach pit DeviceTree source file in the
the Chrome OS kernel 3.8 tree.

Signed-off-by: Javier Martinez Canillas 
Tested-by: Naveen Krishna Chatradhi 
---

Changes since v5:
 - Fix style issues and a typo on peach pit and pi DTS.
   Suggested by Tushar Behera.

Changes since v4: None

Changes since v3:
 - Add support for Exynos5800 based Peach pi board. Suggested by Doug Anderson.
 - Model the actual regulators relationship instead of a simplistic model.
   Suggested by Mark Brown.

Changes since v2: None

Changes since v1:
 - Use "regulators" for child node instead of "voltage-regulators" to be
   consistent with other PMIC. Suggested by Mark Brown.
 - Use regulators node names instead of the deprecated "regulator-compatible"
   property. Suggested by Mark Brown.
---
 arch/arm/boot/dts/exynos5420-peach-pit.dts | 382 +
 arch/arm/boot/dts/exynos5800-peach-pi.dts  | 382 +
 2 files changed, 764 insertions(+)

diff --git a/arch/arm/boot/dts/exynos5420-peach-pit.dts 
b/arch/arm/boot/dts/exynos5420-peach-pit.dts
index b2f1237..99768d7 100644
--- a/arch/arm/boot/dts/exynos5420-peach-pit.dts
+++ b/arch/arm/boot/dts/exynos5420-peach-pit.dts
@@ -143,6 +143,350 @@
ddc = <&i2c_2>;
 };
 
+&hsi2c_4 {
+   status = "okay";
+   clock-frequency = <40>;
+
+   max77802-pmic@9 {
+   compatible = "maxim,max77802";
+   interrupt-parent = <&gpx3>;
+   interrupts = <1 0>;
+   pinctrl-names = "default";
+   pinctrl-0 = <&max77802_irq>, <&pmic_selb>,
+   <&pmic_dvs_1>, <&pmic_dvs_2>, <&pmic_dvs_3>;
+   wakeup-source;
+   reg = <0x9>;
+   #clock-cells = <1>;
+
+   /* Using idx 1 means warm reset will get good voltage */
+   max77686,pmic-buck-default-dvs-idx = <1>;
+   max77686,pmic-buck-dvs-gpios = <&gpy7 6 GPIO_ACTIVE_HIGH>,
+  <&gpj4 2 GPIO_ACTIVE_HIGH>,
+  <&gpj4 3 GPIO_ACTIVE_HIGH>;
+   max77686,pmic-buck-selb-gpios = <&gph0 2 GPIO_ACTIVE_HIGH>,
+   <&gph0 3 GPIO_ACTIVE_HIGH>,
+   <&gph0 4 GPIO_ACTIVE_HIGH>,
+   <&gph0 5 GPIO_ACTIVE_HIGH>,
+   <&gph0 6 GPIO_ACTIVE_HIGH>;
+
+   inb1-supply = <&tps65090_dcdc2>;
+   inb2-supply = <&tps65090_dcdc1>;
+   inb3-supply = <&tps65090_dcdc2>;
+   inb4-supply = <&tps65090_dcdc2>;
+   inb5-supply = <&tps65090_dcdc1>;
+   inb6-supply = <&tps65090_dcdc2>;
+   inb7-supply = <&tps65090_dcdc1>;
+   inb8-supply = <&tps65090_dcdc1>;
+   inb9-supply = <&tps65090_dcdc1>;
+   inb10-supply = <&tps65090_dcdc1>;
+
+   inl1-supply = <&buck5_reg>;
+   inl2-supply = <&buck7_reg>;
+   inl3-supply = <&buck9_reg>;
+   inl4-supply = <&buck9_reg>;
+   inl5-supply = <&buck9_reg>;
+   inl6-supply = <&tps65090_dcdc2>;
+   inl7-supply = <&buck9_reg>;
+   inl9-supply = <&tps65090_dcdc2>;
+   inl10-supply = <&buck7_reg>;
+
+   regulators {
+   buck1_reg: BUCK1 {
+   regulator-name = "vdd_mif";
+   regulator-min-microvolt = <80>;
+   regulator-max-microvolt = <130>;
+   regulator-always-on;
+   regulator-boot-on;
+   regulator-ramp-delay = <12500>;
+   };
+
+   buck2_reg: BUCK2 {
+   regulator-name = "vdd_arm_real";
+   regulator-min-microvolt = <80>;
+   regulator-max-microvolt = <150>;
+   regulator-always-on;
+   regulator-boot-on;
+  

[PATCH v6 15/23] regulator: max77686: Setup DVS-related GPIOs on probe

2014-07-04 Thread Javier Martinez Canillas
MAX77686 PMIC support Dyamic Voltage Scaling (DVS) on a set
of Buck regulators. A number of GPIO are connected to these
lines and are requested by the mfd driver. Setup the GPIO
pins from the regulator driver.

Signed-off-by: Javier Martinez Canillas 
---
 drivers/regulator/max77686.c | 34 ++
 1 file changed, 34 insertions(+)

diff --git a/drivers/regulator/max77686.c b/drivers/regulator/max77686.c
index ef1af2d..ecce77a 100644
--- a/drivers/regulator/max77686.c
+++ b/drivers/regulator/max77686.c
@@ -435,6 +435,12 @@ static int max77686_pmic_dt_parse_pdata(struct 
platform_device *pdev,
 }
 #endif /* CONFIG_OF */
 
+static inline bool max77686_is_dvs_buck(int id)
+{
+   /* BUCK 2,3 and 4 support DVS */
+   return (id >= MAX77686_BUCK2 && id <= MAX77686_BUCK4);
+}
+
 static int max77686_pmic_probe(struct platform_device *pdev)
 {
struct max77686_dev *iodev = dev_get_drvdata(pdev->dev.parent);
@@ -442,6 +448,9 @@ static int max77686_pmic_probe(struct platform_device *pdev)
struct max77686_data *max77686;
int i, ret = 0;
struct regulator_config config = { };
+   unsigned int reg;
+   int buck_default_idx;
+   int buck_old_idx;
 
dev_dbg(&pdev->dev, "%s\n", __func__);
 
@@ -472,13 +481,34 @@ static int max77686_pmic_probe(struct platform_device 
*pdev)
config.driver_data = max77686;
platform_set_drvdata(pdev, max77686);
 
+   buck_default_idx = pdata->buck_default_idx;
+   buck_old_idx = max77686_read_gpios(pdata);
+
for (i = 0; i < MAX77686_REGULATORS; i++) {
struct regulator_dev *rdev;
+   int id = pdata->regulators[i].id;
 
config.init_data = pdata->regulators[i].initdata;
config.of_node = pdata->regulators[i].of_node;
 
max77686->opmode[i] = regulators[i].enable_mask;
+
+   if (max77686_is_dvs_buck(id)) {
+   /* Try to copy over data so we keep firmware settings */
+   reg = regulators[i].vsel_reg;
+
+   ret = regmap_reg_copy(iodev->regmap,
+ reg + buck_default_idx,
+ reg + buck_old_idx);
+
+   if (ret)
+   dev_warn(&pdev->dev, "Copy err %d => %d (%d)\n",
+reg + buck_old_idx,
+reg + buck_default_idx, ret);
+
+   regulators[i].vsel_reg += buck_default_idx;
+   }
+
rdev = devm_regulator_register(&pdev->dev,
®ulators[i], &config);
if (IS_ERR(rdev)) {
@@ -488,6 +518,10 @@ static int max77686_pmic_probe(struct platform_device 
*pdev)
}
}
 
+   ret = max77686_setup_gpios(iodev->dev);
+   if (ret)
+   return ret;
+
return 0;
 }
 
-- 
2.0.0.rc2

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v6 14/23] regmap: Add regmap_reg_copy function

2014-07-04 Thread Javier Martinez Canillas
Some device drivers using the register map API need to copy the
value from one register to another. Even though it can be done
with a combination of regmap_read() and regmap_write(), it is
better to have a function to avoid code duplication and also it
sanity check and do it atomically by holding the regmap lock.

Signed-off-by: Javier Martinez Canillas 
---

Changes since v5: None

Changes since v4: None

Changes since v3: None
---
 drivers/base/regmap/regmap.c | 34 ++
 include/linux/regmap.h   |  9 +
 2 files changed, 43 insertions(+)

diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index 74d8c06..a2e0b04 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -2555,6 +2555,40 @@ int regmap_parse_val(struct regmap *map, const void *buf,
 }
 EXPORT_SYMBOL_GPL(regmap_parse_val);
 
+/**
+ * regmap_reg_copy(): Copy a value from a single register to another one
+ *
+ * @map: Register map to operate on
+ * @dest: Register to copy the value to
+ * @src: Register to copy the value from
+ *
+ * A value of zero will be returned on success, a negative errno will
+ * be returned in error cases.
+ */
+int regmap_reg_copy(struct regmap *map, unsigned int dest, unsigned int src)
+{
+   int val;
+   int ret = 0;
+
+   if (dest == src)
+   return ret;
+
+   if (dest % map->reg_stride ||
+   src % map->reg_stride)
+   return -EINVAL;
+
+   map->lock(map->lock_arg);
+
+   ret = _regmap_read(map, src, &val);
+   if (!ret)
+   ret = _regmap_write(map, dest, val);
+
+   map->unlock(map->lock_arg);
+
+   return ret;
+}
+EXPORT_SYMBOL_GPL(regmap_reg_copy);
+
 static int __init regmap_initcall(void)
 {
regmap_debugfs_initcall();
diff --git a/include/linux/regmap.h b/include/linux/regmap.h
index 7b0e4b4..116c22b 100644
--- a/include/linux/regmap.h
+++ b/include/linux/regmap.h
@@ -445,6 +445,8 @@ int regmap_register_patch(struct regmap *map, const struct 
reg_default *regs,
 int regmap_parse_val(struct regmap *map, const void *buf,
unsigned int *val);
 
+int regmap_reg_copy(struct regmap *map, unsigned int dest, unsigned int src);
+
 static inline bool regmap_reg_in_range(unsigned int reg,
   const struct regmap_range *range)
 {
@@ -723,6 +725,13 @@ static inline int regmap_parse_val(struct regmap *map, 
const void *buf,
return -EINVAL;
 }
 
+static inline int regmap_reg_copy(struct regmap *map, unsigned int dest,
+ unsigned int src)
+{
+   WARN_ONCE(1, "regmap API is disabled");
+   return -EINVAL;
+}
+
 static inline struct regmap *dev_get_regmap(struct device *dev,
const char *name)
 {
-- 
2.0.0.rc2

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v6 13/23] clk: max77686: Improve Maxim 77686 PMIC clocks binding

2014-07-04 Thread Javier Martinez Canillas
Like most clock drivers, the Maxim 77686 PMIC clock binding
follows the convention that the "#clock-cells" property is
used to specify the number of cells in a clock provider.

But the binding document is not clear enough that it shall
be set to 1 since the PMIC support multiple clocks outputs.

Also, explain that the clocks identifiers are defined in a
header file that can be included by Device Tree source with
client nodes to avoid using magic numbers.

Finally, add "clock-output-names" as an optional property
since now is supported by the clock driver.

Signed-off-by: Javier Martinez Canillas 
Reviewed-by: Krzysztof Kozlowski 
Reviewed-by: Doug Anderson 
Reviewed-by: Mike Turquette 
---

Changes since v5:
  - Add "clock-output-names" as an optional property now that is supported.

Changes since v4: None

Changes since v3:
 - Don't change clock-names property to make clear that it's
   the consumer clock name and should not match the producer clock.
   Suggested by Doug Anderson.
---
 .../devicetree/bindings/clock/maxim,max77686.txt | 16 
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/Documentation/devicetree/bindings/clock/maxim,max77686.txt 
b/Documentation/devicetree/bindings/clock/maxim,max77686.txt
index 96ce71b..9c40739 100644
--- a/Documentation/devicetree/bindings/clock/maxim,max77686.txt
+++ b/Documentation/devicetree/bindings/clock/maxim,max77686.txt
@@ -9,13 +9,21 @@ The MAX77686 contains three 32.768khz clock outputs that can 
be controlled
 Following properties should be presend in main device node of the MFD chip.
 
 Required properties:
-- #clock-cells: simple one-cell clock specifier format is used, where the
-  only cell is used as an index of the clock inside the provider. Following
-  indices are allowed:
+
+- #clock-cells: from common clock binding; shall be set to 1.
+
+Optional properties:
+- clock-output-names: From common clock binding.
+
+Each clock is assigned an identifier and client nodes can use this identifier
+to specify the clock which they consume. Following indices are allowed:
 - 0: 32khz_ap clock,
 - 1: 32khz_cp clock,
 - 2: 32khz_pmic clock.
 
+Clocks are defined as preprocessor macros in dt-bindings/clock/maxim,max77686.h
+header and can be used in device tree sources.
+
 Example: Node of the MFD chip
 
max77686: max77686@09 {
@@ -34,5 +42,5 @@ Example: Clock consumer node
compatible = "bar,foo";
/* ... */
clock-names = "my-clock";
-   clocks = <&max77686 2>;
+   clocks = <&max77686 MAX77686_CLK_PMIC>;
};
-- 
2.0.0.rc2

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v6 12/23] clk: max77686: Convert to the generic max clock driver

2014-07-04 Thread Javier Martinez Canillas
Clocks drivers for Maxim PMIC are very similar so they can
be converted to use the generic Maxim clock driver.

Also, while being there use module_platform_driver() helper
macro to eliminate more boilerplate code.

Signed-off-by: Javier Martinez Canillas 
Reviewed-by: Krzysztof Kozlowski 
---

Changes since v5: None

Changes since v4: None

Changes since v3: None
---
 drivers/clk/Kconfig|   1 +
 drivers/clk/clk-max77686.c | 176 +++--
 2 files changed, 9 insertions(+), 168 deletions(-)

diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
index 73f78e8..3fd4270 100644
--- a/drivers/clk/Kconfig
+++ b/drivers/clk/Kconfig
@@ -38,6 +38,7 @@ config COMMON_CLK_MAX_GEN
 config COMMON_CLK_MAX77686
tristate "Clock driver for Maxim 77686 MFD"
depends on MFD_MAX77686
+   select COMMON_CLK_MAX_GEN
---help---
  This driver supports Maxim 77686 crystal oscillator clock. 
 
diff --git a/drivers/clk/clk-max77686.c b/drivers/clk/clk-max77686.c
index 185b611..ed0beb4 100644
--- a/drivers/clk/clk-max77686.c
+++ b/drivers/clk/clk-max77686.c
@@ -31,187 +31,37 @@
 #include 
 
 #include 
-
-struct max77686_clk {
-   struct max77686_dev *iodev;
-   u32 mask;
-   struct clk_hw hw;
-   struct clk_lookup *lookup;
-};
-
-static struct max77686_clk *to_max77686_clk(struct clk_hw *hw)
-{
-   return container_of(hw, struct max77686_clk, hw);
-}
-
-static int max77686_clk_prepare(struct clk_hw *hw)
-{
-   struct max77686_clk *max77686 = to_max77686_clk(hw);
-
-   return regmap_update_bits(max77686->iodev->regmap,
- MAX77686_REG_32KHZ, max77686->mask,
- max77686->mask);
-}
-
-static void max77686_clk_unprepare(struct clk_hw *hw)
-{
-   struct max77686_clk *max77686 = to_max77686_clk(hw);
-
-   regmap_update_bits(max77686->iodev->regmap,
-   MAX77686_REG_32KHZ, max77686->mask, ~max77686->mask);
-}
-
-static int max77686_clk_is_prepared(struct clk_hw *hw)
-{
-   struct max77686_clk *max77686 = to_max77686_clk(hw);
-   int ret;
-   u32 val;
-
-   ret = regmap_read(max77686->iodev->regmap,
-   MAX77686_REG_32KHZ, &val);
-
-   if (ret < 0)
-   return -EINVAL;
-
-   return val & max77686->mask;
-}
-
-static unsigned long max77686_recalc_rate(struct clk_hw *hw,
- unsigned long parent_rate)
-{
-   return 32768;
-}
-
-static struct clk_ops max77686_clk_ops = {
-   .prepare= max77686_clk_prepare,
-   .unprepare  = max77686_clk_unprepare,
-   .is_prepared= max77686_clk_is_prepared,
-   .recalc_rate= max77686_recalc_rate,
-};
+#include "clk-max-gen.h"
 
 static struct clk_init_data max77686_clks_init[MAX77686_CLKS_NUM] = {
[MAX77686_CLK_AP] = {
.name = "32khz_ap",
-   .ops = &max77686_clk_ops,
+   .ops = &max_gen_clk_ops,
.flags = CLK_IS_ROOT,
},
[MAX77686_CLK_CP] = {
.name = "32khz_cp",
-   .ops = &max77686_clk_ops,
+   .ops = &max_gen_clk_ops,
.flags = CLK_IS_ROOT,
},
[MAX77686_CLK_PMIC] = {
.name = "32khz_pmic",
-   .ops = &max77686_clk_ops,
+   .ops = &max_gen_clk_ops,
.flags = CLK_IS_ROOT,
},
 };
 
-static struct clk *max77686_clk_register(struct device *dev,
-   struct max77686_clk *max77686)
-{
-   struct clk *clk;
-   struct clk_hw *hw = &max77686->hw;
-
-   clk = clk_register(dev, hw);
-   if (IS_ERR(clk))
-   return clk;
-
-   max77686->lookup = kzalloc(sizeof(struct clk_lookup), GFP_KERNEL);
-   if (!max77686->lookup)
-   return ERR_PTR(-ENOMEM);
-
-   max77686->lookup->con_id = hw->init->name;
-   max77686->lookup->clk = clk;
-
-   clkdev_add(max77686->lookup);
-
-   return clk;
-}
-
 static int max77686_clk_probe(struct platform_device *pdev)
 {
struct max77686_dev *iodev = dev_get_drvdata(pdev->dev.parent);
-   struct max77686_clk *max77686_clks[MAX77686_CLKS_NUM];
-   struct clk **clocks;
-   int i, ret;
-
-   clocks = devm_kzalloc(&pdev->dev, sizeof(struct clk *)
-   * MAX77686_CLKS_NUM, GFP_KERNEL);
-   if (!clocks)
-   return -ENOMEM;
-
-   for (i = 0; i < MAX77686_CLKS_NUM; i++) {
-   max77686_clks[i] = devm_kzalloc(&pdev->dev,
-   sizeof(struct max77686_clk), 
GFP_KERNEL);
-   if (!max77686_clks[i])
-   return -ENOMEM;
-   }
-
-   for (i = 

[PATCH v6 10/23] clk: max77686: Add DT include for MAX77686 PMIC clock

2014-07-04 Thread Javier Martinez Canillas
This patch adds a dt-binding include for Maxim 77686
PMIC clock IDs that can be used by both the max77686
clock driver and Device Tree source files.

Signed-off-by: Javier Martinez Canillas 
Reviewed-by: Krzysztof Kozlowski 
Reviewed-by: Mike Turquette 
---

Changes since v5:
 - Improve wording in commit message. Suggested by Andreas Farber.

Changes since v4: None

Changes since v3:
 - Keep the note that this patch needs another change due wakeup
   ordering problems.
---
 drivers/clk/clk-max77686.c |  7 +--
 include/dt-bindings/clock/maxim,max77686.h | 23 +++
 2 files changed, 24 insertions(+), 6 deletions(-)
 create mode 100644 include/dt-bindings/clock/maxim,max77686.h

diff --git a/drivers/clk/clk-max77686.c b/drivers/clk/clk-max77686.c
index 3d7e8dd..185b611 100644
--- a/drivers/clk/clk-max77686.c
+++ b/drivers/clk/clk-max77686.c
@@ -30,12 +30,7 @@
 #include 
 #include 
 
-enum {
-   MAX77686_CLK_AP = 0,
-   MAX77686_CLK_CP,
-   MAX77686_CLK_PMIC,
-   MAX77686_CLKS_NUM,
-};
+#include 
 
 struct max77686_clk {
struct max77686_dev *iodev;
diff --git a/include/dt-bindings/clock/maxim,max77686.h 
b/include/dt-bindings/clock/maxim,max77686.h
new file mode 100644
index 000..7b28b09
--- /dev/null
+++ b/include/dt-bindings/clock/maxim,max77686.h
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2014 Google, Inc
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Device Tree binding constants clocks for the Maxim 77686 PMIC.
+ */
+
+#ifndef _DT_BINDINGS_CLOCK_MAXIM_MAX77686_CLOCK_H
+#define _DT_BINDINGS_CLOCK_MAXIM_MAX77686_CLOCK_H
+
+/* Fixed rate clocks. */
+
+#define MAX77686_CLK_AP0
+#define MAX77686_CLK_CP1
+#define MAX77686_CLK_PMIC  2
+
+/* Total number of clocks. */
+#define MAX77686_CLKS_NUM  (MAX77686_CLK_PMIC + 1)
+
+#endif /* _DT_BINDINGS_CLOCK_MAXIM_MAX77686_CLOCK_H */
-- 
2.0.0.rc2

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v6 11/23] clk: Add generic driver for Maxim PMIC clocks

2014-07-04 Thread Javier Martinez Canillas
Maxim Integrated Power Management ICs are very similar with
regard to their clock outputs. Most of the clock drivers for
these chips are duplicating code and are simpler enough that
can be converted to use a generic driver to consolidate code
and avoid duplication.

Signed-off-by: Javier Martinez Canillas 
Reviewed-by: Krzysztof Kozlowski 
---

Changes since v5:
 - Fix generic driver changes merged into max77802 clock patch by mistake.
   Suggested by Yadwinder Singh Brar.
 - Register clock lookups using clk_register_clkdev() instead of doing manually.
 - Use the managed devm_clk_register() function and remove clk un-registration.
 - Add "clock-output-names" property support. Suggested by Yadwinder Singh Brar.
 - Return the rate unconditionally in recalc_rate. Suggested by Mike Turquette.

Changes since v4: None

Changes since v3:
 - Don't change clock-names property to make clear that it's
   the consumer clock name and should not match the producer clock.
   Suggested by Doug Anderson.
---
 drivers/clk/Kconfig   |   3 +
 drivers/clk/Makefile  |   1 +
 drivers/clk/clk-max-gen.c | 192 ++
 drivers/clk/clk-max-gen.h |  32 
 4 files changed, 228 insertions(+)
 create mode 100644 drivers/clk/clk-max-gen.c
 create mode 100644 drivers/clk/clk-max-gen.h

diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
index 9f9c5ae..73f78e8 100644
--- a/drivers/clk/Kconfig
+++ b/drivers/clk/Kconfig
@@ -32,6 +32,9 @@ config COMMON_CLK_WM831X
 
 source "drivers/clk/versatile/Kconfig"
 
+config COMMON_CLK_MAX_GEN
+bool
+
 config COMMON_CLK_MAX77686
tristate "Clock driver for Maxim 77686 MFD"
depends on MFD_MAX77686
diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
index 567f102..6c1aff6 100644
--- a/drivers/clk/Makefile
+++ b/drivers/clk/Makefile
@@ -18,6 +18,7 @@ obj-$(CONFIG_ARCH_BCM2835)+= clk-bcm2835.o
 obj-$(CONFIG_ARCH_EFM32)   += clk-efm32gg.o
 obj-$(CONFIG_ARCH_HIGHBANK)+= clk-highbank.o
 obj-$(CONFIG_MACH_LOONGSON1)   += clk-ls1x.o
+obj-$(CONFIG_COMMON_CLK_MAX_GEN)   += clk-max-gen.o
 obj-$(CONFIG_COMMON_CLK_MAX77686)  += clk-max77686.o
 obj-$(CONFIG_ARCH_MOXART)  += clk-moxart.o
 obj-$(CONFIG_ARCH_NOMADIK) += clk-nomadik.o
diff --git a/drivers/clk/clk-max-gen.c b/drivers/clk/clk-max-gen.c
new file mode 100644
index 000..6505049
--- /dev/null
+++ b/drivers/clk/clk-max-gen.c
@@ -0,0 +1,192 @@
+/*
+ * clk-max-gen.c - Generic clock driver for Maxim PMICs clocks
+ *
+ * Copyright (C) 2014 Google, Inc
+ *
+ * Copyright (C) 2012 Samsung Electornics
+ * Jonghwa Lee 
+ *
+ * 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.
+ *
+ * This driver is based on clk-max77686.c
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct max_gen_clk {
+   struct regmap *regmap;
+   u32 mask;
+   u32 reg;
+   struct clk_hw hw;
+};
+
+static struct max_gen_clk *to_max_gen_clk(struct clk_hw *hw)
+{
+   return container_of(hw, struct max_gen_clk, hw);
+}
+
+static int max_gen_clk_prepare(struct clk_hw *hw)
+{
+   struct max_gen_clk *max_gen = to_max_gen_clk(hw);
+
+   return regmap_update_bits(max_gen->regmap, max_gen->reg,
+ max_gen->mask, max_gen->mask);
+}
+
+static void max_gen_clk_unprepare(struct clk_hw *hw)
+{
+   struct max_gen_clk *max_gen = to_max_gen_clk(hw);
+
+   regmap_update_bits(max_gen->regmap, max_gen->reg,
+  max_gen->mask, ~max_gen->mask);
+}
+
+static int max_gen_clk_is_prepared(struct clk_hw *hw)
+{
+   struct max_gen_clk *max_gen = to_max_gen_clk(hw);
+   int ret;
+   u32 val;
+
+   ret = regmap_read(max_gen->regmap, max_gen->reg, &val);
+
+   if (ret < 0)
+   return -EINVAL;
+
+   return val & max_gen->mask;
+}
+
+static unsigned long max_gen_recalc_rate(struct clk_hw *hw,
+unsigned long parent_rate)
+{
+   return 32768;
+}
+
+struct clk_ops max_gen_clk_ops = {
+   .prepare= max_gen_clk_prepare,
+   .unprepare  = max_gen_clk_unprepare,
+   .is_prepared= max_gen_clk_is_prepared,
+   .recalc_rate= max_gen_recalc_rate,
+};
+EXPORT_SYMBOL_GPL(max_gen_clk_ops);
+
+static struct clk *max_gen_clk_register(struct device *dev,
+  

[PATCH v6 09/23] rtc: max77686: Allow the max77686 rtc to wakeup the system

2014-07-04 Thread Javier Martinez Canillas
From: Doug Anderson 

The max77686 includes an RTC that keeps power during suspend.  It's
convenient to be able to use it as a wakeup source.

NOTE: due to wakeup ordering problems this patch alone doesn't work so
well on exynos5250-snow.  You also need something that brings the i2c
bus up before the max77686 wakeup runs.

Signed-off-by: Doug Anderson 
Reviewed-by: Javier Martinez Canillas 
Reviewed-by: Krzysztof Kozlowski 
---

Changes since v5:
 - Fix $SUBJECT since the patch does not actually touch the mfd subsys.
   Suggested by Lee Jones.

Changes since v4: None

Changes since v3:
 - Keep the note that this patch needs another change due wakeup
   ordering problems.
---
 drivers/rtc/rtc-max77686.c | 28 
 1 file changed, 28 insertions(+)

diff --git a/drivers/rtc/rtc-max77686.c b/drivers/rtc/rtc-max77686.c
index d20a7f0..c1c6055 100644
--- a/drivers/rtc/rtc-max77686.c
+++ b/drivers/rtc/rtc-max77686.c
@@ -583,6 +583,33 @@ static void max77686_rtc_shutdown(struct platform_device 
*pdev)
 #endif /* MAX77686_RTC_WTSR_SMPL */
 }
 
+#ifdef CONFIG_PM_SLEEP
+static int max77686_rtc_suspend(struct device *dev)
+{
+   if (device_may_wakeup(dev)) {
+   struct max77686_rtc_info *info = dev_get_drvdata(dev);
+
+   return enable_irq_wake(info->virq);
+   }
+
+   return 0;
+}
+
+static int max77686_rtc_resume(struct device *dev)
+{
+   if (device_may_wakeup(dev)) {
+   struct max77686_rtc_info *info = dev_get_drvdata(dev);
+
+   return disable_irq_wake(info->virq);
+   }
+
+   return 0;
+}
+#endif
+
+static SIMPLE_DEV_PM_OPS(max77686_rtc_pm_ops,
+max77686_rtc_suspend, max77686_rtc_resume);
+
 static const struct platform_device_id rtc_id[] = {
{ "max77686-rtc", 0 },
{},
@@ -592,6 +619,7 @@ static struct platform_driver max77686_rtc_driver = {
.driver = {
.name   = "max77686-rtc",
.owner  = THIS_MODULE,
+   .pm = &max77686_rtc_pm_ops,
},
.probe  = max77686_rtc_probe,
.shutdown   = max77686_rtc_shutdown,
-- 
2.0.0.rc2

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v6 08/23] mfd: max77686: Add Dynamic Voltage Scaling (DVS) support

2014-07-04 Thread Javier Martinez Canillas
Some regulators on the MAX77686 PMIC have Dynamic Voltage Scaling
(DVS) support that allows output voltage to change dynamically.

For MAX77686, these regulators are Buck regulators 2, 3 and 4.

Each Buck output voltage is selected using a set of external
inputs: DVS1-3 and SELB2-4.

DVS registers can be used to configure the output voltages for each
Buck regulator and which one is active is controled by DVSx lines.

SELBx lines are used to control if individual Buck lines are ON or OFF.

This patch adds support to configure the DVSx and SELBx lines
from DT and to setup and read the GPIO lines connected to them.

Signed-off-by: Javier Martinez Canillas 
---
 drivers/mfd/max77686.c   | 115 +++
 include/linux/mfd/max77686.h |  18 ---
 2 files changed, 125 insertions(+), 8 deletions(-)

diff --git a/drivers/mfd/max77686.c b/drivers/mfd/max77686.c
index 8650832..648d564 100644
--- a/drivers/mfd/max77686.c
+++ b/drivers/mfd/max77686.c
@@ -32,8 +32,10 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
+#include 
 
 #define I2C_ADDR_RTC   (0x0C >> 1)
 
@@ -101,9 +103,115 @@ static const struct of_device_id max77686_pmic_dt_match[] 
= {
{},
 };
 
+static void max77686_dt_parse_dvs_gpio(struct device *dev)
+{
+   struct max77686_platform_data *pd = dev_get_platdata(dev);
+   int i;
+
+   /*
+* NOTE: we don't consider GPIO errors fatal; board may have some lines
+* directly pulled high or low and thus doesn't specify them.
+*/
+   for (i = 0; i < ARRAY_SIZE(pd->buck_gpio_dvs); i++)
+   pd->buck_gpio_dvs[i] =
+   devm_gpiod_get_index(dev, "max77686,pmic-buck-dvs", i);
+
+   for (i = 0; i < ARRAY_SIZE(pd->buck_gpio_selb); i++)
+   pd->buck_gpio_selb[i] =
+   devm_gpiod_get_index(dev, "max77686,pmic-buck-selb", i);
+}
+
+/**
+ * max77686_setup_gpios - init DVS-related GPIOs
+ *
+ * This function claims / initalizations GPIOs related to DVS if they are
+ * defined. This may have the effect of switching voltages if the
+ * pdata->buck_default_idx does not match the boot time state of pins.
+ */
+int max77686_setup_gpios(struct device *dev)
+{
+   struct max77686_platform_data *pd = dev_get_platdata(dev);
+   int buck_default_idx = pd->buck_default_idx;
+   int ret;
+   int i;
+
+   /* Set all SELB high to avoid glitching while DVS is changing */
+   for (i = 0; i < ARRAY_SIZE(pd->buck_gpio_selb); i++) {
+   struct gpio_desc *gpio = pd->buck_gpio_selb[i];
+
+   /* OK if some GPIOs aren't defined */
+   if (IS_ERR(gpio))
+   continue;
+
+   ret = gpiod_direction_output_raw(gpio, 1);
+   if (ret) {
+   dev_err(dev, "can't set gpio[%d] dir: %d\n", i, ret);
+   return ret;
+   }
+   }
+
+   /* Set our initial setting */
+   for (i = 0; i < ARRAY_SIZE(pd->buck_gpio_dvs); i++) {
+   struct gpio_desc *gpio = pd->buck_gpio_dvs[i];
+
+   /* OK if some GPIOs aren't defined */
+   if (IS_ERR(gpio))
+   continue;
+
+   /* If a GPIO is valid, set it */
+   gpiod_direction_output(gpio, (buck_default_idx >> i) & 1);
+   if (ret) {
+   dev_err(dev, "can't set gpio[%d]: dir %d\n", i, ret);
+   return ret;
+   }
+   }
+
+   /* Now set SELB low to take effect */
+   for (i = 0; i < ARRAY_SIZE(pd->buck_gpio_selb); i++) {
+   struct gpio_desc *gpio = pd->buck_gpio_selb[i];
+
+   if (!IS_ERR(gpio))
+   gpiod_set_value(gpio, 0);
+   }
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(max77686_setup_gpios);
+
+/**
+ * max77686_read_gpios - read the current state of the dvs GPIOs
+ *
+ * We call this function at bootup to detect what slot the firmware was
+ * using for the DVS GPIOs.  That way we can properly preserve the firmware's
+ * voltage settings
+ */
+int max77686_read_gpios(struct max77686_platform_data *pdata)
+{
+   int buck_default_idx = pdata->buck_default_idx;
+   int result = 0;
+   int i;
+
+   for (i = 0; i < ARRAY_SIZE(pdata->buck_gpio_dvs); i++) {
+   struct gpio_desc *gpio = pdata->buck_gpio_dvs[i];
+
+   /* OK if some GPIOs aren't defined; we'll use default */
+   if (IS_ERR(gpio)) {
+   result |= buck_default_idx & (1 << i);
+   continue;
+   }
+
+   if (gpiod_get_value_cansleep(gpio))
+   result |= 1 << i;
+   }
+
+   return result;
+}
+EXPORT_SYMBOL_GPL(max77686_read_

[PATCH v6 07/23] mfd: max77686: Remove unneeded OOM error message

2014-07-04 Thread Javier Martinez Canillas
There is no need to print out-of-memory errors since this is already
done by the memory management subsystem which even calls dump_stack().

Signed-off-by: Javier Martinez Canillas 
---
 drivers/mfd/max77686.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/mfd/max77686.c b/drivers/mfd/max77686.c
index 87fe52e..8650832 100644
--- a/drivers/mfd/max77686.c
+++ b/drivers/mfd/max77686.c
@@ -107,10 +107,8 @@ static struct max77686_platform_data 
*max77686_i2c_parse_dt_pdata(struct device
struct max77686_platform_data *pd;
 
pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL);
-   if (!pd) {
-   dev_err(dev, "could not allocate memory for pdata\n");
+   if (!pd)
return NULL;
-   }
 
dev->platform_data = pd;
return pd;
-- 
2.0.0.rc2

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v6 05/23] mfd: max77686: Return correct error when pdata isn't found

2014-07-04 Thread Javier Martinez Canillas
When platform data is not found an -EIO (I/O error) code is returned.
This doesn't seem to be the correct error so better return -EINVAL
(Invalid argument) which is what most drivers do in this case.

Signed-off-by: Javier Martinez Canillas 
---
 drivers/mfd/max77686.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mfd/max77686.c b/drivers/mfd/max77686.c
index 12d4c17..ada4976 100644
--- a/drivers/mfd/max77686.c
+++ b/drivers/mfd/max77686.c
@@ -129,7 +129,7 @@ static int max77686_i2c_probe(struct i2c_client *i2c,
 
if (!pdata) {
dev_err(&i2c->dev, "No platform data found.\n");
-   return -EIO;
+   return -EINVAL;
}
 
max77686 = devm_kzalloc(&i2c->dev,
-- 
2.0.0.rc2

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v6 03/23] mfd: max77686: Don't define dummy function if OF isn't enabled

2014-07-04 Thread Javier Martinez Canillas
When the CONFIG_OF option was not enabled, a dummy function
max77686_i2c_parse_dt_pdata() was defined since this is called
unconditionally on probe(). Just always define the real function
and conditionally call it if CONFIG_OF is enabled instead.

Signed-off-by: Javier Martinez Canillas 
---
 drivers/mfd/max77686.c | 10 +-
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/drivers/mfd/max77686.c b/drivers/mfd/max77686.c
index a38e9ee..d1f9d04 100644
--- a/drivers/mfd/max77686.c
+++ b/drivers/mfd/max77686.c
@@ -96,7 +96,6 @@ static const struct regmap_irq_chip max77686_rtc_irq_chip = {
.num_irqs   = ARRAY_SIZE(max77686_rtc_irqs),
 };
 
-#ifdef CONFIG_OF
 static const struct of_device_id max77686_pmic_dt_match[] = {
{.compatible = "maxim,max77686", .data = NULL},
{},
@@ -116,13 +115,6 @@ static struct max77686_platform_data 
*max77686_i2c_parse_dt_pdata(struct device
dev->platform_data = pd;
return pd;
 }
-#else
-static struct max77686_platform_data *max77686_i2c_parse_dt_pdata(struct device
- *dev)
-{
-   return 0;
-}
-#endif
 
 static int max77686_i2c_probe(struct i2c_client *i2c,
  const struct i2c_device_id *id)
@@ -132,7 +124,7 @@ static int max77686_i2c_probe(struct i2c_client *i2c,
unsigned int data;
int ret = 0;
 
-   if (i2c->dev.of_node)
+   if (IS_ENABLED(CONFIG_OF) && i2c->dev.of_node)
pdata = max77686_i2c_parse_dt_pdata(&i2c->dev);
 
if (!pdata) {
-- 
2.0.0.rc2

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v6 04/23] mfd: max77686: Make platform data over-rule DT

2014-07-04 Thread Javier Martinez Canillas
The function max77802_i2c_parse_dt_pdata() should only be called
if there isn't already platform data for the device.

Signed-off-by: Javier Martinez Canillas 
---
 drivers/mfd/max77686.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mfd/max77686.c b/drivers/mfd/max77686.c
index d1f9d04..12d4c17 100644
--- a/drivers/mfd/max77686.c
+++ b/drivers/mfd/max77686.c
@@ -124,7 +124,7 @@ static int max77686_i2c_probe(struct i2c_client *i2c,
unsigned int data;
int ret = 0;
 
-   if (IS_ENABLED(CONFIG_OF) && i2c->dev.of_node)
+   if (IS_ENABLED(CONFIG_OF) && i2c->dev.of_node && !pdata)
pdata = max77686_i2c_parse_dt_pdata(&i2c->dev);
 
if (!pdata) {
-- 
2.0.0.rc2

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v6 02/23] mfd: max77686: Add power management support

2014-07-04 Thread Javier Martinez Canillas
The driver doesn't have PM operations defined so add a suspend
and resume function handlers to allow the PMIC IRQ to wakeup
the system when it is put into a sleep state.

Signed-off-by: Javier Martinez Canillas 
---
 drivers/mfd/max77686.c | 40 
 1 file changed, 40 insertions(+)

diff --git a/drivers/mfd/max77686.c b/drivers/mfd/max77686.c
index 3cb41d0..a38e9ee 100644
--- a/drivers/mfd/max77686.c
+++ b/drivers/mfd/max77686.c
@@ -240,10 +240,50 @@ static const struct i2c_device_id max77686_i2c_id[] = {
 };
 MODULE_DEVICE_TABLE(i2c, max77686_i2c_id);
 
+#ifdef CONFIG_PM_SLEEP
+static int max77686_suspend(struct device *dev)
+{
+   struct i2c_client *i2c = container_of(dev, struct i2c_client, dev);
+   struct max77686_dev *max77686 = i2c_get_clientdata(i2c);
+
+   if (device_may_wakeup(dev))
+   enable_irq_wake(max77686->irq);
+
+   /*
+* IRQ must be disabled during suspend because if it happens
+* while suspended it will be handled before resuming I2C.
+*
+* When device is woken up from suspend (e.g. by RTC wake alarm),
+* an interrupt occurs before resuming I2C bus controller.
+* Interrupt handler tries to read registers but this read
+* will fail because I2C is still suspended.
+*/
+   disable_irq(max77686->irq);
+
+   return 0;
+}
+
+static int max77686_resume(struct device *dev)
+{
+   struct i2c_client *i2c = container_of(dev, struct i2c_client, dev);
+   struct max77686_dev *max77686 = i2c_get_clientdata(i2c);
+
+   if (device_may_wakeup(dev))
+   disable_irq_wake(max77686->irq);
+
+   enable_irq(max77686->irq);
+
+   return 0;
+}
+#endif /* CONFIG_PM_SLEEP */
+
+static SIMPLE_DEV_PM_OPS(max77686_pm, max77686_suspend, max77686_resume);
+
 static struct i2c_driver max77686_i2c_driver = {
.driver = {
   .name = "max77686",
   .owner = THIS_MODULE,
+  .pm = &max77686_pm,
   .of_match_table = of_match_ptr(max77686_pmic_dt_match),
},
.probe = max77686_i2c_probe,
-- 
2.0.0.rc2

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v6 01/23] mfd: max77686: Convert to use regmap_irq

2014-07-04 Thread Javier Martinez Canillas
By using the generic IRQ support in the Register map API, it
is possible to get rid max77686-irq.c and simplify the code.

Suggested-by: Krzysztof Kozlowski 
Signed-off-by: Javier Martinez Canillas 
Acked-by: Lee Jones 
Reviewed-by: Doug Anderson 
Tested-by: Doug Anderson 
---

Changes since v5: None

Changes since v4:
 - Remove left over defines not used anymore. Suggested by Krzysztof Kozlowski.

Changes since v3: None

Changes since v2:
 - Cleanup regmap irqchips on i2c_driver .remove function.
   Suggested by Doug Anderson.
 - Remove unused MAX77686_IRQ_NR enum. Suggested by Doug Anderson.
---
 drivers/mfd/Kconfig  |   1 +
 drivers/mfd/Makefile |   2 +-
 drivers/mfd/max77686-irq.c   | 319 ---
 drivers/mfd/max77686.c   |  97 ++-
 drivers/rtc/rtc-max77686.c   |  27 +--
 include/linux/mfd/max77686-private.h |  31 +++-
 include/linux/mfd/max77686.h |   2 -
 7 files changed, 123 insertions(+), 356 deletions(-)
 delete mode 100644 drivers/mfd/max77686-irq.c

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index b8d9ca0..3010204 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -384,6 +384,7 @@ config MFD_MAX77686
depends on I2C=y
select MFD_CORE
select REGMAP_I2C
+   select REGMAP_IRQ
select IRQ_DOMAIN
help
  Say yes here to add support for Maxim Semiconductor MAX77686.
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 4e2bc25..f001487 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -115,7 +115,7 @@ da9063-objs := da9063-core.o da9063-irq.o 
da9063-i2c.o
 obj-$(CONFIG_MFD_DA9063)   += da9063.o
 
 obj-$(CONFIG_MFD_MAX14577) += max14577.o
-obj-$(CONFIG_MFD_MAX77686) += max77686.o max77686-irq.o
+obj-$(CONFIG_MFD_MAX77686) += max77686.o
 obj-$(CONFIG_MFD_MAX77693) += max77693.o
 obj-$(CONFIG_MFD_MAX8907)  += max8907.o
 max8925-objs   := max8925-core.o max8925-i2c.o
diff --git a/drivers/mfd/max77686-irq.c b/drivers/mfd/max77686-irq.c
deleted file mode 100644
index cdc3280..000
--- a/drivers/mfd/max77686-irq.c
+++ /dev/null
@@ -1,319 +0,0 @@
-/*
- * max77686-irq.c - Interrupt controller support for MAX77686
- *
- * Copyright (C) 2012 Samsung Electronics Co.Ltd
- * Chiwoong Byun 
- *
- * 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.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- * This driver is based on max8997-irq.c
- */
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-enum {
-   MAX77686_DEBUG_IRQ_INFO = 1 << 0,
-   MAX77686_DEBUG_IRQ_MASK = 1 << 1,
-   MAX77686_DEBUG_IRQ_INT = 1 << 2,
-};
-
-static int debug_mask = 0;
-module_param(debug_mask, int, 0);
-MODULE_PARM_DESC(debug_mask, "Set debug_mask : 0x0=off 0x1=IRQ_INFO  
0x2=IRQ_MASK 0x4=IRQ_INI)");
-
-static const u8 max77686_mask_reg[] = {
-   [PMIC_INT1] = MAX77686_REG_INT1MSK,
-   [PMIC_INT2] = MAX77686_REG_INT2MSK,
-   [RTC_INT] = MAX77686_RTC_INTM,
-};
-
-static struct regmap *max77686_get_regmap(struct max77686_dev *max77686,
-   enum max77686_irq_source src)
-{
-   switch (src) {
-   case PMIC_INT1 ... PMIC_INT2:
-   return max77686->regmap;
-   case RTC_INT:
-   return max77686->rtc_regmap;
-   default:
-   return ERR_PTR(-EINVAL);
-   }
-}
-
-struct max77686_irq_data {
-   int mask;
-   enum max77686_irq_source group;
-};
-
-#define DECLARE_IRQ(idx, _group, _mask)\
-   [(idx)] = { .group = (_group), .mask = (_mask) }
-static const struct max77686_irq_data max77686_irqs[] = {
-   DECLARE_IRQ(MAX77686_PMICIRQ_PWRONF,PMIC_INT1, 1 << 0),
-   DECLARE_IRQ(MAX77686_PMICIRQ_PWRONR,PMIC_INT1, 1 << 1),
-   DECLARE_IRQ(MAX77686_PMICIRQ_JIGONBF,   PMIC_INT1, 1 << 2),
-   DECLARE_IRQ(MAX77686_PMICIRQ_JIGONBR,   PMIC_INT1, 1 << 3),
-   DECLARE_IRQ(MAX77686_PMICIRQ_ACOKBF,PMIC_INT1, 1 << 4),
-   DECLARE_IRQ(MAX77686_PMICIRQ_ACOKBR,PMIC_INT1, 1 << 5),
-   DECLARE_IRQ(MAX77686_PMICIRQ_ONKEY1S,   PMIC_INT1, 1 << 6),
-   DECLARE_IRQ(MAX77686_PMICIRQ_MRSTB, PMIC_INT1, 1

[PATCH v6 00/23] Add Maxim 77802 PMIC support

2014-07-04 Thread Javier Martinez Canillas
MAX77802 is a PMIC that contains 10 high efficiency Buck regulators,
32 Low-dropout (LDO) regulators, two 32kHz buffered clock outputs,
a Real-Time-Clock (RTC) and a I2C interface to program the individual
regulators, clocks and the RTC.

This series are based on drivers added by Simon Glass to the Chrome OS
kernel and adds support for the Maxim 77802 Power Management IC, their
regulators, clocks, RTC and I2C interface and depend on patch:

"[PATCH v3] ARM: dts: Add cros_ec to exynos5420-peach-pit and 
exynos5800-peach-pi"
https://patchwork.kernel.org/patch/4411351/

which adds tps65090 support to Peach boards since regulators from this
PMIC supply power to a set of MAX77802 regulators.

This is a sixth version of the patch-set that addresses several issues
pointed out in v5. Individual changes are added on each patch change log.

The biggest change is that now the MAX77686 mfd driver is extended to
also support the MAX77802 PMIC instead of having a separate mfd driver
as was suggested by Lee Jones.

Patches 1-16 are cleanups and improvements to the MAX77686 PMIC driver
as a preparation to also support the MAX77802 PMIC. Patch 17 adds support
for MAX77802 to the MAX77686 mfd driver and Patch 18 adds the DT binding
doc for this PMIC. Patch 19 adds support for the regulators in the PMIC,
Patch 20 adds support for the clocks in the PMIC and Patch 21 adds its DT
binding. Patch 22 adds support for the Real-Time-Clock found in the PMIC
and Patch 23 adds the needed device nodes for the max77802 to the Exynos5
base Peach Pit and Pi boards device tree source files.

The patch-set has been tested on both Daisy/Snow (max77686) and Peach
Pit (max77802) Chromebooks and it's composed of the following patches:

Doug Anderson (1):
  rtc: max77686: Allow the max77686 rtc to wakeup the system

Javier Martinez Canillas (22):
  mfd: max77686: Convert to use regmap_irq
  mfd: max77686: Add power management support
  mfd: max77686: don't define dummy function if OF isn't enabled
  mfd: max77686: make platform data over-rule DT
  mfd: max77686: Return correct error when pdata isn't found
  mfd: max77686: Make error checking consistent
  mfd: max77686: Remove unneeded OOM error message
  mfd: max77686: Add Dynamic Voltage Scaling (DVS) support
  clk: max77686: Add DT include for MAX77686 PMIC clock
  clk: Add generic driver for Maxim PMIC clocks
  clk: max77686: Convert to the generic max clock driver
  clk: max77686: Improve Maxim 77686 PMIC clocks binding
  regmap: Add regmap_reg_copy function
  regulator: max77686: Setup DVS-related GPIOs on probe
  mfd: max77686: Add documentation for DVS bindings
  mfd: max77686: Add Maxim 77802 PMIC support
  mfd: max77802: Add DT binding documentation
  regulator: Add driver for Maxim 77802 PMIC regulators
  clk: Add driver for Maxim 77802 PMIC clocks
  clk: max77802: Add DT binding documentation
  rtc: Add driver for Maxim 77802 PMIC Real-Time-Clock
  ARM: dts: Add max77802 to exynos5420-peach-pit and exynos5800-peach-pi

 .../devicetree/bindings/clock/maxim,max77686.txt   |  16 +-
 .../devicetree/bindings/clock/maxim,max77802.txt   |  44 ++
 Documentation/devicetree/bindings/mfd/max77686.txt |  34 ++
 Documentation/devicetree/bindings/mfd/max77802.txt |  95 +++
 arch/arm/boot/dts/exynos5420-peach-pit.dts | 382 
 arch/arm/boot/dts/exynos5800-peach-pi.dts  | 382 
 drivers/base/regmap/regmap.c   |  34 ++
 drivers/clk/Kconfig|  11 +
 drivers/clk/Makefile   |   2 +
 drivers/clk/clk-max-gen.c  | 192 +++
 drivers/clk/clk-max-gen.h  |  32 ++
 drivers/clk/clk-max77686.c | 183 +-
 drivers/clk/clk-max77802.c |  98 
 drivers/mfd/Kconfig|   1 +
 drivers/mfd/Makefile   |   2 +-
 drivers/mfd/max77686-irq.c | 319 ---
 drivers/mfd/max77686.c | 435 --
 drivers/regulator/Kconfig  |   9 +
 drivers/regulator/Makefile |   1 +
 drivers/regulator/max77686.c   |  34 ++
 drivers/regulator/max77802.c   | 609 
 drivers/rtc/Kconfig|  10 +
 drivers/rtc/Makefile   |   1 +
 drivers/rtc/rtc-max77686.c |  55 +-
 drivers/rtc/rtc-max77802.c | 637 +
 include/dt-bindings/clock/maxim,max77686.h |  23 +
 include/dt-bindings/clock/maxim,max77802.h |  22 +
 include/linux/mfd/max77686-private.h   | 237 +++-
 include/linux/mfd/max77686.h   |  78 ++-
 include/linux/regmap.h |   9 +
 30 files changed, 3414 insertions(+), 573 de

Re: [PATCH v6 08/23] mfd: max77686: Add Dynamic Voltage Scaling (DVS) support

2014-07-04 Thread Javier Martinez Canillas
Hello Krzysztof,

Again, thanks a lot for taking the time to review the series.

On 07/04/2014 01:15 PM, Krzysztof Kozlowski wrote:
> On pią, 2014-07-04 at 11:55 +0200, Javier Martinez Canillas wrote:
>> Some regulators on the MAX77686 PMIC have Dynamic Voltage Scaling
>> (DVS) support that allows output voltage to change dynamically.
>> 
>> For MAX77686, these regulators are Buck regulators 2, 3 and 4.
>> 
>> Each Buck output voltage is selected using a set of external
>> inputs: DVS1-3 and SELB2-4.
>> 
>> DVS registers can be used to configure the output voltages for each
>> Buck regulator and which one is active is controled by DVSx lines.
>> 
>> SELBx lines are used to control if individual Buck lines are ON or OFF.
>> 
>> This patch adds support to configure the DVSx and SELBx lines
>> from DT and to setup and read the GPIO lines connected to them.
>> 
>> Signed-off-by: Javier Martinez Canillas 
>> ---
>>  drivers/mfd/max77686.c   | 115 
>> +++
>>  include/linux/mfd/max77686.h |  18 ---
>>  2 files changed, 125 insertions(+), 8 deletions(-)
> 
> One minor comment below, but overall looks good to me:
> Reviewed-by: Krzysztof Kozlowski 
> 
> 
>> diff --git a/drivers/mfd/max77686.c b/drivers/mfd/max77686.c
>> index 8650832..648d564 100644
>> --- a/drivers/mfd/max77686.c
>> +++ b/drivers/mfd/max77686.c
>> @@ -32,8 +32,10 @@
>>  #include 
>>  #include 
>>  #include 
>> +#include 
>>  #include 
>>  #include 
>> +#include 
>>  
>>  #define I2C_ADDR_RTC(0x0C >> 1)
>>  
>> @@ -101,9 +103,115 @@ static const struct of_device_id 
>> max77686_pmic_dt_match[] = {
>>  {},
>>  };
>>  
>> +static void max77686_dt_parse_dvs_gpio(struct device *dev)
>> +{
>> +struct max77686_platform_data *pd = dev_get_platdata(dev);
>> +int i;
>> +
>> +/*
>> + * NOTE: we don't consider GPIO errors fatal; board may have some lines
>> + * directly pulled high or low and thus doesn't specify them.
>> + */
>> +for (i = 0; i < ARRAY_SIZE(pd->buck_gpio_dvs); i++)
>> +pd->buck_gpio_dvs[i] =
>> +devm_gpiod_get_index(dev, "max77686,pmic-buck-dvs", i);
>> +
>> +for (i = 0; i < ARRAY_SIZE(pd->buck_gpio_selb); i++)
>> +pd->buck_gpio_selb[i] =
>> +devm_gpiod_get_index(dev, "max77686,pmic-buck-selb", i);
>> +}
>> +
>> +/**
>> + * max77686_setup_gpios - init DVS-related GPIOs
>> + *
>> + * This function claims / initalizations GPIOs related to DVS if they are
>> + * defined. This may have the effect of switching voltages if the
>> + * pdata->buck_default_idx does not match the boot time state of pins.
>> + */
>> +int max77686_setup_gpios(struct device *dev)
>> +{
>> +struct max77686_platform_data *pd = dev_get_platdata(dev);
>> +int buck_default_idx = pd->buck_default_idx;
>> +int ret;
>> +int i;
>> +
>> +/* Set all SELB high to avoid glitching while DVS is changing */
>> +for (i = 0; i < ARRAY_SIZE(pd->buck_gpio_selb); i++) {
>> +struct gpio_desc *gpio = pd->buck_gpio_selb[i];
>> +
>> +/* OK if some GPIOs aren't defined */
>> +if (IS_ERR(gpio))
>> +continue;
>> +
>> +ret = gpiod_direction_output_raw(gpio, 1);
>> +if (ret) {
>> +dev_err(dev, "can't set gpio[%d] dir: %d\n", i, ret);
>> +return ret;
>> +}
>> +}
>> +
>> +/* Set our initial setting */
>> +for (i = 0; i < ARRAY_SIZE(pd->buck_gpio_dvs); i++) {
>> +struct gpio_desc *gpio = pd->buck_gpio_dvs[i];
>> +
>> +/* OK if some GPIOs aren't defined */
>> +if (IS_ERR(gpio))
>> +continue;
>> +
>> +/* If a GPIO is valid, set it */
>> +gpiod_direction_output(gpio, (buck_default_idx >> i) & 1);
>> +if (ret) {
>> +dev_err(dev, "can't set gpio[%d]: dir %d\n", i, ret);
>> +return ret;
>> +}
>> +}
>> +
>> +/* Now set SELB low to take effect */
>> +for (i = 0; i < ARRAY_SIZE(pd->buck_gpio_selb); i++) {
>> +struct gpio_desc *gpio = pd->buck

Re: [PATCH v6 17/23] mfd: max77686: Add Maxim 77802 PMIC support

2014-07-04 Thread Javier Martinez Canillas
Hello Krzysztof,

On 07/04/2014 01:30 PM, Krzysztof Kozlowski wrote:
> On pią, 2014-07-04 at 11:55 +0200, Javier Martinez Canillas wrote:
>> Maxim MAX77802 is a power management chip that contains 10 high
>> efficiency Buck regulators, 32 Low-dropout (LDO) regulators used
>> to power up application processors and peripherals, a 2-channel
>> 32kHz clock outputs, a Real-Time-Clock (RTC) and a I2C interface
>> to program the individual regulators, clocks outputs and the RTC.
>> 
>> This patch adds support for MAX77802 to the MAX77686 driver and is
>> based on a driver added to the Chrome OS kernel 3.8 by Simon Glass.
>> 
>> Signed-off-by: Javier Martinez Canillas 
>> ---
>> 
>> NOTE: I didn't carry previous {Review,Acked,Tested}-by tags since
>> this patch extending MAX77686 is quite different than the old one
>> adding a new mfd driver. So review and test is highly appreciated.
>> 
>> Changes since v5:
>>  - Extend the 77686 driver to support 77802 instead of adding a new 
>> driver.
>>Suggested by Lee Jones.
>> 
>> Changes since v4:
>>  - Use consistent expressions when checking for NULL values.
>>Suggested by Krzysztof Kozlowski.
>>  - Remove unused defines. Suggested by Krzysztof Kozlowski.
>>  - Explain why IRQ is disabled on suspend. Suggested by Krzysztof 
>> Kozlowski.
>> 
>> Changes since v3:
>>  - Remove unnecessary OOM error message since the mm subsystem already 
>> logs it.
>> 
>> Changes since v2:
>>  - Split the DT binding docs in a separate patch and improve the 
>> documentation.
>>Suggested by Mark Brown.
>>  - Add all the devices in the MFD driver instead of doing in separate 
>> patches.
>>Suggested by Mark Brown.
>> 
>> Changes since v1:
>>  - Convert max77{686,802} to regmap irq API and get rid of 
>> max77{686,802}-irq.c
>>Suggested by Krzysztof Kozlowski.
>>  - Don't protect max77802 mfd_cells using Kconfig options since mfd core 
>> omits
>>devices that don't match. Suggested by Lee Jones.
>>  - Change mfd driver to be tristate instead of boolean. Suggested by 
>> Mark Brown.
>>  - Change binding "voltage-regulators" property to "regulators" to be 
>> consistent
>>with other PMIC drivers. Suggested by Mark Brown.
>>  - Use regulators node names instead of the deprecated 
>> "regulator-compatible"
>>property. Suggested by Mark Brown.
>>  - Use the new descriptor-based GPIO interface instead of the deprecated
>> ---
>>  drivers/mfd/Kconfig  |   6 +-
>>  drivers/mfd/max77686.c   | 187 ++-
>>  include/linux/mfd/max77686-private.h | 208 
>> ++-
>>  include/linux/mfd/max77686.h |  60 +-
>>  4 files changed, 428 insertions(+), 33 deletions(-)
>> 
> 
> Three comments below, after fixing:
> Reviewed-by: Krzysztof Kozlowski 
> 
> (...)
> 
>> @@ -55,6 +123,17 @@ static struct regmap_config max77686_rtc_regmap_config = 
>> {
>>  .val_bits = 8,
>>  };
>>  
>> +static struct regmap_config max77802_regmap_config = {
>> +.reg_bits = 8,
>> +.val_bits = 8,
>> +.writeable_reg = max77802_is_accessible_reg,
>> +.readable_reg = max77802_is_accessible_reg,
>> +.precious_reg = max77802_is_precious_reg,
>> +.volatile_reg = max77802_is_volatile_reg,
>> +.name = "max77802-pmic",
>> +.cache_type = REGCACHE_RBTREE,
>> +};
>> +
>>  static const struct regmap_irq max77686_irqs[] = {
>>  /* INT1 interrupts */
>>  { .reg_offset = 0, .mask = MAX77686_INT1_PWRONF_MSK, },
>> @@ -98,9 +177,34 @@ static const struct regmap_irq_chip 
>> max77686_rtc_irq_chip = {
>>  .num_irqs   = ARRAY_SIZE(max77686_rtc_irqs),
>>  };
>>  
>> +static const struct regmap_irq_chip max77802_irq_chip = {
>> +.name   = "max77802-pmic",
>> +.status_base= MAX77802_REG_INT1,
>> +.mask_base  = MAX77802_REG_INT1MSK,
>> +.num_regs   = 2,
>> +.irqs   = max77686_irqs, /* same masks than 77686 */
> 
> "same masks as 77686"
>

Ok

>> +.num_irqs   = ARRAY_SIZE(max77686_irqs),
>> +};
>> +
>> +static const struct regmap_irq_chip max77802_rtc_irq_chip = {
>> +   

Re: [PATCH v6 22/23] rtc: Add driver for Maxim 77802 PMIC Real-Time-Clock

2014-07-04 Thread Javier Martinez Canillas
Hello Krzysztof,

Thanks a lot for your feedback.

On 07/04/2014 01:56 PM, Krzysztof Kozlowski wrote:
> On pią, 2014-07-04 at 11:55 +0200, Javier Martinez Canillas wrote:
>> The MAX7802 PMIC has a Real-Time-Clock (RTC) with two alarms.
>> This patch adds support for the RTC and is based on a driver
>> added by Simon Glass to the Chrome OS kernel 3.8 tree.
>> 
>> Signed-off-by: Javier Martinez Canillas 
>> ---
>> 
>> Changes since v5: None
>> 
>> Changes since v4: None
>> 
>> Changes since v3: None
>> ---
>>  drivers/rtc/Kconfig|  10 +
>>  drivers/rtc/Makefile   |   1 +
>>  drivers/rtc/rtc-max77802.c | 637 
>> +
>>  3 files changed, 648 insertions(+)
>>  create mode 100644 drivers/rtc/rtc-max77802.c
>> 
>> diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
>> index a672dd1..243ac72 100644
>> --- a/drivers/rtc/Kconfig
>> +++ b/drivers/rtc/Kconfig
>> @@ -288,6 +288,16 @@ config RTC_DRV_MAX77686
>>This driver can also be built as a module. If so, the module
>>will be called rtc-max77686.
>>  
>> +config RTC_DRV_MAX77802
>> +tristate "Maxim 77802 RTC"
>> +depends on MFD_MAX77686
>> +help
>> +  If you say yes here you will get support for the
>> +  RTC of Maxim MAX77802 PMIC.
>> +
>> +  This driver can also be built as a module. If so, the module
>> +  will be called rtc-max77802.
>> +
>>  config RTC_DRV_RS5C372
>>  tristate "Ricoh R2025S/D, RS5C372A/B, RV5C386, RV5C387A"
>>  help
>> diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
>> index 70347d0..247de78 100644
>> --- a/drivers/rtc/Makefile
>> +++ b/drivers/rtc/Makefile
>> @@ -81,6 +81,7 @@ obj-$(CONFIG_RTC_DRV_MAX8998)  += rtc-max8998.o
>>  obj-$(CONFIG_RTC_DRV_MAX8997)   += rtc-max8997.o
>>  obj-$(CONFIG_RTC_DRV_MAX6902)   += rtc-max6902.o
>>  obj-$(CONFIG_RTC_DRV_MAX77686)  += rtc-max77686.o
>> +obj-$(CONFIG_RTC_DRV_MAX77802)  += rtc-max77802.o
>>  obj-$(CONFIG_RTC_DRV_MC13XXX)   += rtc-mc13xxx.o
>>  obj-$(CONFIG_RTC_DRV_MCP795)+= rtc-mcp795.o
>>  obj-$(CONFIG_RTC_DRV_MSM6242)   += rtc-msm6242.o
>> diff --git a/drivers/rtc/rtc-max77802.c b/drivers/rtc/rtc-max77802.c
>> new file mode 100644
>> index 000..2f4fc2e
>> --- /dev/null
>> +++ b/drivers/rtc/rtc-max77802.c
>> @@ -0,0 +1,637 @@
>> +/*
>> + * RTC driver for Maxim MAX77802
>> + *
>> + * Copyright (C) 2013 Google, Inc
>> + *
>> + * Copyright (C) 2012 Samsung Electronics Co.Ltd
>> + *
>> + *  based on rtc-max8997.c
>> + *
>> + *  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.
>> + *
>> + */
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +/* RTC Control Register */
>> +#define BCD_EN_SHIFT0
>> +#define BCD_EN_MASK (1 << BCD_EN_SHIFT)
>> +#define MODEL24_SHIFT   1
>> +#define MODEL24_MASK(1 << MODEL24_SHIFT)
>> +/* RTC Update Register1 */
>> +#define RTC_UDR_SHIFT   0
>> +#define RTC_UDR_MASK(1 << RTC_UDR_SHIFT)
>> +#define RTC_RBUDR_SHIFT 4
>> +#define RTC_RBUDR_MASK  (1 << RTC_RBUDR_SHIFT)
>> +/* WTSR and SMPL Register */
>> +#define WTSRT_SHIFT 0
>> +#define SMPLT_SHIFT 2
>> +#define WTSR_EN_SHIFT   6
>> +#define SMPL_EN_SHIFT   7
>> +#define WTSRT_MASK  (3 << WTSRT_SHIFT)
>> +#define SMPLT_MASK  (3 << SMPLT_SHIFT)
>> +#define WTSR_EN_MASK(1 << WTSR_EN_SHIFT)
>> +#define SMPL_EN_MASK(1 << SMPL_EN_SHIFT)
>> +/* RTC Hour register */
>> +#define HOUR_PM_SHIFT   6
>> +#define HOUR_PM_MASK(1 << HOUR_PM_SHIFT)
>> +/* RTC Alarm Enable */
>> +#define ALARM_ENABLE_SHIFT  7
>> +#define ALARM_ENABLE_MASK   (1 << ALARM_ENABLE_SHIFT)
>> +
>>

Re: [PATCH v6 22/23] rtc: Add driver for Maxim 77802 PMIC Real-Time-Clock

2014-07-04 Thread Javier Martinez Canillas
Hello Krzysztof,

On 07/04/2014 03:11 PM, Krzysztof Kozlowski wrote:
> On pią, 2014-07-04 at 14:52 +0200, Javier Martinez Canillas wrote:
>> Hello Krzysztof,
>> 
>> Thanks a lot for your feedback.
>> 
>> On 07/04/2014 01:56 PM, Krzysztof Kozlowski wrote:
>> > On pią, 2014-07-04 at 11:55 +0200, Javier Martinez Canillas wrote:
>> >> The MAX7802 PMIC has a Real-Time-Clock (RTC) with two alarms.
>> >> This patch adds support for the RTC and is based on a driver
>> >> added by Simon Glass to the Chrome OS kernel 3.8 tree.
>> >> 
>> >> Signed-off-by: Javier Martinez Canillas 
>> >> ---
>> >> 
>> >> Changes since v5: None
>> >> 
>> >> Changes since v4: None
>> >> 
>> >> Changes since v3: None
>> >> ---
>> >>  drivers/rtc/Kconfig|  10 +
>> >>  drivers/rtc/Makefile   |   1 +
>> >>  drivers/rtc/rtc-max77802.c | 637 
>> >> +
>> >>  3 files changed, 648 insertions(+)
>> >>  create mode 100644 drivers/rtc/rtc-max77802.c
>> >> 
>> >> diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
>> >> index a672dd1..243ac72 100644
>> >> --- a/drivers/rtc/Kconfig
>> >> +++ b/drivers/rtc/Kconfig
>> >> @@ -288,6 +288,16 @@ config RTC_DRV_MAX77686
>> >> This driver can also be built as a module. If so, the module
>> >> will be called rtc-max77686.
>> >>  
>> >> +config RTC_DRV_MAX77802
>> >> + tristate "Maxim 77802 RTC"
>> >> + depends on MFD_MAX77686
>> >> + help
>> >> +   If you say yes here you will get support for the
>> >> +   RTC of Maxim MAX77802 PMIC.
>> >> +
>> >> +   This driver can also be built as a module. If so, the module
>> >> +   will be called rtc-max77802.
>> >> +
>> >>  config RTC_DRV_RS5C372
>> >>   tristate "Ricoh R2025S/D, RS5C372A/B, RV5C386, RV5C387A"
>> >>   help
>> >> diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
>> >> index 70347d0..247de78 100644
>> >> --- a/drivers/rtc/Makefile
>> >> +++ b/drivers/rtc/Makefile
>> >> @@ -81,6 +81,7 @@ obj-$(CONFIG_RTC_DRV_MAX8998)   += rtc-max8998.o
>> >>  obj-$(CONFIG_RTC_DRV_MAX8997)+= rtc-max8997.o
>> >>  obj-$(CONFIG_RTC_DRV_MAX6902)+= rtc-max6902.o
>> >>  obj-$(CONFIG_RTC_DRV_MAX77686)   += rtc-max77686.o
>> >> +obj-$(CONFIG_RTC_DRV_MAX77802)  += rtc-max77802.o
>> >>  obj-$(CONFIG_RTC_DRV_MC13XXX)+= rtc-mc13xxx.o
>> >>  obj-$(CONFIG_RTC_DRV_MCP795) += rtc-mcp795.o
>> >>  obj-$(CONFIG_RTC_DRV_MSM6242)+= rtc-msm6242.o
>> >> diff --git a/drivers/rtc/rtc-max77802.c b/drivers/rtc/rtc-max77802.c
>> >> new file mode 100644
>> >> index 000..2f4fc2e
>> >> --- /dev/null
>> >> +++ b/drivers/rtc/rtc-max77802.c
>> >> @@ -0,0 +1,637 @@
>> >> +/*
>> >> + * RTC driver for Maxim MAX77802
>> >> + *
>> >> + * Copyright (C) 2013 Google, Inc
>> >> + *
>> >> + * Copyright (C) 2012 Samsung Electronics Co.Ltd
>> >> + *
>> >> + *  based on rtc-max8997.c
>> >> + *
>> >> + *  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.
>> >> + *
>> >> + */
>> >> +
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +
>> >> +/* RTC Control Register */
>> >> +#define BCD_EN_SHIFT 0
>> >> +#define BCD_EN_MASK  (1 << BCD_EN_SHIFT)
>> >> +#define MODEL24_SHIFT1
>> >> +#define MODEL24_MASK (1 << MODEL24_SHIFT)
>> >> +/* RTC Update Register1 */
>> >> +#define RTC_UDR_SHIFT0
>> >> +#define RTC_UDR_MASK (1 << RTC_UDR_SHIFT)
>>

[PATCH v7 00/24] Add Maxim 77802 PMIC support

2014-07-04 Thread Javier Martinez Canillas
MAX77802 is a PMIC that contains 10 high efficiency Buck regulators,
32 Low-dropout (LDO) regulators, two 32kHz buffered clock outputs,
a Real-Time-Clock (RTC) and a I2C interface to program the individual
regulators, clocks and the RTC.

This series are based on drivers added by Simon Glass to the Chrome OS
kernel and adds support for the Maxim 77802 Power Management IC, their
regulators, clocks, RTC and I2C interface. The series depend on patch:

"[PATCH v3] ARM: dts: Add cros_ec to exynos5420-peach-pit and 
exynos5800-peach-pi"
https://patchwork.kernel.org/patch/4411351/

which adds tps65090 support to Peach boards since regulators from this
PMIC supply power to a set of MAX77802 regulators.

This is the seventh version of the patch-set that addresses issues pointed
out in v6. Individual changes are added on each patch change log.

Patches 1-17 are cleanups and improvements to the MAX77686 PMIC driver
as a preparation to also support the MAX77802 PMIC. Patch 18 adds support
for MAX77802 to the MAX77686 mfd driver and Patch 19 adds the DT binding
doc for this PMIC. Patch 20 adds support for the regulators in the PMIC,
Patch 21 adds support for the clocks in the PMIC and Patch 22 adds its DT
binding. Patch 23 adds support for the Real-Time-Clock found in the PMIC
and Patch 24 adds the needed device nodes for the max77802 to the Exynos5
base Peach Pit and Pi boards device tree source files.

The patch-set has been tested on both Daisy/Snow (max77686) and Peach
Pit (max77802) Chromebooks and it's composed of the following patches:

Doug Anderson (1):
  rtc: max77686: Allow the max77686 rtc to wakeup the system

Javier Martinez Canillas (23):
  mfd: max77686: Convert to use regmap_irq
  mfd: max77686: Add power management support
  mfd: max77686: Don't define dummy function if OF isn't enabled
  mfd: max77686: Make platform data over-rule DT
  mfd: max77686: Return correct error when pdata isn't found
  mfd: max77686: Make error checking consistent
  mfd: max77686: Remove unneeded OOM error message
  mfd: max77686: Add Dynamic Voltage Scaling (DVS) support
  rtc: max77686: Remove dead code for SMPL and WTSR.
  clk: max77686: Add DT include for MAX77686 PMIC clock
  clk: Add generic driver for Maxim PMIC clocks
  clk: max77686: Convert to the generic max clock driver
  clk: max77686: Improve Maxim 77686 PMIC clocks binding
  regmap: Add regmap_reg_copy function
  regulator: max77686: Setup DVS-related GPIOs on probe
  mfd: max77686: Add documentation for DVS bindings
  mfd: max77686: Add Maxim 77802 PMIC support
  mfd: max77802: Add DT binding documentation
  regulator: Add driver for Maxim 77802 PMIC regulators
  clk: Add driver for Maxim 77802 PMIC clocks
  clk: max77802: Add DT binding documentation
  rtc: Add driver for Maxim 77802 PMIC Real-Time-Clock
  ARM: dts: Add max77802 to exynos5420-peach-pit and exynos5800-peach-pi

 .../devicetree/bindings/clock/maxim,max77686.txt   |  16 +-
 .../devicetree/bindings/clock/maxim,max77802.txt   |  44 ++
 Documentation/devicetree/bindings/mfd/max77686.txt |  34 ++
 Documentation/devicetree/bindings/mfd/max77802.txt |  95 
 arch/arm/boot/dts/exynos5420-peach-pit.dts | 382 +
 arch/arm/boot/dts/exynos5800-peach-pi.dts  | 382 +
 drivers/base/regmap/regmap.c   |  34 ++
 drivers/clk/Kconfig|  11 +
 drivers/clk/Makefile   |   2 +
 drivers/clk/clk-max-gen.c  | 192 +++
 drivers/clk/clk-max-gen.h  |  32 ++
 drivers/clk/clk-max77686.c | 183 +--
 drivers/clk/clk-max77802.c |  98 
 drivers/mfd/Kconfig|   7 +-
 drivers/mfd/Makefile   |   2 +-
 drivers/mfd/max77686-irq.c | 319 ---
 drivers/mfd/max77686.c | 442 +--
 drivers/regulator/Kconfig  |   9 +
 drivers/regulator/Makefile |   1 +
 drivers/regulator/max77686.c   |  34 ++
 drivers/regulator/max77802.c   | 609 +
 drivers/rtc/Kconfig|  10 +
 drivers/rtc/Makefile   |   1 +
 drivers/rtc/rtc-max77686.c | 146 ++---
 drivers/rtc/rtc-max77802.c | 508 +
 include/dt-bindings/clock/maxim,max77686.h |  23 +
 include/dt-bindings/clock/maxim,max77802.h |  22 +
 include/linux/mfd/max77686-private.h   | 237 +++-
 include/linux/mfd/max77686.h   |  78 ++-
 include/linux/regmap.h |   9 +
 30 files changed, 3289 insertions(+), 673 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/clock/maxim,max77802.txt
 create mode 100644 Documen

[PATCH v7 23/24] rtc: Add driver for Maxim 77802 PMIC Real-Time-Clock

2014-07-04 Thread Javier Martinez Canillas
The MAX7802 PMIC has a Real-Time-Clock (RTC) with two alarms.
This patch adds support for the RTC and is based on a driver
added by Simon Glass to the Chrome OS kernel 3.8 tree.

Signed-off-by: Javier Martinez Canillas 
---

Changes since v6:
 - Remove unused code for SMPL and WTSR. Suggested by Krzysztof Kozlowski.
 - Don't spam the kernel log with unimportant info and just print for debug.
   Suggested by Krzysztof Kozlowski.
 - Use ARRAY_SIZE() instead of constant value. Suggested by Krzysztof Kozlowski.
 - Remove duplicated register setup. Suggested by Krzysztof Kozlowski.
 - Don't free/unregister managed allocated resources.
   Suggested by Krzysztof Kozlowski.
---
 drivers/rtc/Kconfig|  10 +
 drivers/rtc/Makefile   |   1 +
 drivers/rtc/rtc-max77802.c | 508 +
 3 files changed, 519 insertions(+)
 create mode 100644 drivers/rtc/rtc-max77802.c

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index a672dd1..243ac72 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -288,6 +288,16 @@ config RTC_DRV_MAX77686
  This driver can also be built as a module. If so, the module
  will be called rtc-max77686.
 
+config RTC_DRV_MAX77802
+   tristate "Maxim 77802 RTC"
+   depends on MFD_MAX77686
+   help
+ If you say yes here you will get support for the
+ RTC of Maxim MAX77802 PMIC.
+
+ This driver can also be built as a module. If so, the module
+ will be called rtc-max77802.
+
 config RTC_DRV_RS5C372
tristate "Ricoh R2025S/D, RS5C372A/B, RV5C386, RV5C387A"
help
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 70347d0..247de78 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -81,6 +81,7 @@ obj-$(CONFIG_RTC_DRV_MAX8998) += rtc-max8998.o
 obj-$(CONFIG_RTC_DRV_MAX8997)  += rtc-max8997.o
 obj-$(CONFIG_RTC_DRV_MAX6902)  += rtc-max6902.o
 obj-$(CONFIG_RTC_DRV_MAX77686) += rtc-max77686.o
+obj-$(CONFIG_RTC_DRV_MAX77802)  += rtc-max77802.o
 obj-$(CONFIG_RTC_DRV_MC13XXX)  += rtc-mc13xxx.o
 obj-$(CONFIG_RTC_DRV_MCP795)   += rtc-mcp795.o
 obj-$(CONFIG_RTC_DRV_MSM6242)  += rtc-msm6242.o
diff --git a/drivers/rtc/rtc-max77802.c b/drivers/rtc/rtc-max77802.c
new file mode 100644
index 000..f8898ff
--- /dev/null
+++ b/drivers/rtc/rtc-max77802.c
@@ -0,0 +1,508 @@
+/*
+ * RTC driver for Maxim MAX77802
+ *
+ * Copyright (C) 2013 Google, Inc
+ *
+ * Copyright (C) 2012 Samsung Electronics Co.Ltd
+ *
+ *  based on rtc-max8997.c
+ *
+ *  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.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* RTC Control Register */
+#define BCD_EN_SHIFT   0
+#define BCD_EN_MASK(1 << BCD_EN_SHIFT)
+#define MODEL24_SHIFT  1
+#define MODEL24_MASK   (1 << MODEL24_SHIFT)
+/* RTC Update Register1 */
+#define RTC_UDR_SHIFT  0
+#define RTC_UDR_MASK   (1 << RTC_UDR_SHIFT)
+#define RTC_RBUDR_SHIFT4
+#define RTC_RBUDR_MASK (1 << RTC_RBUDR_SHIFT)
+/* RTC Hour register */
+#define HOUR_PM_SHIFT  6
+#define HOUR_PM_MASK   (1 << HOUR_PM_SHIFT)
+/* RTC Alarm Enable */
+#define ALARM_ENABLE_SHIFT 7
+#define ALARM_ENABLE_MASK  (1 << ALARM_ENABLE_SHIFT)
+
+/* For the RTCAE1 register, we write this value to enable the alarm */
+#define ALARM_ENABLE_VALUE 0x77
+
+#define MAX77802_RTC_UPDATE_DELAY_US   200
+
+enum {
+   RTC_SEC = 0,
+   RTC_MIN,
+   RTC_HOUR,
+   RTC_WEEKDAY,
+   RTC_MONTH,
+   RTC_YEAR,
+   RTC_DATE,
+   RTC_NR_TIME
+};
+
+struct max77802_rtc_info {
+   struct device   *dev;
+   struct max77686_dev *max77802;
+   struct i2c_client   *rtc;
+   struct rtc_device   *rtc_dev;
+   struct mutexlock;
+
+   struct regmap   *regmap;
+
+   int virq;
+   int rtc_24hr_mode;
+};
+
+enum MAX77802_RTC_OP {
+   MAX77802_RTC_WRITE,
+   MAX77802_RTC_READ,
+};
+
+static inline int max77802_rtc_calculate_wday(u8 shifted)
+{
+   int counter = -1;
+
+   while (shifted) {
+   shifted >>= 1;
+   counter++;
+   }
+
+   return counter;
+}
+
+static void max77802_rtc_data_to_tm(u8 *data, struct rtc_time *tm,
+  int rtc_24hr_mode)
+{
+   tm->tm_sec = data[RTC_SEC] & 0xff;
+   tm->tm_min = data[RTC_MIN] & 0xff;
+   if (rtc_24hr_mode)
+   tm->tm_hour = data[RTC_HOUR] & 0x1f;
+   

[PATCH v7 24/24] ARM: dts: Add max77802 to exynos5420-peach-pit and exynos5800-peach-pi

2014-07-04 Thread Javier Martinez Canillas
Peach pit and pi boards uses a Maxim 77802 power management
IC to drive regulators and its Real Time Clock. This patch
adds support for this chip.

These are the device nodes and pinctrl configuration that
are present on the Peach pit DeviceTree source file in the
the Chrome OS kernel 3.8 tree.

Signed-off-by: Javier Martinez Canillas 
Tested-by: Naveen Krishna Chatradhi 
---

Changes since v6: None

Changes since v5:
 - Fix style issues and a typo on peach pit and pi DTS.
   Suggested by Tushar Behera.

Changes since v4: None

Changes since v3:
 - Add support for Exynos5800 based Peach pi board. Suggested by Doug Anderson.
 - Model the actual regulators relationship instead of a simplistic model.
   Suggested by Mark Brown.

Changes since v2: None

Changes since v1:
 - Use "regulators" for child node instead of "voltage-regulators" to be
   consistent with other PMIC. Suggested by Mark Brown.
 - Use regulators node names instead of the deprecated "regulator-compatible"
   property. Suggested by Mark Brown.
---
 arch/arm/boot/dts/exynos5420-peach-pit.dts | 382 +
 arch/arm/boot/dts/exynos5800-peach-pi.dts  | 382 +
 2 files changed, 764 insertions(+)

diff --git a/arch/arm/boot/dts/exynos5420-peach-pit.dts 
b/arch/arm/boot/dts/exynos5420-peach-pit.dts
index b2f1237..99768d7 100644
--- a/arch/arm/boot/dts/exynos5420-peach-pit.dts
+++ b/arch/arm/boot/dts/exynos5420-peach-pit.dts
@@ -143,6 +143,350 @@
ddc = <&i2c_2>;
 };
 
+&hsi2c_4 {
+   status = "okay";
+   clock-frequency = <40>;
+
+   max77802-pmic@9 {
+   compatible = "maxim,max77802";
+   interrupt-parent = <&gpx3>;
+   interrupts = <1 0>;
+   pinctrl-names = "default";
+   pinctrl-0 = <&max77802_irq>, <&pmic_selb>,
+   <&pmic_dvs_1>, <&pmic_dvs_2>, <&pmic_dvs_3>;
+   wakeup-source;
+   reg = <0x9>;
+   #clock-cells = <1>;
+
+   /* Using idx 1 means warm reset will get good voltage */
+   max77686,pmic-buck-default-dvs-idx = <1>;
+   max77686,pmic-buck-dvs-gpios = <&gpy7 6 GPIO_ACTIVE_HIGH>,
+  <&gpj4 2 GPIO_ACTIVE_HIGH>,
+  <&gpj4 3 GPIO_ACTIVE_HIGH>;
+   max77686,pmic-buck-selb-gpios = <&gph0 2 GPIO_ACTIVE_HIGH>,
+   <&gph0 3 GPIO_ACTIVE_HIGH>,
+   <&gph0 4 GPIO_ACTIVE_HIGH>,
+   <&gph0 5 GPIO_ACTIVE_HIGH>,
+   <&gph0 6 GPIO_ACTIVE_HIGH>;
+
+   inb1-supply = <&tps65090_dcdc2>;
+   inb2-supply = <&tps65090_dcdc1>;
+   inb3-supply = <&tps65090_dcdc2>;
+   inb4-supply = <&tps65090_dcdc2>;
+   inb5-supply = <&tps65090_dcdc1>;
+   inb6-supply = <&tps65090_dcdc2>;
+   inb7-supply = <&tps65090_dcdc1>;
+   inb8-supply = <&tps65090_dcdc1>;
+   inb9-supply = <&tps65090_dcdc1>;
+   inb10-supply = <&tps65090_dcdc1>;
+
+   inl1-supply = <&buck5_reg>;
+   inl2-supply = <&buck7_reg>;
+   inl3-supply = <&buck9_reg>;
+   inl4-supply = <&buck9_reg>;
+   inl5-supply = <&buck9_reg>;
+   inl6-supply = <&tps65090_dcdc2>;
+   inl7-supply = <&buck9_reg>;
+   inl9-supply = <&tps65090_dcdc2>;
+   inl10-supply = <&buck7_reg>;
+
+   regulators {
+   buck1_reg: BUCK1 {
+   regulator-name = "vdd_mif";
+   regulator-min-microvolt = <80>;
+   regulator-max-microvolt = <130>;
+   regulator-always-on;
+   regulator-boot-on;
+   regulator-ramp-delay = <12500>;
+   };
+
+   buck2_reg: BUCK2 {
+   regulator-name = "vdd_arm_real";
+   regulator-min-microvolt = <80>;
+   regulator-max-microvolt = <150>;
+   regulator-always-on;
+   regulator-boot-on;
+  

[PATCH v7 20/24] regulator: Add driver for Maxim 77802 PMIC regulators

2014-07-04 Thread Javier Martinez Canillas
The MAX77802 PMIC has 10 high-efficiency Buck and 32 Low-dropout
(LDO) regulators. This patch adds support for all these regulators
found on the MAX77802 PMIC and is based on a driver added by Simon
Glass to the Chrome OS kernel 3.8 tree.

Signed-off-by: Javier Martinez Canillas 
Tested-by: Naveen Krishna Chatradhi 
---

Changes since v6: None

Changes since v5:
 - Take out the mfd changes from v4 that were squashed by mistake.
   Suggested by Lee Jones.

Changes since v4: None

Changes since v3:
 - Set the supply_name for regulators to lookup their parent supply node.
   Suggested by Mark Brown.
 - Change Exyno5 for Exynos5420/Exynos5800 in regulator driver Kconfig.
   Suggested by Doug Anderson.
---
 drivers/regulator/Kconfig|   9 +
 drivers/regulator/Makefile   |   1 +
 drivers/regulator/max77802.c | 609 +++
 3 files changed, 619 insertions(+)
 create mode 100644 drivers/regulator/max77802.c

diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index 789eb46..96d1c68 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -377,6 +377,15 @@ config REGULATOR_MAX77693
  and one current regulator 'CHARGER'. This is suitable for
  Exynos-4x12 chips.
 
+config REGULATOR_MAX77802
+   tristate "Maxim 77802 regulator"
+   depends on MFD_MAX77686
+   help
+ This driver controls a Maxim 77802 regulator
+ via I2C bus. The provided regulator is suitable for
+ Exynos5420/Exynos5800 SoCs to control various voltages.
+ It includes support for control of voltage and ramp speed.
+
 config REGULATOR_MC13XXX_CORE
tristate
 
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index d461110..2aea4b6 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -51,6 +51,7 @@ obj-$(CONFIG_REGULATOR_MAX8997) += max8997.o
 obj-$(CONFIG_REGULATOR_MAX8998) += max8998.o
 obj-$(CONFIG_REGULATOR_MAX77686) += max77686.o
 obj-$(CONFIG_REGULATOR_MAX77693) += max77693.o
+obj-$(CONFIG_REGULATOR_MAX77802) += max77802.o
 obj-$(CONFIG_REGULATOR_MC13783) += mc13783-regulator.o
 obj-$(CONFIG_REGULATOR_MC13892) += mc13892-regulator.o
 obj-$(CONFIG_REGULATOR_MC13XXX_CORE) +=  mc13xxx-regulator-core.o
diff --git a/drivers/regulator/max77802.c b/drivers/regulator/max77802.c
new file mode 100644
index 000..23b2488
--- /dev/null
+++ b/drivers/regulator/max77802.c
@@ -0,0 +1,609 @@
+/*
+ * max77802.c - Regulator driver for the Maxim 77802
+ *
+ * Copyright (C) 2013-2014 Google, Inc
+ * Simon Glass 
+ *
+ * Copyright (C) 2012 Samsung Electronics
+ * Chiwoong Byun 
+ * Jonghwa Lee 
+ *
+ * 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.
+ *
+ * This driver is based on max8997.c
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* Default ramp delay in case it is not manually set */
+#define MAX77802_RAMP_DELAY10  /* uV/us */
+
+#define MAX77802_OPMODE_SHIFT_LDO  6
+#define MAX77802_OPMODE_BUCK234_SHIFT  4
+#define MAX77802_OPMODE_MASK   0x3
+
+#define MAX77802_VSEL_MASK 0x3F
+#define MAX77802_DVS_VSEL_MASK 0xFF
+
+#define MAX77802_RAMP_RATE_MASK_2BIT   0xC0
+#define MAX77802_RAMP_RATE_SHIFT_2BIT  6
+#define MAX77802_RAMP_RATE_MASK_4BIT   0xF0
+#define MAX77802_RAMP_RATE_SHIFT_4BIT  4
+
+/* MAX77802 has two register formats: 2-bit and 4-bit */
+static const unsigned int ramp_table_77802_2bit[] = {
+   12500,
+   25000,
+   5,
+   10,
+};
+
+static unsigned int ramp_table_77802_4bit[] = {
+   1000,   2000,   3030,   4000,
+   5000,   5880,   7140,   8330,
+   9090,   1,  0,  12500,
+   16670,  25000,  5,  10,
+};
+
+struct max77802_regulator_prv {
+   int num_regulators;
+   struct regulator_dev *rdev[MAX77802_REG_MAX];
+   unsigned int opmode[MAX77802_REG_MAX];
+};
+
+static int max77802_get_opmode_shift(int id)
+{
+   if (id >= MAX77802_LDO1 && id <= MAX77802_LDO35)
+   return MAX77802_OPMODE_SHIFT_LDO;
+   else if (id == MAX77802_BUCK1 || (id >= MAX77802_BUCK5 &&
+ id <= MAX77802_BUCK10))
+   return 0;
+   else if (id >= MAX77802_BUCK2 && id <= MAX77802_BUCK4)
+   return MAX77802_OPMODE_BUCK234_SHIFT;
+   else
+   return -EINVAL;
+}
+
+/*
+ * Some BU

[PATCH v7 19/24] mfd: max77802: Add DT binding documentation

2014-07-04 Thread Javier Martinez Canillas
Add Device Tree binding documentation for Maxim 77802 PMIC.

Signed-off-by: Javier Martinez Canillas 
---

Changes since v6: None

Changes since v5:
 - Use max77686,* properties instead of max77802,* since the support is
   now in the max77686 driver and that IP defined the properties first.
 - Fix issues in DT binding documentation. Suggested by Andreas Farber.

Changes since v4: None

Changes since v3: None

Changes since v2:
 - Explain better the Dynamic Voltage Scaling (DVS) support in some Buck
   regulators and the max77802,pmic-buck-{dvs,selb}-gpios properties.
   Suggested by Mark Brown.
---
 Documentation/devicetree/bindings/mfd/max77802.txt | 95 ++
 1 file changed, 95 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/max77802.txt

diff --git a/Documentation/devicetree/bindings/mfd/max77802.txt 
b/Documentation/devicetree/bindings/mfd/max77802.txt
new file mode 100644
index 000..5460e20
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/max77802.txt
@@ -0,0 +1,95 @@
+Maxim MAX77802 multi-function device
+
+MAX77802 is a Multifunction device with PMIC, RTC and Charger on chip. It is
+interfaced to host controller using i2c interface. PMIC, Charger and RTC
+submodules are addressed using same i2c slave address.
+
+Buck regulators 1, 2, 3, 4 and 6 include Dynamic Voltage Scaling (DVS) that
+allows each output voltage to change dynamically. Each Buck output voltage
+is selected using a set of external inputs: DVS1-3 and SELB1, 2, 3, 4 and 6.
+
+There are 8 DVS registers that can be used to configure the output voltage
+for each Buck regulator and which one is active is controled by DVSx lines.
+
+SELBx lines are used to control if individual Buck lines are ON or OFF.
+
+This document describes the binding for mfd device and PMIC submodule.
+
+Binding for the built-in 32k clock generator block is defined separately
+in bindings/clk/maxim,max77802.txt file.
+
+Required properties:
+- compatible : Must be "maxim,max77802";
+- reg : Specifies the i2c slave address of PMIC block.
+- interrupts : This i2c device has an IRQ line connected to the main SoC.
+- interrupt-parent : The parent interrupt controller.
+
+Optional properties:
+- max77686,pmic-buck-default-dvs-idx: We'll always write this DVS index in the
+  PMIC for Bucks with DVS.
+  NOTE: at the moment these bindings don't include enough details for actual
+  GPIO-DVS--this just lets you choose which single slot to use.
+
+- max77686,pmic-buck-dvs-gpios: A GPIO array where each GPIO is connected to a
+  DVS line. We'll try to set these GPIOs to match pmic-buck-default-dvs-idx at
+  probe time if they are defined. If some or all of these GPIOs are not defined
+  it's assumed that the board has any missing GPIOs hardwired to match
+  pmic-buck-default-dvs-idx.
+
+- max77686,pmic-buck-selb-gpios: A GPIO array where each GPIO is connected to a
+  SELBx line. Should be five values: 1, 2, 3, 4, 6. It is strongly suggested to
+  include these GPIOs if there's any chance that changing DVS GPIOs one line at
+  a time might glitch your DVS values.
+
+Optional node:
+- regulators : The regulators of max77802 have to be instantiated
+  under subnode named "regulators" using the following format.
+
+   regulator-name {
+   standard regulator constraints
+   };
+   refer Documentation/devicetree/bindings/regulator/regulator.txt
+
+  The regulator node name should be initialized with a string
+to get matched with their hardware counterparts as follow. The valid names are:
+
+   -LDOn   :   for LDOs, where n can lie in range 1 to 35.
+   example: LDO1, LDO2, LDO35.
+   -BUCKn  :   for BUCKs, where n can lie in range 1 to 10.
+   example: BUCK1, BUCK5, BUCK10.
+Example:
+
+   max77802@09 {
+   compatible = "maxim,max77802";
+   interrupt-parent = <&wakeup_eint>;
+   interrupts = <26 0>;
+   reg = <0x09>;
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   max77686,pmic-buck-default-dvs-idx = <1>;
+   max77686,pmic-buck-dvs-gpios = <&gpy7 6 0>,
+  <&gpj4 2 0>,
+  <&gpj4 3 0>;
+   max77686,pmic-buck-selb-gpios = <&gph0 2 0>,
+   <&gph0 3 0>,
+   <&gph0 4 0>,
+   <&gph0 5 0>,
+   <&gph0 6 0>;
+
+   regulators {
+   ldo11_reg: LDO11 {
+   regulator-name = "vdd_ldo11";
+   

[PATCH v7 22/24] clk: max77802: Add DT binding documentation

2014-07-04 Thread Javier Martinez Canillas
Add Device Tree binding documentation for the clocks
outputs in the Maxim 77802 Power Management IC.

Signed-off-by: Javier Martinez Canillas 
---

Changes since v6: None

Changes since v5:
 - Fix typo error in DT binding. Suggested by Andreas Farber.
 - Add "clock-output-names" as an optional property since now is supported.

Changes since v4: None

Changes since v3:
 - Don't use the same clock driver name in clock-names since it's a consumer
   concept and most probably will be different. Suggested by Doug Anderson.

Changes since v2:
 - Split the DT binding documentation in a separate patch.
---
 .../devicetree/bindings/clock/maxim,max77802.txt   | 44 ++
 1 file changed, 44 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/maxim,max77802.txt

diff --git a/Documentation/devicetree/bindings/clock/maxim,max77802.txt 
b/Documentation/devicetree/bindings/clock/maxim,max77802.txt
new file mode 100644
index 000..c6dc783
--- /dev/null
+++ b/Documentation/devicetree/bindings/clock/maxim,max77802.txt
@@ -0,0 +1,44 @@
+Binding for Maxim MAX77802 32k clock generator block
+
+This is a part of device tree bindings of MAX77802 multi-function device.
+More information can be found in bindings/mfd/max77802.txt file.
+
+The MAX77802 contains two 32.768khz clock outputs that can be controlled
+(gated/ungated) over I2C.
+
+Following properties should be present in main device node of the MFD chip.
+
+Required properties:
+- #clock-cells: From common clock binding; shall be set to 1.
+
+Optional properties:
+- clock-output-names: From common clock binding.
+
+Each clock is assigned an identifier and client nodes can use this identifier
+to specify the clock which they consume. Following indices are allowed:
+ - 0: 32khz_ap clock,
+ - 1: 32khz_cp clock.
+
+Clocks are defined as preprocessor macros in dt-bindings/clock/maxim,max77802.h
+header and can be used in device tree sources.
+
+Example: Node of the MFD chip
+
+   max77802: max77802@09 {
+   compatible = "maxim,max77802";
+   interrupt-parent = <&wakeup_eint>;
+   interrupts = <26 0>;
+   reg = <0x09>;
+   #clock-cells = <1>;
+
+   /* ... */
+   };
+
+Example: Clock consumer node
+
+   foo@0 {
+   compatible = "bar,foo";
+   /* ... */
+   clock-names = "my-clock";
+   clocks = <&max77802 MAX77802_CLK_32K_AP>;
+   };
-- 
2.0.0.rc2

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 21/24] clk: Add driver for Maxim 77802 PMIC clocks

2014-07-04 Thread Javier Martinez Canillas
The MAX77802 PMIC has two 32.768kHz Buffered Clock Outputs with
Low Jitter Mode. This patch adds support for these two clocks.

Signed-off-by: Javier Martinez Canillas 
Reviewed-by: Krzysztof Kozlowski 
---

Changes since v6: None

Changes since v5: None

Changes since v4: None

Changes since v3: None

Changes since v2: None

Changes since v1:
 - Use module_platform_driver() instead of having init/exit functions.
   Suggested by Mark Brown.
 - Use the generic maxim clock driver to reduce code duplication with
   clk-max77686.c driver.
---
 drivers/clk/Kconfig|  7 +++
 drivers/clk/Makefile   |  1 +
 drivers/clk/clk-max77802.c | 98 ++
 include/dt-bindings/clock/maxim,max77802.h | 22 +++
 4 files changed, 128 insertions(+)
 create mode 100644 drivers/clk/clk-max77802.c
 create mode 100644 include/dt-bindings/clock/maxim,max77802.h

diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
index 3fd4270..8808f2a 100644
--- a/drivers/clk/Kconfig
+++ b/drivers/clk/Kconfig
@@ -42,6 +42,13 @@ config COMMON_CLK_MAX77686
---help---
  This driver supports Maxim 77686 crystal oscillator clock. 
 
+config COMMON_CLK_MAX77802
+   tristate "Clock driver for Maxim 77802 PMIC"
+   depends on MFD_MAX77686
+   select COMMON_CLK_MAX_GEN
+   ---help---
+ This driver supports Maxim 77802 crystal oscillator clock.
+
 config COMMON_CLK_SI5351
tristate "Clock driver for SiLabs 5351A/B/C"
depends on I2C
diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
index 6c1aff6..520ff76 100644
--- a/drivers/clk/Makefile
+++ b/drivers/clk/Makefile
@@ -20,6 +20,7 @@ obj-$(CONFIG_ARCH_HIGHBANK)   += clk-highbank.o
 obj-$(CONFIG_MACH_LOONGSON1)   += clk-ls1x.o
 obj-$(CONFIG_COMMON_CLK_MAX_GEN)   += clk-max-gen.o
 obj-$(CONFIG_COMMON_CLK_MAX77686)  += clk-max77686.o
+obj-$(CONFIG_COMMON_CLK_MAX77802)  += clk-max77802.o
 obj-$(CONFIG_ARCH_MOXART)  += clk-moxart.o
 obj-$(CONFIG_ARCH_NOMADIK) += clk-nomadik.o
 obj-$(CONFIG_ARCH_NSPIRE)  += clk-nspire.o
diff --git a/drivers/clk/clk-max77802.c b/drivers/clk/clk-max77802.c
new file mode 100644
index 000..8e480c5
--- /dev/null
+++ b/drivers/clk/clk-max77802.c
@@ -0,0 +1,98 @@
+/*
+ * clk-max77802.c - Clock driver for Maxim 77802
+ *
+ * Copyright (C) 2014 Google, Inc
+ *
+ * Copyright (C) 2012 Samsung Electornics
+ * Jonghwa Lee 
+ *
+ * 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.
+ *
+ * This driver is based on clk-max77686.c
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include "clk-max-gen.h"
+
+#define MAX77802_CLOCK_OPMODE_MASK 0x1
+#define MAX77802_CLOCK_LOW_JITTER_SHIFT 0x3
+
+static struct clk_init_data max77802_clks_init[MAX77802_CLKS_NUM] = {
+   [MAX77802_CLK_32K_AP] = {
+   .name = "32khz_ap",
+   .ops = &max_gen_clk_ops,
+   .flags = CLK_IS_ROOT,
+   },
+   [MAX77802_CLK_32K_CP] = {
+   .name = "32khz_cp",
+   .ops = &max_gen_clk_ops,
+   .flags = CLK_IS_ROOT,
+   },
+};
+
+static int max77802_clk_probe(struct platform_device *pdev)
+{
+   struct max77686_dev *iodev = dev_get_drvdata(pdev->dev.parent);
+   int ret;
+
+   ret = max_gen_clk_probe(pdev, iodev->regmap, MAX77802_REG_32KHZ,
+   max77802_clks_init, MAX77802_CLKS_NUM);
+
+   if (ret) {
+   dev_err(&pdev->dev, "generic probe failed %d\n", ret);
+   return ret;
+   }
+
+   /* Enable low-jitter mode on the 32khz clocks. */
+   ret = regmap_update_bits(iodev->regmap, MAX77802_REG_32KHZ,
+1 << MAX77802_CLOCK_LOW_JITTER_SHIFT,
+1 << MAX77802_CLOCK_LOW_JITTER_SHIFT);
+   if (ret < 0)
+   dev_err(&pdev->dev, "failed to enable low-jitter mode\n");
+
+   return ret;
+}
+
+static int max77802_clk_remove(struct platform_device *pdev)
+{
+   return max_gen_clk_remove(pdev, MAX77802_CLKS_NUM);
+}
+
+static const struct platform_device_id max77802_clk_id[] = {
+   { "max77802-clk", 0},
+   { },
+};
+MODULE_DEVICE_TABLE(platform, max77802_clk_id);
+
+static struct platform_driver max77802_clk_driver = {
+   .driver = {

[PATCH v7 18/24] mfd: max77686: Add Maxim 77802 PMIC support

2014-07-04 Thread Javier Martinez Canillas
Maxim MAX77802 is a power management chip that contains 10 high
efficiency Buck regulators, 32 Low-dropout (LDO) regulators used
to power up application processors and peripherals, a 2-channel
32kHz clock outputs, a Real-Time-Clock (RTC) and a I2C interface
to program the individual regulators, clocks outputs and the RTC.

This patch adds support for MAX77802 to the MAX77686 driver and is
based on a driver added to the Chrome OS kernel 3.8 by Simon Glass.

Signed-off-by: Javier Martinez Canillas 
Reviewed-by: Krzysztof Kozlowski 
---

Changes since v6:
 - Fix comments grammar. Suggested by Krzysztof Kozlowski.
 - Only unregister the RTC i2c device if the type is MAX77686.
   Suggested by Krzysztof Kozlowski.

Changes since v5:
 - Extend the 77686 driver to support 77802 instead of adding a new driver.
   Suggested by Lee Jones.

Changes since v4:
 - Use consistent expressions when checking for NULL values.
   Suggested by Krzysztof Kozlowski.
 - Remove unused defines. Suggested by Krzysztof Kozlowski.
 - Explain why IRQ is disabled on suspend. Suggested by Krzysztof Kozlowski.

Changes since v3:
 - Remove unnecessary OOM error message since the mm subsystem already logs it.

Changes since v2:
 - Split the DT binding docs in a separate patch and improve the documentation.
   Suggested by Mark Brown.
 - Add all the devices in the MFD driver instead of doing in separate patches.
   Suggested by Mark Brown.

Changes since v1:
 - Convert max77{686,802} to regmap irq API and get rid of max77{686,802}-irq.c
   Suggested by Krzysztof Kozlowski.
 - Don't protect max77802 mfd_cells using Kconfig options since mfd core omits
   devices that don't match. Suggested by Lee Jones.
 - Change mfd driver to be tristate instead of boolean. Suggested by Mark Brown.
 - Change binding "voltage-regulators" property to "regulators" to be consistent
   with other PMIC drivers. Suggested by Mark Brown.
 - Use regulators node names instead of the deprecated "regulator-compatible"
   property. Suggested by Mark Brown.
 - Use the new descriptor-based GPIO interface instead of the deprecated
---
 drivers/mfd/Kconfig  |   6 +-
 drivers/mfd/max77686.c   | 190 +++-
 include/linux/mfd/max77686-private.h | 208 ++-
 include/linux/mfd/max77686.h |  60 +-
 4 files changed, 430 insertions(+), 34 deletions(-)

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 3010204..de5abf2 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -380,15 +380,15 @@ config MFD_MAX14577
  of the device.
 
 config MFD_MAX77686
-   bool "Maxim Semiconductor MAX77686 PMIC Support"
+   bool "Maxim Semiconductor MAX77686/802 PMIC Support"
depends on I2C=y
select MFD_CORE
select REGMAP_I2C
select REGMAP_IRQ
select IRQ_DOMAIN
help
- Say yes here to add support for Maxim Semiconductor MAX77686.
- This is a Power Management IC with RTC on chip.
+ Say yes here to add support for Maxim Semiconductor MAX77686 and
+ MAX77802 which are Power Management IC with an RTC on chip.
  This driver provides common support for accessing the device;
  additional drivers must be enabled in order to use the functionality
  of the device.
diff --git a/drivers/mfd/max77686.c b/drivers/mfd/max77686.c
index d193873..17d5cb3 100644
--- a/drivers/mfd/max77686.c
+++ b/drivers/mfd/max77686.c
@@ -1,5 +1,5 @@
 /*
- * max77686.c - mfd core driver for the Maxim 77686
+ * max77686.c - mfd core driver for the Maxim 77686/802
  *
  * Copyright (C) 2012 Samsung Electronics
  * Chiwoong Byun 
@@ -45,6 +45,74 @@ static const struct mfd_cell max77686_devs[] = {
{ .name = "max77686-clk", },
 };
 
+static const struct mfd_cell max77802_devs[] = {
+   { .name = "max77802-pmic", },
+   { .name = "max77802-clk", },
+   { .name = "max77802-rtc", },
+};
+
+static bool max77802_pmic_is_accessible_reg(struct device *dev,
+   unsigned int reg)
+{
+   return (reg >= MAX77802_REG_DEVICE_ID && reg < MAX77802_REG_PMIC_END);
+}
+
+static bool max77802_rtc_is_accessible_reg(struct device *dev,
+  unsigned int reg)
+{
+   return (reg >= MAX77802_RTC_INT && reg < MAX77802_RTC_END);
+}
+
+static bool max77802_is_accessible_reg(struct device *dev, unsigned int reg)
+{
+   return (max77802_pmic_is_accessible_reg(dev, reg) ||
+   max77802_rtc_is_accessible_reg(dev, reg));
+}
+
+static bool max77802_pmic_is_precious_reg(struct device *dev, unsigned int reg)
+{
+   return (reg == MAX77802_REG_INTSRC || reg == MAX77802_REG_INT1 ||
+   reg == MAX77802_REG_INT2);
+}
+
+static bool max77802_rtc_is_precious_reg(struct device *dev, un

[PATCH v7 16/24] regulator: max77686: Setup DVS-related GPIOs on probe

2014-07-04 Thread Javier Martinez Canillas
MAX77686 PMIC support Dyamic Voltage Scaling (DVS) on a set
of Buck regulators. A number of GPIO are connected to these
lines and are requested by the mfd driver. Setup the GPIO
pins from the regulator driver.

Signed-off-by: Javier Martinez Canillas 
---
 drivers/regulator/max77686.c | 34 ++
 1 file changed, 34 insertions(+)

diff --git a/drivers/regulator/max77686.c b/drivers/regulator/max77686.c
index ef1af2d..ecce77a 100644
--- a/drivers/regulator/max77686.c
+++ b/drivers/regulator/max77686.c
@@ -435,6 +435,12 @@ static int max77686_pmic_dt_parse_pdata(struct 
platform_device *pdev,
 }
 #endif /* CONFIG_OF */
 
+static inline bool max77686_is_dvs_buck(int id)
+{
+   /* BUCK 2,3 and 4 support DVS */
+   return (id >= MAX77686_BUCK2 && id <= MAX77686_BUCK4);
+}
+
 static int max77686_pmic_probe(struct platform_device *pdev)
 {
struct max77686_dev *iodev = dev_get_drvdata(pdev->dev.parent);
@@ -442,6 +448,9 @@ static int max77686_pmic_probe(struct platform_device *pdev)
struct max77686_data *max77686;
int i, ret = 0;
struct regulator_config config = { };
+   unsigned int reg;
+   int buck_default_idx;
+   int buck_old_idx;
 
dev_dbg(&pdev->dev, "%s\n", __func__);
 
@@ -472,13 +481,34 @@ static int max77686_pmic_probe(struct platform_device 
*pdev)
config.driver_data = max77686;
platform_set_drvdata(pdev, max77686);
 
+   buck_default_idx = pdata->buck_default_idx;
+   buck_old_idx = max77686_read_gpios(pdata);
+
for (i = 0; i < MAX77686_REGULATORS; i++) {
struct regulator_dev *rdev;
+   int id = pdata->regulators[i].id;
 
config.init_data = pdata->regulators[i].initdata;
config.of_node = pdata->regulators[i].of_node;
 
max77686->opmode[i] = regulators[i].enable_mask;
+
+   if (max77686_is_dvs_buck(id)) {
+   /* Try to copy over data so we keep firmware settings */
+   reg = regulators[i].vsel_reg;
+
+   ret = regmap_reg_copy(iodev->regmap,
+ reg + buck_default_idx,
+ reg + buck_old_idx);
+
+   if (ret)
+   dev_warn(&pdev->dev, "Copy err %d => %d (%d)\n",
+reg + buck_old_idx,
+reg + buck_default_idx, ret);
+
+   regulators[i].vsel_reg += buck_default_idx;
+   }
+
rdev = devm_regulator_register(&pdev->dev,
®ulators[i], &config);
if (IS_ERR(rdev)) {
@@ -488,6 +518,10 @@ static int max77686_pmic_probe(struct platform_device 
*pdev)
}
}
 
+   ret = max77686_setup_gpios(iodev->dev);
+   if (ret)
+   return ret;
+
return 0;
 }
 
-- 
2.0.0.rc2

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 14/24] clk: max77686: Improve Maxim 77686 PMIC clocks binding

2014-07-04 Thread Javier Martinez Canillas
Like most clock drivers, the Maxim 77686 PMIC clock binding
follows the convention that the "#clock-cells" property is
used to specify the number of cells in a clock provider.

But the binding document is not clear enough that it shall
be set to 1 since the PMIC support multiple clocks outputs.

Also, explain that the clocks identifiers are defined in a
header file that can be included by Device Tree source with
client nodes to avoid using magic numbers.

Finally, add "clock-output-names" as an optional property
since now is supported by the clock driver.

Signed-off-by: Javier Martinez Canillas 
Reviewed-by: Krzysztof Kozlowski 
Reviewed-by: Doug Anderson 
Reviewed-by: Mike Turquette 
---

Changes since v6: None

Changes since v5:
 - Fix generic driver changes merged into max77802 clock patch by mistake.
   Suggested by Yadwinder Singh Brar.
 - Register clock lookups using clk_register_clkdev() instead of doing manually.
 - Use the managed devm_clk_register() function and remove clk un-registration.
 - Add "clock-output-names" property support. Suggested by Yadwinder Singh Brar.
 - Return the rate unconditionally in recalc_rate. Suggested by Mike Turquette.

Changes since v4: None

Changes since v3:
 - Don't change clock-names property to make clear that it's
   the consumer clock name and should not match the producer clock.
   Suggested by Doug Anderson.
---
 .../devicetree/bindings/clock/maxim,max77686.txt | 16 
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/Documentation/devicetree/bindings/clock/maxim,max77686.txt 
b/Documentation/devicetree/bindings/clock/maxim,max77686.txt
index 96ce71b..9c40739 100644
--- a/Documentation/devicetree/bindings/clock/maxim,max77686.txt
+++ b/Documentation/devicetree/bindings/clock/maxim,max77686.txt
@@ -9,13 +9,21 @@ The MAX77686 contains three 32.768khz clock outputs that can 
be controlled
 Following properties should be presend in main device node of the MFD chip.
 
 Required properties:
-- #clock-cells: simple one-cell clock specifier format is used, where the
-  only cell is used as an index of the clock inside the provider. Following
-  indices are allowed:
+
+- #clock-cells: from common clock binding; shall be set to 1.
+
+Optional properties:
+- clock-output-names: From common clock binding.
+
+Each clock is assigned an identifier and client nodes can use this identifier
+to specify the clock which they consume. Following indices are allowed:
 - 0: 32khz_ap clock,
 - 1: 32khz_cp clock,
 - 2: 32khz_pmic clock.
 
+Clocks are defined as preprocessor macros in dt-bindings/clock/maxim,max77686.h
+header and can be used in device tree sources.
+
 Example: Node of the MFD chip
 
max77686: max77686@09 {
@@ -34,5 +42,5 @@ Example: Clock consumer node
compatible = "bar,foo";
/* ... */
clock-names = "my-clock";
-   clocks = <&max77686 2>;
+   clocks = <&max77686 MAX77686_CLK_PMIC>;
};
-- 
2.0.0.rc2

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 17/24] mfd: max77686: Add documentation for DVS bindings

2014-07-04 Thread Javier Martinez Canillas
The MAX77686 PMIC submodule has Dynamic Voltage Scaling (DVS)
support on some regulators. Now that the regulator driver has
bindings to configure it, these bindings have to be documented.

Signed-off-by: Javier Martinez Canillas 
---
 Documentation/devicetree/bindings/mfd/max77686.txt | 34 ++
 1 file changed, 34 insertions(+)

diff --git a/Documentation/devicetree/bindings/mfd/max77686.txt 
b/Documentation/devicetree/bindings/mfd/max77686.txt
index 678f3cf..daf1c07 100644
--- a/Documentation/devicetree/bindings/mfd/max77686.txt
+++ b/Documentation/devicetree/bindings/mfd/max77686.txt
@@ -10,12 +10,38 @@ PMIC submodule.
 Binding for the built-in 32k clock generator block is defined separately
 in bindings/clk/maxim,max77686.txt file.
 
+Buck regulators 2, 3 and 4 include Dynamic Voltage Scaling (DVS) that allows
+each output voltage to change dynamically. Each Buck output voltage is selected
+using a set of external inputs: DVS1-3 and SELB2, 3 and 4.
+
+There are 8 DVS registers that can be used to configure the output voltage
+for each Buck regulator and which one is active is controled by DVSx lines.
+
+SELBx lines are used to control if individual Buck lines are ON or OFF.
+
 Required properties:
 - compatible : Must be "maxim,max77686";
 - reg : Specifies the i2c slave address of PMIC block.
 - interrupts : This i2c device has an IRQ line connected to the main SoC.
 - interrupt-parent : The parent interrupt controller.
 
+Optional properties:
+- max77686,pmic-buck-default-dvs-idx: We'll always write this DVS index in the
+  PMIC for Bucks with DVS.
+  NOTE: at the moment these bindings don't include enough details for actual
+  GPIO-DVS--this just lets you choose which single slot to use.
+
+- max77686,pmic-buck-dvs-gpios: A GPIO array where each GPIO is connected to a
+  DVS line. We'll try to set these GPIOs to match pmic-buck-default-dvs-idx at
+  probe time if they are defined. If some or all of these GPIOs are not defined
+  it's assumed that the board has any missing GPIOs hardwired to match
+  pmic-buck-default-dvs-idx.
+
+- max77686,pmic-buck-selb-gpios: A GPIO array where each GPIO is connected to a
+  SELBx line. Should be three values: 2, 3 and 4. It is strongly suggested to
+  include these GPIOs if there's any chance that changing DVS GPIOs one line at
+  a time might glitch your DVS values.
+
 Optional node:
 - voltage-regulators : The regulators of max77686 have to be instantiated
   under subnode named "voltage-regulators" using the following format.
@@ -42,6 +68,14 @@ Example:
interrupts = <26 0>;
reg = <0x09>;
 
+   max77686,pmic-buck-default-dvs-idx = <1>;
+   max77686,pmic-buck-dvs-gpios = <&gpy7 6 0>,
+  <&gpj4 2 0>,
+  <&gpj4 3 0>;
+   max77686,pmic-buck-selb-gpios = <&gph0 1 0>,
+   <&gph0 2 0>,
+   <&gph0 3 0>,
+
voltage-regulators {
ldo11_reg {
regulator-compatible = "LDO11";
-- 
2.0.0.rc2

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 15/24] regmap: Add regmap_reg_copy function

2014-07-04 Thread Javier Martinez Canillas
Some device drivers using the register map API need to copy the
value from one register to another. Even though it can be done
with a combination of regmap_read() and regmap_write(), it is
better to have a function to avoid code duplication and also it
sanity check and do it atomically by holding the regmap lock.

Signed-off-by: Javier Martinez Canillas 
---
 drivers/base/regmap/regmap.c | 34 ++
 include/linux/regmap.h   |  9 +
 2 files changed, 43 insertions(+)

diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index 74d8c06..a2e0b04 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -2555,6 +2555,40 @@ int regmap_parse_val(struct regmap *map, const void *buf,
 }
 EXPORT_SYMBOL_GPL(regmap_parse_val);
 
+/**
+ * regmap_reg_copy(): Copy a value from a single register to another one
+ *
+ * @map: Register map to operate on
+ * @dest: Register to copy the value to
+ * @src: Register to copy the value from
+ *
+ * A value of zero will be returned on success, a negative errno will
+ * be returned in error cases.
+ */
+int regmap_reg_copy(struct regmap *map, unsigned int dest, unsigned int src)
+{
+   int val;
+   int ret = 0;
+
+   if (dest == src)
+   return ret;
+
+   if (dest % map->reg_stride ||
+   src % map->reg_stride)
+   return -EINVAL;
+
+   map->lock(map->lock_arg);
+
+   ret = _regmap_read(map, src, &val);
+   if (!ret)
+   ret = _regmap_write(map, dest, val);
+
+   map->unlock(map->lock_arg);
+
+   return ret;
+}
+EXPORT_SYMBOL_GPL(regmap_reg_copy);
+
 static int __init regmap_initcall(void)
 {
regmap_debugfs_initcall();
diff --git a/include/linux/regmap.h b/include/linux/regmap.h
index 7b0e4b4..116c22b 100644
--- a/include/linux/regmap.h
+++ b/include/linux/regmap.h
@@ -445,6 +445,8 @@ int regmap_register_patch(struct regmap *map, const struct 
reg_default *regs,
 int regmap_parse_val(struct regmap *map, const void *buf,
unsigned int *val);
 
+int regmap_reg_copy(struct regmap *map, unsigned int dest, unsigned int src);
+
 static inline bool regmap_reg_in_range(unsigned int reg,
   const struct regmap_range *range)
 {
@@ -723,6 +725,13 @@ static inline int regmap_parse_val(struct regmap *map, 
const void *buf,
return -EINVAL;
 }
 
+static inline int regmap_reg_copy(struct regmap *map, unsigned int dest,
+ unsigned int src)
+{
+   WARN_ONCE(1, "regmap API is disabled");
+   return -EINVAL;
+}
+
 static inline struct regmap *dev_get_regmap(struct device *dev,
const char *name)
 {
-- 
2.0.0.rc2

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 12/24] clk: Add generic driver for Maxim PMIC clocks

2014-07-04 Thread Javier Martinez Canillas
Maxim Integrated Power Management ICs are very similar with
regard to their clock outputs. Most of the clock drivers for
these chips are duplicating code and are simpler enough that
can be converted to use a generic driver to consolidate code
and avoid duplication.

Signed-off-by: Javier Martinez Canillas 
Reviewed-by: Krzysztof Kozlowski 
--

Changes since v6: None

Changes since v5:
 - Fix generic driver changes merged into max77802 clock patch by mistake.
   Suggested by Yadwinder Singh Brar.
 - Register clock lookups using clk_register_clkdev() instead of doing manually.
 - Use the managed devm_clk_register() function and remove clk un-registration.
 - Add "clock-output-names" property support. Suggested by Yadwinder Singh Brar.
 - Return the rate unconditionally in recalc_rate. Suggested by Mike Turquette.

Changes since v4: None

Changes since v3:
 - Don't change clock-names property to make clear that it's
   the consumer clock name and should not match the producer clock.
   Suggested by Doug Anderson.
---
 drivers/clk/Kconfig   |   3 +
 drivers/clk/Makefile  |   1 +
 drivers/clk/clk-max-gen.c | 192 ++
 drivers/clk/clk-max-gen.h |  32 
 4 files changed, 228 insertions(+)
 create mode 100644 drivers/clk/clk-max-gen.c
 create mode 100644 drivers/clk/clk-max-gen.h

diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
index 9f9c5ae..73f78e8 100644
--- a/drivers/clk/Kconfig
+++ b/drivers/clk/Kconfig
@@ -32,6 +32,9 @@ config COMMON_CLK_WM831X
 
 source "drivers/clk/versatile/Kconfig"
 
+config COMMON_CLK_MAX_GEN
+bool
+
 config COMMON_CLK_MAX77686
tristate "Clock driver for Maxim 77686 MFD"
depends on MFD_MAX77686
diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
index 567f102..6c1aff6 100644
--- a/drivers/clk/Makefile
+++ b/drivers/clk/Makefile
@@ -18,6 +18,7 @@ obj-$(CONFIG_ARCH_BCM2835)+= clk-bcm2835.o
 obj-$(CONFIG_ARCH_EFM32)   += clk-efm32gg.o
 obj-$(CONFIG_ARCH_HIGHBANK)+= clk-highbank.o
 obj-$(CONFIG_MACH_LOONGSON1)   += clk-ls1x.o
+obj-$(CONFIG_COMMON_CLK_MAX_GEN)   += clk-max-gen.o
 obj-$(CONFIG_COMMON_CLK_MAX77686)  += clk-max77686.o
 obj-$(CONFIG_ARCH_MOXART)  += clk-moxart.o
 obj-$(CONFIG_ARCH_NOMADIK) += clk-nomadik.o
diff --git a/drivers/clk/clk-max-gen.c b/drivers/clk/clk-max-gen.c
new file mode 100644
index 000..6505049
--- /dev/null
+++ b/drivers/clk/clk-max-gen.c
@@ -0,0 +1,192 @@
+/*
+ * clk-max-gen.c - Generic clock driver for Maxim PMICs clocks
+ *
+ * Copyright (C) 2014 Google, Inc
+ *
+ * Copyright (C) 2012 Samsung Electornics
+ * Jonghwa Lee 
+ *
+ * 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.
+ *
+ * This driver is based on clk-max77686.c
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct max_gen_clk {
+   struct regmap *regmap;
+   u32 mask;
+   u32 reg;
+   struct clk_hw hw;
+};
+
+static struct max_gen_clk *to_max_gen_clk(struct clk_hw *hw)
+{
+   return container_of(hw, struct max_gen_clk, hw);
+}
+
+static int max_gen_clk_prepare(struct clk_hw *hw)
+{
+   struct max_gen_clk *max_gen = to_max_gen_clk(hw);
+
+   return regmap_update_bits(max_gen->regmap, max_gen->reg,
+ max_gen->mask, max_gen->mask);
+}
+
+static void max_gen_clk_unprepare(struct clk_hw *hw)
+{
+   struct max_gen_clk *max_gen = to_max_gen_clk(hw);
+
+   regmap_update_bits(max_gen->regmap, max_gen->reg,
+  max_gen->mask, ~max_gen->mask);
+}
+
+static int max_gen_clk_is_prepared(struct clk_hw *hw)
+{
+   struct max_gen_clk *max_gen = to_max_gen_clk(hw);
+   int ret;
+   u32 val;
+
+   ret = regmap_read(max_gen->regmap, max_gen->reg, &val);
+
+   if (ret < 0)
+   return -EINVAL;
+
+   return val & max_gen->mask;
+}
+
+static unsigned long max_gen_recalc_rate(struct clk_hw *hw,
+unsigned long parent_rate)
+{
+   return 32768;
+}
+
+struct clk_ops max_gen_clk_ops = {
+   .prepare= max_gen_clk_prepare,
+   .unprepare  = max_gen_clk_unprepare,
+   .is_prepared= max_gen_clk_is_prepared,
+   .recalc_rate= max_gen_recalc_rate,
+};
+EXPORT_SYMBOL_GPL(max_gen_clk_ops);
+
+static struct clk *max_gen_clk_register(str

[PATCH v7 13/24] clk: max77686: Convert to the generic max clock driver

2014-07-04 Thread Javier Martinez Canillas
Clocks drivers for Maxim PMIC are very similar so they can
be converted to use the generic Maxim clock driver.

Also, while being there use module_platform_driver() helper
macro to eliminate more boilerplate code.

Signed-off-by: Javier Martinez Canillas 
Reviewed-by: Krzysztof Kozlowski 
---
 drivers/clk/Kconfig|   1 +
 drivers/clk/clk-max77686.c | 176 +++--
 2 files changed, 9 insertions(+), 168 deletions(-)

diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
index 73f78e8..3fd4270 100644
--- a/drivers/clk/Kconfig
+++ b/drivers/clk/Kconfig
@@ -38,6 +38,7 @@ config COMMON_CLK_MAX_GEN
 config COMMON_CLK_MAX77686
tristate "Clock driver for Maxim 77686 MFD"
depends on MFD_MAX77686
+   select COMMON_CLK_MAX_GEN
---help---
  This driver supports Maxim 77686 crystal oscillator clock. 
 
diff --git a/drivers/clk/clk-max77686.c b/drivers/clk/clk-max77686.c
index 185b611..ed0beb4 100644
--- a/drivers/clk/clk-max77686.c
+++ b/drivers/clk/clk-max77686.c
@@ -31,187 +31,37 @@
 #include 
 
 #include 
-
-struct max77686_clk {
-   struct max77686_dev *iodev;
-   u32 mask;
-   struct clk_hw hw;
-   struct clk_lookup *lookup;
-};
-
-static struct max77686_clk *to_max77686_clk(struct clk_hw *hw)
-{
-   return container_of(hw, struct max77686_clk, hw);
-}
-
-static int max77686_clk_prepare(struct clk_hw *hw)
-{
-   struct max77686_clk *max77686 = to_max77686_clk(hw);
-
-   return regmap_update_bits(max77686->iodev->regmap,
- MAX77686_REG_32KHZ, max77686->mask,
- max77686->mask);
-}
-
-static void max77686_clk_unprepare(struct clk_hw *hw)
-{
-   struct max77686_clk *max77686 = to_max77686_clk(hw);
-
-   regmap_update_bits(max77686->iodev->regmap,
-   MAX77686_REG_32KHZ, max77686->mask, ~max77686->mask);
-}
-
-static int max77686_clk_is_prepared(struct clk_hw *hw)
-{
-   struct max77686_clk *max77686 = to_max77686_clk(hw);
-   int ret;
-   u32 val;
-
-   ret = regmap_read(max77686->iodev->regmap,
-   MAX77686_REG_32KHZ, &val);
-
-   if (ret < 0)
-   return -EINVAL;
-
-   return val & max77686->mask;
-}
-
-static unsigned long max77686_recalc_rate(struct clk_hw *hw,
- unsigned long parent_rate)
-{
-   return 32768;
-}
-
-static struct clk_ops max77686_clk_ops = {
-   .prepare= max77686_clk_prepare,
-   .unprepare  = max77686_clk_unprepare,
-   .is_prepared= max77686_clk_is_prepared,
-   .recalc_rate= max77686_recalc_rate,
-};
+#include "clk-max-gen.h"
 
 static struct clk_init_data max77686_clks_init[MAX77686_CLKS_NUM] = {
[MAX77686_CLK_AP] = {
.name = "32khz_ap",
-   .ops = &max77686_clk_ops,
+   .ops = &max_gen_clk_ops,
.flags = CLK_IS_ROOT,
},
[MAX77686_CLK_CP] = {
.name = "32khz_cp",
-   .ops = &max77686_clk_ops,
+   .ops = &max_gen_clk_ops,
.flags = CLK_IS_ROOT,
},
[MAX77686_CLK_PMIC] = {
.name = "32khz_pmic",
-   .ops = &max77686_clk_ops,
+   .ops = &max_gen_clk_ops,
.flags = CLK_IS_ROOT,
},
 };
 
-static struct clk *max77686_clk_register(struct device *dev,
-   struct max77686_clk *max77686)
-{
-   struct clk *clk;
-   struct clk_hw *hw = &max77686->hw;
-
-   clk = clk_register(dev, hw);
-   if (IS_ERR(clk))
-   return clk;
-
-   max77686->lookup = kzalloc(sizeof(struct clk_lookup), GFP_KERNEL);
-   if (!max77686->lookup)
-   return ERR_PTR(-ENOMEM);
-
-   max77686->lookup->con_id = hw->init->name;
-   max77686->lookup->clk = clk;
-
-   clkdev_add(max77686->lookup);
-
-   return clk;
-}
-
 static int max77686_clk_probe(struct platform_device *pdev)
 {
struct max77686_dev *iodev = dev_get_drvdata(pdev->dev.parent);
-   struct max77686_clk *max77686_clks[MAX77686_CLKS_NUM];
-   struct clk **clocks;
-   int i, ret;
-
-   clocks = devm_kzalloc(&pdev->dev, sizeof(struct clk *)
-   * MAX77686_CLKS_NUM, GFP_KERNEL);
-   if (!clocks)
-   return -ENOMEM;
-
-   for (i = 0; i < MAX77686_CLKS_NUM; i++) {
-   max77686_clks[i] = devm_kzalloc(&pdev->dev,
-   sizeof(struct max77686_clk), 
GFP_KERNEL);
-   if (!max77686_clks[i])
-   return -ENOMEM;
-   }
-
-   for (i = 0; i < MAX77686_CLKS_NUM; i++) {
-   max77686_clks[i]->iodev = iodev;
-

[PATCH v7 10/24] rtc: max77686: Remove dead code for SMPL and WTSR.

2014-07-04 Thread Javier Martinez Canillas
The MAX77686 RTC chip has two features called SMPL (Sudden Momentary
Power Loss) and WTSR (Watchdog Timeout and Software Resets).
Support for these features seems to be implemented in the driver but
compilation is disabled using a C pre-processor conditional.

This code has been disabled since the driver was original merged in
commit fca1dd03 ("rtc: max77686: add Maxim 77686 driver").

So, since this code has never been built, let's just remove it.

Signed-off-by: Javier Martinez Canillas 
---
 drivers/rtc/rtc-max77686.c | 101 -
 1 file changed, 101 deletions(-)

diff --git a/drivers/rtc/rtc-max77686.c b/drivers/rtc/rtc-max77686.c
index c1c6055..7bb5433 100644
--- a/drivers/rtc/rtc-max77686.c
+++ b/drivers/rtc/rtc-max77686.c
@@ -32,15 +32,6 @@
 #define RTC_UDR_MASK   (1 << RTC_UDR_SHIFT)
 #define RTC_RBUDR_SHIFT4
 #define RTC_RBUDR_MASK (1 << RTC_RBUDR_SHIFT)
-/* WTSR and SMPL Register */
-#define WTSRT_SHIFT0
-#define SMPLT_SHIFT2
-#define WTSR_EN_SHIFT  6
-#define SMPL_EN_SHIFT  7
-#define WTSRT_MASK (3 << WTSRT_SHIFT)
-#define SMPLT_MASK (3 << SMPLT_SHIFT)
-#define WTSR_EN_MASK   (1 << WTSR_EN_SHIFT)
-#define SMPL_EN_MASK   (1 << SMPL_EN_SHIFT)
 /* RTC Hour register */
 #define HOUR_PM_SHIFT  6
 #define HOUR_PM_MASK   (1 << HOUR_PM_SHIFT)
@@ -49,7 +40,6 @@
 #define ALARM_ENABLE_MASK  (1 << ALARM_ENABLE_SHIFT)
 
 #define MAX77686_RTC_UPDATE_DELAY  16
-#undef MAX77686_RTC_WTSR_SMPL
 
 enum {
RTC_SEC = 0,
@@ -412,64 +402,6 @@ static const struct rtc_class_ops max77686_rtc_ops = {
.alarm_irq_enable = max77686_rtc_alarm_irq_enable,
 };
 
-#ifdef MAX77686_RTC_WTSR_SMPL
-static void max77686_rtc_enable_wtsr(struct max77686_rtc_info *info, bool 
enable)
-{
-   int ret;
-   unsigned int val, mask;
-
-   if (enable)
-   val = (1 << WTSR_EN_SHIFT) | (3 << WTSRT_SHIFT);
-   else
-   val = 0;
-
-   mask = WTSR_EN_MASK | WTSRT_MASK;
-
-   dev_info(info->dev, "%s: %s WTSR\n", __func__,
-   enable ? "enable" : "disable");
-
-   ret = regmap_update_bits(info->max77686->rtc_regmap,
-MAX77686_WTSR_SMPL_CNTL, mask, val);
-   if (ret < 0) {
-   dev_err(info->dev, "%s: fail to update WTSR reg(%d)\n",
-   __func__, ret);
-   return;
-   }
-
-   max77686_rtc_update(info, MAX77686_RTC_WRITE);
-}
-
-static void max77686_rtc_enable_smpl(struct max77686_rtc_info *info, bool 
enable)
-{
-   int ret;
-   unsigned int val, mask;
-
-   if (enable)
-   val = (1 << SMPL_EN_SHIFT) | (0 << SMPLT_SHIFT);
-   else
-   val = 0;
-
-   mask = SMPL_EN_MASK | SMPLT_MASK;
-
-   dev_info(info->dev, "%s: %s SMPL\n", __func__,
-   enable ? "enable" : "disable");
-
-   ret = regmap_update_bits(info->max77686->rtc_regmap,
-MAX77686_WTSR_SMPL_CNTL, mask, val);
-   if (ret < 0) {
-   dev_err(info->dev, "%s: fail to update SMPL reg(%d)\n",
-   __func__, ret);
-   return;
-   }
-
-   max77686_rtc_update(info, MAX77686_RTC_WRITE);
-
-   val = 0;
-   regmap_read(info->max77686->rtc_regmap, MAX77686_WTSR_SMPL_CNTL, &val);
-   dev_info(info->dev, "%s: WTSR_SMPL(0x%02x)\n", __func__, val);
-}
-#endif /* MAX77686_RTC_WTSR_SMPL */
-
 static int max77686_rtc_init_reg(struct max77686_rtc_info *info)
 {
u8 data[2];
@@ -519,11 +451,6 @@ static int max77686_rtc_probe(struct platform_device *pdev)
goto err_rtc;
}
 
-#ifdef MAX77686_RTC_WTSR_SMPL
-   max77686_rtc_enable_wtsr(info, true);
-   max77686_rtc_enable_smpl(info, true);
-#endif
-
device_init_wakeup(&pdev->dev, 1);
 
info->rtc_dev = devm_rtc_device_register(&pdev->dev, "max77686-rtc",
@@ -556,33 +483,6 @@ err_rtc:
return ret;
 }
 
-static void max77686_rtc_shutdown(struct platform_device *pdev)
-{
-#ifdef MAX77686_RTC_WTSR_SMPL
-   struct max77686_rtc_info *info = platform_get_drvdata(pdev);
-   int i;
-   u8 val = 0;
-
-   for (i = 0; i < 3; i++) {
-   max77686_rtc_enable_wtsr(info, false);
-   regmap_read(info->max77686->rtc_regmap, 
MAX77686_WTSR_SMPL_CNTL, &val);
-   dev_info(info->dev, "%s: WTSR_SMPL reg(0x%02x)\n", __func__,
-   

[PATCH v7 11/24] clk: max77686: Add DT include for MAX77686 PMIC clock

2014-07-04 Thread Javier Martinez Canillas
This patch adds a dt-binding include for Maxim 77686
PMIC clock IDs that can be used by both the max77686
clock driver and Device Tree source files.

Signed-off-by: Javier Martinez Canillas 
Reviewed-by: Krzysztof Kozlowski 
Reviewed-by: Mike Turquette 
---

Changes since v6: None

Changes since v5:
 - Improve wording in commit message. Suggested by Andreas Farber.

Changes since v4: None

Changes since v3:
 - Keep the note that this patch needs another change due wakeup
   ordering problems.
---
 drivers/clk/clk-max77686.c |  7 +--
 include/dt-bindings/clock/maxim,max77686.h | 23 +++
 2 files changed, 24 insertions(+), 6 deletions(-)
 create mode 100644 include/dt-bindings/clock/maxim,max77686.h

diff --git a/drivers/clk/clk-max77686.c b/drivers/clk/clk-max77686.c
index 3d7e8dd..185b611 100644
--- a/drivers/clk/clk-max77686.c
+++ b/drivers/clk/clk-max77686.c
@@ -30,12 +30,7 @@
 #include 
 #include 
 
-enum {
-   MAX77686_CLK_AP = 0,
-   MAX77686_CLK_CP,
-   MAX77686_CLK_PMIC,
-   MAX77686_CLKS_NUM,
-};
+#include 
 
 struct max77686_clk {
struct max77686_dev *iodev;
diff --git a/include/dt-bindings/clock/maxim,max77686.h 
b/include/dt-bindings/clock/maxim,max77686.h
new file mode 100644
index 000..7b28b09
--- /dev/null
+++ b/include/dt-bindings/clock/maxim,max77686.h
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2014 Google, Inc
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Device Tree binding constants clocks for the Maxim 77686 PMIC.
+ */
+
+#ifndef _DT_BINDINGS_CLOCK_MAXIM_MAX77686_CLOCK_H
+#define _DT_BINDINGS_CLOCK_MAXIM_MAX77686_CLOCK_H
+
+/* Fixed rate clocks. */
+
+#define MAX77686_CLK_AP0
+#define MAX77686_CLK_CP1
+#define MAX77686_CLK_PMIC  2
+
+/* Total number of clocks. */
+#define MAX77686_CLKS_NUM  (MAX77686_CLK_PMIC + 1)
+
+#endif /* _DT_BINDINGS_CLOCK_MAXIM_MAX77686_CLOCK_H */
-- 
2.0.0.rc2

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 09/24] rtc: max77686: Allow the max77686 rtc to wakeup the system

2014-07-04 Thread Javier Martinez Canillas
From: Doug Anderson 

The max77686 includes an RTC that keeps power during suspend.  It's
convenient to be able to use it as a wakeup source.

NOTE: due to wakeup ordering problems this patch alone doesn't work so
well on exynos5250-snow.  You also need something that brings the i2c
bus up before the max77686 wakeup runs.

Signed-off-by: Doug Anderson 
Reviewed-by: Javier Martinez Canillas 
Reviewed-by: Krzysztof Kozlowski 
---

Changes since v6: None

Changes since v5:
 - Fix $SUBJECT since the patch does not actually touch the mfd subsys.
   Suggested by Lee Jones.

Changes since v4: None

Changes since v3:
 - Keep the note that this patch needs another change due wakeup
   ordering problems.
---
 drivers/rtc/rtc-max77686.c | 28 
 1 file changed, 28 insertions(+)

diff --git a/drivers/rtc/rtc-max77686.c b/drivers/rtc/rtc-max77686.c
index d20a7f0..c1c6055 100644
--- a/drivers/rtc/rtc-max77686.c
+++ b/drivers/rtc/rtc-max77686.c
@@ -583,6 +583,33 @@ static void max77686_rtc_shutdown(struct platform_device 
*pdev)
 #endif /* MAX77686_RTC_WTSR_SMPL */
 }
 
+#ifdef CONFIG_PM_SLEEP
+static int max77686_rtc_suspend(struct device *dev)
+{
+   if (device_may_wakeup(dev)) {
+   struct max77686_rtc_info *info = dev_get_drvdata(dev);
+
+   return enable_irq_wake(info->virq);
+   }
+
+   return 0;
+}
+
+static int max77686_rtc_resume(struct device *dev)
+{
+   if (device_may_wakeup(dev)) {
+   struct max77686_rtc_info *info = dev_get_drvdata(dev);
+
+   return disable_irq_wake(info->virq);
+   }
+
+   return 0;
+}
+#endif
+
+static SIMPLE_DEV_PM_OPS(max77686_rtc_pm_ops,
+max77686_rtc_suspend, max77686_rtc_resume);
+
 static const struct platform_device_id rtc_id[] = {
{ "max77686-rtc", 0 },
{},
@@ -592,6 +619,7 @@ static struct platform_driver max77686_rtc_driver = {
.driver = {
.name   = "max77686-rtc",
.owner  = THIS_MODULE,
+   .pm = &max77686_rtc_pm_ops,
},
.probe  = max77686_rtc_probe,
.shutdown   = max77686_rtc_shutdown,
-- 
2.0.0.rc2

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 07/24] mfd: max77686: Remove unneeded OOM error message

2014-07-04 Thread Javier Martinez Canillas
There is no need to print out-of-memory errors since this is already
done by the memory management subsystem which even calls dump_stack().

Signed-off-by: Javier Martinez Canillas 
---
 drivers/mfd/max77686.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/mfd/max77686.c b/drivers/mfd/max77686.c
index 87fe52e..8650832 100644
--- a/drivers/mfd/max77686.c
+++ b/drivers/mfd/max77686.c
@@ -107,10 +107,8 @@ static struct max77686_platform_data 
*max77686_i2c_parse_dt_pdata(struct device
struct max77686_platform_data *pd;
 
pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL);
-   if (!pd) {
-   dev_err(dev, "could not allocate memory for pdata\n");
+   if (!pd)
return NULL;
-   }
 
dev->platform_data = pd;
return pd;
-- 
2.0.0.rc2

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 08/24] mfd: max77686: Add Dynamic Voltage Scaling (DVS) support

2014-07-04 Thread Javier Martinez Canillas
Some regulators on the MAX77686 PMIC have Dynamic Voltage Scaling
(DVS) support that allows output voltage to change dynamically.

For MAX77686, these regulators are Buck regulators 2, 3 and 4.

Each Buck output voltage is selected using a set of external
inputs: DVS1-3 and SELB2-4.

DVS registers can be used to configure the output voltages for each
Buck regulator and which one is active is controled by DVSx lines.

SELBx lines are used to control if individual Buck lines are ON or OFF.

This patch adds support to configure the DVSx and SELBx lines
from DT and to setup and read the GPIO lines connected to them.

Signed-off-by: Javier Martinez Canillas 
Reviewed-by: Krzysztof Kozlowski 
---

Changes since v6:
 - Add a comment that max77686_read_gpios() function can sleep.
   Sugggested by Krzysztof Kozlowski
---
 drivers/mfd/max77686.c   | 119 +++
 include/linux/mfd/max77686.h |  18 ---
 2 files changed, 129 insertions(+), 8 deletions(-)

diff --git a/drivers/mfd/max77686.c b/drivers/mfd/max77686.c
index 8650832..d193873 100644
--- a/drivers/mfd/max77686.c
+++ b/drivers/mfd/max77686.c
@@ -32,8 +32,10 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
+#include 
 
 #define I2C_ADDR_RTC   (0x0C >> 1)
 
@@ -101,9 +103,119 @@ static const struct of_device_id max77686_pmic_dt_match[] 
= {
{},
 };
 
+static void max77686_dt_parse_dvs_gpio(struct device *dev)
+{
+   struct max77686_platform_data *pd = dev_get_platdata(dev);
+   int i;
+
+   /*
+* NOTE: we don't consider GPIO errors fatal; board may have some lines
+* directly pulled high or low and thus doesn't specify them.
+*/
+   for (i = 0; i < ARRAY_SIZE(pd->buck_gpio_dvs); i++)
+   pd->buck_gpio_dvs[i] =
+   devm_gpiod_get_index(dev, "max77686,pmic-buck-dvs", i);
+
+   for (i = 0; i < ARRAY_SIZE(pd->buck_gpio_selb); i++)
+   pd->buck_gpio_selb[i] =
+   devm_gpiod_get_index(dev, "max77686,pmic-buck-selb", i);
+}
+
+/**
+ * max77686_setup_gpios() - init DVS-related GPIOs
+ * @dev: device whose platform data contains the dvs GPIOs information
+ *
+ * This function claims / initalizations GPIOs related to DVS if they are
+ * defined. This may have the effect of switching voltages if the
+ * pdata->buck_default_idx does not match the boot time state of pins.
+ */
+int max77686_setup_gpios(struct device *dev)
+{
+   struct max77686_platform_data *pd = dev_get_platdata(dev);
+   int buck_default_idx = pd->buck_default_idx;
+   int ret;
+   int i;
+
+   /* Set all SELB high to avoid glitching while DVS is changing */
+   for (i = 0; i < ARRAY_SIZE(pd->buck_gpio_selb); i++) {
+   struct gpio_desc *gpio = pd->buck_gpio_selb[i];
+
+   /* OK if some GPIOs aren't defined */
+   if (IS_ERR(gpio))
+   continue;
+
+   ret = gpiod_direction_output_raw(gpio, 1);
+   if (ret) {
+   dev_err(dev, "can't set gpio[%d] dir: %d\n", i, ret);
+   return ret;
+   }
+   }
+
+   /* Set our initial setting */
+   for (i = 0; i < ARRAY_SIZE(pd->buck_gpio_dvs); i++) {
+   struct gpio_desc *gpio = pd->buck_gpio_dvs[i];
+
+   /* OK if some GPIOs aren't defined */
+   if (IS_ERR(gpio))
+   continue;
+
+   /* If a GPIO is valid, set it */
+   gpiod_direction_output(gpio, (buck_default_idx >> i) & 1);
+   if (ret) {
+   dev_err(dev, "can't set gpio[%d]: dir %d\n", i, ret);
+   return ret;
+   }
+   }
+
+   /* Now set SELB low to take effect */
+   for (i = 0; i < ARRAY_SIZE(pd->buck_gpio_selb); i++) {
+   struct gpio_desc *gpio = pd->buck_gpio_selb[i];
+
+   if (!IS_ERR(gpio))
+   gpiod_set_value(gpio, 0);
+   }
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(max77686_setup_gpios);
+
+/**
+ * max77686_read_gpios() - read the current state of the dvs GPIOs
+ * @pdata: platform data that contains the dvs GPIOs information
+ *
+ * We call this function at bootup to detect what slot the firmware was
+ * using for the DVS GPIOs.  That way we can properly preserve the firmware's
+ * voltage settings
+ *
+ * This function can sleep so must not be called from atomic context.
+ */
+int max77686_read_gpios(struct max77686_platform_data *pdata)
+{
+   int buck_default_idx = pdata->buck_default_idx;
+   int result = 0;
+   int i;
+
+   for (i = 0; i < ARRAY_SIZE(pdata->buck_gpio_dvs); i++) {
+   struct gpio_desc *gpio = pdata->buck_gpio_dvs[i];
+
+  

[PATCH v7 05/24] mfd: max77686: Return correct error when pdata isn't found

2014-07-04 Thread Javier Martinez Canillas
When platform data is not found an -EIO (I/O error) code is returned.
This doesn't seem to be the correct error so better return -EINVAL
(Invalid argument) which is what most drivers do in this case.

Signed-off-by: Javier Martinez Canillas 
---
 drivers/mfd/max77686.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mfd/max77686.c b/drivers/mfd/max77686.c
index 12d4c17..ada4976 100644
--- a/drivers/mfd/max77686.c
+++ b/drivers/mfd/max77686.c
@@ -129,7 +129,7 @@ static int max77686_i2c_probe(struct i2c_client *i2c,
 
if (!pdata) {
dev_err(&i2c->dev, "No platform data found.\n");
-   return -EIO;
+   return -EINVAL;
}
 
max77686 = devm_kzalloc(&i2c->dev,
-- 
2.0.0.rc2

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 06/24] mfd: max77686: Make error checking consistent

2014-07-04 Thread Javier Martinez Canillas
Error checking across the driver is mostly consistent besides
a few exceptions, so change these exceptions for consistency.

Signed-off-by: Javier Martinez Canillas 
Reviewed-by: Krzysztof Kozlowski 
---
 drivers/mfd/max77686.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/mfd/max77686.c b/drivers/mfd/max77686.c
index ada4976..87fe52e 100644
--- a/drivers/mfd/max77686.c
+++ b/drivers/mfd/max77686.c
@@ -134,7 +134,7 @@ static int max77686_i2c_probe(struct i2c_client *i2c,
 
max77686 = devm_kzalloc(&i2c->dev,
sizeof(struct max77686_dev), GFP_KERNEL);
-   if (max77686 == NULL)
+   if (!max77686)
return -ENOMEM;
 
i2c_set_clientdata(i2c, max77686);
@@ -153,8 +153,8 @@ static int max77686_i2c_probe(struct i2c_client *i2c,
return ret;
}
 
-   if (regmap_read(max77686->regmap,
-MAX77686_REG_DEVICE_ID, &data) < 0) {
+   ret = regmap_read(max77686->regmap, MAX77686_REG_DEVICE_ID, &data);
+   if (ret < 0) {
dev_err(max77686->dev,
"device not found on this channel (this is not an 
error)\n");
return -ENODEV;
@@ -180,7 +180,7 @@ static int max77686_i2c_probe(struct i2c_client *i2c,
  IRQF_TRIGGER_FALLING | IRQF_ONESHOT |
  IRQF_SHARED, 0, &max77686_irq_chip,
  &max77686->irq_data);
-   if (ret != 0) {
+   if (ret) {
dev_err(&i2c->dev, "failed to add PMIC irq chip: %d\n", ret);
goto err_unregister_i2c;
}
@@ -188,7 +188,7 @@ static int max77686_i2c_probe(struct i2c_client *i2c,
  IRQF_TRIGGER_FALLING | IRQF_ONESHOT |
  IRQF_SHARED, 0, &max77686_rtc_irq_chip,
  &max77686->rtc_irq_data);
-   if (ret != 0) {
+   if (ret) {
dev_err(&i2c->dev, "failed to add RTC irq chip: %d\n", ret);
goto err_del_irqc;
}
-- 
2.0.0.rc2

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 03/24] mfd: max77686: Don't define dummy function if OF isn't enabled

2014-07-04 Thread Javier Martinez Canillas
When the CONFIG_OF option was not enabled, a dummy function
max77686_i2c_parse_dt_pdata() was defined since this is called
unconditionally on probe(). Just always define the real function
and conditionally call it if CONFIG_OF is enabled instead.

Signed-off-by: Javier Martinez Canillas 
---
 drivers/mfd/max77686.c | 10 +-
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/drivers/mfd/max77686.c b/drivers/mfd/max77686.c
index a38e9ee..d1f9d04 100644
--- a/drivers/mfd/max77686.c
+++ b/drivers/mfd/max77686.c
@@ -96,7 +96,6 @@ static const struct regmap_irq_chip max77686_rtc_irq_chip = {
.num_irqs   = ARRAY_SIZE(max77686_rtc_irqs),
 };
 
-#ifdef CONFIG_OF
 static const struct of_device_id max77686_pmic_dt_match[] = {
{.compatible = "maxim,max77686", .data = NULL},
{},
@@ -116,13 +115,6 @@ static struct max77686_platform_data 
*max77686_i2c_parse_dt_pdata(struct device
dev->platform_data = pd;
return pd;
 }
-#else
-static struct max77686_platform_data *max77686_i2c_parse_dt_pdata(struct device
- *dev)
-{
-   return 0;
-}
-#endif
 
 static int max77686_i2c_probe(struct i2c_client *i2c,
  const struct i2c_device_id *id)
@@ -132,7 +124,7 @@ static int max77686_i2c_probe(struct i2c_client *i2c,
unsigned int data;
int ret = 0;
 
-   if (i2c->dev.of_node)
+   if (IS_ENABLED(CONFIG_OF) && i2c->dev.of_node)
pdata = max77686_i2c_parse_dt_pdata(&i2c->dev);
 
if (!pdata) {
-- 
2.0.0.rc2

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 04/24] mfd: max77686: Make platform data over-rule DT

2014-07-04 Thread Javier Martinez Canillas
The function max77802_i2c_parse_dt_pdata() should only be called
if there isn't already platform data for the device.

Signed-off-by: Javier Martinez Canillas 
---
 drivers/mfd/max77686.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mfd/max77686.c b/drivers/mfd/max77686.c
index d1f9d04..12d4c17 100644
--- a/drivers/mfd/max77686.c
+++ b/drivers/mfd/max77686.c
@@ -124,7 +124,7 @@ static int max77686_i2c_probe(struct i2c_client *i2c,
unsigned int data;
int ret = 0;
 
-   if (IS_ENABLED(CONFIG_OF) && i2c->dev.of_node)
+   if (IS_ENABLED(CONFIG_OF) && i2c->dev.of_node && !pdata)
pdata = max77686_i2c_parse_dt_pdata(&i2c->dev);
 
if (!pdata) {
-- 
2.0.0.rc2

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 02/24] mfd: max77686: Add power management support

2014-07-04 Thread Javier Martinez Canillas
The driver doesn't have PM operations defined so add a suspend
and resume function handlers to allow the PMIC IRQ to wakeup
the system when it is put into a sleep state.

Signed-off-by: Javier Martinez Canillas 
Reviewed-by: Krzysztof Kozlowski 
---
 drivers/mfd/max77686.c | 40 
 1 file changed, 40 insertions(+)

diff --git a/drivers/mfd/max77686.c b/drivers/mfd/max77686.c
index 3cb41d0..a38e9ee 100644
--- a/drivers/mfd/max77686.c
+++ b/drivers/mfd/max77686.c
@@ -240,10 +240,50 @@ static const struct i2c_device_id max77686_i2c_id[] = {
 };
 MODULE_DEVICE_TABLE(i2c, max77686_i2c_id);
 
+#ifdef CONFIG_PM_SLEEP
+static int max77686_suspend(struct device *dev)
+{
+   struct i2c_client *i2c = container_of(dev, struct i2c_client, dev);
+   struct max77686_dev *max77686 = i2c_get_clientdata(i2c);
+
+   if (device_may_wakeup(dev))
+   enable_irq_wake(max77686->irq);
+
+   /*
+* IRQ must be disabled during suspend because if it happens
+* while suspended it will be handled before resuming I2C.
+*
+* When device is woken up from suspend (e.g. by RTC wake alarm),
+* an interrupt occurs before resuming I2C bus controller.
+* Interrupt handler tries to read registers but this read
+* will fail because I2C is still suspended.
+*/
+   disable_irq(max77686->irq);
+
+   return 0;
+}
+
+static int max77686_resume(struct device *dev)
+{
+   struct i2c_client *i2c = container_of(dev, struct i2c_client, dev);
+   struct max77686_dev *max77686 = i2c_get_clientdata(i2c);
+
+   if (device_may_wakeup(dev))
+   disable_irq_wake(max77686->irq);
+
+   enable_irq(max77686->irq);
+
+   return 0;
+}
+#endif /* CONFIG_PM_SLEEP */
+
+static SIMPLE_DEV_PM_OPS(max77686_pm, max77686_suspend, max77686_resume);
+
 static struct i2c_driver max77686_i2c_driver = {
.driver = {
   .name = "max77686",
   .owner = THIS_MODULE,
+  .pm = &max77686_pm,
   .of_match_table = of_match_ptr(max77686_pmic_dt_match),
},
.probe = max77686_i2c_probe,
-- 
2.0.0.rc2

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 01/24] mfd: max77686: Convert to use regmap_irq

2014-07-04 Thread Javier Martinez Canillas
By using the generic IRQ support in the Register map API, it
is possible to get rid max77686-irq.c and simplify the code.

Suggested-by: Krzysztof Kozlowski 
Signed-off-by: Javier Martinez Canillas 
Acked-by: Lee Jones 
Reviewed-by: Doug Anderson 
Tested-by: Doug Anderson 
--

Changes since v6: None

Changes since v5: None

Changes since v4:
 - Remove left over defines not used anymore. Suggested by Krzysztof Kozlowski.

Changes since v3: None

Changes since v2:
 - Cleanup regmap irqchips on i2c_driver .remove function.
   Suggested by Doug Anderson.
 - Remove unused MAX77686_IRQ_NR enum. Suggested by Doug Anderson.
---
 drivers/mfd/Kconfig  |   1 +
 drivers/mfd/Makefile |   2 +-
 drivers/mfd/max77686-irq.c   | 319 ---
 drivers/mfd/max77686.c   |  97 ++-
 drivers/rtc/rtc-max77686.c   |  27 +--
 include/linux/mfd/max77686-private.h |  31 +++-
 include/linux/mfd/max77686.h |   2 -
 7 files changed, 123 insertions(+), 356 deletions(-)
 delete mode 100644 drivers/mfd/max77686-irq.c

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index b8d9ca0..3010204 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -384,6 +384,7 @@ config MFD_MAX77686
depends on I2C=y
select MFD_CORE
select REGMAP_I2C
+   select REGMAP_IRQ
select IRQ_DOMAIN
help
  Say yes here to add support for Maxim Semiconductor MAX77686.
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 4e2bc25..f001487 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -115,7 +115,7 @@ da9063-objs := da9063-core.o da9063-irq.o 
da9063-i2c.o
 obj-$(CONFIG_MFD_DA9063)   += da9063.o
 
 obj-$(CONFIG_MFD_MAX14577) += max14577.o
-obj-$(CONFIG_MFD_MAX77686) += max77686.o max77686-irq.o
+obj-$(CONFIG_MFD_MAX77686) += max77686.o
 obj-$(CONFIG_MFD_MAX77693) += max77693.o
 obj-$(CONFIG_MFD_MAX8907)  += max8907.o
 max8925-objs   := max8925-core.o max8925-i2c.o
diff --git a/drivers/mfd/max77686-irq.c b/drivers/mfd/max77686-irq.c
deleted file mode 100644
index cdc3280..000
--- a/drivers/mfd/max77686-irq.c
+++ /dev/null
@@ -1,319 +0,0 @@
-/*
- * max77686-irq.c - Interrupt controller support for MAX77686
- *
- * Copyright (C) 2012 Samsung Electronics Co.Ltd
- * Chiwoong Byun 
- *
- * 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.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- * This driver is based on max8997-irq.c
- */
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-enum {
-   MAX77686_DEBUG_IRQ_INFO = 1 << 0,
-   MAX77686_DEBUG_IRQ_MASK = 1 << 1,
-   MAX77686_DEBUG_IRQ_INT = 1 << 2,
-};
-
-static int debug_mask = 0;
-module_param(debug_mask, int, 0);
-MODULE_PARM_DESC(debug_mask, "Set debug_mask : 0x0=off 0x1=IRQ_INFO  
0x2=IRQ_MASK 0x4=IRQ_INI)");
-
-static const u8 max77686_mask_reg[] = {
-   [PMIC_INT1] = MAX77686_REG_INT1MSK,
-   [PMIC_INT2] = MAX77686_REG_INT2MSK,
-   [RTC_INT] = MAX77686_RTC_INTM,
-};
-
-static struct regmap *max77686_get_regmap(struct max77686_dev *max77686,
-   enum max77686_irq_source src)
-{
-   switch (src) {
-   case PMIC_INT1 ... PMIC_INT2:
-   return max77686->regmap;
-   case RTC_INT:
-   return max77686->rtc_regmap;
-   default:
-   return ERR_PTR(-EINVAL);
-   }
-}
-
-struct max77686_irq_data {
-   int mask;
-   enum max77686_irq_source group;
-};
-
-#define DECLARE_IRQ(idx, _group, _mask)\
-   [(idx)] = { .group = (_group), .mask = (_mask) }
-static const struct max77686_irq_data max77686_irqs[] = {
-   DECLARE_IRQ(MAX77686_PMICIRQ_PWRONF,PMIC_INT1, 1 << 0),
-   DECLARE_IRQ(MAX77686_PMICIRQ_PWRONR,PMIC_INT1, 1 << 1),
-   DECLARE_IRQ(MAX77686_PMICIRQ_JIGONBF,   PMIC_INT1, 1 << 2),
-   DECLARE_IRQ(MAX77686_PMICIRQ_JIGONBR,   PMIC_INT1, 1 << 3),
-   DECLARE_IRQ(MAX77686_PMICIRQ_ACOKBF,PMIC_INT1, 1 << 4),
-   DECLARE_IRQ(MAX77686_PMICIRQ_ACOKBR,PMIC_INT1, 1 << 5),
-   DECLARE_IRQ(MAX77686_PMICIRQ_ONKEY1S,   PMIC_INT1, 1 << 6),
-   DECLARE_IRQ(MAX77686_PMICIRQ_MRST

Re: [PATCH v7 23/24] rtc: Add driver for Maxim 77802 PMIC Real-Time-Clock

2014-07-06 Thread Javier Martinez Canillas
Hello Krzysztof,

On 07/07/2014 08:06 AM, Krzysztof Kozlowski wrote:
> On pią, 2014-07-04 at 22:24 +0200, Javier Martinez Canillas wrote:
>> The MAX7802 PMIC has a Real-Time-Clock (RTC) with two alarms.
>> This patch adds support for the RTC and is based on a driver
>> added by Simon Glass to the Chrome OS kernel 3.8 tree.
>> 
>> Signed-off-by: Javier Martinez Canillas 
>> ---
>> 
>> Changes since v6:
>>  - Remove unused code for SMPL and WTSR. Suggested by Krzysztof Kozlowski.
>>  - Don't spam the kernel log with unimportant info and just print for debug.
>>Suggested by Krzysztof Kozlowski.
>>  - Use ARRAY_SIZE() instead of constant value. Suggested by Krzysztof 
>> Kozlowski.
>>  - Remove duplicated register setup. Suggested by Krzysztof Kozlowski.
>>  - Don't free/unregister managed allocated resources.
>>Suggested by Krzysztof Kozlowski.
>> ---
>>  drivers/rtc/Kconfig|  10 +
>>  drivers/rtc/Makefile   |   1 +
>>  drivers/rtc/rtc-max77802.c | 508 
>> +
>>  3 files changed, 519 insertions(+)
>>  create mode 100644 drivers/rtc/rtc-max77802.c
> 
> 
> Reviewed-by: Krzysztof Kozlowski 
> 

Thanks a lot for the review and for all the feedback you gave me on each version
of the series.

> Best regards,
> Krzysztof
> 
> 

Best regards,
Javier
--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/3 v5] spi: s3c64xx: fix broken "cs_gpios" usage in the driver

2014-07-07 Thread Javier Martinez Canillas
Hello Naveen and Mark,

On Mon, Jul 7, 2014 at 10:31 AM, Naveen Krishna Ch
 wrote:
> Hello Mark,
>
> On 7 July 2014 13:02, Mark Brown  wrote:
>> On Mon, Jul 07, 2014 at 11:51:38AM +0530, Naveen Krishna Ch wrote:
>>> On 2 July 2014 22:26, Mark Brown  wrote:
>>> > On Fri, Jun 13, 2014 at 09:29:50AM +0530, Naveen Krishna Chatradhi wrote:
>>
>>> >> Hence, spi-s3c64xx.c is broken since "Jun 21 11:26:12 2013" and
>>> >> considering the time with no compliants about the breakage.
>>
>>> > I'm not clear what the breakage is?  Some boards are broken but what's
>>> > the driver issue?
>>
>>> ToT was broken for few boards
>>> exynos4412-trats2.dts, exynos4210-smdkv310.dts and exynos5250-smdk5250.dts
>>
>>> With some DTS changes SPI works well, spi-s3c64xx.c driver had no issues.
>>

Correct me if I'm wrong but I think that the driver does have issues
since the commit mentioned (3146bee) broke DT backward compatibility.

>> No, you're not answering my question - to repeat, what is the breakage?
>

As far as I understand, the breakage is that any DTS that followed the
DT binding documented in
Documentation/devicetree/bindings/spi/spi-samsung.txt is not working
with the current driver. So is not that some boards are broken, is
that the driver is broken and it has been broken for more than a year
(the commit date is Jun 21 2013).

> The Documentation/devicetree/bindings/spi/spi-samsung.txt
> describes "cs-gpio" as a controller specific property.
>
> The dts entries for SPI in exynos4412-trats2.dts, exynos4210-smdkv310.dts
> and exynos5250-smdk5250.dts boards have the "cs-gpio" property defined
> under controller-data node, which is inside the SPI device node
> &spi_1 {
>   controller-data {
> cs-gpio = <>;
>   };
> };
>
> But, _probe() of spi-s3c64xx.c driver looks for "cs-gpio" in the SPI
> device node and
> sets a flag "sdd->cs_gpio = false" (If the property is not available)
> &spi_1 {
>   cs-gpio = <>;
> };
>
> the sdd->cs_gpio flag is checked before actually getting the gpios
> from the controller-data node
>if (sdd->cs_gpio)
> cs->line = of_get_named_gpio(data_np, "cs-gpio", 0);
>

I think that if changing the binding is not possible, at least we
should document this new "cs-gpio" property that is looked in the top
level SPI node after commit 3146bee and also revert the default in
order to allow DTs using the old binding to keep working.

By default not having the "cs-gpio" property in the SPI dev node
should mean that the "cs-gpio" property in the controller-data node
should be used to signal the chip-select and having the "cs-gpio"
property in the SPI node should mean that the native chip select
should be used instead of a GPIO. That preserves the old DT binding
semantic while making the GPIO to be optional.

Of course in that case the property name does not make too much sense,
so probably should be changed to "cs-native" or something like that.
But I still don't understand why this is needed in the first place
since according to Documentation/devicetree/bindings/spi/spi-bus.txt
you can use the cs-gpios property to specify that a native chip-select
will be used instead of a GPIO by doing:

cs-gpios = <&gpio1 0 0> <0>

cs0 : &gpio1 0 0
cs1 : native

> Hence, SPI was failing on those boards.
>
> 1. As the SPI core and several drivers were changed to work with
> DT property "cs-gpios" (plural) defined under SPI node.
> 2. Since the commit 3146beec21b64f4551fcf0ac148381d54dc41b1b
> "spi: s3c64xx: Added provision for dedicated cs pin"
> Dated:   Fri Jun 21 11:26:12 2013 +0530
>
> For the above 2 reasons, It was decided to drop the backward compatibility
> of using "cs-gpio"(singular) in controller-data.
> Instead, start supporting "cs-gpios"(plural) in the SPI node.
>

Right, since the DT binding has been broken for a year and because is
not consistent with the bindings used by all other SPI drivers, many
agreed that it was one of the exceptional cases where the DT binding
can be rethought and changed to use the generic "cs-gpios" property
already supported by SPI core. It breaks backward compatibility that's
true but the DT binding has been broken anyways and nobody noticed
before.

The other option is what I said above, fixing the DT binding
compatibility breakage while keeping the custom binding for this SPI
driver.

>>
>>> > Also I'd need to check but are you sure that GPIO 0 is not valid?
>>
>>> gpio_is_valid() returns true for
>>> "number >= 0 && number < ARCH_NR_GPIOS"
>>
>> Right, so this means that any board that is using the internal chip
>> select with zero as default in their platform data is broken by this
>> change.
>

I think this problem could be present in other SPI drivers as well? So
maybe the right fix for this is to convert the SPI core gpio handling
to use the new descriptor-based gpio API instead of the integer-base
one?

> using gpio_is_valid() to "sdd->cs_gpio" flag every where to check for the
> validity was a review comment.
> Which seems to fail for 

Re: [PATCH 2/3] ARM: dts: Update the parent for Audss clocks in Exynos5420

2014-07-09 Thread Javier Martinez Canillas
Hello Tushar,

On Tue, Jul 8, 2014 at 5:00 AM, Tushar Behera  wrote:
>>>
>>> The u-boot version is a little different on my Peach-Pi as compared to
>>> the market release version. Not sure if that is making any difference.
>>>
>>> Peach # version
>>>
>>> U-Boot 2013.04 (Feb 13 2014 - 16:35:03) for Peach
>>> armv7a-cros-linux-gnueabi-gcc.real (4.8.1_cos_gg_feea904_4.8.1-r66)
>>> 4.8.x-google 20130905 (prerelease)
>>> GNU ld (binutils-2.22_cos_gg_2) 2.22
>>>
>>

I'm using the same U-Boot version than Kevin (U-Boot 2013.04-gb98ed09)
and on my setup using chained nv-uboot I also need patch 1/3 along
with 2/3 to fix the issue.

>> Note that I've applied this only from this series so I'm not sure how
>> much the problem can be solved...any updates for 1/3 and 3/3?
>>
>> - Kukjin
>
> Thanks for applying 2/3. I am working on 1/3 to see if we are following
> the right approach to fix Kevin's issue (unfortunately, I am not hitting
> the bug on my board ATM). 3/3 has already been merged through a
> different patchset.
>

I'm sending as an attachment my complete boot log when booting today's
next (20140709) until it hangs and my u-boot env vars. I hope that
helps.

> --
> Tushar Behera
> --

Best regards,
Javier


boot_log
Description: Binary data


uboot_env
Description: Binary data


Re: [PATCH 2/3] ARM: dts: Update the parent for Audss clocks in Exynos5420

2014-07-09 Thread Javier Martinez Canillas
Hello Tushar,

On Wed, Jul 9, 2014 at 2:11 PM, Tushar Behera  wrote:
> On 07/09/2014 03:44 PM, Javier Martinez Canillas wrote:
>> Hello Tushar,
>>
>> On Tue, Jul 8, 2014 at 5:00 AM, Tushar Behera  wrote:
>>>>>
>>>>> The u-boot version is a little different on my Peach-Pi as compared to
>>>>> the market release version. Not sure if that is making any difference.
>>>>>
>>>>> Peach # version
>>>>>
>>>>> U-Boot 2013.04 (Feb 13 2014 - 16:35:03) for Peach
>>>>> armv7a-cros-linux-gnueabi-gcc.real (4.8.1_cos_gg_feea904_4.8.1-r66)
>>>>> 4.8.x-google 20130905 (prerelease)
>>>>> GNU ld (binutils-2.22_cos_gg_2) 2.22
>>>>>
>>>>
>>
>> I'm using the same U-Boot version than Kevin (U-Boot 2013.04-gb98ed09)
>> and on my setup using chained nv-uboot I also need patch 1/3 along
>> with 2/3 to fix the issue.
>>
>>>> Note that I've applied this only from this series so I'm not sure how
>>>> much the problem can be solved...any updates for 1/3 and 3/3?
>>>>
>>>> - Kukjin
>>>
>>> Thanks for applying 2/3. I am working on 1/3 to see if we are following
>>> the right approach to fix Kevin's issue (unfortunately, I am not hitting
>>> the bug on my board ATM). 3/3 has already been merged through a
>>> different patchset.
>>>
>>
>> I'm sending as an attachment my complete boot log when booting today's
>> next (20140709) until it hangs and my u-boot env vars. I hope that
>> helps.
>>
>
> Would you please check the behaviour after enabling following config
> options?
>
> diff --git a/arch/arm/configs/exynos_defconfig
> b/arch/arm/configs/exynos_defconfig
> index e07a227..d6056ab 100644
> --- a/arch/arm/configs/exynos_defconfig
> +++ b/arch/arm/configs/exynos_defconfig
> @@ -93,6 +93,11 @@ CONFIG_FRAMEBUFFER_CONSOLE=y
>  CONFIG_FONTS=y
>  CONFIG_FONT_7x14=y
>  CONFIG_LOGO=y
> +CONFIG_SOUND=y
> +CONFIG_SND=y
> +CONFIG_SND_SOC=y
> +CONFIG_SND_SOC_SAMSUNG=y
> +CONFIG_SND_SOC_SNOW=y
>  CONFIG_USB=y
>  CONFIG_USB_EHCI_HCD=y
>  CONFIG_USB_EHCI_EXYNOS=y
> @@ -109,6 +114,8 @@ CONFIG_MMC_DW_IDMAC=y
>  CONFIG_MMC_DW_EXYNOS=y
>  CONFIG_RTC_CLASS=y
>  CONFIG_RTC_DRV_S3C=y
> +CONFIG_DMADEVICES=y
> +CONFIG_PL330_DMA=y
>  CONFIG_COMMON_CLK_MAX77686=y
>  CONFIG_EXT2_FS=y
>  CONFIG_EXT3_FS=y
>
>

With those Kconfig options enabled the kernel does not hang anymore so
patch 1/3 is not needed in that case.

Best regards,
Javier
--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/3] ARM: dts: Update the parent for Audss clocks in Exynos5420

2014-07-09 Thread Javier Martinez Canillas
Hello Doug,

On Wed, Jul 9, 2014 at 6:01 PM, Doug Anderson  wrote:
> Javier,
>
> On Wed, Jul 9, 2014 at 6:03 AM, Javier Martinez Canillas
>  wrote:
>> Hello Tushar,
>>
>> On Wed, Jul 9, 2014 at 2:11 PM, Tushar Behera  wrote:
>>> On 07/09/2014 03:44 PM, Javier Martinez Canillas wrote:
>>>> Hello Tushar,
>>>>
>>>> On Tue, Jul 8, 2014 at 5:00 AM, Tushar Behera  wrote:
>>>>>>>
>>>>>>> The u-boot version is a little different on my Peach-Pi as compared to
>>>>>>> the market release version. Not sure if that is making any difference.
>>>>>>>
>>>>>>> Peach # version
>>>>>>>
>>>>>>> U-Boot 2013.04 (Feb 13 2014 - 16:35:03) for Peach
>>>>>>> armv7a-cros-linux-gnueabi-gcc.real (4.8.1_cos_gg_feea904_4.8.1-r66)
>>>>>>> 4.8.x-google 20130905 (prerelease)
>>>>>>> GNU ld (binutils-2.22_cos_gg_2) 2.22
>>>>>>>
>>>>>>
>>>>
>>>> I'm using the same U-Boot version than Kevin (U-Boot 2013.04-gb98ed09)
>>>> and on my setup using chained nv-uboot I also need patch 1/3 along
>>>> with 2/3 to fix the issue.
>>>>
>>>>>> Note that I've applied this only from this series so I'm not sure how
>>>>>> much the problem can be solved...any updates for 1/3 and 3/3?
>>>>>>
>>>>>> - Kukjin
>>>>>
>>>>> Thanks for applying 2/3. I am working on 1/3 to see if we are following
>>>>> the right approach to fix Kevin's issue (unfortunately, I am not hitting
>>>>> the bug on my board ATM). 3/3 has already been merged through a
>>>>> different patchset.
>>>>>
>>>>
>>>> I'm sending as an attachment my complete boot log when booting today's
>>>> next (20140709) until it hangs and my u-boot env vars. I hope that
>>>> helps.
>>>>
>>>
>>> Would you please check the behaviour after enabling following config
>>> options?
>>>
>>> diff --git a/arch/arm/configs/exynos_defconfig
>>> b/arch/arm/configs/exynos_defconfig
>>> index e07a227..d6056ab 100644
>>> --- a/arch/arm/configs/exynos_defconfig
>>> +++ b/arch/arm/configs/exynos_defconfig
>>> @@ -93,6 +93,11 @@ CONFIG_FRAMEBUFFER_CONSOLE=y
>>>  CONFIG_FONTS=y
>>>  CONFIG_FONT_7x14=y
>>>  CONFIG_LOGO=y
>>> +CONFIG_SOUND=y
>>> +CONFIG_SND=y
>>> +CONFIG_SND_SOC=y
>>> +CONFIG_SND_SOC_SAMSUNG=y
>>> +CONFIG_SND_SOC_SNOW=y
>>>  CONFIG_USB=y
>>>  CONFIG_USB_EHCI_HCD=y
>>>  CONFIG_USB_EHCI_EXYNOS=y
>>> @@ -109,6 +114,8 @@ CONFIG_MMC_DW_IDMAC=y
>>>  CONFIG_MMC_DW_EXYNOS=y
>>>  CONFIG_RTC_CLASS=y
>>>  CONFIG_RTC_DRV_S3C=y
>>> +CONFIG_DMADEVICES=y
>>> +CONFIG_PL330_DMA=y
>>>  CONFIG_COMMON_CLK_MAX77686=y
>>>  CONFIG_EXT2_FS=y
>>>  CONFIG_EXT3_FS=y
>>>
>>>
>>
>> With those Kconfig options enabled the kernel does not hang anymore so
>> patch 1/3 is not needed in that case.
>
> Just checking: did you happen to confirm whether it's the PL330 /
> DMADEVICES that fixes things or do you actually need the sound stuff?

Sorry I should had mentioned this before. The DMADEVICES and PL330
Kconfig are enough to avoid the kernel to hang, the sound config
options are not actually required.

Best regards,
Javier
--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v7 04/24] mfd: max77686: Make platform data over-rule DT

2014-07-09 Thread Javier Martinez Canillas
Hello Lee,

On 07/09/2014 04:52 PM, Lee Jones wrote:
> On Fri, 04 Jul 2014, Javier Martinez Canillas wrote:
> 
>> The function max77802_i2c_parse_dt_pdata() should only be called
>> if there isn't already platform data for the device.
>> 
>> Signed-off-by: Javier Martinez Canillas 
>> ---
>>  drivers/mfd/max77686.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> I assume some of these patches can be applied independently.
>

Yes, some patches can be applied independently and it would be quite helpful
indeed since that will allow me to keep a smaller series :)

> Let me know which ones and I'll apply them.  In the mean time:
> 
> Acked-by: Lee Jones 
> 

Patches 1-7 are just cleanups and improvements for max77686 mfd driver so they
can be applied safely. You had already acked 1-6 and 7 is just a trivial patch
so I guess you won't have issues with that one as well.

Patches 11 and 14 are small patches for the max77802 clk driver and Mike already
gave his Reviewed-by tag so if you are going to take the whole set through your
tree those two patches are safe to be applied as well.

Thanks a lot for your help and best regards,
Javier
--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v7 08/24] mfd: max77686: Add Dynamic Voltage Scaling (DVS) support

2014-07-09 Thread Javier Martinez Canillas
Hello Lee,

Thanks a lot for your feedback.

On 07/09/2014 05:13 PM, Lee Jones wrote:
> I'd really like Linus Walleij to look over this if possible.
> 

Ok, I'll cc Linus when posting the next version of the series.

> On Fri, 04 Jul 2014, Javier Martinez Canillas wrote:
>> Some regulators on the MAX77686 PMIC have Dynamic Voltage Scaling
>> (DVS) support that allows output voltage to change dynamically.
>> 
>> For MAX77686, these regulators are Buck regulators 2, 3 and 4.
>> 
>> Each Buck output voltage is selected using a set of external
>> inputs: DVS1-3 and SELB2-4.
>> 
>> DVS registers can be used to configure the output voltages for each
>> Buck regulator and which one is active is controled by DVSx lines.
>> 
>> SELBx lines are used to control if individual Buck lines are ON or OFF.
>> 
>> This patch adds support to configure the DVSx and SELBx lines
>> from DT and to setup and read the GPIO lines connected to them.
>> 
>> Signed-off-by: Javier Martinez Canillas 
>> Reviewed-by: Krzysztof Kozlowski 
>> ---
>> 
>> Changes since v6:
>>  - Add a comment that max77686_read_gpios() function can sleep.
>>Sugggested by Krzysztof Kozlowski
>> ---
>>  drivers/mfd/max77686.c   | 119 
>> +++
>>  include/linux/mfd/max77686.h |  18 ---
>>  2 files changed, 129 insertions(+), 8 deletions(-)
>> 
>> diff --git a/drivers/mfd/max77686.c b/drivers/mfd/max77686.c
>> index 8650832..d193873 100644
>> --- a/drivers/mfd/max77686.c
>> +++ b/drivers/mfd/max77686.c
>> @@ -32,8 +32,10 @@
>>  #include 
>>  #include 
>>  #include 
>> +#include 
>>  #include 
>>  #include 
>> +#include 
>>  
>>  #define I2C_ADDR_RTC(0x0C >> 1)
>>  
>> @@ -101,9 +103,119 @@ static const struct of_device_id 
>> max77686_pmic_dt_match[] = {
>>  {},
>>  };
>>  
>> +static void max77686_dt_parse_dvs_gpio(struct device *dev)
>> +{
>> +struct max77686_platform_data *pd = dev_get_platdata(dev);
>> +int i;
>> +
>> +/*
>> + * NOTE: we don't consider GPIO errors fatal; board may have some lines
>> + * directly pulled high or low and thus doesn't specify them.
>> + */
>> +for (i = 0; i < ARRAY_SIZE(pd->buck_gpio_dvs); i++)
>> +pd->buck_gpio_dvs[i] =
>> +devm_gpiod_get_index(dev, "max77686,pmic-buck-dvs", i);
>> +
>> +for (i = 0; i < ARRAY_SIZE(pd->buck_gpio_selb); i++)
>> +pd->buck_gpio_selb[i] =
>> +devm_gpiod_get_index(dev, "max77686,pmic-buck-selb", i);
>> +}
> 
> Not sure why you've pulled this out for parse_dt_pdata()?
> 

Ok, I'll remove that function and put the code in max77686_i2c_parse_dt_pdata().

>> +/**
>> + * max77686_setup_gpios() - init DVS-related GPIOs
>> + * @dev: device whose platform data contains the dvs GPIOs information
>> + *
>> + * This function claims / initalizations GPIOs related to DVS if they are
> 
> s/initialzations/initialises
> 

Right, will fix the typo.

>> + * defined. This may have the effect of switching voltages if the
> 
> s/if the/if
> 

Ditto.

>> + * pdata->buck_default_idx does not match the boot time state of pins.
>> + */
>> +int max77686_setup_gpios(struct device *dev)
>> +{
>> +struct max77686_platform_data *pd = dev_get_platdata(dev);
>> +int buck_default_idx = pd->buck_default_idx;
> 
> You're saving 4 characters once here.  Just use the variable in pd.
> 

Ok

>> +int ret;
>> +int i;
> 
> Don't you want some locking around this?
> 

This function is only called in the max77686 and max77802 regulator drivers
probe functions and we expect to have either one of those in a system but never
both so this function can't really be executed concurrently.

And even in the case that a system has both max77686 and max77802 PMICs, all the
data accessed is local to the driver's struct device so I think there is no need
to add any locking here.

>> +/* Set all SELB high to avoid glitching while DVS is changing */
>> +for (i = 0; i < ARRAY_SIZE(pd->buck_gpio_selb); i++) {
>> +struct gpio_desc *gpio = pd->buck_gpio_selb[i];
>> +
>> +/* OK if some GPIOs aren't defined */
>> +if (IS_ERR(gpio))
>> +continue;
>> +
>> +ret = gpiod_direction_output_raw(gpio, 1);
>> +if (ret)

Re: [PATCH v7 18/24] mfd: max77686: Add Maxim 77802 PMIC support

2014-07-09 Thread Javier Martinez Canillas
Hello Lee,

On 07/09/2014 05:31 PM, Lee Jones wrote:
> On Fri, 04 Jul 2014, Javier Martinez Canillas wrote:
>> Maxim MAX77802 is a power management chip that contains 10 high
>> efficiency Buck regulators, 32 Low-dropout (LDO) regulators used
>> to power up application processors and peripherals, a 2-channel
>> 32kHz clock outputs, a Real-Time-Clock (RTC) and a I2C interface
>> to program the individual regulators, clocks outputs and the RTC.
>> 
>> This patch adds support for MAX77802 to the MAX77686 driver and is
>> based on a driver added to the Chrome OS kernel 3.8 by Simon Glass.
>> 
>> Signed-off-by: Javier Martinez Canillas 
>> Reviewed-by: Krzysztof Kozlowski 
>> ---
> 
> [...]
> 
>>  static const struct i2c_device_id max77686_i2c_id[] = {
>>  { "max77686", TYPE_MAX77686 },
>> +{ "max77802", TYPE_MAX77802 },
>>  { }
> 
> There's no point in filling this in.  Just empty it completely.
> 

Ok, I won't fill this

> Once you've done that, resubmit the patchset with my:
> 
> Acked-by: Lee Jones 
> 

Thanks a lot.

Best regards,
Javier
--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v7 08/24] mfd: max77686: Add Dynamic Voltage Scaling (DVS) support

2014-07-10 Thread Javier Martinez Canillas
Hello Linus,

On 07/10/2014 11:46 AM, Linus Walleij wrote:
> On Fri, Jul 4, 2014 at 10:24 PM, Javier Martinez Canillas
>  wrote:
> 
>> Some regulators on the MAX77686 PMIC have Dynamic Voltage Scaling
>> (DVS) support that allows output voltage to change dynamically.
>>
>> For MAX77686, these regulators are Buck regulators 2, 3 and 4.
>>
>> Each Buck output voltage is selected using a set of external
>> inputs: DVS1-3 and SELB2-4.
>>
>> DVS registers can be used to configure the output voltages for each
>> Buck regulator and which one is active is controled by DVSx lines.
>>
>> SELBx lines are used to control if individual Buck lines are ON or OFF.
>>
>> This patch adds support to configure the DVSx and SELBx lines
>> from DT and to setup and read the GPIO lines connected to them.
>>
>> Signed-off-by: Javier Martinez Canillas 
>> Reviewed-by: Krzysztof Kozlowski 
> 
> (...)
>> +#include 
> 
> THANKS for using modern interfaces!
> 

Thanks to you and Alexandre for keep improving the GPIO subsystem!

>> +static void max77686_dt_parse_dvs_gpio(struct device *dev)
>> +{
>> +   struct max77686_platform_data *pd = dev_get_platdata(dev);
>> +   int i;
>> +
>> +   /*
>> +* NOTE: we don't consider GPIO errors fatal; board may have some 
>> lines
>> +* directly pulled high or low and thus doesn't specify them.
>> +*/
>> +   for (i = 0; i < ARRAY_SIZE(pd->buck_gpio_dvs); i++)
>> +   pd->buck_gpio_dvs[i] =
>> +   devm_gpiod_get_index(dev, "max77686,pmic-buck-dvs", 
>> i);
>> +
>> +   for (i = 0; i < ARRAY_SIZE(pd->buck_gpio_selb); i++)
>> +   pd->buck_gpio_selb[i] =
>> +   devm_gpiod_get_index(dev, "max77686,pmic-buck-selb", 
>> i);
>> +}
> 
> Rob Jones has a patch cooking that adds gpio_get_array() so this thing
> merits also adding devm_gpiod_get_array() I think?
> 

Yes, I just asked [0] Rob on the other thread if he is already implementing the
descriptor-based version of his devm_request_gpio_array() or if I should go and
implement it.

Now, I wonder if that can be done in a follow-up patch (e.g: use the new
devm_gpiod_get_array once it lands in Torvalds tree)  since this series already
touches several subsystems (mfd, regulators, clk and rtc) so if possible I would
prefer to not add another cross-subsystem dependency :)

>> +/**
>> + * max77686_setup_gpios() - init DVS-related GPIOs
>> + * @dev: device whose platform data contains the dvs GPIOs information
>> + *
>> + * This function claims / initalizations GPIOs related to DVS if they are
>> + * defined. This may have the effect of switching voltages if the
>> + * pdata->buck_default_idx does not match the boot time state of pins.
>> + */
>> +int max77686_setup_gpios(struct device *dev)
>> +{
>> +   struct max77686_platform_data *pd = dev_get_platdata(dev);
>> +   int buck_default_idx = pd->buck_default_idx;
>> +   int ret;
>> +   int i;
>> +
>> +   /* Set all SELB high to avoid glitching while DVS is changing */
>> +   for (i = 0; i < ARRAY_SIZE(pd->buck_gpio_selb); i++) {
>> +   struct gpio_desc *gpio = pd->buck_gpio_selb[i];
>> +
>> +   /* OK if some GPIOs aren't defined */
>> +   if (IS_ERR(gpio))
>> +   continue;
>> +
>> +   ret = gpiod_direction_output_raw(gpio, 1);
> 
> Why does this have to be raw? Usually that is not to be used.
> 

Right, I can't think of a good reason why this has to be raw and not just use
gpiod_direction_output() which will check the active-low flag and set the value
accordingly. I'll change it on the next revision.

> Apart from this it looks OK.
> 

Great, thanks a lot for your feedback.

> Yours,
> Linus Walleij
> 

Best regards,
Javier

[0]: https://lkml.org/lkml/2014/7/10/722
--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v7 08/24] mfd: max77686: Add Dynamic Voltage Scaling (DVS) support

2014-07-10 Thread Javier Martinez Canillas
Hello Amit,

On 07/10/2014 11:59 AM, amit daniel kachhap wrote:
> On Sat, Jul 5, 2014 at 1:54 AM, Javier Martinez Canillas
>  wrote:
>> Some regulators on the MAX77686 PMIC have Dynamic Voltage Scaling
>> (DVS) support that allows output voltage to change dynamically.
>>
>> For MAX77686, these regulators are Buck regulators 2, 3 and 4.
>>
>> Each Buck output voltage is selected using a set of external
>> inputs: DVS1-3 and SELB2-4.
>>
>> DVS registers can be used to configure the output voltages for each
>> Buck regulator and which one is active is controled by DVSx lines.
>>
>> SELBx lines are used to control if individual Buck lines are ON or OFF.
>>
>> This patch adds support to configure the DVSx and SELBx lines
>> from DT and to setup and read the GPIO lines connected to them.
> 
> The entire series looks nice. Few minor comments from my side. I guess
> still one more version in needed as per other ppls comment.
> You may add,
> Reviewed-by: Amit Daniel Kachhap 
>

Thanks.

>>
>> Signed-off-by: Javier Martinez Canillas 
>> Reviewed-by: Krzysztof Kozlowski 
>> ---
>>
>> Changes since v6:
>>  - Add a comment that max77686_read_gpios() function can sleep.
>>Sugggested by Krzysztof Kozlowski
>> ---
>>  drivers/mfd/max77686.c   | 119 
>> +++
>>  include/linux/mfd/max77686.h |  18 ---
>>  2 files changed, 129 insertions(+), 8 deletions(-)
>>
>> diff --git a/drivers/mfd/max77686.c b/drivers/mfd/max77686.c
>> index 8650832..d193873 100644
>> --- a/drivers/mfd/max77686.c
>> +++ b/drivers/mfd/max77686.c
>> @@ -32,8 +32,10 @@
>>  #include 
>>  #include 
>>  #include 
>> +#include 
>>  #include 
>>  #include 
>> +#include 
>>
>>  #define I2C_ADDR_RTC   (0x0C >> 1)
>>
>> @@ -101,9 +103,119 @@ static const struct of_device_id 
>> max77686_pmic_dt_match[] = {
>> {},
>>  };
>>
>> +static void max77686_dt_parse_dvs_gpio(struct device *dev)
>> +{
>> +   struct max77686_platform_data *pd = dev_get_platdata(dev);
>> +   int i;
>> +
>> +   /*
>> +* NOTE: we don't consider GPIO errors fatal; board may have some 
>> lines
>> +* directly pulled high or low and thus doesn't specify them.
>> +*/
>> +   for (i = 0; i < ARRAY_SIZE(pd->buck_gpio_dvs); i++)
>> +   pd->buck_gpio_dvs[i] =
>> +   devm_gpiod_get_index(dev, "max77686,pmic-buck-dvs", 
>> i);
>> +
>> +   for (i = 0; i < ARRAY_SIZE(pd->buck_gpio_selb); i++)
>> +   pd->buck_gpio_selb[i] =
>> +   devm_gpiod_get_index(dev, "max77686,pmic-buck-selb", 
>> i);
>> +}
>> +
>> +/**
>> + * max77686_setup_gpios() - init DVS-related GPIOs
>> + * @dev: device whose platform data contains the dvs GPIOs information
>> + *
>> + * This function claims / initalizations GPIOs related to DVS if they are
>> + * defined. This may have the effect of switching voltages if the
>> + * pdata->buck_default_idx does not match the boot time state of pins.
>> + */
>> +int max77686_setup_gpios(struct device *dev)
>> +{
>> +   struct max77686_platform_data *pd = dev_get_platdata(dev);
>> +   int buck_default_idx = pd->buck_default_idx;
>> +   int ret;
>> +   int i;
>> +
>> +   /* Set all SELB high to avoid glitching while DVS is changing */
>> +   for (i = 0; i < ARRAY_SIZE(pd->buck_gpio_selb); i++) {
>> +   struct gpio_desc *gpio = pd->buck_gpio_selb[i];
>> +
>> +   /* OK if some GPIOs aren't defined */
>> +   if (IS_ERR(gpio))
>> +   continue;
>> +
>> +   ret = gpiod_direction_output_raw(gpio, 1);
>> +   if (ret) {
>> +   dev_err(dev, "can't set gpio[%d] dir: %d\n", i, ret);
>> +   return ret;
>> +   }
>> +   }
>> +
>> +   /* Set our initial setting */
>> +   for (i = 0; i < ARRAY_SIZE(pd->buck_gpio_dvs); i++) {
>> +   struct gpio_desc *gpio = pd->buck_gpio_dvs[i];
>> +
>> +   /* OK if some GPIOs aren't defined */
>> +   if (IS_ERR(gpio))
>> +   continue;
>> +
>> +   /* If a GPIO is valid, set it */
>> +   gpiod_di

Re: [PATCH v6 15/23] regulator: max77686: Setup DVS-related GPIOs on probe

2014-07-10 Thread Javier Martinez Canillas
Hello Amit,

On 07/10/2014 12:08 PM, amit daniel kachhap wrote:
> On Fri, Jul 4, 2014 at 3:25 PM, Javier Martinez Canillas
>  wrote:
>> MAX77686 PMIC support Dyamic Voltage Scaling (DVS) on a set
>> of Buck regulators. A number of GPIO are connected to these
>> lines and are requested by the mfd driver. Setup the GPIO
>> pins from the regulator driver.
> If possible merge this patch with patch 8. Both are adding DVS
> support. Put regmap_copy dependency patch in very beginning.

As Lee already said, I split the changes to minimize the cross-subsystem churn.

>>
>> Signed-off-by: Javier Martinez Canillas 
>> ---
>>  drivers/regulator/max77686.c | 34 ++
>>  1 file changed, 34 insertions(+)
>>
>> diff --git a/drivers/regulator/max77686.c b/drivers/regulator/max77686.c
>> index ef1af2d..ecce77a 100644
>> --- a/drivers/regulator/max77686.c
>> +++ b/drivers/regulator/max77686.c
>> @@ -435,6 +435,12 @@ static int max77686_pmic_dt_parse_pdata(struct 
>> platform_device *pdev,
>>  }
>>  #endif /* CONFIG_OF */
>>
>> +static inline bool max77686_is_dvs_buck(int id)
>> +{
>> +   /* BUCK 2,3 and 4 support DVS */
>> +   return (id >= MAX77686_BUCK2 && id <= MAX77686_BUCK4);
> I am just wondering if along with above check, SELB gpios (if present)
> can be used to confirm if BUCK's are DVS based or not.

I don't know if SELB gpios being present or not should be used to determine
whether a BUCK includes the DVS feature. AFAIK boards could have some of these
lines hardwired and pulled high or low instead of using a GPIO.

>> +}
>> +
>>  static int max77686_pmic_probe(struct platform_device *pdev)
>>  {
>> struct max77686_dev *iodev = dev_get_drvdata(pdev->dev.parent);
>> @@ -442,6 +448,9 @@ static int max77686_pmic_probe(struct platform_device 
>> *pdev)
>> struct max77686_data *max77686;
>> int i, ret = 0;
>> struct regulator_config config = { };
>> +   unsigned int reg;
>> +   int buck_default_idx;
>> +   int buck_old_idx;
>>
>> dev_dbg(&pdev->dev, "%s\n", __func__);
>>
>> @@ -472,13 +481,34 @@ static int max77686_pmic_probe(struct platform_device 
>> *pdev)
>> config.driver_data = max77686;
>> platform_set_drvdata(pdev, max77686);
>>
>> +   buck_default_idx = pdata->buck_default_idx;
>> +   buck_old_idx = max77686_read_gpios(pdata);
>> +
>> for (i = 0; i < MAX77686_REGULATORS; i++) {
>> struct regulator_dev *rdev;
>> +   int id = pdata->regulators[i].id;
>>
>> config.init_data = pdata->regulators[i].initdata;
>> config.of_node = pdata->regulators[i].of_node;
>>
>> max77686->opmode[i] = regulators[i].enable_mask;
>> +
>> +   if (max77686_is_dvs_buck(id)) {
>> +   /* Try to copy over data so we keep firmware 
>> settings */
>> +   reg = regulators[i].vsel_reg;
>> +
>> +   ret = regmap_reg_copy(iodev->regmap,
>> + reg + buck_default_idx,
>> + reg + buck_old_idx);
>> +
>> +   if (ret)
>> +   dev_warn(&pdev->dev, "Copy err %d => %d 
>> (%d)\n",
>> +reg + buck_old_idx,
>> +reg + buck_default_idx, ret);
>> +
>> +   regulators[i].vsel_reg += buck_default_idx;
>> +   }
>> +
>> rdev = devm_regulator_register(&pdev->dev,
>> ®ulators[i], &config);
>> if (IS_ERR(rdev)) {
>> @@ -488,6 +518,10 @@ static int max77686_pmic_probe(struct platform_device 
>> *pdev)
>> }
>> }
>>
>> +   ret = max77686_setup_gpios(iodev->dev);
>> +   if (ret)
>> +   return ret;
>> +
>> return 0;
>>  }
>>
>> --
>> 2.0.0.rc2
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" 
>> in
>> the body of a message to majord...@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

Best regards,
Javier
--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v7 08/24] mfd: max77686: Add Dynamic Voltage Scaling (DVS) support

2014-07-11 Thread Javier Martinez Canillas
Hello Tomasz,

On 07/11/2014 11:43 AM, Tomasz Figa wrote:
> Hi Javier,
> 
> On 11.07.2014 03:45, Javier Martinez Canillas wrote:
>> On 07/10/2014 11:59 AM, amit daniel kachhap wrote:
>>> On Sat, Jul 5, 2014 at 1:54 AM, Javier Martinez Canillas
>>>  wrote:
> 
> [snip]
> 
>>>> @@ -111,6 +223,13 @@ static struct max77686_platform_data 
>>>> *max77686_i2c_parse_dt_pdata(struct device
>>>> return NULL;
>>>>
>>>> dev->platform_data = pd;
>>>> +
>>>> +   /* Read default index and ignore errors, since default is 0 */
>>>> +   of_property_read_u32(np, "max77686,pmic-buck-default-dvs-idx",
>>>> +&pd->buck_default_idx);
>>> Any error checking code here. Say if pmic-buck-default-dvs-idx exceed 8?
>> 
>> I'm not a DT expert but AFAIK the kernel should expect the data in a FDT to 
>> be
>> correct and should not validate it on runtime. There is work-in-progress to 
>> add
>> a proper schema checking for DTS to the dtc so on build time it can be 
>> validated
>> that a DTS is valid.
>> 
>> AFAIU the only thing that the kernel should check is if a required property 
>> does
>> not exist.
> 
> I'd disagree on this.
> 
> IMHO schema (if it progresses further, as unfortunately I can't find
> time to dedicate to it and looks like it's similar for other people that
> used to be involved) should be focused on structural checks, i.e. proper
> layout of nodes and properties, basic data types and so, to figure out
> common errors earlier than at boot-up time.
> 
> On kernel side this should be treated in the same way as platform data.
> I agree that some existing drivers do little to validate incoming data,
> but I believe it is a good practice to validate things that the driver
> has no control over, especially when it's about a PMIC, when invalid
> data can have quite serious effects and detecting even some of them
> (e.g. value to big, which would overflow in target bit field) might
> prevent a failure.
> 

Thanks a lot for the clarification and I completely agree with your explanation.
I'll add proper validation for the data obtained by DT then. It would be nice if
this was documented somewhere (or maybe I missed it).

> Best regards,
> Tomasz
> 

Best regards,
Javier
--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/3 v5] spi: s3c64xx: fix broken "cs_gpios" usage in the driver

2014-07-11 Thread Javier Martinez Canillas
Hello Naveen and Mark,

On Mon, Jul 7, 2014 at 1:22 PM, Javier Martinez Canillas
 wrote:
> On Mon, Jul 7, 2014 at 10:31 AM, Naveen Krishna Ch
>  wrote:
>>>
>>>> >> Hence, spi-s3c64xx.c is broken since "Jun 21 11:26:12 2013" and
>>>> >> considering the time with no compliants about the breakage.
>>>
>>>> > I'm not clear what the breakage is?  Some boards are broken but what's
>>>> > the driver issue?
>>>
>>>> ToT was broken for few boards
>>>> exynos4412-trats2.dts, exynos4210-smdkv310.dts and exynos5250-smdk5250.dts
>>>
>>>> With some DTS changes SPI works well, spi-s3c64xx.c driver had no issues.
>>>
>
> Correct me if I'm wrong but I think that the driver does have issues
> since the commit mentioned (3146bee) broke DT backward compatibility.
>
>>> No, you're not answering my question - to repeat, what is the breakage?
>>
>
> As far as I understand, the breakage is that any DTS that followed the
> DT binding documented in
> Documentation/devicetree/bindings/spi/spi-samsung.txt is not working
> with the current driver. So is not that some boards are broken, is
> that the driver is broken and it has been broken for more than a year
> (the commit date is Jun 21 2013).
>
>> The Documentation/devicetree/bindings/spi/spi-samsung.txt
>> describes "cs-gpio" as a controller specific property.
>>
>> The dts entries for SPI in exynos4412-trats2.dts, exynos4210-smdkv310.dts
>> and exynos5250-smdk5250.dts boards have the "cs-gpio" property defined
>> under controller-data node, which is inside the SPI device node
>> &spi_1 {
>>   controller-data {
>> cs-gpio = <>;
>>   };
>> };
>>
>> But, _probe() of spi-s3c64xx.c driver looks for "cs-gpio" in the SPI
>> device node and
>> sets a flag "sdd->cs_gpio = false" (If the property is not available)
>> &spi_1 {
>>   cs-gpio = <>;
>> };
>>
>> the sdd->cs_gpio flag is checked before actually getting the gpios
>> from the controller-data node
>>if (sdd->cs_gpio)
>> cs->line = of_get_named_gpio(data_np, "cs-gpio", 0);
>>
>
> I think that if changing the binding is not possible, at least we
> should document this new "cs-gpio" property that is looked in the top
> level SPI node after commit 3146bee and also revert the default in
> order to allow DTs using the old binding to keep working.
>
> By default not having the "cs-gpio" property in the SPI dev node
> should mean that the "cs-gpio" property in the controller-data node
> should be used to signal the chip-select and having the "cs-gpio"
> property in the SPI node should mean that the native chip select
> should be used instead of a GPIO. That preserves the old DT binding
> semantic while making the GPIO to be optional.
>
> Of course in that case the property name does not make too much sense,
> so probably should be changed to "cs-native" or something like that.
> But I still don't understand why this is needed in the first place
> since according to Documentation/devicetree/bindings/spi/spi-bus.txt
> you can use the cs-gpios property to specify that a native chip-select
> will be used instead of a GPIO by doing:
>
> cs-gpios = <&gpio1 0 0> <0>
>
> cs0 : &gpio1 0 0
> cs1 : native
>
>> Hence, SPI was failing on those boards.
>>
>> 1. As the SPI core and several drivers were changed to work with
>> DT property "cs-gpios" (plural) defined under SPI node.
>> 2. Since the commit 3146beec21b64f4551fcf0ac148381d54dc41b1b
>> "spi: s3c64xx: Added provision for dedicated cs pin"
>> Dated:   Fri Jun 21 11:26:12 2013 +0530
>>
>> For the above 2 reasons, It was decided to drop the backward compatibility
>> of using "cs-gpio"(singular) in controller-data.
>> Instead, start supporting "cs-gpios"(plural) in the SPI node.
>>
>
> Right, since the DT binding has been broken for a year and because is
> not consistent with the bindings used by all other SPI drivers, many
> agreed that it was one of the exceptional cases where the DT binding
> can be rethought and changed to use the generic "cs-gpios" property
> already supported by SPI core. It breaks backward compatibility that's
> true but the DT binding has been broken anyways and nobody noticed
> before.
>
> The other option is what I said above, fixing the DT binding
> compatibility breakage w

[PATCH v8 00/13] Add Maxim 77802 PMIC support

2014-07-14 Thread Javier Martinez Canillas
This series are based on drivers added by Simon Glass to the Chrome OS
kernel and adds support for the Maxim 77802 Power Management IC, their
regulators, clocks, RTC and i2c interface.

This is a v8 of the patch-set that addresses issues pointed out in v7.
Individual changes are added on each patch but the biggest changes are:

* Patches 1-7 from v7 are not included since those were improvements to
the max77686 mfd driver and can be applied independently. Lee Jones said
that he is going to pick them from the posted v7 series.

I've created a patchwork bundle with 1-7 from v7 to make it easy to apply:

https://patchwork.kernel.org/bundle/javier/max77686-improvements/

* The Dynamic Voltage Scaling support has been removed since that can be
added in a follow up series and shouldn't block the minimum PMIC support.

The patch-set has been tested on both Daisy/Snow (max77686) and Peach
Pit (max77802) Chromebooks and it's composed of the following patches:

[PATCH v8 01/13] mfd: max77686: Add Maxim 77802 PMIC support
[PATCH v8 02/13] mfd: max77802: Add DT binding documentation
[PATCH v8 03/13] regulator: Add driver for Maxim 77802 PMIC regulators
[PATCH v8 04/13] clk: max77686: Add DT include for MAX77686 PMIC clock
[PATCH v8 05/13] clk: Add generic driver for Maxim PMIC clocks
[PATCH v8 06/13] clk: max77686: Convert to the generic max clock driver
[PATCH v8 07/13] clk: max77686: Improve Maxim 77686 PMIC clocks binding
[PATCH v8 08/13] clk: Add driver for Maxim 77802 PMIC clocks
[PATCH v8 09/13] clk: max77802: Add DT binding documentation
[PATCH v8 10/13] rtc: max77686: Allow the max77686 rtc to wakeup the system
[PATCH v8 11/13] rtc: max77686: Remove dead code for SMPL and WTSR
[PATCH v8 12/13] rtc: Add driver for Maxim 77802 PMIC Real-Time-Clock
[PATCH v8 13/13] ARM: dts: Add max77802 to exynos5420-peach-pit and 
exynos5800-peach-pi

Patch 01/13 extend the max77686 mfd driver to also support the max77802
PMIC and patch 02/13 adds the DT binding documentation for this PMIC.

Patch 03/13 adds support for the regulators found in the PMIC.

Patch 04/13 to 07/13 are improvements and refactoring to the max77686 clock
driver to avoid code duplication when adding max77802 clocks support in patch
08/13. Patch 09/13 adds the DT binding document for the max77802 clock driver.

Patches 10/13 and 11/13 are improvements to max77686 RTC driver and patch
12/13 adds support for the RTC found in the max77802 PMIC.

Finally patch 13/13 adds the required device node to the Peach Pit and Pi
exynos5 based boards.

Since there are cross-subsystems dependencies, I think that the best way to
sort this out is if relevant maintainers ack the patches so 01/13 to 012/13
can be merged through the mfd tree. The patches and the relevant acks are:

Patch 03/13 (regulator - Mark Brown)
Patches 04/13 to 09/13 (clk - Mike Turquette)
Patches 10/13 to 12/13 (rtc - Alessandro Zummo)

Patch 13/13 is only a DTS change so it can be picked by Kukjin Kim once the
other patches are picked by Lee Jones.

Since we are in 3.16-rc5 already, it would be great if I can get your acks
or feedback since I was hoping this series to make it to 3.17. This is due
other series that were already posted depend on this one.

Also, the series have been reviewed and tested by Samsung folks and most of
the patches already collected Reviewed-by and Tested-by tags.

Thanks a lot and best regards,
Javier

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v8 01/13] mfd: max77686: Add Maxim 77802 PMIC support

2014-07-14 Thread Javier Martinez Canillas
Maxim MAX77802 is a power management chip that contains 10 high
efficiency Buck regulators, 32 Low-dropout (LDO) regulators used
to power up application processors and peripherals, a 2-channel
32kHz clock outputs, a Real-Time-Clock (RTC) and a I2C interface
to program the individual regulators, clocks outputs and the RTC.

This patch adds support for MAX77802 to the MAX77686 driver and is
based on a driver added to the Chrome OS kernel 3.8 by Simon Glass.

Signed-off-by: Javier Martinez Canillas 
Reviewed-by: Krzysztof Kozlowski 
Acked-by: Lee Jones 
---

Changes since v7:
 - Don't add an entry in the i2c_device_id table. Suggested by Lee Jones.
 - Use of_device_id match table instead of i2c_device_id to know the PMIC type.

Changes since v6:
 - Fix comments grammar. Suggested by Krzysztof Kozlowski.
 - Only unregister the RTC i2c device if the type is MAX77686.
   Suggested by Krzysztof Kozlowski.

Changes since v5:
 - Extend the 77686 driver to support 77802 instead of adding a new driver.
   Suggested by Lee Jones.

Changes since v4:
 - Use consistent expressions when checking for NULL values.
   Suggested by Krzysztof Kozlowski.
 - Remove unused defines. Suggested by Krzysztof Kozlowski.
 - Explain why IRQ is disabled on suspend. Suggested by Krzysztof Kozlowski.

Changes since v3:
 - Remove unnecessary OOM error message since the mm subsystem already logs it.

Changes since v2:
 - Split the DT binding docs in a separate patch and improve the documentation.
   Suggested by Mark Brown.
 - Add all the devices in the MFD driver instead of doing in separate patches.
   Suggested by Mark Brown.

Changes since v1:
 - Convert max77{686,802} to regmap irq API and get rid of max77{686,802}-irq.c
   Suggested by Krzysztof Kozlowski.
 - Don't protect max77802 mfd_cells using Kconfig options since mfd core omits
   devices that don't match. Suggested by Lee Jones.
 - Change mfd driver to be tristate instead of boolean. Suggested by Mark Brown.
 - Change binding "voltage-regulators" property to "regulators" to be consistent
   with other PMIC drivers. Suggested by Mark Brown.
 - Use regulators node names instead of the deprecated "regulator-compatible"
   property. Suggested by Mark Brown.
 - Use the new descriptor-based GPIO interface instead of the deprecated
---
 drivers/mfd/Kconfig  |   6 +-
 drivers/mfd/max77686.c   | 201 -
 include/linux/mfd/max77686-private.h | 208 ++-
 include/linux/mfd/max77686.h |  57 +-
 4 files changed, 438 insertions(+), 34 deletions(-)

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 3010204..de5abf2 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -380,15 +380,15 @@ config MFD_MAX14577
  of the device.
 
 config MFD_MAX77686
-   bool "Maxim Semiconductor MAX77686 PMIC Support"
+   bool "Maxim Semiconductor MAX77686/802 PMIC Support"
depends on I2C=y
select MFD_CORE
select REGMAP_I2C
select REGMAP_IRQ
select IRQ_DOMAIN
help
- Say yes here to add support for Maxim Semiconductor MAX77686.
- This is a Power Management IC with RTC on chip.
+ Say yes here to add support for Maxim Semiconductor MAX77686 and
+ MAX77802 which are Power Management IC with an RTC on chip.
  This driver provides common support for accessing the device;
  additional drivers must be enabled in order to use the functionality
  of the device.
diff --git a/drivers/mfd/max77686.c b/drivers/mfd/max77686.c
index 8650832..b26335e 100644
--- a/drivers/mfd/max77686.c
+++ b/drivers/mfd/max77686.c
@@ -1,5 +1,5 @@
 /*
- * max77686.c - mfd core driver for the Maxim 77686
+ * max77686.c - mfd core driver for the Maxim 77686/802
  *
  * Copyright (C) 2012 Samsung Electronics
  * Chiwoong Byun 
@@ -43,6 +43,74 @@ static const struct mfd_cell max77686_devs[] = {
{ .name = "max77686-clk", },
 };
 
+static const struct mfd_cell max77802_devs[] = {
+   { .name = "max77802-pmic", },
+   { .name = "max77802-clk", },
+   { .name = "max77802-rtc", },
+};
+
+static bool max77802_pmic_is_accessible_reg(struct device *dev,
+   unsigned int reg)
+{
+   return (reg >= MAX77802_REG_DEVICE_ID && reg < MAX77802_REG_PMIC_END);
+}
+
+static bool max77802_rtc_is_accessible_reg(struct device *dev,
+  unsigned int reg)
+{
+   return (reg >= MAX77802_RTC_INT && reg < MAX77802_RTC_END);
+}
+
+static bool max77802_is_accessible_reg(struct device *dev, unsigned int reg)
+{
+   return (max77802_pmic_is_accessible_reg(dev, reg) ||
+   max77802_rtc_is_accessible_reg(dev, reg));
+}
+
+static bool max77802_pmic_is_precious_reg(struct device *dev, un

[PATCH v8 02/13] mfd: max77802: Add DT binding documentation

2014-07-14 Thread Javier Martinez Canillas
Add Device Tree binding documentation for Maxim 77802 PMIC.

Signed-off-by: Javier Martinez Canillas 
---

Changes since v7:
 - Remove information about DVS since that will be added as a follow up.

Changes since v6: None

Changes since v5:
 - Use max77686,* properties instead of max77802,* since the support is
   now in the max77686 driver and that IP defined the properties first.
 - Fix issues in DT binding documentation. Suggested by Andreas Farber.

Changes since v4: None

Changes since v3: None

Changes since v2:
 - Explain better the Dynamic Voltage Scaling (DVS) support in some Buck
   regulators and the max77802,pmic-buck-{dvs,selb}-gpios properties.
   Suggested by Mark Brown.
---
 Documentation/devicetree/bindings/mfd/max77802.txt | 59 ++
 1 file changed, 59 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/max77802.txt

diff --git a/Documentation/devicetree/bindings/mfd/max77802.txt 
b/Documentation/devicetree/bindings/mfd/max77802.txt
new file mode 100644
index 000..9f72b8f
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/max77802.txt
@@ -0,0 +1,59 @@
+Maxim MAX77802 multi-function device
+
+MAX77802 is a Multifunction device with PMIC, RTC and Charger on chip. It is
+interfaced to host controller using i2c interface. PMIC, Charger and RTC
+submodules are addressed using same i2c slave address.
+
+This document describes the binding for mfd device and PMIC submodule.
+
+Binding for the built-in 32k clock generator block is defined separately
+in bindings/clk/maxim,max77802.txt file.
+
+Required properties:
+- compatible : Must be "maxim,max77802";
+- reg : Specifies the i2c slave address of PMIC block.
+- interrupts : This i2c device has an IRQ line connected to the main SoC.
+- interrupt-parent : The parent interrupt controller.
+
+Optional node:
+- regulators : The regulators of max77802 have to be instantiated
+  under subnode named "regulators" using the following format.
+
+   regulator-name {
+   standard regulator constraints
+   };
+   refer Documentation/devicetree/bindings/regulator/regulator.txt
+
+  The regulator node name should be initialized with a string
+to get matched with their hardware counterparts as follow. The valid names are:
+
+   -LDOn   :   for LDOs, where n can lie in range 1 to 35.
+   example: LDO1, LDO2, LDO35.
+   -BUCKn  :   for BUCKs, where n can lie in range 1 to 10.
+   example: BUCK1, BUCK5, BUCK10.
+Example:
+
+   max77802@09 {
+   compatible = "maxim,max77802";
+   interrupt-parent = <&wakeup_eint>;
+   interrupts = <26 0>;
+   reg = <0x09>;
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   regulators {
+   ldo11_reg: LDO11 {
+   regulator-name = "vdd_ldo11";
+   regulator-min-microvolt = <190>;
+   regulator-max-microvolt = <190>;
+   regulator-always-on;
+   };
+
+   buck1_reg: BUCK1 {
+   regulator-name = "vdd_mif";
+   regulator-min-microvolt = <95>;
+   regulator-max-microvolt = <130>;
+   regulator-always-on;
+   regulator-boot-on;
+   };
+   };
-- 
2.0.0.rc2

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v8 06/13] clk: max77686: Convert to the generic max clock driver

2014-07-14 Thread Javier Martinez Canillas
Clocks drivers for Maxim PMIC are very similar so they can
be converted to use the generic Maxim clock driver.

Also, while being there use module_platform_driver() helper
macro to eliminate more boilerplate code.

Signed-off-by: Javier Martinez Canillas 
Reviewed-by: Krzysztof Kozlowski 
---
 drivers/clk/Kconfig|   1 +
 drivers/clk/clk-max77686.c | 176 +++--
 2 files changed, 9 insertions(+), 168 deletions(-)

diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
index 73f78e8..3fd4270 100644
--- a/drivers/clk/Kconfig
+++ b/drivers/clk/Kconfig
@@ -38,6 +38,7 @@ config COMMON_CLK_MAX_GEN
 config COMMON_CLK_MAX77686
tristate "Clock driver for Maxim 77686 MFD"
depends on MFD_MAX77686
+   select COMMON_CLK_MAX_GEN
---help---
  This driver supports Maxim 77686 crystal oscillator clock. 
 
diff --git a/drivers/clk/clk-max77686.c b/drivers/clk/clk-max77686.c
index 185b611..ed0beb4 100644
--- a/drivers/clk/clk-max77686.c
+++ b/drivers/clk/clk-max77686.c
@@ -31,187 +31,37 @@
 #include 
 
 #include 
-
-struct max77686_clk {
-   struct max77686_dev *iodev;
-   u32 mask;
-   struct clk_hw hw;
-   struct clk_lookup *lookup;
-};
-
-static struct max77686_clk *to_max77686_clk(struct clk_hw *hw)
-{
-   return container_of(hw, struct max77686_clk, hw);
-}
-
-static int max77686_clk_prepare(struct clk_hw *hw)
-{
-   struct max77686_clk *max77686 = to_max77686_clk(hw);
-
-   return regmap_update_bits(max77686->iodev->regmap,
- MAX77686_REG_32KHZ, max77686->mask,
- max77686->mask);
-}
-
-static void max77686_clk_unprepare(struct clk_hw *hw)
-{
-   struct max77686_clk *max77686 = to_max77686_clk(hw);
-
-   regmap_update_bits(max77686->iodev->regmap,
-   MAX77686_REG_32KHZ, max77686->mask, ~max77686->mask);
-}
-
-static int max77686_clk_is_prepared(struct clk_hw *hw)
-{
-   struct max77686_clk *max77686 = to_max77686_clk(hw);
-   int ret;
-   u32 val;
-
-   ret = regmap_read(max77686->iodev->regmap,
-   MAX77686_REG_32KHZ, &val);
-
-   if (ret < 0)
-   return -EINVAL;
-
-   return val & max77686->mask;
-}
-
-static unsigned long max77686_recalc_rate(struct clk_hw *hw,
- unsigned long parent_rate)
-{
-   return 32768;
-}
-
-static struct clk_ops max77686_clk_ops = {
-   .prepare= max77686_clk_prepare,
-   .unprepare  = max77686_clk_unprepare,
-   .is_prepared= max77686_clk_is_prepared,
-   .recalc_rate= max77686_recalc_rate,
-};
+#include "clk-max-gen.h"
 
 static struct clk_init_data max77686_clks_init[MAX77686_CLKS_NUM] = {
[MAX77686_CLK_AP] = {
.name = "32khz_ap",
-   .ops = &max77686_clk_ops,
+   .ops = &max_gen_clk_ops,
.flags = CLK_IS_ROOT,
},
[MAX77686_CLK_CP] = {
.name = "32khz_cp",
-   .ops = &max77686_clk_ops,
+   .ops = &max_gen_clk_ops,
.flags = CLK_IS_ROOT,
},
[MAX77686_CLK_PMIC] = {
.name = "32khz_pmic",
-   .ops = &max77686_clk_ops,
+   .ops = &max_gen_clk_ops,
.flags = CLK_IS_ROOT,
},
 };
 
-static struct clk *max77686_clk_register(struct device *dev,
-   struct max77686_clk *max77686)
-{
-   struct clk *clk;
-   struct clk_hw *hw = &max77686->hw;
-
-   clk = clk_register(dev, hw);
-   if (IS_ERR(clk))
-   return clk;
-
-   max77686->lookup = kzalloc(sizeof(struct clk_lookup), GFP_KERNEL);
-   if (!max77686->lookup)
-   return ERR_PTR(-ENOMEM);
-
-   max77686->lookup->con_id = hw->init->name;
-   max77686->lookup->clk = clk;
-
-   clkdev_add(max77686->lookup);
-
-   return clk;
-}
-
 static int max77686_clk_probe(struct platform_device *pdev)
 {
struct max77686_dev *iodev = dev_get_drvdata(pdev->dev.parent);
-   struct max77686_clk *max77686_clks[MAX77686_CLKS_NUM];
-   struct clk **clocks;
-   int i, ret;
-
-   clocks = devm_kzalloc(&pdev->dev, sizeof(struct clk *)
-   * MAX77686_CLKS_NUM, GFP_KERNEL);
-   if (!clocks)
-   return -ENOMEM;
-
-   for (i = 0; i < MAX77686_CLKS_NUM; i++) {
-   max77686_clks[i] = devm_kzalloc(&pdev->dev,
-   sizeof(struct max77686_clk), 
GFP_KERNEL);
-   if (!max77686_clks[i])
-   return -ENOMEM;
-   }
-
-   for (i = 0; i < MAX77686_CLKS_NUM; i++) {
-   max77686_clks[i]->iodev = iodev;
-

[PATCH v8 13/13] ARM: dts: Add max77802 to exynos5420-peach-pit and exynos5800-peach-pi

2014-07-14 Thread Javier Martinez Canillas
Peach pit and pi boards uses a Maxim 77802 power management
IC to drive regulators and its Real Time Clock. This patch
adds support for this chip.

These are the device nodes and pinctrl configuration that
are present on the Peach pit DeviceTree source file in the
the Chrome OS kernel 3.8 tree.

Signed-off-by: Javier Martinez Canillas 
Tested-by: Naveen Krishna Chatradhi 
---

Changes since v7:
 - Change Buck2 and 3 regulator name to "vdd_arm" and "vdd_int".
   Suggested by Naveen Krishna Chatradhi.
 - Remove DVS properties since this is going to be added as a follow up.

Changes since v6: None

Changes since v5:
 - Fix style issues and a typo on peach pit and pi DTS.
   Suggested by Tushar Behera.

Changes since v4: None

Changes since v3:
 - Add support for Exynos5800 based Peach pi board. Suggested by Doug Anderson.
 - Model the actual regulators relationship instead of a simplistic model.
   Suggested by Mark Brown.

Changes since v2: None

Changes since v1:
 - Use "regulators" for child node instead of "voltage-regulators" to be
   consistent with other PMIC. Suggested by Mark Brown.
 - Use regulators node names instead of the deprecated "regulator-compatible"
   property. Suggested by Mark Brown.
---
 arch/arm/boot/dts/exynos5420-peach-pit.dts | 371 +
 arch/arm/boot/dts/exynos5800-peach-pi.dts  | 371 +
 2 files changed, 742 insertions(+)

diff --git a/arch/arm/boot/dts/exynos5420-peach-pit.dts 
b/arch/arm/boot/dts/exynos5420-peach-pit.dts
index b2f1237..e5d450a 100644
--- a/arch/arm/boot/dts/exynos5420-peach-pit.dts
+++ b/arch/arm/boot/dts/exynos5420-peach-pit.dts
@@ -143,6 +143,339 @@
ddc = <&i2c_2>;
 };
 
+&hsi2c_4 {
+   status = "okay";
+   clock-frequency = <40>;
+
+   max77802-pmic@9 {
+   compatible = "maxim,max77802";
+   interrupt-parent = <&gpx3>;
+   interrupts = <1 0>;
+   pinctrl-names = "default";
+   pinctrl-0 = <&max77802_irq>, <&pmic_selb>,
+   <&pmic_dvs_1>, <&pmic_dvs_2>, <&pmic_dvs_3>;
+   wakeup-source;
+   reg = <0x9>;
+   #clock-cells = <1>;
+
+   inb1-supply = <&tps65090_dcdc2>;
+   inb2-supply = <&tps65090_dcdc1>;
+   inb3-supply = <&tps65090_dcdc2>;
+   inb4-supply = <&tps65090_dcdc2>;
+   inb5-supply = <&tps65090_dcdc1>;
+   inb6-supply = <&tps65090_dcdc2>;
+   inb7-supply = <&tps65090_dcdc1>;
+   inb8-supply = <&tps65090_dcdc1>;
+   inb9-supply = <&tps65090_dcdc1>;
+   inb10-supply = <&tps65090_dcdc1>;
+
+   inl1-supply = <&buck5_reg>;
+   inl2-supply = <&buck7_reg>;
+   inl3-supply = <&buck9_reg>;
+   inl4-supply = <&buck9_reg>;
+   inl5-supply = <&buck9_reg>;
+   inl6-supply = <&tps65090_dcdc2>;
+   inl7-supply = <&buck9_reg>;
+   inl9-supply = <&tps65090_dcdc2>;
+   inl10-supply = <&buck7_reg>;
+
+   regulators {
+   buck1_reg: BUCK1 {
+   regulator-name = "vdd_mif";
+   regulator-min-microvolt = <80>;
+   regulator-max-microvolt = <130>;
+   regulator-always-on;
+   regulator-boot-on;
+   regulator-ramp-delay = <12500>;
+   };
+
+   buck2_reg: BUCK2 {
+   regulator-name = "vdd_arm";
+   regulator-min-microvolt = <80>;
+   regulator-max-microvolt = <150>;
+   regulator-always-on;
+   regulator-boot-on;
+   regulator-ramp-delay = <12500>;
+   };
+
+   buck3_reg: BUCK3 {
+   regulator-name = "vdd_int";
+   regulator-min-microvolt = <80>;
+   regulator-max-microvolt = <140>;
+   regulator-always-on;
+   regulator-boot-on;
+   regulator-ramp-delay = <12500>;
+   };
+
+   buck4_reg: BUCK4 {
+   regulator-

[PATCH v8 12/13] rtc: Add driver for Maxim 77802 PMIC Real-Time-Clock

2014-07-14 Thread Javier Martinez Canillas
The MAX7802 PMIC has a Real-Time-Clock (RTC) with two alarms.
This patch adds support for the RTC and is based on a driver
added by Simon Glass to the Chrome OS kernel 3.8 tree.

Signed-off-by: Javier Martinez Canillas 
Reviewed-by: Krzysztof Kozlowski 
---

Changes since v6:
 - Remove unused code for SMPL and WTSR. Suggested by Krzysztof Kozlowski.
 - Don't spam the kernel log with unnecessarily info and just print for debug.
   Suggested by Krzysztof Kozlowski.
 - Use ARRAY_SIZE() instead of constant value. Suggested by Krzysztof Kozlowski.
 - Remove duplicated register setup. Suggested by Krzysztof Kozlowski.
 - Don't free/unregister managed allocated resources.
   Suggested by Krzysztof Kozlowski.
---
 drivers/rtc/Kconfig|  10 +
 drivers/rtc/Makefile   |   1 +
 drivers/rtc/rtc-max77802.c | 508 +
 3 files changed, 519 insertions(+)
 create mode 100644 drivers/rtc/rtc-max77802.c

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index a672dd1..243ac72 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -288,6 +288,16 @@ config RTC_DRV_MAX77686
  This driver can also be built as a module. If so, the module
  will be called rtc-max77686.
 
+config RTC_DRV_MAX77802
+   tristate "Maxim 77802 RTC"
+   depends on MFD_MAX77686
+   help
+ If you say yes here you will get support for the
+ RTC of Maxim MAX77802 PMIC.
+
+ This driver can also be built as a module. If so, the module
+ will be called rtc-max77802.
+
 config RTC_DRV_RS5C372
tristate "Ricoh R2025S/D, RS5C372A/B, RV5C386, RV5C387A"
help
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 70347d0..247de78 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -81,6 +81,7 @@ obj-$(CONFIG_RTC_DRV_MAX8998) += rtc-max8998.o
 obj-$(CONFIG_RTC_DRV_MAX8997)  += rtc-max8997.o
 obj-$(CONFIG_RTC_DRV_MAX6902)  += rtc-max6902.o
 obj-$(CONFIG_RTC_DRV_MAX77686) += rtc-max77686.o
+obj-$(CONFIG_RTC_DRV_MAX77802)  += rtc-max77802.o
 obj-$(CONFIG_RTC_DRV_MC13XXX)  += rtc-mc13xxx.o
 obj-$(CONFIG_RTC_DRV_MCP795)   += rtc-mcp795.o
 obj-$(CONFIG_RTC_DRV_MSM6242)  += rtc-msm6242.o
diff --git a/drivers/rtc/rtc-max77802.c b/drivers/rtc/rtc-max77802.c
new file mode 100644
index 000..f8898ff
--- /dev/null
+++ b/drivers/rtc/rtc-max77802.c
@@ -0,0 +1,508 @@
+/*
+ * RTC driver for Maxim MAX77802
+ *
+ * Copyright (C) 2013 Google, Inc
+ *
+ * Copyright (C) 2012 Samsung Electronics Co.Ltd
+ *
+ *  based on rtc-max8997.c
+ *
+ *  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.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* RTC Control Register */
+#define BCD_EN_SHIFT   0
+#define BCD_EN_MASK(1 << BCD_EN_SHIFT)
+#define MODEL24_SHIFT  1
+#define MODEL24_MASK   (1 << MODEL24_SHIFT)
+/* RTC Update Register1 */
+#define RTC_UDR_SHIFT  0
+#define RTC_UDR_MASK   (1 << RTC_UDR_SHIFT)
+#define RTC_RBUDR_SHIFT4
+#define RTC_RBUDR_MASK (1 << RTC_RBUDR_SHIFT)
+/* RTC Hour register */
+#define HOUR_PM_SHIFT  6
+#define HOUR_PM_MASK   (1 << HOUR_PM_SHIFT)
+/* RTC Alarm Enable */
+#define ALARM_ENABLE_SHIFT 7
+#define ALARM_ENABLE_MASK  (1 << ALARM_ENABLE_SHIFT)
+
+/* For the RTCAE1 register, we write this value to enable the alarm */
+#define ALARM_ENABLE_VALUE 0x77
+
+#define MAX77802_RTC_UPDATE_DELAY_US   200
+
+enum {
+   RTC_SEC = 0,
+   RTC_MIN,
+   RTC_HOUR,
+   RTC_WEEKDAY,
+   RTC_MONTH,
+   RTC_YEAR,
+   RTC_DATE,
+   RTC_NR_TIME
+};
+
+struct max77802_rtc_info {
+   struct device   *dev;
+   struct max77686_dev *max77802;
+   struct i2c_client   *rtc;
+   struct rtc_device   *rtc_dev;
+   struct mutexlock;
+
+   struct regmap   *regmap;
+
+   int virq;
+   int rtc_24hr_mode;
+};
+
+enum MAX77802_RTC_OP {
+   MAX77802_RTC_WRITE,
+   MAX77802_RTC_READ,
+};
+
+static inline int max77802_rtc_calculate_wday(u8 shifted)
+{
+   int counter = -1;
+
+   while (shifted) {
+   shifted >>= 1;
+   counter++;
+   }
+
+   return counter;
+}
+
+static void max77802_rtc_data_to_tm(u8 *data, struct rtc_time *tm,
+  int rtc_24hr_mode)
+{
+   tm->tm_sec = data[RTC_SEC] & 0xff;
+   tm->tm_min = data[RTC_MIN] & 0xff;
+   if (rtc_24hr_mode)
+   tm->tm_hour = 

[PATCH v8 09/13] clk: max77802: Add DT binding documentation

2014-07-14 Thread Javier Martinez Canillas
Add Device Tree binding documentation for the clocks
outputs in the Maxim 77802 Power Management IC.

Signed-off-by: Javier Martinez Canillas 
---

Changes since v6: None

Changes since v5:
 - Fix typo error in DT binding. Suggested by Andreas Farber.
 - Add "clock-output-names" as an optional property since now is supported.

Changes since v4: None

Changes since v3:
 - Don't use the same clock driver name in clock-names since it's a consumer
   concept and most probably will be different. Suggested by Doug Anderson.

Changes since v2:
 - Split the DT binding documentation in a separate patch.
---
 .../devicetree/bindings/clock/maxim,max77802.txt   | 44 ++
 1 file changed, 44 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/maxim,max77802.txt

diff --git a/Documentation/devicetree/bindings/clock/maxim,max77802.txt 
b/Documentation/devicetree/bindings/clock/maxim,max77802.txt
new file mode 100644
index 000..c6dc783
--- /dev/null
+++ b/Documentation/devicetree/bindings/clock/maxim,max77802.txt
@@ -0,0 +1,44 @@
+Binding for Maxim MAX77802 32k clock generator block
+
+This is a part of device tree bindings of MAX77802 multi-function device.
+More information can be found in bindings/mfd/max77802.txt file.
+
+The MAX77802 contains two 32.768khz clock outputs that can be controlled
+(gated/ungated) over I2C.
+
+Following properties should be present in main device node of the MFD chip.
+
+Required properties:
+- #clock-cells: From common clock binding; shall be set to 1.
+
+Optional properties:
+- clock-output-names: From common clock binding.
+
+Each clock is assigned an identifier and client nodes can use this identifier
+to specify the clock which they consume. Following indices are allowed:
+ - 0: 32khz_ap clock,
+ - 1: 32khz_cp clock.
+
+Clocks are defined as preprocessor macros in dt-bindings/clock/maxim,max77802.h
+header and can be used in device tree sources.
+
+Example: Node of the MFD chip
+
+   max77802: max77802@09 {
+   compatible = "maxim,max77802";
+   interrupt-parent = <&wakeup_eint>;
+   interrupts = <26 0>;
+   reg = <0x09>;
+   #clock-cells = <1>;
+
+   /* ... */
+   };
+
+Example: Clock consumer node
+
+   foo@0 {
+   compatible = "bar,foo";
+   /* ... */
+   clock-names = "my-clock";
+   clocks = <&max77802 MAX77802_CLK_32K_AP>;
+   };
-- 
2.0.0.rc2

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v8 10/13] rtc: max77686: Allow the max77686 rtc to wakeup the system

2014-07-14 Thread Javier Martinez Canillas
From: Doug Anderson 

The max77686 includes an RTC that keeps power during suspend.  It's
convenient to be able to use it as a wakeup source.

NOTE: due to wakeup ordering problems this patch alone doesn't work so
well on exynos5250-snow.  You also need something that brings the i2c
bus up before the max77686 wakeup runs.

Signed-off-by: Doug Anderson 
Reviewed-by: Javier Martinez Canillas 
Reviewed-by: Krzysztof Kozlowski 
---

Changes since v6: None

Changes since v5:
 - Fix $SUBJECT since the patch does not actually touch the mfd subsys.
   Suggested by Lee Jones.

Changes since v4: None

Changes since v3:
 - Keep the note that this patch needs another change due wakeup
   ordering problems.
---
 drivers/rtc/rtc-max77686.c | 28 
 1 file changed, 28 insertions(+)

diff --git a/drivers/rtc/rtc-max77686.c b/drivers/rtc/rtc-max77686.c
index d20a7f0..c1c6055 100644
--- a/drivers/rtc/rtc-max77686.c
+++ b/drivers/rtc/rtc-max77686.c
@@ -583,6 +583,33 @@ static void max77686_rtc_shutdown(struct platform_device 
*pdev)
 #endif /* MAX77686_RTC_WTSR_SMPL */
 }
 
+#ifdef CONFIG_PM_SLEEP
+static int max77686_rtc_suspend(struct device *dev)
+{
+   if (device_may_wakeup(dev)) {
+   struct max77686_rtc_info *info = dev_get_drvdata(dev);
+
+   return enable_irq_wake(info->virq);
+   }
+
+   return 0;
+}
+
+static int max77686_rtc_resume(struct device *dev)
+{
+   if (device_may_wakeup(dev)) {
+   struct max77686_rtc_info *info = dev_get_drvdata(dev);
+
+   return disable_irq_wake(info->virq);
+   }
+
+   return 0;
+}
+#endif
+
+static SIMPLE_DEV_PM_OPS(max77686_rtc_pm_ops,
+max77686_rtc_suspend, max77686_rtc_resume);
+
 static const struct platform_device_id rtc_id[] = {
{ "max77686-rtc", 0 },
{},
@@ -592,6 +619,7 @@ static struct platform_driver max77686_rtc_driver = {
.driver = {
.name   = "max77686-rtc",
.owner  = THIS_MODULE,
+   .pm = &max77686_rtc_pm_ops,
},
.probe  = max77686_rtc_probe,
.shutdown   = max77686_rtc_shutdown,
-- 
2.0.0.rc2

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v8 05/13] clk: Add generic driver for Maxim PMIC clocks

2014-07-14 Thread Javier Martinez Canillas
Maxim Integrated Power Management ICs are very similar with
regard to their clock outputs. Most of the clock drivers for
these chips are duplicating code and are simpler enough that
can be converted to use a generic driver to consolidate code
and avoid duplication.

Signed-off-by: Javier Martinez Canillas 
Reviewed-by: Krzysztof Kozlowski 
---

Changes since v6: None

Changes since v5:
 - Fix generic driver changes merged into max77802 clock patch by mistake.
   Suggested by Yadwinder Singh Brar.
 - Register clock lookups using clk_register_clkdev() instead of doing manually.
 - Use the managed devm_clk_register() function and remove clk un-registration.
 - Add "clock-output-names" property support. Suggested by Yadwinder Singh Brar.
 - Return the rate unconditionally in recalc_rate. Suggested by Mike Turquette.

Changes since v4: None

Changes since v3:
 - Don't change clock-names property to make clear that it's
   the consumer clock name and should not match the producer clock.
   Suggested by Doug Anderson.
---
 drivers/clk/Kconfig   |   3 +
 drivers/clk/Makefile  |   1 +
 drivers/clk/clk-max-gen.c | 192 ++
 drivers/clk/clk-max-gen.h |  32 
 4 files changed, 228 insertions(+)
 create mode 100644 drivers/clk/clk-max-gen.c
 create mode 100644 drivers/clk/clk-max-gen.h

diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
index 9f9c5ae..73f78e8 100644
--- a/drivers/clk/Kconfig
+++ b/drivers/clk/Kconfig
@@ -32,6 +32,9 @@ config COMMON_CLK_WM831X
 
 source "drivers/clk/versatile/Kconfig"
 
+config COMMON_CLK_MAX_GEN
+bool
+
 config COMMON_CLK_MAX77686
tristate "Clock driver for Maxim 77686 MFD"
depends on MFD_MAX77686
diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
index 567f102..6c1aff6 100644
--- a/drivers/clk/Makefile
+++ b/drivers/clk/Makefile
@@ -18,6 +18,7 @@ obj-$(CONFIG_ARCH_BCM2835)+= clk-bcm2835.o
 obj-$(CONFIG_ARCH_EFM32)   += clk-efm32gg.o
 obj-$(CONFIG_ARCH_HIGHBANK)+= clk-highbank.o
 obj-$(CONFIG_MACH_LOONGSON1)   += clk-ls1x.o
+obj-$(CONFIG_COMMON_CLK_MAX_GEN)   += clk-max-gen.o
 obj-$(CONFIG_COMMON_CLK_MAX77686)  += clk-max77686.o
 obj-$(CONFIG_ARCH_MOXART)  += clk-moxart.o
 obj-$(CONFIG_ARCH_NOMADIK) += clk-nomadik.o
diff --git a/drivers/clk/clk-max-gen.c b/drivers/clk/clk-max-gen.c
new file mode 100644
index 000..6505049
--- /dev/null
+++ b/drivers/clk/clk-max-gen.c
@@ -0,0 +1,192 @@
+/*
+ * clk-max-gen.c - Generic clock driver for Maxim PMICs clocks
+ *
+ * Copyright (C) 2014 Google, Inc
+ *
+ * Copyright (C) 2012 Samsung Electornics
+ * Jonghwa Lee 
+ *
+ * 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.
+ *
+ * This driver is based on clk-max77686.c
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct max_gen_clk {
+   struct regmap *regmap;
+   u32 mask;
+   u32 reg;
+   struct clk_hw hw;
+};
+
+static struct max_gen_clk *to_max_gen_clk(struct clk_hw *hw)
+{
+   return container_of(hw, struct max_gen_clk, hw);
+}
+
+static int max_gen_clk_prepare(struct clk_hw *hw)
+{
+   struct max_gen_clk *max_gen = to_max_gen_clk(hw);
+
+   return regmap_update_bits(max_gen->regmap, max_gen->reg,
+ max_gen->mask, max_gen->mask);
+}
+
+static void max_gen_clk_unprepare(struct clk_hw *hw)
+{
+   struct max_gen_clk *max_gen = to_max_gen_clk(hw);
+
+   regmap_update_bits(max_gen->regmap, max_gen->reg,
+  max_gen->mask, ~max_gen->mask);
+}
+
+static int max_gen_clk_is_prepared(struct clk_hw *hw)
+{
+   struct max_gen_clk *max_gen = to_max_gen_clk(hw);
+   int ret;
+   u32 val;
+
+   ret = regmap_read(max_gen->regmap, max_gen->reg, &val);
+
+   if (ret < 0)
+   return -EINVAL;
+
+   return val & max_gen->mask;
+}
+
+static unsigned long max_gen_recalc_rate(struct clk_hw *hw,
+unsigned long parent_rate)
+{
+   return 32768;
+}
+
+struct clk_ops max_gen_clk_ops = {
+   .prepare= max_gen_clk_prepare,
+   .unprepare  = max_gen_clk_unprepare,
+   .is_prepared= max_gen_clk_is_prepared,
+   .recalc_rate= max_gen_recalc_rate,
+};
+EXPORT_SYMBOL_GPL(max_gen_clk_ops);
+
+static struct clk *max_gen_clk_register(str

[PATCH v8 11/13] rtc: max77686: Remove dead code for SMPL and WTSR.

2014-07-14 Thread Javier Martinez Canillas
The MAX77686 RTC chip has two features called SMPL (Sudden Momentary
Power Loss) and WTSR (Watchdog Timeout and Software Resets).
Support for these features seems to be implemented in the driver but
compilation is disabled using a C pre-processor conditional.

This code has been disabled since the driver was original merged in
commit fca1dd03 ("rtc: max77686: add Maxim 77686 driver").

So, since this code has never been built, let's just remove it.

Signed-off-by: Javier Martinez Canillas 
Reviewed-by: Krzysztof Kozlowski 
---
 drivers/rtc/rtc-max77686.c | 101 -
 1 file changed, 101 deletions(-)

diff --git a/drivers/rtc/rtc-max77686.c b/drivers/rtc/rtc-max77686.c
index c1c6055..7bb5433 100644
--- a/drivers/rtc/rtc-max77686.c
+++ b/drivers/rtc/rtc-max77686.c
@@ -32,15 +32,6 @@
 #define RTC_UDR_MASK   (1 << RTC_UDR_SHIFT)
 #define RTC_RBUDR_SHIFT4
 #define RTC_RBUDR_MASK (1 << RTC_RBUDR_SHIFT)
-/* WTSR and SMPL Register */
-#define WTSRT_SHIFT0
-#define SMPLT_SHIFT2
-#define WTSR_EN_SHIFT  6
-#define SMPL_EN_SHIFT  7
-#define WTSRT_MASK (3 << WTSRT_SHIFT)
-#define SMPLT_MASK (3 << SMPLT_SHIFT)
-#define WTSR_EN_MASK   (1 << WTSR_EN_SHIFT)
-#define SMPL_EN_MASK   (1 << SMPL_EN_SHIFT)
 /* RTC Hour register */
 #define HOUR_PM_SHIFT  6
 #define HOUR_PM_MASK   (1 << HOUR_PM_SHIFT)
@@ -49,7 +40,6 @@
 #define ALARM_ENABLE_MASK  (1 << ALARM_ENABLE_SHIFT)
 
 #define MAX77686_RTC_UPDATE_DELAY  16
-#undef MAX77686_RTC_WTSR_SMPL
 
 enum {
RTC_SEC = 0,
@@ -412,64 +402,6 @@ static const struct rtc_class_ops max77686_rtc_ops = {
.alarm_irq_enable = max77686_rtc_alarm_irq_enable,
 };
 
-#ifdef MAX77686_RTC_WTSR_SMPL
-static void max77686_rtc_enable_wtsr(struct max77686_rtc_info *info, bool 
enable)
-{
-   int ret;
-   unsigned int val, mask;
-
-   if (enable)
-   val = (1 << WTSR_EN_SHIFT) | (3 << WTSRT_SHIFT);
-   else
-   val = 0;
-
-   mask = WTSR_EN_MASK | WTSRT_MASK;
-
-   dev_info(info->dev, "%s: %s WTSR\n", __func__,
-   enable ? "enable" : "disable");
-
-   ret = regmap_update_bits(info->max77686->rtc_regmap,
-MAX77686_WTSR_SMPL_CNTL, mask, val);
-   if (ret < 0) {
-   dev_err(info->dev, "%s: fail to update WTSR reg(%d)\n",
-   __func__, ret);
-   return;
-   }
-
-   max77686_rtc_update(info, MAX77686_RTC_WRITE);
-}
-
-static void max77686_rtc_enable_smpl(struct max77686_rtc_info *info, bool 
enable)
-{
-   int ret;
-   unsigned int val, mask;
-
-   if (enable)
-   val = (1 << SMPL_EN_SHIFT) | (0 << SMPLT_SHIFT);
-   else
-   val = 0;
-
-   mask = SMPL_EN_MASK | SMPLT_MASK;
-
-   dev_info(info->dev, "%s: %s SMPL\n", __func__,
-   enable ? "enable" : "disable");
-
-   ret = regmap_update_bits(info->max77686->rtc_regmap,
-MAX77686_WTSR_SMPL_CNTL, mask, val);
-   if (ret < 0) {
-   dev_err(info->dev, "%s: fail to update SMPL reg(%d)\n",
-   __func__, ret);
-   return;
-   }
-
-   max77686_rtc_update(info, MAX77686_RTC_WRITE);
-
-   val = 0;
-   regmap_read(info->max77686->rtc_regmap, MAX77686_WTSR_SMPL_CNTL, &val);
-   dev_info(info->dev, "%s: WTSR_SMPL(0x%02x)\n", __func__, val);
-}
-#endif /* MAX77686_RTC_WTSR_SMPL */
-
 static int max77686_rtc_init_reg(struct max77686_rtc_info *info)
 {
u8 data[2];
@@ -519,11 +451,6 @@ static int max77686_rtc_probe(struct platform_device *pdev)
goto err_rtc;
}
 
-#ifdef MAX77686_RTC_WTSR_SMPL
-   max77686_rtc_enable_wtsr(info, true);
-   max77686_rtc_enable_smpl(info, true);
-#endif
-
device_init_wakeup(&pdev->dev, 1);
 
info->rtc_dev = devm_rtc_device_register(&pdev->dev, "max77686-rtc",
@@ -556,33 +483,6 @@ err_rtc:
return ret;
 }
 
-static void max77686_rtc_shutdown(struct platform_device *pdev)
-{
-#ifdef MAX77686_RTC_WTSR_SMPL
-   struct max77686_rtc_info *info = platform_get_drvdata(pdev);
-   int i;
-   u8 val = 0;
-
-   for (i = 0; i < 3; i++) {
-   max77686_rtc_enable_wtsr(info, false);
-   regmap_read(info->max77686->rtc_regmap, 
MAX77686_WTSR_SMPL_CNTL, &val);
-   dev_info(info->dev, "%s: WTSR_SMPL reg(0x%02x)\n", __func__,
-

[PATCH v8 08/13] clk: Add driver for Maxim 77802 PMIC clocks

2014-07-14 Thread Javier Martinez Canillas
The MAX77802 PMIC has two 32.768kHz Buffered Clock Outputs with
Low Jitter Mode. This patch adds support for these two clocks.

Signed-off-by: Javier Martinez Canillas 
Reviewed-by: Krzysztof Kozlowski 
---

Changes since v6: None

Changes since v5: None

Changes since v4: None

Changes since v3: None

Changes since v2: None

Changes since v1:
 - Use module_platform_driver() instead of having init/exit functions.
   Suggested by Mark Brown.
 - Use the generic maxim clock driver to reduce code duplication with
   clk-max77686.c driver.
---
 drivers/clk/Kconfig|  7 +++
 drivers/clk/Makefile   |  1 +
 drivers/clk/clk-max77802.c | 98 ++
 include/dt-bindings/clock/maxim,max77802.h | 22 +++
 4 files changed, 128 insertions(+)
 create mode 100644 drivers/clk/clk-max77802.c
 create mode 100644 include/dt-bindings/clock/maxim,max77802.h

diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
index 3fd4270..8808f2a 100644
--- a/drivers/clk/Kconfig
+++ b/drivers/clk/Kconfig
@@ -42,6 +42,13 @@ config COMMON_CLK_MAX77686
---help---
  This driver supports Maxim 77686 crystal oscillator clock. 
 
+config COMMON_CLK_MAX77802
+   tristate "Clock driver for Maxim 77802 PMIC"
+   depends on MFD_MAX77686
+   select COMMON_CLK_MAX_GEN
+   ---help---
+ This driver supports Maxim 77802 crystal oscillator clock.
+
 config COMMON_CLK_SI5351
tristate "Clock driver for SiLabs 5351A/B/C"
depends on I2C
diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
index 6c1aff6..520ff76 100644
--- a/drivers/clk/Makefile
+++ b/drivers/clk/Makefile
@@ -20,6 +20,7 @@ obj-$(CONFIG_ARCH_HIGHBANK)   += clk-highbank.o
 obj-$(CONFIG_MACH_LOONGSON1)   += clk-ls1x.o
 obj-$(CONFIG_COMMON_CLK_MAX_GEN)   += clk-max-gen.o
 obj-$(CONFIG_COMMON_CLK_MAX77686)  += clk-max77686.o
+obj-$(CONFIG_COMMON_CLK_MAX77802)  += clk-max77802.o
 obj-$(CONFIG_ARCH_MOXART)  += clk-moxart.o
 obj-$(CONFIG_ARCH_NOMADIK) += clk-nomadik.o
 obj-$(CONFIG_ARCH_NSPIRE)  += clk-nspire.o
diff --git a/drivers/clk/clk-max77802.c b/drivers/clk/clk-max77802.c
new file mode 100644
index 000..8e480c5
--- /dev/null
+++ b/drivers/clk/clk-max77802.c
@@ -0,0 +1,98 @@
+/*
+ * clk-max77802.c - Clock driver for Maxim 77802
+ *
+ * Copyright (C) 2014 Google, Inc
+ *
+ * Copyright (C) 2012 Samsung Electornics
+ * Jonghwa Lee 
+ *
+ * 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.
+ *
+ * This driver is based on clk-max77686.c
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include "clk-max-gen.h"
+
+#define MAX77802_CLOCK_OPMODE_MASK 0x1
+#define MAX77802_CLOCK_LOW_JITTER_SHIFT 0x3
+
+static struct clk_init_data max77802_clks_init[MAX77802_CLKS_NUM] = {
+   [MAX77802_CLK_32K_AP] = {
+   .name = "32khz_ap",
+   .ops = &max_gen_clk_ops,
+   .flags = CLK_IS_ROOT,
+   },
+   [MAX77802_CLK_32K_CP] = {
+   .name = "32khz_cp",
+   .ops = &max_gen_clk_ops,
+   .flags = CLK_IS_ROOT,
+   },
+};
+
+static int max77802_clk_probe(struct platform_device *pdev)
+{
+   struct max77686_dev *iodev = dev_get_drvdata(pdev->dev.parent);
+   int ret;
+
+   ret = max_gen_clk_probe(pdev, iodev->regmap, MAX77802_REG_32KHZ,
+   max77802_clks_init, MAX77802_CLKS_NUM);
+
+   if (ret) {
+   dev_err(&pdev->dev, "generic probe failed %d\n", ret);
+   return ret;
+   }
+
+   /* Enable low-jitter mode on the 32khz clocks. */
+   ret = regmap_update_bits(iodev->regmap, MAX77802_REG_32KHZ,
+1 << MAX77802_CLOCK_LOW_JITTER_SHIFT,
+1 << MAX77802_CLOCK_LOW_JITTER_SHIFT);
+   if (ret < 0)
+   dev_err(&pdev->dev, "failed to enable low-jitter mode\n");
+
+   return ret;
+}
+
+static int max77802_clk_remove(struct platform_device *pdev)
+{
+   return max_gen_clk_remove(pdev, MAX77802_CLKS_NUM);
+}
+
+static const struct platform_device_id max77802_clk_id[] = {
+   { "max77802-clk", 0},
+   { },
+};
+MODULE_DEVICE_TABLE(platform, max77802_clk_id);
+
+static struct platform_driver max77802_clk_driver = {
+   .driver = {

[PATCH v8 03/13] regulator: Add driver for Maxim 77802 PMIC regulators

2014-07-14 Thread Javier Martinez Canillas
The MAX77802 PMIC has 10 high-efficiency Buck and 32 Low-dropout
(LDO) regulators. This patch adds support for all these regulators
found on the MAX77802 PMIC and is based on a driver added by Simon
Glass to the Chrome OS kernel 3.8 tree.

Signed-off-by: Javier Martinez Canillas 
Tested-by: Naveen Krishna Chatradhi 
---

Changes since v7:
 - Remove DVS support since that can be added as a follow up.

Changes since v6: None

Changes since v5:
 - Take out the mfd changes from v4 that were squashed by mistake.
   Suggested by Lee Jones.

Changes since v4: None

Changes since v3:
 - Set the supply_name for regulators to lookup their parent supply node.
   Suggested by Mark Brown.
 - Change Exyno5 for Exynos5420/Exynos5800 in regulator driver Kconfig.
   Suggested by Doug Anderson.
---
 drivers/regulator/Kconfig|   9 +
 drivers/regulator/Makefile   |   1 +
 drivers/regulator/max77802.c | 578 +++
 3 files changed, 588 insertions(+)
 create mode 100644 drivers/regulator/max77802.c

diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index 789eb46..96d1c68 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -377,6 +377,15 @@ config REGULATOR_MAX77693
  and one current regulator 'CHARGER'. This is suitable for
  Exynos-4x12 chips.
 
+config REGULATOR_MAX77802
+   tristate "Maxim 77802 regulator"
+   depends on MFD_MAX77686
+   help
+ This driver controls a Maxim 77802 regulator
+ via I2C bus. The provided regulator is suitable for
+ Exynos5420/Exynos5800 SoCs to control various voltages.
+ It includes support for control of voltage and ramp speed.
+
 config REGULATOR_MC13XXX_CORE
tristate
 
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index d461110..2aea4b6 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -51,6 +51,7 @@ obj-$(CONFIG_REGULATOR_MAX8997) += max8997.o
 obj-$(CONFIG_REGULATOR_MAX8998) += max8998.o
 obj-$(CONFIG_REGULATOR_MAX77686) += max77686.o
 obj-$(CONFIG_REGULATOR_MAX77693) += max77693.o
+obj-$(CONFIG_REGULATOR_MAX77802) += max77802.o
 obj-$(CONFIG_REGULATOR_MC13783) += mc13783-regulator.o
 obj-$(CONFIG_REGULATOR_MC13892) += mc13892-regulator.o
 obj-$(CONFIG_REGULATOR_MC13XXX_CORE) +=  mc13xxx-regulator-core.o
diff --git a/drivers/regulator/max77802.c b/drivers/regulator/max77802.c
new file mode 100644
index 000..5f022f8
--- /dev/null
+++ b/drivers/regulator/max77802.c
@@ -0,0 +1,578 @@
+/*
+ * max77802.c - Regulator driver for the Maxim 77802
+ *
+ * Copyright (C) 2013-2014 Google, Inc
+ * Simon Glass 
+ *
+ * Copyright (C) 2012 Samsung Electronics
+ * Chiwoong Byun 
+ * Jonghwa Lee 
+ *
+ * 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.
+ *
+ * This driver is based on max8997.c
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* Default ramp delay in case it is not manually set */
+#define MAX77802_RAMP_DELAY10  /* uV/us */
+
+#define MAX77802_OPMODE_SHIFT_LDO  6
+#define MAX77802_OPMODE_BUCK234_SHIFT  4
+#define MAX77802_OPMODE_MASK   0x3
+
+#define MAX77802_VSEL_MASK 0x3F
+#define MAX77802_DVS_VSEL_MASK 0xFF
+
+#define MAX77802_RAMP_RATE_MASK_2BIT   0xC0
+#define MAX77802_RAMP_RATE_SHIFT_2BIT  6
+#define MAX77802_RAMP_RATE_MASK_4BIT   0xF0
+#define MAX77802_RAMP_RATE_SHIFT_4BIT  4
+
+/* MAX77802 has two register formats: 2-bit and 4-bit */
+static const unsigned int ramp_table_77802_2bit[] = {
+   12500,
+   25000,
+   5,
+   10,
+};
+
+static unsigned int ramp_table_77802_4bit[] = {
+   1000,   2000,   3030,   4000,
+   5000,   5880,   7140,   8330,
+   9090,   1,  0,  12500,
+   16670,  25000,  5,  10,
+};
+
+struct max77802_regulator_prv {
+   int num_regulators;
+   struct regulator_dev *rdev[MAX77802_REG_MAX];
+   unsigned int opmode[MAX77802_REG_MAX];
+};
+
+static int max77802_get_opmode_shift(int id)
+{
+   if (id == MAX77802_BUCK1 || (id >= MAX77802_BUCK5 &&
+id <= MAX77802_BUCK10))
+   return 0;
+
+   if (id >= MAX77802_BUCK2 && id <= MAX77802_BUCK4)
+   return MAX77802_OPMODE_BUCK234_SHIFT;
+
+   if (id >= MAX77802_LDO1 && id <= MAX77802_LDO35)
+   return MAX77802_OPMOD

[PATCH v8 07/13] clk: max77686: Improve Maxim 77686 PMIC clocks binding

2014-07-14 Thread Javier Martinez Canillas
Like most clock drivers, the Maxim 77686 PMIC clock binding
follows the convention that the "#clock-cells" property is
used to specify the number of cells in a clock provider.

But the binding document is not clear enough that it shall
be set to 1 since the PMIC support multiple clocks outputs.

Also, explain that the clocks identifiers are defined in a
header file that can be included by Device Tree source with
client nodes to avoid using magic numbers.

Finally, add "clock-output-names" as an optional property
since now is supported by the clock driver.

Signed-off-by: Javier Martinez Canillas 
Reviewed-by: Krzysztof Kozlowski 
Reviewed-by: Doug Anderson 
Reviewed-by: Mike Turquette 
---

Changes since v6: None

Changes since v5:
 - Fix generic driver changes merged into max77802 clock patch by mistake.
   Suggested by Yadwinder Singh Brar.
 - Register clock lookups using clk_register_clkdev() instead of doing manually.
 - Use the managed devm_clk_register() function and remove clk un-registration.
 - Add "clock-output-names" property support. Suggested by Yadwinder Singh Brar.
 - Return the rate unconditionally in recalc_rate. Suggested by Mike Turquette.

Changes since v4: None

Changes since v3:
 - Don't change clock-names property to make clear that it's
   the consumer clock name and should not match the producer clock.
   Suggested by Doug Anderson.
---
 .../devicetree/bindings/clock/maxim,max77686.txt | 16 
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/Documentation/devicetree/bindings/clock/maxim,max77686.txt 
b/Documentation/devicetree/bindings/clock/maxim,max77686.txt
index 96ce71b..9c40739 100644
--- a/Documentation/devicetree/bindings/clock/maxim,max77686.txt
+++ b/Documentation/devicetree/bindings/clock/maxim,max77686.txt
@@ -9,13 +9,21 @@ The MAX77686 contains three 32.768khz clock outputs that can 
be controlled
 Following properties should be presend in main device node of the MFD chip.
 
 Required properties:
-- #clock-cells: simple one-cell clock specifier format is used, where the
-  only cell is used as an index of the clock inside the provider. Following
-  indices are allowed:
+
+- #clock-cells: from common clock binding; shall be set to 1.
+
+Optional properties:
+- clock-output-names: From common clock binding.
+
+Each clock is assigned an identifier and client nodes can use this identifier
+to specify the clock which they consume. Following indices are allowed:
 - 0: 32khz_ap clock,
 - 1: 32khz_cp clock,
 - 2: 32khz_pmic clock.
 
+Clocks are defined as preprocessor macros in dt-bindings/clock/maxim,max77686.h
+header and can be used in device tree sources.
+
 Example: Node of the MFD chip
 
max77686: max77686@09 {
@@ -34,5 +42,5 @@ Example: Clock consumer node
compatible = "bar,foo";
/* ... */
clock-names = "my-clock";
-   clocks = <&max77686 2>;
+   clocks = <&max77686 MAX77686_CLK_PMIC>;
};
-- 
2.0.0.rc2

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v8 04/13] clk: max77686: Add DT include for MAX77686 PMIC clock

2014-07-14 Thread Javier Martinez Canillas
This patch adds a dt-binding include for Maxim 77686
PMIC clock IDs that can be used by both the max77686
clock driver and Device Tree source files.

Signed-off-by: Javier Martinez Canillas 
Reviewed-by: Krzysztof Kozlowski 
Reviewed-by: Mike Turquette 
---

Changes since v6: None

Changes since v5:
 - Improve wording in commit message. Suggested by Andreas Farber.

Changes since v4: None

Changes since v3:
 - Keep the note that this patch needs another change due wakeup
   ordering problems.
---
 drivers/clk/clk-max77686.c |  7 +--
 include/dt-bindings/clock/maxim,max77686.h | 23 +++
 2 files changed, 24 insertions(+), 6 deletions(-)
 create mode 100644 include/dt-bindings/clock/maxim,max77686.h

diff --git a/drivers/clk/clk-max77686.c b/drivers/clk/clk-max77686.c
index 3d7e8dd..185b611 100644
--- a/drivers/clk/clk-max77686.c
+++ b/drivers/clk/clk-max77686.c
@@ -30,12 +30,7 @@
 #include 
 #include 
 
-enum {
-   MAX77686_CLK_AP = 0,
-   MAX77686_CLK_CP,
-   MAX77686_CLK_PMIC,
-   MAX77686_CLKS_NUM,
-};
+#include 
 
 struct max77686_clk {
struct max77686_dev *iodev;
diff --git a/include/dt-bindings/clock/maxim,max77686.h 
b/include/dt-bindings/clock/maxim,max77686.h
new file mode 100644
index 000..7b28b09
--- /dev/null
+++ b/include/dt-bindings/clock/maxim,max77686.h
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2014 Google, Inc
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Device Tree binding constants clocks for the Maxim 77686 PMIC.
+ */
+
+#ifndef _DT_BINDINGS_CLOCK_MAXIM_MAX77686_CLOCK_H
+#define _DT_BINDINGS_CLOCK_MAXIM_MAX77686_CLOCK_H
+
+/* Fixed rate clocks. */
+
+#define MAX77686_CLK_AP0
+#define MAX77686_CLK_CP1
+#define MAX77686_CLK_PMIC  2
+
+/* Total number of clocks. */
+#define MAX77686_CLKS_NUM  (MAX77686_CLK_PMIC + 1)
+
+#endif /* _DT_BINDINGS_CLOCK_MAXIM_MAX77686_CLOCK_H */
-- 
2.0.0.rc2

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/3 v6] spi: s3c64xx: fix broken "cs_gpios" usage in the driver

2014-07-15 Thread Javier Martinez Canillas
Hello Mark,

I agree that the commit message could have a better description and I
understand your concerns. I'm not an SPI expert by any means but I did
my best to review the patches and provide feedback to Naveen on the
first iterations of the series.

On Mon, Jul 14, 2014 at 7:25 PM, Mark Brown  wrote:
> On Mon, Jul 14, 2014 at 11:11:44AM +0530, Naveen Krishna Chatradhi wrote:
>
>> @@ -812,6 +800,10 @@ static int s3c64xx_spi_setup(struct spi_device *spi)
>>   spi->controller_data = cs;
>>   }
>>
>> + /* For the non-DT platforms derive chip selects from controller data */
>> + if (!spi->dev.of_node)
>> + spi->cs_gpio = cs->line;
>> +
>>   if (IS_ERR_OR_NULL(cs)) {
>>   dev_err(&spi->dev, "No CS for SPI(%d)\n", spi->chip_select);
>>   return -ENODEV;
>> @@ -819,17 +811,16 @@ static int s3c64xx_spi_setup(struct spi_device *spi)
>>
>>   if (!spi_get_ctldata(spi)) {
>>   /* Request gpio only if cs line is asserted by gpio pins */
>> - if (sdd->cs_gpio) {
>> - err = gpio_request_one(cs->line, GPIOF_OUT_INIT_HIGH,
>> - dev_name(&spi->dev));
>> + if (gpio_is_valid(spi->cs_gpio)) {
>
> As previously mentioned gpio_is_valid() is *not* a direct substitute for
> checking if the boolean flag cs_gpio has been set since 0 is a valid
> GPIO on at least some of these platforms and as discussed several times
> already some of the SoCs require the use of the built in chip select.
>

Please correct me if I'm wrong but in this case I think that using
gpio_is_valid(spi->cs_gpio) is the right thing to do. The SPI core
will set spi->cs_gpio to -ENOENT if a Device Tree didn't use the
"cs-gpios" property of if the format (explained in
Documentation/devicetree/bindings/spi/spi-bus.txt) to specify a
native/built-in line chip select is used:

cs-gpios = <&gpio1 0 0> <0>
cs0 : &gpio1 0 0
cs1 : native

So in that case gpio_is_valid(spi->cs_gpio) will return false which is
what Naveen wants in his patch.

Now, a problem is that in the non-DT case the patch does not rely on
the spi->cs_gpio value set by the SPI core but instead overwrites it
with the value in cs->line. So as you said this would have been an
issue if legacy non-DT board code used s3c64xx_spi_csinfo .line to
specify that the built-in chip select should be used instead of a
GPIO.

But looking at the board files that sets struct spi_board_info
.controller_data to struct s3c64xx_spi_csinfo I see that the the .line
field is actually used to specify a GPIO pin and not a chip select.

In fact there is only one user in mainline
(arch/arm/mach-s3c64xx/mach-crag6410-module.c) that do this:

#define S3C64XX_GPC(_nr)  (S3C64XX_GPIO_C_START + (_nr))

static struct s3c64xx_spi_csinfo wm0010_spi_csinfo = {
.line = S3C64XX_GPC(3),
};

static struct spi_board_info wm1253_devs[] = {
[0] = {
.modalias   = "wm0010",
.max_speed_hz   = 26 * 1000 * 1000,
.bus_num= 0,
.chip_select= 0,
.mode   = SPI_MODE_0,
.irq= S3C_EINT(4),
.controller_data = &wm0010_spi_csinfo,
.platform_data = &wm0010_pdata,
},
};

So, the .line field is used to specify a GPIO, not a chip select. So
gpio_is_valid() should also be used to check that cs->line is a valid
GPIO. If board file does not want to use a GPIO and wants to use a
built-in chip select then it should either not use a struct
s3c64xx_spi_csinfo at all or set .line to -ENOENT in order to be
consistent with the SPI core.

Now, looking at this I realize that there is a bug in the spi-s3c64xx
driver since it does not check if spi->controller_data is NULL in the
non-DT case which I believe it can be true.

> In general it's quite hard to tie the description in the patch to the
> code changes, not helped by the decision to do separate refactorings
> like this conversion to gpio_is_valid() as part of the one patch.  The
> description of the patch now makes some statements about what the
> problem that's intended to be fixed is but it still doesn't seem
> entirely clear that everything has been thought through fully and tied
> to the code.
>

AFAICT most of the refactoring is actually removing the buggy code
that was introduced in commit 3146bee ("spi: s3c64xx: Added provision
for dedicated cs pin"). So maybe Naveen can try doing a new series
first reverting the offending commit and then on top of that adding
the support for the generic "cs-gpios" DT property used by the SPI
core?

As I said before this patch is fixing a bug in the SPI driver, the
first version of the series was posted on June, 10 so many other
patches already depend on this fix. So it would be great if we can
move this forward since this is hurting the platform support as a
whole.

Thanks a lot and best regards,
Javier
--
To unsubscribe from this list:

Re: [PATCH 2/3] spi: s3c64xx: validate s3c64xx_spi_csinfo before using

2014-07-15 Thread Javier Martinez Canillas
Hello Naveen,

On 07/15/2014 07:49 PM, Tomasz Figa wrote:
> 
> In general, I liked previous version of this series much more, as it was
> doing what it should as opposed to this one.
> 
> Best regards,
> Tomasz
> 

I agree with Tomasz. I think version v6 of your series was (almost) correct
while this is one is not. You only had to address Mark's concerns about using
gpio_is_valid(spi->cs_gpio).

Also, you need to work out your commit messages since I they are still not
clearly explaining the motivation for the changes. You are explaining what the
patches are changing but you have to explain why the changes are needed in the
first place.

Best regards,
Javier
--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 0/4] spi: s3c64xx: fix DT binding breakage

2014-07-16 Thread Javier Martinez Canillas
Hello Mark,

The s3c64xx SPI driver DT binding is currently broken. Commit
3146bee ("spi: s3c64xx: Added provision for dedicated cs pin")
added a new "cs-gpio" property and made it a requirement in
order to make the driver behave in the same way that it used to.

The motivation of the offending commit was to allow boards that
want to use the native chip select (instead of a GPIO) to work
with the s3c64xx SPI driver. Something that was not possible
before since the driver made it mandatory to specify a GPIO.

Unfortunately the commit also changed the driver defaults since
now besides specifying a GPIO, it makes mandatory to also specify
that a GPIO is used while the default used to be the opposite.

That mean that old FDT are not working anymore after 3146bee
so DT backward compatibility was not ensured by that commit.

This is a follow-up series from a previous one posted by Naveen
Krishna [0] which attempts to solve the issue.

The feedback from Naveen's series was that the patches did not
provide a clear explanation about the rationale and goal of both
the series as a whole and the individual changes [1].

So I tried to take Navee's series and rework them to provide
an easier to understand patch series.

The series is composed of the following patches:

Javier Martinez Canillas (1):
  Revert "spi: s3c64xx: Added provision for dedicated cs pin"

Naveen Krishna Chatradhi (3):
  spi: s3c64xx: use the generic SPI "cs-gpios" property
  spi: samsung: Update binding documentation
  ARM: DTS: fix the chip select gpios definition in the SPI nodes

 .../devicetree/bindings/spi/spi-samsung.txt|  8 ++--
 arch/arm/boot/dts/exynos4210-smdkv310.dts  |  2 +-
 arch/arm/boot/dts/exynos4412-trats2.dts|  2 +-
 arch/arm/boot/dts/exynos5250-smdk5250.dts  |  2 +-
 drivers/spi/spi-s3c64xx.c  | 54 ++
 5 files changed, 30 insertions(+), 38 deletions(-)

Patch 01/04 reverts the offending commit since it not only broke
the DT binding but also introduced a confusing "cs-gpio" property
while the driver already used a property with the same name.

Patch 02/04 fixes the DT binding for good by using the SPI core
"cs-gpios" property to specify the chip select GPIO instead of
using a custom property only used by this driver. This change
breaks backward compatibility but this has been broken for more
than a year and nobody complained so I think it's safe to change
it again in favor of using standard DT binding properties.

A benefit of Patch 02/04 is that it allows DT and legacy boards
that need to use the built-in CS instead of a GPIO to work with
the driver which was the original motivation of the broken commit.

Patch 03/04 updates the driver binding documentation accordingly
and patch 04/04 updates all the DTS board files in mainline.

Best regards,
Javier

[0]: http://www.spinics.net/lists/linux-samsung-soc/msg34163.html
[1]: http://www.spinics.net/lists/linux-samsung-soc/msg34309.html

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 3/4] spi: samsung: Update binding documentation

2014-07-16 Thread Javier Martinez Canillas
From: Naveen Krishna Chatradhi 

Samsung SPI driver now uses the generic SPI "cs-gpios"
binding so update the documentation accordingly.

Signed-off-by: Naveen Krishna Chatradhi 
[javier.marti...@collabora.co.uk: split changes and improve commit message]
Signed-off-by: Javier Martinez Canillas 
Reviewed-by: Tomasz Figa 
---
 Documentation/devicetree/bindings/spi/spi-samsung.txt | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/Documentation/devicetree/bindings/spi/spi-samsung.txt 
b/Documentation/devicetree/bindings/spi/spi-samsung.txt
index 7f2d88d..1e8a857 100644
--- a/Documentation/devicetree/bindings/spi/spi-samsung.txt
+++ b/Documentation/devicetree/bindings/spi/spi-samsung.txt
@@ -38,15 +38,13 @@ Optional Board Specific Properties:
 - num-cs: Specifies the number of chip select lines supported. If
   not specified, the default number of chip select lines is set to 1.
 
+- cs-gpios: should specify GPIOs used for chipselects (see spi-bus.txt)
+
 SPI Controller specific data in SPI slave nodes:
 
 - The spi slave nodes should provide the following information which is 
required
   by the spi controller.
 
-  - cs-gpio: A gpio specifier that specifies the gpio line used as
-the slave select line by the spi controller. The format of the gpio
-specifier depends on the gpio controller.
-
   - samsung,spi-feedback-delay: The sampling phase shift to be applied on the
 miso line (to account for any lag in the miso line). The following are the
 valid values.
@@ -84,6 +82,7 @@ Example:
#size-cells = <0>;
pinctrl-names = "default";
pinctrl-0 = <&spi0_bus>;
+   cs-gpios = <&gpa2 5 0>;
 
w25q80bw@0 {
#address-cells = <1>;
@@ -93,7 +92,6 @@ Example:
spi-max-frequency = <1>;
 
controller-data {
-   cs-gpio = <&gpa2 5 1 0 3>;
samsung,spi-feedback-delay = <0>;
};
 
-- 
2.0.0.rc2

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/4] Revert "spi: s3c64xx: Added provision for dedicated cs pin"

2014-07-16 Thread Javier Martinez Canillas
This reverts commit 3146beec21b64f4551fcf0ac148381d54dc41b1b.

This commit resulted in a DT backward compatibility breakage.

Some devices use the native chip select (CS) instead of a GPIO
pin to drive the CS line. But the SPI driver made it mandatory
to specify a GPIO pin in the SPI device node controller-data.
So, using the built-in CS was not possible with the driver.

Commit 3146bee tried to fix that by adding a "cs-gpio" property
which could be defined in the SPI device node to make the driver
request the GPIO from the controller-data node.

Unfortunately that changed the old DT binding semantics since
now it's mandatory to have the "cs-gpio" property defined in
the SPI device node in order to use a GPIO pin to drive the CS.

As an example, a SPI device was defined before the commit with:

spi@12d2 {
slave-node@0 {
controller-data {
 cs-gpio = <&gpb1 2 0>;
}
   }
}

and after the commit, the following DTS snippet must be used:

spi@12d2 {
cs-gpio;
slave-node@0 {
controller-data {
 cs-gpio = <&gpb1 2 0>;
}
   }
}

So, after commit 3146bee the driver does not look for the GPIO
by default and it only looks for it if the top level "cs-gpio"
property is defined while the default used to be the opposite.
To always request the GPIO defined in the controller-data node.

This means that old FDT that of course didn't have this added
"cs-gpio" DT property in the SPI node broke after this change.

The offending commit can't be reverted cleanly since more than
a year have passed and other changes were made in the meantime
but this patch partially reverts the driver to it's original
state so old FDT can work again.

This patch will break Device Trees that were relying on the new
behavior of course but the patch should be reverted because:

a) There aren't DTS in mainline that use this new property.
b) They were relying on a behavior that broke DT compatibility.
c) The new binding is awkard, needing two properties with the
   same name (cs-gpio) on different nodes is confusing at least.
d) The new property was not added to the DT binding doc:
   Documentation/devicetree/bindings/spi/spi-samsung.txt

Signed-off-by: Javier Martinez Canillas 
Reviewed-by: Tomasz Figa 
---
 drivers/spi/spi-s3c64xx.c | 37 +++--
 1 file changed, 11 insertions(+), 26 deletions(-)

diff --git a/drivers/spi/spi-s3c64xx.c b/drivers/spi/spi-s3c64xx.c
index a771a3a..e48c6fa 100644
--- a/drivers/spi/spi-s3c64xx.c
+++ b/drivers/spi/spi-s3c64xx.c
@@ -197,7 +197,6 @@ struct s3c64xx_spi_driver_data {
struct s3c64xx_spi_dma_data tx_dma;
struct s3c64xx_spi_port_config  *port_conf;
unsigned intport_id;
-   boolcs_gpio;
 };
 
 static void flush_fifo(struct s3c64xx_spi_driver_data *sdd)
@@ -754,10 +753,8 @@ static struct s3c64xx_spi_csinfo 
*s3c64xx_get_slave_ctrldata(
 {
struct s3c64xx_spi_csinfo *cs;
struct device_node *slave_np, *data_np = NULL;
-   struct s3c64xx_spi_driver_data *sdd;
u32 fb_delay = 0;
 
-   sdd = spi_master_get_devdata(spi->master);
slave_np = spi->dev.of_node;
if (!slave_np) {
dev_err(&spi->dev, "device node not found\n");
@@ -776,10 +773,7 @@ static struct s3c64xx_spi_csinfo 
*s3c64xx_get_slave_ctrldata(
return ERR_PTR(-ENOMEM);
}
 
-   /* The CS line is asserted/deasserted by the gpio pin */
-   if (sdd->cs_gpio)
-   cs->line = of_get_named_gpio(data_np, "cs-gpio", 0);
-
+   cs->line = of_get_named_gpio(data_np, "cs-gpio", 0);
if (!gpio_is_valid(cs->line)) {
dev_err(&spi->dev, "chip select gpio is not specified or 
invalid\n");
kfree(cs);
@@ -818,20 +812,17 @@ static int s3c64xx_spi_setup(struct spi_device *spi)
}
 
if (!spi_get_ctldata(spi)) {
-   /* Request gpio only if cs line is asserted by gpio pins */
-   if (sdd->cs_gpio) {
-   err = gpio_request_one(cs->line, GPIOF_OUT_INIT_HIGH,
-   dev_name(&spi->dev));
-   if (err) {
-   dev_err(&spi->dev,
-   "Failed to get /CS gpio [%d]: %d\n",
-   cs->line, err);
-   goto err_gpio_req;
-   }
-
-   spi->cs_gpio = cs->line;
+   err = gpio_request_one(cs->line, GPIOF_OUT_INIT_HIGH,
+  dev_name(&spi->dev));
+   if (err) {
+   dev_err(&spi->dev,
+   "Fai

[PATCH 2/4] spi: s3c64xx: use the generic SPI "cs-gpios" property

2014-07-16 Thread Javier Martinez Canillas
From: Naveen Krishna Chatradhi 

The s3c64xx SPI driver uses a custom DT binding to specify
the GPIO used to drive the chip select (CS) line instead of
using the generic "cs-gpios" property already defined in:
Documentation/devicetree/bindings/spi/spi-bus.txt.

It's unfortunate that drivers are not using standard bindings
and creating custom ones instead but in most cases this can't
be changed without breaking Device Tree backward compatibility.

But in the case of this driver, its DT binding has been broken
for more than a year. Since after commit (dated June, 21 2013):

3146bee ("spi: s3c64xx: Added provision for dedicated cs pin")

DT backward compatibility was broken and nobody noticed until
now when the commit was reverted. So it seems to be safe to
change the binding to use the standard SPI "cs-gpios" property
instead of using a custom one just for this driver.

This patch also allows boards that don't use a GPIO pin for the
CS to work with the driver since the SPI core will take care of
setting spi->cs_gpio to -ENOENT if a board wants to use the built
in CS instead of a GPIO as explained in the SPI bus DT binding:
Documentation/devicetree/bindings/spi/spi-bus.txt.

For non-DT platforms, spi->cs_gpio will be set to -ENOENT as well
unless they specify a GPIO pin in their platform data. So both
native and GPIO chip select is also supported for legacy boards.

The above use case was what motivated commit 3146bee which broke
the DT binding backward compatibility in the first place.

Signed-off-by: Naveen Krishna Chatradhi 
[javier.marti...@collabora.co.uk: split changes and improve commit message]
Signed-off-by: Javier Martinez Canillas 
Reviewed-by: Tomasz Figa 
---
 drivers/spi/spi-s3c64xx.c | 49 ---
 1 file changed, 29 insertions(+), 20 deletions(-)

diff --git a/drivers/spi/spi-s3c64xx.c b/drivers/spi/spi-s3c64xx.c
index e48c6fa..480133e 100644
--- a/drivers/spi/spi-s3c64xx.c
+++ b/drivers/spi/spi-s3c64xx.c
@@ -773,14 +773,6 @@ static struct s3c64xx_spi_csinfo 
*s3c64xx_get_slave_ctrldata(
return ERR_PTR(-ENOMEM);
}
 
-   cs->line = of_get_named_gpio(data_np, "cs-gpio", 0);
-   if (!gpio_is_valid(cs->line)) {
-   dev_err(&spi->dev, "chip select gpio is not specified or 
invalid\n");
-   kfree(cs);
-   of_node_put(data_np);
-   return ERR_PTR(-EINVAL);
-   }
-
of_property_read_u32(data_np, "samsung,spi-feedback-delay", &fb_delay);
cs->fb_delay = fb_delay;
of_node_put(data_np);
@@ -801,9 +793,16 @@ static int s3c64xx_spi_setup(struct spi_device *spi)
int err;
 
sdd = spi_master_get_devdata(spi->master);
-   if (!cs && spi->dev.of_node) {
+   if (spi->dev.of_node) {
cs = s3c64xx_get_slave_ctrldata(spi);
spi->controller_data = cs;
+   } else if (cs) {
+   /* On non-DT platforms the SPI core will set spi->cs_gpio
+* to -ENOENT. The GPIO pin used to drive the chip select
+* is defined by using platform data so spi->cs_gpio value
+* has to be override to have the proper GPIO pin number.
+*/
+   spi->cs_gpio = cs->line;
}
 
if (IS_ERR_OR_NULL(cs)) {
@@ -812,17 +811,17 @@ static int s3c64xx_spi_setup(struct spi_device *spi)
}
 
if (!spi_get_ctldata(spi)) {
-   err = gpio_request_one(cs->line, GPIOF_OUT_INIT_HIGH,
-  dev_name(&spi->dev));
-   if (err) {
-   dev_err(&spi->dev,
-   "Failed to get /CS gpio [%d]: %d\n",
-   cs->line, err);
-   goto err_gpio_req;
+   if (gpio_is_valid(spi->cs_gpio)) {
+   err = gpio_request_one(spi->cs_gpio, 
GPIOF_OUT_INIT_HIGH,
+  dev_name(&spi->dev));
+   if (err) {
+   dev_err(&spi->dev,
+   "Failed to get /CS gpio [%d]: %d\n",
+   spi->cs_gpio, err);
+   goto err_gpio_req;
+   }
}
 
-   spi->cs_gpio = cs->line;
-
spi_set_ctldata(spi, cs);
}
 
@@ -875,7 +874,8 @@ setup_exit:
/* setup() returns with device de-selected */
writel(S3C64XX_SPI_SLAVE_SIG_INACT, sdd->regs + S3C64XX_SPI_SLAVE_SEL);
 
-   gpio_free(cs->line);
+   if (gpio_is_valid(spi->cs_gpio))
+   gpio_free(spi->cs_gpio);
spi_set_ctldata(spi, NULL);
 
 err_gpio_req:
@@ -889,11 +889,20 @@

[PATCH 4/4] ARM: DTS: fix the chip select gpios definition in the SPI nodes

2014-07-16 Thread Javier Martinez Canillas
From: Naveen Krishna Chatradhi 

This patch replaces the "cs-gpio" from "controller-data" node
as was specified in the old binding and uses the standard
"cs-gpios" property expected by the SPI core as is defined now
in the spi-s3c64xx driver DT binding.

Signed-off-by: Naveen Krishna Chatradhi 
Reviewed-by: Javier Martinez Canillas 
Reviewed-by: Tomasz Figa 
---
 arch/arm/boot/dts/exynos4210-smdkv310.dts | 2 +-
 arch/arm/boot/dts/exynos4412-trats2.dts   | 2 +-
 arch/arm/boot/dts/exynos5250-smdk5250.dts | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/arm/boot/dts/exynos4210-smdkv310.dts 
b/arch/arm/boot/dts/exynos4210-smdkv310.dts
index 636d166..676e6e0 100644
--- a/arch/arm/boot/dts/exynos4210-smdkv310.dts
+++ b/arch/arm/boot/dts/exynos4210-smdkv310.dts
@@ -168,6 +168,7 @@
};
 
spi_2: spi@1394 {
+   cs-gpios = <&gpc1 2 0>;
status = "okay";
 
w25x80@0 {
@@ -178,7 +179,6 @@
spi-max-frequency = <100>;
 
controller-data {
-   cs-gpio = <&gpc1 2 0>;
samsung,spi-feedback-delay = <0>;
};
 
diff --git a/arch/arm/boot/dts/exynos4412-trats2.dts 
b/arch/arm/boot/dts/exynos4412-trats2.dts
index 7787844..11967f4 100644
--- a/arch/arm/boot/dts/exynos4412-trats2.dts
+++ b/arch/arm/boot/dts/exynos4412-trats2.dts
@@ -589,6 +589,7 @@
spi_1: spi@1393 {
pinctrl-names = "default";
pinctrl-0 = <&spi1_bus>;
+   cs-gpios = <&gpb 5 0>;
status = "okay";
 
s5c73m3_spi: s5c73m3 {
@@ -596,7 +597,6 @@
spi-max-frequency = <5000>;
reg = <0>;
controller-data {
-   cs-gpio = <&gpb 5 0>;
samsung,spi-feedback-delay = <2>;
};
};
diff --git a/arch/arm/boot/dts/exynos5250-smdk5250.dts 
b/arch/arm/boot/dts/exynos5250-smdk5250.dts
index a794a70..0c6433a 100644
--- a/arch/arm/boot/dts/exynos5250-smdk5250.dts
+++ b/arch/arm/boot/dts/exynos5250-smdk5250.dts
@@ -316,6 +316,7 @@
};
 
spi_1: spi@12d3 {
+   cs-gpios = <&gpa2 5 0>;
status = "okay";
 
w25q80bw@0 {
@@ -326,7 +327,6 @@
spi-max-frequency = <100>;
 
controller-data {
-   cs-gpio = <&gpa2 5 0>;
samsung,spi-feedback-delay = <0>;
};
 
-- 
2.0.0.rc2

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 0/4] spi: s3c64xx: fix DT binding breakage

2014-07-16 Thread Javier Martinez Canillas
On 07/16/2014 06:02 PM, Mark Brown wrote:
> On Wed, Jul 16, 2014 at 05:19:06PM +0200, Javier Martinez Canillas wrote:
> 
> *sigh*  Yesterday Naveen submitted another, different, patch series also
> attempting to improve things which I'm not seeing any reference to here.
> Please coordinate with Naveen about what you are doing.
> 

Yes, I answered Naveen on his latest series and told him that I thought his v6
was better and also that the commit messages where still not clearly explaining
the motivation for the changes [0].

So after that I asked him in private if he wouldn't mind if I try to rework his
series to make it easier to understand and he agreed on that. I should had
mentioned it the cover later, sorry about that.

Please take a look to this series instead of the latest that was posted by 
Naveen.

Thanks a lot and best regards,
Javier

[0]: https://www.mail-archive.com/devicetree@vger.kernel.org/msg34860.html
--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 0/4 v2] hwmon: ntc_thermistor: prepose vendor prefix change

2014-07-17 Thread Javier Martinez Canillas
Hello Naveen,

On Thu, Jul 17, 2014 at 6:21 AM, Naveen Krishna Ch
 wrote:
>
> Can you pull the 3/4 and 4/4 patches.
>

Patch 4/4 depends on the max77802 support series [0] since the ADC
uses the max77802 ldo9 regulator as its voltage supply. So that patch
can't be merged before the series land in mainline.

Best regards,
Javier

[0]: https://lkml.org/lkml/2014/7/14/273
--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RESEND PATCH v3] charger: tps65090: Allow charger module to be used when no irq

2014-07-17 Thread Javier Martinez Canillas
Hello Doug,

On 06/20/2014 11:42 PM, Doug Anderson wrote:
> On the ARM Chromebook tps65090 has two masters: the AP (the main
> processor running linux) and the EC (the embedded controller).  The AP
> is allowed to mess with FETs but the EC is in charge of charge control.
> 
> The tps65090 interupt line is routed to both the AP and the EC, which
> can cause quite a headache.  Having two people adjusting masks and
> acking interrupts is a recipe for disaster.
> 
> In the shipping kernel we had a hack to have the AP pay attention to
> the IRQ but not to ack it.  It also wasn't supposed to configure the
> IRQ in any way.  That hack allowed us to detect when the device was
> charging without messing with the EC's state.
> 
> The current tps65090 infrastructure makes the above difficult, and it
> was a bit of a hack to begin with.  Rather than uglify the driver to
> support it, just extend the driver's existing notion of "no irq" to
> the charger.  This makes the charger code poll every 2 seconds for AC
> detect, which is sufficient.
> 
> For proper functioning, requires (mfd: tps65090: Don't tell child
> devices we have an IRQ if we don't).  If we don't have that patch
> we'll simply fail to probe on devices without an interrupt (just like
> we did before this patch).
> 
> Signed-off-by: Doug Anderson 
> ---
> Changes in v2:
> - Split noirq (polling mode) changes into MFD and charger
> 
> This patch has been sent up a number of times with no response.  It's
> needed to make the charger work on exynos5250-snow,
> exynos5420-peach-pit, and exynos5800-peach-pi.  It was originally part
> of a series as <https://patchwork.kernel.org/patch/4042751/> and the
> rest of the series has long since landed.
> 

Looks good to me. Also since this patch makes optional to get an IRQ, the
following annoying message is not shown anymore:

[2.132944] tps65090-charger tps65090-charger: Unable to get charger irq = -6

Reviewed-by: Javier Martinez Canillas 
Tested-by: Javier Martinez Canillas 
--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/4] Revert "spi: s3c64xx: Added provision for dedicated cs pin"

2014-07-17 Thread Javier Martinez Canillas
Hello Mark,

On 07/17/2014 08:46 PM, Mark Brown wrote:
> On Wed, Jul 16, 2014 at 05:19:07PM +0200, Javier Martinez Canillas wrote:
>> This reverts commit 3146beec21b64f4551fcf0ac148381d54dc41b1b.
> 
> For the benefit of those who haven't memorized the SHA1s of every commit
> that's "spi: s3c64xx: Added provision for dedicated cs pin" - please
> include the human readable format whenever you reference a SHA1.
> 

Ok, I'll take into account for the next time.

> I've applied this.
> 

Thanks a lot for your help and sorry for all the inconveniences that this series
caused to you.

Best regards,
Javier
--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/1] ARM: exynos_defconfig: Update exynos_defconfig

2014-07-17 Thread Javier Martinez Canillas
Hello,

On 07/14/2014 09:24 PM, Doug Anderson wrote:
> 
>> [WARN] [2.296011] tps65090-charger tps65090-charger: Unable to get
>> charger irq = -22
>> [WARN] [2.313705] tps65090-charger: probe of tps65090-charger
>> failed with error -22
> 
> I have resent the patch to fix this 4 times with no avail.  I'm
> getting a little tired of reposting.  I figure that I'll wait another
> month and try again--maybe the charger subsystem will be in better
> hands by then.

FYI, Sebastian Reichel has applied [0] Doug's patch.

Best regards,
Javier

[0]:
https://git.kernel.org/cgit/linux/kernel/git/sre/linux-power-supply.git/commit/?h=dev&id=5a3effdc8877132fd12f97fea0d4756614b911c7
--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] ARM: config: update multi_v7_defconfig

2014-07-17 Thread Javier Martinez Canillas
Hello,

On Tue, Jul 15, 2014 at 5:59 PM, Doug Anderson  wrote:
>
> Is there a reason not to add more of the max77686 configs?
>
> +CONFIG_RTC_DRV_MAX77686=y
> +CONFIG_COMMON_CLK_MAX77686=y

AFAIK for the multi-platform defconfig we should try to build as a
module as many config options as possible to keep the kernel binary
size to a minimum.

In the case of the MAX77686, the mfd, regulator and clock drivers use
subsys_initcall() instead of module_init() but I wonder which of these
really need to be initialized at subsys init call time and which one
can just be built as a module. The only MAX77686 driver that uses
module_platform_driver() so it's initialized at device initcall time
is the rtc-max77686 driver which ironically is the only MAX77686
driver that doesn't define a MODULE_DEVICE_TABLE() so the module won't
be autoloaded.

Best regards,
Javier
--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3] ARM: dts: Add cros_ec to exynos5420-peach-pit and exynos5800-peach-pi

2014-07-17 Thread Javier Martinez Canillas
Hello Kukjin,

On 06/24/2014 06:28 PM, Doug Anderson wrote:
> This adds cros_ec to exynos5420-peach-pit and exynos5800-peach-pi,
> including:
> * The keyboard
> * The i2c tunnel
> * The tps65090 under the i2c tunnel
> * The battery under the i2c tunnel
> 
> To add extra motivation, it should be noted that tps65090 is one of
> the things needed to get display-related FETs turned on for pit and
> pi.
> 
> Note that this relies on a few outstanding changes:
> * Needs (spi: s3c64xx: fix broken "cs_gpios" usage in the driver) and
>   (spi: s3c64xx: for DT platofrms always get the chipselect info from
>   DT node) to work properly and match the documented bindings.  See
>   <https://patchwork.kernel.org/patch/4346701/> and
>   <https://patchwork.kernel.org/patch/4346711/>
> 
> Signed-off-by: Doug Anderson 
> Tested-by: Javier Martinez Canillas 
> Tested-by: Tushar Behera 
> 

Mark Brown as already applied the SPI DT binding fix from Naveen [0] which was
the dependency for this patch and he said that will try to send the whole series
to Torvalds before the 3.16-rc cycle ends.

So I think that it's safe now if you want to pick this patch.

Thanks a lot!

Best regards,
Javier

[0]:
https://git.kernel.org/cgit/linux/kernel/git/broonie/spi.git/commit/?h=for-next&id=306972cedfdedc662dd8e32a6397d0e29f2ac90e
--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] ARM: config: update multi_v7_defconfig

2014-07-17 Thread Javier Martinez Canillas
Hello Russell,

On Fri, Jul 18, 2014 at 12:44 AM, Russell King - ARM Linux
 wrote:
> On Fri, Jul 18, 2014 at 12:31:48AM +0200, Javier Martinez Canillas wrote:
>> In the case of the MAX77686, the mfd, regulator and clock drivers use
>> subsys_initcall() instead of module_init() but I wonder which of these
>> really need to be initialized at subsys init call time and which one
>> can just be built as a module.
>
> I think you're making a frequently made mistake concerning module
> initialisation.
>
> Having code initialised by subsys_initcall() (or indeed any other level)
> does not preclude it being a module:
>
> #ifndef MODULE
> ...
> #define subsys_initcall(fn) __define_initcall(fn, 4)
> ...
> #else /* MODULE */
> ...
> #define subsys_initcall(fn) module_init(fn)
> ...
> #endif
>
> So, subsys_initcall() automagically becomes module_init() when built
> as a module.  There's no need to change anything here.
>

I was indeed confused, I should had looked at include/linux/init.h
before. Thanks a lot for the clarification.

Best regards,
Javier
--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3 4/5] regulator: max77802: Parse regulator operating mode properties

2014-10-26 Thread Javier Martinez Canillas
Hello Mark,

On 10/24/2014 11:02 PM, Mark Brown wrote:
> On Thu, Oct 23, 2014 at 11:28:09AM +0200, Javier Martinez Canillas wrote:
> 
> Please fix your mailer to word wrap within paragraphs - you should know
> this by now :/  I've reflowed for legibility.
> 

Sorry about that, I was on holidays last week and sent you that email from
my phone. Next time I'll wait until I've access to a mailer that I'm sure
does the right thing before answering you.

>> However this is an implementation detail and should not change the DT
>> bindings in the current version. Could you please let me know if you
>> have any issues with the other patches from this series so I can
>> address all of them when doing a re-spin?
> 
> I can't recall anything but I'm not sure I looked at them in any detail.
> 

Ok, thanks a lot for the feedback.

Best regards,
Javier
--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/1] ARM: exynos_defconfig: Enable max77802 rtc and clock drivers

2014-10-27 Thread Javier Martinez Canillas
Commit 6e80e3d87549 ("ARM: exynos_defconfig: Enable MAX77802")
enabled support for the max77802 regulators but the PMIC also
has a Real-Time-Clock (RTC) and 2-channel 32kHz clock outputs.

Enable the kernel config options to have the drivers for these
devices built-in since they are present in many Exynos boards.

Signed-off-by: Javier Martinez Canillas 
Acked-by: Kevin Hilman 
Tested-by: Kevin Hilman 
---

This patch supersedes [0] since commit "ARM: exynos_defconfig: savedefconfig"
is not present in linux-next anymore which disabled among other options, the
max77802 support.

However, support for the max77802 rtc and clocks were not enabled on exynos
defconfig so $subject is still needed.

Kevin, I carried your tags from [0] since $subject enables the options you
needed to get RTC wakeup from suspend working on exynos5800-peach-pi. Please
let me know if they no longer applies.

Best regards,
Javier

[0]: https://lkml.org/lkml/2014/10/9/413

 arch/arm/configs/exynos_defconfig | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/arm/configs/exynos_defconfig 
b/arch/arm/configs/exynos_defconfig
index 72058b8..e21ef83 100644
--- a/arch/arm/configs/exynos_defconfig
+++ b/arch/arm/configs/exynos_defconfig
@@ -142,11 +142,13 @@ CONFIG_MMC_DW_IDMAC=y
 CONFIG_MMC_DW_EXYNOS=y
 CONFIG_RTC_CLASS=y
 CONFIG_RTC_DRV_MAX77686=y
+CONFIG_RTC_DRV_MAX77802=y
 CONFIG_RTC_DRV_S5M=y
 CONFIG_RTC_DRV_S3C=y
 CONFIG_DMADEVICES=y
 CONFIG_PL330_DMA=y
 CONFIG_COMMON_CLK_MAX77686=y
+CONFIG_COMMON_CLK_MAX77802=y
 CONFIG_COMMON_CLK_S2MPS11=y
 CONFIG_EXYNOS_IOMMU=y
 CONFIG_IIO=y
-- 
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v4 2/3] regulator: max77686: Implement suspend disable for some LDOs

2014-10-27 Thread Javier Martinez Canillas
Hello Krzysztof,

On 10/27/2014 10:44 AM, Krzysztof Kozlowski wrote:
> Some LDOs of Maxim 77686 PMIC support disabling during system suspend
> (LDO{2,6,7,8,10,11,12,14,15,16}). This was already implemented as part
> of set_suspend_mode function. In that case the mode was one of:
>  - disable,
>  - normal mode,
>  - low power mode.
> However there are no bindings for setting the mode during suspend.
> 
> Add suspend disable for LDO regulators supporting this to the existing
> max77686_buck_set_suspend_disable() function. This helps reducing
> energy consumption during system sleep.
> 
> Signed-off-by: Krzysztof Kozlowski 
> ---
>  drivers/regulator/max77686.c | 75 
> ++--
>  1 file changed, 66 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/regulator/max77686.c b/drivers/regulator/max77686.c
> index 3d0922051488..4b35c19c9286 100644
> --- a/drivers/regulator/max77686.c
> +++ b/drivers/regulator/max77686.c
> @@ -87,18 +87,31 @@ struct max77686_data {
>   unsigned int opmode[MAX77686_REGULATORS];
>  };
>  
> -/* Some BUCKS supports Normal[ON/OFF] mode during suspend */
> -static int max77686_buck_set_suspend_disable(struct regulator_dev *rdev)
> +/* Some BUCKs and LDOs supports Normal[ON/OFF] mode during suspend */
> +static int max77686_set_suspend_disable(struct regulator_dev *rdev)
>  {
>   unsigned int val;
>   struct max77686_data *max77686 = rdev_get_drvdata(rdev);
>   int ret, id = rdev_get_id(rdev);
>  
> - if (id == MAX77686_BUCK1)
> + switch (id) {
> + case MAX77686_BUCK1:
>   val = MAX77686_BUCK_OFF_PWRREQ;
> - else
> - val = MAX77686_BUCK_OFF_PWRREQ
> - << MAX77686_OPMODE_BUCK234_SHIFT;
> + break;
> + case MAX77686_BUCK2 ... MAX77686_BUCK4:
> + val = MAX77686_BUCK_OFF_PWRREQ << MAX77686_OPMODE_BUCK234_SHIFT;
> + break;
> + case MAX77686_LDO2:
> + case MAX77686_LDO6 ... MAX77686_LDO8:
> + case MAX77686_LDO10 ... MAX77686_LDO12:
> + case MAX77686_LDO14 ... MAX77686_LDO16:
> + val = MAX77686_LDO_OFF_PWRREQ << MAX77686_OPMODE_SHIFT;
> + break;
> + default:
> + pr_warn("%s: regulator_suspend_disable not supported\n",
> + rdev->desc->name);
> + return -EINVAL;
> + }
>  
>   ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
>rdev->desc->enable_mask, val);
> @@ -176,13 +189,53 @@ static int max77686_ldo_set_suspend_mode(struct 
> regulator_dev *rdev,
>   return 0;
>  }
>  
> +/*
> + * For regulators supporting disabled in suspend it checks if opmode
> + * is 'off_pwrreq' mode (disabled in suspend) and changes it to 'enable'.
> + * For other regulators does nothing.
> + */
> +static void max77686_set_opmode_enable(struct max77686_data *max77686, int 
> id)
> +{
> + unsigned int opmode_shift;
> +
> + /*
> +  * Same enable function is used for LDO and bucks. Assuming
> +  * the same values are used for enable registers.
> +  */
> + BUILD_BUG_ON(MAX77686_LDO_OFF_PWRREQ != MAX77686_BUCK_OFF_PWRREQ);
> + BUILD_BUG_ON(MAX77686_LDO_NORMAL != MAX77686_BUCK_NORMAL);
> +
> + switch (id) {
> + case MAX77686_BUCK1:
> + opmode_shift = 0;
> + break;
> + case MAX77686_BUCK2 ... MAX77686_BUCK4:
> + opmode_shift = MAX77686_OPMODE_BUCK234_SHIFT;
> + break;
> + case MAX77686_LDO2:
> + case MAX77686_LDO6 ... MAX77686_LDO8:
> + case MAX77686_LDO10 ... MAX77686_LDO12:
> + case MAX77686_LDO14 ... MAX77686_LDO16:
> + opmode_shift = MAX77686_OPMODE_SHIFT;
> + break;
> + default:
> + return;
> + }
> +
> + if (max77686->opmode[id] == (MAX77686_LDO_OFF_PWRREQ << opmode_shift))
> + max77686->opmode[id] = MAX77686_LDO_NORMAL << opmode_shift;
> +}
> +
>  static int max77686_enable(struct regulator_dev *rdev)
>  {
>   struct max77686_data *max77686 = rdev_get_drvdata(rdev);
> + int id = rdev_get_id(rdev);
> +
> + max77686_set_opmode_enable(max77686, id);
>  
>   return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
> rdev->desc->enable_mask,
> -   max77686->opmode[rdev_get_id(rdev)]);
> +   max77686->opmode[id]);
>  }

the max77802 driver handles this slightly differently. It stores in opmode[id]
just the value without the shift and there is a max77802_get_opmode_shift() to
obtain the shift that is used before updating the register, e.g:

int shift = max77802_get_opmode_shift(id);
return regmap_update_bits(..., max77802->opmode[id] << shift);

I think the max77802 driver approach is better since it avoids duplicating the
switch statement to get the shift for each regulator. Just look how the max77802
enable and disable functions are easier to read. Looking at th

Re: [PATCH v4 2/3] regulator: max77686: Implement suspend disable for some LDOs

2014-10-27 Thread Javier Martinez Canillas
On 10/27/2014 11:27 AM, Krzysztof Kozlowski wrote:
> 
> Storing opmode in non-shifted form is intuitive also to me. That's way I
> slipped the bug in previous version.
> 

Great.

> I'll change this to non-shifted opmode. The patch will grow bigger but
> the code should be more readable.
> 

Maybe split in two patches? A preparatory that adds max77686_get_opmode_shift()
and changes the current driver and a second one that implements suspend disable
for LDOs?

> Thanks!

You are welcome.

Best regards,
Javier
--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v5 2/4] regulator: max77686: Store opmode non-shifted

2014-10-27 Thread Javier Martinez Canillas
Hello Krzysztof,

On 10/27/2014 01:11 PM, Krzysztof Kozlowski wrote:
> Introduce simple helper for calculating the shift for OPMODE field in
> registers. This allows storing the current value of opmode in
> non-shifted form and simplifies a little set_suspend_disable and enable
> functions. Additionally this will allow adding support LDOs to the
> existing set_suspend_disable function.
> 
> Signed-off-by: Krzysztof Kozlowski 
> Suggested-by: Javier Martinez Canillas 
> ---
>  drivers/regulator/max77686.c | 49 
> ++--
>  1 file changed, 34 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/regulator/max77686.c b/drivers/regulator/max77686.c

The patch looks good to me.

Reviewed-by: Javier Martinez Canillas 

>  
>  static int max77686_set_ramp_delay(struct regulator_dev *rdev, int 
> ramp_delay)
> @@ -495,7 +513,8 @@ static int max77686_pmic_probe(struct platform_device 
> *pdev)
>   config.init_data = pdata->regulators[i].initdata;
>   config.of_node = pdata->regulators[i].of_node;
>  
> - max77686->opmode[i] = regulators[i].enable_mask;
> + max77686->opmode[i] = regulators[i].enable_mask >>
> + max77686_get_opmode_shift(i);

I don't think it has to be done in your patch but as a follow-up it would be
good to change this to:

max77686->opmode[i] = MAX77686_NORMAL;

since that is really what this code is trying to do AFAIU. This just happens
to work because the value of MAX77686_OPMODE_MASK (0x3) is also "Output ON in
Normal Mode" but the code is not correct IMHO.

Or even better, the regulator mode should be read from the hw registers instead
of setting always to normal. That is what the max77802 driver does for example.

Best regards,
Javier
--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v5 3/4] regulator: max77686: Add suspend disable for some LDOs

2014-10-27 Thread Javier Martinez Canillas
Hello Krzysztof,

On 10/27/2014 01:11 PM, Krzysztof Kozlowski wrote:
> Some LDOs of Maxim 77686 PMIC support disabling during system suspend
> (LDO{2,6,7,8,10,11,12,14,15,16}). This was already implemented as part
> of set_suspend_mode function. In that case the mode was one of:
>  - disable,
>  - normal mode,
>  - low power mode.
> However there are no bindings for setting the mode during suspend.
> 
> Add suspend disable for LDO regulators supporting this. Re-use existing
> max77686_buck_set_suspend_disable() function. This helps reducing
> energy consumption during system sleep.
> 
> Signed-off-by: Krzysztof Kozlowski 
> ---
>  drivers/regulator/max77686.c | 15 +++
>  1 file changed, 11 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/regulator/max77686.c b/drivers/regulator/max77686.c
> index 2ebc4257425b..c6bf6f79bd2a 100644
> --- a/drivers/regulator/max77686.c
> +++ b/drivers/regulator/max77686.c

Looks good to me.

Reviewed-by: Javier Martinez Canillas 

Best regards,
Javier

--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/8] regulator: max77802: Remove support for board files

2014-10-27 Thread Javier Martinez Canillas
Hello Krzysztof,

On 10/27/2014 04:03 PM, Krzysztof Kozlowski wrote:
> The driver is used only on Exynos based boards with DTS support.
> Convert the driver to DTS-only version.
> 
> Signed-off-by: Krzysztof Kozlowski 
> ---
>  drivers/regulator/max77802.c | 44 
> +++-
>  1 file changed, 15 insertions(+), 29 deletions(-)
> 
> diff --git a/drivers/regulator/max77802.c b/drivers/regulator/max77802.c
> index 5839c4509e1f..61d03e9f8acf 100644
> --- a/drivers/regulator/max77802.c
> +++ b/drivers/regulator/max77802.c

The original ChromeOS max77xxx driver supported both DT and platform data
configuration and that's why the max77802 driver was not DT-only.

But I looked at the ChromeOS kernel now and indeed even in that tree there
are no board files using the max77802 platform data so I agree that it
should be removed.

Acked-by: Javier Martinez Canillas 

Best regards,
Javier
--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


<    3   4   5   6   7   8   9   10   11   12   >