diff options
author | Horia Geantă <horia.geanta@nxp.com> | 2017-09-01 10:12:59 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2017-09-20 05:42:42 -0400 |
commit | c056d910f08029662080a01b4ce2110e2c9a27b6 (patch) | |
tree | f55aca2a86234afe0c0cfdafb0df23c758da50a9 | |
parent | 3e1166b94e661ed51af1fe1fe5f74bd83450b50f (diff) |
crypto: caam - fix LS1021A support on ARMv7 multiplatform kernel
When built using multi_v7_defconfig, driver does not work on LS1021A:
[...]
caam 1700000.crypto: can't identify CAAM ipg clk: -2
caam: probe of 1700000.crypto failed with error -2
[...]
It turns out we have to detect at runtime whether driver is running
on an i.MX platform or not.
Cc: <stable@vger.kernel.org>
Fixes: 6c3af9559352 ("crypto: caam - add support for LS1021A")
Signed-off-by: Horia Geantă <horia.geanta@nxp.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r-- | drivers/crypto/caam/Kconfig | 5 | ||||
-rw-r--r-- | drivers/crypto/caam/ctrl.c | 19 | ||||
-rw-r--r-- | drivers/crypto/caam/regs.h | 59 |
3 files changed, 39 insertions, 44 deletions
diff --git a/drivers/crypto/caam/Kconfig b/drivers/crypto/caam/Kconfig index e36aeacd7635..1eb852765469 100644 --- a/drivers/crypto/caam/Kconfig +++ b/drivers/crypto/caam/Kconfig | |||
@@ -1,6 +1,7 @@ | |||
1 | config CRYPTO_DEV_FSL_CAAM | 1 | config CRYPTO_DEV_FSL_CAAM |
2 | tristate "Freescale CAAM-Multicore driver backend" | 2 | tristate "Freescale CAAM-Multicore driver backend" |
3 | depends on FSL_SOC || ARCH_MXC || ARCH_LAYERSCAPE | 3 | depends on FSL_SOC || ARCH_MXC || ARCH_LAYERSCAPE |
4 | select SOC_BUS | ||
4 | help | 5 | help |
5 | Enables the driver module for Freescale's Cryptographic Accelerator | 6 | Enables the driver module for Freescale's Cryptographic Accelerator |
6 | and Assurance Module (CAAM), also known as the SEC version 4 (SEC4). | 7 | and Assurance Module (CAAM), also known as the SEC version 4 (SEC4). |
@@ -141,10 +142,6 @@ config CRYPTO_DEV_FSL_CAAM_RNG_API | |||
141 | To compile this as a module, choose M here: the module | 142 | To compile this as a module, choose M here: the module |
142 | will be called caamrng. | 143 | will be called caamrng. |
143 | 144 | ||
144 | config CRYPTO_DEV_FSL_CAAM_IMX | ||
145 | def_bool SOC_IMX6 || SOC_IMX7D | ||
146 | depends on CRYPTO_DEV_FSL_CAAM | ||
147 | |||
148 | config CRYPTO_DEV_FSL_CAAM_DEBUG | 145 | config CRYPTO_DEV_FSL_CAAM_DEBUG |
149 | bool "Enable debug output in CAAM driver" | 146 | bool "Enable debug output in CAAM driver" |
150 | depends on CRYPTO_DEV_FSL_CAAM | 147 | depends on CRYPTO_DEV_FSL_CAAM |
diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c index dacb53fb690e..027e121c6f70 100644 --- a/drivers/crypto/caam/ctrl.c +++ b/drivers/crypto/caam/ctrl.c | |||
@@ -7,6 +7,7 @@ | |||
7 | #include <linux/device.h> | 7 | #include <linux/device.h> |
8 | #include <linux/of_address.h> | 8 | #include <linux/of_address.h> |
9 | #include <linux/of_irq.h> | 9 | #include <linux/of_irq.h> |
10 | #include <linux/sys_soc.h> | ||
10 | 11 | ||
11 | #include "compat.h" | 12 | #include "compat.h" |
12 | #include "regs.h" | 13 | #include "regs.h" |
@@ -19,6 +20,8 @@ bool caam_little_end; | |||
19 | EXPORT_SYMBOL(caam_little_end); | 20 | EXPORT_SYMBOL(caam_little_end); |
20 | bool caam_dpaa2; | 21 | bool caam_dpaa2; |
21 | EXPORT_SYMBOL(caam_dpaa2); | 22 | EXPORT_SYMBOL(caam_dpaa2); |
23 | bool caam_imx; | ||
24 | EXPORT_SYMBOL(caam_imx); | ||
22 | 25 | ||
23 | #ifdef CONFIG_CAAM_QI | 26 | #ifdef CONFIG_CAAM_QI |
24 | #include "qi.h" | 27 | #include "qi.h" |
@@ -28,19 +31,11 @@ EXPORT_SYMBOL(caam_dpaa2); | |||
28 | * i.MX targets tend to have clock control subsystems that can | 31 | * i.MX targets tend to have clock control subsystems that can |
29 | * enable/disable clocking to our device. | 32 | * enable/disable clocking to our device. |
30 | */ | 33 | */ |
31 | #ifdef CONFIG_CRYPTO_DEV_FSL_CAAM_IMX | ||
32 | static inline struct clk *caam_drv_identify_clk(struct device *dev, | 34 | static inline struct clk *caam_drv_identify_clk(struct device *dev, |
33 | char *clk_name) | 35 | char *clk_name) |
34 | { | 36 | { |
35 | return devm_clk_get(dev, clk_name); | 37 | return caam_imx ? devm_clk_get(dev, clk_name) : NULL; |
36 | } | 38 | } |
37 | #else | ||
38 | static inline struct clk *caam_drv_identify_clk(struct device *dev, | ||
39 | char *clk_name) | ||
40 | { | ||
41 | return NULL; | ||
42 | } | ||
43 | #endif | ||
44 | 39 | ||
45 | /* | 40 | /* |
46 | * Descriptor to instantiate RNG State Handle 0 in normal mode and | 41 | * Descriptor to instantiate RNG State Handle 0 in normal mode and |
@@ -430,6 +425,10 @@ static int caam_probe(struct platform_device *pdev) | |||
430 | { | 425 | { |
431 | int ret, ring, gen_sk, ent_delay = RTSDCTL_ENT_DLY_MIN; | 426 | int ret, ring, gen_sk, ent_delay = RTSDCTL_ENT_DLY_MIN; |
432 | u64 caam_id; | 427 | u64 caam_id; |
428 | static const struct soc_device_attribute imx_soc[] = { | ||
429 | {.family = "Freescale i.MX"}, | ||
430 | {}, | ||
431 | }; | ||
433 | struct device *dev; | 432 | struct device *dev; |
434 | struct device_node *nprop, *np; | 433 | struct device_node *nprop, *np; |
435 | struct caam_ctrl __iomem *ctrl; | 434 | struct caam_ctrl __iomem *ctrl; |
@@ -451,6 +450,8 @@ static int caam_probe(struct platform_device *pdev) | |||
451 | dev_set_drvdata(dev, ctrlpriv); | 450 | dev_set_drvdata(dev, ctrlpriv); |
452 | nprop = pdev->dev.of_node; | 451 | nprop = pdev->dev.of_node; |
453 | 452 | ||
453 | caam_imx = (bool)soc_device_match(imx_soc); | ||
454 | |||
454 | /* Enable clocking */ | 455 | /* Enable clocking */ |
455 | clk = caam_drv_identify_clk(&pdev->dev, "ipg"); | 456 | clk = caam_drv_identify_clk(&pdev->dev, "ipg"); |
456 | if (IS_ERR(clk)) { | 457 | if (IS_ERR(clk)) { |
diff --git a/drivers/crypto/caam/regs.h b/drivers/crypto/caam/regs.h index 2b5efff9ec3c..17cfd23a38fa 100644 --- a/drivers/crypto/caam/regs.h +++ b/drivers/crypto/caam/regs.h | |||
@@ -67,6 +67,7 @@ | |||
67 | */ | 67 | */ |
68 | 68 | ||
69 | extern bool caam_little_end; | 69 | extern bool caam_little_end; |
70 | extern bool caam_imx; | ||
70 | 71 | ||
71 | #define caam_to_cpu(len) \ | 72 | #define caam_to_cpu(len) \ |
72 | static inline u##len caam##len ## _to_cpu(u##len val) \ | 73 | static inline u##len caam##len ## _to_cpu(u##len val) \ |
@@ -154,13 +155,10 @@ static inline u64 rd_reg64(void __iomem *reg) | |||
154 | #else /* CONFIG_64BIT */ | 155 | #else /* CONFIG_64BIT */ |
155 | static inline void wr_reg64(void __iomem *reg, u64 data) | 156 | static inline void wr_reg64(void __iomem *reg, u64 data) |
156 | { | 157 | { |
157 | #ifndef CONFIG_CRYPTO_DEV_FSL_CAAM_IMX | 158 | if (!caam_imx && caam_little_end) { |
158 | if (caam_little_end) { | ||
159 | wr_reg32((u32 __iomem *)(reg) + 1, data >> 32); | 159 | wr_reg32((u32 __iomem *)(reg) + 1, data >> 32); |
160 | wr_reg32((u32 __iomem *)(reg), data); | 160 | wr_reg32((u32 __iomem *)(reg), data); |
161 | } else | 161 | } else { |
162 | #endif | ||
163 | { | ||
164 | wr_reg32((u32 __iomem *)(reg), data >> 32); | 162 | wr_reg32((u32 __iomem *)(reg), data >> 32); |
165 | wr_reg32((u32 __iomem *)(reg) + 1, data); | 163 | wr_reg32((u32 __iomem *)(reg) + 1, data); |
166 | } | 164 | } |
@@ -168,41 +166,40 @@ static inline void wr_reg64(void __iomem *reg, u64 data) | |||
168 | 166 | ||
169 | static inline u64 rd_reg64(void __iomem *reg) | 167 | static inline u64 rd_reg64(void __iomem *reg) |
170 | { | 168 | { |
171 | #ifndef CONFIG_CRYPTO_DEV_FSL_CAAM_IMX | 169 | if (!caam_imx && caam_little_end) |
172 | if (caam_little_end) | ||
173 | return ((u64)rd_reg32((u32 __iomem *)(reg) + 1) << 32 | | 170 | return ((u64)rd_reg32((u32 __iomem *)(reg) + 1) << 32 | |
174 | (u64)rd_reg32((u32 __iomem *)(reg))); | 171 | (u64)rd_reg32((u32 __iomem *)(reg))); |
175 | else | 172 | |
176 | #endif | 173 | return ((u64)rd_reg32((u32 __iomem *)(reg)) << 32 | |
177 | return ((u64)rd_reg32((u32 __iomem *)(reg)) << 32 | | 174 | (u64)rd_reg32((u32 __iomem *)(reg) + 1)); |
178 | (u64)rd_reg32((u32 __iomem *)(reg) + 1)); | ||
179 | } | 175 | } |
180 | #endif /* CONFIG_64BIT */ | 176 | #endif /* CONFIG_64BIT */ |
181 | 177 | ||
178 | static inline u64 cpu_to_caam_dma64(dma_addr_t value) | ||
179 | { | ||
180 | if (caam_imx) | ||
181 | return (((u64)cpu_to_caam32(lower_32_bits(value)) << 32) | | ||
182 | (u64)cpu_to_caam32(upper_32_bits(value))); | ||
183 | |||
184 | return cpu_to_caam64(value); | ||
185 | } | ||
186 | |||
187 | static inline u64 caam_dma64_to_cpu(u64 value) | ||
188 | { | ||
189 | if (caam_imx) | ||
190 | return (((u64)caam32_to_cpu(lower_32_bits(value)) << 32) | | ||
191 | (u64)caam32_to_cpu(upper_32_bits(value))); | ||
192 | |||
193 | return caam64_to_cpu(value); | ||
194 | } | ||
195 | |||
182 | #ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT | 196 | #ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT |
183 | #ifdef CONFIG_SOC_IMX7D | 197 | #define cpu_to_caam_dma(value) cpu_to_caam_dma64(value) |
184 | #define cpu_to_caam_dma(value) \ | 198 | #define caam_dma_to_cpu(value) caam_dma64_to_cpu(value) |
185 | (((u64)cpu_to_caam32(lower_32_bits(value)) << 32) | \ | ||
186 | (u64)cpu_to_caam32(upper_32_bits(value))) | ||
187 | #define caam_dma_to_cpu(value) \ | ||
188 | (((u64)caam32_to_cpu(lower_32_bits(value)) << 32) | \ | ||
189 | (u64)caam32_to_cpu(upper_32_bits(value))) | ||
190 | #else | ||
191 | #define cpu_to_caam_dma(value) cpu_to_caam64(value) | ||
192 | #define caam_dma_to_cpu(value) caam64_to_cpu(value) | ||
193 | #endif /* CONFIG_SOC_IMX7D */ | ||
194 | #else | 199 | #else |
195 | #define cpu_to_caam_dma(value) cpu_to_caam32(value) | 200 | #define cpu_to_caam_dma(value) cpu_to_caam32(value) |
196 | #define caam_dma_to_cpu(value) caam32_to_cpu(value) | 201 | #define caam_dma_to_cpu(value) caam32_to_cpu(value) |
197 | #endif /* CONFIG_ARCH_DMA_ADDR_T_64BIT */ | 202 | #endif /* CONFIG_ARCH_DMA_ADDR_T_64BIT */ |
198 | |||
199 | #ifdef CONFIG_CRYPTO_DEV_FSL_CAAM_IMX | ||
200 | #define cpu_to_caam_dma64(value) \ | ||
201 | (((u64)cpu_to_caam32(lower_32_bits(value)) << 32) | \ | ||
202 | (u64)cpu_to_caam32(upper_32_bits(value))) | ||
203 | #else | ||
204 | #define cpu_to_caam_dma64(value) cpu_to_caam64(value) | ||
205 | #endif | ||
206 | 203 | ||
207 | /* | 204 | /* |
208 | * jr_outentry | 205 | * jr_outentry |