blob: b160fd0bc14ba1dc6018dc2a22dfae87a236ef86 [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.
Uwe Hermann539500e2011-02-02 23:56:15 +000014 */
15
Sven Schnelle4a6c9d12011-02-01 10:44:26 +000016#include <arch/io.h>
17#include <console/console.h>
18#include <device/device.h>
19#include <device/pnp.h>
20#include <stdlib.h>
Edward O'Callaghanb57fef92014-06-17 20:13:08 +100021#include <pc80/mc146818rtc.h>
22
Sven Schnelle4a6c9d12011-02-01 10:44:26 +000023#include "pmh7.h"
Sven Schnelle1fa61eb2011-04-11 19:43:50 +000024#include "chip.h"
25
26void pmh7_backlight_enable(int onoff)
27{
28 if (onoff)
29 pmh7_register_set_bit(0x50, 5);
30 else
31 pmh7_register_clear_bit(0x50, 5);
32}
Sven Schnelle4a6c9d12011-02-01 10:44:26 +000033
Sven Schnelle1b9d2ee2011-04-17 12:54:32 +000034void pmh7_dock_event_enable(int onoff)
35{
36 if (onoff)
37 pmh7_register_set_bit(0x60, 3);
38 else
39 pmh7_register_clear_bit(0x60, 3);
40
41}
Sven Schnelle4fff74b2011-04-19 19:57:26 +000042
43void pmh7_touchpad_enable(int onoff)
44{
45 if (onoff)
46 pmh7_register_clear_bit(0x51, 2);
47 else
48 pmh7_register_set_bit(0x51, 2);
49}
Sven Schnellebf9e9302011-04-27 19:47:42 +000050
Vladimir Serbinenkoeada34f2014-01-11 04:22:35 +010051void pmh7_trackpoint_enable(int onoff)
52{
53 if (onoff)
54 pmh7_register_clear_bit(0x51, 0);
55 else
56 pmh7_register_set_bit(0x51, 0);
57}
58
Sven Schnellebf9e9302011-04-27 19:47:42 +000059void pmh7_ultrabay_power_enable(int onoff)
60{
61 if (onoff)
62 pmh7_register_clear_bit(0x62, 0);
63 else
64 pmh7_register_set_bit(0x62, 0);
65}
66
Sven Schnelle4a6c9d12011-02-01 10:44:26 +000067void pmh7_register_set_bit(int reg, int bit)
68{
69 char val;
70
Alexander Couzens74ab0312018-08-17 18:36:56 +020071 val = pmh7_register_read(reg);
72 pmh7_register_write(reg, val | (1 << bit));
Sven Schnelle4a6c9d12011-02-01 10:44:26 +000073}
74
75void pmh7_register_clear_bit(int reg, int bit)
76{
77 char val;
78
Alexander Couzens74ab0312018-08-17 18:36:56 +020079 val = pmh7_register_read(reg);
80 pmh7_register_write(reg, val & ~(1 << bit));
Sven Schnelle4a6c9d12011-02-01 10:44:26 +000081}
82
83char pmh7_register_read(int reg)
84{
85 outb(reg, EC_LENOVO_PMH7_ADDR);
86 return inb(EC_LENOVO_PMH7_DATA);
87}
88
89void pmh7_register_write(int reg, int val)
90{
91 outb(reg, EC_LENOVO_PMH7_ADDR);
92 outb(val, EC_LENOVO_PMH7_DATA);
93}
94
Sven Schnelleb5381102011-10-15 17:31:01 +020095#ifndef __PRE_RAM__
96#ifndef __SMM__
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +110097static void enable_dev(struct device *dev)
Sven Schnelle4a6c9d12011-02-01 10:44:26 +000098{
Sven Schnelle1fa61eb2011-04-11 19:43:50 +000099 struct ec_lenovo_pmh7_config *conf = dev->chip_info;
Sven Schnelle4a6c9d12011-02-01 10:44:26 +0000100 struct resource *resource;
Sven Schnelle51e1bc32011-06-05 21:32:51 +0200101 u8 val;
Uwe Hermann539500e2011-02-02 23:56:15 +0000102
Sven Schnelle4a6c9d12011-02-01 10:44:26 +0000103 resource = new_resource(dev, EC_LENOVO_PMH7_INDEX);
104 resource->flags = IORESOURCE_IO | IORESOURCE_FIXED;
105 resource->base = EC_LENOVO_PMH7_BASE;
106 resource->size = 16;
107 resource->align = 5;
108 resource->gran = 5;
Sven Schnelle1fa61eb2011-04-11 19:43:50 +0000109
110 pmh7_backlight_enable(conf->backlight_enable);
Sven Schnelle1b9d2ee2011-04-17 12:54:32 +0000111 pmh7_dock_event_enable(conf->dock_event_enable);
Sven Schnelle51e1bc32011-06-05 21:32:51 +0200112
Vladimir Serbinenko2c876682013-11-13 18:31:24 +0100113 if (get_option(&val, "touchpad") != CB_SUCCESS)
114 val = 1;
115 pmh7_touchpad_enable(val);
Vladimir Serbinenkoeada34f2014-01-11 04:22:35 +0100116
117 if (get_option(&val, "trackpoint") != CB_SUCCESS)
118 val = 1;
119 pmh7_trackpoint_enable(val);
Patrick Rudolph3b0f5422017-07-28 17:34:49 +0200120
121 printk(BIOS_INFO, "PMH7: ID %02x Revision %02x\n",
122 pmh7_register_read(EC_LENOVO_PMH7_REG_ID),
123 pmh7_register_read(EC_LENOVO_PMH7_REG_REV));
Sven Schnelle4a6c9d12011-02-01 10:44:26 +0000124}
125
126struct chip_operations ec_lenovo_pmh7_ops = {
127 CHIP_NAME("Lenovo Power Management Hardware Hub 7")
128 .enable_dev = enable_dev,
129};
Sven Schnelleb5381102011-10-15 17:31:01 +0200130#endif
131#endif