ath79: do not build TP-Link tiny images by default
[oweals/openwrt.git] / package / kernel / lantiq / ltq-atm / src / ifxmips_atm_vr9.c
1 /******************************************************************************
2 **
3 ** FILE NAME    : ifxmips_atm_vr9.c
4 ** PROJECT      : UEIP
5 ** MODULES      : ATM
6 **
7 ** DATE         : 7 Jul 2009
8 ** AUTHOR       : Xu Liang
9 ** DESCRIPTION  : ATM driver common source file (core functions)
10 ** COPYRIGHT    :       Copyright (c) 2006
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 ** 07 JUL 2009  Xu Liang        Init Version
22 *******************************************************************************/
23
24
25
26 /*
27  * ####################################
28  *              Head File
29  * ####################################
30  */
31
32 /*
33  *  Common Head File
34  */
35 #include <linux/kernel.h>
36 #include <linux/module.h>
37 #include <linux/version.h>
38 #include <linux/types.h>
39 #include <linux/errno.h>
40 #include <linux/proc_fs.h>
41 #include <linux/init.h>
42 #include <linux/ioctl.h>
43 #include <linux/platform_device.h>
44 #include <linux/reset.h>
45 #include <asm/delay.h>
46
47 #include "ifxmips_atm_core.h"
48 #include "ifxmips_atm_fw_vr9.h"
49
50 #ifdef CONFIG_VR9
51
52 #include <lantiq_soc.h>
53
54 #define IFX_PMU_MODULE_PPE_SLL01  BIT(19)
55 #define IFX_PMU_MODULE_PPE_TC     BIT(21)
56 #define IFX_PMU_MODULE_PPE_EMA    BIT(22)
57 #define IFX_PMU_MODULE_PPE_QSB    BIT(18)
58 #define IFX_PMU_MODULE_AHBS       BIT(13)
59 #define IFX_PMU_MODULE_DSL_DFE    BIT(9)
60
61 static inline void vr9_reset_ppe(struct platform_device *pdev)
62 {
63         struct device *dev = &pdev->dev;
64         struct reset_control *dsp;
65         struct reset_control *dfe;
66         struct reset_control *tc;
67
68         dsp = devm_reset_control_get(dev, "dsp");
69         if (IS_ERR(dsp)) {
70                 if (PTR_ERR(dsp) != -EPROBE_DEFER)
71                         dev_err(dev, "Failed to lookup dsp reset\n");
72 //              return PTR_ERR(dsp);
73         }
74
75         dfe = devm_reset_control_get(dev, "dfe");
76         if (IS_ERR(dfe)) {
77                 if (PTR_ERR(dfe) != -EPROBE_DEFER)
78                         dev_err(dev, "Failed to lookup dfe reset\n");
79 //              return PTR_ERR(dfe);
80         }
81
82         tc = devm_reset_control_get(dev, "tc");
83         if (IS_ERR(tc)) {
84                 if (PTR_ERR(tc) != -EPROBE_DEFER)
85                         dev_err(dev, "Failed to lookup tc reset\n");
86 //              return PTR_ERR(tc);
87         }
88
89         reset_control_assert(dsp);
90         udelay(1000);
91         reset_control_assert(dfe);
92         udelay(1000);
93         reset_control_assert(tc);
94         udelay(1000);
95         *PP32_SRST &= ~0x000303CF;
96         udelay(1000);
97         *PP32_SRST |= 0x000303CF;
98         udelay(1000);
99 }
100
101 static inline int vr9_pp32_download_code(int pp32, u32 *code_src, unsigned int code_dword_len, u32 *data_src, unsigned int data_dword_len)
102 {
103         unsigned int clr, set;
104         volatile u32 *dest;
105
106         if ( code_src == 0 || ((unsigned long)code_src & 0x03) != 0
107                         || data_src == 0 || ((unsigned long)data_src & 0x03) != 0 )
108                 return -1;
109
110         clr = pp32 ? 0xF0 : 0x0F;
111         if ( code_dword_len <= CDM_CODE_MEMORYn_DWLEN(0) )
112                 set = pp32 ? (3 << 6): (2 << 2);
113         else
114                 set = 0x00;
115         IFX_REG_W32_MASK(clr, set, CDM_CFG);
116
117         dest = CDM_CODE_MEMORY(pp32, 0);
118         while ( code_dword_len-- > 0 )
119                 IFX_REG_W32(*code_src++, dest++);
120
121         dest = CDM_DATA_MEMORY(pp32, 0);
122         while ( data_dword_len-- > 0 )
123                 IFX_REG_W32(*data_src++, dest++);
124
125         return 0;
126 }
127
128 static void vr9_fw_ver(unsigned int *major, unsigned int *minor)
129 {
130
131     *major = FW_VER_ID->major;
132     *minor = FW_VER_ID->minor;
133 }
134
135 static void vr9_init(struct platform_device *pdev)
136 {
137         volatile u32 *p;
138         unsigned int i;
139
140         /* setup pmu */
141         ltq_pmu_enable(IFX_PMU_MODULE_PPE_SLL01 |
142                 IFX_PMU_MODULE_PPE_TC |
143                 IFX_PMU_MODULE_PPE_EMA |
144                 IFX_PMU_MODULE_PPE_QSB |
145                 IFX_PMU_MODULE_AHBS |
146                 IFX_PMU_MODULE_DSL_DFE);
147
148         vr9_reset_ppe(pdev);
149
150         /* pdma init */
151         IFX_REG_W32(0x08,       PDMA_CFG);
152         IFX_REG_W32(0x00203580, SAR_PDMA_RX_CMDBUF_CFG);
153         IFX_REG_W32(0x004035A0, SAR_PDMA_RX_FW_CMDBUF_CFG);
154
155         /* mailbox init */
156         IFX_REG_W32(0xFFFFFFFF, MBOX_IGU1_ISRC);
157         IFX_REG_W32(0x00000000, MBOX_IGU1_IER);
158         IFX_REG_W32(0xFFFFFFFF, MBOX_IGU3_ISRC);
159         IFX_REG_W32(0x00000000, MBOX_IGU3_IER);
160
161         /* tc init - clear sync state */
162         *SFSM_STATE0 = 0;
163         *SFSM_STATE1 = 0;
164
165         /* init shared buffer */
166         p = SB_RAM0_ADDR(0);
167         for ( i = 0; i < SB_RAM0_DWLEN + SB_RAM1_DWLEN + SB_RAM2_DWLEN + SB_RAM3_DWLEN; i++ )
168                 IFX_REG_W32(0, p++);
169
170         p = SB_RAM6_ADDR(0);
171         for ( i = 0; i < SB_RAM6_DWLEN; i++ )
172                 IFX_REG_W32(0, p++);
173 }
174
175 static void vr9_shutdown(void)
176 {
177 }
178
179 static int vr9_start(int pp32)
180 {
181         unsigned int mask = 1 << (pp32 << 4);
182         int ret;
183
184         /*  download firmware   */
185         ret = vr9_pp32_download_code(pp32,
186                 vr9_fw_bin, sizeof(vr9_fw_bin) / sizeof(*vr9_fw_bin),
187                 vr9_fw_data, sizeof(vr9_fw_data) / sizeof(*vr9_fw_data));
188         if ( ret != 0 )
189                 return ret;
190
191         /*  run PP32    */
192         IFX_REG_W32_MASK(mask, 0, PP32_FREEZE);
193
194         /*  idle for a while to let PP32 init itself    */
195         udelay(10);
196
197         return 0;
198 }
199
200 static void vr9_stop(int pp32)
201 {
202         unsigned int mask = 1 << (pp32 << 4);
203
204         IFX_REG_W32_MASK(0, mask, PP32_FREEZE);
205 }
206
207 struct ltq_atm_ops vr9_ops = {
208         .init = vr9_init,
209         .shutdown = vr9_shutdown,
210         .start = vr9_start,
211         .stop = vr9_stop,
212         .fw_ver = vr9_fw_ver,
213 };
214
215 #endif