Angel Pons | 210a008 | 2020-04-02 23:48:24 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Uwe Hermann | 539500e | 2011-02-02 23:56:15 +0000 | [diff] [blame] | 2 | |
Sven Schnelle | 4a6c9d1 | 2011-02-01 10:44:26 +0000 | [diff] [blame] | 3 | #include <arch/io.h> |
| 4 | #include <console/console.h> |
| 5 | #include <device/device.h> |
| 6 | #include <device/pnp.h> |
Kyösti Mälkki | cbf9571 | 2020-01-05 08:05:45 +0200 | [diff] [blame] | 7 | #include <option.h> |
Evgeny Zinoviev | 384e9ae | 2018-08-30 02:18:48 +0300 | [diff] [blame] | 8 | #include <delay.h> |
Elyes HAOUAS | 5fd93e0 | 2019-05-15 21:07:30 +0200 | [diff] [blame] | 9 | #include <types.h> |
Edward O'Callaghan | b57fef9 | 2014-06-17 20:13:08 +1000 | [diff] [blame] | 10 | |
Sven Schnelle | 4a6c9d1 | 2011-02-01 10:44:26 +0000 | [diff] [blame] | 11 | #include "pmh7.h" |
Sven Schnelle | 1fa61eb | 2011-04-11 19:43:50 +0000 | [diff] [blame] | 12 | #include "chip.h" |
| 13 | |
| 14 | void pmh7_backlight_enable(int onoff) |
| 15 | { |
| 16 | if (onoff) |
| 17 | pmh7_register_set_bit(0x50, 5); |
| 18 | else |
| 19 | pmh7_register_clear_bit(0x50, 5); |
| 20 | } |
Sven Schnelle | 4a6c9d1 | 2011-02-01 10:44:26 +0000 | [diff] [blame] | 21 | |
Sven Schnelle | 1b9d2ee | 2011-04-17 12:54:32 +0000 | [diff] [blame] | 22 | void pmh7_dock_event_enable(int onoff) |
| 23 | { |
| 24 | if (onoff) |
| 25 | pmh7_register_set_bit(0x60, 3); |
| 26 | else |
| 27 | pmh7_register_clear_bit(0x60, 3); |
Sven Schnelle | 1b9d2ee | 2011-04-17 12:54:32 +0000 | [diff] [blame] | 28 | } |
Sven Schnelle | 4fff74b | 2011-04-19 19:57:26 +0000 | [diff] [blame] | 29 | |
| 30 | void pmh7_touchpad_enable(int onoff) |
| 31 | { |
| 32 | if (onoff) |
| 33 | pmh7_register_clear_bit(0x51, 2); |
| 34 | else |
| 35 | pmh7_register_set_bit(0x51, 2); |
| 36 | } |
Sven Schnelle | bf9e930 | 2011-04-27 19:47:42 +0000 | [diff] [blame] | 37 | |
Vladimir Serbinenko | eada34f | 2014-01-11 04:22:35 +0100 | [diff] [blame] | 38 | void pmh7_trackpoint_enable(int onoff) |
| 39 | { |
| 40 | if (onoff) |
| 41 | pmh7_register_clear_bit(0x51, 0); |
| 42 | else |
| 43 | pmh7_register_set_bit(0x51, 0); |
| 44 | } |
| 45 | |
Sven Schnelle | bf9e930 | 2011-04-27 19:47:42 +0000 | [diff] [blame] | 46 | void pmh7_ultrabay_power_enable(int onoff) |
| 47 | { |
| 48 | if (onoff) |
| 49 | pmh7_register_clear_bit(0x62, 0); |
| 50 | else |
| 51 | pmh7_register_set_bit(0x62, 0); |
| 52 | } |
| 53 | |
Evgeny Zinoviev | 384e9ae | 2018-08-30 02:18:48 +0300 | [diff] [blame] | 54 | void pmh7_dgpu_power_enable(int onoff) |
| 55 | { |
| 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 |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | bool pmh7_dgpu_power_state(void) |
| 70 | { |
| 71 | return (pmh7_register_read(0x50) & 0x08) == 8; |
| 72 | } |
| 73 | |
Sven Schnelle | 4a6c9d1 | 2011-02-01 10:44:26 +0000 | [diff] [blame] | 74 | void pmh7_register_set_bit(int reg, int bit) |
| 75 | { |
| 76 | char val; |
| 77 | |
Alexander Couzens | 74ab031 | 2018-08-17 18:36:56 +0200 | [diff] [blame] | 78 | val = pmh7_register_read(reg); |
| 79 | pmh7_register_write(reg, val | (1 << bit)); |
Sven Schnelle | 4a6c9d1 | 2011-02-01 10:44:26 +0000 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | void pmh7_register_clear_bit(int reg, int bit) |
| 83 | { |
| 84 | char val; |
| 85 | |
Alexander Couzens | 74ab031 | 2018-08-17 18:36:56 +0200 | [diff] [blame] | 86 | val = pmh7_register_read(reg); |
| 87 | pmh7_register_write(reg, val & ~(1 << bit)); |
Sven Schnelle | 4a6c9d1 | 2011-02-01 10:44:26 +0000 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | char pmh7_register_read(int reg) |
| 91 | { |
Alexander Couzens | 86b8d17 | 2018-08-17 18:47:52 +0200 | [diff] [blame] | 92 | outb(reg & 0xff, EC_LENOVO_PMH7_ADDR_L); |
| 93 | outb((reg & 0xff00) >> 8, EC_LENOVO_PMH7_ADDR_H); |
Sven Schnelle | 4a6c9d1 | 2011-02-01 10:44:26 +0000 | [diff] [blame] | 94 | return inb(EC_LENOVO_PMH7_DATA); |
| 95 | } |
| 96 | |
| 97 | void pmh7_register_write(int reg, int val) |
| 98 | { |
Alexander Couzens | 86b8d17 | 2018-08-17 18:47:52 +0200 | [diff] [blame] | 99 | outb(reg & 0xff, EC_LENOVO_PMH7_ADDR_L); |
| 100 | outb((reg & 0xff00) >> 8, EC_LENOVO_PMH7_ADDR_H); |
Sven Schnelle | 4a6c9d1 | 2011-02-01 10:44:26 +0000 | [diff] [blame] | 101 | outb(val, EC_LENOVO_PMH7_DATA); |
| 102 | } |
| 103 | |
Edward O'Callaghan | 2c9d2cf | 2014-10-27 23:29:29 +1100 | [diff] [blame] | 104 | static void enable_dev(struct device *dev) |
Sven Schnelle | 4a6c9d1 | 2011-02-01 10:44:26 +0000 | [diff] [blame] | 105 | { |
Kyösti Mälkki | e405c27 | 2019-08-17 05:28:38 +0300 | [diff] [blame] | 106 | const struct ec_lenovo_pmh7_config *conf = dev->chip_info; |
Sven Schnelle | 4a6c9d1 | 2011-02-01 10:44:26 +0000 | [diff] [blame] | 107 | struct resource *resource; |
Uwe Hermann | 539500e | 2011-02-02 23:56:15 +0000 | [diff] [blame] | 108 | |
Sven Schnelle | 4a6c9d1 | 2011-02-01 10:44:26 +0000 | [diff] [blame] | 109 | resource = new_resource(dev, EC_LENOVO_PMH7_INDEX); |
| 110 | resource->flags = IORESOURCE_IO | IORESOURCE_FIXED; |
| 111 | resource->base = EC_LENOVO_PMH7_BASE; |
| 112 | resource->size = 16; |
| 113 | resource->align = 5; |
| 114 | resource->gran = 5; |
Sven Schnelle | 1fa61eb | 2011-04-11 19:43:50 +0000 | [diff] [blame] | 115 | |
| 116 | pmh7_backlight_enable(conf->backlight_enable); |
Sven Schnelle | 1b9d2ee | 2011-04-17 12:54:32 +0000 | [diff] [blame] | 117 | pmh7_dock_event_enable(conf->dock_event_enable); |
Sven Schnelle | 51e1bc3 | 2011-06-05 21:32:51 +0200 | [diff] [blame] | 118 | |
Angel Pons | 88dcb31 | 2021-04-26 17:10:28 +0200 | [diff] [blame] | 119 | pmh7_touchpad_enable(get_uint_option("touchpad", 1)); |
Vladimir Serbinenko | eada34f | 2014-01-11 04:22:35 +0100 | [diff] [blame] | 120 | |
Angel Pons | 88dcb31 | 2021-04-26 17:10:28 +0200 | [diff] [blame] | 121 | pmh7_trackpoint_enable(get_uint_option("trackpoint", 1)); |
Patrick Rudolph | 3b0f542 | 2017-07-28 17:34:49 +0200 | [diff] [blame] | 122 | |
| 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)); |
Sven Schnelle | 4a6c9d1 | 2011-02-01 10:44:26 +0000 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | struct chip_operations ec_lenovo_pmh7_ops = { |
| 129 | CHIP_NAME("Lenovo Power Management Hardware Hub 7") |
| 130 | .enable_dev = enable_dev, |
| 131 | }; |