linux/drivers/pcmcia/pxa2xx_viper.c
<<
>>
Prefs
   1/*
   2 * VIPER PCMCIA support
   3 *   Copyright 2004 Arcom Control Systems
   4 *
   5 * Maintained by Marc Zyngier <maz@misterjones.org>
   6 *                            <marc.zyngier@altran.com>
   7 *
   8 * Based on:
   9 *   iPAQ h2200 PCMCIA support
  10 *   Copyright 2004 Koen Kooi <koen@vestingbar.nl>
  11 *
  12 * This file is subject to the terms and conditions of the GNU General Public
  13 * License.  See the file COPYING in the main directory of this archive for
  14 * more details.
  15 */
  16
  17#include <linux/module.h>
  18#include <linux/init.h>
  19#include <linux/kernel.h>
  20#include <linux/errno.h>
  21#include <linux/interrupt.h>
  22#include <linux/platform_device.h>
  23#include <linux/gpio.h>
  24
  25#include <pcmcia/ss.h>
  26
  27#include <asm/irq.h>
  28
  29#include <mach/viper.h>
  30#include <asm/mach-types.h>
  31
  32#include "soc_common.h"
  33#include "pxa2xx_base.h"
  34
  35static struct pcmcia_irqs irqs[] = {
  36        { 0, gpio_to_irq(VIPER_CF_CD_GPIO),  "PCMCIA_CD" }
  37};
  38
  39static int viper_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
  40{
  41        unsigned long flags;
  42
  43        skt->irq = gpio_to_irq(VIPER_CF_RDY_GPIO);
  44
  45        if (gpio_request(VIPER_CF_CD_GPIO, "CF detect"))
  46                goto err_request_cd;
  47
  48        if (gpio_request(VIPER_CF_RDY_GPIO, "CF ready"))
  49                goto err_request_rdy;
  50
  51        if (gpio_request(VIPER_CF_POWER_GPIO, "CF power"))
  52                goto err_request_pwr;
  53
  54        local_irq_save(flags);
  55
  56        /* GPIO 82 is the CF power enable line. initially off */
  57        if (gpio_direction_output(VIPER_CF_POWER_GPIO, 0) ||
  58            gpio_direction_input(VIPER_CF_CD_GPIO) ||
  59            gpio_direction_input(VIPER_CF_RDY_GPIO)) {
  60                local_irq_restore(flags);
  61                goto err_dir;
  62        }
  63
  64        local_irq_restore(flags);
  65
  66        return soc_pcmcia_request_irqs(skt, irqs, ARRAY_SIZE(irqs));
  67
  68err_dir:
  69        gpio_free(VIPER_CF_POWER_GPIO);
  70err_request_pwr:
  71        gpio_free(VIPER_CF_RDY_GPIO);
  72err_request_rdy:
  73        gpio_free(VIPER_CF_CD_GPIO);
  74err_request_cd:
  75        printk(KERN_ERR "viper: Failed to setup PCMCIA GPIOs\n");
  76        return -1;
  77}
  78
  79/*
  80 * Release all resources.
  81 */
  82static void viper_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
  83{
  84        soc_pcmcia_free_irqs(skt, irqs, ARRAY_SIZE(irqs));
  85        gpio_free(VIPER_CF_POWER_GPIO);
  86        gpio_free(VIPER_CF_RDY_GPIO);
  87        gpio_free(VIPER_CF_CD_GPIO);
  88}
  89
  90static void viper_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
  91                                      struct pcmcia_state *state)
  92{
  93        state->detect = gpio_get_value(VIPER_CF_CD_GPIO) ? 0 : 1;
  94        state->ready  = gpio_get_value(VIPER_CF_RDY_GPIO) ? 1 : 0;
  95        state->bvd1   = 1;
  96        state->bvd2   = 1;
  97        state->wrprot = 0;
  98        state->vs_3v  = 1; /* Can only apply 3.3V */
  99        state->vs_Xv  = 0;
 100}
 101
 102static int viper_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
 103                                         const socket_state_t *state)
 104{
 105        /* Silently ignore Vpp, output enable, speaker enable. */
 106        viper_cf_rst(state->flags & SS_RESET);
 107
 108        /* Apply socket voltage */
 109        switch (state->Vcc) {
 110        case 0:
 111                gpio_set_value(VIPER_CF_POWER_GPIO, 0);
 112                break;
 113        case 33:
 114                gpio_set_value(VIPER_CF_POWER_GPIO, 1);
 115                break;
 116        default:
 117                printk(KERN_ERR "%s: Unsupported Vcc:%d\n",
 118                       __func__, state->Vcc);
 119                return -1;
 120        }
 121
 122        return 0;
 123}
 124
 125static void viper_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
 126{
 127}
 128
 129static void viper_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
 130{
 131}
 132
 133static struct pcmcia_low_level viper_pcmcia_ops __initdata = {
 134        .owner                  = THIS_MODULE,
 135        .hw_init                = viper_pcmcia_hw_init,
 136        .hw_shutdown            = viper_pcmcia_hw_shutdown,
 137        .socket_state           = viper_pcmcia_socket_state,
 138        .configure_socket       = viper_pcmcia_configure_socket,
 139        .socket_init            = viper_pcmcia_socket_init,
 140        .socket_suspend         = viper_pcmcia_socket_suspend,
 141        .nr                     = 1,
 142};
 143
 144static struct platform_device *viper_pcmcia_device;
 145
 146static int __init viper_pcmcia_init(void)
 147{
 148        int ret;
 149
 150        if (!machine_is_viper())
 151                return -ENODEV;
 152
 153        viper_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
 154        if (!viper_pcmcia_device)
 155                return -ENOMEM;
 156
 157        ret = platform_device_add_data(viper_pcmcia_device,
 158                                       &viper_pcmcia_ops,
 159                                       sizeof(viper_pcmcia_ops));
 160
 161        if (!ret)
 162                ret = platform_device_add(viper_pcmcia_device);
 163
 164        if (ret)
 165                platform_device_put(viper_pcmcia_device);
 166
 167        return ret;
 168}
 169
 170static void __exit viper_pcmcia_exit(void)
 171{
 172        platform_device_unregister(viper_pcmcia_device);
 173}
 174
 175module_init(viper_pcmcia_init);
 176module_exit(viper_pcmcia_exit);
 177
 178MODULE_LICENSE("GPL");
 179