power: reset: add palmas power off driver
Laxman Dewangan [Mon, 26 Aug 2013 08:46:23 +0000 (13:46 +0530)]
Add power off driver for Palmas which will provide the system
system power off through Palmas PMIC off.

Change-Id: I8ccfeba886b40696a81adc429134ab118efc4b45
Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
Reviewed-on: http://git-master/r/265996

drivers/power/reset/Kconfig
drivers/power/reset/Makefile
drivers/power/reset/palmas-poweroff.c [new file with mode: 0644]
include/linux/mfd/palmas.h

index 7119f11..7ba6776 100644 (file)
@@ -40,3 +40,11 @@ config POWER_RESET_VEXPRESS
        help
          Power off and reset support for the ARM Ltd. Versatile
          Express boards.
+
+config POWER_OFF_PALMAS
+       bool "Palmas power-off-reset driver"
+       depends on MFD_PALMAS
+       select SYSTEM_PMIC
+       help
+         This driver supports turning off and resetting board through Palmas
+         PMIC.
index dd3e776..f5b2dcb 100644 (file)
@@ -3,3 +3,4 @@ obj-$(CONFIG_POWER_RESET_GPIO) += gpio-poweroff.o
 obj-$(CONFIG_POWER_RESET_QNAP) += qnap-poweroff.o
 obj-$(CONFIG_POWER_RESET_RESTART) += restart-poweroff.o
 obj-$(CONFIG_POWER_RESET_VEXPRESS) += vexpress-poweroff.o
