annotate target-utils/c139explore/uwire.c @ 1006:6e1fcffd3266

gsm-fw/riviera/rvt channel addition: missed the bit in rvt_task.c
author Mychaela Falconia <falcon@ivan.Harhan.ORG>
date Sun, 20 Mar 2016 18:58:07 +0000
parents 15b1b396ad23
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
950
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
1 /* Driver for uWire Master Controller inside TI Calypso */
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
2 /* lifted from OsmocomBB and ported to FreeCalypso target-utils environment */
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
3
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
4 /* (C) 2010 by Sylvain Munaut <tnt@246tNt.com>
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
5 *
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
6 * All Rights Reserved
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
7 *
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
11 * (at your option) any later version.
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
12 *
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful,
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
16 * GNU General Public License for more details.
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
17 *
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License along
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
19 * with this program; if not, write to the Free Software Foundation, Inc.,
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
21 *
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
22 */
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
23
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
24 #include "types.h"
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
25
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
26 struct uwire_regs {
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
27 u16 reg_data;
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
28 u16 reg_csr;
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
29 u16 reg_sr1;
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
30 u16 reg_sr2;
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
31 u16 reg_sr3;
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
32 };
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
33
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
34 #define UWIRE_REGS (*(volatile struct uwire_regs *) 0xFFFE4000)
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
35
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
36 #define UWIRE_CSR_BITS_RD(n) (((n) & 0x1f) << 0)
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
37 #define UWIRE_CSR_BITS_WR(n) (((n) & 0x1f) << 5)
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
38 #define UWIRE_CSR_IDX(n) (((n) & 3) << 10)
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
39 #define UWIRE_CSR_CS_CMD (1 << 12)
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
40 #define UWIRE_CSR_START (1 << 13)
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
41 #define UWIRE_CSR_CSRB (1 << 14)
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
42 #define UWIRE_CSR_RDRB (1 << 15)
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
43
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
44 #define UWIRE_CSn_EDGE_RD (1 << 0) /* 1=falling 0=rising */
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
45 #define UWIRE_CSn_EDGE_WR (1 << 1) /* 1=falling 0=rising */
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
46 #define UWIRE_CSn_CS_LVL (1 << 2)
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
47 #define UWIRE_CSn_FRQ_DIV2 (0 << 3)
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
48 #define UWIRE_CSn_FRQ_DIV4 (1 << 3)
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
49 #define UWIRE_CSn_FRQ_DIV8 (2 << 3)
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
50 #define UWIRE_CSn_CKH
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
51
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
52 #define UWIRE_CSn_SHIFT(n) (((n) & 1) ? 6 : 0)
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
53 #define UWIRE_CSn_REG(n) (((n) & 2) ? REG_SR2 : REG_SR1)
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
54
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
55 #define UWIRE_SR3_CLK_EN (1 << 0)
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
56 #define UWIRE_SR3_CLK_DIV2 (0 << 1)
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
57 #define UWIRE_SR3_CLK_DIV4 (1 << 1)
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
58 #define UWIRE_SR3_CLK_DIV7 (2 << 1)
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
59 #define UWIRE_SR3_CLK_DIV10 (3 << 1)
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
60
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
61 static inline void _uwire_wait(int mask, int val)
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
62 {
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
63 while ((UWIRE_REGS.reg_csr & mask) != val);
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
64 }
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
65
952
15b1b396ad23 c139explore: OsmocomBB morons got uwire wrong, TI got it right
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents: 950
diff changeset
66 /*
15b1b396ad23 c139explore: OsmocomBB morons got uwire wrong, TI got it right
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents: 950
diff changeset
67 * Let's try changing the chip select logic from OsmocomBB way
15b1b396ad23 c139explore: OsmocomBB morons got uwire wrong, TI got it right
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents: 950
diff changeset
68 * to the way seen in TI's R2D source.
15b1b396ad23 c139explore: OsmocomBB morons got uwire wrong, TI got it right
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents: 950
diff changeset
69 */
15b1b396ad23 c139explore: OsmocomBB morons got uwire wrong, TI got it right
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents: 950
diff changeset
70
950
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
71 void uwire_init(void)
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
72 {
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
73 UWIRE_REGS.reg_sr3 = UWIRE_SR3_CLK_EN | UWIRE_SR3_CLK_DIV2;
952
15b1b396ad23 c139explore: OsmocomBB morons got uwire wrong, TI got it right
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents: 950
diff changeset
74 UWIRE_REGS.reg_sr1 = UWIRE_CSn_FRQ_DIV2;
15b1b396ad23 c139explore: OsmocomBB morons got uwire wrong, TI got it right
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents: 950
diff changeset
75 #if 0
950
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
76 UWIRE_REGS.reg_sr1 = UWIRE_CSn_CS_LVL | UWIRE_CSn_FRQ_DIV2;
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
77 UWIRE_REGS.reg_csr = UWIRE_CSR_IDX(0) | UWIRE_CSR_CS_CMD;
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
78 _uwire_wait(UWIRE_CSR_CSRB, 0);
952
15b1b396ad23 c139explore: OsmocomBB morons got uwire wrong, TI got it right
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents: 950
diff changeset
79 #endif
950
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
80 }
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
81
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
82 send_via_uwire(word)
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
83 unsigned word;
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
84 {
952
15b1b396ad23 c139explore: OsmocomBB morons got uwire wrong, TI got it right
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents: 950
diff changeset
85 #if 0
950
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
86 /* select the chip */
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
87 UWIRE_REGS.reg_csr = UWIRE_CSR_IDX(0) | UWIRE_CSR_CS_CMD;
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
88 _uwire_wait(UWIRE_CSR_CSRB, 0);
952
15b1b396ad23 c139explore: OsmocomBB morons got uwire wrong, TI got it right
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents: 950
diff changeset
89 #endif
950
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
90
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
91 UWIRE_REGS.reg_data = word << 7;
952
15b1b396ad23 c139explore: OsmocomBB morons got uwire wrong, TI got it right
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents: 950
diff changeset
92 UWIRE_REGS.reg_csr = UWIRE_CSR_BITS_WR(9) | UWIRE_CSR_START
15b1b396ad23 c139explore: OsmocomBB morons got uwire wrong, TI got it right
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents: 950
diff changeset
93 | UWIRE_CSR_CS_CMD;
950
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
94 _uwire_wait(UWIRE_CSR_CSRB, 0);
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
95
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
96 /* unselect the chip */
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
97 UWIRE_REGS.reg_csr = UWIRE_CSR_IDX(0) | 0;
952
15b1b396ad23 c139explore: OsmocomBB morons got uwire wrong, TI got it right
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents: 950
diff changeset
98 #if 0
950
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
99 _uwire_wait(UWIRE_CSR_CSRB, 0);
952
15b1b396ad23 c139explore: OsmocomBB morons got uwire wrong, TI got it right
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents: 950
diff changeset
100 #endif
950
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
101
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
102 return 0;
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
103 }