RE: [PATCH 5/6] soc: aspeed: Add eSPI driver

2021-01-07 Thread Ryan Chen
> -Original Message-
> From: Joel Stanley 
> Sent: Friday, January 8, 2021 10:59 AM
> To: ChiaWei Wang ; Jeremy Kerr
> 
> Cc: Rob Herring ; and...@aj.id.au; t...@linutronix.de;
> m...@kernel.org; p.za...@pengutronix.de; linux-asp...@lists.ozlabs.org;
> open...@lists.ozlabs.org; devicet...@vger.kernel.org;
> linux-arm-ker...@lists.infradead.org; linux-kernel@vger.kernel.org; BMC-SW
> 
> Subject: Re: [PATCH 5/6] soc: aspeed: Add eSPI driver
> 
> On Thu, 7 Jan 2021 at 02:39, ChiaWei Wang
>  wrote:
> >
> > Hi Rob,
> >
> > > -Original Message-
> > > From: Rob Herring 
> > > Sent: Wednesday, January 6, 2021 11:32 PM
> > > To: ChiaWei Wang 
> > > Subject: Re: [PATCH 5/6] soc: aspeed: Add eSPI driver
> > >
> > > On Wed, Jan 06, 2021 at 01:59:38PM +0800, Chia-Wei, Wang wrote:
> > > > The Aspeed eSPI controller is slave device to communicate with the
> > > > master through the Enhanced Serial Peripheral Interface (eSPI).
> > > > All of the four eSPI channels, namely peripheral, virtual wire,
> > > > out-of-band, and flash are supported.
> > > >
> > > > Signed-off-by: Chia-Wei, Wang 
> > > > ---
> > > >  drivers/soc/aspeed/Kconfig  |  49 ++
> > > >  drivers/soc/aspeed/Makefile |   5 +
> > > >  drivers/soc/aspeed/aspeed-espi-ctrl.c   | 197 ++
> > > >  drivers/soc/aspeed/aspeed-espi-flash.c  | 490 ++
> > > >  drivers/soc/aspeed/aspeed-espi-oob.c| 706
> > > 
> > > >  drivers/soc/aspeed/aspeed-espi-peripheral.c | 613
> +
> > > >  drivers/soc/aspeed/aspeed-espi-vw.c | 211 ++
> > > >  include/uapi/linux/aspeed-espi.h| 160 +
> > > >  8 files changed, 2431 insertions(+)  create mode 100644
> > > > drivers/soc/aspeed/aspeed-espi-ctrl.c
> > > >  create mode 100644 drivers/soc/aspeed/aspeed-espi-flash.c
> > > >  create mode 100644 drivers/soc/aspeed/aspeed-espi-oob.c
> > > >  create mode 100644 drivers/soc/aspeed/aspeed-espi-peripheral.c
> > > >  create mode 100644 drivers/soc/aspeed/aspeed-espi-vw.c
> > >
> > > drivers/spi/ is the correct location for a SPI controller.
> > >
> > > >  create mode 100644 include/uapi/linux/aspeed-espi.h
> > >
> > > This userspace interface is not going to be accepted upstream.
> > >
> > > I'd suggest you look at similar SPI flash capable SPI controller
> > > drivers upstream and model your driver after them. This looks like it 
> > > needs
> major reworking.
> > >
> > eSPI resues the timing and electrical specification of SPI but runs 
> > completely
> different protocol.
> > Only the flash channel is related to SPI and the other 3 channels are for
> EC/BMC/SIO.
> > Therefore, an eSPI driver might not fit into the SPI model.
> 
> I agree, the naming is confusing but eSPI doesn't belong in drivers/spi.
> 
> As it is a bus that is common to more than just the Aspeed BMC, we may want
> to implement it as a new bus type that has devices hanging off it, similar to
> FSI.
> 
The ASPEED eSPI controller driver is slave side device, not master side. I 
think it will be stay soc/aspeed first. 
Because is most SoC Chip related. 

Cheers,

Ryan


Re: [PATCH 5/6] soc: aspeed: Add eSPI driver

