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)) { |
Patrick Georgi | 5161509 | 2012-03-11 19:31:03 +0100 | [diff] [blame] | 121 | printk(BIOS_ERR, "ERROR: %s %02lx %s size: 0x%010llx " |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 122 | "not assigned\n", dev_path(dev), resource->index, |
| 123 | resource_type(resource), resource->size); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 124 | return; |
| 125 | } |
Li-Ta Lo | 75337f7 | 2004-05-07 21:56:48 +0000 | [diff] [blame] | 126 | |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 127 | /* Now store the resource. */ |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 128 | if (resource->flags & IORESOURCE_IO) { |
| 129 | pnp_set_iobase(dev, resource->index, resource->base); |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 130 | } else if (resource->flags & IORESOURCE_DRQ) { |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 131 | pnp_set_drq(dev, resource->index, resource->base); |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 132 | } else if (resource->flags & IORESOURCE_IRQ) { |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 133 | pnp_set_irq(dev, resource->index, resource->base); |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 134 | } else { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 135 | printk(BIOS_ERR, "ERROR: %s %02lx unknown resource type\n", |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 136 | dev_path(dev), resource->index); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 137 | return; |
| 138 | } |
Li-Ta Lo | 9f0d0f9 | 2004-05-10 16:05:16 +0000 | [diff] [blame] | 139 | resource->flags |= IORESOURCE_STORED; |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 140 | |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 141 | report_resource_stored(dev, resource, ""); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 142 | } |
| 143 | |
Elyes HAOUAS | b77cf62 | 2018-05-02 21:01:18 +0200 | [diff] [blame] | 144 | void pnp_set_resources(struct device *dev) |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 145 | { |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 146 | struct resource *res; |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 147 | |
Nico Huber | dd4715b | 2013-06-10 22:08:35 +0200 | [diff] [blame] | 148 | pnp_enter_conf_mode(dev); |
| 149 | |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 150 | /* Select the logical device (LDN). */ |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 151 | pnp_set_logical_device(dev); |
| 152 | |
| 153 | /* Paranoia says I should disable the device here... */ |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 154 | for (res = dev->resource_list; res; res = res->next) |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 155 | pnp_set_resource(dev, res); |
Nico Huber | dd4715b | 2013-06-10 22:08:35 +0200 | [diff] [blame] | 156 | |
| 157 | pnp_exit_conf_mode(dev); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 158 | } |
| 159 | |
Elyes HAOUAS | b77cf62 | 2018-05-02 21:01:18 +0200 | [diff] [blame] | 160 | void pnp_enable_resources(struct device *dev) |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 161 | { |
Nico Huber | dd4715b | 2013-06-10 22:08:35 +0200 | [diff] [blame] | 162 | pnp_enter_conf_mode(dev); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 163 | pnp_set_logical_device(dev); |
| 164 | pnp_set_enable(dev, 1); |
Nico Huber | dd4715b | 2013-06-10 22:08:35 +0200 | [diff] [blame] | 165 | pnp_exit_conf_mode(dev); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 166 | } |
| 167 | |
Elyes HAOUAS | b77cf62 | 2018-05-02 21:01:18 +0200 | [diff] [blame] | 168 | void pnp_enable(struct device *dev) |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 169 | { |
Li-Ta Lo | 75337f7 | 2004-05-07 21:56:48 +0000 | [diff] [blame] | 170 | if (!dev->enabled) { |
Nico Huber | dd4715b | 2013-06-10 22:08:35 +0200 | [diff] [blame] | 171 | pnp_enter_conf_mode(dev); |
Li-Ta Lo | c6bcedb | 2004-04-21 16:57:05 +0000 | [diff] [blame] | 172 | pnp_set_logical_device(dev); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 173 | pnp_set_enable(dev, 0); |
Nico Huber | dd4715b | 2013-06-10 22:08:35 +0200 | [diff] [blame] | 174 | pnp_exit_conf_mode(dev); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 175 | } |
| 176 | } |
| 177 | |
Elyes HAOUAS | b77cf62 | 2018-05-02 21:01:18 +0200 | [diff] [blame] | 178 | void pnp_alt_enable(struct device *dev) |
Nico Huber | f898f7b | 2013-06-10 22:57:12 +0200 | [diff] [blame] | 179 | { |
Nico Huber | dd4715b | 2013-06-10 22:08:35 +0200 | [diff] [blame] | 180 | pnp_enter_conf_mode(dev); |
Nico Huber | f898f7b | 2013-06-10 22:57:12 +0200 | [diff] [blame] | 181 | pnp_set_logical_device(dev); |
| 182 | pnp_set_enable(dev, !!dev->enabled); |
Nico Huber | dd4715b | 2013-06-10 22:08:35 +0200 | [diff] [blame] | 183 | pnp_exit_conf_mode(dev); |
Nico Huber | f898f7b | 2013-06-10 22:57:12 +0200 | [diff] [blame] | 184 | } |
| 185 | |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 186 | struct device_operations pnp_ops = { |
| 187 | .read_resources = pnp_read_resources, |
| 188 | .set_resources = pnp_set_resources, |
| 189 | .enable_resources = pnp_enable_resources, |
| 190 | .enable = pnp_enable, |
| 191 | }; |
| 192 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 193 | /* PNP chip operations */ |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 194 | |
Elyes HAOUAS | b77cf62 | 2018-05-02 21:01:18 +0200 | [diff] [blame] | 195 | static void pnp_get_ioresource(struct device *dev, u8 index, u16 mask) |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 196 | { |
| 197 | struct resource *resource; |
Felix Held | f2ec648 | 2018-07-27 02:31:09 +0200 | [diff] [blame^] | 198 | unsigned int bit; |
Li-Ta Lo | 75337f7 | 2004-05-07 21:56:48 +0000 | [diff] [blame] | 199 | |
Felix Held | f2ec648 | 2018-07-27 02:31:09 +0200 | [diff] [blame^] | 200 | /* If none of the mask bits is set, the resource would occupy the whole |
| 201 | IO space leading to IO resource conflicts with the other devices */ |
Samuel Holland | 7daac91 | 2017-06-06 22:55:01 -0500 | [diff] [blame] | 202 | if (!mask) { |
Stefan Reinauer | aeead27 | 2011-01-31 21:16:48 +0000 | [diff] [blame] | 203 | printk(BIOS_ERR, "ERROR: device %s index %d has no mask.\n", |
| 204 | dev_path(dev), index); |
| 205 | return; |
| 206 | } |
| 207 | |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 208 | resource = new_resource(dev, index); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 209 | resource->flags |= IORESOURCE_IO; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 210 | |
Felix Held | f2ec648 | 2018-07-27 02:31:09 +0200 | [diff] [blame^] | 211 | /* Calculate IO region size which is determined by the first one from |
| 212 | the LSB of the mask. */ |
| 213 | for (bit = 0; bit <= 15 && (mask & (1 << bit)) == 0; ++bit) |
| 214 | ; |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 215 | |
Felix Held | f2ec648 | 2018-07-27 02:31:09 +0200 | [diff] [blame^] | 216 | resource->gran = bit; |
| 217 | resource->align = bit; |
| 218 | resource->size = 1 << bit; |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 219 | |
Felix Held | f2ec648 | 2018-07-27 02:31:09 +0200 | [diff] [blame^] | 220 | /* Calculate IO region address limit which is determined by the first |
| 221 | one from the MSB of the mask. */ |
| 222 | for (bit = 15; bit != 0 && (mask & (1 << bit)) == 0; --bit) |
| 223 | ; |
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 | resource->limit = (1 << (bit + 1)) - 1; |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 226 | |
Felix Held | f2ec648 | 2018-07-27 02:31:09 +0200 | [diff] [blame^] | 227 | /* The block of ones in the mask is expected to be continuous. |
| 228 | If there is any zero inbetween the block of ones, it is ignored |
| 229 | in the calculation of the resource size and limit. */ |
| 230 | if (mask != (resource->limit ^ (resource->size - 1))) |
| 231 | printk(BIOS_WARNING, |
| 232 | "WARNING: mask of device %s index %d is wrong.\n", |
| 233 | dev_path(dev), index); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 234 | } |
| 235 | |
Elyes HAOUAS | b77cf62 | 2018-05-02 21:01:18 +0200 | [diff] [blame] | 236 | static void get_resources(struct device *dev, struct pnp_info *info) |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 237 | { |
| 238 | struct resource *resource; |
| 239 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 240 | if (info->flags & PNP_IO0) |
Samuel Holland | 7daac91 | 2017-06-06 22:55:01 -0500 | [diff] [blame] | 241 | pnp_get_ioresource(dev, PNP_IDX_IO0, info->io0); |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 242 | if (info->flags & PNP_IO1) |
Samuel Holland | 7daac91 | 2017-06-06 22:55:01 -0500 | [diff] [blame] | 243 | pnp_get_ioresource(dev, PNP_IDX_IO1, info->io1); |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 244 | if (info->flags & PNP_IO2) |
Samuel Holland | 7daac91 | 2017-06-06 22:55:01 -0500 | [diff] [blame] | 245 | pnp_get_ioresource(dev, PNP_IDX_IO2, info->io2); |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 246 | if (info->flags & PNP_IO3) |
Samuel Holland | 7daac91 | 2017-06-06 22:55:01 -0500 | [diff] [blame] | 247 | pnp_get_ioresource(dev, PNP_IDX_IO3, info->io3); |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 248 | |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 249 | if (info->flags & PNP_IRQ0) { |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 250 | resource = new_resource(dev, PNP_IDX_IRQ0); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 251 | resource->size = 1; |
| 252 | resource->flags |= IORESOURCE_IRQ; |
| 253 | } |
| 254 | if (info->flags & PNP_IRQ1) { |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 255 | resource = new_resource(dev, PNP_IDX_IRQ1); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 256 | resource->size = 1; |
| 257 | resource->flags |= IORESOURCE_IRQ; |
| 258 | } |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 259 | |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 260 | if (info->flags & PNP_DRQ0) { |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 261 | resource = new_resource(dev, PNP_IDX_DRQ0); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 262 | resource->size = 1; |
| 263 | resource->flags |= IORESOURCE_DRQ; |
| 264 | } |
| 265 | if (info->flags & PNP_DRQ1) { |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 266 | resource = new_resource(dev, PNP_IDX_DRQ1); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 267 | resource->size = 1; |
| 268 | resource->flags |= IORESOURCE_DRQ; |
Stefan Reinauer | de3206a | 2010-02-22 06:09:43 +0000 | [diff] [blame] | 269 | } |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 270 | |
| 271 | /* |
| 272 | * These are not IRQs, but set the flag to have the |
| 273 | * resource allocator do the right thing. |
Stefan Reinauer | de3206a | 2010-02-22 06:09:43 +0000 | [diff] [blame] | 274 | */ |
| 275 | if (info->flags & PNP_EN) { |
| 276 | resource = new_resource(dev, PNP_IDX_EN); |
| 277 | resource->size = 1; |
| 278 | resource->flags |= IORESOURCE_IRQ; |
| 279 | } |
| 280 | if (info->flags & PNP_MSC0) { |
| 281 | resource = new_resource(dev, PNP_IDX_MSC0); |
| 282 | resource->size = 1; |
| 283 | resource->flags |= IORESOURCE_IRQ; |
| 284 | } |
| 285 | if (info->flags & PNP_MSC1) { |
| 286 | resource = new_resource(dev, PNP_IDX_MSC1); |
| 287 | resource->size = 1; |
| 288 | resource->flags |= IORESOURCE_IRQ; |
| 289 | } |
Damien Zammit | 62c0276 | 2015-12-28 23:04:47 +1100 | [diff] [blame] | 290 | if (info->flags & PNP_MSC2) { |
| 291 | resource = new_resource(dev, PNP_IDX_MSC2); |
| 292 | resource->size = 1; |
| 293 | resource->flags |= IORESOURCE_IRQ; |
| 294 | } |
| 295 | if (info->flags & PNP_MSC3) { |
| 296 | resource = new_resource(dev, PNP_IDX_MSC3); |
| 297 | resource->size = 1; |
| 298 | resource->flags |= IORESOURCE_IRQ; |
| 299 | } |
Stefan Reinauer | 0108b93 | 2013-12-11 11:06:08 -0800 | [diff] [blame] | 300 | if (info->flags & PNP_MSC4) { |
| 301 | resource = new_resource(dev, PNP_IDX_MSC4); |
| 302 | resource->size = 1; |
| 303 | resource->flags |= IORESOURCE_IRQ; |
| 304 | } |
Damien Zammit | 62c0276 | 2015-12-28 23:04:47 +1100 | [diff] [blame] | 305 | if (info->flags & PNP_MSC5) { |
| 306 | resource = new_resource(dev, PNP_IDX_MSC5); |
| 307 | resource->size = 1; |
| 308 | resource->flags |= IORESOURCE_IRQ; |
| 309 | } |
| 310 | if (info->flags & PNP_MSC6) { |
| 311 | resource = new_resource(dev, PNP_IDX_MSC6); |
| 312 | resource->size = 1; |
| 313 | resource->flags |= IORESOURCE_IRQ; |
| 314 | } |
| 315 | if (info->flags & PNP_MSC7) { |
| 316 | resource = new_resource(dev, PNP_IDX_MSC7); |
| 317 | resource->size = 1; |
| 318 | resource->flags |= IORESOURCE_IRQ; |
| 319 | } |
| 320 | if (info->flags & PNP_MSC8) { |
| 321 | resource = new_resource(dev, PNP_IDX_MSC8); |
| 322 | resource->size = 1; |
| 323 | resource->flags |= IORESOURCE_IRQ; |
| 324 | } |
| 325 | if (info->flags & PNP_MSC9) { |
| 326 | resource = new_resource(dev, PNP_IDX_MSC9); |
| 327 | resource->size = 1; |
| 328 | resource->flags |= IORESOURCE_IRQ; |
| 329 | } |
| 330 | if (info->flags & PNP_MSCA) { |
| 331 | resource = new_resource(dev, PNP_IDX_MSCA); |
| 332 | resource->size = 1; |
| 333 | resource->flags |= IORESOURCE_IRQ; |
| 334 | } |
| 335 | if (info->flags & PNP_MSCB) { |
| 336 | resource = new_resource(dev, PNP_IDX_MSCB); |
| 337 | resource->size = 1; |
| 338 | resource->flags |= IORESOURCE_IRQ; |
| 339 | } |
| 340 | if (info->flags & PNP_MSCC) { |
| 341 | resource = new_resource(dev, PNP_IDX_MSCC); |
| 342 | resource->size = 1; |
| 343 | resource->flags |= IORESOURCE_IRQ; |
| 344 | } |
| 345 | if (info->flags & PNP_MSCD) { |
| 346 | resource = new_resource(dev, PNP_IDX_MSCD); |
| 347 | resource->size = 1; |
| 348 | resource->flags |= IORESOURCE_IRQ; |
| 349 | } |
| 350 | if (info->flags & PNP_MSCE) { |
| 351 | resource = new_resource(dev, PNP_IDX_MSCE); |
Stefan Reinauer | 08ba7d0 | 2013-10-31 15:58:50 -0700 | [diff] [blame] | 352 | resource->size = 1; |
| 353 | resource->flags |= IORESOURCE_IRQ; |
| 354 | } |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 355 | } |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 356 | |
Elyes HAOUAS | b77cf62 | 2018-05-02 21:01:18 +0200 | [diff] [blame] | 357 | void pnp_enable_devices(struct device *base_dev, struct device_operations *ops, |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 358 | unsigned int functions, struct pnp_info *info) |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 359 | { |
| 360 | struct device_path path; |
Elyes HAOUAS | b77cf62 | 2018-05-02 21:01:18 +0200 | [diff] [blame] | 361 | struct device *dev; |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 362 | int i; |
| 363 | |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 364 | path.type = DEVICE_PATH_PNP; |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 365 | path.pnp.port = base_dev->path.pnp.port; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 366 | |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 367 | /* Setup the ops and resources on the newly allocated devices. */ |
| 368 | for (i = 0; i < functions; i++) { |
Uwe Hermann | aa4bedf | 2007-07-12 13:12:47 +0000 | [diff] [blame] | 369 | /* Skip logical devices this Super I/O doesn't have. */ |
| 370 | if (info[i].function == -1) |
| 371 | continue; |
| 372 | |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 373 | path.pnp.device = info[i].function; |
Eric Biederman | 7003ba4 | 2004-10-16 06:20:29 +0000 | [diff] [blame] | 374 | dev = alloc_find_dev(base_dev->bus, &path); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 375 | |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 376 | /* Don't initialize a device multiple times. */ |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 377 | if (dev->ops) |
Eric Biederman | 7003ba4 | 2004-10-16 06:20:29 +0000 | [diff] [blame] | 378 | continue; |
Li-Ta Lo | c6bcedb | 2004-04-21 16:57:05 +0000 | [diff] [blame] | 379 | |
Felix Held | 745e58a | 2018-07-06 19:38:24 +0200 | [diff] [blame] | 380 | /* use LDN-specific ops override from corresponding pnp_info |
| 381 | entry if not NULL */ |
| 382 | if (info[i].ops) |
Li-Ta Lo | 75337f7 | 2004-05-07 21:56:48 +0000 | [diff] [blame] | 383 | dev->ops = info[i].ops; |
Felix Held | 745e58a | 2018-07-06 19:38:24 +0200 | [diff] [blame] | 384 | /* else use device ops */ |
| 385 | else |
| 386 | dev->ops = ops; |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 387 | |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 388 | get_resources(dev, &info[i]); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 389 | } |
| 390 | } |