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.
18 #include <console/console.h>
22 int gpio_base2_value(gpio_t gpio
[], int num_gpio
)
26 for (i
= 0; i
< num_gpio
; i
++)
29 /* Wait until signals become stable */
32 for (i
= 0; i
< num_gpio
; i
++)
33 result
|= gpio_get(gpio
[i
]) << i
;
38 int gpio_base3_value(gpio_t gpio
[], int num_gpio
)
41 * GPIOs which are tied to stronger external pull up or pull down
42 * will stay there regardless of the internal pull up or pull
45 * GPIOs which are floating will go to whatever level they're
46 * internally pulled to.
49 static const char tristate_char
[] = {[0] = '0', [1] = '1', [Z
] = 'Z'};
54 assert(num_gpio
<= 32);
56 /* Enable internal pull up */
57 for (index
= 0; index
< num_gpio
; ++index
)
58 gpio_input_pullup(gpio
[index
]);
60 /* Wait until signals become stable */
63 /* Get gpio values at internal pull up */
64 for (index
= 0; index
< num_gpio
; ++index
)
65 value
[index
] = gpio_get(gpio
[index
]);
67 /* Enable internal pull down */
68 for (index
= 0; index
< num_gpio
; ++index
)
69 gpio_input_pulldown(gpio
[index
]);
71 /* Wait until signals become stable */
75 * Get gpio values at internal pull down.
76 * Compare with gpio pull up value and then
77 * determine a gpio final value/state:
82 printk(BIOS_DEBUG
, "Reading tristate GPIOs: ");
83 for (index
= num_gpio
- 1; index
>= 0; --index
) {
84 temp
= gpio_get(gpio
[index
]);
85 temp
|= ((value
[index
] ^ temp
) << 1);
86 printk(BIOS_DEBUG
, "%c ", tristate_char
[temp
]);
87 result
= (result
* 3) + temp
;
89 printk(BIOS_DEBUG
, "= %d\n", result
);
91 /* Disable pull up / pull down to conserve power */
92 for (index
= 0; index
< num_gpio
; ++index
)
93 gpio_input(gpio
[index
]);