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> |
Felix Held | f2ec648 | 2018-07-27 02:31:09 +0200 | [diff] [blame] | 10 | * Copyright (C) 2018 Felix Held <felix-coreboot@felixheld.de> |
Uwe Hermann | b80dbf0 | 2007-04-22 19:08:13 +0000 | [diff] [blame] | 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License as published by |
| 14 | * the Free Software Foundation; version 2 of the License. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
Uwe Hermann | b80dbf0 | 2007-04-22 19:08:13 +0000 | [diff] [blame] | 20 | */ |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 21 | |
| 22 | #include <console/console.h> |
| 23 | #include <stdlib.h> |
| 24 | #include <stdint.h> |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 25 | #include <string.h> |
| 26 | #include <arch/io.h> |
| 27 | #include <device/device.h> |
| 28 | #include <device/pnp.h> |
| 29 | |
Nico Huber | dd4715b | 2013-06-10 22:08:35 +0200 | [diff] [blame] | 30 | /* PNP config mode wrappers */ |
| 31 | |
Elyes HAOUAS | b77cf62 | 2018-05-02 21:01:18 +0200 | [diff] [blame] | 32 | void pnp_enter_conf_mode(struct device *dev) |
Nico Huber | dd4715b | 2013-06-10 22:08:35 +0200 | [diff] [blame] | 33 | { |
| 34 | if (dev->ops->ops_pnp_mode) |
| 35 | dev->ops->ops_pnp_mode->enter_conf_mode(dev); |
| 36 | } |
| 37 | |
Elyes HAOUAS | b77cf62 | 2018-05-02 21:01:18 +0200 | [diff] [blame] | 38 | void pnp_exit_conf_mode(struct device *dev) |
Nico Huber | dd4715b | 2013-06-10 22:08:35 +0200 | [diff] [blame] | 39 | { |
| 40 | if (dev->ops->ops_pnp_mode) |
| 41 | dev->ops->ops_pnp_mode->exit_conf_mode(dev); |
| 42 | } |
| 43 | |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 44 | /* PNP fundamental operations */ |
| 45 | |
Elyes HAOUAS | b77cf62 | 2018-05-02 21:01:18 +0200 | [diff] [blame] | 46 | void pnp_write_config(struct device *dev, u8 reg, u8 value) |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 47 | { |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 48 | outb(reg, dev->path.pnp.port); |
| 49 | outb(value, dev->path.pnp.port + 1); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 50 | } |
| 51 | |
Elyes HAOUAS | b77cf62 | 2018-05-02 21:01:18 +0200 | [diff] [blame] | 52 | u8 pnp_read_config(struct device *dev, u8 reg) |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 53 | { |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 54 | outb(reg, dev->path.pnp.port); |
| 55 | return inb(dev->path.pnp.port + 1); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 56 | } |
| 57 | |
Elyes HAOUAS | b77cf62 | 2018-05-02 21:01:18 +0200 | [diff] [blame] | 58 | void pnp_set_logical_device(struct device *dev) |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 59 | { |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 60 | pnp_write_config(dev, 0x07, dev->path.pnp.device & 0xff); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 61 | } |
| 62 | |
Elyes HAOUAS | b77cf62 | 2018-05-02 21:01:18 +0200 | [diff] [blame] | 63 | void pnp_set_enable(struct device *dev, int enable) |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 64 | { |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 65 | u8 tmp, bitpos; |
Rudolf Marek | 623df67 | 2008-02-18 20:32:46 +0000 | [diff] [blame] | 66 | |
| 67 | tmp = pnp_read_config(dev, 0x30); |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 68 | |
| 69 | /* Handle virtual devices, which share the same LDN register. */ |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 70 | bitpos = (dev->path.pnp.device >> 8) & 0x7; |
Rudolf Marek | 623df67 | 2008-02-18 20:32:46 +0000 | [diff] [blame] | 71 | |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 72 | if (enable) |
Rudolf Marek | 623df67 | 2008-02-18 20:32:46 +0000 | [diff] [blame] | 73 | tmp |= (1 << bitpos); |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 74 | else |
Rudolf Marek | 623df67 | 2008-02-18 20:32:46 +0000 | [diff] [blame] | 75 | tmp &= ~(1 << bitpos); |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 76 | |
Rudolf Marek | 623df67 | 2008-02-18 20:32:46 +0000 | [diff] [blame] | 77 | pnp_write_config(dev, 0x30, tmp); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 78 | } |
| 79 | |
Elyes HAOUAS | b77cf62 | 2018-05-02 21:01:18 +0200 | [diff] [blame] | 80 | int pnp_read_enable(struct device *dev) |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 81 | { |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 82 | u8 tmp, bitpos; |
| 83 | |
Rudolf Marek | 623df67 | 2008-02-18 20:32:46 +0000 | [diff] [blame] | 84 | tmp = pnp_read_config(dev, 0x30); |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 85 | |
| 86 | /* Handle virtual devices, which share the same LDN register. */ |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 87 | bitpos = (dev->path.pnp.device >> 8) & 0x7; |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 88 | |
Rudolf Marek | b05d4bb | 2008-02-19 20:30:25 +0000 | [diff] [blame] | 89 | return !!(tmp & (1 << bitpos)); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 90 | } |
| 91 | |
Elyes HAOUAS | b77cf62 | 2018-05-02 21:01:18 +0200 | [diff] [blame] | 92 | void pnp_set_iobase(struct device *dev, u8 index, u16 iobase) |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 93 | { |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 94 | /* Index == 0x60 or 0x62. */ |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 95 | pnp_write_config(dev, index + 0, (iobase >> 8) & 0xff); |
| 96 | pnp_write_config(dev, index + 1, iobase & 0xff); |
| 97 | } |
| 98 | |
Elyes HAOUAS | b77cf62 | 2018-05-02 21:01:18 +0200 | [diff] [blame] | 99 | void pnp_set_irq(struct device *dev, u8 index, u8 irq) |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 100 | { |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 101 | /* Index == 0x70 or 0x72. */ |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 102 | pnp_write_config(dev, index, irq); |
| 103 | } |
| 104 | |
Elyes HAOUAS | b77cf62 | 2018-05-02 21:01:18 +0200 | [diff] [blame] | 105 | void pnp_set_drq(struct device *dev, u8 index, u8 drq) |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 106 | { |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 107 | /* Index == 0x74. */ |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 108 | pnp_write_config(dev, index, drq & 0xff); |
| 109 | } |
| 110 | |
| 111 | /* PNP device operations */ |
| 112 | |
Elyes HAOUAS | b77cf62 | 2018-05-02 21:01:18 +0200 | [diff] [blame] | 113 | void pnp_read_resources(struct device *dev) |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 114 | { |
| 115 | return; |
| 116 | } |
| 117 | |
Elyes HAOUAS | b77cf62 | 2018-05-02 21:01:18 +0200 | [diff] [blame] | 118 | static void pnp_set_resource(struct device *dev, struct resource *resource) |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 119 | { |
| 120 | if (!(resource->flags & IORESOURCE_ASSIGNED)) { |
Felix Held | a662777 | 2018-07-27 16:41:32 +0200 | [diff] [blame^] | 121 | /* The PNP_MSC super IO registers have the IRQ flag set. If no |
| 122 | value is assigned in the devicetree, the corresponding |
| 123 | PNP_MSC register doesn't get written, which should be printed |
| 124 | as warning and not as error. */ |
| 125 | if (resource->flags & IORESOURCE_IRQ && |
| 126 | (resource->index != PNP_IDX_IRQ0) && |
| 127 | (resource->index != PNP_IDX_IRQ1)) |
| 128 | printk(BIOS_WARNING, "WARNING: %s %02lx %s size: " |
| 129 | "0x%010llx not assigned\n", dev_path(dev), |
| 130 | resource->index, resource_type(resource), |
| 131 | resource->size); |
| 132 | else |
| 133 | printk(BIOS_ERR, "ERROR: %s %02lx %s size: 0x%010llx " |
| 134 | "not assigned\n", dev_path(dev), resource->index, |
| 135 | resource_type(resource), resource->size); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 136 | return; |
| 137 | } |
Li-Ta Lo | 75337f7 | 2004-05-07 21:56:48 +0000 | [diff] [blame] | 138 | |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 139 | /* Now store the resource. */ |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 140 | if (resource->flags & IORESOURCE_IO) { |
| 141 | pnp_set_iobase(dev, resource->index, resource->base); |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 142 | } else if (resource->flags & IORESOURCE_DRQ) { |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 143 | pnp_set_drq(dev, resource->index, resource->base); |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 144 | } else if (resource->flags & IORESOURCE_IRQ) { |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 145 | pnp_set_irq(dev, resource->index, resource->base); |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 146 | } else { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 147 | printk(BIOS_ERR, "ERROR: %s %02lx unknown resource type\n", |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 148 | dev_path(dev), resource->index); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 149 | return; |
| 150 | } |
Li-Ta Lo | 9f0d0f9 | 2004-05-10 16:05:16 +0000 | [diff] [blame] | 151 | resource->flags |= IORESOURCE_STORED; |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 152 | |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 153 | report_resource_stored(dev, resource, ""); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 154 | } |
| 155 | |
Elyes HAOUAS | b77cf62 | 2018-05-02 21:01:18 +0200 | [diff] [blame] | 156 | void pnp_set_resources(struct device *dev) |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 157 | { |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 158 | struct resource *res; |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 159 | |
Nico Huber | dd4715b | 2013-06-10 22:08:35 +0200 | [diff] [blame] | 160 | pnp_enter_conf_mode(dev); |
| 161 | |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 162 | /* Select the logical device (LDN). */ |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 163 | pnp_set_logical_device(dev); |
| 164 | |
| 165 | /* Paranoia says I should disable the device here... */ |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 166 | for (res = dev->resource_list; res; res = res->next) |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 167 | pnp_set_resource(dev, res); |
Nico Huber | dd4715b | 2013-06-10 22:08:35 +0200 | [diff] [blame] | 168 | |
| 169 | pnp_exit_conf_mode(dev); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 170 | } |
| 171 | |
Elyes HAOUAS | b77cf62 | 2018-05-02 21:01:18 +0200 | [diff] [blame] | 172 | void pnp_enable_resources(struct device *dev) |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 173 | { |
Nico Huber | dd4715b | 2013-06-10 22:08:35 +0200 | [diff] [blame] | 174 | pnp_enter_conf_mode(dev); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 175 | pnp_set_logical_device(dev); |
| 176 | pnp_set_enable(dev, 1); |
Nico Huber | dd4715b | 2013-06-10 22:08:35 +0200 | [diff] [blame] | 177 | pnp_exit_conf_mode(dev); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 178 | } |
| 179 | |
Elyes HAOUAS | b77cf62 | 2018-05-02 21:01:18 +0200 | [diff] [blame] | 180 | void pnp_enable(struct device *dev) |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 181 | { |
Li-Ta Lo | 75337f7 | 2004-05-07 21:56:48 +0000 | [diff] [blame] | 182 | if (!dev->enabled) { |
Nico Huber | dd4715b | 2013-06-10 22:08:35 +0200 | [diff] [blame] | 183 | pnp_enter_conf_mode(dev); |
Li-Ta Lo | c6bcedb | 2004-04-21 16:57:05 +0000 | [diff] [blame] | 184 | pnp_set_logical_device(dev); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 185 | pnp_set_enable(dev, 0); |
Nico Huber | dd4715b | 2013-06-10 22:08:35 +0200 | [diff] [blame] | 186 | pnp_exit_conf_mode(dev); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 187 | } |
| 188 | } |
| 189 | |
Elyes HAOUAS | b77cf62 | 2018-05-02 21:01:18 +0200 | [diff] [blame] | 190 | void pnp_alt_enable(struct device *dev) |
Nico Huber | f898f7b | 2013-06-10 22:57:12 +0200 | [diff] [blame] | 191 | { |
Nico Huber | dd4715b | 2013-06-10 22:08:35 +0200 | [diff] [blame] | 192 | pnp_enter_conf_mode(dev); |
Nico Huber | f898f7b | 2013-06-10 22:57:12 +0200 | [diff] [blame] | 193 | pnp_set_logical_device(dev); |
| 194 | pnp_set_enable(dev, !!dev->enabled); |
Nico Huber | dd4715b | 2013-06-10 22:08:35 +0200 | [diff] [blame] | 195 | pnp_exit_conf_mode(dev); |
Nico Huber | f898f7b | 2013-06-10 22:57:12 +0200 | [diff] [blame] | 196 | } |
| 197 | |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 198 | struct device_operations pnp_ops = { |
| 199 | .read_resources = pnp_read_resources, |
| 200 | .set_resources = pnp_set_resources, |
| 201 | .enable_resources = pnp_enable_resources, |
| 202 | .enable = pnp_enable, |
| 203 | }; |
| 204 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 205 | /* PNP chip operations */ |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 206 | |
Elyes HAOUAS | b77cf62 | 2018-05-02 21:01:18 +0200 | [diff] [blame] | 207 | static void pnp_get_ioresource(struct device *dev, u8 index, u16 mask) |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 208 | { |
| 209 | struct resource *resource; |
Felix Held | f2ec648 | 2018-07-27 02:31:09 +0200 | [diff] [blame] | 210 | unsigned int bit; |
Li-Ta Lo | 75337f7 | 2004-05-07 21:56:48 +0000 | [diff] [blame] | 211 | |
Felix Held | f2ec648 | 2018-07-27 02:31:09 +0200 | [diff] [blame] | 212 | /* If none of the mask bits is set, the resource would occupy the whole |
| 213 | IO space leading to IO resource conflicts with the other devices */ |
Samuel Holland | 7daac91 | 2017-06-06 22:55:01 -0500 | [diff] [blame] | 214 | if (!mask) { |
Stefan Reinauer | aeead27 | 2011-01-31 21:16:48 +0000 | [diff] [blame] | 215 | printk(BIOS_ERR, "ERROR: device %s index %d has no mask.\n", |
| 216 | dev_path(dev), index); |
| 217 | return; |
| 218 | } |
| 219 | |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 220 | resource = new_resource(dev, index); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 221 | resource->flags |= IORESOURCE_IO; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 222 | |
Felix Held | f2ec648 | 2018-07-27 02:31:09 +0200 | [diff] [blame] | 223 | /* Calculate IO region size which is determined by the first one from |
| 224 | the LSB of the mask. */ |
| 225 | for (bit = 0; bit <= 15 && (mask & (1 << bit)) == 0; ++bit) |
| 226 | ; |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 227 | |
Felix Held | f2ec648 | 2018-07-27 02:31:09 +0200 | [diff] [blame] | 228 | resource->gran = bit; |
| 229 | resource->align = bit; |
| 230 | resource->size = 1 << bit; |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 231 | |
Felix Held | f2ec648 | 2018-07-27 02:31:09 +0200 | [diff] [blame] | 232 | /* Calculate IO region address limit which is determined by the first |
| 233 | one from the MSB of the mask. */ |
| 234 | for (bit = 15; bit != 0 && (mask & (1 << bit)) == 0; --bit) |
| 235 | ; |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 236 | |
Felix Held | f2ec648 | 2018-07-27 02:31:09 +0200 | [diff] [blame] | 237 | resource->limit = (1 << (bit + 1)) - 1; |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 238 | |
Felix Held | f2ec648 | 2018-07-27 02:31:09 +0200 | [diff] [blame] | 239 | /* The block of ones in the mask is expected to be continuous. |
| 240 | If there is any zero inbetween the block of ones, it is ignored |
| 241 | in the calculation of the resource size and limit. */ |
| 242 | if (mask != (resource->limit ^ (resource->size - 1))) |
| 243 | printk(BIOS_WARNING, |
| 244 | "WARNING: mask of device %s index %d is wrong.\n", |
| 245 | dev_path(dev), index); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 246 | } |
| 247 | |
Elyes HAOUAS | b77cf62 | 2018-05-02 21:01:18 +0200 | [diff] [blame] | 248 | static void get_resources(struct device *dev, struct pnp_info *info) |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 249 | { |
| 250 | struct resource *resource; |
| 251 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 252 | if (info->flags & PNP_IO0) |
Samuel Holland | 7daac91 | 2017-06-06 22:55:01 -0500 | [diff] [blame] | 253 | pnp_get_ioresource(dev, PNP_IDX_IO0, info->io0); |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 254 | if (info->flags & PNP_IO1) |
Samuel Holland | 7daac91 | 2017-06-06 22:55:01 -0500 | [diff] [blame] | 255 | pnp_get_ioresource(dev, PNP_IDX_IO1, info->io1); |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 256 | if (info->flags & PNP_IO2) |
Samuel Holland | 7daac91 | 2017-06-06 22:55:01 -0500 | [diff] [blame] | 257 | pnp_get_ioresource(dev, PNP_IDX_IO2, info->io2); |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 258 | if (info->flags & PNP_IO3) |
Samuel Holland | 7daac91 | 2017-06-06 22:55:01 -0500 | [diff] [blame] | 259 | pnp_get_ioresource(dev, PNP_IDX_IO3, info->io3); |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 260 | |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 261 | if (info->flags & PNP_IRQ0) { |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 262 | resource = new_resource(dev, PNP_IDX_IRQ0); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 263 | resource->size = 1; |
| 264 | resource->flags |= IORESOURCE_IRQ; |
| 265 | } |
| 266 | if (info->flags & PNP_IRQ1) { |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 267 | resource = new_resource(dev, PNP_IDX_IRQ1); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 268 | resource->size = 1; |
| 269 | resource->flags |= IORESOURCE_IRQ; |
| 270 | } |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 271 | |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 272 | if (info->flags & PNP_DRQ0) { |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 273 | resource = new_resource(dev, PNP_IDX_DRQ0); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 274 | resource->size = 1; |
| 275 | resource->flags |= IORESOURCE_DRQ; |
| 276 | } |
| 277 | if (info->flags & PNP_DRQ1) { |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 278 | resource = new_resource(dev, PNP_IDX_DRQ1); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 279 | resource->size = 1; |
| 280 | resource->flags |= IORESOURCE_DRQ; |
Stefan Reinauer | de3206a | 2010-02-22 06:09:43 +0000 | [diff] [blame] | 281 | } |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 282 | |
| 283 | /* |
| 284 | * These are not IRQs, but set the flag to have the |
| 285 | * resource allocator do the right thing. |
Stefan Reinauer | de3206a | 2010-02-22 06:09:43 +0000 | [diff] [blame] | 286 | */ |
| 287 | if (info->flags & PNP_EN) { |
| 288 | resource = new_resource(dev, PNP_IDX_EN); |
| 289 | resource->size = 1; |
| 290 | resource->flags |= IORESOURCE_IRQ; |
| 291 | } |
| 292 | if (info->flags & PNP_MSC0) { |
| 293 | resource = new_resource(dev, PNP_IDX_MSC0); |
| 294 | resource->size = 1; |
| 295 | resource->flags |= IORESOURCE_IRQ; |
| 296 | } |
| 297 | if (info->flags & PNP_MSC1) { |
| 298 | resource = new_resource(dev, PNP_IDX_MSC1); |
| 299 | resource->size = 1; |
| 300 | resource->flags |= IORESOURCE_IRQ; |
| 301 | } |
Damien Zammit | 62c0276 | 2015-12-28 23:04:47 +1100 | [diff] [blame] | 302 | if (info->flags & PNP_MSC2) { |
| 303 | resource = new_resource(dev, PNP_IDX_MSC2); |
| 304 | resource->size = 1; |
| 305 | resource->flags |= IORESOURCE_IRQ; |
| 306 | } |
| 307 | if (info->flags & PNP_MSC3) { |
| 308 | resource = new_resource(dev, PNP_IDX_MSC3); |
| 309 | resource->size = 1; |
| 310 | resource->flags |= IORESOURCE_IRQ; |
| 311 | } |
Stefan Reinauer | 0108b93 | 2013-12-11 11:06:08 -0800 | [diff] [blame] | 312 | if (info->flags & PNP_MSC4) { |
| 313 | resource = new_resource(dev, PNP_IDX_MSC4); |
| 314 | resource->size = 1; |
| 315 | resource->flags |= IORESOURCE_IRQ; |
| 316 | } |
Damien Zammit | 62c0276 | 2015-12-28 23:04:47 +1100 | [diff] [blame] | 317 | if (info->flags & PNP_MSC5) { |
| 318 | resource = new_resource(dev, PNP_IDX_MSC5); |
| 319 | resource->size = 1; |
| 320 | resource->flags |= IORESOURCE_IRQ; |
| 321 | } |
| 322 | if (info->flags & PNP_MSC6) { |
| 323 | resource = new_resource(dev, PNP_IDX_MSC6); |
| 324 | resource->size = 1; |
| 325 | resource->flags |= IORESOURCE_IRQ; |
| 326 | } |
| 327 | if (info->flags & PNP_MSC7) { |
| 328 | resource = new_resource(dev, PNP_IDX_MSC7); |
| 329 | resource->size = 1; |
| 330 | resource->flags |= IORESOURCE_IRQ; |
| 331 | } |
| 332 | if (info->flags & PNP_MSC8) { |
| 333 | resource = new_resource(dev, PNP_IDX_MSC8); |
| 334 | resource->size = 1; |
| 335 | resource->flags |= IORESOURCE_IRQ; |
| 336 | } |
| 337 | if (info->flags & PNP_MSC9) { |
| 338 | resource = new_resource(dev, PNP_IDX_MSC9); |
| 339 | resource->size = 1; |
| 340 | resource->flags |= IORESOURCE_IRQ; |
| 341 | } |
| 342 | if (info->flags & PNP_MSCA) { |
| 343 | resource = new_resource(dev, PNP_IDX_MSCA); |
| 344 | resource->size = 1; |
| 345 | resource->flags |= IORESOURCE_IRQ; |
| 346 | } |
| 347 | if (info->flags & PNP_MSCB) { |
| 348 | resource = new_resource(dev, PNP_IDX_MSCB); |
| 349 | resource->size = 1; |
| 350 | resource->flags |= IORESOURCE_IRQ; |
| 351 | } |
| 352 | if (info->flags & PNP_MSCC) { |
| 353 | resource = new_resource(dev, PNP_IDX_MSCC); |
| 354 | resource->size = 1; |
| 355 | resource->flags |= IORESOURCE_IRQ; |
| 356 | } |
| 357 | if (info->flags & PNP_MSCD) { |
| 358 | resource = new_resource(dev, PNP_IDX_MSCD); |
| 359 | resource->size = 1; |
| 360 | resource->flags |= IORESOURCE_IRQ; |
| 361 | } |
| 362 | if (info->flags & PNP_MSCE) { |
| 363 | resource = new_resource(dev, PNP_IDX_MSCE); |
Stefan Reinauer | 08ba7d0 | 2013-10-31 15:58:50 -0700 | [diff] [blame] | 364 | resource->size = 1; |
| 365 | resource->flags |= IORESOURCE_IRQ; |
| 366 | } |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 367 | } |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 368 | |
Elyes HAOUAS | b77cf62 | 2018-05-02 21:01:18 +0200 | [diff] [blame] | 369 | void pnp_enable_devices(struct device *base_dev, struct device_operations *ops, |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 370 | unsigned int functions, struct pnp_info *info) |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 371 | { |
| 372 | struct device_path path; |
Elyes HAOUAS | b77cf62 | 2018-05-02 21:01:18 +0200 | [diff] [blame] | 373 | struct device *dev; |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 374 | int i; |
| 375 | |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 376 | path.type = DEVICE_PATH_PNP; |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 377 | path.pnp.port = base_dev->path.pnp.port; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 378 | |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 379 | /* Setup the ops and resources on the newly allocated devices. */ |
| 380 | for (i = 0; i < functions; i++) { |
Uwe Hermann | aa4bedf | 2007-07-12 13:12:47 +0000 | [diff] [blame] | 381 | /* Skip logical devices this Super I/O doesn't have. */ |
| 382 | if (info[i].function == -1) |
| 383 | continue; |
| 384 | |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 385 | path.pnp.device = info[i].function; |
Eric Biederman | 7003ba4 | 2004-10-16 06:20:29 +0000 | [diff] [blame] | 386 | dev = alloc_find_dev(base_dev->bus, &path); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 387 | |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 388 | /* Don't initialize a device multiple times. */ |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 389 | if (dev->ops) |
Eric Biederman | 7003ba4 | 2004-10-16 06:20:29 +0000 | [diff] [blame] | 390 | continue; |
Li-Ta Lo | c6bcedb | 2004-04-21 16:57:05 +0000 | [diff] [blame] | 391 | |
Felix Held | 745e58a | 2018-07-06 19:38:24 +0200 | [diff] [blame] | 392 | /* use LDN-specific ops override from corresponding pnp_info |
| 393 | entry if not NULL */ |
| 394 | if (info[i].ops) |
Li-Ta Lo | 75337f7 | 2004-05-07 21:56:48 +0000 | [diff] [blame] | 395 | dev->ops = info[i].ops; |
Felix Held | 745e58a | 2018-07-06 19:38:24 +0200 | [diff] [blame] | 396 | /* else use device ops */ |
| 397 | else |
| 398 | dev->ops = ops; |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 399 | |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 400 | get_resources(dev, &info[i]); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 401 | } |
| 402 | } |