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/mfd/core.h> 1984c99db8SAshish Jangam #include <linux/slab.h> 2084c99db8SAshish Jangam #include <linux/module.h> 21ebf55511SSebastian Reichel #include <linux/property.h> 2284c99db8SAshish Jangam 2384c99db8SAshish Jangam #include <linux/mfd/da9052/da9052.h> 2484c99db8SAshish Jangam #include <linux/mfd/da9052/pdata.h> 2584c99db8SAshish Jangam #include <linux/mfd/da9052/reg.h> 2684c99db8SAshish Jangam 2784c99db8SAshish Jangam static bool da9052_reg_readable(struct device *dev, unsigned int reg) 2884c99db8SAshish Jangam { 2984c99db8SAshish Jangam switch (reg) { 3084c99db8SAshish Jangam case DA9052_PAGE0_CON_REG: 3184c99db8SAshish Jangam case DA9052_STATUS_A_REG: 3284c99db8SAshish Jangam case DA9052_STATUS_B_REG: 3384c99db8SAshish Jangam case DA9052_STATUS_C_REG: 3484c99db8SAshish Jangam case DA9052_STATUS_D_REG: 3584c99db8SAshish Jangam case DA9052_EVENT_A_REG: 3684c99db8SAshish Jangam case DA9052_EVENT_B_REG: 3784c99db8SAshish Jangam case DA9052_EVENT_C_REG: 3884c99db8SAshish Jangam case DA9052_EVENT_D_REG: 3984c99db8SAshish Jangam case DA9052_FAULTLOG_REG: 4084c99db8SAshish Jangam case DA9052_IRQ_MASK_A_REG: 4184c99db8SAshish Jangam case DA9052_IRQ_MASK_B_REG: 4284c99db8SAshish Jangam case DA9052_IRQ_MASK_C_REG: 4384c99db8SAshish Jangam case DA9052_IRQ_MASK_D_REG: 4484c99db8SAshish Jangam case DA9052_CONTROL_A_REG: 4584c99db8SAshish Jangam case DA9052_CONTROL_B_REG: 4684c99db8SAshish Jangam case DA9052_CONTROL_C_REG: 4784c99db8SAshish Jangam case DA9052_CONTROL_D_REG: 4884c99db8SAshish Jangam case DA9052_PDDIS_REG: 4984c99db8SAshish Jangam case DA9052_INTERFACE_REG: 5084c99db8SAshish Jangam case DA9052_RESET_REG: 5184c99db8SAshish Jangam case DA9052_GPIO_0_1_REG: 5284c99db8SAshish Jangam case DA9052_GPIO_2_3_REG: 5384c99db8SAshish Jangam case DA9052_GPIO_4_5_REG: 5484c99db8SAshish Jangam case DA9052_GPIO_6_7_REG: 550386af30SSteve Twiss case DA9052_GPIO_8_9_REG: 560386af30SSteve Twiss case DA9052_GPIO_10_11_REG: 570386af30SSteve Twiss case DA9052_GPIO_12_13_REG: 5884c99db8SAshish Jangam case DA9052_GPIO_14_15_REG: 5984c99db8SAshish Jangam case DA9052_ID_0_1_REG: 6084c99db8SAshish Jangam case DA9052_ID_2_3_REG: 6184c99db8SAshish Jangam case DA9052_ID_4_5_REG: 6284c99db8SAshish Jangam case DA9052_ID_6_7_REG: 6384c99db8SAshish Jangam case DA9052_ID_8_9_REG: 6484c99db8SAshish Jangam case DA9052_ID_10_11_REG: 6584c99db8SAshish Jangam case DA9052_ID_12_13_REG: 6684c99db8SAshish Jangam case DA9052_ID_14_15_REG: 6784c99db8SAshish Jangam case DA9052_ID_16_17_REG: 6884c99db8SAshish Jangam case DA9052_ID_18_19_REG: 6984c99db8SAshish Jangam case DA9052_ID_20_21_REG: 7084c99db8SAshish Jangam case DA9052_SEQ_STATUS_REG: 7184c99db8SAshish Jangam case DA9052_SEQ_A_REG: 7284c99db8SAshish Jangam case DA9052_SEQ_B_REG: 7384c99db8SAshish Jangam case DA9052_SEQ_TIMER_REG: 7484c99db8SAshish Jangam case DA9052_BUCKA_REG: 7584c99db8SAshish Jangam case DA9052_BUCKB_REG: 7684c99db8SAshish Jangam case DA9052_BUCKCORE_REG: 7784c99db8SAshish Jangam case DA9052_BUCKPRO_REG: 7884c99db8SAshish Jangam case DA9052_BUCKMEM_REG: 7984c99db8SAshish Jangam case DA9052_BUCKPERI_REG: 8084c99db8SAshish Jangam case DA9052_LDO1_REG: 8184c99db8SAshish Jangam case DA9052_LDO2_REG: 8284c99db8SAshish Jangam case DA9052_LDO3_REG: 8384c99db8SAshish Jangam case DA9052_LDO4_REG: 8484c99db8SAshish Jangam case DA9052_LDO5_REG: 8584c99db8SAshish Jangam case DA9052_LDO6_REG: 8684c99db8SAshish Jangam case DA9052_LDO7_REG: 8784c99db8SAshish Jangam case DA9052_LDO8_REG: 8884c99db8SAshish Jangam case DA9052_LDO9_REG: 8984c99db8SAshish Jangam case DA9052_LDO10_REG: 9084c99db8SAshish Jangam case DA9052_SUPPLY_REG: 9184c99db8SAshish Jangam case DA9052_PULLDOWN_REG: 9284c99db8SAshish Jangam case DA9052_CHGBUCK_REG: 9384c99db8SAshish Jangam case DA9052_WAITCONT_REG: 9484c99db8SAshish Jangam case DA9052_ISET_REG: 9584c99db8SAshish Jangam case DA9052_BATCHG_REG: 9684c99db8SAshish Jangam case DA9052_CHG_CONT_REG: 9784c99db8SAshish Jangam case DA9052_INPUT_CONT_REG: 9884c99db8SAshish Jangam case DA9052_CHG_TIME_REG: 9984c99db8SAshish Jangam case DA9052_BBAT_CONT_REG: 10084c99db8SAshish Jangam case DA9052_BOOST_REG: 10184c99db8SAshish Jangam case DA9052_LED_CONT_REG: 10284c99db8SAshish Jangam case DA9052_LEDMIN123_REG: 10384c99db8SAshish Jangam case DA9052_LED1_CONF_REG: 10484c99db8SAshish Jangam case DA9052_LED2_CONF_REG: 10584c99db8SAshish Jangam case DA9052_LED3_CONF_REG: 10684c99db8SAshish Jangam case DA9052_LED1CONT_REG: 10784c99db8SAshish Jangam case DA9052_LED2CONT_REG: 10884c99db8SAshish Jangam case DA9052_LED3CONT_REG: 10984c99db8SAshish Jangam case DA9052_LED_CONT_4_REG: 11084c99db8SAshish Jangam case DA9052_LED_CONT_5_REG: 11184c99db8SAshish Jangam case DA9052_ADC_MAN_REG: 11284c99db8SAshish Jangam case DA9052_ADC_CONT_REG: 11384c99db8SAshish Jangam case DA9052_ADC_RES_L_REG: 11484c99db8SAshish Jangam case DA9052_ADC_RES_H_REG: 11584c99db8SAshish Jangam case DA9052_VDD_RES_REG: 11684c99db8SAshish Jangam case DA9052_VDD_MON_REG: 11784c99db8SAshish Jangam case DA9052_ICHG_AV_REG: 11884c99db8SAshish Jangam case DA9052_ICHG_THD_REG: 11984c99db8SAshish Jangam case DA9052_ICHG_END_REG: 12084c99db8SAshish Jangam case DA9052_TBAT_RES_REG: 12184c99db8SAshish Jangam case DA9052_TBAT_HIGHP_REG: 12284c99db8SAshish Jangam case DA9052_TBAT_HIGHN_REG: 12384c99db8SAshish Jangam case DA9052_TBAT_LOW_REG: 12484c99db8SAshish Jangam case DA9052_T_OFFSET_REG: 12584c99db8SAshish Jangam case DA9052_ADCIN4_RES_REG: 12684c99db8SAshish Jangam case DA9052_AUTO4_HIGH_REG: 12784c99db8SAshish Jangam case DA9052_AUTO4_LOW_REG: 12884c99db8SAshish Jangam case DA9052_ADCIN5_RES_REG: 12984c99db8SAshish Jangam case DA9052_AUTO5_HIGH_REG: 13084c99db8SAshish Jangam case DA9052_AUTO5_LOW_REG: 13184c99db8SAshish Jangam case DA9052_ADCIN6_RES_REG: 13284c99db8SAshish Jangam case DA9052_AUTO6_HIGH_REG: 13384c99db8SAshish Jangam case DA9052_AUTO6_LOW_REG: 13484c99db8SAshish Jangam case DA9052_TJUNC_RES_REG: 13584c99db8SAshish Jangam case DA9052_TSI_CONT_A_REG: 13684c99db8SAshish Jangam case DA9052_TSI_CONT_B_REG: 13784c99db8SAshish Jangam case DA9052_TSI_X_MSB_REG: 13884c99db8SAshish Jangam case DA9052_TSI_Y_MSB_REG: 13984c99db8SAshish Jangam case DA9052_TSI_LSB_REG: 14084c99db8SAshish Jangam case DA9052_TSI_Z_MSB_REG: 14184c99db8SAshish Jangam case DA9052_COUNT_S_REG: 14284c99db8SAshish Jangam case DA9052_COUNT_MI_REG: 14384c99db8SAshish Jangam case DA9052_COUNT_H_REG: 14484c99db8SAshish Jangam case DA9052_COUNT_D_REG: 14584c99db8SAshish Jangam case DA9052_COUNT_MO_REG: 14684c99db8SAshish Jangam case DA9052_COUNT_Y_REG: 14784c99db8SAshish Jangam case DA9052_ALARM_MI_REG: 14884c99db8SAshish Jangam case DA9052_ALARM_H_REG: 14984c99db8SAshish Jangam case DA9052_ALARM_D_REG: 15084c99db8SAshish Jangam case DA9052_ALARM_MO_REG: 15184c99db8SAshish Jangam case DA9052_ALARM_Y_REG: 15284c99db8SAshish Jangam case DA9052_SECOND_A_REG: 15384c99db8SAshish Jangam case DA9052_SECOND_B_REG: 15484c99db8SAshish Jangam case DA9052_SECOND_C_REG: 15584c99db8SAshish Jangam case DA9052_SECOND_D_REG: 15684c99db8SAshish Jangam case DA9052_PAGE1_CON_REG: 15784c99db8SAshish Jangam return true; 15884c99db8SAshish Jangam default: 15984c99db8SAshish Jangam return false; 16084c99db8SAshish Jangam } 16184c99db8SAshish Jangam } 16284c99db8SAshish Jangam 16384c99db8SAshish Jangam static bool da9052_reg_writeable(struct device *dev, unsigned int reg) 16484c99db8SAshish Jangam { 16584c99db8SAshish Jangam switch (reg) { 16684c99db8SAshish Jangam case DA9052_PAGE0_CON_REG: 1670a92815dSAshish Jangam case DA9052_EVENT_A_REG: 1680a92815dSAshish Jangam case DA9052_EVENT_B_REG: 1690a92815dSAshish Jangam case DA9052_EVENT_C_REG: 1700a92815dSAshish Jangam case DA9052_EVENT_D_REG: 171547120edSSteve Twiss case DA9052_FAULTLOG_REG: 17284c99db8SAshish Jangam case DA9052_IRQ_MASK_A_REG: 17384c99db8SAshish Jangam case DA9052_IRQ_MASK_B_REG: 17484c99db8SAshish Jangam case DA9052_IRQ_MASK_C_REG: 17584c99db8SAshish Jangam case DA9052_IRQ_MASK_D_REG: 17684c99db8SAshish Jangam case DA9052_CONTROL_A_REG: 17784c99db8SAshish Jangam case DA9052_CONTROL_B_REG: 17884c99db8SAshish Jangam case DA9052_CONTROL_C_REG: 17984c99db8SAshish Jangam case DA9052_CONTROL_D_REG: 18084c99db8SAshish Jangam case DA9052_PDDIS_REG: 18184c99db8SAshish Jangam case DA9052_RESET_REG: 18284c99db8SAshish Jangam case DA9052_GPIO_0_1_REG: 18384c99db8SAshish Jangam case DA9052_GPIO_2_3_REG: 18484c99db8SAshish Jangam case DA9052_GPIO_4_5_REG: 18584c99db8SAshish Jangam case DA9052_GPIO_6_7_REG: 1860386af30SSteve Twiss case DA9052_GPIO_8_9_REG: 1870386af30SSteve Twiss case DA9052_GPIO_10_11_REG: 1880386af30SSteve Twiss case DA9052_GPIO_12_13_REG: 18984c99db8SAshish Jangam case DA9052_GPIO_14_15_REG: 19084c99db8SAshish Jangam case DA9052_ID_0_1_REG: 19184c99db8SAshish Jangam case DA9052_ID_2_3_REG: 19284c99db8SAshish Jangam case DA9052_ID_4_5_REG: 19384c99db8SAshish Jangam case DA9052_ID_6_7_REG: 19484c99db8SAshish Jangam case DA9052_ID_8_9_REG: 19584c99db8SAshish Jangam case DA9052_ID_10_11_REG: 19684c99db8SAshish Jangam case DA9052_ID_12_13_REG: 19784c99db8SAshish Jangam case DA9052_ID_14_15_REG: 19884c99db8SAshish Jangam case DA9052_ID_16_17_REG: 19984c99db8SAshish Jangam case DA9052_ID_18_19_REG: 20084c99db8SAshish Jangam case DA9052_ID_20_21_REG: 20184c99db8SAshish Jangam case DA9052_SEQ_STATUS_REG: 20284c99db8SAshish Jangam case DA9052_SEQ_A_REG: 20384c99db8SAshish Jangam case DA9052_SEQ_B_REG: 20484c99db8SAshish Jangam case DA9052_SEQ_TIMER_REG: 20584c99db8SAshish Jangam case DA9052_BUCKA_REG: 20684c99db8SAshish Jangam case DA9052_BUCKB_REG: 20784c99db8SAshish Jangam case DA9052_BUCKCORE_REG: 20884c99db8SAshish Jangam case DA9052_BUCKPRO_REG: 20984c99db8SAshish Jangam case DA9052_BUCKMEM_REG: 21084c99db8SAshish Jangam case DA9052_BUCKPERI_REG: 21184c99db8SAshish Jangam case DA9052_LDO1_REG: 21284c99db8SAshish Jangam case DA9052_LDO2_REG: 21384c99db8SAshish Jangam case DA9052_LDO3_REG: 21484c99db8SAshish Jangam case DA9052_LDO4_REG: 21584c99db8SAshish Jangam case DA9052_LDO5_REG: 21684c99db8SAshish Jangam case DA9052_LDO6_REG: 21784c99db8SAshish Jangam case DA9052_LDO7_REG: 21884c99db8SAshish Jangam case DA9052_LDO8_REG: 21984c99db8SAshish Jangam case DA9052_LDO9_REG: 22084c99db8SAshish Jangam case DA9052_LDO10_REG: 22184c99db8SAshish Jangam case DA9052_SUPPLY_REG: 22284c99db8SAshish Jangam case DA9052_PULLDOWN_REG: 22384c99db8SAshish Jangam case DA9052_CHGBUCK_REG: 22484c99db8SAshish Jangam case DA9052_WAITCONT_REG: 22584c99db8SAshish Jangam case DA9052_ISET_REG: 22684c99db8SAshish Jangam case DA9052_BATCHG_REG: 22784c99db8SAshish Jangam case DA9052_CHG_CONT_REG: 22884c99db8SAshish Jangam case DA9052_INPUT_CONT_REG: 22984c99db8SAshish Jangam case DA9052_BBAT_CONT_REG: 23084c99db8SAshish Jangam case DA9052_BOOST_REG: 23184c99db8SAshish Jangam case DA9052_LED_CONT_REG: 23284c99db8SAshish Jangam case DA9052_LEDMIN123_REG: 23384c99db8SAshish Jangam case DA9052_LED1_CONF_REG: 23484c99db8SAshish Jangam case DA9052_LED2_CONF_REG: 23584c99db8SAshish Jangam case DA9052_LED3_CONF_REG: 23684c99db8SAshish Jangam case DA9052_LED1CONT_REG: 23784c99db8SAshish Jangam case DA9052_LED2CONT_REG: 23884c99db8SAshish Jangam case DA9052_LED3CONT_REG: 23984c99db8SAshish Jangam case DA9052_LED_CONT_4_REG: 24084c99db8SAshish Jangam case DA9052_LED_CONT_5_REG: 24184c99db8SAshish Jangam case DA9052_ADC_MAN_REG: 24284c99db8SAshish Jangam case DA9052_ADC_CONT_REG: 24384c99db8SAshish Jangam case DA9052_ADC_RES_L_REG: 24484c99db8SAshish Jangam case DA9052_ADC_RES_H_REG: 24584c99db8SAshish Jangam case DA9052_VDD_RES_REG: 24684c99db8SAshish Jangam case DA9052_VDD_MON_REG: 24784c99db8SAshish Jangam case DA9052_ICHG_THD_REG: 24884c99db8SAshish Jangam case DA9052_ICHG_END_REG: 24984c99db8SAshish Jangam case DA9052_TBAT_HIGHP_REG: 25084c99db8SAshish Jangam case DA9052_TBAT_HIGHN_REG: 25184c99db8SAshish Jangam case DA9052_TBAT_LOW_REG: 25284c99db8SAshish Jangam case DA9052_T_OFFSET_REG: 25384c99db8SAshish Jangam case DA9052_AUTO4_HIGH_REG: 25484c99db8SAshish Jangam case DA9052_AUTO4_LOW_REG: 25584c99db8SAshish Jangam case DA9052_AUTO5_HIGH_REG: 25684c99db8SAshish Jangam case DA9052_AUTO5_LOW_REG: 25784c99db8SAshish Jangam case DA9052_AUTO6_HIGH_REG: 25884c99db8SAshish Jangam case DA9052_AUTO6_LOW_REG: 25984c99db8SAshish Jangam case DA9052_TSI_CONT_A_REG: 26084c99db8SAshish Jangam case DA9052_TSI_CONT_B_REG: 26184c99db8SAshish Jangam case DA9052_COUNT_S_REG: 26284c99db8SAshish Jangam case DA9052_COUNT_MI_REG: 26384c99db8SAshish Jangam case DA9052_COUNT_H_REG: 26484c99db8SAshish Jangam case DA9052_COUNT_D_REG: 26584c99db8SAshish Jangam case DA9052_COUNT_MO_REG: 26684c99db8SAshish Jangam case DA9052_COUNT_Y_REG: 26784c99db8SAshish Jangam case DA9052_ALARM_MI_REG: 26884c99db8SAshish Jangam case DA9052_ALARM_H_REG: 26984c99db8SAshish Jangam case DA9052_ALARM_D_REG: 27084c99db8SAshish Jangam case DA9052_ALARM_MO_REG: 27184c99db8SAshish Jangam case DA9052_ALARM_Y_REG: 27284c99db8SAshish Jangam case DA9052_PAGE1_CON_REG: 27384c99db8SAshish Jangam return true; 27484c99db8SAshish Jangam default: 27584c99db8SAshish Jangam return false; 27684c99db8SAshish Jangam } 27784c99db8SAshish Jangam } 27884c99db8SAshish Jangam 27984c99db8SAshish Jangam static bool da9052_reg_volatile(struct device *dev, unsigned int reg) 28084c99db8SAshish Jangam { 28184c99db8SAshish Jangam switch (reg) { 28284c99db8SAshish Jangam case DA9052_STATUS_A_REG: 28384c99db8SAshish Jangam case DA9052_STATUS_B_REG: 28484c99db8SAshish Jangam case DA9052_STATUS_C_REG: 28584c99db8SAshish Jangam case DA9052_STATUS_D_REG: 28684c99db8SAshish Jangam case DA9052_EVENT_A_REG: 28784c99db8SAshish Jangam case DA9052_EVENT_B_REG: 28884c99db8SAshish Jangam case DA9052_EVENT_C_REG: 28984c99db8SAshish Jangam case DA9052_EVENT_D_REG: 290bcb5a7d3Santhony.olech.opensource@diasemi.com case DA9052_CONTROL_B_REG: 291bcb5a7d3Santhony.olech.opensource@diasemi.com case DA9052_CONTROL_D_REG: 292bcb5a7d3Santhony.olech.opensource@diasemi.com case DA9052_SUPPLY_REG: 29384c99db8SAshish Jangam case DA9052_FAULTLOG_REG: 29484c99db8SAshish Jangam case DA9052_CHG_TIME_REG: 29584c99db8SAshish Jangam case DA9052_ADC_RES_L_REG: 29684c99db8SAshish Jangam case DA9052_ADC_RES_H_REG: 29784c99db8SAshish Jangam case DA9052_VDD_RES_REG: 29884c99db8SAshish Jangam case DA9052_ICHG_AV_REG: 29984c99db8SAshish Jangam case DA9052_TBAT_RES_REG: 30084c99db8SAshish Jangam case DA9052_ADCIN4_RES_REG: 30184c99db8SAshish Jangam case DA9052_ADCIN5_RES_REG: 30284c99db8SAshish Jangam case DA9052_ADCIN6_RES_REG: 30384c99db8SAshish Jangam case DA9052_TJUNC_RES_REG: 30484c99db8SAshish Jangam case DA9052_TSI_X_MSB_REG: 30584c99db8SAshish Jangam case DA9052_TSI_Y_MSB_REG: 30684c99db8SAshish Jangam case DA9052_TSI_LSB_REG: 30784c99db8SAshish Jangam case DA9052_TSI_Z_MSB_REG: 30884c99db8SAshish Jangam case DA9052_COUNT_S_REG: 30984c99db8SAshish Jangam case DA9052_COUNT_MI_REG: 31084c99db8SAshish Jangam case DA9052_COUNT_H_REG: 31184c99db8SAshish Jangam case DA9052_COUNT_D_REG: 31284c99db8SAshish Jangam case DA9052_COUNT_MO_REG: 31384c99db8SAshish Jangam case DA9052_COUNT_Y_REG: 31484c99db8SAshish Jangam case DA9052_ALARM_MI_REG: 31584c99db8SAshish Jangam return true; 31684c99db8SAshish Jangam default: 31784c99db8SAshish Jangam return false; 31884c99db8SAshish Jangam } 31984c99db8SAshish Jangam } 32084c99db8SAshish Jangam 32116e5e204SAshish Jangam /* 32216e5e204SAshish Jangam * TBAT look-up table is computed from the R90 reg (8 bit register) 32316e5e204SAshish Jangam * reading as below. The battery temperature is in milliCentigrade 32416e5e204SAshish Jangam * TBAT = (1/(t1+1/298) - 273) * 1000 mC 32516e5e204SAshish Jangam * where t1 = (1/B)* ln(( ADCval * 2.5)/(R25*ITBAT*255)) 32616e5e204SAshish Jangam * Default values are R25 = 10e3, B = 3380, ITBAT = 50e-6 32716e5e204SAshish Jangam * Example: 32816e5e204SAshish Jangam * R25=10E3, B=3380, ITBAT=50e-6, ADCVAL=62d calculates 32916e5e204SAshish Jangam * TBAT = 20015 mili degrees Centrigrade 33016e5e204SAshish Jangam * 33116e5e204SAshish Jangam */ 33216e5e204SAshish Jangam static const int32_t tbat_lookup[255] = { 33316e5e204SAshish Jangam 183258, 144221, 124334, 111336, 101826, 94397, 88343, 83257, 33416e5e204SAshish Jangam 78889, 75071, 71688, 68656, 65914, 63414, 61120, 59001, 33516e5e204SAshish Jangam 570366, 55204, 53490, 51881, 50364, 48931, 47574, 46285, 33616e5e204SAshish Jangam 45059, 43889, 42772, 41703, 40678, 39694, 38748, 37838, 33716e5e204SAshish Jangam 36961, 36115, 35297, 34507, 33743, 33002, 32284, 31588, 33816e5e204SAshish Jangam 30911, 30254, 29615, 28994, 28389, 27799, 27225, 26664, 33916e5e204SAshish Jangam 26117, 25584, 25062, 24553, 24054, 23567, 23091, 22624, 34016e5e204SAshish Jangam 22167, 21719, 21281, 20851, 20429, 20015, 19610, 19211, 34116e5e204SAshish Jangam 18820, 18436, 18058, 17688, 17323, 16965, 16612, 16266, 34216e5e204SAshish Jangam 15925, 15589, 15259, 14933, 14613, 14298, 13987, 13681, 34316e5e204SAshish Jangam 13379, 13082, 12788, 12499, 12214, 11933, 11655, 11382, 34416e5e204SAshish Jangam 11112, 10845, 10582, 10322, 10066, 9812, 9562, 9315, 34516e5e204SAshish Jangam 9071, 8830, 8591, 8356, 8123, 7893, 7665, 7440, 34616e5e204SAshish Jangam 7218, 6998, 6780, 6565, 6352, 6141, 5933, 5726, 34716e5e204SAshish Jangam 5522, 5320, 5120, 4922, 4726, 4532, 4340, 4149, 34816e5e204SAshish Jangam 3961, 3774, 3589, 3406, 3225, 3045, 2867, 2690, 34916e5e204SAshish Jangam 2516, 2342, 2170, 2000, 1831, 1664, 1498, 1334, 35016e5e204SAshish Jangam 1171, 1009, 849, 690, 532, 376, 221, 67, 35116e5e204SAshish Jangam -84, -236, -386, -535, -683, -830, -975, -1119, 35216e5e204SAshish Jangam -1263, -1405, -1546, -1686, -1825, -1964, -2101, -2237, 35316e5e204SAshish Jangam -2372, -2506, -2639, -2771, -2902, -3033, -3162, -3291, 35416e5e204SAshish Jangam -3418, -3545, -3671, -3796, -3920, -4044, -4166, -4288, 35516e5e204SAshish Jangam -4409, -4529, -4649, -4767, -4885, -5002, -5119, -5235, 35616e5e204SAshish Jangam -5349, -5464, -5577, -5690, -5802, -5913, -6024, -6134, 35716e5e204SAshish Jangam -6244, -6352, -6461, -6568, -6675, -6781, -6887, -6992, 35816e5e204SAshish Jangam -7096, -7200, -7303, -7406, -7508, -7609, -7710, -7810, 35916e5e204SAshish Jangam -7910, -8009, -8108, -8206, -8304, -8401, -8497, -8593, 36016e5e204SAshish Jangam -8689, -8784, -8878, -8972, -9066, -9159, -9251, -9343, 36116e5e204SAshish Jangam -9435, -9526, -9617, -9707, -9796, -9886, -9975, -10063, 36216e5e204SAshish Jangam -10151, -10238, -10325, -10412, -10839, -10923, -11007, -11090, 36316e5e204SAshish Jangam -11173, -11256, -11338, -11420, -11501, -11583, -11663, -11744, 36416e5e204SAshish Jangam -11823, -11903, -11982 36516e5e204SAshish Jangam }; 36616e5e204SAshish Jangam 36716e5e204SAshish Jangam static const u8 chan_mux[DA9052_ADC_VBBAT + 1] = { 36816e5e204SAshish Jangam [DA9052_ADC_VDDOUT] = DA9052_ADC_MAN_MUXSEL_VDDOUT, 36916e5e204SAshish Jangam [DA9052_ADC_ICH] = DA9052_ADC_MAN_MUXSEL_ICH, 37016e5e204SAshish Jangam [DA9052_ADC_TBAT] = DA9052_ADC_MAN_MUXSEL_TBAT, 37116e5e204SAshish Jangam [DA9052_ADC_VBAT] = DA9052_ADC_MAN_MUXSEL_VBAT, 37216e5e204SAshish Jangam [DA9052_ADC_IN4] = DA9052_ADC_MAN_MUXSEL_AD4, 37316e5e204SAshish Jangam [DA9052_ADC_IN5] = DA9052_ADC_MAN_MUXSEL_AD5, 37416e5e204SAshish Jangam [DA9052_ADC_IN6] = DA9052_ADC_MAN_MUXSEL_AD6, 37516e5e204SAshish Jangam [DA9052_ADC_VBBAT] = DA9052_ADC_MAN_MUXSEL_VBBAT 37616e5e204SAshish Jangam }; 37716e5e204SAshish Jangam 37816e5e204SAshish Jangam int da9052_adc_manual_read(struct da9052 *da9052, unsigned char channel) 37916e5e204SAshish Jangam { 38016e5e204SAshish Jangam int ret; 38116e5e204SAshish Jangam unsigned short calc_data; 38216e5e204SAshish Jangam unsigned short data; 38316e5e204SAshish Jangam unsigned char mux_sel; 38416e5e204SAshish Jangam 38516e5e204SAshish Jangam if (channel > DA9052_ADC_VBBAT) 38616e5e204SAshish Jangam return -EINVAL; 38716e5e204SAshish Jangam 38816e5e204SAshish Jangam mutex_lock(&da9052->auxadc_lock); 38916e5e204SAshish Jangam 390*45f80a9fSSebastian Reichel reinit_completion(&da9052->done); 391*45f80a9fSSebastian Reichel 39216e5e204SAshish Jangam /* Channel gets activated on enabling the Conversion bit */ 39316e5e204SAshish Jangam mux_sel = chan_mux[channel] | DA9052_ADC_MAN_MAN_CONV; 39416e5e204SAshish Jangam 39516e5e204SAshish Jangam ret = da9052_reg_write(da9052, DA9052_ADC_MAN_REG, mux_sel); 39616e5e204SAshish Jangam if (ret < 0) 39716e5e204SAshish Jangam goto err; 39816e5e204SAshish Jangam 39916e5e204SAshish Jangam /* Wait for an interrupt */ 40016e5e204SAshish Jangam if (!wait_for_completion_timeout(&da9052->done, 40116e5e204SAshish Jangam msecs_to_jiffies(500))) { 40216e5e204SAshish Jangam dev_err(da9052->dev, 40316e5e204SAshish Jangam "timeout waiting for ADC conversion interrupt\n"); 40416e5e204SAshish Jangam ret = -ETIMEDOUT; 40516e5e204SAshish Jangam goto err; 40616e5e204SAshish Jangam } 40716e5e204SAshish Jangam 40816e5e204SAshish Jangam ret = da9052_reg_read(da9052, DA9052_ADC_RES_H_REG); 40916e5e204SAshish Jangam if (ret < 0) 41016e5e204SAshish Jangam goto err; 41116e5e204SAshish Jangam 41216e5e204SAshish Jangam calc_data = (unsigned short)ret; 41316e5e204SAshish Jangam data = calc_data << 2; 41416e5e204SAshish Jangam 41516e5e204SAshish Jangam ret = da9052_reg_read(da9052, DA9052_ADC_RES_L_REG); 41616e5e204SAshish Jangam if (ret < 0) 41716e5e204SAshish Jangam goto err; 41816e5e204SAshish Jangam 41916e5e204SAshish Jangam calc_data = (unsigned short)(ret & DA9052_ADC_RES_LSB); 42016e5e204SAshish Jangam data |= calc_data; 42116e5e204SAshish Jangam 42216e5e204SAshish Jangam ret = data; 42316e5e204SAshish Jangam 42416e5e204SAshish Jangam err: 42516e5e204SAshish Jangam mutex_unlock(&da9052->auxadc_lock); 42616e5e204SAshish Jangam return ret; 42716e5e204SAshish Jangam } 42816e5e204SAshish Jangam EXPORT_SYMBOL_GPL(da9052_adc_manual_read); 42916e5e204SAshish Jangam 43016e5e204SAshish Jangam int da9052_adc_read_temp(struct da9052 *da9052) 43116e5e204SAshish Jangam { 43216e5e204SAshish Jangam int tbat; 43316e5e204SAshish Jangam 43416e5e204SAshish Jangam tbat = da9052_reg_read(da9052, DA9052_TBAT_RES_REG); 43516e5e204SAshish Jangam if (tbat <= 0) 43616e5e204SAshish Jangam return tbat; 43716e5e204SAshish Jangam 43816e5e204SAshish Jangam /* ARRAY_SIZE check is not needed since TBAT is a 8-bit register */ 43916e5e204SAshish Jangam return tbat_lookup[tbat - 1]; 44016e5e204SAshish Jangam } 44116e5e204SAshish Jangam EXPORT_SYMBOL_GPL(da9052_adc_read_temp); 44216e5e204SAshish Jangam 443c8f675ffSGeert Uytterhoeven static const struct mfd_cell da9052_subdev_info[] = { 44484c99db8SAshish Jangam { 44584c99db8SAshish Jangam .name = "da9052-regulator", 446e0c21530SJohan Hovold .id = 0, 447e0c21530SJohan Hovold }, 448e0c21530SJohan Hovold { 449e0c21530SJohan Hovold .name = "da9052-regulator", 45084c99db8SAshish Jangam .id = 1, 45184c99db8SAshish Jangam }, 45284c99db8SAshish Jangam { 45384c99db8SAshish Jangam .name = "da9052-regulator", 45484c99db8SAshish Jangam .id = 2, 45584c99db8SAshish Jangam }, 45684c99db8SAshish Jangam { 45784c99db8SAshish Jangam .name = "da9052-regulator", 45884c99db8SAshish Jangam .id = 3, 45984c99db8SAshish Jangam }, 46084c99db8SAshish Jangam { 46184c99db8SAshish Jangam .name = "da9052-regulator", 46284c99db8SAshish Jangam .id = 4, 46384c99db8SAshish Jangam }, 46484c99db8SAshish Jangam { 46584c99db8SAshish Jangam .name = "da9052-regulator", 46684c99db8SAshish Jangam .id = 5, 46784c99db8SAshish Jangam }, 46884c99db8SAshish Jangam { 46984c99db8SAshish Jangam .name = "da9052-regulator", 47084c99db8SAshish Jangam .id = 6, 47184c99db8SAshish Jangam }, 47284c99db8SAshish Jangam { 47384c99db8SAshish Jangam .name = "da9052-regulator", 47484c99db8SAshish Jangam .id = 7, 47584c99db8SAshish Jangam }, 47684c99db8SAshish Jangam { 47784c99db8SAshish Jangam .name = "da9052-regulator", 47884c99db8SAshish Jangam .id = 8, 47984c99db8SAshish Jangam }, 48084c99db8SAshish Jangam { 48184c99db8SAshish Jangam .name = "da9052-regulator", 48284c99db8SAshish Jangam .id = 9, 48384c99db8SAshish Jangam }, 48484c99db8SAshish Jangam { 48584c99db8SAshish Jangam .name = "da9052-regulator", 48684c99db8SAshish Jangam .id = 10, 48784c99db8SAshish Jangam }, 48884c99db8SAshish Jangam { 48984c99db8SAshish Jangam .name = "da9052-regulator", 49084c99db8SAshish Jangam .id = 11, 49184c99db8SAshish Jangam }, 49284c99db8SAshish Jangam { 49384c99db8SAshish Jangam .name = "da9052-regulator", 49484c99db8SAshish Jangam .id = 12, 49584c99db8SAshish Jangam }, 49684c99db8SAshish Jangam { 49784c99db8SAshish Jangam .name = "da9052-regulator", 49884c99db8SAshish Jangam .id = 13, 49984c99db8SAshish Jangam }, 50084c99db8SAshish Jangam { 50184c99db8SAshish Jangam .name = "da9052-onkey", 50284c99db8SAshish Jangam }, 50384c99db8SAshish Jangam { 50484c99db8SAshish Jangam .name = "da9052-rtc", 50584c99db8SAshish Jangam }, 50684c99db8SAshish Jangam { 50784c99db8SAshish Jangam .name = "da9052-gpio", 50884c99db8SAshish Jangam }, 50984c99db8SAshish Jangam { 51084c99db8SAshish Jangam .name = "da9052-hwmon", 51184c99db8SAshish Jangam }, 51284c99db8SAshish Jangam { 51384c99db8SAshish Jangam .name = "da9052-leds", 51484c99db8SAshish Jangam }, 51584c99db8SAshish Jangam { 51684c99db8SAshish Jangam .name = "da9052-wled1", 51784c99db8SAshish Jangam }, 51884c99db8SAshish Jangam { 51984c99db8SAshish Jangam .name = "da9052-wled2", 52084c99db8SAshish Jangam }, 52184c99db8SAshish Jangam { 52284c99db8SAshish Jangam .name = "da9052-wled3", 52384c99db8SAshish Jangam }, 52484c99db8SAshish Jangam { 52584c99db8SAshish Jangam .name = "da9052-bat", 52684c99db8SAshish Jangam }, 52784c99db8SAshish Jangam { 52884c99db8SAshish Jangam .name = "da9052-watchdog", 52984c99db8SAshish Jangam }, 53084c99db8SAshish Jangam }; 53184c99db8SAshish Jangam 532ebf55511SSebastian Reichel static const struct mfd_cell da9052_tsi_subdev_info[] = { 533ebf55511SSebastian Reichel { .name = "da9052-tsi" }, 534ebf55511SSebastian Reichel }; 535ebf55511SSebastian Reichel 536e9e9d397SAxel Lin const struct regmap_config da9052_regmap_config = { 53784c99db8SAshish Jangam .reg_bits = 8, 53884c99db8SAshish Jangam .val_bits = 8, 53984c99db8SAshish Jangam 54084c99db8SAshish Jangam .cache_type = REGCACHE_RBTREE, 54184c99db8SAshish Jangam 54284c99db8SAshish Jangam .max_register = DA9052_PAGE1_CON_REG, 54384c99db8SAshish Jangam .readable_reg = da9052_reg_readable, 54484c99db8SAshish Jangam .writeable_reg = da9052_reg_writeable, 54584c99db8SAshish Jangam .volatile_reg = da9052_reg_volatile, 54684c99db8SAshish Jangam }; 54784c99db8SAshish Jangam EXPORT_SYMBOL_GPL(da9052_regmap_config); 54884c99db8SAshish Jangam 549547120edSSteve Twiss static int da9052_clear_fault_log(struct da9052 *da9052) 550547120edSSteve Twiss { 551547120edSSteve Twiss int ret = 0; 552547120edSSteve Twiss int fault_log = 0; 553547120edSSteve Twiss 554547120edSSteve Twiss fault_log = da9052_reg_read(da9052, DA9052_FAULTLOG_REG); 555547120edSSteve Twiss if (fault_log < 0) { 556547120edSSteve Twiss dev_err(da9052->dev, 557547120edSSteve Twiss "Cannot read FAULT_LOG %d\n", fault_log); 558547120edSSteve Twiss return fault_log; 559547120edSSteve Twiss } 560547120edSSteve Twiss 561547120edSSteve Twiss if (fault_log) { 562547120edSSteve Twiss if (fault_log & DA9052_FAULTLOG_TWDERROR) 563547120edSSteve Twiss dev_dbg(da9052->dev, 564547120edSSteve Twiss "Fault log entry detected: TWD_ERROR\n"); 565547120edSSteve Twiss if (fault_log & DA9052_FAULTLOG_VDDFAULT) 566547120edSSteve Twiss dev_dbg(da9052->dev, 567547120edSSteve Twiss "Fault log entry detected: VDD_FAULT\n"); 568547120edSSteve Twiss if (fault_log & DA9052_FAULTLOG_VDDSTART) 569547120edSSteve Twiss dev_dbg(da9052->dev, 570547120edSSteve Twiss "Fault log entry detected: VDD_START\n"); 571547120edSSteve Twiss if (fault_log & DA9052_FAULTLOG_TEMPOVER) 572547120edSSteve Twiss dev_dbg(da9052->dev, 573547120edSSteve Twiss "Fault log entry detected: TEMP_OVER\n"); 574547120edSSteve Twiss if (fault_log & DA9052_FAULTLOG_KEYSHUT) 575547120edSSteve Twiss dev_dbg(da9052->dev, 576547120edSSteve Twiss "Fault log entry detected: KEY_SHUT\n"); 577547120edSSteve Twiss if (fault_log & DA9052_FAULTLOG_NSDSET) 578547120edSSteve Twiss dev_dbg(da9052->dev, 579547120edSSteve Twiss "Fault log entry detected: nSD_SHUT\n"); 580547120edSSteve Twiss if (fault_log & DA9052_FAULTLOG_WAITSET) 581547120edSSteve Twiss dev_dbg(da9052->dev, 582547120edSSteve Twiss "Fault log entry detected: WAIT_SHUT\n"); 583547120edSSteve Twiss 584547120edSSteve Twiss ret = da9052_reg_write(da9052, 585547120edSSteve Twiss DA9052_FAULTLOG_REG, 586547120edSSteve Twiss 0xFF); 587547120edSSteve Twiss if (ret < 0) 588547120edSSteve Twiss dev_err(da9052->dev, 589547120edSSteve Twiss "Cannot reset FAULT_LOG values %d\n", ret); 590547120edSSteve Twiss } 591547120edSSteve Twiss 592547120edSSteve Twiss return ret; 593547120edSSteve Twiss } 594547120edSSteve Twiss 595f791be49SBill Pemberton int da9052_device_init(struct da9052 *da9052, u8 chip_id) 59684c99db8SAshish Jangam { 597334a41ceSJingoo Han struct da9052_pdata *pdata = dev_get_platdata(da9052->dev); 59884c99db8SAshish Jangam int ret; 59984c99db8SAshish Jangam 60016e5e204SAshish Jangam mutex_init(&da9052->auxadc_lock); 60116e5e204SAshish Jangam init_completion(&da9052->done); 60216e5e204SAshish Jangam 603547120edSSteve Twiss ret = da9052_clear_fault_log(da9052); 604547120edSSteve Twiss if (ret < 0) 605547120edSSteve Twiss dev_warn(da9052->dev, "Cannot clear FAULT_LOG\n"); 606547120edSSteve Twiss 60784c99db8SAshish Jangam if (pdata && pdata->init != NULL) 60884c99db8SAshish Jangam pdata->init(da9052); 60984c99db8SAshish Jangam 61084c99db8SAshish Jangam da9052->chip_id = chip_id; 61184c99db8SAshish Jangam 6128bad1abdSFabio Estevam ret = da9052_irq_init(da9052); 6138bad1abdSFabio Estevam if (ret != 0) { 6148bad1abdSFabio Estevam dev_err(da9052->dev, "da9052_irq_init failed: %d\n", ret); 6158bad1abdSFabio Estevam return ret; 616ffe20b68SFabio Estevam } 61716e5e204SAshish Jangam 618b3f6c73dSFabio Estevam ret = mfd_add_devices(da9052->dev, PLATFORM_DEVID_AUTO, 619b3f6c73dSFabio Estevam da9052_subdev_info, 6200848c94fSMark Brown ARRAY_SIZE(da9052_subdev_info), NULL, 0, NULL); 621ffe20b68SFabio Estevam if (ret) { 622ffe20b68SFabio Estevam dev_err(da9052->dev, "mfd_add_devices failed: %d\n", ret); 62384c99db8SAshish Jangam goto err; 624ffe20b68SFabio Estevam } 62584c99db8SAshish Jangam 626ebf55511SSebastian Reichel /* 627ebf55511SSebastian Reichel * Check if touchscreen pins are used are analogue input instead 628ebf55511SSebastian Reichel * of having a touchscreen connected to them. The analogue input 629ebf55511SSebastian Reichel * functionality will be provided by hwmon driver (if enabled). 630ebf55511SSebastian Reichel */ 631ebf55511SSebastian Reichel if (!device_property_read_bool(da9052->dev, "dlg,tsi-as-adc")) { 632ebf55511SSebastian Reichel ret = mfd_add_devices(da9052->dev, PLATFORM_DEVID_AUTO, 633ebf55511SSebastian Reichel da9052_tsi_subdev_info, 634ebf55511SSebastian Reichel ARRAY_SIZE(da9052_tsi_subdev_info), 635ebf55511SSebastian Reichel NULL, 0, NULL); 636ebf55511SSebastian Reichel if (ret) { 637ebf55511SSebastian Reichel dev_err(da9052->dev, "failed to add TSI subdev: %d\n", 638ebf55511SSebastian Reichel ret); 639ebf55511SSebastian Reichel goto err; 640ebf55511SSebastian Reichel } 641ebf55511SSebastian Reichel } 642ebf55511SSebastian Reichel 64384c99db8SAshish Jangam return 0; 64484c99db8SAshish Jangam 64584c99db8SAshish Jangam err: 646ebf55511SSebastian Reichel mfd_remove_devices(da9052->dev); 6478bad1abdSFabio Estevam da9052_irq_exit(da9052); 6488bad1abdSFabio Estevam 64984c99db8SAshish Jangam return ret; 65084c99db8SAshish Jangam } 65184c99db8SAshish Jangam 65284c99db8SAshish Jangam void da9052_device_exit(struct da9052 *da9052) 65384c99db8SAshish Jangam { 65484c99db8SAshish Jangam mfd_remove_devices(da9052->dev); 6558bad1abdSFabio Estevam da9052_irq_exit(da9052); 65684c99db8SAshish Jangam } 65784c99db8SAshish Jangam 65884c99db8SAshish Jangam MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>"); 65984c99db8SAshish Jangam MODULE_DESCRIPTION("DA9052 MFD Core"); 66084c99db8SAshish Jangam MODULE_LICENSE("GPL"); 661