huang lin | d5fb66e | 2014-08-26 18:22:08 +0800 | [diff] [blame] | 1 | /* |
| 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. |
huang lin | d5fb66e | 2014-08-26 18:22:08 +0800 | [diff] [blame] | 14 | */ |
| 15 | |
huang lin | d5fb66e | 2014-08-26 18:22:08 +0800 | [diff] [blame] | 16 | #include <arch/io.h> |
Julius Werner | 7a453eb | 2014-10-20 13:14:55 -0700 | [diff] [blame] | 17 | #include <console/console.h> |
Julius Werner | eaa9c45 | 2014-09-24 15:40:49 -0700 | [diff] [blame] | 18 | #include <gpio.h> |
Julius Werner | 7a453eb | 2014-10-20 13:14:55 -0700 | [diff] [blame] | 19 | #include <soc/grf.h> |
| 20 | #include <soc/pmu.h> |
Julius Werner | eaa9c45 | 2014-09-24 15:40:49 -0700 | [diff] [blame] | 21 | #include <soc/soc.h> |
huang lin | d5fb66e | 2014-08-26 18:22:08 +0800 | [diff] [blame] | 22 | #include <stdlib.h> |
huang lin | d5fb66e | 2014-08-26 18:22:08 +0800 | [diff] [blame] | 23 | |
| 24 | struct rk3288_gpio_regs *gpio_port[] = { |
| 25 | (struct rk3288_gpio_regs *)0xff750000, |
| 26 | (struct rk3288_gpio_regs *)0xff780000, |
| 27 | (struct rk3288_gpio_regs *)0xff790000, |
| 28 | (struct rk3288_gpio_regs *)0xff7a0000, |
| 29 | (struct rk3288_gpio_regs *)0xff7b0000, |
| 30 | (struct rk3288_gpio_regs *)0xff7c0000, |
| 31 | (struct rk3288_gpio_regs *)0xff7d0000, |
| 32 | (struct rk3288_gpio_regs *)0xff7e0000, |
| 33 | (struct rk3288_gpio_regs *)0xff7f0000 |
| 34 | }; |
| 35 | |
| 36 | enum { |
| 37 | PULLNONE = 0, |
| 38 | PULLUP, |
| 39 | PULLDOWN |
| 40 | }; |
| 41 | |
| 42 | #define PMU_GPIO_PORT 0 |
| 43 | |
| 44 | static void __gpio_input(gpio_t gpio, u32 pull) |
| 45 | { |
| 46 | clrbits_le32(&gpio_port[gpio.port]->swporta_ddr, 1 << gpio.num); |
| 47 | if (gpio.port == PMU_GPIO_PORT) |
| 48 | clrsetbits_le32(&rk3288_pmu->gpio0pull[gpio.bank], |
| 49 | 3 << (gpio.idx * 2), pull << (gpio.idx * 2)); |
| 50 | else |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 51 | write32(&rk3288_grf->gpio1_p[(gpio.port - 1)][gpio.bank], |
Julius Werner | 9418476 | 2015-02-19 20:19:23 -0800 | [diff] [blame] | 52 | RK_CLRSETBITS(3 << (gpio.idx * 2), |
| 53 | pull << (gpio.idx * 2))); |
huang lin | d5fb66e | 2014-08-26 18:22:08 +0800 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | void gpio_input(gpio_t gpio) |
| 57 | { |
| 58 | __gpio_input(gpio, PULLNONE); |
| 59 | } |
| 60 | |
| 61 | void gpio_input_pulldown(gpio_t gpio) |
| 62 | { |
| 63 | __gpio_input(gpio, PULLDOWN); |
| 64 | } |
| 65 | |
| 66 | void gpio_input_pullup(gpio_t gpio) |
| 67 | { |
| 68 | __gpio_input(gpio, PULLUP); |
| 69 | } |
| 70 | |
Julius Werner | eaa9c45 | 2014-09-24 15:40:49 -0700 | [diff] [blame] | 71 | int gpio_get(gpio_t gpio) |
huang lin | d5fb66e | 2014-08-26 18:22:08 +0800 | [diff] [blame] | 72 | { |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 73 | return (read32(&gpio_port[gpio.port]->ext_porta) >> gpio.num) & 0x1; |
huang lin | d5fb66e | 2014-08-26 18:22:08 +0800 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | void gpio_output(gpio_t gpio, int value) |
| 77 | { |
| 78 | setbits_le32(&gpio_port[gpio.port]->swporta_ddr, 1 << gpio.num); |
| 79 | clrsetbits_le32(&gpio_port[gpio.port]->swporta_dr, 1 << gpio.num, |
| 80 | !!value << gpio.num); |
| 81 | } |