Loading...
1/*
2 * linux/drivers/pcmcia/pxa2xx_stargate2.c
3 *
4 * Stargate 2 PCMCIA specific routines.
5 *
6 * Created: December 6, 2005
7 * Author: Ed C. Epp
8 * Copyright: Intel Corp 2005
9 * Jonathan Cameron <jic23@cam.ac.uk> 2009
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
14 */
15
16#include <linux/module.h>
17#include <linux/init.h>
18#include <linux/kernel.h>
19#include <linux/interrupt.h>
20#include <linux/delay.h>
21#include <linux/platform_device.h>
22#include <linux/gpio.h>
23
24#include <pcmcia/ss.h>
25
26#include <asm/irq.h>
27#include <asm/mach-types.h>
28
29#include "soc_common.h"
30
31#define SG2_S0_POWER_CTL 108
32#define SG2_S0_GPIO_RESET 82
33#define SG2_S0_GPIO_DETECT 53
34#define SG2_S0_GPIO_READY 81
35
36static struct pcmcia_irqs irqs[] = {
37 { 0, IRQ_GPIO(SG2_S0_GPIO_DETECT), "PCMCIA0 CD" },
38};
39
40static struct gpio sg2_pcmcia_gpios[] = {
41 { SG2_S0_GPIO_RESET, GPIOF_OUT_INIT_HIGH, "PCMCIA Reset" },
42 { SG2_S0_POWER_CTL, GPIOF_OUT_INIT_HIGH, "PCMCIA Power Ctrl" },
43};
44
45static int sg2_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
46{
47 skt->socket.pci_irq = IRQ_GPIO(SG2_S0_GPIO_READY);
48 return soc_pcmcia_request_irqs(skt, irqs, ARRAY_SIZE(irqs));
49}
50
51static void sg2_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
52{
53 soc_pcmcia_free_irqs(skt, irqs, ARRAY_SIZE(irqs));
54}
55
56static void sg2_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
57 struct pcmcia_state *state)
58{
59 state->detect = !gpio_get_value(SG2_S0_GPIO_DETECT);
60 state->ready = !!gpio_get_value(SG2_S0_GPIO_READY);
61 state->bvd1 = 0; /* not available - battery detect on card */
62 state->bvd2 = 0; /* not available */
63 state->vs_3v = 1; /* not available - voltage detect for card */
64 state->vs_Xv = 0; /* not available */
65 state->wrprot = 0; /* not available - write protect */
66}
67
68static int sg2_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
69 const socket_state_t *state)
70{
71 /* Enable card power */
72 switch (state->Vcc) {
73 case 0:
74 /* sets power ctl register high */
75 gpio_set_value(SG2_S0_POWER_CTL, 1);
76 break;
77 case 33:
78 case 50:
79 /* sets power control register low (clear) */
80 gpio_set_value(SG2_S0_POWER_CTL, 0);
81 msleep(100);
82 break;
83 default:
84 pr_err("%s(): bad Vcc %u\n",
85 __func__, state->Vcc);
86 return -1;
87 }
88
89 /* reset */
90 gpio_set_value(SG2_S0_GPIO_RESET, !!(state->flags & SS_RESET));
91
92 return 0;
93}
94
95static void sg2_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
96{
97 soc_pcmcia_enable_irqs(skt, irqs, ARRAY_SIZE(irqs));
98}
99
100static void sg2_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
101{
102 soc_pcmcia_disable_irqs(skt, irqs, ARRAY_SIZE(irqs));
103}
104
105static struct pcmcia_low_level sg2_pcmcia_ops __initdata = {
106 .owner = THIS_MODULE,
107 .hw_init = sg2_pcmcia_hw_init,
108 .hw_shutdown = sg2_pcmcia_hw_shutdown,
109 .socket_state = sg2_pcmcia_socket_state,
110 .configure_socket = sg2_pcmcia_configure_socket,
111 .socket_init = sg2_pcmcia_socket_init,
112 .socket_suspend = sg2_pcmcia_socket_suspend,
113 .nr = 1,
114};
115
116static struct platform_device *sg2_pcmcia_device;
117
118static int __init sg2_pcmcia_init(void)
119{
120 int ret;
121
122 if (!machine_is_stargate2())
123 return -ENODEV;
124
125 sg2_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
126 if (!sg2_pcmcia_device)
127 return -ENOMEM;
128
129 ret = gpio_request_array(sg2_pcmcia_gpios, ARRAY_SIZE(sg2_pcmcia_gpios));
130 if (ret)
131 goto error_put_platform_device;
132
133 ret = platform_device_add_data(sg2_pcmcia_device,
134 &sg2_pcmcia_ops,
135 sizeof(sg2_pcmcia_ops));
136 if (ret)
137 goto error_free_gpios;
138
139 ret = platform_device_add(sg2_pcmcia_device);
140 if (ret)
141 goto error_free_gpios;
142
143 return 0;
144error_free_gpios:
145 gpio_free_array(sg2_pcmcia_gpios, ARRAY_SIZE(sg2_pcmcia_gpios));
146error_put_platform_device:
147 platform_device_put(sg2_pcmcia_device);
148
149 return ret;
150}
151
152static void __exit sg2_pcmcia_exit(void)
153{
154 platform_device_unregister(sg2_pcmcia_device);
155 gpio_free_array(sg2_pcmcia_gpios, ARRAY_SIZE(sg2_pcmcia_gpios));
156}
157
158fs_initcall(sg2_pcmcia_init);
159module_exit(sg2_pcmcia_exit);
160
161MODULE_LICENSE("GPL");
162MODULE_ALIAS("platform:pxa2xx-pcmcia");
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * linux/drivers/pcmcia/pxa2xx_stargate2.c
4 *
5 * Stargate 2 PCMCIA specific routines.
6 *
7 * Created: December 6, 2005
8 * Author: Ed C. Epp
9 * Copyright: Intel Corp 2005
10 * Jonathan Cameron <jic23@cam.ac.uk> 2009
11 */
12
13#include <linux/module.h>
14#include <linux/init.h>
15#include <linux/kernel.h>
16#include <linux/interrupt.h>
17#include <linux/delay.h>
18#include <linux/platform_device.h>
19#include <linux/gpio.h>
20
21#include <pcmcia/ss.h>
22
23#include <asm/irq.h>
24#include <asm/mach-types.h>
25
26#include "soc_common.h"
27
28#define SG2_S0_POWER_CTL 108
29#define SG2_S0_GPIO_RESET 82
30#define SG2_S0_GPIO_DETECT 53
31#define SG2_S0_GPIO_READY 81
32
33static struct gpio sg2_pcmcia_gpios[] = {
34 { SG2_S0_GPIO_RESET, GPIOF_OUT_INIT_HIGH, "PCMCIA Reset" },
35 { SG2_S0_POWER_CTL, GPIOF_OUT_INIT_HIGH, "PCMCIA Power Ctrl" },
36};
37
38static int sg2_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
39{
40 skt->stat[SOC_STAT_CD].gpio = SG2_S0_GPIO_DETECT;
41 skt->stat[SOC_STAT_CD].name = "PCMCIA0 CD";
42 skt->stat[SOC_STAT_RDY].gpio = SG2_S0_GPIO_READY;
43 skt->stat[SOC_STAT_RDY].name = "PCMCIA0 RDY";
44 return 0;
45}
46
47static void sg2_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
48 struct pcmcia_state *state)
49{
50 state->bvd1 = 0; /* not available - battery detect on card */
51 state->bvd2 = 0; /* not available */
52 state->vs_3v = 1; /* not available - voltage detect for card */
53 state->vs_Xv = 0; /* not available */
54}
55
56static int sg2_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
57 const socket_state_t *state)
58{
59 /* Enable card power */
60 switch (state->Vcc) {
61 case 0:
62 /* sets power ctl register high */
63 gpio_set_value(SG2_S0_POWER_CTL, 1);
64 break;
65 case 33:
66 case 50:
67 /* sets power control register low (clear) */
68 gpio_set_value(SG2_S0_POWER_CTL, 0);
69 msleep(100);
70 break;
71 default:
72 pr_err("%s(): bad Vcc %u\n",
73 __func__, state->Vcc);
74 return -1;
75 }
76
77 /* reset */
78 gpio_set_value(SG2_S0_GPIO_RESET, !!(state->flags & SS_RESET));
79
80 return 0;
81}
82
83static struct pcmcia_low_level sg2_pcmcia_ops __initdata = {
84 .owner = THIS_MODULE,
85 .hw_init = sg2_pcmcia_hw_init,
86 .socket_state = sg2_pcmcia_socket_state,
87 .configure_socket = sg2_pcmcia_configure_socket,
88 .nr = 1,
89};
90
91static struct platform_device *sg2_pcmcia_device;
92
93static int __init sg2_pcmcia_init(void)
94{
95 int ret;
96
97 if (!machine_is_stargate2())
98 return -ENODEV;
99
100 sg2_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
101 if (!sg2_pcmcia_device)
102 return -ENOMEM;
103
104 ret = gpio_request_array(sg2_pcmcia_gpios, ARRAY_SIZE(sg2_pcmcia_gpios));
105 if (ret)
106 goto error_put_platform_device;
107
108 ret = platform_device_add_data(sg2_pcmcia_device,
109 &sg2_pcmcia_ops,
110 sizeof(sg2_pcmcia_ops));
111 if (ret)
112 goto error_free_gpios;
113
114 ret = platform_device_add(sg2_pcmcia_device);
115 if (ret)
116 goto error_free_gpios;
117
118 return 0;
119error_free_gpios:
120 gpio_free_array(sg2_pcmcia_gpios, ARRAY_SIZE(sg2_pcmcia_gpios));
121error_put_platform_device:
122 platform_device_put(sg2_pcmcia_device);
123
124 return ret;
125}
126
127static void __exit sg2_pcmcia_exit(void)
128{
129 platform_device_unregister(sg2_pcmcia_device);
130 gpio_free_array(sg2_pcmcia_gpios, ARRAY_SIZE(sg2_pcmcia_gpios));
131}
132
133fs_initcall(sg2_pcmcia_init);
134module_exit(sg2_pcmcia_exit);
135
136MODULE_LICENSE("GPL");
137MODULE_ALIAS("platform:pxa2xx-pcmcia");