mfd: max77620: add support for configuring low-battery monitor
Laxman Dewangan [Wed, 7 Oct 2015 13:01:45 +0000 (18:01 +0530)]
Add support to configure low battery monitor configuration register.

Change-Id: I426742d3af44b8bd1980f10da67142215b4e6d93
Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
(cherry picked from commit 18d0e3f001a6e831172766fd51b42a4b8deefaa1)
Reviewed-on: http://git-master/r/815126
GVS: Gerrit_Virtual_Submit

Documentation/devicetree/bindings/mfd/max77620.txt
drivers/mfd/max77620-core.c
include/linux/mfd/max77620.h

index 40030f1..cd9bcd9 100644 (file)
@@ -189,6 +189,26 @@ Optinal properties:
                        to nearest lower side if other than above is configured.
        -maxim,backup-battery-output-resister: Output resistor on Ohm.
                        Device supports 100/1000/3000/6000 Ohms.
+Low-Battery Monitor:
+==================
+This sub-node configure low battery monitor configuration registers. Device has
+support for low-battery monitor configuration through child DT node
+"low-battery-monitor".
+
+Optinal properties:
+       - maxim,low-battery-dac-enable: Enable low battery DAC.
+       - maxim,low-battery-dac-disable: Disable low battery DAC.
+       - maxim,low-battery-shutdown-enable: Enable low battery shutdown.
+       - maxim,low-battery-shutdown-disable: Disable low battery shutdown.
+       - maxim,low-battery-reset-enable: Enable low battery reset.
+       - maxim,low-battery-reset-disable: Disable low battery reset.
+Watchdog:
+==============
+This sub-node configure watchdog timer of the device. Device has watchdog
+for monitoring system health. If WDT expire, system get reset.
+
+Optinal properties:
+       -maxim,wdt-timeout: Watchdog timeout.
 Watchdog:
 ==============
 This sub-node configure watchdog timer of the device. Device has watchdog
index 3b3e2b2..f0fe151 100644 (file)
@@ -450,6 +450,56 @@ static int max77620_init_backup_battery_charging(struct max77620_chip *chip,
        return 0;
 }
 
+static int max77620_init_low_battery_monitor(struct max77620_chip *chip,
+               struct device *dev)
+{
+       struct device_node *np;
+       bool pval;
+       u8 mask = 0;
+       u8 val = 0;
+       int ret;
+
+
+       np = of_get_child_by_name(dev->of_node, "low-battery-monitor");
+       if (!np)
+               return 0;
+
+       pval = of_property_read_bool(np, "maxim,low-battery-dac-enable");
+       if (pval) {
+               mask |= MAX77620_CNFGGLBL1_LBDAC_EN;
+               val |= MAX77620_CNFGGLBL1_LBDAC_EN;
+       }
+       pval = of_property_read_bool(np, "maxim,low-battery-dac-disable");
+       if (pval)
+               mask |= MAX77620_CNFGGLBL1_LBDAC_EN;
+
+       pval = of_property_read_bool(np, "maxim,low-battery-shutdown-enable");
+       if (pval) {
+               mask |= MAX77620_CNFGGLBL1_MPPLD;
+               val |= MAX77620_CNFGGLBL1_MPPLD;
+       }
+       pval = of_property_read_bool(np, "maxim,low-battery-shutdown-disable");
+       if (pval)
+               mask |= MAX77620_CNFGGLBL1_MPPLD;
+
+       pval = of_property_read_bool(np, "maxim,low-battery-reset-enable");
+       if (pval) {
+               mask |= MAX77620_CNFGGLBL1_LBRSTEN;
+               val |= MAX77620_CNFGGLBL1_LBRSTEN;
+       }
+       pval = of_property_read_bool(np, "maxim,low-battery-reset-disable");
+       if (pval)
+               mask |= MAX77620_CNFGGLBL1_LBRSTEN;
+
+       ret = max77620_reg_update(dev, MAX77620_PWR_SLAVE,
+                       MAX77620_REG_CNFGGLBL1, mask, val);
+       if (ret < 0) {
+               dev_err(dev, "Reg CNFGGLBL1 update failed, %d\n", ret);
+               return ret;
+       }
+       return 0;
+}
+
 static int max77620_initialise_chip(struct max77620_chip *chip,
                        struct device *dev)
 {
@@ -624,6 +674,13 @@ static int max77620_probe(struct i2c_client *client,
                goto fail_free_irq;
        }
 
+       ret = max77620_init_low_battery_monitor(chip, &client->dev);
+       if (ret < 0) {
+               dev_err(&client->dev, "Low battery monitor init failed, %d\n",
+                       ret);
+               goto fail_free_irq;
+       }
+
        ret =  mfd_add_devices(&client->dev, -1, children->cells,
                        children->ncells, NULL, 0,
                        regmap_irq_get_domain(chip->top_irq_data));
index 579c199..19273a2 100644 (file)
 #define MAX77620_TWD_64s                       0x2
 #define MAX77620_TWD_128s                      0x3
 
+#define MAX77620_CNFGGLBL1_LBDAC_EN            BIT(7)
+#define MAX77620_CNFGGLBL1_MPPLD               BIT(6)
+#define MAX77620_CNFGGLBL1_LBHYST              (BIT(5) | BIT(4))
+#define MAX77620_CNFGGLBL1_LBDAC               0x0E
+#define MAX77620_CNFGGLBL1_LBRSTEN             BIT(0)
+
 /* CNFG BBC registers */
 #define MAX77620_CNFGBBC_ENABLE                        BIT(0)
 #define MAX77620_CNFGBBC_CURRENT_MASK          0x06