Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mfd: twl4030-madc: Cleanup driver

Some style fixes in twl4030-madc driver.

Reported-by: Jonathan Cameron <jic23@kernel.org>
Reported-by: Lee Jones <lee.jones@linaro.org>
Signed-off-by: Sebastian Reichel <sre@debian.org>
Acked-by: Jonathan Cameron <jic23@kernel.org>
Tested-by: Marek Belisko <marek@goldelico.com>
Signed-off-by: Lee Jones <lee.jones@linaro.org>

authored by

Sebastian Reichel and committed by
Lee Jones
99be0245 2f39b70f

+73 -74
+72 -73
drivers/mfd/twl4030-madc.c
··· 49 49 50 50 #include <linux/iio/iio.h> 51 51 52 - /* 52 + /** 53 53 * struct twl4030_madc_data - a container for madc info 54 - * @dev - pointer to device structure for madc 55 - * @lock - mutex protecting this data structure 56 - * @requests - Array of request struct corresponding to SW1, SW2 and RT 57 - * @use_second_irq - IRQ selection (main or co-processor) 58 - * @imr - Interrupt mask register of MADC 59 - * @isr - Interrupt status register of MADC 54 + * @dev: Pointer to device structure for madc 55 + * @lock: Mutex protecting this data structure 56 + * @requests: Array of request struct corresponding to SW1, SW2 and RT 57 + * @use_second_irq: IRQ selection (main or co-processor) 58 + * @imr: Interrupt mask register of MADC 59 + * @isr: Interrupt status register of MADC 60 60 */ 61 61 struct twl4030_madc_data { 62 62 struct device *dev; 63 63 struct mutex lock; /* mutex protecting this data structure */ 64 64 struct twl4030_madc_request requests[TWL4030_MADC_NUM_METHODS]; 65 65 bool use_second_irq; 66 - int imr; 67 - int isr; 66 + u8 imr; 67 + u8 isr; 68 68 }; 69 69 70 70 static int twl4030_madc_read(struct iio_dev *iio_dev, ··· 155 155 }; 156 156 157 157 158 - /* 159 - * Conversion table from -3 to 55 degree Celcius 160 - */ 161 - static int therm_tbl[] = { 162 - 30800, 29500, 28300, 27100, 163 - 26000, 24900, 23900, 22900, 22000, 21100, 20300, 19400, 18700, 17900, 164 - 17200, 16500, 15900, 15300, 14700, 14100, 13600, 13100, 12600, 12100, 165 - 11600, 11200, 10800, 10400, 10000, 9630, 9280, 8950, 8620, 8310, 166 - 8020, 7730, 7460, 7200, 6950, 6710, 6470, 6250, 6040, 5830, 167 - 5640, 5450, 5260, 5090, 4920, 4760, 4600, 4450, 4310, 4170, 168 - 4040, 3910, 3790, 3670, 3550 158 + /* Conversion table from -3 to 55 degrees Celcius */ 159 + static int twl4030_therm_tbl[] = { 160 + 30800, 29500, 28300, 27100, 161 + 26000, 24900, 23900, 22900, 22000, 21100, 20300, 19400, 18700, 162 + 17900, 17200, 16500, 15900, 15300, 14700, 14100, 13600, 13100, 163 + 12600, 12100, 11600, 11200, 10800, 10400, 10000, 9630, 9280, 164 + 8950, 8620, 8310, 8020, 7730, 7460, 7200, 6950, 6710, 165 + 6470, 6250, 6040, 5830, 5640, 5450, 5260, 5090, 4920, 166 + 4760, 4600, 4450, 4310, 4170, 4040, 3910, 3790, 3670, 167 + 3550 169 168 }; 170 169 171 170 /* ··· 196 197 }, 197 198 }; 198 199 199 - /* 200 - * Function to read a particular channel value. 201 - * @madc - pointer to struct twl4030_madc_data 202 - * @reg - lsb of ADC Channel 203 - * If the i2c read fails it returns an error else returns 0. 200 + /** 201 + * twl4030_madc_channel_raw_read() - Function to read a particular channel value 202 + * @madc: pointer to struct twl4030_madc_data 203 + * @reg: lsb of ADC Channel 204 + * 205 + * Return: 0 on success, an error code otherwise. 204 206 */ 205 207 static int twl4030_madc_channel_raw_read(struct twl4030_madc_data *madc, u8 reg) 206 208 { ··· 227 227 } 228 228 229 229 /* 230 - * Return battery temperature 230 + * Return battery temperature in degrees Celsius 231 231 * Or < 0 on failure. 232 232 */ 233 233 static int twl4030battery_temperature(int raw_volt) ··· 236 236 int temp, curr, volt, res, ret; 237 237 238 238 volt = (raw_volt * TEMP_STEP_SIZE) / TEMP_PSR_R; 239 - /* Getting and calculating the supply current in micro ampers */ 239 + /* Getting and calculating the supply current in micro amperes */ 240 240 ret = twl_i2c_read_u8(TWL_MODULE_MAIN_CHARGE, &val, 241 241 REG_BCICTL2); 242 242 if (ret < 0) 243 243 return ret; 244 + 244 245 curr = ((val & TWL4030_BCI_ITHEN) + 1) * 10; 245 246 /* Getting and calculating the thermistor resistance in ohms */ 246 247 res = volt * 1000 / curr; 247 248 /* calculating temperature */ 248 249 for (temp = 58; temp >= 0; temp--) { 249 - int actual = therm_tbl[temp]; 250 - 250 + int actual = twl4030_therm_tbl[temp]; 251 251 if ((actual - res) >= 0) 252 252 break; 253 253 } ··· 269 269 else /* slope of 0.88 mV/mA */ 270 270 return (raw_volt * CURR_STEP_SIZE) / CURR_PSR_R2; 271 271 } 272 + 272 273 /* 273 274 * Function to read channel values 274 275 * @madc - pointer to twl4030_madc_data struct 275 276 * @reg_base - Base address of the first channel 276 - * @Channels - 16 bit bitmap. If the bit is set, channel value is read 277 + * @Channels - 16 bit bitmap. If the bit is set, channel's value is read 277 278 * @buf - The channel values are stored here. if read fails error 278 279 * @raw - Return raw values without conversion 279 280 * value is stored ··· 285 284 long channels, int *buf, 286 285 bool raw) 287 286 { 288 - int count = 0, count_req = 0, i; 287 + int count = 0; 288 + int i; 289 289 u8 reg; 290 290 291 291 for_each_set_bit(i, &channels, TWL4030_MADC_MAX_CHANNELS) { 292 - reg = reg_base + 2 * i; 292 + reg = reg_base + (2 * i); 293 293 buf[i] = twl4030_madc_channel_raw_read(madc, reg); 294 294 if (buf[i] < 0) { 295 - dev_err(madc->dev, 296 - "Unable to read register 0x%X\n", reg); 297 - count_req++; 298 - continue; 295 + dev_err(madc->dev, "Unable to read register 0x%X\n", 296 + reg); 297 + return buf[i]; 299 298 } 300 299 if (raw) { 301 300 count++; ··· 306 305 buf[i] = twl4030battery_current(buf[i]); 307 306 if (buf[i] < 0) { 308 307 dev_err(madc->dev, "err reading current\n"); 309 - count_req++; 308 + return buf[i]; 310 309 } else { 311 310 count++; 312 311 buf[i] = buf[i] - 750; ··· 316 315 buf[i] = twl4030battery_temperature(buf[i]); 317 316 if (buf[i] < 0) { 318 317 dev_err(madc->dev, "err reading temperature\n"); 319 - count_req++; 318 + return buf[i]; 320 319 } else { 321 320 buf[i] -= 3; 322 321 count++; ··· 337 336 twl4030_divider_ratios[i].numerator); 338 337 } 339 338 } 340 - if (count_req) 341 - dev_err(madc->dev, "%d channel conversion failed\n", count_req); 342 339 343 340 return count; 344 341 } ··· 360 361 madc->imr); 361 362 return ret; 362 363 } 364 + 363 365 val &= ~(1 << id); 364 366 ret = twl_i2c_write_u8(TWL4030_MODULE_MADC, val, madc->imr); 365 367 if (ret) { 366 368 dev_err(madc->dev, 367 369 "unable to write imr register 0x%X\n", madc->imr); 368 370 return ret; 369 - 370 371 } 371 372 372 373 return 0; ··· 429 430 continue; 430 431 ret = twl4030_madc_disable_irq(madc, i); 431 432 if (ret < 0) 432 - dev_dbg(madc->dev, "Disable interrupt failed%d\n", i); 433 + dev_dbg(madc->dev, "Disable interrupt failed %d\n", i); 433 434 madc->requests[i].result_pending = 1; 434 435 } 435 436 for (i = 0; i < TWL4030_MADC_NUM_METHODS; i++) { ··· 511 512 { 512 513 const struct twl4030_madc_conversion_method *method; 513 514 int ret = 0; 515 + 516 + if (conv_method != TWL4030_MADC_SW1 && conv_method != TWL4030_MADC_SW2) 517 + return -ENOTSUPP; 518 + 514 519 method = &twl4030_conversion_methods[conv_method]; 515 - switch (conv_method) { 516 - case TWL4030_MADC_SW1: 517 - case TWL4030_MADC_SW2: 518 - ret = twl_i2c_write_u8(TWL4030_MODULE_MADC, 519 - TWL4030_MADC_SW_START, method->ctrl); 520 - if (ret) { 521 - dev_err(madc->dev, 522 - "unable to write ctrl register 0x%X\n", 523 - method->ctrl); 524 - return ret; 525 - } 526 - break; 527 - default: 528 - break; 520 + ret = twl_i2c_write_u8(TWL4030_MODULE_MADC, TWL4030_MADC_SW_START, 521 + method->ctrl); 522 + if (ret) { 523 + dev_err(madc->dev, "unable to write ctrl register 0x%X\n", 524 + method->ctrl); 525 + return ret; 529 526 } 530 527 531 528 return 0; ··· 618 623 ch_lsb, method->avg); 619 624 if (ret) { 620 625 dev_err(twl4030_madc->dev, 621 - "unable to write sel reg 0x%X\n", 622 - method->sel + 1); 626 + "unable to write avg reg 0x%X\n", 627 + method->avg); 623 628 goto out; 624 629 } 625 630 } ··· 660 665 } 661 666 EXPORT_SYMBOL_GPL(twl4030_madc_conversion); 662 667 663 - /* 664 - * Return channel value 665 - * Or < 0 on failure. 666 - */ 667 668 int twl4030_get_madc_conversion(int channel_no) 668 669 { 669 670 struct twl4030_madc_request req; ··· 680 689 } 681 690 EXPORT_SYMBOL_GPL(twl4030_get_madc_conversion); 682 691 683 - /* 692 + /** 693 + * twl4030_madc_set_current_generator() - setup bias current 694 + * 695 + * @madc: pointer to twl4030_madc_data struct 696 + * @chan: can be one of the two values: 697 + * TWL4030_BCI_ITHEN 698 + * Enables bias current for main battery type reading 699 + * TWL4030_BCI_TYPEN 700 + * Enables bias current for main battery temperature sensing 701 + * @on: enable or disable chan. 702 + * 684 703 * Function to enable or disable bias current for 685 704 * main battery type reading or temperature sensing 686 - * @madc - pointer to twl4030_madc_data struct 687 - * @chan - can be one of the two values 688 - * TWL4030_BCI_ITHEN - Enables bias current for main battery type reading 689 - * TWL4030_BCI_TYPEN - Enables bias current for main battery temperature 690 - * sensing 691 - * @on - enable or disable chan. 692 705 */ 693 706 static int twl4030_madc_set_current_generator(struct twl4030_madc_data *madc, 694 707 int chan, int on) 695 708 { 696 709 int ret; 710 + int regmask; 697 711 u8 regval; 698 712 699 713 ret = twl_i2c_read_u8(TWL_MODULE_MAIN_CHARGE, ··· 708 712 TWL4030_BCI_BCICTL1); 709 713 return ret; 710 714 } 715 + 716 + regmask = chan ? TWL4030_BCI_ITHEN : TWL4030_BCI_TYPEN; 711 717 if (on) 712 - regval |= chan ? TWL4030_BCI_ITHEN : TWL4030_BCI_TYPEN; 718 + regval |= regmask; 713 719 else 714 - regval &= chan ? ~TWL4030_BCI_ITHEN : ~TWL4030_BCI_TYPEN; 720 + regval &= ~regmask; 721 + 715 722 ret = twl_i2c_write_u8(TWL_MODULE_MAIN_CHARGE, 716 723 regval, TWL4030_BCI_BCICTL1); 717 724 if (ret) { ··· 729 730 /* 730 731 * Function that sets MADC software power on bit to enable MADC 731 732 * @madc - pointer to twl4030_madc_data struct 732 - * @on - Enable or disable MADC software powen on bit. 733 + * @on - Enable or disable MADC software power on bit. 733 734 * returns error if i2c read/write fails else 0 734 735 */ 735 736 static int twl4030_madc_set_power(struct twl4030_madc_data *madc, int on) ··· 908 909 .name = "twl4030_madc", 909 910 .owner = THIS_MODULE, 910 911 .of_match_table = of_match_ptr(twl_madc_of_match), 911 - }, 912 + }, 912 913 }; 913 914 914 915 module_platform_driver(twl4030_madc_driver);
+1 -1
include/linux/i2c/twl4030-madc.h
··· 44 44 45 45 struct twl4030_madc_request { 46 46 unsigned long channels; 47 - u16 do_avg; 47 + bool do_avg; 48 48 u16 method; 49 49 u16 type; 50 50 bool active;