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