| .. | .. |
|---|
| 8 | 8 | #include <crypto.h> |
|---|
| 9 | 9 | #include <dm.h> |
|---|
| 10 | 10 | #include <asm/io.h> |
|---|
| 11 | +#include <clk-uclass.h> |
|---|
| 11 | 12 | #include <asm/arch/hardware.h> |
|---|
| 12 | 13 | #include <asm/arch/clock.h> |
|---|
| 13 | 14 | #include <rockchip/crypto_hash_cache.h> |
|---|
| .. | .. |
|---|
| 54 | 55 | char *clocks; |
|---|
| 55 | 56 | u32 *frequencies; |
|---|
| 56 | 57 | u32 nclocks; |
|---|
| 58 | + u32 freq_nclocks; |
|---|
| 57 | 59 | u32 length; |
|---|
| 58 | 60 | struct rk_hash_ctx *hw_ctx; |
|---|
| 59 | 61 | struct rk_crypto_soc_data *soc_data; |
|---|
| .. | .. |
|---|
| 217 | 219 | |
|---|
| 218 | 220 | for (i = 0; i < tag_len / 4; i++, chn_base += 4) |
|---|
| 219 | 221 | word2byte_be(crypto_read(chn_base), tag + 4 * i); |
|---|
| 222 | +} |
|---|
| 223 | + |
|---|
| 224 | +static int rk_crypto_do_enable_clk(struct udevice *dev, int enable) |
|---|
| 225 | +{ |
|---|
| 226 | + struct rockchip_crypto_priv *priv = dev_get_priv(dev); |
|---|
| 227 | + struct clk clk; |
|---|
| 228 | + int i, ret; |
|---|
| 229 | + |
|---|
| 230 | + for (i = 0; i < priv->nclocks; i++) { |
|---|
| 231 | + ret = clk_get_by_index(dev, i, &clk); |
|---|
| 232 | + if (ret < 0) { |
|---|
| 233 | + printf("Failed to get clk index %d, ret=%d\n", i, ret); |
|---|
| 234 | + return ret; |
|---|
| 235 | + } |
|---|
| 236 | + |
|---|
| 237 | + if (enable) |
|---|
| 238 | + ret = clk_enable(&clk); |
|---|
| 239 | + else |
|---|
| 240 | + ret = clk_disable(&clk); |
|---|
| 241 | + if (ret < 0 && ret != -ENOSYS) { |
|---|
| 242 | + printf("Failed to enable(%d) clk(%ld): ret=%d\n", |
|---|
| 243 | + enable, clk.id, ret); |
|---|
| 244 | + return ret; |
|---|
| 245 | + } |
|---|
| 246 | + } |
|---|
| 247 | + |
|---|
| 248 | + return 0; |
|---|
| 249 | +} |
|---|
| 250 | + |
|---|
| 251 | +static int rk_crypto_enable_clk(struct udevice *dev) |
|---|
| 252 | +{ |
|---|
| 253 | + return rk_crypto_do_enable_clk(dev, 1); |
|---|
| 254 | +} |
|---|
| 255 | + |
|---|
| 256 | +static int rk_crypto_disable_clk(struct udevice *dev) |
|---|
| 257 | +{ |
|---|
| 258 | + return rk_crypto_do_enable_clk(dev, 0); |
|---|
| 220 | 259 | } |
|---|
| 221 | 260 | |
|---|
| 222 | 261 | static u32 crypto_v3_dynamic_cap(void) |
|---|
| .. | .. |
|---|
| 397 | 436 | |
|---|
| 398 | 437 | if (!(*started_flag)) { |
|---|
| 399 | 438 | lli->user_define |= |
|---|
| 400 | | - (LLI_USER_STRING_START | LLI_USER_CPIHER_START); |
|---|
| 439 | + (LLI_USER_STRING_START | LLI_USER_CIPHER_START); |
|---|
| 401 | 440 | crypto_write((u32)virt_to_phys(lli), CRYPTO_DMA_LLI_ADDR); |
|---|
| 402 | 441 | crypto_write((CRYPTO_HASH_ENABLE << CRYPTO_WRITE_MASK_SHIFT) | |
|---|
| 403 | 442 | CRYPTO_HASH_ENABLE, CRYPTO_HASH_CTL); |
|---|
| .. | .. |
|---|
| 520 | 559 | { |
|---|
| 521 | 560 | struct rockchip_crypto_priv *priv = dev_get_priv(dev); |
|---|
| 522 | 561 | struct rk_hash_ctx *hash_ctx = priv->hw_ctx; |
|---|
| 562 | + int ret = 0; |
|---|
| 523 | 563 | |
|---|
| 524 | 564 | if (!ctx) |
|---|
| 525 | 565 | return -EINVAL; |
|---|
| .. | .. |
|---|
| 535 | 575 | if (!hash_ctx->hash_cache) |
|---|
| 536 | 576 | return -EFAULT; |
|---|
| 537 | 577 | |
|---|
| 538 | | - return rk_hash_init(hash_ctx, ctx->algo); |
|---|
| 578 | + rk_crypto_enable_clk(dev); |
|---|
| 579 | + ret = rk_hash_init(hash_ctx, ctx->algo); |
|---|
| 580 | + if (ret) |
|---|
| 581 | + rk_crypto_disable_clk(dev); |
|---|
| 582 | + |
|---|
| 583 | + return ret; |
|---|
| 539 | 584 | } |
|---|
| 540 | 585 | |
|---|
| 541 | 586 | static int rockchip_crypto_sha_update(struct udevice *dev, |
|---|
| .. | .. |
|---|
| 545 | 590 | int ret, i; |
|---|
| 546 | 591 | u8 *p; |
|---|
| 547 | 592 | |
|---|
| 548 | | - if (!len) |
|---|
| 549 | | - return -EINVAL; |
|---|
| 593 | + if (!len) { |
|---|
| 594 | + ret = -EINVAL; |
|---|
| 595 | + goto exit; |
|---|
| 596 | + } |
|---|
| 550 | 597 | |
|---|
| 551 | 598 | p = (u8 *)input; |
|---|
| 552 | 599 | |
|---|
| .. | .. |
|---|
| 560 | 607 | ret = rk_hash_update(priv->hw_ctx, p, len % HASH_UPDATE_LIMIT); |
|---|
| 561 | 608 | |
|---|
| 562 | 609 | exit: |
|---|
| 610 | + if (ret) |
|---|
| 611 | + rk_crypto_disable_clk(dev); |
|---|
| 612 | + |
|---|
| 563 | 613 | return ret; |
|---|
| 564 | 614 | } |
|---|
| 565 | 615 | |
|---|
| .. | .. |
|---|
| 583 | 633 | |
|---|
| 584 | 634 | exit: |
|---|
| 585 | 635 | hw_hash_clean_ctx(priv->hw_ctx); |
|---|
| 636 | + rk_crypto_disable_clk(dev); |
|---|
| 637 | + |
|---|
| 586 | 638 | return ret; |
|---|
| 587 | 639 | } |
|---|
| 588 | 640 | |
|---|
| .. | .. |
|---|
| 614 | 666 | { |
|---|
| 615 | 667 | struct rockchip_crypto_priv *priv = dev_get_priv(dev); |
|---|
| 616 | 668 | struct rk_hash_ctx *hash_ctx = priv->hw_ctx; |
|---|
| 669 | + int ret = 0; |
|---|
| 617 | 670 | |
|---|
| 618 | 671 | if (!ctx) |
|---|
| 619 | 672 | return -EINVAL; |
|---|
| .. | .. |
|---|
| 629 | 682 | if (!hash_ctx->hash_cache) |
|---|
| 630 | 683 | return -EFAULT; |
|---|
| 631 | 684 | |
|---|
| 632 | | - return rk_hmac_init(priv->hw_ctx, ctx->algo, key, key_len); |
|---|
| 685 | + rk_crypto_enable_clk(dev); |
|---|
| 686 | + ret = rk_hmac_init(priv->hw_ctx, ctx->algo, key, key_len); |
|---|
| 687 | + if (ret) |
|---|
| 688 | + rk_crypto_disable_clk(dev); |
|---|
| 689 | + |
|---|
| 690 | + return ret; |
|---|
| 633 | 691 | } |
|---|
| 634 | 692 | |
|---|
| 635 | 693 | static int rockchip_crypto_hmac_update(struct udevice *dev, |
|---|
| .. | .. |
|---|
| 763 | 821 | { |
|---|
| 764 | 822 | u32 i; |
|---|
| 765 | 823 | |
|---|
| 824 | + if (aad_len == 0) { |
|---|
| 825 | + *padding_size = 0; |
|---|
| 826 | + return; |
|---|
| 827 | + } |
|---|
| 828 | + |
|---|
| 766 | 829 | i = aad_len < (0x10000 - 0x100) ? 2 : 6; |
|---|
| 767 | 830 | |
|---|
| 768 | 831 | if (i == 2) { |
|---|
| .. | .. |
|---|
| 779 | 842 | *padding_size = i; |
|---|
| 780 | 843 | } |
|---|
| 781 | 844 | |
|---|
| 782 | | -static int ccm_compose_aad_iv(u8 *aad_iv, u32 data_len, u32 tag_size) |
|---|
| 845 | +static int ccm_compose_aad_iv(u8 *aad_iv, u32 data_len, u32 aad_len, u32 tag_size) |
|---|
| 783 | 846 | { |
|---|
| 784 | 847 | aad_iv[0] |= ((u8)(((tag_size - 2) / 2) & 7) << 3); |
|---|
| 785 | 848 | |
|---|
| .. | .. |
|---|
| 788 | 851 | aad_iv[14] = (u8)(data_len >> 8); |
|---|
| 789 | 852 | aad_iv[15] = (u8)data_len; |
|---|
| 790 | 853 | |
|---|
| 791 | | - aad_iv[0] |= 0x40; //set aad flag |
|---|
| 854 | + if (aad_len) |
|---|
| 855 | + aad_iv[0] |= 0x40; //set aad flag |
|---|
| 792 | 856 | |
|---|
| 793 | 857 | return 0; |
|---|
| 794 | 858 | } |
|---|
| .. | .. |
|---|
| 925 | 989 | data_desc->dma_ctrl |= LLI_DMA_CTRL_DST_DONE; |
|---|
| 926 | 990 | } |
|---|
| 927 | 991 | |
|---|
| 992 | + data_desc->user_define = LLI_USER_CIPHER_START | |
|---|
| 993 | + LLI_USER_STRING_START | |
|---|
| 994 | + LLI_USER_STRING_LAST | |
|---|
| 995 | + (key_chn << 4); |
|---|
| 996 | + crypto_write((u32)virt_to_phys(data_desc), CRYPTO_DMA_LLI_ADDR); |
|---|
| 997 | + |
|---|
| 928 | 998 | if (rk_mode == RK_MODE_CCM || rk_mode == RK_MODE_GCM) { |
|---|
| 929 | 999 | u32 aad_tmp_len = 0; |
|---|
| 930 | | - |
|---|
| 931 | | - data_desc->user_define = LLI_USER_STRING_START | |
|---|
| 932 | | - LLI_USER_STRING_LAST | |
|---|
| 933 | | - (key_chn << 4); |
|---|
| 934 | 1000 | |
|---|
| 935 | 1001 | aad_desc = align_malloc(sizeof(*aad_desc), LLI_ADDR_ALIGN_SIZE); |
|---|
| 936 | 1002 | if (!aad_desc) |
|---|
| .. | .. |
|---|
| 938 | 1004 | |
|---|
| 939 | 1005 | memset(aad_desc, 0x00, sizeof(*aad_desc)); |
|---|
| 940 | 1006 | aad_desc->next_addr = (u32)virt_to_phys(data_desc); |
|---|
| 941 | | - aad_desc->user_define = LLI_USER_CPIHER_START | |
|---|
| 1007 | + aad_desc->user_define = LLI_USER_CIPHER_START | |
|---|
| 942 | 1008 | LLI_USER_STRING_START | |
|---|
| 943 | 1009 | LLI_USER_STRING_LAST | |
|---|
| 944 | 1010 | LLI_USER_STRING_AAD | |
|---|
| .. | .. |
|---|
| 958 | 1024 | if (!aad_tmp) |
|---|
| 959 | 1025 | goto exit; |
|---|
| 960 | 1026 | |
|---|
| 961 | | - /* read iv data from reg */ |
|---|
| 962 | | - get_iv_reg(key_chn, aad_tmp, AES_BLOCK_SIZE); |
|---|
| 963 | | - ccm_compose_aad_iv(aad_tmp, tmp_len, tag_len); |
|---|
| 964 | | - memcpy(aad_tmp + AES_BLOCK_SIZE, padding, padding_size); |
|---|
| 1027 | + /* clear last block */ |
|---|
| 965 | 1028 | memset(aad_tmp + aad_tmp_len - AES_BLOCK_SIZE, |
|---|
| 966 | 1029 | 0x00, AES_BLOCK_SIZE); |
|---|
| 1030 | + |
|---|
| 1031 | + /* read iv data from reg */ |
|---|
| 1032 | + get_iv_reg(key_chn, aad_tmp, AES_BLOCK_SIZE); |
|---|
| 1033 | + ccm_compose_aad_iv(aad_tmp, tmp_len, aad_len, tag_len); |
|---|
| 1034 | + memcpy(aad_tmp + AES_BLOCK_SIZE, padding, padding_size); |
|---|
| 1035 | + |
|---|
| 967 | 1036 | memcpy(aad_tmp + AES_BLOCK_SIZE + padding_size, |
|---|
| 968 | 1037 | aad, aad_len); |
|---|
| 969 | 1038 | } else { |
|---|
| .. | .. |
|---|
| 985 | 1054 | |
|---|
| 986 | 1055 | aad_desc->src_addr = (u32)virt_to_phys(aad_tmp); |
|---|
| 987 | 1056 | aad_desc->src_len = aad_tmp_len; |
|---|
| 988 | | - crypto_write((u32)virt_to_phys(aad_desc), CRYPTO_DMA_LLI_ADDR); |
|---|
| 989 | | - cache_op_inner(DCACHE_AREA_CLEAN, aad_tmp, aad_tmp_len); |
|---|
| 990 | | - cache_op_inner(DCACHE_AREA_CLEAN, aad_desc, sizeof(*aad_desc)); |
|---|
| 991 | | - } else { |
|---|
| 992 | | - data_desc->user_define = LLI_USER_CPIHER_START | |
|---|
| 993 | | - LLI_USER_STRING_START | |
|---|
| 994 | | - LLI_USER_STRING_LAST | |
|---|
| 995 | | - (key_chn << 4); |
|---|
| 996 | | - crypto_write((u32)virt_to_phys(data_desc), CRYPTO_DMA_LLI_ADDR); |
|---|
| 1057 | + |
|---|
| 1058 | + if (aad_tmp_len) { |
|---|
| 1059 | + data_desc->user_define = LLI_USER_STRING_START | |
|---|
| 1060 | + LLI_USER_STRING_LAST | |
|---|
| 1061 | + (key_chn << 4); |
|---|
| 1062 | + crypto_write((u32)virt_to_phys(aad_desc), CRYPTO_DMA_LLI_ADDR); |
|---|
| 1063 | + cache_op_inner(DCACHE_AREA_CLEAN, aad_tmp, aad_tmp_len); |
|---|
| 1064 | + cache_op_inner(DCACHE_AREA_CLEAN, aad_desc, sizeof(*aad_desc)); |
|---|
| 1065 | + } |
|---|
| 997 | 1066 | } |
|---|
| 998 | 1067 | |
|---|
| 999 | 1068 | cache_op_inner(DCACHE_AREA_CLEAN, data_desc, sizeof(*data_desc)); |
|---|
| .. | .. |
|---|
| 1175 | 1244 | int rockchip_crypto_cipher(struct udevice *dev, cipher_context *ctx, |
|---|
| 1176 | 1245 | const u8 *in, u8 *out, u32 len, bool enc) |
|---|
| 1177 | 1246 | { |
|---|
| 1247 | + int ret; |
|---|
| 1248 | + |
|---|
| 1249 | + rk_crypto_enable_clk(dev); |
|---|
| 1250 | + |
|---|
| 1178 | 1251 | switch (ctx->algo) { |
|---|
| 1179 | 1252 | case CRYPTO_DES: |
|---|
| 1180 | | - return rk_crypto_des(dev, ctx->mode, ctx->key, ctx->key_len, |
|---|
| 1181 | | - ctx->iv, in, out, len, enc); |
|---|
| 1253 | + ret = rk_crypto_des(dev, ctx->mode, ctx->key, ctx->key_len, |
|---|
| 1254 | + ctx->iv, in, out, len, enc); |
|---|
| 1182 | 1255 | case CRYPTO_AES: |
|---|
| 1183 | | - return rk_crypto_aes(dev, ctx->mode, |
|---|
| 1184 | | - ctx->key, ctx->twk_key, ctx->key_len, |
|---|
| 1185 | | - ctx->iv, ctx->iv_len, in, out, len, enc); |
|---|
| 1256 | + ret = rk_crypto_aes(dev, ctx->mode, |
|---|
| 1257 | + ctx->key, ctx->twk_key, ctx->key_len, |
|---|
| 1258 | + ctx->iv, ctx->iv_len, in, out, len, enc); |
|---|
| 1186 | 1259 | case CRYPTO_SM4: |
|---|
| 1187 | | - return rk_crypto_sm4(dev, ctx->mode, |
|---|
| 1188 | | - ctx->key, ctx->twk_key, ctx->key_len, |
|---|
| 1189 | | - ctx->iv, ctx->iv_len, in, out, len, enc); |
|---|
| 1260 | + ret = rk_crypto_sm4(dev, ctx->mode, |
|---|
| 1261 | + ctx->key, ctx->twk_key, ctx->key_len, |
|---|
| 1262 | + ctx->iv, ctx->iv_len, in, out, len, enc); |
|---|
| 1190 | 1263 | default: |
|---|
| 1191 | | - return -EINVAL; |
|---|
| 1264 | + ret = -EINVAL; |
|---|
| 1192 | 1265 | } |
|---|
| 1266 | + |
|---|
| 1267 | + rk_crypto_disable_clk(dev); |
|---|
| 1268 | + |
|---|
| 1269 | + return ret; |
|---|
| 1193 | 1270 | } |
|---|
| 1194 | 1271 | |
|---|
| 1195 | 1272 | int rk_crypto_mac(struct udevice *dev, u32 algo, u32 mode, |
|---|
| .. | .. |
|---|
| 1223 | 1300 | int rockchip_crypto_mac(struct udevice *dev, cipher_context *ctx, |
|---|
| 1224 | 1301 | const u8 *in, u32 len, u8 *tag) |
|---|
| 1225 | 1302 | { |
|---|
| 1226 | | - return rk_crypto_mac(dev, ctx->algo, ctx->mode, |
|---|
| 1227 | | - ctx->key, ctx->key_len, in, len, tag); |
|---|
| 1303 | + int ret = 0; |
|---|
| 1304 | + |
|---|
| 1305 | + rk_crypto_enable_clk(dev); |
|---|
| 1306 | + |
|---|
| 1307 | + ret = rk_crypto_mac(dev, ctx->algo, ctx->mode, |
|---|
| 1308 | + ctx->key, ctx->key_len, in, len, tag); |
|---|
| 1309 | + |
|---|
| 1310 | + rk_crypto_disable_clk(dev); |
|---|
| 1311 | + |
|---|
| 1312 | + return ret; |
|---|
| 1228 | 1313 | } |
|---|
| 1229 | 1314 | |
|---|
| 1230 | 1315 | int rk_crypto_ae(struct udevice *dev, u32 algo, u32 mode, |
|---|
| .. | .. |
|---|
| 1236 | 1321 | int ret; |
|---|
| 1237 | 1322 | |
|---|
| 1238 | 1323 | if (!IS_AE_MODE(rk_mode)) |
|---|
| 1324 | + return -EINVAL; |
|---|
| 1325 | + |
|---|
| 1326 | + if (len == 0) |
|---|
| 1239 | 1327 | return -EINVAL; |
|---|
| 1240 | 1328 | |
|---|
| 1241 | 1329 | if (algo != CRYPTO_AES && algo != CRYPTO_SM4) |
|---|
| .. | .. |
|---|
| 1261 | 1349 | u8 *out, u8 *tag) |
|---|
| 1262 | 1350 | |
|---|
| 1263 | 1351 | { |
|---|
| 1264 | | - return rk_crypto_ae(dev, ctx->algo, ctx->mode, ctx->key, ctx->key_len, |
|---|
| 1265 | | - ctx->iv, ctx->iv_len, in, len, |
|---|
| 1266 | | - aad, aad_len, out, tag); |
|---|
| 1352 | + int ret = 0; |
|---|
| 1353 | + |
|---|
| 1354 | + rk_crypto_enable_clk(dev); |
|---|
| 1355 | + |
|---|
| 1356 | + ret = rk_crypto_ae(dev, ctx->algo, ctx->mode, ctx->key, ctx->key_len, |
|---|
| 1357 | + ctx->iv, ctx->iv_len, in, len, |
|---|
| 1358 | + aad, aad_len, out, tag); |
|---|
| 1359 | + |
|---|
| 1360 | + rk_crypto_disable_clk(dev); |
|---|
| 1361 | + |
|---|
| 1362 | + return ret; |
|---|
| 1267 | 1363 | } |
|---|
| 1268 | 1364 | |
|---|
| 1269 | 1365 | #endif |
|---|
| .. | .. |
|---|
| 1312 | 1408 | if (ret) |
|---|
| 1313 | 1409 | goto exit; |
|---|
| 1314 | 1410 | |
|---|
| 1411 | + rk_crypto_enable_clk(dev); |
|---|
| 1315 | 1412 | ret = rk_exptmod_np(mpa_m, mpa_e, mpa_n, mpa_c, mpa_result); |
|---|
| 1316 | 1413 | if (!ret) |
|---|
| 1317 | 1414 | memcpy(output, mpa_result->d, BITS2BYTE(n_bits)); |
|---|
| 1415 | + rk_crypto_disable_clk(dev); |
|---|
| 1318 | 1416 | |
|---|
| 1319 | 1417 | exit: |
|---|
| 1320 | 1418 | rk_mpa_free(&mpa_m); |
|---|
| .. | .. |
|---|
| 1378 | 1476 | if (!priv->clocks) |
|---|
| 1379 | 1477 | return -ENOMEM; |
|---|
| 1380 | 1478 | |
|---|
| 1381 | | - priv->nclocks = len / sizeof(u32); |
|---|
| 1479 | + priv->nclocks = len / (2 * sizeof(u32)); |
|---|
| 1382 | 1480 | if (dev_read_u32_array(dev, "clocks", (u32 *)priv->clocks, |
|---|
| 1383 | 1481 | priv->nclocks)) { |
|---|
| 1384 | 1482 | printf("Can't read \"clocks\" property\n"); |
|---|
| .. | .. |
|---|
| 1386 | 1484 | goto exit; |
|---|
| 1387 | 1485 | } |
|---|
| 1388 | 1486 | |
|---|
| 1389 | | - if (!dev_read_prop(dev, "clock-frequency", &len)) { |
|---|
| 1390 | | - printf("Can't find \"clock-frequency\" property\n"); |
|---|
| 1391 | | - ret = -EINVAL; |
|---|
| 1392 | | - goto exit; |
|---|
| 1393 | | - } |
|---|
| 1394 | | - |
|---|
| 1395 | | - priv->frequencies = malloc(len); |
|---|
| 1396 | | - if (!priv->frequencies) { |
|---|
| 1397 | | - ret = -ENOMEM; |
|---|
| 1398 | | - goto exit; |
|---|
| 1399 | | - } |
|---|
| 1400 | | - |
|---|
| 1401 | | - priv->nclocks = len / sizeof(u32); |
|---|
| 1402 | | - if (dev_read_u32_array(dev, "clock-frequency", priv->frequencies, |
|---|
| 1403 | | - priv->nclocks)) { |
|---|
| 1404 | | - printf("Can't read \"clock-frequency\" property\n"); |
|---|
| 1405 | | - ret = -EINVAL; |
|---|
| 1406 | | - goto exit; |
|---|
| 1487 | + if (dev_read_prop(dev, "clock-frequency", &len)) { |
|---|
| 1488 | + priv->frequencies = malloc(len); |
|---|
| 1489 | + if (!priv->frequencies) { |
|---|
| 1490 | + ret = -ENOMEM; |
|---|
| 1491 | + goto exit; |
|---|
| 1492 | + } |
|---|
| 1493 | + priv->freq_nclocks = len / sizeof(u32); |
|---|
| 1494 | + if (dev_read_u32_array(dev, "clock-frequency", priv->frequencies, |
|---|
| 1495 | + priv->freq_nclocks)) { |
|---|
| 1496 | + printf("Can't read \"clock-frequency\" property\n"); |
|---|
| 1497 | + ret = -EINVAL; |
|---|
| 1498 | + goto exit; |
|---|
| 1499 | + } |
|---|
| 1407 | 1500 | } |
|---|
| 1408 | 1501 | |
|---|
| 1409 | 1502 | return 0; |
|---|
| .. | .. |
|---|
| 1423 | 1516 | struct clk clk; |
|---|
| 1424 | 1517 | int i, ret; |
|---|
| 1425 | 1518 | |
|---|
| 1426 | | - if (!priv->clocks && priv->nclocks == 0) |
|---|
| 1519 | + /* use standard "assigned-clock-rates" props */ |
|---|
| 1520 | + if (dev_read_size(dev, "assigned-clock-rates") > 0) |
|---|
| 1521 | + return clk_set_defaults(dev); |
|---|
| 1522 | + |
|---|
| 1523 | + /* use "clock-frequency" props */ |
|---|
| 1524 | + if (priv->freq_nclocks == 0) |
|---|
| 1427 | 1525 | return 0; |
|---|
| 1428 | 1526 | |
|---|
| 1429 | | - for (i = 0; i < priv->nclocks; i++) { |
|---|
| 1527 | + for (i = 0; i < priv->freq_nclocks; i++) { |
|---|
| 1430 | 1528 | ret = clk_get_by_index(dev, i, &clk); |
|---|
| 1431 | 1529 | if (ret < 0) { |
|---|
| 1432 | 1530 | printf("Failed to get clk index %d, ret=%d\n", i, ret); |
|---|
| .. | .. |
|---|
| 1465 | 1563 | if (ret) |
|---|
| 1466 | 1564 | return ret; |
|---|
| 1467 | 1565 | |
|---|
| 1566 | + rk_crypto_enable_clk(dev); |
|---|
| 1567 | + |
|---|
| 1468 | 1568 | hw_crypto_reset(); |
|---|
| 1569 | + |
|---|
| 1570 | + rk_crypto_disable_clk(dev); |
|---|
| 1469 | 1571 | |
|---|
| 1470 | 1572 | return 0; |
|---|
| 1471 | 1573 | } |
|---|
| .. | .. |
|---|
| 1557 | 1659 | .compatible = "rockchip,crypto-v3", |
|---|
| 1558 | 1660 | .data = (ulong)&soc_data_cryptov3 |
|---|
| 1559 | 1661 | }, |
|---|
| 1662 | + { |
|---|
| 1663 | + .compatible = "rockchip,crypto-v4", |
|---|
| 1664 | + .data = (ulong)&soc_data_cryptov3 /* reuse crypto v3 config */ |
|---|
| 1665 | + }, |
|---|
| 1560 | 1666 | { } |
|---|
| 1561 | 1667 | }; |
|---|
| 1562 | 1668 | |
|---|