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