summaryrefslogtreecommitdiffstats
path: root/firmware/target/arm/s5l8702/uart-s5l8702.c
blob: 9d8faaa173064a93dadda20f28326e78996c152e (plain)
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
/***************************************************************************
 *             __________               __   ___.
 *   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 "cpu.h"
#include "system.h"

#include "s5l8702.h"
#include "uc870x.h"


/*
 * s5l8702 UC870X HW: 1 UARTC, 4 ports
 */
static struct uartc_port *uartc_port_l[UARTC_N_PORTS];
const struct uartc s5l8702_uartc =
{
    .id       = 0,
    .baddr    = UARTC_BASE_ADDR,
    .port_off = UARTC_PORT_OFFSET,
    .n_ports  = UARTC_N_PORTS,
    .port_l   = uartc_port_l,
};

/*
 * Device level functions specific to S5L8702
 */
void uart_target_enable_gpio(int uart_id, int port_id)
{
    (void) uart_id;
    switch (port_id) {
        case 0:
            /* configure UART0 Tx/Rx GPIO ports */
            PCON0 = (PCON0 & 0xff00ffff) | 0x00220000;
            break;
        case 1:
            /* configure UART1 GPIO ports, including RTS/CTS signals */
            PCOND = (PCOND & 0xff0000ff) | 0x00222200;
            break;
        case 2:
        case 3:
            /* unknown */
        default:
            break;
    }
}

void uart_target_disable_gpio(int uart_id, int port_id)
{
    (void) uart_id;
    switch (port_id) {
        /* configure minimal power consumption */
        case 0:
            PCON0 = (PCON0 & 0xff00ffff) | 0x00ee0000;
            break;
        case 1:
            PCOND = (PCOND & 0xff0000ff) | 0x00eeee00;
            break;
        case 2:
        case 3:
        default:
            break;
    }
}

void uart_target_enable_irq(int uart_id, int port_id)
{
    (void) uart_id;
    VIC0INTENABLE = 1 << IRQ_UART(port_id);
}

void uart_target_disable_irq(int uart_id, int port_id)
{
    (void) uart_id;
    VIC0INTENCLEAR = 1 << IRQ_UART(port_id);
}

void uart_target_clear_irq(int uart_id, int port_id)
{
    (void) uart_id;
    (void) port_id;
}

void uart_target_enable_clocks(int uart_id)
{
    (void) uart_id;
    PWRCON(1) &= ~(1 << (CLOCKGATE_UARTC - 32));
}

void uart_target_disable_clocks(int uart_id)
{
    (void) uart_id;
    PWRCON(1) |= (1 << (CLOCKGATE_UARTC - 32));
}

/*
 * ISRs
 */

/* On Classic, PORT0 interrupts are not used when iAP is disabled */
#if !defined(IPOD_6G) || defined(IPOD_ACCESSORY_PROTOCOL)
void ICODE_ATTR INT_UART0(void)
{
    uartc_callback(&s5l8702_uartc, 0);
}
#endif

/* PORT1,2,3 not used on Classic */
#ifndef IPOD_6G
void ICODE_ATTR INT_UART1(void)
{
    uartc_callback(&s5l8702_uartc, 1);
}

void ICODE_ATTR INT_UART2(void)
{
    uartc_callback(&s5l8702_uartc, 2);
}

void ICODE_ATTR INT_UART3(void)
{
    uartc_callback(&s5l8702_uartc, 3);
}
#endif

/* Main init */
void uart_init(void)
{
    uartc_open(&s5l8702_uartc);
}