blob: ed09d02fc4da639af149255b5132d72b4750c8bd [file] [log] [blame]
Angel Ponsbbc99cf2020-04-04 18:51:23 +02001/* SPDX-License-Identifier: GPL-2.0-only */
huang lind5fb66e2014-08-26 18:22:08 +08002
Julius Wernereaa9c452014-09-24 15:40:49 -07003#include <gpio.h>
Elyes HAOUAS78efb842020-10-13 11:13:59 +02004#include <soc/addressmap.h>
Shunqian Zheng015ae112016-04-20 20:35:09 +08005#include <soc/gpio.h>
Julius Werner7a453eb2014-10-20 13:14:55 -07006#include <soc/grf.h>
7#include <soc/pmu.h>
Julius Wernereaa9c452014-09-24 15:40:49 -07008#include <soc/soc.h>
huang lind5fb66e2014-08-26 18:22:08 +08009
Shunqian Zheng015ae112016-04-20 20:35:09 +080010struct rockchip_gpio_regs *gpio_port[] = {
Elyes HAOUAS78efb842020-10-13 11:13:59 +020011 (struct rockchip_gpio_regs *)GPIO0_BASE,
12 (struct rockchip_gpio_regs *)GPIO1_BASE,
13 (struct rockchip_gpio_regs *)GPIO2_BASE,
14 (struct rockchip_gpio_regs *)GPIO3_BASE,
15 (struct rockchip_gpio_regs *)GPIO4_BASE,
16 (struct rockchip_gpio_regs *)GPIO5_BASE,
17 (struct rockchip_gpio_regs *)GPIO6_BASE,
18 (struct rockchip_gpio_regs *)GPIO7_BASE,
19 (struct rockchip_gpio_regs *)GPIO8_BASE
huang lind5fb66e2014-08-26 18:22:08 +080020};
21
22#define PMU_GPIO_PORT 0
23
Shunqian Zheng015ae112016-04-20 20:35:09 +080024int is_pmu_gpio(gpio_t gpio)
huang lind5fb66e2014-08-26 18:22:08 +080025{
huang lind5fb66e2014-08-26 18:22:08 +080026 if (gpio.port == PMU_GPIO_PORT)
Shunqian Zheng015ae112016-04-20 20:35:09 +080027 return 1;
28 return 0;
huang lind5fb66e2014-08-26 18:22:08 +080029}
30
Shunqian Zheng015ae112016-04-20 20:35:09 +080031void *gpio_grf_reg(gpio_t gpio)
huang lind5fb66e2014-08-26 18:22:08 +080032{
Shunqian Zheng015ae112016-04-20 20:35:09 +080033 if (is_pmu_gpio(gpio))
34 return &rk3288_pmu->gpio0pull[gpio.bank];
Elyes HAOUASa342f392018-10-17 10:56:26 +020035 /* There is one pmu gpio, gpio0, so " - 1" */
Shunqian Zheng015ae112016-04-20 20:35:09 +080036 return &rk3288_grf->gpio1_p[(gpio.port - 1)][gpio.bank];
huang lind5fb66e2014-08-26 18:22:08 +080037}
Shunqian Zheng74bb4122016-05-17 14:00:04 +080038
Julius Werner2768a112016-09-01 22:55:58 -070039u32 gpio_get_pull_val(gpio_t gpio, enum gpio_pull pull)
Shunqian Zheng74bb4122016-05-17 14:00:04 +080040{
41 /* use the default gpio pull bias setting defined in soc/gpio.h */
42 return pull;
43}