blob: 350cc77cf0b74e070823d876d5218c86e8e252cb [file] [log] [blame]
Sven Schnelleffcd1432011-04-11 19:43:32 +00001/*
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 Menzela46a7122013-02-23 18:37:27 +010017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sven Schnelleffcd1432011-04-11 19:43:32 +000018 */
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 Schnelle1b8068e2011-06-05 20:47:49 +020028#include <pc80/mc146818rtc.h>
Sven Schnelleffcd1432011-04-11 19:43:32 +000029
Vladimir Serbinenko7d1ebbf2013-06-05 22:43:44 +020030#if defined (CONFIG_BOARD_LENOVO_X201) && CONFIG_BOARD_LENOVO_X201
31#include "mainboard/lenovo/x201/dock.h"
32#endif
33
Sven Schnellebba03462012-01-31 17:41:12 +010034static 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 Schnelleffcd1432011-04-11 19:43:32 +000042void h8_trackpoint_enable(int on)
43{
Vladimir Serbinenko7d1ebbf2013-06-05 22:43:44 +020044 ec_write(H8_TRACKPOINT_CTRL, on ? H8_TRACKPOINT_ON : H8_TRACKPOINT_OFF);
Sven Schnelleffcd1432011-04-11 19:43:32 +000045
46}
47
48void 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 Serbinenko7d1ebbf2013-06-05 22:43:44 +020056static 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 Schnelleffcd1432011-04-11 19:43:32 +000064static 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 Schnelled0ea6782011-10-25 15:29:47 +020085void h8_set_audio_mute(int mute)
Sven Schnelleffcd1432011-04-11 19:43:32 +000086{
Sven Schnelled0ea6782011-10-25 15:29:47 +020087 if (mute)
88 ec_set_bit(0x3a, 0);
Sven Schnelleffcd1432011-04-11 19:43:32 +000089 else
Sven Schnelled0ea6782011-10-25 15:29:47 +020090 ec_clr_bit(0x3a, 0);
Sven Schnelleffcd1432011-04-11 19:43:32 +000091}
92
93void 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
101void 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 Schnelle86e1aea2011-06-16 16:43:04 +0200110void 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 Schnellecf7dffe2011-04-27 19:47:28 +0000118int h8_ultrabay_device_present(void)
119{
120 return ec_read(H8_STATUS1) & 0x5 ? 0 : 1;
121}
122
Sven Schnelleffcd1432011-04-11 19:43:32 +0000123static void h8_enable(device_t dev)
124{
125 struct ec_lenovo_h8_config *conf = dev->chip_info;
Sven Schnelled5992b82011-12-07 14:30:58 -0800126 u8 val, tmp;
Sven Schnelle1b8068e2011-06-05 20:47:49 +0200127
Sven Schnelleffcd1432011-04-11 19:43:32 +0000128 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 Schnelle3e2f6792011-04-12 18:18:24 +0000156 ec_write(H8_FAN_CONTROL, H8_FAN_CONTROL_AUTO);
Sven Schnelleffcd1432011-04-11 19:43:32 +0000157 h8_wlan_enable(conf->wlan_enable);
158 h8_trackpoint_enable(conf->trackpoint_enable);
Sven Schnelle86e1aea2011-06-16 16:43:04 +0200159 h8_usb_power_enable(1);
Sven Schnelleffcd1432011-04-11 19:43:32 +0000160
Sven Schnelle1b8068e2011-06-05 20:47:49 +0200161 if (!get_option(&val, "volume"))
162 ec_write(H8_VOLUME_CONTROL, val);
Sven Schnelle6901b562011-08-19 13:43:04 +0200163
Vladimir Serbinenko7d1ebbf2013-06-05 22:43:44 +0200164 if (get_option(&val, "bluetooth"))
165 val = 1;
166 h8_bluetooth_enable(val);
Sven Schnelled5992b82011-12-07 14:30:58 -0800167
Vladimir Serbinenko7d1ebbf2013-06-05 22:43:44 +0200168 if (get_option(&val, "umts"))
169 val = 1;
Sven Schnellebba03462012-01-31 17:41:12 +0100170
Vladimir Serbinenko7d1ebbf2013-06-05 22:43:44 +0200171 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 Schnelle6901b562011-08-19 13:43:04 +0200180 h8_set_audio_mute(0);
Vladimir Serbinenko7d1ebbf2013-06-05 22:43:44 +0200181
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 Schnelleffcd1432011-04-11 19:43:32 +0000189}
190
191struct chip_operations ec_lenovo_h8_ops = {
192 CHIP_NAME("Lenovo H8 EC")
193 .enable_dev = h8_enable
194};