blob: aebf9a66fddea777dd8b8be8c679ed4ed829e326 [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
Dmitry Artamonow2a837092009-12-06 17:12:49 +010027 switch (skt->nr) {
28 case 0:
Russell King65474b42012-01-13 23:07:26 +000029 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";
Dmitry Artamonow2a837092009-12-06 17:12:49 +010033
Dmitry Artamonow22f97402009-11-27 12:02:28 +010034 err = gpio_request(H3XXX_EGPIO_OPT_NVRAM_ON, "OPT NVRAM ON");
Dmitry Artamonow2a837092009-12-06 17:12:49 +010035 if (err)
Russell King65474b42012-01-13 23:07:26 +000036 goto err01;
Dmitry Artamonow22f97402009-11-27 12:02:28 +010037 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;
Dmitry Artamonow2a837092009-12-06 17:12:49 +010058 break;
59 case 1:
Russell King65474b42012-01-13 23:07:26 +000060 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";
Dmitry Artamonow2a837092009-12-06 17:12:49 +010064 break;
65 }
66 return 0;
67
Dmitry Artamonow22f97402009-11-27 12:02:28 +010068err06: gpio_free(H3XXX_EGPIO_CARD_RESET);
69err05: gpio_free(H3XXX_EGPIO_OPT_RESET);
70err04: gpio_free(H3XXX_EGPIO_OPT_ON);
71err03: gpio_free(H3XXX_EGPIO_OPT_NVRAM_ON);
Dmitry Artamonow2a837092009-12-06 17:12:49 +010072err01: gpio_free(H3XXX_GPIO_PCMCIA_IRQ0);
Russell King65474b42012-01-13 23:07:26 +000073 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074}
75
76static void h3600_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
77{
Dmitry Artamonow2a837092009-12-06 17:12:49 +010078 switch (skt->nr) {
79 case 0:
Dmitry Artamonow22f97402009-11-27 12:02:28 +010080 /* 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);
84
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);
Dmitry Artamonow2a837092009-12-06 17:12:49 +010089 break;
90 case 1:
Dmitry Artamonow2a837092009-12-06 17:12:49 +010091 break;
92 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070093}
94
95static void
96h3600_pcmcia_socket_state(struct soc_pcmcia_socket *skt, struct pcmcia_state *state)
97{
Russell King65474b42012-01-13 23:07:26 +000098 state->bvd1 = 0;
99 state->bvd2 = 0;
Russell King65474b42012-01-13 23:07:26 +0000100 state->vs_3v = 0;
101 state->vs_Xv = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102}
103
104static int
105h3600_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, const socket_state_t *state)
106{
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;
111 }
112
Dmitry Artamonow22f97402009-11-27 12:02:28 +0100113 gpio_set_value(H3XXX_EGPIO_CARD_RESET, !!(state->flags & SS_RESET));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
115 /* Silently ignore Vpp, output enable, speaker enable. */
116
117 return 0;
118}
119
120static void h3600_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
121{
122 /* Enable CF bus: */
Dmitry Artamonow22f97402009-11-27 12:02:28 +0100123 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
127 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128}
129
130static void h3600_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
131{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 /*
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.
137 */
138 if (skt->nr == 1) {
Dmitry Artamonow22f97402009-11-27 12:02:28 +0100139 gpio_set_value(H3XXX_EGPIO_OPT_ON, 0);
140 gpio_set_value(H3XXX_EGPIO_OPT_NVRAM_ON, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 /* hmm, does this suck power? */
Dmitry Artamonow22f97402009-11-27 12:02:28 +0100142 gpio_set_value(H3XXX_EGPIO_OPT_RESET, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 }
144}
145
146struct 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,
152
153 .socket_init = h3600_pcmcia_socket_init,
154 .socket_suspend = h3600_pcmcia_socket_suspend,
155};
156
Bill Pemberton34cdf252012-11-19 13:23:12 -0500157int pcmcia_h3600_init(struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158{
159 int ret = -ENODEV;
160
Dmitry Artamonowe7435f82009-11-27 12:13:47 +0100161 if (machine_is_h3600() || machine_is_h3100())
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 ret = sa11xx_drv_pcmcia_probe(dev, &h3600_pcmcia_ops, 0, 2);
163
164 return ret;
165}