blob: fe32dd95ae4ff20008baeaaa9a78046b6b6c0ed0 [file] [log] [blame]
Dmitry Kasatkin537559a2010-09-03 19:16:02 +08001/*
2 * Cryptographic API.
3 *
4 * Support for OMAP AES HW acceleration.
5 *
6 * Copyright (c) 2010 Nokia Corporation
7 * Author: Dmitry Kasatkin <dmitry.kasatkin@nokia.com>
Mark A. Greer0d355832013-01-08 11:57:46 -07008 * Copyright (c) 2011 Texas Instruments Incorporated
Dmitry Kasatkin537559a2010-09-03 19:16:02 +08009 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as published
12 * by the Free Software Foundation.
13 *
14 */
15
Joel Fernandes016af9b2013-08-18 00:56:11 -050016#define pr_fmt(fmt) "%20s: " fmt, __func__
17#define prn(num) pr_debug(#num "=%d\n", num)
18#define prx(num) pr_debug(#num "=%x\n", num)
Dmitry Kasatkin537559a2010-09-03 19:16:02 +080019
20#include <linux/err.h>
21#include <linux/module.h>
22#include <linux/init.h>
23#include <linux/errno.h>
24#include <linux/kernel.h>
Dmitry Kasatkin537559a2010-09-03 19:16:02 +080025#include <linux/platform_device.h>
26#include <linux/scatterlist.h>
27#include <linux/dma-mapping.h>
Mark A. Greerebedbf72013-01-08 11:57:42 -070028#include <linux/dmaengine.h>
Mark A. Greer5946c4a2013-01-08 11:57:40 -070029#include <linux/pm_runtime.h>
Mark A. Greerbc69d122013-01-08 11:57:44 -070030#include <linux/of.h>
31#include <linux/of_device.h>
32#include <linux/of_address.h>
Dmitry Kasatkin537559a2010-09-03 19:16:02 +080033#include <linux/io.h>
34#include <linux/crypto.h>
35#include <linux/interrupt.h>
36#include <crypto/scatterwalk.h>
37#include <crypto/aes.h>
Corentin LABBE2589ad82016-08-31 14:02:57 +020038#include <crypto/engine.h>
Lokesh Vutla9fcb1912016-08-04 13:28:44 +030039#include <crypto/internal/skcipher.h>
Dmitry Kasatkin537559a2010-09-03 19:16:02 +080040
Mark A. Greerebedbf72013-01-08 11:57:42 -070041#define DST_MAXBURST 4
42#define DMA_MIN (DST_MAXBURST * sizeof(u32))
Dmitry Kasatkin537559a2010-09-03 19:16:02 +080043
Joel Fernandes1bf95cc2013-08-17 21:42:29 -050044#define _calc_walked(inout) (dd->inout##_walk.offset - dd->inout##_sg->offset)
45
Dmitry Kasatkin537559a2010-09-03 19:16:02 +080046/* OMAP TRM gives bitfields as start:end, where start is the higher bit
47 number. For example 7:0 */
48#define FLD_MASK(start, end) (((1 << ((start) - (end) + 1)) - 1) << (end))
49#define FLD_VAL(val, start, end) (((val) << (end)) & FLD_MASK(start, end))
50
Mark A. Greer0d355832013-01-08 11:57:46 -070051#define AES_REG_KEY(dd, x) ((dd)->pdata->key_ofs - \
52 ((x ^ 0x01) * 0x04))
53#define AES_REG_IV(dd, x) ((dd)->pdata->iv_ofs + ((x) * 0x04))
Dmitry Kasatkin537559a2010-09-03 19:16:02 +080054
Mark A. Greer0d355832013-01-08 11:57:46 -070055#define AES_REG_CTRL(dd) ((dd)->pdata->ctrl_ofs)
Vutla, Lokesh340d9d32015-07-07 21:01:46 +053056#define AES_REG_CTRL_CTR_WIDTH_MASK GENMASK(8, 7)
57#define AES_REG_CTRL_CTR_WIDTH_32 0
58#define AES_REG_CTRL_CTR_WIDTH_64 BIT(7)
59#define AES_REG_CTRL_CTR_WIDTH_96 BIT(8)
60#define AES_REG_CTRL_CTR_WIDTH_128 GENMASK(8, 7)
61#define AES_REG_CTRL_CTR BIT(6)
62#define AES_REG_CTRL_CBC BIT(5)
63#define AES_REG_CTRL_KEY_SIZE GENMASK(4, 3)
64#define AES_REG_CTRL_DIRECTION BIT(2)
65#define AES_REG_CTRL_INPUT_READY BIT(1)
66#define AES_REG_CTRL_OUTPUT_READY BIT(0)
Vutla, Lokesh5396c6c2015-07-07 21:01:45 +053067#define AES_REG_CTRL_MASK GENMASK(24, 2)
Dmitry Kasatkin537559a2010-09-03 19:16:02 +080068
Mark A. Greer0d355832013-01-08 11:57:46 -070069#define AES_REG_DATA_N(dd, x) ((dd)->pdata->data_ofs + ((x) * 0x04))
Dmitry Kasatkin537559a2010-09-03 19:16:02 +080070
Mark A. Greer0d355832013-01-08 11:57:46 -070071#define AES_REG_REV(dd) ((dd)->pdata->rev_ofs)
Dmitry Kasatkin537559a2010-09-03 19:16:02 +080072
Mark A. Greer0d355832013-01-08 11:57:46 -070073#define AES_REG_MASK(dd) ((dd)->pdata->mask_ofs)
Vutla, Lokesh340d9d32015-07-07 21:01:46 +053074#define AES_REG_MASK_SIDLE BIT(6)
75#define AES_REG_MASK_START BIT(5)
76#define AES_REG_MASK_DMA_OUT_EN BIT(3)
77#define AES_REG_MASK_DMA_IN_EN BIT(2)
78#define AES_REG_MASK_SOFTRESET BIT(1)
79#define AES_REG_AUTOIDLE BIT(0)
Dmitry Kasatkin537559a2010-09-03 19:16:02 +080080
Mark A. Greer0d355832013-01-08 11:57:46 -070081#define AES_REG_LENGTH_N(x) (0x54 + ((x) * 0x04))
Dmitry Kasatkin537559a2010-09-03 19:16:02 +080082
Joel Fernandes67216752013-08-17 21:42:28 -050083#define AES_REG_IRQ_STATUS(dd) ((dd)->pdata->irq_status_ofs)
84#define AES_REG_IRQ_ENABLE(dd) ((dd)->pdata->irq_enable_ofs)
85#define AES_REG_IRQ_DATA_IN BIT(1)
86#define AES_REG_IRQ_DATA_OUT BIT(2)
Dmitry Kasatkin537559a2010-09-03 19:16:02 +080087#define DEFAULT_TIMEOUT (5*HZ)
88
Tero Kristof303b452016-08-04 13:28:42 +030089#define DEFAULT_AUTOSUSPEND_DELAY 1000
90
Dmitry Kasatkin537559a2010-09-03 19:16:02 +080091#define FLAGS_MODE_MASK 0x000f
92#define FLAGS_ENCRYPT BIT(0)
93#define FLAGS_CBC BIT(1)
94#define FLAGS_GIV BIT(2)
Mark A. Greerf9fb69e2013-01-08 11:57:47 -070095#define FLAGS_CTR BIT(3)
Dmitry Kasatkin537559a2010-09-03 19:16:02 +080096
Dmitry Kasatkin67a730c2010-11-30 10:13:30 +020097#define FLAGS_INIT BIT(4)
98#define FLAGS_FAST BIT(5)
99#define FLAGS_BUSY BIT(6)
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800100
Joel Fernandes1bf95cc2013-08-17 21:42:29 -0500101#define AES_BLOCK_WORDS (AES_BLOCK_SIZE >> 2)
102
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800103struct omap_aes_ctx {
104 struct omap_aes_dev *dd;
105
106 int keylen;
107 u32 key[AES_KEYSIZE_256 / sizeof(u32)];
108 unsigned long flags;
Lokesh Vutla9fcb1912016-08-04 13:28:44 +0300109 struct crypto_skcipher *fallback;
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800110};
111
112struct omap_aes_reqctx {
113 unsigned long mode;
114};
115
116#define OMAP_AES_QUEUE_LENGTH 1
117#define OMAP_AES_CACHE_SIZE 0
118
Mark A. Greerf9fb69e2013-01-08 11:57:47 -0700119struct omap_aes_algs_info {
120 struct crypto_alg *algs_list;
121 unsigned int size;
122 unsigned int registered;
123};
124
Mark A. Greer0d355832013-01-08 11:57:46 -0700125struct omap_aes_pdata {
Mark A. Greerf9fb69e2013-01-08 11:57:47 -0700126 struct omap_aes_algs_info *algs_info;
127 unsigned int algs_info_size;
128
Mark A. Greer0d355832013-01-08 11:57:46 -0700129 void (*trigger)(struct omap_aes_dev *dd, int length);
130
131 u32 key_ofs;
132 u32 iv_ofs;
133 u32 ctrl_ofs;
134 u32 data_ofs;
135 u32 rev_ofs;
136 u32 mask_ofs;
Joel Fernandes67216752013-08-17 21:42:28 -0500137 u32 irq_enable_ofs;
138 u32 irq_status_ofs;
Mark A. Greer0d355832013-01-08 11:57:46 -0700139
140 u32 dma_enable_in;
141 u32 dma_enable_out;
142 u32 dma_start;
143
144 u32 major_mask;
145 u32 major_shift;
146 u32 minor_mask;
147 u32 minor_shift;
148};
149
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800150struct omap_aes_dev {
151 struct list_head list;
152 unsigned long phys_base;
Dmitry Kasatkinefce41b2010-11-30 10:13:32 +0200153 void __iomem *io_base;
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800154 struct omap_aes_ctx *ctx;
155 struct device *dev;
156 unsigned long flags;
Dmitry Kasatkin21fe9762010-11-30 10:13:29 +0200157 int err;
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800158
Dmitry Kasatkin21fe9762010-11-30 10:13:29 +0200159 struct tasklet_struct done_task;
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800160
161 struct ablkcipher_request *req;
Baolin Wang05299002016-01-26 20:25:40 +0800162 struct crypto_engine *engine;
Joel Fernandes62423322013-08-17 21:42:32 -0500163
164 /*
165 * total is used by PIO mode for book keeping so introduce
166 * variable total_save as need it to calc page_order
167 */
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800168 size_t total;
Joel Fernandes62423322013-08-17 21:42:32 -0500169 size_t total_save;
170
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800171 struct scatterlist *in_sg;
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800172 struct scatterlist *out_sg;
Joel Fernandes62423322013-08-17 21:42:32 -0500173
174 /* Buffers for copying for unaligned cases */
175 struct scatterlist in_sgl;
176 struct scatterlist out_sgl;
177 struct scatterlist *orig_out;
178 int sgs_copied;
179
Joel Fernandes1bf95cc2013-08-17 21:42:29 -0500180 struct scatter_walk in_walk;
181 struct scatter_walk out_walk;
Mark A. Greerebedbf72013-01-08 11:57:42 -0700182 struct dma_chan *dma_lch_in;
Mark A. Greerebedbf72013-01-08 11:57:42 -0700183 struct dma_chan *dma_lch_out;
Joel Fernandese77c7562013-08-17 21:42:24 -0500184 int in_sg_len;
185 int out_sg_len;
Joel Fernandes98837ab2013-08-17 21:42:30 -0500186 int pio_only;
Mark A. Greer0d355832013-01-08 11:57:46 -0700187 const struct omap_aes_pdata *pdata;
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800188};
189
190/* keep registered devices data here */
191static LIST_HEAD(dev_list);
192static DEFINE_SPINLOCK(list_lock);
193
Joel Fernandes016af9b2013-08-18 00:56:11 -0500194#ifdef DEBUG
195#define omap_aes_read(dd, offset) \
196({ \
197 int _read_ret; \
198 _read_ret = __raw_readl(dd->io_base + offset); \
199 pr_debug("omap_aes_read(" #offset "=%#x)= %#x\n", \
200 offset, _read_ret); \
201 _read_ret; \
202})
203#else
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800204static inline u32 omap_aes_read(struct omap_aes_dev *dd, u32 offset)
205{
206 return __raw_readl(dd->io_base + offset);
207}
Joel Fernandes016af9b2013-08-18 00:56:11 -0500208#endif
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800209
Joel Fernandes016af9b2013-08-18 00:56:11 -0500210#ifdef DEBUG
211#define omap_aes_write(dd, offset, value) \
212 do { \
213 pr_debug("omap_aes_write(" #offset "=%#x) value=%#x\n", \
214 offset, value); \
215 __raw_writel(value, dd->io_base + offset); \
216 } while (0)
217#else
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800218static inline void omap_aes_write(struct omap_aes_dev *dd, u32 offset,
219 u32 value)
220{
221 __raw_writel(value, dd->io_base + offset);
222}
Joel Fernandes016af9b2013-08-18 00:56:11 -0500223#endif
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800224
225static inline void omap_aes_write_mask(struct omap_aes_dev *dd, u32 offset,
226 u32 value, u32 mask)
227{
228 u32 val;
229
230 val = omap_aes_read(dd, offset);
231 val &= ~mask;
232 val |= value;
233 omap_aes_write(dd, offset, val);
234}
235
236static void omap_aes_write_n(struct omap_aes_dev *dd, u32 offset,
237 u32 *value, int count)
238{
239 for (; count--; value++, offset += 4)
240 omap_aes_write(dd, offset, *value);
241}
242
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800243static int omap_aes_hw_init(struct omap_aes_dev *dd)
244{
Tero Kristof303b452016-08-04 13:28:42 +0300245 int err;
246
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800247 if (!(dd->flags & FLAGS_INIT)) {
Dmitry Kasatkineeb2b202010-11-30 10:13:28 +0200248 dd->flags |= FLAGS_INIT;
Dmitry Kasatkin21fe9762010-11-30 10:13:29 +0200249 dd->err = 0;
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800250 }
251
Tero Kristof303b452016-08-04 13:28:42 +0300252 err = pm_runtime_get_sync(dd->dev);
253 if (err < 0) {
254 dev_err(dd->dev, "failed to get sync: %d\n", err);
255 return err;
256 }
257
Dmitry Kasatkineeb2b202010-11-30 10:13:28 +0200258 return 0;
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800259}
260
Dmitry Kasatkin21fe9762010-11-30 10:13:29 +0200261static int omap_aes_write_ctrl(struct omap_aes_dev *dd)
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800262{
263 unsigned int key32;
Dmitry Kasatkin67a730c2010-11-30 10:13:30 +0200264 int i, err;
Vutla, Lokesh5396c6c2015-07-07 21:01:45 +0530265 u32 val;
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800266
Dmitry Kasatkin21fe9762010-11-30 10:13:29 +0200267 err = omap_aes_hw_init(dd);
268 if (err)
269 return err;
270
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800271 key32 = dd->ctx->keylen / sizeof(u32);
Dmitry Kasatkin67a730c2010-11-30 10:13:30 +0200272
273 /* it seems a key should always be set even if it has not changed */
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800274 for (i = 0; i < key32; i++) {
Mark A. Greer0d355832013-01-08 11:57:46 -0700275 omap_aes_write(dd, AES_REG_KEY(dd, i),
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800276 __le32_to_cpu(dd->ctx->key[i]));
277 }
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800278
Mark A. Greerf9fb69e2013-01-08 11:57:47 -0700279 if ((dd->flags & (FLAGS_CBC | FLAGS_CTR)) && dd->req->info)
Mark A. Greer0d355832013-01-08 11:57:46 -0700280 omap_aes_write_n(dd, AES_REG_IV(dd, 0), dd->req->info, 4);
Dmitry Kasatkin67a730c2010-11-30 10:13:30 +0200281
282 val = FLD_VAL(((dd->ctx->keylen >> 3) - 1), 4, 3);
283 if (dd->flags & FLAGS_CBC)
284 val |= AES_REG_CTRL_CBC;
Vutla, Lokesh5396c6c2015-07-07 21:01:45 +0530285 if (dd->flags & FLAGS_CTR)
Joel Fernandes8ed49c72013-10-29 17:37:38 -0500286 val |= AES_REG_CTRL_CTR | AES_REG_CTRL_CTR_WIDTH_128;
Vutla, Lokesh5396c6c2015-07-07 21:01:45 +0530287
Dmitry Kasatkin67a730c2010-11-30 10:13:30 +0200288 if (dd->flags & FLAGS_ENCRYPT)
289 val |= AES_REG_CTRL_DIRECTION;
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800290
Vutla, Lokesh5396c6c2015-07-07 21:01:45 +0530291 omap_aes_write_mask(dd, AES_REG_CTRL(dd), val, AES_REG_CTRL_MASK);
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800292
Dmitry Kasatkin21fe9762010-11-30 10:13:29 +0200293 return 0;
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800294}
295
Mark A. Greer0d355832013-01-08 11:57:46 -0700296static void omap_aes_dma_trigger_omap2(struct omap_aes_dev *dd, int length)
297{
298 u32 mask, val;
299
300 val = dd->pdata->dma_start;
301
302 if (dd->dma_lch_out != NULL)
303 val |= dd->pdata->dma_enable_out;
304 if (dd->dma_lch_in != NULL)
305 val |= dd->pdata->dma_enable_in;
306
307 mask = dd->pdata->dma_enable_out | dd->pdata->dma_enable_in |
308 dd->pdata->dma_start;
309
310 omap_aes_write_mask(dd, AES_REG_MASK(dd), val, mask);
311
312}
313
314static void omap_aes_dma_trigger_omap4(struct omap_aes_dev *dd, int length)
315{
316 omap_aes_write(dd, AES_REG_LENGTH_N(0), length);
317 omap_aes_write(dd, AES_REG_LENGTH_N(1), 0);
318
319 omap_aes_dma_trigger_omap2(dd, length);
320}
321
322static void omap_aes_dma_stop(struct omap_aes_dev *dd)
323{
324 u32 mask;
325
326 mask = dd->pdata->dma_enable_out | dd->pdata->dma_enable_in |
327 dd->pdata->dma_start;
328
329 omap_aes_write_mask(dd, AES_REG_MASK(dd), 0, mask);
330}
331
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800332static struct omap_aes_dev *omap_aes_find_dev(struct omap_aes_ctx *ctx)
333{
Lokesh Vutla164f3ef2016-08-04 13:28:43 +0300334 struct omap_aes_dev *dd;
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800335
336 spin_lock_bh(&list_lock);
Lokesh Vutla164f3ef2016-08-04 13:28:43 +0300337 dd = list_first_entry(&dev_list, struct omap_aes_dev, list);
338 list_move_tail(&dd->list, &dev_list);
339 ctx->dd = dd;
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800340 spin_unlock_bh(&list_lock);
341
342 return dd;
343}
344
Mark A. Greerebedbf72013-01-08 11:57:42 -0700345static void omap_aes_dma_out_callback(void *data)
346{
347 struct omap_aes_dev *dd = data;
348
349 /* dma_lch_out - completed */
350 tasklet_schedule(&dd->done_task);
351}
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800352
353static int omap_aes_dma_init(struct omap_aes_dev *dd)
354{
Peter Ujfalusida8b29a2016-04-29 16:02:18 +0300355 int err;
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800356
Mark A. Greerebedbf72013-01-08 11:57:42 -0700357 dd->dma_lch_out = NULL;
358 dd->dma_lch_in = NULL;
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800359
Peter Ujfalusida8b29a2016-04-29 16:02:18 +0300360 dd->dma_lch_in = dma_request_chan(dd->dev, "rx");
361 if (IS_ERR(dd->dma_lch_in)) {
Mark A. Greerebedbf72013-01-08 11:57:42 -0700362 dev_err(dd->dev, "Unable to request in DMA channel\n");
Peter Ujfalusida8b29a2016-04-29 16:02:18 +0300363 return PTR_ERR(dd->dma_lch_in);
Mark A. Greerebedbf72013-01-08 11:57:42 -0700364 }
365
Peter Ujfalusida8b29a2016-04-29 16:02:18 +0300366 dd->dma_lch_out = dma_request_chan(dd->dev, "tx");
367 if (IS_ERR(dd->dma_lch_out)) {
Mark A. Greerebedbf72013-01-08 11:57:42 -0700368 dev_err(dd->dev, "Unable to request out DMA channel\n");
Peter Ujfalusida8b29a2016-04-29 16:02:18 +0300369 err = PTR_ERR(dd->dma_lch_out);
Mark A. Greerebedbf72013-01-08 11:57:42 -0700370 goto err_dma_out;
371 }
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800372
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800373 return 0;
374
375err_dma_out:
Mark A. Greerebedbf72013-01-08 11:57:42 -0700376 dma_release_channel(dd->dma_lch_in);
Peter Ujfalusida8b29a2016-04-29 16:02:18 +0300377
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800378 return err;
379}
380
381static void omap_aes_dma_cleanup(struct omap_aes_dev *dd)
382{
Peter Ujfalusida8b29a2016-04-29 16:02:18 +0300383 if (dd->pio_only)
384 return;
385
Mark A. Greerebedbf72013-01-08 11:57:42 -0700386 dma_release_channel(dd->dma_lch_out);
387 dma_release_channel(dd->dma_lch_in);
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800388}
389
390static void sg_copy_buf(void *buf, struct scatterlist *sg,
391 unsigned int start, unsigned int nbytes, int out)
392{
393 struct scatter_walk walk;
394
395 if (!nbytes)
396 return;
397
398 scatterwalk_start(&walk, sg);
399 scatterwalk_advance(&walk, start);
400 scatterwalk_copychunks(buf, &walk, nbytes, out);
401 scatterwalk_done(&walk, out, 0);
402}
403
Mark A. Greerebedbf72013-01-08 11:57:42 -0700404static int omap_aes_crypt_dma(struct crypto_tfm *tfm,
Joel Fernandes4b645c92013-08-17 21:42:25 -0500405 struct scatterlist *in_sg, struct scatterlist *out_sg,
406 int in_sg_len, int out_sg_len)
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800407{
408 struct omap_aes_ctx *ctx = crypto_tfm_ctx(tfm);
409 struct omap_aes_dev *dd = ctx->dd;
Mark A. Greerebedbf72013-01-08 11:57:42 -0700410 struct dma_async_tx_descriptor *tx_in, *tx_out;
411 struct dma_slave_config cfg;
Joel Fernandes4b645c92013-08-17 21:42:25 -0500412 int ret;
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800413
Joel Fernandes98837ab2013-08-17 21:42:30 -0500414 if (dd->pio_only) {
415 scatterwalk_start(&dd->in_walk, dd->in_sg);
416 scatterwalk_start(&dd->out_walk, dd->out_sg);
417
418 /* Enable DATAIN interrupt and let it take
419 care of the rest */
420 omap_aes_write(dd, AES_REG_IRQ_ENABLE(dd), 0x2);
421 return 0;
422 }
423
Joel Fernandes0a641712013-08-17 21:42:26 -0500424 dma_sync_sg_for_device(dd->dev, dd->in_sg, in_sg_len, DMA_TO_DEVICE);
425
Mark A. Greerebedbf72013-01-08 11:57:42 -0700426 memset(&cfg, 0, sizeof(cfg));
427
Mark A. Greer0d355832013-01-08 11:57:46 -0700428 cfg.src_addr = dd->phys_base + AES_REG_DATA_N(dd, 0);
429 cfg.dst_addr = dd->phys_base + AES_REG_DATA_N(dd, 0);
Mark A. Greerebedbf72013-01-08 11:57:42 -0700430 cfg.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
431 cfg.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
432 cfg.src_maxburst = DST_MAXBURST;
433 cfg.dst_maxburst = DST_MAXBURST;
434
435 /* IN */
436 ret = dmaengine_slave_config(dd->dma_lch_in, &cfg);
437 if (ret) {
438 dev_err(dd->dev, "can't configure IN dmaengine slave: %d\n",
439 ret);
440 return ret;
441 }
442
Joel Fernandes4b645c92013-08-17 21:42:25 -0500443 tx_in = dmaengine_prep_slave_sg(dd->dma_lch_in, in_sg, in_sg_len,
Mark A. Greerebedbf72013-01-08 11:57:42 -0700444 DMA_MEM_TO_DEV,
445 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
446 if (!tx_in) {
447 dev_err(dd->dev, "IN prep_slave_sg() failed\n");
448 return -EINVAL;
449 }
450
451 /* No callback necessary */
452 tx_in->callback_param = dd;
453
454 /* OUT */
455 ret = dmaengine_slave_config(dd->dma_lch_out, &cfg);
456 if (ret) {
457 dev_err(dd->dev, "can't configure OUT dmaengine slave: %d\n",
458 ret);
459 return ret;
460 }
461
Joel Fernandes4b645c92013-08-17 21:42:25 -0500462 tx_out = dmaengine_prep_slave_sg(dd->dma_lch_out, out_sg, out_sg_len,
Mark A. Greerebedbf72013-01-08 11:57:42 -0700463 DMA_DEV_TO_MEM,
464 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
465 if (!tx_out) {
466 dev_err(dd->dev, "OUT prep_slave_sg() failed\n");
467 return -EINVAL;
468 }
469
470 tx_out->callback = omap_aes_dma_out_callback;
471 tx_out->callback_param = dd;
472
473 dmaengine_submit(tx_in);
474 dmaengine_submit(tx_out);
475
476 dma_async_issue_pending(dd->dma_lch_in);
477 dma_async_issue_pending(dd->dma_lch_out);
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800478
Mark A. Greer0d355832013-01-08 11:57:46 -0700479 /* start DMA */
Joel Fernandes4b645c92013-08-17 21:42:25 -0500480 dd->pdata->trigger(dd, dd->total);
Dmitry Kasatkin83ea7e02010-11-30 10:13:31 +0200481
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800482 return 0;
483}
484
485static int omap_aes_crypt_dma_start(struct omap_aes_dev *dd)
486{
487 struct crypto_tfm *tfm = crypto_ablkcipher_tfm(
488 crypto_ablkcipher_reqtfm(dd->req));
Joel Fernandes4b645c92013-08-17 21:42:25 -0500489 int err;
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800490
491 pr_debug("total: %d\n", dd->total);
492
Joel Fernandes98837ab2013-08-17 21:42:30 -0500493 if (!dd->pio_only) {
494 err = dma_map_sg(dd->dev, dd->in_sg, dd->in_sg_len,
495 DMA_TO_DEVICE);
496 if (!err) {
497 dev_err(dd->dev, "dma_map_sg() error\n");
498 return -EINVAL;
499 }
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800500
Joel Fernandes98837ab2013-08-17 21:42:30 -0500501 err = dma_map_sg(dd->dev, dd->out_sg, dd->out_sg_len,
502 DMA_FROM_DEVICE);
503 if (!err) {
504 dev_err(dd->dev, "dma_map_sg() error\n");
505 return -EINVAL;
506 }
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800507 }
508
Joel Fernandes4b645c92013-08-17 21:42:25 -0500509 err = omap_aes_crypt_dma(tfm, dd->in_sg, dd->out_sg, dd->in_sg_len,
510 dd->out_sg_len);
Joel Fernandes98837ab2013-08-17 21:42:30 -0500511 if (err && !dd->pio_only) {
Joel Fernandes4b645c92013-08-17 21:42:25 -0500512 dma_unmap_sg(dd->dev, dd->in_sg, dd->in_sg_len, DMA_TO_DEVICE);
513 dma_unmap_sg(dd->dev, dd->out_sg, dd->out_sg_len,
514 DMA_FROM_DEVICE);
Dmitry Kasatkin21fe9762010-11-30 10:13:29 +0200515 }
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800516
517 return err;
518}
519
520static void omap_aes_finish_req(struct omap_aes_dev *dd, int err)
521{
Dmitry Kasatkin21fe9762010-11-30 10:13:29 +0200522 struct ablkcipher_request *req = dd->req;
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800523
524 pr_debug("err: %d\n", err);
525
Corentin LABBE4cba7cf2016-08-31 14:02:58 +0200526 crypto_finalize_cipher_request(dd->engine, req, err);
Tero Kristof303b452016-08-04 13:28:42 +0300527
528 pm_runtime_mark_last_busy(dd->dev);
529 pm_runtime_put_autosuspend(dd->dev);
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800530}
531
532static int omap_aes_crypt_dma_stop(struct omap_aes_dev *dd)
533{
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800534 pr_debug("total: %d\n", dd->total);
535
Mark A. Greer0d355832013-01-08 11:57:46 -0700536 omap_aes_dma_stop(dd);
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800537
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800538
Rahul Pathak16f080a2015-12-14 08:45:23 +0000539 return 0;
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800540}
541
Vutla, Lokesh6d7e7e02015-03-31 09:52:25 +0530542static int omap_aes_check_aligned(struct scatterlist *sg, int total)
Joel Fernandes62423322013-08-17 21:42:32 -0500543{
Vutla, Lokesh6d7e7e02015-03-31 09:52:25 +0530544 int len = 0;
545
Vutla, Lokesh310b0d52015-07-07 21:01:43 +0530546 if (!IS_ALIGNED(total, AES_BLOCK_SIZE))
547 return -EINVAL;
548
Joel Fernandes62423322013-08-17 21:42:32 -0500549 while (sg) {
550 if (!IS_ALIGNED(sg->offset, 4))
551 return -1;
552 if (!IS_ALIGNED(sg->length, AES_BLOCK_SIZE))
553 return -1;
Vutla, Lokesh6d7e7e02015-03-31 09:52:25 +0530554
555 len += sg->length;
Joel Fernandes62423322013-08-17 21:42:32 -0500556 sg = sg_next(sg);
557 }
Vutla, Lokesh6d7e7e02015-03-31 09:52:25 +0530558
559 if (len != total)
560 return -1;
561
Joel Fernandes62423322013-08-17 21:42:32 -0500562 return 0;
563}
564
Sachin Kamat034568e2013-09-13 17:06:46 +0530565static int omap_aes_copy_sgs(struct omap_aes_dev *dd)
Joel Fernandes62423322013-08-17 21:42:32 -0500566{
567 void *buf_in, *buf_out;
Vutla, Lokesh310b0d52015-07-07 21:01:43 +0530568 int pages, total;
Joel Fernandes62423322013-08-17 21:42:32 -0500569
Vutla, Lokesh310b0d52015-07-07 21:01:43 +0530570 total = ALIGN(dd->total, AES_BLOCK_SIZE);
571 pages = get_order(total);
Joel Fernandes62423322013-08-17 21:42:32 -0500572
573 buf_in = (void *)__get_free_pages(GFP_ATOMIC, pages);
574 buf_out = (void *)__get_free_pages(GFP_ATOMIC, pages);
575
576 if (!buf_in || !buf_out) {
577 pr_err("Couldn't allocated pages for unaligned cases.\n");
578 return -1;
579 }
580
581 dd->orig_out = dd->out_sg;
582
583 sg_copy_buf(buf_in, dd->in_sg, 0, dd->total, 0);
584
585 sg_init_table(&dd->in_sgl, 1);
Vutla, Lokesh310b0d52015-07-07 21:01:43 +0530586 sg_set_buf(&dd->in_sgl, buf_in, total);
Joel Fernandes62423322013-08-17 21:42:32 -0500587 dd->in_sg = &dd->in_sgl;
Herbert Xu7c001a82016-07-12 13:17:52 +0800588 dd->in_sg_len = 1;
Joel Fernandes62423322013-08-17 21:42:32 -0500589
590 sg_init_table(&dd->out_sgl, 1);
Vutla, Lokesh310b0d52015-07-07 21:01:43 +0530591 sg_set_buf(&dd->out_sgl, buf_out, total);
Joel Fernandes62423322013-08-17 21:42:32 -0500592 dd->out_sg = &dd->out_sgl;
Herbert Xu7c001a82016-07-12 13:17:52 +0800593 dd->out_sg_len = 1;
Joel Fernandes62423322013-08-17 21:42:32 -0500594
595 return 0;
596}
597
Dmitry Kasatkin21fe9762010-11-30 10:13:29 +0200598static int omap_aes_handle_queue(struct omap_aes_dev *dd,
Baolin Wang05299002016-01-26 20:25:40 +0800599 struct ablkcipher_request *req)
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800600{
Dmitry Kasatkineeb2b202010-11-30 10:13:28 +0200601 if (req)
Corentin LABBE4cba7cf2016-08-31 14:02:58 +0200602 return crypto_transfer_cipher_request_to_engine(dd->engine, req);
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800603
Baolin Wang05299002016-01-26 20:25:40 +0800604 return 0;
605}
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800606
Baolin Wang05299002016-01-26 20:25:40 +0800607static int omap_aes_prepare_req(struct crypto_engine *engine,
608 struct ablkcipher_request *req)
609{
610 struct omap_aes_ctx *ctx = crypto_ablkcipher_ctx(
611 crypto_ablkcipher_reqtfm(req));
Lokesh Vutla164f3ef2016-08-04 13:28:43 +0300612 struct omap_aes_dev *dd = ctx->dd;
Baolin Wang05299002016-01-26 20:25:40 +0800613 struct omap_aes_reqctx *rctx;
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800614
Baolin Wang05299002016-01-26 20:25:40 +0800615 if (!dd)
616 return -ENODEV;
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800617
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800618 /* assign new request to device */
619 dd->req = req;
620 dd->total = req->nbytes;
Joel Fernandes62423322013-08-17 21:42:32 -0500621 dd->total_save = req->nbytes;
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800622 dd->in_sg = req->src;
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800623 dd->out_sg = req->dst;
624
Herbert Xu7c001a82016-07-12 13:17:52 +0800625 dd->in_sg_len = sg_nents_for_len(dd->in_sg, dd->total);
626 if (dd->in_sg_len < 0)
627 return dd->in_sg_len;
628
629 dd->out_sg_len = sg_nents_for_len(dd->out_sg, dd->total);
630 if (dd->out_sg_len < 0)
631 return dd->out_sg_len;
632
Vutla, Lokesh6d7e7e02015-03-31 09:52:25 +0530633 if (omap_aes_check_aligned(dd->in_sg, dd->total) ||
634 omap_aes_check_aligned(dd->out_sg, dd->total)) {
Joel Fernandes62423322013-08-17 21:42:32 -0500635 if (omap_aes_copy_sgs(dd))
636 pr_err("Failed to copy SGs for unaligned cases\n");
637 dd->sgs_copied = 1;
638 } else {
639 dd->sgs_copied = 0;
640 }
641
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800642 rctx = ablkcipher_request_ctx(req);
643 ctx = crypto_ablkcipher_ctx(crypto_ablkcipher_reqtfm(req));
644 rctx->mode &= FLAGS_MODE_MASK;
645 dd->flags = (dd->flags & ~FLAGS_MODE_MASK) | rctx->mode;
646
Dmitry Kasatkin67a730c2010-11-30 10:13:30 +0200647 dd->ctx = ctx;
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800648 ctx->dd = dd;
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800649
Baolin Wang05299002016-01-26 20:25:40 +0800650 return omap_aes_write_ctrl(dd);
651}
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800652
Baolin Wang05299002016-01-26 20:25:40 +0800653static int omap_aes_crypt_req(struct crypto_engine *engine,
654 struct ablkcipher_request *req)
655{
656 struct omap_aes_ctx *ctx = crypto_ablkcipher_ctx(
657 crypto_ablkcipher_reqtfm(req));
Lokesh Vutla164f3ef2016-08-04 13:28:43 +0300658 struct omap_aes_dev *dd = ctx->dd;
Baolin Wang05299002016-01-26 20:25:40 +0800659
660 if (!dd)
661 return -ENODEV;
662
663 return omap_aes_crypt_dma_start(dd);
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800664}
665
Dmitry Kasatkin21fe9762010-11-30 10:13:29 +0200666static void omap_aes_done_task(unsigned long data)
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800667{
668 struct omap_aes_dev *dd = (struct omap_aes_dev *)data;
Joel Fernandes62423322013-08-17 21:42:32 -0500669 void *buf_in, *buf_out;
Vutla, Lokesh310b0d52015-07-07 21:01:43 +0530670 int pages, len;
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800671
Joel Fernandes4b645c92013-08-17 21:42:25 -0500672 pr_debug("enter done_task\n");
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800673
Joel Fernandes98837ab2013-08-17 21:42:30 -0500674 if (!dd->pio_only) {
675 dma_sync_sg_for_device(dd->dev, dd->out_sg, dd->out_sg_len,
676 DMA_FROM_DEVICE);
Joel Fernandes62423322013-08-17 21:42:32 -0500677 dma_unmap_sg(dd->dev, dd->in_sg, dd->in_sg_len, DMA_TO_DEVICE);
678 dma_unmap_sg(dd->dev, dd->out_sg, dd->out_sg_len,
679 DMA_FROM_DEVICE);
Joel Fernandes98837ab2013-08-17 21:42:30 -0500680 omap_aes_crypt_dma_stop(dd);
681 }
Joel Fernandes62423322013-08-17 21:42:32 -0500682
683 if (dd->sgs_copied) {
684 buf_in = sg_virt(&dd->in_sgl);
685 buf_out = sg_virt(&dd->out_sgl);
686
687 sg_copy_buf(buf_out, dd->orig_out, 0, dd->total_save, 1);
688
Vutla, Lokesh310b0d52015-07-07 21:01:43 +0530689 len = ALIGN(dd->total_save, AES_BLOCK_SIZE);
690 pages = get_order(len);
Joel Fernandes62423322013-08-17 21:42:32 -0500691 free_pages((unsigned long)buf_in, pages);
692 free_pages((unsigned long)buf_out, pages);
693 }
694
Joel Fernandes4b645c92013-08-17 21:42:25 -0500695 omap_aes_finish_req(dd, 0);
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800696
697 pr_debug("exit\n");
698}
699
700static int omap_aes_crypt(struct ablkcipher_request *req, unsigned long mode)
701{
702 struct omap_aes_ctx *ctx = crypto_ablkcipher_ctx(
703 crypto_ablkcipher_reqtfm(req));
704 struct omap_aes_reqctx *rctx = ablkcipher_request_ctx(req);
705 struct omap_aes_dev *dd;
Lokesh Vutla9fcb1912016-08-04 13:28:44 +0300706 int ret;
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800707
708 pr_debug("nbytes: %d, enc: %d, cbc: %d\n", req->nbytes,
709 !!(mode & FLAGS_ENCRYPT),
710 !!(mode & FLAGS_CBC));
711
Lokesh Vutla9fcb1912016-08-04 13:28:44 +0300712 if (req->nbytes < 200) {
713 SKCIPHER_REQUEST_ON_STACK(subreq, ctx->fallback);
714
715 skcipher_request_set_tfm(subreq, ctx->fallback);
716 skcipher_request_set_callback(subreq, req->base.flags, NULL,
717 NULL);
718 skcipher_request_set_crypt(subreq, req->src, req->dst,
719 req->nbytes, req->info);
720
721 if (mode & FLAGS_ENCRYPT)
722 ret = crypto_skcipher_encrypt(subreq);
723 else
724 ret = crypto_skcipher_decrypt(subreq);
725
726 skcipher_request_zero(subreq);
727 return ret;
728 }
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800729 dd = omap_aes_find_dev(ctx);
730 if (!dd)
731 return -ENODEV;
732
733 rctx->mode = mode;
734
Dmitry Kasatkin21fe9762010-11-30 10:13:29 +0200735 return omap_aes_handle_queue(dd, req);
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800736}
737
738/* ********************** ALG API ************************************ */
739
740static int omap_aes_setkey(struct crypto_ablkcipher *tfm, const u8 *key,
741 unsigned int keylen)
742{
743 struct omap_aes_ctx *ctx = crypto_ablkcipher_ctx(tfm);
Lokesh Vutla9fcb1912016-08-04 13:28:44 +0300744 int ret;
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800745
746 if (keylen != AES_KEYSIZE_128 && keylen != AES_KEYSIZE_192 &&
747 keylen != AES_KEYSIZE_256)
748 return -EINVAL;
749
750 pr_debug("enter, keylen: %d\n", keylen);
751
752 memcpy(ctx->key, key, keylen);
753 ctx->keylen = keylen;
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800754
Lokesh Vutla9fcb1912016-08-04 13:28:44 +0300755 crypto_skcipher_clear_flags(ctx->fallback, CRYPTO_TFM_REQ_MASK);
756 crypto_skcipher_set_flags(ctx->fallback, tfm->base.crt_flags &
757 CRYPTO_TFM_REQ_MASK);
758
759 ret = crypto_skcipher_setkey(ctx->fallback, key, keylen);
760 if (!ret)
761 return 0;
762
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800763 return 0;
764}
765
766static int omap_aes_ecb_encrypt(struct ablkcipher_request *req)
767{
768 return omap_aes_crypt(req, FLAGS_ENCRYPT);
769}
770
771static int omap_aes_ecb_decrypt(struct ablkcipher_request *req)
772{
773 return omap_aes_crypt(req, 0);
774}
775
776static int omap_aes_cbc_encrypt(struct ablkcipher_request *req)
777{
778 return omap_aes_crypt(req, FLAGS_ENCRYPT | FLAGS_CBC);
779}
780
781static int omap_aes_cbc_decrypt(struct ablkcipher_request *req)
782{
783 return omap_aes_crypt(req, FLAGS_CBC);
784}
785
Mark A. Greerf9fb69e2013-01-08 11:57:47 -0700786static int omap_aes_ctr_encrypt(struct ablkcipher_request *req)
787{
788 return omap_aes_crypt(req, FLAGS_ENCRYPT | FLAGS_CTR);
789}
790
791static int omap_aes_ctr_decrypt(struct ablkcipher_request *req)
792{
793 return omap_aes_crypt(req, FLAGS_CTR);
794}
795
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800796static int omap_aes_cra_init(struct crypto_tfm *tfm)
797{
Lokesh Vutla9fcb1912016-08-04 13:28:44 +0300798 const char *name = crypto_tfm_alg_name(tfm);
799 const u32 flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_NEED_FALLBACK;
800 struct omap_aes_ctx *ctx = crypto_tfm_ctx(tfm);
801 struct crypto_skcipher *blk;
802
803 blk = crypto_alloc_skcipher(name, 0, flags);
804 if (IS_ERR(blk))
805 return PTR_ERR(blk);
806
807 ctx->fallback = blk;
808
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800809 tfm->crt_ablkcipher.reqsize = sizeof(struct omap_aes_reqctx);
810
811 return 0;
812}
813
814static void omap_aes_cra_exit(struct crypto_tfm *tfm)
815{
Lokesh Vutla9fcb1912016-08-04 13:28:44 +0300816 struct omap_aes_ctx *ctx = crypto_tfm_ctx(tfm);
817
818 if (ctx->fallback)
819 crypto_free_skcipher(ctx->fallback);
820
821 ctx->fallback = NULL;
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800822}
823
824/* ********************** ALGS ************************************ */
825
Mark A. Greerf9fb69e2013-01-08 11:57:47 -0700826static struct crypto_alg algs_ecb_cbc[] = {
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800827{
828 .cra_name = "ecb(aes)",
829 .cra_driver_name = "ecb-aes-omap",
Vutla, Lokesh6e2e3d12015-07-07 21:01:44 +0530830 .cra_priority = 300,
Nikos Mavrogiannopoulosd912bb72011-11-01 13:39:56 +0100831 .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER |
832 CRYPTO_ALG_KERN_DRIVER_ONLY |
Lokesh Vutla9fcb1912016-08-04 13:28:44 +0300833 CRYPTO_ALG_ASYNC | CRYPTO_ALG_NEED_FALLBACK,
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800834 .cra_blocksize = AES_BLOCK_SIZE,
835 .cra_ctxsize = sizeof(struct omap_aes_ctx),
Dmitry Kasatkinefce41b2010-11-30 10:13:32 +0200836 .cra_alignmask = 0,
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800837 .cra_type = &crypto_ablkcipher_type,
838 .cra_module = THIS_MODULE,
839 .cra_init = omap_aes_cra_init,
840 .cra_exit = omap_aes_cra_exit,
841 .cra_u.ablkcipher = {
842 .min_keysize = AES_MIN_KEY_SIZE,
843 .max_keysize = AES_MAX_KEY_SIZE,
844 .setkey = omap_aes_setkey,
845 .encrypt = omap_aes_ecb_encrypt,
846 .decrypt = omap_aes_ecb_decrypt,
847 }
848},
849{
850 .cra_name = "cbc(aes)",
851 .cra_driver_name = "cbc-aes-omap",
Vutla, Lokesh6e2e3d12015-07-07 21:01:44 +0530852 .cra_priority = 300,
Nikos Mavrogiannopoulosd912bb72011-11-01 13:39:56 +0100853 .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER |
854 CRYPTO_ALG_KERN_DRIVER_ONLY |
Lokesh Vutla9fcb1912016-08-04 13:28:44 +0300855 CRYPTO_ALG_ASYNC | CRYPTO_ALG_NEED_FALLBACK,
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800856 .cra_blocksize = AES_BLOCK_SIZE,
857 .cra_ctxsize = sizeof(struct omap_aes_ctx),
Dmitry Kasatkinefce41b2010-11-30 10:13:32 +0200858 .cra_alignmask = 0,
Dmitry Kasatkin537559a2010-09-03 19:16:02 +0800859 .cra_type = &crypto_ablkcipher_type,
860 .cra_module = THIS_MODULE,
861 .cra_init = omap_aes_cra_init,
862 .cra_exit = omap_aes_cra_exit,
863 .cra_u.ablkcipher = {
864 .min_keysize = AES_MIN_KEY_SIZE,
865 .max_keysize = AES_MAX_KEY_SIZE,
866 .ivsize = AES_BLOCK_SIZE,
867 .setkey = omap_aes_setkey,
868 .encrypt = omap_aes_cbc_encrypt,
869 .decrypt = omap_aes_cbc_decrypt,
870 }
871}
872};
873
Mark A. Greerf9fb69e2013-01-08 11:57:47 -0700874static struct crypto_alg algs_ctr[] = {
875{
876 .cra_name = "ctr(aes)",
877 .cra_driver_name = "ctr-aes-omap",
Vutla, Lokesh6e2e3d12015-07-07 21:01:44 +0530878 .cra_priority = 300,
Mark A. Greerf9fb69e2013-01-08 11:57:47 -0700879 .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER |
880 CRYPTO_ALG_KERN_DRIVER_ONLY |
Lokesh Vutla9fcb1912016-08-04 13:28:44 +0300881 CRYPTO_ALG_ASYNC | CRYPTO_ALG_NEED_FALLBACK,
Mark A. Greerf9fb69e2013-01-08 11:57:47 -0700882 .cra_blocksize = AES_BLOCK_SIZE,
883 .cra_ctxsize = sizeof(struct omap_aes_ctx),
884 .cra_alignmask = 0,
885 .cra_type = &crypto_ablkcipher_type,
886 .cra_module = THIS_MODULE,
887 .cra_init = omap_aes_cra_init,
888 .cra_exit = omap_aes_cra_exit,
889 .cra_u.ablkcipher = {
890 .min_keysize = AES_MIN_KEY_SIZE,
891 .max_keysize = AES_MAX_KEY_SIZE,
892 .geniv = "eseqiv",
893 .ivsize = AES_BLOCK_SIZE,
894 .setkey = omap_aes_setkey,
895 .encrypt = omap_aes_ctr_encrypt,
896 .decrypt = omap_aes_ctr_decrypt,
897 }
898} ,
899};
900
901static struct omap_aes_algs_info omap_aes_algs_info_ecb_cbc[] = {
902 {
903 .algs_list = algs_ecb_cbc,
904 .size = ARRAY_SIZE(algs_ecb_cbc),
905 },
906};
907
Mark A. Greer0d355832013-01-08 11:57:46 -0700908static const struct omap_aes_pdata omap_aes_pdata_omap2 = {
Mark A. Greerf9fb69e2013-01-08 11:57:47 -0700909 .algs_info = omap_aes_algs_info_ecb_cbc,
910 .algs_info_size = ARRAY_SIZE(omap_aes_algs_info_ecb_cbc),
Mark A. Greer0d355832013-01-08 11:57:46 -0700911 .trigger = omap_aes_dma_trigger_omap2,
912 .key_ofs = 0x1c,
913 .iv_ofs = 0x20,
914 .ctrl_ofs = 0x30,
915 .data_ofs = 0x34,
916 .rev_ofs = 0x44,
917 .mask_ofs = 0x48,
918 .dma_enable_in = BIT(2),
919 .dma_enable_out = BIT(3),
920 .dma_start = BIT(5),
921 .major_mask = 0xf0,
922 .major_shift = 4,
923 .minor_mask = 0x0f,
924 .minor_shift = 0,
925};
926
Mark A. Greerbc69d122013-01-08 11:57:44 -0700927#ifdef CONFIG_OF
Mark A. Greerf9fb69e2013-01-08 11:57:47 -0700928static struct omap_aes_algs_info omap_aes_algs_info_ecb_cbc_ctr[] = {
929 {
930 .algs_list = algs_ecb_cbc,
931 .size = ARRAY_SIZE(algs_ecb_cbc),
932 },
933 {
934 .algs_list = algs_ctr,
935 .size = ARRAY_SIZE(algs_ctr),
936 },
937};
938
939static const struct omap_aes_pdata omap_aes_pdata_omap3 = {
940 .algs_info = omap_aes_algs_info_ecb_cbc_ctr,
941 .algs_info_size = ARRAY_SIZE(omap_aes_algs_info_ecb_cbc_ctr),
942 .trigger = omap_aes_dma_trigger_omap2,
943 .key_ofs = 0x1c,
944 .iv_ofs = 0x20,
945 .ctrl_ofs = 0x30,
946 .data_ofs = 0x34,
947 .rev_ofs = 0x44,
948 .mask_ofs = 0x48,
949 .dma_enable_in = BIT(2),
950 .dma_enable_out = BIT(3),
951 .dma_start = BIT(5),
952 .major_mask = 0xf0,
953 .major_shift = 4,
954 .minor_mask = 0x0f,
955 .minor_shift = 0,
956};
957
Mark A. Greer0d355832013-01-08 11:57:46 -0700958static const struct omap_aes_pdata omap_aes_pdata_omap4 = {
Mark A. Greerf9fb69e2013-01-08 11:57:47 -0700959 .algs_info = omap_aes_algs_info_ecb_cbc_ctr,
960 .algs_info_size = ARRAY_SIZE(omap_aes_algs_info_ecb_cbc_ctr),
Mark A. Greer0d355832013-01-08 11:57:46 -0700961 .trigger = omap_aes_dma_trigger_omap4,
962 .key_ofs = 0x3c,
963 .iv_ofs = 0x40,
964 .ctrl_ofs = 0x50,
965 .data_ofs = 0x60,
966 .rev_ofs = 0x80,
967 .mask_ofs = 0x84,
Joel Fernandes67216752013-08-17 21:42:28 -0500968 .irq_status_ofs = 0x8c,
969 .irq_enable_ofs = 0x90,
Mark A. Greer0d355832013-01-08 11:57:46 -0700970 .dma_enable_in = BIT(5),
971 .dma_enable_out = BIT(6),
972 .major_mask = 0x0700,
973 .major_shift = 8,
974 .minor_mask = 0x003f,
975 .minor_shift = 0,
976};
977
Joel Fernandes1bf95cc2013-08-17 21:42:29 -0500978static irqreturn_t omap_aes_irq(int irq, void *dev_id)
979{
980 struct omap_aes_dev *dd = dev_id;
981 u32 status, i;
982 u32 *src, *dst;
983
984 status = omap_aes_read(dd, AES_REG_IRQ_STATUS(dd));
985 if (status & AES_REG_IRQ_DATA_IN) {
986 omap_aes_write(dd, AES_REG_IRQ_ENABLE(dd), 0x0);
987
988 BUG_ON(!dd->in_sg);
989
990 BUG_ON(_calc_walked(in) > dd->in_sg->length);
991
992 src = sg_virt(dd->in_sg) + _calc_walked(in);
993
994 for (i = 0; i < AES_BLOCK_WORDS; i++) {
995 omap_aes_write(dd, AES_REG_DATA_N(dd, i), *src);
996
997 scatterwalk_advance(&dd->in_walk, 4);
998 if (dd->in_sg->length == _calc_walked(in)) {
Cristian Stoica5be4d4c2015-01-20 10:06:16 +0200999 dd->in_sg = sg_next(dd->in_sg);
Joel Fernandes1bf95cc2013-08-17 21:42:29 -05001000 if (dd->in_sg) {
1001 scatterwalk_start(&dd->in_walk,
1002 dd->in_sg);
1003 src = sg_virt(dd->in_sg) +
1004 _calc_walked(in);
1005 }
1006 } else {
1007 src++;
1008 }
1009 }
1010
1011 /* Clear IRQ status */
1012 status &= ~AES_REG_IRQ_DATA_IN;
1013 omap_aes_write(dd, AES_REG_IRQ_STATUS(dd), status);
1014
1015 /* Enable DATA_OUT interrupt */
1016 omap_aes_write(dd, AES_REG_IRQ_ENABLE(dd), 0x4);
1017
1018 } else if (status & AES_REG_IRQ_DATA_OUT) {
1019 omap_aes_write(dd, AES_REG_IRQ_ENABLE(dd), 0x0);
1020
1021 BUG_ON(!dd->out_sg);
1022
1023 BUG_ON(_calc_walked(out) > dd->out_sg->length);
1024
1025 dst = sg_virt(dd->out_sg) + _calc_walked(out);
1026
1027 for (i = 0; i < AES_BLOCK_WORDS; i++) {
1028 *dst = omap_aes_read(dd, AES_REG_DATA_N(dd, i));
1029 scatterwalk_advance(&dd->out_walk, 4);
1030 if (dd->out_sg->length == _calc_walked(out)) {
Cristian Stoica5be4d4c2015-01-20 10:06:16 +02001031 dd->out_sg = sg_next(dd->out_sg);
Joel Fernandes1bf95cc2013-08-17 21:42:29 -05001032 if (dd->out_sg) {
1033 scatterwalk_start(&dd->out_walk,
1034 dd->out_sg);
1035 dst = sg_virt(dd->out_sg) +
1036 _calc_walked(out);
1037 }
1038 } else {
1039 dst++;
1040 }
1041 }
1042
Vutla, Lokesh310b0d52015-07-07 21:01:43 +05301043 dd->total -= min_t(size_t, AES_BLOCK_SIZE, dd->total);
Joel Fernandes1bf95cc2013-08-17 21:42:29 -05001044
1045 /* Clear IRQ status */
1046 status &= ~AES_REG_IRQ_DATA_OUT;
1047 omap_aes_write(dd, AES_REG_IRQ_STATUS(dd), status);
1048
1049 if (!dd->total)
1050 /* All bytes read! */
1051 tasklet_schedule(&dd->done_task);
1052 else
1053 /* Enable DATA_IN interrupt for next block */
1054 omap_aes_write(dd, AES_REG_IRQ_ENABLE(dd), 0x2);
1055 }
1056
1057 return IRQ_HANDLED;
1058}
1059
Mark A. Greerbc69d122013-01-08 11:57:44 -07001060static const struct of_device_id omap_aes_of_match[] = {
1061 {
1062 .compatible = "ti,omap2-aes",
Mark A. Greer0d355832013-01-08 11:57:46 -07001063 .data = &omap_aes_pdata_omap2,
1064 },
1065 {
Mark A. Greerf9fb69e2013-01-08 11:57:47 -07001066 .compatible = "ti,omap3-aes",
1067 .data = &omap_aes_pdata_omap3,
1068 },
1069 {
Mark A. Greer0d355832013-01-08 11:57:46 -07001070 .compatible = "ti,omap4-aes",
1071 .data = &omap_aes_pdata_omap4,
Mark A. Greerbc69d122013-01-08 11:57:44 -07001072 },
1073 {},
1074};
1075MODULE_DEVICE_TABLE(of, omap_aes_of_match);
1076
1077static int omap_aes_get_res_of(struct omap_aes_dev *dd,
1078 struct device *dev, struct resource *res)
1079{
1080 struct device_node *node = dev->of_node;
1081 const struct of_device_id *match;
1082 int err = 0;
1083
1084 match = of_match_device(of_match_ptr(omap_aes_of_match), dev);
1085 if (!match) {
1086 dev_err(dev, "no compatible OF match\n");
1087 err = -EINVAL;
1088 goto err;
1089 }
1090
1091 err = of_address_to_resource(node, 0, res);
1092 if (err < 0) {
1093 dev_err(dev, "can't translate OF node address\n");
1094 err = -EINVAL;
1095 goto err;
1096 }
1097
Mark A. Greer0d355832013-01-08 11:57:46 -07001098 dd->pdata = match->data;
1099
Mark A. Greerbc69d122013-01-08 11:57:44 -07001100err:
1101 return err;
1102}
1103#else
1104static const struct of_device_id omap_aes_of_match[] = {
1105 {},
1106};
1107
1108static int omap_aes_get_res_of(struct omap_aes_dev *dd,
1109 struct device *dev, struct resource *res)
1110{
1111 return -EINVAL;
1112}
1113#endif
1114
1115static int omap_aes_get_res_pdev(struct omap_aes_dev *dd,
1116 struct platform_device *pdev, struct resource *res)
1117{
1118 struct device *dev = &pdev->dev;
1119 struct resource *r;
1120 int err = 0;
1121
1122 /* Get the base address */
1123 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1124 if (!r) {
1125 dev_err(dev, "no MEM resource info\n");
1126 err = -ENODEV;
1127 goto err;
1128 }
1129 memcpy(res, r, sizeof(*res));
1130
Mark A. Greer0d355832013-01-08 11:57:46 -07001131 /* Only OMAP2/3 can be non-DT */
1132 dd->pdata = &omap_aes_pdata_omap2;
1133
Mark A. Greerbc69d122013-01-08 11:57:44 -07001134err:
1135 return err;
1136}
1137
Dmitry Kasatkin537559a2010-09-03 19:16:02 +08001138static int omap_aes_probe(struct platform_device *pdev)
1139{
1140 struct device *dev = &pdev->dev;
1141 struct omap_aes_dev *dd;
Mark A. Greerf9fb69e2013-01-08 11:57:47 -07001142 struct crypto_alg *algp;
Mark A. Greerbc69d122013-01-08 11:57:44 -07001143 struct resource res;
Joel Fernandes1801ad92013-08-17 21:42:31 -05001144 int err = -ENOMEM, i, j, irq = -1;
Dmitry Kasatkin537559a2010-09-03 19:16:02 +08001145 u32 reg;
1146
Joel Fernandes05007c12013-08-17 21:42:33 -05001147 dd = devm_kzalloc(dev, sizeof(struct omap_aes_dev), GFP_KERNEL);
Dmitry Kasatkin537559a2010-09-03 19:16:02 +08001148 if (dd == NULL) {
1149 dev_err(dev, "unable to alloc data struct.\n");
1150 goto err_data;
1151 }
1152 dd->dev = dev;
1153 platform_set_drvdata(pdev, dd);
1154
Mark A. Greerbc69d122013-01-08 11:57:44 -07001155 err = (dev->of_node) ? omap_aes_get_res_of(dd, dev, &res) :
1156 omap_aes_get_res_pdev(dd, pdev, &res);
1157 if (err)
Dmitry Kasatkin537559a2010-09-03 19:16:02 +08001158 goto err_res;
Dmitry Kasatkin537559a2010-09-03 19:16:02 +08001159
Laurent Navet30862282013-05-02 14:00:38 +02001160 dd->io_base = devm_ioremap_resource(dev, &res);
1161 if (IS_ERR(dd->io_base)) {
1162 err = PTR_ERR(dd->io_base);
Mark A. Greer5946c4a2013-01-08 11:57:40 -07001163 goto err_res;
Dmitry Kasatkin537559a2010-09-03 19:16:02 +08001164 }
Mark A. Greerbc69d122013-01-08 11:57:44 -07001165 dd->phys_base = res.start;
Dmitry Kasatkin537559a2010-09-03 19:16:02 +08001166
Tero Kristof303b452016-08-04 13:28:42 +03001167 pm_runtime_use_autosuspend(dev);
1168 pm_runtime_set_autosuspend_delay(dev, DEFAULT_AUTOSUSPEND_DELAY);
1169
Mark A. Greer5946c4a2013-01-08 11:57:40 -07001170 pm_runtime_enable(dev);
Nishanth Menonf7b2b5d2013-12-03 19:43:13 -06001171 err = pm_runtime_get_sync(dev);
1172 if (err < 0) {
1173 dev_err(dev, "%s: failed to get_sync(%d)\n",
1174 __func__, err);
1175 goto err_res;
1176 }
Mark A. Greer5946c4a2013-01-08 11:57:40 -07001177
Mark A. Greer0d355832013-01-08 11:57:46 -07001178 omap_aes_dma_stop(dd);
1179
1180 reg = omap_aes_read(dd, AES_REG_REV(dd));
Mark A. Greer5946c4a2013-01-08 11:57:40 -07001181
1182 pm_runtime_put_sync(dev);
Dmitry Kasatkin537559a2010-09-03 19:16:02 +08001183
Mark A. Greer0d355832013-01-08 11:57:46 -07001184 dev_info(dev, "OMAP AES hw accel rev: %u.%u\n",
1185 (reg & dd->pdata->major_mask) >> dd->pdata->major_shift,
1186 (reg & dd->pdata->minor_mask) >> dd->pdata->minor_shift);
1187
Dmitry Kasatkin21fe9762010-11-30 10:13:29 +02001188 tasklet_init(&dd->done_task, omap_aes_done_task, (unsigned long)dd);
Dmitry Kasatkin537559a2010-09-03 19:16:02 +08001189
1190 err = omap_aes_dma_init(dd);
Peter Ujfalusida8b29a2016-04-29 16:02:18 +03001191 if (err == -EPROBE_DEFER) {
1192 goto err_irq;
1193 } else if (err && AES_REG_IRQ_STATUS(dd) && AES_REG_IRQ_ENABLE(dd)) {
Joel Fernandes1801ad92013-08-17 21:42:31 -05001194 dd->pio_only = 1;
1195
1196 irq = platform_get_irq(pdev, 0);
1197 if (irq < 0) {
1198 dev_err(dev, "can't get IRQ resource\n");
1199 goto err_irq;
1200 }
1201
Joel Fernandesbce2a222013-08-17 21:42:34 -05001202 err = devm_request_irq(dev, irq, omap_aes_irq, 0,
Joel Fernandes1801ad92013-08-17 21:42:31 -05001203 dev_name(dev), dd);
1204 if (err) {
1205 dev_err(dev, "Unable to grab omap-aes IRQ\n");
1206 goto err_irq;
1207 }
1208 }
1209
Dmitry Kasatkin537559a2010-09-03 19:16:02 +08001210
1211 INIT_LIST_HEAD(&dd->list);
1212 spin_lock(&list_lock);
1213 list_add_tail(&dd->list, &dev_list);
1214 spin_unlock(&list_lock);
1215
Tero Kristo0d0cda932016-08-04 13:28:45 +03001216 /* Initialize crypto engine */
1217 dd->engine = crypto_engine_alloc_init(dev, 1);
Wei Yongjunc98ef8d2016-09-15 03:27:32 +00001218 if (!dd->engine) {
1219 err = -ENOMEM;
Tero Kristo0d0cda932016-08-04 13:28:45 +03001220 goto err_engine;
Wei Yongjunc98ef8d2016-09-15 03:27:32 +00001221 }
Tero Kristo0d0cda932016-08-04 13:28:45 +03001222
1223 dd->engine->prepare_cipher_request = omap_aes_prepare_req;
1224 dd->engine->cipher_one_request = omap_aes_crypt_req;
1225 err = crypto_engine_start(dd->engine);
1226 if (err)
1227 goto err_engine;
1228
Mark A. Greerf9fb69e2013-01-08 11:57:47 -07001229 for (i = 0; i < dd->pdata->algs_info_size; i++) {
Lokesh Vutla3741bbb2016-06-01 11:56:02 +03001230 if (!dd->pdata->algs_info[i].registered) {
1231 for (j = 0; j < dd->pdata->algs_info[i].size; j++) {
1232 algp = &dd->pdata->algs_info[i].algs_list[j];
Mark A. Greerf9fb69e2013-01-08 11:57:47 -07001233
Lokesh Vutla3741bbb2016-06-01 11:56:02 +03001234 pr_debug("reg alg: %s\n", algp->cra_name);
1235 INIT_LIST_HEAD(&algp->cra_list);
Mark A. Greerf9fb69e2013-01-08 11:57:47 -07001236
Lokesh Vutla3741bbb2016-06-01 11:56:02 +03001237 err = crypto_register_alg(algp);
1238 if (err)
1239 goto err_algs;
Mark A. Greerf9fb69e2013-01-08 11:57:47 -07001240
Lokesh Vutla3741bbb2016-06-01 11:56:02 +03001241 dd->pdata->algs_info[i].registered++;
1242 }
Mark A. Greerf9fb69e2013-01-08 11:57:47 -07001243 }
Dmitry Kasatkin537559a2010-09-03 19:16:02 +08001244 }
1245
Dmitry Kasatkin537559a2010-09-03 19:16:02 +08001246 return 0;
1247err_algs:
Mark A. Greerf9fb69e2013-01-08 11:57:47 -07001248 for (i = dd->pdata->algs_info_size - 1; i >= 0; i--)
1249 for (j = dd->pdata->algs_info[i].registered - 1; j >= 0; j--)
1250 crypto_unregister_alg(
1251 &dd->pdata->algs_info[i].algs_list[j]);
Peter Ujfalusida8b29a2016-04-29 16:02:18 +03001252
Tero Kristo0d0cda932016-08-04 13:28:45 +03001253err_engine:
1254 if (dd->engine)
1255 crypto_engine_exit(dd->engine);
1256
Peter Ujfalusida8b29a2016-04-29 16:02:18 +03001257 omap_aes_dma_cleanup(dd);
Joel Fernandes1801ad92013-08-17 21:42:31 -05001258err_irq:
Dmitry Kasatkin21fe9762010-11-30 10:13:29 +02001259 tasklet_kill(&dd->done_task);
Mark A. Greer5946c4a2013-01-08 11:57:40 -07001260 pm_runtime_disable(dev);
Dmitry Kasatkin537559a2010-09-03 19:16:02 +08001261err_res:
Dmitry Kasatkin537559a2010-09-03 19:16:02 +08001262 dd = NULL;
1263err_data:
1264 dev_err(dev, "initialization failed.\n");
1265 return err;
1266}
1267
1268static int omap_aes_remove(struct platform_device *pdev)
1269{
1270 struct omap_aes_dev *dd = platform_get_drvdata(pdev);
Mark A. Greerf9fb69e2013-01-08 11:57:47 -07001271 int i, j;
Dmitry Kasatkin537559a2010-09-03 19:16:02 +08001272
1273 if (!dd)
1274 return -ENODEV;
1275
1276 spin_lock(&list_lock);
1277 list_del(&dd->list);
1278 spin_unlock(&list_lock);
1279
Mark A. Greerf9fb69e2013-01-08 11:57:47 -07001280 for (i = dd->pdata->algs_info_size - 1; i >= 0; i--)
1281 for (j = dd->pdata->algs_info[i].registered - 1; j >= 0; j--)
1282 crypto_unregister_alg(
1283 &dd->pdata->algs_info[i].algs_list[j]);
Dmitry Kasatkin537559a2010-09-03 19:16:02 +08001284
Baolin Wang05299002016-01-26 20:25:40 +08001285 crypto_engine_exit(dd->engine);
Dmitry Kasatkin21fe9762010-11-30 10:13:29 +02001286 tasklet_kill(&dd->done_task);
Dmitry Kasatkin537559a2010-09-03 19:16:02 +08001287 omap_aes_dma_cleanup(dd);
Mark A. Greer5946c4a2013-01-08 11:57:40 -07001288 pm_runtime_disable(dd->dev);
Dmitry Kasatkin537559a2010-09-03 19:16:02 +08001289 dd = NULL;
1290
1291 return 0;
1292}
1293
Mark A. Greer0635fb32013-01-08 11:57:41 -07001294#ifdef CONFIG_PM_SLEEP
1295static int omap_aes_suspend(struct device *dev)
1296{
1297 pm_runtime_put_sync(dev);
1298 return 0;
1299}
1300
1301static int omap_aes_resume(struct device *dev)
1302{
1303 pm_runtime_get_sync(dev);
1304 return 0;
1305}
1306#endif
1307
Jingoo Hanea7b2842014-02-27 20:31:38 +09001308static SIMPLE_DEV_PM_OPS(omap_aes_pm_ops, omap_aes_suspend, omap_aes_resume);
Mark A. Greer0635fb32013-01-08 11:57:41 -07001309
Dmitry Kasatkin537559a2010-09-03 19:16:02 +08001310static struct platform_driver omap_aes_driver = {
1311 .probe = omap_aes_probe,
1312 .remove = omap_aes_remove,
1313 .driver = {
1314 .name = "omap-aes",
Mark A. Greer0635fb32013-01-08 11:57:41 -07001315 .pm = &omap_aes_pm_ops,
Mark A. Greerbc69d122013-01-08 11:57:44 -07001316 .of_match_table = omap_aes_of_match,
Dmitry Kasatkin537559a2010-09-03 19:16:02 +08001317 },
1318};
1319
Sachin Kamat94e51df2013-03-04 15:09:42 +05301320module_platform_driver(omap_aes_driver);
Dmitry Kasatkin537559a2010-09-03 19:16:02 +08001321
1322MODULE_DESCRIPTION("OMAP AES hw acceleration support.");
1323MODULE_LICENSE("GPL v2");
1324MODULE_AUTHOR("Dmitry Kasatkin");
1325