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