Initial import of OsmocomBB into git repository
[osmocom-bb.git] / src / target / firmware / include / abb / twl3025.h
1 #ifndef _TWL3025_H
2 #define _TWL3025_H
3
4 #define PAGE(n)         (n << 7)
5 enum twl3025_reg {
6         VRPCCFG         = PAGE(1) | 30,
7         VRPCDEV         = PAGE(0) | 30,
8         VRPCMSK         = PAGE(1) | 31,
9         VRPCMSKABB      = PAGE(1) | 29,
10         VRPCSTS         = PAGE(0) | 31,
11         /* Monitoring ADC Registers */
12         MADCTRL         = PAGE(0) | 13,
13         MADCSTAT        = PAGE(0) | 24,
14         VBATREG         = PAGE(0) | 15,
15         VCHGREG         = PAGE(0) | 16,
16         ICHGREG         = PAGE(0) | 17,
17         VBKPREG         = PAGE(0) | 18,
18         ADIN1REG        = PAGE(0) | 19,
19         ADIN2REG        = PAGE(0) | 20,
20         ADIN3REG        = PAGE(0) | 21,
21         ADIN4REG        = PAGE(0) | 22,
22         /* Clock Generator Registers */
23         TOGBR1          = PAGE(0) | 4,
24         TOGBR2          = PAGE(0) | 5,
25         PWDNRG          = PAGE(1) | 9,
26         TAPCTRL         = PAGE(1) | 19,
27         TAPREG          = PAGE(1) | 20,
28         /* Automatic Frequency Control (AFC) Registers */
29         AUXAFC1         = PAGE(0) | 7,
30         AUXAFC2         = PAGE(0) | 8,
31         AFCCTLADD       = PAGE(1) | 21,
32         AFCOUT          = PAGE(1) | 22,
33         /* Automatic Power Control (APC) Registers */
34         APCDEL1         = PAGE(0) | 2,
35         APCDEL2         = PAGE(1) | 26,
36         AUXAPC          = PAGE(0) | 9,
37         APCRAM          = PAGE(0) | 10,
38         APCOFF          = PAGE(0) | 11,
39         APCOUT          = PAGE(1) | 12,
40         /* Auxiliary DAC Control Register */
41         AUXDAC          = PAGE(0) | 12,
42         /* SimCard Control Register */
43         VRPCSIM         = PAGE(1) | 23,
44         /* LED Driver Register */
45         AUXLED          = PAGE(1) | 24,
46         /* Battery Charger Interface (BCI) Registers */
47         CHGREG          = PAGE(0) | 25,
48         BCICTL1         = PAGE(0) | 28,
49         BCICTL2         = PAGE(0) | 29,
50         BCICONF         = PAGE(1) | 13,
51         /* Interrupt and Bus Control (IBIC) Registers */
52         ITMASK          = PAGE(0) | 28,
53         ITSTATREG       = PAGE(0) | 27, /* both pages! */
54         PAGEREG         = PAGE(0) | 1,  /* both pages! */
55         /* Baseband Codec (BBC) Registers */
56         BULIOFF         = PAGE(1) | 2,
57         BULQOFF         = PAGE(1) | 3,
58         BULIDAC         = PAGE(1) | 5,
59         BULQDAC         = PAGE(1) | 4,
60         BULGCAL         = PAGE(1) | 14,
61         BULDATA1        = PAGE(0) | 3,  /* 16 words */
62         BBCTRL          = PAGE(1) | 6,
63         /* Voiceband Codec (VBC) Registers */
64         VBCTRL1         = PAGE(1) | 8,
65         VBCTRL2         = PAGE(1) | 11,
66         VBPOP           = PAGE(1) | 10,
67         VBUCTRL         = PAGE(1) | 7,
68         VBDCTRL         = PAGE(0) | 6,
69 };
70 #define BULDATA2        BULDATA1
71
72 enum togbr2_bits {
73         TOGBR2_KEEPR    = (1 << 0),     /* Clear KEEPON bit */
74         TOGBR2_KEEPS    = (1 << 1),     /* Set KEEPON bit */
75         TOGBR2_ACTR     = (1 << 2),     /* Dectivate MCLK */
76         TOGBR2_ACTS     = (1 << 3),     /* Activate MCLK */
77         TOGBR2_IBUFPTR1 = (1 << 4),     /* Initialize pointer of burst buffer 1 */
78         TOGBR2_IBUFPTR2 = (1 << 5),     /* Initialize pointer of burst buffer 2 */
79         TOGBR2_IAPCPTR  = (1 << 6),     /* Initialize pointer of APC RAM */
80 };
81
82 enum twl3025_unit {
83         TWL3025_UNIT_AFC,
84         TWL3025_UNIT_MAD,
85         TWL3025_UNIT_ADA,
86         TWL3025_UNIT_VDL,
87         TWL3025_UNIT_VUL,
88 };
89
90 void twl3025_init(void);
91 void twl3025_reg_write(uint8_t reg, uint16_t data);
92 uint16_t twl3025_reg_read(uint8_t reg);
93
94 void twl3025_power_off(void);
95
96 void twl3025_clk13m(int enable);
97
98 void twl3025_unit_enable(enum twl3025_unit unit, int on);
99
100 enum twl3025_tsp_bits {
101         BULON           = 0x80,
102         BULCAL          = 0x40,
103         BULENA          = 0x20,
104         BDLON           = 0x10,
105         BDLCAL          = 0x08,
106         BDLENA          = 0x04,
107         STARTADC        = 0x02,
108 };
109
110 /* Enqueue a TSP signal change via the TPU */
111 void twl3025_tsp_write(uint8_t data);
112
113 /* Enqueue a series of TSP commands in the TPU to (de)activate the downlink path */
114 void twl3025_downlink(int on, int16_t at);
115
116 /* Update the AFC DAC value */
117 void twl3025_afc_set(int16_t val);
118
119 /* Get the AFC DAC value */
120 int16_t twl3025_afc_get(void);
121
122 /* Get the AFC DAC output value */
123 uint8_t twl3025_afcout_get(void);
124
125 /* Force a certain static AFC DAC output value */
126 void twl3025_afcout_set(uint8_t val);
127
128 #endif