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