FreeCalypso > hg > freecalypso-sw
annotate target-utils/libcommon/abbdrv.c @ 413:1ed2d78f150c
loadtools: boot-reflash-hack hwparam setting hooked in
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Tue, 17 Jun 2014 05:11:25 +0000 |
parents | 6661e5bc0712 |
children |
rev | line source |
---|---|
389
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 /* Driver for Analog Baseband Circuit (TWL3025) */ |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 /* lifted from OsmocomBB and ported to FreeCalypso target-utils environment */ |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 /* (C) 2010 by Harald Welte <laforge@gnumonks.org> |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 * |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 * All Rights Reserved |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 * |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 * This program is free software; you can redistribute it and/or modify |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 * it under the terms of the GNU General Public License as published by |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 * the Free Software Foundation; either version 2 of the License, or |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 * (at your option) any later version. |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
12 * |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
16 * GNU General Public License for more details. |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
17 * |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
18 * You should have received a copy of the GNU General Public License along |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
19 * with this program; if not, write to the Free Software Foundation, Inc., |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
21 * |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
22 */ |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
23 |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
24 #include "types.h" |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
25 #include "abbdefs.h" |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
26 |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 /* TWL3025 */ |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
28 #define REG_PAGE(n) ((n) >> 7) |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
29 #define REG_ADDR(n) ((n) & 0x1f) |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
30 |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
31 #define TWL3025_DEV_IDX 0 /* On the SPI bus */ |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 #define TWL3025_TSP_DEV_IDX 0 /* On the TSP bus */ |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
33 |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
34 int abb_state_initdone, abb_state_page; |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
35 |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
36 void |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
37 abb_reg_write(reg, data) |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
38 { |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
39 u16 tx; |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
40 |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
41 if (reg != PAGEREG && REG_PAGE(reg) != abb_state_page) |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
42 abb_select_page(REG_PAGE(reg)); |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
43 |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
44 tx = ((data & 0x3ff) << 6) | (REG_ADDR(reg) << 1); |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
45 |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
46 spi_xfer(TWL3025_DEV_IDX, 16, &tx, 0); |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
47 } |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
48 |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
49 u16 |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
50 abb_reg_read(reg) |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
51 { |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
52 u16 tx, rx; |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
53 |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
54 if (REG_PAGE(reg) != abb_state_page) |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
55 abb_select_page(REG_PAGE(reg)); |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
56 |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
57 tx = (REG_ADDR(reg) << 1) | 1; |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
58 |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
59 /* A read cycle contains two SPI transfers */ |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
60 spi_xfer(TWL3025_DEV_IDX, 16, &tx, &rx); |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
61 osmo_delay_ms(1); |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
62 spi_xfer(TWL3025_DEV_IDX, 16, &tx, &rx); |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
63 |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
64 rx >>= 6; |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
65 |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
66 return rx; |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
67 } |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
68 |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
69 /* Switch the register page of the TWL3025 */ |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
70 abb_select_page(page) |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
71 { |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
72 if (page == 0) |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
73 abb_reg_write(PAGEREG, 1 << 0); |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
74 else |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
75 abb_reg_write(PAGEREG, 1 << 1); |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
76 abb_state_page = page; |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
77 return(0); |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
78 } |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
79 |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
80 abb_init() |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
81 { |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
82 if (abb_state_initdone) |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
83 return(0); |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
84 spi_init(); |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
85 abb_select_page(0); |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
86 /* CLK13M enable */ |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
87 abb_reg_write(TOGBR2, TOGBR2_ACTS); |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
88 osmo_delay_ms(1); |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
89 /* for whatever reason we need to do this twice */ |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
90 abb_reg_write(TOGBR2, TOGBR2_ACTS); |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
91 osmo_delay_ms(1); |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
92 abb_state_initdone = 1; |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
93 return(1); |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
94 } |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
95 |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
96 void |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
97 abb_power_off() |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
98 { |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
99 abb_init(); |
394
6661e5bc0712
target-utils: flush serial output before Iota poweroff
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
389
diff
changeset
|
100 serial_flush(); |
389
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
101 abb_reg_write(VRPCDEV, 0x01); |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
102 } |