Sven Schnelle | 7592e8b | 2011-01-27 11:43:03 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2008-2009 coresystems GmbH |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License as |
| 8 | * published by the Free Software Foundation; version 2 of |
| 9 | * the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
Sven Schnelle | 7592e8b | 2011-01-27 11:43:03 +0000 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <console/console.h> |
| 18 | #include <arch/io.h> |
| 19 | #include <delay.h> |
| 20 | #include <ec/acpi/ec.h> |
| 21 | #include "ec_oem.h" |
| 22 | |
| 23 | int send_ec_oem_command(u8 command) |
| 24 | { |
| 25 | int timeout; |
| 26 | |
| 27 | timeout = 0x7ff; |
| 28 | while ((inb(EC_OEM_SC) & EC_IBF) && --timeout) { |
| 29 | udelay(10); |
| 30 | if ((timeout & 0xff) == 0) |
| 31 | printk(BIOS_SPEW, "."); |
| 32 | } |
| 33 | if (!timeout) { |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 34 | printk(BIOS_DEBUG, "Timeout while sending OEM command 0x%02x to EC!\n", |
Sven Schnelle | 7592e8b | 2011-01-27 11:43:03 +0000 | [diff] [blame] | 35 | command); |
| 36 | // return -1; |
| 37 | } |
| 38 | |
| 39 | outb(command, EC_OEM_SC); |
| 40 | return 0; |
| 41 | } |
| 42 | |
| 43 | int send_ec_oem_data(u8 data) |
| 44 | { |
| 45 | int timeout; |
| 46 | |
| 47 | timeout = 0x7ff; |
| 48 | while ((inb(EC_OEM_SC) & EC_IBF) && --timeout) { // wait for IBF = 0 |
| 49 | udelay(10); |
| 50 | if ((timeout & 0xff) == 0) |
| 51 | printk(BIOS_SPEW, "."); |
| 52 | } |
| 53 | if (!timeout) { |
| 54 | printk(BIOS_DEBUG, "Timeout while sending OEM data 0x%02x to EC!\n", |
| 55 | data); |
| 56 | // return -1; |
| 57 | } |
| 58 | |
| 59 | outb(data, EC_OEM_DATA); |
| 60 | |
| 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | int send_ec_oem_data_nowait(u8 data) |
| 65 | { |
| 66 | outb(data, EC_OEM_DATA); |
| 67 | |
| 68 | return 0; |
| 69 | } |
| 70 | |
| 71 | u8 recv_ec_oem_data(void) |
| 72 | { |
| 73 | int timeout; |
| 74 | u8 data; |
| 75 | |
| 76 | timeout = 0x7fff; |
| 77 | while (--timeout) { // Wait for OBF = 1 |
| 78 | if (inb(EC_OEM_SC) & EC_OBF) { |
| 79 | break; |
| 80 | } |
| 81 | udelay(10); |
| 82 | if ((timeout & 0xff) == 0) |
| 83 | printk(BIOS_SPEW, "."); |
| 84 | } |
| 85 | if (!timeout) { |
| 86 | printk(BIOS_DEBUG, "\nTimeout while receiving OEM data from EC!\n"); |
| 87 | // return -1; |
| 88 | } |
| 89 | |
| 90 | data = inb(EC_OEM_DATA); |
| 91 | // printk(BIOS_SPEW, "recv_ec_oem_data: 0x%02x\n", data); |
| 92 | |
| 93 | return data; |
| 94 | } |
| 95 | |
| 96 | u8 ec_oem_read(u8 addr) |
| 97 | { |
| 98 | send_ec_oem_command(0x80); |
| 99 | send_ec_oem_data(addr); |
| 100 | |
| 101 | return recv_ec_oem_data(); |
| 102 | } |
| 103 | |
| 104 | int ec_oem_write(u8 addr, u8 data) |
| 105 | { |
| 106 | send_ec_oem_command(0x81); |
| 107 | send_ec_oem_data(addr); |
| 108 | return send_ec_oem_data(data); |
| 109 | } |
| 110 | |
| 111 | int ec_oem_dump_status(void) |
| 112 | { |
| 113 | u8 ec_sc = inb(EC_OEM_SC); |
| 114 | printk(BIOS_DEBUG, "Embedded Controller Status: "); |
| 115 | if (ec_sc & (1 << 6)) printk(BIOS_DEBUG, "SMI_EVT "); |
| 116 | if (ec_sc & (1 << 5)) printk(BIOS_DEBUG, "SCI_EVT "); |
| 117 | if (ec_sc & (1 << 4)) printk(BIOS_DEBUG, "BURST "); |
| 118 | if (ec_sc & (1 << 3)) printk(BIOS_DEBUG, "CMD "); |
| 119 | if (ec_sc & (1 << 1)) printk(BIOS_DEBUG, "IBF "); |
| 120 | if (ec_sc & (1 << 0)) printk(BIOS_DEBUG, "OBF "); |
| 121 | printk(BIOS_DEBUG, "\n"); |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 122 | |
Sven Schnelle | 7592e8b | 2011-01-27 11:43:03 +0000 | [diff] [blame] | 123 | return ec_sc; |
| 124 | } |