[U-Boot] [EXT] Re: [PATCH v4 2/5] dm: spi: Convert Freescale ESPI driver to driver model
Jagan Teki
jagan at amarulasolutions.com
Wed Aug 14 18:02:44 UTC 2019
On Wed, Aug 14, 2019 at 3:31 PM Chuanhua Han <chuanhua.han at nxp.com> wrote:
>
>
>
> > -----Original Message-----
> > From: Jagan Teki <jagan at amarulasolutions.com>
> > Sent: 2019年8月14日 15:38
> > To: Chuanhua Han <chuanhua.han at nxp.com>
> > Cc: Wolfgang Denk <wd at denx.de>; Shengzhou Liu <shengzhou.liu at nxp.com>;
> > Ruchika Gupta <ruchika.gupta at nxp.com>; Jagan Teki <jagan at openedev.com>;
> > Simon Glass <sjg at chromium.org>; Prabhakar Kushwaha
> > <prabhakar.kushwaha at nxp.com>; U-Boot-Denx <u-boot at lists.denx.de>
> > Subject: [EXT] Re: [U-Boot] [PATCH v4 2/5] dm: spi: Convert Freescale ESPI
> > driver to driver model
> >
> > Caution: EXT Email
> >
> > On Fri, Jun 21, 2019 at 7:52 AM Chuanhua Han <chuanhua.han at nxp.com>
> > wrote:
> > >
> > > Modify the Freescale ESPI driver to support the driver model.
> > > Also resolved the following problems:
> > >
> > > ===================== WARNING ====================== This board
> > does
> > > not use CONFIG_DM_SPI. Please update the board before v2019.04 for no
> > > dm conversion and v2019.07 for partially dm converted drivers.
> > > Failure to update can lead to driver/board removal See
> > > doc/driver-model/MIGRATION.txt for more info.
> > > ====================================================
> > > ===================== WARNING ====================== This board
> > does
> > > not use CONFIG_DM_SPI_FLASH. Please update the board to use
> > > CONFIG_SPI_FLASH before the v2019.07 release.
> > > Failure to update by the deadline may result in board removal.
> > > See doc/driver-model/MIGRATION.txt for more info.
> > > ====================================================
> > >
> > > Signed-off-by: Chuanhua Han <chuanhua.han at nxp.com>
> > > ---
> > > Changes in v4:
> > > - Update copyright information.
> > > - Move the fsl_espi_platdata data structure to the
> > > include/dm/platform_data/.
> > > - Merge the contents of the fsl_espi_priv structure into the
> > > fsl_spi_slave structure.
> > > - Implement the fsl_espi_set_speed function.
> > > - Implement the fsl_espi_set_mode function.
> > > - Implement the espi_release_bus function.
> > > - Remove unwanted fsl_espi_bind functions.
> > > - Implement the fsl_espi_child_pre_probe function as needed.
> > > - Use #if CONFIG_IS_ENABLED(OF_CONTROL)
> > && !CONFIG_IS_ENABLED(OF_PLATDATA).
> > > Changes in v3:
> > > - Add a cover-letter for this patch set.
> > > Changes in v2:
> > > - The fsl_espi driver support both OF_CONTROL and PLATDATA.
> > >
> > > drivers/spi/fsl_espi.c | 444 ++++++++++++++++++++--------
> > > include/dm/platform_data/fsl_espi.h | 16 +
> > > 2 files changed, 339 insertions(+), 121 deletions(-) create mode
> > > 100644 include/dm/platform_data/fsl_espi.h
> > >
> > > diff --git a/drivers/spi/fsl_espi.c b/drivers/spi/fsl_espi.c index
> > > 7444ae1a06..849f65f0e6 100644
> > > --- a/drivers/spi/fsl_espi.c
> > > +++ b/drivers/spi/fsl_espi.c
> > > @@ -3,18 +3,25 @@
> > > * eSPI controller driver.
> > > *
> > > * Copyright 2010-2011 Freescale Semiconductor, Inc.
> > > + * Copyright 2019 NXP
> > > * Author: Mingkai Hu (Mingkai.hu at freescale.com)
> > > + * Chuanhua Han (chuanhua.han at nxp.com)
> > > */
> > >
> > > #include <common.h>
> > > -
> > > #include <malloc.h>
> > > #include <spi.h>
> > > #include <asm/immap_85xx.h>
> > > +#include <dm.h>
> > > +#include <errno.h>
> > > +#include <fdtdec.h>
> > > +#include <dm/platform_data/fsl_espi.h>
> > >
> > > struct fsl_spi_slave {
> > > struct spi_slave slave;
> > > ccsr_espi_t *espi;
> > > + u32 speed_hz;
> > > + unsigned int cs;
> > > unsigned int div16;
> > > unsigned int pm;
> > > int tx_timeout;
> > > @@ -28,6 +35,9 @@ struct fsl_spi_slave { #define to_fsl_spi_slave(s)
> > > container_of(s, struct fsl_spi_slave, slave)
> > > #define US_PER_SECOND 1000000UL
> > >
> > > +/* default SCK frequency, unit: HZ */
> > > +#define FSL_ESPI_DEFAULT_SCK_FREQ 10000000
> > > +
> > > #define ESPI_MAX_CS_NUM 4
> > > #define ESPI_FIFO_WIDTH_BIT 32
> > >
> > > @@ -62,116 +72,32 @@ struct fsl_spi_slave {
> > >
> > > #define ESPI_MAX_DATA_TRANSFER_LEN 0xFFF0
> > >
> > > -struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
> > > - unsigned int max_hz, unsigned int mode)
> > > -{
> > > - struct fsl_spi_slave *fsl;
> > > - sys_info_t sysinfo;
> > > - unsigned long spibrg = 0;
> > > - unsigned long spi_freq = 0;
> > > - unsigned char pm = 0;
> > > -
> > > - if (!spi_cs_is_valid(bus, cs))
> > > - return NULL;
> > > -
> > > - fsl = spi_alloc_slave(struct fsl_spi_slave, bus, cs);
> > > - if (!fsl)
> > > - return NULL;
> > > -
> > > - fsl->espi = (void *)(CONFIG_SYS_MPC85xx_ESPI_ADDR);
> > > - fsl->mode = mode;
> > > - fsl->max_transfer_length = ESPI_MAX_DATA_TRANSFER_LEN;
> > > -
> > > - /* Set eSPI BRG clock source */
> > > - get_sys_info(&sysinfo);
> > > - spibrg = sysinfo.freq_systembus / 2;
> > > - fsl->div16 = 0;
> > > - if ((spibrg / max_hz) > 32) {
> > > - fsl->div16 = ESPI_CSMODE_DIV16;
> > > - pm = spibrg / (max_hz * 16 * 2);
> > > - if (pm > 16) {
> > > - pm = 16;
> > > - debug("Requested speed is too low: %d Hz, %ld
> > Hz "
> > > - "is used.\n", max_hz, spibrg / (32 * 16));
> > > - }
> > > - } else
> > > - pm = spibrg / (max_hz * 2);
> > > - if (pm)
> > > - pm--;
> > > - fsl->pm = pm;
> > > -
> > > - if (fsl->div16)
> > > - spi_freq = spibrg / ((pm + 1) * 2 * 16);
> > > - else
> > > - spi_freq = spibrg / ((pm + 1) * 2);
> > > -
> > > - /* set tx_timeout to 10 times of one espi FIFO entry go out */
> > > - fsl->tx_timeout = DIV_ROUND_UP((US_PER_SECOND *
> > ESPI_FIFO_WIDTH_BIT
> > > - * 10), spi_freq);
> > > -
> > > - return &fsl->slave;
> > > -}
> > > -
> > > -void spi_free_slave(struct spi_slave *slave)
> > > +void spi_cs_activate(struct spi_slave *slave)
> > > {
> > > struct fsl_spi_slave *fsl = to_fsl_spi_slave(slave);
> > > - free(fsl);
> > > + ccsr_espi_t *espi = fsl->espi;
> > > + unsigned int com = 0;
> > > + size_t data_len = fsl->data_len;
> > > + uint cs;
> > > +#ifndef CONFIG_DM_SPI
> > > + cs = slave->cs;
> > > +#else
> > > + cs = fsl->cs;
> > > +#endif
> >
> > Preserve cs in private struct and resuse it w/o this ifdef.
> What does that mean? Private data, do you mean struct spi_slave? What does w/o mean?
Add cs variable in struct and assign it in dm and non-dm codes.
More information about the U-Boot
mailing list