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