UPSTREAM: spi/rockchip: Make sure spi clk is on in rockchip_spi_set_cs
[firefly-linux-kernel-4.4.55.git] / drivers / mfd / ricoh619.c
index feb23c8c96e8eb6a31d6d5832f51cd3dc0a53914..c20f1aebd21af8df3c0cd6200b2ccd0a6de97326 100755 (executable)
@@ -44,6 +44,7 @@
 #include <linux/regulator/machine.h>
 #include <linux/regmap.h>
 #include <linux/delay.h>
+#include <linux/syscore_ops.h>
 
 struct ricoh619 *g_ricoh619;
 struct sleep_control_data {
@@ -67,7 +68,7 @@ static struct mfd_cell ricoh619s[] = {
 
 #define SLEEP_INIT(_id, _reg)          \
        [RICOH619_DS_##_id] = {.reg_add = _reg}
-
+/*
 static struct sleep_control_data sleep_data[] = {
        SLEEP_INIT(DC1, 0x16),
        SLEEP_INIT(DC2, 0x17),
@@ -91,6 +92,7 @@ static struct sleep_control_data sleep_data[] = {
        SLEEP_INIT(PSO4, 0x29),
        SLEEP_INIT(LDORTC1, 0x2A),
 };
+*/
 static inline int __ricoh619_read(struct i2c_client *client,
                                  u8 reg, uint8_t *val)
 {
@@ -395,7 +397,7 @@ out:
 }
 
 static struct i2c_client *ricoh619_i2c_client;
-static int ricoh619_device_shutdown(struct i2c_client *client)
+static void ricoh619_device_shutdown(void)
 {
        int ret;
        uint8_t val;
@@ -425,11 +427,10 @@ static int ricoh619_device_shutdown(struct i2c_client *client)
        ret = ricoh619_write(ricoh619->dev, RICOH619_INTC_INTEN, 0); 
        ret = ricoh619_clr_bits(ricoh619->dev,RICOH619_PWR_REP_CNT,(0x1<<0));//Not repeat power ON after power off(Power Off/N_OE)
        mutex_lock(&ricoh619->io_lock);
-       msleep(100);
-       return 0;
+       mdelay(100);
 }
 EXPORT_SYMBOL_GPL(ricoh619_device_shutdown);
-static int ricoh619_power_off(void)
+static void ricoh619_power_off(void)
 {
        int ret,i=0;
        uint8_t val,charge_state;
@@ -464,6 +465,7 @@ static int ricoh619_power_off(void)
 }
 EXPORT_SYMBOL_GPL(ricoh619_power_off);
 
+#if 0
 static int ricoh619_gpio_get(struct gpio_chip *gc, unsigned offset)
 {
        struct ricoh619 *ricoh619 = container_of(gc, struct ricoh619, gpio_chip);
@@ -517,7 +519,6 @@ static int ricoh619_gpio_to_irq(struct gpio_chip *gc, unsigned off)
        return -EIO;
 }
 
-
 static void ricoh619_gpio_init(struct ricoh619 *ricoh619,
        struct ricoh619_platform_data *pdata)
 {
@@ -590,7 +591,7 @@ static void ricoh619_gpio_init(struct ricoh619 *ricoh619,
        if (ret)
                dev_warn(ricoh619->dev, "GPIO registration failed: %d\n", ret);
 }
-
+#endif
 static int ricoh619_remove_subdev(struct device *dev, void *unused)
 {
        platform_device_unregister(to_platform_device(dev));
@@ -602,7 +603,7 @@ static int ricoh619_remove_subdevs(struct ricoh619 *ricoh619)
        return device_for_each_child(ricoh619->dev, NULL,
                                     ricoh619_remove_subdev);
 }
-
+#if 0
 static int ricoh619_add_subdevs(struct ricoh619 *ricoh619,
                                struct ricoh619_platform_data *pdata)
 {
@@ -628,7 +629,7 @@ failed:
        ricoh619_remove_subdevs(ricoh619);
        return ret;
 }
-
+#endif
 #ifdef CONFIG_DEBUG_FS
 #include <linux/debugfs.h>
 #include <linux/seq_file.h>
@@ -730,8 +731,7 @@ static void __init ricoh619_debuginit(struct ricoh619 *ricoh)
 static struct ricoh619_platform_data *ricoh619_parse_dt(struct ricoh619 *ricoh619)
 {
        struct ricoh619_platform_data *pdata;
-       struct device_node *regs,*ricoh619_pmic_np;
-       int i, count;
+       struct device_node *ricoh619_pmic_np;
 
        ricoh619_pmic_np = of_node_get(ricoh619->dev->of_node);
        if (!ricoh619_pmic_np) {
@@ -771,6 +771,10 @@ static struct ricoh619_platform_data *ricoh619_parse_dt(struct ricoh619 *ricoh61
 }
 #endif
 
+static struct syscore_ops ricoh619_syscore_ops = {
+       .shutdown = ricoh619_device_shutdown,
+};
+
 static void ricoh619_noe_init(struct ricoh619 *ricoh)
 {
        int ret;
@@ -786,7 +790,6 @@ static void ricoh619_noe_init(struct ricoh619 *ricoh)
 static int ricoh619_pre_init(struct ricoh619 *ricoh619)
 {
        int ret=0;
-       u8 val;
         printk("%s,line=%d\n", __func__,__LINE__);
         /*
        ret = ricoh619_read(ricoh619->dev,0x09,&val);
@@ -894,6 +897,7 @@ static int ricoh619_i2c_probe(struct i2c_client *client,
        ricoh619_debuginit(ricoh619);
 
        ricoh619_i2c_client = client;
+       register_syscore_ops(&ricoh619_syscore_ops);
        return 0;
 err:
        mfd_remove_devices(ricoh619->dev);
@@ -903,6 +907,8 @@ err:
 static int ricoh619_i2c_remove(struct i2c_client *client)
 {
        struct ricoh619 *ricoh619 = i2c_get_clientdata(client);
+
+       unregister_syscore_ops(&ricoh619_syscore_ops);
        ricoh619_remove_subdevs(ricoh619);
        return 0;
 }
@@ -912,9 +918,10 @@ extern u8 ricoh619_pwr_key_reg;
 int ricoh619_pwrkey_wakeup = 0;
 static int ricoh619_i2c_suspend(struct i2c_client *client, pm_message_t state)
 {
-//     if (g_ricoh619->chip_irq)
-//             disable_irq(g_ricoh619->chip_irq);
 //     printk("PMU: %s: \n",__func__);
+
+       if (g_ricoh619->chip_irq)
+               disable_irq(g_ricoh619->chip_irq);
        ricoh619_pwrkey_wakeup = 1;
        __ricoh619_write(client, RICOH619_INT_IR_SYS, 0x0); //Clear PWR_KEY IRQ
         __ricoh619_read(client, RICOH619_INT_IR_SYS, &ricoh619_pwr_key_reg);
@@ -922,9 +929,9 @@ static int ricoh619_i2c_suspend(struct i2c_client *client, pm_message_t state)
 }
 static int ricoh619_i2c_resume(struct i2c_client *client)
 {
+       /*
        uint8_t reg_val;
        int ret;
-       /*
        ret = __ricoh619_read(client, RICOH619_INT_IR_SYS, &reg_val);
        if(ricoh619_pwr_key_reg & 0x01) { //If PWR_KEY wakeup
                //printk("PMU: %s: PWR_KEY Wakeup %08x\n",__func__,ricoh619_pwr_key_reg);
@@ -932,10 +939,33 @@ static int ricoh619_i2c_resume(struct i2c_client *client)
                __ricoh619_write(client, RICOH619_INT_IR_SYS, 0x0); //Clear PWR_KEY IRQ
        }
        */
-//     enable_irq(g_ricoh619->chip_irq);
+       
+       if (g_ricoh619->chip_irq)
+               enable_irq(g_ricoh619->chip_irq);
        return 0;
 }
 
+static int  ricoh619_i2c_late_suspend(struct device *dev)
+{
+       struct i2c_client *client = i2c_verify_client(dev);
+
+        ricoh619_i2c_suspend(client,PMSG_SUSPEND);
+       return 0;
+}
+
+static int rockchip_i2c_late_resume(struct device *dev)
+{
+       struct i2c_client *client = i2c_verify_client(dev);    
+    
+        ricoh619_i2c_resume(client);
+       return 0;
+}
+
+static const struct dev_pm_ops ricoh619_i2c_dev_pm= {
+       .suspend_late = ricoh619_i2c_late_suspend,
+       .resume_early = rockchip_i2c_late_resume,
+};
+
 #endif
 
 static const struct i2c_device_id ricoh619_i2c_id[] = {
@@ -952,20 +982,18 @@ static const struct of_device_id ricoh619_dt_match[] = {
 MODULE_DEVICE_TABLE(of, ricoh619_dt_match);
 #endif
 
-
 static struct i2c_driver ricoh619_i2c_driver = {
        .driver = {
                   .name = "ricoh619",
                   .owner = THIS_MODULE,
+                  #ifdef CONFIG_PM
+                   .pm = (&ricoh619_i2c_dev_pm),
+                  #endif                  
                   .of_match_table = of_match_ptr(ricoh619_dt_match),
                   },
        .probe = ricoh619_i2c_probe,
        .remove = ricoh619_i2c_remove,
-       .shutdown = ricoh619_device_shutdown,
-#ifdef CONFIG_PM
-       .suspend = ricoh619_i2c_suspend,
-       .resume = ricoh619_i2c_resume,
-#endif
+
        .id_table = ricoh619_i2c_id,
 };