ec/starlabs/merlin: Remove unused variant directories
[coreboot.git] / src / ec / lenovo / pmh7 / pmh7.c
blob95502f3d8890191433a18856d627e89c7c9eb394
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <arch/io.h>
4 #include <console/console.h>
5 #include <device/device.h>
6 #include <device/pnp.h>
7 #include <option.h>
8 #include <delay.h>
9 #include <types.h>
11 #include "pmh7.h"
12 #include "chip.h"
14 void pmh7_backlight_enable(int onoff)
16 if (onoff)
17 pmh7_register_set_bit(0x50, 5);
18 else
19 pmh7_register_clear_bit(0x50, 5);
22 void pmh7_dock_event_enable(int onoff)
24 if (onoff)
25 pmh7_register_set_bit(0x60, 3);
26 else
27 pmh7_register_clear_bit(0x60, 3);
30 void pmh7_touchpad_enable(int onoff)
32 if (onoff)
33 pmh7_register_clear_bit(0x51, 2);
34 else
35 pmh7_register_set_bit(0x51, 2);
38 void pmh7_trackpoint_enable(int onoff)
40 if (onoff)
41 pmh7_register_clear_bit(0x51, 0);
42 else
43 pmh7_register_set_bit(0x51, 0);
46 void pmh7_ultrabay_power_enable(int onoff)
48 if (onoff)
49 pmh7_register_clear_bit(0x62, 0);
50 else
51 pmh7_register_set_bit(0x62, 0);
54 void pmh7_dgpu_power_enable(int onoff)
56 if (onoff) {
57 pmh7_register_clear_bit(0x50, 7); // DGPU_RST
58 pmh7_register_set_bit(0x50, 3); // DGPU_PWR
59 mdelay(10);
60 pmh7_register_set_bit(0x50, 7); // DGPU_RST
61 mdelay(50);
62 } else {
63 pmh7_register_clear_bit(0x50, 7); // DGPU_RST
64 udelay(100);
65 pmh7_register_clear_bit(0x50, 3); // DGPU_PWR
69 bool pmh7_dgpu_power_state(void)
71 return (pmh7_register_read(0x50) & 0x08) == 8;
74 void pmh7_register_set_bit(int reg, int bit)
76 char val;
78 val = pmh7_register_read(reg);
79 pmh7_register_write(reg, val | (1 << bit));
82 void pmh7_register_clear_bit(int reg, int bit)
84 char val;
86 val = pmh7_register_read(reg);
87 pmh7_register_write(reg, val & ~(1 << bit));
90 char pmh7_register_read(int reg)
92 outb(reg & 0xff, EC_LENOVO_PMH7_ADDR_L);
93 outb((reg & 0xff00) >> 8, EC_LENOVO_PMH7_ADDR_H);
94 return inb(EC_LENOVO_PMH7_DATA);
97 void pmh7_register_write(int reg, int val)
99 outb(reg & 0xff, EC_LENOVO_PMH7_ADDR_L);
100 outb((reg & 0xff00) >> 8, EC_LENOVO_PMH7_ADDR_H);
101 outb(val, EC_LENOVO_PMH7_DATA);
104 static void enable_dev(struct device *dev)
106 const struct ec_lenovo_pmh7_config *conf = dev->chip_info;
107 struct resource *resource;
109 resource = new_resource(dev, EC_LENOVO_PMH7_INDEX);
110 resource->base = EC_LENOVO_PMH7_BASE;
111 resource->size = 16;
112 resource->align = 5;
113 resource->gran = 5;
114 resource->flags = IORESOURCE_IO | IORESOURCE_FIXED | IORESOURCE_ASSIGNED;
116 pmh7_backlight_enable(conf->backlight_enable);
117 pmh7_dock_event_enable(conf->dock_event_enable);
119 pmh7_touchpad_enable(get_uint_option("touchpad", 1));
121 pmh7_trackpoint_enable(get_uint_option("trackpoint", 1));
123 printk(BIOS_INFO, "PMH7: ID %02x Revision %02x\n",
124 pmh7_register_read(EC_LENOVO_PMH7_REG_ID),
125 pmh7_register_read(EC_LENOVO_PMH7_REG_REV));
128 struct chip_operations ec_lenovo_pmh7_ops = {
129 .name = "Lenovo Power Management Hardware Hub 7",
130 .enable_dev = enable_dev,