blob: 9607c83e52669460d55859b8c5c1ca61263e1156 [file] [log] [blame]
Uwe Hermann539500e2011-02-02 23:56:15 +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
Uwe Hermann539500e2011-02-02 23:56:15 +000018 */
19
Sven Schnelle4a6c9d12011-02-01 10:44:26 +000020#include <arch/io.h>
21#include <console/console.h>
Stefan Reinauer57879c92012-07-31 16:47:25 -070022#ifndef __PRE_RAM__
23#ifndef __SMM__
Sven Schnelle4a6c9d12011-02-01 10:44:26 +000024#include <device/device.h>
25#include <device/pnp.h>
Stefan Reinauer57879c92012-07-31 16:47:25 -070026#endif
27#endif
Sven Schnelle4a6c9d12011-02-01 10:44:26 +000028#include <stdlib.h>
Sven Schnelle4a6c9d12011-02-01 10:44:26 +000029#include "pmh7.h"
Sven Schnelle1fa61eb2011-04-11 19:43:50 +000030#include "chip.h"
Sven Schnelle51e1bc32011-06-05 21:32:51 +020031#include <pc80/mc146818rtc.h>
Sven Schnelle1fa61eb2011-04-11 19:43:50 +000032
33void pmh7_backlight_enable(int onoff)
34{
35 if (onoff)
36 pmh7_register_set_bit(0x50, 5);
37 else
38 pmh7_register_clear_bit(0x50, 5);
39}
Sven Schnelle4a6c9d12011-02-01 10:44:26 +000040
Sven Schnelle1b9d2ee2011-04-17 12:54:32 +000041void pmh7_dock_event_enable(int onoff)
42{
43 if (onoff)
44 pmh7_register_set_bit(0x60, 3);
45 else
46 pmh7_register_clear_bit(0x60, 3);
47
48}
Sven Schnelle4fff74b2011-04-19 19:57:26 +000049
50void pmh7_touchpad_enable(int onoff)
51{
52 if (onoff)
53 pmh7_register_clear_bit(0x51, 2);
54 else
55 pmh7_register_set_bit(0x51, 2);
56}
Sven Schnellebf9e9302011-04-27 19:47:42 +000057
58void pmh7_ultrabay_power_enable(int onoff)
59{
60 if (onoff)
61 pmh7_register_clear_bit(0x62, 0);
62 else
63 pmh7_register_set_bit(0x62, 0);
64}
65
Sven Schnelle4a6c9d12011-02-01 10:44:26 +000066void pmh7_register_set_bit(int reg, int bit)
67{
68 char val;
69
70 outb(reg, EC_LENOVO_PMH7_ADDR);
71 val = inb(EC_LENOVO_PMH7_DATA);
72 outb(reg, EC_LENOVO_PMH7_ADDR);
73 outb(val | (1 << bit), EC_LENOVO_PMH7_DATA);
74}
75
76void pmh7_register_clear_bit(int reg, int bit)
77{
78 char val;
79
80 outb(reg, EC_LENOVO_PMH7_ADDR);
81 val = inb(EC_LENOVO_PMH7_DATA);
82 outb(reg, EC_LENOVO_PMH7_ADDR);
83 outb(val &= ~(1 << bit), EC_LENOVO_PMH7_DATA);
84}
85
86char pmh7_register_read(int reg)
87{
88 outb(reg, EC_LENOVO_PMH7_ADDR);
89 return inb(EC_LENOVO_PMH7_DATA);
90}
91
92void pmh7_register_write(int reg, int val)
93{
94 outb(reg, EC_LENOVO_PMH7_ADDR);
95 outb(val, EC_LENOVO_PMH7_DATA);
96}
97
Sven Schnelleb5381102011-10-15 17:31:01 +020098#ifndef __PRE_RAM__
99#ifndef __SMM__
Sven Schnelle4a6c9d12011-02-01 10:44:26 +0000100static void enable_dev(device_t dev)
101{
Sven Schnelle1fa61eb2011-04-11 19:43:50 +0000102 struct ec_lenovo_pmh7_config *conf = dev->chip_info;
Sven Schnelle4a6c9d12011-02-01 10:44:26 +0000103 struct resource *resource;
Sven Schnelle51e1bc32011-06-05 21:32:51 +0200104 u8 val;
Uwe Hermann539500e2011-02-02 23:56:15 +0000105
Sven Schnelle4a6c9d12011-02-01 10:44:26 +0000106 resource = new_resource(dev, EC_LENOVO_PMH7_INDEX);
107 resource->flags = IORESOURCE_IO | IORESOURCE_FIXED;
108 resource->base = EC_LENOVO_PMH7_BASE;
109 resource->size = 16;
110 resource->align = 5;
111 resource->gran = 5;
Sven Schnelle1fa61eb2011-04-11 19:43:50 +0000112
113 pmh7_backlight_enable(conf->backlight_enable);
Sven Schnelle1b9d2ee2011-04-17 12:54:32 +0000114 pmh7_dock_event_enable(conf->dock_event_enable);
Sven Schnelle51e1bc32011-06-05 21:32:51 +0200115
Vladimir Serbinenko2c876682013-11-13 18:31:24 +0100116 if (get_option(&val, "touchpad") != CB_SUCCESS)
117 val = 1;
118 pmh7_touchpad_enable(val);
Sven Schnelle4a6c9d12011-02-01 10:44:26 +0000119}
120
121struct chip_operations ec_lenovo_pmh7_ops = {
122 CHIP_NAME("Lenovo Power Management Hardware Hub 7")
123 .enable_dev = enable_dev,
124};
Sven Schnelleb5381102011-10-15 17:31:01 +0200125#endif
126#endif