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