blob: a91222bc3824c285ef916c6d54d9d030cbbfc372 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * drivers/pcmcia/sa1100_h3600.c
4 *
5 * PCMCIA implementation routines for H3600
6 *
7 */
8#include <linux/module.h>
9#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/device.h>
11#include <linux/interrupt.h>
12#include <linux/init.h>
13#include <linux/delay.h>
Dmitry Artamonow2a837092009-12-06 17:12:49 +010014#include <linux/gpio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
Russell Kinga09e64f2008-08-05 16:14:15 +010016#include <mach/hardware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <asm/irq.h>
18#include <asm/mach-types.h>
Dmitry Artamonow8715b292009-11-27 12:09:25 +010019#include <mach/h3xxx.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
21#include "sa1100_generic.h"
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023static int h3600_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
24{
Dmitry Artamonow2a837092009-12-06 17:12:49 +010025 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
Russell Kinga00315d2016-08-31 08:49:48 +010027 skt->stat[SOC_STAT_CD].name = skt->nr ? "pcmcia1-detect" : "pcmcia0-detect";
28 skt->stat[SOC_STAT_RDY].name = skt->nr ? "pcmcia1-ready" : "pcmcia0-ready";
29
30 err = soc_pcmcia_request_gpiods(skt);
31 if (err)
32 return err;
33
Dmitry Artamonow2a837092009-12-06 17:12:49 +010034 switch (skt->nr) {
35 case 0:
Dmitry Artamonow22f97402009-11-27 12:02:28 +010036 err = gpio_request(H3XXX_EGPIO_OPT_NVRAM_ON, "OPT NVRAM ON");
Dmitry Artamonow2a837092009-12-06 17:12:49 +010037 if (err)
Russell King65474b42012-01-13 23:07:26 +000038 goto err01;
Dmitry Artamonow22f97402009-11-27 12:02:28 +010039 err = gpio_direction_output(H3XXX_EGPIO_OPT_NVRAM_ON, 0);
40 if (err)
41 goto err03;
42 err = gpio_request(H3XXX_EGPIO_OPT_ON, "OPT ON");
43 if (err)
44 goto err03;
45 err = gpio_direction_output(H3XXX_EGPIO_OPT_ON, 0);
46 if (err)
47 goto err04;
48 err = gpio_request(H3XXX_EGPIO_OPT_RESET, "OPT RESET");
49 if (err)
50 goto err04;
51 err = gpio_direction_output(H3XXX_EGPIO_OPT_RESET, 0);
52 if (err)
53 goto err05;
54 err = gpio_request(H3XXX_EGPIO_CARD_RESET, "PCMCIA CARD RESET");
55 if (err)
56 goto err05;
57 err = gpio_direction_output(H3XXX_EGPIO_CARD_RESET, 0);
58 if (err)
59 goto err06;
Dmitry Artamonow2a837092009-12-06 17:12:49 +010060 break;
61 case 1:
Dmitry Artamonow2a837092009-12-06 17:12:49 +010062 break;
63 }
64 return 0;
65
Dmitry Artamonow22f97402009-11-27 12:02:28 +010066err06: gpio_free(H3XXX_EGPIO_CARD_RESET);
67err05: gpio_free(H3XXX_EGPIO_OPT_RESET);
68err04: gpio_free(H3XXX_EGPIO_OPT_ON);
69err03: gpio_free(H3XXX_EGPIO_OPT_NVRAM_ON);
Dmitry Artamonow2a837092009-12-06 17:12:49 +010070err01: gpio_free(H3XXX_GPIO_PCMCIA_IRQ0);
Russell King65474b42012-01-13 23:07:26 +000071 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072}
73
74static void h3600_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
75{
Dmitry Artamonow2a837092009-12-06 17:12:49 +010076 switch (skt->nr) {
77 case 0:
Dmitry Artamonow22f97402009-11-27 12:02:28 +010078 /* Disable CF bus: */
79 gpio_set_value(H3XXX_EGPIO_OPT_NVRAM_ON, 0);
80 gpio_set_value(H3XXX_EGPIO_OPT_ON, 0);
81 gpio_set_value(H3XXX_EGPIO_OPT_RESET, 1);
82
83 gpio_free(H3XXX_EGPIO_CARD_RESET);
84 gpio_free(H3XXX_EGPIO_OPT_RESET);
85 gpio_free(H3XXX_EGPIO_OPT_ON);
86 gpio_free(H3XXX_EGPIO_OPT_NVRAM_ON);
Dmitry Artamonow2a837092009-12-06 17:12:49 +010087 break;
88 case 1:
Dmitry Artamonow2a837092009-12-06 17:12:49 +010089 break;
90 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070091}
92
93static void
94h3600_pcmcia_socket_state(struct soc_pcmcia_socket *skt, struct pcmcia_state *state)
95{
Russell King65474b42012-01-13 23:07:26 +000096 state->bvd1 = 0;
97 state->bvd2 = 0;
Russell King65474b42012-01-13 23:07:26 +000098 state->vs_3v = 0;
99 state->vs_Xv = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100}
101
102static int
103h3600_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, const socket_state_t *state)
104{
105 if (state->Vcc != 0 && state->Vcc != 33 && state->Vcc != 50) {
106 printk(KERN_ERR "h3600_pcmcia: unrecognized Vcc %u.%uV\n",
107 state->Vcc / 10, state->Vcc % 10);
108 return -1;
109 }
110
Dmitry Artamonow22f97402009-11-27 12:02:28 +0100111 gpio_set_value(H3XXX_EGPIO_CARD_RESET, !!(state->flags & SS_RESET));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
113 /* Silently ignore Vpp, output enable, speaker enable. */
114
115 return 0;
116}
117
118static void h3600_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
119{
120 /* Enable CF bus: */
Dmitry Artamonow22f97402009-11-27 12:02:28 +0100121 gpio_set_value(H3XXX_EGPIO_OPT_NVRAM_ON, 1);
122 gpio_set_value(H3XXX_EGPIO_OPT_ON, 1);
123 gpio_set_value(H3XXX_EGPIO_OPT_RESET, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
125 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126}
127
128static void h3600_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
129{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 /*
131 * FIXME: This doesn't fit well. We don't have the mechanism in
132 * the generic PCMCIA layer to deal with the idea of two sockets
133 * on one bus. We rely on the cs.c behaviour shutting down
134 * socket 0 then socket 1.
135 */
136 if (skt->nr == 1) {
Dmitry Artamonow22f97402009-11-27 12:02:28 +0100137 gpio_set_value(H3XXX_EGPIO_OPT_ON, 0);
138 gpio_set_value(H3XXX_EGPIO_OPT_NVRAM_ON, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 /* hmm, does this suck power? */
Dmitry Artamonow22f97402009-11-27 12:02:28 +0100140 gpio_set_value(H3XXX_EGPIO_OPT_RESET, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 }
142}
143
144struct pcmcia_low_level h3600_pcmcia_ops = {
145 .owner = THIS_MODULE,
146 .hw_init = h3600_pcmcia_hw_init,
147 .hw_shutdown = h3600_pcmcia_hw_shutdown,
148 .socket_state = h3600_pcmcia_socket_state,
149 .configure_socket = h3600_pcmcia_configure_socket,
150
151 .socket_init = h3600_pcmcia_socket_init,
152 .socket_suspend = h3600_pcmcia_socket_suspend,
153};
154
Bill Pemberton34cdf252012-11-19 13:23:12 -0500155int pcmcia_h3600_init(struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156{
157 int ret = -ENODEV;
158
Dmitry Artamonowe7435f82009-11-27 12:13:47 +0100159 if (machine_is_h3600() || machine_is_h3100())
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 ret = sa11xx_drv_pcmcia_probe(dev, &h3600_pcmcia_ops, 0, 2);
161
162 return ret;
163}