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