Blame view

drivers/pcmcia/pxa2xx_mainstone.c 4.26 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
  /*
   * linux/drivers/pcmcia/pxa2xx_mainstone.c
   *
   * Mainstone PCMCIA specific routines.
   *
   * Created:	May 12, 2004
   * Author:	Nicolas Pitre
   * Copyright:	MontaVista Software Inc.
   *
   * This program is free software; you can redistribute it and/or modify
   * it under the terms of the GNU General Public License version 2 as
   * published by the Free Software Foundation.
   */
  
  #include <linux/module.h>
  #include <linux/init.h>
  #include <linux/kernel.h>
  #include <linux/errno.h>
  #include <linux/interrupt.h>
d052d1bef   Russell King   Create platform_d...
20
  #include <linux/platform_device.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
21
22
  
  #include <pcmcia/ss.h>
04ba0f656   Russell King   [ARM] pxa: avoid ...
23
  #include <asm/mach-types.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
24
  #include <asm/irq.h>
b74d19690   Eric Miao   [ARM] pxa: move p...
25
  #include <mach/pxa2xx-regs.h>
a09e64fbc   Russell King   [ARM] Move includ...
26
  #include <mach/mainstone.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
27
28
  
  #include "soc_common.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
29
30
31
32
33
34
  static int mst_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
  {
  	/*
  	 * Setup default state of GPIO outputs
  	 * before we enable them as outputs.
  	 */
a9bb5a4bf   Russell King   PCMCIA: pxa: conv...
35
36
37
38
39
40
41
42
43
44
45
46
47
48
  	if (skt->nr == 0) {
  		skt->socket.pci_irq = MAINSTONE_S0_IRQ;
  		skt->stat[SOC_STAT_CD].irq = MAINSTONE_S0_CD_IRQ;
  		skt->stat[SOC_STAT_CD].name = "PCMCIA0 CD";
  		skt->stat[SOC_STAT_BVD1].irq = MAINSTONE_S0_STSCHG_IRQ;
  		skt->stat[SOC_STAT_BVD1].name = "PCMCIA0 STSCHG";
  	} else {
  		skt->socket.pci_irq = MAINSTONE_S1_IRQ;
  		skt->stat[SOC_STAT_CD].irq = MAINSTONE_S1_CD_IRQ;
  		skt->stat[SOC_STAT_CD].name = "PCMCIA1 CD";
  		skt->stat[SOC_STAT_BVD1].irq = MAINSTONE_S1_STSCHG_IRQ;
  		skt->stat[SOC_STAT_BVD1].name = "PCMCIA1 STSCHG";
  	}
  	return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
  }
  
  static unsigned long mst_pcmcia_status[2];
  
  static void mst_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
  				    struct pcmcia_state *state)
  {
  	unsigned long status, flip;
  
  	status = (skt->nr == 0) ? MST_PCMCIA0 : MST_PCMCIA1;
  	flip = (status ^ mst_pcmcia_status[skt->nr]) & MST_PCMCIA_nSTSCHG_BVD1;
  
  	/*
  	 * Workaround for STSCHG which can't be deasserted:
  	 * We therefore disable/enable corresponding IRQs
  	 * as needed to avoid IRQ locks.
  	 */
  	if (flip) {
  		mst_pcmcia_status[skt->nr] = status;
  		if (status & MST_PCMCIA_nSTSCHG_BVD1)
  			enable_irq( (skt->nr == 0) ? MAINSTONE_S0_STSCHG_IRQ
  						   : MAINSTONE_S1_STSCHG_IRQ );
  		else
  			disable_irq( (skt->nr == 0) ? MAINSTONE_S0_STSCHG_IRQ
  						    : MAINSTONE_S1_STSCHG_IRQ );
  	}
  
  	state->detect = (status & MST_PCMCIA_nCD) ? 0 : 1;
  	state->ready  = (status & MST_PCMCIA_nIRQ) ? 1 : 0;
  	state->bvd1   = (status & MST_PCMCIA_nSTSCHG_BVD1) ? 1 : 0;
  	state->bvd2   = (status & MST_PCMCIA_nSPKR_BVD2) ? 1 : 0;
  	state->vs_3v  = (status & MST_PCMCIA_nVS1) ? 0 : 1;
  	state->vs_Xv  = (status & MST_PCMCIA_nVS2) ? 0 : 1;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
  }
  
  static int mst_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
  				       const socket_state_t *state)
  {
  	unsigned long power = 0;
  	int ret = 0;
  
  	switch (state->Vcc) {
  	case 0:  power |= MST_PCMCIA_PWR_VCC_0;  break;
  	case 33: power |= MST_PCMCIA_PWR_VCC_33; break;
  	case 50: power |= MST_PCMCIA_PWR_VCC_50; break;
  	default:
  		 printk(KERN_ERR "%s(): bad Vcc %u
  ",
2e11cb4c5   Harvey Harrison   pcmcia: replace r...
97
  				 __func__, state->Vcc);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
98
99
100
101
102
103
104
105
106
107
108
109
  		 ret = -1;
  	}
  
  	switch (state->Vpp) {
  	case 0:   power |= MST_PCMCIA_PWR_VPP_0;   break;
  	case 120: power |= MST_PCMCIA_PWR_VPP_120; break;
  	default:
  		  if(state->Vpp == state->Vcc) {
  			  power |= MST_PCMCIA_PWR_VPP_VCC;
  		  } else {
  			  printk(KERN_ERR "%s(): bad Vpp %u
  ",
2e11cb4c5   Harvey Harrison   pcmcia: replace r...
110
  					  __func__, state->Vpp);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
  			  ret = -1;
  		  }
  	}
  
  	if (state->flags & SS_RESET)
  	       power |= MST_PCMCIA_RESET;
  
  	switch (skt->nr) {
  	case 0:  MST_PCMCIA0 = power; break;
  	case 1:  MST_PCMCIA1 = power; break;
  	default: ret = -1;
  	}
  
  	return ret;
  }
