summaryrefslogtreecommitdiffstats
path: root/drivers/mfd/ab8500-gpadc.c
diff options
context:
space:
mode:
authorLee Jones <lee.jones@linaro.org>2015-10-28 06:32:10 -0400
committerLee Jones <lee.jones@linaro.org>2016-01-14 03:43:56 -0500
commitdf36442cfe2689e1b26c9633c17a28a9fe4e91ec (patch)
tree4e1aba217c22c3b3d482ff3ce801498d2cdd9259 /drivers/mfd/ab8500-gpadc.c
parentde6a76933317a4dee9b33e1989623cf31098e2ff (diff)
mfd: ab8500-gpadc: Squash a whole bunch of Checkpatch warnings and one error
WARNING: line over 80 characters +#define ADC_CH_IBAT_MIN (-6000) /* mA range measured by ADC for ib t*/ WARNING: line over 80 characters +#define ADC_CH_IBAT_MIN_V (-60) /* mV range measured by ADC for ibat*/ WARNING: suspect code indent for conditional statements (16, 20) + if (!strcmp(name, dev_name(gpadc->dev))) + return gpadc; WARNING: suspect code indent for conditional statements (0, 16) +if (ad_value < 0) { + dev_err(gpadc->dev, "GPADC raw value failed ch: %d\n", WARNING: quoted string split across lines + dev_err(gpadc->dev, "GPADC to voltage conversion failed ch:" + " %d AD: 0x%x\n", channel, ad_value); WARNING: Missing a blank line after declarations + int raw_data; + raw_data = ab8500_gpadc_double_read_raw(gpadc, channel, WARNING: msleep < 20ms can sleep for up to 20ms; see Documentation/timers/timers-howto.txt + msleep(10); ERROR: else should follow close brace '}' + } + else WARNING: line over 80 characters + delay_max = 10000; /* large range to optimise sleep mode */ WARNING: line over 80 characters + gpadc->cal_data[ADC_INPUT_IBAT].gain = V_gain * V2A_gain; WARNING: line over 80 characters + gpadc = devm_kzalloc(&pdev->dev, sizeof(struct ab8500_gpadc), GFP_KERNEL); WARNING: Possible unnecessary 'out of memory' message + if (!gpadc) { + dev_err(&pdev->dev, "Error: No memory\n"); WARNING: space prohibited before semicolon + return ; WARNING: void function return statements are not generally useful + return ; +} WARNING: quoted string split across lines +MODULE_AUTHOR("Arun R Murthy, Daniel Willerud, Johan Palsson," + "M'boumba Cedric Madianga"); total: 1 errors, 14 warnings, 1089 lines checked Cc: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Lee Jones <lee.jones@linaro.org>
Diffstat (limited to 'drivers/mfd/ab8500-gpadc.c')
-rw-r--r--drivers/mfd/ab8500-gpadc.c145
1 files changed, 73 insertions, 72 deletions
diff --git a/drivers/mfd/ab8500-gpadc.c b/drivers/mfd/ab8500-gpadc.c
index c51c1b188d64..97dcadc8fa8b 100644
--- a/drivers/mfd/ab8500-gpadc.c
+++ b/drivers/mfd/ab8500-gpadc.c
@@ -49,61 +49,61 @@
49 * OTP register offsets 49 * OTP register offsets
50 * Bank : 0x15 50 * Bank : 0x15
51 */ 51 */
52#define AB8500_GPADC_CAL_1 0x0F 52#define AB8500_GPADC_CAL_1 0x0F
53#define AB8500_GPADC_CAL_2 0x10 53#define AB8500_GPADC_CAL_2 0x10
54#define AB8500_GPADC_CAL_3 0x11 54#define AB8500_GPADC_CAL_3 0x11
55#define AB8500_GPADC_CAL_4 0x12 55#define AB8500_GPADC_CAL_4 0x12
56#define AB8500_GPADC_CAL_5 0x13 56#define AB8500_GPADC_CAL_5 0x13
57#define AB8500_GPADC_CAL_6 0x14 57#define AB8500_GPADC_CAL_6 0x14
58#define AB8500_GPADC_CAL_7 0x15 58#define AB8500_GPADC_CAL_7 0x15
59/* New calibration for 8540 */ 59/* New calibration for 8540 */
60#define AB8540_GPADC_OTP4_REG_7 0x38 60#define AB8540_GPADC_OTP4_REG_7 0x38
61#define AB8540_GPADC_OTP4_REG_6 0x39 61#define AB8540_GPADC_OTP4_REG_6 0x39
62#define AB8540_GPADC_OTP4_REG_5 0x3A 62#define AB8540_GPADC_OTP4_REG_5 0x3A
63 63
64/* gpadc constants */ 64/* gpadc constants */
65#define EN_VINTCORE12 0x04 65#define EN_VINTCORE12 0x04
66#define EN_VTVOUT 0x02 66#define EN_VTVOUT 0x02
67#define EN_GPADC 0x01 67#define EN_GPADC 0x01
68#define DIS_GPADC 0x00 68#define DIS_GPADC 0x00
69#define AVG_1 0x00 69#define AVG_1 0x00
70#define AVG_4 0x20 70#define AVG_4 0x20
71#define AVG_8 0x40 71#define AVG_8 0x40
72#define AVG_16 0x60 72#define AVG_16 0x60
73#define ADC_SW_CONV 0x04 73#define ADC_SW_CONV 0x04
74#define EN_ICHAR 0x80 74#define EN_ICHAR 0x80
75#define BTEMP_PULL_UP 0x08 75#define BTEMP_PULL_UP 0x08
76#define EN_BUF 0x40 76#define EN_BUF 0x40
77#define DIS_ZERO 0x00 77#define DIS_ZERO 0x00
78#define GPADC_BUSY 0x01 78#define GPADC_BUSY 0x01
79#define EN_FALLING 0x10 79#define EN_FALLING 0x10
80#define EN_TRIG_EDGE 0x02 80#define EN_TRIG_EDGE 0x02
81#define EN_VBIAS_XTAL_TEMP 0x02 81#define EN_VBIAS_XTAL_TEMP 0x02
82 82
83/* GPADC constants from AB8500 spec, UM0836 */ 83/* GPADC constants from AB8500 spec, UM0836 */
84#define ADC_RESOLUTION 1024 84#define ADC_RESOLUTION 1024
85#define ADC_CH_BTEMP_MIN 0 85#define ADC_CH_BTEMP_MIN 0
86#define ADC_CH_BTEMP_MAX 1350 86#define ADC_CH_BTEMP_MAX 1350
87#define ADC_CH_DIETEMP_MIN 0 87#define ADC_CH_DIETEMP_MIN 0
88#define ADC_CH_DIETEMP_MAX 1350 88#define ADC_CH_DIETEMP_MAX 1350
89#define ADC_CH_CHG_V_MIN 0 89#define ADC_CH_CHG_V_MIN 0
90#define ADC_CH_CHG_V_MAX 20030 90#define ADC_CH_CHG_V_MAX 20030
91#define ADC_CH_ACCDET2_MIN 0 91#define ADC_CH_ACCDET2_MIN 0
92#define ADC_CH_ACCDET2_MAX 2500 92#define ADC_CH_ACCDET2_MAX 2500
93#define ADC_CH_VBAT_MIN 2300 93#define ADC_CH_VBAT_MIN 2300
94#define ADC_CH_VBAT_MAX 4800 94#define ADC_CH_VBAT_MAX 4800
95#define ADC_CH_CHG_I_MIN 0 95#define ADC_CH_CHG_I_MIN 0
96#define ADC_CH_CHG_I_MAX 1500 96#define ADC_CH_CHG_I_MAX 1500
97#define ADC_CH_BKBAT_MIN 0 97#define ADC_CH_BKBAT_MIN 0
98#define ADC_CH_BKBAT_MAX 3200 98#define ADC_CH_BKBAT_MAX 3200
99 99
100/* GPADC constants from AB8540 spec */ 100/* GPADC constants from AB8540 spec */
101#define ADC_CH_IBAT_MIN (-6000) /* mA range measured by ADC for ibat*/ 101#define ADC_CH_IBAT_MIN (-6000) /* mA range measured by ADC for ibat */
102#define ADC_CH_IBAT_MAX 6000 102#define ADC_CH_IBAT_MAX 6000
103#define ADC_CH_IBAT_MIN_V (-60) /* mV range measured by ADC for ibat*/ 103#define ADC_CH_IBAT_MIN_V (-60) /* mV range measured by ADC for ibat */
104#define ADC_CH_IBAT_MAX_V 60 104#define ADC_CH_IBAT_MAX_V 60
105#define IBAT_VDROP_L (-56) /* mV */ 105#define IBAT_VDROP_L (-56) /* mV */
106#define IBAT_VDROP_H 56 106#define IBAT_VDROP_H 56
107 107
108/* This is used to not lose precision when dividing to get gain and offset */ 108/* This is used to not lose precision when dividing to get gain and offset */
109#define CALIB_SCALE 1000 109#define CALIB_SCALE 1000
@@ -179,7 +179,7 @@ struct ab8500_gpadc *ab8500_gpadc_get(char *name)
179 179
180 list_for_each_entry(gpadc, &ab8500_gpadc_list, node) { 180 list_for_each_entry(gpadc, &ab8500_gpadc_list, node) {
181 if (!strcmp(name, dev_name(gpadc->dev))) 181 if (!strcmp(name, dev_name(gpadc->dev)))
182 return gpadc; 182 return gpadc;
183 } 183 }
184 184
185 return ERR_PTR(-ENOENT); 185 return ERR_PTR(-ENOENT);
@@ -315,11 +315,12 @@ int ab8500_gpadc_sw_hw_convert(struct ab8500_gpadc *gpadc, u8 channel,
315 315
316 ad_value = ab8500_gpadc_read_raw(gpadc, channel, avg_sample, 316 ad_value = ab8500_gpadc_read_raw(gpadc, channel, avg_sample,
317 trig_edge, trig_timer, conv_type); 317 trig_edge, trig_timer, conv_type);
318/* On failure retry a second time */ 318
319 /* On failure retry a second time */
319 if (ad_value < 0) 320 if (ad_value < 0)
320 ad_value = ab8500_gpadc_read_raw(gpadc, channel, avg_sample, 321 ad_value = ab8500_gpadc_read_raw(gpadc, channel, avg_sample,
321 trig_edge, trig_timer, conv_type); 322 trig_edge, trig_timer, conv_type);
322if (ad_value < 0) { 323 if (ad_value < 0) {
323 dev_err(gpadc->dev, "GPADC raw value failed ch: %d\n", 324 dev_err(gpadc->dev, "GPADC raw value failed ch: %d\n",
324 channel); 325 channel);
325 return ad_value; 326 return ad_value;
@@ -327,8 +328,9 @@ if (ad_value < 0) {
327 328
328 voltage = ab8500_gpadc_ad_to_voltage(gpadc, channel, ad_value); 329 voltage = ab8500_gpadc_ad_to_voltage(gpadc, channel, ad_value);
329 if (voltage < 0) 330 if (voltage < 0)
330 dev_err(gpadc->dev, "GPADC to voltage conversion failed ch:" 331 dev_err(gpadc->dev,
331 " %d AD: 0x%x\n", channel, ad_value); 332 "GPADC to voltage conversion failed ch: %d AD: 0x%x\n",
333 channel, ad_value);
332 334
333 return voltage; 335 return voltage;
334} 336}
@@ -348,10 +350,9 @@ EXPORT_SYMBOL(ab8500_gpadc_sw_hw_convert);
348int ab8500_gpadc_read_raw(struct ab8500_gpadc *gpadc, u8 channel, 350int ab8500_gpadc_read_raw(struct ab8500_gpadc *gpadc, u8 channel,
349 u8 avg_sample, u8 trig_edge, u8 trig_timer, u8 conv_type) 351 u8 avg_sample, u8 trig_edge, u8 trig_timer, u8 conv_type)
350{ 352{
351 int raw_data; 353 return ab8500_gpadc_double_read_raw(gpadc, channel, avg_sample,
352 raw_data = ab8500_gpadc_double_read_raw(gpadc, channel, 354 trig_edge, trig_timer, conv_type,
353 avg_sample, trig_edge, trig_timer, conv_type, NULL); 355 NULL);
354 return raw_data;
355} 356}
356 357
357int ab8500_gpadc_double_read_raw(struct ab8500_gpadc *gpadc, u8 channel, 358int ab8500_gpadc_double_read_raw(struct ab8500_gpadc *gpadc, u8 channel,
@@ -388,7 +389,7 @@ int ab8500_gpadc_double_read_raw(struct ab8500_gpadc *gpadc, u8 channel,
388 goto out; 389 goto out;
389 if (!(val & GPADC_BUSY)) 390 if (!(val & GPADC_BUSY))
390 break; 391 break;
391 msleep(10); 392 msleep(20);
392 } while (++looplimit < 10); 393 } while (++looplimit < 10);
393 if (looplimit >= 10 && (val & GPADC_BUSY)) { 394 if (looplimit >= 10 && (val & GPADC_BUSY)) {
394 dev_err(gpadc->dev, "gpadc_conversion: GPADC busy"); 395 dev_err(gpadc->dev, "gpadc_conversion: GPADC busy");
@@ -421,8 +422,7 @@ int ab8500_gpadc_double_read_raw(struct ab8500_gpadc *gpadc, u8 channel,
421 val_reg1 |= EN_TRIG_EDGE; 422 val_reg1 |= EN_TRIG_EDGE;
422 if (trig_edge) 423 if (trig_edge)
423 val_reg1 |= EN_FALLING; 424 val_reg1 |= EN_FALLING;
424 } 425 } else
425 else
426 ret = abx500_set_register_interruptible(gpadc->dev, 426 ret = abx500_set_register_interruptible(gpadc->dev,
427 AB8500_GPADC, AB8500_GPADC_CTRL2_REG, val); 427 AB8500_GPADC, AB8500_GPADC_CTRL2_REG, val);
428 if (ret < 0) { 428 if (ret < 0) {
@@ -449,7 +449,7 @@ int ab8500_gpadc_double_read_raw(struct ab8500_gpadc *gpadc, u8 channel,
449 * remove when hardware will be availible 449 * remove when hardware will be availible
450 */ 450 */
451 delay_min = 1000; /* Delay in micro seconds */ 451 delay_min = 1000; /* Delay in micro seconds */
452 delay_max = 10000; /* large range to optimise sleep mode */ 452 delay_max = 10000; /* large range optimises sleepmode */
453 break; 453 break;
454 } 454 }
455 /* Intentional fallthrough */ 455 /* Intentional fallthrough */
@@ -785,9 +785,10 @@ static void ab8500_gpadc_read_calibration_data(struct ab8500_gpadc *gpadc)
785 << CALIB_SHIFT_IBAT) 785 << CALIB_SHIFT_IBAT)
786 / (ADC_CH_IBAT_MAX_V - ADC_CH_IBAT_MIN_V); 786 / (ADC_CH_IBAT_MAX_V - ADC_CH_IBAT_MIN_V);
787 787
788 gpadc->cal_data[ADC_INPUT_IBAT].gain = V_gain * V2A_gain; 788 gpadc->cal_data[ADC_INPUT_IBAT].gain =
789 gpadc->cal_data[ADC_INPUT_IBAT].offset = V_offset * 789 V_gain * V2A_gain;
790 V2A_gain + V2A_offset; 790 gpadc->cal_data[ADC_INPUT_IBAT].offset =
791 V_offset * V2A_gain + V2A_offset;
791 } else { 792 } else {
792 gpadc->cal_data[ADC_INPUT_IBAT].gain = 0; 793 gpadc->cal_data[ADC_INPUT_IBAT].gain = 0;
793 } 794 }
@@ -923,11 +924,10 @@ static int ab8500_gpadc_probe(struct platform_device *pdev)
923 int ret = 0; 924 int ret = 0;
924 struct ab8500_gpadc *gpadc; 925 struct ab8500_gpadc *gpadc;
925 926
926 gpadc = devm_kzalloc(&pdev->dev, sizeof(struct ab8500_gpadc), GFP_KERNEL); 927 gpadc = devm_kzalloc(&pdev->dev,
927 if (!gpadc) { 928 sizeof(struct ab8500_gpadc), GFP_KERNEL);
928 dev_err(&pdev->dev, "Error: No memory\n"); 929 if (!gpadc)
929 return -ENOMEM; 930 return -ENOMEM;
930 }
931 931
932 gpadc->irq_sw = platform_get_irq_byname(pdev, "SW_CONV_END"); 932 gpadc->irq_sw = platform_get_irq_byname(pdev, "SW_CONV_END");
933 if (gpadc->irq_sw < 0) 933 if (gpadc->irq_sw < 0)
@@ -1072,18 +1072,19 @@ void ab8540_gpadc_get_otp(struct ab8500_gpadc *gpadc,
1072 *vmain_h = gpadc->cal_data[ADC_INPUT_VMAIN].otp_calib_hi; 1072 *vmain_h = gpadc->cal_data[ADC_INPUT_VMAIN].otp_calib_hi;
1073 *btemp_l = gpadc->cal_data[ADC_INPUT_BTEMP].otp_calib_lo; 1073 *btemp_l = gpadc->cal_data[ADC_INPUT_BTEMP].otp_calib_lo;
1074 *btemp_h = gpadc->cal_data[ADC_INPUT_BTEMP].otp_calib_hi; 1074 *btemp_h = gpadc->cal_data[ADC_INPUT_BTEMP].otp_calib_hi;
1075 *vbat_l = gpadc->cal_data[ADC_INPUT_VBAT].otp_calib_lo; 1075 *vbat_l = gpadc->cal_data[ADC_INPUT_VBAT].otp_calib_lo;
1076 *vbat_h = gpadc->cal_data[ADC_INPUT_VBAT].otp_calib_hi; 1076 *vbat_h = gpadc->cal_data[ADC_INPUT_VBAT].otp_calib_hi;
1077 *ibat_l = gpadc->cal_data[ADC_INPUT_IBAT].otp_calib_lo; 1077 *ibat_l = gpadc->cal_data[ADC_INPUT_IBAT].otp_calib_lo;
1078 *ibat_h = gpadc->cal_data[ADC_INPUT_IBAT].otp_calib_hi; 1078 *ibat_h = gpadc->cal_data[ADC_INPUT_IBAT].otp_calib_hi;
1079 return ;
1080} 1079}
1081 1080
1082subsys_initcall_sync(ab8500_gpadc_init); 1081subsys_initcall_sync(ab8500_gpadc_init);
1083module_exit(ab8500_gpadc_exit); 1082module_exit(ab8500_gpadc_exit);
1084 1083
1085MODULE_LICENSE("GPL v2"); 1084MODULE_LICENSE("GPL v2");
1086MODULE_AUTHOR("Arun R Murthy, Daniel Willerud, Johan Palsson," 1085MODULE_AUTHOR("Arun R Murthy");
1087 "M'boumba Cedric Madianga"); 1086MODULE_AUTHOR("Daniel Willerud");
1087MODULE_AUTHOR("Johan Palsson");
1088MODULE_AUTHOR("M'boumba Cedric Madianga");
1088MODULE_ALIAS("platform:ab8500_gpadc"); 1089MODULE_ALIAS("platform:ab8500_gpadc");
1089MODULE_DESCRIPTION("AB8500 GPADC driver"); 1090MODULE_DESCRIPTION("AB8500 GPADC driver");