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