1a49e490cSVladimir Zapolskiy /* 2a49e490cSVladimir Zapolskiy * Cryptographic API. 3a49e490cSVladimir Zapolskiy * 4a49e490cSVladimir Zapolskiy * Support for Samsung S5PV210 HW acceleration. 5a49e490cSVladimir Zapolskiy * 6a49e490cSVladimir Zapolskiy * Copyright (C) 2011 NetUP Inc. All rights reserved. 7a49e490cSVladimir Zapolskiy * 8a49e490cSVladimir Zapolskiy * This program is free software; you can redistribute it and/or modify 9a49e490cSVladimir Zapolskiy * it under the terms of the GNU General Public License version 2 as published 10a49e490cSVladimir Zapolskiy * by the Free Software Foundation. 11a49e490cSVladimir Zapolskiy * 12a49e490cSVladimir Zapolskiy */ 13a49e490cSVladimir Zapolskiy 14a49e490cSVladimir Zapolskiy #include <linux/delay.h> 15a49e490cSVladimir Zapolskiy #include <linux/err.h> 16a49e490cSVladimir Zapolskiy #include <linux/module.h> 17a49e490cSVladimir Zapolskiy #include <linux/init.h> 18a49e490cSVladimir Zapolskiy #include <linux/errno.h> 19a49e490cSVladimir Zapolskiy #include <linux/kernel.h> 20a49e490cSVladimir Zapolskiy #include <linux/clk.h> 21a49e490cSVladimir Zapolskiy #include <linux/platform_device.h> 22a49e490cSVladimir Zapolskiy #include <linux/scatterlist.h> 23a49e490cSVladimir Zapolskiy #include <linux/dma-mapping.h> 24a49e490cSVladimir Zapolskiy #include <linux/io.h> 25a49e490cSVladimir Zapolskiy #include <linux/crypto.h> 26a49e490cSVladimir Zapolskiy #include <linux/interrupt.h> 27a49e490cSVladimir Zapolskiy 28a49e490cSVladimir Zapolskiy #include <crypto/algapi.h> 29a49e490cSVladimir Zapolskiy #include <crypto/aes.h> 30a49e490cSVladimir Zapolskiy #include <crypto/ctr.h> 31a49e490cSVladimir Zapolskiy 32a49e490cSVladimir Zapolskiy #include <plat/cpu.h> 33a465348fSSachin Kamat #include <mach/dma.h> 34a49e490cSVladimir Zapolskiy 35a49e490cSVladimir Zapolskiy #define _SBF(s, v) ((v) << (s)) 36a49e490cSVladimir Zapolskiy #define _BIT(b) _SBF(b, 1) 37a49e490cSVladimir Zapolskiy 38a49e490cSVladimir Zapolskiy /* Feed control registers */ 39a49e490cSVladimir Zapolskiy #define SSS_REG_FCINTSTAT 0x0000 40a49e490cSVladimir Zapolskiy #define SSS_FCINTSTAT_BRDMAINT _BIT(3) 41a49e490cSVladimir Zapolskiy #define SSS_FCINTSTAT_BTDMAINT _BIT(2) 42a49e490cSVladimir Zapolskiy #define SSS_FCINTSTAT_HRDMAINT _BIT(1) 43a49e490cSVladimir Zapolskiy #define SSS_FCINTSTAT_PKDMAINT _BIT(0) 44a49e490cSVladimir Zapolskiy 45a49e490cSVladimir Zapolskiy #define SSS_REG_FCINTENSET 0x0004 46a49e490cSVladimir Zapolskiy #define SSS_FCINTENSET_BRDMAINTENSET _BIT(3) 47a49e490cSVladimir Zapolskiy #define SSS_FCINTENSET_BTDMAINTENSET _BIT(2) 48a49e490cSVladimir Zapolskiy #define SSS_FCINTENSET_HRDMAINTENSET _BIT(1) 49a49e490cSVladimir Zapolskiy #define SSS_FCINTENSET_PKDMAINTENSET _BIT(0) 50a49e490cSVladimir Zapolskiy 51a49e490cSVladimir Zapolskiy #define SSS_REG_FCINTENCLR 0x0008 52a49e490cSVladimir Zapolskiy #define SSS_FCINTENCLR_BRDMAINTENCLR _BIT(3) 53a49e490cSVladimir Zapolskiy #define SSS_FCINTENCLR_BTDMAINTENCLR _BIT(2) 54a49e490cSVladimir Zapolskiy #define SSS_FCINTENCLR_HRDMAINTENCLR _BIT(1) 55a49e490cSVladimir Zapolskiy #define SSS_FCINTENCLR_PKDMAINTENCLR _BIT(0) 56a49e490cSVladimir Zapolskiy 57a49e490cSVladimir Zapolskiy #define SSS_REG_FCINTPEND 0x000C 58a49e490cSVladimir Zapolskiy #define SSS_FCINTPEND_BRDMAINTP _BIT(3) 59a49e490cSVladimir Zapolskiy #define SSS_FCINTPEND_BTDMAINTP _BIT(2) 60a49e490cSVladimir Zapolskiy #define SSS_FCINTPEND_HRDMAINTP _BIT(1) 61a49e490cSVladimir Zapolskiy #define SSS_FCINTPEND_PKDMAINTP _BIT(0) 62a49e490cSVladimir Zapolskiy 63a49e490cSVladimir Zapolskiy #define SSS_REG_FCFIFOSTAT 0x0010 64a49e490cSVladimir Zapolskiy #define SSS_FCFIFOSTAT_BRFIFOFUL _BIT(7) 65a49e490cSVladimir Zapolskiy #define SSS_FCFIFOSTAT_BRFIFOEMP _BIT(6) 66a49e490cSVladimir Zapolskiy #define SSS_FCFIFOSTAT_BTFIFOFUL _BIT(5) 67a49e490cSVladimir Zapolskiy #define SSS_FCFIFOSTAT_BTFIFOEMP _BIT(4) 68a49e490cSVladimir Zapolskiy #define SSS_FCFIFOSTAT_HRFIFOFUL _BIT(3) 69a49e490cSVladimir Zapolskiy #define SSS_FCFIFOSTAT_HRFIFOEMP _BIT(2) 70a49e490cSVladimir Zapolskiy #define SSS_FCFIFOSTAT_PKFIFOFUL _BIT(1) 71a49e490cSVladimir Zapolskiy #define SSS_FCFIFOSTAT_PKFIFOEMP _BIT(0) 72a49e490cSVladimir Zapolskiy 73a49e490cSVladimir Zapolskiy #define SSS_REG_FCFIFOCTRL 0x0014 74a49e490cSVladimir Zapolskiy #define SSS_FCFIFOCTRL_DESSEL _BIT(2) 75a49e490cSVladimir Zapolskiy #define SSS_HASHIN_INDEPENDENT _SBF(0, 0x00) 76a49e490cSVladimir Zapolskiy #define SSS_HASHIN_CIPHER_INPUT _SBF(0, 0x01) 77a49e490cSVladimir Zapolskiy #define SSS_HASHIN_CIPHER_OUTPUT _SBF(0, 0x02) 78a49e490cSVladimir Zapolskiy 79a49e490cSVladimir Zapolskiy #define SSS_REG_FCBRDMAS 0x0020 80a49e490cSVladimir Zapolskiy #define SSS_REG_FCBRDMAL 0x0024 81a49e490cSVladimir Zapolskiy #define SSS_REG_FCBRDMAC 0x0028 82a49e490cSVladimir Zapolskiy #define SSS_FCBRDMAC_BYTESWAP _BIT(1) 83a49e490cSVladimir Zapolskiy #define SSS_FCBRDMAC_FLUSH _BIT(0) 84a49e490cSVladimir Zapolskiy 85a49e490cSVladimir Zapolskiy #define SSS_REG_FCBTDMAS 0x0030 86a49e490cSVladimir Zapolskiy #define SSS_REG_FCBTDMAL 0x0034 87a49e490cSVladimir Zapolskiy #define SSS_REG_FCBTDMAC 0x0038 88a49e490cSVladimir Zapolskiy #define SSS_FCBTDMAC_BYTESWAP _BIT(1) 89a49e490cSVladimir Zapolskiy #define SSS_FCBTDMAC_FLUSH _BIT(0) 90a49e490cSVladimir Zapolskiy 91a49e490cSVladimir Zapolskiy #define SSS_REG_FCHRDMAS 0x0040 92a49e490cSVladimir Zapolskiy #define SSS_REG_FCHRDMAL 0x0044 93a49e490cSVladimir Zapolskiy #define SSS_REG_FCHRDMAC 0x0048 94a49e490cSVladimir Zapolskiy #define SSS_FCHRDMAC_BYTESWAP _BIT(1) 95a49e490cSVladimir Zapolskiy #define SSS_FCHRDMAC_FLUSH _BIT(0) 96a49e490cSVladimir Zapolskiy 97a49e490cSVladimir Zapolskiy #define SSS_REG_FCPKDMAS 0x0050 98a49e490cSVladimir Zapolskiy #define SSS_REG_FCPKDMAL 0x0054 99a49e490cSVladimir Zapolskiy #define SSS_REG_FCPKDMAC 0x0058 100a49e490cSVladimir Zapolskiy #define SSS_FCPKDMAC_BYTESWAP _BIT(3) 101a49e490cSVladimir Zapolskiy #define SSS_FCPKDMAC_DESCEND _BIT(2) 102a49e490cSVladimir Zapolskiy #define SSS_FCPKDMAC_TRANSMIT _BIT(1) 103a49e490cSVladimir Zapolskiy #define SSS_FCPKDMAC_FLUSH _BIT(0) 104a49e490cSVladimir Zapolskiy 105a49e490cSVladimir Zapolskiy #define SSS_REG_FCPKDMAO 0x005C 106a49e490cSVladimir Zapolskiy 107a49e490cSVladimir Zapolskiy /* AES registers */ 108a49e490cSVladimir Zapolskiy #define SSS_REG_AES_CONTROL 0x4000 109a49e490cSVladimir Zapolskiy #define SSS_AES_BYTESWAP_DI _BIT(11) 110a49e490cSVladimir Zapolskiy #define SSS_AES_BYTESWAP_DO _BIT(10) 111a49e490cSVladimir Zapolskiy #define SSS_AES_BYTESWAP_IV _BIT(9) 112a49e490cSVladimir Zapolskiy #define SSS_AES_BYTESWAP_CNT _BIT(8) 113a49e490cSVladimir Zapolskiy #define SSS_AES_BYTESWAP_KEY _BIT(7) 114a49e490cSVladimir Zapolskiy #define SSS_AES_KEY_CHANGE_MODE _BIT(6) 115a49e490cSVladimir Zapolskiy #define SSS_AES_KEY_SIZE_128 _SBF(4, 0x00) 116a49e490cSVladimir Zapolskiy #define SSS_AES_KEY_SIZE_192 _SBF(4, 0x01) 117a49e490cSVladimir Zapolskiy #define SSS_AES_KEY_SIZE_256 _SBF(4, 0x02) 118a49e490cSVladimir Zapolskiy #define SSS_AES_FIFO_MODE _BIT(3) 119a49e490cSVladimir Zapolskiy #define SSS_AES_CHAIN_MODE_ECB _SBF(1, 0x00) 120a49e490cSVladimir Zapolskiy #define SSS_AES_CHAIN_MODE_CBC _SBF(1, 0x01) 121a49e490cSVladimir Zapolskiy #define SSS_AES_CHAIN_MODE_CTR _SBF(1, 0x02) 122a49e490cSVladimir Zapolskiy #define SSS_AES_MODE_DECRYPT _BIT(0) 123a49e490cSVladimir Zapolskiy 124a49e490cSVladimir Zapolskiy #define SSS_REG_AES_STATUS 0x4004 125a49e490cSVladimir Zapolskiy #define SSS_AES_BUSY _BIT(2) 126a49e490cSVladimir Zapolskiy #define SSS_AES_INPUT_READY _BIT(1) 127a49e490cSVladimir Zapolskiy #define SSS_AES_OUTPUT_READY _BIT(0) 128a49e490cSVladimir Zapolskiy 129a49e490cSVladimir Zapolskiy #define SSS_REG_AES_IN_DATA(s) (0x4010 + (s << 2)) 130a49e490cSVladimir Zapolskiy #define SSS_REG_AES_OUT_DATA(s) (0x4020 + (s << 2)) 131a49e490cSVladimir Zapolskiy #define SSS_REG_AES_IV_DATA(s) (0x4030 + (s << 2)) 132a49e490cSVladimir Zapolskiy #define SSS_REG_AES_CNT_DATA(s) (0x4040 + (s << 2)) 133a49e490cSVladimir Zapolskiy #define SSS_REG_AES_KEY_DATA(s) (0x4080 + (s << 2)) 134a49e490cSVladimir Zapolskiy 135a49e490cSVladimir Zapolskiy #define SSS_REG(dev, reg) ((dev)->ioaddr + (SSS_REG_##reg)) 136a49e490cSVladimir Zapolskiy #define SSS_READ(dev, reg) __raw_readl(SSS_REG(dev, reg)) 137a49e490cSVladimir Zapolskiy #define SSS_WRITE(dev, reg, val) __raw_writel((val), SSS_REG(dev, reg)) 138a49e490cSVladimir Zapolskiy 139a49e490cSVladimir Zapolskiy /* HW engine modes */ 140a49e490cSVladimir Zapolskiy #define FLAGS_AES_DECRYPT _BIT(0) 141a49e490cSVladimir Zapolskiy #define FLAGS_AES_MODE_MASK _SBF(1, 0x03) 142a49e490cSVladimir Zapolskiy #define FLAGS_AES_CBC _SBF(1, 0x01) 143a49e490cSVladimir Zapolskiy #define FLAGS_AES_CTR _SBF(1, 0x02) 144a49e490cSVladimir Zapolskiy 145a49e490cSVladimir Zapolskiy #define AES_KEY_LEN 16 146a49e490cSVladimir Zapolskiy #define CRYPTO_QUEUE_LEN 1 147a49e490cSVladimir Zapolskiy 148a49e490cSVladimir Zapolskiy struct s5p_aes_reqctx { 149a49e490cSVladimir Zapolskiy unsigned long mode; 150a49e490cSVladimir Zapolskiy }; 151a49e490cSVladimir Zapolskiy 152a49e490cSVladimir Zapolskiy struct s5p_aes_ctx { 153a49e490cSVladimir Zapolskiy struct s5p_aes_dev *dev; 154a49e490cSVladimir Zapolskiy 155a49e490cSVladimir Zapolskiy uint8_t aes_key[AES_MAX_KEY_SIZE]; 156a49e490cSVladimir Zapolskiy uint8_t nonce[CTR_RFC3686_NONCE_SIZE]; 157a49e490cSVladimir Zapolskiy int keylen; 158a49e490cSVladimir Zapolskiy }; 159a49e490cSVladimir Zapolskiy 160a49e490cSVladimir Zapolskiy struct s5p_aes_dev { 161a49e490cSVladimir Zapolskiy struct device *dev; 162a49e490cSVladimir Zapolskiy struct clk *clk; 163a49e490cSVladimir Zapolskiy void __iomem *ioaddr; 164a49e490cSVladimir Zapolskiy int irq_hash; 165a49e490cSVladimir Zapolskiy int irq_fc; 166a49e490cSVladimir Zapolskiy 167a49e490cSVladimir Zapolskiy struct ablkcipher_request *req; 168a49e490cSVladimir Zapolskiy struct s5p_aes_ctx *ctx; 169a49e490cSVladimir Zapolskiy struct scatterlist *sg_src; 170a49e490cSVladimir Zapolskiy struct scatterlist *sg_dst; 171a49e490cSVladimir Zapolskiy 172a49e490cSVladimir Zapolskiy struct tasklet_struct tasklet; 173a49e490cSVladimir Zapolskiy struct crypto_queue queue; 174a49e490cSVladimir Zapolskiy bool busy; 175a49e490cSVladimir Zapolskiy spinlock_t lock; 176a49e490cSVladimir Zapolskiy }; 177a49e490cSVladimir Zapolskiy 178a49e490cSVladimir Zapolskiy static struct s5p_aes_dev *s5p_dev; 179a49e490cSVladimir Zapolskiy 180a49e490cSVladimir Zapolskiy static void s5p_set_dma_indata(struct s5p_aes_dev *dev, struct scatterlist *sg) 181a49e490cSVladimir Zapolskiy { 182a49e490cSVladimir Zapolskiy SSS_WRITE(dev, FCBRDMAS, sg_dma_address(sg)); 183a49e490cSVladimir Zapolskiy SSS_WRITE(dev, FCBRDMAL, sg_dma_len(sg)); 184a49e490cSVladimir Zapolskiy } 185a49e490cSVladimir Zapolskiy 186a49e490cSVladimir Zapolskiy static void s5p_set_dma_outdata(struct s5p_aes_dev *dev, struct scatterlist *sg) 187a49e490cSVladimir Zapolskiy { 188a49e490cSVladimir Zapolskiy SSS_WRITE(dev, FCBTDMAS, sg_dma_address(sg)); 189a49e490cSVladimir Zapolskiy SSS_WRITE(dev, FCBTDMAL, sg_dma_len(sg)); 190a49e490cSVladimir Zapolskiy } 191a49e490cSVladimir Zapolskiy 192a49e490cSVladimir Zapolskiy static void s5p_aes_complete(struct s5p_aes_dev *dev, int err) 193a49e490cSVladimir Zapolskiy { 194a49e490cSVladimir Zapolskiy /* holding a lock outside */ 195a49e490cSVladimir Zapolskiy dev->req->base.complete(&dev->req->base, err); 196a49e490cSVladimir Zapolskiy dev->busy = false; 197a49e490cSVladimir Zapolskiy } 198a49e490cSVladimir Zapolskiy 199a49e490cSVladimir Zapolskiy static void s5p_unset_outdata(struct s5p_aes_dev *dev) 200a49e490cSVladimir Zapolskiy { 201a49e490cSVladimir Zapolskiy dma_unmap_sg(dev->dev, dev->sg_dst, 1, DMA_FROM_DEVICE); 202a49e490cSVladimir Zapolskiy } 203a49e490cSVladimir Zapolskiy 204a49e490cSVladimir Zapolskiy static void s5p_unset_indata(struct s5p_aes_dev *dev) 205a49e490cSVladimir Zapolskiy { 206a49e490cSVladimir Zapolskiy dma_unmap_sg(dev->dev, dev->sg_src, 1, DMA_TO_DEVICE); 207a49e490cSVladimir Zapolskiy } 208a49e490cSVladimir Zapolskiy 209a49e490cSVladimir Zapolskiy static int s5p_set_outdata(struct s5p_aes_dev *dev, struct scatterlist *sg) 210a49e490cSVladimir Zapolskiy { 211a49e490cSVladimir Zapolskiy int err; 212a49e490cSVladimir Zapolskiy 213a49e490cSVladimir Zapolskiy if (!IS_ALIGNED(sg_dma_len(sg), AES_BLOCK_SIZE)) { 214a49e490cSVladimir Zapolskiy err = -EINVAL; 215a49e490cSVladimir Zapolskiy goto exit; 216a49e490cSVladimir Zapolskiy } 217a49e490cSVladimir Zapolskiy if (!sg_dma_len(sg)) { 218a49e490cSVladimir Zapolskiy err = -EINVAL; 219a49e490cSVladimir Zapolskiy goto exit; 220a49e490cSVladimir Zapolskiy } 221a49e490cSVladimir Zapolskiy 222a49e490cSVladimir Zapolskiy err = dma_map_sg(dev->dev, sg, 1, DMA_FROM_DEVICE); 223a49e490cSVladimir Zapolskiy if (!err) { 224a49e490cSVladimir Zapolskiy err = -ENOMEM; 225a49e490cSVladimir Zapolskiy goto exit; 226a49e490cSVladimir Zapolskiy } 227a49e490cSVladimir Zapolskiy 228a49e490cSVladimir Zapolskiy dev->sg_dst = sg; 229a49e490cSVladimir Zapolskiy err = 0; 230a49e490cSVladimir Zapolskiy 231a49e490cSVladimir Zapolskiy exit: 232a49e490cSVladimir Zapolskiy return err; 233a49e490cSVladimir Zapolskiy } 234a49e490cSVladimir Zapolskiy 235a49e490cSVladimir Zapolskiy static int s5p_set_indata(struct s5p_aes_dev *dev, struct scatterlist *sg) 236a49e490cSVladimir Zapolskiy { 237a49e490cSVladimir Zapolskiy int err; 238a49e490cSVladimir Zapolskiy 239a49e490cSVladimir Zapolskiy if (!IS_ALIGNED(sg_dma_len(sg), AES_BLOCK_SIZE)) { 240a49e490cSVladimir Zapolskiy err = -EINVAL; 241a49e490cSVladimir Zapolskiy goto exit; 242a49e490cSVladimir Zapolskiy } 243a49e490cSVladimir Zapolskiy if (!sg_dma_len(sg)) { 244a49e490cSVladimir Zapolskiy err = -EINVAL; 245a49e490cSVladimir Zapolskiy goto exit; 246a49e490cSVladimir Zapolskiy } 247a49e490cSVladimir Zapolskiy 248a49e490cSVladimir Zapolskiy err = dma_map_sg(dev->dev, sg, 1, DMA_TO_DEVICE); 249a49e490cSVladimir Zapolskiy if (!err) { 250a49e490cSVladimir Zapolskiy err = -ENOMEM; 251a49e490cSVladimir Zapolskiy goto exit; 252a49e490cSVladimir Zapolskiy } 253a49e490cSVladimir Zapolskiy 254a49e490cSVladimir Zapolskiy dev->sg_src = sg; 255a49e490cSVladimir Zapolskiy err = 0; 256a49e490cSVladimir Zapolskiy 257a49e490cSVladimir Zapolskiy exit: 258a49e490cSVladimir Zapolskiy return err; 259a49e490cSVladimir Zapolskiy } 260a49e490cSVladimir Zapolskiy 261a49e490cSVladimir Zapolskiy static void s5p_aes_tx(struct s5p_aes_dev *dev) 262a49e490cSVladimir Zapolskiy { 263a49e490cSVladimir Zapolskiy int err = 0; 264a49e490cSVladimir Zapolskiy 265a49e490cSVladimir Zapolskiy s5p_unset_outdata(dev); 266a49e490cSVladimir Zapolskiy 267a49e490cSVladimir Zapolskiy if (!sg_is_last(dev->sg_dst)) { 268a49e490cSVladimir Zapolskiy err = s5p_set_outdata(dev, sg_next(dev->sg_dst)); 269a49e490cSVladimir Zapolskiy if (err) { 270a49e490cSVladimir Zapolskiy s5p_aes_complete(dev, err); 271a49e490cSVladimir Zapolskiy return; 272a49e490cSVladimir Zapolskiy } 273a49e490cSVladimir Zapolskiy 274a49e490cSVladimir Zapolskiy s5p_set_dma_outdata(dev, dev->sg_dst); 275a49e490cSVladimir Zapolskiy } else 276a49e490cSVladimir Zapolskiy s5p_aes_complete(dev, err); 277a49e490cSVladimir Zapolskiy } 278a49e490cSVladimir Zapolskiy 279a49e490cSVladimir Zapolskiy static void s5p_aes_rx(struct s5p_aes_dev *dev) 280a49e490cSVladimir Zapolskiy { 281a49e490cSVladimir Zapolskiy int err; 282a49e490cSVladimir Zapolskiy 283a49e490cSVladimir Zapolskiy s5p_unset_indata(dev); 284a49e490cSVladimir Zapolskiy 285a49e490cSVladimir Zapolskiy if (!sg_is_last(dev->sg_src)) { 286a49e490cSVladimir Zapolskiy err = s5p_set_indata(dev, sg_next(dev->sg_src)); 287a49e490cSVladimir Zapolskiy if (err) { 288a49e490cSVladimir Zapolskiy s5p_aes_complete(dev, err); 289a49e490cSVladimir Zapolskiy return; 290a49e490cSVladimir Zapolskiy } 291a49e490cSVladimir Zapolskiy 292a49e490cSVladimir Zapolskiy s5p_set_dma_indata(dev, dev->sg_src); 293a49e490cSVladimir Zapolskiy } 294a49e490cSVladimir Zapolskiy } 295a49e490cSVladimir Zapolskiy 296a49e490cSVladimir Zapolskiy static irqreturn_t s5p_aes_interrupt(int irq, void *dev_id) 297a49e490cSVladimir Zapolskiy { 298a49e490cSVladimir Zapolskiy struct platform_device *pdev = dev_id; 299a49e490cSVladimir Zapolskiy struct s5p_aes_dev *dev = platform_get_drvdata(pdev); 300a49e490cSVladimir Zapolskiy uint32_t status; 301a49e490cSVladimir Zapolskiy unsigned long flags; 302a49e490cSVladimir Zapolskiy 303a49e490cSVladimir Zapolskiy spin_lock_irqsave(&dev->lock, flags); 304a49e490cSVladimir Zapolskiy 305a49e490cSVladimir Zapolskiy if (irq == dev->irq_fc) { 306a49e490cSVladimir Zapolskiy status = SSS_READ(dev, FCINTSTAT); 307a49e490cSVladimir Zapolskiy if (status & SSS_FCINTSTAT_BRDMAINT) 308a49e490cSVladimir Zapolskiy s5p_aes_rx(dev); 309a49e490cSVladimir Zapolskiy if (status & SSS_FCINTSTAT_BTDMAINT) 310a49e490cSVladimir Zapolskiy s5p_aes_tx(dev); 311a49e490cSVladimir Zapolskiy 312a49e490cSVladimir Zapolskiy SSS_WRITE(dev, FCINTPEND, status); 313a49e490cSVladimir Zapolskiy } 314a49e490cSVladimir Zapolskiy 315a49e490cSVladimir Zapolskiy spin_unlock_irqrestore(&dev->lock, flags); 316a49e490cSVladimir Zapolskiy 317a49e490cSVladimir Zapolskiy return IRQ_HANDLED; 318a49e490cSVladimir Zapolskiy } 319a49e490cSVladimir Zapolskiy 320a49e490cSVladimir Zapolskiy static void s5p_set_aes(struct s5p_aes_dev *dev, 321a49e490cSVladimir Zapolskiy uint8_t *key, uint8_t *iv, unsigned int keylen) 322a49e490cSVladimir Zapolskiy { 323a49e490cSVladimir Zapolskiy void __iomem *keystart; 324a49e490cSVladimir Zapolskiy 325a49e490cSVladimir Zapolskiy memcpy(dev->ioaddr + SSS_REG_AES_IV_DATA(0), iv, 0x10); 326a49e490cSVladimir Zapolskiy 327a49e490cSVladimir Zapolskiy if (keylen == AES_KEYSIZE_256) 328a49e490cSVladimir Zapolskiy keystart = dev->ioaddr + SSS_REG_AES_KEY_DATA(0); 329a49e490cSVladimir Zapolskiy else if (keylen == AES_KEYSIZE_192) 330a49e490cSVladimir Zapolskiy keystart = dev->ioaddr + SSS_REG_AES_KEY_DATA(2); 331a49e490cSVladimir Zapolskiy else 332a49e490cSVladimir Zapolskiy keystart = dev->ioaddr + SSS_REG_AES_KEY_DATA(4); 333a49e490cSVladimir Zapolskiy 334a49e490cSVladimir Zapolskiy memcpy(keystart, key, keylen); 335a49e490cSVladimir Zapolskiy } 336a49e490cSVladimir Zapolskiy 337a49e490cSVladimir Zapolskiy static void s5p_aes_crypt_start(struct s5p_aes_dev *dev, unsigned long mode) 338a49e490cSVladimir Zapolskiy { 339a49e490cSVladimir Zapolskiy struct ablkcipher_request *req = dev->req; 340a49e490cSVladimir Zapolskiy 341a49e490cSVladimir Zapolskiy uint32_t aes_control; 342a49e490cSVladimir Zapolskiy int err; 343a49e490cSVladimir Zapolskiy unsigned long flags; 344a49e490cSVladimir Zapolskiy 345a49e490cSVladimir Zapolskiy aes_control = SSS_AES_KEY_CHANGE_MODE; 346a49e490cSVladimir Zapolskiy if (mode & FLAGS_AES_DECRYPT) 347a49e490cSVladimir Zapolskiy aes_control |= SSS_AES_MODE_DECRYPT; 348a49e490cSVladimir Zapolskiy 349a49e490cSVladimir Zapolskiy if ((mode & FLAGS_AES_MODE_MASK) == FLAGS_AES_CBC) 350a49e490cSVladimir Zapolskiy aes_control |= SSS_AES_CHAIN_MODE_CBC; 351a49e490cSVladimir Zapolskiy else if ((mode & FLAGS_AES_MODE_MASK) == FLAGS_AES_CTR) 352a49e490cSVladimir Zapolskiy aes_control |= SSS_AES_CHAIN_MODE_CTR; 353a49e490cSVladimir Zapolskiy 354a49e490cSVladimir Zapolskiy if (dev->ctx->keylen == AES_KEYSIZE_192) 355a49e490cSVladimir Zapolskiy aes_control |= SSS_AES_KEY_SIZE_192; 356a49e490cSVladimir Zapolskiy else if (dev->ctx->keylen == AES_KEYSIZE_256) 357a49e490cSVladimir Zapolskiy aes_control |= SSS_AES_KEY_SIZE_256; 358a49e490cSVladimir Zapolskiy 359a49e490cSVladimir Zapolskiy aes_control |= SSS_AES_FIFO_MODE; 360a49e490cSVladimir Zapolskiy 361a49e490cSVladimir Zapolskiy /* as a variant it is possible to use byte swapping on DMA side */ 362a49e490cSVladimir Zapolskiy aes_control |= SSS_AES_BYTESWAP_DI 363a49e490cSVladimir Zapolskiy | SSS_AES_BYTESWAP_DO 364a49e490cSVladimir Zapolskiy | SSS_AES_BYTESWAP_IV 365a49e490cSVladimir Zapolskiy | SSS_AES_BYTESWAP_KEY 366a49e490cSVladimir Zapolskiy | SSS_AES_BYTESWAP_CNT; 367a49e490cSVladimir Zapolskiy 368a49e490cSVladimir Zapolskiy spin_lock_irqsave(&dev->lock, flags); 369a49e490cSVladimir Zapolskiy 370a49e490cSVladimir Zapolskiy SSS_WRITE(dev, FCINTENCLR, 371a49e490cSVladimir Zapolskiy SSS_FCINTENCLR_BTDMAINTENCLR | SSS_FCINTENCLR_BRDMAINTENCLR); 372a49e490cSVladimir Zapolskiy SSS_WRITE(dev, FCFIFOCTRL, 0x00); 373a49e490cSVladimir Zapolskiy 374a49e490cSVladimir Zapolskiy err = s5p_set_indata(dev, req->src); 375a49e490cSVladimir Zapolskiy if (err) 376a49e490cSVladimir Zapolskiy goto indata_error; 377a49e490cSVladimir Zapolskiy 378a49e490cSVladimir Zapolskiy err = s5p_set_outdata(dev, req->dst); 379a49e490cSVladimir Zapolskiy if (err) 380a49e490cSVladimir Zapolskiy goto outdata_error; 381a49e490cSVladimir Zapolskiy 382a49e490cSVladimir Zapolskiy SSS_WRITE(dev, AES_CONTROL, aes_control); 383a49e490cSVladimir Zapolskiy s5p_set_aes(dev, dev->ctx->aes_key, req->info, dev->ctx->keylen); 384a49e490cSVladimir Zapolskiy 385a49e490cSVladimir Zapolskiy s5p_set_dma_indata(dev, req->src); 386a49e490cSVladimir Zapolskiy s5p_set_dma_outdata(dev, req->dst); 387a49e490cSVladimir Zapolskiy 388a49e490cSVladimir Zapolskiy SSS_WRITE(dev, FCINTENSET, 389a49e490cSVladimir Zapolskiy SSS_FCINTENSET_BTDMAINTENSET | SSS_FCINTENSET_BRDMAINTENSET); 390a49e490cSVladimir Zapolskiy 391a49e490cSVladimir Zapolskiy spin_unlock_irqrestore(&dev->lock, flags); 392a49e490cSVladimir Zapolskiy 393a49e490cSVladimir Zapolskiy return; 394a49e490cSVladimir Zapolskiy 395a49e490cSVladimir Zapolskiy outdata_error: 396a49e490cSVladimir Zapolskiy s5p_unset_indata(dev); 397a49e490cSVladimir Zapolskiy 398a49e490cSVladimir Zapolskiy indata_error: 399a49e490cSVladimir Zapolskiy s5p_aes_complete(dev, err); 400a49e490cSVladimir Zapolskiy spin_unlock_irqrestore(&dev->lock, flags); 401a49e490cSVladimir Zapolskiy } 402a49e490cSVladimir Zapolskiy 403a49e490cSVladimir Zapolskiy static void s5p_tasklet_cb(unsigned long data) 404a49e490cSVladimir Zapolskiy { 405a49e490cSVladimir Zapolskiy struct s5p_aes_dev *dev = (struct s5p_aes_dev *)data; 406a49e490cSVladimir Zapolskiy struct crypto_async_request *async_req, *backlog; 407a49e490cSVladimir Zapolskiy struct s5p_aes_reqctx *reqctx; 408a49e490cSVladimir Zapolskiy unsigned long flags; 409a49e490cSVladimir Zapolskiy 410a49e490cSVladimir Zapolskiy spin_lock_irqsave(&dev->lock, flags); 411a49e490cSVladimir Zapolskiy backlog = crypto_get_backlog(&dev->queue); 412a49e490cSVladimir Zapolskiy async_req = crypto_dequeue_request(&dev->queue); 413a49e490cSVladimir Zapolskiy spin_unlock_irqrestore(&dev->lock, flags); 414a49e490cSVladimir Zapolskiy 415a49e490cSVladimir Zapolskiy if (!async_req) 416a49e490cSVladimir Zapolskiy return; 417a49e490cSVladimir Zapolskiy 418a49e490cSVladimir Zapolskiy if (backlog) 419a49e490cSVladimir Zapolskiy backlog->complete(backlog, -EINPROGRESS); 420a49e490cSVladimir Zapolskiy 421a49e490cSVladimir Zapolskiy dev->req = ablkcipher_request_cast(async_req); 422a49e490cSVladimir Zapolskiy dev->ctx = crypto_tfm_ctx(dev->req->base.tfm); 423a49e490cSVladimir Zapolskiy reqctx = ablkcipher_request_ctx(dev->req); 424a49e490cSVladimir Zapolskiy 425a49e490cSVladimir Zapolskiy s5p_aes_crypt_start(dev, reqctx->mode); 426a49e490cSVladimir Zapolskiy } 427a49e490cSVladimir Zapolskiy 428a49e490cSVladimir Zapolskiy static int s5p_aes_handle_req(struct s5p_aes_dev *dev, 429a49e490cSVladimir Zapolskiy struct ablkcipher_request *req) 430a49e490cSVladimir Zapolskiy { 431a49e490cSVladimir Zapolskiy unsigned long flags; 432a49e490cSVladimir Zapolskiy int err; 433a49e490cSVladimir Zapolskiy 434a49e490cSVladimir Zapolskiy spin_lock_irqsave(&dev->lock, flags); 435a49e490cSVladimir Zapolskiy if (dev->busy) { 436a49e490cSVladimir Zapolskiy err = -EAGAIN; 437a49e490cSVladimir Zapolskiy spin_unlock_irqrestore(&dev->lock, flags); 438a49e490cSVladimir Zapolskiy goto exit; 439a49e490cSVladimir Zapolskiy } 440a49e490cSVladimir Zapolskiy dev->busy = true; 441a49e490cSVladimir Zapolskiy 442a49e490cSVladimir Zapolskiy err = ablkcipher_enqueue_request(&dev->queue, req); 443a49e490cSVladimir Zapolskiy spin_unlock_irqrestore(&dev->lock, flags); 444a49e490cSVladimir Zapolskiy 445a49e490cSVladimir Zapolskiy tasklet_schedule(&dev->tasklet); 446a49e490cSVladimir Zapolskiy 447a49e490cSVladimir Zapolskiy exit: 448a49e490cSVladimir Zapolskiy return err; 449a49e490cSVladimir Zapolskiy } 450a49e490cSVladimir Zapolskiy 451a49e490cSVladimir Zapolskiy static int s5p_aes_crypt(struct ablkcipher_request *req, unsigned long mode) 452a49e490cSVladimir Zapolskiy { 453a49e490cSVladimir Zapolskiy struct crypto_ablkcipher *tfm = crypto_ablkcipher_reqtfm(req); 454a49e490cSVladimir Zapolskiy struct s5p_aes_ctx *ctx = crypto_ablkcipher_ctx(tfm); 455a49e490cSVladimir Zapolskiy struct s5p_aes_reqctx *reqctx = ablkcipher_request_ctx(req); 456a49e490cSVladimir Zapolskiy struct s5p_aes_dev *dev = ctx->dev; 457a49e490cSVladimir Zapolskiy 458a49e490cSVladimir Zapolskiy if (!IS_ALIGNED(req->nbytes, AES_BLOCK_SIZE)) { 459a49e490cSVladimir Zapolskiy pr_err("request size is not exact amount of AES blocks\n"); 460a49e490cSVladimir Zapolskiy return -EINVAL; 461a49e490cSVladimir Zapolskiy } 462a49e490cSVladimir Zapolskiy 463a49e490cSVladimir Zapolskiy reqctx->mode = mode; 464a49e490cSVladimir Zapolskiy 465a49e490cSVladimir Zapolskiy return s5p_aes_handle_req(dev, req); 466a49e490cSVladimir Zapolskiy } 467a49e490cSVladimir Zapolskiy 468a49e490cSVladimir Zapolskiy static int s5p_aes_setkey(struct crypto_ablkcipher *cipher, 469a49e490cSVladimir Zapolskiy const uint8_t *key, unsigned int keylen) 470a49e490cSVladimir Zapolskiy { 471a49e490cSVladimir Zapolskiy struct crypto_tfm *tfm = crypto_ablkcipher_tfm(cipher); 472a49e490cSVladimir Zapolskiy struct s5p_aes_ctx *ctx = crypto_tfm_ctx(tfm); 473a49e490cSVladimir Zapolskiy 474a49e490cSVladimir Zapolskiy if (keylen != AES_KEYSIZE_128 && 475a49e490cSVladimir Zapolskiy keylen != AES_KEYSIZE_192 && 476a49e490cSVladimir Zapolskiy keylen != AES_KEYSIZE_256) 477a49e490cSVladimir Zapolskiy return -EINVAL; 478a49e490cSVladimir Zapolskiy 479a49e490cSVladimir Zapolskiy memcpy(ctx->aes_key, key, keylen); 480a49e490cSVladimir Zapolskiy ctx->keylen = keylen; 481a49e490cSVladimir Zapolskiy 482a49e490cSVladimir Zapolskiy return 0; 483a49e490cSVladimir Zapolskiy } 484a49e490cSVladimir Zapolskiy 485a49e490cSVladimir Zapolskiy static int s5p_aes_ecb_encrypt(struct ablkcipher_request *req) 486a49e490cSVladimir Zapolskiy { 487a49e490cSVladimir Zapolskiy return s5p_aes_crypt(req, 0); 488a49e490cSVladimir Zapolskiy } 489a49e490cSVladimir Zapolskiy 490a49e490cSVladimir Zapolskiy static int s5p_aes_ecb_decrypt(struct ablkcipher_request *req) 491a49e490cSVladimir Zapolskiy { 492a49e490cSVladimir Zapolskiy return s5p_aes_crypt(req, FLAGS_AES_DECRYPT); 493a49e490cSVladimir Zapolskiy } 494a49e490cSVladimir Zapolskiy 495a49e490cSVladimir Zapolskiy static int s5p_aes_cbc_encrypt(struct ablkcipher_request *req) 496a49e490cSVladimir Zapolskiy { 497a49e490cSVladimir Zapolskiy return s5p_aes_crypt(req, FLAGS_AES_CBC); 498a49e490cSVladimir Zapolskiy } 499a49e490cSVladimir Zapolskiy 500a49e490cSVladimir Zapolskiy static int s5p_aes_cbc_decrypt(struct ablkcipher_request *req) 501a49e490cSVladimir Zapolskiy { 502a49e490cSVladimir Zapolskiy return s5p_aes_crypt(req, FLAGS_AES_DECRYPT | FLAGS_AES_CBC); 503a49e490cSVladimir Zapolskiy } 504a49e490cSVladimir Zapolskiy 505a49e490cSVladimir Zapolskiy static int s5p_aes_cra_init(struct crypto_tfm *tfm) 506a49e490cSVladimir Zapolskiy { 507a49e490cSVladimir Zapolskiy struct s5p_aes_ctx *ctx = crypto_tfm_ctx(tfm); 508a49e490cSVladimir Zapolskiy 509a49e490cSVladimir Zapolskiy ctx->dev = s5p_dev; 510a49e490cSVladimir Zapolskiy tfm->crt_ablkcipher.reqsize = sizeof(struct s5p_aes_reqctx); 511a49e490cSVladimir Zapolskiy 512a49e490cSVladimir Zapolskiy return 0; 513a49e490cSVladimir Zapolskiy } 514a49e490cSVladimir Zapolskiy 515a49e490cSVladimir Zapolskiy static struct crypto_alg algs[] = { 516a49e490cSVladimir Zapolskiy { 517a49e490cSVladimir Zapolskiy .cra_name = "ecb(aes)", 518a49e490cSVladimir Zapolskiy .cra_driver_name = "ecb-aes-s5p", 519a49e490cSVladimir Zapolskiy .cra_priority = 100, 520a49e490cSVladimir Zapolskiy .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | 521d912bb76SNikos Mavrogiannopoulos CRYPTO_ALG_ASYNC | 522d912bb76SNikos Mavrogiannopoulos CRYPTO_ALG_KERN_DRIVER_ONLY, 523a49e490cSVladimir Zapolskiy .cra_blocksize = AES_BLOCK_SIZE, 524a49e490cSVladimir Zapolskiy .cra_ctxsize = sizeof(struct s5p_aes_ctx), 525a49e490cSVladimir Zapolskiy .cra_alignmask = 0x0f, 526a49e490cSVladimir Zapolskiy .cra_type = &crypto_ablkcipher_type, 527a49e490cSVladimir Zapolskiy .cra_module = THIS_MODULE, 528a49e490cSVladimir Zapolskiy .cra_init = s5p_aes_cra_init, 529a49e490cSVladimir Zapolskiy .cra_u.ablkcipher = { 530a49e490cSVladimir Zapolskiy .min_keysize = AES_MIN_KEY_SIZE, 531a49e490cSVladimir Zapolskiy .max_keysize = AES_MAX_KEY_SIZE, 532a49e490cSVladimir Zapolskiy .setkey = s5p_aes_setkey, 533a49e490cSVladimir Zapolskiy .encrypt = s5p_aes_ecb_encrypt, 534a49e490cSVladimir Zapolskiy .decrypt = s5p_aes_ecb_decrypt, 535a49e490cSVladimir Zapolskiy } 536a49e490cSVladimir Zapolskiy }, 537a49e490cSVladimir Zapolskiy { 538a49e490cSVladimir Zapolskiy .cra_name = "cbc(aes)", 539a49e490cSVladimir Zapolskiy .cra_driver_name = "cbc-aes-s5p", 540a49e490cSVladimir Zapolskiy .cra_priority = 100, 541a49e490cSVladimir Zapolskiy .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | 542d912bb76SNikos Mavrogiannopoulos CRYPTO_ALG_ASYNC | 543d912bb76SNikos Mavrogiannopoulos CRYPTO_ALG_KERN_DRIVER_ONLY, 544a49e490cSVladimir Zapolskiy .cra_blocksize = AES_BLOCK_SIZE, 545a49e490cSVladimir Zapolskiy .cra_ctxsize = sizeof(struct s5p_aes_ctx), 546a49e490cSVladimir Zapolskiy .cra_alignmask = 0x0f, 547a49e490cSVladimir Zapolskiy .cra_type = &crypto_ablkcipher_type, 548a49e490cSVladimir Zapolskiy .cra_module = THIS_MODULE, 549a49e490cSVladimir Zapolskiy .cra_init = s5p_aes_cra_init, 550a49e490cSVladimir Zapolskiy .cra_u.ablkcipher = { 551a49e490cSVladimir Zapolskiy .min_keysize = AES_MIN_KEY_SIZE, 552a49e490cSVladimir Zapolskiy .max_keysize = AES_MAX_KEY_SIZE, 553a49e490cSVladimir Zapolskiy .ivsize = AES_BLOCK_SIZE, 554a49e490cSVladimir Zapolskiy .setkey = s5p_aes_setkey, 555a49e490cSVladimir Zapolskiy .encrypt = s5p_aes_cbc_encrypt, 556a49e490cSVladimir Zapolskiy .decrypt = s5p_aes_cbc_decrypt, 557a49e490cSVladimir Zapolskiy } 558a49e490cSVladimir Zapolskiy }, 559a49e490cSVladimir Zapolskiy }; 560a49e490cSVladimir Zapolskiy 561a49e490cSVladimir Zapolskiy static int s5p_aes_probe(struct platform_device *pdev) 562a49e490cSVladimir Zapolskiy { 563a49e490cSVladimir Zapolskiy int i, j, err = -ENODEV; 564a49e490cSVladimir Zapolskiy struct s5p_aes_dev *pdata; 565a49e490cSVladimir Zapolskiy struct device *dev = &pdev->dev; 566a49e490cSVladimir Zapolskiy struct resource *res; 567a49e490cSVladimir Zapolskiy 568a49e490cSVladimir Zapolskiy if (s5p_dev) 569a49e490cSVladimir Zapolskiy return -EEXIST; 570a49e490cSVladimir Zapolskiy 571a49e490cSVladimir Zapolskiy pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); 572a49e490cSVladimir Zapolskiy if (!pdata) 573a49e490cSVladimir Zapolskiy return -ENOMEM; 574a49e490cSVladimir Zapolskiy 5750fdefe2cSJingoo Han res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 5760fdefe2cSJingoo Han pdata->ioaddr = devm_ioremap_resource(&pdev->dev, res); 5770fdefe2cSJingoo Han if (IS_ERR(pdata->ioaddr)) 5780fdefe2cSJingoo Han return PTR_ERR(pdata->ioaddr); 579a49e490cSVladimir Zapolskiy 5805c22ba66SJingoo Han pdata->clk = devm_clk_get(dev, "secss"); 581a49e490cSVladimir Zapolskiy if (IS_ERR(pdata->clk)) { 582a49e490cSVladimir Zapolskiy dev_err(dev, "failed to find secss clock source\n"); 583a49e490cSVladimir Zapolskiy return -ENOENT; 584a49e490cSVladimir Zapolskiy } 585a49e490cSVladimir Zapolskiy 586a49e490cSVladimir Zapolskiy clk_enable(pdata->clk); 587a49e490cSVladimir Zapolskiy 588a49e490cSVladimir Zapolskiy spin_lock_init(&pdata->lock); 589a49e490cSVladimir Zapolskiy 590*96fc70b6SNaveen Krishna Chatradhi pdata->irq_fc = platform_get_irq(pdev, 0); 591a49e490cSVladimir Zapolskiy if (pdata->irq_fc < 0) { 592a49e490cSVladimir Zapolskiy err = pdata->irq_fc; 593a49e490cSVladimir Zapolskiy dev_warn(dev, "feed control interrupt is not available.\n"); 594a49e490cSVladimir Zapolskiy goto err_irq; 595a49e490cSVladimir Zapolskiy } 596a49e490cSVladimir Zapolskiy err = devm_request_irq(dev, pdata->irq_fc, s5p_aes_interrupt, 597a49e490cSVladimir Zapolskiy IRQF_SHARED, pdev->name, pdev); 598a49e490cSVladimir Zapolskiy if (err < 0) { 599a49e490cSVladimir Zapolskiy dev_warn(dev, "feed control interrupt is not available.\n"); 600a49e490cSVladimir Zapolskiy goto err_irq; 601a49e490cSVladimir Zapolskiy } 602a49e490cSVladimir Zapolskiy 603*96fc70b6SNaveen Krishna Chatradhi pdata->irq_hash = platform_get_irq(pdev, 1); 604*96fc70b6SNaveen Krishna Chatradhi if (pdata->irq_hash < 0) { 605*96fc70b6SNaveen Krishna Chatradhi err = pdata->irq_hash; 606*96fc70b6SNaveen Krishna Chatradhi dev_warn(dev, "hash interrupt is not available.\n"); 607*96fc70b6SNaveen Krishna Chatradhi goto err_irq; 608*96fc70b6SNaveen Krishna Chatradhi } 609*96fc70b6SNaveen Krishna Chatradhi err = devm_request_irq(dev, pdata->irq_hash, s5p_aes_interrupt, 610*96fc70b6SNaveen Krishna Chatradhi IRQF_SHARED, pdev->name, pdev); 611*96fc70b6SNaveen Krishna Chatradhi if (err < 0) { 612*96fc70b6SNaveen Krishna Chatradhi dev_warn(dev, "hash interrupt is not available.\n"); 613*96fc70b6SNaveen Krishna Chatradhi goto err_irq; 614*96fc70b6SNaveen Krishna Chatradhi } 615*96fc70b6SNaveen Krishna Chatradhi 616a49e490cSVladimir Zapolskiy pdata->dev = dev; 617a49e490cSVladimir Zapolskiy platform_set_drvdata(pdev, pdata); 618a49e490cSVladimir Zapolskiy s5p_dev = pdata; 619a49e490cSVladimir Zapolskiy 620a49e490cSVladimir Zapolskiy tasklet_init(&pdata->tasklet, s5p_tasklet_cb, (unsigned long)pdata); 621a49e490cSVladimir Zapolskiy crypto_init_queue(&pdata->queue, CRYPTO_QUEUE_LEN); 622a49e490cSVladimir Zapolskiy 623a49e490cSVladimir Zapolskiy for (i = 0; i < ARRAY_SIZE(algs); i++) { 624a49e490cSVladimir Zapolskiy err = crypto_register_alg(&algs[i]); 625a49e490cSVladimir Zapolskiy if (err) 626a49e490cSVladimir Zapolskiy goto err_algs; 627a49e490cSVladimir Zapolskiy } 628a49e490cSVladimir Zapolskiy 629a49e490cSVladimir Zapolskiy pr_info("s5p-sss driver registered\n"); 630a49e490cSVladimir Zapolskiy 631a49e490cSVladimir Zapolskiy return 0; 632a49e490cSVladimir Zapolskiy 633a49e490cSVladimir Zapolskiy err_algs: 634a49e490cSVladimir Zapolskiy dev_err(dev, "can't register '%s': %d\n", algs[i].cra_name, err); 635a49e490cSVladimir Zapolskiy 636a49e490cSVladimir Zapolskiy for (j = 0; j < i; j++) 637a49e490cSVladimir Zapolskiy crypto_unregister_alg(&algs[j]); 638a49e490cSVladimir Zapolskiy 639a49e490cSVladimir Zapolskiy tasklet_kill(&pdata->tasklet); 640a49e490cSVladimir Zapolskiy 641a49e490cSVladimir Zapolskiy err_irq: 642a49e490cSVladimir Zapolskiy clk_disable(pdata->clk); 643a49e490cSVladimir Zapolskiy 644a49e490cSVladimir Zapolskiy s5p_dev = NULL; 645a49e490cSVladimir Zapolskiy 646a49e490cSVladimir Zapolskiy return err; 647a49e490cSVladimir Zapolskiy } 648a49e490cSVladimir Zapolskiy 649a49e490cSVladimir Zapolskiy static int s5p_aes_remove(struct platform_device *pdev) 650a49e490cSVladimir Zapolskiy { 651a49e490cSVladimir Zapolskiy struct s5p_aes_dev *pdata = platform_get_drvdata(pdev); 652a49e490cSVladimir Zapolskiy int i; 653a49e490cSVladimir Zapolskiy 654a49e490cSVladimir Zapolskiy if (!pdata) 655a49e490cSVladimir Zapolskiy return -ENODEV; 656a49e490cSVladimir Zapolskiy 657a49e490cSVladimir Zapolskiy for (i = 0; i < ARRAY_SIZE(algs); i++) 658a49e490cSVladimir Zapolskiy crypto_unregister_alg(&algs[i]); 659a49e490cSVladimir Zapolskiy 660a49e490cSVladimir Zapolskiy tasklet_kill(&pdata->tasklet); 661a49e490cSVladimir Zapolskiy 662a49e490cSVladimir Zapolskiy clk_disable(pdata->clk); 663a49e490cSVladimir Zapolskiy 664a49e490cSVladimir Zapolskiy s5p_dev = NULL; 665a49e490cSVladimir Zapolskiy 666a49e490cSVladimir Zapolskiy return 0; 667a49e490cSVladimir Zapolskiy } 668a49e490cSVladimir Zapolskiy 669a49e490cSVladimir Zapolskiy static struct platform_driver s5p_aes_crypto = { 670a49e490cSVladimir Zapolskiy .probe = s5p_aes_probe, 671a49e490cSVladimir Zapolskiy .remove = s5p_aes_remove, 672a49e490cSVladimir Zapolskiy .driver = { 673a49e490cSVladimir Zapolskiy .owner = THIS_MODULE, 674a49e490cSVladimir Zapolskiy .name = "s5p-secss", 675a49e490cSVladimir Zapolskiy }, 676a49e490cSVladimir Zapolskiy }; 677a49e490cSVladimir Zapolskiy 678741e8c2dSAxel Lin module_platform_driver(s5p_aes_crypto); 679a49e490cSVladimir Zapolskiy 680a49e490cSVladimir Zapolskiy MODULE_DESCRIPTION("S5PV210 AES hw acceleration support."); 681a49e490cSVladimir Zapolskiy MODULE_LICENSE("GPL v2"); 682a49e490cSVladimir Zapolskiy MODULE_AUTHOR("Vladimir Zapolskiy <vzapolskiy@gmail.com>"); 683