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" |
| 26 | |
| 27 | void pmh7_register_set_bit(int reg, int bit) |
| 28 | { |
| 29 | char val; |
| 30 | |
| 31 | outb(reg, EC_LENOVO_PMH7_ADDR); |
| 32 | val = inb(EC_LENOVO_PMH7_DATA); |
| 33 | outb(reg, EC_LENOVO_PMH7_ADDR); |
| 34 | outb(val | (1 << bit), EC_LENOVO_PMH7_DATA); |
| 35 | } |
| 36 | |
| 37 | void pmh7_register_clear_bit(int reg, int bit) |
| 38 | { |
| 39 | char val; |
| 40 | |
| 41 | outb(reg, EC_LENOVO_PMH7_ADDR); |
| 42 | val = inb(EC_LENOVO_PMH7_DATA); |
| 43 | outb(reg, EC_LENOVO_PMH7_ADDR); |
| 44 | outb(val &= ~(1 << bit), EC_LENOVO_PMH7_DATA); |
| 45 | } |
| 46 | |
| 47 | char pmh7_register_read(int reg) |
| 48 | { |
| 49 | outb(reg, EC_LENOVO_PMH7_ADDR); |
| 50 | return inb(EC_LENOVO_PMH7_DATA); |
| 51 | } |
| 52 | |
| 53 | void pmh7_register_write(int reg, int val) |
| 54 | { |
| 55 | outb(reg, EC_LENOVO_PMH7_ADDR); |
| 56 | outb(val, EC_LENOVO_PMH7_DATA); |
| 57 | } |
| 58 | |
| 59 | static void enable_dev(device_t dev) |
| 60 | { |
| 61 | struct resource *resource; |
Uwe Hermann | 539500e | 2011-02-02 23:56:15 +0000 | [diff] [blame^] | 62 | |
Sven Schnelle | 4a6c9d1 | 2011-02-01 10:44:26 +0000 | [diff] [blame] | 63 | resource = new_resource(dev, EC_LENOVO_PMH7_INDEX); |
| 64 | resource->flags = IORESOURCE_IO | IORESOURCE_FIXED; |
| 65 | resource->base = EC_LENOVO_PMH7_BASE; |
| 66 | resource->size = 16; |
| 67 | resource->align = 5; |
| 68 | resource->gran = 5; |
Sven Schnelle | 4a6c9d1 | 2011-02-01 10:44:26 +0000 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | struct chip_operations ec_lenovo_pmh7_ops = { |
| 72 | CHIP_NAME("Lenovo Power Management Hardware Hub 7") |
| 73 | .enable_dev = enable_dev, |
| 74 | }; |