Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #include <linux/device.h> |
| 10 | #include <linux/errno.h> |
| 11 | #include <linux/init.h> |
| 12 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 13 | #include <mach/hardware.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <asm/hardware/sa1111.h> |
| 15 | #include <asm/mach-types.h> |
| 16 | |
| 17 | #include "sa1111_generic.h" |
| 18 | |
Kristoffer Ericson | 02e87d1 | 2009-09-21 17:03:56 -0700 | [diff] [blame] | 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) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #define SOCKET1_3V GPIO_GPIO3 |
| 24 | |
| 25 | static int jornada720_pcmcia_hw_init(struct soc_pcmcia_socket *skt) |
| 26 | { |
Kristoffer Ericson | 02e87d1 | 2009-09-21 17:03:56 -0700 | [diff] [blame] | 27 | unsigned int pin = GPIO_A0 | GPIO_A1 | GPIO_A2 | GPIO_A3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | |
Kristoffer Ericson | 02e87d1 | 2009-09-21 17:03:56 -0700 | [diff] [blame] | 29 | /* |
| 30 | * What is all this crap for? |
| 31 | */ |
| 32 | GRER |= 0x00000002; |
| 33 | /* Set GPIO_A<3:1> to be outputs for PCMCIA/CF power controller: */ |
| 34 | sa1111_set_io_dir(SA1111_DEV(skt->dev), pin, 0, 0); |
| 35 | sa1111_set_io(SA1111_DEV(skt->dev), pin, 0); |
| 36 | sa1111_set_sleep_io(SA1111_DEV(skt->dev), pin, 0); |
| 37 | |
| 38 | return sa1111_pcmcia_hw_init(skt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | static int |
| 42 | jornada720_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, const socket_state_t *state) |
| 43 | { |
Kristoffer Ericson | 02e87d1 | 2009-09-21 17:03:56 -0700 | [diff] [blame] | 44 | unsigned int pa_dwr_mask, pa_dwr_set; |
| 45 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
Kristoffer Ericson | 02e87d1 | 2009-09-21 17:03:56 -0700 | [diff] [blame] | 47 | printk(KERN_INFO "%s(): config socket %d vcc %d vpp %d\n", __func__, |
| 48 | skt->nr, state->Vcc, state->Vpp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
Kristoffer Ericson | 02e87d1 | 2009-09-21 17:03:56 -0700 | [diff] [blame] | 50 | switch (skt->nr) { |
| 51 | case 0: |
| 52 | pa_dwr_mask = SOCKET0_POWER | SOCKET0_3V; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
Kristoffer Ericson | 02e87d1 | 2009-09-21 17:03:56 -0700 | [diff] [blame] | 54 | switch (state->Vcc) { |
| 55 | default: |
| 56 | case 0: |
| 57 | pa_dwr_set = 0; |
| 58 | break; |
| 59 | case 33: |
| 60 | pa_dwr_set = SOCKET0_POWER | SOCKET0_3V; |
| 61 | break; |
| 62 | case 50: |
| 63 | pa_dwr_set = SOCKET0_POWER; |
| 64 | break; |
| 65 | } |
| 66 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
Kristoffer Ericson | 02e87d1 | 2009-09-21 17:03:56 -0700 | [diff] [blame] | 68 | case 1: |
| 69 | pa_dwr_mask = SOCKET1_POWER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | |
Kristoffer Ericson | 02e87d1 | 2009-09-21 17:03:56 -0700 | [diff] [blame] | 71 | switch (state->Vcc) { |
| 72 | default: |
| 73 | case 0: |
| 74 | pa_dwr_set = 0; |
| 75 | break; |
| 76 | case 33: |
| 77 | pa_dwr_set = SOCKET1_POWER; |
| 78 | break; |
| 79 | case 50: |
| 80 | pa_dwr_set = SOCKET1_POWER; |
| 81 | break; |
| 82 | } |
| 83 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | |
Kristoffer Ericson | 02e87d1 | 2009-09-21 17:03:56 -0700 | [diff] [blame] | 85 | default: |
| 86 | return -1; |
| 87 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
Kristoffer Ericson | 02e87d1 | 2009-09-21 17:03:56 -0700 | [diff] [blame] | 89 | if (state->Vpp != state->Vcc && state->Vpp != 0) { |
| 90 | printk(KERN_ERR "%s(): slot cannot support VPP %u\n", |
| 91 | __func__, state->Vpp); |
| 92 | return -EPERM; |
| 93 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | |
Kristoffer Ericson | 02e87d1 | 2009-09-21 17:03:56 -0700 | [diff] [blame] | 95 | ret = sa1111_pcmcia_configure_socket(skt, state); |
| 96 | if (ret == 0) { |
| 97 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | |
Kristoffer Ericson | 02e87d1 | 2009-09-21 17:03:56 -0700 | [diff] [blame] | 99 | local_irq_save(flags); |
| 100 | sa1111_set_io(SA1111_DEV(skt->dev), pa_dwr_mask, pa_dwr_set); |
| 101 | local_irq_restore(flags); |
| 102 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | |
Kristoffer Ericson | 02e87d1 | 2009-09-21 17:03:56 -0700 | [diff] [blame] | 104 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | static struct pcmcia_low_level jornada720_pcmcia_ops = { |
Kristoffer Ericson | 02e87d1 | 2009-09-21 17:03:56 -0700 | [diff] [blame] | 108 | .owner = THIS_MODULE, |
| 109 | .hw_init = jornada720_pcmcia_hw_init, |
| 110 | .hw_shutdown = sa1111_pcmcia_hw_shutdown, |
| 111 | .socket_state = sa1111_pcmcia_socket_state, |
| 112 | .configure_socket = jornada720_pcmcia_configure_socket, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | |
Kristoffer Ericson | 02e87d1 | 2009-09-21 17:03:56 -0700 | [diff] [blame] | 114 | .socket_init = sa1111_pcmcia_socket_init, |
| 115 | .socket_suspend = sa1111_pcmcia_socket_suspend, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | }; |
| 117 | |
Kristoffer Ericson | 85e6c7a | 2008-02-03 22:08:10 +0100 | [diff] [blame] | 118 | int __devinit pcmcia_jornada720_init(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | { |
| 120 | int ret = -ENODEV; |
| 121 | |
| 122 | if (machine_is_jornada720()) |
| 123 | ret = sa11xx_drv_pcmcia_probe(dev, &jornada720_pcmcia_ops, 0, 2); |
| 124 | |
| 125 | return ret; |
| 126 | } |