[U-Boot] [PATCH 1/2] SPI: Add i.MX ECSPI driver

Dirk Behme dirk.behme at de.bosch.com
Fri Jan 13 12:45:28 CET 2012


On 13.01.2012 11:48, Stefano Babic wrote:
> On 12/01/2012 16:27, Dirk Behme wrote:
>> From: Eric Nelson <eric.nelson at boundarydevices.com>
>>
>> Signed-off-by: Eric Nelson <eric.nelson at boundarydevices.com>
>> CC: Jason Liu <jason.hui at linaro.org>
>> CC: Stefano Babic <sbabic at denx.de>
>> ---
>>  drivers/spi/Makefile    |    1 +
>>  drivers/spi/imx_ecspi.c |  334 +++++++++++++++++++++++++++++++++++++++++++++++
>>  include/imx_spi.h       |   97 ++++++++++++++
>>  3 files changed, 432 insertions(+), 0 deletions(-)
>>  create mode 100644 drivers/spi/imx_ecspi.c
>>  create mode 100644 include/imx_spi.h
>>
> 
> Hi Dirk,
> 
> before digging too deep inside the driver: I do not see any apoparent
> reason why we must add a separate driver instead of adapting what we
> currently have. And most part are quite identical to
> drivers/spi/mxc_spi.c. We should change mxc_spi.c for the imx6 relevant
> parts, instead of adding a new copy.
> 
>> new file mode 100644
>> index 0000000..1468208
>> --- /dev/null
>> +++ b/drivers/spi/imx_ecspi.c
>> @@ -0,0 +1,334 @@
>> +/*
>> + * (C) Copyright 2008-2010 Freescale Semiconductor, Inc.
>> + *
>> + * 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
>> + */
>> +
>> +#include <config.h>
>> +#include <common.h>
>> +#include <spi.h>
>> +#include <asm/errno.h>
>> +#include <linux/types.h>
>> +#include <asm/io.h>
>> +#include <malloc.h>
>> +#include <asm/arch/clock.h>
>> +#include <imx_spi.h>
>> +
>> +static inline struct imx_spi_dev_t *to_imx_spi_slave(struct spi_slave *slave)
>> +{
>> +	return container_of(slave, struct imx_spi_dev_t, slave);
>> +}
>> +
>> +static s32 spi_reset(struct spi_slave *slave)
>> +{
>> +	u32 clk_src = mxc_get_clock(MXC_CSPI_CLK);
>> +	u32 pre_div = 0, post_div = 0, reg_ctrl, reg_config;
>> +	struct imx_spi_dev_t *dev = to_imx_spi_slave(slave);
>> +	struct spi_reg_t *reg = &(dev->reg);
>> +
>> +	if (dev->freq == 0) {
>> +		printf("Error: desired clock is 0\n");
>> +		return 1;
>> +	}
>> +
>> +	reg_ctrl = readl(dev->base + SPI_CON_REG);
>> +	reg_config = readl(dev->base + SPI_CFG_REG);
>> +	/* Reset spi */
> 
> The functiion reassembles spi_cfg_mxc in mxc_spi.c, usinf fixed offset
> instead of structures.
> 
>> +/*
>> + * SPI xchg
>> + */
>> +
>> +int spi_xchg_single(struct spi_slave *slave, unsigned int bitlen,
>> +	const u8 *dout, u8 *din, unsigned long flags)
>> +{
>> +	int nbytes = (bitlen + 7) / 8;
>> +	struct imx_spi_dev_t *dev = to_imx_spi_slave(slave);
>> +	struct spi_reg_t *spi_reg = &(dev->reg);
>> +	u32 loop_cnt ;
>> +	if (!slave)
>> +		return -1;
>> +
>> +	if (spi_reg->ctrl_reg == 0) {
>> +		printf("Error: spi(base=0x%x) has not been initialized yet\n",
>> +				dev->base);
>> +		return -1;
>> +	}
>> +	spi_reg->ctrl_reg = (spi_reg->ctrl_reg & ~0xFFF00000) | \
>> +			((bitlen - 1) << 20);
>> +
>> +	writel(spi_reg->ctrl_reg, dev->base + SPI_CON_REG);
>> +	writel(spi_reg->cfg_reg, dev->base + SPI_CFG_REG);
>> +
>> +	/* move data to the tx fifo */
>> +	debug("dout=0x%p, bitlen=%x\n", dout, bitlen);
>> +
>> +	/*
>> +	 * The SPI controller works only with words,
>> +	 * check if less than a word is sent.
>> +	 * Access to the FIFO is only 32 bit
>> +	 */
>> +	if (bitlen % 32) {
>> +		u32 data = 0;
> 
> I see no specific i.MX6 code here, and the function is not very
> different as spi_xchg_single(). Really I do not think we can add a copy
> of the already provided driver, sorry.

Yes, understood, see

http://lists.denx.de/pipermail/u-boot/2012-January/115611.html

Let's have Eric a look to this.

Anyway, many thanks for looking at it,

Dirk


More information about the U-Boot mailing list