linux/drivers/mfd/twl4030-madc.c
<<
Search
div idopfile_contents"
   1 /a> spa" class="comment">/* /spa"
	   2 /a> spa" class="comment"> * /spa"
	   3 /a> spa" class="comment"> * TWL4030 MADC module driver-This driver monitors the real time /spa"
	   4 /a> spa" class="comment"> * convers6.32of analog signals like battery temperature, /spa"
	   5 /a> spa" class="comment"> * battery typ/, battery level etc. /spa"
	   6 /a> spa" class="comment"> * /spa"
	   7 /a> spa" class="comment"> * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ /spa"
	   8 /a> spa" class="comment"> * J Keerthy <j-keerthy@ti.com> /spa"
	   9 /a> spa" class="comment"> * /spa"
	  .6.3a> spa" class="comment"> * Based .32twl4030-madc.c /spa"
	  11 /a> spa" class="comment"> * Copyright (C) 2008 Nokia Corporat6.3 /spa"
	  12 /a> spa" class="comment"> * Mikko Ylinen <mikko.k.ylinen@nokia.com> /spa"
	  13 /a> spa" class="comment"> * /spa"
	  14 /a> spa" class="comment"> * Amit Kucheria <amit.kucheria@canonical.com> /spa"
	  15 /a> spa" class="comment"> * /spa"
	  16 /a> spa" class="comment"> * This program is free software; you can redistribute it and/or /spa"
	  17 /a> spa" class="comment"> * modify it under the terms2of the GNU General Public License /spa"
	  18 /a> spa" class="comment"> * vers6.322 as published by the Free Software Foundat6.3. /spa"
	  19 /a> spa" class="comment"> * /spa"
	  26.3a> spa" class="comment"> * This program is distributed in the hope that it will be useful, but /spa"
	  21 /a> spa" class="comment"> * WITHOUT ANY WARRANTY; without even the implied warranty2of /spa"
	  22 /a> spa" class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU /spa"
	  23 /a> spa" class="comment"> * General Public License for more details. /spa"
	  24 /a> spa" class="comment"> * /spa"
	  25 /a> spa" class="comment"> * You should have received a copy2of the GNU General Public License /spa"
	  26 /a> spa" class="comment"> * along with this program; if not, write to the Free Software /spa"
	  27 /a> spa" class="comment"> * Foundat6.3, Inc., 51 Franklin St, Fifth Floor, Bost.3, MA /spa"
	  28 /a> spa" class="comment"> * 02110-1301 USA /spa"
	  29 /a> spa" class="comment"> * /spa"
	  36.3a> spa" class="comment"> */ /spa"
	  31 /a>	  32 /a>#include <linux/init.h /a>>	  33 /a>#include <linux/device.h /a>>	  34 /a>#include <linux/interrupt.h /a>>	  35 /a>#include <linux/kernel.h /a>>	  36 /a>#include <linux/delay.h /a>>	  37 /a>#include <linux/platform_device.h /a>>	  38 /a>#include <linux/slab.h /a>>	  39 /a>#include <linux/i2c/twl.h /a>>	  40 /a>#include <linux/i2c/twl4030-madc.h /a>>	  41 /a>#include <linux/module.h /a>>	  42 /a>#include <linux/stddef.h /a>>	  43 /a>#include <linux/mutex.h /a>>	  44 /a>#include <linux/bitops.h /a>>	  45 /a>#include <linux/jiffies.h /a>>	  46 /a>#include <linux/typ/s.h /a>>	  47 /a>#include <linux/gfp.h /a>>	  48 /a>#include <linux/err.h /a>>	  49 /a>	  56.3a> spa" class="comment">/* /spa"
	  51 /a> spa" class="comment"> * struct2twl4030_madc_data - a container for madc info /spa"
	  52 /a> spa" class="comment"> * @dev - pointer to device structure for madc /spa"
	  53 /a> spa" class="comment"> * @lock - mutex protecting this data structure /spa"
	  54 /a> spa" class="comment"> * @requests - Array2of request struct2corresponding to SW1, SW2 and RT /spa"
	  55 /a> spa" class="comment"> * @imr - Interrupt mask register of MADC /spa"
	  56 /a> spa" class="comment"> * @isr - Interrupt status register of MADC /spa"
	  57 /a> spa" class="comment"> */ /spa"
	  58 /a>struct2 a href="+code=twl4030_madc_data" class="sref">twl4030_madc_data /a> {	  59 /a>        struct2 a href="+code=device" class="sref">device /a> * a href="+code=dev" class="sref">dev /a>;	  60 /a>        struct2 a href="+code=mutex" class="sref">mutex /a>  a href="+code=lock" class="sref">lock /a>;pt
    spa" class="comment">/* mutex protecting this data structure */ /spa"
	  61 /a>        struct2 a href="+code=twl4030_madc_request" class="sref">twl4030_madc_request /a>  a href="+code=requests" class="sref">requests /a>[ a href="+code=TWL4030_MADC_NUM_METHODS" class="sref">TWL4030_MADC_NUM_METHODS /a>];	  62 /a>        int  a href="+code=imr" class="sref">imr /a>;	  63 /a>        int  a href="+code=isr" class="sref">isr /a>;	  64 /a>};	  65 /a>	  66 /a>static struct2 a href="+code=twl4030_madc_data" class="sref">twl4030_madc_data /a> * a href="+code=twl4030_madc" class="sref">twl4030_madc /a>;	  67 /a>	  68 /a>struct2 a href="+code=twl4030_prescale_divider_rat6.s" class="sref">twl4030_prescale_divider_rat6.s /a> {	  69 /a>         a href="+code=s16" class="sref">s16 /a>  a href="+code=numerator" class="sref">numerator /a>;	  70 /a>         a href="+code=s16" class="sref">s16 /a>  a href="+code=denominator" class="sref">denominator /a>;	  71 /a>};	  72 /a>	  73 /a>static const struct2 a href="+code=twl4030_prescale_divider_rat6.s" class="sref">twl4030_prescale_divider_rat6.s /a>	  74 /a> a href="+code=twl4030_divider_rat6.s" class="sref">twl4030_divider_rat6.s /a>[16] = {	  75 /a>        {1, 1},          spa" class="comment">/* CHANNEL 0 No Prescaler */ /spa"
	  76 /a>        {1, 1},          spa" class="comment">/* CHANNEL 1 No Prescaler */ /spa"
	  77 /a>        {6, 10},         spa" class="comment">/* CHANNEL 2 */ /spa"
	  78 /a>        {6, 10},         spa" class="comment">/* CHANNEL 3 */ /spa"
	  79 /a>        {6, 10},         spa" class="comment">/* CHANNEL 4 */ /spa"
	  80 /a>        {6, 10},         spa" class="comment">/* CHANNEL 5 */ /spa"
	  81 /a>        {6, 10},         spa" class="comment">/* CHANNEL 6 */ /spa"
	  82 /a>        {6, 10},         spa" class="comment">/* CHANNEL 7 */ /spa"
	  83 /a>        {3, 14},         spa" class="comment">/* CHANNEL 8 */ /spa"
	  84 /a>        {1, 3},          spa" class="comment">/* CHANNEL 9 */ /spa"
	  85 /a>        {1, 1},          spa" class="comment">/* CHANNEL 10 No Prescaler */ /spa"
	  86 /a>        {15, 100},       spa" class="comment">/* CHANNEL 11 */ /spa"
	  87 /a>        {1, 4},          spa" class="comment">/* CHANNEL 12 */ /spa"
	  88 /a>        {1, 1},          spa" class="comment">/* CHANNEL 13 Reserved channels */ /spa"
	  89 /a>        {1, 1},          spa" class="comment">/* CHANNEL 14 Reseved channels */ /spa"
	  90 /a>        {5, 11},         spa" class="comment">/* CHANNEL 15 */ /spa"
	  91 /a>};	  92 /a>	  93 /a>	  94 /a> spa" class="comment">/* /spa"
	  95 /a> spa" class="comment"> * Convers6.32table from -3 to 55 degree Celcius /spa"
	  96 /a> spa" class="comment"> */ /spa"
	  97 /a>static int  a href="+code=therm_tbl" class="sref">therm_tbl /a>[] = {	  98 /a>30800,  29500,  28300,  27100,	  99 /a>26000,  24900,  23900,  22900,  22000,  21100,  20300,  19400,  18700,  17900,	 100 /a>17200,  16500,  15900,  15300,  14700,  14100,  13600,  13100,  12600,  12100,	 101 /a>11600,  11200,  10800,  10400,  10000,  9630,   9280,   8950,   8620,   8310,	 102 /a>8020,   7730,   7460,   7200,   6950,   6710,   6470,   6250,   6040,   5830,	 103 /a>5640,   5450,   5260,   5090,   4920,   4760,   4600,   4450,   4310,   4170,	 104 /a>4040,   3910,   3790,   3670,   3550	 105 /a>};	 106 /a>	 107 /a> spa" class="comment">/* /spa"
	 108 /a> spa" class="comment"> * Structure containing the registers /spa"
	 109 /a> spa" class="comment"> * of different convers6.32methods supported by MADC. /spa"
	 1.6.3a> spa" class="comment"> * Hardware or RT real time convers6.32request initiated by external host /spa"
	 111 /a> spa" class="comment"> * processor for RT Signal convers6.3s. /spa"
	 112 /a> spa" class="comment"> * External host processors can also2request for n.32RT convers6.3s /spa"
	 113 /a> spa" class="comment"> * SW1 and SW2 software convers6.3s also2called asynchronous or GPC2request. /spa"
	 114 /a> spa" class="comment"> */ /spa"
	 115 /a>static	 116 /a>const struct2 a href="+code=twl4030_madc_convers6.3_method" class="sref">twl4030_madc_convers6.3_method /a>  a href="+code=twl4030_convers6.3_methods" class="sref">twl4030_convers6.3_methods /a>[] = {	 117 /a>        [ a href="+code=TWL4030_MADC_RT" class="sref">TWL4030_MADC_RT /a>] = {	 118 /a>                             . a href="+code=sel" class="sref">sel /a> =  a href="+code=TWL4030_MADC_RTSELECT_LSB" class="sref">TWL4030_MADC_RTSELECT_LSB /a>,	 119 /a>                             . a href="+code=avg" class="sref">avg /a> =  a href="+code=TWL4030_MADC_RTAVERAGE_LSB" class="sref">TWL4030_MADC_RTAVERAGE_LSB /a>,	 120 /a>                             . a href="+code=rbase" class="sref">rbase /a> =  a href="+code=TWL4030_MADC_RTCH0_LSB" class="sref">TWL4030_MADC_RTCH0_LSB /a>,	 121 /a>                             },	 122 /a>        [ a href="+code=TWL4030_MADC_SW1" class="sref">TWL4030_MADC_SW1 /a>] = {	 123 /a>                              . a href="+code=sel" class="sref">sel /a> =  a href="+code=TWL4030_MADC_SW1SELECT_LSB" class="sref">TWL4030_MADC_SW1SELECT_LSB /a>,	 124 /a>                              . a href="+code=avg" class="sref">avg /a> =  a href="+code=TWL4030_MADC_SW1AVERAGE_LSB" class="sref">TWL4030_MADC_SW1AVERAGE_LSB /a>,	 125 /a>                              . a href="+code=rbase" class="sref">rbase /a> =  a href="+code=TWL4030_MADC_GPCH0_LSB" class="sref">TWL4030_MADC_GPCH0_LSB /a>,	 126 /a>                              . a href="+code=ctrl" class="sref">ctrl /a> =  a href="+code=TWL4030_MADC_CTRL_SW1" class="sref">TWL4030_MADC_CTRL_SW1 /a>,	 127 /a>                              },	 128 /a>        [ a href="+code=TWL4030_MADC_SW2" class="sref">TWL4030_MADC_SW2 /a>] = {	 129 /a>                              . a href="+code=sel" class="sref">sel /a> =  a href="+code=TWL4030_MADC_SW2SELECT_LSB" class="sref">TWL4030_MADC_SW2SELECT_LSB /a>,	 130 /a>                              . a href="+code=avg" class="sref">avg /a> =  a href="+code=TWL4030_MADC_SW2AVERAGE_LSB" class="sref">TWL4030_MADC_SW2AVERAGE_LSB /a>,	 131 /a>                              . a href="+code=rbase" class="sref">rbase /a> =  a href="+code=TWL4030_MADC_GPCH0_LSB" class="sref">TWL4030_MADC_GPCH0_LSB /a>,	 132 /a>                              . a href="+code=ctrl" class="sref">ctrl /a> =  a href="+code=TWL4030_MADC_CTRL_SW2" class="sref">TWL4030_MADC_CTRL_SW2 /a>,	 133 /a>                              },	 134 /a>};	 135 /a>	 136 /a> spa" class="comment">/* /spa"
	 137 /a> spa" class="comment"> * Func.12" to read a particular channel .12 138 /a> spa" class="comment"> * @madc - pointer to struct2twl4030_madc_data /spa"
	 139 /a> spa" class="comment"> * @reg - lsb of ADC Channel /spa"
	 146.3a> spa" class="comment"> * If the i2c read fails it returns a" error else returns 0. /spa"
	 141 /a> spa" class="comment"> */ /spa"
	 142 /a>static int  a href="+code=twl4030_madc_channel_raw_read" class="sref">twl4030_madc_channel_raw_read /a>(struct2 a href="+code=twl4030_madc_data" class="sref">twl4030_madc_data /a> * a href="+code=madc" class="sref">madc /a>,2 a href="+code=u8" class="sref">u8 /a>  a href="+code=reg" class="sref">reg /a>)	 143 /a>{	 144 /a>         a href="+code=u8" class="sref">u8 /a>  a href="+code=msb" class="sref">msb /a>,2 a href="+code=lsb" class="sref">lsb /a>;	 145 /a>        int  a href="+code=ret" class="sref">ret /a>;	 146 /a>         spa" class="comment">/* /spa"
	 147 /a> spa" class="comment">         * For each ADC channel, we have MSB and LSB register pair. MSB address /spa"
	 148 /a> spa" class="comment">         * is always LSB address+1. reg param/ter is the address of LSB register /spa"
	 149 /a> spa" class="comment">         */ /spa"
	 150 /a>         a href="+code=ret" class="sref">ret /a> =  a href="+code=twl_i2c_read_u8" class="sref">twl_i2c_read_u8 /a>( a href="+code=TWL4030_MODULE_MADC" class="sref">TWL4030_MODULE_MADC /a>,2& a href="+code=msb" class="sref">msb /a>,2 a href="+code=reg" class="sref">reg /a> + 1);	 151 /a>        if ( a href="+code=ret" class="sref">ret /a>) {	 152 /a>                 a href="+code=dev_err" class="sref">dev_err /a>( a href="+code=madc" class="sref">madc /a>-> a href="+code=dev" class="sref">dev /a>,2 spa" class="string">"unable to read MSB register 0x%X\n" /spa"
,	 153 /a>                         a href="+code=reg" class="sref">reg /a> + 1);	 154 /a>                return  a href="+code=ret" class="sref">ret /a>;	 155 /a>        }	 156 /a>         a href="+code=ret" class="sref">ret /a> =  a href="+code=twl_i2c_read_u8" class="sref">twl_i2c_read_u8 /a>( a href="+code=TWL4030_MODULE_MADC" class="sref">TWL4030_MODULE_MADC /a>,2& a href="+code=lsb" class="sref">lsb /a>,2 a href="+code=reg" class="sref">reg /a>);	 157 /a>        if ( a href="+code=ret" class="sref">ret /a>) {	 158 /a>                 a href="+code=dev_err" class="sref">dev_err /a>( a href="+code=madc" class="sref">madc /a>-> a href="+code=dev" class="sref">dev /a>,2 spa" class="string">"unable to read LSB register 0x%X\n" /spa"
,2 a href="+code=reg" class="sref">reg /a>);	 159 /a>                return  a href="+code=ret" class="sref">ret /a>;	 160 /a>        }	 161 /a>	 162 /a>        return (int)((( a href="+code=msb" class="sref">msb /a> << 8) |2 a href="+code=lsb" class="sref">lsb /a>) >> 6);	 163 /a>}	 164 /a>	 165 /a> spa" class="comment">/* /spa"
	 166 /a> spa" class="comment"> * Return battery temperature /spa"
	 167 /a> spa" class="comment"> * Or < 0 .32failure. /spa"
	 168 /a> spa" class="comment"> */ /spa"
	 169 /a>static int  a href="+code=twl4030battery_temperature" class="sref">twl4030battery_temperature /a>(int  a href="+code=raw_volt" class="sref">raw_volt /a>)	 170 /a>{	 171 /a>         a href="+code=u8" class="sref">u8 /a>  a href="+code=val" class="sref">val /a>;	 172 /a>        int  a href="+code=temp" class="sref">temp /a>,2 a href="+code=curr" class="sref">curr /a>,2 a href="+code=volt" class="sref">volt /a>,2 a href="+code=res" class="sref">res /a>,2 a href="+code=ret" class="sref">ret /a>;	 173 /a>	 174 /a>         a href="+code=volt" class="sref">volt /a> = ( a href="+code=raw_volt" class="sref">raw_volt /a> *  a href="+code=TEMP_STEP_SIZE" class="sref">TEMP_STEP_SIZE /a>) /  a href="+code=TEMP_PSR_R" class="sref">TEMP_PSR_R /a>;	 175 /a>         spa" class="comment">/* Getting and calculating the supply current in micro ampers */ /spa"
	 176 /a>         a href="+code=ret" class="sref">ret /a> =  a href="+code=twl_i2c_read_u8" class="sref">twl_i2c_read_u8 /a>( a href="+code=TWL4030_MODULE_MAIN_CHARGE" class="sref">TWL4030_MODULE_MAIN_CHARGE /a>,2& a href="+code=val" class="sref">val /a>,	 177 /a>                 a href="+code=REG_BCICTL2" class="sref">REG_BCICTL2 /a>);	 178 /a>        if ( a href="+code=ret" class="sref">ret /a> < 0)	 179 /a>                return  a href="+code=ret" class="sref">ret /a>;	 180 /a>         a href="+code=curr" class="sref">curr /a> = (( a href="+code=val" class="sref">val /a>2&  a href="+code=TWL4030_BCI_ITHEN" class="sref">TWL4030_BCI_ITHEN /a>) + 1) * 10;	 181 /a>         spa" class="comment">/* Getting and calculating the thermistor resistance in ohms */ /spa"
	 182 /a>         a href="+code=res" class="sref">res /a> =  a href="+code=volt" class="sref">volt /a> * 1000 /  a href="+code=curr" class="sref">curr /a>;	 183 /a>         spa" class="comment">/* calculating temperature */ /spa"
	 184 /a>        for ( a href="+code=temp" class="sref">temp /a> = 58;  a href="+code=temp" class="sref">temp /a> >= 0;  a href="+code=temp" class="sref">temp /a>--) {	 185 /a>                int  a href="+code=actual" class="sref">actual /a> =  a href="+code=therm_tbl" class="sref">therm_tbl /a>[ a href="+code=temp" class="sref">temp /a>];	 186 /a>	 187 /a>                if (( a href="+code=actual" class="sref">actual /a> -  a href="+code=res" class="sref">res /a>) >= 0)	 188 /a>                        break;	 189 /a>        }	 190 /a>	 191 /a>        return  a href="+code=temp" class="sref">temp /a> + 1;	 192 /a>}	 193 /a>	 194 /a>static int  a href="+code=twl4030battery_current" class="sref">twl4030battery_current /a>(int  a href="+code=raw_volt" class="sref">raw_volt /a>)	 195 /a>{	 196 /a>        int  a href="+code=ret" class="sref">ret /a>;	 197 /a>         a href="+code=u8" class="sref">u8 /a>  a href="+code=val" class="sref">val /a>;	 198 /a>	 199 /a>         a href="+code=ret" class="sref">ret /a> =  a href="+code=twl_i2c_read_u8" class="sref">twl_i2c_read_u8 /a>( a href="+code=TWL4030_MODULE_MAIN_CHARGE" class="sref">TWL4030_MODULE_MAIN_CHARGE /a>,2& a href="+code=val" class="sref">val /a>,	 200 /a>                 a href="+code=TWL4030_BCI_BCICTL1" class="sref">TWL4030_BCI_BCICTL1 /a>);	 201 /a>        if ( a href="+code=ret" class="sref">ret /a>)	 202 /a>                return  a href="+code=ret" class="sref">ret /a>;	 203 /a>        if ( a href="+code=val" class="sref">val /a>2&  a href="+code=TWL4030_BCI_CGAIN" class="sref">TWL4030_BCI_CGAIN /a>)  spa" class="comment">/* slope of 0.44 mV/mA */ /spa"
	 204 /a>                return ( a href="+code=raw_volt" class="sref">raw_volt /a> *  a href="+code=CURR_STEP_SIZE" class="sref">CURR_STEP_SIZE /a>) /  a href="+code=CURR_PSR_R1" class="sref">CURR_PSR_R1 /a>;	 205 /a>        else  spa" class="comment">/* slope of 0.88 mV/mA */ /spa"
	 206 /a>                return ( a href="+code=raw_volt" class="sref">raw_volt /a> *  a href="+code=CURR_STEP_SIZE" class="sref">CURR_STEP_SIZE /a>) /  a href="+code=CURR_PSR_R2" class="sref">CURR_PSR_R2 /a>;	 207 /a>}	 208 /a> spa" class="comment">/* /spa"
	 209 /a> spa" class="comment"> * Func.12" to read channel .12 2.6.3a> spa" class="comment"> * @madc - pointer to twl4030_madc_data struct /spa"
	 211 /a> spa" class="comment"> * @reg_base - Base address of the first channel /spa"
	 212 /a> spa" class="comment"> * @Channels - 16 bit bitmap. If the bit is set, channel .12 213 /a> spa" class="comment"> * @buf - The channel .12 214 /a> spa" class="comment"> * .12 215 /a> spa" class="comment"> * Returns the number of successfully read channels. /spa"
	 216 /a> spa" class="comment"> */ /spa"
	 217 /a>static int  a href="+code=twl4030_madc_read_channels" class="sref">twl4030_madc_read_channels /a>(struct2 a href="+code=twl4030_madc_data" class="sref">twl4030_madc_data /a> * a href="+code=madc" class="sref">madc /a>,	 218 /a>                                       a href="+code=u8" class="sref">u8 /a>  a href="+code=reg_base" class="sref">reg_base /a>,2unsigned	 219 /a>                                                long  a href="+code=channels" class="sref">channels /a>, int * a href="+code=buf" class="sref">buf /a>)	 220 /a>{	 221 /a>        int  a href="+code=count" class="sref">count /a> = 0,2 a href="+code=count_req" class="sref">count_req /a> = 0,2 a href="+code=i" class="sref">i /a>;	 222 /a>         a href="+code=u8" class="sref">u8 /a>  a href="+code=reg" class="sref">reg /a>;	 223 /a>	 224 /a>         a href="+code=for_each_set_bit" class="sref">for_each_set_bit /a>( a href="+code=i" class="sref">i /a>,2& a href="+code=channels" class="sref">channels /a>,  a href="+code=TWL4030_MADC_MAX_CHANNELS" class="sref">TWL4030_MADC_MAX_CHANNELS /a>) {	 225 /a>                 a href="+code=reg" class="sref">reg /a> =  a href="+code=reg_base" class="sref">reg_base /a> + 2 *2 a href="+code=i" class="sref">i /a>;	 226 /a>                 a href="+code=buf" class="sref">buf /a>[ a href="+code=i" class="sref">i /a>] =  a href="+code=twl4030_madc_channel_raw_read" class="sref">twl4030_madc_channel_raw_read /a>( a href="+code=madc" class="sref">madc /a>,2 a href="+code=reg" class="sref">reg /a>);	 227 /a>                if ( a href="+code=buf" class="sref">buf /a>[ a href="+code=i" class="sref">i /a>] < 0) {	 228 /a>                         a href="+code=dev_err" class="sref">dev_err /a>( a href="+code=madc" class="sref">madc /a>-> a href="+code=dev" class="sref">dev /a>,	 229 /a>                               2 spa" class="string">"Unable to read register 0x%X\n" /spa"
,2 a href="+code=reg" class="sref">reg /a>);	 230 /a>                         a href="+code=count_req" class="sref">count_req /a>++;	 231 /a>                        continue;	 232 /a>                }	 233 /a>                switch ( a href="+code=i" class="sref">i /a>) {	 234 /a>                case 10:	 235 /a>                         a href="+code=buf" class="sref">buf /a>[ a href="+code=i" class="sref">i /a>] =  a href="+code=twl4030battery_current" class="sref">twl4030battery_current /a>( a href="+code=buf" class="sref">buf /a>[ a href="+code=i" class="sref">i /a>]);	 236 /a>                        if ( a href="+code=buf" class="sref">buf /a>[ a href="+code=i" class="sref">i /a>] < 0) {	 237 /a>                                 a href="+code=dev_err" class="sref">dev_err /a>( a href="+code=madc" class="sref">madc /a>-> a href="+code=dev" class="sref">dev /a>,2 spa" class="string">"err reading current\n" /spa"
);	 238 /a>                                 a href="+code=count_req" class="sref">count_req /a>++;	 239 /a>                        } else {	 240 /a>                                 a href="+code=count" class="sref">count /a>++;	 241 /a>                                 a href="+code=buf" class="sref">buf /a>[ a href="+code=i" class="sref">i /a>] =  a href="+code=buf" class="sref">buf /a>[ a href="+code=i" class="sref">i /a>] - 750;	 242 /a>                        }	 243 /a>                        break;	 244 /a>                case 1:	 245 /a>                         a href="+code=buf" class="sref">buf /a>[ a href="+code=i" class="sref">i /a>] =  a href="+code=twl4030battery_temperature" class="sref">twl4030battery_temperature /a>( a href="+code=buf" class="sref">buf /a>[ a href="+code=i" class="sref">i /a>]);	 246 /a>                        if ( a href="+code=buf" class="sref">buf /a>[ a href="+code=i" class="sref">i /a>] < 0) {	 247 /a>                                 a href="+code=dev_err" class="sref">dev_err /a>( a href="+code=madc" class="sref">madc /a>-> a href="+code=dev" class="sref">dev /a>,2 spa" class="string">"err reading temperature\n" /spa"
);	 248 /a>                                 a href="+code=count_req" class="sref">count_req /a>++;	 249 /a>                        } else {	 250 /a>                                 a href="+code=buf" class="sref">buf /a>[ a href="+code=i" class="sref">i /a>] -= 3;	 251 /a>                                 a href="+code=count" class="sref">count /a>++;	 252 /a>                        }	 253 /a>                        break;	 254 /a>                default:	 255 /a>                         a href="+code=count" class="sref">count /a>++;	 256 /a>                         spa" class="comment">/* Analog Input (V) = conv_result * step_size / R /spa"
	 257 /a> spa" class="comment">                         * conv_result = decimal .12 258 /a> spa" class="comment">                         *               result /spa"
	 259 /a> spa" class="comment">                         * step size = 1.5 / (2 ^ 10 -1) /spa"
	 266.3a> spa" class="comment">                         * R = Prescaler rat6. for input channels. /spa"
	 261 /a> spa" class="comment">                         * Result given in mV hence multiplied by 1000. /spa"
	 262 /a> spa" class="comment">                         */ /spa"
	 263 /a>                         a href="+code=buf" class="sref">buf /a>[ a href="+code=i" class="sref">i /a>] = ( a href="+code=buf" class="sref">buf /a>[ a href="+code=i" class="sref">i /a>] * 3 * 1000 *	 264 /a>                                  a href="+code=twl4030_divider_rat6.s" class="sref">twl4030_divider_rat6.s /a>[ a href="+code=i" class="sref">i /a>]. a href="+code=denominator" class="sref">denominator /a>)	 265 /a>                                / (2 * 1023 *	 266 /a>                                 a href="+code=twl4030_divider_rat6.s" class="sref">twl4030_divider_rat6.s /a>[ a href="+code=i" class="sref">i /a>]. a href="+code=numerator" class="sref">numerator /a>);	 267 /a>                }	 268 /a>        }	 269 /a>        if ( a href="+code=count_req" class="sref">count_req /a>)	 270 /a>                 a href="+code=dev_err" class="sref">dev_err /a>( a href="+code=madc" class="sref">madc /a>-> a href="+code=dev" class="sref">dev /a>,2 spa" class="string">"%d channel convers6.32failed\n" /spa"
,2 a href="+code=count_req" class="sref">count_req /a>);	 271 /a>	 272 /a>        return  a href="+code=count" class="sref">count /a>;	 273 /a>}	 274 /a>	 275 /a> spa" class="comment">/* /spa"
	 276 /a> spa" class="comment"> * Enables irq. /spa"
	 277 /a> spa" class="comment"> * @madc - pointer to twl4030_madc_data struct /spa"
	 278 /a> spa" class="comment"> * @id - irq number to be enabled /spa"
	 279 /a> spa" class="comment"> * can tak/ on/ of TWL4030_MADC_RT, TWL4030_MADC_SW1, TWL4030_MADC_SW2 /spa"
	 286.3a> spa" class="comment"> * corresponding to RT, SW1, SW2 convers6.32requests. /spa"
	 281 /a> spa" class="comment"> * If the i2c read fails it returns a" error else returns 0. /spa"
	 282 /a> spa" class="comment"> */ /spa"
	 283 /a>static int  a href="+code=twl4030_madc_enable_irq" class="sref">twl4030_madc_enable_irq /a>(struct2 a href="+code=twl4030_madc_data" class="sref">twl4030_madc_data /a> * a href="+code=madc" class="sref">madc /a>,2 a href="+code=u8" class="sref">u8 /a>  a href="+code=id" class="sref">id /a>)	 284 /a>{	 285 /a>         a href="+code=u8" class="sref">u8 /a>  a href="+code=val" class="sref">val /a>;	 286 /a>        int  a href="+code=ret" class="sref">ret /a>;	 287 /a>	 288 /a>         a href="+code=ret" class="sref">ret /a> =  a href="+code=twl_i2c_read_u8" class="sref">twl_i2c_read_u8 /a>( a href="+code=TWL4030_MODULE_MADC" class="sref">TWL4030_MODULE_MADC /a>,2& a href="+code=val" class="sref">val /a>,  a href="+code=madc" class="sref">madc /a>-> a href="+code=imr" class="sref">imr /a>);	 289 /a>        if ( a href="+code=ret" class="sref">ret /a>) {	 290 /a>                 a href="+code=dev_err" class="sref">dev_err /a>( a href="+code=madc" class="sref">madc /a>-> a href="+code=dev" class="sref">dev /a>,2 spa" class="string">"unable to read imr register 0x%X\n" /spa"
,	 291 /a>                         a href="+code=madc" class="sref">madc /a>-> a href="+code=imr" class="sref">imr /a>);	 292 /a>                return  a href="+code=ret" class="sref">ret /a>;	 293 /a>        }	 294 /a>         a href="+code=val" class="sref">val /a>2&= ~(1 <<  a href="+code=id" class="sref">id /a>);	 295 /a>         a href="+code=ret" class="sref">ret /a> =  a href="+code=twl_i2c_write_u8" class="sref">twl_i2c_write_u8 /a>( a href="+code=TWL4030_MODULE_MADC" class="sref">TWL4030_MODULE_MADC /a>,2 a href="+code=val" class="sref">val /a>,  a href="+code=madc" class="sref">madc /a>-> a href="+code=imr" class="sref">imr /a>);	 296 /a>        if ( a href="+code=ret" class="sref">ret /a>) {	 297 /a>                 a href="+code=dev_err" class="sref">dev_err /a>( a href="+code=madc" class="sref">madc /a>-> a href="+code=dev" class="sref">dev /a>,	 298 /a>                         spa" class="string">"unable to write imr register 0x%X\n" /spa"
,  a href="+code=madc" class="sref">madc /a>-> a href="+code=imr" class="sref">imr /a>);	 299 /a>                return  a href="+code=ret" class="sref">ret /a>;	 300 /a>	 301 /a>        }	 302 /a>	 303 /a>        return 0;	 304 /a>}	 305 /a>	 306 /a> spa" class="comment">/* /spa"
	 307 /a> spa" class="comment"> * Disables irq. /spa"
	 308 /a> spa" class="comment"> * @madc - pointer to twl4030_madc_data struct /spa"
	 309 /a> spa" class="comment"> * @id - irq number to be disabled /spa"
	 3.6.3a> spa" class="comment"> * can tak/ on/ of TWL4030_MADC_RT, TWL4030_MADC_SW1, TWL4030_MADC_SW2 /spa"
	 311 /a> spa" class="comment"> * corresponding to RT, SW1, SW2 convers6.32requests. /spa"
	 312 /a> spa" class="comment"> * Returns error if i2c read/write fails. /spa"
	 313 /a> spa" class="comment"> */ /spa"
	 314 /a>static int  a href="+code=twl4030_madc_disable_irq" class="sref">twl4030_madc_disable_irq /a>(struct2 a href="+code=twl4030_madc_data" class="sref">twl4030_madc_data /a> * a href="+code=madc" class="sref">madc /a>,2 a href="+code=u8" class="sref">u8 /a>  a href="+code=id" class="sref">id /a>)	 315 /a>{	 316 /a>         a href="+code=u8" class="sref">u8 /a>  a href="+code=val" class="sref">val /a>;	 317 /a>        int  a href="+code=ret" class="sref">ret /a>;	 318 /a>	 319 /a>         a href="+code=ret" class="sref">ret /a> =  a href="+code=twl_i2c_read_u8" class="sref">twl_i2c_read_u8 /a>( a href="+code=TWL4030_MODULE_MADC" class="sref">TWL4030_MODULE_MADC /a>,2& a href="+code=val" class="sref">val /a>,  a href="+code=madc" class="sref">madc /a>-> a href="+code=imr" class="sref">imr /a>);	 320 /a>        if ( a href="+code=ret" class="sref">ret /a>) {	 321 /a>                 a href="+code=dev_err" class="sref">dev_err /a>( a href="+code=madc" class="sref">madc /a>-> a href="+code=dev" class="sref">dev /a>,2 spa" class="string">"unable to read imr register 0x%X\n" /spa"
,	 322 /a>                         a href="+code=madc" class="sref">madc /a>-> a href="+code=imr" class="sref">imr /a>);	 323 /a>                return  a href="+code=ret" class="sref">ret /a>;	 324 /a>        }	 325 /a>         a href="+code=val" class="sref">val /a>2|= (1 <<  a href="+code=id" class="sref">id /a>);	 326 /a>         a href="+code=ret" class="sref">ret /a> =  a href="+code=twl_i2c_write_u8" class="sref">twl_i2c_write_u8 /a>( a href="+code=TWL4030_MODULE_MADC" class="sref">TWL4030_MODULE_MADC /a>,2 a href="+code=val" class="sref">val /a>,  a href="+code=madc" class="sref">madc /a>-> a href="+code=imr" class="sref">imr /a>);	 327 /a>        if ( a href="+code=ret" class="sref">ret /a>) {	 328 /a>                 a href="+code=dev_err" class="sref">dev_err /a>( a href="+code=madc" class="sref">madc /a>-> a href="+code=dev" class="sref">dev /a>,	 329 /a>                         spa" class="string">"unable to write imr register 0x%X\n" /spa"
,  a href="+code=madc" class="sref">madc /a>-> a href="+code=imr" class="sref">imr /a>);	 330 /a>                return  a href="+code=ret" class="sref">ret /a>;	 331 /a>        }	 332 /a>	 333 /a>        return 0;	 334 /a>}	 335 /a>	 336 /a>static  a href="+code=irqreturn_t" class="sref">irqreturn_t /a>  a href="+code=twl4030_madc_threaded_irq_handler" class="sref">twl4030_madc_threaded_irq_handler /a>(int  a href="+code=irq" class="sref">irq /a>, void * a href="+code=_madc" class="sref">_madc /a>)	 337 /a>{	 338 /a>        struct2 a href="+code=twl4030_madc_data" class="sref">twl4030_madc_data /a> * a href="+code=madc" class="sref">madc /a> =  a href="+code=_madc" class="sref">_madc /a>;	 339 /a>        const struct2 a href="+code=twl4030_madc_convers6.3_method" class="sref">twl4030_madc_convers6.3_method /a> * a href="+code=method" class="sref">method /a>;	 340 /a>         a href="+code=u8" class="sref">u8 /a>  a href="+code=isr_val" class="sref">isr_val /a>,  a href="+code=imr_val" class="sref">imr_val /a>;	 341 /a>        int  a href="+code=i" class="sref">i /a>,2 a href="+code=len" class="sref">len /a>,2 a href="+code=ret" class="sref">ret /a>;	 342 /a>        struct2 a href="+code=twl4030_madc_request" class="sref">twl4030_madc_request /a> * a href="+code=r" class="sref">r /a>;	 343 /a>	 344 /a>         a href="+code=mutex_lock" class="sref">mutex_lock /a>(& a href="+code=madc" class="sref">madc /a>-> a href="+code=lock" class="sref">lock /a>);	 345 /a>         a href="+code=ret" class="sref">ret /a> =  a href="+code=twl_i2c_read_u8" class="sref">twl_i2c_read_u8 /a>( a href="+code=TWL4030_MODULE_MADC" class="sref">TWL4030_MODULE_MADC /a>,2& a href="+code=isr_val" class="sref">isr_val /a>,  a href="+code=madc" class="sref">madc /a>-> a href="+code=isr" class="sref">isr /a>);	 346 /a>        if ( a href="+code=ret" class="sref">ret /a>) {	 347 /a>                 a href="+code=dev_err" class="sref">dev_err /a>( a href="+code=madc" class="sref">madc /a>-> a href="+code=dev" class="sref">dev /a>,2 spa" class="string">"unable to read isr register 0x%X\n" /spa"
,	 348 /a>                         a href="+code=madc" class="sref">madc /a>-> a href="+code=isr" class="sref">isr /a>);	 349 /a>                goto  a href="+code=err_i2c" class="sref">err_i2c /a>;	 350 /a>        }	 351 /a>         a href="+code=ret" class="sref">ret /a> =  a href="+code=twl_i2c_read_u8" class="sref">twl_i2c_read_u8 /a>( a href="+code=TWL4030_MODULE_MADC" class="sref">TWL4030_MODULE_MADC /a>,2& a href="+code=imr_val" class="sref">imr_val /a>,  a href="+code=madc" class="sref">madc /a>-> a href="+code=imr" class="sref">imr /a>);	 352 /a>        if ( a href="+code=ret" class="sref">ret /a>) {	 353 /a>                 a href="+code=dev_err" class="sref">dev_err /a>( a href="+code=madc" class="sref">madc /a>-> a href="+code=dev" class="sref">dev /a>,2 spa" class="string">"unable to read imr register 0x%X\n" /spa"
,	 354 /a>                         a href="+code=madc" class="sref">madc /a>-> a href="+code=imr" class="sref">imr /a>);	 355 /a>                goto  a href="+code=err_i2c" class="sref">err_i2c /a>;	 356 /a>        }	 357 /a>         a href="+code=isr_val" class="sref">isr_val /a>2&= ~ a href="+code=imr_val" class="sref">imr_val /a>;	 358 /a>        for ( a href="+code=i" class="sref">i /a> = 0;  a href="+code=i" class="sref">i /a> <  a href="+code=TWL4030_MADC_NUM_METHODS" class="sref">TWL4030_MADC_NUM_METHODS /a>;  a href="+code=i" class="sref">i /a>++) {	 359 /a>                if (!( a href="+code=isr_val" class="sref">isr_val /a>2& (1 <<  a href="+code=i" class="sref">i /a>)))	 360 /a>                        continue;	 361 /a>                 a href="+code=ret" class="sref">ret /a> =  a href="+code=twl4030_madc_disable_irq" class="sref">twl4030_madc_disable_irq /a>( a href="+code=madc" class="sref">madc /a>,2 a href="+code=i" class="sref">i /a>);	 362 /a>                if ( a href="+code=ret" class="sref">ret /a> < 0)	 363 /a>                         a href="+code=dev_dbg" class="sref">dev_dbg /a>( a href="+code=madc" class="sref">madc /a>-> a href="+code=dev" class="sref">dev /a>,2 spa" class="string">"Disable interrupt2failed%d\n" /spa"
,  a href="+code=i" class="sref">i /a>);	 364 /a>                 a href="+code=madc" class="sref">madc /a>-> a href="+code=requests" class="sref">requests /a>[ a href="+code=i" class="sref">i /a>]. a href="+code=result_pending" class="sref">result_pending /a> = 1;	 365 /a>        }	 366 /a>        for ( a href="+code=i" class="sref">i /a> = 0;  a href="+code=i" class="sref">i /a> <  a href="+code=TWL4030_MADC_NUM_METHODS" class="sref">TWL4030_MADC_NUM_METHODS /a>;  a href="+code=i" class="sref">i /a>++) {	 367 /a>                 a href="+code=r" class="sref">r /a> = & a href="+code=madc" class="sref">madc /a>-> a href="+code=requests" class="sref">requests /a>[ a href="+code=i" class="sref">i /a>];	 368 /a>                 spa" class="comment">/* No pending results for this method, move to next on/ */ /spa"
	 369 /a>                if (! a href="+code=r" class="sref">r /a>-> a href="+code=result_pending" class="sref">result_pending /a>)	 370 /a>                        continue;	 371 /a>                 a href="+code=method" class="sref">method /a> = & a href="+code=twl4030_convers6.3_methods" class="sref">twl4030_convers6.3_methods /a>[ a href="+code=r" class="sref">r /a>-> a href="+code=method" class="sref">method /a>];	 372 /a>                 spa" class="comment">/* Read results */ /spa"
	 373 /a>                 a href="+code=len" class="sref">len /a> =  a href="+code=twl4030_madc_read_channels" class="sref">twl4030_madc_read_channels /a>( a href="+code=madc" class="sref">madc /a>,2 a href="+code=method" class="sref">method /a>-> a href="+code=rbase" class="sref">rbase /a>,	 374 /a>                                                  a href="+code=r" class="sref">r /a>-> a href="+code=channels" class="sref">channels /a>,  a href="+code=r" class="sref">r /a>-> a href="+code=rbuf" class="sref">rbuf /a>);	 375 /a>                 spa" class="comment">/* Return results to caller */ /spa"
	 376 /a>                if ( a href="+code=r" class="sref">r /a>-> a href="+code=func_cb" class="sref">func_cb /a> !=  a href="+code=NULL" class="sref">NULL /a>) {	 377 /a>                         a href="+code=r" class="sref">r /a>-> a href="+code=func_cb" class="sref">func_cb /a>( a href="+code=len" class="sref">len /a>,2 a href="+code=r" class="sref">r /a>-> a href="+code=channels" class="sref">channels /a>,  a href="+code=r" class="sref">r /a>-> a href="+code=rbuf" class="sref">rbuf /a>);	 378 /a>                         a href="+code=r" class="sref">r /a>-> a href="+code=func_cb" class="sref">func_cb /a> =  a href="+code=NULL" class="sref">NULL /a>;	 379 /a>                }	 380 /a>                 spa" class="comment">/* Free2request */ /spa"
	 381 /a>                 a href="+code=r" class="sref">r /a>-> a href="+code=result_pending" class="sref">result_pending /a> = 0;	 382 /a>                 a href="+code=r" class="sref">r /a>-> a href="+code=active" class="sref">active /a> = 0;	 383 /a>        }	 384 /a>         a href="+code=mutex_unlock" class="sref">mutex_unlock /a>(& a href="+code=madc" class="sref">madc /a>-> a href="+code=lock" class="sref">lock /a>);	 385 /a>	 386 /a>        return  a href="+code=IRQ_HANDLED" class="sref">IRQ_HANDLED /a>;	 387 /a>	 388 /a> a href="+code=err_i2c" class="sref">err_i2c /a>:	 389 /a>         spa" class="comment">/* /spa"
	 396.3a> spa" class="comment">         * In case of error check whichever request is active /spa"
	 391 /a> spa" class="comment">         * and service the sam/. /spa"
	 392 /a> spa" class="comment">         */ /spa"
	 393 /a>        for ( a href="+code=i" class="sref">i /a> = 0;  a href="+code=i" class="sref">i /a> <  a href="+code=TWL4030_MADC_NUM_METHODS" class="sref">TWL4030_MADC_NUM_METHODS /a>;  a href="+code=i" class="sref">i /a>++) {	 394 /a>                 a href="+code=r" class="sref">r /a> = & a href="+code=madc" class="sref">madc /a>-> a href="+code=requests" class="sref">requests /a>[ a href="+code=i" class="sref">i /a>];	 395 /a>                if ( a href="+code=r" class="sref">r /a>-> a href="+code=active" class="sref">active /a> == 0)	 396 /a>                        continue;	 397 /a>                 a href="+code=method" class="sref">method /a> = & a href="+code=twl4030_convers6.3_methods" class="sref">twl4030_convers6.3_methods /a>[ a href="+code=r" class="sref">r /a>-> a href="+code=method" class="sref">method /a>];	 398 /a>                 spa" class="comment">/* Read results */ /spa"
	 399 /a>                 a href="+code=len" class="sref">len /a> =  a href="+code=twl4030_madc_read_channels" class="sref">twl4030_madc_read_channels /a>( a href="+code=madc" class="sref">madc /a>,2 a href="+code=method" class="sref">method /a>-> a href="+code=rbase" class="sref">rbase /a>,	 400 /a>                                                  a href="+code=r" class="sref">r /a>-> a href="+code=channels" class="sref">channels /a>,  a href="+code=r" class="sref">r /a>-> a href="+code=rbuf" class="sref">rbuf /a>);	 401 /a>                 spa" class="comment">/* Return results to caller */ /spa"
	 402 /a>                if ( a href="+code=r" class="sref">r /a>-> a href="+code=func_cb" class="sref">func_cb /a> !=  a href="+code=NULL" class="sref">NULL /a>) {	 403 /a>                         a href="+code=r" class="sref">r /a>-> a href="+code=func_cb" class="sref">func_cb /a>( a href="+code=len" class="sref">len /a>,2 a href="+code=r" class="sref">r /a>-> a href="+code=channels" class="sref">channels /a>,  a href="+code=r" class="sref">r /a>-> a href="+code=rbuf" class="sref">rbuf /a>);	 404 /a>                         a href="+code=r" class="sref">r /a>-> a href="+code=func_cb" class="sref">func_cb /a> =  a href="+code=NULL" class="sref">NULL /a>;	 405 /a>                }	 406 /a>                 spa" class="comment">/* Free2request */ /spa"
	 407 /a>                 a href="+code=r" class="sref">r /a>-> a href="+code=result_pending" class="sref">result_pending /a> = 0;	 408 /a>                 a href="+code=r" class="sref">r /a>-> a href="+code=active" class="sref">active /a> = 0;	 409 /a>        }	 410 /a>         a href="+code=mutex_unlock" class="sref">mutex_unlock /a>(& a href="+code=madc" class="sref">madc /a>-> a href="+code=lock" class="sref">lock /a>);	 411 /a>	 412 /a>        return  a href="+code=IRQ_HANDLED" class="sref">IRQ_HANDLED /a>;	 413 /a>}	 414 /a>	 415 /a>static int  a href="+code=twl4030_madc_set_irq" class="sref">twl4030_madc_set_irq /a>(struct2 a href="+code=twl4030_madc_data" class="sref">twl4030_madc_data /a> * a href="+code=madc" class="sref">madc /a>,	 416 /a>                                struct2 a href="+code=twl4030_madc_request" class="sref">twl4030_madc_request /a> * a href="+code=req" class="sref">req /a>)	 417 /a>{	 418 /a>        struct2 a href="+code=twl4030_madc_request" class="sref">twl4030_madc_request /a> * a href="+code=p" class="sref">p /a>;	 419 /a>        int  a href="+code=ret" class="sref">ret /a>;	 420 /a>	 421 /a>         a href="+code=p" class="sref">p /a> = & a href="+code=madc" class="sref">madc /a>-> a href="+code=requests" class="sref">requests /a>[ a href="+code=req" class="sref">req /a>-> a href="+code=method" class="sref">method /a>];	 422 /a>         a href="+code=memcpy" class="sref">memcpy /a>( a href="+code=p" class="sref">p /a>,2 a href="+code=req" class="sref">req /a>, sizeof(* a href="+code=req" class="sref">req /a>));	 423 /a>         a href="+code=ret" class="sref">ret /a> =  a href="+code=twl4030_madc_enable_irq" class="sref">twl4030_madc_enable_irq /a>( a href="+code=madc" class="sref">madc /a>,2 a href="+code=req" class="sref">req /a>-> a href="+code=method" class="sref">method /a>);	 424 /a>        if ( a href="+code=ret" class="sref">ret /a> < 0) {	 425 /a>                 a href="+code=dev_err" class="sref">dev_err /a>( a href="+code=madc" class="sref">madc /a>-> a href="+code=dev" class="sref">dev /a>,2 spa" class="string">"enable irq failed!!\n" /spa"
);	 426 /a>                return  a href="+code=ret" class="sref">ret /a>;	 427 /a>        }	 428 /a>	 429 /a>        return 0;	 430 /a>}	 431 /a>	 432 /a> spa" class="comment">/* /spa"
	 433 /a> spa" class="comment"> * Function which enables the madc convers6.3 /spa"
	 434 /a> spa" class="comment"> * by writing to the control register. /spa"
	 435 /a> spa" class="comment"> * @madc - pointer to twl4030_madc_data struct /spa"
	 436 /a> spa" class="comment"> * @conv_method - can be TWL4030_MADC_RT, TWL4030_MADC_SW2, TWL4030_MADC_SW1 /spa"
	 437 /a> spa" class="comment"> * corresponding to RT SW1 or SW2 convers6.32methods. /spa"
	 438 /a> spa" class="comment"> * Returns 0 if succeeds else a negative error value /spa"
	 439 /a> spa" class="comment"> */ /spa"
	 440 /a>static int  a href="+code=twl4030_madc_start_convers6.3" class="sref">twl4030_madc_start_convers6.3 /a>(struct2 a href="+code=twl4030_madc_data" class="sref">twl4030_madc_data /a> * a href="+code=madc" class="sref">madc /a>,	 441 /a>                                         int  a href="+code=conv_method" class="sref">conv_method /a>)	 442 /a>{	 443 /a>        const struct2 a href="+code=twl4030_madc_convers6.3_method" class="sref">twl4030_madc_convers6.3_method /a> * a href="+code=method" class="sref">method /a>;	 444 /a>        int  a href="+code=ret" class="sref">ret /a> = 0;	 445 /a>         a href="+code=method" class="sref">method /a> = & a href="+code=twl4030_convers6.3_methods" class="sref">twl4030_convers6.3_methods /a>[ a href="+code=conv_method" class="sref">conv_method /a>];	 446 /a>        switch ( a href="+code=conv_method" class="sref">conv_method /a>) {	 447 /a>        case  a href="+code=TWL4030_MADC_SW1" class="sref">TWL4030_MADC_SW1 /a>:	 448 /a>        case  a href="+code=TWL4030_MADC_SW2" class="sref">TWL4030_MADC_SW2 /a>:	 449 /a>                 a href="+code=ret" class="sref">ret /a> =  a href="+code=twl_i2c_write_u8" class="sref">twl_i2c_write_u8 /a>( a href="+code=TWL4030_MODULE_MADC" class="sref">TWL4030_MODULE_MADC /a>,	 450 /a>                                        a href="+code=TWL4030_MADC_SW_START" class="sref">TWL4030_MADC_SW_START /a>,2 a href="+code=method" class="sref">method /a>-> a href="+code=ctrl" class="sref">ctrl /a>);	 451 /a>                if ( a href="+code=ret" class="sref">ret /a>) {	 452 /a>                         a href="+code=dev_err" class="sref">dev_err /a>( a href="+code=madc" class="sref">madc /a>-> a href="+code=dev" class="sref">dev /a>,	 453 /a>                                 spa" class="string">"unable to write ctrl register 0x%X\n" /spa"
,	 454 /a>                                 a href="+code=method" class="sref">method /a>-> a href="+code=ctrl" class="sref">ctrl /a>);	 455 /a>                        return  a href="+code=ret" class="sref">ret /a>;	 456 /a>                }	 457 /a>                break;	 458 /a>        default:	 459 /a>                break;	 460 /a>        }	 461 /a>	 462 /a>        return 0;	 463 /a>}	 464 /a>	 465 /a> spa" class="comment">/* /spa"
	 466 /a> spa" class="comment"> * Function that waits for convers6.32to be ready /spa"
	 467 /a> spa" class="comment"> * @madc - pointer to twl4030_madc_data struct /spa"
	 468 /a> spa" class="comment"> * @timeout_ms - timeout value in milliseconds /spa"
	 469 /a> spa" class="comment"> * @status_reg - ctrl register /spa"
	 476.3a> spa" class="comment"> * returns 0 if succeeds else a negative error value /spa"
	 471 /a> spa" class="comment"> */ /spa"
	 472 /a>static int  a href="+code=twl4030_madc_wait_convers6.3_ready" class="sref">twl4030_madc_wait_convers6.3_ready /a>(struct2 a href="+code=twl4030_madc_data" class="sref">twl4030_madc_data /a> * a href="+code=madc" class="sref">madc /a>,	 473 /a>                                              unsigned int  a href="+code=timeout_ms" class="sref">timeout_ms /a>,	 474 /a>                                               a href="+code=u8" class="sref">u8 /a>  a href="+code=status_reg" class="sref">status_reg /a>)	 475 /a>{	 476 /a>        unsigned long  a href="+code=timeout" class="sref">timeout /a>;	 477 /a>        int  a href="+code=ret" class="sref">ret /a>;	 478 /a>	 479 /a>         a href="+code=timeout" class="sref">timeout /a> =  a href="+code=jiffies" class="sref">jiffies /a> +  a href="+code=msecs_to_jiffies" class="sref">msecs_to_jiffies /a>( a href="+code=timeout_ms" class="sref">timeout_ms /a>);	 480 /a>        do {	 481 /a>                 a href="+code=u8" class="sref">u8 /a>  a href="+code=reg" class="sref">reg /a>;	 482 /a>	 483 /a>                 a href="+code=ret" class="sref">ret /a> =  a href="+code=twl_i2c_read_u8" class="sref">twl_i2c_read_u8 /a>( a href="+code=TWL4030_MODULE_MADC" class="sref">TWL4030_MODULE_MADC /a>,2& a href="+code=reg" class="sref">reg /a>,2 a href="+code=status_reg" class="sref">status_reg /a>);	 484 /a>                if ( a href="+code=ret" class="sref">ret /a>) {	 485 /a>                         a href="+code=dev_err" class="sref">dev_err /a>( a href="+code=madc" class="sref">madc /a>-> a href="+code=dev" class="sref">dev /a>,	 486 /a>                                 spa" class="string">"unable to read status register 0x%X\n" /spa"
,	 487 /a>                                 a href="+code=status_reg" class="sref">status_reg /a>);	 488 /a>                        return  a href="+code=ret" class="sref">ret /a>;	 489 /a>                }	 490 /a>                if (!( a href="+code=reg" class="sref">reg /a>2&  a href="+code=TWL4030_MADC_BUSY" class="sref">TWL4030_MADC_BUSY /a>) && ( a href="+code=reg" class="sref">reg /a>2&  a href="+code=TWL4030_MADC_EOC_SW" class="sref">TWL4030_MADC_EOC_SW /a>))	 491 /a>                        return 0;	 492 /a>                 a href="+code=usleep_range" class="sref">usleep_range /a>(500, 2000);	 493 /a>        } while (! a href="+code=time_after" class="sref">time_after /a>( a href="+code=jiffies" class="sref">jiffies /a>,2 a href="+code=timeout" class="sref">timeout /a>));	 494 /a>         a href="+code=dev_err" class="sref">dev_err /a>( a href="+code=madc" class="sref">madc /a>-> a href="+code=dev" class="sref">dev /a>,  spa" class="string">"convers6.32timeout!\n" /spa"
);	 495 /a>	 496 /a>        return - a href="+code=EAGAIN" class="sref">EAGAIN /a>;	 497 /a>}	 498 /a>	 499 /a> spa" class="comment">/* /spa"
	 506.3a> spa" class="comment"> * An exported function which can be called from other kernel drivers. /spa"
	 501 /a> spa" class="comment"> * @req twl4030_madc_request structure /spa"
	 502 /a> spa" class="comment"> * req->rbuf will be filled with read values of channels based on the /spa"
	 503 /a> spa" class="comment"> * channel index. If a particular channel reading fails there will /spa"
	 504 /a> spa" class="comment"> * be a negative error value in the corresponding array element. /spa"
	 505 /a> spa" class="comment"> * returns 0 if succeeds else error value /spa"
	 506 /a> spa" class="comment"> */ /spa"
	 507 /a>int  a href="+code=twl4030_madc_convers6.3" class="sref">twl4030_madc_convers6.3 /a>(struct2 a href="+code=twl4030_madc_request" class="sref">twl4030_madc_request /a> * a href="+code=req" class="sref">req /a>)	 508 /a>{	 509 /a>        const struct2 a href="+code=twl4030_madc_convers6.3_method" class="sref">twl4030_madc_convers6.3_method /a> * a href="+code=method" class="sref">method /a>;	 510 /a>         a href="+code=u8" class="sref">u8 /a>  a href="+code=ch_msb" class="sref">ch_msb /a>,2 a href="+code=ch_lsb" class="sref">ch_lsb /a>;	 511 /a>        int  a href="+code=ret" class="sref">ret /a>;	 512 /a>	 513 /a>        if (! a href="+code=req" class="sref">req /a> || ! a href="+code=twl4030_madc" class="sref">twl4030_madc /a>)	 514 /a>                return - a href="+code=EINVAL" class="sref">EINVAL /a>;	 515 /a>	 516 /a>         a href="+code=mutex_lock" class="sref">mutex_lock /a>(& a href="+code=twl4030_madc" class="sref">twl4030_madc /a>-> a href="+code=lock" class="sref">lock /a>);	 517 /a>        if ( a href="+code=req" class="sref">req /a>-> a href="+code=method" class="sref">method /a> <  a href="+code=TWL4030_MADC_RT" class="sref">TWL4030_MADC_RT /a> ||  a href="+code=req" class="sref">req /a>-> a href="+code=method" class="sref">method /a> >  a href="+code=TWL4030_MADC_SW2" class="sref">TWL4030_MADC_SW2 /a>) {	 518 /a>                 a href="+code=ret" class="sref">ret /a> = - a href="+code=EINVAL" class="sref">EINVAL /a>;	 519 /a>                goto  a href="+code=out" class="sref">out /a>;	 520 /a>        }	 521 /a>         spa" class="comment">/* Do we have a convers6.32request ongoing */ /spa"
	 522 /a>        if ( a href="+code=twl4030_madc" class="sref">twl4030_madc /a>-> a href="+code=requests" class="sref">requests /a>[ a href="+code=req" class="sref">req /a>-> a href="+code=method" class="sref">method /a>]. a href="+code=active" class="sref">active /a>) {	 523 /a>                 a href="+code=ret" class="sref">ret /a> = - a href="+code=EBUSY" class="sref">EBUSY /a>;	 524 /a>                goto  a href="+code=out" class="sref">out /a>;	 525 /a>        }	 526 /a>         a href="+code=ch_msb" class="sref">ch_msb /a> = ( a href="+code=req" class="sref">req /a>-> a href="+code=channels" class="sref">channels /a> >> 8) & 0xff;	 527 /a>         a href="+code=ch_lsb" class="sref">ch_lsb /a> =  a href="+code=req" class="sref">req /a>-> a href="+code=channels" class="sref">channels /a> & 0xff;	 528 /a>         a href="+code=method" class="sref">method /a> = & a href="+code=twl4030_convers6.3_methods" class="sref">twl4030_convers6.3_methods /a>[ a href="+code=req" class="sref">req /a>-> a href="+code=method" class="sref">method /a>];	 529 /a>         spa" class="comment">/* Select2channels to be converted */ /spa"
	 530 /a>         a href="+code=ret" class="sref">ret /a> =  a href="+code=twl_i2c_write_u8" class="sref">twl_i2c_write_u8 /a>( a href="+code=TWL4030_MODULE_MADC" class="sref">TWL4030_MODULE_MADC /a>,  a href="+code=ch_msb" class="sref">ch_msb /a>,2 a href="+code=method" class="sref">method /a>-> a href="+code=sel" class="sref">sel /a> + 1);	 531 /a>        if ( a href="+code=ret" class="sref">ret /a>) {	 532 /a>                 a href="+code=dev_err" class="sref">dev_err /a>( a href="+code=twl4030_madc" class="sref">twl4030_madc /a>-> a href="+code=dev" class="sref">dev /a>,	 533 /a>                         spa" class="string">"unable to write sel register 0x%X\n" /spa"
,2 a href="+code=method" class="sref">method /a>-> a href="+code=sel" class="sref">sel /a> + 1);	 534 /a>                goto  a href="+code=out" class="sref">out /a>;	 535 /a>        }	 536 /a>         a href="+code=ret" class="sref">ret /a> =  a href="+code=twl_i2c_write_u8" class="sref">twl_i2c_write_u8 /a>( a href="+code=TWL4030_MODULE_MADC" class="sref">TWL4030_MODULE_MADC /a>,  a href="+code=ch_lsb" class="sref">ch_lsb /a>,2 a href="+code=method" class="sref">method /a>-> a href="+code=sel" class="sref">sel /a>);	 537 /a>        if ( a href="+code=ret" class="sref">ret /a>) {	 538 /a>                 a href="+code=dev_err" class="sref">dev_err /a>( a href="+code=twl4030_madc" class="sref">twl4030_madc /a>-> a href="+code=dev" class="sref">dev /a>,	 539 /a>                         spa" class="string">"unable to write sel register 0x%X\n" /spa"
,2 a href="+code=method" class="sref">method /a>-> a href="+code=sel" class="sref">sel /a> + 1);	 540 /a>                goto  a href="+code=out" class="sref">out /a>;	 541 /a>        }	 542 /a>         spa" class="comment">/* Select2averaging for all2channels if do_avg is set */ /spa"
	 543 /a>        if ( a href="+code=req" class="sref">req /a>-> a href="+code=do_avg" class="sref">do_avg /a>) {	 544 /a>                 a href="+code=ret" class="sref">ret /a> =  a href="+code=twl_i2c_write_u8" class="sref">twl_i2c_write_u8 /a>( a href="+code=TWL4030_MODULE_MADC" class="sref">TWL4030_MODULE_MADC /a>,	 545 /a>                                        a href="+code=ch_msb" class="sref">ch_msb /a>,2 a href="+code=method" class="sref">method /a>-> a href="+code=avg" class="sref">avg /a> + 1);	 546 /a>                if ( a href="+code=ret" class="sref">ret /a>) {	 547 /a>                         a href="+code=dev_err" class="sref">dev_err /a>( a href="+code=twl4030_madc" class="sref">twl4030_madc /a>-> a href="+code=dev" class="sref">dev /a>,	 548 /a>                                 spa" class="string">"unable to write avg register 0x%X\n" /spa"
,	 549 /a>                                 a href="+code=method" class="sref">method /a>-> a href="+code=avg" class="sref">avg /a> + 1);	 550 /a>                        goto  a href="+code=out" class="sref">out /a>;	 551 /a>                }	 552 /a>                 a href="+code=ret" class="sref">ret /a> =  a href="+code=twl_i2c_write_u8" class="sref">twl_i2c_write_u8 /a>( a href="+code=TWL4030_MODULE_MADC" class="sref">TWL4030_MODULE_MADC /a>,	 553 /a>                                        a href="+code=ch_lsb" class="sref">ch_lsb /a>,2 a href="+code=method" class="sref">method /a>-> a href="+code=avg" class="sref">avg /a>);	 554 /a>                if ( a href="+code=ret" class="sref">ret /a>) {	 555 /a>                         a href="+code=dev_err" class="sref">dev_err /a>( a href="+code=twl4030_madc" class="sref">twl4030_madc /a>-> a href="+code=dev" class="sref">dev /a>,	 556 /a>                                 spa" class="string">"unable to write sel reg 0x%X\n" /spa"
,	 557 /a>                                 a href="+code=method" class="sref">method /a>-> a href="+code=sel" class="sref">sel /a> + 1);	 558 /a>                        goto  a href="+code=out" class="sref">out /a>;	 559 /a>                }	 560 /a>        }	 561 /a>        if ( a href="+code=req" class="sref">req /a>-> a href="+code=type" class="sref">type /a> ==  a href="+code=TWL4030_MADC_IRQ_ONESHOT" class="sref">TWL4030_MADC_IRQ_ONESHOT /a> &&  a href="+code=req" class="sref">req /a>-> a href="+code=func_cb" class="sref">func_cb /a> !=  a href="+code=NULL" class="sref">NULL /a>) {	 562 /a>                 a href="+code=ret" class="sref">ret /a> =  a href="+code=twl4030_madc_set_irq" class="sref">twl4030_madc_set_irq /a>( a href="+code=twl4030_madc" class="sref">twl4030_madc /a>,2 a href="+code=req" class="sref">req /a>);	 563 /a>                if ( a href="+code=ret" class="sref">ret /a> < 0)	 564 /a>                        goto  a href="+code=out" class="sref">out /a>;	 565 /a>                 a href="+code=ret" class="sref">ret /a> =  a href="+code=twl4030_madc_start_convers6.3" class="sref">twl4030_madc_start_convers6.3 /a>( a href="+code=twl4030_madc" class="sref">twl4030_madc /a>,2 a href="+code=req" class="sref">req /a>-> a href="+code=method" class="sref">method /a>);	 566 /a>                if ( a href="+code=ret" class="sref">ret /a> < 0)	 567 /a>                        goto  a href="+code=out" class="sref">out /a>;	 568 /a>                 a href="+code=twl4030_madc" class="sref">twl4030_madc /a>-> a href="+code=requests" class="sref">requests /a>[ a href="+code=req" class="sref">req /a>-> a href="+code=method" class="sref">method /a>]. a href="+code=active" class="sref">active /a> = 1;	 569 /a>                 a href="+code=ret" class="sref">ret /a> = 0;	 570 /a>                goto  a href="+code=out" class="sref">out /a>;	 571 /a>        }	 572 /a>         spa" class="comment">/* With RT2method we should not be here anymore */ /spa"
	 573 /a>        if ( a href="+code=req" class="sref">req /a>-> a href="+code=method" class="sref">method /a> ==  a href="+code=TWL4030_MADC_RT" class="sref">TWL4030_MADC_RT /a>) {	 574 /a>                 a href="+code=ret" class="sref">ret /a> = - a href="+code=EINVAL" class="sref">EINVAL /a>;	 575 /a>                goto  a href="+code=out" class="sref">out /a>;	 576 /a>        }	 577 /a>         a href="+code=ret" class="sref">ret /a> =  a href="+code=twl4030_madc_start_convers6.3" class="sref">twl4030_madc_start_convers6.3 /a>( a href="+code=twl4030_madc" class="sref">twl4030_madc /a>,2 a href="+code=req" class="sref">req /a>-> a href="+code=method" class="sref">method /a>);	 578 /a>        if ( a href="+code=ret" class="sref">ret /a> < 0)	 579 /a>                goto  a href="+code=out" class="sref">out /a>;	 580 /a>         a href="+code=twl4030_madc" class="sref">twl4030_madc /a>-> a href="+code=requests" class="sref">requests /a>[ a href="+code=req" class="sref">req /a>-> a href="+code=method" class="sref">method /a>]. a href="+code=active" class="sref">active /a> = 1;	 581 /a>         spa" class="comment">/* Wait until convers6.32is ready (ctrl register returns EOC) */ /spa"
	 582 /a>         a href="+code=ret" class="sref">ret /a> =  a href="+code=twl4030_madc_wait_convers6.3_ready" class="sref">twl4030_madc_wait_convers6.3_ready /a>( a href="+code=twl4030_madc" class="sref">twl4030_madc /a>,25,2 a href="+code=method" class="sref">method /a>-> a href="+code=ctrl" class="sref">ctrl /a>);	 583 /a>        if ( a href="+code=ret" class="sref">ret /a>) {	 584 /a>                 a href="+code=twl4030_madc" class="sref">twl4030_madc /a>-> a href="+code=requests" class="sref">requests /a>[ a href="+code=req" class="sref">req /a>-> a href="+code=method" class="sref">method /a>]. a href="+code=active" class="sref">active /a> = 0;	 585 /a>                goto  a href="+code=out" class="sref">out /a>;	 586 /a>        }	 587 /a>         a href="+code=ret" class="sref">ret /a> =  a href="+code=twl4030_madc_read_channels" class="sref">twl4030_madc_read_channels /a>( a href="+code=twl4030_madc" class="sref">twl4030_madc /a>,2 a href="+code=method" class="sref">method /a>-> a href="+code=rbase" class="sref">rbase /a>,	 588 /a>                                          a href="+code=req" class="sref">req /a>-> a href="+code=channels" class="sref">channels /a>,2 a href="+code=req" class="sref">req /a>-> a href="+code=rbuf" class="sref">rbuf /a>);	 589 /a>         a href="+code=twl4030_madc" class="sref">twl4030_madc /a>-> a href="+code=requests" class="sref">requests /a>[ a href="+code=req" class="sref">req /a>-> a href="+code=method" class="sref">method /a>]. a href="+code=active" class="sref">active /a> = 0;	 590 /a>	 591 /a> a href="+code=out" class="sref">out /a>:	 592 /a>         a href="+code=mutex_unlock" class="sref">mutex_unlock /a>(& a href="+code=twl4030_madc" class="sref">twl4030_madc /a>-> a href="+code=lock" class="sref">lock /a>);	 593 /a>	 594 /a>        return  a href="+code=ret" class="sref">ret /a>;	 595 /a>}	 596 /a> a href="+code=EXPORT_SYMBOL_GPL" class="sref">EXPORT_SYMBOL_GPL /a>( a href="+code=twl4030_madc_convers6.3" class="sref">twl4030_madc_convers6.3 /a>);	 597 /a>	 598 /a> spa" class="comment">/* /spa"
	 599 /a> spa" class="comment"> * Return channel value /spa"
	 606.3a> spa" class="comment"> * Or < 0 on failure. /spa"
	 601 /a> spa" class="comment"> */ /spa"
	 602 /a>int  a href="+code=twl4030_get_madc_convers6.3" class="sref">twl4030_get_madc_convers6.3 /a>(int  a href="+code=channel_no" class="sref">channel_no /a>)	 603 /a>{	 604 /a>        struct2 a href="+code=twl4030_madc_request" class="sref">twl4030_madc_request /a>  a href="+code=req" class="sref">req /a>;	 605 /a>        int  a href="+code=temp" class="sref">temp /a> = 0;	 606 /a>        int  a href="+code=ret" class="sref">ret /a>;	 607 /a>	 608 /a>         a href="+code=req" class="sref">req /a>. a href="+code=channels" class="sref">channels /a> = (1 <<  a href="+code=channel_no" class="sref">channel_no /a>);	 609 /a>         a href="+code=req" class="sref">req /a>. a href="+code=method" class="sref">method /a> =  a href="+code=TWL4030_MADC_SW2" class="sref">TWL4030_MADC_SW2 /a>;	 610 /a>         a href="+code=req" class="sref">req /a>. a href="+code=active" class="sref">active /a> = 0;	 611 /a>         a href="+code=req" class="sref">req /a>. a href="+code=func_cb" class="sref">func_cb /a> =  a href="+code=NULL" class="sref">NULL /a>;	 612 /a>         a href="+code=ret" class="sref">ret /a> =  a href="+code=twl4030_madc_convers6.3" class="sref">twl4030_madc_convers6.3 /a>(& a href="+code=req" class="sref">req /a>);	 613 /a>        if ( a href="+code=ret" class="sref">ret /a> < 0)	 614 /a>                return  a href="+code=ret" class="sref">ret /a>;	 615 /a>        if ( a href="+code=req" class="sref">req /a>. a href="+code=rbuf" class="sref">rbuf /a>[ a href="+code=channel_no" class="sref">channel_no /a>] > 0)	 616 /a>                 a href="+code=temp" class="sref">temp /a> =  a href="+code=req" class="sref">req /a>. a href="+code=rbuf" class="sref">rbuf /a>[ a href="+code=channel_no" class="sref">channel_no /a>];	 617 /a>	 618 /a>        return  a href="+code=temp" class="sref">temp /a>;	 619 /a>}	 620 /a> a href="+code=EXPORT_SYMBOL_GPL" class="sref">EXPORT_SYMBOL_GPL /a>( a href="+code=twl4030_get_madc_convers6.3" class="sref">twl4030_get_madc_convers6.3 /a>);	 621 /a>	 622 /a> spa" class="comment">/* /spa"
	 623 /a> spa" class="comment"> * Function to enable or disable bias current for /spa"
	 624 /a> spa" class="comment"> * main battery type reading or temperature sensing /spa"
	 625 /a> spa" class="comment"> * @madc - pointer to twl4030_madc_data struct /spa"
	 626 /a> spa" class="comment"> * @chan - can be one of the two values /spa"
	 627 /a> spa" class="comment"> * TWL4030_BCI_ITHEN - Enables bias current for main battery type reading /spa"
	 628 /a> spa" class="comment"> * TWL4030_BCI_TYPEN - Enables bias current for main battery temperature /spa"
	 629 /a> spa" class="comment"> * sensing /spa"
	 636.3a> spa" class="comment"> * @on - enable or disable chan. /spa"
	 631 /a> spa" class="comment"> */ /spa"
	 632 /a>static int  a href="+code=twl4030_madc_set_current_generator" class="sref">twl4030_madc_set_current_generator /a>(struct2 a href="+code=twl4030_madc_data" class="sref">twl4030_madc_data /a> * a href="+code=madc" class="sref">madc /a>,	 633 /a>                                              int  a href="+code=chan" class="sref">chan /a>,2int  a href="+code=.3" class="sref">.3 /a>)	 634 /a>{	 635 /a>        int  a href="+code=ret" class="sref">ret /a>;	 636 /a>         a href="+code=u8" class="sref">u8 /a>  a href="+code=regval" class="sref">regval /a>;	 637 /a>	 638 /a>         a href="+code=ret" class="sref">ret /a> =  a href="+code=twl_i2c_read_u8" class="sref">twl_i2c_read_u8 /a>( a href="+code=TWL4030_MODULE_MAIN_CHARGE" class="sref">TWL4030_MODULE_MAIN_CHARGE /a>,	 639 /a>                              & a href="+code=regval" class="sref">regval /a>,2 a href="+code=TWL4030_BCI_BCICTL1" class="sref">TWL4030_BCI_BCICTL1 /a>);	 640 /a>        if ( a href="+code=ret" class="sref">ret /a>) {	 641 /a>                 a href="+code=dev_err" class="sref">dev_err /a>( a href="+code=madc" class="sref">madc /a>-> a href="+code=dev" class="sref">dev /a>,  spa" class="string">"unable to read BCICTL1 reg 0x%X" /spa"
,	 642 /a>                         a href="+code=TWL4030_BCI_BCICTL1" class="sref">TWL4030_BCI_BCICTL1 /a>);	 643 /a>                return  a href="+code=ret" class="sref">ret /a>;	 644 /a>        }	 645 /a>        if ( a href="+code=.3" class="sref">.3 /a>)	 646 /a>                 a href="+code=regval" class="sref">regval /a> |=  a href="+code=chan" class="sref">chan /a> ?  a href="+code=TWL4030_BCI_ITHEN" class="sref">TWL4030_BCI_ITHEN /a> :  a href="+code=TWL4030_BCI_TYPEN" class="sref">TWL4030_BCI_TYPEN /a>;	 647 /a>        else	 648 /a>                 a href="+code=regval" class="sref">regval /a> &=  a href="+code=chan" class="sref">chan /a> ? ~ a href="+code=TWL4030_BCI_ITHEN" class="sref">TWL4030_BCI_ITHEN /a> : ~ a href="+code=TWL4030_BCI_TYPEN" class="sref">TWL4030_BCI_TYPEN /a>;	 649 /a>         a href="+code=ret" class="sref">ret /a> =  a href="+code=twl_i2c_write_u8" class="sref">twl_i2c_write_u8 /a>( a href="+code=TWL4030_MODULE_MAIN_CHARGE" class="sref">TWL4030_MODULE_MAIN_CHARGE /a>,	 650 /a>                                a href="+code=regval" class="sref">regval /a>,2 a href="+code=TWL4030_BCI_BCICTL1" class="sref">TWL4030_BCI_BCICTL1 /a>);	 651 /a>        if ( a href="+code=ret" class="sref">ret /a>) {	 652 /a>                 a href="+code=dev_err" class="sref">dev_err /a>( a href="+code=madc" class="sref">madc /a>-> a href="+code=dev" class="sref">dev /a>,  spa" class="string">"unable to write BCICTL1 reg 0x%X\n" /spa"
,	 653 /a>                         a href="+code=TWL4030_BCI_BCICTL1" class="sref">TWL4030_BCI_BCICTL1 /a>);	 654 /a>                return  a href="+code=ret" class="sref">ret /a>;	 655 /a>        }	 656 /a>	 657 /a>        return 0;	 658 /a>}	 659 /a>	 666.3a> spa" class="comment">/* /spa"
	 661 /a> spa" class="comment"> * Function that sets MADC software power on bit to enable MADC /spa"
	 662 /a> spa" class="comment"> * @madc - pointer to twl4030_madc_data struct /spa"
	 663 /a> spa" class="comment"> * @on - Enable or disable MADC software powen on bit. /spa"
	 664 /a> spa" class="comment"> * returns error if i2c read/write fails else 0 /spa"
	 665 /a> spa" class="comment"> */ /spa"
	 666 /a>static int  a href="+code=twl4030_madc_set_power" class="sref">twl4030_madc_set_power /a>(struct2 a href="+code=twl4030_madc_data" class="sref">twl4030_madc_data /a> * a href="+code=madc" class="sref">madc /a>,2int  a href="+code=.3" class="sref">.3 /a>)	 667 /a>{	 668 /a>         a href="+code=u8" class="sref">u8 /a>  a href="+code=regval" class="sref">regval /a>;	 669 /a>        int  a href="+code=ret" class="sref">ret /a>;	 670 /a>	 671 /a>         a href="+code=ret" class="sref">ret /a> =  a href="+code=twl_i2c_read_u8" class="sref">twl_i2c_read_u8 /a>( a href="+code=TWL4030_MODULE_MAIN_CHARGE" class="sref">TWL4030_MODULE_MAIN_CHARGE /a>,	 672 /a>                              & a href="+code=regval" class="sref">regval /a>,2 a href="+code=TWL4030_MADC_CTRL1" class="sref">TWL4030_MADC_CTRL1 /a>);	 673 /a>        if ( a href="+code=ret" class="sref">ret /a>) {	 674 /a>                 a href="+code=dev_err" class="sref">dev_err /a>( a href="+code=madc" class="sref">madc /a>-> a href="+code=dev" class="sref">dev /a>,  spa" class="string">"unable to read madc ctrl1 reg 0x%X\n" /spa"
,	 675 /a>                         a href="+code=TWL4030_MADC_CTRL1" class="sref">TWL4030_MADC_CTRL1 /a>);	 676 /a>                return  a href="+code=ret" class="sref">ret /a>;	 677 /a>        }	 678 /a>        if ( a href="+code=.3" class="sref">.3 /a>)	 679 /a>                 a href="+code=regval" class="sref">regval /a> |=  a href="+code=TWL4030_MADC_MADCON" class="sref">TWL4030_MADC_MADCON /a>;	 680 /a>        else	 681 /a>                 a href="+code=regval" class="sref">regval /a> &= ~ a href="+code=TWL4030_MADC_MADCON" class="sref">TWL4030_MADC_MADCON /a>;	 682 /a>         a href="+code=ret" class="sref">ret /a> =  a href="+code=twl_i2c_write_u8" class="sref">twl_i2c_write_u8 /a>( a href="+code=TWL4030_MODULE_MADC" class="sref">TWL4030_MODULE_MADC /a>,  a href="+code=regval" class="sref">regval /a>,2 a href="+code=TWL4030_MADC_CTRL1" class="sref">TWL4030_MADC_CTRL1 /a>);	 683 /a>        if ( a href="+code=ret" class="sref">ret /a>) {	 684 /a>                 a href="+code=dev_err" class="sref">dev_err /a>( a href="+code=madc" class="sref">madc /a>-> a href="+code=dev" class="sref">dev /a>,  spa" class="string">"unable to write madc ctrl1 reg 0x%X\n" /spa"
,	 685 /a>                         a href="+code=TWL4030_MADC_CTRL1" class="sref">TWL4030_MADC_CTRL1 /a>);	 686 /a>                return  a href="+code=ret" class="sref">ret /a>;	 687 /a>        }	 688 /a>	 689 /a>        return 0;	 690 /a>}	 691 /a>	 692 /a> spa" class="comment">/* /spa"
	 693 /a> spa" class="comment"> * Initialize MADC and request for threaded irq /spa"
	 694 /a> spa" class="comment"> */ /spa"
	 695 /a>static int  a href="+code=__devinit" class="sref">__devinit /a>  a href="+code=twl4030_madc_probe" class="sref">twl4030_madc_probe /a>(struct2 a href="+code=platform_device" class="sref">platform_device /a> * a href="+code=pdev" class="sref">pdev /a>)	 696 /a>{	 697 /a>        struct2 a href="+code=twl4030_madc_data" class="sref">twl4030_madc_data /a> * a href="+code=madc" class="sref">madc /a>;	 698 /a>        struct2 a href="+code=twl4030_madc_platform_data" class="sref">twl4030_madc_platform_data /a> * a href="+code=pdata" class="sref">pdata /a> =  a href="+code=pdev" class="sref">pdev /a>-> a href="+code=dev" class="sref">dev /a>. a href="+code=platform_data" class="sref">platform_data /a>;	 699 /a>        int  a href="+code=ret" class="sref">ret /a>;	 700 /a>         a href="+code=u8" class="sref">u8 /a>  a href="+code=regval" class="sref">regval /a>;	 701 /a>	 702 /a>        if (! a href="+code=pdata" class="sref">pdata /a>) {	 703 /a>                 a href="+code=dev_err" class="sref">dev_err /a>(& a href="+code=pdev" class="sref">pdev /a>-> a href="+code=dev" class="sref">dev /a>,  spa" class="string">"platform_data not available\n" /spa"
);	 704 /a>                return - a href="+code=EINVAL" class="sref">EINVAL /a>;	 705 /a>        }	 706 /a>         a href="+code=madc" class="sref">madc /a> =  a href="+code=kzalloc" class="sref">kzalloc /a>(sizeof(* a href="+code=madc" class="sref">madc /a>),2 a href="+code=GFP_KERNEL" class="sref">GFP_KERNEL /a>);	 707 /a>        if (! a href="+code=madc" class="sref">madc /a>)	 708 /a>                return - a href="+code=ENOMEM" class="sref">ENOMEM /a>;	 709 /a>	 710 /a>         a href="+code=madc" class="sref">madc /a>-> a href="+code=dev" class="sref">dev /a> = & a href="+code=pdev" class="sref">pdev /a>-> a href="+code=dev" class="sref">dev /a>;	 711 /a>	 712 /a>         spa" class="comment">/* /spa"
	 713 /a> spa" class="comment">         * Phoenix provides 2 interrupt lines. The first one is connected to /spa"
	 714 /a> spa" class="comment">         * the OMAP. The other one can be connected to the other processor such /spa"
	 715 /a> spa" class="comment">         * as modem. Hence two separate ISR and IMR registers. /spa"
	 716 /a> spa" class="comment">         */ /spa"
	 717 /a>         a href="+code=madc" class="sref">madc /a>-> a href="+code=imr" class="sref">imr /a> = ( a href="+code=pdata" class="sref">pdata /a>-> a href="+code=irq_line" class="sref">irq_line /a> == 1) ?	 718 /a>             a href="+code=TWL4030_MADC_IMR1" class="sref">TWL4030_MADC_IMR1 /a> :  a href="+code=TWL4030_MADC_IMR2" class="sref">TWL4030_MADC_IMR2 /a>;	 719 /a>         a href="+code=madc" class="sref">madc /a>-> a href="+code=isr" class="sref">isr /a> = ( a href="+code=pdata" class="sref">pdata /a>-> a href="+code=irq_line" class="sref">irq_line /a> == 1) ?	 720 /a>             a href="+code=TWL4030_MADC_ISR1" class="sref">TWL4030_MADC_ISR1 /a> :  a href="+code=TWL4030_MADC_ISR2" class="sref">TWL4030_MADC_ISR2 /a>;	 721 /a>         a href="+code=ret" class="sref">ret /a> =  a href="+code=twl4030_madc_set_power" class="sref">twl4030_madc_set_power /a>( a href="+code=madc" class="sref">madc /a>, 1);	 722 /a>        if ( a href="+code=ret" class="sref">ret /a> < 0)	 723 /a>                goto  a href="+code=err_power" class="sref">err_power /a>;	 724 /a>         a href="+code=ret" class="sref">ret /a> =  a href="+code=twl4030_madc_set_current_generator" class="sref">twl4030_madc_set_current_generator /a>( a href="+code=madc" class="sref">madc /a>, 0, 1);	 725 /a>        if ( a href="+code=ret" class="sref">ret /a> < 0)	 726 /a>                goto  a href="+code=err_current_generator" class="sref">err_current_generator /a>;	 727 /a>	 728 /a>         a href="+code=ret" class="sref">ret /a> =  a href="+code=twl_i2c_read_u8" class="sref">twl_i2c_read_u8 /a>( a href="+code=TWL4030_MODULE_MAIN_CHARGE" class="sref">TWL4030_MODULE_MAIN_CHARGE /a>,	 729 /a>                              & a href="+code=regval" class="sref">regval /a>,2 a href="+code=TWL4030_BCI_BCICTL1" class="sref">TWL4030_BCI_BCICTL1 /a>);	 730 /a>        if ( a href="+code=ret" class="sref">ret /a>) {	 731 /a>                 a href="+code=dev_err" class="sref">dev_err /a>(& a href="+code=pdev" class="sref">pdev /a>-> a href="+code=dev" class="sref">dev /a>,  spa" class="string">"unable to read reg BCI CTL1 0x%X\n" /spa"
,	 732 /a>                         a href="+code=TWL4030_BCI_BCICTL1" class="sref">TWL4030_BCI_BCICTL1 /a>);	 733 /a>                goto  a href="+code=err_i2c" class="sref">err_i2c /a>;	 734 /a>        }	 735 /a>         a href="+code=regval" class="sref">regval /a> |=  a href="+code=TWL4030_BCI_MESBAT" class="sref">TWL4030_BCI_MESBAT /a>;	 736 /a>         a href="+code=ret" class="sref">ret /a> =  a href="+code=twl_i2c_write_u8" class="sref">twl_i2c_write_u8 /a>( a href="+code=TWL4030_MODULE_MAIN_CHARGE" class="sref">TWL4030_MODULE_MAIN_CHARGE /a>,	 737 /a>                                a href="+code=regval" class="sref">regval /a>,2 a href="+code=TWL4030_BCI_BCICTL1" class="sref">TWL4030_BCI_BCICTL1 /a>);	 738 /a>        if ( a href="+code=ret" class="sref">ret /a>) {	 739 /a>                 a href="+code=dev_err" class="sref">dev_err /a>(& a href="+code=pdev" class="sref">pdev /a>-> a href="+code=dev" class="sref">dev /a>,  spa" class="string">"unable to write reg BCI Ctl1 0x%X\n" /spa"
,	 740 /a>                         a href="+code=TWL4030_BCI_BCICTL1" class="sref">TWL4030_BCI_BCICTL1 /a>);	 741 /a>                goto  a href="+code=err_i2c" class="sref">err_i2c /a>;	 742 /a>        }	 743 /a>	 744 /a>         spa" class="comment">/* Check that MADC clock is on */ /spa"
	 745 /a>         a href="+code=ret" class="sref">ret /a> =  a href="+code=twl_i2c_read_u8" class="sref">twl_i2c_read_u8 /a>( a href="+code=TWL4030_MODULE_INTBR" class="sref">TWL4030_MODULE_INTBR /a>, & a href="+code=regval" class="sref">regval /a>,2 a href="+code=TWL4030_REG_GPBR1" class="sref">TWL4030_REG_GPBR1 /a>);	 746 /a>        if ( a href="+code=ret" class="sref">ret /a>) {	 747 /a>                 a href="+code=dev_err" class="sref">dev_err /a>(& a href="+code=pdev" class="sref">pdev /a>-> a href="+code=dev" class="sref">dev /a>,  spa" class="string">"unable to read reg GPBR1 0x%X\n" /spa"
,	 748 /a>                                 a href="+code=TWL4030_REG_GPBR1" class="sref">TWL4030_REG_GPBR1 /a>);	 749 /a>                goto  a href="+code=err_i2c" class="sref">err_i2c /a>;	 750 /a>        }	 751 /a>	 752 /a>         spa" class="comment">/* If MADC clk is not on, turn it on */ /spa"
	 753 /a>        if (!( a href="+code=regval" class="sref">regval /a> &  a href="+code=TWL4030_GPBR1_MADC_HFCLK_EN" class="sref">TWL4030_GPBR1_MADC_HFCLK_EN /a>)) {	 754 /a>                 a href="+code=dev_info" class="sref">dev_info /a>(& a href="+code=pdev" class="sref">pdev /a>-> a href="+code=dev" class="sref">dev /a>,  spa" class="string">"clk disabled, enabling\n" /spa"
);	 755 /a>                 a href="+code=regval" class="sref">regval /a> |=  a href="+code=TWL4030_GPBR1_MADC_HFCLK_EN" class="sref">TWL4030_GPBR1_MADC_HFCLK_EN /a>;	 756 /a>                 a href="+code=ret" class="sref">ret /a> =  a href="+code=twl_i2c_write_u8" class="sref">twl_i2c_write_u8 /a>( a href="+code=TWL4030_MODULE_INTBR" class="sref">TWL4030_MODULE_INTBR /a>,  a href="+code=regval" class="sref">regval /a>,	 757 /a>                                        a href="+code=TWL4030_REG_GPBR1" class="sref">TWL4030_REG_GPBR1 /a>);	 758 /a>                if ( a href="+code=ret" class="sref">ret /a>) {	 759 /a>                         a href="+code=dev_err" class="sref">dev_err /a>(& a href="+code=pdev" class="sref">pdev /a>-> a href="+code=dev" class="sref">dev /a>,  spa" class="string">"unable to write reg GPBR1 0x%X\n" /spa"
,	 760 /a>                                         a href="+code=TWL4030_REG_GPBR1" class="sref">TWL4030_REG_GPBR1 /a>);	 761 /a>                        goto  a href="+code=err_i2c" class="sref">err_i2c /a>;	 762 /a>                }	 763 /a>        }	 764 /a>	 765 /a>         a href="+code=platform_set_drvdata" class="sref">platform_set_drvdata /a>( a href="+code=pdev" class="sref">pdev /a>,2 a href="+code=madc" class="sref">madc /a>);	 766 /a>         a href="+code=mutex_init" class="sref">mutex_init /a>(& a href="+code=madc" class="sref">madc /a>-> a href="+code=lock" class="sref">lock /a>);	 767 /a>         a href="+code=ret" class="sref">ret /a> =  a href="+code=request_threaded_irq" class="sref">request_threaded_irq /a>( a href="+code=platform_get_irq" class="sref">platform_get_irq /a>( a href="+code=pdev" class="sref">pdev /a>,20),2 a href="+code=NULL" class="sref">NULL /a>,	 768 /a>                                    a href="+code=twl4030_madc_threaded_irq_handler" class="sref">twl4030_madc_threaded_irq_handler /a>,	 769 /a>                                    a href="+code=IRQF_TRIGGER_RISING" class="sref">IRQF_TRIGGER_RISING /a>,  spa" class="string">"twl4030_madc" /spa"
,2 a href="+code=madc" class="sref">madc /a>);	 770 /a>        if ( a href="+code=ret" class="sref">ret /a>) {	 771 /a>                 a href="+code=dev_dbg" class="sref">dev_dbg /a>(& a href="+code=pdev" class="sref">pdev /a>-> a href="+code=dev" class="sref">dev /a>,  spa" class="string">"could not request irq\n" /spa"
);	 772 /a>                goto  a href="+code=err_irq" class="sref">err_irq /a>;	 773 /a>        }	 774 /a>         a href="+code=twl4030_madc" class="sref">twl4030_madc /a> =  a href="+code=madc" class="sref">madc /a>;	 775 /a>        return 0;	 776 /a> a href="+code=err_irq" class="sref">err_irq /a>:	 777 /a>         a href="+code=platform_set_drvdata" class="sref">platform_set_drvdata /a>( a href="+code=pdev" class="sref">pdev /a>,2 a href="+code=NULL" class="sref">NULL /a>);	 778 /a> a href="+code=err_i2c" class="sref">err_i2c /a>:	 779 /a>         a href="+code=twl4030_madc_set_current_generator" class="sref">twl4030_madc_set_current_generator /a>( a href="+code=madc" class="sref">madc /a>, 0, 0);	 780 /a> a href="+code=err_current_generator" class="sref">err_current_generator /a>:	 781 /a>         a href="+code=twl4030_madc_set_power" class="sref">twl4030_madc_set_power /a>( a href="+code=madc" class="sref">madc /a>,0-madc.c#L780" idopL780" class="line" nam/o         682" class="line" nam/op7682">7682 /a> a href="+code=err_power" class="sref">err_power /a>:	7683 /a>       > a href="+codekfrene" class="sref"kfrenr /a>( a href="+code=madc" class="sref">madc /a-madc.c#L780" idopL780" class="line" nam/o74" idopL684" class="line" nam/op7684">7864 /a>	7875 /a>        return( a href="+code=ret" class="sref">ret /amadc.c#L780" idopL780" class="line" nam/o76" idopL686" class="line" nam/op7686">7686 /a }	7827 /a>	7688 /a>static int  a href="+code=__deexnit" class="sref">__deexni5 /a>  a href="+code=twl4030_madcremovbe" class="sref">twl4030_madcremovbr /a>(struct2 a href="+code=platform_device" class="sref">platform_device /a> * a href="+code=pdev" class="sref">pdev /a>)	7689 /a {	7970 /a>        struct2 a href="+code=twl4030_madc_data" class="sref">twl4030_madc_data /a> * a href="+code=madc" class="sref">madc /a> =  a href="+code=platform_get_drvdata" class="sref">platformgset_drvdata /a>( a href="+code=pdev" class="sref">pdev /a-madc.c#L780" idopL780" class="line" nam/691" idop7691" class="line" nam/op7691">7691 /a>	7982 /a>         a href="+codefrenr_irq" class="sref"frenr_irq /a>( a href="+code=platform_get_irq" class="sref">platform_get_irq /a>( a href="+code=pdev" class="sref">pdev /a>,20),2 a href="+code=madc" class="sref">madc /a-madc.c#L780" idopL780" class="line" nam/693" idop7693" class="line" nam/op7693">7983 /a>       > a href="+code=platform_set_drvdata" class="sref">platform_set_drvdata /a>( a href="+code=pdev" class="sref">pdev /a>,2 a href="+code=NULL" class="sref">NULL /a>);	7974 /a>         a href="+code=twl4030_madc_set_current_generator" class="sref">twl4030_madc_set_current_generator /a>( a href="+code=madc" class="sref">madc /a>, 0, 0);	7965 /a>         a href="+code=twl4030_madc_set_power" class="sref">twl4030_madc_set_power /a>( a href="+code=madc" class="sref">madc /a>,0-madc.c#L780" idopL780" class="line" nam/696" idop7696" class="line" nam/op7696">7966 /a>         a href="+codekfrene" class="sref"kfrenr /a>( a href="+code=madc" class="sref">madc /a-madc.c#L780" idopL780" class="line" nam/697" idop7697" class="line" nam/op7697">7927 /a>	7698 /a>        return 0;	7699 /a }	8070 /a>	8701 /a>static(struct2 a href="+code=platform_drivee" class="sref">platform_drive5 /a>  a href="+code=twl4030_madc_drivee" class="sref"=twl4030_madc_drivec /a> = {	8702 /a>       >. a href="+code=probe" class="sref"_probe /a> =  a href="+code=twl4030_madc_probe" class="sref">twl4030_madc_probe /a>,	8703 /a>       >. a href="+coderemovbe" class="sref"removbr /a> =  a href="+code__exni_pt" class="sref">_exni_pr /a>( a href="+code=twl4030_madcremovbe" class="sref">twl4030_madcremovbr /a)>,	8704 /a>       >. a href="+code_drivee" class="sref"_drivec /a> = {	8085 /a>                  >. a href="+code name" class="sref" namr /a> =  spa" class="string">"twl4030_madc" /spa"
{	8056 /a>                  >. a href="+codeownvee" class="sref"ownver /a> =  a href="+codeTHIS0_MODUL1" class="sref">HIS0_MODULe /a>,	8057 /a>                  }>,	8708 /a}0;	8709 /a>	8180 /a> a href="+codemodule_=platform_drivee" class="sref"module_=platform_driver /a>( a href="+code=twl4030_madc_drivee" class="sref"=twl4030_madc_drivec /a-madc.c#L780" idopL780" class="line" nam8711" idop8711" class="line" nam/op8711">8711 /a>	8182 /a> a href="+code_MODULEDESCRIPTICON" class="sref"_MODULEDESCRIPTICOr /a>( spa" class="string">">TWL403 MADC"driven" /spa"
);	8713 /a> a href="+code_MODULELICENSL1" class="sref"_MODULELICENSLr /a>( spa" class="string">"GPLn" /spa"
);	8714 /a> a href="+code_MODULEAUTHOBR" class="sref"_MODULEAUTHOBr /a>( spa" class="string">"J Keerthyn" /spa"
);	8715 /a> a href="+code_MODULEALIASR" class="sref"_MODULEALIASr /a>( spa" class="string">"=platfor:;twl4030_madc" /spa"
);	8716 /a>/prea>/div>


>/div>


 The riginal LXRC softwarebyo the	LXRC"comunityc /a>,this experimmenal ivertionbyo	lxe@"liux.noc /a.
>/div>

lxe."liux.no kindly hosctedbyo	Redpill Llipro ASr /a,x providr of Lliuxe cosultrinR andopneratios serevics sience1995.
>/div>