20
20
#include <linux/of.h>
21
21
#include <linux/platform_device.h>
22
22
#include <linux/stmp_device.h>
23
+ #include <linux/clk.h>
23
24
24
25
#include <crypto/aes.h>
25
26
#include <crypto/sha.h>
@@ -82,6 +83,7 @@ struct dcp {
82
83
spinlock_t lock [DCP_MAX_CHANS ];
83
84
struct task_struct * thread [DCP_MAX_CHANS ];
84
85
struct crypto_queue queue [DCP_MAX_CHANS ];
86
+ struct clk * dcp_clk ;
85
87
};
86
88
87
89
enum dcp_chan {
@@ -1053,11 +1055,24 @@ static int mxs_dcp_probe(struct platform_device *pdev)
1053
1055
/* Re-align the structure so it fits the DCP constraints. */
1054
1056
sdcp -> coh = PTR_ALIGN (sdcp -> coh , DCP_ALIGNMENT );
1055
1057
1056
- /* Restart the DCP block. */
1057
- ret = stmp_reset_block (sdcp -> base );
1058
+ /* DCP clock is optional, only used on some SOCs */
1059
+ sdcp -> dcp_clk = devm_clk_get (dev , "dcp" );
1060
+ if (IS_ERR (sdcp -> dcp_clk )) {
1061
+ if (sdcp -> dcp_clk != ERR_PTR (- ENOENT ))
1062
+ return PTR_ERR (sdcp -> dcp_clk );
1063
+ sdcp -> dcp_clk = NULL ;
1064
+ }
1065
+ ret = clk_prepare_enable (sdcp -> dcp_clk );
1058
1066
if (ret )
1059
1067
return ret ;
1060
1068
1069
+ /* Restart the DCP block. */
1070
+ ret = stmp_reset_block (sdcp -> base );
1071
+ if (ret ) {
1072
+ dev_err (dev , "Failed reset\n" );
1073
+ goto err_disable_unprepare_clk ;
1074
+ }
1075
+
1061
1076
/* Initialize control register. */
1062
1077
writel (MXS_DCP_CTRL_GATHER_RESIDUAL_WRITES |
1063
1078
MXS_DCP_CTRL_ENABLE_CONTEXT_CACHING | 0xf ,
@@ -1094,7 +1109,8 @@ static int mxs_dcp_probe(struct platform_device *pdev)
1094
1109
NULL , "mxs_dcp_chan/sha" );
1095
1110
if (IS_ERR (sdcp -> thread [DCP_CHAN_HASH_SHA ])) {
1096
1111
dev_err (dev , "Error starting SHA thread!\n" );
1097
- return PTR_ERR (sdcp -> thread [DCP_CHAN_HASH_SHA ]);
1112
+ ret = PTR_ERR (sdcp -> thread [DCP_CHAN_HASH_SHA ]);
1113
+ goto err_disable_unprepare_clk ;
1098
1114
}
1099
1115
1100
1116
sdcp -> thread [DCP_CHAN_CRYPTO ] = kthread_run (dcp_chan_thread_aes ,
@@ -1151,6 +1167,10 @@ static int mxs_dcp_probe(struct platform_device *pdev)
1151
1167
1152
1168
err_destroy_sha_thread :
1153
1169
kthread_stop (sdcp -> thread [DCP_CHAN_HASH_SHA ]);
1170
+
1171
+ err_disable_unprepare_clk :
1172
+ clk_disable_unprepare (sdcp -> dcp_clk );
1173
+
1154
1174
return ret ;
1155
1175
}
1156
1176
@@ -1170,6 +1190,8 @@ static int mxs_dcp_remove(struct platform_device *pdev)
1170
1190
kthread_stop (sdcp -> thread [DCP_CHAN_HASH_SHA ]);
1171
1191
kthread_stop (sdcp -> thread [DCP_CHAN_CRYPTO ]);
1172
1192
1193
+ clk_disable_unprepare (sdcp -> dcp_clk );
1194
+
1173
1195
platform_set_drvdata (pdev , NULL );
1174
1196
1175
1197
global_sdcp = NULL ;
0 commit comments