blob: 46ef2eb1148d17e3d0547679a2d1e5a1ffd9a1a9 [file] [log] [blame]
huang lind5fb66e2014-08-26 18:22:08 +08001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2014 Rockchip Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#include <console/console.h>
21#include <arch/io.h>
22#include <stdlib.h>
23#include "cpu.h"
24#include "gpio.h"
25#include "pmu.h"
26
27struct rk3288_gpio_regs *gpio_port[] = {
28 (struct rk3288_gpio_regs *)0xff750000,
29 (struct rk3288_gpio_regs *)0xff780000,
30 (struct rk3288_gpio_regs *)0xff790000,
31 (struct rk3288_gpio_regs *)0xff7a0000,
32 (struct rk3288_gpio_regs *)0xff7b0000,
33 (struct rk3288_gpio_regs *)0xff7c0000,
34 (struct rk3288_gpio_regs *)0xff7d0000,
35 (struct rk3288_gpio_regs *)0xff7e0000,
36 (struct rk3288_gpio_regs *)0xff7f0000
37};
38
39enum {
40 PULLNONE = 0,
41 PULLUP,
42 PULLDOWN
43};
44
45#define PMU_GPIO_PORT 0
46
47static void __gpio_input(gpio_t gpio, u32 pull)
48{
49 clrbits_le32(&gpio_port[gpio.port]->swporta_ddr, 1 << gpio.num);
50 if (gpio.port == PMU_GPIO_PORT)
51 clrsetbits_le32(&rk3288_pmu->gpio0pull[gpio.bank],
52 3 << (gpio.idx * 2), pull << (gpio.idx * 2));
53 else
54 writel(RK_CLRSETBITS(3 << (gpio.idx * 2),
55 pull << (gpio.idx * 2)),
56 &rk3288_grf->gpio1_p[(gpio.port - 1)][gpio.bank]);
57}
58
59void gpio_input(gpio_t gpio)
60{
61 __gpio_input(gpio, PULLNONE);
62}
63
64void gpio_input_pulldown(gpio_t gpio)
65{
66 __gpio_input(gpio, PULLDOWN);
67}
68
69void gpio_input_pullup(gpio_t gpio)
70{
71 __gpio_input(gpio, PULLUP);
72}
73
74int gpio_get_in_value(gpio_t gpio)
75{
76 return (readl(&gpio_port[gpio.port]->ext_porta) >> gpio.num) & 0x1;
77}
78
79void gpio_output(gpio_t gpio, int value)
80{
81 setbits_le32(&gpio_port[gpio.port]->swporta_ddr, 1 << gpio.num);
82 clrsetbits_le32(&gpio_port[gpio.port]->swporta_dr, 1 << gpio.num,
83 !!value << gpio.num);
84}