linux/drivers/pcmcia/pxa2xx_hx4700.c
<<
>>
Prefs
   1/*
   2 *  Copyright (C) 2012 Paul Parsons <lost.distance@yahoo.com>
   3 *
   4 *  This program is free software; you can redistribute it and/or modify
   5 *  it under the terms of the GNU General Public License version 2 as
   6 *  published by the Free Software Foundation.
   7 */
   8
   9#include <linux/module.h>
  10#include <linux/platform_device.h>
  11#include <linux/err.h>
  12#include <linux/gpio.h>
  13#include <linux/irq.h>
  14
  15#include <asm/mach-types.h>
  16#include <mach/hx4700.h>
  17
  18#include "soc_common.h"
  19
  20static struct gpio gpios[] = {
  21        { GPIO114_HX4700_CF_RESET,    GPIOF_OUT_INIT_LOW,   "CF reset"        },
  22        { EGPIO4_CF_3V3_ON,           GPIOF_OUT_INIT_LOW,   "CF 3.3V enable"  },
  23};
  24
  25static int hx4700_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
  26{
  27        int ret;
  28
  29        ret = gpio_request_array(gpios, ARRAY_SIZE(gpios));
  30        if (ret)
  31                goto out;
  32
  33        /*
  34         * IRQ type must be set before soc_pcmcia_hw_init() calls request_irq().
  35         * The asic3 default IRQ type is level trigger low level detect, exactly
  36         * the the signal present on GPIOD4_CF_nCD when a CF card is inserted.
  37         * If the IRQ type is not changed, the asic3 interrupt handler will loop
  38         * repeatedly because it is unable to clear the level trigger interrupt.
  39         */
  40        irq_set_irq_type(gpio_to_irq(GPIOD4_CF_nCD), IRQ_TYPE_EDGE_BOTH);
  41
  42        skt->stat[SOC_STAT_CD].gpio = GPIOD4_CF_nCD;
  43        skt->stat[SOC_STAT_CD].name = "PCMCIA CD";
  44        skt->stat[SOC_STAT_RDY].gpio = GPIO60_HX4700_CF_RNB;
  45        skt->stat[SOC_STAT_RDY].name = "PCMCIA Ready";
  46
  47out:
  48        return ret;
  49}
  50
  51static void hx4700_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
  52{
  53        gpio_free_array(gpios, ARRAY_SIZE(gpios));
  54}
  55
  56static void hx4700_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
  57        struct pcmcia_state *state)
  58{
  59        state->vs_3v = 1;
  60        state->vs_Xv = 0;
  61}
  62
  63static int hx4700_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
  64        const socket_state_t *state)
  65{
  66        switch (state->Vcc) {
  67        case 0:
  68                gpio_set_value(EGPIO4_CF_3V3_ON, 0);
  69                break;
  70        case 33:
  71                gpio_set_value(EGPIO4_CF_3V3_ON, 1);
  72                break;
  73        default:
  74                printk(KERN_ERR "pcmcia: Unsupported Vcc: %d\n", state->Vcc);
  75                return -EINVAL;
  76        }
  77
  78        gpio_set_value(GPIO114_HX4700_CF_RESET, (state->flags & SS_RESET) != 0);
  79
  80        return 0;
  81}
  82
  83static struct pcmcia_low_level hx4700_pcmcia_ops = {
  84        .owner          = THIS_MODULE,
  85        .nr             = 1,
  86        .hw_init        = hx4700_pcmcia_hw_init,
  87        .hw_shutdown    = hx4700_pcmcia_hw_shutdown,
  88        .socket_state   = hx4700_pcmcia_socket_state,
  89        .configure_socket = hx4700_pcmcia_configure_socket,
  90};
  91
  92static struct platform_device *hx4700_pcmcia_device;
  93
  94static int __init hx4700_pcmcia_init(void)
  95{
  96        struct platform_device *pdev;
  97
  98        if (!machine_is_h4700())
  99                return -ENODEV;
 100
 101        pdev = platform_device_register_data(NULL, "pxa2xx-pcmcia", -1,
 102                &hx4700_pcmcia_ops, sizeof(hx4700_pcmcia_ops));
 103        if (IS_ERR(pdev))
 104                return PTR_ERR(pdev);
 105
 106        hx4700_pcmcia_device = pdev;
 107
 108        return 0;
 109}
 110
 111static void __exit hx4700_pcmcia_exit(void)
 112{
 113        platform_device_unregister(hx4700_pcmcia_device);
 114}
 115
 116module_init(hx4700_pcmcia_init);
 117module_exit(hx4700_pcmcia_exit);
 118
 119MODULE_AUTHOR("Paul Parsons <lost.distance@yahoo.com>");
 120MODULE_DESCRIPTION("HP iPAQ hx4700 PCMCIA driver");
 121MODULE_LICENSE("GPL");
 122