atmel-aes.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206
  1. /*
  2. * Cryptographic API.
  3. *
  4. * Support for ATMEL AES HW acceleration.
  5. *
  6. * Copyright (c) 2012 Eukréa Electromatique - ATMEL
  7. * Author: Nicolas Royer <nicolas@eukrea.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as published
  11. * by the Free Software Foundation.
  12. *
  13. * Some ideas are from omap-aes.c driver.
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/module.h>
  17. #include <linux/slab.h>
  18. #include <linux/err.h>
  19. #include <linux/clk.h>
  20. #include <linux/io.h>
  21. #include <linux/hw_random.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/device.h>
  24. #include <linux/module.h>
  25. #include <linux/init.h>
  26. #include <linux/errno.h>
  27. #include <linux/interrupt.h>
  28. #include <linux/kernel.h>
  29. #include <linux/clk.h>
  30. #include <linux/irq.h>
  31. #include <linux/io.h>
  32. #include <linux/platform_device.h>
  33. #include <linux/scatterlist.h>
  34. #include <linux/dma-mapping.h>
  35. #include <linux/delay.h>
  36. #include <linux/crypto.h>
  37. #include <linux/cryptohash.h>
  38. #include <crypto/scatterwalk.h>
  39. #include <crypto/algapi.h>
  40. #include <crypto/aes.h>
  41. #include <crypto/hash.h>
  42. #include <crypto/internal/hash.h>
  43. #include <linux/platform_data/atmel-aes.h>
  44. #include "atmel-aes-regs.h"
  45. #define CFB8_BLOCK_SIZE 1
  46. #define CFB16_BLOCK_SIZE 2
  47. #define CFB32_BLOCK_SIZE 4
  48. #define CFB64_BLOCK_SIZE 8
  49. /* AES flags */
  50. #define AES_FLAGS_MODE_MASK 0x01ff
  51. #define AES_FLAGS_ENCRYPT BIT(0)
  52. #define AES_FLAGS_CBC BIT(1)
  53. #define AES_FLAGS_CFB BIT(2)
  54. #define AES_FLAGS_CFB8 BIT(3)
  55. #define AES_FLAGS_CFB16 BIT(4)
  56. #define AES_FLAGS_CFB32 BIT(5)
  57. #define AES_FLAGS_CFB64 BIT(6)
  58. #define AES_FLAGS_OFB BIT(7)
  59. #define AES_FLAGS_CTR BIT(8)
  60. #define AES_FLAGS_INIT BIT(16)
  61. #define AES_FLAGS_DMA BIT(17)
  62. #define AES_FLAGS_BUSY BIT(18)
  63. #define AES_FLAGS_DUALBUFF BIT(24)
  64. #define ATMEL_AES_QUEUE_LENGTH 1
  65. #define ATMEL_AES_CACHE_SIZE 0
  66. #define ATMEL_AES_DMA_THRESHOLD 16
  67. struct atmel_aes_dev;
  68. struct atmel_aes_ctx {
  69. struct atmel_aes_dev *dd;
  70. int keylen;
  71. u32 key[AES_KEYSIZE_256 / sizeof(u32)];
  72. };
  73. struct atmel_aes_reqctx {
  74. unsigned long mode;
  75. };
  76. struct atmel_aes_dma {
  77. struct dma_chan *chan;
  78. struct dma_slave_config dma_conf;
  79. };
  80. struct atmel_aes_dev {
  81. struct list_head list;
  82. unsigned long phys_base;
  83. void __iomem *io_base;
  84. struct atmel_aes_ctx *ctx;
  85. struct device *dev;
  86. struct clk *iclk;
  87. int irq;
  88. unsigned long flags;
  89. int err;
  90. spinlock_t lock;
  91. struct crypto_queue queue;
  92. struct tasklet_struct done_task;
  93. struct tasklet_struct queue_task;
  94. struct ablkcipher_request *req;
  95. size_t total;
  96. struct scatterlist *in_sg;
  97. unsigned int nb_in_sg;
  98. struct scatterlist *out_sg;
  99. unsigned int nb_out_sg;
  100. size_t bufcnt;
  101. u8 buf_in[ATMEL_AES_DMA_THRESHOLD] __aligned(sizeof(u32));
  102. int dma_in;
  103. struct atmel_aes_dma dma_lch_in;
  104. u8 buf_out[ATMEL_AES_DMA_THRESHOLD] __aligned(sizeof(u32));
  105. int dma_out;
  106. struct atmel_aes_dma dma_lch_out;
  107. u32 hw_version;
  108. };
  109. struct atmel_aes_drv {
  110. struct list_head dev_list;
  111. spinlock_t lock;
  112. };
  113. static struct atmel_aes_drv atmel_aes = {
  114. .dev_list = LIST_HEAD_INIT(atmel_aes.dev_list),
  115. .lock = __SPIN_LOCK_UNLOCKED(atmel_aes.lock),
  116. };
  117. static int atmel_aes_sg_length(struct ablkcipher_request *req,
  118. struct scatterlist *sg)
  119. {
  120. unsigned int total = req->nbytes;
  121. int sg_nb;
  122. unsigned int len;
  123. struct scatterlist *sg_list;
  124. sg_nb = 0;
  125. sg_list = sg;
  126. total = req->nbytes;
  127. while (total) {
  128. len = min(sg_list->length, total);
  129. sg_nb++;
  130. total -= len;
  131. sg_list = sg_next(sg_list);
  132. if (!sg_list)
  133. total = 0;
  134. }
  135. return sg_nb;
  136. }
  137. static inline u32 atmel_aes_read(struct atmel_aes_dev *dd, u32 offset)
  138. {
  139. return readl_relaxed(dd->io_base + offset);
  140. }
  141. static inline void atmel_aes_write(struct atmel_aes_dev *dd,
  142. u32 offset, u32 value)
  143. {
  144. writel_relaxed(value, dd->io_base + offset);
  145. }
  146. static void atmel_aes_read_n(struct atmel_aes_dev *dd, u32 offset,
  147. u32 *value, int count)
  148. {
  149. for (; count--; value++, offset += 4)
  150. *value = atmel_aes_read(dd, offset);
  151. }
  152. static void atmel_aes_write_n(struct atmel_aes_dev *dd, u32 offset,
  153. u32 *value, int count)
  154. {
  155. for (; count--; value++, offset += 4)
  156. atmel_aes_write(dd, offset, *value);
  157. }
  158. static void atmel_aes_dualbuff_test(struct atmel_aes_dev *dd)
  159. {
  160. atmel_aes_write(dd, AES_MR, AES_MR_DUALBUFF);
  161. if (atmel_aes_read(dd, AES_MR) & AES_MR_DUALBUFF)
  162. dd->flags |= AES_FLAGS_DUALBUFF;
  163. }
  164. static struct atmel_aes_dev *atmel_aes_find_dev(struct atmel_aes_ctx *ctx)
  165. {
  166. struct atmel_aes_dev *aes_dd = NULL;
  167. struct atmel_aes_dev *tmp;
  168. spin_lock_bh(&atmel_aes.lock);
  169. if (!ctx->dd) {
  170. list_for_each_entry(tmp, &atmel_aes.dev_list, list) {
  171. aes_dd = tmp;
  172. break;
  173. }
  174. ctx->dd = aes_dd;
  175. } else {
  176. aes_dd = ctx->dd;
  177. }
  178. spin_unlock_bh(&atmel_aes.lock);
  179. return aes_dd;
  180. }
  181. static int atmel_aes_hw_init(struct atmel_aes_dev *dd)
  182. {
  183. clk_prepare_enable(dd->iclk);
  184. if (!(dd->flags & AES_FLAGS_INIT)) {
  185. atmel_aes_write(dd, AES_CR, AES_CR_SWRST);
  186. atmel_aes_dualbuff_test(dd);
  187. dd->flags |= AES_FLAGS_INIT;
  188. dd->err = 0;
  189. }
  190. return 0;
  191. }
  192. static void atmel_aes_hw_version_init(struct atmel_aes_dev *dd)
  193. {
  194. atmel_aes_hw_init(dd);
  195. dd->hw_version = atmel_aes_read(dd, AES_HW_VERSION);
  196. clk_disable_unprepare(dd->iclk);
  197. }
  198. static void atmel_aes_finish_req(struct atmel_aes_dev *dd, int err)
  199. {
  200. struct ablkcipher_request *req = dd->req;
  201. clk_disable_unprepare(dd->iclk);
  202. dd->flags &= ~AES_FLAGS_BUSY;
  203. req->base.complete(&req->base, err);
  204. }
  205. static void atmel_aes_dma_callback(void *data)
  206. {
  207. struct atmel_aes_dev *dd = data;
  208. /* dma_lch_out - completed */
  209. tasklet_schedule(&dd->done_task);
  210. }
  211. static int atmel_aes_crypt_dma(struct atmel_aes_dev *dd)
  212. {
  213. struct dma_async_tx_descriptor *in_desc, *out_desc;
  214. int nb_dma_sg_in, nb_dma_sg_out;
  215. dd->nb_in_sg = atmel_aes_sg_length(dd->req, dd->in_sg);
  216. if (!dd->nb_in_sg)
  217. goto exit_err;
  218. nb_dma_sg_in = dma_map_sg(dd->dev, dd->in_sg, dd->nb_in_sg,
  219. DMA_TO_DEVICE);
  220. if (!nb_dma_sg_in)
  221. goto exit_err;
  222. in_desc = dmaengine_prep_slave_sg(dd->dma_lch_in.chan, dd->in_sg,
  223. nb_dma_sg_in, DMA_MEM_TO_DEV,
  224. DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
  225. if (!in_desc)
  226. goto unmap_in;
  227. /* callback not needed */
  228. dd->nb_out_sg = atmel_aes_sg_length(dd->req, dd->out_sg);
  229. if (!dd->nb_out_sg)
  230. goto unmap_in;
  231. nb_dma_sg_out = dma_map_sg(dd->dev, dd->out_sg, dd->nb_out_sg,
  232. DMA_FROM_DEVICE);
  233. if (!nb_dma_sg_out)
  234. goto unmap_out;
  235. out_desc = dmaengine_prep_slave_sg(dd->dma_lch_out.chan, dd->out_sg,
  236. nb_dma_sg_out, DMA_DEV_TO_MEM,
  237. DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
  238. if (!out_desc)
  239. goto unmap_out;
  240. out_desc->callback = atmel_aes_dma_callback;
  241. out_desc->callback_param = dd;
  242. dd->total -= dd->req->nbytes;
  243. dmaengine_submit(out_desc);
  244. dma_async_issue_pending(dd->dma_lch_out.chan);
  245. dmaengine_submit(in_desc);
  246. dma_async_issue_pending(dd->dma_lch_in.chan);
  247. return 0;
  248. unmap_out:
  249. dma_unmap_sg(dd->dev, dd->out_sg, dd->nb_out_sg,
  250. DMA_FROM_DEVICE);
  251. unmap_in:
  252. dma_unmap_sg(dd->dev, dd->in_sg, dd->nb_in_sg,
  253. DMA_TO_DEVICE);
  254. exit_err:
  255. return -EINVAL;
  256. }
  257. static int atmel_aes_crypt_cpu_start(struct atmel_aes_dev *dd)
  258. {
  259. dd->flags &= ~AES_FLAGS_DMA;
  260. /* use cache buffers */
  261. dd->nb_in_sg = atmel_aes_sg_length(dd->req, dd->in_sg);
  262. if (!dd->nb_in_sg)
  263. return -EINVAL;
  264. dd->nb_out_sg = atmel_aes_sg_length(dd->req, dd->out_sg);
  265. if (!dd->nb_in_sg)
  266. return -EINVAL;
  267. dd->bufcnt = sg_copy_to_buffer(dd->in_sg, dd->nb_in_sg,
  268. dd->buf_in, dd->total);
  269. if (!dd->bufcnt)
  270. return -EINVAL;
  271. dd->total -= dd->bufcnt;
  272. atmel_aes_write(dd, AES_IER, AES_INT_DATARDY);
  273. atmel_aes_write_n(dd, AES_IDATAR(0), (u32 *) dd->buf_in,
  274. dd->bufcnt >> 2);
  275. return 0;
  276. }
  277. static int atmel_aes_crypt_dma_start(struct atmel_aes_dev *dd)
  278. {
  279. int err;
  280. if (dd->flags & AES_FLAGS_CFB8) {
  281. dd->dma_lch_in.dma_conf.dst_addr_width =
  282. DMA_SLAVE_BUSWIDTH_1_BYTE;
  283. dd->dma_lch_out.dma_conf.src_addr_width =
  284. DMA_SLAVE_BUSWIDTH_1_BYTE;
  285. } else if (dd->flags & AES_FLAGS_CFB16) {
  286. dd->dma_lch_in.dma_conf.dst_addr_width =
  287. DMA_SLAVE_BUSWIDTH_2_BYTES;
  288. dd->dma_lch_out.dma_conf.src_addr_width =
  289. DMA_SLAVE_BUSWIDTH_2_BYTES;
  290. } else {
  291. dd->dma_lch_in.dma_conf.dst_addr_width =
  292. DMA_SLAVE_BUSWIDTH_4_BYTES;
  293. dd->dma_lch_out.dma_conf.src_addr_width =
  294. DMA_SLAVE_BUSWIDTH_4_BYTES;
  295. }
  296. dmaengine_slave_config(dd->dma_lch_in.chan, &dd->dma_lch_in.dma_conf);
  297. dmaengine_slave_config(dd->dma_lch_out.chan, &dd->dma_lch_out.dma_conf);
  298. dd->flags |= AES_FLAGS_DMA;
  299. err = atmel_aes_crypt_dma(dd);
  300. return err;
  301. }
  302. static int atmel_aes_write_ctrl(struct atmel_aes_dev *dd)
  303. {
  304. int err;
  305. u32 valcr = 0, valmr = 0;
  306. err = atmel_aes_hw_init(dd);
  307. if (err)
  308. return err;
  309. /* MR register must be set before IV registers */
  310. if (dd->ctx->keylen == AES_KEYSIZE_128)
  311. valmr |= AES_MR_KEYSIZE_128;
  312. else if (dd->ctx->keylen == AES_KEYSIZE_192)
  313. valmr |= AES_MR_KEYSIZE_192;
  314. else
  315. valmr |= AES_MR_KEYSIZE_256;
  316. if (dd->flags & AES_FLAGS_CBC) {
  317. valmr |= AES_MR_OPMOD_CBC;
  318. } else if (dd->flags & AES_FLAGS_CFB) {
  319. valmr |= AES_MR_OPMOD_CFB;
  320. if (dd->flags & AES_FLAGS_CFB8)
  321. valmr |= AES_MR_CFBS_8b;
  322. else if (dd->flags & AES_FLAGS_CFB16)
  323. valmr |= AES_MR_CFBS_16b;
  324. else if (dd->flags & AES_FLAGS_CFB32)
  325. valmr |= AES_MR_CFBS_32b;
  326. else if (dd->flags & AES_FLAGS_CFB64)
  327. valmr |= AES_MR_CFBS_64b;
  328. } else if (dd->flags & AES_FLAGS_OFB) {
  329. valmr |= AES_MR_OPMOD_OFB;
  330. } else if (dd->flags & AES_FLAGS_CTR) {
  331. valmr |= AES_MR_OPMOD_CTR;
  332. } else {
  333. valmr |= AES_MR_OPMOD_ECB;
  334. }
  335. if (dd->flags & AES_FLAGS_ENCRYPT)
  336. valmr |= AES_MR_CYPHER_ENC;
  337. if (dd->total > ATMEL_AES_DMA_THRESHOLD) {
  338. valmr |= AES_MR_SMOD_IDATAR0;
  339. if (dd->flags & AES_FLAGS_DUALBUFF)
  340. valmr |= AES_MR_DUALBUFF;
  341. } else {
  342. valmr |= AES_MR_SMOD_AUTO;
  343. }
  344. atmel_aes_write(dd, AES_CR, valcr);
  345. atmel_aes_write(dd, AES_MR, valmr);
  346. atmel_aes_write_n(dd, AES_KEYWR(0), dd->ctx->key,
  347. dd->ctx->keylen >> 2);
  348. if (((dd->flags & AES_FLAGS_CBC) || (dd->flags & AES_FLAGS_CFB) ||
  349. (dd->flags & AES_FLAGS_OFB) || (dd->flags & AES_FLAGS_CTR)) &&
  350. dd->req->info) {
  351. atmel_aes_write_n(dd, AES_IVR(0), dd->req->info, 4);
  352. }
  353. return 0;
  354. }
  355. static int atmel_aes_handle_queue(struct atmel_aes_dev *dd,
  356. struct ablkcipher_request *req)
  357. {
  358. struct crypto_async_request *async_req, *backlog;
  359. struct atmel_aes_ctx *ctx;
  360. struct atmel_aes_reqctx *rctx;
  361. unsigned long flags;
  362. int err, ret = 0;
  363. spin_lock_irqsave(&dd->lock, flags);
  364. if (req)
  365. ret = ablkcipher_enqueue_request(&dd->queue, req);
  366. if (dd->flags & AES_FLAGS_BUSY) {
  367. spin_unlock_irqrestore(&dd->lock, flags);
  368. return ret;
  369. }
  370. backlog = crypto_get_backlog(&dd->queue);
  371. async_req = crypto_dequeue_request(&dd->queue);
  372. if (async_req)
  373. dd->flags |= AES_FLAGS_BUSY;
  374. spin_unlock_irqrestore(&dd->lock, flags);
  375. if (!async_req)
  376. return ret;
  377. if (backlog)
  378. backlog->complete(backlog, -EINPROGRESS);
  379. req = ablkcipher_request_cast(async_req);
  380. /* assign new request to device */
  381. dd->req = req;
  382. dd->total = req->nbytes;
  383. dd->in_sg = req->src;
  384. dd->out_sg = req->dst;
  385. rctx = ablkcipher_request_ctx(req);
  386. ctx = crypto_ablkcipher_ctx(crypto_ablkcipher_reqtfm(req));
  387. rctx->mode &= AES_FLAGS_MODE_MASK;
  388. dd->flags = (dd->flags & ~AES_FLAGS_MODE_MASK) | rctx->mode;
  389. dd->ctx = ctx;
  390. ctx->dd = dd;
  391. err = atmel_aes_write_ctrl(dd);
  392. if (!err) {
  393. if (dd->total > ATMEL_AES_DMA_THRESHOLD)
  394. err = atmel_aes_crypt_dma_start(dd);
  395. else
  396. err = atmel_aes_crypt_cpu_start(dd);
  397. }
  398. if (err) {
  399. /* aes_task will not finish it, so do it here */
  400. atmel_aes_finish_req(dd, err);
  401. tasklet_schedule(&dd->queue_task);
  402. }
  403. return ret;
  404. }
  405. static int atmel_aes_crypt_dma_stop(struct atmel_aes_dev *dd)
  406. {
  407. int err = -EINVAL;
  408. if (dd->flags & AES_FLAGS_DMA) {
  409. dma_unmap_sg(dd->dev, dd->out_sg,
  410. dd->nb_out_sg, DMA_FROM_DEVICE);
  411. dma_unmap_sg(dd->dev, dd->in_sg,
  412. dd->nb_in_sg, DMA_TO_DEVICE);
  413. err = 0;
  414. }
  415. return err;
  416. }
  417. static int atmel_aes_crypt(struct ablkcipher_request *req, unsigned long mode)
  418. {
  419. struct atmel_aes_ctx *ctx = crypto_ablkcipher_ctx(
  420. crypto_ablkcipher_reqtfm(req));
  421. struct atmel_aes_reqctx *rctx = ablkcipher_request_ctx(req);
  422. struct atmel_aes_dev *dd;
  423. if (!IS_ALIGNED(req->nbytes, AES_BLOCK_SIZE)) {
  424. pr_err("request size is not exact amount of AES blocks\n");
  425. return -EINVAL;
  426. }
  427. dd = atmel_aes_find_dev(ctx);
  428. if (!dd)
  429. return -ENODEV;
  430. rctx->mode = mode;
  431. return atmel_aes_handle_queue(dd, req);
  432. }
  433. static bool atmel_aes_filter(struct dma_chan *chan, void *slave)
  434. {
  435. struct at_dma_slave *sl = slave;
  436. if (sl && sl->dma_dev == chan->device->dev) {
  437. chan->private = sl;
  438. return true;
  439. } else {
  440. return false;
  441. }
  442. }
  443. static int atmel_aes_dma_init(struct atmel_aes_dev *dd)
  444. {
  445. int err = -ENOMEM;
  446. struct aes_platform_data *pdata;
  447. dma_cap_mask_t mask_in, mask_out;
  448. pdata = dd->dev->platform_data;
  449. if (pdata && pdata->dma_slave->txdata.dma_dev &&
  450. pdata->dma_slave->rxdata.dma_dev) {
  451. /* Try to grab 2 DMA channels */
  452. dma_cap_zero(mask_in);
  453. dma_cap_set(DMA_SLAVE, mask_in);
  454. dd->dma_lch_in.chan = dma_request_channel(mask_in,
  455. atmel_aes_filter, &pdata->dma_slave->rxdata);
  456. if (!dd->dma_lch_in.chan)
  457. goto err_dma_in;
  458. dd->dma_lch_in.dma_conf.direction = DMA_MEM_TO_DEV;
  459. dd->dma_lch_in.dma_conf.dst_addr = dd->phys_base +
  460. AES_IDATAR(0);
  461. dd->dma_lch_in.dma_conf.src_maxburst = 1;
  462. dd->dma_lch_in.dma_conf.dst_maxburst = 1;
  463. dd->dma_lch_in.dma_conf.device_fc = false;
  464. dma_cap_zero(mask_out);
  465. dma_cap_set(DMA_SLAVE, mask_out);
  466. dd->dma_lch_out.chan = dma_request_channel(mask_out,
  467. atmel_aes_filter, &pdata->dma_slave->txdata);
  468. if (!dd->dma_lch_out.chan)
  469. goto err_dma_out;
  470. dd->dma_lch_out.dma_conf.direction = DMA_DEV_TO_MEM;
  471. dd->dma_lch_out.dma_conf.src_addr = dd->phys_base +
  472. AES_ODATAR(0);
  473. dd->dma_lch_out.dma_conf.src_maxburst = 1;
  474. dd->dma_lch_out.dma_conf.dst_maxburst = 1;
  475. dd->dma_lch_out.dma_conf.device_fc = false;
  476. return 0;
  477. } else {
  478. return -ENODEV;
  479. }
  480. err_dma_out:
  481. dma_release_channel(dd->dma_lch_in.chan);
  482. err_dma_in:
  483. return err;
  484. }
  485. static void atmel_aes_dma_cleanup(struct atmel_aes_dev *dd)
  486. {
  487. dma_release_channel(dd->dma_lch_in.chan);
  488. dma_release_channel(dd->dma_lch_out.chan);
  489. }
  490. static int atmel_aes_setkey(struct crypto_ablkcipher *tfm, const u8 *key,
  491. unsigned int keylen)
  492. {
  493. struct atmel_aes_ctx *ctx = crypto_ablkcipher_ctx(tfm);
  494. if (keylen != AES_KEYSIZE_128 && keylen != AES_KEYSIZE_192 &&
  495. keylen != AES_KEYSIZE_256) {
  496. crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
  497. return -EINVAL;
  498. }
  499. memcpy(ctx->key, key, keylen);
  500. ctx->keylen = keylen;
  501. return 0;
  502. }
  503. static int atmel_aes_ecb_encrypt(struct ablkcipher_request *req)
  504. {
  505. return atmel_aes_crypt(req,
  506. AES_FLAGS_ENCRYPT);
  507. }
  508. static int atmel_aes_ecb_decrypt(struct ablkcipher_request *req)
  509. {
  510. return atmel_aes_crypt(req,
  511. 0);
  512. }
  513. static int atmel_aes_cbc_encrypt(struct ablkcipher_request *req)
  514. {
  515. return atmel_aes_crypt(req,
  516. AES_FLAGS_ENCRYPT | AES_FLAGS_CBC);
  517. }
  518. static int atmel_aes_cbc_decrypt(struct ablkcipher_request *req)
  519. {
  520. return atmel_aes_crypt(req,
  521. AES_FLAGS_CBC);
  522. }
  523. static int atmel_aes_ofb_encrypt(struct ablkcipher_request *req)
  524. {
  525. return atmel_aes_crypt(req,
  526. AES_FLAGS_ENCRYPT | AES_FLAGS_OFB);
  527. }
  528. static int atmel_aes_ofb_decrypt(struct ablkcipher_request *req)
  529. {
  530. return atmel_aes_crypt(req,
  531. AES_FLAGS_OFB);
  532. }
  533. static int atmel_aes_cfb_encrypt(struct ablkcipher_request *req)
  534. {
  535. return atmel_aes_crypt(req,
  536. AES_FLAGS_ENCRYPT | AES_FLAGS_CFB);
  537. }
  538. static int atmel_aes_cfb_decrypt(struct ablkcipher_request *req)
  539. {
  540. return atmel_aes_crypt(req,
  541. AES_FLAGS_CFB);
  542. }
  543. static int atmel_aes_cfb64_encrypt(struct ablkcipher_request *req)
  544. {
  545. return atmel_aes_crypt(req,
  546. AES_FLAGS_ENCRYPT | AES_FLAGS_CFB | AES_FLAGS_CFB64);
  547. }
  548. static int atmel_aes_cfb64_decrypt(struct ablkcipher_request *req)
  549. {
  550. return atmel_aes_crypt(req,
  551. AES_FLAGS_CFB | AES_FLAGS_CFB64);
  552. }
  553. static int atmel_aes_cfb32_encrypt(struct ablkcipher_request *req)
  554. {
  555. return atmel_aes_crypt(req,
  556. AES_FLAGS_ENCRYPT | AES_FLAGS_CFB | AES_FLAGS_CFB32);
  557. }
  558. static int atmel_aes_cfb32_decrypt(struct ablkcipher_request *req)
  559. {
  560. return atmel_aes_crypt(req,
  561. AES_FLAGS_CFB | AES_FLAGS_CFB32);
  562. }
  563. static int atmel_aes_cfb16_encrypt(struct ablkcipher_request *req)
  564. {
  565. return atmel_aes_crypt(req,
  566. AES_FLAGS_ENCRYPT | AES_FLAGS_CFB | AES_FLAGS_CFB16);
  567. }
  568. static int atmel_aes_cfb16_decrypt(struct ablkcipher_request *req)
  569. {
  570. return atmel_aes_crypt(req,
  571. AES_FLAGS_CFB | AES_FLAGS_CFB16);
  572. }
  573. static int atmel_aes_cfb8_encrypt(struct ablkcipher_request *req)
  574. {
  575. return atmel_aes_crypt(req,
  576. AES_FLAGS_ENCRYPT | AES_FLAGS_CFB | AES_FLAGS_CFB8);
  577. }
  578. static int atmel_aes_cfb8_decrypt(struct ablkcipher_request *req)
  579. {
  580. return atmel_aes_crypt(req,
  581. AES_FLAGS_CFB | AES_FLAGS_CFB8);
  582. }
  583. static int atmel_aes_ctr_encrypt(struct ablkcipher_request *req)
  584. {
  585. return atmel_aes_crypt(req,
  586. AES_FLAGS_ENCRYPT | AES_FLAGS_CTR);
  587. }
  588. static int atmel_aes_ctr_decrypt(struct ablkcipher_request *req)
  589. {
  590. return atmel_aes_crypt(req,
  591. AES_FLAGS_CTR);
  592. }
  593. static int atmel_aes_cra_init(struct crypto_tfm *tfm)
  594. {
  595. tfm->crt_ablkcipher.reqsize = sizeof(struct atmel_aes_reqctx);
  596. return 0;
  597. }
  598. static void atmel_aes_cra_exit(struct crypto_tfm *tfm)
  599. {
  600. }
  601. static struct crypto_alg aes_algs[] = {
  602. {
  603. .cra_name = "ecb(aes)",
  604. .cra_driver_name = "atmel-ecb-aes",
  605. .cra_priority = 100,
  606. .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC,
  607. .cra_blocksize = AES_BLOCK_SIZE,
  608. .cra_ctxsize = sizeof(struct atmel_aes_ctx),
  609. .cra_alignmask = 0x0,
  610. .cra_type = &crypto_ablkcipher_type,
  611. .cra_module = THIS_MODULE,
  612. .cra_init = atmel_aes_cra_init,
  613. .cra_exit = atmel_aes_cra_exit,
  614. .cra_u.ablkcipher = {
  615. .min_keysize = AES_MIN_KEY_SIZE,
  616. .max_keysize = AES_MAX_KEY_SIZE,
  617. .setkey = atmel_aes_setkey,
  618. .encrypt = atmel_aes_ecb_encrypt,
  619. .decrypt = atmel_aes_ecb_decrypt,
  620. }
  621. },
  622. {
  623. .cra_name = "cbc(aes)",
  624. .cra_driver_name = "atmel-cbc-aes",
  625. .cra_priority = 100,
  626. .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC,
  627. .cra_blocksize = AES_BLOCK_SIZE,
  628. .cra_ctxsize = sizeof(struct atmel_aes_ctx),
  629. .cra_alignmask = 0x0,
  630. .cra_type = &crypto_ablkcipher_type,
  631. .cra_module = THIS_MODULE,
  632. .cra_init = atmel_aes_cra_init,
  633. .cra_exit = atmel_aes_cra_exit,
  634. .cra_u.ablkcipher = {
  635. .min_keysize = AES_MIN_KEY_SIZE,
  636. .max_keysize = AES_MAX_KEY_SIZE,
  637. .ivsize = AES_BLOCK_SIZE,
  638. .setkey = atmel_aes_setkey,
  639. .encrypt = atmel_aes_cbc_encrypt,
  640. .decrypt = atmel_aes_cbc_decrypt,
  641. }
  642. },
  643. {
  644. .cra_name = "ofb(aes)",
  645. .cra_driver_name = "atmel-ofb-aes",
  646. .cra_priority = 100,
  647. .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC,
  648. .cra_blocksize = AES_BLOCK_SIZE,
  649. .cra_ctxsize = sizeof(struct atmel_aes_ctx),
  650. .cra_alignmask = 0x0,
  651. .cra_type = &crypto_ablkcipher_type,
  652. .cra_module = THIS_MODULE,
  653. .cra_init = atmel_aes_cra_init,
  654. .cra_exit = atmel_aes_cra_exit,
  655. .cra_u.ablkcipher = {
  656. .min_keysize = AES_MIN_KEY_SIZE,
  657. .max_keysize = AES_MAX_KEY_SIZE,
  658. .ivsize = AES_BLOCK_SIZE,
  659. .setkey = atmel_aes_setkey,
  660. .encrypt = atmel_aes_ofb_encrypt,
  661. .decrypt = atmel_aes_ofb_decrypt,
  662. }
  663. },
  664. {
  665. .cra_name = "cfb(aes)",
  666. .cra_driver_name = "atmel-cfb-aes",
  667. .cra_priority = 100,
  668. .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC,
  669. .cra_blocksize = AES_BLOCK_SIZE,
  670. .cra_ctxsize = sizeof(struct atmel_aes_ctx),
  671. .cra_alignmask = 0x0,
  672. .cra_type = &crypto_ablkcipher_type,
  673. .cra_module = THIS_MODULE,
  674. .cra_init = atmel_aes_cra_init,
  675. .cra_exit = atmel_aes_cra_exit,
  676. .cra_u.ablkcipher = {
  677. .min_keysize = AES_MIN_KEY_SIZE,
  678. .max_keysize = AES_MAX_KEY_SIZE,
  679. .ivsize = AES_BLOCK_SIZE,
  680. .setkey = atmel_aes_setkey,
  681. .encrypt = atmel_aes_cfb_encrypt,
  682. .decrypt = atmel_aes_cfb_decrypt,
  683. }
  684. },
  685. {
  686. .cra_name = "cfb32(aes)",
  687. .cra_driver_name = "atmel-cfb32-aes",
  688. .cra_priority = 100,
  689. .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC,
  690. .cra_blocksize = CFB32_BLOCK_SIZE,
  691. .cra_ctxsize = sizeof(struct atmel_aes_ctx),
  692. .cra_alignmask = 0x0,
  693. .cra_type = &crypto_ablkcipher_type,
  694. .cra_module = THIS_MODULE,
  695. .cra_init = atmel_aes_cra_init,
  696. .cra_exit = atmel_aes_cra_exit,
  697. .cra_u.ablkcipher = {
  698. .min_keysize = AES_MIN_KEY_SIZE,
  699. .max_keysize = AES_MAX_KEY_SIZE,
  700. .ivsize = AES_BLOCK_SIZE,
  701. .setkey = atmel_aes_setkey,
  702. .encrypt = atmel_aes_cfb32_encrypt,
  703. .decrypt = atmel_aes_cfb32_decrypt,
  704. }
  705. },
  706. {
  707. .cra_name = "cfb16(aes)",
  708. .cra_driver_name = "atmel-cfb16-aes",
  709. .cra_priority = 100,
  710. .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC,
  711. .cra_blocksize = CFB16_BLOCK_SIZE,
  712. .cra_ctxsize = sizeof(struct atmel_aes_ctx),
  713. .cra_alignmask = 0x0,
  714. .cra_type = &crypto_ablkcipher_type,
  715. .cra_module = THIS_MODULE,
  716. .cra_init = atmel_aes_cra_init,
  717. .cra_exit = atmel_aes_cra_exit,
  718. .cra_u.ablkcipher = {
  719. .min_keysize = AES_MIN_KEY_SIZE,
  720. .max_keysize = AES_MAX_KEY_SIZE,
  721. .ivsize = AES_BLOCK_SIZE,
  722. .setkey = atmel_aes_setkey,
  723. .encrypt = atmel_aes_cfb16_encrypt,
  724. .decrypt = atmel_aes_cfb16_decrypt,
  725. }
  726. },
  727. {
  728. .cra_name = "cfb8(aes)",
  729. .cra_driver_name = "atmel-cfb8-aes",
  730. .cra_priority = 100,
  731. .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC,
  732. .cra_blocksize = CFB64_BLOCK_SIZE,
  733. .cra_ctxsize = sizeof(struct atmel_aes_ctx),
  734. .cra_alignmask = 0x0,
  735. .cra_type = &crypto_ablkcipher_type,
  736. .cra_module = THIS_MODULE,
  737. .cra_init = atmel_aes_cra_init,
  738. .cra_exit = atmel_aes_cra_exit,
  739. .cra_u.ablkcipher = {
  740. .min_keysize = AES_MIN_KEY_SIZE,
  741. .max_keysize = AES_MAX_KEY_SIZE,
  742. .ivsize = AES_BLOCK_SIZE,
  743. .setkey = atmel_aes_setkey,
  744. .encrypt = atmel_aes_cfb8_encrypt,
  745. .decrypt = atmel_aes_cfb8_decrypt,
  746. }
  747. },
  748. {
  749. .cra_name = "ctr(aes)",
  750. .cra_driver_name = "atmel-ctr-aes",
  751. .cra_priority = 100,
  752. .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC,
  753. .cra_blocksize = AES_BLOCK_SIZE,
  754. .cra_ctxsize = sizeof(struct atmel_aes_ctx),
  755. .cra_alignmask = 0x0,
  756. .cra_type = &crypto_ablkcipher_type,
  757. .cra_module = THIS_MODULE,
  758. .cra_init = atmel_aes_cra_init,
  759. .cra_exit = atmel_aes_cra_exit,
  760. .cra_u.ablkcipher = {
  761. .min_keysize = AES_MIN_KEY_SIZE,
  762. .max_keysize = AES_MAX_KEY_SIZE,
  763. .ivsize = AES_BLOCK_SIZE,
  764. .setkey = atmel_aes_setkey,
  765. .encrypt = atmel_aes_ctr_encrypt,
  766. .decrypt = atmel_aes_ctr_decrypt,
  767. }
  768. },
  769. };
  770. static struct crypto_alg aes_cfb64_alg[] = {
  771. {
  772. .cra_name = "cfb64(aes)",
  773. .cra_driver_name = "atmel-cfb64-aes",
  774. .cra_priority = 100,
  775. .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC,
  776. .cra_blocksize = CFB64_BLOCK_SIZE,
  777. .cra_ctxsize = sizeof(struct atmel_aes_ctx),
  778. .cra_alignmask = 0x0,
  779. .cra_type = &crypto_ablkcipher_type,
  780. .cra_module = THIS_MODULE,
  781. .cra_init = atmel_aes_cra_init,
  782. .cra_exit = atmel_aes_cra_exit,
  783. .cra_u.ablkcipher = {
  784. .min_keysize = AES_MIN_KEY_SIZE,
  785. .max_keysize = AES_MAX_KEY_SIZE,
  786. .ivsize = AES_BLOCK_SIZE,
  787. .setkey = atmel_aes_setkey,
  788. .encrypt = atmel_aes_cfb64_encrypt,
  789. .decrypt = atmel_aes_cfb64_decrypt,
  790. }
  791. },
  792. };
  793. static void atmel_aes_queue_task(unsigned long data)
  794. {
  795. struct atmel_aes_dev *dd = (struct atmel_aes_dev *)data;
  796. atmel_aes_handle_queue(dd, NULL);
  797. }
  798. static void atmel_aes_done_task(unsigned long data)
  799. {
  800. struct atmel_aes_dev *dd = (struct atmel_aes_dev *) data;
  801. int err;
  802. if (!(dd->flags & AES_FLAGS_DMA)) {
  803. atmel_aes_read_n(dd, AES_ODATAR(0), (u32 *) dd->buf_out,
  804. dd->bufcnt >> 2);
  805. if (sg_copy_from_buffer(dd->out_sg, dd->nb_out_sg,
  806. dd->buf_out, dd->bufcnt))
  807. err = 0;
  808. else
  809. err = -EINVAL;
  810. goto cpu_end;
  811. }
  812. err = atmel_aes_crypt_dma_stop(dd);
  813. err = dd->err ? : err;
  814. if (dd->total && !err) {
  815. err = atmel_aes_crypt_dma_start(dd);
  816. if (!err)
  817. return; /* DMA started. Not fininishing. */
  818. }
  819. cpu_end:
  820. atmel_aes_finish_req(dd, err);
  821. atmel_aes_handle_queue(dd, NULL);
  822. }
  823. static irqreturn_t atmel_aes_irq(int irq, void *dev_id)
  824. {
  825. struct atmel_aes_dev *aes_dd = dev_id;
  826. u32 reg;
  827. reg = atmel_aes_read(aes_dd, AES_ISR);
  828. if (reg & atmel_aes_read(aes_dd, AES_IMR)) {
  829. atmel_aes_write(aes_dd, AES_IDR, reg);
  830. if (AES_FLAGS_BUSY & aes_dd->flags)
  831. tasklet_schedule(&aes_dd->done_task);
  832. else
  833. dev_warn(aes_dd->dev, "AES interrupt when no active requests.\n");
  834. return IRQ_HANDLED;
  835. }
  836. return IRQ_NONE;
  837. }
  838. static void atmel_aes_unregister_algs(struct atmel_aes_dev *dd)
  839. {
  840. int i;
  841. for (i = 0; i < ARRAY_SIZE(aes_algs); i++)
  842. crypto_unregister_alg(&aes_algs[i]);
  843. if (dd->hw_version >= 0x130)
  844. crypto_unregister_alg(&aes_cfb64_alg[0]);
  845. }
  846. static int atmel_aes_register_algs(struct atmel_aes_dev *dd)
  847. {
  848. int err, i, j;
  849. for (i = 0; i < ARRAY_SIZE(aes_algs); i++) {
  850. INIT_LIST_HEAD(&aes_algs[i].cra_list);
  851. err = crypto_register_alg(&aes_algs[i]);
  852. if (err)
  853. goto err_aes_algs;
  854. }
  855. atmel_aes_hw_version_init(dd);
  856. if (dd->hw_version >= 0x130) {
  857. INIT_LIST_HEAD(&aes_cfb64_alg[0].cra_list);
  858. err = crypto_register_alg(&aes_cfb64_alg[0]);
  859. if (err)
  860. goto err_aes_cfb64_alg;
  861. }
  862. return 0;
  863. err_aes_cfb64_alg:
  864. i = ARRAY_SIZE(aes_algs);
  865. err_aes_algs:
  866. for (j = 0; j < i; j++)
  867. crypto_unregister_alg(&aes_algs[j]);
  868. return err;
  869. }
  870. static int __devinit atmel_aes_probe(struct platform_device *pdev)
  871. {
  872. struct atmel_aes_dev *aes_dd;
  873. struct aes_platform_data *pdata;
  874. struct device *dev = &pdev->dev;
  875. struct resource *aes_res;
  876. unsigned long aes_phys_size;
  877. int err;
  878. pdata = pdev->dev.platform_data;
  879. if (!pdata) {
  880. err = -ENXIO;
  881. goto aes_dd_err;
  882. }
  883. aes_dd = kzalloc(sizeof(struct atmel_aes_dev), GFP_KERNEL);
  884. if (aes_dd == NULL) {
  885. dev_err(dev, "unable to alloc data struct.\n");
  886. err = -ENOMEM;
  887. goto aes_dd_err;
  888. }
  889. aes_dd->dev = dev;
  890. platform_set_drvdata(pdev, aes_dd);
  891. INIT_LIST_HEAD(&aes_dd->list);
  892. tasklet_init(&aes_dd->done_task, atmel_aes_done_task,
  893. (unsigned long)aes_dd);
  894. tasklet_init(&aes_dd->queue_task, atmel_aes_queue_task,
  895. (unsigned long)aes_dd);
  896. crypto_init_queue(&aes_dd->queue, ATMEL_AES_QUEUE_LENGTH);
  897. aes_dd->irq = -1;
  898. /* Get the base address */
  899. aes_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  900. if (!aes_res) {
  901. dev_err(dev, "no MEM resource info\n");
  902. err = -ENODEV;
  903. goto res_err;
  904. }
  905. aes_dd->phys_base = aes_res->start;
  906. aes_phys_size = resource_size(aes_res);
  907. /* Get the IRQ */
  908. aes_dd->irq = platform_get_irq(pdev, 0);
  909. if (aes_dd->irq < 0) {
  910. dev_err(dev, "no IRQ resource info\n");
  911. err = aes_dd->irq;
  912. goto aes_irq_err;
  913. }
  914. err = request_irq(aes_dd->irq, atmel_aes_irq, IRQF_SHARED, "atmel-aes",
  915. aes_dd);
  916. if (err) {
  917. dev_err(dev, "unable to request aes irq.\n");
  918. goto aes_irq_err;
  919. }
  920. /* Initializing the clock */
  921. aes_dd->iclk = clk_get(&pdev->dev, NULL);
  922. if (IS_ERR(aes_dd->iclk)) {
  923. dev_err(dev, "clock intialization failed.\n");
  924. err = PTR_ERR(aes_dd->iclk);
  925. goto clk_err;
  926. }
  927. aes_dd->io_base = ioremap(aes_dd->phys_base, aes_phys_size);
  928. if (!aes_dd->io_base) {
  929. dev_err(dev, "can't ioremap\n");
  930. err = -ENOMEM;
  931. goto aes_io_err;
  932. }
  933. err = atmel_aes_dma_init(aes_dd);
  934. if (err)
  935. goto err_aes_dma;
  936. spin_lock(&atmel_aes.lock);
  937. list_add_tail(&aes_dd->list, &atmel_aes.dev_list);
  938. spin_unlock(&atmel_aes.lock);
  939. err = atmel_aes_register_algs(aes_dd);
  940. if (err)
  941. goto err_algs;
  942. dev_info(dev, "Atmel AES\n");
  943. return 0;
  944. err_algs:
  945. spin_lock(&atmel_aes.lock);
  946. list_del(&aes_dd->list);
  947. spin_unlock(&atmel_aes.lock);
  948. atmel_aes_dma_cleanup(aes_dd);
  949. err_aes_dma:
  950. iounmap(aes_dd->io_base);
  951. aes_io_err:
  952. clk_put(aes_dd->iclk);
  953. clk_err:
  954. free_irq(aes_dd->irq, aes_dd);
  955. aes_irq_err:
  956. res_err:
  957. tasklet_kill(&aes_dd->done_task);
  958. tasklet_kill(&aes_dd->queue_task);
  959. kfree(aes_dd);
  960. aes_dd = NULL;
  961. aes_dd_err:
  962. dev_err(dev, "initialization failed.\n");
  963. return err;
  964. }
  965. static int __devexit atmel_aes_remove(struct platform_device *pdev)
  966. {
  967. static struct atmel_aes_dev *aes_dd;
  968. aes_dd = platform_get_drvdata(pdev);
  969. if (!aes_dd)
  970. return -ENODEV;
  971. spin_lock(&atmel_aes.lock);
  972. list_del(&aes_dd->list);
  973. spin_unlock(&atmel_aes.lock);
  974. atmel_aes_unregister_algs(aes_dd);
  975. tasklet_kill(&aes_dd->done_task);
  976. tasklet_kill(&aes_dd->queue_task);
  977. atmel_aes_dma_cleanup(aes_dd);
  978. iounmap(aes_dd->io_base);
  979. clk_put(aes_dd->iclk);
  980. if (aes_dd->irq > 0)
  981. free_irq(aes_dd->irq, aes_dd);
  982. kfree(aes_dd);
  983. aes_dd = NULL;
  984. return 0;
  985. }
  986. static struct platform_driver atmel_aes_driver = {
  987. .probe = atmel_aes_probe,
  988. .remove = __devexit_p(atmel_aes_remove),
  989. .driver = {
  990. .name = "atmel_aes",
  991. .owner = THIS_MODULE,
  992. },
  993. };
  994. module_platform_driver(atmel_aes_driver);
  995. MODULE_DESCRIPTION("Atmel AES hw acceleration support.");
  996. MODULE_LICENSE("GPL v2");
  997. MODULE_AUTHOR("Nicolas Royer - Eukréa Electromatique");