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