blob: 7b64ebfe80668858f99180557a22839b1bf3aaa4 [file] [log] [blame]
Vadim Bendebury9c9c3362014-07-23 09:40:02 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2014 Google 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
Julius Wernereaa9c452014-09-24 15:40:49 -070020#ifndef __SRC_INCLUDE_GPIO_H__
21#define __SRC_INCLUDE_GPIO_H__
Vadim Bendebury9c9c3362014-07-23 09:40:02 -070022
Julius Wernereaa9c452014-09-24 15:40:49 -070023#include <soc/gpio.h>
24#include <types.h>
25
26/* <soc/gpio.h> must typedef a gpio_t that fits in 32 bits. */
27_Static_assert(sizeof(gpio_t) <= sizeof(u32), "gpio_t doesn't fit in lb_gpio");
28
29/* The following functions must be implemented by SoC/board code. */
30int gpio_get(gpio_t gpio);
31void gpio_set(gpio_t gpio, int value);
32void gpio_input_pulldown(gpio_t gpio);
33void gpio_input_pullup(gpio_t gpio);
34void gpio_input(gpio_t gpio);
35void gpio_output(gpio_t gpio, int value);
Vadim Bendebury9c9c3362014-07-23 09:40:02 -070036
37/*
38 * Read the value presented by the set of GPIOs, when each pin is interpreted
David Hendricks21db62e2014-11-06 15:05:35 -080039 * as a base-2 digit (LOW = 0, HIGH = 1).
40 *
41 * gpio[]: pin positions to read. gpio[0] is less significant than gpio[1].
42 * num_gpio: number of pins to read.
43 */
44int gpio_base2_value(gpio_t gpio[], int num_gpio);
45
46/*
47 * Read the value presented by the set of GPIOs, when each pin is interpreted
Julius Werner886d29b2014-09-24 15:40:49 -070048 * as a base-3 digit (LOW = 0, HIGH = 1, Z/floating = 2).
David Hendricks3fc63682014-11-06 15:09:27 -080049 * Example: X1 = Z, X2 = 1 -> gpio_base3_value({GPIO(X1), GPIO(X2)}) = 5
Julius Werner886d29b2014-09-24 15:40:49 -070050 * BASE3() from <base3.h> can generate numbers to compare the result to.
Vadim Bendebury9c9c3362014-07-23 09:40:02 -070051 *
Julius Werner886d29b2014-09-24 15:40:49 -070052 * gpio[]: pin positions to read. gpio[0] is less significant than gpio[1].
Daisuke Nojiri573e2112014-08-08 15:38:52 -070053 * num_gpio: number of pins to read.
Vadim Bendebury9c9c3362014-07-23 09:40:02 -070054 */
David Hendricks3fc63682014-11-06 15:09:27 -080055int gpio_base3_value(gpio_t gpio[], int num_gpio);
Vadim Bendebury9c9c3362014-07-23 09:40:02 -070056
Julius Wernereaa9c452014-09-24 15:40:49 -070057#endif /* __SRC_INCLUDE_GPIO_H__ */