2019-06-01 16:08:37 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2010-01-21 22:46:42 +08:00
|
|
|
/*
|
2011-06-06 15:16:30 +08:00
|
|
|
* Memory-mapped interface driver for DW SPI Core
|
2010-01-21 22:46:42 +08:00
|
|
|
*
|
|
|
|
* Copyright (c) 2010, Octasic semiconductor.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/clk.h>
|
2011-01-11 20:43:52 +08:00
|
|
|
#include <linux/err.h>
|
2010-01-21 22:46:42 +08:00
|
|
|
#include <linux/platform_device.h>
|
2019-10-18 21:21:29 +08:00
|
|
|
#include <linux/pm_runtime.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2010-01-21 22:46:42 +08:00
|
|
|
#include <linux/spi/spi.h>
|
2011-03-01 03:47:12 +08:00
|
|
|
#include <linux/scatterlist.h>
|
2018-07-28 03:53:56 +08:00
|
|
|
#include <linux/mfd/syscon.h>
|
2011-07-04 03:44:29 +08:00
|
|
|
#include <linux/module.h>
|
2014-06-13 21:36:18 +08:00
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/of_platform.h>
|
2018-12-03 11:15:50 +08:00
|
|
|
#include <linux/acpi.h>
|
2015-10-15 04:12:25 +08:00
|
|
|
#include <linux/property.h>
|
2018-07-28 03:53:56 +08:00
|
|
|
#include <linux/regmap.h>
|
2020-05-29 23:58:05 +08:00
|
|
|
#include <linux/reset.h>
|
2011-03-01 03:47:12 +08:00
|
|
|
|
2011-06-06 15:16:30 +08:00
|
|
|
#include "spi-dw.h"
|
2010-01-21 22:46:42 +08:00
|
|
|
|
|
|
|
#define DRIVER_NAME "dw_spi_mmio"
|
|
|
|
|
|
|
|
struct dw_spi_mmio {
|
2010-01-22 00:55:42 +08:00
|
|
|
struct dw_spi dws;
|
|
|
|
struct clk *clk;
|
2019-03-19 23:52:07 +08:00
|
|
|
struct clk *pclk;
|
2018-07-28 03:53:56 +08:00
|
|
|
void *priv;
|
2020-05-29 23:58:05 +08:00
|
|
|
struct reset_control *rstc;
|
2010-01-21 22:46:42 +08:00
|
|
|
};
|
|
|
|
|
2018-07-28 03:53:56 +08:00
|
|
|
#define MSCC_CPU_SYSTEM_CTRL_GENERAL_CTRL 0x24
|
|
|
|
#define OCELOT_IF_SI_OWNER_OFFSET 4
|
2018-08-29 20:45:48 +08:00
|
|
|
#define JAGUAR2_IF_SI_OWNER_OFFSET 6
|
2018-08-31 19:40:46 +08:00
|
|
|
#define MSCC_IF_SI_OWNER_MASK GENMASK(1, 0)
|
2018-07-28 03:53:56 +08:00
|
|
|
#define MSCC_IF_SI_OWNER_SISL 0
|
|
|
|
#define MSCC_IF_SI_OWNER_SIBM 1
|
|
|
|
#define MSCC_IF_SI_OWNER_SIMC 2
|
|
|
|
|
|
|
|
#define MSCC_SPI_MST_SW_MODE 0x14
|
|
|
|
#define MSCC_SPI_MST_SW_MODE_SW_PIN_CTRL_MODE BIT(13)
|
|
|
|
#define MSCC_SPI_MST_SW_MODE_SW_SPI_CS(x) (x << 5)
|
|
|
|
|
2020-08-25 04:30:06 +08:00
|
|
|
#define SPARX5_FORCE_ENA 0xa4
|
|
|
|
#define SPARX5_FORCE_VAL 0xa8
|
|
|
|
|
2018-07-28 03:53:56 +08:00
|
|
|
struct dw_spi_mscc {
|
|
|
|
struct regmap *syscon;
|
2020-08-25 04:30:06 +08:00
|
|
|
void __iomem *spi_mst; /* Not sparx5 */
|
2018-07-28 03:53:56 +08:00
|
|
|
};
|
|
|
|
|
2023-04-11 02:45:21 +08:00
|
|
|
/*
|
|
|
|
* Elba SoC does not use ssi, pin override is used for cs 0,1 and
|
|
|
|
* gpios for cs 2,3 as defined in the device tree.
|
|
|
|
*
|
|
|
|
* cs: | 1 0
|
|
|
|
* bit: |---3-------2-------1-------0
|
|
|
|
* | cs1 cs1_ovr cs0 cs0_ovr
|
|
|
|
*/
|
|
|
|
#define ELBA_SPICS_REG 0x2468
|
|
|
|
#define ELBA_SPICS_OFFSET(cs) ((cs) << 1)
|
|
|
|
#define ELBA_SPICS_MASK(cs) (GENMASK(1, 0) << ELBA_SPICS_OFFSET(cs))
|
|
|
|
#define ELBA_SPICS_SET(cs, val) \
|
|
|
|
((((val) << 1) | BIT(0)) << ELBA_SPICS_OFFSET(cs))
|
|
|
|
|
2018-07-28 03:53:56 +08:00
|
|
|
/*
|
2023-08-16 17:39:38 +08:00
|
|
|
* The Designware SPI controller (referred to as master in the documentation)
|
2018-07-28 03:53:56 +08:00
|
|
|
* automatically deasserts chip select when the tx fifo is empty. The chip
|
2021-05-10 14:58:22 +08:00
|
|
|
* selects then needs to be either driven as GPIOs or, for the first 4 using
|
2018-07-28 03:53:56 +08:00
|
|
|
* the SPI boot controller registers. the final chip select is an OR gate
|
|
|
|
* between the Designware SPI controller and the SPI boot controller.
|
|
|
|
*/
|
|
|
|
static void dw_spi_mscc_set_cs(struct spi_device *spi, bool enable)
|
|
|
|
{
|
2023-07-28 17:32:19 +08:00
|
|
|
struct dw_spi *dws = spi_controller_get_devdata(spi->controller);
|
2018-07-28 03:53:56 +08:00
|
|
|
struct dw_spi_mmio *dwsmmio = container_of(dws, struct dw_spi_mmio, dws);
|
|
|
|
struct dw_spi_mscc *dwsmscc = dwsmmio->priv;
|
2023-03-11 01:32:03 +08:00
|
|
|
u32 cs = spi_get_chipselect(spi, 0);
|
2018-07-28 03:53:56 +08:00
|
|
|
|
|
|
|
if (cs < 4) {
|
|
|
|
u32 sw_mode = MSCC_SPI_MST_SW_MODE_SW_PIN_CTRL_MODE;
|
|
|
|
|
|
|
|
if (!enable)
|
|
|
|
sw_mode |= MSCC_SPI_MST_SW_MODE_SW_SPI_CS(BIT(cs));
|
|
|
|
|
|
|
|
writel(sw_mode, dwsmscc->spi_mst + MSCC_SPI_MST_SW_MODE);
|
|
|
|
}
|
|
|
|
|
|
|
|
dw_spi_set_cs(spi, enable);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dw_spi_mscc_init(struct platform_device *pdev,
|
2018-08-29 20:45:48 +08:00
|
|
|
struct dw_spi_mmio *dwsmmio,
|
|
|
|
const char *cpu_syscon, u32 if_si_owner_offset)
|
2018-07-28 03:53:56 +08:00
|
|
|
{
|
|
|
|
struct dw_spi_mscc *dwsmscc;
|
|
|
|
|
|
|
|
dwsmscc = devm_kzalloc(&pdev->dev, sizeof(*dwsmscc), GFP_KERNEL);
|
|
|
|
if (!dwsmscc)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2019-09-04 21:58:54 +08:00
|
|
|
dwsmscc->spi_mst = devm_platform_ioremap_resource(pdev, 1);
|
2018-07-28 03:53:56 +08:00
|
|
|
if (IS_ERR(dwsmscc->spi_mst)) {
|
|
|
|
dev_err(&pdev->dev, "SPI_MST region map failed\n");
|
|
|
|
return PTR_ERR(dwsmscc->spi_mst);
|
|
|
|
}
|
|
|
|
|
2018-08-29 20:45:48 +08:00
|
|
|
dwsmscc->syscon = syscon_regmap_lookup_by_compatible(cpu_syscon);
|
2018-07-28 03:53:56 +08:00
|
|
|
if (IS_ERR(dwsmscc->syscon))
|
|
|
|
return PTR_ERR(dwsmscc->syscon);
|
|
|
|
|
|
|
|
/* Deassert all CS */
|
|
|
|
writel(0, dwsmscc->spi_mst + MSCC_SPI_MST_SW_MODE);
|
|
|
|
|
|
|
|
/* Select the owner of the SI interface */
|
|
|
|
regmap_update_bits(dwsmscc->syscon, MSCC_CPU_SYSTEM_CTRL_GENERAL_CTRL,
|
2018-08-31 19:40:46 +08:00
|
|
|
MSCC_IF_SI_OWNER_MASK << if_si_owner_offset,
|
2018-08-29 20:45:48 +08:00
|
|
|
MSCC_IF_SI_OWNER_SIMC << if_si_owner_offset);
|
2018-07-28 03:53:56 +08:00
|
|
|
|
|
|
|
dwsmmio->dws.set_cs = dw_spi_mscc_set_cs;
|
|
|
|
dwsmmio->priv = dwsmscc;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-08-29 20:45:48 +08:00
|
|
|
static int dw_spi_mscc_ocelot_init(struct platform_device *pdev,
|
|
|
|
struct dw_spi_mmio *dwsmmio)
|
|
|
|
{
|
|
|
|
return dw_spi_mscc_init(pdev, dwsmmio, "mscc,ocelot-cpu-syscon",
|
|
|
|
OCELOT_IF_SI_OWNER_OFFSET);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dw_spi_mscc_jaguar2_init(struct platform_device *pdev,
|
|
|
|
struct dw_spi_mmio *dwsmmio)
|
|
|
|
{
|
|
|
|
return dw_spi_mscc_init(pdev, dwsmmio, "mscc,jaguar2-cpu-syscon",
|
|
|
|
JAGUAR2_IF_SI_OWNER_OFFSET);
|
|
|
|
}
|
|
|
|
|
2020-08-25 04:30:06 +08:00
|
|
|
/*
|
2023-08-16 17:39:38 +08:00
|
|
|
* The Designware SPI controller (referred to as master in the
|
2020-08-25 04:30:06 +08:00
|
|
|
* documentation) automatically deasserts chip select when the tx fifo
|
|
|
|
* is empty. The chip selects then needs to be driven by a CS override
|
|
|
|
* register. enable is an active low signal.
|
|
|
|
*/
|
|
|
|
static void dw_spi_sparx5_set_cs(struct spi_device *spi, bool enable)
|
|
|
|
{
|
2023-07-28 17:32:19 +08:00
|
|
|
struct dw_spi *dws = spi_controller_get_devdata(spi->controller);
|
2020-08-25 04:30:06 +08:00
|
|
|
struct dw_spi_mmio *dwsmmio = container_of(dws, struct dw_spi_mmio, dws);
|
|
|
|
struct dw_spi_mscc *dwsmscc = dwsmmio->priv;
|
2023-03-11 01:32:03 +08:00
|
|
|
u8 cs = spi_get_chipselect(spi, 0);
|
2020-08-25 04:30:06 +08:00
|
|
|
|
|
|
|
if (!enable) {
|
|
|
|
/* CS override drive enable */
|
|
|
|
regmap_write(dwsmscc->syscon, SPARX5_FORCE_ENA, 1);
|
|
|
|
/* Now set CSx enabled */
|
|
|
|
regmap_write(dwsmscc->syscon, SPARX5_FORCE_VAL, ~BIT(cs));
|
|
|
|
/* Allow settle */
|
|
|
|
usleep_range(1, 5);
|
|
|
|
} else {
|
|
|
|
/* CS value */
|
|
|
|
regmap_write(dwsmscc->syscon, SPARX5_FORCE_VAL, ~0);
|
|
|
|
/* Allow settle */
|
|
|
|
usleep_range(1, 5);
|
|
|
|
/* CS override drive disable */
|
|
|
|
regmap_write(dwsmscc->syscon, SPARX5_FORCE_ENA, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
dw_spi_set_cs(spi, enable);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dw_spi_mscc_sparx5_init(struct platform_device *pdev,
|
|
|
|
struct dw_spi_mmio *dwsmmio)
|
|
|
|
{
|
|
|
|
const char *syscon_name = "microchip,sparx5-cpu-syscon";
|
|
|
|
struct device *dev = &pdev->dev;
|
|
|
|
struct dw_spi_mscc *dwsmscc;
|
|
|
|
|
|
|
|
if (!IS_ENABLED(CONFIG_SPI_MUX)) {
|
|
|
|
dev_err(dev, "This driver needs CONFIG_SPI_MUX\n");
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
dwsmscc = devm_kzalloc(dev, sizeof(*dwsmscc), GFP_KERNEL);
|
|
|
|
if (!dwsmscc)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
dwsmscc->syscon =
|
|
|
|
syscon_regmap_lookup_by_compatible(syscon_name);
|
|
|
|
if (IS_ERR(dwsmscc->syscon)) {
|
|
|
|
dev_err(dev, "No syscon map %s\n", syscon_name);
|
|
|
|
return PTR_ERR(dwsmscc->syscon);
|
|
|
|
}
|
|
|
|
|
|
|
|
dwsmmio->dws.set_cs = dw_spi_sparx5_set_cs;
|
|
|
|
dwsmmio->priv = dwsmscc;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-10-11 19:20:07 +08:00
|
|
|
static int dw_spi_alpine_init(struct platform_device *pdev,
|
|
|
|
struct dw_spi_mmio *dwsmmio)
|
|
|
|
{
|
2020-09-20 19:28:53 +08:00
|
|
|
dwsmmio->dws.caps = DW_SPI_CAP_CS_OVERRIDE;
|
2018-10-11 19:20:07 +08:00
|
|
|
|
2020-05-05 21:06:13 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-11-16 02:19:13 +08:00
|
|
|
static int dw_spi_pssi_init(struct platform_device *pdev,
|
|
|
|
struct dw_spi_mmio *dwsmmio)
|
2020-05-05 21:06:13 +08:00
|
|
|
{
|
2020-05-29 21:12:03 +08:00
|
|
|
dw_spi_dma_setup_generic(&dwsmmio->dws);
|
|
|
|
|
2018-10-11 19:20:07 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-11-16 02:19:13 +08:00
|
|
|
static int dw_spi_hssi_init(struct platform_device *pdev,
|
|
|
|
struct dw_spi_mmio *dwsmmio)
|
2020-05-05 21:06:14 +08:00
|
|
|
{
|
2021-11-16 02:19:16 +08:00
|
|
|
dwsmmio->dws.ip = DW_HSSI_ID;
|
2020-05-05 21:06:14 +08:00
|
|
|
|
2020-05-29 21:12:03 +08:00
|
|
|
dw_spi_dma_setup_generic(&dwsmmio->dws);
|
|
|
|
|
2020-05-05 21:06:14 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-07-13 12:22:23 +08:00
|
|
|
static int dw_spi_intel_init(struct platform_device *pdev,
|
|
|
|
struct dw_spi_mmio *dwsmmio)
|
2020-05-05 21:06:16 +08:00
|
|
|
{
|
2021-11-16 02:19:16 +08:00
|
|
|
dwsmmio->dws.ip = DW_HSSI_ID;
|
2020-05-05 21:06:16 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-06-06 22:54:01 +08:00
|
|
|
/*
|
2023-06-07 07:18:44 +08:00
|
|
|
* DMA-based mem ops are not configured for this device and are not tested.
|
2023-06-06 22:54:01 +08:00
|
|
|
*/
|
|
|
|
static int dw_spi_mountevans_imc_init(struct platform_device *pdev,
|
|
|
|
struct dw_spi_mmio *dwsmmio)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* The Intel Mount Evans SoC's Integrated Management Complex DW
|
|
|
|
* apb_ssi_v4.02a controller has an errata where a full TX FIFO can
|
|
|
|
* result in data corruption. The suggested workaround is to never
|
|
|
|
* completely fill the FIFO. The TX FIFO has a size of 32 so the
|
|
|
|
* fifo_len is set to 31.
|
|
|
|
*/
|
|
|
|
dwsmmio->dws.fifo_len = 31;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-12-06 09:18:17 +08:00
|
|
|
static int dw_spi_canaan_k210_init(struct platform_device *pdev,
|
|
|
|
struct dw_spi_mmio *dwsmmio)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* The Canaan Kendryte K210 SoC DW apb_ssi v4 spi controller is
|
|
|
|
* documented to have a 32 word deep TX and RX FIFO, which
|
|
|
|
* spi_hw_init() detects. However, when the RX FIFO is filled up to
|
|
|
|
* 32 entries (RXFLR = 32), an RX FIFO overrun error occurs. Avoid this
|
|
|
|
* problem by force setting fifo_len to 31.
|
|
|
|
*/
|
|
|
|
dwsmmio->dws.fifo_len = 31;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-04-11 02:45:21 +08:00
|
|
|
static void dw_spi_elba_override_cs(struct regmap *syscon, int cs, int enable)
|
|
|
|
{
|
|
|
|
regmap_update_bits(syscon, ELBA_SPICS_REG, ELBA_SPICS_MASK(cs),
|
|
|
|
ELBA_SPICS_SET(cs, enable));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dw_spi_elba_set_cs(struct spi_device *spi, bool enable)
|
|
|
|
{
|
2023-07-28 17:32:19 +08:00
|
|
|
struct dw_spi *dws = spi_controller_get_devdata(spi->controller);
|
2023-04-11 02:45:21 +08:00
|
|
|
struct dw_spi_mmio *dwsmmio = container_of(dws, struct dw_spi_mmio, dws);
|
|
|
|
struct regmap *syscon = dwsmmio->priv;
|
|
|
|
u8 cs;
|
|
|
|
|
2023-05-15 21:03:43 +08:00
|
|
|
cs = spi_get_chipselect(spi, 0);
|
2023-04-11 02:45:21 +08:00
|
|
|
if (cs < 2)
|
2023-05-15 21:03:43 +08:00
|
|
|
dw_spi_elba_override_cs(syscon, spi_get_chipselect(spi, 0), enable);
|
2023-04-11 02:45:21 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The DW SPI controller needs a native CS bit selected to start
|
|
|
|
* the serial engine.
|
|
|
|
*/
|
2023-05-15 21:03:43 +08:00
|
|
|
spi_set_chipselect(spi, 0, 0);
|
2023-04-11 02:45:21 +08:00
|
|
|
dw_spi_set_cs(spi, enable);
|
2023-06-14 00:21:03 +08:00
|
|
|
spi_set_chipselect(spi, 0, cs);
|
2023-04-11 02:45:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int dw_spi_elba_init(struct platform_device *pdev,
|
|
|
|
struct dw_spi_mmio *dwsmmio)
|
|
|
|
{
|
|
|
|
struct regmap *syscon;
|
|
|
|
|
|
|
|
syscon = syscon_regmap_lookup_by_phandle(dev_of_node(&pdev->dev),
|
|
|
|
"amd,pensando-elba-syscon");
|
|
|
|
if (IS_ERR(syscon))
|
|
|
|
return dev_err_probe(&pdev->dev, PTR_ERR(syscon),
|
|
|
|
"syscon regmap lookup failed\n");
|
|
|
|
|
|
|
|
dwsmmio->priv = syscon;
|
|
|
|
dwsmmio->dws.set_cs = dw_spi_elba_set_cs;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-08 00:57:14 +08:00
|
|
|
static int dw_spi_mmio_probe(struct platform_device *pdev)
|
2010-01-21 22:46:42 +08:00
|
|
|
{
|
2018-07-28 03:53:56 +08:00
|
|
|
int (*init_func)(struct platform_device *pdev,
|
|
|
|
struct dw_spi_mmio *dwsmmio);
|
2010-01-21 22:46:42 +08:00
|
|
|
struct dw_spi_mmio *dwsmmio;
|
2020-05-15 18:47:50 +08:00
|
|
|
struct resource *mem;
|
2010-01-21 22:46:42 +08:00
|
|
|
struct dw_spi *dws;
|
|
|
|
int ret;
|
2014-06-13 21:36:18 +08:00
|
|
|
int num_cs;
|
2010-01-21 22:46:42 +08:00
|
|
|
|
2013-12-31 02:30:44 +08:00
|
|
|
dwsmmio = devm_kzalloc(&pdev->dev, sizeof(struct dw_spi_mmio),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!dwsmmio)
|
|
|
|
return -ENOMEM;
|
2010-01-21 22:46:42 +08:00
|
|
|
|
|
|
|
dws = &dwsmmio->dws;
|
|
|
|
|
|
|
|
/* Get basic io resource and map it */
|
2020-05-15 18:47:50 +08:00
|
|
|
dws->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &mem);
|
2020-05-12 19:03:15 +08:00
|
|
|
if (IS_ERR(dws->regs))
|
2013-12-31 02:30:44 +08:00
|
|
|
return PTR_ERR(dws->regs);
|
2010-01-21 22:46:42 +08:00
|
|
|
|
2020-05-15 18:47:50 +08:00
|
|
|
dws->paddr = mem->start;
|
|
|
|
|
2010-01-21 22:46:42 +08:00
|
|
|
dws->irq = platform_get_irq(pdev, 0);
|
2019-07-31 02:15:41 +08:00
|
|
|
if (dws->irq < 0)
|
2013-12-31 02:30:44 +08:00
|
|
|
return dws->irq; /* -ENXIO */
|
2010-01-21 22:46:42 +08:00
|
|
|
|
2023-08-23 21:39:25 +08:00
|
|
|
dwsmmio->clk = devm_clk_get_enabled(&pdev->dev, NULL);
|
2013-12-31 02:30:44 +08:00
|
|
|
if (IS_ERR(dwsmmio->clk))
|
|
|
|
return PTR_ERR(dwsmmio->clk);
|
2010-01-21 22:46:42 +08:00
|
|
|
|
2019-03-19 23:52:07 +08:00
|
|
|
/* Optional clock needed to access the registers */
|
2023-08-23 21:39:25 +08:00
|
|
|
dwsmmio->pclk = devm_clk_get_optional_enabled(&pdev->dev, "pclk");
|
|
|
|
if (IS_ERR(dwsmmio->pclk))
|
|
|
|
return PTR_ERR(dwsmmio->pclk);
|
2019-03-19 23:52:07 +08:00
|
|
|
|
2020-05-29 23:58:05 +08:00
|
|
|
/* find an optional reset controller */
|
|
|
|
dwsmmio->rstc = devm_reset_control_get_optional_exclusive(&pdev->dev, "spi");
|
2023-08-23 21:39:25 +08:00
|
|
|
if (IS_ERR(dwsmmio->rstc))
|
|
|
|
return PTR_ERR(dwsmmio->rstc);
|
|
|
|
|
2020-05-29 23:58:05 +08:00
|
|
|
reset_control_deassert(dwsmmio->rstc);
|
|
|
|
|
2014-01-26 16:14:32 +08:00
|
|
|
dws->bus_num = pdev->id;
|
2014-06-13 21:36:18 +08:00
|
|
|
|
2010-01-21 22:46:42 +08:00
|
|
|
dws->max_freq = clk_get_rate(dwsmmio->clk);
|
|
|
|
|
2023-08-07 08:16:21 +08:00
|
|
|
if (device_property_read_u32(&pdev->dev, "reg-io-width",
|
|
|
|
&dws->reg_io_width))
|
|
|
|
dws->reg_io_width = 4;
|
2015-08-19 04:21:53 +08:00
|
|
|
|
2014-06-13 21:36:18 +08:00
|
|
|
num_cs = 4;
|
|
|
|
|
2015-10-15 04:12:25 +08:00
|
|
|
device_property_read_u32(&pdev->dev, "num-cs", &num_cs);
|
2014-06-13 21:36:18 +08:00
|
|
|
|
|
|
|
dws->num_cs = num_cs;
|
|
|
|
|
2018-07-28 03:53:56 +08:00
|
|
|
init_func = device_get_match_data(&pdev->dev);
|
|
|
|
if (init_func) {
|
|
|
|
ret = init_func(pdev, dwsmmio);
|
|
|
|
if (ret)
|
2023-08-23 21:39:25 +08:00
|
|
|
goto out_reset;
|
2018-07-28 03:53:56 +08:00
|
|
|
}
|
|
|
|
|
2019-10-18 21:21:29 +08:00
|
|
|
pm_runtime_enable(&pdev->dev);
|
|
|
|
|
2013-12-31 02:30:44 +08:00
|
|
|
ret = dw_spi_add_host(&pdev->dev, dws);
|
2010-01-21 22:46:42 +08:00
|
|
|
if (ret)
|
2013-12-31 02:30:44 +08:00
|
|
|
goto out;
|
2010-01-21 22:46:42 +08:00
|
|
|
|
|
|
|
platform_set_drvdata(pdev, dwsmmio);
|
|
|
|
return 0;
|
|
|
|
|
2013-12-31 02:30:44 +08:00
|
|
|
out:
|
2019-10-18 21:21:29 +08:00
|
|
|
pm_runtime_disable(&pdev->dev);
|
2023-08-23 21:39:25 +08:00
|
|
|
out_reset:
|
2020-05-29 23:58:05 +08:00
|
|
|
reset_control_assert(dwsmmio->rstc);
|
|
|
|
|
2010-01-21 22:46:42 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-03-04 01:19:36 +08:00
|
|
|
static void dw_spi_mmio_remove(struct platform_device *pdev)
|
2010-01-21 22:46:42 +08:00
|
|
|
{
|
|
|
|
struct dw_spi_mmio *dwsmmio = platform_get_drvdata(pdev);
|
|
|
|
|
|
|
|
dw_spi_remove_host(&dwsmmio->dws);
|
2019-10-18 21:21:29 +08:00
|
|
|
pm_runtime_disable(&pdev->dev);
|
2020-05-29 23:58:05 +08:00
|
|
|
reset_control_assert(dwsmmio->rstc);
|
2010-01-21 22:46:42 +08:00
|
|
|
}
|
|
|
|
|
2014-06-13 21:36:18 +08:00
|
|
|
static const struct of_device_id dw_spi_mmio_of_match[] = {
|
2021-11-16 02:19:13 +08:00
|
|
|
{ .compatible = "snps,dw-apb-ssi", .data = dw_spi_pssi_init},
|
2018-08-29 20:45:48 +08:00
|
|
|
{ .compatible = "mscc,ocelot-spi", .data = dw_spi_mscc_ocelot_init},
|
|
|
|
{ .compatible = "mscc,jaguar2-spi", .data = dw_spi_mscc_jaguar2_init},
|
2018-10-11 19:20:07 +08:00
|
|
|
{ .compatible = "amazon,alpine-dw-apb-ssi", .data = dw_spi_alpine_init},
|
2021-11-16 02:19:13 +08:00
|
|
|
{ .compatible = "renesas,rzn1-spi", .data = dw_spi_pssi_init},
|
|
|
|
{ .compatible = "snps,dwc-ssi-1.01a", .data = dw_spi_hssi_init},
|
2022-07-13 12:22:23 +08:00
|
|
|
{ .compatible = "intel,keembay-ssi", .data = dw_spi_intel_init},
|
|
|
|
{ .compatible = "intel,thunderbay-ssi", .data = dw_spi_intel_init},
|
2023-06-06 22:54:01 +08:00
|
|
|
{
|
|
|
|
.compatible = "intel,mountevans-imc-ssi",
|
|
|
|
.data = dw_spi_mountevans_imc_init,
|
|
|
|
},
|
2020-08-25 04:30:06 +08:00
|
|
|
{ .compatible = "microchip,sparx5-spi", dw_spi_mscc_sparx5_init},
|
2020-12-06 09:18:17 +08:00
|
|
|
{ .compatible = "canaan,k210-spi", dw_spi_canaan_k210_init},
|
2023-04-11 02:45:21 +08:00
|
|
|
{ .compatible = "amd,pensando-elba-spi", .data = dw_spi_elba_init},
|
2014-06-13 21:36:18 +08:00
|
|
|
{ /* end of table */}
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, dw_spi_mmio_of_match);
|
|
|
|
|
2020-05-09 10:29:51 +08:00
|
|
|
#ifdef CONFIG_ACPI
|
2018-12-03 11:15:50 +08:00
|
|
|
static const struct acpi_device_id dw_spi_mmio_acpi_match[] = {
|
2021-11-16 02:19:13 +08:00
|
|
|
{"HISI0173", (kernel_ulong_t)dw_spi_pssi_init},
|
2018-12-03 11:15:50 +08:00
|
|
|
{},
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(acpi, dw_spi_mmio_acpi_match);
|
2020-05-09 10:29:51 +08:00
|
|
|
#endif
|
2018-12-03 11:15:50 +08:00
|
|
|
|
2010-01-21 22:46:42 +08:00
|
|
|
static struct platform_driver dw_spi_mmio_driver = {
|
2011-10-06 01:29:49 +08:00
|
|
|
.probe = dw_spi_mmio_probe,
|
2023-03-04 01:19:36 +08:00
|
|
|
.remove_new = dw_spi_mmio_remove,
|
2010-01-21 22:46:42 +08:00
|
|
|
.driver = {
|
|
|
|
.name = DRIVER_NAME,
|
2014-06-13 21:36:18 +08:00
|
|
|
.of_match_table = dw_spi_mmio_of_match,
|
2018-12-03 11:15:50 +08:00
|
|
|
.acpi_match_table = ACPI_PTR(dw_spi_mmio_acpi_match),
|
2010-01-21 22:46:42 +08:00
|
|
|
},
|
|
|
|
};
|
2011-10-06 01:29:49 +08:00
|
|
|
module_platform_driver(dw_spi_mmio_driver);
|
2010-01-21 22:46:42 +08:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Jean-Hugues Deschenes <jean-hugues.deschenes@octasic.com>");
|
|
|
|
MODULE_DESCRIPTION("Memory-mapped I/O interface driver for DW SPI Core");
|
|
|
|
MODULE_LICENSE("GPL v2");
|
2021-11-16 02:19:11 +08:00
|
|
|
MODULE_IMPORT_NS(SPI_DW_CORE);
|