Uwe Hermann | b80dbf0 | 2007-04-22 19:08:13 +0000 | [diff] [blame] | 1 | /* |
Stefan Reinauer | 7e61e45 | 2008-01-18 10:35:56 +0000 | [diff] [blame] | 2 | * This file is part of the coreboot project. |
Uwe Hermann | b80dbf0 | 2007-04-22 19:08:13 +0000 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2004 Linux Networx |
| 5 | * (Written by Eric Biederman <ebiederman@lnxi.com> for Linux Networx) |
| 6 | * Copyright (C) 2004 Li-Ta Lo <ollie@lanl.gov> |
| 7 | * Copyright (C) 2005 Tyan |
| 8 | * (Written by Yinghai Lu <yhlu@tyan.com> for Tyan) |
Nico Huber | dd4715b | 2013-06-10 22:08:35 +0200 | [diff] [blame] | 9 | * Copyright (C) 2013 Nico Huber <nico.h@gmx.de> |
Uwe Hermann | b80dbf0 | 2007-04-22 19:08:13 +0000 | [diff] [blame] | 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; version 2 of the License. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
Uwe Hermann | b80dbf0 | 2007-04-22 19:08:13 +0000 | [diff] [blame] | 19 | */ |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 20 | |
| 21 | #include <console/console.h> |
| 22 | #include <stdlib.h> |
| 23 | #include <stdint.h> |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 24 | #include <string.h> |
| 25 | #include <arch/io.h> |
| 26 | #include <device/device.h> |
| 27 | #include <device/pnp.h> |
| 28 | |
Nico Huber | dd4715b | 2013-06-10 22:08:35 +0200 | [diff] [blame] | 29 | /* PNP config mode wrappers */ |
| 30 | |
| 31 | void pnp_enter_conf_mode(device_t dev) |
| 32 | { |
| 33 | if (dev->ops->ops_pnp_mode) |
| 34 | dev->ops->ops_pnp_mode->enter_conf_mode(dev); |
| 35 | } |
| 36 | |
| 37 | void pnp_exit_conf_mode(device_t dev) |
| 38 | { |
| 39 | if (dev->ops->ops_pnp_mode) |
| 40 | dev->ops->ops_pnp_mode->exit_conf_mode(dev); |
| 41 | } |
| 42 | |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 43 | /* PNP fundamental operations */ |
| 44 | |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 45 | void pnp_write_config(device_t dev, u8 reg, u8 value) |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 46 | { |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 47 | outb(reg, dev->path.pnp.port); |
| 48 | outb(value, dev->path.pnp.port + 1); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 49 | } |
| 50 | |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 51 | u8 pnp_read_config(device_t dev, u8 reg) |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 52 | { |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 53 | outb(reg, dev->path.pnp.port); |
| 54 | return inb(dev->path.pnp.port + 1); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | void pnp_set_logical_device(device_t dev) |
| 58 | { |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 59 | pnp_write_config(dev, 0x07, dev->path.pnp.device & 0xff); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | void pnp_set_enable(device_t dev, int enable) |
| 63 | { |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 64 | u8 tmp, bitpos; |
Rudolf Marek | 623df67 | 2008-02-18 20:32:46 +0000 | [diff] [blame] | 65 | |
| 66 | tmp = pnp_read_config(dev, 0x30); |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 67 | |
| 68 | /* Handle virtual devices, which share the same LDN register. */ |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 69 | bitpos = (dev->path.pnp.device >> 8) & 0x7; |
Rudolf Marek | 623df67 | 2008-02-18 20:32:46 +0000 | [diff] [blame] | 70 | |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 71 | if (enable) |
Rudolf Marek | 623df67 | 2008-02-18 20:32:46 +0000 | [diff] [blame] | 72 | tmp |= (1 << bitpos); |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 73 | else |
Rudolf Marek | 623df67 | 2008-02-18 20:32:46 +0000 | [diff] [blame] | 74 | tmp &= ~(1 << bitpos); |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 75 | |
Rudolf Marek | 623df67 | 2008-02-18 20:32:46 +0000 | [diff] [blame] | 76 | pnp_write_config(dev, 0x30, tmp); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | int pnp_read_enable(device_t dev) |
| 80 | { |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 81 | u8 tmp, bitpos; |
| 82 | |
Rudolf Marek | 623df67 | 2008-02-18 20:32:46 +0000 | [diff] [blame] | 83 | tmp = pnp_read_config(dev, 0x30); |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 84 | |
| 85 | /* Handle virtual devices, which share the same LDN register. */ |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 86 | bitpos = (dev->path.pnp.device >> 8) & 0x7; |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 87 | |
Rudolf Marek | b05d4bb | 2008-02-19 20:30:25 +0000 | [diff] [blame] | 88 | return !!(tmp & (1 << bitpos)); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 89 | } |
| 90 | |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 91 | void pnp_set_iobase(device_t dev, u8 index, u16 iobase) |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 92 | { |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 93 | /* Index == 0x60 or 0x62. */ |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 94 | pnp_write_config(dev, index + 0, (iobase >> 8) & 0xff); |
| 95 | pnp_write_config(dev, index + 1, iobase & 0xff); |
| 96 | } |
| 97 | |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 98 | void pnp_set_irq(device_t dev, u8 index, u8 irq) |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 99 | { |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 100 | /* Index == 0x70 or 0x72. */ |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 101 | pnp_write_config(dev, index, irq); |
| 102 | } |
| 103 | |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 104 | void pnp_set_drq(device_t dev, u8 index, u8 drq) |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 105 | { |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 106 | /* Index == 0x74. */ |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 107 | pnp_write_config(dev, index, drq & 0xff); |
| 108 | } |
| 109 | |
| 110 | /* PNP device operations */ |
| 111 | |
| 112 | void pnp_read_resources(device_t dev) |
| 113 | { |
| 114 | return; |
| 115 | } |
| 116 | |
| 117 | static void pnp_set_resource(device_t dev, struct resource *resource) |
| 118 | { |
| 119 | if (!(resource->flags & IORESOURCE_ASSIGNED)) { |
Patrick Georgi | 5161509 | 2012-03-11 19:31:03 +0100 | [diff] [blame] | 120 | printk(BIOS_ERR, "ERROR: %s %02lx %s size: 0x%010llx " |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 121 | "not assigned\n", dev_path(dev), resource->index, |
| 122 | resource_type(resource), resource->size); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 123 | return; |
| 124 | } |
Li-Ta Lo | 75337f7 | 2004-05-07 21:56:48 +0000 | [diff] [blame] | 125 | |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 126 | /* Now store the resource. */ |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 127 | if (resource->flags & IORESOURCE_IO) { |
| 128 | pnp_set_iobase(dev, resource->index, resource->base); |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 129 | } else if (resource->flags & IORESOURCE_DRQ) { |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 130 | pnp_set_drq(dev, resource->index, resource->base); |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 131 | } else if (resource->flags & IORESOURCE_IRQ) { |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 132 | pnp_set_irq(dev, resource->index, resource->base); |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 133 | } else { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 134 | printk(BIOS_ERR, "ERROR: %s %02lx unknown resource type\n", |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 135 | dev_path(dev), resource->index); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 136 | return; |
| 137 | } |
Li-Ta Lo | 9f0d0f9 | 2004-05-10 16:05:16 +0000 | [diff] [blame] | 138 | resource->flags |= IORESOURCE_STORED; |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 139 | |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 140 | report_resource_stored(dev, resource, ""); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | void pnp_set_resources(device_t dev) |
| 144 | { |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 145 | struct resource *res; |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 146 | |
Nico Huber | dd4715b | 2013-06-10 22:08:35 +0200 | [diff] [blame] | 147 | pnp_enter_conf_mode(dev); |
| 148 | |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 149 | /* Select the logical device (LDN). */ |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 150 | pnp_set_logical_device(dev); |
| 151 | |
| 152 | /* Paranoia says I should disable the device here... */ |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 153 | for (res = dev->resource_list; res; res = res->next) |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 154 | pnp_set_resource(dev, res); |
Nico Huber | dd4715b | 2013-06-10 22:08:35 +0200 | [diff] [blame] | 155 | |
| 156 | pnp_exit_conf_mode(dev); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | void pnp_enable_resources(device_t dev) |
| 160 | { |
Nico Huber | dd4715b | 2013-06-10 22:08:35 +0200 | [diff] [blame] | 161 | pnp_enter_conf_mode(dev); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 162 | pnp_set_logical_device(dev); |
| 163 | pnp_set_enable(dev, 1); |
Nico Huber | dd4715b | 2013-06-10 22:08:35 +0200 | [diff] [blame] | 164 | pnp_exit_conf_mode(dev); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | void pnp_enable(device_t dev) |
| 168 | { |
Li-Ta Lo | 75337f7 | 2004-05-07 21:56:48 +0000 | [diff] [blame] | 169 | if (!dev->enabled) { |
Nico Huber | dd4715b | 2013-06-10 22:08:35 +0200 | [diff] [blame] | 170 | pnp_enter_conf_mode(dev); |
Li-Ta Lo | c6bcedb | 2004-04-21 16:57:05 +0000 | [diff] [blame] | 171 | pnp_set_logical_device(dev); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 172 | pnp_set_enable(dev, 0); |
Nico Huber | dd4715b | 2013-06-10 22:08:35 +0200 | [diff] [blame] | 173 | pnp_exit_conf_mode(dev); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 174 | } |
| 175 | } |
| 176 | |
Nico Huber | f898f7b | 2013-06-10 22:57:12 +0200 | [diff] [blame] | 177 | void pnp_alt_enable(device_t dev) |
| 178 | { |
Nico Huber | dd4715b | 2013-06-10 22:08:35 +0200 | [diff] [blame] | 179 | pnp_enter_conf_mode(dev); |
Nico Huber | f898f7b | 2013-06-10 22:57:12 +0200 | [diff] [blame] | 180 | pnp_set_logical_device(dev); |
| 181 | pnp_set_enable(dev, !!dev->enabled); |
Nico Huber | dd4715b | 2013-06-10 22:08:35 +0200 | [diff] [blame] | 182 | pnp_exit_conf_mode(dev); |
Nico Huber | f898f7b | 2013-06-10 22:57:12 +0200 | [diff] [blame] | 183 | } |
| 184 | |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 185 | struct device_operations pnp_ops = { |
| 186 | .read_resources = pnp_read_resources, |
| 187 | .set_resources = pnp_set_resources, |
| 188 | .enable_resources = pnp_enable_resources, |
| 189 | .enable = pnp_enable, |
| 190 | }; |
| 191 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 192 | /* PNP chip operations */ |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 193 | |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 194 | static void pnp_get_ioresource(device_t dev, u8 index, struct io_info *info) |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 195 | { |
| 196 | struct resource *resource; |
Eric Biederman | dbec2d4 | 2004-10-21 10:44:08 +0000 | [diff] [blame] | 197 | unsigned moving, gran, step; |
Li-Ta Lo | 75337f7 | 2004-05-07 21:56:48 +0000 | [diff] [blame] | 198 | |
Stefan Reinauer | aeead27 | 2011-01-31 21:16:48 +0000 | [diff] [blame] | 199 | if (!info->mask) { |
| 200 | printk(BIOS_ERR, "ERROR: device %s index %d has no mask.\n", |
| 201 | dev_path(dev), index); |
| 202 | return; |
| 203 | } |
| 204 | |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 205 | resource = new_resource(dev, index); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 206 | |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 207 | /* Initilize the resource. */ |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 208 | resource->limit = 0xffff; |
| 209 | resource->flags |= IORESOURCE_IO; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 210 | |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 211 | /* Get the resource size... */ |
| 212 | |
Eric Biederman | dbec2d4 | 2004-10-21 10:44:08 +0000 | [diff] [blame] | 213 | moving = info->mask; |
| 214 | gran = 15; |
| 215 | step = 1 << gran; |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 216 | |
| 217 | /* Find the first bit that moves. */ |
| 218 | while ((moving & step) == 0) { |
Eric Biederman | dbec2d4 | 2004-10-21 10:44:08 +0000 | [diff] [blame] | 219 | gran--; |
| 220 | step >>= 1; |
| 221 | } |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 222 | |
| 223 | /* Now find the first bit that does not move. */ |
| 224 | while ((moving & step) != 0) { |
Eric Biederman | dbec2d4 | 2004-10-21 10:44:08 +0000 | [diff] [blame] | 225 | gran--; |
| 226 | step >>= 1; |
| 227 | } |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 228 | |
| 229 | /* |
| 230 | * Of the moving bits the last bit in the first group, |
Eric Biederman | dbec2d4 | 2004-10-21 10:44:08 +0000 | [diff] [blame] | 231 | * tells us the size of this resource. |
| 232 | */ |
| 233 | if ((moving & step) == 0) { |
| 234 | gran++; |
| 235 | step <<= 1; |
| 236 | } |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 237 | |
| 238 | /* Set the resource size and alignment. */ |
Eric Biederman | dbec2d4 | 2004-10-21 10:44:08 +0000 | [diff] [blame] | 239 | resource->gran = gran; |
| 240 | resource->align = gran; |
| 241 | resource->limit = info->mask | (step - 1); |
| 242 | resource->size = 1 << gran; |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | static void get_resources(device_t dev, struct pnp_info *info) |
| 246 | { |
| 247 | struct resource *resource; |
| 248 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 249 | if (info->flags & PNP_IO0) |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 250 | pnp_get_ioresource(dev, PNP_IDX_IO0, &info->io0); |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 251 | if (info->flags & PNP_IO1) |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 252 | pnp_get_ioresource(dev, PNP_IDX_IO1, &info->io1); |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 253 | if (info->flags & PNP_IO2) |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 254 | pnp_get_ioresource(dev, PNP_IDX_IO2, &info->io2); |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 255 | if (info->flags & PNP_IO3) |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 256 | pnp_get_ioresource(dev, PNP_IDX_IO3, &info->io3); |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 257 | |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 258 | if (info->flags & PNP_IRQ0) { |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 259 | resource = new_resource(dev, PNP_IDX_IRQ0); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 260 | resource->size = 1; |
| 261 | resource->flags |= IORESOURCE_IRQ; |
| 262 | } |
| 263 | if (info->flags & PNP_IRQ1) { |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 264 | resource = new_resource(dev, PNP_IDX_IRQ1); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 265 | resource->size = 1; |
| 266 | resource->flags |= IORESOURCE_IRQ; |
| 267 | } |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 268 | |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 269 | if (info->flags & PNP_DRQ0) { |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 270 | resource = new_resource(dev, PNP_IDX_DRQ0); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 271 | resource->size = 1; |
| 272 | resource->flags |= IORESOURCE_DRQ; |
| 273 | } |
| 274 | if (info->flags & PNP_DRQ1) { |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 275 | resource = new_resource(dev, PNP_IDX_DRQ1); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 276 | resource->size = 1; |
| 277 | resource->flags |= IORESOURCE_DRQ; |
Stefan Reinauer | de3206a | 2010-02-22 06:09:43 +0000 | [diff] [blame] | 278 | } |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 279 | |
| 280 | /* |
| 281 | * These are not IRQs, but set the flag to have the |
| 282 | * resource allocator do the right thing. |
Stefan Reinauer | de3206a | 2010-02-22 06:09:43 +0000 | [diff] [blame] | 283 | */ |
| 284 | if (info->flags & PNP_EN) { |
| 285 | resource = new_resource(dev, PNP_IDX_EN); |
| 286 | resource->size = 1; |
| 287 | resource->flags |= IORESOURCE_IRQ; |
| 288 | } |
| 289 | if (info->flags & PNP_MSC0) { |
| 290 | resource = new_resource(dev, PNP_IDX_MSC0); |
| 291 | resource->size = 1; |
| 292 | resource->flags |= IORESOURCE_IRQ; |
| 293 | } |
| 294 | if (info->flags & PNP_MSC1) { |
| 295 | resource = new_resource(dev, PNP_IDX_MSC1); |
| 296 | resource->size = 1; |
| 297 | resource->flags |= IORESOURCE_IRQ; |
| 298 | } |
Stefan Reinauer | 0108b93 | 2013-12-11 11:06:08 -0800 | [diff] [blame] | 299 | if (info->flags & PNP_MSC4) { |
| 300 | resource = new_resource(dev, PNP_IDX_MSC4); |
| 301 | resource->size = 1; |
| 302 | resource->flags |= IORESOURCE_IRQ; |
| 303 | } |
Stefan Reinauer | 08ba7d0 | 2013-10-31 15:58:50 -0700 | [diff] [blame] | 304 | if (info->flags & PNP_MSC10) { |
| 305 | resource = new_resource(dev, PNP_IDX_MSC10); |
| 306 | resource->size = 1; |
| 307 | resource->flags |= IORESOURCE_IRQ; |
| 308 | } |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 309 | } |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 310 | |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 311 | void pnp_enable_devices(device_t base_dev, struct device_operations *ops, |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 312 | unsigned int functions, struct pnp_info *info) |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 313 | { |
| 314 | struct device_path path; |
| 315 | device_t dev; |
| 316 | int i; |
| 317 | |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 318 | path.type = DEVICE_PATH_PNP; |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 319 | path.pnp.port = base_dev->path.pnp.port; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 320 | |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 321 | /* Setup the ops and resources on the newly allocated devices. */ |
| 322 | for (i = 0; i < functions; i++) { |
Uwe Hermann | aa4bedf | 2007-07-12 13:12:47 +0000 | [diff] [blame] | 323 | /* Skip logical devices this Super I/O doesn't have. */ |
| 324 | if (info[i].function == -1) |
| 325 | continue; |
| 326 | |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 327 | path.pnp.device = info[i].function; |
Eric Biederman | 7003ba4 | 2004-10-16 06:20:29 +0000 | [diff] [blame] | 328 | dev = alloc_find_dev(base_dev->bus, &path); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 329 | |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 330 | /* Don't initialize a device multiple times. */ |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 331 | if (dev->ops) |
Eric Biederman | 7003ba4 | 2004-10-16 06:20:29 +0000 | [diff] [blame] | 332 | continue; |
Li-Ta Lo | c6bcedb | 2004-04-21 16:57:05 +0000 | [diff] [blame] | 333 | |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 334 | if (info[i].ops == 0) |
Li-Ta Lo | 75337f7 | 2004-05-07 21:56:48 +0000 | [diff] [blame] | 335 | dev->ops = ops; |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 336 | else |
Li-Ta Lo | 75337f7 | 2004-05-07 21:56:48 +0000 | [diff] [blame] | 337 | dev->ops = info[i].ops; |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 338 | |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 339 | get_resources(dev, &info[i]); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 340 | } |
| 341 | } |