Uwe Hermann | 539500e | 2011-02-02 23:56:15 +0000 | [diff] [blame] | 1 | /* |
| 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. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
Paul Menzel | a46a712 | 2013-02-23 18:37:27 +0100 | [diff] [blame] | 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Uwe Hermann | 539500e | 2011-02-02 23:56:15 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
Sven Schnelle | 4a6c9d1 | 2011-02-01 10:44:26 +0000 | [diff] [blame] | 20 | #include <arch/io.h> |
| 21 | #include <console/console.h> |
Stefan Reinauer | 57879c9 | 2012-07-31 16:47:25 -0700 | [diff] [blame] | 22 | #ifndef __PRE_RAM__ |
| 23 | #ifndef __SMM__ |
Sven Schnelle | 4a6c9d1 | 2011-02-01 10:44:26 +0000 | [diff] [blame] | 24 | #include <device/device.h> |
| 25 | #include <device/pnp.h> |
Stefan Reinauer | 57879c9 | 2012-07-31 16:47:25 -0700 | [diff] [blame] | 26 | #endif |
| 27 | #endif |
Sven Schnelle | 4a6c9d1 | 2011-02-01 10:44:26 +0000 | [diff] [blame] | 28 | #include <stdlib.h> |
Sven Schnelle | 4a6c9d1 | 2011-02-01 10:44:26 +0000 | [diff] [blame] | 29 | #include "pmh7.h" |
Sven Schnelle | 1fa61eb | 2011-04-11 19:43:50 +0000 | [diff] [blame] | 30 | #include "chip.h" |
Sven Schnelle | 51e1bc3 | 2011-06-05 21:32:51 +0200 | [diff] [blame] | 31 | #include <pc80/mc146818rtc.h> |
Sven Schnelle | 1fa61eb | 2011-04-11 19:43:50 +0000 | [diff] [blame] | 32 | |
| 33 | void pmh7_backlight_enable(int onoff) |
| 34 | { |
| 35 | if (onoff) |
| 36 | pmh7_register_set_bit(0x50, 5); |
| 37 | else |
| 38 | pmh7_register_clear_bit(0x50, 5); |
| 39 | } |
Sven Schnelle | 4a6c9d1 | 2011-02-01 10:44:26 +0000 | [diff] [blame] | 40 | |
Sven Schnelle | 1b9d2ee | 2011-04-17 12:54:32 +0000 | [diff] [blame] | 41 | void pmh7_dock_event_enable(int onoff) |
| 42 | { |
| 43 | if (onoff) |
| 44 | pmh7_register_set_bit(0x60, 3); |
| 45 | else |
| 46 | pmh7_register_clear_bit(0x60, 3); |
| 47 | |
| 48 | } |
Sven Schnelle | 4fff74b | 2011-04-19 19:57:26 +0000 | [diff] [blame] | 49 | |
| 50 | void pmh7_touchpad_enable(int onoff) |
| 51 | { |
| 52 | if (onoff) |
| 53 | pmh7_register_clear_bit(0x51, 2); |
| 54 | else |
| 55 | pmh7_register_set_bit(0x51, 2); |
| 56 | } |
Sven Schnelle | bf9e930 | 2011-04-27 19:47:42 +0000 | [diff] [blame] | 57 | |
| 58 | void pmh7_ultrabay_power_enable(int onoff) |
| 59 | { |
| 60 | if (onoff) |
| 61 | pmh7_register_clear_bit(0x62, 0); |
| 62 | else |
| 63 | pmh7_register_set_bit(0x62, 0); |
| 64 | } |
| 65 | |
Sven Schnelle | 4a6c9d1 | 2011-02-01 10:44:26 +0000 | [diff] [blame] | 66 | void pmh7_register_set_bit(int reg, int bit) |
| 67 | { |
| 68 | char val; |
| 69 | |
| 70 | outb(reg, EC_LENOVO_PMH7_ADDR); |
| 71 | val = inb(EC_LENOVO_PMH7_DATA); |
| 72 | outb(reg, EC_LENOVO_PMH7_ADDR); |
| 73 | outb(val | (1 << bit), EC_LENOVO_PMH7_DATA); |
| 74 | } |
| 75 | |
| 76 | void pmh7_register_clear_bit(int reg, int bit) |
| 77 | { |
| 78 | char val; |
| 79 | |
| 80 | outb(reg, EC_LENOVO_PMH7_ADDR); |
| 81 | val = inb(EC_LENOVO_PMH7_DATA); |
| 82 | outb(reg, EC_LENOVO_PMH7_ADDR); |
| 83 | outb(val &= ~(1 << bit), EC_LENOVO_PMH7_DATA); |
| 84 | } |
| 85 | |
| 86 | char pmh7_register_read(int reg) |
| 87 | { |
| 88 | outb(reg, EC_LENOVO_PMH7_ADDR); |
| 89 | return inb(EC_LENOVO_PMH7_DATA); |
| 90 | } |
| 91 | |
| 92 | void pmh7_register_write(int reg, int val) |
| 93 | { |
| 94 | outb(reg, EC_LENOVO_PMH7_ADDR); |
| 95 | outb(val, EC_LENOVO_PMH7_DATA); |
| 96 | } |
| 97 | |
Sven Schnelle | b538110 | 2011-10-15 17:31:01 +0200 | [diff] [blame] | 98 | #ifndef __PRE_RAM__ |
| 99 | #ifndef __SMM__ |
Sven Schnelle | 4a6c9d1 | 2011-02-01 10:44:26 +0000 | [diff] [blame] | 100 | static void enable_dev(device_t dev) |
| 101 | { |
Sven Schnelle | 1fa61eb | 2011-04-11 19:43:50 +0000 | [diff] [blame] | 102 | struct ec_lenovo_pmh7_config *conf = dev->chip_info; |
Sven Schnelle | 4a6c9d1 | 2011-02-01 10:44:26 +0000 | [diff] [blame] | 103 | struct resource *resource; |
Sven Schnelle | 51e1bc3 | 2011-06-05 21:32:51 +0200 | [diff] [blame] | 104 | u8 val; |
Uwe Hermann | 539500e | 2011-02-02 23:56:15 +0000 | [diff] [blame] | 105 | |
Sven Schnelle | 4a6c9d1 | 2011-02-01 10:44:26 +0000 | [diff] [blame] | 106 | resource = new_resource(dev, EC_LENOVO_PMH7_INDEX); |
| 107 | resource->flags = IORESOURCE_IO | IORESOURCE_FIXED; |
| 108 | resource->base = EC_LENOVO_PMH7_BASE; |
| 109 | resource->size = 16; |
| 110 | resource->align = 5; |
| 111 | resource->gran = 5; |
Sven Schnelle | 1fa61eb | 2011-04-11 19:43:50 +0000 | [diff] [blame] | 112 | |
| 113 | pmh7_backlight_enable(conf->backlight_enable); |
Sven Schnelle | 1b9d2ee | 2011-04-17 12:54:32 +0000 | [diff] [blame] | 114 | pmh7_dock_event_enable(conf->dock_event_enable); |
Sven Schnelle | 51e1bc3 | 2011-06-05 21:32:51 +0200 | [diff] [blame] | 115 | |
Vladimir Serbinenko | 2c87668 | 2013-11-13 18:31:24 +0100 | [diff] [blame^] | 116 | if (get_option(&val, "touchpad") != CB_SUCCESS) |
| 117 | val = 1; |
| 118 | pmh7_touchpad_enable(val); |
Sven Schnelle | 4a6c9d1 | 2011-02-01 10:44:26 +0000 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | struct chip_operations ec_lenovo_pmh7_ops = { |
| 122 | CHIP_NAME("Lenovo Power Management Hardware Hub 7") |
| 123 | .enable_dev = enable_dev, |
| 124 | }; |
Sven Schnelle | b538110 | 2011-10-15 17:31:01 +0200 | [diff] [blame] | 125 | #endif |
| 126 | #endif |