[ubicom32]: move new files out from platform support patch
[openwrt/svn-archive/archive.git] / target / linux / ubicom32 / files / arch / ubicom32 / crypto / crypto_ubicom32.c
1 /*
2 * arch/ubicom32/crypto/crypto_ubicom32.c
3 * Generic code to support ubicom32 hardware crypto accelerator
4 *
5 * (C) Copyright 2009, Ubicom, Inc.
6 *
7 * This file is part of the Ubicom32 Linux Kernel Port.
8 *
9 * The Ubicom32 Linux Kernel Port is free software: you can redistribute
10 * it and/or modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation, either version 2 of the
12 * License, or (at your option) any later version.
13 *
14 * The Ubicom32 Linux Kernel Port is distributed in the hope that it
15 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
16 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
17 * the GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with the Ubicom32 Linux Kernel Port. If not,
21 * see <http://www.gnu.org/licenses/>.
22 *
23 * Ubicom32 implementation derived from (with many thanks):
24 * arch/m68knommu
25 * arch/blackfin
26 * arch/parisc
27 */
28 #include "crypto_ubicom32.h"
29
30 spinlock_t crypto_ubicom32_lock;
31 bool crypto_ubicom32_inited = false;
32 volatile bool crypto_ubicom32_on = false;
33 volatile unsigned long crypto_ubicom32_last_use;
34
35 struct timer_list crypto_ubicom32_ps_timer;
36 void crypto_ubicom32_ps_check(unsigned long data)
37 {
38 unsigned long idle_time = msecs_to_jiffies(HW_CRYPTO_PS_MAX_IDLE_MS);
39
40 BUG_ON(!crypto_ubicom32_on);
41
42 if (((jiffies - crypto_ubicom32_last_use) > idle_time) && spin_trylock_bh(&crypto_ubicom32_lock)) {
43 hw_crypto_turn_off();
44 spin_unlock_bh(&crypto_ubicom32_lock);
45 return;
46 }
47
48 /* keep monitoring */
49 hw_crypto_ps_start();
50 }