Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Marek Vasut | a9c0629 | 2010-07-27 21:48:10 +0200 | [diff] [blame] | 2 | /* |
| 3 | * linux/drivers/pcmcia/pxa2xx_balloon3.c |
| 4 | * |
| 5 | * Balloon3 PCMCIA specific routines. |
| 6 | * |
| 7 | * Author: Nick Bane |
| 8 | * Created: June, 2006 |
| 9 | * Copyright: Toby Churchill Ltd |
| 10 | * Derived from pxa2xx_mainstone.c, by Nico Pitre |
| 11 | * |
| 12 | * Various modification by Marek Vasut <marek.vasut@gmail.com> |
Marek Vasut | a9c0629 | 2010-07-27 21:48:10 +0200 | [diff] [blame] | 13 | */ |
| 14 | |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/gpio.h> |
| 17 | #include <linux/errno.h> |
| 18 | #include <linux/interrupt.h> |
| 19 | #include <linux/platform_device.h> |
| 20 | #include <linux/irq.h> |
| 21 | #include <linux/io.h> |
| 22 | |
| 23 | #include <mach/balloon3.h> |
| 24 | |
Dmitry Eremin-Solenikov | af21cbb | 2011-04-01 13:28:45 +0400 | [diff] [blame] | 25 | #include <asm/mach-types.h> |
| 26 | |
Marek Vasut | a9c0629 | 2010-07-27 21:48:10 +0200 | [diff] [blame] | 27 | #include "soc_common.h" |
| 28 | |
Marek Vasut | a9c0629 | 2010-07-27 21:48:10 +0200 | [diff] [blame] | 29 | static int balloon3_pcmcia_hw_init(struct soc_pcmcia_socket *skt) |
| 30 | { |
| 31 | uint16_t ver; |
Marek Vasut | a9c0629 | 2010-07-27 21:48:10 +0200 | [diff] [blame] | 32 | |
| 33 | ver = __raw_readw(BALLOON3_FPGA_VER); |
Marek Vasut | 1b9169d | 2010-10-19 16:19:32 +0200 | [diff] [blame] | 34 | if (ver < 0x4f08) |
| 35 | pr_warn("The FPGA code, version 0x%04x, is too old. " |
Marek Vasut | a9c0629 | 2010-07-27 21:48:10 +0200 | [diff] [blame] | 36 | "PCMCIA/CF support might be broken in this version!", |
| 37 | ver); |
| 38 | |
| 39 | skt->socket.pci_irq = BALLOON3_BP_CF_NRDY_IRQ; |
Russell King | a9bb5a4 | 2012-01-13 22:56:32 +0000 | [diff] [blame] | 40 | skt->stat[SOC_STAT_CD].gpio = BALLOON3_GPIO_S0_CD; |
| 41 | skt->stat[SOC_STAT_CD].name = "PCMCIA0 CD"; |
| 42 | skt->stat[SOC_STAT_BVD1].irq = BALLOON3_BP_NSTSCHG_IRQ; |
| 43 | skt->stat[SOC_STAT_BVD1].name = "PCMCIA0 STSCHG"; |
Marek Vasut | a9c0629 | 2010-07-27 21:48:10 +0200 | [diff] [blame] | 44 | |
Russell King | a9bb5a4 | 2012-01-13 22:56:32 +0000 | [diff] [blame] | 45 | return 0; |
Marek Vasut | a9c0629 | 2010-07-27 21:48:10 +0200 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | static unsigned long balloon3_pcmcia_status[2] = { |
| 49 | BALLOON3_CF_nSTSCHG_BVD1, |
| 50 | BALLOON3_CF_nSTSCHG_BVD1 |
| 51 | }; |
| 52 | |
| 53 | static void balloon3_pcmcia_socket_state(struct soc_pcmcia_socket *skt, |
| 54 | struct pcmcia_state *state) |
| 55 | { |
| 56 | uint16_t status; |
| 57 | int flip; |
| 58 | |
| 59 | /* This actually reads the STATUS register */ |
| 60 | status = __raw_readw(BALLOON3_CF_STATUS_REG); |
| 61 | flip = (status ^ balloon3_pcmcia_status[skt->nr]) |
| 62 | & BALLOON3_CF_nSTSCHG_BVD1; |
| 63 | /* |
| 64 | * Workaround for STSCHG which can't be deasserted: |
| 65 | * We therefore disable/enable corresponding IRQs |
| 66 | * as needed to avoid IRQ locks. |
| 67 | */ |
| 68 | if (flip) { |
| 69 | balloon3_pcmcia_status[skt->nr] = status; |
| 70 | if (status & BALLOON3_CF_nSTSCHG_BVD1) |
| 71 | enable_irq(BALLOON3_BP_NSTSCHG_IRQ); |
| 72 | else |
| 73 | disable_irq(BALLOON3_BP_NSTSCHG_IRQ); |
| 74 | } |
| 75 | |
Marek Vasut | a9c0629 | 2010-07-27 21:48:10 +0200 | [diff] [blame] | 76 | state->ready = !!(status & BALLOON3_CF_nIRQ); |
| 77 | state->bvd1 = !!(status & BALLOON3_CF_nSTSCHG_BVD1); |
| 78 | state->bvd2 = 0; /* not available */ |
| 79 | state->vs_3v = 1; /* Always true its a CF card */ |
| 80 | state->vs_Xv = 0; /* not available */ |
Marek Vasut | a9c0629 | 2010-07-27 21:48:10 +0200 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | static int balloon3_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, |
| 84 | const socket_state_t *state) |
| 85 | { |
Arnd Bergmann | 97b09da | 2011-10-01 22:03:45 +0200 | [diff] [blame] | 86 | __raw_writew(BALLOON3_CF_RESET, BALLOON3_CF_CONTROL_REG + |
Marek Vasut | 1b9169d | 2010-10-19 16:19:32 +0200 | [diff] [blame] | 87 | ((state->flags & SS_RESET) ? |
| 88 | BALLOON3_FPGA_SETnCLR : 0)); |
Marek Vasut | a9c0629 | 2010-07-27 21:48:10 +0200 | [diff] [blame] | 89 | return 0; |
| 90 | } |
| 91 | |
Marek Vasut | a9c0629 | 2010-07-27 21:48:10 +0200 | [diff] [blame] | 92 | static struct pcmcia_low_level balloon3_pcmcia_ops = { |
| 93 | .owner = THIS_MODULE, |
| 94 | .hw_init = balloon3_pcmcia_hw_init, |
Marek Vasut | a9c0629 | 2010-07-27 21:48:10 +0200 | [diff] [blame] | 95 | .socket_state = balloon3_pcmcia_socket_state, |
| 96 | .configure_socket = balloon3_pcmcia_configure_socket, |
Marek Vasut | a9c0629 | 2010-07-27 21:48:10 +0200 | [diff] [blame] | 97 | .first = 0, |
| 98 | .nr = 1, |
| 99 | }; |
| 100 | |
| 101 | static struct platform_device *balloon3_pcmcia_device; |
| 102 | |
| 103 | static int __init balloon3_pcmcia_init(void) |
| 104 | { |
| 105 | int ret; |
| 106 | |
Dmitry Eremin-Solenikov | af21cbb | 2011-04-01 13:28:45 +0400 | [diff] [blame] | 107 | if (!machine_is_balloon3()) |
| 108 | return -ENODEV; |
| 109 | |
Marek Vasut | a9c0629 | 2010-07-27 21:48:10 +0200 | [diff] [blame] | 110 | balloon3_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1); |
| 111 | if (!balloon3_pcmcia_device) |
| 112 | return -ENOMEM; |
| 113 | |
| 114 | ret = platform_device_add_data(balloon3_pcmcia_device, |
| 115 | &balloon3_pcmcia_ops, sizeof(balloon3_pcmcia_ops)); |
| 116 | |
| 117 | if (!ret) |
| 118 | ret = platform_device_add(balloon3_pcmcia_device); |
| 119 | |
| 120 | if (ret) |
| 121 | platform_device_put(balloon3_pcmcia_device); |
| 122 | |
| 123 | return ret; |
| 124 | } |
| 125 | |
| 126 | static void __exit balloon3_pcmcia_exit(void) |
| 127 | { |
| 128 | platform_device_unregister(balloon3_pcmcia_device); |
| 129 | } |
| 130 | |
| 131 | module_init(balloon3_pcmcia_init); |
| 132 | module_exit(balloon3_pcmcia_exit); |
| 133 | |
| 134 | MODULE_LICENSE("GPL"); |
| 135 | MODULE_AUTHOR("Nick Bane <nick@cecomputing.co.uk>"); |
| 136 | MODULE_ALIAS("platform:pxa2xx-pcmcia"); |
| 137 | MODULE_DESCRIPTION("Balloon3 board CF/PCMCIA driver"); |