Christian Gmeiner | 86f992c | 2012-07-13 11:36:08 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2012 Bachmann electronic GmbH |
| 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 version 2 as |
| 8 | * published by the Free Software Foundation. |
| 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 |
Paul Menzel | a8ae1c6 | 2013-02-20 13:21:20 +0100 | [diff] [blame] | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Christian Gmeiner | 86f992c | 2012-07-13 11:36:08 +0200 | [diff] [blame] | 13 | * GNU General Public License for more details. |
Christian Gmeiner | 86f992c | 2012-07-13 11:36:08 +0200 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <device/device.h> |
Christian Gmeiner | a59a9f7 | 2012-09-14 16:29:10 +0200 | [diff] [blame] | 17 | #include <device/smbus.h> |
| 18 | #include <smbios.h> |
| 19 | #include <console/console.h> |
Christian Gmeiner | 4412bc4 | 2013-03-12 11:07:07 +0100 | [diff] [blame] | 20 | #include <cpu/x86/msr.h> |
Christian Gmeiner | 1990ab9 | 2013-05-23 13:26:37 +0200 | [diff] [blame] | 21 | #include <arch/io.h> |
Christian Gmeiner | a59a9f7 | 2012-09-14 16:29:10 +0200 | [diff] [blame] | 22 | |
| 23 | /* overwrite a weak function to fill SMBIOS table with a custom value */ |
| 24 | static u8 hw_rev = 0; |
| 25 | static char mb_rev_str[2] = { '0' }; |
| 26 | |
| 27 | const char *smbios_mainboard_version(void) |
| 28 | { |
| 29 | /* UDMA is not working on all supported devices */ |
| 30 | if (hw_rev < 113) { |
| 31 | mb_rev_str[0] = '1'; |
| 32 | } else { |
| 33 | mb_rev_str[0] = '2'; |
| 34 | } |
| 35 | |
| 36 | return mb_rev_str; |
| 37 | } |
| 38 | |
| 39 | static void init(struct device *dev) |
| 40 | { |
| 41 | unsigned int i; |
| 42 | u32 chksum = 0; |
| 43 | char block[20]; |
Christian Gmeiner | 4412bc4 | 2013-03-12 11:07:07 +0100 | [diff] [blame] | 44 | msr_t reset; |
Christian Gmeiner | a59a9f7 | 2012-09-14 16:29:10 +0200 | [diff] [blame] | 45 | device_t eeprom_dev = dev_find_slot_on_smbus(1, 0x52); |
| 46 | |
| 47 | if (eeprom_dev == 0) { |
| 48 | printk(BIOS_WARNING, "eeprom not found\n"); |
| 49 | return; |
| 50 | } |
| 51 | |
Christian Gmeiner | 1990ab9 | 2013-05-23 13:26:37 +0200 | [diff] [blame] | 52 | /* turn off all leds except led_ini */ |
| 53 | outb(0x02, 0x5a); /* bit0 - led_run */ |
| 54 | /* bit1 - led_ini */ |
| 55 | /* bit2 - led_err */ |
| 56 | /* bit3-bit7 - write has no effect */ |
| 57 | outb(0x00, 0x49); /* bit0-bit6 - led_7-led_1 */ |
| 58 | /* bit7 - write has no effect */ |
| 59 | |
Christian Gmeiner | a59a9f7 | 2012-09-14 16:29:10 +0200 | [diff] [blame] | 60 | /* read the whole block and check if checksum is okay */ |
| 61 | for (i = 0; i < 20; i++) { |
| 62 | block[i] = smbus_read_byte(eeprom_dev, i); |
| 63 | chksum += block[i]; |
| 64 | } |
| 65 | |
| 66 | if (chksum != 0) { |
| 67 | printk(BIOS_WARNING, "wrong checksum: 0x%0x\n", chksum); |
| 68 | } |
| 69 | |
| 70 | hw_rev = block[5]; |
| 71 | |
| 72 | printk(BIOS_DEBUG, "hw revision: %u\n", hw_rev); |
Christian Gmeiner | 4412bc4 | 2013-03-12 11:07:07 +0100 | [diff] [blame] | 73 | |
| 74 | /* Reset MFGPT7 (standby power domain) - this is done via |
| 75 | * an undocumented register */ |
| 76 | reset = rdmsr(0x5140002b); |
| 77 | reset.lo |= 1 << 7; |
| 78 | wrmsr(0x5140002b, reset); |
Christian Gmeiner | a59a9f7 | 2012-09-14 16:29:10 +0200 | [diff] [blame] | 79 | } |
| 80 | |
Paul Menzel | 528640d | 2013-02-23 21:31:23 +0100 | [diff] [blame] | 81 | static void mainboard_enable(struct device *dev) |
Christian Gmeiner | a59a9f7 | 2012-09-14 16:29:10 +0200 | [diff] [blame] | 82 | { |
| 83 | dev->ops->init = init; |
| 84 | } |
Christian Gmeiner | 86f992c | 2012-07-13 11:36:08 +0200 | [diff] [blame] | 85 | |
| 86 | struct chip_operations mainboard_ops = { |
Paul Menzel | 528640d | 2013-02-23 21:31:23 +0100 | [diff] [blame] | 87 | .enable_dev = mainboard_enable, |
Christian Gmeiner | 86f992c | 2012-07-13 11:36:08 +0200 | [diff] [blame] | 88 | }; |