Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  *  Copyright (C) 2012 Paul Parsons <lost.distance@yahoo.com>
0004  */
0005 
0006 #include <linux/module.h>
0007 #include <linux/platform_device.h>
0008 #include <linux/err.h>
0009 #include <linux/gpio.h>
0010 #include <linux/irq.h>
0011 
0012 #include <asm/mach-types.h>
0013 #include "hx4700.h"
0014 
0015 #include <pcmcia/soc_common.h>
0016 
0017 static struct gpio gpios[] = {
0018     { GPIO114_HX4700_CF_RESET,    GPIOF_OUT_INIT_LOW,   "CF reset"        },
0019     { EGPIO4_CF_3V3_ON,           GPIOF_OUT_INIT_LOW,   "CF 3.3V enable"  },
0020 };
0021 
0022 static int hx4700_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
0023 {
0024     int ret;
0025 
0026     ret = gpio_request_array(gpios, ARRAY_SIZE(gpios));
0027     if (ret)
0028         goto out;
0029 
0030     /*
0031      * IRQ type must be set before soc_pcmcia_hw_init() calls request_irq().
0032      * The asic3 default IRQ type is level trigger low level detect, exactly
0033      * the the signal present on GPIOD4_CF_nCD when a CF card is inserted.
0034      * If the IRQ type is not changed, the asic3 interrupt handler will loop
0035      * repeatedly because it is unable to clear the level trigger interrupt.
0036      */
0037     irq_set_irq_type(gpio_to_irq(GPIOD4_CF_nCD), IRQ_TYPE_EDGE_BOTH);
0038 
0039     skt->stat[SOC_STAT_CD].gpio = GPIOD4_CF_nCD;
0040     skt->stat[SOC_STAT_CD].name = "PCMCIA CD";
0041     skt->stat[SOC_STAT_RDY].gpio = GPIO60_HX4700_CF_RNB;
0042     skt->stat[SOC_STAT_RDY].name = "PCMCIA Ready";
0043 
0044 out:
0045     return ret;
0046 }
0047 
0048 static void hx4700_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
0049 {
0050     gpio_free_array(gpios, ARRAY_SIZE(gpios));
0051 }
0052 
0053 static void hx4700_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
0054     struct pcmcia_state *state)
0055 {
0056     state->vs_3v = 1;
0057     state->vs_Xv = 0;
0058 }
0059 
0060 static int hx4700_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
0061     const socket_state_t *state)
0062 {
0063     switch (state->Vcc) {
0064     case 0:
0065         gpio_set_value(EGPIO4_CF_3V3_ON, 0);
0066         break;
0067     case 33:
0068         gpio_set_value(EGPIO4_CF_3V3_ON, 1);
0069         break;
0070     default:
0071         printk(KERN_ERR "pcmcia: Unsupported Vcc: %d\n", state->Vcc);
0072         return -EINVAL;
0073     }
0074 
0075     gpio_set_value(GPIO114_HX4700_CF_RESET, (state->flags & SS_RESET) != 0);
0076 
0077     return 0;
0078 }
0079 
0080 static struct pcmcia_low_level hx4700_pcmcia_ops = {
0081     .owner          = THIS_MODULE,
0082     .nr             = 1,
0083     .hw_init        = hx4700_pcmcia_hw_init,
0084     .hw_shutdown    = hx4700_pcmcia_hw_shutdown,
0085     .socket_state   = hx4700_pcmcia_socket_state,
0086     .configure_socket = hx4700_pcmcia_configure_socket,
0087 };
0088 
0089 static struct platform_device *hx4700_pcmcia_device;
0090 
0091 static int __init hx4700_pcmcia_init(void)
0092 {
0093     struct platform_device *pdev;
0094 
0095     if (!machine_is_h4700())
0096         return -ENODEV;
0097 
0098     pdev = platform_device_register_data(NULL, "pxa2xx-pcmcia", -1,
0099         &hx4700_pcmcia_ops, sizeof(hx4700_pcmcia_ops));
0100     if (IS_ERR(pdev))
0101         return PTR_ERR(pdev);
0102 
0103     hx4700_pcmcia_device = pdev;
0104 
0105     return 0;
0106 }
0107 
0108 static void __exit hx4700_pcmcia_exit(void)
0109 {
0110     platform_device_unregister(hx4700_pcmcia_device);
0111 }
0112 
0113 module_init(hx4700_pcmcia_init);
0114 module_exit(hx4700_pcmcia_exit);
0115 
0116 MODULE_AUTHOR("Paul Parsons <lost.distance@yahoo.com>");
0117 MODULE_DESCRIPTION("HP iPAQ hx4700 PCMCIA driver");
0118 MODULE_LICENSE("GPL");