u-boot/drivers/gpio/vybrid_gpio.c

138 lines
3.4 KiB
C
Raw Normal View History

// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (C) 2015
* Bhuvanchandra DV, Toradex, Inc.
*/
#include <common.h>
#include <dm.h>
#include <errno.h>
#include <fdtdec.h>
#include <asm/gpio.h>
imx: reorganize IMX code as other SOCs Change is consistent with other SOCs and it is in preparation for adding SOMs. SOC's related files are moved from cpu/ to mach-imx/<SOC>. This change is also coherent with the structure in kernel. Signed-off-by: Stefano Babic <sbabic@denx.de> CC: Fabio Estevam <fabio.estevam@nxp.com> CC: Akshay Bhat <akshaybhat@timesys.com> CC: Ken Lin <Ken.Lin@advantech.com.tw> CC: Marek Vasut <marek.vasut@gmail.com> CC: Heiko Schocher <hs@denx.de> CC: "Sébastien Szymanski" <sebastien.szymanski@armadeus.com> CC: Christian Gmeiner <christian.gmeiner@gmail.com> CC: Stefan Roese <sr@denx.de> CC: Patrick Bruenn <p.bruenn@beckhoff.com> CC: Troy Kisky <troy.kisky@boundarydevices.com> CC: Nikita Kiryanov <nikita@compulab.co.il> CC: Otavio Salvador <otavio@ossystems.com.br> CC: "Eric Bénard" <eric@eukrea.com> CC: Jagan Teki <jagan@amarulasolutions.com> CC: Ye Li <ye.li@nxp.com> CC: Peng Fan <peng.fan@nxp.com> CC: Adrian Alonso <adrian.alonso@nxp.com> CC: Alison Wang <b18965@freescale.com> CC: Tim Harvey <tharvey@gateworks.com> CC: Martin Donnelly <martin.donnelly@ge.com> CC: Marcin Niestroj <m.niestroj@grinn-global.com> CC: Lukasz Majewski <lukma@denx.de> CC: Adam Ford <aford173@gmail.com> CC: "Albert ARIBAUD (3ADEV)" <albert.aribaud@3adev.fr> CC: Boris Brezillon <boris.brezillon@free-electrons.com> CC: Soeren Moch <smoch@web.de> CC: Richard Hu <richard.hu@technexion.com> CC: Wig Cheng <wig.cheng@technexion.com> CC: Vanessa Maegima <vanessa.maegima@nxp.com> CC: Max Krummenacher <max.krummenacher@toradex.com> CC: Stefan Agner <stefan.agner@toradex.com> CC: Markus Niebel <Markus.Niebel@tq-group.com> CC: Breno Lima <breno.lima@nxp.com> CC: Francesco Montefoschi <francesco.montefoschi@udoo.org> CC: Jaehoon Chung <jh80.chung@samsung.com> CC: Scott Wood <oss@buserror.net> CC: Joe Hershberger <joe.hershberger@ni.com> CC: Anatolij Gustschin <agust@denx.de> CC: Simon Glass <sjg@chromium.org> CC: "Andrew F. Davis" <afd@ti.com> CC: "Łukasz Majewski" <l.majewski@samsung.com> CC: Patrice Chotard <patrice.chotard@st.com> CC: Nobuhiro Iwamatsu <iwamatsu@nigauri.org> CC: Hans de Goede <hdegoede@redhat.com> CC: Masahiro Yamada <yamada.masahiro@socionext.com> CC: Stephen Warren <swarren@nvidia.com> CC: Andre Przywara <andre.przywara@arm.com> CC: "Álvaro Fernández Rojas" <noltari@gmail.com> CC: York Sun <york.sun@nxp.com> CC: Xiaoliang Yang <xiaoliang.yang@nxp.com> CC: Chen-Yu Tsai <wens@csie.org> CC: George McCollister <george.mccollister@gmail.com> CC: Sven Ebenfeld <sven.ebenfeld@gmail.com> CC: Filip Brozovic <fbrozovic@gmail.com> CC: Petr Kulhavy <brain@jikos.cz> CC: Eric Nelson <eric@nelint.com> CC: Bai Ping <ping.bai@nxp.com> CC: Anson Huang <Anson.Huang@nxp.com> CC: Sanchayan Maity <maitysanchayan@gmail.com> CC: Lokesh Vutla <lokeshvutla@ti.com> CC: Patrick Delaunay <patrick.delaunay@st.com> CC: Gary Bisson <gary.bisson@boundarydevices.com> CC: Alexander Graf <agraf@suse.de> CC: u-boot@lists.denx.de Reviewed-by: Fabio Estevam <fabio.estevam@nxp.com> Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com>
2017-06-29 08:16:06 +00:00
#include <asm/mach-imx/iomux-v3.h>
#include <asm/io.h>
#include <malloc.h>
DECLARE_GLOBAL_DATA_PTR;
struct vybrid_gpios {
unsigned int chip;
struct vybrid_gpio_regs *reg;
};
static int vybrid_gpio_direction_input(struct udevice *dev, unsigned gpio)
{
const struct vybrid_gpios *gpios = dev_get_priv(dev);
gpio = gpio + (gpios->chip * VYBRID_GPIO_COUNT);
imx_iomux_gpio_set_direction(gpio, VF610_GPIO_DIRECTION_IN);
return 0;
}
static int vybrid_gpio_direction_output(struct udevice *dev, unsigned gpio,
int value)
{
const struct vybrid_gpios *gpios = dev_get_priv(dev);
gpio = gpio + (gpios->chip * VYBRID_GPIO_COUNT);
gpio_set_value(gpio, value);
imx_iomux_gpio_set_direction(gpio, VF610_GPIO_DIRECTION_OUT);
return 0;
}
static int vybrid_gpio_get_value(struct udevice *dev, unsigned gpio)
{
const struct vybrid_gpios *gpios = dev_get_priv(dev);
return ((readl(&gpios->reg->gpio_pdir) & (1 << gpio))) ? 1 : 0;
}
static int vybrid_gpio_set_value(struct udevice *dev, unsigned gpio,
int value)
{
const struct vybrid_gpios *gpios = dev_get_priv(dev);
if (value)
writel((1 << gpio), &gpios->reg->gpio_psor);
else
writel((1 << gpio), &gpios->reg->gpio_pcor);
return 0;
}
static int vybrid_gpio_get_function(struct udevice *dev, unsigned gpio)
{
const struct vybrid_gpios *gpios = dev_get_priv(dev);
u32 g_state = 0;
gpio = gpio + (gpios->chip * VYBRID_GPIO_COUNT);
imx_iomux_gpio_get_function(gpio, &g_state);
if (((g_state & (0x07 << PAD_MUX_MODE_SHIFT)) >> PAD_MUX_MODE_SHIFT) > 0)
return GPIOF_FUNC;
if (g_state & PAD_CTL_OBE_ENABLE)
return GPIOF_OUTPUT;
if (g_state & PAD_CTL_IBE_ENABLE)
return GPIOF_INPUT;
if (!(g_state & PAD_CTL_OBE_IBE_ENABLE))
return GPIOF_UNUSED;
return GPIOF_UNKNOWN;
}
static const struct dm_gpio_ops gpio_vybrid_ops = {
.direction_input = vybrid_gpio_direction_input,
.direction_output = vybrid_gpio_direction_output,
.get_value = vybrid_gpio_get_value,
.set_value = vybrid_gpio_set_value,
.get_function = vybrid_gpio_get_function,
};
static int vybrid_gpio_probe(struct udevice *dev)
{
struct vybrid_gpios *gpios = dev_get_priv(dev);
struct vybrid_gpio_platdata *plat = dev_get_platdata(dev);
struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
uc_priv->bank_name = plat->port_name;
uc_priv->gpio_count = VYBRID_GPIO_COUNT;
gpios->reg = (struct vybrid_gpio_regs *)plat->base;
gpios->chip = plat->chip;
return 0;
}
static int vybrid_gpio_odata_to_platdata(struct udevice *dev)
{
struct vybrid_gpio_platdata *plat = dev_get_platdata(dev);
fdt_addr_t base_addr;
base_addr = devfdt_get_addr(dev);
if (base_addr == FDT_ADDR_T_NONE)
return -EINVAL;
plat->base = base_addr;
plat->chip = dev->req_seq;
plat->port_name = fdt_get_name(gd->fdt_blob, dev_of_offset(dev), NULL);
return 0;
}
static const struct udevice_id vybrid_gpio_ids[] = {
{ .compatible = "fsl,vf610-gpio" },
{ }
};
U_BOOT_DRIVER(gpio_vybrid) = {
.name = "gpio_vybrid",
.id = UCLASS_GPIO,
.ops = &gpio_vybrid_ops,
.of_match = vybrid_gpio_ids,
.ofdata_to_platdata = vybrid_gpio_odata_to_platdata,
.probe = vybrid_gpio_probe,
.priv_auto_alloc_size = sizeof(struct vybrid_gpios),
.platdata_auto_alloc_size = sizeof(struct vybrid_gpio_platdata),
};