1 /*====================================================================== 2 3 Common support code for the PCMCIA control functionality of 4 integrated SOCs like the SA-11x0 and PXA2xx microprocessors. 5 6 The contents of this file are subject to the Mozilla Public 7 License Version 1.1 (the "License"); you may not use this file 8 except in compliance with the License. You may obtain a copy of 9 the License at http://www.mozilla.org/MPL/ 10 11 Software distributed under the License is distributed on an "AS 12 IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 13 implied. See the License for the specific language governing 14 rights and limitations under the License. 15 16 The initial developer of the original code is John G. Dorsey 17 <john+@cs.cmu.edu>. Portions created by John G. Dorsey are 18 Copyright (C) 1999 John G. Dorsey. All Rights Reserved. 19 20 Alternatively, the contents of this file may be used under the 21 terms of the GNU Public License version 2 (the "GPL"), in which 22 case the provisions of the GPL are applicable instead of the 23 above. If you wish to allow the use of your version of this file 24 only under the terms of the GPL and not to allow others to use 25 your version of this file under the MPL, indicate your decision 26 by deleting the provisions above and replace them with the notice 27 and other provisions required by the GPL. If you do not delete 28 the provisions above, a recipient may use your version of this 29 file under either the MPL or the GPL. 30 31 ======================================================================*/ 32 33 34 #include <linux/cpufreq.h> 35 #include <linux/gpio.h> 36 #include <linux/init.h> 37 #include <linux/interrupt.h> 38 #include <linux/io.h> 39 #include <linux/irq.h> 40 #include <linux/kernel.h> 41 #include <linux/mm.h> 42 #include <linux/module.h> 43 #include <linux/moduleparam.h> 44 #include <linux/mutex.h> 45 #include <linux/spinlock.h> 46 #include <linux/timer.h> 47 48 #include <mach/hardware.h> 49 50 #include "soc_common.h" 51 52 static irqreturn_t soc_common_pcmcia_interrupt(int irq, void *dev); 53 54 #ifdef CONFIG_PCMCIA_DEBUG 55 56 static int pc_debug; 57 module_param(pc_debug, int, 0644); 58 59 void soc_pcmcia_debug(struct soc_pcmcia_socket *skt, const char *func, 60 int lvl, const char *fmt, ...) 61 { 62 struct va_format vaf; 63 va_list args; 64 if (pc_debug > lvl) { 65 va_start(args, fmt); 66 67 vaf.fmt = fmt; 68 vaf.va = &args; 69 70 printk(KERN_DEBUG "skt%u: %s: %pV", skt->nr, func, &vaf); 71 72 va_end(args); 73 } 74 } 75 EXPORT_SYMBOL(soc_pcmcia_debug); 76 77 #endif 78 79 #define to_soc_pcmcia_socket(x) \ 80 container_of(x, struct soc_pcmcia_socket, socket) 81 82 static unsigned short 83 calc_speed(unsigned short *spds, int num, unsigned short dflt) 84 { 85 unsigned short speed = 0; 86 int i; 87 88 for (i = 0; i < num; i++) 89 if (speed < spds[i]) 90 speed = spds[i]; 91 if (speed == 0) 92 speed = dflt; 93 94 return speed; 95 } 96 97 void soc_common_pcmcia_get_timing(struct soc_pcmcia_socket *skt, 98 struct soc_pcmcia_timing *timing) 99 { 100 timing->io = 101 calc_speed(skt->spd_io, MAX_IO_WIN, SOC_PCMCIA_IO_ACCESS); 102 timing->mem = 103 calc_speed(skt->spd_mem, MAX_WIN, SOC_PCMCIA_3V_MEM_ACCESS); 104 timing->attr = 105 calc_speed(skt->spd_attr, MAX_WIN, SOC_PCMCIA_3V_MEM_ACCESS); 106 } 107 EXPORT_SYMBOL(soc_common_pcmcia_get_timing); 108 109 static void __soc_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt, 110 unsigned int nr) 111 { 112 unsigned int i; 113 114 for (i = 0; i < nr; i++) { 115 if (skt->stat[i].irq) 116 free_irq(skt->stat[i].irq, skt); 117 if (gpio_is_valid(skt->stat[i].gpio)) 118 gpio_free(skt->stat[i].gpio); 119 } 120 121 if (skt->ops->hw_shutdown) 122 skt->ops->hw_shutdown(skt); 123 124 clk_disable_unprepare(skt->clk); 125 } 126 127 static void soc_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt) 128 { 129 __soc_pcmcia_hw_shutdown(skt, ARRAY_SIZE(skt->stat)); 130 } 131 132 static int soc_pcmcia_hw_init(struct soc_pcmcia_socket *skt) 133 { 134 int ret = 0, i; 135 136 clk_prepare_enable(skt->clk); 137 138 if (skt->ops->hw_init) { 139 ret = skt->ops->hw_init(skt); 140 if (ret) 141 return ret; 142 } 143 144 for (i = 0; i < ARRAY_SIZE(skt->stat); i++) { 145 if (gpio_is_valid(skt->stat[i].gpio)) { 146 int irq; 147 148 ret = gpio_request_one(skt->stat[i].gpio, GPIOF_IN, 149 skt->stat[i].name); 150 if (ret) { 151 __soc_pcmcia_hw_shutdown(skt, i); 152 return ret; 153 } 154 155 irq = gpio_to_irq(skt->stat[i].gpio); 156 157 if (i == SOC_STAT_RDY) 158 skt->socket.pci_irq = irq; 159 else 160 skt->stat[i].irq = irq; 161 } 162 163 if (skt->stat[i].irq) { 164 ret = request_irq(skt->stat[i].irq, 165 soc_common_pcmcia_interrupt, 166 IRQF_TRIGGER_NONE, 167 skt->stat[i].name, skt); 168 if (ret) { 169 if (gpio_is_valid(skt->stat[i].gpio)) 170 gpio_free(skt->stat[i].gpio); 171 __soc_pcmcia_hw_shutdown(skt, i); 172 return ret; 173 } 174 } 175 } 176 177 return ret; 178 } 179 180 static void soc_pcmcia_hw_enable(struct soc_pcmcia_socket *skt) 181 { 182 int i; 183 184 for (i = 0; i < ARRAY_SIZE(skt->stat); i++) 185 if (skt->stat[i].irq) { 186 irq_set_irq_type(skt->stat[i].irq, IRQ_TYPE_EDGE_RISING); 187 irq_set_irq_type(skt->stat[i].irq, IRQ_TYPE_EDGE_BOTH); 188 } 189 } 190 191 static void soc_pcmcia_hw_disable(struct soc_pcmcia_socket *skt) 192 { 193 int i; 194 195 for (i = 0; i < ARRAY_SIZE(skt->stat); i++) 196 if (skt->stat[i].irq) 197 irq_set_irq_type(skt->stat[i].irq, IRQ_TYPE_NONE); 198 } 199 200 static unsigned int soc_common_pcmcia_skt_state(struct soc_pcmcia_socket *skt) 201 { 202 struct pcmcia_state state; 203 unsigned int stat; 204 205 memset(&state, 0, sizeof(struct pcmcia_state)); 206 207 /* Make battery voltage state report 'good' */ 208 state.bvd1 = 1; 209 state.bvd2 = 1; 210 211 /* CD is active low by default */ 212 if (gpio_is_valid(skt->stat[SOC_STAT_CD].gpio)) 213 state.detect = !gpio_get_value(skt->stat[SOC_STAT_CD].gpio); 214 215 /* RDY and BVD are active high by default */ 216 if (gpio_is_valid(skt->stat[SOC_STAT_RDY].gpio)) 217 state.ready = !!gpio_get_value(skt->stat[SOC_STAT_RDY].gpio); 218 if (gpio_is_valid(skt->stat[SOC_STAT_BVD1].gpio)) 219 state.bvd1 = !!gpio_get_value(skt->stat[SOC_STAT_BVD1].gpio); 220 if (gpio_is_valid(skt->stat[SOC_STAT_BVD2].gpio)) 221 state.bvd2 = !!gpio_get_value(skt->stat[SOC_STAT_BVD2].gpio); 222 223 skt->ops->socket_state(skt, &state); 224 225 stat = state.detect ? SS_DETECT : 0; 226 stat |= state.ready ? SS_READY : 0; 227 stat |= state.wrprot ? SS_WRPROT : 0; 228 stat |= state.vs_3v ? SS_3VCARD : 0; 229 stat |= state.vs_Xv ? SS_XVCARD : 0; 230 231 /* The power status of individual sockets is not available 232 * explicitly from the hardware, so we just remember the state 233 * and regurgitate it upon request: 234 */ 235 stat |= skt->cs_state.Vcc ? SS_POWERON : 0; 236 237 if (skt->cs_state.flags & SS_IOCARD) 238 stat |= state.bvd1 ? SS_STSCHG : 0; 239 else { 240 if (state.bvd1 == 0) 241 stat |= SS_BATDEAD; 242 else if (state.bvd2 == 0) 243 stat |= SS_BATWARN; 244 } 245 return stat; 246 } 247 248 /* 249 * soc_common_pcmcia_config_skt 250 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 251 * 252 * Convert PCMCIA socket state to our socket configure structure. 253 */ 254 static int soc_common_pcmcia_config_skt( 255 struct soc_pcmcia_socket *skt, socket_state_t *state) 256 { 257 int ret; 258 259 ret = skt->ops->configure_socket(skt, state); 260 if (ret == 0) { 261 /* 262 * This really needs a better solution. The IRQ 263 * may or may not be claimed by the driver. 264 */ 265 if (skt->irq_state != 1 && state->io_irq) { 266 skt->irq_state = 1; 267 irq_set_irq_type(skt->socket.pci_irq, 268 IRQ_TYPE_EDGE_FALLING); 269 } else if (skt->irq_state == 1 && state->io_irq == 0) { 270 skt->irq_state = 0; 271 irq_set_irq_type(skt->socket.pci_irq, IRQ_TYPE_NONE); 272 } 273 274 skt->cs_state = *state; 275 } 276 277 if (ret < 0) 278 printk(KERN_ERR "soc_common_pcmcia: unable to configure " 279 "socket %d\n", skt->nr); 280 281 return ret; 282 } 283 284 /* soc_common_pcmcia_sock_init() 285 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 286 * 287 * (Re-)Initialise the socket, turning on status interrupts 288 * and PCMCIA bus. This must wait for power to stabilise 289 * so that the card status signals report correctly. 290 * 291 * Returns: 0 292 */ 293 static int soc_common_pcmcia_sock_init(struct pcmcia_socket *sock) 294 { 295 struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock); 296 297 debug(skt, 2, "initializing socket\n"); 298 if (skt->ops->socket_init) 299 skt->ops->socket_init(skt); 300 soc_pcmcia_hw_enable(skt); 301 return 0; 302 } 303 304 305 /* 306 * soc_common_pcmcia_suspend() 307 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 308 * 309 * Remove power on the socket, disable IRQs from the card. 310 * Turn off status interrupts, and disable the PCMCIA bus. 311 * 312 * Returns: 0 313 */ 314 static int soc_common_pcmcia_suspend(struct pcmcia_socket *sock) 315 { 316 struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock); 317 318 debug(skt, 2, "suspending socket\n"); 319 320 soc_pcmcia_hw_disable(skt); 321 if (skt->ops->socket_suspend) 322 skt->ops->socket_suspend(skt); 323 324 return 0; 325 } 326 327 static DEFINE_SPINLOCK(status_lock); 328 329 static void soc_common_check_status(struct soc_pcmcia_socket *skt) 330 { 331 unsigned int events; 332 333 debug(skt, 4, "entering PCMCIA monitoring thread\n"); 334 335 do { 336 unsigned int status; 337 unsigned long flags; 338 339 status = soc_common_pcmcia_skt_state(skt); 340 341 spin_lock_irqsave(&status_lock, flags); 342 events = (status ^ skt->status) & skt->cs_state.csc_mask; 343 skt->status = status; 344 spin_unlock_irqrestore(&status_lock, flags); 345 346 debug(skt, 4, "events: %s%s%s%s%s%s\n", 347 events == 0 ? "<NONE>" : "", 348 events & SS_DETECT ? "DETECT " : "", 349 events & SS_READY ? "READY " : "", 350 events & SS_BATDEAD ? "BATDEAD " : "", 351 events & SS_BATWARN ? "BATWARN " : "", 352 events & SS_STSCHG ? "STSCHG " : ""); 353 354 if (events) 355 pcmcia_parse_events(&skt->socket, events); 356 } while (events); 357 } 358 359 /* Let's poll for events in addition to IRQs since IRQ only is unreliable... */ 360 static void soc_common_pcmcia_poll_event(unsigned long dummy) 361 { 362 struct soc_pcmcia_socket *skt = (struct soc_pcmcia_socket *)dummy; 363 debug(skt, 4, "polling for events\n"); 364 365 mod_timer(&skt->poll_timer, jiffies + SOC_PCMCIA_POLL_PERIOD); 366 367 soc_common_check_status(skt); 368 } 369 370 371 /* 372 * Service routine for socket driver interrupts (requested by the 373 * low-level PCMCIA init() operation via soc_common_pcmcia_thread()). 374 * The actual interrupt-servicing work is performed by 375 * soc_common_pcmcia_thread(), largely because the Card Services event- 376 * handling code performs scheduling operations which cannot be 377 * executed from within an interrupt context. 378 */ 379 static irqreturn_t soc_common_pcmcia_interrupt(int irq, void *dev) 380 { 381 struct soc_pcmcia_socket *skt = dev; 382 383 debug(skt, 3, "servicing IRQ %d\n", irq); 384 385 soc_common_check_status(skt); 386 387 return IRQ_HANDLED; 388 } 389 390 391 /* 392 * Implements the get_status() operation for the in-kernel PCMCIA 393 * service (formerly SS_GetStatus in Card Services). Essentially just 394 * fills in bits in `status' according to internal driver state or 395 * the value of the voltage detect chipselect register. 396 * 397 * As a debugging note, during card startup, the PCMCIA core issues 398 * three set_socket() commands in a row the first with RESET deasserted, 399 * the second with RESET asserted, and the last with RESET deasserted 400 * again. Following the third set_socket(), a get_status() command will 401 * be issued. The kernel is looking for the SS_READY flag (see 402 * setup_socket(), reset_socket(), and unreset_socket() in cs.c). 403 * 404 * Returns: 0 405 */ 406 static int 407 soc_common_pcmcia_get_status(struct pcmcia_socket *sock, unsigned int *status) 408 { 409 struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock); 410 411 skt->status = soc_common_pcmcia_skt_state(skt); 412 *status = skt->status; 413 414 return 0; 415 } 416 417 418 /* 419 * Implements the set_socket() operation for the in-kernel PCMCIA 420 * service (formerly SS_SetSocket in Card Services). We more or 421 * less punt all of this work and let the kernel handle the details 422 * of power configuration, reset, &c. We also record the value of 423 * `state' in order to regurgitate it to the PCMCIA core later. 424 */ 425 static int soc_common_pcmcia_set_socket( 426 struct pcmcia_socket *sock, socket_state_t *state) 427 { 428 struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock); 429 430 debug(skt, 2, "mask: %s%s%s%s%s%s flags: %s%s%s%s%s%s Vcc %d Vpp %d irq %d\n", 431 (state->csc_mask == 0) ? "<NONE> " : "", 432 (state->csc_mask & SS_DETECT) ? "DETECT " : "", 433 (state->csc_mask & SS_READY) ? "READY " : "", 434 (state->csc_mask & SS_BATDEAD) ? "BATDEAD " : "", 435 (state->csc_mask & SS_BATWARN) ? "BATWARN " : "", 436 (state->csc_mask & SS_STSCHG) ? "STSCHG " : "", 437 (state->flags == 0) ? "<NONE> " : "", 438 (state->flags & SS_PWR_AUTO) ? "PWR_AUTO " : "", 439 (state->flags & SS_IOCARD) ? "IOCARD " : "", 440 (state->flags & SS_RESET) ? "RESET " : "", 441 (state->flags & SS_SPKR_ENA) ? "SPKR_ENA " : "", 442 (state->flags & SS_OUTPUT_ENA) ? "OUTPUT_ENA " : "", 443 state->Vcc, state->Vpp, state->io_irq); 444 445 return soc_common_pcmcia_config_skt(skt, state); 446 } 447 448 449 /* 450 * Implements the set_io_map() operation for the in-kernel PCMCIA 451 * service (formerly SS_SetIOMap in Card Services). We configure 452 * the map speed as requested, but override the address ranges 453 * supplied by Card Services. 454 * 455 * Returns: 0 on success, -1 on error 456 */ 457 static int soc_common_pcmcia_set_io_map( 458 struct pcmcia_socket *sock, struct pccard_io_map *map) 459 { 460 struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock); 461 unsigned short speed = map->speed; 462 463 debug(skt, 2, "map %u speed %u start 0x%08llx stop 0x%08llx\n", 464 map->map, map->speed, (unsigned long long)map->start, 465 (unsigned long long)map->stop); 466 debug(skt, 2, "flags: %s%s%s%s%s%s%s%s\n", 467 (map->flags == 0) ? "<NONE>" : "", 468 (map->flags & MAP_ACTIVE) ? "ACTIVE " : "", 469 (map->flags & MAP_16BIT) ? "16BIT " : "", 470 (map->flags & MAP_AUTOSZ) ? "AUTOSZ " : "", 471 (map->flags & MAP_0WS) ? "0WS " : "", 472 (map->flags & MAP_WRPROT) ? "WRPROT " : "", 473 (map->flags & MAP_USE_WAIT) ? "USE_WAIT " : "", 474 (map->flags & MAP_PREFETCH) ? "PREFETCH " : ""); 475 476 if (map->map >= MAX_IO_WIN) { 477 printk(KERN_ERR "%s(): map (%d) out of range\n", __func__, 478 map->map); 479 return -1; 480 } 481 482 if (map->flags & MAP_ACTIVE) { 483 if (speed == 0) 484 speed = SOC_PCMCIA_IO_ACCESS; 485 } else { 486 speed = 0; 487 } 488 489 skt->spd_io[map->map] = speed; 490 skt->ops->set_timing(skt); 491 492 if (map->stop == 1) 493 map->stop = PAGE_SIZE-1; 494 495 map->stop -= map->start; 496 map->stop += skt->socket.io_offset; 497 map->start = skt->socket.io_offset; 498 499 return 0; 500 } 501 502 503 /* 504 * Implements the set_mem_map() operation for the in-kernel PCMCIA 505 * service (formerly SS_SetMemMap in Card Services). We configure 506 * the map speed as requested, but override the address ranges 507 * supplied by Card Services. 508 * 509 * Returns: 0 on success, -ERRNO on error 510 */ 511 static int soc_common_pcmcia_set_mem_map( 512 struct pcmcia_socket *sock, struct pccard_mem_map *map) 513 { 514 struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock); 515 struct resource *res; 516 unsigned short speed = map->speed; 517 518 debug(skt, 2, "map %u speed %u card_start %08x\n", 519 map->map, map->speed, map->card_start); 520 debug(skt, 2, "flags: %s%s%s%s%s%s%s%s\n", 521 (map->flags == 0) ? "<NONE>" : "", 522 (map->flags & MAP_ACTIVE) ? "ACTIVE " : "", 523 (map->flags & MAP_16BIT) ? "16BIT " : "", 524 (map->flags & MAP_AUTOSZ) ? "AUTOSZ " : "", 525 (map->flags & MAP_0WS) ? "0WS " : "", 526 (map->flags & MAP_WRPROT) ? "WRPROT " : "", 527 (map->flags & MAP_ATTRIB) ? "ATTRIB " : "", 528 (map->flags & MAP_USE_WAIT) ? "USE_WAIT " : ""); 529 530 if (map->map >= MAX_WIN) 531 return -EINVAL; 532 533 if (map->flags & MAP_ACTIVE) { 534 if (speed == 0) 535 speed = 300; 536 } else { 537 speed = 0; 538 } 539 540 if (map->flags & MAP_ATTRIB) { 541 res = &skt->res_attr; 542 skt->spd_attr[map->map] = speed; 543 skt->spd_mem[map->map] = 0; 544 } else { 545 res = &skt->res_mem; 546 skt->spd_attr[map->map] = 0; 547 skt->spd_mem[map->map] = speed; 548 } 549 550 skt->ops->set_timing(skt); 551 552 map->static_start = res->start + map->card_start; 553 554 return 0; 555 } 556 557 struct bittbl { 558 unsigned int mask; 559 const char *name; 560 }; 561 562 static struct bittbl status_bits[] = { 563 { SS_WRPROT, "SS_WRPROT" }, 564 { SS_BATDEAD, "SS_BATDEAD" }, 565 { SS_BATWARN, "SS_BATWARN" }, 566 { SS_READY, "SS_READY" }, 567 { SS_DETECT, "SS_DETECT" }, 568 { SS_POWERON, "SS_POWERON" }, 569 { SS_STSCHG, "SS_STSCHG" }, 570 { SS_3VCARD, "SS_3VCARD" }, 571 { SS_XVCARD, "SS_XVCARD" }, 572 }; 573 574 static struct bittbl conf_bits[] = { 575 { SS_PWR_AUTO, "SS_PWR_AUTO" }, 576 { SS_IOCARD, "SS_IOCARD" }, 577 { SS_RESET, "SS_RESET" }, 578 { SS_DMA_MODE, "SS_DMA_MODE" }, 579 { SS_SPKR_ENA, "SS_SPKR_ENA" }, 580 { SS_OUTPUT_ENA, "SS_OUTPUT_ENA" }, 581 }; 582 583 static void dump_bits(char **p, const char *prefix, 584 unsigned int val, struct bittbl *bits, int sz) 585 { 586 char *b = *p; 587 int i; 588 589 b += sprintf(b, "%-9s:", prefix); 590 for (i = 0; i < sz; i++) 591 if (val & bits[i].mask) 592 b += sprintf(b, " %s", bits[i].name); 593 *b++ = '\n'; 594 *p = b; 595 } 596 597 /* 598 * Implements the /sys/class/pcmcia_socket/??/status file. 599 * 600 * Returns: the number of characters added to the buffer 601 */ 602 static ssize_t show_status( 603 struct device *dev, struct device_attribute *attr, char *buf) 604 { 605 struct soc_pcmcia_socket *skt = 606 container_of(dev, struct soc_pcmcia_socket, socket.dev); 607 char *p = buf; 608 609 p += sprintf(p, "slot : %d\n", skt->nr); 610 611 dump_bits(&p, "status", skt->status, 612 status_bits, ARRAY_SIZE(status_bits)); 613 dump_bits(&p, "csc_mask", skt->cs_state.csc_mask, 614 status_bits, ARRAY_SIZE(status_bits)); 615 dump_bits(&p, "cs_flags", skt->cs_state.flags, 616 conf_bits, ARRAY_SIZE(conf_bits)); 617 618 p += sprintf(p, "Vcc : %d\n", skt->cs_state.Vcc); 619 p += sprintf(p, "Vpp : %d\n", skt->cs_state.Vpp); 620 p += sprintf(p, "IRQ : %d (%d)\n", skt->cs_state.io_irq, 621 skt->socket.pci_irq); 622 if (skt->ops->show_timing) 623 p += skt->ops->show_timing(skt, p); 624 625 return p-buf; 626 } 627 static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); 628 629 630 static struct pccard_operations soc_common_pcmcia_operations = { 631 .init = soc_common_pcmcia_sock_init, 632 .suspend = soc_common_pcmcia_suspend, 633 .get_status = soc_common_pcmcia_get_status, 634 .set_socket = soc_common_pcmcia_set_socket, 635 .set_io_map = soc_common_pcmcia_set_io_map, 636 .set_mem_map = soc_common_pcmcia_set_mem_map, 637 }; 638 639 640 static LIST_HEAD(soc_pcmcia_sockets); 641 static DEFINE_MUTEX(soc_pcmcia_sockets_lock); 642 643 #ifdef CONFIG_CPU_FREQ 644 static int 645 soc_pcmcia_notifier(struct notifier_block *nb, unsigned long val, void *data) 646 { 647 struct soc_pcmcia_socket *skt; 648 struct cpufreq_freqs *freqs = data; 649 int ret = 0; 650 651 mutex_lock(&soc_pcmcia_sockets_lock); 652 list_for_each_entry(skt, &soc_pcmcia_sockets, node) 653 if (skt->ops->frequency_change) 654 ret += skt->ops->frequency_change(skt, val, freqs); 655 mutex_unlock(&soc_pcmcia_sockets_lock); 656 657 return ret; 658 } 659 660 static struct notifier_block soc_pcmcia_notifier_block = { 661 .notifier_call = soc_pcmcia_notifier 662 }; 663 664 static int soc_pcmcia_cpufreq_register(void) 665 { 666 int ret; 667 668 ret = cpufreq_register_notifier(&soc_pcmcia_notifier_block, 669 CPUFREQ_TRANSITION_NOTIFIER); 670 if (ret < 0) 671 printk(KERN_ERR "Unable to register CPU frequency change " 672 "notifier for PCMCIA (%d)\n", ret); 673 return ret; 674 } 675 fs_initcall(soc_pcmcia_cpufreq_register); 676 677 static void soc_pcmcia_cpufreq_unregister(void) 678 { 679 cpufreq_unregister_notifier(&soc_pcmcia_notifier_block, 680 CPUFREQ_TRANSITION_NOTIFIER); 681 } 682 module_exit(soc_pcmcia_cpufreq_unregister); 683 684 #endif 685 686 void soc_pcmcia_init_one(struct soc_pcmcia_socket *skt, 687 struct pcmcia_low_level *ops, struct device *dev) 688 { 689 int i; 690 691 skt->ops = ops; 692 skt->socket.owner = ops->owner; 693 skt->socket.dev.parent = dev; 694 skt->socket.pci_irq = NO_IRQ; 695 696 for (i = 0; i < ARRAY_SIZE(skt->stat); i++) 697 skt->stat[i].gpio = -EINVAL; 698 } 699 EXPORT_SYMBOL(soc_pcmcia_init_one); 700 701 void soc_pcmcia_remove_one(struct soc_pcmcia_socket *skt) 702 { 703 mutex_lock(&soc_pcmcia_sockets_lock); 704 del_timer_sync(&skt->poll_timer); 705 706 pcmcia_unregister_socket(&skt->socket); 707 708 soc_pcmcia_hw_shutdown(skt); 709 710 /* should not be required; violates some lowlevel drivers */ 711 soc_common_pcmcia_config_skt(skt, &dead_socket); 712 713 list_del(&skt->node); 714 mutex_unlock(&soc_pcmcia_sockets_lock); 715 716 iounmap(skt->virt_io); 717 skt->virt_io = NULL; 718 release_resource(&skt->res_attr); 719 release_resource(&skt->res_mem); 720 release_resource(&skt->res_io); 721 release_resource(&skt->res_skt); 722 } 723 EXPORT_SYMBOL(soc_pcmcia_remove_one); 724 725 int soc_pcmcia_add_one(struct soc_pcmcia_socket *skt) 726 { 727 int ret; 728 729 init_timer(&skt->poll_timer); 730 skt->poll_timer.function = soc_common_pcmcia_poll_event; 731 skt->poll_timer.data = (unsigned long)skt; 732 skt->poll_timer.expires = jiffies + SOC_PCMCIA_POLL_PERIOD; 733 734 ret = request_resource(&iomem_resource, &skt->res_skt); 735 if (ret) 736 goto out_err_1; 737 738 ret = request_resource(&skt->res_skt, &skt->res_io); 739 if (ret) 740 goto out_err_2; 741 742 ret = request_resource(&skt->res_skt, &skt->res_mem); 743 if (ret) 744 goto out_err_3; 745 746 ret = request_resource(&skt->res_skt, &skt->res_attr); 747 if (ret) 748 goto out_err_4; 749 750 skt->virt_io = ioremap(skt->res_io.start, 0x10000); 751 if (skt->virt_io == NULL) { 752 ret = -ENOMEM; 753 goto out_err_5; 754 } 755 756 mutex_lock(&soc_pcmcia_sockets_lock); 757 758 list_add(&skt->node, &soc_pcmcia_sockets); 759 760 /* 761 * We initialize default socket timing here, because 762 * we are not guaranteed to see a SetIOMap operation at 763 * runtime. 764 */ 765 skt->ops->set_timing(skt); 766 767 ret = soc_pcmcia_hw_init(skt); 768 if (ret) 769 goto out_err_6; 770 771 skt->socket.ops = &soc_common_pcmcia_operations; 772 skt->socket.features = SS_CAP_STATIC_MAP|SS_CAP_PCCARD; 773 skt->socket.resource_ops = &pccard_static_ops; 774 skt->socket.irq_mask = 0; 775 skt->socket.map_size = PAGE_SIZE; 776 skt->socket.io_offset = (unsigned long)skt->virt_io; 777 778 skt->status = soc_common_pcmcia_skt_state(skt); 779 780 ret = pcmcia_register_socket(&skt->socket); 781 if (ret) 782 goto out_err_7; 783 784 add_timer(&skt->poll_timer); 785 786 mutex_unlock(&soc_pcmcia_sockets_lock); 787 788 ret = device_create_file(&skt->socket.dev, &dev_attr_status); 789 if (ret) 790 goto out_err_8; 791 792 return ret; 793 794 out_err_8: 795 mutex_lock(&soc_pcmcia_sockets_lock); 796 del_timer_sync(&skt->poll_timer); 797 pcmcia_unregister_socket(&skt->socket); 798 799 out_err_7: 800 soc_pcmcia_hw_shutdown(skt); 801 out_err_6: 802 list_del(&skt->node); 803 mutex_unlock(&soc_pcmcia_sockets_lock); 804 iounmap(skt->virt_io); 805 out_err_5: 806 release_resource(&skt->res_attr); 807 out_err_4: 808 release_resource(&skt->res_mem); 809 out_err_3: 810 release_resource(&skt->res_io); 811 out_err_2: 812 release_resource(&skt->res_skt); 813 out_err_1: 814 815 return ret; 816 } 817 EXPORT_SYMBOL(soc_pcmcia_add_one); 818 819 MODULE_AUTHOR("John Dorsey <john+@cs.cmu.edu>"); 820 MODULE_DESCRIPTION("Linux PCMCIA Card Services: Common SoC support"); 821 MODULE_LICENSE("Dual MPL/GPL"); 822