soc: Remove copyright notices
[coreboot.git] / src / soc / qualcomm / qcs405 / gpio.c
blobeab29f390fe663df45c2994badaa70e1e4b16537
1 /*
2 * This file is part of the coreboot project.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
15 #include <device/mmio.h>
16 #include <types.h>
17 #include <gpio.h>
19 void gpio_configure(gpio_t gpio, uint32_t func, uint32_t pull,
20 uint32_t drive_str, uint32_t enable)
22 uint32_t reg_val;
23 struct tlmm_gpio *regs = (void *)(uintptr_t)gpio.addr;
25 reg_val = ((enable & GPIO_CFG_OE_BMSK) << GPIO_CFG_OE_SHFT) |
26 ((drive_str & GPIO_CFG_DRV_BMSK) << GPIO_CFG_DRV_SHFT) |
27 ((func & GPIO_CFG_FUNC_BMSK) << GPIO_CFG_FUNC_SHFT) |
28 ((pull & GPIO_CFG_PULL_BMSK) << GPIO_CFG_PULL_SHFT);
30 write32(&regs->cfg, reg_val);
33 void gpio_set(gpio_t gpio, int value)
35 struct tlmm_gpio *regs = (void *)(uintptr_t)gpio.addr;
36 write32(&regs->in_out, (!!value) << GPIO_IO_OUT_SHFT);
39 int gpio_get(gpio_t gpio)
41 struct tlmm_gpio *regs = (void *)(uintptr_t)gpio.addr;
43 return ((read32(&regs->in_out) >> GPIO_IO_IN_SHFT) &
44 GPIO_IO_IN_BMSK);
47 void gpio_input_pulldown(gpio_t gpio)
49 gpio_configure(gpio, GPIO_FUNC_GPIO,
50 GPIO_PULL_DOWN, GPIO_2MA, GPIO_DISABLE);
53 void gpio_input_pullup(gpio_t gpio)
55 gpio_configure(gpio, GPIO_FUNC_GPIO,
56 GPIO_PULL_UP, GPIO_2MA, GPIO_DISABLE);
59 void gpio_input(gpio_t gpio)
61 gpio_configure(gpio, GPIO_FUNC_GPIO,
62 GPIO_NO_PULL, GPIO_2MA, GPIO_DISABLE);
65 void gpio_output(gpio_t gpio, int value)
67 gpio_set(gpio, value);
68 gpio_configure(gpio, GPIO_FUNC_GPIO,
69 GPIO_NO_PULL, GPIO_2MA, GPIO_ENABLE);
72 void gpio_input_irq(gpio_t gpio, enum gpio_irq_type type, uint32_t pull)
74 struct tlmm_gpio *regs = (void *)(uintptr_t)gpio.addr;
76 gpio_configure(gpio, GPIO_FUNC_GPIO,
77 pull, GPIO_2MA, GPIO_DISABLE);
79 clrsetbits32(&regs->intr_cfg, GPIO_INTR_DECT_CTL_MASK <<
80 GPIO_INTR_DECT_CTL_SHIFT, type << GPIO_INTR_DECT_CTL_SHIFT);
81 clrsetbits32(&regs->intr_cfg, GPIO_INTR_RAW_STATUS_ENABLE
82 << GPIO_INTR_RAW_STATUS_EN_SHIFT, GPIO_INTR_RAW_STATUS_ENABLE
83 << GPIO_INTR_RAW_STATUS_EN_SHIFT);
86 int gpio_irq_status(gpio_t gpio)
88 struct tlmm_gpio *regs = (void *)(uintptr_t)gpio.addr;
90 if (!(read32(&regs->intr_status) & GPIO_INTR_STATUS_MASK))
91 return 0;
93 write32(&regs->intr_status, GPIO_INTR_STATUS_DISABLE);
94 return 1;