Commit 6c95fa80 authored by Jingoo Han's avatar Jingoo Han Committed by Alexandre Belloni

rtc: rtc-v3020: use gpio_request_array()

Using gpio_request_array()/gpio_free_array() can make the code
simpler because it can set the direction and initial value
in one shot and the for loop is unnecessary.

Also, struct v3020_gpio is removed, because the struct v3020_gpio
is replaced with struct gpio.
Signed-off-by: default avatarJingoo Han <jg1.han@samsung.com>
Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@free-electrons.com>
parent ff32ff17
...@@ -49,18 +49,13 @@ struct v3020_chip_ops { ...@@ -49,18 +49,13 @@ struct v3020_chip_ops {
#define V3020_RD 2 #define V3020_RD 2
#define V3020_IO 3 #define V3020_IO 3
struct v3020_gpio {
const char *name;
unsigned int gpio;
};
struct v3020 { struct v3020 {
/* MMIO access */ /* MMIO access */
void __iomem *ioaddress; void __iomem *ioaddress;
int leftshift; int leftshift;
/* GPIO access */ /* GPIO access */
struct v3020_gpio *gpio; struct gpio *gpio;
struct v3020_chip_ops *ops; struct v3020_chip_ops *ops;
...@@ -107,48 +102,34 @@ static struct v3020_chip_ops v3020_mmio_ops = { ...@@ -107,48 +102,34 @@ static struct v3020_chip_ops v3020_mmio_ops = {
.write_bit = v3020_mmio_write_bit, .write_bit = v3020_mmio_write_bit,
}; };
static struct v3020_gpio v3020_gpio[] = { static struct gpio v3020_gpio[] = {
{ "RTC CS", 0 }, { 0, GPIOF_OUT_INIT_HIGH, "RTC CS"},
{ "RTC WR", 0 }, { 0, GPIOF_OUT_INIT_HIGH, "RTC WR"},
{ "RTC RD", 0 }, { 0, GPIOF_OUT_INIT_HIGH, "RTC RD"},
{ "RTC IO", 0 }, { 0, GPIOF_OUT_INIT_HIGH, "RTC IO"},
}; };
static int v3020_gpio_map(struct v3020 *chip, struct platform_device *pdev, static int v3020_gpio_map(struct v3020 *chip, struct platform_device *pdev,
struct v3020_platform_data *pdata) struct v3020_platform_data *pdata)
{ {
int i, err; int err;
v3020_gpio[V3020_CS].gpio = pdata->gpio_cs; v3020_gpio[V3020_CS].gpio = pdata->gpio_cs;
v3020_gpio[V3020_WR].gpio = pdata->gpio_wr; v3020_gpio[V3020_WR].gpio = pdata->gpio_wr;
v3020_gpio[V3020_RD].gpio = pdata->gpio_rd; v3020_gpio[V3020_RD].gpio = pdata->gpio_rd;
v3020_gpio[V3020_IO].gpio = pdata->gpio_io; v3020_gpio[V3020_IO].gpio = pdata->gpio_io;
for (i = 0; i < ARRAY_SIZE(v3020_gpio); i++) { err = gpio_request_array(v3020_gpio, ARRAY_SIZE(v3020_gpio));
err = gpio_request(v3020_gpio[i].gpio, v3020_gpio[i].name);
if (err)
goto err_request;
gpio_direction_output(v3020_gpio[i].gpio, 1); if (!err)
} chip->gpio = v3020_gpio;
chip->gpio = v3020_gpio;
return 0;
err_request:
while (--i >= 0)
gpio_free(v3020_gpio[i].gpio);
return err; return err;
} }
static void v3020_gpio_unmap(struct v3020 *chip) static void v3020_gpio_unmap(struct v3020 *chip)
{ {
int i; gpio_free_array(v3020_gpio, ARRAY_SIZE(v3020_gpio));
for (i = 0; i < ARRAY_SIZE(v3020_gpio); i++)
gpio_free(v3020_gpio[i].gpio);
} }
static void v3020_gpio_write_bit(struct v3020 *chip, unsigned char bit) static void v3020_gpio_write_bit(struct v3020 *chip, unsigned char bit)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment