| 1 |
|
| 2 |
|
| 3 |
#include <types.h> |
| 4 |
#include <cbfs.h> |
| 5 |
#include <device/device.h> |
| 6 |
#include <device/pci_ops.h> |
| 7 |
#include <console/console.h> |
| 8 |
#include <drivers/intel/gma/int15.h> |
| 9 |
#include <fmap.h> |
| 10 |
#include <arch/io.h> |
| 11 |
#include "onboard.h" |
| 12 |
#include "ec.h" |
| 13 |
#include <southbridge/intel/bd82x6x/pch.h> |
| 14 |
#include <smbios.h> |
| 15 |
#include <ec/quanta/ene_kb3940q/ec.h> |
| 16 |
|
| 17 |
static unsigned int search(char *p, char *a, unsigned int lengthp, |
| 18 |
unsigned int lengtha) |
| 19 |
{ |
| 20 |
int i, j; |
| 21 |
|
| 22 |
|
| 23 |
for (j = 0; j <= lengtha - lengthp; j++) { |
| 24 |
for (i = 0; i < lengthp && p[i] == a[i + j]; i++) |
| 25 |
; |
| 26 |
if (i >= lengthp) |
| 27 |
return j; |
| 28 |
} |
| 29 |
return lengtha; |
| 30 |
} |
| 31 |
|
| 32 |
static unsigned char get_hex_digit(char *offset) |
| 33 |
{ |
| 34 |
unsigned char retval = 0; |
| 35 |
|
| 36 |
retval = *offset - '0'; |
| 37 |
if (retval > 0x09) { |
| 38 |
retval = *offset - 'A' + 0x0A; |
| 39 |
if (retval > 0x0F) |
| 40 |
retval = *offset - 'a' + 0x0a; |
| 41 |
} |
| 42 |
if (retval > 0x0F) { |
| 43 |
printk(BIOS_ERR, "Invalid Hex digit found: %c - 0x%02x\n", |
| 44 |
*offset, (unsigned char)*offset); |
| 45 |
retval = 0; |
| 46 |
} |
| 47 |
|
| 48 |
return retval; |
| 49 |
} |
| 50 |
|
| 51 |
static int get_mac_address(u32 *high_dword, u32 *low_dword, |
| 52 |
uintptr_t search_address, u32 search_length) |
| 53 |
{ |
| 54 |
char key[] = "ethernet_mac"; |
| 55 |
unsigned int offset; |
| 56 |
int i; |
| 57 |
|
| 58 |
offset = search(key, (char *)search_address, |
| 59 |
sizeof(key) - 1, search_length); |
| 60 |
if (offset == search_length) { |
| 61 |
printk(BIOS_ERR, "Could not locate '%s' in VPD\n", key); |
| 62 |
return 0; |
| 63 |
} |
| 64 |
printk(BIOS_DEBUG, "Located '%s' in VPD\n", key); |
| 65 |
|
| 66 |
offset += sizeof(key); |
| 67 |
*high_dword = 0; |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
for (i = 0; i < 4; i++) { |
| 79 |
*high_dword |= (get_hex_digit((char *)(search_address + offset)) |
| 80 |
<< (4 + (i * 8))); |
| 81 |
*high_dword |= (get_hex_digit((char *)(search_address + offset + 1)) |
| 82 |
<< (i * 8)); |
| 83 |
offset += 3; |
| 84 |
} |
| 85 |
|
| 86 |
*low_dword = 0; |
| 87 |
for (i = 0; i < 2; i++) { |
| 88 |
*low_dword |= (get_hex_digit((char *)(search_address + offset)) |
| 89 |
<< (4 + (i * 8))); |
| 90 |
*low_dword |= (get_hex_digit((char *)(search_address + offset + 1)) |
| 91 |
<< (i * 8)); |
| 92 |
offset += 3; |
| 93 |
} |
| 94 |
|
| 95 |
return *high_dword | *low_dword; |
| 96 |
} |
| 97 |
|
| 98 |
static void program_mac_address(u16 io_base, u32 search_address, |
| 99 |
u32 search_length) |
| 100 |
{ |
| 101 |
|
| 102 |
u32 high_dword = 0xD0BA00A0; |
| 103 |
u32 low_dword = 0x0000AD0B; |
| 104 |
|
| 105 |
if (search_length != -1) |
| 106 |
get_mac_address(&high_dword, &low_dword, search_address, |
| 107 |
search_length); |
| 108 |
|
| 109 |
if (io_base) { |
| 110 |
printk(BIOS_DEBUG, "Realtek NIC io_base = 0x%04x\n", io_base); |
| 111 |
printk(BIOS_DEBUG, "Programming MAC Address\n"); |
| 112 |
|
| 113 |
outb(0xc0, io_base + 0x50); |
| 114 |
outl(high_dword, io_base); |
| 115 |
outl(low_dword, io_base + 0x04); |
| 116 |
outb(0x60, io_base + 54); |
| 117 |
outb(0x00, io_base + 0x50); |
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
static void program_keyboard_type(uintptr_t search_address, u32 search_length) |
| 122 |
{ |
| 123 |
char key[] = "keyboard_layout"; |
| 124 |
char kbd_jpn[] = "xkb:jp::jpn"; |
| 125 |
unsigned int offset; |
| 126 |
char kbd_type = EC_KBD_EN; |
| 127 |
|
| 128 |
if (search_length != -1) { |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
offset = search(key, (char *)search_address, sizeof(key) - 1, |
| 138 |
search_length); |
| 139 |
if (offset != search_length) { |
| 140 |
printk(BIOS_DEBUG, "Located '%s' in VPD\n", key); |
| 141 |
|
| 142 |
offset += sizeof(key); |
| 143 |
search_length = sizeof(kbd_jpn); |
| 144 |
offset = search(kbd_jpn, (char *)(search_address + offset), |
| 145 |
sizeof(kbd_jpn) - 1, search_length); |
| 146 |
if (offset != search_length) |
| 147 |
kbd_type = EC_KBD_JP; |
| 148 |
} |
| 149 |
} else { |
| 150 |
printk(BIOS_ERR, "Could not locate VPD area\n"); |
| 151 |
} |
| 152 |
|
| 153 |
printk(BIOS_DEBUG, "Setting Keyboard type in EC to "); |
| 154 |
printk(BIOS_DEBUG, (kbd_type == EC_KBD_JP) ? "Japanese" : "English"); |
| 155 |
printk(BIOS_DEBUG, ".\n"); |
| 156 |
|
| 157 |
ec_mem_write(EC_KBID_REG, kbd_type); |
| 158 |
} |
| 159 |
|
| 160 |
static void mainboard_init(struct device *dev) |
| 161 |
{ |
| 162 |
uintptr_t search_address = 0x0; |
| 163 |
size_t search_length = -1; |
| 164 |
u16 io_base = 0; |
| 165 |
struct device *ethernet_dev = NULL; |
| 166 |
void *vpd_file; |
| 167 |
|
| 168 |
if (CONFIG(VPD)) { |
| 169 |
struct region_device rdev; |
| 170 |
|
| 171 |
if (fmap_locate_area_as_rdev("RO_VPD", &rdev) == 0) { |
| 172 |
vpd_file = rdev_mmap_full(&rdev); |
| 173 |
|
| 174 |
if (vpd_file != NULL) { |
| 175 |
search_length = region_device_sz(&rdev); |
| 176 |
search_address = (uintptr_t)vpd_file; |
| 177 |
} |
| 178 |
} |
| 179 |
} else { |
| 180 |
vpd_file = cbfs_map("vpd.bin", &search_length); |
| 181 |
if (vpd_file) { |
| 182 |
search_address = (uintptr_t)vpd_file; |
| 183 |
} else { |
| 184 |
search_length = -1; |
| 185 |
search_address = 0; |
| 186 |
} |
| 187 |
} |
| 188 |
|
| 189 |
|
| 190 |
butterfly_ec_init(); |
| 191 |
|
| 192 |
|
| 193 |
program_keyboard_type(search_address, search_length); |
| 194 |
|
| 195 |
|
| 196 |
ethernet_dev = dev_find_device(BUTTERFLY_NIC_VENDOR_ID, |
| 197 |
BUTTERFLY_NIC_DEVICE_ID, dev); |
| 198 |
if (ethernet_dev != NULL) { |
| 199 |
io_base = pci_read_config16(ethernet_dev, 0x10) & 0xfffe; |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
pci_write_config8(ethernet_dev, 0x81, 0x01); |
| 207 |
} |
| 208 |
|
| 209 |
if (io_base) { |
| 210 |
|
| 211 |
program_mac_address(io_base, search_address, search_length); |
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
outb(0xc0, io_base + 0x50); |
| 227 |
outb((BUTTERFLY_NIC_LED_MODE << 6) | 0x0f, io_base + 0x52); |
| 228 |
outb(0x00, io_base + 0x50); |
| 229 |
} |
| 230 |
} |
| 231 |
|
| 232 |
static int butterfly_onboard_smbios_data(struct device *dev, int *handle, |
| 233 |
unsigned long *current) |
| 234 |
{ |
| 235 |
int len = 0; |
| 236 |
|
| 237 |
len += smbios_write_type41( |
| 238 |
current, handle, |
| 239 |
BOARD_TRACKPAD_NAME, |
| 240 |
BOARD_TRACKPAD_IRQ, |
| 241 |
0, |
| 242 |
BOARD_TRACKPAD_I2C_ADDR, |
| 243 |
0, |
| 244 |
0, |
| 245 |
SMBIOS_DEVICE_TYPE_OTHER); |
| 246 |
|
| 247 |
return len; |
| 248 |
} |
| 249 |
|
| 250 |
static void mainboard_enable(struct device *dev) |
| 251 |
{ |
| 252 |
dev->ops->init = mainboard_init; |
| 253 |
dev->ops->get_smbios_data = butterfly_onboard_smbios_data; |
| 254 |
install_intel_vga_int15_handler(GMA_INT15_ACTIVE_LFP_INT_LVDS, GMA_INT15_PANEL_FIT_DEFAULT, GMA_INT15_BOOT_DISPLAY_DEFAULT, 0); |
| 255 |
} |
| 256 |
|
| 257 |
struct chip_operations mainboard_ops = { |
| 258 |
.enable_dev = mainboard_enable, |
| 259 |
}; |