treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / pcmcia / pxa2xx_trizeps4.c
blob6db8fe880ed464a9a2082259ee4d1628736f6efc
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * linux/drivers/pcmcia/pxa2xx_trizeps4.c
5 * TRIZEPS PCMCIA specific routines.
7 * Author: Jürgen Schindele
8 * Created: 20 02, 2006
9 * Copyright: Jürgen Schindele
12 #include <linux/module.h>
13 #include <linux/init.h>
14 #include <linux/kernel.h>
15 #include <linux/gpio.h>
16 #include <linux/interrupt.h>
17 #include <linux/platform_device.h>
19 #include <asm/mach-types.h>
20 #include <asm/irq.h>
22 #include <mach/pxa2xx-regs.h>
23 #include <mach/trizeps4.h>
25 #include "soc_common.h"
27 extern void board_pcmcia_power(int power);
29 static int trizeps_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
31 /* we dont have voltage/card/ready detection
32 * so we dont need interrupts for it
34 switch (skt->nr) {
35 case 0:
36 skt->stat[SOC_STAT_CD].gpio = GPIO_PCD;
37 skt->stat[SOC_STAT_CD].name = "cs0_cd";
38 skt->stat[SOC_STAT_RDY].gpio = GPIO_PRDY;
39 skt->stat[SOC_STAT_RDY].name = "cs0_rdy";
40 break;
41 default:
42 break;
44 /* release the reset of this card */
45 pr_debug("%s: sock %d irq %d\n", __func__, skt->nr, skt->socket.pci_irq);
47 return 0;
50 static unsigned long trizeps_pcmcia_status[2];
52 static void trizeps_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
53 struct pcmcia_state *state)
55 unsigned short status = 0, change;
56 status = CFSR_readw();
57 change = (status ^ trizeps_pcmcia_status[skt->nr]) &
58 ConXS_CFSR_BVD_MASK;
59 if (change) {
60 trizeps_pcmcia_status[skt->nr] = status;
61 if (status & ConXS_CFSR_BVD1) {
62 /* enable_irq empty */
63 } else {
64 /* disable_irq empty */
68 switch (skt->nr) {
69 case 0:
70 /* just fill in fix states */
71 state->bvd1 = (status & ConXS_CFSR_BVD1) ? 1 : 0;
72 state->bvd2 = (status & ConXS_CFSR_BVD2) ? 1 : 0;
73 state->vs_3v = (status & ConXS_CFSR_VS1) ? 0 : 1;
74 state->vs_Xv = (status & ConXS_CFSR_VS2) ? 0 : 1;
75 break;
77 #ifndef CONFIG_MACH_TRIZEPS_CONXS
78 /* on ConXS we only have one slot. Second is inactive */
79 case 1:
80 state->detect = 0;
81 state->ready = 0;
82 state->bvd1 = 0;
83 state->bvd2 = 0;
84 state->vs_3v = 0;
85 state->vs_Xv = 0;
86 break;
88 #endif
92 static int trizeps_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
93 const socket_state_t *state)
95 int ret = 0;
96 unsigned short power = 0;
98 /* we do nothing here just check a bit */
99 switch (state->Vcc) {
100 case 0: power &= 0xfc; break;
101 case 33: power |= ConXS_BCR_S0_VCC_3V3; break;
102 case 50:
103 pr_err("%s(): Vcc 5V not supported in socket\n", __func__);
104 break;
105 default:
106 pr_err("%s(): bad Vcc %u\n", __func__, state->Vcc);
107 ret = -1;
110 switch (state->Vpp) {
111 case 0: power &= 0xf3; break;
112 case 33: power |= ConXS_BCR_S0_VPP_3V3; break;
113 case 120:
114 pr_err("%s(): Vpp 12V not supported in socket\n", __func__);
115 break;
116 default:
117 if (state->Vpp != state->Vcc) {
118 pr_err("%s(): bad Vpp %u\n", __func__, state->Vpp);
119 ret = -1;
123 switch (skt->nr) {
124 case 0: /* we only have 3.3V */
125 board_pcmcia_power(power);
126 break;
128 #ifndef CONFIG_MACH_TRIZEPS_CONXS
129 /* on ConXS we only have one slot. Second is inactive */
130 case 1:
131 #endif
132 default:
133 break;
136 return ret;
139 static void trizeps_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
141 /* default is on */
142 board_pcmcia_power(0x9);
145 static void trizeps_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
147 board_pcmcia_power(0x0);
150 static struct pcmcia_low_level trizeps_pcmcia_ops = {
151 .owner = THIS_MODULE,
152 .hw_init = trizeps_pcmcia_hw_init,
153 .socket_state = trizeps_pcmcia_socket_state,
154 .configure_socket = trizeps_pcmcia_configure_socket,
155 .socket_init = trizeps_pcmcia_socket_init,
156 .socket_suspend = trizeps_pcmcia_socket_suspend,
157 #ifdef CONFIG_MACH_TRIZEPS_CONXS
158 .nr = 1,
159 #else
160 .nr = 2,
161 #endif
162 .first = 0,
165 static struct platform_device *trizeps_pcmcia_device;
167 static int __init trizeps_pcmcia_init(void)
169 int ret;
171 if (!machine_is_trizeps4() && !machine_is_trizeps4wl())
172 return -ENODEV;
174 trizeps_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
175 if (!trizeps_pcmcia_device)
176 return -ENOMEM;
178 ret = platform_device_add_data(trizeps_pcmcia_device,
179 &trizeps_pcmcia_ops, sizeof(trizeps_pcmcia_ops));
181 if (ret == 0)
182 ret = platform_device_add(trizeps_pcmcia_device);
184 if (ret)
185 platform_device_put(trizeps_pcmcia_device);
187 return ret;
190 static void __exit trizeps_pcmcia_exit(void)
192 platform_device_unregister(trizeps_pcmcia_device);
195 fs_initcall(trizeps_pcmcia_init);
196 module_exit(trizeps_pcmcia_exit);
198 MODULE_LICENSE("GPL");
199 MODULE_AUTHOR("Juergen Schindele");
200 MODULE_ALIAS("platform:pxa2xx-pcmcia");