Sven Schnelle | ffcd143 | 2011-04-11 19:43:32 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2011 Sven Schnelle <svens@stackframe.org> |
| 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. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
Paul Menzel | a46a712 | 2013-02-23 18:37:27 +0100 | [diff] [blame] | 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Sven Schnelle | ffcd143 | 2011-04-11 19:43:32 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | #include <arch/io.h> |
| 21 | #include <console/console.h> |
| 22 | #include <device/device.h> |
| 23 | #include <ec/acpi/ec.h> |
| 24 | #include <device/pnp.h> |
| 25 | #include <stdlib.h> |
| 26 | #include "h8.h" |
| 27 | #include "chip.h" |
Sven Schnelle | 1b8068e | 2011-06-05 20:47:49 +0200 | [diff] [blame] | 28 | #include <pc80/mc146818rtc.h> |
Sven Schnelle | ffcd143 | 2011-04-11 19:43:32 +0000 | [diff] [blame] | 29 | |
Vladimir Serbinenko | 7d1ebbf | 2013-06-05 22:43:44 +0200 | [diff] [blame^] | 30 | #if defined (CONFIG_BOARD_LENOVO_X201) && CONFIG_BOARD_LENOVO_X201 |
| 31 | #include "mainboard/lenovo/x201/dock.h" |
| 32 | #endif |
| 33 | |
Sven Schnelle | bba0346 | 2012-01-31 17:41:12 +0100 | [diff] [blame] | 34 | static void h8_bluetooth_enable(int on) |
| 35 | { |
| 36 | if (on) |
| 37 | ec_set_bit(0x3a, 4); |
| 38 | else |
| 39 | ec_clr_bit(0x3a, 4); |
| 40 | } |
| 41 | |
Sven Schnelle | ffcd143 | 2011-04-11 19:43:32 +0000 | [diff] [blame] | 42 | void h8_trackpoint_enable(int on) |
| 43 | { |
Vladimir Serbinenko | 7d1ebbf | 2013-06-05 22:43:44 +0200 | [diff] [blame^] | 44 | ec_write(H8_TRACKPOINT_CTRL, on ? H8_TRACKPOINT_ON : H8_TRACKPOINT_OFF); |
Sven Schnelle | ffcd143 | 2011-04-11 19:43:32 +0000 | [diff] [blame] | 45 | |
| 46 | } |
| 47 | |
| 48 | void h8_wlan_enable(int on) |
| 49 | { |
| 50 | if (on) |
| 51 | ec_set_bit(0x3a, 5); |
| 52 | else |
| 53 | ec_clr_bit(0x3a, 5); |
| 54 | } |
| 55 | |
Vladimir Serbinenko | 7d1ebbf | 2013-06-05 22:43:44 +0200 | [diff] [blame^] | 56 | static void h8_3g_enable(int on) |
| 57 | { |
| 58 | if (on) |
| 59 | ec_set_bit(0x3a, 6); |
| 60 | else |
| 61 | ec_clr_bit(0x3a, 6); |
| 62 | } |
| 63 | |
Sven Schnelle | ffcd143 | 2011-04-11 19:43:32 +0000 | [diff] [blame] | 64 | static void h8_log_ec_version(void) |
| 65 | { |
| 66 | unsigned char ecfw[9], c; |
| 67 | u16 fwvh, fwvl; |
| 68 | int i; |
| 69 | |
| 70 | for(i = 0; i < 8; i++) { |
| 71 | c = ec_read(0xf0 + i); |
| 72 | if (c < 0x20 || c > 0x7f) |
| 73 | break; |
| 74 | ecfw[i] = c; |
| 75 | } |
| 76 | ecfw[i] = '\0'; |
| 77 | |
| 78 | fwvh = ec_read(0xe9); |
| 79 | fwvl = ec_read(0xe8); |
| 80 | |
| 81 | printk(BIOS_INFO, "EC Firmware ID %s, Version %d.%d%d%c\n", ecfw, |
| 82 | fwvh >> 4, fwvh & 0x0f, fwvl >> 4, 0x41 + (fwvl & 0xf)); |
| 83 | } |
| 84 | |
Sven Schnelle | d0ea678 | 2011-10-25 15:29:47 +0200 | [diff] [blame] | 85 | void h8_set_audio_mute(int mute) |
Sven Schnelle | ffcd143 | 2011-04-11 19:43:32 +0000 | [diff] [blame] | 86 | { |
Sven Schnelle | d0ea678 | 2011-10-25 15:29:47 +0200 | [diff] [blame] | 87 | if (mute) |
| 88 | ec_set_bit(0x3a, 0); |
Sven Schnelle | ffcd143 | 2011-04-11 19:43:32 +0000 | [diff] [blame] | 89 | else |
Sven Schnelle | d0ea678 | 2011-10-25 15:29:47 +0200 | [diff] [blame] | 90 | ec_clr_bit(0x3a, 0); |
Sven Schnelle | ffcd143 | 2011-04-11 19:43:32 +0000 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | void h8_enable_event(int event) |
| 94 | { |
| 95 | if (event < 0 || event > 127) |
| 96 | return; |
| 97 | |
| 98 | ec_set_bit(0x10 + (event >> 3), event & 7); |
| 99 | } |
| 100 | |
| 101 | void h8_disable_event(int event) |
| 102 | { |
| 103 | if (event < 0 || event > 127) |
| 104 | return; |
| 105 | |
| 106 | ec_clr_bit(0x10 + (event >> 3), event & 7); |
| 107 | |
| 108 | } |
| 109 | |
Sven Schnelle | 86e1aea | 2011-06-16 16:43:04 +0200 | [diff] [blame] | 110 | void h8_usb_power_enable(int onoff) |
| 111 | { |
| 112 | if (onoff) |
| 113 | ec_set_bit(0x3b, 4); |
| 114 | else |
| 115 | ec_clr_bit(0x3b, 4); |
| 116 | } |
| 117 | |
Sven Schnelle | cf7dffe | 2011-04-27 19:47:28 +0000 | [diff] [blame] | 118 | int h8_ultrabay_device_present(void) |
| 119 | { |
| 120 | return ec_read(H8_STATUS1) & 0x5 ? 0 : 1; |
| 121 | } |
| 122 | |
Sven Schnelle | ffcd143 | 2011-04-11 19:43:32 +0000 | [diff] [blame] | 123 | static void h8_enable(device_t dev) |
| 124 | { |
| 125 | struct ec_lenovo_h8_config *conf = dev->chip_info; |
Sven Schnelle | d5992b8 | 2011-12-07 14:30:58 -0800 | [diff] [blame] | 126 | u8 val, tmp; |
Sven Schnelle | 1b8068e | 2011-06-05 20:47:49 +0200 | [diff] [blame] | 127 | |
Sven Schnelle | ffcd143 | 2011-04-11 19:43:32 +0000 | [diff] [blame] | 128 | h8_log_ec_version(); |
| 129 | |
| 130 | ec_write(H8_CONFIG0, conf->config0); |
| 131 | ec_write(H8_CONFIG1, conf->config1); |
| 132 | ec_write(H8_CONFIG2, conf->config2); |
| 133 | ec_write(H8_CONFIG3, conf->config3); |
| 134 | |
| 135 | ec_write(H8_SOUND_ENABLE0, conf->beepmask0); |
| 136 | ec_write(H8_SOUND_ENABLE1, conf->beepmask1); |
| 137 | ec_write(H8_SOUND_REPEAT, 0x00); |
| 138 | |
| 139 | ec_write(0x10, conf->event0_enable); |
| 140 | ec_write(0x11, conf->event1_enable); |
| 141 | ec_write(0x12, conf->event2_enable); |
| 142 | ec_write(0x13, conf->event3_enable); |
| 143 | ec_write(0x14, conf->event4_enable); |
| 144 | ec_write(0x15, conf->event5_enable); |
| 145 | ec_write(0x16, conf->event6_enable); |
| 146 | ec_write(0x17, conf->event7_enable); |
| 147 | ec_write(0x18, conf->event8_enable); |
| 148 | ec_write(0x19, conf->event9_enable); |
| 149 | ec_write(0x1a, conf->eventa_enable); |
| 150 | ec_write(0x1b, conf->eventb_enable); |
| 151 | ec_write(0x1c, conf->eventc_enable); |
| 152 | ec_write(0x1d, conf->eventd_enable); |
| 153 | ec_write(0x1e, conf->evente_enable); |
| 154 | ec_write(0x1f, conf->eventf_enable); |
| 155 | |
Sven Schnelle | 3e2f679 | 2011-04-12 18:18:24 +0000 | [diff] [blame] | 156 | ec_write(H8_FAN_CONTROL, H8_FAN_CONTROL_AUTO); |
Sven Schnelle | ffcd143 | 2011-04-11 19:43:32 +0000 | [diff] [blame] | 157 | h8_wlan_enable(conf->wlan_enable); |
| 158 | h8_trackpoint_enable(conf->trackpoint_enable); |
Sven Schnelle | 86e1aea | 2011-06-16 16:43:04 +0200 | [diff] [blame] | 159 | h8_usb_power_enable(1); |
Sven Schnelle | ffcd143 | 2011-04-11 19:43:32 +0000 | [diff] [blame] | 160 | |
Sven Schnelle | 1b8068e | 2011-06-05 20:47:49 +0200 | [diff] [blame] | 161 | if (!get_option(&val, "volume")) |
| 162 | ec_write(H8_VOLUME_CONTROL, val); |
Sven Schnelle | 6901b56 | 2011-08-19 13:43:04 +0200 | [diff] [blame] | 163 | |
Vladimir Serbinenko | 7d1ebbf | 2013-06-05 22:43:44 +0200 | [diff] [blame^] | 164 | if (get_option(&val, "bluetooth")) |
| 165 | val = 1; |
| 166 | h8_bluetooth_enable(val); |
Sven Schnelle | d5992b8 | 2011-12-07 14:30:58 -0800 | [diff] [blame] | 167 | |
Vladimir Serbinenko | 7d1ebbf | 2013-06-05 22:43:44 +0200 | [diff] [blame^] | 168 | if (get_option(&val, "umts")) |
| 169 | val = 1; |
Sven Schnelle | bba0346 | 2012-01-31 17:41:12 +0100 | [diff] [blame] | 170 | |
Vladimir Serbinenko | 7d1ebbf | 2013-06-05 22:43:44 +0200 | [diff] [blame^] | 171 | h8_3g_enable(val); |
| 172 | |
| 173 | if (get_option(&val, "first_battery")) |
| 174 | val = 1; |
| 175 | |
| 176 | tmp = ec_read(H8_CONFIG3); |
| 177 | tmp &= ~(1 << 4); |
| 178 | tmp |= (val & 1) << 4; |
| 179 | ec_write(H8_CONFIG3, tmp); |
Sven Schnelle | 6901b56 | 2011-08-19 13:43:04 +0200 | [diff] [blame] | 180 | h8_set_audio_mute(0); |
Vladimir Serbinenko | 7d1ebbf | 2013-06-05 22:43:44 +0200 | [diff] [blame^] | 181 | |
| 182 | #if defined (CONFIG_BOARD_LENOVO_X201) && CONFIG_BOARD_LENOVO_X201 |
| 183 | if (dock_present()) { |
| 184 | printk(BIOS_DEBUG, "dock is connected\n"); |
| 185 | dock_connect(); |
| 186 | } else |
| 187 | printk(BIOS_DEBUG, "dock is not connected\n"); |
| 188 | #endif |
Sven Schnelle | ffcd143 | 2011-04-11 19:43:32 +0000 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | struct chip_operations ec_lenovo_h8_ops = { |
| 192 | CHIP_NAME("Lenovo H8 EC") |
| 193 | .enable_dev = h8_enable |
| 194 | }; |