1 /*
2  * drivers/pcmcia/sa1100_jornada720.c
3  *
4  * Jornada720 PCMCIA specific routines
5  *
6  */
7 #include <linux/module.h>
8 #include <linux/kernel.h>
9 #include <linux/device.h>
10 #include <linux/errno.h>
11 #include <linux/init.h>
12 #include <linux/io.h>
13 
14 #include <mach/hardware.h>
15 #include <asm/hardware/sa1111.h>
16 #include <asm/mach-types.h>
17 
18 #include "sa1111_generic.h"
19 
20 /* Does SOCKET1_3V actually do anything? */
21 #define SOCKET0_POWER	GPIO_GPIO0
22 #define SOCKET0_3V	GPIO_GPIO2
23 #define SOCKET1_POWER	(GPIO_GPIO1 | GPIO_GPIO3)
24 #define SOCKET1_3V	GPIO_GPIO3
25 
26 static int
27 jornada720_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, const socket_state_t *state)
28 {
29 	struct sa1111_pcmcia_socket *s = to_skt(skt);
30 	unsigned int pa_dwr_mask, pa_dwr_set;
31 	int ret;
32 
33 	printk(KERN_INFO "%s(): config socket %d vcc %d vpp %d\n", __func__,
34 		skt->nr, state->Vcc, state->Vpp);
35 
36 	switch (skt->nr) {
37 	case 0:
38 		pa_dwr_mask = SOCKET0_POWER | SOCKET0_3V;
39 
40 		switch (state->Vcc) {
41 		default:
42 		case  0:
43 			pa_dwr_set = 0;
44 			break;
45 		case 33:
46 			pa_dwr_set = SOCKET0_POWER | SOCKET0_3V;
47 			break;
48 		case 50:
49 			pa_dwr_set = SOCKET0_POWER;
50 			break;
51 		}
52 		break;
53 
54 	case 1:
55 		pa_dwr_mask = SOCKET1_POWER;
56 
57 		switch (state->Vcc) {
58 		default:
59 		case 0:
60 			pa_dwr_set = 0;
61 			break;
62 		case 33:
63 			pa_dwr_set = SOCKET1_POWER;
64 			break;
65 		case 50:
66 			pa_dwr_set = SOCKET1_POWER;
67 			break;
68 		}
69 		break;
70 
71 	default:
72 		return -1;
73 	}
74 
75 	if (state->Vpp != state->Vcc && state->Vpp != 0) {
76 		printk(KERN_ERR "%s(): slot cannot support VPP %u\n",
77 			__func__, state->Vpp);
78 		return -EPERM;
79 	}
80 
81 	ret = sa1111_pcmcia_configure_socket(skt, state);
82 	if (ret == 0)
83 		sa1111_set_io(s->dev, pa_dwr_mask, pa_dwr_set);
84 
85 	return ret;
86 }
87 
88 static struct pcmcia_low_level jornada720_pcmcia_ops = {
89 	.owner			= THIS_MODULE,
90 	.configure_socket	= jornada720_pcmcia_configure_socket,
91 	.first			= 0,
92 	.nr			= 2,
93 };
94 
95 int pcmcia_jornada720_init(struct sa1111_dev *sadev)
96 {
97 	int ret = -ENODEV;
98 
99 	if (machine_is_jornada720()) {
100 		unsigned int pin = GPIO_A0 | GPIO_A1 | GPIO_A2 | GPIO_A3;
101 
102 		GRER |= 0x00000002;
103 
104 		/* Set GPIO_A<3:1> to be outputs for PCMCIA/CF power controller: */
105 		sa1111_set_io_dir(sadev, pin, 0, 0);
106 		sa1111_set_io(sadev, pin, 0);
107 		sa1111_set_sleep_io(sadev, pin, 0);
108 
109 		sa11xx_drv_pcmcia_ops(&jornada720_pcmcia_ops);
110 		ret = sa1111_pcmcia_add(sadev, &jornada720_pcmcia_ops,
111 				sa11xx_drv_pcmcia_add_one);
112 	}
113 
114 	return ret;
115 }
116