blob: 40e040314503c64377b1978628adfeda7103205b [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>
Arnd Bergmann58409f92014-06-05 23:05:47 +020012#include <linux/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
Russell Kinga09e64f2008-08-05 16:14:15 +010014#include <mach/hardware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <asm/hardware/sa1111.h>
16#include <asm/mach-types.h>
17
18#include "sa1111_generic.h"
19
Kristoffer Ericson02e87d12009-09-21 17:03:56 -070020/* 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)
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#define SOCKET1_3V GPIO_GPIO3
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026static int
27jornada720_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, const socket_state_t *state)
28{
Russell King - ARM Linux701a5dc2009-03-29 19:42:44 +010029 struct sa1111_pcmcia_socket *s = to_skt(skt);
Kristoffer Ericson02e87d12009-09-21 17:03:56 -070030 unsigned int pa_dwr_mask, pa_dwr_set;
31 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Kristoffer Ericson02e87d12009-09-21 17:03:56 -070033 printk(KERN_INFO "%s(): config socket %d vcc %d vpp %d\n", __func__,
34 skt->nr, state->Vcc, state->Vpp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
Kristoffer Ericson02e87d12009-09-21 17:03:56 -070036 switch (skt->nr) {
37 case 0:
38 pa_dwr_mask = SOCKET0_POWER | SOCKET0_3V;
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Kristoffer Ericson02e87d12009-09-21 17:03:56 -070040 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Kristoffer Ericson02e87d12009-09-21 17:03:56 -070054 case 1:
55 pa_dwr_mask = SOCKET1_POWER;
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Kristoffer Ericson02e87d12009-09-21 17:03:56 -070057 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Kristoffer Ericson02e87d12009-09-21 17:03:56 -070071 default:
72 return -1;
73 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
Kristoffer Ericson02e87d12009-09-21 17:03:56 -070075 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 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
Kristoffer Ericson02e87d12009-09-21 17:03:56 -070081 ret = sa1111_pcmcia_configure_socket(skt, state);
Russell Kinge2adbecfc2012-01-16 09:28:49 +000082 if (ret == 0)
Russell King - ARM Linux701a5dc2009-03-29 19:42:44 +010083 sa1111_set_io(s->dev, pa_dwr_mask, pa_dwr_set);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
Kristoffer Ericson02e87d12009-09-21 17:03:56 -070085 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086}
87
88static struct pcmcia_low_level jornada720_pcmcia_ops = {
Kristoffer Ericson02e87d12009-09-21 17:03:56 -070089 .owner = THIS_MODULE,
Kristoffer Ericson02e87d12009-09-21 17:03:56 -070090 .configure_socket = jornada720_pcmcia_configure_socket,
Russell King - ARM Linux701a5dc2009-03-29 19:42:44 +010091 .first = 0,
92 .nr = 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -070093};
94
Bill Pemberton34cdf252012-11-19 13:23:12 -050095int pcmcia_jornada720_init(struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070096{
97 int ret = -ENODEV;
Arnd Bergmann58409f92014-06-05 23:05:47 +020098 struct sa1111_dev *sadev = SA1111_DEV(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
Russell King - ARM Linux701a5dc2009-03-29 19:42:44 +0100100 if (machine_is_jornada720()) {
Russell King - ARM Linuxdabd1462009-03-29 22:35:11 +0100101 unsigned int pin = GPIO_A0 | GPIO_A1 | GPIO_A2 | GPIO_A3;
102
103 GRER |= 0x00000002;
104
105 /* Set GPIO_A<3:1> to be outputs for PCMCIA/CF power controller: */
Arnd Bergmann58409f92014-06-05 23:05:47 +0200106 sa1111_set_io_dir(sadev, pin, 0, 0);
107 sa1111_set_io(sadev, pin, 0);
108 sa1111_set_sleep_io(sadev, pin, 0);
Russell King - ARM Linuxdabd1462009-03-29 22:35:11 +0100109
Russell King - ARM Linux701a5dc2009-03-29 19:42:44 +0100110 sa11xx_drv_pcmcia_ops(&jornada720_pcmcia_ops);
Arnd Bergmann58409f92014-06-05 23:05:47 +0200111 ret = sa1111_pcmcia_add(sadev, &jornada720_pcmcia_ops,
Russell King - ARM Linux701a5dc2009-03-29 19:42:44 +0100112 sa11xx_drv_pcmcia_add_one);
113 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
115 return ret;
116}