Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * drivers/pcmcia/sa1100_simpad.c |
| 3 | * |
| 4 | * PCMCIA implementation routines for simpad |
| 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/init.h> |
| 11 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 12 | #include <mach/hardware.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <asm/mach-types.h> |
| 14 | #include <asm/irq.h> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 15 | #include <mach/simpad.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include "sa1100_generic.h" |
| 17 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | static struct pcmcia_irqs irqs[] = { |
| 19 | { 1, IRQ_GPIO_CF_CD, "CF_CD" }, |
| 20 | }; |
| 21 | |
| 22 | static int simpad_pcmcia_hw_init(struct soc_pcmcia_socket *skt) |
| 23 | { |
| 24 | |
Jochen Friedrich | de0bc0d | 2011-08-18 21:50:31 +0100 | [diff] [blame] | 25 | simpad_clear_cs3_bit(VCC_3V_EN|VCC_5V_EN|EN0|EN1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
Russell King - ARM Linux | 66024db | 2009-03-29 22:45:26 +0100 | [diff] [blame] | 27 | skt->socket.pci_irq = IRQ_GPIO_CF_IRQ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | |
| 29 | return soc_pcmcia_request_irqs(skt, irqs, ARRAY_SIZE(irqs)); |
| 30 | } |
| 31 | |
| 32 | static void simpad_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt) |
| 33 | { |
| 34 | soc_pcmcia_free_irqs(skt, irqs, ARRAY_SIZE(irqs)); |
| 35 | |
| 36 | /* Disable CF bus: */ |
Jochen Friedrich | de0bc0d | 2011-08-18 21:50:31 +0100 | [diff] [blame] | 37 | /*simpad_set_cs3_bit(PCMCIA_BUFF_DIS);*/ |
| 38 | simpad_clear_cs3_bit(PCMCIA_RESET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | static void |
| 42 | simpad_pcmcia_socket_state(struct soc_pcmcia_socket *skt, |
| 43 | struct pcmcia_state *state) |
| 44 | { |
| 45 | unsigned long levels = GPLR; |
Jochen Friedrich | de0bc0d | 2011-08-18 21:50:31 +0100 | [diff] [blame] | 46 | long cs3reg = simpad_get_cs3_ro(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
| 48 | state->detect=((levels & GPIO_CF_CD)==0)?1:0; |
| 49 | state->ready=(levels & GPIO_CF_IRQ)?1:0; |
Jochen Friedrich | de0bc0d | 2011-08-18 21:50:31 +0100 | [diff] [blame] | 50 | state->bvd1 = 1; /* Might be cs3reg & PCMCIA_BVD1 */ |
| 51 | state->bvd2 = 1; /* Might be cs3reg & PCMCIA_BVD2 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | state->wrprot=0; /* Not available on Simpad. */ |
Jochen Friedrich | de0bc0d | 2011-08-18 21:50:31 +0100 | [diff] [blame] | 53 | |
| 54 | if ((cs3reg & (PCMCIA_VS1|PCMCIA_VS2)) == |
| 55 | (PCMCIA_VS1|PCMCIA_VS2)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | state->vs_3v=0; |
| 57 | state->vs_Xv=0; |
| 58 | } else { |
| 59 | state->vs_3v=1; |
| 60 | state->vs_Xv=0; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | static int |
| 65 | simpad_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, |
| 66 | const socket_state_t *state) |
| 67 | { |
| 68 | unsigned long flags; |
| 69 | |
| 70 | local_irq_save(flags); |
| 71 | |
| 72 | /* Murphy: see table of MIC2562a-1 */ |
| 73 | switch (state->Vcc) { |
| 74 | case 0: |
Jochen Friedrich | de0bc0d | 2011-08-18 21:50:31 +0100 | [diff] [blame] | 75 | simpad_clear_cs3_bit(VCC_3V_EN|VCC_5V_EN|EN0|EN1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | break; |
| 77 | |
| 78 | case 33: |
Jochen Friedrich | de0bc0d | 2011-08-18 21:50:31 +0100 | [diff] [blame] | 79 | simpad_clear_cs3_bit(VCC_3V_EN|EN1); |
| 80 | simpad_set_cs3_bit(VCC_5V_EN|EN0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | break; |
| 82 | |
| 83 | case 50: |
Jochen Friedrich | de0bc0d | 2011-08-18 21:50:31 +0100 | [diff] [blame] | 84 | simpad_clear_cs3_bit(VCC_5V_EN|EN1); |
| 85 | simpad_set_cs3_bit(VCC_3V_EN|EN0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | break; |
| 87 | |
| 88 | default: |
| 89 | printk(KERN_ERR "%s(): unrecognized Vcc %u\n", |
Harvey Harrison | 2e11cb4 | 2008-05-01 04:34:54 -0700 | [diff] [blame] | 90 | __func__, state->Vcc); |
Jochen Friedrich | de0bc0d | 2011-08-18 21:50:31 +0100 | [diff] [blame] | 91 | simpad_clear_cs3_bit(VCC_3V_EN|VCC_5V_EN|EN0|EN1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | local_irq_restore(flags); |
| 93 | return -1; |
| 94 | } |
| 95 | |
| 96 | |
| 97 | local_irq_restore(flags); |
| 98 | |
| 99 | return 0; |
| 100 | } |
| 101 | |
| 102 | static void simpad_pcmcia_socket_init(struct soc_pcmcia_socket *skt) |
| 103 | { |
| 104 | soc_pcmcia_enable_irqs(skt, irqs, ARRAY_SIZE(irqs)); |
| 105 | } |
| 106 | |
| 107 | static void simpad_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt) |
| 108 | { |
| 109 | soc_pcmcia_disable_irqs(skt, irqs, ARRAY_SIZE(irqs)); |
Jochen Friedrich | de0bc0d | 2011-08-18 21:50:31 +0100 | [diff] [blame] | 110 | simpad_set_cs3_bit(PCMCIA_RESET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | static struct pcmcia_low_level simpad_pcmcia_ops = { |
| 114 | .owner = THIS_MODULE, |
| 115 | .hw_init = simpad_pcmcia_hw_init, |
| 116 | .hw_shutdown = simpad_pcmcia_hw_shutdown, |
| 117 | .socket_state = simpad_pcmcia_socket_state, |
| 118 | .configure_socket = simpad_pcmcia_configure_socket, |
| 119 | .socket_init = simpad_pcmcia_socket_init, |
| 120 | .socket_suspend = simpad_pcmcia_socket_suspend, |
| 121 | }; |
| 122 | |
Uwe Kleine-König | 5b85e04 | 2010-11-04 10:46:14 +0100 | [diff] [blame] | 123 | int __devinit pcmcia_simpad_init(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | { |
| 125 | int ret = -ENODEV; |
| 126 | |
| 127 | if (machine_is_simpad()) |
| 128 | ret = sa11xx_drv_pcmcia_probe(dev, &simpad_pcmcia_ops, 1, 1); |
| 129 | |
| 130 | return ret; |
| 131 | } |