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

Commit f2edc756 authored by Ben Dooks's avatar Ben Dooks
Browse files

[ARM] S3C24XX: Reduce code lineage of gpiolib.c



All the s3c24xx gpiolib chips share the same get/set
calls and all but one bank shares the same calls for
.direction_input and .direction_output methods.

Change the initialisation process to use an new call
to register the chips that fills in any blank calls
with the default values to avoid having to fill them
in the structure initialisers.

Signed-off-by: default avatarBen Dooks <ben-linux@fluff.org>
parent cec444b7
Loading
Loading
Loading
Loading
+22 −27
Original line number Original line Diff line number Diff line
@@ -161,8 +161,6 @@ static struct s3c24xx_gpio_chip gpios[] = {
			.ngpio			= 24,
			.ngpio			= 24,
			.direction_input	= s3c24xx_gpiolib_banka_input,
			.direction_input	= s3c24xx_gpiolib_banka_input,
			.direction_output	= s3c24xx_gpiolib_banka_output,
			.direction_output	= s3c24xx_gpiolib_banka_output,
			.set			= s3c24xx_gpiolib_set,
			.get			= s3c24xx_gpiolib_get,
		},
		},
	},
	},
	[1] = {
	[1] = {
@@ -172,10 +170,6 @@ static struct s3c24xx_gpio_chip gpios[] = {
			.owner			= THIS_MODULE,
			.owner			= THIS_MODULE,
			.label			= "GPIOB",
			.label			= "GPIOB",
			.ngpio			= 16,
			.ngpio			= 16,
			.direction_input	= s3c24xx_gpiolib_input,
			.direction_output	= s3c24xx_gpiolib_output,
			.set			= s3c24xx_gpiolib_set,
			.get			= s3c24xx_gpiolib_get,
		},
		},
	},
	},
	[2] = {
	[2] = {
@@ -185,10 +179,6 @@ static struct s3c24xx_gpio_chip gpios[] = {
			.owner			= THIS_MODULE,
			.owner			= THIS_MODULE,
			.label			= "GPIOC",
			.label			= "GPIOC",
			.ngpio			= 16,
			.ngpio			= 16,
			.direction_input	= s3c24xx_gpiolib_input,
			.direction_output	= s3c24xx_gpiolib_output,
			.set			= s3c24xx_gpiolib_set,
			.get			= s3c24xx_gpiolib_get,
		},
		},
	},
	},
	[3] = {
	[3] = {
@@ -198,10 +188,6 @@ static struct s3c24xx_gpio_chip gpios[] = {
			.owner			= THIS_MODULE,
			.owner			= THIS_MODULE,
			.label			= "GPIOD",
			.label			= "GPIOD",
			.ngpio			= 16,
			.ngpio			= 16,
			.direction_input	= s3c24xx_gpiolib_input,
			.direction_output	= s3c24xx_gpiolib_output,
			.set			= s3c24xx_gpiolib_set,
			.get			= s3c24xx_gpiolib_get,
		},
		},
	},
	},
	[4] = {
	[4] = {
@@ -211,10 +197,6 @@ static struct s3c24xx_gpio_chip gpios[] = {
			.label			= "GPIOE",
			.label			= "GPIOE",
			.owner			= THIS_MODULE,
			.owner			= THIS_MODULE,
			.ngpio			= 16,
			.ngpio			= 16,
			.direction_input	= s3c24xx_gpiolib_input,
			.direction_output	= s3c24xx_gpiolib_output,
			.set			= s3c24xx_gpiolib_set,
			.get			= s3c24xx_gpiolib_get,
		},
		},
	},
	},
	[5] = {
	[5] = {
@@ -224,10 +206,6 @@ static struct s3c24xx_gpio_chip gpios[] = {
			.owner			= THIS_MODULE,
			.owner			= THIS_MODULE,
			.label			= "GPIOF",
			.label			= "GPIOF",
			.ngpio			= 8,
			.ngpio			= 8,
			.direction_input	= s3c24xx_gpiolib_input,
			.direction_output	= s3c24xx_gpiolib_output,
			.set			= s3c24xx_gpiolib_set,
			.get			= s3c24xx_gpiolib_get,
		},
		},
	},
	},
	[6] = {
	[6] = {
@@ -237,21 +215,38 @@ static struct s3c24xx_gpio_chip gpios[] = {
			.owner			= THIS_MODULE,
			.owner			= THIS_MODULE,
			.label			= "GPIOG",
			.label			= "GPIOG",
			.ngpio			= 10,
			.ngpio			= 10,
			.direction_input	= s3c24xx_gpiolib_input,
			.direction_output	= s3c24xx_gpiolib_output,
			.set			= s3c24xx_gpiolib_set,
			.get			= s3c24xx_gpiolib_get,
		},
		},
	},
	},
};
};


static __init void s3c24xx_gpiolib_add(struct s3c24xx_gpio_chip *chip)
{
	struct gpio_chip *gc = &chip->chip;

	BUG_ON(!chip->base);
	BUG_ON(!gc->label);
	BUG_ON(!gc->ngpio);

	if (!gc->direction_input)
		gc->direction_input = s3c24xx_gpiolib_input;
	if (!gc->direction_output)
		gc->direction_output = s3c24xx_gpiolib_output;
	if (!gc->set)
		gc->set = s3c24xx_gpiolib_set;
	if (!gc->get)
		gc->get = s3c24xx_gpiolib_get;

	/* gpiochip_add() prints own failure message on error. */
	gpiochip_add(gc);
}

static __init int s3c24xx_gpiolib_init(void)
static __init int s3c24xx_gpiolib_init(void)
{
{
	struct s3c24xx_gpio_chip *chip = gpios;
	struct s3c24xx_gpio_chip *chip = gpios;
	int gpn;
	int gpn;


	for (gpn = 0; gpn < ARRAY_SIZE(gpios); gpn++, chip++)
	for (gpn = 0; gpn < ARRAY_SIZE(gpios); gpn++, chip++)
		gpiochip_add(&chip->chip);
		s3c24xx_gpiolib_add(chip);


	return 0;
	return 0;
}
}