lantiq: Tune the XWAY subtarget cflags
[openwrt.git] / package / platform / lantiq / ltq-deu / src / ifxmips_deu_danube.c
1 /******************************************************************************
2 **
3 ** FILE NAME    : ifxmips_deu_danube.c
4 ** PROJECT      : IFX UEIP
5 ** MODULES      : DEU Module for Danube
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   \defgroup IFX_DEU IFX_DEU_DRIVERS
25   \ingroup API
26   \brief deu driver module
27 */
28
29 /*!
30   \file ifxmips_deu_danube.c
31   \ingroup IFX_DEU
32   \brief board specific deu driver file for danube
33 */
34
35 /*!
36   \defgroup BOARD_SPECIFIC_FUNCTIONS IFX_BOARD_SPECIFIC_FUNCTIONS
37   \ingroup IFX_DEU
38   \brief board specific deu functions
39 */
40
41 /* Project header files */
42 #include <linux/module.h>
43 #include <linux/init.h>
44 #include <linux/types.h>
45 #include <linux/errno.h>
46 #include <asm/io.h> //dma_cache_inv
47
48 #include "ifxmips_deu_dma.h"
49 #include "ifxmips_deu_danube.h"
50
51
52 /* Function Declerations */
53 int aes_memory_allocate(int value);
54 int des_memory_allocate(int value);
55 void memory_release(u32 *addr); 
56 int aes_chip_init (void);
57 void des_chip_init (void);
58 int deu_dma_init (void);
59 u32 endian_swap(u32 input);
60 u32* memory_alignment(const u8 *arg, u32 *buff_alloc, int in_out, int nbytes);
61 void dma_memory_copy(u32 *outcopy, u32 *out_dma, u8 *out_arg, int nbytes);
62 void chip_version(void); 
63 void deu_dma_priv_init(void);
64 void __exit ifxdeu_fini_dma(void);
65
66 #define DES_3DES_START  IFX_DES_CON
67 #define AES_START       IFX_AES_CON
68 #define CLC_START       IFX_DEU_CLK
69
70 /* Variables definition */
71 int ifx_danube_pre_1_4; 
72 u8 *g_dma_page_ptr = NULL;
73 u8 *g_dma_block = NULL;
74 u8 *g_dma_block2 = NULL;
75
76 deu_drv_priv_t deu_dma_priv;
77
78
79 /*! \fn u32 endian_swap(u32 input) 
80  *  \ingroup BOARD_SPECIFIC_FUNCTIONS
81  *  \brief function is not used
82  *  \param input Data input to be swapped
83  *  \return input
84 */
85
86 u32 endian_swap(u32 input)
87 {
88     return input;
89 }
90
91 /*! \fn u32 input_swap(u32 input)
92  *  \ingroup BOARD_SPECIFIC_FUNCTIONS
93  *  \brief Swap the input data if the current chip is Danube version
94  *         1.4 and do nothing to the data if the current chip is 
95  *         Danube version 1.3 
96  *  \param input data that needs to be swapped
97  *  \return input or swapped input
98 */
99
100 u32 input_swap(u32 input)
101 {
102     if (!ifx_danube_pre_1_4) {
103         u8 *ptr = (u8 *)&input;
104         return ((ptr[3] << 24) | (ptr[2] << 16) | (ptr[1] << 8) | ptr[0]); 
105     }
106     else 
107         return input;
108 }
109
110
111
112 /*! \fn void aes_chip_init (void)
113  *  \ingroup BOARD_SPECIFIC_FUNCTIONS
114  * \brief initialize AES hardware   
115 */
116
117 int aes_chip_init (void)
118 {
119     volatile struct aes_t *aes = (struct aes_t *) AES_START;
120
121     //start crypto engine with write to ILR
122     aes->controlr.SM = 1;
123     aes->controlr.ARS = 1;
124     return 0;
125 }
126
127 /*! \fn void des_chip_init (void)
128  *  \ingroup BOARD_SPECIFIC_FUNCTIONS
129  *  \brief initialize DES hardware
130 */  
131                         
132 void des_chip_init (void)
133 {
134         volatile struct des_t *des = (struct des_t *) DES_3DES_START;
135
136         // start crypto engine with write to ILR
137         des->controlr.SM = 1;
138         des->controlr.ARS = 1;
139 }
140
141 /*! \fn void chip_version (void)
142  *  \ingroup IFX_DES_FUNCTIONS
143  *  \brief To find the version of the chip by looking at the chip ID
144  *  \param ifx_danube_pre_1_4 (sets to 1 if Chip is Danube less than v1.4)
145 */  
146 #define IFX_MPS               (KSEG1 | 0x1F107000)
147 #define IFX_MPS_CHIPID                          ((volatile u32*)(IFX_MPS + 0x0344))
148
149 void chip_version(void) 
150 {
151
152     /* DANUBE PRE 1.4 SOFTWARE FIX */
153     int chip_id = 0;
154     chip_id = *IFX_MPS_CHIPID;
155     chip_id >>= 28;
156
157     if (chip_id >= 4) {
158         ifx_danube_pre_1_4 = 0;
159         printk("Danube Chip ver. 1.4 detected. \n");
160     }
161     else {
162         ifx_danube_pre_1_4 = 1; 
163         printk("Danube Chip ver. 1.3 or below detected. \n");
164     }
165
166     return;
167 }
168