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> |
Dmitry Artamonow | 8715b29 | 2009-11-27 12:09:25 +0100 | [diff] [blame] | 18 | #include <mach/h3xxx.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
| 20 | #include "sa1100_generic.h" |
| 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | static int h3600_pcmcia_hw_init(struct soc_pcmcia_socket *skt) |
| 23 | { |
Dmitry Artamonow | 2a83709 | 2009-12-06 17:12:49 +0100 | [diff] [blame] | 24 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
Dmitry Artamonow | 2a83709 | 2009-12-06 17:12:49 +0100 | [diff] [blame] | 26 | switch (skt->nr) { |
| 27 | case 0: |
Russell King | 65474b4 | 2012-01-13 23:07:26 +0000 | [diff] [blame^] | 28 | skt->stat[SOC_STAT_CD].gpio = H3XXX_GPIO_PCMCIA_CD0; |
| 29 | skt->stat[SOC_STAT_CD].name = "PCMCIA CD0"; |
| 30 | skt->stat[SOC_STAT_RDY].gpio = H3XXX_GPIO_PCMCIA_IRQ0; |
| 31 | skt->stat[SOC_STAT_RDY].name = "PCMCIA IRQ0"; |
Dmitry Artamonow | 2a83709 | 2009-12-06 17:12:49 +0100 | [diff] [blame] | 32 | |
Dmitry Artamonow | 22f9740 | 2009-11-27 12:02:28 +0100 | [diff] [blame] | 33 | err = gpio_request(H3XXX_EGPIO_OPT_NVRAM_ON, "OPT NVRAM ON"); |
Dmitry Artamonow | 2a83709 | 2009-12-06 17:12:49 +0100 | [diff] [blame] | 34 | if (err) |
Russell King | 65474b4 | 2012-01-13 23:07:26 +0000 | [diff] [blame^] | 35 | goto err01; |
Dmitry Artamonow | 22f9740 | 2009-11-27 12:02:28 +0100 | [diff] [blame] | 36 | err = gpio_direction_output(H3XXX_EGPIO_OPT_NVRAM_ON, 0); |
| 37 | if (err) |
| 38 | goto err03; |
| 39 | err = gpio_request(H3XXX_EGPIO_OPT_ON, "OPT ON"); |
| 40 | if (err) |
| 41 | goto err03; |
| 42 | err = gpio_direction_output(H3XXX_EGPIO_OPT_ON, 0); |
| 43 | if (err) |
| 44 | goto err04; |
| 45 | err = gpio_request(H3XXX_EGPIO_OPT_RESET, "OPT RESET"); |
| 46 | if (err) |
| 47 | goto err04; |
| 48 | err = gpio_direction_output(H3XXX_EGPIO_OPT_RESET, 0); |
| 49 | if (err) |
| 50 | goto err05; |
| 51 | err = gpio_request(H3XXX_EGPIO_CARD_RESET, "PCMCIA CARD RESET"); |
| 52 | if (err) |
| 53 | goto err05; |
| 54 | err = gpio_direction_output(H3XXX_EGPIO_CARD_RESET, 0); |
| 55 | if (err) |
| 56 | goto err06; |
Dmitry Artamonow | 2a83709 | 2009-12-06 17:12:49 +0100 | [diff] [blame] | 57 | break; |
| 58 | case 1: |
Russell King | 65474b4 | 2012-01-13 23:07:26 +0000 | [diff] [blame^] | 59 | skt->stat[SOC_STAT_CD].gpio = H3XXX_GPIO_PCMCIA_CD1; |
| 60 | skt->stat[SOC_STAT_CD].name = "PCMCIA CD1"; |
| 61 | skt->stat[SOC_STAT_RDY].gpio = H3XXX_GPIO_PCMCIA_IRQ1; |
| 62 | skt->stat[SOC_STAT_RDY].name = "PCMCIA IRQ1"; |
Dmitry Artamonow | 2a83709 | 2009-12-06 17:12:49 +0100 | [diff] [blame] | 63 | break; |
| 64 | } |
| 65 | return 0; |
| 66 | |
Dmitry Artamonow | 22f9740 | 2009-11-27 12:02:28 +0100 | [diff] [blame] | 67 | err06: gpio_free(H3XXX_EGPIO_CARD_RESET); |
| 68 | err05: gpio_free(H3XXX_EGPIO_OPT_RESET); |
| 69 | err04: gpio_free(H3XXX_EGPIO_OPT_ON); |
| 70 | err03: gpio_free(H3XXX_EGPIO_OPT_NVRAM_ON); |
Dmitry Artamonow | 2a83709 | 2009-12-06 17:12:49 +0100 | [diff] [blame] | 71 | err01: gpio_free(H3XXX_GPIO_PCMCIA_IRQ0); |
Russell King | 65474b4 | 2012-01-13 23:07:26 +0000 | [diff] [blame^] | 72 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | static void h3600_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt) |
| 76 | { |
Dmitry Artamonow | 2a83709 | 2009-12-06 17:12:49 +0100 | [diff] [blame] | 77 | switch (skt->nr) { |
| 78 | case 0: |
Dmitry Artamonow | 22f9740 | 2009-11-27 12:02:28 +0100 | [diff] [blame] | 79 | /* Disable CF bus: */ |
| 80 | gpio_set_value(H3XXX_EGPIO_OPT_NVRAM_ON, 0); |
| 81 | gpio_set_value(H3XXX_EGPIO_OPT_ON, 0); |
| 82 | gpio_set_value(H3XXX_EGPIO_OPT_RESET, 1); |
| 83 | |
| 84 | gpio_free(H3XXX_EGPIO_CARD_RESET); |
| 85 | gpio_free(H3XXX_EGPIO_OPT_RESET); |
| 86 | gpio_free(H3XXX_EGPIO_OPT_ON); |
| 87 | gpio_free(H3XXX_EGPIO_OPT_NVRAM_ON); |
Dmitry Artamonow | 2a83709 | 2009-12-06 17:12:49 +0100 | [diff] [blame] | 88 | break; |
| 89 | case 1: |
Dmitry Artamonow | 2a83709 | 2009-12-06 17:12:49 +0100 | [diff] [blame] | 90 | break; |
| 91 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | static void |
| 95 | h3600_pcmcia_socket_state(struct soc_pcmcia_socket *skt, struct pcmcia_state *state) |
| 96 | { |
Russell King | 65474b4 | 2012-01-13 23:07:26 +0000 | [diff] [blame^] | 97 | state->bvd1 = 0; |
| 98 | state->bvd2 = 0; |
| 99 | state->wrprot = 0; /* Not available on H3600. */ |
| 100 | state->vs_3v = 0; |
| 101 | state->vs_Xv = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | static int |
| 105 | h3600_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, const socket_state_t *state) |
| 106 | { |
| 107 | if (state->Vcc != 0 && state->Vcc != 33 && state->Vcc != 50) { |
| 108 | printk(KERN_ERR "h3600_pcmcia: unrecognized Vcc %u.%uV\n", |
| 109 | state->Vcc / 10, state->Vcc % 10); |
| 110 | return -1; |
| 111 | } |
| 112 | |
Dmitry Artamonow | 22f9740 | 2009-11-27 12:02:28 +0100 | [diff] [blame] | 113 | gpio_set_value(H3XXX_EGPIO_CARD_RESET, !!(state->flags & SS_RESET)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | |
| 115 | /* Silently ignore Vpp, output enable, speaker enable. */ |
| 116 | |
| 117 | return 0; |
| 118 | } |
| 119 | |
| 120 | static void h3600_pcmcia_socket_init(struct soc_pcmcia_socket *skt) |
| 121 | { |
| 122 | /* Enable CF bus: */ |
Dmitry Artamonow | 22f9740 | 2009-11-27 12:02:28 +0100 | [diff] [blame] | 123 | gpio_set_value(H3XXX_EGPIO_OPT_NVRAM_ON, 1); |
| 124 | gpio_set_value(H3XXX_EGPIO_OPT_ON, 1); |
| 125 | gpio_set_value(H3XXX_EGPIO_OPT_RESET, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | |
| 127 | msleep(10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | static void h3600_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt) |
| 131 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | /* |
| 133 | * FIXME: This doesn't fit well. We don't have the mechanism in |
| 134 | * the generic PCMCIA layer to deal with the idea of two sockets |
| 135 | * on one bus. We rely on the cs.c behaviour shutting down |
| 136 | * socket 0 then socket 1. |
| 137 | */ |
| 138 | if (skt->nr == 1) { |
Dmitry Artamonow | 22f9740 | 2009-11-27 12:02:28 +0100 | [diff] [blame] | 139 | gpio_set_value(H3XXX_EGPIO_OPT_ON, 0); |
| 140 | gpio_set_value(H3XXX_EGPIO_OPT_NVRAM_ON, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | /* hmm, does this suck power? */ |
Dmitry Artamonow | 22f9740 | 2009-11-27 12:02:28 +0100 | [diff] [blame] | 142 | gpio_set_value(H3XXX_EGPIO_OPT_RESET, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | } |
| 144 | } |
| 145 | |
| 146 | struct pcmcia_low_level h3600_pcmcia_ops = { |
| 147 | .owner = THIS_MODULE, |
| 148 | .hw_init = h3600_pcmcia_hw_init, |
| 149 | .hw_shutdown = h3600_pcmcia_hw_shutdown, |
| 150 | .socket_state = h3600_pcmcia_socket_state, |
| 151 | .configure_socket = h3600_pcmcia_configure_socket, |
| 152 | |
| 153 | .socket_init = h3600_pcmcia_socket_init, |
| 154 | .socket_suspend = h3600_pcmcia_socket_suspend, |
| 155 | }; |
| 156 | |
Uwe Kleine-König | 5b85e04 | 2010-11-04 10:46:14 +0100 | [diff] [blame] | 157 | int __devinit pcmcia_h3600_init(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | { |
| 159 | int ret = -ENODEV; |
| 160 | |
Dmitry Artamonow | e7435f8 | 2009-11-27 12:13:47 +0100 | [diff] [blame] | 161 | if (machine_is_h3600() || machine_is_h3100()) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | ret = sa11xx_drv_pcmcia_probe(dev, &h3600_pcmcia_ops, 0, 2); |
| 163 | |
| 164 | return ret; |
| 165 | } |