[U-Boot] [PATCH v3 3/7] cros: add SPI support for cros_ec
Simon Glass
sjg at chromium.org
Sat Mar 30 22:08:39 CET 2013
Hi Hung-ying,
On Thu, Mar 28, 2013 at 12:45 AM, Hung-ying Tyan <tyanh at chromium.org> wrote:
> This patch adds SPI support for carrying out the cros_ec protocol.
>
> Signed-off-by: Hung-ying Tyan <tyanh at chromium.org>
> Signed-off-by: Randall Spangler <rspangler at chromium.org>
> Signed-off-by: Simon Glass <sjg at chromium.org>
>
> ---
> Changes in v3: None
> Changes in v2:
> - Fixed warnings of exceeding 80 chars in a line.
> - Added commit message.
> - Dropped the period from commit subject.
>
> drivers/misc/Makefile | 1 +
> drivers/misc/cros_ec_spi.c | 166
> +++++++++++++++++++++++++++++++++++++++++++++
> drivers/spi/exynos_spi.c | 22 ++++++
> include/spi.h | 16 +++++
> 4 files changed, 205 insertions(+)
> create mode 100644 drivers/misc/cros_ec_spi.c
>
> diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
> index 9363ef9..18209ec 100644
> --- a/drivers/misc/Makefile
> +++ b/drivers/misc/Makefile
> @@ -32,6 +32,7 @@ COBJS-$(CONFIG_GPIO_LED) += gpio_led.o
> COBJS-$(CONFIG_FSL_MC9SDZ60) += mc9sdz60.o
> COBJS-$(CONFIG_CROS_EC) += cros_ec.o
> COBJS-$(CONFIG_CROS_EC_I2C) += cros_ec_i2c.o
> +COBJS-$(CONFIG_CROS_EC_SPI) += cros_ec_spi.o
> COBJS-$(CONFIG_NS87308) += ns87308.o
> COBJS-$(CONFIG_PDSP188x) += pdsp188x.o
> COBJS-$(CONFIG_STATUS_LED) += status_led.o
> diff --git a/drivers/misc/cros_ec_spi.c b/drivers/misc/cros_ec_spi.c
> new file mode 100644
> index 0000000..82cc1bb
> --- /dev/null
> +++ b/drivers/misc/cros_ec_spi.c
> @@ -0,0 +1,166 @@
> +/*
> + * Chromium OS cros_ec driver - SPI interface
> + *
> + * Copyright (c) 2012 The Chromium OS Authors.
> + * 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 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.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
> + * MA 02111-1307 USA
> + */
> +
> +/*
> + * The Matrix Keyboard Protocol driver handles talking to the keyboard
> + * controller chip. Mostly this is for keyboard functions, but some other
> + * things have slipped in, so we provide generic services to talk to the
> + * KBC.
> + */
> +
> +#include <common.h>
> +#include <cros_ec.h>
> +#include <spi.h>
> +
> +#ifdef CONFIG_NEW_SPI_XFER
> +#error "CONFIG_NEW_SPI_XFER not supported in CROS_EC"
> +#endif
>
This is an artifact of old code and can be removed.
> +
> +/**
> + * Send a command to a LPC CROS_EC device and return the reply.
> + *
> + * The device's internal input/output buffers are used.
> + *
> + * @param dev CROS_EC device
> + * @param cmd Command to send (EC_CMD_...)
> + * @param cmd_version Version of command to send (EC_VER_...)
> + * @param dout Output data (may be NULL If dout_len=0)
> + * @param dout_len Size of output data in bytes
> + * @param dinp Returns pointer to response data. This will be
> + * untouched unless we return a value > 0.
> + * @param din_len Maximum size of response in bytes
> + * @return number of bytes in response, or -1 on error
> + */
> +int cros_ec_spi_command(struct cros_ec_dev *dev, uint8_t cmd, int
> cmd_version,
> + const uint8_t *dout, int dout_len,
> + uint8_t **dinp, int din_len)
> +{
> + int in_bytes = din_len + 4; /* status, length, checksum,
> trailer */
> + uint8_t *out;
> + uint8_t *p;
> + int csum, len;
> + int rv;
> +
> + /*
> + * Sanity-check input size to make sure it plus transaction
> overhead
> + * fits in the internal device buffer.
> + */
> + if (in_bytes > sizeof(dev->din)) {
> + debug("%s: Cannot receive %d bytes\n", __func__, din_len);
> + return -1;
> + }
> +
> + /* We represent message length as a byte */
> + if (dout_len > 0xff) {
> + debug("%s: Cannot send %d bytes\n", __func__, dout_len);
> + return -1;
> + }
> +
> + /*
> + * TODO(sjg at chromium.org): Clear input buffer so we don't get
> false
> + * hits for MSG_HEADER
>
You can keep the comment but remove the TODO(...)
> + */
> + memset(dev->din, '\0', in_bytes);
> +
>
Regards,
Simon
More information about the U-Boot
mailing list