2021-01-07 Thread Joel Stanley
On Thu, 7 Jan 2021 at 02:39, ChiaWei Wang  wrote:
>
> Hi Rob,
>
> > -Original Message-
> > From: Rob Herring 
> > Sent: Wednesday, January 6, 2021 11:32 PM
> > To: ChiaWei Wang 
> > Subject: Re: [PATCH 5/6] soc: aspeed: Add eSPI driver
> >
> > On Wed, Jan 06, 2021 at 01:59:38PM +0800, Chia-Wei, Wang wrote:
> > > The Aspeed eSPI controller is slave device to communicate with the
> > > master through the Enhanced Serial Peripheral Interface (eSPI).
> > > All of the four eSPI channels, namely peripheral, virtual wire,
> > > out-of-band, and flash are supported.
> > >
> > > Signed-off-by: Chia-Wei, Wang 
> > > ---
> > >  drivers/soc/aspeed/Kconfig  |  49 ++
> > >  drivers/soc/aspeed/Makefile |   5 +
> > >  drivers/soc/aspeed/aspeed-espi-ctrl.c   | 197 ++
> > >  drivers/soc/aspeed/aspeed-espi-flash.c  | 490 ++
> > >  drivers/soc/aspeed/aspeed-espi-oob.c| 706
> > 
> > >  drivers/soc/aspeed/aspeed-espi-peripheral.c | 613 +
> > >  drivers/soc/aspeed/aspeed-espi-vw.c | 211 ++
> > >  include/uapi/linux/aspeed-espi.h| 160 +
> > >  8 files changed, 2431 insertions(+)
> > >  create mode 100644 drivers/soc/aspeed/aspeed-espi-ctrl.c
> > >  create mode 100644 drivers/soc/aspeed/aspeed-espi-flash.c
> > >  create mode 100644 drivers/soc/aspeed/aspeed-espi-oob.c
> > >  create mode 100644 drivers/soc/aspeed/aspeed-espi-peripheral.c
> > >  create mode 100644 drivers/soc/aspeed/aspeed-espi-vw.c
> >
> > drivers/spi/ is the correct location for a SPI controller.
> >
> > >  create mode 100644 include/uapi/linux/aspeed-espi.h
> >
> > This userspace interface is not going to be accepted upstream.
> >
> > I'd suggest you look at similar SPI flash capable SPI controller drivers 
> > upstream
> > and model your driver after them. This looks like it needs major reworking.
> >
> eSPI resues the timing and electrical specification of SPI but runs 
> completely different protocol.
> Only the flash channel is related to SPI and the other 3 channels are for 
> EC/BMC/SIO.
> Therefore, an eSPI driver might not fit into the SPI model.

I agree, the naming is confusing but eSPI doesn't belong in drivers/spi.

As it is a bus that is common to more than just the Aspeed BMC, we may
want to implement it as a new bus type that has devices hanging off
it, similar to FSI.

Cheers,

Joel


RE: [PATCH 5/6] soc: aspeed: Add eSPI driver

2021-01-06 Thread ChiaWei Wang
Hi Rob,

> -Original Message-
> From: Rob Herring 
> Sent: Wednesday, January 6, 2021 11:32 PM
> To: ChiaWei Wang 
> Subject: Re: [PATCH 5/6] soc: aspeed: Add eSPI driver
> 
> On Wed, Jan 06, 2021 at 01:59:38PM +0800, Chia-Wei, Wang wrote:
> > The Aspeed eSPI controller is slave device to communicate with the
> > master through the Enhanced Serial Peripheral Interface (eSPI).
> > All of the four eSPI channels, namely peripheral, virtual wire,
> > out-of-band, and flash are supported.
> >
> > Signed-off-by: Chia-Wei, Wang 
> > ---
> >  drivers/soc/aspeed/Kconfig  |  49 ++
> >  drivers/soc/aspeed/Makefile |   5 +
> >  drivers/soc/aspeed/aspeed-espi-ctrl.c   | 197 ++
> >  drivers/soc/aspeed/aspeed-espi-flash.c  | 490 ++
> >  drivers/soc/aspeed/aspeed-espi-oob.c| 706
> 
> >  drivers/soc/aspeed/aspeed-espi-peripheral.c | 613 +
> >  drivers/soc/aspeed/aspeed-espi-vw.c | 211 ++
> >  include/uapi/linux/aspeed-espi.h| 160 +
> >  8 files changed, 2431 insertions(+)
> >  create mode 100644 drivers/soc/aspeed/aspeed-espi-ctrl.c
> >  create mode 100644 drivers/soc/aspeed/aspeed-espi-flash.c
> >  create mode 100644 drivers/soc/aspeed/aspeed-espi-oob.c
> >  create mode 100644 drivers/soc/aspeed/aspeed-espi-peripheral.c
> >  create mode 100644 drivers/soc/aspeed/aspeed-espi-vw.c
> 
> drivers/spi/ is the correct location for a SPI controller.
> 
> >  create mode 100644 include/uapi/linux/aspeed-espi.h
> 
> This userspace interface is not going to be accepted upstream.
> 
> I'd suggest you look at similar SPI flash capable SPI controller drivers 
> upstream
> and model your driver after them. This looks like it needs major reworking.
> 
eSPI resues the timing and electrical specification of SPI but runs completely 
different protocol.
Only the flash channel is related to SPI and the other 3 channels are for 
EC/BMC/SIO.
Therefore, an eSPI driver might not fit into the SPI model.