+obj-$(CONFIG_POWER_OFF_PALMAS) += palmas-poweroff.o
diff --git a/drivers/power/reset/palmas-poweroff.c b/drivers/power/reset/palmas-poweroff.c
new file mode 100644 (file)
index 0000000..08cf4c6
--- /dev/null
@@ -0,0 +1,163 @@
+/*
+ * palmas-poweroff.c : Power off and reset for Palma device.
+ *
+ * Copyright (c) 2013, NVIDIA Corporation.
+ *
+ * Author: Laxman Dewangan <ldewangan@nvidia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation version 2.
+ *
+ * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind,
+ * whether express or implied; 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
+ */
+
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/mfd/palmas.h>
+#include <linux/power/reset/system-pmic.h>
+
+struct palmas_pm {
+       struct device *dev;
+       struct palmas *palmas;
+       struct system_pmic_dev *system_pmic_dev;
+       int num_int_mask_regs;
+       int int_mask_reg_add[PALMAS_MAX_INTERRUPT_MASK_REG];
+       int int_status_reg_add[PALMAS_MAX_INTERRUPT_MASK_REG];
+       int int_mask_val[PALMAS_MAX_INTERRUPT_MASK_REG];
+};
+
+static void palmas_power_off(void *drv_data)
+{
+       struct palmas_pm *palmas_pm = drv_data;
+       struct palmas *palmas = palmas_pm->palmas;
+       unsigned int val;
+       int i;
+       int ret;
+
+       for (i = 0; i < palmas_pm->num_int_mask_regs; ++i) {
+               ret = palmas_write(palmas, PALMAS_INTERRUPT_BASE,
+                               palmas_pm->int_mask_reg_add[i],
+                               palmas_pm->int_mask_val[i]);
+               if (ret < 0)
+                       dev_err(palmas_pm->dev,
+                               "register 0x%02x write failed: %d\n",
+                               palmas_pm->int_mask_reg_add[i], ret);
+
+               ret = palmas_read(palmas, PALMAS_INTERRUPT_BASE,
+                                       palmas_pm->int_status_reg_add[i], &val);
+               if (ret < 0)
+                       dev_err(palmas_pm->dev,
+                               "register 0x%02x read failed: %d\n",
+                               palmas_pm->int_status_reg_add[i], ret);
+       }
+
+       /* Mask all COLD RST condition */
+       palmas_write(palmas, PALMAS_PMU_CONTROL_BASE,
+                               PALMAS_SWOFF_COLDRST, 0x0);
+
+       dev_info(palmas_pm->dev, "Powering off the device\n");
+
+       /* Power off the device */
+       palmas_update_bits(palmas, PALMAS_PMU_CONTROL_BASE,
+                               PALMAS_DEV_CTRL, 1, 0);
+}
+
+static struct system_pmic_ops palmas_pm_ops = {
+       .power_off = palmas_power_off,
+};
+
+static int palmas_pm_probe(struct platform_device *pdev)
+{
+       struct palmas *palmas = dev_get_drvdata(pdev->dev.parent);
+       struct palmas_pm *palmas_pm = NULL;
+       struct palmas_platform_data *palmas_pdata;
+       struct palmas_pm_platform_data *pm_pdata = NULL;
+       struct system_pmic_config config;
+       int i;
+
+       palmas_pm = devm_kzalloc(&pdev->dev, sizeof(*palmas_pm),
+                       GFP_KERNEL);
+       if (!palmas_pm) {
+               dev_err(&pdev->dev, "Memory allocation failed.\n");
+               return -ENOMEM;
+       }
+
+       palmas_pm->dev = &pdev->dev;
+       palmas_pm->palmas = palmas;
+       platform_set_drvdata(pdev, palmas_pm);
+
+       palmas_pm->num_int_mask_regs = PALMAS_MAX_INTERRUPT_MASK_REG;
+       if (palmas->id != TPS80036)
+               palmas_pm->num_int_mask_regs = 4;
+
+       palmas_pm->int_mask_reg_add[0] = PALMAS_INT1_MASK;
+       palmas_pm->int_mask_reg_add[1] = PALMAS_INT2_MASK;
+       palmas_pm->int_mask_reg_add[2] = PALMAS_INT3_MASK;
+       palmas_pm->int_mask_reg_add[3] = PALMAS_INT4_MASK;
+       palmas_pm->int_mask_reg_add[4] = PALMAS_INT5_MASK;
+       palmas_pm->int_mask_reg_add[5] = PALMAS_INT6_MASK;
+       palmas_pm->int_status_reg_add[0] = PALMAS_INT1_STATUS;
+       palmas_pm->int_status_reg_add[1] = PALMAS_INT2_STATUS;
+       palmas_pm->int_status_reg_add[2] = PALMAS_INT3_STATUS;
+       palmas_pm->int_status_reg_add[3] = PALMAS_INT4_STATUS;
+       palmas_pm->int_status_reg_add[4] = PALMAS_INT5_STATUS;
+       palmas_pm->int_status_reg_add[5] = PALMAS_INT6_STATUS;
+       for (i = 0; i < palmas_pm->num_int_mask_regs; ++i)
+               palmas_pm->int_mask_val[i] = 0xFF;
+
+       palmas_pdata = dev_get_platdata(pdev->dev.parent);
+       if (palmas_pdata)
+               pm_pdata = palmas_pdata->pm_pdata;
+
+       if (pm_pdata) {
+               config.allow_power_off = pm_pdata->use_power_off;
+               config.allow_power_reset = pm_pdata->use_power_reset;
+       } else {
+               config.allow_power_off = true;
+               config.allow_power_reset = false;
+       }
+
+       palmas_pm->system_pmic_dev = system_pmic_register(&pdev->dev,
+                               &palmas_pm_ops, &config, palmas_pm);
+       if (IS_ERR(palmas_pm->system_pmic_dev)) {
+               int ret = PTR_ERR(palmas_pm->system_pmic_dev);
+               dev_err(&pdev->dev, "System PMIC registartion failed: %d\n",
+                       ret);
+               return ret;
+       }
+       return 0;
+}
+
+static int palmas_pm_remove(struct platform_device *pdev)
+{
+       struct palmas_pm *palmas_pm = platform_get_drvdata(pdev);
+
+       system_pmic_unregister(palmas_pm->system_pmic_dev);
+       return 0;
+}
+
+static struct platform_driver palmas_pm_driver = {
+       .probe          = palmas_pm_probe,
+       .remove         = palmas_pm_remove,
+       .driver         = {
+               .owner  = THIS_MODULE,
+               .name   = "palmas-pm",
+       },
+};
+
+module_platform_driver(palmas_pm_driver);
+MODULE_ALIAS("platform:palmas-pm");
+MODULE_AUTHOR("Laxman Dewangan <ldewangan@nvidia.com>");
+MODULE_LICENSE("GPL v2");
index 6f494d0..c6345f5 100644 (file)
@@ -527,6 +527,11 @@ struct palmas_rtc_platform_data {
        unsigned charging_current_ua;
 };
 
+struct palmas_pm_platform_data {
+       bool use_power_off;
+       bool use_power_reset;
+};
+
 struct palmas_pinctrl_config {
        int pin_name;
        int pin_mux_option;
@@ -592,6 +597,7 @@ struct palmas_platform_data {
        struct palmas_resource_platform_data *resource_pdata;
        struct palmas_clk_platform_data *clk_pdata;
        struct palmas_rtc_platform_data *rtc_pdata;
+       struct palmas_pm_platform_data *pm_pdata;
        struct palmas_battery_platform_data *battery_pdata;
        struct palmas_sim_platform_data *sim_pdata;