diff mbox series

[U-Boot,v3,085/108] spi: ich: Add support for get_mmap() method

Message ID 20191021033913.220758-80-sjg@chromium.org
State Superseded
Delegated to: Bin Meng
Headers show
Series x86: Add initial support for apollolake | expand

Commit Message

Simon Glass Oct. 21, 2019, 3:38 a.m. UTC
Add this method so that the memory-mapped location of the SPI flash can
be queried.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v3: None
Changes in v2: None

 drivers/spi/ich.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

Comments

Bin Meng Nov. 19, 2019, 2:36 p.m. UTC | #1
Hi Simon,

On Mon, Oct 21, 2019 at 11:40 AM Simon Glass <sjg@chromium.org> wrote:
>
> Add this method so that the memory-mapped location of the SPI flash can
> be queried.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
> Changes in v3: None
> Changes in v2: None
>
>  drivers/spi/ich.c | 32 ++++++++++++++++++++++++++++++++
>  1 file changed, 32 insertions(+)
>
> diff --git a/drivers/spi/ich.c b/drivers/spi/ich.c
> index ae1dc64bde8..ec0f77f6e40 100644
> --- a/drivers/spi/ich.c
> +++ b/drivers/spi/ich.c
> @@ -610,6 +610,37 @@ static int ich_spi_exec_op(struct spi_slave *slave, const struct spi_mem_op *op)
>         return ret;
>  }
>
> +static int ich_get_mmap_bus(struct udevice *bus, ulong *map_basep,
> +                           uint *map_sizep, uint *offsetp)
> +{
> +       pci_dev_t spi_bdf;
> +
> +#if !CONFIG_IS_ENABLED(OF_PLATDATA)
> +       struct pci_child_platdata *pplat = dev_get_parent_platdata(bus);
> +
> +       spi_bdf = pplat->devfn;
> +#else
> +       struct ich_spi_platdata *plat = dev_get_platdata(bus);
> +
> +       /*
> +        * We cannot rely on plat->bdf being set up yet since this method can
> +        * be called before the device is probed. Use the of-platdata directly
> +        * instead.
> +        */
> +       spi_bdf = pci_x86_ofplat_get_devfn(plat->dtplat.reg[0]);
> +#endif
> +
> +       return fast_spi_get_bios_mmap(spi_bdf, map_basep, map_sizep, offsetp);

I think we should move fast_spi_get_bios_mmap() to this driver,
instead of having the ICH driver depend on something external.

> +}
> +
> +static int ich_get_mmap(struct udevice *dev, ulong *map_basep, uint *map_sizep,
> +                       uint *offsetp)
> +{
> +       struct udevice *bus = dev_get_parent(dev);
> +
> +       return ich_get_mmap_bus(bus, map_basep, map_sizep, offsetp);
> +}
> +
>  static int ich_spi_adjust_size(struct spi_slave *slave, struct spi_mem_op *op)
>  {
>         unsigned int page_offset;
> @@ -826,6 +857,7 @@ static const struct dm_spi_ops ich_spi_ops = {
>         .set_speed      = ich_spi_set_speed,
>         .set_mode       = ich_spi_set_mode,
>         .mem_ops        = &ich_controller_mem_ops,
> +       .get_mmap       = ich_get_mmap,
>         /*
>          * cs_info is not needed, since we require all chip selects to be
>          * in the device tree explicitly
> --

Regards,
Bin
Simon Glass Nov. 21, 2019, 1:50 p.m. UTC | #2
Hi BIn,

On Tue, 19 Nov 2019 at 07:37, Bin Meng <bmeng.cn@gmail.com> wrote:
>
> Hi Simon,
>
> On Mon, Oct 21, 2019 at 11:40 AM Simon Glass <sjg@chromium.org> wrote:
> >
> > Add this method so that the memory-mapped location of the SPI flash can
> > be queried.
> >
> > Signed-off-by: Simon Glass <sjg@chromium.org>
> > ---
> >
> > Changes in v3: None
> > Changes in v2: None
> >
> >  drivers/spi/ich.c | 32 ++++++++++++++++++++++++++++++++
> >  1 file changed, 32 insertions(+)
> >
> > diff --git a/drivers/spi/ich.c b/drivers/spi/ich.c
> > index ae1dc64bde8..ec0f77f6e40 100644
> > --- a/drivers/spi/ich.c
> > +++ b/drivers/spi/ich.c
> > @@ -610,6 +610,37 @@ static int ich_spi_exec_op(struct spi_slave *slave, const struct spi_mem_op *op)
> >         return ret;
> >  }
> >
> > +static int ich_get_mmap_bus(struct udevice *bus, ulong *map_basep,
> > +                           uint *map_sizep, uint *offsetp)
> > +{
> > +       pci_dev_t spi_bdf;
> > +
> > +#if !CONFIG_IS_ENABLED(OF_PLATDATA)
> > +       struct pci_child_platdata *pplat = dev_get_parent_platdata(bus);
> > +
> > +       spi_bdf = pplat->devfn;
> > +#else
> > +       struct ich_spi_platdata *plat = dev_get_platdata(bus);
> > +
> > +       /*
> > +        * We cannot rely on plat->bdf being set up yet since this method can
> > +        * be called before the device is probed. Use the of-platdata directly
> > +        * instead.
> > +        */
> > +       spi_bdf = pci_x86_ofplat_get_devfn(plat->dtplat.reg[0]);
> > +#endif
> > +
> > +       return fast_spi_get_bios_mmap(spi_bdf, map_basep, map_sizep, offsetp);
>
> I think we should move fast_spi_get_bios_mmap() to this driver,
> instead of having the ICH driver depend on something external.

The problem is that this function is needed in APL's cpu_spl.c to
cache the BIOS region.and also by rom_load_image() to read from the
mapped SPI flash.

This driver is in fact not normally included in TPL, since it is quite
large and not needed.

So we have to call these functions from outside the driver and
therefore it is best to have them in the arch-specific code.

It is in intel_common so is shared.

Regards,
Simon
diff mbox series

Patch

diff --git a/drivers/spi/ich.c b/drivers/spi/ich.c
index ae1dc64bde8..ec0f77f6e40 100644
--- a/drivers/spi/ich.c
+++ b/drivers/spi/ich.c
@@ -610,6 +610,37 @@  static int ich_spi_exec_op(struct spi_slave *slave, const struct spi_mem_op *op)
 	return ret;
 }
 
+static int ich_get_mmap_bus(struct udevice *bus, ulong *map_basep,
+			    uint *map_sizep, uint *offsetp)
+{
+	pci_dev_t spi_bdf;
+
+#if !CONFIG_IS_ENABLED(OF_PLATDATA)
+	struct pci_child_platdata *pplat = dev_get_parent_platdata(bus);
+
+	spi_bdf = pplat->devfn;
+#else
+	struct ich_spi_platdata *plat = dev_get_platdata(bus);
+
+	/*
+	 * We cannot rely on plat->bdf being set up yet since this method can
+	 * be called before the device is probed. Use the of-platdata directly
+	 * instead.
+	 */
+	spi_bdf = pci_x86_ofplat_get_devfn(plat->dtplat.reg[0]);
+#endif
+
+	return fast_spi_get_bios_mmap(spi_bdf, map_basep, map_sizep, offsetp);
+}
+
+static int ich_get_mmap(struct udevice *dev, ulong *map_basep, uint *map_sizep,
+			uint *offsetp)
+{
+	struct udevice *bus = dev_get_parent(dev);
+
+	return ich_get_mmap_bus(bus, map_basep, map_sizep, offsetp);
+}
+
 static int ich_spi_adjust_size(struct spi_slave *slave, struct spi_mem_op *op)
 {
 	unsigned int page_offset;
@@ -826,6 +857,7 @@  static const struct dm_spi_ops ich_spi_ops = {
 	.set_speed	= ich_spi_set_speed,
 	.set_mode	= ich_spi_set_mode,
 	.mem_ops	= &ich_controller_mem_ops,
+	.get_mmap	= ich_get_mmap,
 	/*
 	 * cs_info is not needed, since we require all chip selects to be
 	 * in the device tree explicitly