2 * driver/mfd/ricoh619.c
4 * Core driver implementation to access RICOH RC5T619 power management chip.
6 * Copyright (C) 2012-2013 RICOH COMPANY,LTD
9 * Copyright (C) 2011 NVIDIA Corporation
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 /*#define VERBOSE_DEBUG 1*/
27 #include <linux/interrupt.h>
28 #include <linux/irq.h>
29 #include <linux/kernel.h>
30 #include <linux/module.h>
31 #include <linux/init.h>
32 #include <linux/slab.h>
33 #include <linux/gpio.h>
34 #include <linux/i2c.h>
35 #include <linux/mfd/core.h>
36 #include <linux/mfd/ricoh619.h>
37 #include <linux/power/ricoh619_battery.h>
38 #include <linux/of_irq.h>
39 #include <linux/of_gpio.h>
41 #include <linux/of_device.h>
42 #include <linux/regulator/of_regulator.h>
43 #include <linux/regulator/driver.h>
44 #include <linux/regulator/machine.h>
45 #include <linux/regmap.h>
48 struct ricoh619 *g_ricoh619;
49 struct sleep_control_data {
52 static struct mfd_cell ricoh619s[] = {
54 .name = "ricoh619-regulator",
57 .name = "ricoh619-battery",
60 .name = "ricoh619-rtc",
63 .name = "ricoh619-pwrkey",
68 #define SLEEP_INIT(_id, _reg) \
69 [RICOH619_DS_##_id] = {.reg_add = _reg}
71 static struct sleep_control_data sleep_data[] = {
72 SLEEP_INIT(DC1, 0x16),
73 SLEEP_INIT(DC2, 0x17),
74 SLEEP_INIT(DC3, 0x18),
75 SLEEP_INIT(DC4, 0x19),
76 SLEEP_INIT(DC5, 0x1A),
77 SLEEP_INIT(LDO1, 0x1B),
78 SLEEP_INIT(LDO2, 0x1C),
79 SLEEP_INIT(LDO3, 0x1D),
80 SLEEP_INIT(LDO4, 0x1E),
81 SLEEP_INIT(LDO5, 0x1F),
82 SLEEP_INIT(LDO6, 0x20),
83 SLEEP_INIT(LDO7, 0x21),
84 SLEEP_INIT(LDO8, 0x22),
85 SLEEP_INIT(LDO9, 0x23),
86 SLEEP_INIT(LDO10, 0x24),
87 SLEEP_INIT(PSO0, 0x25),
88 SLEEP_INIT(PSO1, 0x26),
89 SLEEP_INIT(PSO2, 0x27),
90 SLEEP_INIT(PSO3, 0x28),
91 SLEEP_INIT(PSO4, 0x29),
92 SLEEP_INIT(LDORTC1, 0x2A),
94 static inline int __ricoh619_read(struct i2c_client *client,
98 ret = i2c_smbus_read_byte_data(client, reg);
100 dev_err(&client->dev, "failed reading at 0x%02x\n", reg);
105 dev_dbg(&client->dev, "ricoh619: reg read reg=%x, val=%x\n",
110 static inline int __ricoh619_bulk_reads(struct i2c_client *client, u8 reg,
111 int len, uint8_t *val)
116 ret = i2c_smbus_read_i2c_block_data(client, reg, len, val);
118 dev_err(&client->dev, "failed reading from 0x%02x\n", reg);
121 for (i = 0; i < len; ++i) {
122 dev_dbg(&client->dev, "ricoh619: reg read reg=%x, val=%x\n",
123 reg + i, *(val + i));
128 static inline int __ricoh619_write(struct i2c_client *client,
133 dev_dbg(&client->dev, "ricoh619: reg write reg=%x, val=%x\n",
135 ret = i2c_smbus_write_byte_data(client, reg, val);
137 dev_err(&client->dev, "failed writing 0x%02x to 0x%02x\n",
144 static inline int __ricoh619_bulk_writes(struct i2c_client *client, u8 reg,
145 int len, uint8_t *val)
150 for (i = 0; i < len; ++i) {
151 dev_dbg(&client->dev, "ricoh619: reg write reg=%x, val=%x\n",
152 reg + i, *(val + i));
155 ret = i2c_smbus_write_i2c_block_data(client, reg, len, val);
157 dev_err(&client->dev, "failed writings to 0x%02x\n", reg);
163 static inline int set_bank_ricoh619(struct device *dev, int bank)
165 struct ricoh619 *ricoh619 = dev_get_drvdata(dev);
168 if (bank != (bank & 1))
170 if (bank == ricoh619->bank_num)
172 ret = __ricoh619_write(to_i2c_client(dev), RICOH619_REG_BANKSEL, bank);
174 ricoh619->bank_num = bank;
179 int ricoh619_write(struct device *dev, u8 reg, uint8_t val)
181 struct ricoh619 *ricoh619 = dev_get_drvdata(dev);
184 // mutex_lock(&ricoh619->io_lock);
185 ret = set_bank_ricoh619(dev, 0);
187 ret = __ricoh619_write(to_i2c_client(dev), reg, val);
188 // mutex_unlock(&ricoh619->io_lock);
192 EXPORT_SYMBOL_GPL(ricoh619_write);
194 int ricoh619_write_bank1(struct device *dev, u8 reg, uint8_t val)
196 struct ricoh619 *ricoh619 = dev_get_drvdata(dev);
199 mutex_lock(&ricoh619->io_lock);
200 ret = set_bank_ricoh619(dev, 1);
202 ret = __ricoh619_write(to_i2c_client(dev), reg, val);
203 mutex_unlock(&ricoh619->io_lock);
207 EXPORT_SYMBOL_GPL(ricoh619_write_bank1);
209 int ricoh619_bulk_writes(struct device *dev, u8 reg, u8 len, uint8_t *val)
211 struct ricoh619 *ricoh619 = dev_get_drvdata(dev);
214 mutex_lock(&ricoh619->io_lock);
215 ret = set_bank_ricoh619(dev, 0);
217 ret = __ricoh619_bulk_writes(to_i2c_client(dev), reg, len, val);
218 mutex_unlock(&ricoh619->io_lock);
222 EXPORT_SYMBOL_GPL(ricoh619_bulk_writes);
224 int ricoh619_bulk_writes_bank1(struct device *dev, u8 reg, u8 len, uint8_t *val)
226 struct ricoh619 *ricoh619 = dev_get_drvdata(dev);
229 mutex_lock(&ricoh619->io_lock);
230 ret = set_bank_ricoh619(dev, 1);
232 ret = __ricoh619_bulk_writes(to_i2c_client(dev), reg, len, val);
233 mutex_unlock(&ricoh619->io_lock);
237 EXPORT_SYMBOL_GPL(ricoh619_bulk_writes_bank1);
239 int ricoh619_read(struct device *dev, u8 reg, uint8_t *val)
241 struct ricoh619 *ricoh619 = dev_get_drvdata(dev);
244 mutex_lock(&ricoh619->io_lock);
245 ret = set_bank_ricoh619(dev, 0);
247 ret = __ricoh619_read(to_i2c_client(dev), reg, val);
248 mutex_unlock(&ricoh619->io_lock);
252 EXPORT_SYMBOL_GPL(ricoh619_read);
254 int ricoh619_read_bank1(struct device *dev, u8 reg, uint8_t *val)
256 struct ricoh619 *ricoh619 = dev_get_drvdata(dev);
259 mutex_lock(&ricoh619->io_lock);
260 ret = set_bank_ricoh619(dev, 1);
262 ret = __ricoh619_read(to_i2c_client(dev), reg, val);
263 mutex_unlock(&ricoh619->io_lock);
268 EXPORT_SYMBOL_GPL(ricoh619_read_bank1);
270 int ricoh619_bulk_reads(struct device *dev, u8 reg, u8 len, uint8_t *val)
272 struct ricoh619 *ricoh619 = dev_get_drvdata(dev);
275 mutex_lock(&ricoh619->io_lock);
276 ret = set_bank_ricoh619(dev, 0);
278 ret = __ricoh619_bulk_reads(to_i2c_client(dev), reg, len, val);
279 mutex_unlock(&ricoh619->io_lock);
283 EXPORT_SYMBOL_GPL(ricoh619_bulk_reads);
285 int ricoh619_bulk_reads_bank1(struct device *dev, u8 reg, u8 len, uint8_t *val)
287 struct ricoh619 *ricoh619 = dev_get_drvdata(dev);
290 mutex_lock(&ricoh619->io_lock);
291 ret = set_bank_ricoh619(dev, 1);
293 ret = __ricoh619_bulk_reads(to_i2c_client(dev), reg, len, val);
294 mutex_unlock(&ricoh619->io_lock);
298 EXPORT_SYMBOL_GPL(ricoh619_bulk_reads_bank1);
300 int ricoh619_set_bits(struct device *dev, u8 reg, uint8_t bit_mask)
302 struct ricoh619 *ricoh619 = dev_get_drvdata(dev);
306 mutex_lock(&ricoh619->io_lock);
307 ret = set_bank_ricoh619(dev, 0);
309 ret = __ricoh619_read(to_i2c_client(dev), reg, ®_val);
313 if ((reg_val & bit_mask) != bit_mask) {
315 ret = __ricoh619_write(to_i2c_client(dev), reg,
320 mutex_unlock(&ricoh619->io_lock);
323 EXPORT_SYMBOL_GPL(ricoh619_set_bits);
325 int ricoh619_clr_bits(struct device *dev, u8 reg, uint8_t bit_mask)
327 struct ricoh619 *ricoh619 = dev_get_drvdata(dev);
331 mutex_lock(&ricoh619->io_lock);
332 ret = set_bank_ricoh619(dev, 0);
334 ret = __ricoh619_read(to_i2c_client(dev), reg, ®_val);
338 if (reg_val & bit_mask) {
339 reg_val &= ~bit_mask;
340 ret = __ricoh619_write(to_i2c_client(dev), reg,
345 mutex_unlock(&ricoh619->io_lock);
348 EXPORT_SYMBOL_GPL(ricoh619_clr_bits);
350 int ricoh619_update(struct device *dev, u8 reg, uint8_t val, uint8_t mask)
352 struct ricoh619 *ricoh619 = dev_get_drvdata(dev);
356 mutex_lock(&ricoh619->io_lock);
357 ret = set_bank_ricoh619(dev, 0);
359 ret = __ricoh619_read(ricoh619->client, reg, ®_val);
363 if ((reg_val & mask) != val) {
364 reg_val = (reg_val & ~mask) | (val & mask);
365 ret = __ricoh619_write(ricoh619->client, reg, reg_val);
369 mutex_unlock(&ricoh619->io_lock);
372 EXPORT_SYMBOL_GPL(ricoh619_update);
374 int ricoh619_update_bank1(struct device *dev, u8 reg, uint8_t val, uint8_t mask)
376 struct ricoh619 *ricoh619 = dev_get_drvdata(dev);
380 mutex_lock(&ricoh619->io_lock);
381 ret = set_bank_ricoh619(dev, 1);
383 ret = __ricoh619_read(ricoh619->client, reg, ®_val);
387 if ((reg_val & mask) != val) {
388 reg_val = (reg_val & ~mask) | (val & mask);
389 ret = __ricoh619_write(ricoh619->client, reg, reg_val);
393 mutex_unlock(&ricoh619->io_lock);
397 static struct i2c_client *ricoh619_i2c_client;
398 static int ricoh619_power_off(void)
403 int status, charge_state;
404 struct ricoh619 *ricoh619 = g_ricoh619;
405 #ifdef CONFIG_BATTERY_RICOH619
408 ricoh619_read(ricoh619->dev, 0xBD, &status);
409 charge_state = (status & 0x1F);
410 // supply_state = ((status & 0xC0) >> 6);
412 ret = ricoh619_write(ricoh619->dev, RICOH619_PSWR, val);
414 dev_err(ricoh619->dev, "Error in writing PSWR_REG\n");
416 if (g_fg_on_mode == 0) {
417 ret = ricoh619_clr_bits(ricoh619->dev,
418 RICOH619_FG_CTRL, 0x01);
420 dev_err(ricoh619->dev, "Error in writing FG_CTRL\n");
423 /* set rapid timer 300 min */
424 err = ricoh619_set_bits(ricoh619->dev, TIMSET_REG, 0x03);
426 dev_err(ricoh619->dev, "Error in writing the TIMSET_Reg\n");
428 ret = ricoh619_clr_bits(ricoh619->dev, 0xae, (0x1 <<6)); //disable alam_d
429 ret = ricoh619_write(ricoh619->dev, RICOH619_INTC_INTEN, 0);
430 ret = ricoh619_clr_bits(ricoh619->dev,RICOH619_PWR_REP_CNT,(0x1<<0));//Not repeat power ON after power off(Power Off/N_OE)
432 if(( charge_state == CHG_STATE_CHG_TRICKLE)||( charge_state == CHG_STATE_CHG_RAPID))
433 ricoh619_set_bits(ricoh619->dev, RICOH619_PWR_REP_CNT,(0x1<<0));//Power OFF
434 ret = ricoh619_set_bits(ricoh619->dev, RICOH619_PWR_SLP_CNT,(0x1<<0));//Power OFF
436 printk("ricoh619 power off error!\n");
441 EXPORT_SYMBOL_GPL(ricoh619_power_off);
443 static int ricoh619_gpio_get(struct gpio_chip *gc, unsigned offset)
445 struct ricoh619 *ricoh619 = container_of(gc, struct ricoh619, gpio_chip);
449 ret = ricoh619_read(ricoh619->dev, RICOH619_GPIO_MON_IOIN, &val);
453 return ((val & (0x1 << offset)) != 0);
456 static void ricoh619_gpio_set(struct gpio_chip *gc, unsigned offset,
459 struct ricoh619 *ricoh619 = container_of(gc, struct ricoh619, gpio_chip);
461 ricoh619_set_bits(ricoh619->dev, RICOH619_GPIO_IOOUT,
464 ricoh619_clr_bits(ricoh619->dev, RICOH619_GPIO_IOOUT,
468 static int ricoh619_gpio_input(struct gpio_chip *gc, unsigned offset)
470 struct ricoh619 *ricoh619 = container_of(gc, struct ricoh619, gpio_chip);
472 return ricoh619_clr_bits(ricoh619->dev, RICOH619_GPIO_IOSEL,
476 static int ricoh619_gpio_output(struct gpio_chip *gc, unsigned offset,
479 struct ricoh619 *ricoh619 = container_of(gc, struct ricoh619, gpio_chip);
481 ricoh619_gpio_set(gc, offset, value);
482 return ricoh619_set_bits(ricoh619->dev, RICOH619_GPIO_IOSEL,
486 static int ricoh619_gpio_to_irq(struct gpio_chip *gc, unsigned off)
488 struct ricoh619 *ricoh619 = container_of(gc, struct ricoh619, gpio_chip);
490 if ((off >= 0) && (off < 8))
491 return ricoh619->irq_base + RICOH619_IRQ_GPIO0 + off;
497 static void ricoh619_gpio_init(struct ricoh619 *ricoh619,
498 struct ricoh619_platform_data *pdata)
502 struct ricoh619_gpio_init_data *ginit;
504 if (pdata->gpio_base <= 0)
507 for (i = 0; i < pdata->num_gpioinit_data; ++i) {
508 ginit = &pdata->gpio_init_data[i];
510 if (!ginit->init_apply)
513 if (ginit->output_mode_en) {
514 /* GPIO output mode */
515 if (ginit->output_val)
517 ret = ricoh619_set_bits(ricoh619->dev,
518 RICOH619_GPIO_IOOUT, 1 << i);
521 ret = ricoh619_clr_bits(ricoh619->dev,
522 RICOH619_GPIO_IOOUT, 1 << i);
524 ret = ricoh619_set_bits(ricoh619->dev,
525 RICOH619_GPIO_IOSEL, 1 << i);
527 /* GPIO input mode */
528 ret = ricoh619_clr_bits(ricoh619->dev,
529 RICOH619_GPIO_IOSEL, 1 << i);
531 /* if LED function enabled in OTP */
532 if (ginit->led_mode) {
534 if (i == 0) /* GP0 */
535 ret = ricoh619_set_bits(ricoh619->dev,
536 RICOH619_GPIO_LED_FUNC,
537 0x04 | (ginit->led_func & 0x03));
538 if (i == 1) /* GP1 */
539 ret = ricoh619_set_bits(ricoh619->dev,
540 RICOH619_GPIO_LED_FUNC,
541 0x40 | (ginit->led_func & 0x03) << 4);
547 dev_err(ricoh619->dev, "Gpio %d init "
548 "dir configuration failed: %d\n", i, ret);
552 ricoh619->gpio_chip.owner = THIS_MODULE;
553 ricoh619->gpio_chip.label = ricoh619->client->name;
554 ricoh619->gpio_chip.dev = ricoh619->dev;
555 ricoh619->gpio_chip.base = pdata->gpio_base;
556 ricoh619->gpio_chip.ngpio = RICOH619_NR_GPIO;
557 ricoh619->gpio_chip.can_sleep = 1;
559 ricoh619->gpio_chip.direction_input = ricoh619_gpio_input;
560 ricoh619->gpio_chip.direction_output = ricoh619_gpio_output;
561 ricoh619->gpio_chip.set = ricoh619_gpio_set;
562 ricoh619->gpio_chip.get = ricoh619_gpio_get;
563 ricoh619->gpio_chip.to_irq = ricoh619_gpio_to_irq;
565 ret = gpiochip_add(&ricoh619->gpio_chip);
567 dev_warn(ricoh619->dev, "GPIO registration failed: %d\n", ret);
570 static int ricoh619_remove_subdev(struct device *dev, void *unused)
572 platform_device_unregister(to_platform_device(dev));
576 static int ricoh619_remove_subdevs(struct ricoh619 *ricoh619)
578 return device_for_each_child(ricoh619->dev, NULL,
579 ricoh619_remove_subdev);
582 static int ricoh619_add_subdevs(struct ricoh619 *ricoh619,
583 struct ricoh619_platform_data *pdata)
585 struct ricoh619_subdev_info *subdev;
586 struct platform_device *pdev;
589 for (i = 0; i < pdata->num_subdevs; i++) {
590 subdev = &pdata->subdevs[i];
592 pdev = platform_device_alloc(subdev->name, subdev->id);
594 pdev->dev.parent = ricoh619->dev;
595 pdev->dev.platform_data = subdev->platform_data;
597 ret = platform_device_add(pdev);
604 ricoh619_remove_subdevs(ricoh619);
608 #ifdef CONFIG_DEBUG_FS
609 #include <linux/debugfs.h>
610 #include <linux/seq_file.h>
611 static void print_regs(const char *header, struct seq_file *s,
612 struct i2c_client *client, int start_offset,
619 seq_printf(s, "%s\n", header);
620 for (i = start_offset; i <= end_offset; ++i) {
621 ret = __ricoh619_read(client, i, ®_val);
623 seq_printf(s, "Reg 0x%02x Value 0x%02x\n", i, reg_val);
625 seq_printf(s, "------------------\n");
628 static int dbg_ricoh_show(struct seq_file *s, void *unused)
630 struct ricoh619 *ricoh = s->private;
631 struct i2c_client *client = ricoh->client;
633 seq_printf(s, "RICOH619 Registers\n");
634 seq_printf(s, "------------------\n");
636 print_regs("System Regs", s, client, 0x0, 0x05);
637 print_regs("Power Control Regs", s, client, 0x07, 0x2B);
638 print_regs("DCDC Regs", s, client, 0x2C, 0x43);
639 print_regs("LDO Regs", s, client, 0x44, 0x61);
640 print_regs("ADC Regs", s, client, 0x64, 0x8F);
641 print_regs("GPIO Regs", s, client, 0x90, 0x98);
642 print_regs("INTC Regs", s, client, 0x9C, 0x9E);
643 print_regs("RTC Regs", s, client, 0xA0, 0xAF);
644 print_regs("OPT Regs", s, client, 0xB0, 0xB1);
645 print_regs("CHG Regs", s, client, 0xB2, 0xDF);
646 print_regs("FUEL Regs", s, client, 0xE0, 0xFC);
650 static int dbg_ricoh_open(struct inode *inode, struct file *file)
652 return single_open(file, dbg_ricoh_show, inode->i_private);
655 static const struct file_operations debug_fops = {
656 .open = dbg_ricoh_open,
659 .release = single_release,
661 static void __init ricoh619_debuginit(struct ricoh619 *ricoh)
663 (void)debugfs_create_file("ricoh619", S_IRUGO, NULL,
667 static void print_regs(const char *header, struct i2c_client *client,
668 int start_offset, int end_offset)
674 printk(KERN_INFO "%s\n", header);
675 for (i = start_offset; i <= end_offset; ++i) {
676 ret = __ricoh619_read(client, i, ®_val);
678 printk(KERN_INFO "Reg 0x%02x Value 0x%02x\n",
681 printk(KERN_INFO "------------------\n");
683 static void __init ricoh619_debuginit(struct ricoh619 *ricoh)
685 struct i2c_client *client = ricoh->client;
687 printk(KERN_INFO "RICOH619 Registers\n");
688 printk(KERN_INFO "------------------\n");
690 print_regs("System Regs", client, 0x0, 0x05);
691 print_regs("Power Control Regs", client, 0x07, 0x2B);
692 print_regs("DCDC Regs", client, 0x2C, 0x43);
693 print_regs("LDO Regs", client, 0x44, 0x5C);
694 print_regs("ADC Regs", client, 0x64, 0x8F);
695 print_regs("GPIO Regs", client, 0x90, 0x9B);
696 print_regs("INTC Regs", client, 0x9C, 0x9E);
697 print_regs("OPT Regs", client, 0xB0, 0xB1);
698 print_regs("CHG Regs", client, 0xB2, 0xDF);
699 print_regs("FUEL Regs", client, 0xE0, 0xFC);
706 static struct ricoh619_platform_data *ricoh619_parse_dt(struct ricoh619 *ricoh619)
708 struct ricoh619_platform_data *pdata;
709 struct device_node *regs,*ricoh619_pmic_np;
712 ricoh619_pmic_np = of_node_get(ricoh619->dev->of_node);
713 if (!ricoh619_pmic_np) {
714 printk("could not find pmic sub-node\n");
717 pdata = devm_kzalloc(ricoh619->dev, sizeof(*pdata), GFP_KERNEL);
721 pdata->irq_gpio = of_get_named_gpio(ricoh619_pmic_np,"gpios",0);
722 if (!gpio_is_valid(pdata->irq_gpio)) {
723 printk("invalid gpio: %d\n", pdata->irq_gpio);
727 pdata->pmic_sleep_gpio = of_get_named_gpio(ricoh619_pmic_np,"gpios",1);
728 if (!gpio_is_valid(pdata->pmic_sleep_gpio)) {
729 printk("invalid gpio: %d\n", pdata->pmic_sleep_gpio);
732 pdata->dc_det = of_get_named_gpio(ricoh619_pmic_np,"gpios",2);
733 if (!gpio_is_valid(pdata->dc_det)) {
734 printk("invalid gpio: %d\n", pdata->dc_det);
736 pdata->pmic_sleep = true;
738 pdata->pm_off = of_property_read_bool(ricoh619_pmic_np,"ricoh619,system-power-controller");
744 static struct ricoh619_platform_data *ricoh619_parse_dt(struct ricoh619 *ricoh619)
750 static void ricoh619_noe_init(struct ricoh619 *ricoh)
754 /***************set noe time 128ms**************/
755 ret = ricoh619_set_bits(ricoh->dev,0x11,(0x1 <<3));
756 ret = ricoh619_clr_bits(ricoh->dev,0x11,(0x7 <<0));
757 ret = ricoh619_clr_bits(ricoh->dev,0x11,(0x1 <<3));//N_OE timer setting to 128mS
758 /**********************************************/
759 ret = ricoh619_clr_bits(ricoh->dev,RICOH619_PWR_REP_CNT,(1 << 0)); //Repeat power ON after reset (Power Off/N_OE) :1:reset 0:power off
762 static int ricoh619_pre_init(struct ricoh619 *ricoh619)
766 printk("%s,line=%d\n", __func__,__LINE__);
768 ret = ricoh619_read(ricoh619->dev,0x09,&val);
769 printk("%s,line=%d ricoh619 power on his %08x\n", __func__,__LINE__,val);
770 ret = ricoh619_read(ricoh619->dev,0x0a,&val);
771 printk("%s,line=%d ricoh619 power off his %08x\n", __func__,__LINE__,val);
773 ricoh619_set_bits(ricoh619->dev, 0xae, (0x1 <<6));//enable alam_d
775 ricoh619_noe_init(ricoh619);
776 /***************set PKEY long press time 0sec*******/
777 ret = ricoh619_set_bits(ricoh619->dev,0x10,(0x1 <<7));
778 ret = ricoh619_clr_bits(ricoh619->dev,0x10,(0x1 <<3));
779 ret = ricoh619_clr_bits(ricoh619->dev,0x10,(0x1 <<7));
780 /**********************************************/
781 ret = ricoh619_set_bits(ricoh619->dev,BATSET2_REG,(3 << 0));
782 ret = ricoh619_clr_bits(ricoh619->dev,BATSET2_REG,(1 << 2)); //set vrchg 4v
786 static int ricoh619_i2c_probe(struct i2c_client *client,
787 const struct i2c_device_id *id)
789 struct ricoh619 *ricoh619;
790 struct ricoh619_platform_data *pdata;
793 printk("%s,line=%d\n", __func__,__LINE__);
795 ricoh619 = devm_kzalloc(&client->dev,sizeof(struct ricoh619), GFP_KERNEL);
796 if (ricoh619 == NULL)
799 ricoh619->client = client;
800 ricoh619->dev = &client->dev;
801 i2c_set_clientdata(client, ricoh619);
802 mutex_init(&ricoh619->io_lock);
804 ret = ricoh619_read(ricoh619->dev, 0x36, &control);
805 if ((ret <0) || (control < 0) || (control == 0xff) || (control == 0) ){
806 printk(KERN_INFO "The device is not ricoh619 %08x %d\n",control,ret);
810 ret = ricoh619_pre_init(ricoh619);
812 printk("The ricoh619_pre_init failed %d\n",ret);
816 ricoh619->bank_num = 0;
818 if (ricoh619->dev->of_node)
819 pdata = ricoh619_parse_dt(ricoh619);
821 if (gpio_is_valid(pdata->dc_det))
822 ricoh619->dc_det = pdata->dc_det;
824 /******************************set sleep vol & dcdc mode******************/
826 if (pdata->pmic_sleep_gpio) {
827 ret = gpio_request(pdata->pmic_sleep_gpio, "ricoh619_pmic_sleep");
829 dev_err(ricoh619->dev,"Failed to request gpio %d with ret:""%d\n", pdata->pmic_sleep_gpio, ret);
832 gpio_direction_output(pdata->pmic_sleep_gpio,0);
833 ret = gpio_get_value(pdata->pmic_sleep_gpio);
834 gpio_free(pdata->pmic_sleep_gpio);
835 pr_info("%s: ricoh619_pmic_sleep=%x\n", __func__, ret);
838 /**********************************************************/
839 ret = ricoh619_irq_init(ricoh619, pdata->irq_gpio, pdata);
843 ret = mfd_add_devices(ricoh619->dev, -1,
844 ricoh619s, ARRAY_SIZE(ricoh619s),
846 g_ricoh619 = ricoh619;
847 if (pdata->pm_off && !pm_power_off) {
848 pm_power_off = ricoh619_power_off;
850 ricoh619_debuginit(ricoh619);
852 ricoh619_i2c_client = client;
855 mfd_remove_devices(ricoh619->dev);
859 static int ricoh619_i2c_remove(struct i2c_client *client)
861 struct ricoh619 *ricoh619 = i2c_get_clientdata(client);
862 ricoh619_remove_subdevs(ricoh619);
867 static int ricoh619_i2c_suspend(struct i2c_client *client, pm_message_t state)
869 // if (g_ricoh619->chip_irq)
870 // disable_irq(g_ricoh619->chip_irq);
871 // printk("PMU: %s: \n",__func__);
876 static int ricoh619_i2c_resume(struct i2c_client *client)
880 ret = __ricoh619_read(client, RICOH619_INT_IR_SYS, ®_val);
881 if(reg_val & 0x01) { //If PWR_KEY wakeup
882 // printk("PMU: %s: PWR_KEY Wakeup\n",__func__);
884 __ricoh619_write(client, RICOH619_INT_IR_SYS, 0x0); //Clear PWR_KEY IRQ
886 // enable_irq(g_ricoh619->chip_irq);
892 static const struct i2c_device_id ricoh619_i2c_id[] = {
896 MODULE_DEVICE_TABLE(i2c, ricoh619_i2c_id);
899 static const struct of_device_id ricoh619_dt_match[] = {
900 { .compatible = "ricoh,ricoh619", },
903 MODULE_DEVICE_TABLE(of, ricoh619_dt_match);
907 static struct i2c_driver ricoh619_i2c_driver = {
910 .owner = THIS_MODULE,
911 .of_match_table = of_match_ptr(ricoh619_dt_match),
913 .probe = ricoh619_i2c_probe,
914 .remove = ricoh619_i2c_remove,
916 .suspend = ricoh619_i2c_suspend,
917 .resume = ricoh619_i2c_resume,
919 .id_table = ricoh619_i2c_id,
923 static int __init ricoh619_i2c_init(void)
926 ret = i2c_add_driver(&ricoh619_i2c_driver);
928 pr_err("Failed to register I2C driver: %d\n", ret);
933 subsys_initcall_sync(ricoh619_i2c_init);
935 static void __exit ricoh619_i2c_exit(void)
937 i2c_del_driver(&ricoh619_i2c_driver);
940 module_exit(ricoh619_i2c_exit);
942 MODULE_DESCRIPTION("RICOH RC5T619 PMU multi-function core driver");
943 MODULE_AUTHOR("zhangqing <zhangqing@rock-chips.com>");
944 MODULE_LICENSE("GPL");