Thomas Gleixner | 75a6faf | 2019-06-01 10:08:37 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Jean-Hugues Deschenes | f7b6fd6 | 2010-01-21 07:46:42 -0700 | [diff] [blame] | 2 | /* |
Grant Likely | ca632f5 | 2011-06-06 01:16:30 -0600 | [diff] [blame] | 3 | * Memory-mapped interface driver for DW SPI Core |
Jean-Hugues Deschenes | f7b6fd6 | 2010-01-21 07:46:42 -0700 | [diff] [blame] | 4 | * |
| 5 | * Copyright (c) 2010, Octasic semiconductor. |
Jean-Hugues Deschenes | f7b6fd6 | 2010-01-21 07:46:42 -0700 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <linux/clk.h> |
Jamie Iles | 50c01fc | 2011-01-11 12:43:52 +0000 | [diff] [blame] | 9 | #include <linux/err.h> |
Jean-Hugues Deschenes | f7b6fd6 | 2010-01-21 07:46:42 -0700 | [diff] [blame] | 10 | #include <linux/platform_device.h> |
Jarkko Nikula | b9fc2d2 | 2019-10-18 16:21:29 +0300 | [diff] [blame] | 11 | #include <linux/pm_runtime.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 12 | #include <linux/slab.h> |
Jean-Hugues Deschenes | f7b6fd6 | 2010-01-21 07:46:42 -0700 | [diff] [blame] | 13 | #include <linux/spi/spi.h> |
Grant Likely | 568a60e | 2011-02-28 12:47:12 -0700 | [diff] [blame] | 14 | #include <linux/scatterlist.h> |
Alexandre Belloni | c2c25cc | 2018-07-27 21:53:56 +0200 | [diff] [blame] | 15 | #include <linux/mfd/syscon.h> |
Paul Gortmaker | d7614de | 2011-07-03 15:44:29 -0400 | [diff] [blame] | 16 | #include <linux/module.h> |
Steffen Trumtrar | 22dae17 | 2014-06-13 15:36:18 +0200 | [diff] [blame] | 17 | #include <linux/of.h> |
Steffen Trumtrar | 22dae17 | 2014-06-13 15:36:18 +0200 | [diff] [blame] | 18 | #include <linux/of_platform.h> |
Jay Fang | 32215a6 | 2018-12-03 11:15:50 +0800 | [diff] [blame] | 19 | #include <linux/acpi.h> |
Andy Shevchenko | 9899995 | 2015-10-14 23:12:25 +0300 | [diff] [blame] | 20 | #include <linux/property.h> |
Alexandre Belloni | c2c25cc | 2018-07-27 21:53:56 +0200 | [diff] [blame] | 21 | #include <linux/regmap.h> |
Dinh Nguyen | 7830c0e | 2020-05-29 10:58:05 -0500 | [diff] [blame] | 22 | #include <linux/reset.h> |
Grant Likely | 568a60e | 2011-02-28 12:47:12 -0700 | [diff] [blame] | 23 | |
Grant Likely | ca632f5 | 2011-06-06 01:16:30 -0600 | [diff] [blame] | 24 | #include "spi-dw.h" |
Jean-Hugues Deschenes | f7b6fd6 | 2010-01-21 07:46:42 -0700 | [diff] [blame] | 25 | |
| 26 | #define DRIVER_NAME "dw_spi_mmio" |
| 27 | |
| 28 | struct dw_spi_mmio { |
Jean-Hugues Deschenes | 0a4c1d7 | 2010-01-21 09:55:42 -0700 | [diff] [blame] | 29 | struct dw_spi dws; |
| 30 | struct clk *clk; |
Phil Edworthy | 560ee7e | 2019-03-19 15:52:07 +0000 | [diff] [blame] | 31 | struct clk *pclk; |
Alexandre Belloni | c2c25cc | 2018-07-27 21:53:56 +0200 | [diff] [blame] | 32 | void *priv; |
Dinh Nguyen | 7830c0e | 2020-05-29 10:58:05 -0500 | [diff] [blame] | 33 | struct reset_control *rstc; |
Jean-Hugues Deschenes | f7b6fd6 | 2010-01-21 07:46:42 -0700 | [diff] [blame] | 34 | }; |
| 35 | |
Alexandre Belloni | c2c25cc | 2018-07-27 21:53:56 +0200 | [diff] [blame] | 36 | #define MSCC_CPU_SYSTEM_CTRL_GENERAL_CTRL 0x24 |
Alexandre Belloni | c2c25cc | 2018-07-27 21:53:56 +0200 | [diff] [blame] | 37 | #define OCELOT_IF_SI_OWNER_OFFSET 4 |
Alexandre Belloni | be17ee0 | 2018-08-29 14:45:48 +0200 | [diff] [blame] | 38 | #define JAGUAR2_IF_SI_OWNER_OFFSET 6 |
Alexandre Belloni | c1d8b08 | 2018-08-31 13:40:46 +0200 | [diff] [blame] | 39 | #define MSCC_IF_SI_OWNER_MASK GENMASK(1, 0) |
Alexandre Belloni | c2c25cc | 2018-07-27 21:53:56 +0200 | [diff] [blame] | 40 | #define MSCC_IF_SI_OWNER_SISL 0 |
| 41 | #define MSCC_IF_SI_OWNER_SIBM 1 |
| 42 | #define MSCC_IF_SI_OWNER_SIMC 2 |
| 43 | |
| 44 | #define MSCC_SPI_MST_SW_MODE 0x14 |
| 45 | #define MSCC_SPI_MST_SW_MODE_SW_PIN_CTRL_MODE BIT(13) |
| 46 | #define MSCC_SPI_MST_SW_MODE_SW_SPI_CS(x) (x << 5) |
| 47 | |
Lars Povlsen | 53a0963 | 2020-08-24 22:30:06 +0200 | [diff] [blame^] | 48 | #define SPARX5_FORCE_ENA 0xa4 |
| 49 | #define SPARX5_FORCE_VAL 0xa8 |
| 50 | |
Wan Ahmad Zainie | f423779 | 2020-05-05 21:06:16 +0800 | [diff] [blame] | 51 | /* |
| 52 | * For Keem Bay, CTRLR0[31] is used to select controller mode. |
| 53 | * 0: SSI is slave |
| 54 | * 1: SSI is master |
| 55 | */ |
| 56 | #define KEEMBAY_CTRLR0_SSIC_IS_MST BIT(31) |
| 57 | |
Alexandre Belloni | c2c25cc | 2018-07-27 21:53:56 +0200 | [diff] [blame] | 58 | struct dw_spi_mscc { |
| 59 | struct regmap *syscon; |
Lars Povlsen | 53a0963 | 2020-08-24 22:30:06 +0200 | [diff] [blame^] | 60 | void __iomem *spi_mst; /* Not sparx5 */ |
Alexandre Belloni | c2c25cc | 2018-07-27 21:53:56 +0200 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | /* |
| 64 | * The Designware SPI controller (referred to as master in the documentation) |
| 65 | * automatically deasserts chip select when the tx fifo is empty. The chip |
| 66 | * selects then needs to be either driven as GPIOs or, for the first 4 using the |
| 67 | * the SPI boot controller registers. the final chip select is an OR gate |
| 68 | * between the Designware SPI controller and the SPI boot controller. |
| 69 | */ |
| 70 | static void dw_spi_mscc_set_cs(struct spi_device *spi, bool enable) |
| 71 | { |
| 72 | struct dw_spi *dws = spi_master_get_devdata(spi->master); |
| 73 | struct dw_spi_mmio *dwsmmio = container_of(dws, struct dw_spi_mmio, dws); |
| 74 | struct dw_spi_mscc *dwsmscc = dwsmmio->priv; |
| 75 | u32 cs = spi->chip_select; |
| 76 | |
| 77 | if (cs < 4) { |
| 78 | u32 sw_mode = MSCC_SPI_MST_SW_MODE_SW_PIN_CTRL_MODE; |
| 79 | |
| 80 | if (!enable) |
| 81 | sw_mode |= MSCC_SPI_MST_SW_MODE_SW_SPI_CS(BIT(cs)); |
| 82 | |
| 83 | writel(sw_mode, dwsmscc->spi_mst + MSCC_SPI_MST_SW_MODE); |
| 84 | } |
| 85 | |
| 86 | dw_spi_set_cs(spi, enable); |
| 87 | } |
| 88 | |
| 89 | static int dw_spi_mscc_init(struct platform_device *pdev, |
Alexandre Belloni | be17ee0 | 2018-08-29 14:45:48 +0200 | [diff] [blame] | 90 | struct dw_spi_mmio *dwsmmio, |
| 91 | const char *cpu_syscon, u32 if_si_owner_offset) |
Alexandre Belloni | c2c25cc | 2018-07-27 21:53:56 +0200 | [diff] [blame] | 92 | { |
| 93 | struct dw_spi_mscc *dwsmscc; |
Alexandre Belloni | c2c25cc | 2018-07-27 21:53:56 +0200 | [diff] [blame] | 94 | |
| 95 | dwsmscc = devm_kzalloc(&pdev->dev, sizeof(*dwsmscc), GFP_KERNEL); |
| 96 | if (!dwsmscc) |
| 97 | return -ENOMEM; |
| 98 | |
YueHaibing | 5cc6fdc | 2019-09-04 21:58:54 +0800 | [diff] [blame] | 99 | dwsmscc->spi_mst = devm_platform_ioremap_resource(pdev, 1); |
Alexandre Belloni | c2c25cc | 2018-07-27 21:53:56 +0200 | [diff] [blame] | 100 | if (IS_ERR(dwsmscc->spi_mst)) { |
| 101 | dev_err(&pdev->dev, "SPI_MST region map failed\n"); |
| 102 | return PTR_ERR(dwsmscc->spi_mst); |
| 103 | } |
| 104 | |
Alexandre Belloni | be17ee0 | 2018-08-29 14:45:48 +0200 | [diff] [blame] | 105 | dwsmscc->syscon = syscon_regmap_lookup_by_compatible(cpu_syscon); |
Alexandre Belloni | c2c25cc | 2018-07-27 21:53:56 +0200 | [diff] [blame] | 106 | if (IS_ERR(dwsmscc->syscon)) |
| 107 | return PTR_ERR(dwsmscc->syscon); |
| 108 | |
| 109 | /* Deassert all CS */ |
| 110 | writel(0, dwsmscc->spi_mst + MSCC_SPI_MST_SW_MODE); |
| 111 | |
| 112 | /* Select the owner of the SI interface */ |
| 113 | regmap_update_bits(dwsmscc->syscon, MSCC_CPU_SYSTEM_CTRL_GENERAL_CTRL, |
Alexandre Belloni | c1d8b08 | 2018-08-31 13:40:46 +0200 | [diff] [blame] | 114 | MSCC_IF_SI_OWNER_MASK << if_si_owner_offset, |
Alexandre Belloni | be17ee0 | 2018-08-29 14:45:48 +0200 | [diff] [blame] | 115 | MSCC_IF_SI_OWNER_SIMC << if_si_owner_offset); |
Alexandre Belloni | c2c25cc | 2018-07-27 21:53:56 +0200 | [diff] [blame] | 116 | |
| 117 | dwsmmio->dws.set_cs = dw_spi_mscc_set_cs; |
| 118 | dwsmmio->priv = dwsmscc; |
| 119 | |
Wan Ahmad Zainie | c4eadee | 2020-05-05 21:06:13 +0800 | [diff] [blame] | 120 | /* Register hook to configure CTRLR0 */ |
| 121 | dwsmmio->dws.update_cr0 = dw_spi_update_cr0; |
| 122 | |
Alexandre Belloni | c2c25cc | 2018-07-27 21:53:56 +0200 | [diff] [blame] | 123 | return 0; |
| 124 | } |
| 125 | |
Alexandre Belloni | be17ee0 | 2018-08-29 14:45:48 +0200 | [diff] [blame] | 126 | static int dw_spi_mscc_ocelot_init(struct platform_device *pdev, |
| 127 | struct dw_spi_mmio *dwsmmio) |
| 128 | { |
| 129 | return dw_spi_mscc_init(pdev, dwsmmio, "mscc,ocelot-cpu-syscon", |
| 130 | OCELOT_IF_SI_OWNER_OFFSET); |
| 131 | } |
| 132 | |
| 133 | static int dw_spi_mscc_jaguar2_init(struct platform_device *pdev, |
| 134 | struct dw_spi_mmio *dwsmmio) |
| 135 | { |
| 136 | return dw_spi_mscc_init(pdev, dwsmmio, "mscc,jaguar2-cpu-syscon", |
| 137 | JAGUAR2_IF_SI_OWNER_OFFSET); |
| 138 | } |
| 139 | |
Lars Povlsen | 53a0963 | 2020-08-24 22:30:06 +0200 | [diff] [blame^] | 140 | /* |
| 141 | * The Designware SPI controller (referred to as master in the |
| 142 | * documentation) automatically deasserts chip select when the tx fifo |
| 143 | * is empty. The chip selects then needs to be driven by a CS override |
| 144 | * register. enable is an active low signal. |
| 145 | */ |
| 146 | static void dw_spi_sparx5_set_cs(struct spi_device *spi, bool enable) |
| 147 | { |
| 148 | struct dw_spi *dws = spi_master_get_devdata(spi->master); |
| 149 | struct dw_spi_mmio *dwsmmio = container_of(dws, struct dw_spi_mmio, dws); |
| 150 | struct dw_spi_mscc *dwsmscc = dwsmmio->priv; |
| 151 | u8 cs = spi->chip_select; |
| 152 | |
| 153 | if (!enable) { |
| 154 | /* CS override drive enable */ |
| 155 | regmap_write(dwsmscc->syscon, SPARX5_FORCE_ENA, 1); |
| 156 | /* Now set CSx enabled */ |
| 157 | regmap_write(dwsmscc->syscon, SPARX5_FORCE_VAL, ~BIT(cs)); |
| 158 | /* Allow settle */ |
| 159 | usleep_range(1, 5); |
| 160 | } else { |
| 161 | /* CS value */ |
| 162 | regmap_write(dwsmscc->syscon, SPARX5_FORCE_VAL, ~0); |
| 163 | /* Allow settle */ |
| 164 | usleep_range(1, 5); |
| 165 | /* CS override drive disable */ |
| 166 | regmap_write(dwsmscc->syscon, SPARX5_FORCE_ENA, 0); |
| 167 | } |
| 168 | |
| 169 | dw_spi_set_cs(spi, enable); |
| 170 | } |
| 171 | |
| 172 | static int dw_spi_mscc_sparx5_init(struct platform_device *pdev, |
| 173 | struct dw_spi_mmio *dwsmmio) |
| 174 | { |
| 175 | const char *syscon_name = "microchip,sparx5-cpu-syscon"; |
| 176 | struct device *dev = &pdev->dev; |
| 177 | struct dw_spi_mscc *dwsmscc; |
| 178 | |
| 179 | if (!IS_ENABLED(CONFIG_SPI_MUX)) { |
| 180 | dev_err(dev, "This driver needs CONFIG_SPI_MUX\n"); |
| 181 | return -EOPNOTSUPP; |
| 182 | } |
| 183 | |
| 184 | dwsmscc = devm_kzalloc(dev, sizeof(*dwsmscc), GFP_KERNEL); |
| 185 | if (!dwsmscc) |
| 186 | return -ENOMEM; |
| 187 | |
| 188 | dwsmscc->syscon = |
| 189 | syscon_regmap_lookup_by_compatible(syscon_name); |
| 190 | if (IS_ERR(dwsmscc->syscon)) { |
| 191 | dev_err(dev, "No syscon map %s\n", syscon_name); |
| 192 | return PTR_ERR(dwsmscc->syscon); |
| 193 | } |
| 194 | |
| 195 | dwsmmio->dws.set_cs = dw_spi_sparx5_set_cs; |
| 196 | dwsmmio->priv = dwsmscc; |
| 197 | |
| 198 | /* Register hook to configure CTRLR0 */ |
| 199 | dwsmmio->dws.update_cr0 = dw_spi_update_cr0; |
| 200 | |
| 201 | return 0; |
| 202 | } |
| 203 | |
Talel Shenhar | f2d7047 | 2018-10-11 14:20:07 +0300 | [diff] [blame] | 204 | static int dw_spi_alpine_init(struct platform_device *pdev, |
| 205 | struct dw_spi_mmio *dwsmmio) |
| 206 | { |
| 207 | dwsmmio->dws.cs_override = 1; |
| 208 | |
Wan Ahmad Zainie | c4eadee | 2020-05-05 21:06:13 +0800 | [diff] [blame] | 209 | /* Register hook to configure CTRLR0 */ |
| 210 | dwsmmio->dws.update_cr0 = dw_spi_update_cr0; |
| 211 | |
| 212 | return 0; |
| 213 | } |
| 214 | |
| 215 | static int dw_spi_dw_apb_init(struct platform_device *pdev, |
| 216 | struct dw_spi_mmio *dwsmmio) |
| 217 | { |
| 218 | /* Register hook to configure CTRLR0 */ |
| 219 | dwsmmio->dws.update_cr0 = dw_spi_update_cr0; |
| 220 | |
Serge Semin | 0fdad59 | 2020-05-29 16:12:03 +0300 | [diff] [blame] | 221 | dw_spi_dma_setup_generic(&dwsmmio->dws); |
| 222 | |
Talel Shenhar | f2d7047 | 2018-10-11 14:20:07 +0300 | [diff] [blame] | 223 | return 0; |
| 224 | } |
| 225 | |
Wan Ahmad Zainie | e539f43 | 2020-05-05 21:06:14 +0800 | [diff] [blame] | 226 | static int dw_spi_dwc_ssi_init(struct platform_device *pdev, |
| 227 | struct dw_spi_mmio *dwsmmio) |
| 228 | { |
| 229 | /* Register hook to configure CTRLR0 */ |
| 230 | dwsmmio->dws.update_cr0 = dw_spi_update_cr0_v1_01a; |
| 231 | |
Serge Semin | 0fdad59 | 2020-05-29 16:12:03 +0300 | [diff] [blame] | 232 | dw_spi_dma_setup_generic(&dwsmmio->dws); |
| 233 | |
Wan Ahmad Zainie | e539f43 | 2020-05-05 21:06:14 +0800 | [diff] [blame] | 234 | return 0; |
| 235 | } |
| 236 | |
Wan Ahmad Zainie | f423779 | 2020-05-05 21:06:16 +0800 | [diff] [blame] | 237 | static u32 dw_spi_update_cr0_keembay(struct spi_controller *master, |
| 238 | struct spi_device *spi, |
| 239 | struct spi_transfer *transfer) |
| 240 | { |
| 241 | u32 cr0 = dw_spi_update_cr0_v1_01a(master, spi, transfer); |
| 242 | |
| 243 | return cr0 | KEEMBAY_CTRLR0_SSIC_IS_MST; |
| 244 | } |
| 245 | |
| 246 | static int dw_spi_keembay_init(struct platform_device *pdev, |
| 247 | struct dw_spi_mmio *dwsmmio) |
| 248 | { |
| 249 | /* Register hook to configure CTRLR0 */ |
| 250 | dwsmmio->dws.update_cr0 = dw_spi_update_cr0_keembay; |
| 251 | |
| 252 | return 0; |
| 253 | } |
| 254 | |
Grant Likely | fd4a319 | 2012-12-07 16:57:14 +0000 | [diff] [blame] | 255 | static int dw_spi_mmio_probe(struct platform_device *pdev) |
Jean-Hugues Deschenes | f7b6fd6 | 2010-01-21 07:46:42 -0700 | [diff] [blame] | 256 | { |
Alexandre Belloni | c2c25cc | 2018-07-27 21:53:56 +0200 | [diff] [blame] | 257 | int (*init_func)(struct platform_device *pdev, |
| 258 | struct dw_spi_mmio *dwsmmio); |
Jean-Hugues Deschenes | f7b6fd6 | 2010-01-21 07:46:42 -0700 | [diff] [blame] | 259 | struct dw_spi_mmio *dwsmmio; |
Serge Semin | 77810d4 | 2020-05-15 13:47:50 +0300 | [diff] [blame] | 260 | struct resource *mem; |
Jean-Hugues Deschenes | f7b6fd6 | 2010-01-21 07:46:42 -0700 | [diff] [blame] | 261 | struct dw_spi *dws; |
Jean-Hugues Deschenes | f7b6fd6 | 2010-01-21 07:46:42 -0700 | [diff] [blame] | 262 | int ret; |
Steffen Trumtrar | 22dae17 | 2014-06-13 15:36:18 +0200 | [diff] [blame] | 263 | int num_cs; |
Jean-Hugues Deschenes | f7b6fd6 | 2010-01-21 07:46:42 -0700 | [diff] [blame] | 264 | |
Baruch Siach | 04f421e | 2013-12-30 20:30:44 +0200 | [diff] [blame] | 265 | dwsmmio = devm_kzalloc(&pdev->dev, sizeof(struct dw_spi_mmio), |
| 266 | GFP_KERNEL); |
| 267 | if (!dwsmmio) |
| 268 | return -ENOMEM; |
Jean-Hugues Deschenes | f7b6fd6 | 2010-01-21 07:46:42 -0700 | [diff] [blame] | 269 | |
| 270 | dws = &dwsmmio->dws; |
| 271 | |
| 272 | /* Get basic io resource and map it */ |
Serge Semin | 77810d4 | 2020-05-15 13:47:50 +0300 | [diff] [blame] | 273 | dws->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &mem); |
Andy Shevchenko | afb7f565 | 2020-05-12 14:03:15 +0300 | [diff] [blame] | 274 | if (IS_ERR(dws->regs)) |
Baruch Siach | 04f421e | 2013-12-30 20:30:44 +0200 | [diff] [blame] | 275 | return PTR_ERR(dws->regs); |
Jean-Hugues Deschenes | f7b6fd6 | 2010-01-21 07:46:42 -0700 | [diff] [blame] | 276 | |
Serge Semin | 77810d4 | 2020-05-15 13:47:50 +0300 | [diff] [blame] | 277 | dws->paddr = mem->start; |
| 278 | |
Jean-Hugues Deschenes | f7b6fd6 | 2010-01-21 07:46:42 -0700 | [diff] [blame] | 279 | dws->irq = platform_get_irq(pdev, 0); |
Stephen Boyd | 6b8ac10 | 2019-07-30 11:15:41 -0700 | [diff] [blame] | 280 | if (dws->irq < 0) |
Baruch Siach | 04f421e | 2013-12-30 20:30:44 +0200 | [diff] [blame] | 281 | return dws->irq; /* -ENXIO */ |
Jean-Hugues Deschenes | f7b6fd6 | 2010-01-21 07:46:42 -0700 | [diff] [blame] | 282 | |
Baruch Siach | 04f421e | 2013-12-30 20:30:44 +0200 | [diff] [blame] | 283 | dwsmmio->clk = devm_clk_get(&pdev->dev, NULL); |
| 284 | if (IS_ERR(dwsmmio->clk)) |
| 285 | return PTR_ERR(dwsmmio->clk); |
Baruch Siach | 020fe3f | 2013-12-30 20:30:45 +0200 | [diff] [blame] | 286 | ret = clk_prepare_enable(dwsmmio->clk); |
Baruch Siach | 04f421e | 2013-12-30 20:30:44 +0200 | [diff] [blame] | 287 | if (ret) |
| 288 | return ret; |
Jean-Hugues Deschenes | f7b6fd6 | 2010-01-21 07:46:42 -0700 | [diff] [blame] | 289 | |
Phil Edworthy | 560ee7e | 2019-03-19 15:52:07 +0000 | [diff] [blame] | 290 | /* Optional clock needed to access the registers */ |
| 291 | dwsmmio->pclk = devm_clk_get_optional(&pdev->dev, "pclk"); |
Andy Shevchenko | 3da9834 | 2019-07-10 14:42:43 +0300 | [diff] [blame] | 292 | if (IS_ERR(dwsmmio->pclk)) { |
| 293 | ret = PTR_ERR(dwsmmio->pclk); |
| 294 | goto out_clk; |
| 295 | } |
Phil Edworthy | 560ee7e | 2019-03-19 15:52:07 +0000 | [diff] [blame] | 296 | ret = clk_prepare_enable(dwsmmio->pclk); |
| 297 | if (ret) |
| 298 | goto out_clk; |
| 299 | |
Dinh Nguyen | 7830c0e | 2020-05-29 10:58:05 -0500 | [diff] [blame] | 300 | /* find an optional reset controller */ |
| 301 | dwsmmio->rstc = devm_reset_control_get_optional_exclusive(&pdev->dev, "spi"); |
| 302 | if (IS_ERR(dwsmmio->rstc)) { |
| 303 | ret = PTR_ERR(dwsmmio->rstc); |
| 304 | goto out_clk; |
| 305 | } |
| 306 | reset_control_deassert(dwsmmio->rstc); |
| 307 | |
Baruch Siach | 2418991e | 2014-01-26 10:14:32 +0200 | [diff] [blame] | 308 | dws->bus_num = pdev->id; |
Steffen Trumtrar | 22dae17 | 2014-06-13 15:36:18 +0200 | [diff] [blame] | 309 | |
Jean-Hugues Deschenes | f7b6fd6 | 2010-01-21 07:46:42 -0700 | [diff] [blame] | 310 | dws->max_freq = clk_get_rate(dwsmmio->clk); |
| 311 | |
Andy Shevchenko | 9899995 | 2015-10-14 23:12:25 +0300 | [diff] [blame] | 312 | device_property_read_u32(&pdev->dev, "reg-io-width", &dws->reg_io_width); |
Michael van der Westhuizen | c4fe57f | 2015-08-18 22:21:53 +0200 | [diff] [blame] | 313 | |
Steffen Trumtrar | 22dae17 | 2014-06-13 15:36:18 +0200 | [diff] [blame] | 314 | num_cs = 4; |
| 315 | |
Andy Shevchenko | 9899995 | 2015-10-14 23:12:25 +0300 | [diff] [blame] | 316 | device_property_read_u32(&pdev->dev, "num-cs", &num_cs); |
Steffen Trumtrar | 22dae17 | 2014-06-13 15:36:18 +0200 | [diff] [blame] | 317 | |
| 318 | dws->num_cs = num_cs; |
| 319 | |
Alexandre Belloni | c2c25cc | 2018-07-27 21:53:56 +0200 | [diff] [blame] | 320 | init_func = device_get_match_data(&pdev->dev); |
| 321 | if (init_func) { |
| 322 | ret = init_func(pdev, dwsmmio); |
| 323 | if (ret) |
| 324 | goto out; |
| 325 | } |
| 326 | |
Jarkko Nikula | b9fc2d2 | 2019-10-18 16:21:29 +0300 | [diff] [blame] | 327 | pm_runtime_enable(&pdev->dev); |
| 328 | |
Baruch Siach | 04f421e | 2013-12-30 20:30:44 +0200 | [diff] [blame] | 329 | ret = dw_spi_add_host(&pdev->dev, dws); |
Jean-Hugues Deschenes | f7b6fd6 | 2010-01-21 07:46:42 -0700 | [diff] [blame] | 330 | if (ret) |
Baruch Siach | 04f421e | 2013-12-30 20:30:44 +0200 | [diff] [blame] | 331 | goto out; |
Jean-Hugues Deschenes | f7b6fd6 | 2010-01-21 07:46:42 -0700 | [diff] [blame] | 332 | |
| 333 | platform_set_drvdata(pdev, dwsmmio); |
| 334 | return 0; |
| 335 | |
Baruch Siach | 04f421e | 2013-12-30 20:30:44 +0200 | [diff] [blame] | 336 | out: |
Jarkko Nikula | b9fc2d2 | 2019-10-18 16:21:29 +0300 | [diff] [blame] | 337 | pm_runtime_disable(&pdev->dev); |
Phil Edworthy | 560ee7e | 2019-03-19 15:52:07 +0000 | [diff] [blame] | 338 | clk_disable_unprepare(dwsmmio->pclk); |
| 339 | out_clk: |
Baruch Siach | 020fe3f | 2013-12-30 20:30:45 +0200 | [diff] [blame] | 340 | clk_disable_unprepare(dwsmmio->clk); |
Dinh Nguyen | 7830c0e | 2020-05-29 10:58:05 -0500 | [diff] [blame] | 341 | reset_control_assert(dwsmmio->rstc); |
| 342 | |
Jean-Hugues Deschenes | f7b6fd6 | 2010-01-21 07:46:42 -0700 | [diff] [blame] | 343 | return ret; |
| 344 | } |
| 345 | |
Grant Likely | fd4a319 | 2012-12-07 16:57:14 +0000 | [diff] [blame] | 346 | static int dw_spi_mmio_remove(struct platform_device *pdev) |
Jean-Hugues Deschenes | f7b6fd6 | 2010-01-21 07:46:42 -0700 | [diff] [blame] | 347 | { |
| 348 | struct dw_spi_mmio *dwsmmio = platform_get_drvdata(pdev); |
Jean-Hugues Deschenes | f7b6fd6 | 2010-01-21 07:46:42 -0700 | [diff] [blame] | 349 | |
Jean-Hugues Deschenes | f7b6fd6 | 2010-01-21 07:46:42 -0700 | [diff] [blame] | 350 | dw_spi_remove_host(&dwsmmio->dws); |
Jarkko Nikula | b9fc2d2 | 2019-10-18 16:21:29 +0300 | [diff] [blame] | 351 | pm_runtime_disable(&pdev->dev); |
Phil Edworthy | 560ee7e | 2019-03-19 15:52:07 +0000 | [diff] [blame] | 352 | clk_disable_unprepare(dwsmmio->pclk); |
Marek Vasut | 400c18e | 2017-04-18 20:09:06 +0200 | [diff] [blame] | 353 | clk_disable_unprepare(dwsmmio->clk); |
Dinh Nguyen | 7830c0e | 2020-05-29 10:58:05 -0500 | [diff] [blame] | 354 | reset_control_assert(dwsmmio->rstc); |
Jean-Hugues Deschenes | f7b6fd6 | 2010-01-21 07:46:42 -0700 | [diff] [blame] | 355 | |
Jean-Hugues Deschenes | f7b6fd6 | 2010-01-21 07:46:42 -0700 | [diff] [blame] | 356 | return 0; |
| 357 | } |
| 358 | |
Steffen Trumtrar | 22dae17 | 2014-06-13 15:36:18 +0200 | [diff] [blame] | 359 | static const struct of_device_id dw_spi_mmio_of_match[] = { |
Wan Ahmad Zainie | c4eadee | 2020-05-05 21:06:13 +0800 | [diff] [blame] | 360 | { .compatible = "snps,dw-apb-ssi", .data = dw_spi_dw_apb_init}, |
Alexandre Belloni | be17ee0 | 2018-08-29 14:45:48 +0200 | [diff] [blame] | 361 | { .compatible = "mscc,ocelot-spi", .data = dw_spi_mscc_ocelot_init}, |
| 362 | { .compatible = "mscc,jaguar2-spi", .data = dw_spi_mscc_jaguar2_init}, |
Talel Shenhar | f2d7047 | 2018-10-11 14:20:07 +0300 | [diff] [blame] | 363 | { .compatible = "amazon,alpine-dw-apb-ssi", .data = dw_spi_alpine_init}, |
Wan Ahmad Zainie | c4eadee | 2020-05-05 21:06:13 +0800 | [diff] [blame] | 364 | { .compatible = "renesas,rzn1-spi", .data = dw_spi_dw_apb_init}, |
Wan Ahmad Zainie | e539f43 | 2020-05-05 21:06:14 +0800 | [diff] [blame] | 365 | { .compatible = "snps,dwc-ssi-1.01a", .data = dw_spi_dwc_ssi_init}, |
Wan Ahmad Zainie | f423779 | 2020-05-05 21:06:16 +0800 | [diff] [blame] | 366 | { .compatible = "intel,keembay-ssi", .data = dw_spi_keembay_init}, |
Lars Povlsen | 53a0963 | 2020-08-24 22:30:06 +0200 | [diff] [blame^] | 367 | { .compatible = "microchip,sparx5-spi", dw_spi_mscc_sparx5_init}, |
Steffen Trumtrar | 22dae17 | 2014-06-13 15:36:18 +0200 | [diff] [blame] | 368 | { /* end of table */} |
| 369 | }; |
| 370 | MODULE_DEVICE_TABLE(of, dw_spi_mmio_of_match); |
| 371 | |
Jay Fang | 4dd227a | 2020-05-09 10:29:51 +0800 | [diff] [blame] | 372 | #ifdef CONFIG_ACPI |
Jay Fang | 32215a6 | 2018-12-03 11:15:50 +0800 | [diff] [blame] | 373 | static const struct acpi_device_id dw_spi_mmio_acpi_match[] = { |
Wan Ahmad Zainie | c4eadee | 2020-05-05 21:06:13 +0800 | [diff] [blame] | 374 | {"HISI0173", (kernel_ulong_t)dw_spi_dw_apb_init}, |
Jay Fang | 32215a6 | 2018-12-03 11:15:50 +0800 | [diff] [blame] | 375 | {}, |
| 376 | }; |
| 377 | MODULE_DEVICE_TABLE(acpi, dw_spi_mmio_acpi_match); |
Jay Fang | 4dd227a | 2020-05-09 10:29:51 +0800 | [diff] [blame] | 378 | #endif |
Jay Fang | 32215a6 | 2018-12-03 11:15:50 +0800 | [diff] [blame] | 379 | |
Jean-Hugues Deschenes | f7b6fd6 | 2010-01-21 07:46:42 -0700 | [diff] [blame] | 380 | static struct platform_driver dw_spi_mmio_driver = { |
Grant Likely | 940ab88 | 2011-10-05 11:29:49 -0600 | [diff] [blame] | 381 | .probe = dw_spi_mmio_probe, |
Grant Likely | fd4a319 | 2012-12-07 16:57:14 +0000 | [diff] [blame] | 382 | .remove = dw_spi_mmio_remove, |
Jean-Hugues Deschenes | f7b6fd6 | 2010-01-21 07:46:42 -0700 | [diff] [blame] | 383 | .driver = { |
| 384 | .name = DRIVER_NAME, |
Steffen Trumtrar | 22dae17 | 2014-06-13 15:36:18 +0200 | [diff] [blame] | 385 | .of_match_table = dw_spi_mmio_of_match, |
Jay Fang | 32215a6 | 2018-12-03 11:15:50 +0800 | [diff] [blame] | 386 | .acpi_match_table = ACPI_PTR(dw_spi_mmio_acpi_match), |
Jean-Hugues Deschenes | f7b6fd6 | 2010-01-21 07:46:42 -0700 | [diff] [blame] | 387 | }, |
| 388 | }; |
Grant Likely | 940ab88 | 2011-10-05 11:29:49 -0600 | [diff] [blame] | 389 | module_platform_driver(dw_spi_mmio_driver); |
Jean-Hugues Deschenes | f7b6fd6 | 2010-01-21 07:46:42 -0700 | [diff] [blame] | 390 | |
| 391 | MODULE_AUTHOR("Jean-Hugues Deschenes <jean-hugues.deschenes@octasic.com>"); |
| 392 | MODULE_DESCRIPTION("Memory-mapped I/O interface driver for DW SPI Core"); |
| 393 | MODULE_LICENSE("GPL v2"); |