c00d09fb8b06153011dd4be41880571e4953e305
[osmocom-bb.git] / src / target / firmware / layer1 / init.c
1 /* OsmocomBB Layer1 initialization */
2
3 /* (C) 2010 by Harald Welte <laforge@gnumonks.org>
4  *
5  * All Rights Reserved
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  */
22
23
24 #include <stdint.h>
25 #include <stdio.h>
26
27 #include <rffe.h>
28 #include <rf/trf6151.h>
29 #include <abb/twl3025.h>
30 #include <calypso/tpu.h>
31 #include <calypso/tsp.h>
32 #include <calypso/dsp.h>
33 #include <calypso/irq.h>
34
35 #include <layer1/sync.h>
36 #include <layer1/async.h>
37 #include <layer1/l23_api.h>
38
39 void layer1_init(void)
40 {
41         struct msgb *msg;
42         struct l1ctl_reset *res;
43
44 #ifndef CONFIG_TX_ENABLE
45         printf("\n\nTHIS FIRMWARE WAS COMPILED WITHOUT TX SUPPORT!!!\n\n");
46 #endif
47
48         /* initialize asynchronous part of L1 */
49         l1a_init();
50         /* initialize TDMA Frame IRQ driven synchronous L1 */
51         l1s_init();
52         /* power up the DSP */
53         dsp_power_on();
54
55         /* Initialize TPU, TSP and TRF drivers */
56         tpu_init();
57         tsp_init();
58         trf6151_init();
59
60         rffe_init();
61
62 #if 0 /* only if RX TPU window is disabled! */
63         /* Put TWL3025 in downlink mode (includes calibration) */
64         twl3025_downlink(1, 1000);
65 #endif
66
67         /* issue the TRF and TWL initialization sequence */
68         tpu_enq_sleep();
69         tpu_enable(1);
70         tpu_wait_idle();
71
72         /* Disable RTC interrupt as it causes lost TDMA frames */
73         irq_disable(IRQ_RTC_TIMER);
74
75         /* inform l2 and upwards that we are ready for orders */
76         msg = l1_create_l2_msg(L1CTL_RESET_IND, 0, 0, 0);
77         res = msgb_put(msg, sizeof(*res));
78         res->type = L1CTL_RES_T_BOOT;
79         l1_queue_for_l2(msg);
80 }