annotate target-utils/c139explore/uwire.c @ 950:cd34e0d534b9

c139explore: LCD output implemented, does not work
author Mychaela Falconia <falcon@ivan.Harhan.ORG>
date Wed, 04 Nov 2015 01:43:44 +0000
parents
children 15b1b396ad23
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
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
66 void uwire_init(void)
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
67 {
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
68 UWIRE_REGS.reg_sr3 = UWIRE_SR3_CLK_EN | UWIRE_SR3_CLK_DIV2;
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
69 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
70 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
71 _uwire_wait(UWIRE_CSR_CSRB, 0);
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
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
74 send_via_uwire(word)
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
75 unsigned word;
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
76 {
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
77 u16 tmp = 0;
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
78
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
79 /* select the chip */
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
80 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
81 _uwire_wait(UWIRE_CSR_CSRB, 0);
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
82
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
83 UWIRE_REGS.reg_data = word << 7;
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
84 UWIRE_REGS.reg_csr = UWIRE_CSR_BITS_WR(9) | UWIRE_CSR_START;
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
85 _uwire_wait(UWIRE_CSR_CSRB, 0);
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
86
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
87 /* unselect the chip */
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
88 UWIRE_REGS.reg_csr = UWIRE_CSR_IDX(0) | 0;
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
89 _uwire_wait(UWIRE_CSR_CSRB, 0);
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 return 0;
cd34e0d534b9 c139explore: LCD output implemented, does not work
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff changeset
92 }