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
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
30 * GPIOs which are floating will go to whatever level they're
31 * internally pulled to.
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 */
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 */
58 * Get gpio values at internal pull down.
59 * Compare with gpio pull up value and then
60 * determine a gpio final value/state:
65 for (index
= num_gpio
- 1; index
>= 0; --index
) {
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
]);