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