blob: 92016fe932b46bfd720b6ecfc56fca26a6add563 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/drivers/pcmcia/pxa2xx_mainstone.c
3 *
4 * Mainstone PCMCIA specific routines.
5 *
6 * Created: May 12, 2004
7 * Author: Nicolas Pitre
8 * Copyright: MontaVista Software Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 */
14
15#include <linux/module.h>
16#include <linux/init.h>
17#include <linux/kernel.h>
18#include <linux/errno.h>
19#include <linux/interrupt.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010020#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
22#include <pcmcia/ss.h>
23
Russell King04ba0f62008-04-24 15:23:25 +010024#include <asm/mach-types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <asm/irq.h>
26
Eric Miaob74d1962009-01-20 10:31:55 +080027#include <mach/pxa2xx-regs.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010028#include <mach/mainstone.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
30#include "soc_common.h"
31
32
33static struct pcmcia_irqs irqs[] = {
34 { 0, MAINSTONE_S0_CD_IRQ, "PCMCIA0 CD" },
35 { 1, MAINSTONE_S1_CD_IRQ, "PCMCIA1 CD" },
36 { 0, MAINSTONE_S0_STSCHG_IRQ, "PCMCIA0 STSCHG" },
37 { 1, MAINSTONE_S1_STSCHG_IRQ, "PCMCIA1 STSCHG" },
38};
39
40static int mst_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
41{
42 /*
43 * Setup default state of GPIO outputs
44 * before we enable them as outputs.
45 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
Russell King - ARM Linux66024db2009-03-29 22:45:26 +010047 skt->socket.pci_irq = (skt->nr == 0) ? MAINSTONE_S0_IRQ : MAINSTONE_S1_IRQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 return soc_pcmcia_request_irqs(skt, irqs, ARRAY_SIZE(irqs));
49}
50
51static void mst_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
52{
53 soc_pcmcia_free_irqs(skt, irqs, ARRAY_SIZE(irqs));
54}
55
56static unsigned long mst_pcmcia_status[2];
57
58static void mst_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
59 struct pcmcia_state *state)
60{
61 unsigned long status, flip;
62
63 status = (skt->nr == 0) ? MST_PCMCIA0 : MST_PCMCIA1;
64 flip = (status ^ mst_pcmcia_status[skt->nr]) & MST_PCMCIA_nSTSCHG_BVD1;
65
66 /*
67 * Workaround for STSCHG which can't be deasserted:
68 * We therefore disable/enable corresponding IRQs
69 * as needed to avoid IRQ locks.
70 */
71 if (flip) {
72 mst_pcmcia_status[skt->nr] = status;
73 if (status & MST_PCMCIA_nSTSCHG_BVD1)
74 enable_irq( (skt->nr == 0) ? MAINSTONE_S0_STSCHG_IRQ
75 : MAINSTONE_S1_STSCHG_IRQ );
76 else
77 disable_irq( (skt->nr == 0) ? MAINSTONE_S0_STSCHG_IRQ
78 : MAINSTONE_S1_STSCHG_IRQ );
79 }
80
81 state->detect = (status & MST_PCMCIA_nCD) ? 0 : 1;
82 state->ready = (status & MST_PCMCIA_nIRQ) ? 1 : 0;
83 state->bvd1 = (status & MST_PCMCIA_nSTSCHG_BVD1) ? 1 : 0;
84 state->bvd2 = (status & MST_PCMCIA_nSPKR_BVD2) ? 1 : 0;
85 state->vs_3v = (status & MST_PCMCIA_nVS1) ? 0 : 1;
86 state->vs_Xv = (status & MST_PCMCIA_nVS2) ? 0 : 1;
87 state->wrprot = 0; /* not available */
88}
89
90static int mst_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
91 const socket_state_t *state)
92{
93 unsigned long power = 0;
94 int ret = 0;
95
96 switch (state->Vcc) {
97 case 0: power |= MST_PCMCIA_PWR_VCC_0; break;
98 case 33: power |= MST_PCMCIA_PWR_VCC_33; break;
99 case 50: power |= MST_PCMCIA_PWR_VCC_50; break;
100 default:
101 printk(KERN_ERR "%s(): bad Vcc %u\n",
Harvey Harrison2e11cb42008-05-01 04:34:54 -0700102 __func__, state->Vcc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 ret = -1;
104 }
105
106 switch (state->Vpp) {
107 case 0: power |= MST_PCMCIA_PWR_VPP_0; break;
108 case 120: power |= MST_PCMCIA_PWR_VPP_120; break;
109 default:
110 if(state->Vpp == state->Vcc) {
111 power |= MST_PCMCIA_PWR_VPP_VCC;
112 } else {
113 printk(KERN_ERR "%s(): bad Vpp %u\n",
Harvey Harrison2e11cb42008-05-01 04:34:54 -0700114 __func__, state->Vpp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 ret = -1;
116 }
117 }
118
119 if (state->flags & SS_RESET)
120 power |= MST_PCMCIA_RESET;
121
122 switch (skt->nr) {
123 case 0: MST_PCMCIA0 = power; break;
124 case 1: MST_PCMCIA1 = power; break;
125 default: ret = -1;
126 }
127
128 return ret;
129}
130
131static void mst_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
132{
133}
134
135static void mst_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
136{
137}
138
Russell King4e5e8de2008-04-24 15:28:11 +0100139static struct pcmcia_low_level mst_pcmcia_ops __initdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 .owner = THIS_MODULE,
141 .hw_init = mst_pcmcia_hw_init,
142 .hw_shutdown = mst_pcmcia_hw_shutdown,
143 .socket_state = mst_pcmcia_socket_state,
144 .configure_socket = mst_pcmcia_configure_socket,
145 .socket_init = mst_pcmcia_socket_init,
146 .socket_suspend = mst_pcmcia_socket_suspend,
147 .nr = 2,
148};
149
150static struct platform_device *mst_pcmcia_device;
151
152static int __init mst_pcmcia_init(void)
153{
154 int ret;
155
Russell King04ba0f62008-04-24 15:23:25 +0100156 if (!machine_is_mainstone())
157 return -ENODEV;
158
Richard Purdieb0164502006-01-10 17:16:12 +0000159 mst_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 if (!mst_pcmcia_device)
161 return -ENOMEM;
Richard Purdieb0164502006-01-10 17:16:12 +0000162
Russell King4e5e8de2008-04-24 15:28:11 +0100163 ret = platform_device_add_data(mst_pcmcia_device, &mst_pcmcia_ops,
164 sizeof(mst_pcmcia_ops));
165 if (ret == 0)
166 ret = platform_device_add(mst_pcmcia_device);
Richard Purdieb0164502006-01-10 17:16:12 +0000167
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 if (ret)
Richard Purdieb0164502006-01-10 17:16:12 +0000169 platform_device_put(mst_pcmcia_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170
171 return ret;
172}
173
174static void __exit mst_pcmcia_exit(void)
175{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 platform_device_unregister(mst_pcmcia_device);
177}
178
Richard Purdief36598a2005-09-03 19:39:25 +0100179fs_initcall(mst_pcmcia_init);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180module_exit(mst_pcmcia_exit);
181
182MODULE_LICENSE("GPL");
Kay Sievers43cc71e2007-08-18 04:40:39 +0200183MODULE_ALIAS("platform:pxa2xx-pcmcia");