summaryrefslogtreecommitdiff
path: root/drivers/mxc/mcu_pmic
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mxc/mcu_pmic')
-rw-r--r--drivers/mxc/mcu_pmic/Kconfig17
-rw-r--r--drivers/mxc/mcu_pmic/Makefile6
-rw-r--r--drivers/mxc/mcu_pmic/max8660.c154
-rw-r--r--drivers/mxc/mcu_pmic/max8660.h49
-rw-r--r--drivers/mxc/mcu_pmic/mc9s08dz60.c197
-rw-r--r--drivers/mxc/mcu_pmic/mc9s08dz60.h73
-rw-r--r--drivers/mxc/mcu_pmic/mcu_pmic_core.c226
-rw-r--r--drivers/mxc/mcu_pmic/mcu_pmic_core.h43
-rw-r--r--drivers/mxc/mcu_pmic/mcu_pmic_gpio.c131
9 files changed, 896 insertions, 0 deletions
diff --git a/drivers/mxc/mcu_pmic/Kconfig b/drivers/mxc/mcu_pmic/Kconfig
new file mode 100644
index 000000000000..cb6815e92d86
--- /dev/null
+++ b/drivers/mxc/mcu_pmic/Kconfig
@@ -0,0 +1,17 @@
+#
+# PMIC Modules configuration
+#
+
+config MXC_PMIC_MC9S08DZ60
+ tristate "MC9S08DZ60 PMIC"
+ depends on ARCH_MXC && I2C
+ ---help---
+ This is the MXC MC9S08DZ60(MCU) PMIC support.
+
+config MXC_MC9SDZ60_RTC
+ tristate "MC9SDZ60 Real Time Clock (RTC) support"
+ depends on MXC_PMIC_MC9SDZ60
+ ---help---
+ This is the MC9SDZ60 RTC module driver. This module provides kernel API
+ for RTC part of MC9SDZ60.
+ If you want MC9SDZ60 RTC support, you should say Y here
diff --git a/drivers/mxc/mcu_pmic/Makefile b/drivers/mxc/mcu_pmic/Makefile
new file mode 100644
index 000000000000..96aae94d5290
--- /dev/null
+++ b/drivers/mxc/mcu_pmic/Makefile
@@ -0,0 +1,6 @@
+#
+# Makefile for the mc9sdz60 pmic drivers.
+#
+
+obj-$(CONFIG_MXC_PMIC_MC9SDZ60) += pmic_mc9sdz60_mod.o
+pmic_mc9sdz60_mod-objs := mcu_pmic_core.o max8660.o mc9s08dz60.o mcu_pmic_gpio.o
diff --git a/drivers/mxc/mcu_pmic/max8660.c b/drivers/mxc/mcu_pmic/max8660.c
new file mode 100644
index 000000000000..17fe22958ca9
--- /dev/null
+++ b/drivers/mxc/mcu_pmic/max8660.c
@@ -0,0 +1,154 @@
+/*
+ * Copyright 2008-2010 Freescale Semiconductor, Inc. All Rights Reserved.
+ */
+
+/*
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+/*!
+ * @file max8660.c
+ * @brief Driver for max8660
+ *
+ * @ingroup pmic
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/delay.h>
+#include <linux/spinlock.h>
+#include <linux/proc_fs.h>
+#include <linux/i2c.h>
+#include <linux/mfd/mc9s08dz60/pmic.h>
+#include <asm/uaccess.h>
+#include "mcu_pmic_core.h"
+#include "max8660.h"
+
+/* I2C bus id and device address of mcu */
+#define I2C1_BUS 0
+#define MAX8660_I2C_ADDR 0x68
+
+static struct i2c_client *max8660_i2c_client;
+
+ /* reg names for max8660
+ REG_MAX8660_OUTPUT_ENABLE_1,
+ REG_MAX8660_OUTPUT_ENABLE_2,
+ REG_MAX8660_VOLT__CHANGE_1,
+ REG_MAX8660_V3_TARGET_VOLT_1,
+ REG_MAX8660_V3_TARGET_VOLT_2,
+ REG_MAX8660_V4_TARGET_VOLT_1,
+ REG_MAX8660_V4_TARGET_VOLT_2,
+ REG_MAX8660_V5_TARGET_VOLT_1,
+ REG_MAX8660_V5_TARGET_VOLT_2,
+ REG_MAX8660_V6V7_TARGET_VOLT,
+ REG_MAX8660_FORCE_PWM
+ */
+
+ /* save down the reg values for the device is write only */
+static u8 max8660_reg_value_table[] = {
+ 0x0, 0x0, 0x0, 0x17, 0x17, 0x1F, 0x1F, 0x04, 0x04, 0x0, 0x0
+};
+static int max8660_dev_present;
+
+int is_max8660_present(void)
+{
+ return max8660_dev_present;
+}
+
+int max8660_get_buffered_reg_val(int reg_name, u8 *value)
+{
+ if (!max8660_dev_present)
+ return -1;
+ /* outof range */
+ if (reg_name < REG_MAX8660_OUTPUT_ENABLE_1
+ || reg_name > REG_MAX8660_FORCE_PWM)
+ return -1;
+ *value =
+ max8660_reg_value_table[reg_name - REG_MAX8660_OUTPUT_ENABLE_1];
+ return 0;
+}
+int max8660_save_buffered_reg_val(int reg_name, u8 value)
+{
+
+ /* outof range */
+ if (reg_name < REG_MAX8660_OUTPUT_ENABLE_1
+ || reg_name > REG_MAX8660_FORCE_PWM)
+ return -1;
+ max8660_reg_value_table[reg_name - REG_MAX8660_OUTPUT_ENABLE_1] = value;
+ return 0;
+}
+
+int max8660_write_reg(u8 reg, u8 value)
+{
+ if (max8660_dev_present && (i2c_smbus_write_byte_data(
+ max8660_i2c_client, reg, value) >= 0))
+ return 0;
+ return -1;
+}
+
+/*!
+ * max8660 I2C attach function
+ *
+ * @param adapter struct i2c_client *
+ * @return 0 for max8660 successfully detected
+ */
+static int max8660_probe(struct i2c_client *client,
+ const struct i2c_device_id *id)
+{
+ int retval;
+ max8660_i2c_client = client;
+ retval = i2c_smbus_write_byte_data(max8660_i2c_client,
+ MAX8660_OUTPUT_ENABLE_1, 0);
+ if (retval == 0) {
+ max8660_dev_present = 1;
+ pr_info("max8660 probed !\n");
+ } else {
+ max8660_dev_present = 0;
+ pr_info("max8660 not detected!\n");
+ }
+ return retval;
+}
+
+/*!
+ * max8660 I2C detach function
+ *
+ * @param client struct i2c_client *
+ * @return 0
+ */
+static int max8660_remove(struct i2c_client *client)
+{
+ return 0;
+}
+
+static const struct i2c_device_id max8660_id[] = {
+ { "max8660", 0 },
+ {},
+};
+MODULE_DEVICE_TABLE(i2c, max8660_id);
+
+static struct i2c_driver max8660_i2c_driver = {
+ .driver = {
+ .owner = THIS_MODULE,
+ .name = "max8660",},
+ .probe = max8660_probe,
+ .remove = max8660_remove,
+ .id_table = max8660_id,
+};
+
+/* called by pmic core when init*/
+int max8660_init(void)
+{
+ int err;
+ err = i2c_add_driver(&max8660_i2c_driver);
+ return err;
+}
+void max8660_exit(void)
+{
+ i2c_del_driver(&max8660_i2c_driver);
+}
diff --git a/drivers/mxc/mcu_pmic/max8660.h b/drivers/mxc/mcu_pmic/max8660.h
new file mode 100644
index 000000000000..370ca5f66a28
--- /dev/null
+++ b/drivers/mxc/mcu_pmic/max8660.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2008-2010 Freescale Semiconductor, Inc. All Rights Reserved.
+ */
+
+/*
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+/*!
+ * @file max8660.h
+ * @brief Driver for max8660
+ *
+ * @ingroup pmic
+ */
+#ifndef _MAX8660_H_
+#define _MAX8660_H_
+
+#ifdef __KERNEL__
+
+#define MAX8660_OUTPUT_ENABLE_1 0x10
+#define MAX8660_OUTPUT_ENABLE_2 0x12
+#define MAX8660_VOLT_CHANGE_CONTROL 0x20
+#define MAX8660_V3_TARGET_VOLT_1 0x23
+#define MAX8660_V3_TARGET_VOLT_2 0x24
+#define MAX8660_V4_TARGET_VOLT_1 0x29
+#define MAX8660_V4_TARGET_VOLT_2 0x2A
+#define MAX8660_V5_TARGET_VOLT_1 0x32
+#define MAX8660_V5_TARGET_VOLT_2 0x33
+#define MAX8660_V6V7_TARGET_VOLT 0x39
+#define MAX8660_FORCE_PWM 0x80
+
+int is_max8660_present(void);
+int max8660_write_reg(u8 reg, u8 value);
+int max8660_save_buffered_reg_val(int reg_name, u8 value);
+int max8660_get_buffered_reg_val(int reg_name, u8 *value);
+int max8660_init(void);
+void max8660_exit(void);
+
+extern int reg_max8660_probe(void);
+extern int reg_max8660_remove(void);
+
+#endif /* __KERNEL__ */
+
+#endif /* _MAX8660_H_ */
diff --git a/drivers/mxc/mcu_pmic/mc9s08dz60.c b/drivers/mxc/mcu_pmic/mc9s08dz60.c
new file mode 100644
index 000000000000..c51ffcd5ba7d
--- /dev/null
+++ b/drivers/mxc/mcu_pmic/mc9s08dz60.c
@@ -0,0 +1,197 @@
+/*
+ * Copyright 2008-2010 Freescale Semiconductor, Inc. All Rights Reserved.
+ */
+
+/*
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+ /*!
+ * @file mc9s08dz60.c
+ * @brief Driver for MC9sdz60
+ *
+ * @ingroup pmic
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/delay.h>
+#include <linux/spinlock.h>
+#include <linux/proc_fs.h>
+#include <linux/i2c.h>
+#include <linux/mfd/mc9s08dz60/core.h>
+
+#include <mach/clock.h>
+#include <linux/uaccess.h>
+#include "mc9s08dz60.h"
+
+/* I2C bus id and device address of mcu */
+#define I2C1_BUS 0
+#define MC9S08DZ60_I2C_ADDR 0xD2 /* 7bits I2C address */
+static struct i2c_client *mc9s08dz60_i2c_client;
+
+int mc9s08dz60_read_reg(u8 reg, u8 *value)
+{
+ *value = (u8) i2c_smbus_read_byte_data(mc9s08dz60_i2c_client, reg);
+ return 0;
+}
+
+int mc9s08dz60_write_reg(u8 reg, u8 value)
+{
+ if (i2c_smbus_write_byte_data(mc9s08dz60_i2c_client, reg, value) < 0)
+ return -1;
+ return 0;
+}
+
+static ssize_t mc9s08dz60_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ unsigned int i;
+ u8 value;
+ int offset = 7;
+
+ for (i = 0; i < 7; i++) {
+ mc9s08dz60_read_reg(i, &value);
+ pr_info("reg%02x: %02x\t", i, value);
+ mc9s08dz60_read_reg(i + offset, &value);
+ pr_info("reg%02x: %02x\t", i + offset, value);
+ mc9s08dz60_read_reg(i + offset * 2, &value);
+ pr_info("reg%02x: %02x\t", i + offset * 2, value);
+ mc9s08dz60_read_reg(i + offset * 3, &value);
+ pr_info("reg%02x: %02x\t", i + offset * 3, value);
+ mc9s08dz60_read_reg(i + offset * 4, &value);
+ pr_info("reg%02x: %02x\t", i + offset * 4, value);
+ mc9s08dz60_read_reg(i + offset * 5, &value);
+ pr_info("reg%02x: %02x\n", i + offset * 5, value);
+ }
+
+ return 0;
+}
+
+static ssize_t mc9s08dz60_store(struct device *dev,
+ struct device_attribute *attr, const char *buf,
+ size_t count)
+{
+ int ret;
+ unsigned long reg, new_value;
+ u8 value;
+ char *p;
+
+ strict_strtoul(buf, 16, &reg);
+
+ p = NULL;
+ p = memchr(buf, ' ', count);
+
+ if (p == NULL) {
+ mc9s08dz60_read_reg(reg, &value);
+ pr_info("reg%02lu: %06x\n", reg, value);
+ return count;
+ }
+
+ p += 1;
+
+ strict_strtoul(p, 16, &new_value);
+ value = new_value;
+
+ ret = mc9s08dz60_write_reg((u8)reg, value);
+ if (ret == 0)
+ pr_info("write reg%02lx: %06x\n", reg, value);
+ else
+ pr_info("register update failed\n");
+
+ return count;
+}
+
+static struct device_attribute mc9s08dz60_dev_attr = {
+ .attr = {
+ .name = "mc9s08dz60_ctl",
+ .mode = S_IRUSR | S_IWUSR,
+ },
+ .show = mc9s08dz60_show,
+ .store = mc9s08dz60_store,
+};
+
+
+/*!
+ * mc9s08dz60 I2C attach function
+ *
+ * @param adapter struct i2c_adapter *
+ * @return 0
+ */
+static int mc9s08dz60_probe(struct i2c_client *client,
+ const struct i2c_device_id *id)
+{
+ int ret = 0;
+ struct mc9s08dz60 *mc9s08dz60 = NULL;
+ struct mc9s08dz60_platform_data *plat_data = client->dev.platform_data;
+ pr_info("mc9s08dz60 probing .... \n");
+
+ mc9s08dz60 = kzalloc(sizeof(struct mc9s08dz60), GFP_KERNEL);
+ if (mc9s08dz60 == NULL)
+ return -ENOMEM;
+
+ i2c_set_clientdata(client, mc9s08dz60);
+ mc9s08dz60->dev = &client->dev;
+ mc9s08dz60->i2c_client = client;
+
+ if (plat_data && plat_data->init) {
+ ret = plat_data->init(mc9s08dz60);
+ if (ret != 0)
+ return -1;
+ }
+
+ ret = device_create_file(&client->dev, &mc9s08dz60_dev_attr);
+ if (ret)
+ dev_err(&client->dev, "create device file failed!\n");
+
+
+ mc9s08dz60_i2c_client = client;
+
+ return 0;
+}
+
+/*!
+ * mc9s08dz60 I2C detach function
+ *
+ * @param client struct i2c_client *
+ * @return 0
+ */
+static int mc9s08dz60_remove(struct i2c_client *client)
+{
+ return 0;
+}
+
+static const struct i2c_device_id mc9s08dz60_id[] = {
+ { "mc9s08dz60", 0 },
+ {},
+};
+MODULE_DEVICE_TABLE(i2c, mc9s08dz60_id);
+
+static struct i2c_driver mc9s08dz60_i2c_driver = {
+ .driver = {.owner = THIS_MODULE,
+ .name = "mc9s08dz60",
+ },
+ .probe = mc9s08dz60_probe,
+ .remove = mc9s08dz60_remove,
+ .id_table = mc9s08dz60_id,
+};
+
+#define SET_BIT_IN_BYTE(byte, pos) (byte |= (0x01 << pos))
+#define CLEAR_BIT_IN_BYTE(byte, pos) (byte &= ~(0x01 << pos))
+
+int mc9s08dz60_init(void)
+{
+ int err;
+ err = i2c_add_driver(&mc9s08dz60_i2c_driver);
+ return err;
+}
+void mc9s08dz60_exit(void)
+{
+ i2c_del_driver(&mc9s08dz60_i2c_driver);
+}
diff --git a/drivers/mxc/mcu_pmic/mc9s08dz60.h b/drivers/mxc/mcu_pmic/mc9s08dz60.h
new file mode 100644
index 000000000000..382d905cd3d1
--- /dev/null
+++ b/drivers/mxc/mcu_pmic/mc9s08dz60.h
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2008-2010 Freescale Semiconductor, Inc. All Rights Reserved.
+ */
+/*
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+/*!
+ * @file mc9s08dz60.h
+ * @brief Driver for mc9s08dz60
+ *
+ * @ingroup pmic
+ */
+#ifndef _MC9SDZ60_H_
+#define _MC9SDZ60_H_
+
+#define MCU_VERSION 0x00
+/*#define Reserved 0x01*/
+#define MCU_SECS 0x02
+#define MCU_MINS 0x03
+#define MCU_HRS 0x04
+#define MCU_DAY 0x05
+#define MCU_DATE 0x06
+#define MCU_MONTH 0x07
+#define MCU_YEAR 0x08
+
+#define MCU_ALARM_SECS 0x09
+#define MCU_ALARM_MINS 0x0A
+#define MCU_ALARM_HRS 0x0B
+/* #define Reserved 0x0C*/
+/* #define Reserved 0x0D*/
+#define MCU_TS_CONTROL 0x0E
+#define MCU_X_LOW 0x0F
+#define MCU_Y_LOW 0x10
+#define MCU_XY_HIGH 0x11
+#define MCU_X_LEFT_LOW 0x12
+#define MCU_X_LEFT_HIGH 0x13
+#define MCU_X_RIGHT 0x14
+#define MCU_Y_TOP_LOW 0x15
+#define MCU_Y_TOP_HIGH 0x16
+#define MCU_Y_BOTTOM 0x17
+/* #define Reserved 0x18*/
+/* #define Reserved 0x19*/
+#define MCU_RESET_1 0x1A
+#define MCU_RESET_2 0x1B
+#define MCU_POWER_CTL 0x1C
+#define MCU_DELAY_CONFIG 0x1D
+/* #define Reserved 0x1E */
+/* #define Reserved 0x1F */
+#define MCU_GPIO_1 0x20
+#define MCU_GPIO_2 0x21
+#define MCU_KPD_1 0x22
+#define MCU_KPD_2 0x23
+#define MCU_KPD_CONTROL 0x24
+#define MCU_INT_ENABLE_1 0x25
+#define MCU_INT_ENABLE_2 0x26
+#define MCU_INT_FLAG_1 0x27
+#define MCU_INT_FLAG_2 0x28
+#define MCU_DES_FLAG 0x29
+int mc9s08dz60_read_reg(u8 reg, u8 *value);
+int mc9s08dz60_write_reg(u8 reg, u8 value);
+int mc9s08dz60_init(void);
+void mc9s08dz60_exit(void);
+
+extern int reg_mc9s08dz60_probe(void);
+extern int reg_mc9s08dz60_remove(void);
+
+#endif /* _MC9SDZ60_H_ */
diff --git a/drivers/mxc/mcu_pmic/mcu_pmic_core.c b/drivers/mxc/mcu_pmic/mcu_pmic_core.c
new file mode 100644
index 000000000000..47c16d1659ca
--- /dev/null
+++ b/drivers/mxc/mcu_pmic/mcu_pmic_core.c
@@ -0,0 +1,226 @@
+/*
+ * Copyright 2008-2010 Freescale Semiconductor, Inc. All Rights Reserved.
+ */
+
+/*
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+/*!
+ * @file mc9s08dz60/mcu_pmic_core.c
+ * @brief This is the main file of mc9s08dz60 Power Control driver.
+ *
+ * @ingroup PMIC_POWER
+ */
+
+/*
+ * Includes
+ */
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/platform_device.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/mfd/mc9s08dz60/pmic.h>
+#include <asm/ioctl.h>
+#include <asm/uaccess.h>
+#include <mach/gpio.h>
+
+#include "mcu_pmic_core.h"
+#include "mc9s08dz60.h"
+#include "max8660.h"
+
+/* bitfield macros for mcu pmic*/
+#define SET_BIT_IN_BYTE(byte, pos) (byte |= (0x01 << pos))
+#define CLEAR_BIT_IN_BYTE(byte, pos) (byte &= ~(0x01 << pos))
+
+
+/* map reg names (enum pmic_reg in pmic_external.h) to real addr*/
+const static u8 mcu_pmic_reg_addr_table[] = {
+ MCU_VERSION,
+ MCU_SECS,
+ MCU_MINS,
+ MCU_HRS,
+ MCU_DAY,
+ MCU_DATE,
+ MCU_MONTH,
+ MCU_YEAR,
+ MCU_ALARM_SECS,
+ MCU_ALARM_MINS,
+ MCU_ALARM_HRS,
+ MCU_TS_CONTROL,
+ MCU_X_LOW,
+ MCU_Y_LOW,
+ MCU_XY_HIGH,
+ MCU_X_LEFT_LOW,
+ MCU_X_LEFT_HIGH,
+ MCU_X_RIGHT,
+ MCU_Y_TOP_LOW,
+ MCU_Y_TOP_HIGH,
+ MCU_Y_BOTTOM,
+ MCU_RESET_1,
+ MCU_RESET_2,
+ MCU_POWER_CTL,
+ MCU_DELAY_CONFIG,
+ MCU_GPIO_1,
+ MCU_GPIO_2,
+ MCU_KPD_1,
+ MCU_KPD_2,
+ MCU_KPD_CONTROL,
+ MCU_INT_ENABLE_1,
+ MCU_INT_ENABLE_2,
+ MCU_INT_FLAG_1,
+ MCU_INT_FLAG_2,
+ MCU_DES_FLAG,
+ MAX8660_OUTPUT_ENABLE_1,
+ MAX8660_OUTPUT_ENABLE_2,
+ MAX8660_VOLT_CHANGE_CONTROL,
+ MAX8660_V3_TARGET_VOLT_1,
+ MAX8660_V3_TARGET_VOLT_2,
+ MAX8660_V4_TARGET_VOLT_1,
+ MAX8660_V4_TARGET_VOLT_2,
+ MAX8660_V5_TARGET_VOLT_1,
+ MAX8660_V5_TARGET_VOLT_2,
+ MAX8660_V6V7_TARGET_VOLT,
+ MAX8660_FORCE_PWM
+};
+
+static int mcu_pmic_read(int reg_num, unsigned int *reg_val)
+{
+ int ret;
+ u8 value = 0;
+ /* mcu ops */
+ if (reg_num >= REG_MCU_VERSION && reg_num <= REG_MCU_DES_FLAG)
+ ret = mc9s08dz60_read_reg(mcu_pmic_reg_addr_table[reg_num],
+ &value);
+ else if (reg_num >= REG_MAX8660_OUTPUT_ENABLE_1
+ && reg_num <= REG_MAX8660_FORCE_PWM)
+ ret = max8660_get_buffered_reg_val(reg_num, &value);
+ else
+ return -1;
+
+ if (ret < 0)
+ return -1;
+ *reg_val = value;
+
+ return 0;
+}
+
+static int mcu_pmic_write(int reg_num, const unsigned int reg_val)
+{
+ int ret;
+ u8 value = reg_val;
+ /* mcu ops */
+ if (reg_num >= REG_MCU_VERSION && reg_num <= REG_MCU_DES_FLAG) {
+
+ ret =
+ mc9s08dz60_write_reg(
+ mcu_pmic_reg_addr_table[reg_num], value);
+ if (ret < 0)
+ return -1;
+ } else if (reg_num >= REG_MAX8660_OUTPUT_ENABLE_1
+ && reg_num <= REG_MAX8660_FORCE_PWM) {
+ ret =
+ max8660_write_reg(mcu_pmic_reg_addr_table[reg_num], value);
+
+ if (ret < 0)
+ return -1;
+
+ ret = max8660_save_buffered_reg_val(reg_num, value);
+ } else
+ return -1;
+
+ return 0;
+}
+
+int mcu_pmic_read_reg(int reg, unsigned int *reg_value,
+ unsigned int reg_mask)
+{
+ int ret = 0;
+ unsigned int temp = 0;
+
+ ret = mcu_pmic_read(reg, &temp);
+ if (ret != 0)
+ return -1;
+ *reg_value = (temp & reg_mask);
+
+ pr_debug("Read REG[ %d ] = 0x%x\n", reg, *reg_value);
+
+ return ret;
+}
+
+
+int mcu_pmic_write_reg(int reg, unsigned int reg_value,
+ unsigned int reg_mask)
+{
+ int ret = 0;
+ unsigned int temp = 0;
+
+ ret = mcu_pmic_read(reg, &temp);
+ if (ret != 0)
+ return -1;
+ temp = (temp & (~reg_mask)) | reg_value;
+
+ ret = mcu_pmic_write(reg, temp);
+ if (ret != 0)
+ return -1;
+
+ pr_debug("Write REG[ %d ] = 0x%x\n", reg, reg_value);
+
+ return ret;
+}
+
+/*!
+ * make max8660 - mc9s08dz60 enter low-power mode
+ */
+static void pmic_power_off(void)
+{
+ mcu_pmic_write_reg(REG_MCU_POWER_CTL, 0x10, 0x10);
+}
+
+static int __init mcu_pmic_init(void)
+{
+ int err;
+
+ /* init chips */
+ err = max8660_init();
+ if (err)
+ goto fail1;
+
+ err = mc9s08dz60_init();
+ if (err)
+ goto fail1;
+
+ if (is_max8660_present()) {
+ pr_info("max8660 is present \n");
+ pm_power_off = pmic_power_off;
+ } else
+ pr_debug("max8660 is not present\n");
+ pr_info("mcu_pmic_init completed!\n");
+ return 0;
+
+fail1:
+ pr_err("mcu_pmic_init failed!\n");
+ return err;
+}
+
+static void __exit mcu_pmic_exit(void)
+{
+ reg_max8660_remove();
+ mc9s08dz60_exit();
+ max8660_exit();
+}
+
+subsys_initcall_sync(mcu_pmic_init);
+module_exit(mcu_pmic_exit);
+
+MODULE_AUTHOR("Freescale Semiconductor, Inc.");
+MODULE_DESCRIPTION("mcu pmic driver");
+MODULE_LICENSE("GPL");
diff --git a/drivers/mxc/mcu_pmic/mcu_pmic_core.h b/drivers/mxc/mcu_pmic/mcu_pmic_core.h
new file mode 100644
index 000000000000..969e84ff5df3
--- /dev/null
+++ b/drivers/mxc/mcu_pmic/mcu_pmic_core.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2009-2010 Freescale Semiconductor, Inc. All Rights Reserved.
+ */
+
+/*
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+/*!
+ * @file mcu_pmic_core.h
+ * @brief Driver for max8660
+ *
+ * @ingroup pmic
+ */
+#ifndef _MCU_PMIC_CORE_H_
+#define _MCU_PMIC_CORE_H_
+
+#include <linux/mfd/mc9s08dz60/pmic.h>
+
+#define MAX8660_REG_START (REG_MCU_DES_FLAG + 1)
+enum {
+
+ /* reg names for max8660 */
+ REG_MAX8660_OUTPUT_ENABLE_1 = MAX8660_REG_START,
+ REG_MAX8660_OUTPUT_ENABLE_2,
+ REG_MAX8660_VOLT_CHANGE_CONTROL_1,
+ REG_MAX8660_V3_TARGET_VOLT_1,
+ REG_MAX8660_V3_TARGET_VOLT_2,
+ REG_MAX8660_V4_TARGET_VOLT_1,
+ REG_MAX8660_V4_TARGET_VOLT_2,
+ REG_MAX8660_V5_TARGET_VOLT_1,
+ REG_MAX8660_V5_TARGET_VOLT_2,
+ REG_MAX8660_V6V7_TARGET_VOLT,
+ REG_MAX8660_FORCE_PWM
+};
+
+
+#endif /* _MCU_PMIC_CORE_H_ */
diff --git a/drivers/mxc/mcu_pmic/mcu_pmic_gpio.c b/drivers/mxc/mcu_pmic/mcu_pmic_gpio.c
new file mode 100644
index 000000000000..417dabe35386
--- /dev/null
+++ b/drivers/mxc/mcu_pmic/mcu_pmic_gpio.c
@@ -0,0 +1,131 @@
+/*
+ * Copyright 2008-2010 Freescale Semiconductor, Inc. All Rights Reserved.
+ */
+
+/*
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+/*!
+ * @file mc9s08dz60/mcu_pmic_gpio.c
+ * @brief This is the main file of mc9s08dz60 Power Control driver.
+ *
+ * @ingroup PMIC_POWER
+ */
+
+/*
+ * Includes
+ */
+#include <linux/platform_device.h>
+#include <linux/mfd/mc9s08dz60/pmic.h>
+#include <linux/pmic_status.h>
+#include <linux/ioctl.h>
+
+#define SET_BIT_IN_BYTE(byte, pos) (byte |= (0x01 << pos))
+#define CLEAR_BIT_IN_BYTE(byte, pos) (byte &= ~(0x01 << pos))
+
+int pmic_gpio_set_bit_val(int reg, unsigned int bit,
+ unsigned int val)
+{
+ int reg_name;
+ u8 reg_mask = 0;
+
+ if (bit > 7)
+ return -1;
+
+ switch (reg) {
+ case MCU_GPIO_REG_RESET_1:
+ reg_name = REG_MCU_RESET_1;
+ break;
+ case MCU_GPIO_REG_RESET_2:
+ reg_name = REG_MCU_RESET_2;
+ break;
+ case MCU_GPIO_REG_POWER_CONTROL:
+ reg_name = REG_MCU_POWER_CTL;
+ break;
+ case MCU_GPIO_REG_GPIO_CONTROL_1:
+ reg_name = REG_MCU_GPIO_1;
+ break;
+ case MCU_GPIO_REG_GPIO_CONTROL_2:
+ reg_name = REG_MCU_GPIO_2;
+ break;
+ default:
+ return -1;
+ }
+
+ SET_BIT_IN_BYTE(reg_mask, bit);
+ if (0 == val)
+ CHECK_ERROR(mcu_pmic_write_reg(reg_name, 0, reg_mask));
+ else
+ CHECK_ERROR(mcu_pmic_write_reg(reg_name, reg_mask, reg_mask));
+
+ return 0;
+}
+EXPORT_SYMBOL(pmic_gpio_set_bit_val);
+
+int pmic_gpio_get_bit_val(int reg, unsigned int bit,
+ unsigned int *val)
+{
+ int reg_name;
+ unsigned int reg_read_val;
+ u8 reg_mask = 0;
+
+ if (bit > 7)
+ return -1;
+
+ switch (reg) {
+ case MCU_GPIO_REG_RESET_1:
+ reg_name = REG_MCU_RESET_1;
+ break;
+ case MCU_GPIO_REG_RESET_2:
+ reg_name = REG_MCU_RESET_2;
+ break;
+ case MCU_GPIO_REG_POWER_CONTROL:
+ reg_name = REG_MCU_POWER_CTL;
+ break;
+ case MCU_GPIO_REG_GPIO_CONTROL_1:
+ reg_name = REG_MCU_GPIO_1;
+ break;
+ case MCU_GPIO_REG_GPIO_CONTROL_2:
+ reg_name = REG_MCU_GPIO_2;
+ break;
+ default:
+ return -1;
+ }
+
+ SET_BIT_IN_BYTE(reg_mask, bit);
+ CHECK_ERROR(mcu_pmic_read_reg(reg_name, &reg_read_val, reg_mask));
+ if (0 == reg_read_val)
+ *val = 0;
+ else
+ *val = 1;
+
+ return 0;
+}
+EXPORT_SYMBOL(pmic_gpio_get_bit_val);
+
+int pmic_gpio_get_designation_bit_val(unsigned int bit,
+ unsigned int *val)
+{
+ unsigned int reg_read_val;
+ u8 reg_mask = 0;
+
+ if (bit > 7)
+ return -1;
+
+ SET_BIT_IN_BYTE(reg_mask, bit);
+ CHECK_ERROR(
+ mcu_pmic_read_reg(REG_MCU_DES_FLAG, &reg_read_val, reg_mask));
+ if (0 == reg_read_val)
+ *val = 0;
+ else
+ *val = 1;
+
+ return 0;
+}
+EXPORT_SYMBOL(pmic_gpio_get_designation_bit_val);