blob: 6bcabee6bde468f7dbd82b4f015d0063ea26d526 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * drivers/pcmcia/sa1100_jornada720.c
3 *
4 * Jornada720 PCMCIA specific routines
5 *
6 */
7#include <linux/module.h>
8#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include <linux/device.h>
10#include <linux/errno.h>
11#include <linux/init.h>
12
Russell Kinga09e64f2008-08-05 16:14:15 +010013#include <mach/hardware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <asm/hardware/sa1111.h>
15#include <asm/mach-types.h>
16
17#include "sa1111_generic.h"
18
Kristoffer Ericson02e87d12009-09-21 17:03:56 -070019/* 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)
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#define SOCKET1_3V GPIO_GPIO3
24
Linus Torvalds1da177e2005-04-16 15:20:36 -070025static int
26jornada720_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, const socket_state_t *state)
27{
Russell King - ARM Linux701a5dc2009-03-29 19:42:44 +010028 struct sa1111_pcmcia_socket *s = to_skt(skt);
Kristoffer Ericson02e87d12009-09-21 17:03:56 -070029 unsigned int pa_dwr_mask, pa_dwr_set;
30 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
Kristoffer Ericson02e87d12009-09-21 17:03:56 -070032 printk(KERN_INFO "%s(): config socket %d vcc %d vpp %d\n", __func__,
33 skt->nr, state->Vcc, state->Vpp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Kristoffer Ericson02e87d12009-09-21 17:03:56 -070035 switch (skt->nr) {
36 case 0:
37 pa_dwr_mask = SOCKET0_POWER | SOCKET0_3V;
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Kristoffer Ericson02e87d12009-09-21 17:03:56 -070039 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Kristoffer Ericson02e87d12009-09-21 17:03:56 -070053 case 1:
54 pa_dwr_mask = SOCKET1_POWER;
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
Kristoffer Ericson02e87d12009-09-21 17:03:56 -070056 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
Kristoffer Ericson02e87d12009-09-21 17:03:56 -070070 default:
71 return -1;
72 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
Kristoffer Ericson02e87d12009-09-21 17:03:56 -070074 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 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
Kristoffer Ericson02e87d12009-09-21 17:03:56 -070080 ret = sa1111_pcmcia_configure_socket(skt, state);
81 if (ret == 0) {
82 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
Kristoffer Ericson02e87d12009-09-21 17:03:56 -070084 local_irq_save(flags);
Russell King - ARM Linux701a5dc2009-03-29 19:42:44 +010085 sa1111_set_io(s->dev, pa_dwr_mask, pa_dwr_set);
Kristoffer Ericson02e87d12009-09-21 17:03:56 -070086 local_irq_restore(flags);
87 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
Kristoffer Ericson02e87d12009-09-21 17:03:56 -070089 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070090}
91
92static struct pcmcia_low_level jornada720_pcmcia_ops = {
Kristoffer Ericson02e87d12009-09-21 17:03:56 -070093 .owner = THIS_MODULE,
Kristoffer Ericson02e87d12009-09-21 17:03:56 -070094 .configure_socket = jornada720_pcmcia_configure_socket,
Kristoffer Ericson02e87d12009-09-21 17:03:56 -070095 .socket_init = sa1111_pcmcia_socket_init,
Russell King - ARM Linux701a5dc2009-03-29 19:42:44 +010096 .first = 0,
97 .nr = 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -070098};
99
Kristoffer Ericson85e6c7a2008-02-03 22:08:10 +0100100int __devinit pcmcia_jornada720_init(struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101{
102 int ret = -ENODEV;
103
Russell King - ARM Linux701a5dc2009-03-29 19:42:44 +0100104 if (machine_is_jornada720()) {
Russell King - ARM Linuxdabd1462009-03-29 22:35:11 +0100105 unsigned int pin = GPIO_A0 | GPIO_A1 | GPIO_A2 | GPIO_A3;
106
107 GRER |= 0x00000002;
108
109 /* Set GPIO_A<3:1> to be outputs for PCMCIA/CF power controller: */
110 sa1111_set_io_dir(dev, pin, 0, 0);
111 sa1111_set_io(dev, pin, 0);
112 sa1111_set_sleep_io(dev, pin, 0);
113
Russell King - ARM Linux701a5dc2009-03-29 19:42:44 +0100114 sa11xx_drv_pcmcia_ops(&jornada720_pcmcia_ops);
115 ret = sa1111_pcmcia_add(dev, &jornada720_pcmcia_ops,
116 sa11xx_drv_pcmcia_add_one);
117 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
119 return ret;
120}