Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * drivers/pcmcia/sa1100_h3600.c |
| 3 | * |
| 4 | * PCMCIA implementation routines for H3600 |
| 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/interrupt.h> |
| 11 | #include <linux/init.h> |
| 12 | #include <linux/delay.h> |
Dmitry Artamonow | 2a83709 | 2009-12-06 17:12:49 +0100 | [diff] [blame] | 13 | #include <linux/gpio.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 15 | #include <mach/hardware.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <asm/irq.h> |
| 17 | #include <asm/mach-types.h> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 18 | #include <mach/h3600.h> |
Dmitry Artamonow | 2a83709 | 2009-12-06 17:12:49 +0100 | [diff] [blame] | 19 | #include <mach/h3600_gpio.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
| 21 | #include "sa1100_generic.h" |
| 22 | |
| 23 | static struct pcmcia_irqs irqs[] = { |
Dmitry Artamonow | 2a83709 | 2009-12-06 17:12:49 +0100 | [diff] [blame] | 24 | { .sock = 0, .str = "PCMCIA CD0" }, /* .irq will be filled later */ |
| 25 | { .sock = 1, .str = "PCMCIA CD1" } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | }; |
| 27 | |
| 28 | static int h3600_pcmcia_hw_init(struct soc_pcmcia_socket *skt) |
| 29 | { |
Dmitry Artamonow | 2a83709 | 2009-12-06 17:12:49 +0100 | [diff] [blame] | 30 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
Dmitry Artamonow | 2a83709 | 2009-12-06 17:12:49 +0100 | [diff] [blame] | 32 | switch (skt->nr) { |
| 33 | case 0: |
| 34 | err = gpio_request(H3XXX_GPIO_PCMCIA_IRQ0, "PCMCIA IRQ0"); |
| 35 | if (err) |
| 36 | goto err00; |
| 37 | err = gpio_direction_input(H3XXX_GPIO_PCMCIA_IRQ0); |
| 38 | if (err) |
| 39 | goto err01; |
| 40 | skt->socket.pci_irq = gpio_to_irq(H3XXX_GPIO_PCMCIA_IRQ0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
Dmitry Artamonow | 2a83709 | 2009-12-06 17:12:49 +0100 | [diff] [blame] | 42 | err = gpio_request(H3XXX_GPIO_PCMCIA_CD0, "PCMCIA CD0"); |
| 43 | if (err) |
| 44 | goto err01; |
| 45 | err = gpio_direction_input(H3XXX_GPIO_PCMCIA_CD0); |
| 46 | if (err) |
| 47 | goto err02; |
| 48 | irqs[0].irq = gpio_to_irq(H3XXX_GPIO_PCMCIA_CD0); |
| 49 | |
| 50 | err = soc_pcmcia_request_irqs(skt, irqs, ARRAY_SIZE(irqs)); |
| 51 | if (err) |
| 52 | goto err02; |
| 53 | break; |
| 54 | case 1: |
| 55 | err = gpio_request(H3XXX_GPIO_PCMCIA_IRQ1, "PCMCIA IRQ1"); |
| 56 | if (err) |
| 57 | goto err10; |
| 58 | err = gpio_direction_input(H3XXX_GPIO_PCMCIA_IRQ1); |
| 59 | if (err) |
| 60 | goto err11; |
| 61 | skt->socket.pci_irq = gpio_to_irq(H3XXX_GPIO_PCMCIA_IRQ1); |
| 62 | |
| 63 | err = gpio_request(H3XXX_GPIO_PCMCIA_CD1, "PCMCIA CD1"); |
| 64 | if (err) |
| 65 | goto err11; |
| 66 | err = gpio_direction_input(H3XXX_GPIO_PCMCIA_CD1); |
| 67 | if (err) |
| 68 | goto err12; |
| 69 | irqs[1].irq = gpio_to_irq(H3XXX_GPIO_PCMCIA_CD1); |
| 70 | |
| 71 | err = soc_pcmcia_request_irqs(skt, irqs, ARRAY_SIZE(irqs)); |
| 72 | if (err) |
| 73 | goto err12; |
| 74 | break; |
| 75 | } |
| 76 | return 0; |
| 77 | |
| 78 | err02: gpio_free(H3XXX_GPIO_PCMCIA_CD0); |
| 79 | err01: gpio_free(H3XXX_GPIO_PCMCIA_IRQ0); |
| 80 | err00: return err; |
| 81 | |
| 82 | err12: gpio_free(H3XXX_GPIO_PCMCIA_CD0); |
| 83 | err11: gpio_free(H3XXX_GPIO_PCMCIA_IRQ0); |
| 84 | err10: return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | static void h3600_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt) |
| 88 | { |
| 89 | soc_pcmcia_free_irqs(skt, irqs, ARRAY_SIZE(irqs)); |
| 90 | |
| 91 | /* Disable CF bus: */ |
Dmitry Artamonow | 104a416 | 2009-03-15 19:13:16 +0100 | [diff] [blame] | 92 | assign_h3600_egpio(IPAQ_EGPIO_OPT_NVRAM_ON, 0); |
| 93 | assign_h3600_egpio(IPAQ_EGPIO_OPT_ON, 0); |
| 94 | assign_h3600_egpio(IPAQ_EGPIO_OPT_RESET, 1); |
Dmitry Artamonow | 2a83709 | 2009-12-06 17:12:49 +0100 | [diff] [blame] | 95 | switch (skt->nr) { |
| 96 | case 0: |
| 97 | gpio_free(H3XXX_GPIO_PCMCIA_CD0); |
| 98 | gpio_free(H3XXX_GPIO_PCMCIA_IRQ0); |
| 99 | break; |
| 100 | case 1: |
| 101 | gpio_free(H3XXX_GPIO_PCMCIA_CD1); |
| 102 | gpio_free(H3XXX_GPIO_PCMCIA_IRQ1); |
| 103 | break; |
| 104 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | static void |
| 108 | h3600_pcmcia_socket_state(struct soc_pcmcia_socket *skt, struct pcmcia_state *state) |
| 109 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | switch (skt->nr) { |
| 111 | case 0: |
Dmitry Artamonow | 2a83709 | 2009-12-06 17:12:49 +0100 | [diff] [blame] | 112 | state->detect = !gpio_get_value(H3XXX_GPIO_PCMCIA_CD0); |
| 113 | state->ready = !!gpio_get_value(H3XXX_GPIO_PCMCIA_IRQ0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | state->bvd1 = 0; |
| 115 | state->bvd2 = 0; |
| 116 | state->wrprot = 0; /* Not available on H3600. */ |
| 117 | state->vs_3v = 0; |
| 118 | state->vs_Xv = 0; |
| 119 | break; |
| 120 | |
| 121 | case 1: |
Dmitry Artamonow | 2a83709 | 2009-12-06 17:12:49 +0100 | [diff] [blame] | 122 | state->detect = !gpio_get_value(H3XXX_GPIO_PCMCIA_CD1); |
| 123 | state->ready = !!gpio_get_value(H3XXX_GPIO_PCMCIA_IRQ1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | state->bvd1 = 0; |
| 125 | state->bvd2 = 0; |
| 126 | state->wrprot = 0; /* Not available on H3600. */ |
| 127 | state->vs_3v = 0; |
| 128 | state->vs_Xv = 0; |
| 129 | break; |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | static int |
| 134 | h3600_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, const socket_state_t *state) |
| 135 | { |
| 136 | if (state->Vcc != 0 && state->Vcc != 33 && state->Vcc != 50) { |
| 137 | printk(KERN_ERR "h3600_pcmcia: unrecognized Vcc %u.%uV\n", |
| 138 | state->Vcc / 10, state->Vcc % 10); |
| 139 | return -1; |
| 140 | } |
| 141 | |
Dmitry Artamonow | 104a416 | 2009-03-15 19:13:16 +0100 | [diff] [blame] | 142 | assign_h3600_egpio(IPAQ_EGPIO_CARD_RESET, !!(state->flags & SS_RESET)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | |
| 144 | /* Silently ignore Vpp, output enable, speaker enable. */ |
| 145 | |
| 146 | return 0; |
| 147 | } |
| 148 | |
| 149 | static void h3600_pcmcia_socket_init(struct soc_pcmcia_socket *skt) |
| 150 | { |
| 151 | /* Enable CF bus: */ |
Dmitry Artamonow | 104a416 | 2009-03-15 19:13:16 +0100 | [diff] [blame] | 152 | assign_h3600_egpio(IPAQ_EGPIO_OPT_NVRAM_ON, 1); |
| 153 | assign_h3600_egpio(IPAQ_EGPIO_OPT_ON, 1); |
| 154 | assign_h3600_egpio(IPAQ_EGPIO_OPT_RESET, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
| 156 | msleep(10); |
| 157 | |
| 158 | soc_pcmcia_enable_irqs(skt, irqs, ARRAY_SIZE(irqs)); |
| 159 | } |
| 160 | |
| 161 | static void h3600_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt) |
| 162 | { |
| 163 | soc_pcmcia_disable_irqs(skt, irqs, ARRAY_SIZE(irqs)); |
| 164 | |
| 165 | /* |
| 166 | * FIXME: This doesn't fit well. We don't have the mechanism in |
| 167 | * the generic PCMCIA layer to deal with the idea of two sockets |
| 168 | * on one bus. We rely on the cs.c behaviour shutting down |
| 169 | * socket 0 then socket 1. |
| 170 | */ |
| 171 | if (skt->nr == 1) { |
Dmitry Artamonow | 104a416 | 2009-03-15 19:13:16 +0100 | [diff] [blame] | 172 | assign_h3600_egpio(IPAQ_EGPIO_OPT_ON, 0); |
| 173 | assign_h3600_egpio(IPAQ_EGPIO_OPT_NVRAM_ON, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | /* hmm, does this suck power? */ |
Dmitry Artamonow | 104a416 | 2009-03-15 19:13:16 +0100 | [diff] [blame] | 175 | assign_h3600_egpio(IPAQ_EGPIO_OPT_RESET, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | } |
| 177 | } |
| 178 | |
| 179 | struct pcmcia_low_level h3600_pcmcia_ops = { |
| 180 | .owner = THIS_MODULE, |
| 181 | .hw_init = h3600_pcmcia_hw_init, |
| 182 | .hw_shutdown = h3600_pcmcia_hw_shutdown, |
| 183 | .socket_state = h3600_pcmcia_socket_state, |
| 184 | .configure_socket = h3600_pcmcia_configure_socket, |
| 185 | |
| 186 | .socket_init = h3600_pcmcia_socket_init, |
| 187 | .socket_suspend = h3600_pcmcia_socket_suspend, |
| 188 | }; |
| 189 | |
| 190 | int __init pcmcia_h3600_init(struct device *dev) |
| 191 | { |
| 192 | int ret = -ENODEV; |
| 193 | |
| 194 | if (machine_is_h3600()) |
| 195 | ret = sa11xx_drv_pcmcia_probe(dev, &h3600_pcmcia_ops, 0, 2); |
| 196 | |
| 197 | return ret; |
| 198 | } |