Chiawei


Re: [PATCH 5/6] soc: aspeed: Add eSPI driver

2021-01-06 Thread Rob Herring
On Wed, Jan 06, 2021 at 01:59:38PM +0800, Chia-Wei, Wang wrote:
> The Aspeed eSPI controller is slave device to communicate with
> the master through the Enhanced Serial Peripheral Interface (eSPI).
> All of the four eSPI channels, namely peripheral, virtual wire,
> out-of-band, and flash are supported.
> 
> Signed-off-by: Chia-Wei, Wang 
> ---
>  drivers/soc/aspeed/Kconfig  |  49 ++
>  drivers/soc/aspeed/Makefile |   5 +
>  drivers/soc/aspeed/aspeed-espi-ctrl.c   | 197 ++
>  drivers/soc/aspeed/aspeed-espi-flash.c  | 490 ++
>  drivers/soc/aspeed/aspeed-espi-oob.c| 706 
>  drivers/soc/aspeed/aspeed-espi-peripheral.c | 613 +
>  drivers/soc/aspeed/aspeed-espi-vw.c | 211 ++
>  include/uapi/linux/aspeed-espi.h| 160 +
>  8 files changed, 2431 insertions(+)
>  create mode 100644 drivers/soc/aspeed/aspeed-espi-ctrl.c
>  create mode 100644 drivers/soc/aspeed/aspeed-espi-flash.c
>  create mode 100644 drivers/soc/aspeed/aspeed-espi-oob.c
>  create mode 100644 drivers/soc/aspeed/aspeed-espi-peripheral.c
>  create mode 100644 drivers/soc/aspeed/aspeed-espi-vw.c

drivers/spi/ is the correct location for a SPI controller.

>  create mode 100644 include/uapi/linux/aspeed-espi.h

This userspace interface is not going to be accepted upstream.

I'd suggest you look at similar SPI flash capable SPI controller drivers 
upstream and model your driver after them. This looks like it needs 
major reworking.

Rob


[PATCH 5/6] soc: aspeed: Add eSPI driver

2021-01-05 Thread Chia-Wei, Wang
The Aspeed eSPI controller is slave device to communicate with
the master through the Enhanced Serial Peripheral Interface (eSPI).
All of the four eSPI channels, namely peripheral, virtual wire,
out-of-band, and flash are supported.

Signed-off-by: Chia-Wei, Wang 
---
 drivers/soc/aspeed/Kconfig  |  49 ++
 drivers/soc/aspeed/Makefile |   5 +
 drivers/soc/aspeed/aspeed-espi-ctrl.c   | 197 ++
 drivers/soc/aspeed/aspeed-espi-flash.c  | 490 ++
 drivers/soc/aspeed/aspeed-espi-oob.c| 706 
 drivers/soc/aspeed/aspeed-espi-peripheral.c | 613 +
 drivers/soc/aspeed/aspeed-espi-vw.c | 211 ++
 include/uapi/linux/aspeed-espi.h| 160 +
 8 files changed, 2431 insertions(+)
 create mode 100644 drivers/soc/aspeed/aspeed-espi-ctrl.c
 create mode 100644 drivers/soc/aspeed/aspeed-espi-flash.c
 create mode 100644 drivers/soc/aspeed/aspeed-espi-oob.c
 create mode 100644 drivers/soc/aspeed/aspeed-espi-peripheral.c
 create mode 100644 drivers/soc/aspeed/aspeed-espi-vw.c
 create mode 100644 include/uapi/linux/aspeed-espi.h

