diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2018-02-08 09:04:21 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2018-02-08 09:04:21 +0100 |
commit | 6f826bfe45298721a92bbe93d32a6a0eb76d46ee (patch) | |
tree | 167158fd037c76aff6a5ff76862aab9996521c97 /drivers | |
parent | a830047442883e130b39b620168c16e0495420db (diff) | |
parent | 643ea6eb95dce1818cc10e6def4d97597d8912d9 (diff) | |
download | barebox-6f826bfe45298721a92bbe93d32a6a0eb76d46ee.tar.gz barebox-6f826bfe45298721a92bbe93d32a6a0eb76d46ee.tar.xz |
Merge branch 'for-next/sandbox-libftdi'
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/gpio/Kconfig | 4 | ||||
-rw-r--r-- | drivers/gpio/Makefile | 1 | ||||
-rw-r--r-- | drivers/gpio/gpio-libftdi1.c | 137 |
3 files changed, 142 insertions, 0 deletions
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index 434c5688b4..ed93e868ae 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -132,6 +132,10 @@ config GPIO_SX150X Say Y here to build support for the Semtec Sx150x I2C GPIO expander chip. +config GPIO_LIBFTDI1 + bool "libftdi1 driver" + depends on SANDBOX + endmenu endif diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile index f37dd08f1a..f5ed876d5e 100644 --- a/drivers/gpio/Makefile +++ b/drivers/gpio/Makefile @@ -8,6 +8,7 @@ obj-$(CONFIG_GPIO_CLPS711X) += gpio-clps711x.o obj-$(CONFIG_GPIO_DIGIC) += gpio-digic.o obj-$(CONFIG_GPIO_GENERIC) += gpio-generic.o obj-$(CONFIG_GPIO_IMX) += gpio-imx.o +obj-$(CONFIG_GPIO_LIBFTDI1) += gpio-libftdi1.o obj-$(CONFIG_GPIO_MXS) += gpio-mxs.o obj-$(CONFIG_GPIO_JZ4740) += gpio-jz4740.o obj-$(CONFIG_GPIO_MALTA_FPGA_I2C) += gpio-malta-fpga-i2c.o diff --git a/drivers/gpio/gpio-libftdi1.c b/drivers/gpio/gpio-libftdi1.c new file mode 100644 index 0000000000..cd36b08ca6 --- /dev/null +++ b/drivers/gpio/gpio-libftdi1.c @@ -0,0 +1,137 @@ +/* + * libftdi1 sandbox barebox GPIO driver + * + * Copyright (C) 2016, 2017 Antony Pavlov <antonynpavlov@gmail.com> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#include <common.h> +#include <errno.h> +#include <gpio.h> +#include <init.h> +#include <malloc.h> +#include <mach/linux.h> + +struct libftdi1_gpio_chip { + struct gpio_chip chip; + struct ft2232_bitbang *ftbb; +}; + +static int libftdi1_gpio_direction_input(struct gpio_chip *chip, unsigned off) +{ + struct libftdi1_gpio_chip *gpio = + container_of(chip, struct libftdi1_gpio_chip, chip); + + barebox_libftdi1_gpio_direction(gpio->ftbb, off, GPIOF_DIR_IN); + barebox_libftdi1_update(gpio->ftbb); + + return 0; +} + +static int libftdi1_gpio_direction_output( + struct gpio_chip *chip, unsigned off, int value) +{ + struct libftdi1_gpio_chip *gpio = + container_of(chip, struct libftdi1_gpio_chip, chip); + + barebox_libftdi1_gpio_set_value(gpio->ftbb, off, value); + barebox_libftdi1_gpio_direction(gpio->ftbb, off, GPIOF_DIR_OUT); + barebox_libftdi1_update(gpio->ftbb); + + return 0; +} + +static int libftdi1_gpio_get_value(struct gpio_chip *chip, unsigned off) +{ + struct libftdi1_gpio_chip *gpio = + container_of(chip, struct libftdi1_gpio_chip, chip); + + return barebox_libftdi1_gpio_get_value(gpio->ftbb, off); +} + +static void libftdi1_gpio_set_value( + struct gpio_chip *chip, unsigned off, int value) +{ + struct libftdi1_gpio_chip *gpio = + container_of(chip, struct libftdi1_gpio_chip, chip); + + barebox_libftdi1_gpio_set_value(gpio->ftbb, off, value); + barebox_libftdi1_update(gpio->ftbb); +} + +static struct gpio_ops libftdi1_gpio_ops = { + .direction_input = libftdi1_gpio_direction_input, + .direction_output = libftdi1_gpio_direction_output, + .get = libftdi1_gpio_get_value, + .set = libftdi1_gpio_set_value, +}; + +static int libftdi1_gpio_probe(struct device_d *dev) +{ + struct libftdi1_gpio_chip *gpio; + struct ft2232_bitbang *ftbb; + int ret; + uint32_t id_vendor, id_product; + const char *i_serial_number = NULL; + + of_property_read_u32(dev->device_node, "usb,id_vendor", + &id_vendor); + + of_property_read_u32(dev->device_node, "usb,id_product", + &id_product); + + of_property_read_string(dev->device_node, "usb,i_serial_number", + &i_serial_number); + + ftbb = barebox_libftdi1_open(id_vendor, id_product, + i_serial_number); + if (!ftbb) + return -EIO; + + gpio = xzalloc(sizeof(*gpio)); + + gpio->ftbb = ftbb; + + gpio->chip.dev = dev; + gpio->chip.ops = &libftdi1_gpio_ops; + gpio->chip.base = 0; + gpio->chip.ngpio = 8; + + ret = gpiochip_add(&gpio->chip); + + dev_dbg(dev, "%d: probed gpio%d with base %d\n", + ret, dev->id, gpio->chip.base); + + return 0; +} + +static __maybe_unused const struct of_device_id libftdi1_gpio_dt_ids[] = { + { + .compatible = "barebox,libftdi1-gpio", + }, { + /* sentinel */ + }, +}; + +static void libftdi1_gpio_remove(struct device_d *dev) +{ + barebox_libftdi1_close(); +} + +static struct driver_d libftdi1_gpio_driver = { + .name = "libftdi1-gpio", + .probe = libftdi1_gpio_probe, + .remove = libftdi1_gpio_remove, + .of_compatible = DRV_OF_COMPAT(libftdi1_gpio_dt_ids), +}; +device_platform_driver(libftdi1_gpio_driver); |