Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / drivers / pcmcia / sa1100_h3600.c
blobaebf9a66fddea777dd8b8be8c679ed4ed829e326
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * drivers/pcmcia/sa1100_h3600.c
5 * PCMCIA implementation routines for H3600
7 */
8 #include <linux/module.h>
9 #include <linux/kernel.h>
10 #include <linux/device.h>
11 #include <linux/interrupt.h>
12 #include <linux/init.h>
13 #include <linux/delay.h>
14 #include <linux/gpio.h>
16 #include <mach/hardware.h>
17 #include <asm/irq.h>
18 #include <asm/mach-types.h>
19 #include <mach/h3xxx.h>
21 #include "sa1100_generic.h"
23 static int h3600_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
25 int err;
27 switch (skt->nr) {
28 case 0:
29 skt->stat[SOC_STAT_CD].gpio = H3XXX_GPIO_PCMCIA_CD0;
30 skt->stat[SOC_STAT_CD].name = "PCMCIA CD0";
31 skt->stat[SOC_STAT_RDY].gpio = H3XXX_GPIO_PCMCIA_IRQ0;
32 skt->stat[SOC_STAT_RDY].name = "PCMCIA IRQ0";
34 err = gpio_request(H3XXX_EGPIO_OPT_NVRAM_ON, "OPT NVRAM ON");
35 if (err)
36 goto err01;
37 err = gpio_direction_output(H3XXX_EGPIO_OPT_NVRAM_ON, 0);
38 if (err)
39 goto err03;
40 err = gpio_request(H3XXX_EGPIO_OPT_ON, "OPT ON");
41 if (err)
42 goto err03;
43 err = gpio_direction_output(H3XXX_EGPIO_OPT_ON, 0);
44 if (err)
45 goto err04;
46 err = gpio_request(H3XXX_EGPIO_OPT_RESET, "OPT RESET");
47 if (err)
48 goto err04;
49 err = gpio_direction_output(H3XXX_EGPIO_OPT_RESET, 0);
50 if (err)
51 goto err05;
52 err = gpio_request(H3XXX_EGPIO_CARD_RESET, "PCMCIA CARD RESET");
53 if (err)
54 goto err05;
55 err = gpio_direction_output(H3XXX_EGPIO_CARD_RESET, 0);
56 if (err)
57 goto err06;
58 break;
59 case 1:
60 skt->stat[SOC_STAT_CD].gpio = H3XXX_GPIO_PCMCIA_CD1;
61 skt->stat[SOC_STAT_CD].name = "PCMCIA CD1";
62 skt->stat[SOC_STAT_RDY].gpio = H3XXX_GPIO_PCMCIA_IRQ1;
63 skt->stat[SOC_STAT_RDY].name = "PCMCIA IRQ1";
64 break;
66 return 0;
68 err06: gpio_free(H3XXX_EGPIO_CARD_RESET);
69 err05: gpio_free(H3XXX_EGPIO_OPT_RESET);
70 err04: gpio_free(H3XXX_EGPIO_OPT_ON);
71 err03: gpio_free(H3XXX_EGPIO_OPT_NVRAM_ON);
72 err01: gpio_free(H3XXX_GPIO_PCMCIA_IRQ0);
73 return err;
76 static void h3600_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
78 switch (skt->nr) {
79 case 0:
80 /* Disable CF bus: */
81 gpio_set_value(H3XXX_EGPIO_OPT_NVRAM_ON, 0);
82 gpio_set_value(H3XXX_EGPIO_OPT_ON, 0);
83 gpio_set_value(H3XXX_EGPIO_OPT_RESET, 1);
85 gpio_free(H3XXX_EGPIO_CARD_RESET);
86 gpio_free(H3XXX_EGPIO_OPT_RESET);
87 gpio_free(H3XXX_EGPIO_OPT_ON);
88 gpio_free(H3XXX_EGPIO_OPT_NVRAM_ON);
89 break;
90 case 1:
91 break;
95 static void
96 h3600_pcmcia_socket_state(struct soc_pcmcia_socket *skt, struct pcmcia_state *state)
98 state->bvd1 = 0;
99 state->bvd2 = 0;
100 state->vs_3v = 0;
101 state->vs_Xv = 0;
104 static int
105 h3600_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, const socket_state_t *state)
107 if (state->Vcc != 0 && state->Vcc != 33 && state->Vcc != 50) {
108 printk(KERN_ERR "h3600_pcmcia: unrecognized Vcc %u.%uV\n",
109 state->Vcc / 10, state->Vcc % 10);
110 return -1;
113 gpio_set_value(H3XXX_EGPIO_CARD_RESET, !!(state->flags & SS_RESET));
115 /* Silently ignore Vpp, output enable, speaker enable. */
117 return 0;
120 static void h3600_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
122 /* Enable CF bus: */
123 gpio_set_value(H3XXX_EGPIO_OPT_NVRAM_ON, 1);
124 gpio_set_value(H3XXX_EGPIO_OPT_ON, 1);
125 gpio_set_value(H3XXX_EGPIO_OPT_RESET, 0);
127 msleep(10);
130 static void h3600_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
133 * FIXME: This doesn't fit well. We don't have the mechanism in
134 * the generic PCMCIA layer to deal with the idea of two sockets
135 * on one bus. We rely on the cs.c behaviour shutting down
136 * socket 0 then socket 1.
138 if (skt->nr == 1) {
139 gpio_set_value(H3XXX_EGPIO_OPT_ON, 0);
140 gpio_set_value(H3XXX_EGPIO_OPT_NVRAM_ON, 0);
141 /* hmm, does this suck power? */
142 gpio_set_value(H3XXX_EGPIO_OPT_RESET, 1);
146 struct pcmcia_low_level h3600_pcmcia_ops = {
147 .owner = THIS_MODULE,
148 .hw_init = h3600_pcmcia_hw_init,
149 .hw_shutdown = h3600_pcmcia_hw_shutdown,
150 .socket_state = h3600_pcmcia_socket_state,
151 .configure_socket = h3600_pcmcia_configure_socket,
153 .socket_init = h3600_pcmcia_socket_init,
154 .socket_suspend = h3600_pcmcia_socket_suspend,
157 int pcmcia_h3600_init(struct device *dev)
159 int ret = -ENODEV;
161 if (machine_is_h3600() || machine_is_h3100())
162 ret = sa11xx_drv_pcmcia_probe(dev, &h3600_pcmcia_ops, 0, 2);
164 return ret;