Vadim Bendebury | 8167880 | 2014-07-28 16:47:08 -0700 | [diff] [blame] | 1 | /* |
| 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 Bendebury | 8167880 | 2014-07-28 16:47:08 -0700 | [diff] [blame] | 14 | */ |
| 15 | |
Vadim Bendebury | 8167880 | 2014-07-28 16:47:08 -0700 | [diff] [blame] | 16 | #include <boardid.h> |
Julius Werner | eaa9c45 | 2014-09-24 15:40:49 -0700 | [diff] [blame] | 17 | #include <gpio.h> |
Vadim Bendebury | 8167880 | 2014-07-28 16:47:08 -0700 | [diff] [blame] | 18 | #include <console/console.h> |
Julius Werner | 73d1ed6 | 2014-10-20 13:20:49 -0700 | [diff] [blame] | 19 | #include <stdlib.h> |
Vadim Bendebury | 8167880 | 2014-07-28 16:47:08 -0700 | [diff] [blame] | 20 | |
| 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 Hendricks | 3fc6368 | 2014-11-06 15:09:27 -0800 | [diff] [blame] | 24 | * gpio_base3_value(), whereas the other two pins are not connected |
| 25 | * and read as 'two'. This results in gpio_base3_value() returning |
Vadim Bendebury | 3760272 | 2014-08-07 12:02:26 -0700 | [diff] [blame] | 26 | * 8 on proto0. |
Vadim Bendebury | 8167880 | 2014-07-28 16:47:08 -0700 | [diff] [blame] | 27 | * |
| 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 Bendebury | 2786ce0 | 2014-09-08 14:04:08 -0700 | [diff] [blame] | 36 | static int board_id_value = -1; |
| 37 | |
| 38 | static uint8_t get_board_id(void) |
Vadim Bendebury | 8167880 | 2014-07-28 16:47:08 -0700 | [diff] [blame] | 39 | { |
| 40 | uint8_t bid; |
Julius Werner | 886d29b | 2014-09-24 15:40:49 -0700 | [diff] [blame] | 41 | gpio_t hw_rev_gpios[] = {[2] = 68, [1] = 30, [0] = 29}; /* 29 is LSB */ |
Vadim Bendebury | 8167880 | 2014-07-28 16:47:08 -0700 | [diff] [blame] | 42 | int offset = 19; |
| 43 | |
David Hendricks | 3fc6368 | 2014-11-06 15:09:27 -0800 | [diff] [blame] | 44 | bid = gpio_base3_value(hw_rev_gpios, ARRAY_SIZE(hw_rev_gpios)); |
Vadim Bendebury | 8167880 | 2014-07-28 16:47:08 -0700 | [diff] [blame] | 45 | bid = (bid + offset) % 27; |
| 46 | printk(BIOS_INFO, "Board ID %d\n", bid); |
| 47 | |
| 48 | return bid; |
| 49 | } |
Vadim Bendebury | 2786ce0 | 2014-09-08 14:04:08 -0700 | [diff] [blame] | 50 | |
| 51 | uint8_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 | } |