gpio: rcar: Fix runtime PM imbalance on error
[linux/fpc-iii.git] / drivers / pcmcia / pxa2xx_e740.c
blob72caa6d05ab99d5ebaad276d29886f58532e0f4f
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Toshiba e740 PCMCIA specific routines.
5 * (c) 2004 Ian Molton <spyro@f2s.com>
6 */
8 #include <linux/init.h>
9 #include <linux/module.h>
10 #include <linux/kernel.h>
11 #include <linux/errno.h>
12 #include <linux/gpio.h>
13 #include <linux/interrupt.h>
14 #include <linux/platform_device.h>
16 #include <mach/eseries-gpio.h>
18 #include <asm/irq.h>
19 #include <asm/mach-types.h>
21 #include "soc_common.h"
23 static int e740_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
25 if (skt->nr == 0) {
26 skt->stat[SOC_STAT_CD].gpio = GPIO_E740_PCMCIA_CD0;
27 skt->stat[SOC_STAT_CD].name = "CF card detect";
28 skt->stat[SOC_STAT_RDY].gpio = GPIO_E740_PCMCIA_RDY0;
29 skt->stat[SOC_STAT_RDY].name = "CF ready";
30 } else {
31 skt->stat[SOC_STAT_CD].gpio = GPIO_E740_PCMCIA_CD1;
32 skt->stat[SOC_STAT_CD].name = "Wifi switch";
33 skt->stat[SOC_STAT_RDY].gpio = GPIO_E740_PCMCIA_RDY1;
34 skt->stat[SOC_STAT_RDY].name = "Wifi ready";
37 return 0;
40 static void e740_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
41 struct pcmcia_state *state)
43 state->vs_3v = 1;
44 state->vs_Xv = 0;
47 static int e740_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
48 const socket_state_t *state)
50 if (state->flags & SS_RESET) {
51 if (skt->nr == 0)
52 gpio_set_value(GPIO_E740_PCMCIA_RST0, 1);
53 else
54 gpio_set_value(GPIO_E740_PCMCIA_RST1, 1);
55 } else {
56 if (skt->nr == 0)
57 gpio_set_value(GPIO_E740_PCMCIA_RST0, 0);
58 else
59 gpio_set_value(GPIO_E740_PCMCIA_RST1, 0);
62 switch (state->Vcc) {
63 case 0: /* Socket off */
64 if (skt->nr == 0)
65 gpio_set_value(GPIO_E740_PCMCIA_PWR0, 0);
66 else
67 gpio_set_value(GPIO_E740_PCMCIA_PWR1, 1);
68 break;
69 case 50:
70 case 33: /* socket on */
71 if (skt->nr == 0)
72 gpio_set_value(GPIO_E740_PCMCIA_PWR0, 1);
73 else
74 gpio_set_value(GPIO_E740_PCMCIA_PWR1, 0);
75 break;
76 default:
77 printk(KERN_ERR "e740_cs: Unsupported Vcc: %d\n", state->Vcc);
80 return 0;
83 static struct pcmcia_low_level e740_pcmcia_ops = {
84 .owner = THIS_MODULE,
85 .hw_init = e740_pcmcia_hw_init,
86 .socket_state = e740_pcmcia_socket_state,
87 .configure_socket = e740_pcmcia_configure_socket,
88 .nr = 2,
91 static struct platform_device *e740_pcmcia_device;
93 static int __init e740_pcmcia_init(void)
95 int ret;
97 if (!machine_is_e740())
98 return -ENODEV;
100 e740_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
101 if (!e740_pcmcia_device)
102 return -ENOMEM;
104 ret = platform_device_add_data(e740_pcmcia_device, &e740_pcmcia_ops,
105 sizeof(e740_pcmcia_ops));
107 if (!ret)
108 ret = platform_device_add(e740_pcmcia_device);
110 if (ret)
111 platform_device_put(e740_pcmcia_device);
113 return ret;
116 static void __exit e740_pcmcia_exit(void)
118 platform_device_unregister(e740_pcmcia_device);
121 module_init(e740_pcmcia_init);
122 module_exit(e740_pcmcia_exit);
124 MODULE_LICENSE("GPL v2");
125 MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
126 MODULE_ALIAS("platform:pxa2xx-pcmcia");
127 MODULE_DESCRIPTION("e740 PCMCIA platform support");