blob: d536d74c75f622fd157bfe8de99c378da7416921 [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
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
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>
Sven Schnelle4a6c9d12011-02-01 10:44:26 +000025#include "pmh7.h"
Sven Schnelle1fa61eb2011-04-11 19:43:50 +000026#include "chip.h"
27
28void pmh7_backlight_enable(int onoff)
29{
30 if (onoff)
31 pmh7_register_set_bit(0x50, 5);
32 else
33 pmh7_register_clear_bit(0x50, 5);
34}
Sven Schnelle4a6c9d12011-02-01 10:44:26 +000035
Sven Schnelle1b9d2ee2011-04-17 12:54:32 +000036void pmh7_dock_event_enable(int onoff)
37{
38 if (onoff)
39 pmh7_register_set_bit(0x60, 3);
40 else
41 pmh7_register_clear_bit(0x60, 3);
42
43}
Sven Schnelle4fff74b2011-04-19 19:57:26 +000044
45void pmh7_touchpad_enable(int onoff)
46{
47 if (onoff)
48 pmh7_register_clear_bit(0x51, 2);
49 else
50 pmh7_register_set_bit(0x51, 2);
51}
Sven Schnelle4a6c9d12011-02-01 10:44:26 +000052void pmh7_register_set_bit(int reg, int bit)
53{
54 char val;
55
56 outb(reg, EC_LENOVO_PMH7_ADDR);
57 val = inb(EC_LENOVO_PMH7_DATA);
58 outb(reg, EC_LENOVO_PMH7_ADDR);
59 outb(val | (1 << bit), EC_LENOVO_PMH7_DATA);
60}
61
62void pmh7_register_clear_bit(int reg, int bit)
63{
64 char val;
65
66 outb(reg, EC_LENOVO_PMH7_ADDR);
67 val = inb(EC_LENOVO_PMH7_DATA);
68 outb(reg, EC_LENOVO_PMH7_ADDR);
69 outb(val &= ~(1 << bit), EC_LENOVO_PMH7_DATA);
70}
71
72char pmh7_register_read(int reg)
73{
74 outb(reg, EC_LENOVO_PMH7_ADDR);
75 return inb(EC_LENOVO_PMH7_DATA);
76}
77
78void pmh7_register_write(int reg, int val)
79{
80 outb(reg, EC_LENOVO_PMH7_ADDR);
81 outb(val, EC_LENOVO_PMH7_DATA);
82}
83
84static void enable_dev(device_t dev)
85{
Sven Schnelle1fa61eb2011-04-11 19:43:50 +000086 struct ec_lenovo_pmh7_config *conf = dev->chip_info;
Sven Schnelle4a6c9d12011-02-01 10:44:26 +000087 struct resource *resource;
Uwe Hermann539500e2011-02-02 23:56:15 +000088
Sven Schnelle4a6c9d12011-02-01 10:44:26 +000089 resource = new_resource(dev, EC_LENOVO_PMH7_INDEX);
90 resource->flags = IORESOURCE_IO | IORESOURCE_FIXED;
91 resource->base = EC_LENOVO_PMH7_BASE;
92 resource->size = 16;
93 resource->align = 5;
94 resource->gran = 5;
Sven Schnelle1fa61eb2011-04-11 19:43:50 +000095
96 pmh7_backlight_enable(conf->backlight_enable);
Sven Schnelle1b9d2ee2011-04-17 12:54:32 +000097 pmh7_dock_event_enable(conf->dock_event_enable);
Sven Schnelle4a6c9d12011-02-01 10:44:26 +000098}
99
100struct chip_operations ec_lenovo_pmh7_ops = {
101 CHIP_NAME("Lenovo Power Management Hardware Hub 7")
102 .enable_dev = enable_dev,
103};