arm64: remove _stack and _estack symbols in linker script
[coreboot.git] / src / lib / tristate_gpios.c
blob8e93e3704aa41225468de930410ad18fb2d45cee
1 /*
2 * This file is part of the coreboot project.
4 * Copyright 2014 Google Inc.
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.
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.
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
20 #include <delay.h>
21 #include <gpiolib.h>
23 int gpio_get_in_tristate_values(gpio_t gpio[], int num_gpio, int tertiary)
26 * GPIOs which are tied to stronger external pull up or pull down
27 * will stay there regardless of the internal pull up or pull
28 * down setting.
30 * GPIOs which are floating will go to whatever level they're
31 * internally pulled to.
34 int temp;
35 int index;
36 int id = 0;
37 char value[num_gpio];
39 /* Enable internal pull up */
40 for (index = 0; index < num_gpio; ++index)
41 gpio_input_pullup(gpio[index]);
43 /* Wait until signals become stable */
44 udelay(10);
46 /* Get gpio values at internal pull up */
47 for (index = 0; index < num_gpio; ++index)
48 value[index] = gpio_get_in_value(gpio[index]);
50 /* Enable internal pull down */
51 for (index = 0; index < num_gpio; ++index)
52 gpio_input_pulldown(gpio[index]);
54 /* Wait until signals become stable */
55 udelay(10);
58 * Get gpio values at internal pull down.
59 * Compare with gpio pull up value and then
60 * determine a gpio final value/state:
61 * 0: pull down
62 * 1: pull up
63 * 2: floating
65 for (index = num_gpio - 1; index >= 0; --index) {
66 if (tertiary)
67 id *= 3;
68 else
69 id <<= 2;
70 temp = gpio_get_in_value(gpio[index]);
71 id += ((value[index] ^ temp) << 1) | temp;
74 /* Disable pull up / pull down to conserve power */
75 for (index = 0; index < num_gpio; ++index)
76 gpio_input(gpio[index]);
78 return id;