blob: ef505cd164d5f8e19aac408bfbf5e106735b3662 [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>
Evgeny Zinoviev384e9ae2018-08-30 02:18:48 +030022#include <delay.h>
Elyes HAOUAS5fd93e02019-05-15 21:07:30 +020023#include <types.h>
Edward O'Callaghanb57fef92014-06-17 20:13:08 +100024
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 Schnellebf9e9302011-04-27 19:47:42 +000052
Vladimir Serbinenkoeada34f2014-01-11 04:22:35 +010053void pmh7_trackpoint_enable(int onoff)
54{
55 if (onoff)
56 pmh7_register_clear_bit(0x51, 0);
57 else
58 pmh7_register_set_bit(0x51, 0);
59}
60
Sven Schnellebf9e9302011-04-27 19:47:42 +000061void pmh7_ultrabay_power_enable(int onoff)
62{
63 if (onoff)
64 pmh7_register_clear_bit(0x62, 0);
65 else
66 pmh7_register_set_bit(0x62, 0);
67}
68
Evgeny Zinoviev384e9ae2018-08-30 02:18:48 +030069void pmh7_dgpu_power_enable(int onoff)
70{
71 if (onoff) {
72 pmh7_register_clear_bit(0x50, 7); // DGPU_RST
73 pmh7_register_set_bit(0x50, 3); // DGPU_PWR
74 mdelay(10);
75 pmh7_register_set_bit(0x50, 7); // DGPU_RST
76 mdelay(50);
77 } else {
78 pmh7_register_clear_bit(0x50, 7); // DGPU_RST
79 udelay(100);
80 pmh7_register_clear_bit(0x50, 3); // DGPU_PWR
81 }
82}
83
84bool pmh7_dgpu_power_state(void)
85{
86 return (pmh7_register_read(0x50) & 0x08) == 8;
87}
88
Sven Schnelle4a6c9d12011-02-01 10:44:26 +000089void pmh7_register_set_bit(int reg, int bit)
90{
91 char val;
92
Alexander Couzens74ab0312018-08-17 18:36:56 +020093 val = pmh7_register_read(reg);
94 pmh7_register_write(reg, val | (1 << bit));
Sven Schnelle4a6c9d12011-02-01 10:44:26 +000095}
96
97void pmh7_register_clear_bit(int reg, int bit)
98{
99 char val;
100
Alexander Couzens74ab0312018-08-17 18:36:56 +0200101 val = pmh7_register_read(reg);
102 pmh7_register_write(reg, val & ~(1 << bit));
Sven Schnelle4a6c9d12011-02-01 10:44:26 +0000103}
104
105char pmh7_register_read(int reg)
106{
Alexander Couzens86b8d172018-08-17 18:47:52 +0200107 outb(reg & 0xff, EC_LENOVO_PMH7_ADDR_L);
108 outb((reg & 0xff00) >> 8, EC_LENOVO_PMH7_ADDR_H);
Sven Schnelle4a6c9d12011-02-01 10:44:26 +0000109 return inb(EC_LENOVO_PMH7_DATA);
110}
111
112void pmh7_register_write(int reg, int val)
113{
Alexander Couzens86b8d172018-08-17 18:47:52 +0200114 outb(reg & 0xff, EC_LENOVO_PMH7_ADDR_L);
115 outb((reg & 0xff00) >> 8, EC_LENOVO_PMH7_ADDR_H);
Sven Schnelle4a6c9d12011-02-01 10:44:26 +0000116 outb(val, EC_LENOVO_PMH7_DATA);
117}
118
Sven Schnelleb5381102011-10-15 17:31:01 +0200119#ifndef __PRE_RAM__
120#ifndef __SMM__
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +1100121static void enable_dev(struct device *dev)
Sven Schnelle4a6c9d12011-02-01 10:44:26 +0000122{
Sven Schnelle1fa61eb2011-04-11 19:43:50 +0000123 struct ec_lenovo_pmh7_config *conf = dev->chip_info;
Sven Schnelle4a6c9d12011-02-01 10:44:26 +0000124 struct resource *resource;
Sven Schnelle51e1bc32011-06-05 21:32:51 +0200125 u8 val;
Uwe Hermann539500e2011-02-02 23:56:15 +0000126
Sven Schnelle4a6c9d12011-02-01 10:44:26 +0000127 resource = new_resource(dev, EC_LENOVO_PMH7_INDEX);
128 resource->flags = IORESOURCE_IO | IORESOURCE_FIXED;
129 resource->base = EC_LENOVO_PMH7_BASE;
130 resource->size = 16;
131 resource->align = 5;
132 resource->gran = 5;
Sven Schnelle1fa61eb2011-04-11 19:43:50 +0000133
134 pmh7_backlight_enable(conf->backlight_enable);
Sven Schnelle1b9d2ee2011-04-17 12:54:32 +0000135 pmh7_dock_event_enable(conf->dock_event_enable);
Sven Schnelle51e1bc32011-06-05 21:32:51 +0200136
Vladimir Serbinenko2c876682013-11-13 18:31:24 +0100137 if (get_option(&val, "touchpad") != CB_SUCCESS)
138 val = 1;
139 pmh7_touchpad_enable(val);
Vladimir Serbinenkoeada34f2014-01-11 04:22:35 +0100140
141 if (get_option(&val, "trackpoint") != CB_SUCCESS)
142 val = 1;
143 pmh7_trackpoint_enable(val);
Patrick Rudolph3b0f5422017-07-28 17:34:49 +0200144
145 printk(BIOS_INFO, "PMH7: ID %02x Revision %02x\n",
146 pmh7_register_read(EC_LENOVO_PMH7_REG_ID),
147 pmh7_register_read(EC_LENOVO_PMH7_REG_REV));
Sven Schnelle4a6c9d12011-02-01 10:44:26 +0000148}
149
150struct chip_operations ec_lenovo_pmh7_ops = {
151 CHIP_NAME("Lenovo Power Management Hardware Hub 7")
152 .enable_dev = enable_dev,
153};
Sven Schnelleb5381102011-10-15 17:31:01 +0200154#endif
155#endif