2016-05-25 13:15:20 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2016
|
|
|
|
* Mario Six, Guntermann & Drunck GmbH, six@gdsys.de
|
|
|
|
*
|
|
|
|
* based on arch/powerpc/include/asm/mpc85xx_gpio.h, which is
|
|
|
|
*
|
|
|
|
* Copyright 2010 eXMeritus, A Boeing Company
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <dm.h>
|
|
|
|
#include <asm/gpio.h>
|
|
|
|
#include <mapmem.h>
|
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
|
|
|
struct ccsr_gpio {
|
|
|
|
u32 gpdir;
|
|
|
|
u32 gpodr;
|
|
|
|
u32 gpdat;
|
|
|
|
u32 gpier;
|
|
|
|
u32 gpimr;
|
|
|
|
u32 gpicr;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct mpc85xx_gpio_data {
|
|
|
|
/* The bank's register base in memory */
|
|
|
|
struct ccsr_gpio __iomem *base;
|
|
|
|
/* The address of the registers; used to identify the bank */
|
|
|
|
ulong addr;
|
|
|
|
/* The GPIO count of the bank */
|
|
|
|
uint gpio_count;
|
|
|
|
/* The GPDAT register cannot be used to determine the value of output
|
|
|
|
* pins on MPC8572/MPC8536, so we shadow it and use the shadowed value
|
|
|
|
* for output pins */
|
|
|
|
u32 dat_shadow;
|
|
|
|
};
|
|
|
|
|
|
|
|
inline u32 gpio_mask(unsigned gpio) {
|
|
|
|
return (1U << (31 - (gpio)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline u32 mpc85xx_gpio_get_val(struct ccsr_gpio *base, u32 mask)
|
|
|
|
{
|
|
|
|
return in_be32(&base->gpdat) & mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline u32 mpc85xx_gpio_get_dir(struct ccsr_gpio *base, u32 mask)
|
|
|
|
{
|
|
|
|
return in_be32(&base->gpdir) & mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void mpc85xx_gpio_set_in(struct ccsr_gpio *base, u32 gpios)
|
|
|
|
{
|
|
|
|
clrbits_be32(&base->gpdat, gpios);
|
|
|
|
/* GPDIR register 0 -> input */
|
|
|
|
clrbits_be32(&base->gpdir, gpios);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void mpc85xx_gpio_set_low(struct ccsr_gpio *base, u32 gpios)
|
|
|
|
{
|
|
|
|
clrbits_be32(&base->gpdat, gpios);
|
|
|
|
/* GPDIR register 1 -> output */
|
|
|
|
setbits_be32(&base->gpdir, gpios);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void mpc85xx_gpio_set_high(struct ccsr_gpio *base, u32 gpios)
|
|
|
|
{
|
|
|
|
setbits_be32(&base->gpdat, gpios);
|
|
|
|
/* GPDIR register 1 -> output */
|
|
|
|
setbits_be32(&base->gpdir, gpios);
|
|
|
|
}
|
|
|
|
|
2016-05-25 13:15:22 +00:00
|
|
|
static inline int mpc85xx_gpio_open_drain_val(struct ccsr_gpio *base, u32 mask)
|
|
|
|
{
|
|
|
|
return in_be32(&base->gpodr) & mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void mpc85xx_gpio_open_drain_on(struct ccsr_gpio *base, u32
|
|
|
|
gpios)
|
|
|
|
{
|
|
|
|
/* GPODR register 1 -> open drain on */
|
|
|
|
setbits_be32(&base->gpodr, gpios);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void mpc85xx_gpio_open_drain_off(struct ccsr_gpio *base,
|
|
|
|
u32 gpios)
|
|
|
|
{
|
|
|
|
/* GPODR register 0 -> open drain off (actively driven) */
|
|
|
|
clrbits_be32(&base->gpodr, gpios);
|
|
|
|
}
|
|
|
|
|
2016-05-25 13:15:20 +00:00
|
|
|
static int mpc85xx_gpio_direction_input(struct udevice *dev, unsigned gpio)
|
|
|
|
{
|
|
|
|
struct mpc85xx_gpio_data *data = dev_get_priv(dev);
|
|
|
|
|
|
|
|
mpc85xx_gpio_set_in(data->base, gpio_mask(gpio));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mpc85xx_gpio_set_value(struct udevice *dev, unsigned gpio,
|
|
|
|
int value)
|
|
|
|
{
|
|
|
|
struct mpc85xx_gpio_data *data = dev_get_priv(dev);
|
|
|
|
|
|
|
|
if (value) {
|
|
|
|
data->dat_shadow |= gpio_mask(gpio);
|
|
|
|
mpc85xx_gpio_set_high(data->base, gpio_mask(gpio));
|
|
|
|
} else {
|
|
|
|
data->dat_shadow &= ~gpio_mask(gpio);
|
|
|
|
mpc85xx_gpio_set_low(data->base, gpio_mask(gpio));
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mpc85xx_gpio_direction_output(struct udevice *dev, unsigned gpio,
|
|
|
|
int value)
|
|
|
|
{
|
|
|
|
return mpc85xx_gpio_set_value(dev, gpio, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mpc85xx_gpio_get_value(struct udevice *dev, unsigned gpio)
|
|
|
|
{
|
|
|
|
struct mpc85xx_gpio_data *data = dev_get_priv(dev);
|
|
|
|
|
|
|
|
if (!!mpc85xx_gpio_get_dir(data->base, gpio_mask(gpio))) {
|
|
|
|
/* Output -> use shadowed value */
|
|
|
|
return !!(data->dat_shadow & gpio_mask(gpio));
|
|
|
|
} else {
|
|
|
|
/* Input -> read value from GPDAT register */
|
|
|
|
return !!mpc85xx_gpio_get_val(data->base, gpio_mask(gpio));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-25 13:15:22 +00:00
|
|
|
static int mpc85xx_gpio_get_open_drain(struct udevice *dev, unsigned gpio)
|
|
|
|
{
|
|
|
|
struct mpc85xx_gpio_data *data = dev_get_priv(dev);
|
|
|
|
|
|
|
|
return !!mpc85xx_gpio_open_drain_val(data->base, gpio_mask(gpio));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mpc85xx_gpio_set_open_drain(struct udevice *dev, unsigned gpio,
|
|
|
|
int value)
|
|
|
|
{
|
|
|
|
struct mpc85xx_gpio_data *data = dev_get_priv(dev);
|
|
|
|
|
|
|
|
if (value) {
|
|
|
|
mpc85xx_gpio_open_drain_on(data->base, gpio_mask(gpio));
|
|
|
|
} else {
|
|
|
|
mpc85xx_gpio_open_drain_off(data->base, gpio_mask(gpio));
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-05-25 13:15:20 +00:00
|
|
|
static int mpc85xx_gpio_get_function(struct udevice *dev, unsigned gpio)
|
|
|
|
{
|
|
|
|
struct mpc85xx_gpio_data *data = dev_get_priv(dev);
|
|
|
|
int dir;
|
|
|
|
|
|
|
|
dir = !!mpc85xx_gpio_get_dir(data->base, gpio_mask(gpio));
|
|
|
|
return dir ? GPIOF_OUTPUT : GPIOF_INPUT;
|
|
|
|
}
|
|
|
|
|
dm: gpio: MPC85XX GPIO platform data support
Define a platform data structure for the MPC85XX GPIO driver to allow
use of the driver without device tree. Users should define the GPIO
blocks for their platform like this:
struct mpc85xx_gpio_plat gpio_blocks[] = {
{
.addr = 0x130000,
.ngpios = 32,
},
{
.addr = 0x131000,
.ngpios = 32,
},
};
U_BOOT_DEVICES(my_platform_gpios) = {
{ "gpio_mpc85xx", &gpio_blocks[0] },
{ "gpio_mpc85xx", &gpio_blocks[1] },
};
This is intended to build upon the recent submission of the base
MPC85XX driver from Mario Six. We need to use that new driver
without dts support and this patch gives us that flexibility.
This has been tested on a Freescale T2080 CPU, although only the first
GPIO block.
Signed-off-by: Hamish Martin <hamish.martin@alliedtelesis.co.nz>
Reviewed-by: Mario Six <mario.six@gdsys.cc>
Tested-by: Mario Six <mario.six@gdsys.cc>
Acked-by: Simon Glass <sjg@chromium.org>
2016-06-13 22:17:05 +00:00
|
|
|
#if CONFIG_IS_ENABLED(OF_CONTROL)
|
2016-05-25 13:15:20 +00:00
|
|
|
static int mpc85xx_gpio_ofdata_to_platdata(struct udevice *dev) {
|
dm: gpio: MPC85XX GPIO platform data support
Define a platform data structure for the MPC85XX GPIO driver to allow
use of the driver without device tree. Users should define the GPIO
blocks for their platform like this:
struct mpc85xx_gpio_plat gpio_blocks[] = {
{
.addr = 0x130000,
.ngpios = 32,
},
{
.addr = 0x131000,
.ngpios = 32,
},
};
U_BOOT_DEVICES(my_platform_gpios) = {
{ "gpio_mpc85xx", &gpio_blocks[0] },
{ "gpio_mpc85xx", &gpio_blocks[1] },
};
This is intended to build upon the recent submission of the base
MPC85XX driver from Mario Six. We need to use that new driver
without dts support and this patch gives us that flexibility.
This has been tested on a Freescale T2080 CPU, although only the first
GPIO block.
Signed-off-by: Hamish Martin <hamish.martin@alliedtelesis.co.nz>
Reviewed-by: Mario Six <mario.six@gdsys.cc>
Tested-by: Mario Six <mario.six@gdsys.cc>
Acked-by: Simon Glass <sjg@chromium.org>
2016-06-13 22:17:05 +00:00
|
|
|
struct mpc85xx_gpio_plat *plat = dev_get_platdata(dev);
|
2016-05-25 13:15:20 +00:00
|
|
|
fdt_addr_t addr;
|
|
|
|
fdt_size_t size;
|
|
|
|
|
|
|
|
addr = fdtdec_get_addr_size_auto_noparent(gd->fdt_blob, dev->of_offset,
|
|
|
|
"reg", 0, &size);
|
|
|
|
|
dm: gpio: MPC85XX GPIO platform data support
Define a platform data structure for the MPC85XX GPIO driver to allow
use of the driver without device tree. Users should define the GPIO
blocks for their platform like this:
struct mpc85xx_gpio_plat gpio_blocks[] = {
{
.addr = 0x130000,
.ngpios = 32,
},
{
.addr = 0x131000,
.ngpios = 32,
},
};
U_BOOT_DEVICES(my_platform_gpios) = {
{ "gpio_mpc85xx", &gpio_blocks[0] },
{ "gpio_mpc85xx", &gpio_blocks[1] },
};
This is intended to build upon the recent submission of the base
MPC85XX driver from Mario Six. We need to use that new driver
without dts support and this patch gives us that flexibility.
This has been tested on a Freescale T2080 CPU, although only the first
GPIO block.
Signed-off-by: Hamish Martin <hamish.martin@alliedtelesis.co.nz>
Reviewed-by: Mario Six <mario.six@gdsys.cc>
Tested-by: Mario Six <mario.six@gdsys.cc>
Acked-by: Simon Glass <sjg@chromium.org>
2016-06-13 22:17:05 +00:00
|
|
|
plat->addr = addr;
|
|
|
|
plat->size = size;
|
|
|
|
plat->ngpios = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
|
|
|
|
"ngpios", 32);
|
2016-05-25 13:15:20 +00:00
|
|
|
|
dm: gpio: MPC85XX GPIO platform data support
Define a platform data structure for the MPC85XX GPIO driver to allow
use of the driver without device tree. Users should define the GPIO
blocks for their platform like this:
struct mpc85xx_gpio_plat gpio_blocks[] = {
{
.addr = 0x130000,
.ngpios = 32,
},
{
.addr = 0x131000,
.ngpios = 32,
},
};
U_BOOT_DEVICES(my_platform_gpios) = {
{ "gpio_mpc85xx", &gpio_blocks[0] },
{ "gpio_mpc85xx", &gpio_blocks[1] },
};
This is intended to build upon the recent submission of the base
MPC85XX driver from Mario Six. We need to use that new driver
without dts support and this patch gives us that flexibility.
This has been tested on a Freescale T2080 CPU, although only the first
GPIO block.
Signed-off-by: Hamish Martin <hamish.martin@alliedtelesis.co.nz>
Reviewed-by: Mario Six <mario.six@gdsys.cc>
Tested-by: Mario Six <mario.six@gdsys.cc>
Acked-by: Simon Glass <sjg@chromium.org>
2016-06-13 22:17:05 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static int mpc85xx_gpio_platdata_to_priv(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct mpc85xx_gpio_data *priv = dev_get_priv(dev);
|
|
|
|
struct mpc85xx_gpio_plat *plat = dev_get_platdata(dev);
|
|
|
|
unsigned long size = plat->size;
|
|
|
|
|
|
|
|
if (size == 0)
|
|
|
|
size = 0x100;
|
|
|
|
|
|
|
|
priv->addr = plat->addr;
|
|
|
|
priv->base = map_sysmem(CONFIG_SYS_IMMR + plat->addr, size);
|
|
|
|
|
|
|
|
if (!priv->base)
|
2016-05-25 13:15:20 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
|
dm: gpio: MPC85XX GPIO platform data support
Define a platform data structure for the MPC85XX GPIO driver to allow
use of the driver without device tree. Users should define the GPIO
blocks for their platform like this:
struct mpc85xx_gpio_plat gpio_blocks[] = {
{
.addr = 0x130000,
.ngpios = 32,
},
{
.addr = 0x131000,
.ngpios = 32,
},
};
U_BOOT_DEVICES(my_platform_gpios) = {
{ "gpio_mpc85xx", &gpio_blocks[0] },
{ "gpio_mpc85xx", &gpio_blocks[1] },
};
This is intended to build upon the recent submission of the base
MPC85XX driver from Mario Six. We need to use that new driver
without dts support and this patch gives us that flexibility.
This has been tested on a Freescale T2080 CPU, although only the first
GPIO block.
Signed-off-by: Hamish Martin <hamish.martin@alliedtelesis.co.nz>
Reviewed-by: Mario Six <mario.six@gdsys.cc>
Tested-by: Mario Six <mario.six@gdsys.cc>
Acked-by: Simon Glass <sjg@chromium.org>
2016-06-13 22:17:05 +00:00
|
|
|
priv->gpio_count = plat->ngpios;
|
|
|
|
priv->dat_shadow = 0;
|
2016-05-25 13:15:20 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mpc85xx_gpio_probe(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
|
|
|
|
struct mpc85xx_gpio_data *data = dev_get_priv(dev);
|
|
|
|
char name[32], *str;
|
|
|
|
|
dm: gpio: MPC85XX GPIO platform data support
Define a platform data structure for the MPC85XX GPIO driver to allow
use of the driver without device tree. Users should define the GPIO
blocks for their platform like this:
struct mpc85xx_gpio_plat gpio_blocks[] = {
{
.addr = 0x130000,
.ngpios = 32,
},
{
.addr = 0x131000,
.ngpios = 32,
},
};
U_BOOT_DEVICES(my_platform_gpios) = {
{ "gpio_mpc85xx", &gpio_blocks[0] },
{ "gpio_mpc85xx", &gpio_blocks[1] },
};
This is intended to build upon the recent submission of the base
MPC85XX driver from Mario Six. We need to use that new driver
without dts support and this patch gives us that flexibility.
This has been tested on a Freescale T2080 CPU, although only the first
GPIO block.
Signed-off-by: Hamish Martin <hamish.martin@alliedtelesis.co.nz>
Reviewed-by: Mario Six <mario.six@gdsys.cc>
Tested-by: Mario Six <mario.six@gdsys.cc>
Acked-by: Simon Glass <sjg@chromium.org>
2016-06-13 22:17:05 +00:00
|
|
|
mpc85xx_gpio_platdata_to_priv(dev);
|
|
|
|
|
2016-05-25 13:15:20 +00:00
|
|
|
snprintf(name, sizeof(name), "MPC@%lx_", data->addr);
|
|
|
|
str = strdup(name);
|
|
|
|
|
|
|
|
if (!str)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
uc_priv->bank_name = str;
|
|
|
|
uc_priv->gpio_count = data->gpio_count;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct dm_gpio_ops gpio_mpc85xx_ops = {
|
|
|
|
.direction_input = mpc85xx_gpio_direction_input,
|
|
|
|
.direction_output = mpc85xx_gpio_direction_output,
|
|
|
|
.get_value = mpc85xx_gpio_get_value,
|
|
|
|
.set_value = mpc85xx_gpio_set_value,
|
2016-05-25 13:15:22 +00:00
|
|
|
.get_open_drain = mpc85xx_gpio_get_open_drain,
|
|
|
|
.set_open_drain = mpc85xx_gpio_set_open_drain,
|
2016-05-25 13:15:20 +00:00
|
|
|
.get_function = mpc85xx_gpio_get_function,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct udevice_id mpc85xx_gpio_ids[] = {
|
|
|
|
{ .compatible = "fsl,pq3-gpio" },
|
|
|
|
{ /* sentinel */ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(gpio_mpc85xx) = {
|
|
|
|
.name = "gpio_mpc85xx",
|
|
|
|
.id = UCLASS_GPIO,
|
|
|
|
.ops = &gpio_mpc85xx_ops,
|
dm: gpio: MPC85XX GPIO platform data support
Define a platform data structure for the MPC85XX GPIO driver to allow
use of the driver without device tree. Users should define the GPIO
blocks for their platform like this:
struct mpc85xx_gpio_plat gpio_blocks[] = {
{
.addr = 0x130000,
.ngpios = 32,
},
{
.addr = 0x131000,
.ngpios = 32,
},
};
U_BOOT_DEVICES(my_platform_gpios) = {
{ "gpio_mpc85xx", &gpio_blocks[0] },
{ "gpio_mpc85xx", &gpio_blocks[1] },
};
This is intended to build upon the recent submission of the base
MPC85XX driver from Mario Six. We need to use that new driver
without dts support and this patch gives us that flexibility.
This has been tested on a Freescale T2080 CPU, although only the first
GPIO block.
Signed-off-by: Hamish Martin <hamish.martin@alliedtelesis.co.nz>
Reviewed-by: Mario Six <mario.six@gdsys.cc>
Tested-by: Mario Six <mario.six@gdsys.cc>
Acked-by: Simon Glass <sjg@chromium.org>
2016-06-13 22:17:05 +00:00
|
|
|
#if CONFIG_IS_ENABLED(OF_CONTROL)
|
2016-05-25 13:15:20 +00:00
|
|
|
.ofdata_to_platdata = mpc85xx_gpio_ofdata_to_platdata,
|
dm: gpio: MPC85XX GPIO platform data support
Define a platform data structure for the MPC85XX GPIO driver to allow
use of the driver without device tree. Users should define the GPIO
blocks for their platform like this:
struct mpc85xx_gpio_plat gpio_blocks[] = {
{
.addr = 0x130000,
.ngpios = 32,
},
{
.addr = 0x131000,
.ngpios = 32,
},
};
U_BOOT_DEVICES(my_platform_gpios) = {
{ "gpio_mpc85xx", &gpio_blocks[0] },
{ "gpio_mpc85xx", &gpio_blocks[1] },
};
This is intended to build upon the recent submission of the base
MPC85XX driver from Mario Six. We need to use that new driver
without dts support and this patch gives us that flexibility.
This has been tested on a Freescale T2080 CPU, although only the first
GPIO block.
Signed-off-by: Hamish Martin <hamish.martin@alliedtelesis.co.nz>
Reviewed-by: Mario Six <mario.six@gdsys.cc>
Tested-by: Mario Six <mario.six@gdsys.cc>
Acked-by: Simon Glass <sjg@chromium.org>
2016-06-13 22:17:05 +00:00
|
|
|
.platdata_auto_alloc_size = sizeof(struct mpc85xx_gpio_plat),
|
2016-05-25 13:15:20 +00:00
|
|
|
.of_match = mpc85xx_gpio_ids,
|
dm: gpio: MPC85XX GPIO platform data support
Define a platform data structure for the MPC85XX GPIO driver to allow
use of the driver without device tree. Users should define the GPIO
blocks for their platform like this:
struct mpc85xx_gpio_plat gpio_blocks[] = {
{
.addr = 0x130000,
.ngpios = 32,
},
{
.addr = 0x131000,
.ngpios = 32,
},
};
U_BOOT_DEVICES(my_platform_gpios) = {
{ "gpio_mpc85xx", &gpio_blocks[0] },
{ "gpio_mpc85xx", &gpio_blocks[1] },
};
This is intended to build upon the recent submission of the base
MPC85XX driver from Mario Six. We need to use that new driver
without dts support and this patch gives us that flexibility.
This has been tested on a Freescale T2080 CPU, although only the first
GPIO block.
Signed-off-by: Hamish Martin <hamish.martin@alliedtelesis.co.nz>
Reviewed-by: Mario Six <mario.six@gdsys.cc>
Tested-by: Mario Six <mario.six@gdsys.cc>
Acked-by: Simon Glass <sjg@chromium.org>
2016-06-13 22:17:05 +00:00
|
|
|
#endif
|
2016-05-25 13:15:20 +00:00
|
|
|
.probe = mpc85xx_gpio_probe,
|
|
|
|
.priv_auto_alloc_size = sizeof(struct mpc85xx_gpio_data),
|
|
|
|
};
|