add chaos_calmer branch
[15.05/openwrt.git] / package / kernel / lantiq / ltq-deu / src / ifxmips_deu_vr9.c
1 /******************************************************************************
2 **
3 ** FILE NAME    : ifxmips_deu_vr9.c
4 ** PROJECT      : IFX UEIP
5 ** MODULES      : DEU Module for VR9
6 **
7 ** DATE         : September 8, 2009
8 ** AUTHOR       : Mohammad Firdaus
9 ** DESCRIPTION  : Data Encryption Unit Driver
10 ** COPYRIGHT    :       Copyright (c) 2009
11 **                      Infineon Technologies AG
12 **                      Am Campeon 1-12, 85579 Neubiberg, Germany
13 **
14 **    This program is free software; you can redistribute it and/or modify
15 **    it under the terms of the GNU General Public License as published by
16 **    the Free Software Foundation; either version 2 of the License, or
17 **    (at your option) any later version.
18 **
19 ** HISTORY
20 ** $Date        $Author             $Comment
21 ** 08,Sept 2009 Mohammad Firdaus    Initial UEIP release
22 *******************************************************************************/
23
24 /*!
25   \defgroup  IFX_DEU IFX_DEU_DRIVERS
26   \ingroup  API
27   \brief deu driver module
28 */
29
30 /*!
31   \file         ifxmips_deu_vr9.c
32   \ingroup      IFX_DEU
33   \brief        board specific deu driver file for vr9
34 */
35
36 /*!
37   \defgroup   BOARD_SPECIFIC_FUNCTIONS IFX_BOARD_SPECIFIC_FUNCTIONS
38   \ingroup IFX_DEU
39   \brief board specific deu driver functions
40 */
41
42 /* Project header files */
43 #include <linux/module.h>
44 #include <linux/init.h>
45 #include <linux/types.h>
46 #include <linux/errno.h>
47 #include <asm/io.h> //dma_cache_inv
48
49 #include "ifxmips_deu_dma.h"
50 #include "ifxmips_deu_vr9.h"
51
52 /* Function decleration */
53 void aes_chip_init (void);
54 void des_chip_init (void);
55 int deu_dma_init (void);
56 void deu_dma_priv_init(void);
57 u32 endian_swap(u32 input);
58 u32* memory_alignment(const u8 *arg, u32 *buff_alloc, int in_out, int nbytes);
59 void aes_dma_memory_copy(u32 *outcopy, u32 *out_dma, u8 *out_arg, int nbytes);
60 void des_dma_memory_copy(u32 *outcopy, u32 *out_dma, u8 *out_arg, int nbytes);
61 void __exit ifxdeu_fini_dma(void);
62
63 #define DES_3DES_START  IFX_DES_CON
64 #define AES_START       IFX_AES_CON
65
66 /* Variables */
67
68 u8 *g_dma_page_ptr = NULL;
69 u8 *g_dma_block = NULL;
70 u8 *g_dma_block2 = NULL;
71
72 deu_drv_priv_t deu_dma_priv;
73
74
75 /*! \fn u32 endian_swap(u32 input) 
76  *  \ingroup BOARD_SPECIFIC_FUNCTIONS
77  *  \brief Swap data given to the function 
78  *  \param input Data input to be swapped
79  *  \return either the swapped data or the input data depending on whether it is in DMA mode or FPI mode
80 */
81
82
83 u32 endian_swap(u32 input)
84 {
85     return input;
86 }
87
88 /*! \fn u32 input_swap(u32 input)
89  *  \ingroup BOARD_SPECIFIC_FUNCTIONS
90  *  \brief Not used  
91  *  \return input
92 */
93
94 u32 input_swap(u32 input)
95 {
96     return input;
97 }
98
99 /*! \fn void aes_chip_init (void)
100  *  \ingroup BOARD_SPECIFIC_FUNCTIONS
101  *  \brief initialize AES hardware   
102 */
103
104 void aes_chip_init (void)
105 {
106     volatile struct aes_t *aes = (struct aes_t *) AES_START;
107
108     // start crypto engine with write to ILR
109     aes->controlr.SM = 1;
110     aes->controlr.NDC = 0;
111     asm("sync");
112     aes->controlr.ENDI = 1;
113     asm("sync");
114     aes->controlr.ARS = 0;
115         
116 }
117
118 /*! \fn void des_chip_init (void)
119  *  \ingroup IFX_AES_FUNCTIONS
120  *  \brief initialize DES hardware
121 */         
122                         
123 void des_chip_init (void)
124 {
125     volatile struct des_t *des = (struct des_t *) DES_3DES_START;
126
127     // start crypto engine with write to ILR
128     des->controlr.SM = 1;
129     des->controlr.NDC = 1;
130     asm("sync");
131     des->controlr.ENDI = 1;
132     asm("sync");    
133     des->controlr.ARS = 0;
134
135 }
136 /*! \fn void chip_version(void)
137  *  \ingroup IFX_DES_FUNCTIONS
138  *  \brief function not used in VR9
139 */
140 void chip_version(void) 
141 {
142     return;
143 }
144