Skip to content

Commit a5055d5

Browse files
paliSamuel Ortiz
authored andcommitted
mfd: twl4030-madc: Add support for raw value in twl4030_madc_conversion
Driver twl4030-madc has hardcoded channel types (10 - battery current, 1 - battery temperature) and also conversation data in variable twl4030_divider_ratios. These hardcoded channels are incorrect for Nokia RX-51 board (where is channel 0 - battery temperature). For Nokia RX-51 there is rx51_battery power_supply driver which reporting battery information via twl4030_madc_conversion. But this driver needs raw values (not converted via some hardcoded functions). So this patch adding new parameter "raw" to struct twl4030_madc_request which tell twl4030-madc driver to not convert values, but rather return raw. Signed-off-by: Pali Rohár <pali.rohar@gmail.com> Reviewed-by: Anton Vorontsov <anton@enomsg.org> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
1 parent d955cba commit a5055d5

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

‎drivers/mfd/twl4030-madc.c‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,14 @@ static int twl4030battery_current(int raw_volt)
211211
* @reg_base - Base address of the first channel
212212
* @Channels - 16 bit bitmap. If the bit is set, channel value is read
213213
* @buf - The channel values are stored here. if read fails error
214+
* @raw - Return raw values without conversion
214215
* value is stored
215216
* Returns the number of successfully read channels.
216217
*/
217218
static int twl4030_madc_read_channels(struct twl4030_madc_data *madc,
218219
u8 reg_base, unsigned
219-
long channels, int *buf)
220+
long channels, int *buf,
221+
bool raw)
220222
{
221223
int count = 0, count_req = 0, i;
222224
u8 reg;
@@ -230,6 +232,10 @@ static int twl4030_madc_read_channels(struct twl4030_madc_data *madc,
230232
count_req++;
231233
continue;
232234
}
235+
if (raw) {
236+
count++;
237+
continue;
238+
}
233239
switch (i) {
234240
case 10:
235241
buf[i] = twl4030battery_current(buf[i]);
@@ -371,7 +377,7 @@ static irqreturn_t twl4030_madc_threaded_irq_handler(int irq, void *_madc)
371377
method = &twl4030_conversion_methods[r->method];
372378
/* Read results */
373379
len = twl4030_madc_read_channels(madc, method->rbase,
374-
r->channels, r->rbuf);
380+
r->channels, r->rbuf, r->raw);
375381
/* Return results to caller */
376382
if (r->func_cb != NULL) {
377383
r->func_cb(len, r->channels, r->rbuf);
@@ -397,7 +403,7 @@ static irqreturn_t twl4030_madc_threaded_irq_handler(int irq, void *_madc)
397403
method = &twl4030_conversion_methods[r->method];
398404
/* Read results */
399405
len = twl4030_madc_read_channels(madc, method->rbase,
400-
r->channels, r->rbuf);
406+
r->channels, r->rbuf, r->raw);
401407
/* Return results to caller */
402408
if (r->func_cb != NULL) {
403409
r->func_cb(len, r->channels, r->rbuf);
@@ -585,7 +591,7 @@ int twl4030_madc_conversion(struct twl4030_madc_request *req)
585591
goto out;
586592
}
587593
ret = twl4030_madc_read_channels(twl4030_madc, method->rbase,
588-
req->channels, req->rbuf);
594+
req->channels, req->rbuf, req->raw);
589595
twl4030_madc->requests[req->method].active = 0;
590596

591597
out:

‎include/linux/i2c/twl4030-madc.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ struct twl4030_madc_conversion_method {
3939
* @do_avgP: sample the input channel for 4 consecutive cycles
4040
* @method: RT, SW1, SW2
4141
* @type: Polling or interrupt based method
42+
* @raw: Return raw value, do not convert it
4243
*/
4344

4445
struct twl4030_madc_request {
@@ -48,6 +49,7 @@ struct twl4030_madc_request {
4849
u16 type;
4950
bool active;
5051
bool result_pending;
52+
bool raw;
5153
int rbuf[TWL4030_MADC_MAX_CHANNELS];
5254
void (*func_cb)(int len, int channels, int *buf);
5355
};

0 commit comments

Comments
 (0)