blob: 7e32e25cdcb29d20965d2e7843bf0a8d3b8bf8a2 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070033static int mst_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
34{
35 /*
36 * Setup default state of GPIO outputs
37 * before we enable them as outputs.
38 */
Russell Kinga9bb5a42012-01-13 22:56:32 +000039 if (skt->nr == 0) {
40 skt->socket.pci_irq = MAINSTONE_S0_IRQ;
41 skt->stat[SOC_STAT_CD].irq = MAINSTONE_S0_CD_IRQ;
42 skt->stat[SOC_STAT_CD].name = "PCMCIA0 CD";
43 skt->stat[SOC_STAT_BVD1].irq = MAINSTONE_S0_STSCHG_IRQ;
44 skt->stat[SOC_STAT_BVD1].name = "PCMCIA0 STSCHG";
45 } else {
46 skt->socket.pci_irq = MAINSTONE_S1_IRQ;
47 skt->stat[SOC_STAT_CD].irq = MAINSTONE_S1_CD_IRQ;
48 skt->stat[SOC_STAT_CD].name = "PCMCIA1 CD";
49 skt->stat[SOC_STAT_BVD1].irq = MAINSTONE_S1_STSCHG_IRQ;
50 skt->stat[SOC_STAT_BVD1].name = "PCMCIA1 STSCHG";
51 }
52 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053}
54
55static unsigned long mst_pcmcia_status[2];
56
57static void mst_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
58 struct pcmcia_state *state)
59{
60 unsigned long status, flip;
61
62 status = (skt->nr == 0) ? MST_PCMCIA0 : MST_PCMCIA1;
63 flip = (status ^ mst_pcmcia_status[skt->nr]) & MST_PCMCIA_nSTSCHG_BVD1;
64
65 /*
66 * Workaround for STSCHG which can't be deasserted:
67 * We therefore disable/enable corresponding IRQs
68 * as needed to avoid IRQ locks.
69 */
70 if (flip) {
71 mst_pcmcia_status[skt->nr] = status;
72 if (status & MST_PCMCIA_nSTSCHG_BVD1)
73 enable_irq( (skt->nr == 0) ? MAINSTONE_S0_STSCHG_IRQ
74 : MAINSTONE_S1_STSCHG_IRQ );
75 else
76 disable_irq( (skt->nr == 0) ? MAINSTONE_S0_STSCHG_IRQ
77 : MAINSTONE_S1_STSCHG_IRQ );
78 }
79
80 state->detect = (status & MST_PCMCIA_nCD) ? 0 : 1;
81 state->ready = (status & MST_PCMCIA_nIRQ) ? 1 : 0;
82 state->bvd1 = (status & MST_PCMCIA_nSTSCHG_BVD1) ? 1 : 0;
83 state->bvd2 = (status & MST_PCMCIA_nSPKR_BVD2) ? 1 : 0;
84 state->vs_3v = (status & MST_PCMCIA_nVS1) ? 0 : 1;
85 state->vs_Xv = (status & MST_PCMCIA_nVS2) ? 0 : 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086}
87
88static int mst_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
89 const socket_state_t *state)
90{
91 unsigned long power = 0;
92 int ret = 0;
93
94 switch (state->Vcc) {
95 case 0: power |= MST_PCMCIA_PWR_VCC_0; break;
96 case 33: power |= MST_PCMCIA_PWR_VCC_33; break;
97 case 50: power |= MST_PCMCIA_PWR_VCC_50; break;
98 default:
99 printk(KERN_ERR "%s(): bad Vcc %u\n",
Harvey Harrison2e11cb42008-05-01 04:34:54 -0700100 __func__, state->Vcc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 ret = -1;
102 }
103
104 switch (state->Vpp) {
105 case 0: power |= MST_PCMCIA_PWR_VPP_0; break;
106 case 120: power |= MST_PCMCIA_PWR_VPP_120; break;
107 default:
108 if(state->Vpp == state->Vcc) {
109 power |= MST_PCMCIA_PWR_VPP_VCC;
110 } else {
111 printk(KERN_ERR "%s(): bad Vpp %u\n",
Harvey Harrison2e11cb42008-05-01 04:34:54 -0700112 __func__, state->Vpp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 ret = -1;
114 }
115 }
116
117 if (state->flags & SS_RESET)
118 power |= MST_PCMCIA_RESET;
119
120 switch (skt->nr) {
121 case 0: MST_PCMCIA0 = power; break;
122 case 1: MST_PCMCIA1 = power; break;
123 default: ret = -1;
124 }
125
126 return ret;
127}
128
Russell King4e5e8de2008-04-24 15:28:11 +0100129static struct pcmcia_low_level mst_pcmcia_ops __initdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 .owner = THIS_MODULE,
131 .hw_init = mst_pcmcia_hw_init,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 .socket_state = mst_pcmcia_socket_state,
133 .configure_socket = mst_pcmcia_configure_socket,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 .nr = 2,
135};
136
137static struct platform_device *mst_pcmcia_device;
138
139static int __init mst_pcmcia_init(void)
140{
141 int ret;
142
Russell King04ba0f62008-04-24 15:23:25 +0100143 if (!machine_is_mainstone())
144 return -ENODEV;
145
Richard Purdieb0164502006-01-10 17:16:12 +0000146 mst_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 if (!mst_pcmcia_device)
148 return -ENOMEM;
Richard Purdieb0164502006-01-10 17:16:12 +0000149
Russell King4e5e8de2008-04-24 15:28:11 +0100150 ret = platform_device_add_data(mst_pcmcia_device, &mst_pcmcia_ops,
151 sizeof(mst_pcmcia_ops));
152 if (ret == 0)
153 ret = platform_device_add(mst_pcmcia_device);
Richard Purdieb0164502006-01-10 17:16:12 +0000154
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 if (ret)
Richard Purdieb0164502006-01-10 17:16:12 +0000156 platform_device_put(mst_pcmcia_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
158 return ret;
159}
160
161static void __exit mst_pcmcia_exit(void)
162{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 platform_device_unregister(mst_pcmcia_device);
164}
165
Richard Purdief36598ae2005-09-03 19:39:25 +0100166fs_initcall(mst_pcmcia_init);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167module_exit(mst_pcmcia_exit);
168
169MODULE_LICENSE("GPL");
Kay Sievers43cc71e2007-08-18 04:40:39 +0200170MODULE_ALIAS("platform:pxa2xx-pcmcia");