diff --git a/drivers/soc/aspeed/Kconfig b/drivers/soc/aspeed/Kconfig
index 243ca196e6ad..e4408e97023d 100644
--- a/drivers/soc/aspeed/Kconfig
+++ b/drivers/soc/aspeed/Kconfig
@@ -42,6 +42,55 @@ config ASPEED_SOCINFO
help
  Say yes to support decoding of ASPEED BMC information.
 
+config ASPEED_ESPI
+   tristate "Aspeed eSPI Engine Driver"
+   select REGMAP
+   select MFD_SYSON
+   select ASPEED_ESPI_PERIPHERAL
+   select ASPEED_ESPI_VW
+   select ASPEED_ESPI_OOB
+   select ASPEED_ESPI_FLASH
+   default n
+   help
+ Enable support for the Aspeed eSPI engine. The eSPI engine
+ plays as a slave device in BMC to communicate with the host
+ side master over the eSPI bus interface.
+
+ eSPI and LPC are mutually execulisve features on Aspeed SoC.
+ If not sure, say N.
+
+config ASPEED_ESPI_PERIPHERAL
+   tristate "Aspeed eSPI peripheral channel driver"
+   depends on ASPEED_ESPI
+   help
+ Control Aspeed eSPI peripheral channel driver. The driver
+ also provides an eSPI packet put/get interface to communicate
+ with the eSPI host.
+
+config ASPEED_ESPI_VW
+   tristate "Aspeed eSPI virtual wire channel driver"
+   depends on ASPEED_ESPI
+   help
+ Control Aspeed eSPI virtual wire channel driver. The driver
+ also provides an eSPI packet put/get interface to communicate
+ with the eSPI host.
+
+config ASPEED_ESPI_OOB
+   tristate "Aspeed eSPI out-of-band channel driver"
+   depends on ASPEED_ESPI
+   help
+ Control Aspeed eSPI out-of-band channel driver. The driver
+ also provides an eSPI packet put/get interface to communicat
+ with the eSPI host.
+
+config ASPEED_ESPI_FLASH
+   tristate "Aspeed eSPI flash channel driver"
+   depends on ASPEED_ESPI
+   help
+ Control Aspeed eSPI flash channel driver. The driver
+ also provides an eSPI packet put/get interface to communicat
+ with the eSPI host.
+
 endmenu
 
 endif
diff --git a/drivers/soc/aspeed/Makefile b/drivers/soc/aspeed/Makefile
index fcab7192e1a4..ac41ce82bb78 100644
--- a/drivers/soc/aspeed/Makefile
+++ b/drivers/soc/aspeed/Makefile
@@ -3,3 +3,8 @@ obj-$(CONFIG_ASPEED_LPC_CTRL)   += aspeed-lpc-ctrl.o
 obj-$(CONFIG_ASPEED_LPC_SNOOP) += aspeed-lpc-snoop.o
 obj-$(CONFIG_ASPEED_P2A_CTRL)  += aspeed-p2a-ctrl.o
 obj-$(CONFIG_ASPEED_SOCINFO)   += aspeed-socinfo.o
+obj-$(CONFIG_ASPEED_ESPI)  += aspeed-espi-ctrl.o \
+  aspeed-espi-peripheral.o \
+  aspeed-espi-vw.o \
+  aspeed-espi-oob.o \
+  aspeed-espi-flash.o
diff --git a/drivers/soc/aspeed/aspeed-espi-ctrl.c 
b/drivers/soc/aspeed/aspeed-espi-ctrl.c
new file mode 100644
index ..e4329f5f8ed3
--- /dev/null
+++ b/drivers/soc/aspeed/aspeed-espi-ctrl.c
@@ -0,0 +1,197 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Aspeed Technology Inc.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#define DEVICE_NAME "aspeed-espi-ctrl"
+
+struct aspeed_espi_ctrl {
+   struct regmap *map;
+   struct clk *clk;
+   struct reset_control *rst;
+
+   int irq;
+   int irq_reset;
+};
+
+static irqreturn_t aspeed_espi_ctrl_isr(int irq, void *arg)
+{
+   uint32_t sts;
+   struct aspeed_espi_ctrl *espi_ctrl = (struct aspeed_espi_ctrl *)arg;
+
+   regmap_read(espi_ctrl->map, ESPI_INT_STS, );
+
+   if (!(sts & ESPI_INT_STS_HW_RST_DEASSERT))
+   return IRQ_NONE;
+
+   regmap_update_bits(espi_ctrl->map, ESPI_SYSEVT,
+  ESPI_SYSEVT_SLV_BOOT_STS |