arm64: dts: qcom: msm8998-clamshell: Remove retention idle state
[linux/fpc-iii.git] / drivers / pcmcia / pxa2xx_balloon3.c
blob5fe1da7a50e4af43d1894e6dc4ab853c0ebf91fb
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * linux/drivers/pcmcia/pxa2xx_balloon3.c
5 * Balloon3 PCMCIA specific routines.
7 * Author: Nick Bane
8 * Created: June, 2006
9 * Copyright: Toby Churchill Ltd
10 * Derived from pxa2xx_mainstone.c, by Nico Pitre
12 * Various modification by Marek Vasut <marek.vasut@gmail.com>
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>
23 #include <mach/balloon3.h>
25 #include <asm/mach-types.h>
27 #include "soc_common.h"
29 static int balloon3_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
31 uint16_t ver;
33 ver = __raw_readw(BALLOON3_FPGA_VER);
34 if (ver < 0x4f08)
35 pr_warn("The FPGA code, version 0x%04x, is too old. "
36 "PCMCIA/CF support might be broken in this version!",
37 ver);
39 skt->socket.pci_irq = BALLOON3_BP_CF_NRDY_IRQ;
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";
45 return 0;
48 static unsigned long balloon3_pcmcia_status[2] = {
49 BALLOON3_CF_nSTSCHG_BVD1,
50 BALLOON3_CF_nSTSCHG_BVD1
53 static void balloon3_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
54 struct pcmcia_state *state)
56 uint16_t status;
57 int flip;
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;
64 * Workaround for STSCHG which can't be deasserted:
65 * We therefore disable/enable corresponding IRQs
66 * as needed to avoid IRQ locks.
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);
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 */
83 static int balloon3_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
84 const socket_state_t *state)
86 __raw_writew(BALLOON3_CF_RESET, BALLOON3_CF_CONTROL_REG +
87 ((state->flags & SS_RESET) ?
88 BALLOON3_FPGA_SETnCLR : 0));
89 return 0;
92 static struct pcmcia_low_level balloon3_pcmcia_ops = {
93 .owner = THIS_MODULE,
94 .hw_init = balloon3_pcmcia_hw_init,
95 .socket_state = balloon3_pcmcia_socket_state,
96 .configure_socket = balloon3_pcmcia_configure_socket,
97 .first = 0,
98 .nr = 1,
101 static struct platform_device *balloon3_pcmcia_device;
103 static int __init balloon3_pcmcia_init(void)
105 int ret;
107 if (!machine_is_balloon3())
108 return -ENODEV;
110 balloon3_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
111 if (!balloon3_pcmcia_device)
112 return -ENOMEM;
114 ret = platform_device_add_data(balloon3_pcmcia_device,
115 &balloon3_pcmcia_ops, sizeof(balloon3_pcmcia_ops));
117 if (!ret)
118 ret = platform_device_add(balloon3_pcmcia_device);
120 if (ret)
121 platform_device_put(balloon3_pcmcia_device);
123 return ret;
126 static void __exit balloon3_pcmcia_exit(void)
128 platform_device_unregister(balloon3_pcmcia_device);
131 module_init(balloon3_pcmcia_init);
132 module_exit(balloon3_pcmcia_exit);
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");