184c99db8SAshish Jangam /* 284c99db8SAshish Jangam * Device access for Dialog DA9052 PMICs. 384c99db8SAshish Jangam * 484c99db8SAshish Jangam * Copyright(c) 2011 Dialog Semiconductor Ltd. 584c99db8SAshish Jangam * 684c99db8SAshish Jangam * Author: David Dajun Chen <dchen@diasemi.com> 784c99db8SAshish Jangam * 884c99db8SAshish Jangam * This program is free software; you can redistribute it and/or modify it 984c99db8SAshish Jangam * under the terms of the GNU General Public License as published by the 1084c99db8SAshish Jangam * Free Software Foundation; either version 2 of the License, or (at your 1184c99db8SAshish Jangam * option) any later version. 1284c99db8SAshish Jangam */ 1384c99db8SAshish Jangam 1484c99db8SAshish Jangam #include <linux/device.h> 1584c99db8SAshish Jangam #include <linux/delay.h> 1684c99db8SAshish Jangam #include <linux/input.h> 1784c99db8SAshish Jangam #include <linux/interrupt.h> 1884c99db8SAshish Jangam #include <linux/irq.h> 1984c99db8SAshish Jangam #include <linux/mutex.h> 2084c99db8SAshish Jangam #include <linux/mfd/core.h> 2184c99db8SAshish Jangam #include <linux/slab.h> 2284c99db8SAshish Jangam #include <linux/module.h> 2384c99db8SAshish Jangam 2484c99db8SAshish Jangam #include <linux/mfd/da9052/da9052.h> 2584c99db8SAshish Jangam #include <linux/mfd/da9052/pdata.h> 2684c99db8SAshish Jangam #include <linux/mfd/da9052/reg.h> 2784c99db8SAshish Jangam 2884c99db8SAshish Jangam #define DA9052_NUM_IRQ_REGS 4 2984c99db8SAshish Jangam #define DA9052_IRQ_MASK_POS_1 0x01 3084c99db8SAshish Jangam #define DA9052_IRQ_MASK_POS_2 0x02 3184c99db8SAshish Jangam #define DA9052_IRQ_MASK_POS_3 0x04 3284c99db8SAshish Jangam #define DA9052_IRQ_MASK_POS_4 0x08 3384c99db8SAshish Jangam #define DA9052_IRQ_MASK_POS_5 0x10 3484c99db8SAshish Jangam #define DA9052_IRQ_MASK_POS_6 0x20 3584c99db8SAshish Jangam #define DA9052_IRQ_MASK_POS_7 0x40 3684c99db8SAshish Jangam #define DA9052_IRQ_MASK_POS_8 0x80 3784c99db8SAshish Jangam 3884c99db8SAshish Jangam static bool da9052_reg_readable(struct device *dev, unsigned int reg) 3984c99db8SAshish Jangam { 4084c99db8SAshish Jangam switch (reg) { 4184c99db8SAshish Jangam case DA9052_PAGE0_CON_REG: 4284c99db8SAshish Jangam case DA9052_STATUS_A_REG: 4384c99db8SAshish Jangam case DA9052_STATUS_B_REG: 4484c99db8SAshish Jangam case DA9052_STATUS_C_REG: 4584c99db8SAshish Jangam case DA9052_STATUS_D_REG: 4684c99db8SAshish Jangam case DA9052_EVENT_A_REG: 4784c99db8SAshish Jangam case DA9052_EVENT_B_REG: 4884c99db8SAshish Jangam case DA9052_EVENT_C_REG: 4984c99db8SAshish Jangam case DA9052_EVENT_D_REG: 5084c99db8SAshish Jangam case DA9052_FAULTLOG_REG: 5184c99db8SAshish Jangam case DA9052_IRQ_MASK_A_REG: 5284c99db8SAshish Jangam case DA9052_IRQ_MASK_B_REG: 5384c99db8SAshish Jangam case DA9052_IRQ_MASK_C_REG: 5484c99db8SAshish Jangam case DA9052_IRQ_MASK_D_REG: 5584c99db8SAshish Jangam case DA9052_CONTROL_A_REG: 5684c99db8SAshish Jangam case DA9052_CONTROL_B_REG: 5784c99db8SAshish Jangam case DA9052_CONTROL_C_REG: 5884c99db8SAshish Jangam case DA9052_CONTROL_D_REG: 5984c99db8SAshish Jangam case DA9052_PDDIS_REG: 6084c99db8SAshish Jangam case DA9052_INTERFACE_REG: 6184c99db8SAshish Jangam case DA9052_RESET_REG: 6284c99db8SAshish Jangam case DA9052_GPIO_0_1_REG: 6384c99db8SAshish Jangam case DA9052_GPIO_2_3_REG: 6484c99db8SAshish Jangam case DA9052_GPIO_4_5_REG: 6584c99db8SAshish Jangam case DA9052_GPIO_6_7_REG: 6684c99db8SAshish Jangam case DA9052_GPIO_14_15_REG: 6784c99db8SAshish Jangam case DA9052_ID_0_1_REG: 6884c99db8SAshish Jangam case DA9052_ID_2_3_REG: 6984c99db8SAshish Jangam case DA9052_ID_4_5_REG: 7084c99db8SAshish Jangam case DA9052_ID_6_7_REG: 7184c99db8SAshish Jangam case DA9052_ID_8_9_REG: 7284c99db8SAshish Jangam case DA9052_ID_10_11_REG: 7384c99db8SAshish Jangam case DA9052_ID_12_13_REG: 7484c99db8SAshish Jangam case DA9052_ID_14_15_REG: 7584c99db8SAshish Jangam case DA9052_ID_16_17_REG: 7684c99db8SAshish Jangam case DA9052_ID_18_19_REG: 7784c99db8SAshish Jangam case DA9052_ID_20_21_REG: 7884c99db8SAshish Jangam case DA9052_SEQ_STATUS_REG: 7984c99db8SAshish Jangam case DA9052_SEQ_A_REG: 8084c99db8SAshish Jangam case DA9052_SEQ_B_REG: 8184c99db8SAshish Jangam case DA9052_SEQ_TIMER_REG: 8284c99db8SAshish Jangam case DA9052_BUCKA_REG: 8384c99db8SAshish Jangam case DA9052_BUCKB_REG: 8484c99db8SAshish Jangam case DA9052_BUCKCORE_REG: 8584c99db8SAshish Jangam case DA9052_BUCKPRO_REG: 8684c99db8SAshish Jangam case DA9052_BUCKMEM_REG: 8784c99db8SAshish Jangam case DA9052_BUCKPERI_REG: 8884c99db8SAshish Jangam case DA9052_LDO1_REG: 8984c99db8SAshish Jangam case DA9052_LDO2_REG: 9084c99db8SAshish Jangam case DA9052_LDO3_REG: 9184c99db8SAshish Jangam case DA9052_LDO4_REG: 9284c99db8SAshish Jangam case DA9052_LDO5_REG: 9384c99db8SAshish Jangam case DA9052_LDO6_REG: 9484c99db8SAshish Jangam case DA9052_LDO7_REG: 9584c99db8SAshish Jangam case DA9052_LDO8_REG: 9684c99db8SAshish Jangam case DA9052_LDO9_REG: 9784c99db8SAshish Jangam case DA9052_LDO10_REG: 9884c99db8SAshish Jangam case DA9052_SUPPLY_REG: 9984c99db8SAshish Jangam case DA9052_PULLDOWN_REG: 10084c99db8SAshish Jangam case DA9052_CHGBUCK_REG: 10184c99db8SAshish Jangam case DA9052_WAITCONT_REG: 10284c99db8SAshish Jangam case DA9052_ISET_REG: 10384c99db8SAshish Jangam case DA9052_BATCHG_REG: 10484c99db8SAshish Jangam case DA9052_CHG_CONT_REG: 10584c99db8SAshish Jangam case DA9052_INPUT_CONT_REG: 10684c99db8SAshish Jangam case DA9052_CHG_TIME_REG: 10784c99db8SAshish Jangam case DA9052_BBAT_CONT_REG: 10884c99db8SAshish Jangam case DA9052_BOOST_REG: 10984c99db8SAshish Jangam case DA9052_LED_CONT_REG: 11084c99db8SAshish Jangam case DA9052_LEDMIN123_REG: 11184c99db8SAshish Jangam case DA9052_LED1_CONF_REG: 11284c99db8SAshish Jangam case DA9052_LED2_CONF_REG: 11384c99db8SAshish Jangam case DA9052_LED3_CONF_REG: 11484c99db8SAshish Jangam case DA9052_LED1CONT_REG: 11584c99db8SAshish Jangam case DA9052_LED2CONT_REG: 11684c99db8SAshish Jangam case DA9052_LED3CONT_REG: 11784c99db8SAshish Jangam case DA9052_LED_CONT_4_REG: 11884c99db8SAshish Jangam case DA9052_LED_CONT_5_REG: 11984c99db8SAshish Jangam case DA9052_ADC_MAN_REG: 12084c99db8SAshish Jangam case DA9052_ADC_CONT_REG: 12184c99db8SAshish Jangam case DA9052_ADC_RES_L_REG: 12284c99db8SAshish Jangam case DA9052_ADC_RES_H_REG: 12384c99db8SAshish Jangam case DA9052_VDD_RES_REG: 12484c99db8SAshish Jangam case DA9052_VDD_MON_REG: 12584c99db8SAshish Jangam case DA9052_ICHG_AV_REG: 12684c99db8SAshish Jangam case DA9052_ICHG_THD_REG: 12784c99db8SAshish Jangam case DA9052_ICHG_END_REG: 12884c99db8SAshish Jangam case DA9052_TBAT_RES_REG: 12984c99db8SAshish Jangam case DA9052_TBAT_HIGHP_REG: 13084c99db8SAshish Jangam case DA9052_TBAT_HIGHN_REG: 13184c99db8SAshish Jangam case DA9052_TBAT_LOW_REG: 13284c99db8SAshish Jangam case DA9052_T_OFFSET_REG: 13384c99db8SAshish Jangam case DA9052_ADCIN4_RES_REG: 13484c99db8SAshish Jangam case DA9052_AUTO4_HIGH_REG: 13584c99db8SAshish Jangam case DA9052_AUTO4_LOW_REG: 13684c99db8SAshish Jangam case DA9052_ADCIN5_RES_REG: 13784c99db8SAshish Jangam case DA9052_AUTO5_HIGH_REG: 13884c99db8SAshish Jangam case DA9052_AUTO5_LOW_REG: 13984c99db8SAshish Jangam case DA9052_ADCIN6_RES_REG: 14084c99db8SAshish Jangam case DA9052_AUTO6_HIGH_REG: 14184c99db8SAshish Jangam case DA9052_AUTO6_LOW_REG: 14284c99db8SAshish Jangam case DA9052_TJUNC_RES_REG: 14384c99db8SAshish Jangam case DA9052_TSI_CONT_A_REG: 14484c99db8SAshish Jangam case DA9052_TSI_CONT_B_REG: 14584c99db8SAshish Jangam case DA9052_TSI_X_MSB_REG: 14684c99db8SAshish Jangam case DA9052_TSI_Y_MSB_REG: 14784c99db8SAshish Jangam case DA9052_TSI_LSB_REG: 14884c99db8SAshish Jangam case DA9052_TSI_Z_MSB_REG: 14984c99db8SAshish Jangam case DA9052_COUNT_S_REG: 15084c99db8SAshish Jangam case DA9052_COUNT_MI_REG: 15184c99db8SAshish Jangam case DA9052_COUNT_H_REG: 15284c99db8SAshish Jangam case DA9052_COUNT_D_REG: 15384c99db8SAshish Jangam case DA9052_COUNT_MO_REG: 15484c99db8SAshish Jangam case DA9052_COUNT_Y_REG: 15584c99db8SAshish Jangam case DA9052_ALARM_MI_REG: 15684c99db8SAshish Jangam case DA9052_ALARM_H_REG: 15784c99db8SAshish Jangam case DA9052_ALARM_D_REG: 15884c99db8SAshish Jangam case DA9052_ALARM_MO_REG: 15984c99db8SAshish Jangam case DA9052_ALARM_Y_REG: 16084c99db8SAshish Jangam case DA9052_SECOND_A_REG: 16184c99db8SAshish Jangam case DA9052_SECOND_B_REG: 16284c99db8SAshish Jangam case DA9052_SECOND_C_REG: 16384c99db8SAshish Jangam case DA9052_SECOND_D_REG: 16484c99db8SAshish Jangam case DA9052_PAGE1_CON_REG: 16584c99db8SAshish Jangam return true; 16684c99db8SAshish Jangam default: 16784c99db8SAshish Jangam return false; 16884c99db8SAshish Jangam } 16984c99db8SAshish Jangam } 17084c99db8SAshish Jangam 17184c99db8SAshish Jangam static bool da9052_reg_writeable(struct device *dev, unsigned int reg) 17284c99db8SAshish Jangam { 17384c99db8SAshish Jangam switch (reg) { 17484c99db8SAshish Jangam case DA9052_PAGE0_CON_REG: 175*0a92815dSAshish Jangam case DA9052_EVENT_A_REG: 176*0a92815dSAshish Jangam case DA9052_EVENT_B_REG: 177*0a92815dSAshish Jangam case DA9052_EVENT_C_REG: 178*0a92815dSAshish Jangam case DA9052_EVENT_D_REG: 17984c99db8SAshish Jangam case DA9052_IRQ_MASK_A_REG: 18084c99db8SAshish Jangam case DA9052_IRQ_MASK_B_REG: 18184c99db8SAshish Jangam case DA9052_IRQ_MASK_C_REG: 18284c99db8SAshish Jangam case DA9052_IRQ_MASK_D_REG: 18384c99db8SAshish Jangam case DA9052_CONTROL_A_REG: 18484c99db8SAshish Jangam case DA9052_CONTROL_B_REG: 18584c99db8SAshish Jangam case DA9052_CONTROL_C_REG: 18684c99db8SAshish Jangam case DA9052_CONTROL_D_REG: 18784c99db8SAshish Jangam case DA9052_PDDIS_REG: 18884c99db8SAshish Jangam case DA9052_RESET_REG: 18984c99db8SAshish Jangam case DA9052_GPIO_0_1_REG: 19084c99db8SAshish Jangam case DA9052_GPIO_2_3_REG: 19184c99db8SAshish Jangam case DA9052_GPIO_4_5_REG: 19284c99db8SAshish Jangam case DA9052_GPIO_6_7_REG: 19384c99db8SAshish Jangam case DA9052_GPIO_14_15_REG: 19484c99db8SAshish Jangam case DA9052_ID_0_1_REG: 19584c99db8SAshish Jangam case DA9052_ID_2_3_REG: 19684c99db8SAshish Jangam case DA9052_ID_4_5_REG: 19784c99db8SAshish Jangam case DA9052_ID_6_7_REG: 19884c99db8SAshish Jangam case DA9052_ID_8_9_REG: 19984c99db8SAshish Jangam case DA9052_ID_10_11_REG: 20084c99db8SAshish Jangam case DA9052_ID_12_13_REG: 20184c99db8SAshish Jangam case DA9052_ID_14_15_REG: 20284c99db8SAshish Jangam case DA9052_ID_16_17_REG: 20384c99db8SAshish Jangam case DA9052_ID_18_19_REG: 20484c99db8SAshish Jangam case DA9052_ID_20_21_REG: 20584c99db8SAshish Jangam case DA9052_SEQ_STATUS_REG: 20684c99db8SAshish Jangam case DA9052_SEQ_A_REG: 20784c99db8SAshish Jangam case DA9052_SEQ_B_REG: 20884c99db8SAshish Jangam case DA9052_SEQ_TIMER_REG: 20984c99db8SAshish Jangam case DA9052_BUCKA_REG: 21084c99db8SAshish Jangam case DA9052_BUCKB_REG: 21184c99db8SAshish Jangam case DA9052_BUCKCORE_REG: 21284c99db8SAshish Jangam case DA9052_BUCKPRO_REG: 21384c99db8SAshish Jangam case DA9052_BUCKMEM_REG: 21484c99db8SAshish Jangam case DA9052_BUCKPERI_REG: 21584c99db8SAshish Jangam case DA9052_LDO1_REG: 21684c99db8SAshish Jangam case DA9052_LDO2_REG: 21784c99db8SAshish Jangam case DA9052_LDO3_REG: 21884c99db8SAshish Jangam case DA9052_LDO4_REG: 21984c99db8SAshish Jangam case DA9052_LDO5_REG: 22084c99db8SAshish Jangam case DA9052_LDO6_REG: 22184c99db8SAshish Jangam case DA9052_LDO7_REG: 22284c99db8SAshish Jangam case DA9052_LDO8_REG: 22384c99db8SAshish Jangam case DA9052_LDO9_REG: 22484c99db8SAshish Jangam case DA9052_LDO10_REG: 22584c99db8SAshish Jangam case DA9052_SUPPLY_REG: 22684c99db8SAshish Jangam case DA9052_PULLDOWN_REG: 22784c99db8SAshish Jangam case DA9052_CHGBUCK_REG: 22884c99db8SAshish Jangam case DA9052_WAITCONT_REG: 22984c99db8SAshish Jangam case DA9052_ISET_REG: 23084c99db8SAshish Jangam case DA9052_BATCHG_REG: 23184c99db8SAshish Jangam case DA9052_CHG_CONT_REG: 23284c99db8SAshish Jangam case DA9052_INPUT_CONT_REG: 23384c99db8SAshish Jangam case DA9052_BBAT_CONT_REG: 23484c99db8SAshish Jangam case DA9052_BOOST_REG: 23584c99db8SAshish Jangam case DA9052_LED_CONT_REG: 23684c99db8SAshish Jangam case DA9052_LEDMIN123_REG: 23784c99db8SAshish Jangam case DA9052_LED1_CONF_REG: 23884c99db8SAshish Jangam case DA9052_LED2_CONF_REG: 23984c99db8SAshish Jangam case DA9052_LED3_CONF_REG: 24084c99db8SAshish Jangam case DA9052_LED1CONT_REG: 24184c99db8SAshish Jangam case DA9052_LED2CONT_REG: 24284c99db8SAshish Jangam case DA9052_LED3CONT_REG: 24384c99db8SAshish Jangam case DA9052_LED_CONT_4_REG: 24484c99db8SAshish Jangam case DA9052_LED_CONT_5_REG: 24584c99db8SAshish Jangam case DA9052_ADC_MAN_REG: 24684c99db8SAshish Jangam case DA9052_ADC_CONT_REG: 24784c99db8SAshish Jangam case DA9052_ADC_RES_L_REG: 24884c99db8SAshish Jangam case DA9052_ADC_RES_H_REG: 24984c99db8SAshish Jangam case DA9052_VDD_RES_REG: 25084c99db8SAshish Jangam case DA9052_VDD_MON_REG: 25184c99db8SAshish Jangam case DA9052_ICHG_THD_REG: 25284c99db8SAshish Jangam case DA9052_ICHG_END_REG: 25384c99db8SAshish Jangam case DA9052_TBAT_HIGHP_REG: 25484c99db8SAshish Jangam case DA9052_TBAT_HIGHN_REG: 25584c99db8SAshish Jangam case DA9052_TBAT_LOW_REG: 25684c99db8SAshish Jangam case DA9052_T_OFFSET_REG: 25784c99db8SAshish Jangam case DA9052_AUTO4_HIGH_REG: 25884c99db8SAshish Jangam case DA9052_AUTO4_LOW_REG: 25984c99db8SAshish Jangam case DA9052_AUTO5_HIGH_REG: 26084c99db8SAshish Jangam case DA9052_AUTO5_LOW_REG: 26184c99db8SAshish Jangam case DA9052_AUTO6_HIGH_REG: 26284c99db8SAshish Jangam case DA9052_AUTO6_LOW_REG: 26384c99db8SAshish Jangam case DA9052_TSI_CONT_A_REG: 26484c99db8SAshish Jangam case DA9052_TSI_CONT_B_REG: 26584c99db8SAshish Jangam case DA9052_COUNT_S_REG: 26684c99db8SAshish Jangam case DA9052_COUNT_MI_REG: 26784c99db8SAshish Jangam case DA9052_COUNT_H_REG: 26884c99db8SAshish Jangam case DA9052_COUNT_D_REG: 26984c99db8SAshish Jangam case DA9052_COUNT_MO_REG: 27084c99db8SAshish Jangam case DA9052_COUNT_Y_REG: 27184c99db8SAshish Jangam case DA9052_ALARM_MI_REG: 27284c99db8SAshish Jangam case DA9052_ALARM_H_REG: 27384c99db8SAshish Jangam case DA9052_ALARM_D_REG: 27484c99db8SAshish Jangam case DA9052_ALARM_MO_REG: 27584c99db8SAshish Jangam case DA9052_ALARM_Y_REG: 27684c99db8SAshish Jangam case DA9052_PAGE1_CON_REG: 27784c99db8SAshish Jangam return true; 27884c99db8SAshish Jangam default: 27984c99db8SAshish Jangam return false; 28084c99db8SAshish Jangam } 28184c99db8SAshish Jangam } 28284c99db8SAshish Jangam 28384c99db8SAshish Jangam static bool da9052_reg_volatile(struct device *dev, unsigned int reg) 28484c99db8SAshish Jangam { 28584c99db8SAshish Jangam switch (reg) { 28684c99db8SAshish Jangam case DA9052_STATUS_A_REG: 28784c99db8SAshish Jangam case DA9052_STATUS_B_REG: 28884c99db8SAshish Jangam case DA9052_STATUS_C_REG: 28984c99db8SAshish Jangam case DA9052_STATUS_D_REG: 29084c99db8SAshish Jangam case DA9052_EVENT_A_REG: 29184c99db8SAshish Jangam case DA9052_EVENT_B_REG: 29284c99db8SAshish Jangam case DA9052_EVENT_C_REG: 29384c99db8SAshish Jangam case DA9052_EVENT_D_REG: 29484c99db8SAshish Jangam case DA9052_FAULTLOG_REG: 29584c99db8SAshish Jangam case DA9052_CHG_TIME_REG: 29684c99db8SAshish Jangam case DA9052_ADC_RES_L_REG: 29784c99db8SAshish Jangam case DA9052_ADC_RES_H_REG: 29884c99db8SAshish Jangam case DA9052_VDD_RES_REG: 29984c99db8SAshish Jangam case DA9052_ICHG_AV_REG: 30084c99db8SAshish Jangam case DA9052_TBAT_RES_REG: 30184c99db8SAshish Jangam case DA9052_ADCIN4_RES_REG: 30284c99db8SAshish Jangam case DA9052_ADCIN5_RES_REG: 30384c99db8SAshish Jangam case DA9052_ADCIN6_RES_REG: 30484c99db8SAshish Jangam case DA9052_TJUNC_RES_REG: 30584c99db8SAshish Jangam case DA9052_TSI_X_MSB_REG: 30684c99db8SAshish Jangam case DA9052_TSI_Y_MSB_REG: 30784c99db8SAshish Jangam case DA9052_TSI_LSB_REG: 30884c99db8SAshish Jangam case DA9052_TSI_Z_MSB_REG: 30984c99db8SAshish Jangam case DA9052_COUNT_S_REG: 31084c99db8SAshish Jangam case DA9052_COUNT_MI_REG: 31184c99db8SAshish Jangam case DA9052_COUNT_H_REG: 31284c99db8SAshish Jangam case DA9052_COUNT_D_REG: 31384c99db8SAshish Jangam case DA9052_COUNT_MO_REG: 31484c99db8SAshish Jangam case DA9052_COUNT_Y_REG: 31584c99db8SAshish Jangam case DA9052_ALARM_MI_REG: 31684c99db8SAshish Jangam return true; 31784c99db8SAshish Jangam default: 31884c99db8SAshish Jangam return false; 31984c99db8SAshish Jangam } 32084c99db8SAshish Jangam } 32184c99db8SAshish Jangam 32284c99db8SAshish Jangam static struct resource da9052_rtc_resource = { 32384c99db8SAshish Jangam .name = "ALM", 32484c99db8SAshish Jangam .start = DA9052_IRQ_ALARM, 32584c99db8SAshish Jangam .end = DA9052_IRQ_ALARM, 32684c99db8SAshish Jangam .flags = IORESOURCE_IRQ, 32784c99db8SAshish Jangam }; 32884c99db8SAshish Jangam 32984c99db8SAshish Jangam static struct resource da9052_onkey_resource = { 33084c99db8SAshish Jangam .name = "ONKEY", 33184c99db8SAshish Jangam .start = DA9052_IRQ_NONKEY, 33284c99db8SAshish Jangam .end = DA9052_IRQ_NONKEY, 33384c99db8SAshish Jangam .flags = IORESOURCE_IRQ, 33484c99db8SAshish Jangam }; 33584c99db8SAshish Jangam 33684c99db8SAshish Jangam static struct resource da9052_bat_resources[] = { 33784c99db8SAshish Jangam { 33884c99db8SAshish Jangam .name = "BATT TEMP", 33984c99db8SAshish Jangam .start = DA9052_IRQ_TBAT, 34084c99db8SAshish Jangam .end = DA9052_IRQ_TBAT, 34184c99db8SAshish Jangam .flags = IORESOURCE_IRQ, 34284c99db8SAshish Jangam }, 34384c99db8SAshish Jangam { 34484c99db8SAshish Jangam .name = "DCIN DET", 34584c99db8SAshish Jangam .start = DA9052_IRQ_DCIN, 34684c99db8SAshish Jangam .end = DA9052_IRQ_DCIN, 34784c99db8SAshish Jangam .flags = IORESOURCE_IRQ, 34884c99db8SAshish Jangam }, 34984c99db8SAshish Jangam { 35084c99db8SAshish Jangam .name = "DCIN REM", 35184c99db8SAshish Jangam .start = DA9052_IRQ_DCINREM, 35284c99db8SAshish Jangam .end = DA9052_IRQ_DCINREM, 35384c99db8SAshish Jangam .flags = IORESOURCE_IRQ, 35484c99db8SAshish Jangam }, 35584c99db8SAshish Jangam { 35684c99db8SAshish Jangam .name = "VBUS DET", 35784c99db8SAshish Jangam .start = DA9052_IRQ_VBUS, 35884c99db8SAshish Jangam .end = DA9052_IRQ_VBUS, 35984c99db8SAshish Jangam .flags = IORESOURCE_IRQ, 36084c99db8SAshish Jangam }, 36184c99db8SAshish Jangam { 36284c99db8SAshish Jangam .name = "VBUS REM", 36384c99db8SAshish Jangam .start = DA9052_IRQ_VBUSREM, 36484c99db8SAshish Jangam .end = DA9052_IRQ_VBUSREM, 36584c99db8SAshish Jangam .flags = IORESOURCE_IRQ, 36684c99db8SAshish Jangam }, 36784c99db8SAshish Jangam { 36884c99db8SAshish Jangam .name = "CHG END", 36984c99db8SAshish Jangam .start = DA9052_IRQ_CHGEND, 37084c99db8SAshish Jangam .end = DA9052_IRQ_CHGEND, 37184c99db8SAshish Jangam .flags = IORESOURCE_IRQ, 37284c99db8SAshish Jangam }, 37384c99db8SAshish Jangam }; 37484c99db8SAshish Jangam 37584c99db8SAshish Jangam static struct resource da9052_tsi_resources[] = { 37684c99db8SAshish Jangam { 37784c99db8SAshish Jangam .name = "PENDWN", 37884c99db8SAshish Jangam .start = DA9052_IRQ_PENDOWN, 37984c99db8SAshish Jangam .end = DA9052_IRQ_PENDOWN, 38084c99db8SAshish Jangam .flags = IORESOURCE_IRQ, 38184c99db8SAshish Jangam }, 38284c99db8SAshish Jangam { 38384c99db8SAshish Jangam .name = "TSIRDY", 38484c99db8SAshish Jangam .start = DA9052_IRQ_TSIREADY, 38584c99db8SAshish Jangam .end = DA9052_IRQ_TSIREADY, 38684c99db8SAshish Jangam .flags = IORESOURCE_IRQ, 38784c99db8SAshish Jangam }, 38884c99db8SAshish Jangam }; 38984c99db8SAshish Jangam 390d9cba483SMark Brown static struct mfd_cell __devinitdata da9052_subdev_info[] = { 39184c99db8SAshish Jangam { 39284c99db8SAshish Jangam .name = "da9052-regulator", 39384c99db8SAshish Jangam .id = 1, 39484c99db8SAshish Jangam }, 39584c99db8SAshish Jangam { 39684c99db8SAshish Jangam .name = "da9052-regulator", 39784c99db8SAshish Jangam .id = 2, 39884c99db8SAshish Jangam }, 39984c99db8SAshish Jangam { 40084c99db8SAshish Jangam .name = "da9052-regulator", 40184c99db8SAshish Jangam .id = 3, 40284c99db8SAshish Jangam }, 40384c99db8SAshish Jangam { 40484c99db8SAshish Jangam .name = "da9052-regulator", 40584c99db8SAshish Jangam .id = 4, 40684c99db8SAshish Jangam }, 40784c99db8SAshish Jangam { 40884c99db8SAshish Jangam .name = "da9052-regulator", 40984c99db8SAshish Jangam .id = 5, 41084c99db8SAshish Jangam }, 41184c99db8SAshish Jangam { 41284c99db8SAshish Jangam .name = "da9052-regulator", 41384c99db8SAshish Jangam .id = 6, 41484c99db8SAshish Jangam }, 41584c99db8SAshish Jangam { 41684c99db8SAshish Jangam .name = "da9052-regulator", 41784c99db8SAshish Jangam .id = 7, 41884c99db8SAshish Jangam }, 41984c99db8SAshish Jangam { 42084c99db8SAshish Jangam .name = "da9052-regulator", 42184c99db8SAshish Jangam .id = 8, 42284c99db8SAshish Jangam }, 42384c99db8SAshish Jangam { 42484c99db8SAshish Jangam .name = "da9052-regulator", 42584c99db8SAshish Jangam .id = 9, 42684c99db8SAshish Jangam }, 42784c99db8SAshish Jangam { 42884c99db8SAshish Jangam .name = "da9052-regulator", 42984c99db8SAshish Jangam .id = 10, 43084c99db8SAshish Jangam }, 43184c99db8SAshish Jangam { 43284c99db8SAshish Jangam .name = "da9052-regulator", 43384c99db8SAshish Jangam .id = 11, 43484c99db8SAshish Jangam }, 43584c99db8SAshish Jangam { 43684c99db8SAshish Jangam .name = "da9052-regulator", 43784c99db8SAshish Jangam .id = 12, 43884c99db8SAshish Jangam }, 43984c99db8SAshish Jangam { 44084c99db8SAshish Jangam .name = "da9052-regulator", 44184c99db8SAshish Jangam .id = 13, 44284c99db8SAshish Jangam }, 44384c99db8SAshish Jangam { 44484c99db8SAshish Jangam .name = "da9052-regulator", 44584c99db8SAshish Jangam .id = 14, 44684c99db8SAshish Jangam }, 44784c99db8SAshish Jangam { 44884c99db8SAshish Jangam .name = "da9052-onkey", 44984c99db8SAshish Jangam .resources = &da9052_onkey_resource, 45084c99db8SAshish Jangam .num_resources = 1, 45184c99db8SAshish Jangam }, 45284c99db8SAshish Jangam { 45384c99db8SAshish Jangam .name = "da9052-rtc", 45484c99db8SAshish Jangam .resources = &da9052_rtc_resource, 45584c99db8SAshish Jangam .num_resources = 1, 45684c99db8SAshish Jangam }, 45784c99db8SAshish Jangam { 45884c99db8SAshish Jangam .name = "da9052-gpio", 45984c99db8SAshish Jangam }, 46084c99db8SAshish Jangam { 46184c99db8SAshish Jangam .name = "da9052-hwmon", 46284c99db8SAshish Jangam }, 46384c99db8SAshish Jangam { 46484c99db8SAshish Jangam .name = "da9052-leds", 46584c99db8SAshish Jangam }, 46684c99db8SAshish Jangam { 46784c99db8SAshish Jangam .name = "da9052-wled1", 46884c99db8SAshish Jangam }, 46984c99db8SAshish Jangam { 47084c99db8SAshish Jangam .name = "da9052-wled2", 47184c99db8SAshish Jangam }, 47284c99db8SAshish Jangam { 47384c99db8SAshish Jangam .name = "da9052-wled3", 47484c99db8SAshish Jangam }, 47584c99db8SAshish Jangam { 47684c99db8SAshish Jangam .name = "da9052-tsi", 47784c99db8SAshish Jangam .resources = da9052_tsi_resources, 47884c99db8SAshish Jangam .num_resources = ARRAY_SIZE(da9052_tsi_resources), 47984c99db8SAshish Jangam }, 48084c99db8SAshish Jangam { 48184c99db8SAshish Jangam .name = "da9052-bat", 48284c99db8SAshish Jangam .resources = da9052_bat_resources, 48384c99db8SAshish Jangam .num_resources = ARRAY_SIZE(da9052_bat_resources), 48484c99db8SAshish Jangam }, 48584c99db8SAshish Jangam { 48684c99db8SAshish Jangam .name = "da9052-watchdog", 48784c99db8SAshish Jangam }, 48884c99db8SAshish Jangam }; 48984c99db8SAshish Jangam 49084c99db8SAshish Jangam static struct regmap_irq da9052_irqs[] = { 49184c99db8SAshish Jangam [DA9052_IRQ_DCIN] = { 49284c99db8SAshish Jangam .reg_offset = 0, 49384c99db8SAshish Jangam .mask = DA9052_IRQ_MASK_POS_1, 49484c99db8SAshish Jangam }, 49584c99db8SAshish Jangam [DA9052_IRQ_VBUS] = { 49684c99db8SAshish Jangam .reg_offset = 0, 49784c99db8SAshish Jangam .mask = DA9052_IRQ_MASK_POS_2, 49884c99db8SAshish Jangam }, 49984c99db8SAshish Jangam [DA9052_IRQ_DCINREM] = { 50084c99db8SAshish Jangam .reg_offset = 0, 50184c99db8SAshish Jangam .mask = DA9052_IRQ_MASK_POS_3, 50284c99db8SAshish Jangam }, 50384c99db8SAshish Jangam [DA9052_IRQ_VBUSREM] = { 50484c99db8SAshish Jangam .reg_offset = 0, 50584c99db8SAshish Jangam .mask = DA9052_IRQ_MASK_POS_4, 50684c99db8SAshish Jangam }, 50784c99db8SAshish Jangam [DA9052_IRQ_VDDLOW] = { 50884c99db8SAshish Jangam .reg_offset = 0, 50984c99db8SAshish Jangam .mask = DA9052_IRQ_MASK_POS_5, 51084c99db8SAshish Jangam }, 51184c99db8SAshish Jangam [DA9052_IRQ_ALARM] = { 51284c99db8SAshish Jangam .reg_offset = 0, 51384c99db8SAshish Jangam .mask = DA9052_IRQ_MASK_POS_6, 51484c99db8SAshish Jangam }, 51584c99db8SAshish Jangam [DA9052_IRQ_SEQRDY] = { 51684c99db8SAshish Jangam .reg_offset = 0, 51784c99db8SAshish Jangam .mask = DA9052_IRQ_MASK_POS_7, 51884c99db8SAshish Jangam }, 51984c99db8SAshish Jangam [DA9052_IRQ_COMP1V2] = { 52084c99db8SAshish Jangam .reg_offset = 0, 52184c99db8SAshish Jangam .mask = DA9052_IRQ_MASK_POS_8, 52284c99db8SAshish Jangam }, 52384c99db8SAshish Jangam [DA9052_IRQ_NONKEY] = { 52484c99db8SAshish Jangam .reg_offset = 1, 52584c99db8SAshish Jangam .mask = DA9052_IRQ_MASK_POS_1, 52684c99db8SAshish Jangam }, 52784c99db8SAshish Jangam [DA9052_IRQ_IDFLOAT] = { 52884c99db8SAshish Jangam .reg_offset = 1, 52984c99db8SAshish Jangam .mask = DA9052_IRQ_MASK_POS_2, 53084c99db8SAshish Jangam }, 53184c99db8SAshish Jangam [DA9052_IRQ_IDGND] = { 53284c99db8SAshish Jangam .reg_offset = 1, 53384c99db8SAshish Jangam .mask = DA9052_IRQ_MASK_POS_3, 53484c99db8SAshish Jangam }, 53584c99db8SAshish Jangam [DA9052_IRQ_CHGEND] = { 53684c99db8SAshish Jangam .reg_offset = 1, 53784c99db8SAshish Jangam .mask = DA9052_IRQ_MASK_POS_4, 53884c99db8SAshish Jangam }, 53984c99db8SAshish Jangam [DA9052_IRQ_TBAT] = { 54084c99db8SAshish Jangam .reg_offset = 1, 54184c99db8SAshish Jangam .mask = DA9052_IRQ_MASK_POS_5, 54284c99db8SAshish Jangam }, 54384c99db8SAshish Jangam [DA9052_IRQ_ADC_EOM] = { 54484c99db8SAshish Jangam .reg_offset = 1, 54584c99db8SAshish Jangam .mask = DA9052_IRQ_MASK_POS_6, 54684c99db8SAshish Jangam }, 54784c99db8SAshish Jangam [DA9052_IRQ_PENDOWN] = { 54884c99db8SAshish Jangam .reg_offset = 1, 54984c99db8SAshish Jangam .mask = DA9052_IRQ_MASK_POS_7, 55084c99db8SAshish Jangam }, 55184c99db8SAshish Jangam [DA9052_IRQ_TSIREADY] = { 55284c99db8SAshish Jangam .reg_offset = 1, 55384c99db8SAshish Jangam .mask = DA9052_IRQ_MASK_POS_8, 55484c99db8SAshish Jangam }, 55584c99db8SAshish Jangam [DA9052_IRQ_GPI0] = { 55684c99db8SAshish Jangam .reg_offset = 2, 55784c99db8SAshish Jangam .mask = DA9052_IRQ_MASK_POS_1, 55884c99db8SAshish Jangam }, 55984c99db8SAshish Jangam [DA9052_IRQ_GPI1] = { 56084c99db8SAshish Jangam .reg_offset = 2, 56184c99db8SAshish Jangam .mask = DA9052_IRQ_MASK_POS_2, 56284c99db8SAshish Jangam }, 56384c99db8SAshish Jangam [DA9052_IRQ_GPI2] = { 56484c99db8SAshish Jangam .reg_offset = 2, 56584c99db8SAshish Jangam .mask = DA9052_IRQ_MASK_POS_3, 56684c99db8SAshish Jangam }, 56784c99db8SAshish Jangam [DA9052_IRQ_GPI3] = { 56884c99db8SAshish Jangam .reg_offset = 2, 56984c99db8SAshish Jangam .mask = DA9052_IRQ_MASK_POS_4, 57084c99db8SAshish Jangam }, 57184c99db8SAshish Jangam [DA9052_IRQ_GPI4] = { 57284c99db8SAshish Jangam .reg_offset = 2, 57384c99db8SAshish Jangam .mask = DA9052_IRQ_MASK_POS_5, 57484c99db8SAshish Jangam }, 57584c99db8SAshish Jangam [DA9052_IRQ_GPI5] = { 57684c99db8SAshish Jangam .reg_offset = 2, 57784c99db8SAshish Jangam .mask = DA9052_IRQ_MASK_POS_6, 57884c99db8SAshish Jangam }, 57984c99db8SAshish Jangam [DA9052_IRQ_GPI6] = { 58084c99db8SAshish Jangam .reg_offset = 2, 58184c99db8SAshish Jangam .mask = DA9052_IRQ_MASK_POS_7, 58284c99db8SAshish Jangam }, 58384c99db8SAshish Jangam [DA9052_IRQ_GPI7] = { 58484c99db8SAshish Jangam .reg_offset = 2, 58584c99db8SAshish Jangam .mask = DA9052_IRQ_MASK_POS_8, 58684c99db8SAshish Jangam }, 58784c99db8SAshish Jangam [DA9052_IRQ_GPI8] = { 58884c99db8SAshish Jangam .reg_offset = 3, 58984c99db8SAshish Jangam .mask = DA9052_IRQ_MASK_POS_1, 59084c99db8SAshish Jangam }, 59184c99db8SAshish Jangam [DA9052_IRQ_GPI9] = { 59284c99db8SAshish Jangam .reg_offset = 3, 59384c99db8SAshish Jangam .mask = DA9052_IRQ_MASK_POS_2, 59484c99db8SAshish Jangam }, 59584c99db8SAshish Jangam [DA9052_IRQ_GPI10] = { 59684c99db8SAshish Jangam .reg_offset = 3, 59784c99db8SAshish Jangam .mask = DA9052_IRQ_MASK_POS_3, 59884c99db8SAshish Jangam }, 59984c99db8SAshish Jangam [DA9052_IRQ_GPI11] = { 60084c99db8SAshish Jangam .reg_offset = 3, 60184c99db8SAshish Jangam .mask = DA9052_IRQ_MASK_POS_4, 60284c99db8SAshish Jangam }, 60384c99db8SAshish Jangam [DA9052_IRQ_GPI12] = { 60484c99db8SAshish Jangam .reg_offset = 3, 60584c99db8SAshish Jangam .mask = DA9052_IRQ_MASK_POS_5, 60684c99db8SAshish Jangam }, 60784c99db8SAshish Jangam [DA9052_IRQ_GPI13] = { 60884c99db8SAshish Jangam .reg_offset = 3, 60984c99db8SAshish Jangam .mask = DA9052_IRQ_MASK_POS_6, 61084c99db8SAshish Jangam }, 61184c99db8SAshish Jangam [DA9052_IRQ_GPI14] = { 61284c99db8SAshish Jangam .reg_offset = 3, 61384c99db8SAshish Jangam .mask = DA9052_IRQ_MASK_POS_7, 61484c99db8SAshish Jangam }, 61584c99db8SAshish Jangam [DA9052_IRQ_GPI15] = { 61684c99db8SAshish Jangam .reg_offset = 3, 61784c99db8SAshish Jangam .mask = DA9052_IRQ_MASK_POS_8, 61884c99db8SAshish Jangam }, 61984c99db8SAshish Jangam }; 62084c99db8SAshish Jangam 62184c99db8SAshish Jangam static struct regmap_irq_chip da9052_regmap_irq_chip = { 62284c99db8SAshish Jangam .name = "da9052_irq", 62384c99db8SAshish Jangam .status_base = DA9052_EVENT_A_REG, 62484c99db8SAshish Jangam .mask_base = DA9052_IRQ_MASK_A_REG, 62584c99db8SAshish Jangam .ack_base = DA9052_EVENT_A_REG, 62684c99db8SAshish Jangam .num_regs = DA9052_NUM_IRQ_REGS, 62784c99db8SAshish Jangam .irqs = da9052_irqs, 62884c99db8SAshish Jangam .num_irqs = ARRAY_SIZE(da9052_irqs), 62984c99db8SAshish Jangam }; 63084c99db8SAshish Jangam 63184c99db8SAshish Jangam struct regmap_config da9052_regmap_config = { 63284c99db8SAshish Jangam .reg_bits = 8, 63384c99db8SAshish Jangam .val_bits = 8, 63484c99db8SAshish Jangam 63584c99db8SAshish Jangam .cache_type = REGCACHE_RBTREE, 63684c99db8SAshish Jangam 63784c99db8SAshish Jangam .max_register = DA9052_PAGE1_CON_REG, 63884c99db8SAshish Jangam .readable_reg = da9052_reg_readable, 63984c99db8SAshish Jangam .writeable_reg = da9052_reg_writeable, 64084c99db8SAshish Jangam .volatile_reg = da9052_reg_volatile, 64184c99db8SAshish Jangam }; 64284c99db8SAshish Jangam EXPORT_SYMBOL_GPL(da9052_regmap_config); 64384c99db8SAshish Jangam 644d9cba483SMark Brown int __devinit da9052_device_init(struct da9052 *da9052, u8 chip_id) 64584c99db8SAshish Jangam { 64684c99db8SAshish Jangam struct da9052_pdata *pdata = da9052->dev->platform_data; 64784c99db8SAshish Jangam struct irq_desc *desc; 64884c99db8SAshish Jangam int ret; 64984c99db8SAshish Jangam 65084c99db8SAshish Jangam mutex_init(&da9052->io_lock); 65184c99db8SAshish Jangam 65284c99db8SAshish Jangam if (pdata && pdata->init != NULL) 65384c99db8SAshish Jangam pdata->init(da9052); 65484c99db8SAshish Jangam 65584c99db8SAshish Jangam da9052->chip_id = chip_id; 65684c99db8SAshish Jangam 65784c99db8SAshish Jangam if (!pdata || !pdata->irq_base) 65884c99db8SAshish Jangam da9052->irq_base = -1; 65984c99db8SAshish Jangam else 66084c99db8SAshish Jangam da9052->irq_base = pdata->irq_base; 66184c99db8SAshish Jangam 66284c99db8SAshish Jangam ret = regmap_add_irq_chip(da9052->regmap, da9052->chip_irq, 66384c99db8SAshish Jangam IRQF_TRIGGER_LOW | IRQF_ONESHOT, 66484c99db8SAshish Jangam da9052->irq_base, &da9052_regmap_irq_chip, 66584c99db8SAshish Jangam NULL); 66684c99db8SAshish Jangam if (ret < 0) 66784c99db8SAshish Jangam goto regmap_err; 66884c99db8SAshish Jangam 66984c99db8SAshish Jangam desc = irq_to_desc(da9052->chip_irq); 67084c99db8SAshish Jangam da9052->irq_base = regmap_irq_chip_get_base(desc->action->dev_id); 67184c99db8SAshish Jangam 67284c99db8SAshish Jangam ret = mfd_add_devices(da9052->dev, -1, da9052_subdev_info, 67384c99db8SAshish Jangam ARRAY_SIZE(da9052_subdev_info), NULL, 0); 67484c99db8SAshish Jangam if (ret) 67584c99db8SAshish Jangam goto err; 67684c99db8SAshish Jangam 67784c99db8SAshish Jangam return 0; 67884c99db8SAshish Jangam 67984c99db8SAshish Jangam err: 68084c99db8SAshish Jangam mfd_remove_devices(da9052->dev); 68184c99db8SAshish Jangam regmap_err: 68284c99db8SAshish Jangam return ret; 68384c99db8SAshish Jangam } 68484c99db8SAshish Jangam 68584c99db8SAshish Jangam void da9052_device_exit(struct da9052 *da9052) 68684c99db8SAshish Jangam { 68784c99db8SAshish Jangam regmap_del_irq_chip(da9052->chip_irq, 68884c99db8SAshish Jangam irq_get_irq_data(da9052->irq_base)->chip_data); 68984c99db8SAshish Jangam mfd_remove_devices(da9052->dev); 69084c99db8SAshish Jangam } 69184c99db8SAshish Jangam 69284c99db8SAshish Jangam MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>"); 69384c99db8SAshish Jangam MODULE_DESCRIPTION("DA9052 MFD Core"); 69484c99db8SAshish Jangam MODULE_LICENSE("GPL"); 695