From: Dirk Behme <dirk.behme@de.bosch.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 1/2] SPI: Add i.MX ECSPI driver
Date: Fri, 13 Jan 2012 12:45:28 +0100 [thread overview]
Message-ID: <4F101958.20106@de.bosch.com> (raw)
In-Reply-To: <4F100BFE.4060706@denx.de>
On 13.01.2012 11:48, Stefano Babic wrote:
> On 12/01/2012 16:27, Dirk Behme wrote:
>> From: Eric Nelson <eric.nelson@boundarydevices.com>
>>
>> Signed-off-by: Eric Nelson <eric.nelson@boundarydevices.com>
>> CC: Jason Liu <jason.hui@linaro.org>
>> CC: Stefano Babic <sbabic@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
next prev parent reply other threads:[~2012-01-13 11:45 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-12 15:27 [U-Boot] [PATCH 1/2] SPI: Add i.MX ECSPI driver Dirk Behme
2012-01-12 15:27 ` [U-Boot] [PATCH 2/2] i.mx6q: SabreLite: Add SPI NOR support Dirk Behme
2012-01-12 15:32 ` Fabio Estevam
2012-01-12 15:38 ` Marek Vasut
2012-01-12 15:48 ` Fabio Estevam
2012-01-13 7:19 ` Dirk Behme
2012-01-15 1:05 ` Mike Frysinger
2012-01-15 1:04 ` Mike Frysinger
2012-01-12 15:37 ` [U-Boot] [PATCH 1/2] SPI: Add i.MX ECSPI driver Marek Vasut
2012-01-13 7:32 ` Dirk Behme
2012-01-13 12:17 ` Marek Vasut
2012-01-12 15:40 ` Fabio Estevam
2012-01-13 10:48 ` Stefano Babic
2012-01-13 11:45 ` Dirk Behme [this message]
2012-01-16 17:29 ` Eric Nelson
2012-01-16 17:38 ` Stefano Babic
2012-01-15 1:04 ` Mike Frysinger
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=4F101958.20106@de.bosch.com \
--to=dirk.behme@de.bosch.com \
--cc=u-boot@lists.denx.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.