blob: f67fbda49e508aa43743f022008161c66f6261d4 [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>
22#include <device/device.h>
23#include <device/pnp.h>
24#include <stdlib.h>
Edward O'Callaghanb57fef92014-06-17 20:13:08 +100025#include <pc80/mc146818rtc.h>
26
Sven Schnelle4a6c9d12011-02-01 10:44:26 +000027#include "pmh7.h"
Sven Schnelle1fa61eb2011-04-11 19:43:50 +000028#include "chip.h"
29
30void pmh7_backlight_enable(int onoff)
31{
32 if (onoff)
33 pmh7_register_set_bit(0x50, 5);
34 else
35 pmh7_register_clear_bit(0x50, 5);
36}
Sven Schnelle4a6c9d12011-02-01 10:44:26 +000037
Sven Schnelle1b9d2ee2011-04-17 12:54:32 +000038void pmh7_dock_event_enable(int onoff)
39{
40 if (onoff)
41 pmh7_register_set_bit(0x60, 3);
42 else
43 pmh7_register_clear_bit(0x60, 3);
44
45}
Sven Schnelle4fff74b2011-04-19 19:57:26 +000046
47void pmh7_touchpad_enable(int onoff)
48{
49 if (onoff)
50 pmh7_register_clear_bit(0x51, 2);
51 else
52 pmh7_register_set_bit(0x51, 2);
53}
Sven Schnellebf9e9302011-04-27 19:47:42 +000054
Vladimir Serbinenkoeada34f2014-01-11 04:22:35 +010055void pmh7_trackpoint_enable(int onoff)
56{
57 if (onoff)
58 pmh7_register_clear_bit(0x51, 0);
59 else
60 pmh7_register_set_bit(0x51, 0);
61}
62
Sven Schnellebf9e9302011-04-27 19:47:42 +000063void pmh7_ultrabay_power_enable(int onoff)
64{
65 if (onoff)
66 pmh7_register_clear_bit(0x62, 0);
67 else
68 pmh7_register_set_bit(0x62, 0);
69}
70
Sven Schnelle4a6c9d12011-02-01 10:44:26 +000071void pmh7_register_set_bit(int reg, int bit)
72{
73 char val;
74
75 outb(reg, EC_LENOVO_PMH7_ADDR);
76 val = inb(EC_LENOVO_PMH7_DATA);
77 outb(reg, EC_LENOVO_PMH7_ADDR);
78 outb(val | (1 << bit), EC_LENOVO_PMH7_DATA);
79}
80
81void pmh7_register_clear_bit(int reg, int bit)
82{
83 char val;
84
85 outb(reg, EC_LENOVO_PMH7_ADDR);
86 val = inb(EC_LENOVO_PMH7_DATA);
87 outb(reg, EC_LENOVO_PMH7_ADDR);
88 outb(val &= ~(1 << bit), EC_LENOVO_PMH7_DATA);
89}
90
91char pmh7_register_read(int reg)
92{
93 outb(reg, EC_LENOVO_PMH7_ADDR);
94 return inb(EC_LENOVO_PMH7_DATA);
95}
96
97void pmh7_register_write(int reg, int val)
98{
99 outb(reg, EC_LENOVO_PMH7_ADDR);
100 outb(val, EC_LENOVO_PMH7_DATA);
101}
102
Sven Schnelleb5381102011-10-15 17:31:01 +0200103#ifndef __PRE_RAM__
104#ifndef __SMM__
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +1100105static void enable_dev(struct device *dev)
Sven Schnelle4a6c9d12011-02-01 10:44:26 +0000106{
Sven Schnelle1fa61eb2011-04-11 19:43:50 +0000107 struct ec_lenovo_pmh7_config *conf = dev->chip_info;
Sven Schnelle4a6c9d12011-02-01 10:44:26 +0000108 struct resource *resource;
Sven Schnelle51e1bc32011-06-05 21:32:51 +0200109 u8 val;
Uwe Hermann539500e2011-02-02 23:56:15 +0000110
Sven Schnelle4a6c9d12011-02-01 10:44:26 +0000111 resource = new_resource(dev, EC_LENOVO_PMH7_INDEX);
112 resource->flags = IORESOURCE_IO | IORESOURCE_FIXED;
113 resource->base = EC_LENOVO_PMH7_BASE;
114 resource->size = 16;
115 resource->align = 5;
116 resource->gran = 5;
Sven Schnelle1fa61eb2011-04-11 19:43:50 +0000117
118 pmh7_backlight_enable(conf->backlight_enable);
Sven Schnelle1b9d2ee2011-04-17 12:54:32 +0000119 pmh7_dock_event_enable(conf->dock_event_enable);
Sven Schnelle51e1bc32011-06-05 21:32:51 +0200120
Vladimir Serbinenko2c876682013-11-13 18:31:24 +0100121 if (get_option(&val, "touchpad") != CB_SUCCESS)
122 val = 1;
123 pmh7_touchpad_enable(val);
Vladimir Serbinenkoeada34f2014-01-11 04:22:35 +0100124
125 if (get_option(&val, "trackpoint") != CB_SUCCESS)
126 val = 1;
127 pmh7_trackpoint_enable(val);
Sven Schnelle4a6c9d12011-02-01 10:44:26 +0000128}
129
130struct chip_operations ec_lenovo_pmh7_ops = {
131 CHIP_NAME("Lenovo Power Management Hardware Hub 7")
132 .enable_dev = enable_dev,
133};
Sven Schnelleb5381102011-10-15 17:31:01 +0200134#endif
135#endif