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

power: supply: s3c-adc-battery: Convert to GPIO descriptors

This converts the S3C ADC battery to use GPIO descriptors
instead of a global GPIO number for the charging completed
GPIO. Using the pattern from the GPIO charger we name this
GPIO line "charge-status" in the board file.

Cc: linux-samsung-soc@vger.kernel.org
Cc: Sergiy Kibrik <sakib@darkstar.site>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>

authored by

Linus Walleij and committed by
Sebastian Reichel
7776bcd2 36dbca14

+49 -34
+10 -2
arch/arm/mach-s3c/mach-h1940.c
··· 297 297 { .volt = 3841, .cur = 0, .level = 0}, 298 298 }; 299 299 300 + static struct gpiod_lookup_table h1940_bat_gpio_table = { 301 + .dev_id = "s3c-adc-battery", 302 + .table = { 303 + /* Charge status S3C2410_GPF(3) */ 304 + GPIO_LOOKUP("GPIOF", 3, "charge-status", GPIO_ACTIVE_LOW), 305 + { }, 306 + }, 307 + }; 308 + 300 309 static int h1940_bat_init(void) 301 310 { 302 311 int ret; ··· 339 330 .exit = h1940_bat_exit, 340 331 .enable_charger = h1940_enable_charger, 341 332 .disable_charger = h1940_disable_charger, 342 - .gpio_charge_finished = S3C2410_GPF(3), 343 - .gpio_inverted = 1, 344 333 .lut_noac = bat_lut_noac, 345 334 .lut_noac_cnt = ARRAY_SIZE(bat_lut_noac), 346 335 .lut_acin = bat_lut_acin, ··· 727 720 s3c24xx_fb_set_platdata(&h1940_fb_info); 728 721 gpiod_add_lookup_table(&h1940_mmc_gpio_table); 729 722 gpiod_add_lookup_table(&h1940_audio_gpio_table); 723 + gpiod_add_lookup_table(&h1940_bat_gpio_table); 730 724 /* Configure the I2S pins (GPE0...GPE4) in correct mode */ 731 725 s3c_gpio_cfgall_range(S3C2410_GPE(0), 5, S3C_GPIO_SFN(2), 732 726 S3C_GPIO_PULL_NONE);
+10 -1
arch/arm/mach-s3c/mach-rx1950.c
··· 206 206 { .volt = 3820, .cur = 0, .level = 0}, 207 207 }; 208 208 209 + static struct gpiod_lookup_table rx1950_bat_gpio_table = { 210 + .dev_id = "s3c-adc-battery", 211 + .table = { 212 + /* Charge status S3C2410_GPF(3) */ 213 + GPIO_LOOKUP("GPIOF", 3, "charge-status", GPIO_ACTIVE_HIGH), 214 + { }, 215 + }, 216 + }; 217 + 209 218 static int rx1950_bat_init(void) 210 219 { 211 220 int ret; ··· 340 331 .exit = rx1950_bat_exit, 341 332 .enable_charger = rx1950_enable_charger, 342 333 .disable_charger = rx1950_disable_charger, 343 - .gpio_charge_finished = S3C2410_GPF(3), 344 334 .lut_noac = bat_lut_noac, 345 335 .lut_noac_cnt = ARRAY_SIZE(bat_lut_noac), 346 336 .lut_acin = bat_lut_acin, ··· 848 840 849 841 pwm_add_table(rx1950_pwm_lookup, ARRAY_SIZE(rx1950_pwm_lookup)); 850 842 gpiod_add_lookup_table(&rx1950_audio_gpio_table); 843 + gpiod_add_lookup_table(&rx1950_bat_gpio_table); 851 844 /* Configure the I2S pins (GPE0...GPE4) in correct mode */ 852 845 s3c_gpio_cfgall_range(S3C2410_GPE(0), 5, S3C_GPIO_SFN(2), 853 846 S3C_GPIO_PULL_NONE);
+29 -28
drivers/power/supply/s3c_adc_battery.c
··· 13 13 #include <linux/platform_device.h> 14 14 #include <linux/power_supply.h> 15 15 #include <linux/leds.h> 16 - #include <linux/gpio.h> 16 + #include <linux/gpio/consumer.h> 17 17 #include <linux/err.h> 18 18 #include <linux/timer.h> 19 19 #include <linux/jiffies.h> ··· 31 31 struct power_supply *psy; 32 32 struct s3c_adc_client *client; 33 33 struct s3c_adc_bat_pdata *pdata; 34 + struct gpio_desc *charge_finished; 34 35 int volt_value; 35 36 int cur_value; 36 37 unsigned int timestamp; ··· 133 132 134 133 static int charge_finished(struct s3c_adc_bat *bat) 135 134 { 136 - return bat->pdata->gpio_inverted ? 137 - !gpio_get_value(bat->pdata->gpio_charge_finished) : 138 - gpio_get_value(bat->pdata->gpio_charge_finished); 135 + return gpiod_get_value(bat->charge_finished); 139 136 } 140 137 141 138 static int s3c_adc_bat_get_property(struct power_supply *psy, ··· 168 169 } 169 170 170 171 if (bat->cable_plugged && 171 - ((bat->pdata->gpio_charge_finished < 0) || 172 + (!bat->charge_finished || 172 173 !charge_finished(bat))) { 173 174 lut = bat->pdata->lut_acin; 174 175 lut_size = bat->pdata->lut_acin_cnt; ··· 205 206 206 207 switch (psp) { 207 208 case POWER_SUPPLY_PROP_STATUS: 208 - if (bat->pdata->gpio_charge_finished < 0) 209 + if (!bat->charge_finished) 209 210 val->intval = bat->level == 100000 ? 210 211 POWER_SUPPLY_STATUS_FULL : bat->status; 211 212 else ··· 264 265 bat->status = POWER_SUPPLY_STATUS_DISCHARGING; 265 266 } 266 267 } else { 267 - if ((bat->pdata->gpio_charge_finished >= 0) && is_plugged) { 268 + if (bat->charge_finished && is_plugged) { 268 269 is_charged = charge_finished(&main_bat); 269 270 if (is_charged) { 270 271 if (bat->pdata->disable_charger) ··· 293 294 struct s3c_adc_client *client; 294 295 struct s3c_adc_bat_pdata *pdata = pdev->dev.platform_data; 295 296 struct power_supply_config psy_cfg = {}; 297 + struct gpio_desc *gpiod; 296 298 int ret; 297 299 298 300 client = s3c_adc_register(pdev, NULL, NULL, 0); ··· 304 304 305 305 platform_set_drvdata(pdev, client); 306 306 307 + gpiod = devm_gpiod_get_optional(&pdev->dev, "charge-status", GPIOD_IN); 308 + if (IS_ERR(gpiod)) { 309 + /* Could be probe deferral etc */ 310 + ret = PTR_ERR(gpiod); 311 + dev_err(&pdev->dev, "no GPIO %d\n", ret); 312 + return ret; 313 + } 314 + 307 315 main_bat.client = client; 308 316 main_bat.pdata = pdata; 317 + main_bat.charge_finished = gpiod; 309 318 main_bat.volt_value = -1; 310 319 main_bat.cur_value = -1; 311 320 main_bat.cable_plugged = 0; ··· 332 323 333 324 backup_bat.client = client; 334 325 backup_bat.pdata = pdev->dev.platform_data; 326 + backup_bat.charge_finished = gpiod; 335 327 backup_bat.volt_value = -1; 336 328 backup_bat.psy = power_supply_register(&pdev->dev, 337 329 &backup_bat_desc, ··· 345 335 346 336 INIT_DELAYED_WORK(&bat_work, s3c_adc_bat_work); 347 337 348 - if (pdata->gpio_charge_finished >= 0) { 349 - ret = gpio_request(pdata->gpio_charge_finished, "charged"); 350 - if (ret) 351 - goto err_gpio; 352 - 353 - ret = request_irq(gpio_to_irq(pdata->gpio_charge_finished), 338 + if (gpiod) { 339 + ret = request_irq(gpiod_to_irq(gpiod), 354 340 s3c_adc_bat_charged, 355 341 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, 356 342 "battery charged", NULL); ··· 370 364 return 0; 371 365 372 366 err_platform: 373 - if (pdata->gpio_charge_finished >= 0) 374 - free_irq(gpio_to_irq(pdata->gpio_charge_finished), NULL); 367 + if (gpiod) 368 + free_irq(gpiod_to_irq(gpiod), NULL); 375 369 err_irq: 376 - if (pdata->gpio_charge_finished >= 0) 377 - gpio_free(pdata->gpio_charge_finished); 378 - err_gpio: 379 370 if (pdata->backup_volt_mult) 380 371 power_supply_unregister(backup_bat.psy); 381 372 err_reg_backup: ··· 392 389 393 390 s3c_adc_release(client); 394 391 395 - if (pdata->gpio_charge_finished >= 0) { 396 - free_irq(gpio_to_irq(pdata->gpio_charge_finished), NULL); 397 - gpio_free(pdata->gpio_charge_finished); 398 - } 392 + if (main_bat.charge_finished) 393 + free_irq(gpiod_to_irq(main_bat.charge_finished), NULL); 399 394 400 395 cancel_delayed_work(&bat_work); 401 396 ··· 409 408 { 410 409 struct s3c_adc_bat_pdata *pdata = pdev->dev.platform_data; 411 410 412 - if (pdata->gpio_charge_finished >= 0) { 411 + if (main_bat.charge_finished) { 413 412 if (device_may_wakeup(&pdev->dev)) 414 413 enable_irq_wake( 415 - gpio_to_irq(pdata->gpio_charge_finished)); 414 + gpiod_to_irq(main_bat.charge_finished)); 416 415 else { 417 - disable_irq(gpio_to_irq(pdata->gpio_charge_finished)); 416 + disable_irq(gpiod_to_irq(main_bat.charge_finished)); 418 417 main_bat.pdata->disable_charger(); 419 418 } 420 419 } ··· 426 425 { 427 426 struct s3c_adc_bat_pdata *pdata = pdev->dev.platform_data; 428 427 429 - if (pdata->gpio_charge_finished >= 0) { 428 + if (main_bat.charge_finished) { 430 429 if (device_may_wakeup(&pdev->dev)) 431 430 disable_irq_wake( 432 - gpio_to_irq(pdata->gpio_charge_finished)); 431 + gpiod_to_irq(main_bat.charge_finished)); 433 432 else 434 - enable_irq(gpio_to_irq(pdata->gpio_charge_finished)); 433 + enable_irq(gpiod_to_irq(main_bat.charge_finished)); 435 434 } 436 435 437 436 /* Schedule timer to check current status */
-3
include/linux/s3c_adc_battery.h
··· 14 14 void (*enable_charger)(void); 15 15 void (*disable_charger)(void); 16 16 17 - int gpio_charge_finished; 18 - int gpio_inverted; 19 - 20 17 const struct s3c_adc_bat_thresh *lut_noac; 21 18 unsigned int lut_noac_cnt; 22 19 const struct s3c_adc_bat_thresh *lut_acin;