mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Aleksander Morgado <aleksander@aleksander.es>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 1/4] ratp: implement i2c read/write support
Date: Wed, 22 Aug 2018 09:46:35 +0200	[thread overview]
Message-ID: <20180822074635.wfst65srfuqne7l6@pengutronix.de> (raw)
In-Reply-To: <20180821152001.5747-2-aleksander@aleksander.es>

On Tue, Aug 21, 2018 at 05:19:58PM +0200, Aleksander Morgado wrote:
> Introduce two new RATP commands that allow running i2c read/write
> operations, very similar in format to the already existing md/mw
> RATP commands.
> 
> The messages are defined with a fixed 16-bit long register field, but
> it will only be treated as a 16-bit address if I2C_FLAG_WIDE_ADDRESS
> is set in the message flags field. If this flag is unset, the start
> register address is assumed 8-bit long.
> 
> If the message includes the I2C_FLAG_MASTER_MODE flag, the start
> register field is ignored and a i2c master send/receive operation is
> performed.
> 
> Signed-off-by: Aleksander Morgado <aleksander@aleksander.es>
> ---
>  common/ratp/Makefile |   1 +
>  common/ratp/i2c.c    | 281 +++++++++++++++++++++++++++++++++++++++++++
>  include/ratp_bb.h    |   4 +
>  3 files changed, 286 insertions(+)
>  create mode 100644 common/ratp/i2c.c
> 
> diff --git a/common/ratp/Makefile b/common/ratp/Makefile
> index 2c6d674f6..0234b55c1 100644
> --- a/common/ratp/Makefile
> +++ b/common/ratp/Makefile
> @@ -4,3 +4,4 @@ obj-y += getenv.o
>  obj-y += md.o
>  obj-y += mw.o
>  obj-y += reset.o
> +obj-y += i2c.o
> diff --git a/common/ratp/i2c.c b/common/ratp/i2c.c
> new file mode 100644
> index 000000000..b8d055b67
> --- /dev/null
> +++ b/common/ratp/i2c.c
> @@ -0,0 +1,281 @@
> +/*
> + * Copyright (c) 2011-2018 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
> + *
> + * See file CREDITS for list of people who contributed to this
> + * project.
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2
> + * as published by the Free Software Foundation.
> + *
> + * 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 <ratp_bb.h>
> +#include <init.h>
> +#include <driver.h>
> +#include <malloc.h>
> +#include <errno.h>
> +#include <i2c/i2c.h>
> +
> +/* NOTE:
> + *  - Fixed-size fields (e.g. integers) are given just after the header.
> + *  - Variable-length fields are stored inside the buffer[] and their position
> + *    within the buffer[] and their size are given as fixed-sized fields after
> + *    the header.
> + *  The message may be extended at any time keeping backwards compatibility,
> + *  as the position of the buffer[] is given by the buffer_offset field. i.e.
> + *  increasing the buffer_offset field we can extend the fixed-sized section
> + *  to add more fields.
> + */
> +
> +#define I2C_FLAG_WIDE_ADDRESS (1 << 0)
> +#define I2C_FLAG_MASTER_MODE  (1 << 1)
> +
> +struct ratp_bb_i2c_read_request {
> +	struct ratp_bb header;
> +	uint16_t buffer_offset;
> +	uint8_t  bus;
> +	uint8_t  addr;

I wonder how we see the RATP support. If it's for adhoc debugging then
bus/addr is fine. The caller should have no expectations that the bus
number is constant though. Likewise for the address which might change
across different board revisions.

Should we have support for resolving names, which could be provided by
aliases in dt?

We could still add name resolving support later as a separate call, I
just thought that now is the time to think how we proceed.

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

  parent reply	other threads:[~2018-08-22  7:46 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-21 15:19 RATP i2c and GPIO support Aleksander Morgado
2018-08-21 15:19 ` [PATCH 1/4] ratp: implement i2c read/write support Aleksander Morgado
2018-08-21 19:38   ` Andrey Smirnov
2018-09-12  9:25     ` Aleksander Morgado
2018-08-22  7:46   ` Sascha Hauer [this message]
2018-08-23 20:54     ` Aleksander Morgado
2018-08-27  9:09       ` Sascha Hauer
2018-08-21 15:19 ` [PATCH 2/4] bbremote: " Aleksander Morgado
2018-08-21 15:20 ` [PATCH 3/4] ratp: implement support for GPIO commands Aleksander Morgado
2018-08-21 20:18   ` Andrey Smirnov
2018-08-22  7:52   ` Sascha Hauer
2018-08-21 15:20 ` [PATCH 4/4] bbremote: implement support for GPIO operations Aleksander Morgado

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=20180822074635.wfst65srfuqne7l6@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=aleksander@aleksander.es \
    --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