blob: 0cc3748f3758d866c0decfd9f7ce020c4cd97b39 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * drivers/pcmcia/sa1100_h3600.c
3 *
4 * PCMCIA implementation routines for H3600
5 *
6 */
7#include <linux/module.h>
8#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include <linux/device.h>
10#include <linux/interrupt.h>
11#include <linux/init.h>
12#include <linux/delay.h>
13
Russell Kinga09e64f2008-08-05 16:14:15 +010014#include <mach/hardware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <asm/irq.h>
16#include <asm/mach-types.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010017#include <mach/h3600.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
19#include "sa1100_generic.h"
20
21static struct pcmcia_irqs irqs[] = {
22 { 0, IRQ_GPIO_H3600_PCMCIA_CD0, "PCMCIA CD0" },
23 { 1, IRQ_GPIO_H3600_PCMCIA_CD1, "PCMCIA CD1" }
24};
25
26static int h3600_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
27{
28 skt->irq = skt->nr ? IRQ_GPIO_H3600_PCMCIA_IRQ1
29 : IRQ_GPIO_H3600_PCMCIA_IRQ0;
30
31
32 return soc_pcmcia_request_irqs(skt, irqs, ARRAY_SIZE(irqs));
33}
34
35static void h3600_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
36{
37 soc_pcmcia_free_irqs(skt, irqs, ARRAY_SIZE(irqs));
38
39 /* Disable CF bus: */
Dmitry Artamonow104a4162009-03-15 19:13:16 +010040 assign_h3600_egpio(IPAQ_EGPIO_OPT_NVRAM_ON, 0);
41 assign_h3600_egpio(IPAQ_EGPIO_OPT_ON, 0);
42 assign_h3600_egpio(IPAQ_EGPIO_OPT_RESET, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -070043}
44
45static void
46h3600_pcmcia_socket_state(struct soc_pcmcia_socket *skt, struct pcmcia_state *state)
47{
48 unsigned long levels = GPLR;
49
50 switch (skt->nr) {
51 case 0:
52 state->detect = levels & GPIO_H3600_PCMCIA_CD0 ? 0 : 1;
53 state->ready = levels & GPIO_H3600_PCMCIA_IRQ0 ? 1 : 0;
54 state->bvd1 = 0;
55 state->bvd2 = 0;
56 state->wrprot = 0; /* Not available on H3600. */
57 state->vs_3v = 0;
58 state->vs_Xv = 0;
59 break;
60
61 case 1:
62 state->detect = levels & GPIO_H3600_PCMCIA_CD1 ? 0 : 1;
63 state->ready = levels & GPIO_H3600_PCMCIA_IRQ1 ? 1 : 0;
64 state->bvd1 = 0;
65 state->bvd2 = 0;
66 state->wrprot = 0; /* Not available on H3600. */
67 state->vs_3v = 0;
68 state->vs_Xv = 0;
69 break;
70 }
71}
72
73static int
74h3600_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, const socket_state_t *state)
75{
76 if (state->Vcc != 0 && state->Vcc != 33 && state->Vcc != 50) {
77 printk(KERN_ERR "h3600_pcmcia: unrecognized Vcc %u.%uV\n",
78 state->Vcc / 10, state->Vcc % 10);
79 return -1;
80 }
81
Dmitry Artamonow104a4162009-03-15 19:13:16 +010082 assign_h3600_egpio(IPAQ_EGPIO_CARD_RESET, !!(state->flags & SS_RESET));
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
84 /* Silently ignore Vpp, output enable, speaker enable. */
85
86 return 0;
87}
88
89static void h3600_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
90{
91 /* Enable CF bus: */
Dmitry Artamonow104a4162009-03-15 19:13:16 +010092 assign_h3600_egpio(IPAQ_EGPIO_OPT_NVRAM_ON, 1);
93 assign_h3600_egpio(IPAQ_EGPIO_OPT_ON, 1);
94 assign_h3600_egpio(IPAQ_EGPIO_OPT_RESET, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
96 msleep(10);
97
98 soc_pcmcia_enable_irqs(skt, irqs, ARRAY_SIZE(irqs));
99}
100
101static void h3600_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
102{
103 soc_pcmcia_disable_irqs(skt, irqs, ARRAY_SIZE(irqs));
104
105 /*
106 * FIXME: This doesn't fit well. We don't have the mechanism in
107 * the generic PCMCIA layer to deal with the idea of two sockets
108 * on one bus. We rely on the cs.c behaviour shutting down
109 * socket 0 then socket 1.
110 */
111 if (skt->nr == 1) {
Dmitry Artamonow104a4162009-03-15 19:13:16 +0100112 assign_h3600_egpio(IPAQ_EGPIO_OPT_ON, 0);
113 assign_h3600_egpio(IPAQ_EGPIO_OPT_NVRAM_ON, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 /* hmm, does this suck power? */
Dmitry Artamonow104a4162009-03-15 19:13:16 +0100115 assign_h3600_egpio(IPAQ_EGPIO_OPT_RESET, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 }
117}
118
119struct pcmcia_low_level h3600_pcmcia_ops = {
120 .owner = THIS_MODULE,
121 .hw_init = h3600_pcmcia_hw_init,
122 .hw_shutdown = h3600_pcmcia_hw_shutdown,
123 .socket_state = h3600_pcmcia_socket_state,
124 .configure_socket = h3600_pcmcia_configure_socket,
125
126 .socket_init = h3600_pcmcia_socket_init,
127 .socket_suspend = h3600_pcmcia_socket_suspend,
128};
129
130int __init pcmcia_h3600_init(struct device *dev)
131{
132 int ret = -ENODEV;
133
134 if (machine_is_h3600())
135 ret = sa11xx_drv_pcmcia_probe(dev, &h3600_pcmcia_ops, 0, 2);
136
137 return ret;
138}