From: Sascha Hauer <s.hauer@pengutronix.de>
To: Antony Pavlov <antonynpavlov@gmail.com>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 2/5] sandbox: add gpio support with libftdi1
Date: Mon, 16 Oct 2017 09:56:51 +0200 [thread overview]
Message-ID: <20171016075651.xgcx7umvhf4cvg5k@pengutronix.de> (raw)
In-Reply-To: <20171010122631.9421-3-antonynpavlov@gmail.com>
Hi Antony,
On Tue, Oct 10, 2017 at 03:26:28PM +0300, Antony Pavlov wrote:
> Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
> ---
> arch/sandbox/Kconfig | 1 +
> arch/sandbox/Makefile | 6 +-
> arch/sandbox/mach-sandbox/include/mach/linux.h | 11 ++
> arch/sandbox/os/Makefile | 3 +
> arch/sandbox/os/ftdi.c | 173 +++++++++++++++++++++++++
> drivers/gpio/Kconfig | 4 +
> drivers/gpio/Makefile | 1 +
> drivers/gpio/gpio-libftdi1.c | 125 ++++++++++++++++++
> 8 files changed, 323 insertions(+), 1 deletion(-)
>
...
> +static struct ft2232_bitbang ftbb;
> +
...
> +
> +int barebox_libftdi1_init(void)
> +{
> + struct ftdi_context *ftdi;
> + int ret;
> + /* default FT2232 values */
> + uint16_t vendor_id = FTDI_VID;
> + uint16_t device_id = FTDI_8U2232C_PID;
> +
> + ftdi = ftdi_new();
> + if (!ftdi) {
> + fprintf(stderr, "ftdi_new failed\n");
> + goto error;
> + }
> +
> + ret = ftdi_usb_open(ftdi, vendor_id, device_id);
> + if (ret < 0 && ret != -5) {
> + fprintf(stderr, "unable to open ftdi device: %d (%s)\n",
> + ret, ftdi_get_error_string(ftdi));
> + goto error;
> + }
What does a return value of -5 mean? Isn't that an error?
> +
> + ftdi_set_interface(ftdi, INTERFACE_A);
> + ftdi_set_bitmode(ftdi, 0x00, BITMODE_MPSSE);
> +
> + ftbb.ftdi = ftdi;
> +
> + /* reset pins to default neutral state */
> + ftbb.dir = 0;
> + ftbb.odata = 0;
> + ftdi_set_high_byte_data_dir(&ftbb);
> +
> + return 0;
> +
> +error:
> + return -1;
> +}
> +
> +struct ft2232_bitbang *barebox_libftdi1_open(void)
> +{
> + if (barebox_libftdi1_init() < 0) {
> + printf("Could not initialize ftdi\n");
> + return NULL;
> + }
> +
> + return &ftbb;
> +}
Somethings fishy here. Do you want to create a new struct ft2232_bitbang
instance for each caller or do you want to return the same instance for
every call to barebox_libftdi1_open()? If you want to do the former you
shouldn't create a static struct ft2232_bitbang, but instead allocate it
dynamically. If you want to do the latter then you should do a "if
(initialized) return existing_instance".
> + 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;
Would be good to actually check 'ret' for errors.
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2017-10-16 7:57 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-10 12:26 [PATCH 0/5] " Antony Pavlov
2017-10-10 12:26 ` [PATCH 1/5] sandbox: avoid symbol conflict for {open,read,close}dir Antony Pavlov
2017-10-10 12:26 ` [PATCH 2/5] sandbox: add gpio support with libftdi1 Antony Pavlov
2017-10-16 7:56 ` Sascha Hauer [this message]
2017-10-10 12:26 ` [PATCH 3/5] sandbox: parse libftdi options Antony Pavlov
2017-10-16 8:21 ` Sascha Hauer
2017-10-16 14:10 ` Antony Pavlov
2017-10-16 14:06 ` Sascha Hauer
2017-10-19 11:55 ` Antony Pavlov
2017-10-19 11:52 ` Sascha Hauer
2017-10-10 12:26 ` [PATCH 4/5] sandbox_defconfig: enable gpio, spi, i2c and led stuff Antony Pavlov
2017-10-10 12:26 ` [PATCH 5/5] sandbox: dts: add i2c and spi libftdi1 bit-bang example Antony Pavlov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171016075651.xgcx7umvhf4cvg5k@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=antonynpavlov@gmail.com \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox