Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * PCMCIA 16-bit resource management functions |
| 3 | * |
| 4 | * The initial developer of the original code is David A. Hinds |
| 5 | * <dahinds@users.sourceforge.net>. Portions created by David A. Hinds |
| 6 | * are Copyright (C) 1999 David A. Hinds. All Rights Reserved. |
| 7 | * |
| 8 | * Copyright (C) 1999 David A. Hinds |
| 9 | * Copyright (C) 2004-2005 Dominik Brodowski |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License version 2 as |
| 13 | * published by the Free Software Foundation. |
| 14 | * |
| 15 | */ |
| 16 | |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 17 | #include <linux/module.h> |
| 18 | #include <linux/kernel.h> |
| 19 | #include <linux/interrupt.h> |
| 20 | #include <linux/delay.h> |
| 21 | #include <linux/pci.h> |
| 22 | #include <linux/device.h> |
Dominik Brodowski | 9128422 | 2009-10-18 23:32:33 +0200 | [diff] [blame] | 23 | #include <linux/netdevice.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 24 | #include <linux/slab.h> |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 25 | |
Dominik Brodowski | 6f0f38c | 2010-04-08 20:33:16 +0200 | [diff] [blame] | 26 | #include <asm/irq.h> |
| 27 | |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 28 | #include <pcmcia/ss.h> |
| 29 | #include <pcmcia/cs.h> |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 30 | #include <pcmcia/cistpl.h> |
| 31 | #include <pcmcia/cisreg.h> |
| 32 | #include <pcmcia/ds.h> |
| 33 | |
| 34 | #include "cs_internal.h" |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 35 | |
| 36 | |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 37 | /* Access speed for IO windows */ |
Dominik Brodowski | 9fea84f | 2009-12-07 22:11:45 +0100 | [diff] [blame] | 38 | static int io_speed; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 39 | module_param(io_speed, int, 0444); |
| 40 | |
| 41 | |
Dominik Brodowski | a3ac9af | 2010-01-06 14:03:03 +0100 | [diff] [blame] | 42 | int pcmcia_validate_mem(struct pcmcia_socket *s) |
| 43 | { |
| 44 | if (s->resource_ops->validate_mem) |
| 45 | return s->resource_ops->validate_mem(s); |
| 46 | /* if there is no callback, we can assume that everything is OK */ |
| 47 | return 0; |
| 48 | } |
| 49 | |
| 50 | struct resource *pcmcia_find_mem_region(u_long base, u_long num, u_long align, |
| 51 | int low, struct pcmcia_socket *s) |
| 52 | { |
| 53 | if (s->resource_ops->find_mem) |
| 54 | return s->resource_ops->find_mem(base, num, align, low, s); |
| 55 | return NULL; |
| 56 | } |
| 57 | |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 58 | |
Dominik Brodowski | ad0c7be | 2010-07-25 13:10:22 +0200 | [diff] [blame] | 59 | static void release_io_space(struct pcmcia_socket *s, struct resource *res) |
| 60 | { |
| 61 | resource_size_t num = resource_size(res); |
| 62 | int i; |
| 63 | |
| 64 | dev_dbg(&s->dev, "release_io_space for %pR\n", res); |
| 65 | |
| 66 | for (i = 0; i < MAX_IO_WIN; i++) { |
| 67 | if (!s->io[i].res) |
| 68 | continue; |
| 69 | if ((s->io[i].res->start <= res->start) && |
| 70 | (s->io[i].res->end >= res->end)) { |
| 71 | s->io[i].InUse -= num; |
| 72 | if (res->parent) |
| 73 | release_resource(res); |
| 74 | res->start = res->end = 0; |
| 75 | res->flags = IORESOURCE_IO; |
| 76 | /* Free the window if no one else is using it */ |
| 77 | if (s->io[i].InUse == 0) { |
| 78 | release_resource(s->io[i].res); |
| 79 | kfree(s->io[i].res); |
| 80 | s->io[i].res = NULL; |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | } /* release_io_space */ |
| 85 | |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 86 | /** alloc_io_space |
| 87 | * |
| 88 | * Special stuff for managing IO windows, because they are scarce |
| 89 | */ |
Dominik Brodowski | 2ce4905 | 2010-07-24 13:14:44 +0200 | [diff] [blame] | 90 | static int alloc_io_space(struct pcmcia_socket *s, struct resource *res, |
| 91 | unsigned int lines) |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 92 | { |
Dominik Brodowski | b19a727 | 2010-03-20 13:10:47 +0100 | [diff] [blame] | 93 | unsigned int align; |
Dominik Brodowski | 2ce4905 | 2010-07-24 13:14:44 +0200 | [diff] [blame] | 94 | unsigned int base = res->start; |
| 95 | unsigned int num = res->end; |
| 96 | int ret; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 97 | |
Dominik Brodowski | 2ce4905 | 2010-07-24 13:14:44 +0200 | [diff] [blame] | 98 | res->flags |= IORESOURCE_IO; |
| 99 | |
Dominik Brodowski | 90abdc3 | 2010-07-24 17:23:51 +0200 | [diff] [blame] | 100 | dev_dbg(&s->dev, "alloc_io_space request for %pR, %d lines\n", |
| 101 | res, lines); |
Dominik Brodowski | 2ce4905 | 2010-07-24 13:14:44 +0200 | [diff] [blame] | 102 | |
| 103 | align = base ? (lines ? 1<<lines : 0) : 1; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 104 | if (align && (align < num)) { |
Dominik Brodowski | 2ce4905 | 2010-07-24 13:14:44 +0200 | [diff] [blame] | 105 | if (base) { |
| 106 | dev_dbg(&s->dev, "odd IO request\n"); |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 107 | align = 0; |
| 108 | } else |
Dominik Brodowski | 9fea84f | 2009-12-07 22:11:45 +0100 | [diff] [blame] | 109 | while (align && (align < num)) |
| 110 | align <<= 1; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 111 | } |
Dominik Brodowski | 2ce4905 | 2010-07-24 13:14:44 +0200 | [diff] [blame] | 112 | if (base & ~(align-1)) { |
| 113 | dev_dbg(&s->dev, "odd IO request\n"); |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 114 | align = 0; |
| 115 | } |
Dominik Brodowski | b19a727 | 2010-03-20 13:10:47 +0100 | [diff] [blame] | 116 | |
Dominik Brodowski | ad0c7be | 2010-07-25 13:10:22 +0200 | [diff] [blame] | 117 | ret = s->resource_ops->find_io(s, res->flags, &base, num, align, |
| 118 | &res->parent); |
Dominik Brodowski | 2ce4905 | 2010-07-24 13:14:44 +0200 | [diff] [blame] | 119 | if (ret) { |
Dominik Brodowski | ad0c7be | 2010-07-25 13:10:22 +0200 | [diff] [blame] | 120 | dev_dbg(&s->dev, "alloc_io_space request failed (%d)\n", ret); |
Dominik Brodowski | 2ce4905 | 2010-07-24 13:14:44 +0200 | [diff] [blame] | 121 | return -EINVAL; |
| 122 | } |
| 123 | |
| 124 | res->start = base; |
| 125 | res->end = res->start + num - 1; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 126 | |
Dominik Brodowski | ad0c7be | 2010-07-25 13:10:22 +0200 | [diff] [blame] | 127 | if (res->parent) { |
| 128 | ret = request_resource(res->parent, res); |
| 129 | if (ret) { |
| 130 | dev_warn(&s->dev, |
| 131 | "request_resource %pR failed: %d\n", res, ret); |
| 132 | res->parent = NULL; |
| 133 | release_io_space(s, res); |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 134 | } |
| 135 | } |
Dominik Brodowski | ad0c7be | 2010-07-25 13:10:22 +0200 | [diff] [blame] | 136 | dev_dbg(&s->dev, "alloc_io_space request result %d: %pR\n", ret, res); |
| 137 | return ret; |
| 138 | } /* alloc_io_space */ |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 139 | |
| 140 | |
Dominik Brodowski | 1d5cc19 | 2010-07-24 12:23:21 +0200 | [diff] [blame] | 141 | /** |
| 142 | * pcmcia_access_config() - read or write card configuration registers |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 143 | * |
Dominik Brodowski | 1d5cc19 | 2010-07-24 12:23:21 +0200 | [diff] [blame] | 144 | * pcmcia_access_config() reads and writes configuration registers in |
| 145 | * attribute memory. Memory window 0 is reserved for this and the tuple |
| 146 | * reading services. Drivers must use pcmcia_read_config_byte() or |
| 147 | * pcmcia_write_config_byte(). |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 148 | */ |
Dominik Brodowski | 1d5cc19 | 2010-07-24 12:23:21 +0200 | [diff] [blame] | 149 | static int pcmcia_access_config(struct pcmcia_device *p_dev, |
| 150 | off_t where, u8 *val, |
| 151 | int (*accessf) (struct pcmcia_socket *s, |
| 152 | int attr, unsigned int addr, |
| 153 | unsigned int len, void *ptr)) |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 154 | { |
Dominik Brodowski | 855cdf1 | 2006-01-10 20:48:59 +0100 | [diff] [blame] | 155 | struct pcmcia_socket *s; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 156 | config_t *c; |
| 157 | int addr; |
Dominik Brodowski | 059f667 | 2010-03-30 18:07:50 +0200 | [diff] [blame] | 158 | int ret = 0; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 159 | |
Dominik Brodowski | 855cdf1 | 2006-01-10 20:48:59 +0100 | [diff] [blame] | 160 | s = p_dev->socket; |
Dominik Brodowski | 94a819f | 2010-01-17 18:31:34 +0100 | [diff] [blame] | 161 | |
| 162 | mutex_lock(&s->ops_mutex); |
Dominik Brodowski | 855cdf1 | 2006-01-10 20:48:59 +0100 | [diff] [blame] | 163 | c = p_dev->function_config; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 164 | |
Dominik Brodowski | 6d9a299 | 2009-10-24 12:20:18 +0200 | [diff] [blame] | 165 | if (!(c->state & CONFIG_LOCKED)) { |
Dominik Brodowski | eb838fe | 2010-09-13 16:51:36 +0200 | [diff] [blame] | 166 | dev_dbg(&p_dev->dev, "Configuration isnt't locked\n"); |
Dominik Brodowski | 94a819f | 2010-01-17 18:31:34 +0100 | [diff] [blame] | 167 | mutex_unlock(&s->ops_mutex); |
Dominik Brodowski | 943f70f | 2008-08-03 11:23:42 +0200 | [diff] [blame] | 168 | return -EACCES; |
Dominik Brodowski | 6d9a299 | 2009-10-24 12:20:18 +0200 | [diff] [blame] | 169 | } |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 170 | |
Dominik Brodowski | 1d5cc19 | 2010-07-24 12:23:21 +0200 | [diff] [blame] | 171 | addr = (c->ConfigBase + where) >> 1; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 172 | |
Dominik Brodowski | 1d5cc19 | 2010-07-24 12:23:21 +0200 | [diff] [blame] | 173 | ret = accessf(s, 1, addr, 1, val); |
| 174 | |
Dominik Brodowski | 059f667 | 2010-03-30 18:07:50 +0200 | [diff] [blame] | 175 | mutex_unlock(&s->ops_mutex); |
Dominik Brodowski | 1d5cc19 | 2010-07-24 12:23:21 +0200 | [diff] [blame] | 176 | |
Dominik Brodowski | 059f667 | 2010-03-30 18:07:50 +0200 | [diff] [blame] | 177 | return ret; |
Dominik Brodowski | 1d5cc19 | 2010-07-24 12:23:21 +0200 | [diff] [blame] | 178 | } /* pcmcia_access_config */ |
| 179 | |
| 180 | |
| 181 | /** |
| 182 | * pcmcia_read_config_byte() - read a byte from a card configuration register |
| 183 | * |
| 184 | * pcmcia_read_config_byte() reads a byte from a configuration register in |
| 185 | * attribute memory. |
| 186 | */ |
| 187 | int pcmcia_read_config_byte(struct pcmcia_device *p_dev, off_t where, u8 *val) |
| 188 | { |
| 189 | return pcmcia_access_config(p_dev, where, val, pcmcia_read_cis_mem); |
| 190 | } |
| 191 | EXPORT_SYMBOL(pcmcia_read_config_byte); |
| 192 | |
| 193 | |
| 194 | /** |
| 195 | * pcmcia_write_config_byte() - write a byte to a card configuration register |
| 196 | * |
| 197 | * pcmcia_write_config_byte() writes a byte to a configuration register in |
| 198 | * attribute memory. |
| 199 | */ |
| 200 | int pcmcia_write_config_byte(struct pcmcia_device *p_dev, off_t where, u8 val) |
| 201 | { |
| 202 | return pcmcia_access_config(p_dev, where, &val, pcmcia_write_cis_mem); |
| 203 | } |
| 204 | EXPORT_SYMBOL(pcmcia_write_config_byte); |
Dominik Brodowski | 3448139 | 2005-06-27 16:28:54 -0700 | [diff] [blame] | 205 | |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 206 | |
Magnus Damm | 868575d | 2006-12-13 19:46:43 +0900 | [diff] [blame] | 207 | int pcmcia_map_mem_page(struct pcmcia_device *p_dev, window_handle_t wh, |
Dominik Brodowski | b5cb259 | 2010-07-24 18:46:42 +0200 | [diff] [blame] | 208 | unsigned int offset) |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 209 | { |
Magnus Damm | 0bdf9b3 | 2006-12-13 19:46:53 +0900 | [diff] [blame] | 210 | struct pcmcia_socket *s = p_dev->socket; |
Dominik Brodowski | 0ca724d | 2010-07-24 19:03:02 +0200 | [diff] [blame] | 211 | struct resource *res = wh; |
| 212 | unsigned int w; |
Dominik Brodowski | 6b8e087 | 2010-01-12 21:42:51 +0100 | [diff] [blame] | 213 | int ret; |
Magnus Damm | 868575d | 2006-12-13 19:46:43 +0900 | [diff] [blame] | 214 | |
Dominik Brodowski | 0ca724d | 2010-07-24 19:03:02 +0200 | [diff] [blame] | 215 | w = ((res->flags & IORESOURCE_BITS & WIN_FLAGS_REQ) >> 2) - 1; |
| 216 | if (w >= MAX_WIN) |
Dominik Brodowski | ffb8da2 | 2008-08-03 11:18:00 +0200 | [diff] [blame] | 217 | return -EINVAL; |
Dominik Brodowski | b5cb259 | 2010-07-24 18:46:42 +0200 | [diff] [blame] | 218 | |
Dominik Brodowski | 6b8e087 | 2010-01-12 21:42:51 +0100 | [diff] [blame] | 219 | mutex_lock(&s->ops_mutex); |
Dominik Brodowski | 0ca724d | 2010-07-24 19:03:02 +0200 | [diff] [blame] | 220 | s->win[w].card_start = offset; |
| 221 | ret = s->ops->set_mem_map(s, &s->win[w]); |
Dominik Brodowski | 6b8e087 | 2010-01-12 21:42:51 +0100 | [diff] [blame] | 222 | if (ret) |
Dominik Brodowski | eb838fe | 2010-09-13 16:51:36 +0200 | [diff] [blame] | 223 | dev_warn(&p_dev->dev, "failed to set_mem_map\n"); |
Dominik Brodowski | 6b8e087 | 2010-01-12 21:42:51 +0100 | [diff] [blame] | 224 | mutex_unlock(&s->ops_mutex); |
| 225 | return ret; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 226 | } /* pcmcia_map_mem_page */ |
| 227 | EXPORT_SYMBOL(pcmcia_map_mem_page); |
| 228 | |
| 229 | |
| 230 | /** pcmcia_modify_configuration |
| 231 | * |
| 232 | * Modify a locked socket configuration |
| 233 | */ |
Dominik Brodowski | 2bc5a9b | 2005-07-07 17:59:02 -0700 | [diff] [blame] | 234 | int pcmcia_modify_configuration(struct pcmcia_device *p_dev, |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 235 | modconf_t *mod) |
| 236 | { |
| 237 | struct pcmcia_socket *s; |
| 238 | config_t *c; |
Jiri Slaby | 4e06e24 | 2010-03-16 15:57:44 +0100 | [diff] [blame] | 239 | int ret; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 240 | |
Dominik Brodowski | 2bc5a9b | 2005-07-07 17:59:02 -0700 | [diff] [blame] | 241 | s = p_dev->socket; |
Dominik Brodowski | 94a819f | 2010-01-17 18:31:34 +0100 | [diff] [blame] | 242 | |
| 243 | mutex_lock(&s->ops_mutex); |
Dominik Brodowski | dbb22f0 | 2006-01-10 20:41:27 +0100 | [diff] [blame] | 244 | c = p_dev->function_config; |
| 245 | |
Dominik Brodowski | 6d9a299 | 2009-10-24 12:20:18 +0200 | [diff] [blame] | 246 | if (!(s->state & SOCKET_PRESENT)) { |
Dominik Brodowski | eb838fe | 2010-09-13 16:51:36 +0200 | [diff] [blame] | 247 | dev_dbg(&p_dev->dev, "No card present\n"); |
Jiri Slaby | 4e06e24 | 2010-03-16 15:57:44 +0100 | [diff] [blame] | 248 | ret = -ENODEV; |
| 249 | goto unlock; |
Dominik Brodowski | 6d9a299 | 2009-10-24 12:20:18 +0200 | [diff] [blame] | 250 | } |
| 251 | if (!(c->state & CONFIG_LOCKED)) { |
Dominik Brodowski | eb838fe | 2010-09-13 16:51:36 +0200 | [diff] [blame] | 252 | dev_dbg(&p_dev->dev, "Configuration isnt't locked\n"); |
Jiri Slaby | 4e06e24 | 2010-03-16 15:57:44 +0100 | [diff] [blame] | 253 | ret = -EACCES; |
| 254 | goto unlock; |
Dominik Brodowski | 6d9a299 | 2009-10-24 12:20:18 +0200 | [diff] [blame] | 255 | } |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 256 | |
Dominik Brodowski | 0cb3c49 | 2010-03-06 20:42:35 +0100 | [diff] [blame] | 257 | if (mod->Attributes & (CONF_IRQ_CHANGE_VALID | CONF_VCC_CHANGE_VALID)) { |
Dominik Brodowski | eb838fe | 2010-09-13 16:51:36 +0200 | [diff] [blame] | 258 | dev_dbg(&p_dev->dev, |
Dominik Brodowski | 0cb3c49 | 2010-03-06 20:42:35 +0100 | [diff] [blame] | 259 | "changing Vcc or IRQ is not allowed at this time\n"); |
Jiri Slaby | 4e06e24 | 2010-03-16 15:57:44 +0100 | [diff] [blame] | 260 | ret = -EINVAL; |
| 261 | goto unlock; |
Dominik Brodowski | d8b0a49 | 2008-08-03 10:56:13 +0200 | [diff] [blame] | 262 | } |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 263 | |
| 264 | /* We only allow changing Vpp1 and Vpp2 to the same value */ |
| 265 | if ((mod->Attributes & CONF_VPP1_CHANGE_VALID) && |
| 266 | (mod->Attributes & CONF_VPP2_CHANGE_VALID)) { |
Ilpo Järvinen | 60df3de8 | 2008-10-30 13:02:54 +0200 | [diff] [blame] | 267 | if (mod->Vpp1 != mod->Vpp2) { |
Dominik Brodowski | eb838fe | 2010-09-13 16:51:36 +0200 | [diff] [blame] | 268 | dev_dbg(&p_dev->dev, |
| 269 | "Vpp1 and Vpp2 must be the same\n"); |
Jiri Slaby | 4e06e24 | 2010-03-16 15:57:44 +0100 | [diff] [blame] | 270 | ret = -EINVAL; |
| 271 | goto unlock; |
Ilpo Järvinen | 60df3de8 | 2008-10-30 13:02:54 +0200 | [diff] [blame] | 272 | } |
Dominik Brodowski | 71ed90d | 2005-09-09 13:03:27 -0700 | [diff] [blame] | 273 | s->socket.Vpp = mod->Vpp1; |
Dominik Brodowski | d8b0a49 | 2008-08-03 10:56:13 +0200 | [diff] [blame] | 274 | if (s->ops->set_socket(s, &s->socket)) { |
Dominik Brodowski | eb838fe | 2010-09-13 16:51:36 +0200 | [diff] [blame] | 275 | dev_printk(KERN_WARNING, &p_dev->dev, |
Dominik Brodowski | d8b0a49 | 2008-08-03 10:56:13 +0200 | [diff] [blame] | 276 | "Unable to set VPP\n"); |
Jiri Slaby | 4e06e24 | 2010-03-16 15:57:44 +0100 | [diff] [blame] | 277 | ret = -EIO; |
| 278 | goto unlock; |
Dominik Brodowski | d8b0a49 | 2008-08-03 10:56:13 +0200 | [diff] [blame] | 279 | } |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 280 | } else if ((mod->Attributes & CONF_VPP1_CHANGE_VALID) || |
Dominik Brodowski | d8b0a49 | 2008-08-03 10:56:13 +0200 | [diff] [blame] | 281 | (mod->Attributes & CONF_VPP2_CHANGE_VALID)) { |
Dominik Brodowski | eb838fe | 2010-09-13 16:51:36 +0200 | [diff] [blame] | 282 | dev_dbg(&p_dev->dev, |
| 283 | "changing Vcc is not allowed at this time\n"); |
Jiri Slaby | 4e06e24 | 2010-03-16 15:57:44 +0100 | [diff] [blame] | 284 | ret = -EINVAL; |
| 285 | goto unlock; |
Dominik Brodowski | d8b0a49 | 2008-08-03 10:56:13 +0200 | [diff] [blame] | 286 | } |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 287 | |
Dominik Brodowski | 4bbed52 | 2006-01-15 11:18:12 +0100 | [diff] [blame] | 288 | if (mod->Attributes & CONF_IO_CHANGE_WIDTH) { |
| 289 | pccard_io_map io_off = { 0, 0, 0, 0, 1 }; |
| 290 | pccard_io_map io_on; |
| 291 | int i; |
| 292 | |
| 293 | io_on.speed = io_speed; |
| 294 | for (i = 0; i < MAX_IO_WIN; i++) { |
| 295 | if (!s->io[i].res) |
| 296 | continue; |
| 297 | io_off.map = i; |
| 298 | io_on.map = i; |
| 299 | |
| 300 | io_on.flags = MAP_ACTIVE | IO_DATA_PATH_WIDTH_8; |
| 301 | io_on.start = s->io[i].res->start; |
| 302 | io_on.stop = s->io[i].res->end; |
| 303 | |
| 304 | s->ops->set_io_map(s, &io_off); |
| 305 | mdelay(40); |
| 306 | s->ops->set_io_map(s, &io_on); |
| 307 | } |
| 308 | } |
Jiri Slaby | 4e06e24 | 2010-03-16 15:57:44 +0100 | [diff] [blame] | 309 | ret = 0; |
| 310 | unlock: |
Dominik Brodowski | 94a819f | 2010-01-17 18:31:34 +0100 | [diff] [blame] | 311 | mutex_unlock(&s->ops_mutex); |
Dominik Brodowski | 4bbed52 | 2006-01-15 11:18:12 +0100 | [diff] [blame] | 312 | |
Jiri Slaby | 4e06e24 | 2010-03-16 15:57:44 +0100 | [diff] [blame] | 313 | return ret; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 314 | } /* modify_configuration */ |
| 315 | EXPORT_SYMBOL(pcmcia_modify_configuration); |
| 316 | |
| 317 | |
Dominik Brodowski | 2bc5a9b | 2005-07-07 17:59:02 -0700 | [diff] [blame] | 318 | int pcmcia_release_configuration(struct pcmcia_device *p_dev) |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 319 | { |
| 320 | pccard_io_map io = { 0, 0, 0, 0, 1 }; |
Dominik Brodowski | 2bc5a9b | 2005-07-07 17:59:02 -0700 | [diff] [blame] | 321 | struct pcmcia_socket *s = p_dev->socket; |
Dominik Brodowski | 94a819f | 2010-01-17 18:31:34 +0100 | [diff] [blame] | 322 | config_t *c; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 323 | int i; |
| 324 | |
Dominik Brodowski | 9e86749c | 2010-01-16 00:26:33 +0100 | [diff] [blame] | 325 | mutex_lock(&s->ops_mutex); |
Dominik Brodowski | 94a819f | 2010-01-17 18:31:34 +0100 | [diff] [blame] | 326 | c = p_dev->function_config; |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 327 | if (p_dev->_locked) { |
| 328 | p_dev->_locked = 0; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 329 | if (--(s->lock_count) == 0) { |
| 330 | s->socket.flags = SS_OUTPUT_ENA; /* Is this correct? */ |
| 331 | s->socket.Vpp = 0; |
| 332 | s->socket.io_irq = 0; |
| 333 | s->ops->set_socket(s, &s->socket); |
| 334 | } |
Dominik Brodowski | 5f2a71f | 2006-01-15 09:32:39 +0100 | [diff] [blame] | 335 | } |
| 336 | if (c->state & CONFIG_LOCKED) { |
| 337 | c->state &= ~CONFIG_LOCKED; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 338 | if (c->state & CONFIG_IO_REQ) |
| 339 | for (i = 0; i < MAX_IO_WIN; i++) { |
Dominik Brodowski | c7d0069 | 2006-01-15 08:04:43 +0100 | [diff] [blame] | 340 | if (!s->io[i].res) |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 341 | continue; |
| 342 | s->io[i].Config--; |
| 343 | if (s->io[i].Config != 0) |
| 344 | continue; |
| 345 | io.map = i; |
| 346 | s->ops->set_io_map(s, &io); |
| 347 | } |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 348 | } |
Dominik Brodowski | 9e86749c | 2010-01-16 00:26:33 +0100 | [diff] [blame] | 349 | mutex_unlock(&s->ops_mutex); |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 350 | |
Dominik Brodowski | 4c89e88 | 2008-08-03 10:07:45 +0200 | [diff] [blame] | 351 | return 0; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 352 | } /* pcmcia_release_configuration */ |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 353 | |
| 354 | |
| 355 | /** pcmcia_release_io |
| 356 | * |
| 357 | * Release_io() releases the I/O ranges allocated by a client. This |
| 358 | * may be invoked some time after a card ejection has already dumped |
| 359 | * the actual socket configuration, so if the client is "stale", we |
| 360 | * don't bother checking the port ranges against the current socket |
| 361 | * values. |
| 362 | */ |
Dominik Brodowski | 2ce4905 | 2010-07-24 13:14:44 +0200 | [diff] [blame] | 363 | static int pcmcia_release_io(struct pcmcia_device *p_dev) |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 364 | { |
Dominik Brodowski | 2bc5a9b | 2005-07-07 17:59:02 -0700 | [diff] [blame] | 365 | struct pcmcia_socket *s = p_dev->socket; |
Dominik Brodowski | 94a819f | 2010-01-17 18:31:34 +0100 | [diff] [blame] | 366 | int ret = -EINVAL; |
| 367 | config_t *c; |
| 368 | |
| 369 | mutex_lock(&s->ops_mutex); |
Dominik Brodowski | 9fea84f | 2009-12-07 22:11:45 +0100 | [diff] [blame] | 370 | if (!p_dev->_io) |
Dominik Brodowski | 94a819f | 2010-01-17 18:31:34 +0100 | [diff] [blame] | 371 | goto out; |
Dominik Brodowski | 5f2a71f | 2006-01-15 09:32:39 +0100 | [diff] [blame] | 372 | |
Dominik Brodowski | 2ce4905 | 2010-07-24 13:14:44 +0200 | [diff] [blame] | 373 | c = p_dev->function_config; |
| 374 | |
| 375 | release_io_space(s, &c->io[0]); |
| 376 | |
| 377 | if (c->io[1].end) |
| 378 | release_io_space(s, &c->io[1]); |
| 379 | |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 380 | p_dev->_io = 0; |
Dominik Brodowski | 5f2a71f | 2006-01-15 09:32:39 +0100 | [diff] [blame] | 381 | c->state &= ~CONFIG_IO_REQ; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 382 | |
Dominik Brodowski | 94a819f | 2010-01-17 18:31:34 +0100 | [diff] [blame] | 383 | out: |
| 384 | mutex_unlock(&s->ops_mutex); |
| 385 | |
| 386 | return ret; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 387 | } /* pcmcia_release_io */ |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 388 | |
| 389 | |
Dominik Brodowski | 0ca724d | 2010-07-24 19:03:02 +0200 | [diff] [blame] | 390 | int pcmcia_release_window(struct pcmcia_device *p_dev, struct resource *res) |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 391 | { |
Magnus Damm | 0bdf9b3 | 2006-12-13 19:46:53 +0900 | [diff] [blame] | 392 | struct pcmcia_socket *s = p_dev->socket; |
Dominik Brodowski | 82f88e3 | 2009-11-03 01:16:12 +0100 | [diff] [blame] | 393 | pccard_mem_map *win; |
Dominik Brodowski | 0ca724d | 2010-07-24 19:03:02 +0200 | [diff] [blame] | 394 | unsigned int w; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 395 | |
Dominik Brodowski | 0ca724d | 2010-07-24 19:03:02 +0200 | [diff] [blame] | 396 | dev_dbg(&p_dev->dev, "releasing window %pR\n", res); |
| 397 | |
| 398 | w = ((res->flags & IORESOURCE_BITS & WIN_FLAGS_REQ) >> 2) - 1; |
| 399 | if (w >= MAX_WIN) |
Dominik Brodowski | ffb8da2 | 2008-08-03 11:18:00 +0200 | [diff] [blame] | 400 | return -EINVAL; |
Magnus Damm | 0bdf9b3 | 2006-12-13 19:46:53 +0900 | [diff] [blame] | 401 | |
Dominik Brodowski | 6b8e087 | 2010-01-12 21:42:51 +0100 | [diff] [blame] | 402 | mutex_lock(&s->ops_mutex); |
Dominik Brodowski | 0ca724d | 2010-07-24 19:03:02 +0200 | [diff] [blame] | 403 | win = &s->win[w]; |
Magnus Damm | 0bdf9b3 | 2006-12-13 19:46:53 +0900 | [diff] [blame] | 404 | |
Dominik Brodowski | 0ca724d | 2010-07-24 19:03:02 +0200 | [diff] [blame] | 405 | if (!(p_dev->_win & CLIENT_WIN_REQ(w))) { |
Dominik Brodowski | eb838fe | 2010-09-13 16:51:36 +0200 | [diff] [blame] | 406 | dev_dbg(&p_dev->dev, "not releasing unknown window\n"); |
Dominik Brodowski | 6b8e087 | 2010-01-12 21:42:51 +0100 | [diff] [blame] | 407 | mutex_unlock(&s->ops_mutex); |
Dominik Brodowski | ffb8da2 | 2008-08-03 11:18:00 +0200 | [diff] [blame] | 408 | return -EINVAL; |
Dominik Brodowski | 6d9a299 | 2009-10-24 12:20:18 +0200 | [diff] [blame] | 409 | } |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 410 | |
| 411 | /* Shut down memory window */ |
Dominik Brodowski | 82f88e3 | 2009-11-03 01:16:12 +0100 | [diff] [blame] | 412 | win->flags &= ~MAP_ACTIVE; |
| 413 | s->ops->set_mem_map(s, win); |
Dominik Brodowski | 0ca724d | 2010-07-24 19:03:02 +0200 | [diff] [blame] | 414 | s->state &= ~SOCKET_WIN_REQ(w); |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 415 | |
| 416 | /* Release system memory */ |
Dominik Brodowski | 82f88e3 | 2009-11-03 01:16:12 +0100 | [diff] [blame] | 417 | if (win->res) { |
Dominik Brodowski | ad0c7be | 2010-07-25 13:10:22 +0200 | [diff] [blame] | 418 | release_resource(res); |
Dominik Brodowski | 82f88e3 | 2009-11-03 01:16:12 +0100 | [diff] [blame] | 419 | release_resource(win->res); |
| 420 | kfree(win->res); |
| 421 | win->res = NULL; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 422 | } |
Dominik Brodowski | 0ca724d | 2010-07-24 19:03:02 +0200 | [diff] [blame] | 423 | p_dev->_win &= ~CLIENT_WIN_REQ(w); |
Dominik Brodowski | 6b8e087 | 2010-01-12 21:42:51 +0100 | [diff] [blame] | 424 | mutex_unlock(&s->ops_mutex); |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 425 | |
Dominik Brodowski | 4c89e88 | 2008-08-03 10:07:45 +0200 | [diff] [blame] | 426 | return 0; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 427 | } /* pcmcia_release_window */ |
| 428 | EXPORT_SYMBOL(pcmcia_release_window); |
| 429 | |
| 430 | |
Dominik Brodowski | 2bc5a9b | 2005-07-07 17:59:02 -0700 | [diff] [blame] | 431 | int pcmcia_request_configuration(struct pcmcia_device *p_dev, |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 432 | config_req_t *req) |
| 433 | { |
| 434 | int i; |
| 435 | u_int base; |
Dominik Brodowski | 2bc5a9b | 2005-07-07 17:59:02 -0700 | [diff] [blame] | 436 | struct pcmcia_socket *s = p_dev->socket; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 437 | config_t *c; |
| 438 | pccard_io_map iomap; |
| 439 | |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 440 | if (!(s->state & SOCKET_PRESENT)) |
Joe Perches | d598de0 | 2009-06-28 09:26:41 -0700 | [diff] [blame] | 441 | return -ENODEV; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 442 | |
Dominik Brodowski | de6405e | 2008-08-03 10:47:59 +0200 | [diff] [blame] | 443 | if (req->IntType & INT_CARDBUS) { |
Dominik Brodowski | eb838fe | 2010-09-13 16:51:36 +0200 | [diff] [blame] | 444 | dev_dbg(&p_dev->dev, "IntType may not be INT_CARDBUS\n"); |
Dominik Brodowski | de6405e | 2008-08-03 10:47:59 +0200 | [diff] [blame] | 445 | return -EINVAL; |
| 446 | } |
Dominik Brodowski | 94a819f | 2010-01-17 18:31:34 +0100 | [diff] [blame] | 447 | |
| 448 | mutex_lock(&s->ops_mutex); |
Dominik Brodowski | dbb22f0 | 2006-01-10 20:41:27 +0100 | [diff] [blame] | 449 | c = p_dev->function_config; |
Dominik Brodowski | 6d9a299 | 2009-10-24 12:20:18 +0200 | [diff] [blame] | 450 | if (c->state & CONFIG_LOCKED) { |
Dominik Brodowski | 94a819f | 2010-01-17 18:31:34 +0100 | [diff] [blame] | 451 | mutex_unlock(&s->ops_mutex); |
Dominik Brodowski | eb838fe | 2010-09-13 16:51:36 +0200 | [diff] [blame] | 452 | dev_dbg(&p_dev->dev, "Configuration is locked\n"); |
Dominik Brodowski | 943f70f | 2008-08-03 11:23:42 +0200 | [diff] [blame] | 453 | return -EACCES; |
Dominik Brodowski | 6d9a299 | 2009-10-24 12:20:18 +0200 | [diff] [blame] | 454 | } |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 455 | |
| 456 | /* Do power control. We don't allow changes in Vcc. */ |
Dominik Brodowski | 70294b4 | 2006-01-15 12:43:16 +0100 | [diff] [blame] | 457 | s->socket.Vpp = req->Vpp; |
Dominik Brodowski | d8b0a49 | 2008-08-03 10:56:13 +0200 | [diff] [blame] | 458 | if (s->ops->set_socket(s, &s->socket)) { |
Dominik Brodowski | 9e86749c | 2010-01-16 00:26:33 +0100 | [diff] [blame] | 459 | mutex_unlock(&s->ops_mutex); |
Dominik Brodowski | eb838fe | 2010-09-13 16:51:36 +0200 | [diff] [blame] | 460 | dev_printk(KERN_WARNING, &p_dev->dev, |
Dominik Brodowski | d8b0a49 | 2008-08-03 10:56:13 +0200 | [diff] [blame] | 461 | "Unable to set socket state\n"); |
| 462 | return -EINVAL; |
| 463 | } |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 464 | |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 465 | /* Pick memory or I/O card, DMA mode, interrupt */ |
| 466 | c->IntType = req->IntType; |
| 467 | c->Attributes = req->Attributes; |
| 468 | if (req->IntType & INT_MEMORY_AND_IO) |
| 469 | s->socket.flags |= SS_IOCARD; |
| 470 | if (req->IntType & INT_ZOOMED_VIDEO) |
| 471 | s->socket.flags |= SS_ZVCARD | SS_IOCARD; |
| 472 | if (req->Attributes & CONF_ENABLE_DMA) |
| 473 | s->socket.flags |= SS_DMA_MODE; |
| 474 | if (req->Attributes & CONF_ENABLE_SPKR) |
| 475 | s->socket.flags |= SS_SPKR_ENA; |
| 476 | if (req->Attributes & CONF_ENABLE_IRQ) |
Dominik Brodowski | 6f840af | 2010-03-07 10:51:23 +0100 | [diff] [blame] | 477 | s->socket.io_irq = s->pcmcia_irq; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 478 | else |
| 479 | s->socket.io_irq = 0; |
| 480 | s->ops->set_socket(s, &s->socket); |
| 481 | s->lock_count++; |
| 482 | |
| 483 | /* Set up CIS configuration registers */ |
| 484 | base = c->ConfigBase = req->ConfigBase; |
Dominik Brodowski | 1ae9c7d | 2006-01-10 20:40:40 +0100 | [diff] [blame] | 485 | c->CardValues = req->Present; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 486 | if (req->Present & PRESENT_COPY) { |
| 487 | c->Copy = req->Copy; |
| 488 | pcmcia_write_cis_mem(s, 1, (base + CISREG_SCR)>>1, 1, &c->Copy); |
| 489 | } |
| 490 | if (req->Present & PRESENT_OPTION) { |
| 491 | if (s->functions == 1) { |
| 492 | c->Option = req->ConfigIndex & COR_CONFIG_MASK; |
| 493 | } else { |
| 494 | c->Option = req->ConfigIndex & COR_MFC_CONFIG_MASK; |
| 495 | c->Option |= COR_FUNC_ENA|COR_IREQ_ENA; |
| 496 | if (req->Present & PRESENT_IOBASE_0) |
| 497 | c->Option |= COR_ADDR_DECODE; |
| 498 | } |
Dominik Brodowski | a7debe7 | 2010-03-07 10:58:29 +0100 | [diff] [blame] | 499 | if ((req->Attributes & CONF_ENABLE_IRQ) && |
| 500 | !(req->Attributes & CONF_ENABLE_PULSE_IRQ)) |
| 501 | c->Option |= COR_LEVEL_REQ; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 502 | pcmcia_write_cis_mem(s, 1, (base + CISREG_COR)>>1, 1, &c->Option); |
| 503 | mdelay(40); |
| 504 | } |
| 505 | if (req->Present & PRESENT_STATUS) { |
| 506 | c->Status = req->Status; |
| 507 | pcmcia_write_cis_mem(s, 1, (base + CISREG_CCSR)>>1, 1, &c->Status); |
| 508 | } |
| 509 | if (req->Present & PRESENT_PIN_REPLACE) { |
| 510 | c->Pin = req->Pin; |
| 511 | pcmcia_write_cis_mem(s, 1, (base + CISREG_PRR)>>1, 1, &c->Pin); |
| 512 | } |
| 513 | if (req->Present & PRESENT_EXT_STATUS) { |
| 514 | c->ExtStatus = req->ExtStatus; |
| 515 | pcmcia_write_cis_mem(s, 1, (base + CISREG_ESR)>>1, 1, &c->ExtStatus); |
| 516 | } |
| 517 | if (req->Present & PRESENT_IOBASE_0) { |
Dominik Brodowski | 2ce4905 | 2010-07-24 13:14:44 +0200 | [diff] [blame] | 518 | u8 b = c->io[0].start & 0xff; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 519 | pcmcia_write_cis_mem(s, 1, (base + CISREG_IOBASE_0)>>1, 1, &b); |
Dominik Brodowski | 2ce4905 | 2010-07-24 13:14:44 +0200 | [diff] [blame] | 520 | b = (c->io[0].start >> 8) & 0xff; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 521 | pcmcia_write_cis_mem(s, 1, (base + CISREG_IOBASE_1)>>1, 1, &b); |
| 522 | } |
| 523 | if (req->Present & PRESENT_IOSIZE) { |
Dominik Brodowski | 2ce4905 | 2010-07-24 13:14:44 +0200 | [diff] [blame] | 524 | u8 b = resource_size(&c->io[0]) + resource_size(&c->io[1]) - 1; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 525 | pcmcia_write_cis_mem(s, 1, (base + CISREG_IOSIZE)>>1, 1, &b); |
| 526 | } |
| 527 | |
| 528 | /* Configure I/O windows */ |
| 529 | if (c->state & CONFIG_IO_REQ) { |
| 530 | iomap.speed = io_speed; |
| 531 | for (i = 0; i < MAX_IO_WIN; i++) |
Dominik Brodowski | c7d0069 | 2006-01-15 08:04:43 +0100 | [diff] [blame] | 532 | if (s->io[i].res) { |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 533 | iomap.map = i; |
| 534 | iomap.flags = MAP_ACTIVE; |
Dominik Brodowski | c7d0069 | 2006-01-15 08:04:43 +0100 | [diff] [blame] | 535 | switch (s->io[i].res->flags & IO_DATA_PATH_WIDTH) { |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 536 | case IO_DATA_PATH_WIDTH_16: |
| 537 | iomap.flags |= MAP_16BIT; break; |
| 538 | case IO_DATA_PATH_WIDTH_AUTO: |
| 539 | iomap.flags |= MAP_AUTOSZ; break; |
| 540 | default: |
| 541 | break; |
| 542 | } |
Dominik Brodowski | c7d0069 | 2006-01-15 08:04:43 +0100 | [diff] [blame] | 543 | iomap.start = s->io[i].res->start; |
| 544 | iomap.stop = s->io[i].res->end; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 545 | s->ops->set_io_map(s, &iomap); |
| 546 | s->io[i].Config++; |
| 547 | } |
| 548 | } |
| 549 | |
| 550 | c->state |= CONFIG_LOCKED; |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 551 | p_dev->_locked = 1; |
Dominik Brodowski | 059f667 | 2010-03-30 18:07:50 +0200 | [diff] [blame] | 552 | mutex_unlock(&s->ops_mutex); |
Dominik Brodowski | 4c89e88 | 2008-08-03 10:07:45 +0200 | [diff] [blame] | 553 | return 0; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 554 | } /* pcmcia_request_configuration */ |
| 555 | EXPORT_SYMBOL(pcmcia_request_configuration); |
| 556 | |
| 557 | |
Dominik Brodowski | 2ce4905 | 2010-07-24 13:14:44 +0200 | [diff] [blame] | 558 | /** |
| 559 | * pcmcia_request_io() - attempt to reserve port ranges for PCMCIA devices |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 560 | * |
Dominik Brodowski | 2ce4905 | 2010-07-24 13:14:44 +0200 | [diff] [blame] | 561 | * pcmcia_request_io() attepts to reserve the IO port ranges specified in |
Dominik Brodowski | 90abdc3 | 2010-07-24 17:23:51 +0200 | [diff] [blame] | 562 | * &struct pcmcia_device @p_dev->resource[0] and @p_dev->resource[1]. The |
Dominik Brodowski | 2ce4905 | 2010-07-24 13:14:44 +0200 | [diff] [blame] | 563 | * "start" value is the requested start of the IO port resource; "end" |
Dominik Brodowski | 90abdc3 | 2010-07-24 17:23:51 +0200 | [diff] [blame] | 564 | * reflects the number of ports requested. The number of IO lines requested |
| 565 | * is specified in &struct pcmcia_device @p_dev->io_lines. |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 566 | */ |
Dominik Brodowski | 90abdc3 | 2010-07-24 17:23:51 +0200 | [diff] [blame] | 567 | int pcmcia_request_io(struct pcmcia_device *p_dev) |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 568 | { |
Dominik Brodowski | 2bc5a9b | 2005-07-07 17:59:02 -0700 | [diff] [blame] | 569 | struct pcmcia_socket *s = p_dev->socket; |
Dominik Brodowski | 90abdc3 | 2010-07-24 17:23:51 +0200 | [diff] [blame] | 570 | config_t *c = p_dev->function_config; |
Dominik Brodowski | 94a819f | 2010-01-17 18:31:34 +0100 | [diff] [blame] | 571 | int ret = -EINVAL; |
| 572 | |
| 573 | mutex_lock(&s->ops_mutex); |
Dominik Brodowski | eb838fe | 2010-09-13 16:51:36 +0200 | [diff] [blame] | 574 | dev_dbg(&p_dev->dev, "pcmcia_request_io: %pR , %pR", |
| 575 | &c->io[0], &c->io[1]); |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 576 | |
Dominik Brodowski | 6d9a299 | 2009-10-24 12:20:18 +0200 | [diff] [blame] | 577 | if (!(s->state & SOCKET_PRESENT)) { |
Dominik Brodowski | eb838fe | 2010-09-13 16:51:36 +0200 | [diff] [blame] | 578 | dev_dbg(&p_dev->dev, "pcmcia_request_io: No card present\n"); |
Dominik Brodowski | 94a819f | 2010-01-17 18:31:34 +0100 | [diff] [blame] | 579 | goto out; |
Dominik Brodowski | 6d9a299 | 2009-10-24 12:20:18 +0200 | [diff] [blame] | 580 | } |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 581 | |
Dominik Brodowski | 6d9a299 | 2009-10-24 12:20:18 +0200 | [diff] [blame] | 582 | if (c->state & CONFIG_LOCKED) { |
Dominik Brodowski | eb838fe | 2010-09-13 16:51:36 +0200 | [diff] [blame] | 583 | dev_dbg(&p_dev->dev, "Configuration is locked\n"); |
Dominik Brodowski | 94a819f | 2010-01-17 18:31:34 +0100 | [diff] [blame] | 584 | goto out; |
Dominik Brodowski | 6d9a299 | 2009-10-24 12:20:18 +0200 | [diff] [blame] | 585 | } |
Dominik Brodowski | f958095 | 2008-08-03 11:40:19 +0200 | [diff] [blame] | 586 | if (c->state & CONFIG_IO_REQ) { |
Dominik Brodowski | eb838fe | 2010-09-13 16:51:36 +0200 | [diff] [blame] | 587 | dev_dbg(&p_dev->dev, "IO already configured\n"); |
Dominik Brodowski | 94a819f | 2010-01-17 18:31:34 +0100 | [diff] [blame] | 588 | goto out; |
Dominik Brodowski | f958095 | 2008-08-03 11:40:19 +0200 | [diff] [blame] | 589 | } |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 590 | |
Dominik Brodowski | 90abdc3 | 2010-07-24 17:23:51 +0200 | [diff] [blame] | 591 | ret = alloc_io_space(s, &c->io[0], p_dev->io_lines); |
Dominik Brodowski | 2ce4905 | 2010-07-24 13:14:44 +0200 | [diff] [blame] | 592 | if (ret) |
Dominik Brodowski | 94a819f | 2010-01-17 18:31:34 +0100 | [diff] [blame] | 593 | goto out; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 594 | |
Dominik Brodowski | 2ce4905 | 2010-07-24 13:14:44 +0200 | [diff] [blame] | 595 | if (c->io[1].end) { |
Dominik Brodowski | 90abdc3 | 2010-07-24 17:23:51 +0200 | [diff] [blame] | 596 | ret = alloc_io_space(s, &c->io[1], p_dev->io_lines); |
Dominik Brodowski | 94a819f | 2010-01-17 18:31:34 +0100 | [diff] [blame] | 597 | if (ret) { |
Dominik Brodowski | 7cdffc8 | 2010-09-18 10:19:13 +0200 | [diff] [blame^] | 598 | struct resource tmp = c->io[0]; |
| 599 | /* release the previously allocated resource */ |
Dominik Brodowski | 2ce4905 | 2010-07-24 13:14:44 +0200 | [diff] [blame] | 600 | release_io_space(s, &c->io[0]); |
Dominik Brodowski | 7cdffc8 | 2010-09-18 10:19:13 +0200 | [diff] [blame^] | 601 | /* but preserve the settings, for they worked... */ |
| 602 | c->io[0].end = resource_size(&tmp); |
| 603 | c->io[0].start = tmp.start; |
| 604 | c->io[0].flags = tmp.flags; |
Dominik Brodowski | 94a819f | 2010-01-17 18:31:34 +0100 | [diff] [blame] | 605 | goto out; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 606 | } |
Dominik Brodowski | 2ce4905 | 2010-07-24 13:14:44 +0200 | [diff] [blame] | 607 | } else |
| 608 | c->io[1].start = 0; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 609 | |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 610 | c->state |= CONFIG_IO_REQ; |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 611 | p_dev->_io = 1; |
Dominik Brodowski | 94a819f | 2010-01-17 18:31:34 +0100 | [diff] [blame] | 612 | |
Dominik Brodowski | eb838fe | 2010-09-13 16:51:36 +0200 | [diff] [blame] | 613 | dev_dbg(&p_dev->dev, "pcmcia_request_io succeeded: %pR , %pR", |
Dominik Brodowski | 2ce4905 | 2010-07-24 13:14:44 +0200 | [diff] [blame] | 614 | &c->io[0], &c->io[1]); |
Dominik Brodowski | 94a819f | 2010-01-17 18:31:34 +0100 | [diff] [blame] | 615 | out: |
| 616 | mutex_unlock(&s->ops_mutex); |
| 617 | |
| 618 | return ret; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 619 | } /* pcmcia_request_io */ |
| 620 | EXPORT_SYMBOL(pcmcia_request_io); |
| 621 | |
| 622 | |
Dominik Brodowski | eb14120 | 2010-03-07 12:21:16 +0100 | [diff] [blame] | 623 | /** |
| 624 | * pcmcia_request_irq() - attempt to request a IRQ for a PCMCIA device |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 625 | * |
Dominik Brodowski | eb14120 | 2010-03-07 12:21:16 +0100 | [diff] [blame] | 626 | * pcmcia_request_irq() is a wrapper around request_irq which will allow |
| 627 | * the PCMCIA core to clean up the registration in pcmcia_disable_device(). |
| 628 | * Drivers are free to use request_irq() directly, but then they need to |
| 629 | * call free_irq themselfves, too. Also, only IRQF_SHARED capable IRQ |
| 630 | * handlers are allowed. |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 631 | */ |
Dominik Brodowski | eb14120 | 2010-03-07 12:21:16 +0100 | [diff] [blame] | 632 | int __must_check pcmcia_request_irq(struct pcmcia_device *p_dev, |
| 633 | irq_handler_t handler) |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 634 | { |
Dominik Brodowski | eb14120 | 2010-03-07 12:21:16 +0100 | [diff] [blame] | 635 | int ret; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 636 | |
Dominik Brodowski | eb14120 | 2010-03-07 12:21:16 +0100 | [diff] [blame] | 637 | if (!p_dev->irq) |
| 638 | return -EINVAL; |
Dominik Brodowski | 94a819f | 2010-01-17 18:31:34 +0100 | [diff] [blame] | 639 | |
Dominik Brodowski | eb14120 | 2010-03-07 12:21:16 +0100 | [diff] [blame] | 640 | ret = request_irq(p_dev->irq, handler, IRQF_SHARED, |
| 641 | p_dev->devname, p_dev->priv); |
| 642 | if (!ret) |
| 643 | p_dev->_irq = 1; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 644 | |
Dominik Brodowski | eb14120 | 2010-03-07 12:21:16 +0100 | [diff] [blame] | 645 | return ret; |
| 646 | } |
| 647 | EXPORT_SYMBOL(pcmcia_request_irq); |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 648 | |
Dominik Brodowski | eb14120 | 2010-03-07 12:21:16 +0100 | [diff] [blame] | 649 | |
| 650 | /** |
| 651 | * pcmcia_request_exclusive_irq() - attempt to request an exclusive IRQ first |
| 652 | * |
| 653 | * pcmcia_request_exclusive_irq() is a wrapper around request_irq which |
| 654 | * attempts first to request an exclusive IRQ. If it fails, it also accepts |
| 655 | * a shared IRQ, but prints out a warning. PCMCIA drivers should allow for |
| 656 | * IRQ sharing and either use request_irq directly (then they need to call |
| 657 | * free_irq themselves, too), or the pcmcia_request_irq() function. |
| 658 | */ |
| 659 | int __must_check |
Dominik Brodowski | b19a727 | 2010-03-20 13:10:47 +0100 | [diff] [blame] | 660 | __pcmcia_request_exclusive_irq(struct pcmcia_device *p_dev, |
| 661 | irq_handler_t handler) |
Dominik Brodowski | eb14120 | 2010-03-07 12:21:16 +0100 | [diff] [blame] | 662 | { |
| 663 | int ret; |
| 664 | |
| 665 | if (!p_dev->irq) |
| 666 | return -EINVAL; |
| 667 | |
| 668 | ret = request_irq(p_dev->irq, handler, 0, p_dev->devname, p_dev->priv); |
| 669 | if (ret) { |
| 670 | ret = pcmcia_request_irq(p_dev, handler); |
| 671 | dev_printk(KERN_WARNING, &p_dev->dev, "pcmcia: " |
| 672 | "request for exclusive IRQ could not be fulfilled.\n"); |
Dominik Brodowski | 6f0f38c | 2010-04-08 20:33:16 +0200 | [diff] [blame] | 673 | dev_printk(KERN_WARNING, &p_dev->dev, "pcmcia: the driver " |
| 674 | "needs updating to supported shared IRQ lines.\n"); |
| 675 | } |
Dominik Brodowski | eb14120 | 2010-03-07 12:21:16 +0100 | [diff] [blame] | 676 | if (ret) |
| 677 | dev_printk(KERN_INFO, &p_dev->dev, "request_irq() failed\n"); |
| 678 | else |
| 679 | p_dev->_irq = 1; |
Dominik Brodowski | 6f0f38c | 2010-04-08 20:33:16 +0200 | [diff] [blame] | 680 | |
Dominik Brodowski | 94a819f | 2010-01-17 18:31:34 +0100 | [diff] [blame] | 681 | return ret; |
Dominik Brodowski | eb14120 | 2010-03-07 12:21:16 +0100 | [diff] [blame] | 682 | } /* pcmcia_request_exclusive_irq */ |
Dominik Brodowski | b19a727 | 2010-03-20 13:10:47 +0100 | [diff] [blame] | 683 | EXPORT_SYMBOL(__pcmcia_request_exclusive_irq); |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 684 | |
| 685 | |
Dominik Brodowski | 6f0f38c | 2010-04-08 20:33:16 +0200 | [diff] [blame] | 686 | #ifdef CONFIG_PCMCIA_PROBE |
| 687 | |
| 688 | /* mask of IRQs already reserved by other cards, we should avoid using them */ |
Dominik Brodowski | 127c03c | 2010-08-03 09:33:45 +0200 | [diff] [blame] | 689 | static u8 pcmcia_used_irq[32]; |
Dominik Brodowski | 6f0f38c | 2010-04-08 20:33:16 +0200 | [diff] [blame] | 690 | |
| 691 | static irqreturn_t test_action(int cpl, void *dev_id) |
| 692 | { |
| 693 | return IRQ_NONE; |
| 694 | } |
| 695 | |
| 696 | /** |
| 697 | * pcmcia_setup_isa_irq() - determine whether an ISA IRQ can be used |
| 698 | * @p_dev - the associated PCMCIA device |
| 699 | * |
| 700 | * locking note: must be called with ops_mutex locked. |
| 701 | */ |
| 702 | static int pcmcia_setup_isa_irq(struct pcmcia_device *p_dev, int type) |
| 703 | { |
| 704 | struct pcmcia_socket *s = p_dev->socket; |
| 705 | unsigned int try, irq; |
| 706 | u32 mask = s->irq_mask; |
| 707 | int ret = -ENODEV; |
| 708 | |
| 709 | for (try = 0; try < 64; try++) { |
| 710 | irq = try % 32; |
| 711 | |
Dominik Brodowski | 127c03c | 2010-08-03 09:33:45 +0200 | [diff] [blame] | 712 | if (irq > NR_IRQS) |
| 713 | continue; |
| 714 | |
Dominik Brodowski | 6f0f38c | 2010-04-08 20:33:16 +0200 | [diff] [blame] | 715 | /* marked as available by driver, not blocked by userspace? */ |
| 716 | if (!((mask >> irq) & 1)) |
| 717 | continue; |
| 718 | |
| 719 | /* avoid an IRQ which is already used by another PCMCIA card */ |
| 720 | if ((try < 32) && pcmcia_used_irq[irq]) |
| 721 | continue; |
| 722 | |
| 723 | /* register the correct driver, if possible, to check whether |
| 724 | * registering a dummy handle works, i.e. if the IRQ isn't |
| 725 | * marked as used by the kernel resource management core */ |
| 726 | ret = request_irq(irq, test_action, type, p_dev->devname, |
| 727 | p_dev); |
| 728 | if (!ret) { |
| 729 | free_irq(irq, p_dev); |
Dominik Brodowski | eb14120 | 2010-03-07 12:21:16 +0100 | [diff] [blame] | 730 | p_dev->irq = s->pcmcia_irq = irq; |
Dominik Brodowski | 6f0f38c | 2010-04-08 20:33:16 +0200 | [diff] [blame] | 731 | pcmcia_used_irq[irq]++; |
| 732 | break; |
| 733 | } |
| 734 | } |
| 735 | |
| 736 | return ret; |
| 737 | } |
| 738 | |
| 739 | void pcmcia_cleanup_irq(struct pcmcia_socket *s) |
| 740 | { |
Dominik Brodowski | 6f840af | 2010-03-07 10:51:23 +0100 | [diff] [blame] | 741 | pcmcia_used_irq[s->pcmcia_irq]--; |
| 742 | s->pcmcia_irq = 0; |
Dominik Brodowski | 6f0f38c | 2010-04-08 20:33:16 +0200 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | #else /* CONFIG_PCMCIA_PROBE */ |
| 746 | |
| 747 | static int pcmcia_setup_isa_irq(struct pcmcia_device *p_dev, int type) |
| 748 | { |
| 749 | return -EINVAL; |
| 750 | } |
| 751 | |
| 752 | void pcmcia_cleanup_irq(struct pcmcia_socket *s) |
| 753 | { |
Dominik Brodowski | 6f840af | 2010-03-07 10:51:23 +0100 | [diff] [blame] | 754 | s->pcmcia_irq = 0; |
Dominik Brodowski | 6f0f38c | 2010-04-08 20:33:16 +0200 | [diff] [blame] | 755 | return; |
| 756 | } |
| 757 | |
| 758 | #endif /* CONFIG_PCMCIA_PROBE */ |
| 759 | |
| 760 | |
| 761 | /** |
| 762 | * pcmcia_setup_irq() - determine IRQ to be used for device |
| 763 | * @p_dev - the associated PCMCIA device |
| 764 | * |
| 765 | * locking note: must be called with ops_mutex locked. |
| 766 | */ |
| 767 | int pcmcia_setup_irq(struct pcmcia_device *p_dev) |
| 768 | { |
| 769 | struct pcmcia_socket *s = p_dev->socket; |
| 770 | |
Dominik Brodowski | eb14120 | 2010-03-07 12:21:16 +0100 | [diff] [blame] | 771 | if (p_dev->irq) |
Dominik Brodowski | 6f0f38c | 2010-04-08 20:33:16 +0200 | [diff] [blame] | 772 | return 0; |
| 773 | |
| 774 | /* already assigned? */ |
Dominik Brodowski | 6f840af | 2010-03-07 10:51:23 +0100 | [diff] [blame] | 775 | if (s->pcmcia_irq) { |
Dominik Brodowski | eb14120 | 2010-03-07 12:21:16 +0100 | [diff] [blame] | 776 | p_dev->irq = s->pcmcia_irq; |
Dominik Brodowski | 6f0f38c | 2010-04-08 20:33:16 +0200 | [diff] [blame] | 777 | return 0; |
| 778 | } |
| 779 | |
| 780 | /* prefer an exclusive ISA irq */ |
| 781 | if (!pcmcia_setup_isa_irq(p_dev, 0)) |
| 782 | return 0; |
| 783 | |
| 784 | /* but accept a shared ISA irq */ |
| 785 | if (!pcmcia_setup_isa_irq(p_dev, IRQF_SHARED)) |
| 786 | return 0; |
| 787 | |
| 788 | /* but use the PCI irq otherwise */ |
| 789 | if (s->pci_irq) { |
Dominik Brodowski | eb14120 | 2010-03-07 12:21:16 +0100 | [diff] [blame] | 790 | p_dev->irq = s->pcmcia_irq = s->pci_irq; |
Dominik Brodowski | 6f0f38c | 2010-04-08 20:33:16 +0200 | [diff] [blame] | 791 | return 0; |
| 792 | } |
| 793 | |
| 794 | return -EINVAL; |
| 795 | } |
| 796 | |
| 797 | |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 798 | /** pcmcia_request_window |
| 799 | * |
| 800 | * Request_window() establishes a mapping between card memory space |
| 801 | * and system memory space. |
| 802 | */ |
Dominik Brodowski | 6838b03 | 2009-11-03 01:31:52 +0100 | [diff] [blame] | 803 | int pcmcia_request_window(struct pcmcia_device *p_dev, win_req_t *req, window_handle_t *wh) |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 804 | { |
Dominik Brodowski | 6838b03 | 2009-11-03 01:31:52 +0100 | [diff] [blame] | 805 | struct pcmcia_socket *s = p_dev->socket; |
Dominik Brodowski | 82f88e3 | 2009-11-03 01:16:12 +0100 | [diff] [blame] | 806 | pccard_mem_map *win; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 807 | u_long align; |
Dominik Brodowski | 0ca724d | 2010-07-24 19:03:02 +0200 | [diff] [blame] | 808 | struct resource *res; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 809 | int w; |
| 810 | |
Dominik Brodowski | 6d9a299 | 2009-10-24 12:20:18 +0200 | [diff] [blame] | 811 | if (!(s->state & SOCKET_PRESENT)) { |
Dominik Brodowski | eb838fe | 2010-09-13 16:51:36 +0200 | [diff] [blame] | 812 | dev_dbg(&p_dev->dev, "No card present\n"); |
Dominik Brodowski | 3939c1ef | 2008-08-03 11:10:56 +0200 | [diff] [blame] | 813 | return -ENODEV; |
Dominik Brodowski | 6d9a299 | 2009-10-24 12:20:18 +0200 | [diff] [blame] | 814 | } |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 815 | |
| 816 | /* Window size defaults to smallest available */ |
| 817 | if (req->Size == 0) |
| 818 | req->Size = s->map_size; |
Dominik Brodowski | 0ca724d | 2010-07-24 19:03:02 +0200 | [diff] [blame] | 819 | align = (s->features & SS_CAP_MEM_ALIGN) ? req->Size : s->map_size; |
Dominik Brodowski | 69ba443 | 2008-08-03 12:10:53 +0200 | [diff] [blame] | 820 | if (req->Size & (s->map_size-1)) { |
Dominik Brodowski | eb838fe | 2010-09-13 16:51:36 +0200 | [diff] [blame] | 821 | dev_dbg(&p_dev->dev, "invalid map size\n"); |
Dominik Brodowski | 69ba443 | 2008-08-03 12:10:53 +0200 | [diff] [blame] | 822 | return -EINVAL; |
| 823 | } |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 824 | if ((req->Base && (s->features & SS_CAP_STATIC_MAP)) || |
Dominik Brodowski | 69ba443 | 2008-08-03 12:10:53 +0200 | [diff] [blame] | 825 | (req->Base & (align-1))) { |
Dominik Brodowski | eb838fe | 2010-09-13 16:51:36 +0200 | [diff] [blame] | 826 | dev_dbg(&p_dev->dev, "invalid base address\n"); |
Dominik Brodowski | 69ba443 | 2008-08-03 12:10:53 +0200 | [diff] [blame] | 827 | return -EINVAL; |
| 828 | } |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 829 | if (req->Base) |
| 830 | align = 0; |
| 831 | |
| 832 | /* Allocate system memory window */ |
Dominik Brodowski | 0ca724d | 2010-07-24 19:03:02 +0200 | [diff] [blame] | 833 | mutex_lock(&s->ops_mutex); |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 834 | for (w = 0; w < MAX_WIN; w++) |
Dominik Brodowski | 9fea84f | 2009-12-07 22:11:45 +0100 | [diff] [blame] | 835 | if (!(s->state & SOCKET_WIN_REQ(w))) |
| 836 | break; |
Dominik Brodowski | f958095 | 2008-08-03 11:40:19 +0200 | [diff] [blame] | 837 | if (w == MAX_WIN) { |
Dominik Brodowski | eb838fe | 2010-09-13 16:51:36 +0200 | [diff] [blame] | 838 | dev_dbg(&p_dev->dev, "all windows are used already\n"); |
Dominik Brodowski | 0ca724d | 2010-07-24 19:03:02 +0200 | [diff] [blame] | 839 | mutex_unlock(&s->ops_mutex); |
Dominik Brodowski | f958095 | 2008-08-03 11:40:19 +0200 | [diff] [blame] | 840 | return -EINVAL; |
| 841 | } |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 842 | |
| 843 | win = &s->win[w]; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 844 | |
| 845 | if (!(s->features & SS_CAP_STATIC_MAP)) { |
Dominik Brodowski | 82f88e3 | 2009-11-03 01:16:12 +0100 | [diff] [blame] | 846 | win->res = pcmcia_find_mem_region(req->Base, req->Size, align, |
Dominik Brodowski | 0ca724d | 2010-07-24 19:03:02 +0200 | [diff] [blame] | 847 | 0, s); |
Dominik Brodowski | 82f88e3 | 2009-11-03 01:16:12 +0100 | [diff] [blame] | 848 | if (!win->res) { |
Dominik Brodowski | eb838fe | 2010-09-13 16:51:36 +0200 | [diff] [blame] | 849 | dev_dbg(&p_dev->dev, "allocating mem region failed\n"); |
Dominik Brodowski | 6b8e087 | 2010-01-12 21:42:51 +0100 | [diff] [blame] | 850 | mutex_unlock(&s->ops_mutex); |
Dominik Brodowski | f958095 | 2008-08-03 11:40:19 +0200 | [diff] [blame] | 851 | return -EINVAL; |
| 852 | } |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 853 | } |
Dominik Brodowski | 6838b03 | 2009-11-03 01:31:52 +0100 | [diff] [blame] | 854 | p_dev->_win |= CLIENT_WIN_REQ(w); |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 855 | |
| 856 | /* Configure the socket controller */ |
Dominik Brodowski | 82f88e3 | 2009-11-03 01:16:12 +0100 | [diff] [blame] | 857 | win->map = w+1; |
Dominik Brodowski | 0ca724d | 2010-07-24 19:03:02 +0200 | [diff] [blame] | 858 | win->flags = req->Attributes; |
Dominik Brodowski | 82f88e3 | 2009-11-03 01:16:12 +0100 | [diff] [blame] | 859 | win->speed = req->AccessSpeed; |
Dominik Brodowski | 82f88e3 | 2009-11-03 01:16:12 +0100 | [diff] [blame] | 860 | win->card_start = 0; |
Dominik Brodowski | 6b8e087 | 2010-01-12 21:42:51 +0100 | [diff] [blame] | 861 | |
Dominik Brodowski | 82f88e3 | 2009-11-03 01:16:12 +0100 | [diff] [blame] | 862 | if (s->ops->set_mem_map(s, win) != 0) { |
Dominik Brodowski | eb838fe | 2010-09-13 16:51:36 +0200 | [diff] [blame] | 863 | dev_dbg(&p_dev->dev, "failed to set memory mapping\n"); |
Dominik Brodowski | 6b8e087 | 2010-01-12 21:42:51 +0100 | [diff] [blame] | 864 | mutex_unlock(&s->ops_mutex); |
Dominik Brodowski | 926c540 | 2008-08-03 12:15:11 +0200 | [diff] [blame] | 865 | return -EIO; |
| 866 | } |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 867 | s->state |= SOCKET_WIN_REQ(w); |
| 868 | |
| 869 | /* Return window handle */ |
Dominik Brodowski | 9fea84f | 2009-12-07 22:11:45 +0100 | [diff] [blame] | 870 | if (s->features & SS_CAP_STATIC_MAP) |
Dominik Brodowski | 82f88e3 | 2009-11-03 01:16:12 +0100 | [diff] [blame] | 871 | req->Base = win->static_start; |
Dominik Brodowski | 9fea84f | 2009-12-07 22:11:45 +0100 | [diff] [blame] | 872 | else |
Dominik Brodowski | 82f88e3 | 2009-11-03 01:16:12 +0100 | [diff] [blame] | 873 | req->Base = win->res->start; |
Dominik Brodowski | 9fea84f | 2009-12-07 22:11:45 +0100 | [diff] [blame] | 874 | |
Dominik Brodowski | 0ca724d | 2010-07-24 19:03:02 +0200 | [diff] [blame] | 875 | /* convert to new-style resources */ |
| 876 | res = p_dev->resource[w + MAX_IO_WIN]; |
| 877 | res->start = req->Base; |
| 878 | res->end = req->Base + req->Size - 1; |
| 879 | res->flags &= ~IORESOURCE_BITS; |
| 880 | res->flags |= (req->Attributes & WIN_FLAGS_MAP) | (win->map << 2); |
Dominik Brodowski | ad0c7be | 2010-07-25 13:10:22 +0200 | [diff] [blame] | 881 | res->flags |= IORESOURCE_MEM; |
| 882 | res->parent = win->res; |
| 883 | if (win->res) |
| 884 | request_resource(&iomem_resource, res); |
| 885 | |
Dominik Brodowski | eb838fe | 2010-09-13 16:51:36 +0200 | [diff] [blame] | 886 | dev_dbg(&p_dev->dev, "request_window results in %pR\n", res); |
Dominik Brodowski | 0ca724d | 2010-07-24 19:03:02 +0200 | [diff] [blame] | 887 | |
Dominik Brodowski | 6b8e087 | 2010-01-12 21:42:51 +0100 | [diff] [blame] | 888 | mutex_unlock(&s->ops_mutex); |
Dominik Brodowski | 0ca724d | 2010-07-24 19:03:02 +0200 | [diff] [blame] | 889 | *wh = res; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 890 | |
Dominik Brodowski | 4c89e88 | 2008-08-03 10:07:45 +0200 | [diff] [blame] | 891 | return 0; |
Dominik Brodowski | 1a8d466 | 2005-06-27 16:28:53 -0700 | [diff] [blame] | 892 | } /* pcmcia_request_window */ |
| 893 | EXPORT_SYMBOL(pcmcia_request_window); |
Dominik Brodowski | 5f2a71f | 2006-01-15 09:32:39 +0100 | [diff] [blame] | 894 | |
Dominik Brodowski | 9fea84f | 2009-12-07 22:11:45 +0100 | [diff] [blame] | 895 | void pcmcia_disable_device(struct pcmcia_device *p_dev) |
| 896 | { |
Dominik Brodowski | 0ca724d | 2010-07-24 19:03:02 +0200 | [diff] [blame] | 897 | int i; |
| 898 | for (i = 0; i < MAX_WIN; i++) { |
| 899 | struct resource *res = p_dev->resource[MAX_IO_WIN + i]; |
| 900 | if (res->flags & WIN_FLAGS_REQ) |
| 901 | pcmcia_release_window(p_dev, res); |
| 902 | } |
| 903 | |
Dominik Brodowski | 5f2a71f | 2006-01-15 09:32:39 +0100 | [diff] [blame] | 904 | pcmcia_release_configuration(p_dev); |
Dominik Brodowski | 2ce4905 | 2010-07-24 13:14:44 +0200 | [diff] [blame] | 905 | pcmcia_release_io(p_dev); |
Patrick McHardy | 418c527 | 2010-07-20 15:21:42 -0700 | [diff] [blame] | 906 | if (p_dev->_irq) { |
Dominik Brodowski | eb14120 | 2010-03-07 12:21:16 +0100 | [diff] [blame] | 907 | free_irq(p_dev->irq, p_dev->priv); |
Patrick McHardy | 418c527 | 2010-07-20 15:21:42 -0700 | [diff] [blame] | 908 | p_dev->_irq = 0; |
| 909 | } |
Dominik Brodowski | 5f2a71f | 2006-01-15 09:32:39 +0100 | [diff] [blame] | 910 | } |
| 911 | EXPORT_SYMBOL(pcmcia_disable_device); |