blob: 47611e54c7089efe27d1cfb8152a0f7383131a94 [file] [log] [blame]
developer5d148cb2023-06-02 13:08:11 +08001From 8fc345d6238b0fb81f6737d21ca9d7efb1dd1489 Mon Sep 17 00:00:00 2001
2From: Sam Shih <sam.shih@mediatek.com>
3Date: Fri, 2 Jun 2023 13:06:20 +0800
4Subject: [PATCH]
5 [spi-and-storage][999-2371-drivers-spi-mt65xx-Move-chip_config-to-driver-priv.patch]
developer1fec6432022-06-23 18:49:35 +08006
developer1fec6432022-06-23 18:49:35 +08007---
8 drivers/spi/spi-mt65xx.c | 31 +++++++++++-------------
9 include/linux/platform_data/spi-mt65xx.h | 17 -------------
10 2 files changed, 14 insertions(+), 34 deletions(-)
11 delete mode 100644 include/linux/platform_data/spi-mt65xx.h
12
13diff --git a/drivers/spi/spi-mt65xx.c b/drivers/spi/spi-mt65xx.c
developer5d148cb2023-06-02 13:08:11 +080014index 83a2417a8..32a0b0264 100644
developer1fec6432022-06-23 18:49:35 +080015--- a/drivers/spi/spi-mt65xx.c
16+++ b/drivers/spi/spi-mt65xx.c
17@@ -14,7 +14,6 @@
18 #include <linux/of.h>
19 #include <linux/of_gpio.h>
20 #include <linux/platform_device.h>
21-#include <linux/platform_data/spi-mt65xx.h>
22 #include <linux/pm_runtime.h>
23 #include <linux/spi/spi.h>
24 #include <linux/spi/spi-mem.h>
25@@ -123,6 +122,11 @@ struct mtk_spi_compatible {
26 bool need_ahb_clk;
27 };
28
29+struct mtk_spi_config {
30+ u32 sample_sel;
31+ u32 get_tick_dly;
32+};
33+
34 struct mtk_spi {
35 void __iomem *base;
36 u32 state;
37@@ -135,6 +139,7 @@ struct mtk_spi {
38 struct scatterlist *tx_sgl, *rx_sgl;
39 u32 tx_sgl_len, rx_sgl_len;
40 const struct mtk_spi_compatible *dev_comp;
41+ struct mtk_spi_config dev_config;
42
43 struct completion spimem_done;
44 bool use_spimem;
45@@ -189,15 +194,6 @@ static const struct mtk_spi_compatible mt8183_compat = {
46 .enhance_timing = true,
47 };
48
49-/*
50- * A piece of default chip info unless the platform
51- * supplies it.
52- */
53-static const struct mtk_chip_config mtk_default_chip_info = {
54- .sample_sel = 0,
55- .get_tick_dly = 2,
56-};
57-
58 static const struct of_device_id mtk_spi_of_match[] = {
59 { .compatible = "mediatek,ipm-spi-single",
60 .data = (void *)&ipm_compat_single,
61@@ -255,7 +251,6 @@ static int mtk_spi_hw_init(struct spi_master *master,
62 {
63 u16 cpha, cpol;
64 u32 reg_val;
65- struct mtk_chip_config *chip_config = spi->controller_data;
66 struct mtk_spi *mdata = spi_master_get_devdata(master);
67
68 cpha = spi->mode & SPI_CPHA ? 1 : 0;
69@@ -270,13 +265,13 @@ static int mtk_spi_hw_init(struct spi_master *master,
70
71 reg_val = readl(mdata->base + SPI_CMD_REG);
72 reg_val &= ~SPI_CMD_IPM_GET_TICKDLY_MASK;
73- reg_val |= chip_config->get_tick_dly
74+ reg_val |= mdata->dev_config.get_tick_dly
75 << SPI_CMD_IPM_GET_TICKDLY_OFFSET;
76 writel(reg_val, mdata->base + SPI_CMD_REG);
77 } else {
78 reg_val = readl(mdata->base + SPI_CFG1_REG);
79 reg_val &= ~SPI_CFG1_GET_TICKDLY_MASK;
80- reg_val |= chip_config->get_tick_dly
81+ reg_val |= mdata->dev_config.get_tick_dly
82 << SPI_CFG1_GET_TICKDLY_OFFSET;
83 writel(reg_val, mdata->base + SPI_CFG1_REG);
84 }
85@@ -326,7 +321,7 @@ static int mtk_spi_hw_init(struct spi_master *master,
86 else
87 reg_val &= ~SPI_CMD_CS_POL;
88
89- if (chip_config->sample_sel)
90+ if (mdata->dev_config.sample_sel)
91 reg_val |= SPI_CMD_SAMPLE_SEL;
92 else
93 reg_val &= ~SPI_CMD_SAMPLE_SEL;
94@@ -623,9 +618,6 @@ static int mtk_spi_setup(struct spi_device *spi)
95 {
96 struct mtk_spi *mdata = spi_master_get_devdata(spi->master);
97
98- if (!spi->controller_data)
99- spi->controller_data = (void *)&mtk_default_chip_info;
100-
101 if (mdata->dev_comp->need_pad_sel && gpio_is_valid(spi->cs_gpio))
102 gpio_direction_output(spi->cs_gpio, !(spi->mode & SPI_CS_HIGH));
103
104@@ -1025,6 +1017,11 @@ static int mtk_spi_probe(struct platform_device *pdev)
105 }
106
107 mdata = spi_master_get_devdata(master);
108+
109+ /* Set device configs to default first. Calibrate it later. */
110+ mdata->dev_config.sample_sel = 0;
111+ mdata->dev_config.get_tick_dly = 2;
112+
113 mdata->dev_comp = of_id->data;
114
115 if (mdata->dev_comp->enhance_timing)
116diff --git a/include/linux/platform_data/spi-mt65xx.h b/include/linux/platform_data/spi-mt65xx.h
117deleted file mode 100644
118index fae9bc15c..000000000
119--- a/include/linux/platform_data/spi-mt65xx.h
120+++ /dev/null
121@@ -1,17 +0,0 @@
122-/* SPDX-License-Identifier: GPL-2.0-only */
123-/*
124- * MTK SPI bus driver definitions
125- *
126- * Copyright (c) 2015 MediaTek Inc.
127- * Author: Leilk Liu <leilk.liu@mediatek.com>
128- */
129-
130-#ifndef ____LINUX_PLATFORM_DATA_SPI_MTK_H
131-#define ____LINUX_PLATFORM_DATA_SPI_MTK_H
132-
133-/* Board specific platform_data */
134-struct mtk_chip_config {
135- u32 sample_sel;
136- u32 get_tick_dly;
137-};
138-#endif
139--
developer5d148cb2023-06-02 13:08:11 +08001402.34.1
developer1fec6432022-06-23 18:49:35 +0800141