1/* 2 * Copyright (C) 2010 ST-Ericsson SA 3 * Licensed under GPLv2. 4 * 5 * Author: Arun R Murthy <arun.murthy@stericsson.com> 6 * Author: Daniel Willerud <daniel.willerud@stericsson.com> 7 * Author: M'boumba Cedric Madianga <cedric.madianga@stericsson.com> 8 */ 9 10#ifndef _AB8500_GPADC_H 11#define _AB8500_GPADC_H 12 13/* GPADC source: From datasheet(ADCSwSel[4:0] in GPADCCtrl2 14 * and ADCHwSel[4:0] in GPADCCtrl3 ) */ 15#define BAT_CTRL 0x01 16#define BTEMP_BALL 0x02 17#define MAIN_CHARGER_V 0x03 18#define ACC_DETECT1 0x04 19#define ACC_DETECT2 0x05 20#define ADC_AUX1 0x06 21#define ADC_AUX2 0x07 22#define MAIN_BAT_V 0x08 23#define VBUS_V 0x09 24#define MAIN_CHARGER_C 0x0A 25#define USB_CHARGER_C 0x0B 26#define BK_BAT_V 0x0C 27#define DIE_TEMP 0x0D 28#define USB_ID 0x0E 29#define XTAL_TEMP 0x12 30#define VBAT_TRUE_MEAS 0x13 31#define BAT_CTRL_AND_IBAT 0x1C 32#define VBAT_MEAS_AND_IBAT 0x1D 33#define VBAT_TRUE_MEAS_AND_IBAT 0x1E 34#define BAT_TEMP_AND_IBAT 0x1F 35 36/* Virtual channel used only for ibat convertion to ampere 37 * Battery current conversion (ibat) cannot be requested as a single conversion 38 * but it is always in combination with other input requests 39 */ 40#define IBAT_VIRTUAL_CHANNEL 0xFF 41 42#define SAMPLE_1 1 43#define SAMPLE_4 4 44#define SAMPLE_8 8 45#define SAMPLE_16 16 46#define RISING_EDGE 0 47#define FALLING_EDGE 1 48 49/* Arbitrary ADC conversion type constants */ 50#define ADC_SW 0 51#define ADC_HW 1 52 53struct ab8500_gpadc; 54 55struct ab8500_gpadc *ab8500_gpadc_get(char *name); 56int ab8500_gpadc_sw_hw_convert(struct ab8500_gpadc *gpadc, u8 channel, 57 u8 avg_sample, u8 trig_edge, u8 trig_timer, u8 conv_type); 58static inline int ab8500_gpadc_convert(struct ab8500_gpadc *gpadc, u8 channel) 59{ 60 return ab8500_gpadc_sw_hw_convert(gpadc, channel, 61 SAMPLE_16, 0, 0, ADC_SW); 62} 63 64int ab8500_gpadc_read_raw(struct ab8500_gpadc *gpadc, u8 channel, 65 u8 avg_sample, u8 trig_edge, u8 trig_timer, u8 conv_type); 66int ab8500_gpadc_double_read_raw(struct ab8500_gpadc *gpadc, u8 channel, 67 u8 avg_sample, u8 trig_edge, u8 trig_timer, u8 conv_type, 68 int *ibat); 69int ab8500_gpadc_ad_to_voltage(struct ab8500_gpadc *gpadc, 70 u8 channel, int ad_value); 71void ab8540_gpadc_get_otp(struct ab8500_gpadc *gpadc, 72 u16 *vmain_l, u16 *vmain_h, u16 *btemp_l, u16 *btemp_h, 73 u16 *vbat_l, u16 *vbat_h, u16 *ibat_l, u16 *ibat_h); 74 75#endif /* _AB8500_GPADC_H */ 76