hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/spi/spi-imx.c
....@@ -242,6 +242,18 @@
242242 return true;
243243 }
244244
245
+/*
246
+ * Note the number of natively supported chip selects for MX51 is 4. Some
247
+ * devices may have less actual SS pins but the register map supports 4. When
248
+ * using gpio chip selects the cs values passed into the macros below can go
249
+ * outside the range 0 - 3. We therefore need to limit the cs value to avoid
250
+ * corrupting bits outside the allocated locations.
251
+ *
252
+ * The simplest way to do this is to just mask the cs bits to 2 bits. This
253
+ * still allows all 4 native chip selects to work as well as gpio chip selects
254
+ * (which can use any of the 4 chip select configurations).
255
+ */
256
+
245257 #define MX51_ECSPI_CTRL 0x08
246258 #define MX51_ECSPI_CTRL_ENABLE (1 << 0)
247259 #define MX51_ECSPI_CTRL_XCH (1 << 2)
....@@ -250,16 +262,16 @@
250262 #define MX51_ECSPI_CTRL_DRCTL(drctl) ((drctl) << 16)
251263 #define MX51_ECSPI_CTRL_POSTDIV_OFFSET 8
252264 #define MX51_ECSPI_CTRL_PREDIV_OFFSET 12
253
-#define MX51_ECSPI_CTRL_CS(cs) ((cs) << 18)
265
+#define MX51_ECSPI_CTRL_CS(cs) ((cs & 3) << 18)
254266 #define MX51_ECSPI_CTRL_BL_OFFSET 20
255267 #define MX51_ECSPI_CTRL_BL_MASK (0xfff << 20)
256268
257269 #define MX51_ECSPI_CONFIG 0x0c
258
-#define MX51_ECSPI_CONFIG_SCLKPHA(cs) (1 << ((cs) + 0))
259
-#define MX51_ECSPI_CONFIG_SCLKPOL(cs) (1 << ((cs) + 4))
260
-#define MX51_ECSPI_CONFIG_SBBCTRL(cs) (1 << ((cs) + 8))
261
-#define MX51_ECSPI_CONFIG_SSBPOL(cs) (1 << ((cs) + 12))
262
-#define MX51_ECSPI_CONFIG_SCLKCTL(cs) (1 << ((cs) + 20))
270
+#define MX51_ECSPI_CONFIG_SCLKPHA(cs) (1 << ((cs & 3) + 0))
271
+#define MX51_ECSPI_CONFIG_SCLKPOL(cs) (1 << ((cs & 3) + 4))
272
+#define MX51_ECSPI_CONFIG_SBBCTRL(cs) (1 << ((cs & 3) + 8))
273
+#define MX51_ECSPI_CONFIG_SSBPOL(cs) (1 << ((cs & 3) + 12))
274
+#define MX51_ECSPI_CONFIG_SCLKCTL(cs) (1 << ((cs & 3) + 20))
263275
264276 #define MX51_ECSPI_INT 0x10
265277 #define MX51_ECSPI_INT_TEEN (1 << 0)
....@@ -1554,9 +1566,8 @@
15541566 struct spi_imx_data *spi_imx = spi_master_get_devdata(master);
15551567 int ret;
15561568
1557
- ret = pm_runtime_get_sync(spi_imx->dev);
1569
+ ret = pm_runtime_resume_and_get(spi_imx->dev);
15581570 if (ret < 0) {
1559
- pm_runtime_put_noidle(spi_imx->dev);
15601571 dev_err(spi_imx->dev, "failed to enable clock\n");
15611572 return ret;
15621573 }
....@@ -1766,13 +1777,10 @@
17661777 spi_bitbang_stop(&spi_imx->bitbang);
17671778
17681779 ret = pm_runtime_get_sync(spi_imx->dev);
1769
- if (ret < 0) {
1770
- pm_runtime_put_noidle(spi_imx->dev);
1771
- dev_err(spi_imx->dev, "failed to enable clock\n");
1772
- return ret;
1773
- }
1774
-
1775
- writel(0, spi_imx->base + MXC_CSPICTRL);
1780
+ if (ret >= 0)
1781
+ writel(0, spi_imx->base + MXC_CSPICTRL);
1782
+ else
1783
+ dev_warn(spi_imx->dev, "failed to enable clock, skip hw disable\n");
17761784
17771785 pm_runtime_dont_use_autosuspend(spi_imx->dev);
17781786 pm_runtime_put_sync(spi_imx->dev);