1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2014 by Cástor Muñoz
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include <stdint.h>
#include <stdbool.h>
#include "config.h"
#include "system.h"
#include "s5l8700.h"
#include "uc87xx.h"
/*
* s5l8701 UC87XX HW: 3 UARTC, 1 port per UARTC
*/
static struct uartc_port *uartc0_port_l[UARTC0_N_PORTS];
const struct uartc s5l8701_uartc0 =
{
.id = 0,
.baddr = UARTC0_BASE_ADDR,
.port_off = UARTC0_PORT_OFFSET,
.n_ports = UARTC0_N_PORTS,
.port_l = uartc0_port_l,
};
/* UARTC1,2 not used on Nano2G */
#ifndef IPOD_NANO2G
static struct uartc_port *uartc1_port_l[UARTC1_N_PORTS];
const struct uartc s5l8701_uartc1 =
{
.id = 1,
.baddr = UARTC1_BASE_ADDR,
.port_off = UARTC1_PORT_OFFSET,
.n_ports = UARTC1_N_PORTS,
.port_l = uartc1_port_l,
};
static struct uartc_port *uartc2_port_l[UARTC2_N_PORTS];
const struct uartc s5l8701_uartc2 =
{
.id = 2,
.baddr = UARTC2_BASE_ADDR,
.port_off = UARTC2_PORT_OFFSET,
.n_ports = UARTC2_N_PORTS,
.port_l = uartc2_port_l,
};
#endif
static uint8_t clockgate_uartc[S5L8701_N_UARTC] = {
CLOCKGATE_UARTC0, CLOCKGATE_UARTC1, CLOCKGATE_UARTC2 };
static int intmsk_uart[S5L8701_N_UARTC] = {
INTMSK_EINTG0, INTMSK_UART1, INTMSK_UART2 };
/*
* Device level functions specific to S5L8701
*/
void uart_target_enable_gpio(int uart_id, int port_id)
{
(void) port_id;
switch (uart_id) {
/* configure UARTx Tx/Rx GPIO ports */
case 0:
PCON1 = (PCON1 & 0xffffff00) | 0x00000044;
break;
case 1:
case 2:
/* unknown */
default:
break;
}
}
void uart_target_disable_gpio(int uart_id, int port_id)
{
(void) port_id;
switch (uart_id) {
/* configure minimal power consumption */
case 0:
PCON1 = (PCON1 & 0xffffff00) | 0x00000011;
break;
case 1:
case 2:
default:
break;
}
}
void uart_target_enable_irq(int uart_id, int port_id)
{
(void) port_id;
if (uart_id == 0) GPIOIC_INTEN(0) = 0x200;
INTMSK |= intmsk_uart[uart_id];
}
void uart_target_disable_irq(int uart_id, int port_id)
{
(void) port_id;
INTMSK &= ~intmsk_uart[uart_id];
if (uart_id == 0) GPIOIC_INTEN(0) = 0;
}
void uart_target_clear_irq(int uart_id, int port_id)
{
(void) port_id;
if (uart_id == 0) GPIOIC_INTSTAT(0) = 0x200;
SRCPND |= intmsk_uart[uart_id];
}
void uart_target_enable_clocks(int uart_id)
{
PWRCON &= ~(1 << clockgate_uartc[uart_id]);
}
void uart_target_disable_clocks(int uart_id)
{
PWRCON |= (1 << clockgate_uartc[uart_id]);
}
/*
* ISRs
*/
/* On Nano2G, PORT0 interrupts are not used when iAP is disabled */
#if !defined(IPOD_NANO2G) || defined(IPOD_ACCESSORY_PROTOCOL)
/*
* UART0 IRQ is connected to EINTG0, this is a quick patch, a "real"
* EINT handler will be needed if in future we use more than one IRQ
* on this group.
*/
void ICODE_ATTR EINT_G0(void)
{
GPIOIC_INTSTAT(0) = 0x200; /* clear external IRQ */
uartc_callback(&s5l8701_uartc0, 0);
}
#endif
/* UARTC1,2 not used on Nano2G */
#ifndef IPOD_NANO2G
void ICODE_ATTR INT_UART1(void)
{
uartc_callback(&s5l8701_uartc1, 0);
}
void ICODE_ATTR INT_UART2(void)
{
uartc_callback(&s5l8701_uartc2, 0);
}
#endif
/* Main init */
void uart_init(void)
{
uartc_open(&s5l8701_uartc0);
}
|