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