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 |
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
Sven Schnelle | 4a6c9d1 | 2011-02-01 10:44:26 +0000 | [diff] [blame] | 20 | #include <arch/io.h> |
| 21 | #include <console/console.h> |
| 22 | #include <device/device.h> |
| 23 | #include <device/pnp.h> |
| 24 | #include <stdlib.h> |
Sven Schnelle | 4a6c9d1 | 2011-02-01 10:44:26 +0000 | [diff] [blame] | 25 | #include "pmh7.h" |
Sven Schnelle | 1fa61eb | 2011-04-11 19:43:50 +0000 | [diff] [blame] | 26 | #include "chip.h" |
| 27 | |
| 28 | void 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 Schnelle | 4a6c9d1 | 2011-02-01 10:44:26 +0000 | [diff] [blame] | 35 | |
Sven Schnelle | 1b9d2ee | 2011-04-17 12:54:32 +0000 | [diff] [blame] | 36 | void 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 Schnelle | 4fff74b | 2011-04-19 19:57:26 +0000 | [diff] [blame] | 44 | |
| 45 | void 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 Schnelle | bf9e930 | 2011-04-27 19:47:42 +0000 | [diff] [blame] | 52 | |
| 53 | void pmh7_ultrabay_power_enable(int onoff) |
| 54 | { |
| 55 | if (onoff) |
| 56 | pmh7_register_clear_bit(0x62, 0); |
| 57 | else |
| 58 | pmh7_register_set_bit(0x62, 0); |
| 59 | } |
| 60 | |
Sven Schnelle | 4a6c9d1 | 2011-02-01 10:44:26 +0000 | [diff] [blame] | 61 | void pmh7_register_set_bit(int reg, int bit) |
| 62 | { |
| 63 | char val; |
| 64 | |
| 65 | outb(reg, EC_LENOVO_PMH7_ADDR); |
| 66 | val = inb(EC_LENOVO_PMH7_DATA); |
| 67 | outb(reg, EC_LENOVO_PMH7_ADDR); |
| 68 | outb(val | (1 << bit), EC_LENOVO_PMH7_DATA); |
| 69 | } |
| 70 | |
| 71 | void pmh7_register_clear_bit(int reg, int bit) |
| 72 | { |
| 73 | char val; |
| 74 | |
| 75 | outb(reg, EC_LENOVO_PMH7_ADDR); |
| 76 | val = inb(EC_LENOVO_PMH7_DATA); |
| 77 | outb(reg, EC_LENOVO_PMH7_ADDR); |
| 78 | outb(val &= ~(1 << bit), EC_LENOVO_PMH7_DATA); |
| 79 | } |
| 80 | |
| 81 | char pmh7_register_read(int reg) |
| 82 | { |
| 83 | outb(reg, EC_LENOVO_PMH7_ADDR); |
| 84 | return inb(EC_LENOVO_PMH7_DATA); |
| 85 | } |
| 86 | |
| 87 | void pmh7_register_write(int reg, int val) |
| 88 | { |
| 89 | outb(reg, EC_LENOVO_PMH7_ADDR); |
| 90 | outb(val, EC_LENOVO_PMH7_DATA); |
| 91 | } |
| 92 | |
| 93 | static void enable_dev(device_t dev) |
| 94 | { |
Sven Schnelle | 1fa61eb | 2011-04-11 19:43:50 +0000 | [diff] [blame] | 95 | struct ec_lenovo_pmh7_config *conf = dev->chip_info; |
Sven Schnelle | 4a6c9d1 | 2011-02-01 10:44:26 +0000 | [diff] [blame] | 96 | struct resource *resource; |
Uwe Hermann | 539500e | 2011-02-02 23:56:15 +0000 | [diff] [blame] | 97 | |
Sven Schnelle | 4a6c9d1 | 2011-02-01 10:44:26 +0000 | [diff] [blame] | 98 | resource = new_resource(dev, EC_LENOVO_PMH7_INDEX); |
| 99 | resource->flags = IORESOURCE_IO | IORESOURCE_FIXED; |
| 100 | resource->base = EC_LENOVO_PMH7_BASE; |
| 101 | resource->size = 16; |
| 102 | resource->align = 5; |
| 103 | resource->gran = 5; |
Sven Schnelle | 1fa61eb | 2011-04-11 19:43:50 +0000 | [diff] [blame] | 104 | |
| 105 | pmh7_backlight_enable(conf->backlight_enable); |
Sven Schnelle | 1b9d2ee | 2011-04-17 12:54:32 +0000 | [diff] [blame] | 106 | pmh7_dock_event_enable(conf->dock_event_enable); |
Sven Schnelle | 4a6c9d1 | 2011-02-01 10:44:26 +0000 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | struct chip_operations ec_lenovo_pmh7_ops = { |
| 110 | CHIP_NAME("Lenovo Power Management Hardware Hub 7") |
| 111 | .enable_dev = enable_dev, |
| 112 | }; |