summaryrefslogtreecommitdiffstats
path: root/firmware/target/arm/s5l8700/uart-s5l8700.c
blob: da22066f5c41a64ef5b7c19dbee3861990154e87 (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
/***************************************************************************
 *             __________               __   ___.
 *   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 "s5l87xx.h"
#include "uc87xx.h"


/*
 * XXX: This code is based on datasheets and NEVER TESTED !!!
 */


/*
 * s5l8700 UC87XX HW: 1 UARTC, 2 ports
 */
static struct uartc_port *uartc_port_l[UARTC_N_PORTS];
const struct uartc s5l8700_uartc =
{
    .id       = 0,
    .baddr    = UARTC_BASE_ADDR,
    .port_off = UARTC_PORT_OFFSET,
    .n_ports  = UARTC_N_PORTS,
    .port_l   = uartc_port_l,
};

static int intmsk_uart[S5L8700_N_PORTS] = { INTMSK_UART0, INTMSK_UART1 };

/*
 * Device level functions specific to S5L8700
 */
void uart_target_enable_gpio(int uart_id, int port_id)
{
    (void) uart_id;
    switch (port_id) {
        /* configure UARTx Tx/Rx GPIO ports */
        case 0:
            PCON0 = (PCON0 & 0x0fff) | 0xa000;
            break;
        case 1:
            PCON6 = (PCON6 & 0xfff00fff) | 0x00044000;
            break;
    }
}

void uart_target_disable_gpio(int uart_id, int port_id)
{
    (void) uart_id;
    switch (port_id) {
        /* configure default reset values */
        case 0:
            PCON0 = (PCON0 & 0x0fff) | 0x0000;
            break;
        case 1:
            PCON6 = (PCON6 & 0xfff00fff) | 0x00000000;
            break;
    }
}

void uart_target_enable_irq(int uart_id, int port_id)
{
    (void) uart_id;
    INTMSK |= intmsk_uart[port_id];
}

void uart_target_disable_irq(int uart_id, int port_id)
{
    (void) uart_id;
    INTMSK &= ~intmsk_uart[port_id];
}

void uart_target_clear_irq(int uart_id, int port_id)
{
    (void) uart_id;
    SRCPND |= intmsk_uart[port_id];
}

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

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

/*
 * ISRs
 */
void ICODE_ATTR INT_UART0(void)
{
    uartc_callback(&s5l8700_uartc, 0);
}

void ICODE_ATTR INT_UART1(void)
{
    uartc_callback(&s5l8700_uartc, 1);
}

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