Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/pcmcia/pxa2xx_mainstone.c |
| 3 | * |
| 4 | * Mainstone PCMCIA specific routines. |
| 5 | * |
| 6 | * Created: May 12, 2004 |
| 7 | * Author: Nicolas Pitre |
| 8 | * Copyright: MontaVista Software Inc. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License version 2 as |
| 12 | * published by the Free Software Foundation. |
| 13 | */ |
| 14 | |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/init.h> |
| 17 | #include <linux/kernel.h> |
| 18 | #include <linux/errno.h> |
| 19 | #include <linux/interrupt.h> |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 20 | #include <linux/platform_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
| 22 | #include <pcmcia/ss.h> |
| 23 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 24 | #include <mach/hardware.h> |
Russell King | 04ba0f6 | 2008-04-24 15:23:25 +0100 | [diff] [blame] | 25 | #include <asm/mach-types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <asm/irq.h> |
| 27 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 28 | #include <mach/pxa-regs.h> |
| 29 | #include <mach/mainstone.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | |
| 31 | #include "soc_common.h" |
| 32 | |
| 33 | |
| 34 | static struct pcmcia_irqs irqs[] = { |
| 35 | { 0, MAINSTONE_S0_CD_IRQ, "PCMCIA0 CD" }, |
| 36 | { 1, MAINSTONE_S1_CD_IRQ, "PCMCIA1 CD" }, |
| 37 | { 0, MAINSTONE_S0_STSCHG_IRQ, "PCMCIA0 STSCHG" }, |
| 38 | { 1, MAINSTONE_S1_STSCHG_IRQ, "PCMCIA1 STSCHG" }, |
| 39 | }; |
| 40 | |
| 41 | static int mst_pcmcia_hw_init(struct soc_pcmcia_socket *skt) |
| 42 | { |
| 43 | /* |
| 44 | * Setup default state of GPIO outputs |
| 45 | * before we enable them as outputs. |
| 46 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
| 48 | skt->irq = (skt->nr == 0) ? MAINSTONE_S0_IRQ : MAINSTONE_S1_IRQ; |
| 49 | return soc_pcmcia_request_irqs(skt, irqs, ARRAY_SIZE(irqs)); |
| 50 | } |
| 51 | |
| 52 | static void mst_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt) |
| 53 | { |
| 54 | soc_pcmcia_free_irqs(skt, irqs, ARRAY_SIZE(irqs)); |
| 55 | } |
| 56 | |
| 57 | static unsigned long mst_pcmcia_status[2]; |
| 58 | |
| 59 | static void mst_pcmcia_socket_state(struct soc_pcmcia_socket *skt, |
| 60 | struct pcmcia_state *state) |
| 61 | { |
| 62 | unsigned long status, flip; |
| 63 | |
| 64 | status = (skt->nr == 0) ? MST_PCMCIA0 : MST_PCMCIA1; |
| 65 | flip = (status ^ mst_pcmcia_status[skt->nr]) & MST_PCMCIA_nSTSCHG_BVD1; |
| 66 | |
| 67 | /* |
| 68 | * Workaround for STSCHG which can't be deasserted: |
| 69 | * We therefore disable/enable corresponding IRQs |
| 70 | * as needed to avoid IRQ locks. |
| 71 | */ |
| 72 | if (flip) { |
| 73 | mst_pcmcia_status[skt->nr] = status; |
| 74 | if (status & MST_PCMCIA_nSTSCHG_BVD1) |
| 75 | enable_irq( (skt->nr == 0) ? MAINSTONE_S0_STSCHG_IRQ |
| 76 | : MAINSTONE_S1_STSCHG_IRQ ); |
| 77 | else |
| 78 | disable_irq( (skt->nr == 0) ? MAINSTONE_S0_STSCHG_IRQ |
| 79 | : MAINSTONE_S1_STSCHG_IRQ ); |
| 80 | } |
| 81 | |
| 82 | state->detect = (status & MST_PCMCIA_nCD) ? 0 : 1; |
| 83 | state->ready = (status & MST_PCMCIA_nIRQ) ? 1 : 0; |
| 84 | state->bvd1 = (status & MST_PCMCIA_nSTSCHG_BVD1) ? 1 : 0; |
| 85 | state->bvd2 = (status & MST_PCMCIA_nSPKR_BVD2) ? 1 : 0; |
| 86 | state->vs_3v = (status & MST_PCMCIA_nVS1) ? 0 : 1; |
| 87 | state->vs_Xv = (status & MST_PCMCIA_nVS2) ? 0 : 1; |
| 88 | state->wrprot = 0; /* not available */ |
| 89 | } |
| 90 | |
| 91 | static int mst_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, |
| 92 | const socket_state_t *state) |
| 93 | { |
| 94 | unsigned long power = 0; |
| 95 | int ret = 0; |
| 96 | |
| 97 | switch (state->Vcc) { |
| 98 | case 0: power |= MST_PCMCIA_PWR_VCC_0; break; |
| 99 | case 33: power |= MST_PCMCIA_PWR_VCC_33; break; |
| 100 | case 50: power |= MST_PCMCIA_PWR_VCC_50; break; |
| 101 | default: |
| 102 | printk(KERN_ERR "%s(): bad Vcc %u\n", |
Harvey Harrison | 2e11cb4 | 2008-05-01 04:34:54 -0700 | [diff] [blame] | 103 | __func__, state->Vcc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | ret = -1; |
| 105 | } |
| 106 | |
| 107 | switch (state->Vpp) { |
| 108 | case 0: power |= MST_PCMCIA_PWR_VPP_0; break; |
| 109 | case 120: power |= MST_PCMCIA_PWR_VPP_120; break; |
| 110 | default: |
| 111 | if(state->Vpp == state->Vcc) { |
| 112 | power |= MST_PCMCIA_PWR_VPP_VCC; |
| 113 | } else { |
| 114 | printk(KERN_ERR "%s(): bad Vpp %u\n", |
Harvey Harrison | 2e11cb4 | 2008-05-01 04:34:54 -0700 | [diff] [blame] | 115 | __func__, state->Vpp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | ret = -1; |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | if (state->flags & SS_RESET) |
| 121 | power |= MST_PCMCIA_RESET; |
| 122 | |
| 123 | switch (skt->nr) { |
| 124 | case 0: MST_PCMCIA0 = power; break; |
| 125 | case 1: MST_PCMCIA1 = power; break; |
| 126 | default: ret = -1; |
| 127 | } |
| 128 | |
| 129 | return ret; |
| 130 | } |
| 131 | |
| 132 | static void mst_pcmcia_socket_init(struct soc_pcmcia_socket *skt) |
| 133 | { |
| 134 | } |
| 135 | |
| 136 | static void mst_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt) |
| 137 | { |
| 138 | } |
| 139 | |
Russell King | 4e5e8de | 2008-04-24 15:28:11 +0100 | [diff] [blame] | 140 | static struct pcmcia_low_level mst_pcmcia_ops __initdata = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | .owner = THIS_MODULE, |
| 142 | .hw_init = mst_pcmcia_hw_init, |
| 143 | .hw_shutdown = mst_pcmcia_hw_shutdown, |
| 144 | .socket_state = mst_pcmcia_socket_state, |
| 145 | .configure_socket = mst_pcmcia_configure_socket, |
| 146 | .socket_init = mst_pcmcia_socket_init, |
| 147 | .socket_suspend = mst_pcmcia_socket_suspend, |
| 148 | .nr = 2, |
| 149 | }; |
| 150 | |
| 151 | static struct platform_device *mst_pcmcia_device; |
| 152 | |
| 153 | static int __init mst_pcmcia_init(void) |
| 154 | { |
| 155 | int ret; |
| 156 | |
Russell King | 04ba0f6 | 2008-04-24 15:23:25 +0100 | [diff] [blame] | 157 | if (!machine_is_mainstone()) |
| 158 | return -ENODEV; |
| 159 | |
Richard Purdie | b016450 | 2006-01-10 17:16:12 +0000 | [diff] [blame] | 160 | mst_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | if (!mst_pcmcia_device) |
| 162 | return -ENOMEM; |
Richard Purdie | b016450 | 2006-01-10 17:16:12 +0000 | [diff] [blame] | 163 | |
Russell King | 4e5e8de | 2008-04-24 15:28:11 +0100 | [diff] [blame] | 164 | ret = platform_device_add_data(mst_pcmcia_device, &mst_pcmcia_ops, |
| 165 | sizeof(mst_pcmcia_ops)); |
| 166 | if (ret == 0) |
| 167 | ret = platform_device_add(mst_pcmcia_device); |
Richard Purdie | b016450 | 2006-01-10 17:16:12 +0000 | [diff] [blame] | 168 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | if (ret) |
Richard Purdie | b016450 | 2006-01-10 17:16:12 +0000 | [diff] [blame] | 170 | platform_device_put(mst_pcmcia_device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | |
| 172 | return ret; |
| 173 | } |
| 174 | |
| 175 | static void __exit mst_pcmcia_exit(void) |
| 176 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | platform_device_unregister(mst_pcmcia_device); |
| 178 | } |
| 179 | |
Richard Purdie | f36598a | 2005-09-03 19:39:25 +0100 | [diff] [blame] | 180 | fs_initcall(mst_pcmcia_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | module_exit(mst_pcmcia_exit); |
| 182 | |
| 183 | MODULE_LICENSE("GPL"); |
Kay Sievers | 43cc71e | 2007-08-18 04:40:39 +0200 | [diff] [blame] | 184 | MODULE_ALIAS("platform:pxa2xx-pcmcia"); |