Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 389cd203 authored by Axel Lin's avatar Axel Lin Committed by Anton Vorontsov
Browse files

collie_battery: Convert to gpio_request_array() / gpio_free_array()



As suggested by Igor Grinberg, this change make the implementation looks
simpler.

Signed-off-by: default avatarAxel Lin <axel.lin@gmail.com>
Signed-off-by: default avatarAnton Vorontsov <cbouatmailru@gmail.com>
parent 7ab2f020
Loading
Loading
Loading
Loading
+13 −40
Original line number Original line Diff line number Diff line
@@ -277,18 +277,13 @@ static struct collie_bat collie_bat_bu = {
	.adc_temp_divider = -1,
	.adc_temp_divider = -1,
};
};


static struct {
static struct gpio collie_batt_gpios[] = {
	int gpio;
	{ COLLIE_GPIO_CO,	    GPIOF_IN,		"main battery full" },
	char *name;
	{ COLLIE_GPIO_MAIN_BAT_LOW, GPIOF_IN,		"main battery low" },
	bool output;
	{ COLLIE_GPIO_CHARGE_ON,    GPIOF_OUT_INIT_LOW,	"main charge on" },
	int value;
	{ COLLIE_GPIO_MBAT_ON,	    GPIOF_OUT_INIT_LOW,	"main battery" },
} gpios[] = {
	{ COLLIE_GPIO_TMP_ON,	    GPIOF_OUT_INIT_LOW,	"main battery temp" },
	{ COLLIE_GPIO_CO,		"main battery full",	0, 0 },
	{ COLLIE_GPIO_BBAT_ON,	    GPIOF_OUT_INIT_LOW,	"backup battery" },
	{ COLLIE_GPIO_MAIN_BAT_LOW,	"main battery low",	0, 0 },
	{ COLLIE_GPIO_CHARGE_ON,	"main charge on",	1, 0 },
	{ COLLIE_GPIO_MBAT_ON,		"main battery",		1, 0 },
	{ COLLIE_GPIO_TMP_ON,		"main battery temp",	1, 0 },
	{ COLLIE_GPIO_BBAT_ON,		"backup battery",	1, 0 },
};
};


#ifdef CONFIG_PM
#ifdef CONFIG_PM
@@ -313,29 +308,16 @@ static int collie_bat_resume(struct ucb1x00_dev *dev)
static int __devinit collie_bat_probe(struct ucb1x00_dev *dev)
static int __devinit collie_bat_probe(struct ucb1x00_dev *dev)
{
{
	int ret;
	int ret;
	int i;


	if (!machine_is_collie())
	if (!machine_is_collie())
		return -ENODEV;
		return -ENODEV;


	ucb = dev->ucb;
	ucb = dev->ucb;


	for (i = 0; i < ARRAY_SIZE(gpios); i++) {
	ret = gpio_request_array(collie_batt_gpios,
		ret = gpio_request(gpios[i].gpio, gpios[i].name);
				 ARRAY_SIZE(collie_batt_gpios));
		if (ret) {
			i--;
			goto err_gpio;
		}

		if (gpios[i].output)
			ret = gpio_direction_output(gpios[i].gpio,
					gpios[i].value);
		else
			ret = gpio_direction_input(gpios[i].gpio);

	if (ret)
	if (ret)
			goto err_gpio;
		return ret;
	}


	mutex_init(&collie_bat_main.work_lock);
	mutex_init(&collie_bat_main.work_lock);


@@ -363,19 +345,12 @@ static int __devinit collie_bat_probe(struct ucb1x00_dev *dev)


	/* see comment in collie_bat_remove */
	/* see comment in collie_bat_remove */
	cancel_work_sync(&bat_work);
	cancel_work_sync(&bat_work);

	gpio_free_array(collie_batt_gpios, ARRAY_SIZE(collie_batt_gpios));
	i--;
err_gpio:
	for (; i >= 0; i--)
		gpio_free(gpios[i].gpio);

	return ret;
	return ret;
}
}


static void __devexit collie_bat_remove(struct ucb1x00_dev *dev)
static void __devexit collie_bat_remove(struct ucb1x00_dev *dev)
{
{
	int i;

	free_irq(gpio_to_irq(COLLIE_GPIO_CO), &collie_bat_main);
	free_irq(gpio_to_irq(COLLIE_GPIO_CO), &collie_bat_main);


	power_supply_unregister(&collie_bat_bu.psy);
	power_supply_unregister(&collie_bat_bu.psy);
@@ -387,9 +362,7 @@ static void __devexit collie_bat_remove(struct ucb1x00_dev *dev)
	 * unregistered now.
	 * unregistered now.
	 */
	 */
	cancel_work_sync(&bat_work);
	cancel_work_sync(&bat_work);

	gpio_free_array(collie_batt_gpios, ARRAY_SIZE(collie_batt_gpios));
	for (i = ARRAY_SIZE(gpios) - 1; i >= 0; i--)
		gpio_free(gpios[i].gpio);
}
}


static struct ucb1x00_driver collie_bat_driver = {
static struct ucb1x00_driver collie_bat_driver = {