Skip to content

Commit

Permalink
gpio/omap: consolidate direction, input, output, remove #ifdefs
Browse files Browse the repository at this point in the history
Add register offset fields to GPIO platform_data for registers.

This patch adds registers that control direction, input and output
data.  Using these register offsets in the common driver allows
removal of #ifdefs and greatly improves readability.

Also create dedicated data out functions: one for banks with dedicated
set/clear registers, and another for banks with a single mask
register.

Signed-off-by: Kevin Hilman <khilman@ti.com>
  • Loading branch information
Kevin Hilman committed Jun 16, 2011
1 parent a8be8da commit fa87931
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 200 deletions.
14 changes: 14 additions & 0 deletions arch/arm/mach-omap1/gpio15xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,18 @@ static struct __initdata resource omap15xx_mpu_gpio_resources[] = {
},
};

static struct omap_gpio_reg_offs omap15xx_mpuio_regs = {
.direction = OMAP_MPUIO_IO_CNTL,
.datain = OMAP_MPUIO_INPUT_LATCH,
.dataout = OMAP_MPUIO_OUTPUT,
};

static struct __initdata omap_gpio_platform_data omap15xx_mpu_gpio_config = {
.virtual_irq_start = IH_MPUIO_BASE,
.bank_type = METHOD_MPUIO,
.bank_width = 16,
.bank_stride = 1,
.regs = &omap15xx_mpuio_regs,
};

static struct __initdata platform_device omap15xx_mpu_gpio = {
Expand All @@ -64,10 +71,17 @@ static struct __initdata resource omap15xx_gpio_resources[] = {
},
};

static struct omap_gpio_reg_offs omap15xx_gpio_regs = {
.direction = OMAP1510_GPIO_DIR_CONTROL,
.datain = OMAP1510_GPIO_DATA_INPUT,
.dataout = OMAP1510_GPIO_DATA_OUTPUT,
};

static struct __initdata omap_gpio_platform_data omap15xx_gpio_config = {
.virtual_irq_start = IH_GPIO_BASE,
.bank_type = METHOD_GPIO_1510,
.bank_width = 16,
.regs = &omap15xx_gpio_regs,
};

static struct __initdata platform_device omap15xx_gpio = {
Expand Down
19 changes: 19 additions & 0 deletions arch/arm/mach-omap1/gpio16xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,18 @@ static struct __initdata resource omap16xx_mpu_gpio_resources[] = {
},
};

static struct omap_gpio_reg_offs omap16xx_mpuio_regs = {
.direction = OMAP_MPUIO_IO_CNTL,
.datain = OMAP_MPUIO_INPUT_LATCH,
.dataout = OMAP_MPUIO_OUTPUT,
};

static struct __initdata omap_gpio_platform_data omap16xx_mpu_gpio_config = {
.virtual_irq_start = IH_MPUIO_BASE,
.bank_type = METHOD_MPUIO,
.bank_width = 16,
.bank_stride = 1,
.regs = &omap16xx_mpuio_regs,
};

static struct __initdata platform_device omap16xx_mpu_gpio = {
Expand All @@ -67,10 +74,19 @@ static struct __initdata resource omap16xx_gpio1_resources[] = {
},
};

static struct omap_gpio_reg_offs omap16xx_gpio_regs = {
.direction = OMAP1610_GPIO_DIRECTION,
.set_dataout = OMAP1610_GPIO_SET_DATAOUT,
.clr_dataout = OMAP1610_GPIO_CLEAR_DATAOUT,
.datain = OMAP1610_GPIO_DATAIN,
.dataout = OMAP1610_GPIO_DATAOUT,
};

static struct __initdata omap_gpio_platform_data omap16xx_gpio1_config = {
.virtual_irq_start = IH_GPIO_BASE,
.bank_type = METHOD_GPIO_1610,
.bank_width = 16,
.regs = &omap16xx_gpio_regs,
};

