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