e2e5f998be818c1959de9e523718817a062bece5
[coreboot.git] / src / ec / lenovo / h8 / h8.c
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
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
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"
28
29 void h8_trackpoint_enable(int on)
30 {
31         ec_write(H8_TRACKPOINT_CTRL,
32                  on ? H8_TRACKPOINT_ON : H8_TRACKPOINT_OFF);
33
34 }
35
36 void h8_wlan_enable(int on)
37 {
38         if (on)
39                 ec_set_bit(0x3a, 5);
40         else
41                 ec_clr_bit(0x3a, 5);
42 }
43
44 static void h8_log_ec_version(void)
45 {
46         unsigned char ecfw[9], c;
47         u16 fwvh, fwvl;
48         int i;
49
50         for(i = 0; i < 8; i++) {
51                 c = ec_read(0xf0 + i);
52                 if (c < 0x20 || c > 0x7f)
53                         break;
54                 ecfw[i] = c;
55         }
56         ecfw[i] = '\0';
57
58         fwvh = ec_read(0xe9);
59         fwvl = ec_read(0xe8);
60
61         printk(BIOS_INFO, "EC Firmware ID %s, Version %d.%d%d%c\n", ecfw,
62                fwvh >> 4, fwvh & 0x0f, fwvl >> 4, 0x41 + (fwvl & 0xf));
63 }
64
65 void h8_set_audio_mute(int on)
66 {
67         if (on)
68                 ec_clr_bit(0x3a, 0);
69         else
70                 ec_set_bit(0x3a, 1);
71 }
72
73 void h8_enable_event(int event)
74 {
75         if (event < 0 || event > 127)
76                 return;
77
78         ec_set_bit(0x10 + (event >> 3), event & 7);
79 }
80
81 void h8_disable_event(int event)
82 {
83         if (event < 0 || event > 127)
84                 return;
85
86         ec_clr_bit(0x10 + (event >> 3), event & 7);
87
88 }
89
90 int h8_ultrabay_device_present(void)
91 {
92         return ec_read(H8_STATUS1) & 0x5 ? 0 : 1;
93 }
94
95 static void h8_enable(device_t dev)
96 {
97         struct ec_lenovo_h8_config *conf = dev->chip_info;
98         h8_log_ec_version();
99
100         ec_write(H8_CONFIG0, conf->config0);
101         ec_write(H8_CONFIG1, conf->config1);
102         ec_write(H8_CONFIG2, conf->config2);
103         ec_write(H8_CONFIG3, conf->config3);
104
105         ec_write(H8_SOUND_ENABLE0, conf->beepmask0);
106         ec_write(H8_SOUND_ENABLE1, conf->beepmask1);
107         ec_write(H8_SOUND_REPEAT, 0x00);
108
109         ec_write(0x10, conf->event0_enable);
110         ec_write(0x11, conf->event1_enable);
111         ec_write(0x12, conf->event2_enable);
112         ec_write(0x13, conf->event3_enable);
113         ec_write(0x14, conf->event4_enable);
114         ec_write(0x15, conf->event5_enable);
115         ec_write(0x16, conf->event6_enable);
116         ec_write(0x17, conf->event7_enable);
117         ec_write(0x18, conf->event8_enable);
118         ec_write(0x19, conf->event9_enable);
119         ec_write(0x1a, conf->eventa_enable);
120         ec_write(0x1b, conf->eventb_enable);
121         ec_write(0x1c, conf->eventc_enable);
122         ec_write(0x1d, conf->eventd_enable);
123         ec_write(0x1e, conf->evente_enable);
124         ec_write(0x1f, conf->eventf_enable);
125
126         ec_write(H8_FAN_CONTROL, H8_FAN_CONTROL_AUTO);
127         h8_wlan_enable(conf->wlan_enable);
128         h8_trackpoint_enable(conf->trackpoint_enable);
129
130 }
131
132 struct chip_operations ec_lenovo_h8_ops = {
133         CHIP_NAME("Lenovo H8 EC")
134         .enable_dev = h8_enable
135 };