treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / pcmcia / pxa2xx_mainstone.c
bloba076e41084528cbb666f23ed2e0d7482843e1c1c
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * linux/drivers/pcmcia/pxa2xx_mainstone.c
5 * Mainstone PCMCIA specific routines.
7 * Created: May 12, 2004
8 * Author: Nicolas Pitre
9 * Copyright: MontaVista Software Inc.
11 #include <linux/gpio/consumer.h>
12 #include <linux/module.h>
13 #include <linux/init.h>
14 #include <linux/interrupt.h>
15 #include <linux/kernel.h>
16 #include <linux/errno.h>
17 #include <linux/platform_device.h>
19 #include <pcmcia/ss.h>
21 #include <asm/mach-types.h>
23 #include "soc_common.h"
24 #include "max1600.h"
26 static int mst_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
28 struct device *dev = skt->socket.dev.parent;
29 struct max1600 *m;
30 int ret;
32 skt->stat[SOC_STAT_CD].name = skt->nr ? "bdetect" : "adetect";
33 skt->stat[SOC_STAT_BVD1].name = skt->nr ? "bbvd1" : "abvd1";
34 skt->stat[SOC_STAT_BVD2].name = skt->nr ? "bbvd2" : "abvd2";
35 skt->stat[SOC_STAT_RDY].name = skt->nr ? "bready" : "aready";
36 skt->stat[SOC_STAT_VS1].name = skt->nr ? "bvs1" : "avs1";
37 skt->stat[SOC_STAT_VS2].name = skt->nr ? "bvs2" : "avs2";
39 skt->gpio_reset = devm_gpiod_get(dev, skt->nr ? "breset" : "areset",
40 GPIOD_OUT_HIGH);
41 if (IS_ERR(skt->gpio_reset))
42 return PTR_ERR(skt->gpio_reset);
44 ret = max1600_init(dev, &m, skt->nr ? MAX1600_CHAN_B : MAX1600_CHAN_A,
45 MAX1600_CODE_HIGH);
46 if (ret)
47 return ret;
49 skt->driver_data = m;
51 return soc_pcmcia_request_gpiods(skt);
54 static unsigned int mst_pcmcia_bvd1_status[2];
56 static void mst_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
57 struct pcmcia_state *state)
59 unsigned int flip = mst_pcmcia_bvd1_status[skt->nr] ^ state->bvd1;
62 * Workaround for STSCHG which can't be deasserted:
63 * We therefore disable/enable corresponding IRQs
64 * as needed to avoid IRQ locks.
66 if (flip) {
67 mst_pcmcia_bvd1_status[skt->nr] = state->bvd1;
68 if (state->bvd1)
69 enable_irq(skt->stat[SOC_STAT_BVD1].irq);
70 else
71 disable_irq(skt->stat[SOC_STAT_BVD2].irq);
75 static int mst_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
76 const socket_state_t *state)
78 return max1600_configure(skt->driver_data, state->Vcc, state->Vpp);
81 static struct pcmcia_low_level mst_pcmcia_ops __initdata = {
82 .owner = THIS_MODULE,
83 .hw_init = mst_pcmcia_hw_init,
84 .socket_state = mst_pcmcia_socket_state,
85 .configure_socket = mst_pcmcia_configure_socket,
86 .nr = 2,
89 static struct platform_device *mst_pcmcia_device;
91 static int __init mst_pcmcia_init(void)
93 int ret;
95 if (!machine_is_mainstone())
96 return -ENODEV;
98 mst_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
99 if (!mst_pcmcia_device)
100 return -ENOMEM;
102 ret = platform_device_add_data(mst_pcmcia_device, &mst_pcmcia_ops,
103 sizeof(mst_pcmcia_ops));
104 if (ret == 0)
105 ret = platform_device_add(mst_pcmcia_device);
107 if (ret)
108 platform_device_put(mst_pcmcia_device);
110 return ret;
113 static void __exit mst_pcmcia_exit(void)
115 platform_device_unregister(mst_pcmcia_device);
118 fs_initcall(mst_pcmcia_init);
119 module_exit(mst_pcmcia_exit);
121 MODULE_LICENSE("GPL");
122 MODULE_ALIAS("platform:pxa2xx-pcmcia");