blob: 2ef576c5b69d06a28808f7d17e48c1ff0334ab73 [file] [log] [blame]
Marek Vasuta9c06292010-07-27 21:48:10 +02001/*
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-Solenikovaf21cbb2011-04-01 13:28:45 +040028#include <asm/mach-types.h>
29
Marek Vasuta9c06292010-07-27 21:48:10 +020030#include "soc_common.h"
31
Marek Vasuta9c06292010-07-27 21:48:10 +020032static int balloon3_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
33{
34 uint16_t ver;
Marek Vasuta9c06292010-07-27 21:48:10 +020035
36 ver = __raw_readw(BALLOON3_FPGA_VER);
Marek Vasut1b9169d2010-10-19 16:19:32 +020037 if (ver < 0x4f08)
38 pr_warn("The FPGA code, version 0x%04x, is too old. "
Marek Vasuta9c06292010-07-27 21:48:10 +020039 "PCMCIA/CF support might be broken in this version!",
40 ver);
41
42 skt->socket.pci_irq = BALLOON3_BP_CF_NRDY_IRQ;
Russell Kinga9bb5a42012-01-13 22:56:32 +000043 skt->stat[SOC_STAT_CD].gpio = BALLOON3_GPIO_S0_CD;
44 skt->stat[SOC_STAT_CD].name = "PCMCIA0 CD";
45 skt->stat[SOC_STAT_BVD1].irq = BALLOON3_BP_NSTSCHG_IRQ;
46 skt->stat[SOC_STAT_BVD1].name = "PCMCIA0 STSCHG";
Marek Vasuta9c06292010-07-27 21:48:10 +020047
Russell Kinga9bb5a42012-01-13 22:56:32 +000048 return 0;
Marek Vasuta9c06292010-07-27 21:48:10 +020049}
50
51static unsigned long balloon3_pcmcia_status[2] = {
52 BALLOON3_CF_nSTSCHG_BVD1,
53 BALLOON3_CF_nSTSCHG_BVD1
54};
55
56static void balloon3_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
57 struct pcmcia_state *state)
58{
59 uint16_t status;
60 int flip;
61
62 /* This actually reads the STATUS register */
63 status = __raw_readw(BALLOON3_CF_STATUS_REG);
64 flip = (status ^ balloon3_pcmcia_status[skt->nr])
65 & BALLOON3_CF_nSTSCHG_BVD1;
66 /*
67 * Workaround for STSCHG which can't be deasserted:
68 * We therefore disable/enable corresponding IRQs
69 * as needed to avoid IRQ locks.
70 */
71 if (flip) {
72 balloon3_pcmcia_status[skt->nr] = status;
73 if (status & BALLOON3_CF_nSTSCHG_BVD1)
74 enable_irq(BALLOON3_BP_NSTSCHG_IRQ);
75 else
76 disable_irq(BALLOON3_BP_NSTSCHG_IRQ);
77 }
78
Marek Vasuta9c06292010-07-27 21:48:10 +020079 state->ready = !!(status & BALLOON3_CF_nIRQ);
80 state->bvd1 = !!(status & BALLOON3_CF_nSTSCHG_BVD1);
81 state->bvd2 = 0; /* not available */
82 state->vs_3v = 1; /* Always true its a CF card */
83 state->vs_Xv = 0; /* not available */
Marek Vasuta9c06292010-07-27 21:48:10 +020084}
85
86static int balloon3_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
87 const socket_state_t *state)
88{
Arnd Bergmann97b09da2011-10-01 22:03:45 +020089 __raw_writew(BALLOON3_CF_RESET, BALLOON3_CF_CONTROL_REG +
Marek Vasut1b9169d2010-10-19 16:19:32 +020090 ((state->flags & SS_RESET) ?
91 BALLOON3_FPGA_SETnCLR : 0));
Marek Vasuta9c06292010-07-27 21:48:10 +020092 return 0;
93}
94
Marek Vasuta9c06292010-07-27 21:48:10 +020095static struct pcmcia_low_level balloon3_pcmcia_ops = {
96 .owner = THIS_MODULE,
97 .hw_init = balloon3_pcmcia_hw_init,
Marek Vasuta9c06292010-07-27 21:48:10 +020098 .socket_state = balloon3_pcmcia_socket_state,
99 .configure_socket = balloon3_pcmcia_configure_socket,
Marek Vasuta9c06292010-07-27 21:48:10 +0200100 .first = 0,
101 .nr = 1,
102};
103
104static struct platform_device *balloon3_pcmcia_device;
105
106static int __init balloon3_pcmcia_init(void)
107{
108 int ret;
109
Dmitry Eremin-Solenikovaf21cbb2011-04-01 13:28:45 +0400110 if (!machine_is_balloon3())
111 return -ENODEV;
112
Marek Vasuta9c06292010-07-27 21:48:10 +0200113 balloon3_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
114 if (!balloon3_pcmcia_device)
115 return -ENOMEM;
116
117 ret = platform_device_add_data(balloon3_pcmcia_device,
118 &balloon3_pcmcia_ops, sizeof(balloon3_pcmcia_ops));
119
120 if (!ret)
121 ret = platform_device_add(balloon3_pcmcia_device);
122
123 if (ret)
124 platform_device_put(balloon3_pcmcia_device);
125
126 return ret;
127}
128
129static void __exit balloon3_pcmcia_exit(void)
130{
131 platform_device_unregister(balloon3_pcmcia_device);
132}
133
134module_init(balloon3_pcmcia_init);
135module_exit(balloon3_pcmcia_exit);
136
137MODULE_LICENSE("GPL");
138MODULE_AUTHOR("Nick Bane <nick@cecomputing.co.uk>");
139MODULE_ALIAS("platform:pxa2xx-pcmcia");
140MODULE_DESCRIPTION("Balloon3 board CF/PCMCIA driver");