static struct __initdata platform_device omap16xx_gpio1 = {
Expand Down Expand Up @@ -100,6 +116,7 @@ static struct __initdata omap_gpio_platform_data omap16xx_gpio2_config = {
.virtual_irq_start = IH_GPIO_BASE + 16,
.bank_type = METHOD_GPIO_1610,
.bank_width = 16,
.regs = &omap16xx_gpio_regs,
};

static struct __initdata platform_device omap16xx_gpio2 = {
Expand Down Expand Up @@ -129,6 +146,7 @@ static struct __initdata omap_gpio_platform_data omap16xx_gpio3_config = {
.virtual_irq_start = IH_GPIO_BASE + 32,
.bank_type = METHOD_GPIO_1610,
.bank_width = 16,
.regs = &omap16xx_gpio_regs,
};

static struct __initdata platform_device omap16xx_gpio3 = {
Expand Down Expand Up @@ -158,6 +176,7 @@ static struct __initdata omap_gpio_platform_data omap16xx_gpio4_config = {
.virtual_irq_start = IH_GPIO_BASE + 48,
.bank_type = METHOD_GPIO_1610,
.bank_width = 16,
.regs = &omap16xx_gpio_regs,
};

static struct __initdata platform_device omap16xx_gpio4 = {
Expand Down
19 changes: 19 additions & 0 deletions arch/arm/mach-omap1/gpio7xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,18 @@ static struct __initdata resource omap7xx_mpu_gpio_resources[] = {
},
};

static struct omap_gpio_reg_offs omap7xx_mpuio_regs = {
.direction = OMAP_MPUIO_IO_CNTL / 2,
.datain = OMAP_MPUIO_INPUT_LATCH / 2,
.dataout = OMAP_MPUIO_OUTPUT / 2,
};

static struct __initdata omap_gpio_platform_data omap7xx_mpu_gpio_config = {
.virtual_irq_start = IH_MPUIO_BASE,
.bank_type = METHOD_MPUIO,
.bank_width = 32,
.bank_stride = 2,
.regs = &omap7xx_mpuio_regs,
};

static struct __initdata platform_device omap7xx_mpu_gpio = {
Expand All @@ -69,10 +76,17 @@ static struct __initdata resource omap7xx_gpio1_resources[] = {
},
};

static struct omap_gpio_reg_offs omap7xx_gpio_regs = {
.direction = OMAP7XX_GPIO_DIR_CONTROL,
.datain = OMAP7XX_GPIO_DATA_INPUT,
.dataout = OMAP7XX_GPIO_DATA_OUTPUT,
};

static struct __initdata omap_gpio_platform_data omap7xx_gpio1_config = {
.virtual_irq_start = IH_GPIO_BASE,
.bank_type = METHOD_GPIO_7XX,
.bank_width = 32,
.regs = &omap7xx_gpio_regs,
};

static struct __initdata platform_device omap7xx_gpio1 = {
Expand Down Expand Up @@ -102,6 +116,7 @@ static struct __initdata omap_gpio_platform_data omap7xx_gpio2_config = {
.virtual_irq_start = IH_GPIO_BASE + 32,
.bank_type = METHOD_GPIO_7XX,
.bank_width = 32,
.regs = &omap7xx_gpio_regs,
};

static struct __initdata platform_device omap7xx_gpio2 = {
Expand Down Expand Up @@ -131,6 +146,7 @@ static struct __initdata omap_gpio_platform_data omap7xx_gpio3_config = {
.virtual_irq_start = IH_GPIO_BASE + 64,
.bank_type = METHOD_GPIO_7XX,
.bank_width = 32,
.regs = &omap7xx_gpio_regs,
};

static struct __initdata platform_device omap7xx_gpio3 = {
Expand Down Expand Up @@ -160,6 +176,7 @@ static struct __initdata omap_gpio_platform_data omap7xx_gpio4_config = {
.virtual_irq_start = IH_GPIO_BASE + 96,
.bank_type = METHOD_GPIO_7XX,
.bank_width = 32,
.regs = &omap7xx_gpio_regs,
};

static struct __initdata platform_device omap7xx_gpio4 = {
Expand Down Expand Up @@ -189,6 +206,7 @@ static struct __initdata omap_gpio_platform_data omap7xx_gpio5_config = {
.virtual_irq_start = IH_GPIO_BASE + 128,
.bank_type = METHOD_GPIO_7XX,
.bank_width = 32,
.regs = &omap7xx_gpio_regs,
};

static struct __initdata platform_device omap7xx_gpio5 = {
Expand Down Expand Up @@ -218,6 +236,7 @@ static struct __initdata omap_gpio_platform_data omap7xx_gpio6_config = {
.virtual_irq_start = IH_GPIO_BASE + 160,
.bank_type = METHOD_GPIO_7XX,
.bank_width = 32,
.regs = &omap7xx_gpio_regs,
};

static struct __initdata platform_device omap7xx_gpio6 = {
Expand Down
16 changes: 16 additions & 0 deletions arch/arm/mach-omap2/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,29 @@ static int omap2_gpio_dev_init(struct omap_hwmod *oh, void *unused)
pdata->dbck_flag = dev_attr->dbck_flag;
pdata->virtual_irq_start = IH_GPIO_BASE + 32 * (id - 1);

pdata->regs = kzalloc(sizeof(struct omap_gpio_reg_offs), GFP_KERNEL);
if (!pdata) {
pr_err("gpio%d: Memory allocation failed\n", id);
return -ENOMEM;
}

switch (oh->class->rev) {
case 0:
case 1:
pdata->bank_type = METHOD_GPIO_24XX;
pdata->regs->direction = OMAP24XX_GPIO_OE;
pdata->regs->datain = OMAP24XX_GPIO_DATAIN;
pdata->regs->dataout = OMAP24XX_GPIO_DATAOUT;
pdata->regs->set_dataout = OMAP24XX_GPIO_SETDATAOUT;
pdata->regs->clr_dataout = OMAP24XX_GPIO_CLEARDATAOUT;
break;
case 2:
pdata->bank_type = METHOD_GPIO_44XX;
pdata->regs->direction = OMAP4_GPIO_OE;
pdata->regs->datain = OMAP4_GPIO_DATAIN;
pdata->regs->dataout = OMAP4_GPIO_DATAOUT;
pdata->regs->set_dataout = OMAP4_GPIO_SETDATAOUT;
pdata->regs->clr_dataout = OMAP4_GPIO_CLEARDATAOUT;
break;
default:
WARN(1, "Invalid gpio bank_type\n");
Expand Down
10 changes: 10 additions & 0 deletions arch/arm/plat-omap/include/plat/gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,22 @@ struct omap_gpio_dev_attr {
bool dbck_flag; /* dbck required or not - True for OMAP3&4 */
};

struct omap_gpio_reg_offs {
u16 direction;
u16 datain;
u16 dataout;
u16 set_dataout;
u16 clr_dataout;
};

struct omap_gpio_platform_data {
u16 virtual_irq_start;
int bank_type;
int bank_width; /* GPIO bank width */
int bank_stride; /* Only needed for omap1 MPUIO */
bool dbck_flag; /* dbck required or not - True for OMAP3&4 */

struct omap_gpio_reg_offs *regs;
};

/* TODO: Analyze removing gpio_bank_count usage from driver code */
Expand Down
Loading

0 comments on commit fa87931

Please sign in to comment.