blob: 295550fe2b97af597675a5849dd2f5bc40e3bb9d [file] [log] [blame]
Vadim Bendebury81678802014-07-28 16:47:08 -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.
Vadim Bendebury81678802014-07-28 16:47:08 -070014 */
15
Vadim Bendebury81678802014-07-28 16:47:08 -070016#include <boardid.h>
Julius Wernereaa9c452014-09-24 15:40:49 -070017#include <gpio.h>
Vadim Bendebury81678802014-07-28 16:47:08 -070018#include <console/console.h>
Julius Werner73d1ed62014-10-20 13:20:49 -070019#include <stdlib.h>
Vadim Bendebury81678802014-07-28 16:47:08 -070020
21/*
22 * Storm boards dedicate to the board ID three GPIOs in tertiary mode: 29, 30
23 * and 68. On proto0 GPIO68 is used and tied low, so it reads as 'zero' by
David Hendricks3fc63682014-11-06 15:09:27 -080024 * gpio_base3_value(), whereas the other two pins are not connected
25 * and read as 'two'. This results in gpio_base3_value() returning
Vadim Bendebury37602722014-08-07 12:02:26 -070026 * 8 on proto0.
Vadim Bendebury81678802014-07-28 16:47:08 -070027 *
28 * Three tertitiary signals could represent 27 different values. To make
29 * calculated board ID value continuous and starting at zero, offset the
30 * calculated value by 19 (i.e. 27 - 8) and return modulo 27 of the offset
31 * number. This results in proto0 returning zero as the board ID, the future
32 * revisions will have the inputs configured to match the actual board
33 * revision.
34 */
35
Vadim Bendebury2786ce02014-09-08 14:04:08 -070036static int board_id_value = -1;
37
38static uint8_t get_board_id(void)
Vadim Bendebury81678802014-07-28 16:47:08 -070039{
40 uint8_t bid;
Julius Werner886d29b2014-09-24 15:40:49 -070041 gpio_t hw_rev_gpios[] = {[2] = 68, [1] = 30, [0] = 29}; /* 29 is LSB */
Vadim Bendebury81678802014-07-28 16:47:08 -070042 int offset = 19;
43
David Hendricks3fc63682014-11-06 15:09:27 -080044 bid = gpio_base3_value(hw_rev_gpios, ARRAY_SIZE(hw_rev_gpios));
Vadim Bendebury81678802014-07-28 16:47:08 -070045 bid = (bid + offset) % 27;
46 printk(BIOS_INFO, "Board ID %d\n", bid);
47
48 return bid;
49}
Vadim Bendebury2786ce02014-09-08 14:04:08 -070050
51uint8_t board_id(void)
52{
53 if (board_id_value < 0)
54 board_id_value = get_board_id();
55
56 return board_id_value;
57}