Stefan Reinauer | 1a08f58 | 2009-10-28 16:52:48 +0000 | [diff] [blame] | 1 | /* |
Uwe Hermann | 2d2f0c1 | 2009-10-28 17:36:11 +0000 | [diff] [blame^] | 2 | * This file is part of the coreboot project. |
Stefan Reinauer | 1a08f58 | 2009-10-28 16:52:48 +0000 | [diff] [blame] | 3 | * |
Uwe Hermann | 2d2f0c1 | 2009-10-28 17:36:11 +0000 | [diff] [blame^] | 4 | * Copyright (C) 2009 coresystems GmbH |
Stefan Reinauer | 1a08f58 | 2009-10-28 16:52:48 +0000 | [diff] [blame] | 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 |
Uwe Hermann | 2d2f0c1 | 2009-10-28 17:36:11 +0000 | [diff] [blame^] | 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Stefan Reinauer | 1a08f58 | 2009-10-28 16:52:48 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
Uwe Hermann | 2d2f0c1 | 2009-10-28 17:36:11 +0000 | [diff] [blame^] | 20 | /* RAM driver for the SMSC LPC47M15X Super I/O chip */ |
| 21 | |
Stefan Reinauer | 1a08f58 | 2009-10-28 16:52:48 +0000 | [diff] [blame] | 22 | #include <arch/io.h> |
| 23 | #include <device/device.h> |
| 24 | #include <device/pnp.h> |
| 25 | #include <console/console.h> |
| 26 | #include <device/smbus.h> |
| 27 | #include <string.h> |
| 28 | #include <bitops.h> |
| 29 | #include <uart8250.h> |
| 30 | #include <pc80/keyboard.h> |
| 31 | #include <stdlib.h> |
| 32 | #include "chip.h" |
| 33 | #include "lpc47m15x.h" |
| 34 | |
| 35 | // Forward declarations |
| 36 | static void enable_dev(device_t dev); |
| 37 | void lpc47m15x_pnp_set_resources(device_t dev); |
| 38 | void lpc47m15x_pnp_set_resources(device_t dev); |
| 39 | void lpc47m15x_pnp_enable_resources(device_t dev); |
| 40 | void lpc47m15x_pnp_enable(device_t dev); |
| 41 | static void lpc47m15x_init(device_t dev); |
| 42 | |
| 43 | static void pnp_enter_conf_state(device_t dev); |
| 44 | static void pnp_exit_conf_state(device_t dev); |
| 45 | static void dump_pnp_device(device_t dev); |
| 46 | |
| 47 | |
| 48 | struct chip_operations superio_smsc_lpc47m15x_ops = { |
| 49 | CHIP_NAME("SMSC LPC47M15x/192/997 Super I/O") |
| 50 | .enable_dev = enable_dev |
| 51 | }; |
| 52 | |
| 53 | static struct device_operations ops = { |
| 54 | .read_resources = pnp_read_resources, |
| 55 | .set_resources = lpc47m15x_pnp_set_resources, |
| 56 | .enable_resources = lpc47m15x_pnp_enable_resources, |
| 57 | .enable = lpc47m15x_pnp_enable, |
| 58 | .init = lpc47m15x_init, |
| 59 | }; |
| 60 | |
| 61 | static struct pnp_info pnp_dev_info[] = { |
| 62 | { &ops, LPC47M15X_FDC, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, { 0x07f8, 0}, }, |
| 63 | { &ops, LPC47M15X_PP, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, { 0x07f8, 0}, }, |
| 64 | { &ops, LPC47M15X_SP1, PNP_IO0 | PNP_IRQ0, { 0x7f8, 0 }, }, |
| 65 | { &ops, LPC47M15X_SP2, PNP_IO0 | PNP_IRQ0, { 0x7f8, 0 }, }, |
| 66 | { &ops, LPC47M15X_KBC, PNP_IO0 | PNP_IO1 | PNP_IRQ0 | PNP_IRQ1, { 0x7ff, 0 }, { 0x7ff, 0x4}, }, |
| 67 | }; |
| 68 | |
| 69 | static void enable_dev(device_t dev) |
| 70 | { |
| 71 | pnp_enable_devices(dev, &pnp_ops, ARRAY_SIZE(pnp_dev_info), pnp_dev_info); |
| 72 | } |
| 73 | |
| 74 | void lpc47m15x_pnp_set_resources(device_t dev) |
| 75 | { |
| 76 | pnp_enter_conf_state(dev); |
| 77 | pnp_set_resources(dev); |
| 78 | pnp_exit_conf_state(dev); |
| 79 | } |
| 80 | |
| 81 | void lpc47m15x_pnp_enable_resources(device_t dev) |
| 82 | { |
| 83 | pnp_enter_conf_state(dev); |
| 84 | pnp_enable_resources(dev); |
| 85 | pnp_exit_conf_state(dev); |
| 86 | } |
| 87 | |
| 88 | void lpc47m15x_pnp_enable(device_t dev) |
| 89 | { |
| 90 | pnp_enter_conf_state(dev); |
| 91 | pnp_set_logical_device(dev); |
| 92 | |
| 93 | if(dev->enabled) { |
| 94 | pnp_set_enable(dev, 1); |
| 95 | } |
| 96 | else { |
| 97 | pnp_set_enable(dev, 0); |
| 98 | } |
| 99 | pnp_exit_conf_state(dev); |
| 100 | } |
| 101 | |
| 102 | static void lpc47m15x_init(device_t dev) |
| 103 | { |
| 104 | struct superio_smsc_lpc47m15x_config *conf = dev->chip_info; |
| 105 | struct resource *res0, *res1; |
| 106 | |
| 107 | if (!dev->enabled) |
| 108 | return; |
| 109 | |
| 110 | switch(dev->path.pnp.device) { |
| 111 | case LPC47M15X_SP1: |
| 112 | res0 = find_resource(dev, PNP_IDX_IO0); |
| 113 | init_uart8250(res0->base, &conf->com1); |
| 114 | break; |
| 115 | |
| 116 | case LPC47M15X_SP2: |
| 117 | res0 = find_resource(dev, PNP_IDX_IO0); |
| 118 | init_uart8250(res0->base, &conf->com2); |
| 119 | break; |
| 120 | |
| 121 | case LPC47M15X_KBC: |
| 122 | res0 = find_resource(dev, PNP_IDX_IO0); |
| 123 | res1 = find_resource(dev, PNP_IDX_IO1); |
| 124 | pc_keyboard_init(&conf->keyboard); |
| 125 | break; |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | static void pnp_enter_conf_state(device_t dev) |
| 130 | { |
| 131 | outb(0x55, dev->path.pnp.port); |
| 132 | } |
| 133 | |
| 134 | static void pnp_exit_conf_state(device_t dev) |
| 135 | { |
| 136 | outb(0xaa, dev->path.pnp.port); |
| 137 | } |
| 138 | |