Stefan Reinauer | 55426df | 2010-01-17 13:50:17 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2005 Digital Design Corporation |
| 5 | * Copyright (C) 2008-2009 coresystems GmbH |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
Stefan Reinauer | 55426df | 2010-01-17 13:50:17 +0000 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | /* RAM-based driver for SMSC LPC47N227 Super I/O chip. */ |
| 18 | |
Stefan Reinauer | 55426df | 2010-01-17 13:50:17 +0000 | [diff] [blame] | 19 | #include <device/device.h> |
| 20 | #include <device/pnp.h> |
| 21 | #include <console/console.h> |
Stefan Reinauer | 55426df | 2010-01-17 13:50:17 +0000 | [diff] [blame] | 22 | #include <assert.h> |
Edward O'Callaghan | def00be | 2014-04-30 05:01:52 +1000 | [diff] [blame] | 23 | #include <pc80/keyboard.h> |
Antonello Dettori | 6321d7c | 2016-03-07 01:59:48 +0000 | [diff] [blame] | 24 | #include <superio/conf_mode.h> |
| 25 | |
Stefan Reinauer | 55426df | 2010-01-17 13:50:17 +0000 | [diff] [blame] | 26 | #include "lpc47n227.h" |
| 27 | |
Uwe Hermann | a69d978 | 2010-11-15 19:35:14 +0000 | [diff] [blame] | 28 | /* Forward declarations. */ |
Edward O'Callaghan | f21bdc3 | 2014-10-21 07:43:41 +1100 | [diff] [blame] | 29 | static void enable_dev(struct device *dev); |
| 30 | void lpc47n227_pnp_set_resources(struct device *dev); |
| 31 | void lpc47n227_pnp_enable_resources(struct device *dev); |
| 32 | void lpc47n227_pnp_enable(struct device *dev); |
| 33 | static void lpc47n227_init(struct device *dev); |
| 34 | static void lpc47n227_pnp_set_resource(struct device *dev, struct resource *resource); |
| 35 | void lpc47n227_pnp_set_iobase(struct device *dev, u16 iobase); |
| 36 | void lpc47n227_pnp_set_drq(struct device *dev, u8 drq); |
| 37 | void lpc47n227_pnp_set_irq(struct device *dev, u8 irq); |
| 38 | void lpc47n227_pnp_set_enable(struct device *dev, int enable); |
Stefan Reinauer | 55426df | 2010-01-17 13:50:17 +0000 | [diff] [blame] | 39 | |
| 40 | struct chip_operations superio_smsc_lpc47n227_ops = { |
| 41 | CHIP_NAME("SMSC LPC47N227 Super I/O") |
Uwe Hermann | a69d978 | 2010-11-15 19:35:14 +0000 | [diff] [blame] | 42 | .enable_dev = enable_dev, |
Stefan Reinauer | 55426df | 2010-01-17 13:50:17 +0000 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | static struct device_operations ops = { |
Uwe Hermann | a69d978 | 2010-11-15 19:35:14 +0000 | [diff] [blame] | 46 | .read_resources = pnp_read_resources, |
| 47 | .set_resources = lpc47n227_pnp_set_resources, |
Stefan Reinauer | 55426df | 2010-01-17 13:50:17 +0000 | [diff] [blame] | 48 | .enable_resources = lpc47n227_pnp_enable_resources, |
Uwe Hermann | a69d978 | 2010-11-15 19:35:14 +0000 | [diff] [blame] | 49 | .enable = lpc47n227_pnp_enable, |
| 50 | .init = lpc47n227_init, |
Patrick Rudolph | 98b72da | 2019-12-10 12:08:37 +0100 | [diff] [blame] | 51 | .ops_pnp_mode = &pnp_conf_mode_55_aa, |
Stefan Reinauer | 55426df | 2010-01-17 13:50:17 +0000 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | static struct pnp_info pnp_dev_info[] = { |
Felix Held | b0d868e | 2018-07-06 23:39:00 +0200 | [diff] [blame] | 55 | { NULL, LPC47N227_PP, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, 0x07f8, }, |
| 56 | { NULL, LPC47N227_SP1, PNP_IO0 | PNP_IRQ0, 0x07f8, }, |
| 57 | { NULL, LPC47N227_SP2, PNP_IO0 | PNP_IRQ0, 0x07f8, }, |
| 58 | { NULL, LPC47N227_KBDC, PNP_IO0 | PNP_IO1 | PNP_IRQ0, 0x07f8, 0x07f8, }, |
Stefan Reinauer | 55426df | 2010-01-17 13:50:17 +0000 | [diff] [blame] | 59 | }; |
| 60 | |
Uwe Hermann | b69cb5a | 2010-10-26 22:46:43 +0000 | [diff] [blame] | 61 | /** |
| 62 | * Create device structures and allocate resources to devices specified in the |
| 63 | * pnp_dev_info array (above). |
| 64 | * |
| 65 | * @param dev Pointer to structure describing a Super I/O device. |
| 66 | */ |
Edward O'Callaghan | f21bdc3 | 2014-10-21 07:43:41 +1100 | [diff] [blame] | 67 | static void enable_dev(struct device *dev) |
Stefan Reinauer | 55426df | 2010-01-17 13:50:17 +0000 | [diff] [blame] | 68 | { |
Felix Held | b0d868e | 2018-07-06 23:39:00 +0200 | [diff] [blame] | 69 | pnp_enable_devices(dev, &ops, ARRAY_SIZE(pnp_dev_info), pnp_dev_info); |
Stefan Reinauer | 55426df | 2010-01-17 13:50:17 +0000 | [diff] [blame] | 70 | } |
| 71 | |
Uwe Hermann | b69cb5a | 2010-10-26 22:46:43 +0000 | [diff] [blame] | 72 | /** |
| 73 | * Configure the specified Super I/O device with the resources (I/O space, |
| 74 | * etc.) that have been allocate for it. |
| 75 | * |
Uwe Hermann | a69d978 | 2010-11-15 19:35:14 +0000 | [diff] [blame] | 76 | * NOTE: Cannot use pnp_set_resources() here because it assumes chip |
| 77 | * support for logical devices, which the LPC47N227 doesn't have. |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 78 | * |
Uwe Hermann | b69cb5a | 2010-10-26 22:46:43 +0000 | [diff] [blame] | 79 | * @param dev Pointer to structure describing a Super I/O device. |
| 80 | */ |
Edward O'Callaghan | f21bdc3 | 2014-10-21 07:43:41 +1100 | [diff] [blame] | 81 | void lpc47n227_pnp_set_resources(struct device *dev) |
Stefan Reinauer | 55426df | 2010-01-17 13:50:17 +0000 | [diff] [blame] | 82 | { |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 83 | struct resource *res; |
Stefan Reinauer | 55426df | 2010-01-17 13:50:17 +0000 | [diff] [blame] | 84 | |
Patrick Rudolph | 98b72da | 2019-12-10 12:08:37 +0100 | [diff] [blame] | 85 | pnp_enter_conf_mode(dev); |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 86 | for (res = dev->resource_list; res; res = res->next) |
| 87 | lpc47n227_pnp_set_resource(dev, res); |
Patrick Rudolph | 98b72da | 2019-12-10 12:08:37 +0100 | [diff] [blame] | 88 | pnp_exit_conf_mode(dev); |
Stefan Reinauer | 55426df | 2010-01-17 13:50:17 +0000 | [diff] [blame] | 89 | } |
| 90 | |
Uwe Hermann | a69d978 | 2010-11-15 19:35:14 +0000 | [diff] [blame] | 91 | /* |
| 92 | * NOTE: Cannot use pnp_enable_resources() here because it assumes chip |
| 93 | * support for logical devices, which the LPC47N227 doesn't have. |
| 94 | */ |
Edward O'Callaghan | f21bdc3 | 2014-10-21 07:43:41 +1100 | [diff] [blame] | 95 | void lpc47n227_pnp_enable_resources(struct device *dev) |
Stefan Reinauer | 55426df | 2010-01-17 13:50:17 +0000 | [diff] [blame] | 96 | { |
Patrick Rudolph | 98b72da | 2019-12-10 12:08:37 +0100 | [diff] [blame] | 97 | pnp_enter_conf_mode(dev); |
Stefan Reinauer | 55426df | 2010-01-17 13:50:17 +0000 | [diff] [blame] | 98 | lpc47n227_pnp_set_enable(dev, 1); |
Patrick Rudolph | 98b72da | 2019-12-10 12:08:37 +0100 | [diff] [blame] | 99 | pnp_exit_conf_mode(dev); |
Stefan Reinauer | 55426df | 2010-01-17 13:50:17 +0000 | [diff] [blame] | 100 | } |
| 101 | |
Uwe Hermann | a69d978 | 2010-11-15 19:35:14 +0000 | [diff] [blame] | 102 | /* |
| 103 | * NOTE: Cannot use pnp_set_enable() here because it assumes chip |
| 104 | * support for logical devices, which the LPC47N227 doesn't have. |
| 105 | */ |
Edward O'Callaghan | f21bdc3 | 2014-10-21 07:43:41 +1100 | [diff] [blame] | 106 | void lpc47n227_pnp_enable(struct device *dev) |
Stefan Reinauer | 55426df | 2010-01-17 13:50:17 +0000 | [diff] [blame] | 107 | { |
Patrick Rudolph | 98b72da | 2019-12-10 12:08:37 +0100 | [diff] [blame] | 108 | pnp_enter_conf_mode(dev); |
Rudolf Marek | 0c8e664 | 2011-02-19 14:51:31 +0000 | [diff] [blame] | 109 | lpc47n227_pnp_set_enable(dev, !!dev->enabled); |
Patrick Rudolph | 98b72da | 2019-12-10 12:08:37 +0100 | [diff] [blame] | 110 | pnp_exit_conf_mode(dev); |
Stefan Reinauer | 55426df | 2010-01-17 13:50:17 +0000 | [diff] [blame] | 111 | } |
| 112 | |
Uwe Hermann | b69cb5a | 2010-10-26 22:46:43 +0000 | [diff] [blame] | 113 | /** |
| 114 | * Initialize the specified Super I/O device. |
| 115 | * |
| 116 | * Devices other than COM ports and keyboard controller are ignored. |
| 117 | * For COM ports, we configure the baud rate. |
| 118 | * |
| 119 | * @param dev Pointer to structure describing a Super I/O device. |
| 120 | */ |
Edward O'Callaghan | f21bdc3 | 2014-10-21 07:43:41 +1100 | [diff] [blame] | 121 | static void lpc47n227_init(struct device *dev) |
Stefan Reinauer | 55426df | 2010-01-17 13:50:17 +0000 | [diff] [blame] | 122 | { |
Stefan Reinauer | 55426df | 2010-01-17 13:50:17 +0000 | [diff] [blame] | 123 | |
| 124 | if (!dev->enabled) |
| 125 | return; |
| 126 | |
| 127 | switch (dev->path.pnp.device) { |
Stefan Reinauer | 55426df | 2010-01-17 13:50:17 +0000 | [diff] [blame] | 128 | case LPC47N227_KBDC: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 129 | printk(BIOS_DEBUG, "LPC47N227: Initializing keyboard.\n"); |
Timothy Pearson | 448e386 | 2015-11-24 14:12:01 -0600 | [diff] [blame] | 130 | pc_keyboard_init(NO_AUX_DEVICE); |
Stefan Reinauer | 55426df | 2010-01-17 13:50:17 +0000 | [diff] [blame] | 131 | break; |
| 132 | } |
| 133 | } |
| 134 | |
Edward O'Callaghan | f21bdc3 | 2014-10-21 07:43:41 +1100 | [diff] [blame] | 135 | static void lpc47n227_pnp_set_resource(struct device *dev, struct resource *resource) |
Stefan Reinauer | 55426df | 2010-01-17 13:50:17 +0000 | [diff] [blame] | 136 | { |
| 137 | if (!(resource->flags & IORESOURCE_ASSIGNED)) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 138 | printk(BIOS_ERR, "ERROR: %s %02lx not allocated\n", |
Uwe Hermann | a69d978 | 2010-11-15 19:35:14 +0000 | [diff] [blame] | 139 | dev_path(dev), resource->index); |
Stefan Reinauer | 55426df | 2010-01-17 13:50:17 +0000 | [diff] [blame] | 140 | return; |
| 141 | } |
| 142 | |
Uwe Hermann | a69d978 | 2010-11-15 19:35:14 +0000 | [diff] [blame] | 143 | /* Now store the resource. */ |
Uwe Hermann | b69cb5a | 2010-10-26 22:46:43 +0000 | [diff] [blame] | 144 | /* |
| 145 | * NOTE: Cannot use pnp_set_XXX() here because they assume chip |
| 146 | * support for logical devices, which the LPC47N227 doesn't have. |
| 147 | */ |
Stefan Reinauer | 55426df | 2010-01-17 13:50:17 +0000 | [diff] [blame] | 148 | if (resource->flags & IORESOURCE_IO) { |
| 149 | lpc47n227_pnp_set_iobase(dev, resource->base); |
| 150 | } else if (resource->flags & IORESOURCE_DRQ) { |
| 151 | lpc47n227_pnp_set_drq(dev, resource->base); |
| 152 | } else if (resource->flags & IORESOURCE_IRQ) { |
| 153 | lpc47n227_pnp_set_irq(dev, resource->base); |
| 154 | } else { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 155 | printk(BIOS_ERR, "ERROR: %s %02lx unknown resource type\n", |
Uwe Hermann | a69d978 | 2010-11-15 19:35:14 +0000 | [diff] [blame] | 156 | dev_path(dev), resource->index); |
Stefan Reinauer | 55426df | 2010-01-17 13:50:17 +0000 | [diff] [blame] | 157 | return; |
| 158 | } |
| 159 | resource->flags |= IORESOURCE_STORED; |
| 160 | |
| 161 | report_resource_stored(dev, resource, ""); |
| 162 | } |
| 163 | |
Edward O'Callaghan | f21bdc3 | 2014-10-21 07:43:41 +1100 | [diff] [blame] | 164 | void lpc47n227_pnp_set_iobase(struct device *dev, u16 iobase) |
Stefan Reinauer | 55426df | 2010-01-17 13:50:17 +0000 | [diff] [blame] | 165 | { |
| 166 | ASSERT(!(iobase & 0x3)); |
| 167 | |
| 168 | switch (dev->path.pnp.device) { |
| 169 | case LPC47N227_PP: |
| 170 | pnp_write_config(dev, 0x23, (iobase >> 2) & 0xff); |
| 171 | break; |
Stefan Reinauer | 55426df | 2010-01-17 13:50:17 +0000 | [diff] [blame] | 172 | case LPC47N227_SP1: |
| 173 | pnp_write_config(dev, 0x24, (iobase >> 2) & 0xff); |
| 174 | break; |
Stefan Reinauer | 55426df | 2010-01-17 13:50:17 +0000 | [diff] [blame] | 175 | case LPC47N227_SP2: |
| 176 | pnp_write_config(dev, 0x25, (iobase >> 2) & 0xff); |
| 177 | break; |
Stefan Reinauer | 55426df | 2010-01-17 13:50:17 +0000 | [diff] [blame] | 178 | case LPC47N227_KBDC: |
| 179 | break; |
Stefan Reinauer | 55426df | 2010-01-17 13:50:17 +0000 | [diff] [blame] | 180 | default: |
| 181 | BUG(); |
| 182 | break; |
| 183 | } |
| 184 | } |
| 185 | |
Edward O'Callaghan | f21bdc3 | 2014-10-21 07:43:41 +1100 | [diff] [blame] | 186 | void lpc47n227_pnp_set_drq(struct device *dev, u8 drq) |
Stefan Reinauer | 55426df | 2010-01-17 13:50:17 +0000 | [diff] [blame] | 187 | { |
Uwe Hermann | a69d978 | 2010-11-15 19:35:14 +0000 | [diff] [blame] | 188 | const u8 PP_DMA_MASK = 0x0F; |
| 189 | const u8 PP_DMA_SELECTION_REGISTER = 0x26; |
| 190 | u8 current_config, new_config; |
Stefan Reinauer | 55426df | 2010-01-17 13:50:17 +0000 | [diff] [blame] | 191 | |
Uwe Hermann | a69d978 | 2010-11-15 19:35:14 +0000 | [diff] [blame] | 192 | if (dev->path.pnp.device == LPC47N227_PP) { |
| 193 | current_config = pnp_read_config(dev, |
| 194 | PP_DMA_SELECTION_REGISTER); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 195 | ASSERT(!(drq & ~PP_DMA_MASK)); // DRQ out of range?? |
Stefan Reinauer | 55426df | 2010-01-17 13:50:17 +0000 | [diff] [blame] | 196 | new_config = (current_config & ~PP_DMA_MASK) | drq; |
| 197 | pnp_write_config(dev, PP_DMA_SELECTION_REGISTER, new_config); |
| 198 | } else { |
| 199 | BUG(); |
| 200 | } |
| 201 | } |
| 202 | |
Edward O'Callaghan | f21bdc3 | 2014-10-21 07:43:41 +1100 | [diff] [blame] | 203 | void lpc47n227_pnp_set_irq(struct device *dev, u8 irq) |
Stefan Reinauer | 55426df | 2010-01-17 13:50:17 +0000 | [diff] [blame] | 204 | { |
Uwe Hermann | a69d978 | 2010-11-15 19:35:14 +0000 | [diff] [blame] | 205 | u8 irq_config_register = 0, irq_config_mask = 0; |
| 206 | u8 current_config, new_config; |
Stefan Reinauer | 55426df | 2010-01-17 13:50:17 +0000 | [diff] [blame] | 207 | |
| 208 | switch (dev->path.pnp.device) { |
| 209 | case LPC47N227_PP: |
| 210 | irq_config_register = 0x27; |
| 211 | irq_config_mask = 0x0F; |
| 212 | break; |
Stefan Reinauer | 55426df | 2010-01-17 13:50:17 +0000 | [diff] [blame] | 213 | case LPC47N227_SP1: |
| 214 | irq_config_register = 0x28; |
| 215 | irq_config_mask = 0xF0; |
| 216 | irq <<= 4; |
| 217 | break; |
Stefan Reinauer | 55426df | 2010-01-17 13:50:17 +0000 | [diff] [blame] | 218 | case LPC47N227_SP2: |
| 219 | irq_config_register = 0x28; |
| 220 | irq_config_mask = 0x0F; |
| 221 | break; |
Stefan Reinauer | 55426df | 2010-01-17 13:50:17 +0000 | [diff] [blame] | 222 | case LPC47N227_KBDC: |
| 223 | break; |
Stefan Reinauer | 55426df | 2010-01-17 13:50:17 +0000 | [diff] [blame] | 224 | default: |
| 225 | BUG(); |
| 226 | return; |
| 227 | } |
| 228 | |
| 229 | current_config = pnp_read_config(dev, irq_config_register); |
| 230 | new_config = (current_config & ~irq_config_mask) | irq; |
| 231 | pnp_write_config(dev, irq_config_register, new_config); |
| 232 | } |
| 233 | |
Edward O'Callaghan | f21bdc3 | 2014-10-21 07:43:41 +1100 | [diff] [blame] | 234 | void lpc47n227_pnp_set_enable(struct device *dev, int enable) |
Stefan Reinauer | 55426df | 2010-01-17 13:50:17 +0000 | [diff] [blame] | 235 | { |
Uwe Hermann | a69d978 | 2010-11-15 19:35:14 +0000 | [diff] [blame] | 236 | u8 power_register = 0, power_mask = 0, current_power, new_power; |
Stefan Reinauer | 55426df | 2010-01-17 13:50:17 +0000 | [diff] [blame] | 237 | |
| 238 | switch (dev->path.pnp.device) { |
| 239 | case LPC47N227_PP: |
| 240 | power_register = 0x01; |
| 241 | power_mask = 0x04; |
| 242 | break; |
Stefan Reinauer | 55426df | 2010-01-17 13:50:17 +0000 | [diff] [blame] | 243 | case LPC47N227_SP1: |
| 244 | power_register = 0x02; |
| 245 | power_mask = 0x08; |
| 246 | break; |
Stefan Reinauer | 55426df | 2010-01-17 13:50:17 +0000 | [diff] [blame] | 247 | case LPC47N227_SP2: |
| 248 | power_register = 0x02; |
| 249 | power_mask = 0x80; |
| 250 | break; |
Stefan Reinauer | 55426df | 2010-01-17 13:50:17 +0000 | [diff] [blame] | 251 | case LPC47N227_KBDC: |
| 252 | break; |
Stefan Reinauer | 55426df | 2010-01-17 13:50:17 +0000 | [diff] [blame] | 253 | default: |
| 254 | BUG(); |
| 255 | return; |
| 256 | } |
| 257 | |
| 258 | current_power = pnp_read_config(dev, power_register); |
Uwe Hermann | a69d978 | 2010-11-15 19:35:14 +0000 | [diff] [blame] | 259 | new_power = current_power & ~power_mask; /* Disable by default. */ |
Stefan Reinauer | 55426df | 2010-01-17 13:50:17 +0000 | [diff] [blame] | 260 | if (enable) { |
Uwe Hermann | a69d978 | 2010-11-15 19:35:14 +0000 | [diff] [blame] | 261 | struct resource *ioport_resource; |
| 262 | ioport_resource = find_resource(dev, PNP_IDX_IO0); |
Stefan Reinauer | 55426df | 2010-01-17 13:50:17 +0000 | [diff] [blame] | 263 | lpc47n227_pnp_set_iobase(dev, ioport_resource->base); |
Uwe Hermann | a69d978 | 2010-11-15 19:35:14 +0000 | [diff] [blame] | 264 | new_power |= power_mask; /* Enable. */ |
Stefan Reinauer | 55426df | 2010-01-17 13:50:17 +0000 | [diff] [blame] | 265 | } else { |
| 266 | lpc47n227_pnp_set_iobase(dev, 0); |
| 267 | } |
| 268 | pnp_write_config(dev, power_register, new_power); |
| 269 | } |