From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dirk Behme Date: Fri, 13 Jan 2012 12:45:28 +0100 Subject: [U-Boot] [PATCH 1/2] SPI: Add i.MX ECSPI driver In-Reply-To: <4F100BFE.4060706@denx.de> References: <1326382034-31058-1-git-send-email-dirk.behme@de.bosch.com> <4F100BFE.4060706@denx.de> Message-ID: <4F101958.20106@de.bosch.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On 13.01.2012 11:48, Stefano Babic wrote: > On 12/01/2012 16:27, Dirk Behme wrote: >> From: Eric Nelson >> >> Signed-off-by: Eric Nelson >> CC: Jason Liu >> CC: Stefano Babic >> --- >> 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 >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> + >> +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