1 /* SPDX-License-Identifier: GPL-2.0-only */
4 #include <console/console.h>
5 #include <device/device.h>
6 #include <device/pnp.h>
14 void pmh7_backlight_enable(int onoff
)
17 pmh7_register_set_bit(0x50, 5);
19 pmh7_register_clear_bit(0x50, 5);
22 void pmh7_dock_event_enable(int onoff
)
25 pmh7_register_set_bit(0x60, 3);
27 pmh7_register_clear_bit(0x60, 3);
30 void pmh7_touchpad_enable(int onoff
)
33 pmh7_register_clear_bit(0x51, 2);
35 pmh7_register_set_bit(0x51, 2);
38 void pmh7_trackpoint_enable(int onoff
)
41 pmh7_register_clear_bit(0x51, 0);
43 pmh7_register_set_bit(0x51, 0);
46 void pmh7_ultrabay_power_enable(int onoff
)
49 pmh7_register_clear_bit(0x62, 0);
51 pmh7_register_set_bit(0x62, 0);
54 void pmh7_dgpu_power_enable(int onoff
)
57 pmh7_register_clear_bit(0x50, 7); // DGPU_RST
58 pmh7_register_set_bit(0x50, 3); // DGPU_PWR
60 pmh7_register_set_bit(0x50, 7); // DGPU_RST
63 pmh7_register_clear_bit(0x50, 7); // DGPU_RST
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
)
78 val
= pmh7_register_read(reg
);
79 pmh7_register_write(reg
, val
| (1 << bit
));
82 void pmh7_register_clear_bit(int reg
, int bit
)
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
;
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
,