4e5e8de0d   Russell King   [ARM] pxa: avoid ...
126
  static struct pcmcia_low_level mst_pcmcia_ops __initdata = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
127
128
  	.owner			= THIS_MODULE,
  	.hw_init		= mst_pcmcia_hw_init,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
129
130
  	.socket_state		= mst_pcmcia_socket_state,
  	.configure_socket	= mst_pcmcia_configure_socket,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
131
132
133
134
135
136
137
138
  	.nr			= 2,
  };
  
  static struct platform_device *mst_pcmcia_device;
  
  static int __init mst_pcmcia_init(void)
  {
  	int ret;
04ba0f656   Russell King   [ARM] pxa: avoid ...
139
140
  	if (!machine_is_mainstone())
  		return -ENODEV;
b016450f9   Richard Purdie   [ARM] 3250/1: Cha...
141
  	mst_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
142
143
  	if (!mst_pcmcia_device)
  		return -ENOMEM;
b016450f9   Richard Purdie   [ARM] 3250/1: Cha...
144

4e5e8de0d   Russell King   [ARM] pxa: avoid ...
145
146
147
148
  	ret = platform_device_add_data(mst_pcmcia_device, &mst_pcmcia_ops,
  				       sizeof(mst_pcmcia_ops));
  	if (ret == 0)
  		ret = platform_device_add(mst_pcmcia_device);
b016450f9   Richard Purdie   [ARM] 3250/1: Cha...
149

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
150
  	if (ret)
b016450f9   Richard Purdie   [ARM] 3250/1: Cha...
151
  		platform_device_put(mst_pcmcia_device);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
152
153
154
155
156
157
  
  	return ret;
  }
  
  static void __exit mst_pcmcia_exit(void)
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
158
159
  	platform_device_unregister(mst_pcmcia_device);
  }
f36598aec   Richard Purdie   [ARM] 2873/1: PCM...
160
  fs_initcall(mst_pcmcia_init);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
161
162
163
  module_exit(mst_pcmcia_exit);
  
  MODULE_LICENSE("GPL");
43cc71eed   Kay Sievers   platform: prefix ...
164
  MODULE_ALIAS("platform:pxa2xx-pcmcia");