Commit 7776bcd2 authored by Linus Walleij's avatar Linus Walleij Committed by Sebastian Reichel
Browse files

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: default avatarLinus Walleij <linus.walleij@linaro.org>
Signed-off-by: default avatarSebastian Reichel <sebastian.reichel@collabora.com>
parent 36dbca14
Loading
Loading
Loading
Loading
+10 −2
Original line number Original line Diff line number Diff line
@@ -297,6 +297,15 @@ static const struct s3c_adc_bat_thresh bat_lut_acin[] = {
	{ .volt = 3841, .cur = 0, .level = 0},
	{ .volt = 3841, .cur = 0, .level = 0},
};
};


static struct gpiod_lookup_table h1940_bat_gpio_table = {
	.dev_id = "s3c-adc-battery",
	.table = {
		/* Charge status S3C2410_GPF(3) */
		GPIO_LOOKUP("GPIOF", 3, "charge-status", GPIO_ACTIVE_LOW),
		{ },
	},
};

static int h1940_bat_init(void)
static int h1940_bat_init(void)
{
{
	int ret;
	int ret;
@@ -330,8 +339,6 @@ static struct s3c_adc_bat_pdata h1940_bat_cfg = {
	.exit = h1940_bat_exit,
	.exit = h1940_bat_exit,
	.enable_charger = h1940_enable_charger,
	.enable_charger = h1940_enable_charger,
	.disable_charger = h1940_disable_charger,
	.disable_charger = h1940_disable_charger,
	.gpio_charge_finished = S3C2410_GPF(3),
	.gpio_inverted = 1,
	.lut_noac = bat_lut_noac,
	.lut_noac = bat_lut_noac,
	.lut_noac_cnt = ARRAY_SIZE(bat_lut_noac),
	.lut_noac_cnt = ARRAY_SIZE(bat_lut_noac),
	.lut_acin = bat_lut_acin,
	.lut_acin = bat_lut_acin,
@@ -720,6 +727,7 @@ static void __init h1940_init(void)
	s3c24xx_fb_set_platdata(&h1940_fb_info);
	s3c24xx_fb_set_platdata(&h1940_fb_info);
	gpiod_add_lookup_table(&h1940_mmc_gpio_table);
	gpiod_add_lookup_table(&h1940_mmc_gpio_table);
	gpiod_add_lookup_table(&h1940_audio_gpio_table);
	gpiod_add_lookup_table(&h1940_audio_gpio_table);
	gpiod_add_lookup_table(&h1940_bat_gpio_table);
	/* Configure the I2S pins (GPE0...GPE4) in correct mode */
	/* Configure the I2S pins (GPE0...GPE4) in correct mode */
	s3c_gpio_cfgall_range(S3C2410_GPE(0), 5, S3C_GPIO_SFN(2),
	s3c_gpio_cfgall_range(S3C2410_GPE(0), 5, S3C_GPIO_SFN(2),
			      S3C_GPIO_PULL_NONE);
			      S3C_GPIO_PULL_NONE);
+10 −1
Original line number Original line Diff line number Diff line
@@ -206,6 +206,15 @@ static const struct s3c_adc_bat_thresh bat_lut_acin[] = {
	{ .volt = 3820, .cur = 0, .level = 0},
	{ .volt = 3820, .cur = 0, .level = 0},
};
};


static struct gpiod_lookup_table rx1950_bat_gpio_table = {
	.dev_id = "s3c-adc-battery",
	.table = {
		/* Charge status S3C2410_GPF(3) */
		GPIO_LOOKUP("GPIOF", 3, "charge-status", GPIO_ACTIVE_HIGH),
		{ },
	},
};

static int rx1950_bat_init(void)
static int rx1950_bat_init(void)
{
{
	int ret;
	int ret;
@@ -331,7 +340,6 @@ static struct s3c_adc_bat_pdata rx1950_bat_cfg = {
	.exit = rx1950_bat_exit,
	.exit = rx1950_bat_exit,
	.enable_charger = rx1950_enable_charger,
	.enable_charger = rx1950_enable_charger,
	.disable_charger = rx1950_disable_charger,
	.disable_charger = rx1950_disable_charger,
	.gpio_charge_finished = S3C2410_GPF(3),
	.lut_noac = bat_lut_noac,
	.lut_noac = bat_lut_noac,
	.lut_noac_cnt = ARRAY_SIZE(bat_lut_noac),
	.lut_noac_cnt = ARRAY_SIZE(bat_lut_noac),
	.lut_acin = bat_lut_acin,
	.lut_acin = bat_lut_acin,
@@ -840,6 +848,7 @@ static void __init rx1950_init_machine(void)


	pwm_add_table(rx1950_pwm_lookup, ARRAY_SIZE(rx1950_pwm_lookup));
	pwm_add_table(rx1950_pwm_lookup, ARRAY_SIZE(rx1950_pwm_lookup));
	gpiod_add_lookup_table(&rx1950_audio_gpio_table);
	gpiod_add_lookup_table(&rx1950_audio_gpio_table);
	gpiod_add_lookup_table(&rx1950_bat_gpio_table);
	/* Configure the I2S pins (GPE0...GPE4) in correct mode */
	/* Configure the I2S pins (GPE0...GPE4) in correct mode */
	s3c_gpio_cfgall_range(S3C2410_GPE(0), 5, S3C_GPIO_SFN(2),
	s3c_gpio_cfgall_range(S3C2410_GPE(0), 5, S3C_GPIO_SFN(2),
			      S3C_GPIO_PULL_NONE);
			      S3C_GPIO_PULL_NONE);
+29 −28
Original line number Original line Diff line number Diff line
@@ -13,7 +13,7 @@
#include <linux/platform_device.h>
#include <linux/platform_device.h>
#include <linux/power_supply.h>
#include <linux/power_supply.h>
#include <linux/leds.h>
#include <linux/leds.h>
#include <linux/gpio.h>
#include <linux/gpio/consumer.h>
#include <linux/err.h>
#include <linux/err.h>
#include <linux/timer.h>
#include <linux/timer.h>
#include <linux/jiffies.h>
#include <linux/jiffies.h>
@@ -31,6 +31,7 @@ struct s3c_adc_bat {
	struct power_supply		*psy;
	struct power_supply		*psy;
	struct s3c_adc_client		*client;
	struct s3c_adc_client		*client;
	struct s3c_adc_bat_pdata	*pdata;
	struct s3c_adc_bat_pdata	*pdata;
	struct gpio_desc		*charge_finished;
	int				volt_value;
	int				volt_value;
	int				cur_value;
	int				cur_value;
	unsigned int			timestamp;
	unsigned int			timestamp;
@@ -132,9 +133,7 @@ static int calc_full_volt(int volt_val, int cur_val, int impedance)


static int charge_finished(struct s3c_adc_bat *bat)
static int charge_finished(struct s3c_adc_bat *bat)
{
{
	return bat->pdata->gpio_inverted ?
	return gpiod_get_value(bat->charge_finished);
		!gpio_get_value(bat->pdata->gpio_charge_finished) :
		gpio_get_value(bat->pdata->gpio_charge_finished);
}
}


static int s3c_adc_bat_get_property(struct power_supply *psy,
static int s3c_adc_bat_get_property(struct power_supply *psy,
@@ -169,7 +168,7 @@ static int s3c_adc_bat_get_property(struct power_supply *psy,
	}
	}


	if (bat->cable_plugged &&
	if (bat->cable_plugged &&
		((bat->pdata->gpio_charge_finished < 0) ||
		(!bat->charge_finished ||
		!charge_finished(bat))) {
		!charge_finished(bat))) {
		lut = bat->pdata->lut_acin;
		lut = bat->pdata->lut_acin;
		lut_size = bat->pdata->lut_acin_cnt;
		lut_size = bat->pdata->lut_acin_cnt;
@@ -206,7 +205,7 @@ static int s3c_adc_bat_get_property(struct power_supply *psy,


	switch (psp) {
	switch (psp) {
	case POWER_SUPPLY_PROP_STATUS:
	case POWER_SUPPLY_PROP_STATUS:
		if (bat->pdata->gpio_charge_finished < 0)
		if (!bat->charge_finished)
			val->intval = bat->level == 100000 ?
			val->intval = bat->level == 100000 ?
				POWER_SUPPLY_STATUS_FULL : bat->status;
				POWER_SUPPLY_STATUS_FULL : bat->status;
		else
		else
@@ -265,7 +264,7 @@ static void s3c_adc_bat_work(struct work_struct *work)
			bat->status = POWER_SUPPLY_STATUS_DISCHARGING;
			bat->status = POWER_SUPPLY_STATUS_DISCHARGING;
		}
		}
	} else {
	} else {
		if ((bat->pdata->gpio_charge_finished >= 0) && is_plugged) {
		if (bat->charge_finished && is_plugged) {
			is_charged = charge_finished(&main_bat);
			is_charged = charge_finished(&main_bat);
			if (is_charged) {
			if (is_charged) {
				if (bat->pdata->disable_charger)
				if (bat->pdata->disable_charger)
@@ -294,6 +293,7 @@ static int s3c_adc_bat_probe(struct platform_device *pdev)
	struct s3c_adc_client	*client;
	struct s3c_adc_client	*client;
	struct s3c_adc_bat_pdata *pdata = pdev->dev.platform_data;
	struct s3c_adc_bat_pdata *pdata = pdev->dev.platform_data;
	struct power_supply_config psy_cfg = {};
	struct power_supply_config psy_cfg = {};
	struct gpio_desc *gpiod;
	int ret;
	int ret;


	client = s3c_adc_register(pdev, NULL, NULL, 0);
	client = s3c_adc_register(pdev, NULL, NULL, 0);
@@ -304,8 +304,17 @@ static int s3c_adc_bat_probe(struct platform_device *pdev)


	platform_set_drvdata(pdev, client);
	platform_set_drvdata(pdev, client);


	gpiod = devm_gpiod_get_optional(&pdev->dev, "charge-status", GPIOD_IN);
	if (IS_ERR(gpiod)) {
		/* Could be probe deferral etc */
		ret = PTR_ERR(gpiod);
		dev_err(&pdev->dev, "no GPIO %d\n", ret);
		return ret;
	}

	main_bat.client = client;
	main_bat.client = client;
	main_bat.pdata = pdata;
	main_bat.pdata = pdata;
	main_bat.charge_finished = gpiod;
	main_bat.volt_value = -1;
	main_bat.volt_value = -1;
	main_bat.cur_value = -1;
	main_bat.cur_value = -1;
	main_bat.cable_plugged = 0;
	main_bat.cable_plugged = 0;
@@ -323,6 +332,7 @@ static int s3c_adc_bat_probe(struct platform_device *pdev)


		backup_bat.client = client;
		backup_bat.client = client;
		backup_bat.pdata = pdev->dev.platform_data;
		backup_bat.pdata = pdev->dev.platform_data;
		backup_bat.charge_finished = gpiod;
		backup_bat.volt_value = -1;
		backup_bat.volt_value = -1;
		backup_bat.psy = power_supply_register(&pdev->dev,
		backup_bat.psy = power_supply_register(&pdev->dev,
						       &backup_bat_desc,
						       &backup_bat_desc,
@@ -335,12 +345,8 @@ static int s3c_adc_bat_probe(struct platform_device *pdev)


	INIT_DELAYED_WORK(&bat_work, s3c_adc_bat_work);
	INIT_DELAYED_WORK(&bat_work, s3c_adc_bat_work);


	if (pdata->gpio_charge_finished >= 0) {
	if (gpiod) {
		ret = gpio_request(pdata->gpio_charge_finished, "charged");
		ret = request_irq(gpiod_to_irq(gpiod),
		if (ret)
			goto err_gpio;

		ret = request_irq(gpio_to_irq(pdata->gpio_charge_finished),
				s3c_adc_bat_charged,
				s3c_adc_bat_charged,
				IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
				IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
				"battery charged", NULL);
				"battery charged", NULL);
@@ -364,12 +370,9 @@ static int s3c_adc_bat_probe(struct platform_device *pdev)
	return 0;
	return 0;


err_platform:
err_platform:
	if (pdata->gpio_charge_finished >= 0)
	if (gpiod)
		free_irq(gpio_to_irq(pdata->gpio_charge_finished), NULL);
		free_irq(gpiod_to_irq(gpiod), NULL);
err_irq:
err_irq:
	if (pdata->gpio_charge_finished >= 0)
		gpio_free(pdata->gpio_charge_finished);
err_gpio:
	if (pdata->backup_volt_mult)
	if (pdata->backup_volt_mult)
		power_supply_unregister(backup_bat.psy);
		power_supply_unregister(backup_bat.psy);
err_reg_backup:
err_reg_backup:
@@ -389,10 +392,8 @@ static int s3c_adc_bat_remove(struct platform_device *pdev)


	s3c_adc_release(client);
	s3c_adc_release(client);


	if (pdata->gpio_charge_finished >= 0) {
	if (main_bat.charge_finished)
		free_irq(gpio_to_irq(pdata->gpio_charge_finished), NULL);
		free_irq(gpiod_to_irq(main_bat.charge_finished), NULL);
		gpio_free(pdata->gpio_charge_finished);
	}


	cancel_delayed_work(&bat_work);
	cancel_delayed_work(&bat_work);


@@ -408,12 +409,12 @@ static int s3c_adc_bat_suspend(struct platform_device *pdev,
{
{
	struct s3c_adc_bat_pdata *pdata = pdev->dev.platform_data;
	struct s3c_adc_bat_pdata *pdata = pdev->dev.platform_data;


	if (pdata->gpio_charge_finished >= 0) {
	if (main_bat.charge_finished) {
		if (device_may_wakeup(&pdev->dev))
		if (device_may_wakeup(&pdev->dev))
			enable_irq_wake(
			enable_irq_wake(
				gpio_to_irq(pdata->gpio_charge_finished));
				gpiod_to_irq(main_bat.charge_finished));
		else {
		else {
			disable_irq(gpio_to_irq(pdata->gpio_charge_finished));
			disable_irq(gpiod_to_irq(main_bat.charge_finished));
			main_bat.pdata->disable_charger();
			main_bat.pdata->disable_charger();
		}
		}
	}
	}
@@ -425,12 +426,12 @@ static int s3c_adc_bat_resume(struct platform_device *pdev)
{
{
	struct s3c_adc_bat_pdata *pdata = pdev->dev.platform_data;
	struct s3c_adc_bat_pdata *pdata = pdev->dev.platform_data;


	if (pdata->gpio_charge_finished >= 0) {
	if (main_bat.charge_finished) {
		if (device_may_wakeup(&pdev->dev))
		if (device_may_wakeup(&pdev->dev))
			disable_irq_wake(
			disable_irq_wake(
				gpio_to_irq(pdata->gpio_charge_finished));
				gpiod_to_irq(main_bat.charge_finished));
		else
		else
			enable_irq(gpio_to_irq(pdata->gpio_charge_finished));
			enable_irq(gpiod_to_irq(main_bat.charge_finished));
	}
	}


	/* Schedule timer to check current status */
	/* Schedule timer to check current status */
+0 −3
Original line number Original line Diff line number Diff line
@@ -14,9 +14,6 @@ struct s3c_adc_bat_pdata {
	void (*enable_charger)(void);
	void (*enable_charger)(void);
	void (*disable_charger)(void);
	void (*disable_charger)(void);


	int gpio_charge_finished;
	int gpio_inverted;

	const struct s3c_adc_bat_thresh *lut_noac;
	const struct s3c_adc_bat_thresh *lut_noac;
	unsigned int lut_noac_cnt;
	unsigned int lut_noac_cnt;
	const struct s3c_adc_bat_thresh *lut_acin;
	const struct s3c_adc_bat_thresh *lut_acin;