Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * linux/drivers/pcmcia/pxa2xx_palmtx.c
0004  *
0005  * Driver for Palm T|X PCMCIA
0006  *
0007  * Copyright (C) 2007-2011 Marek Vasut <marek.vasut@gmail.com>
0008  */
0009 
0010 #include <linux/module.h>
0011 #include <linux/platform_device.h>
0012 #include <linux/gpio.h>
0013 
0014 #include <asm/mach-types.h>
0015 #include "palmtx.h"
0016 #include <pcmcia/soc_common.h>
0017 
0018 static struct gpio palmtx_pcmcia_gpios[] = {
0019     { GPIO_NR_PALMTX_PCMCIA_POWER1, GPIOF_INIT_LOW, "PCMCIA Power 1" },
0020     { GPIO_NR_PALMTX_PCMCIA_POWER2, GPIOF_INIT_LOW, "PCMCIA Power 2" },
0021     { GPIO_NR_PALMTX_PCMCIA_RESET,  GPIOF_INIT_HIGH,"PCMCIA Reset" },
0022 };
0023 
0024 static int palmtx_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
0025 {
0026     int ret;
0027 
0028     ret = gpio_request_array(palmtx_pcmcia_gpios,
0029                 ARRAY_SIZE(palmtx_pcmcia_gpios));
0030 
0031     skt->stat[SOC_STAT_RDY].gpio = GPIO_NR_PALMTX_PCMCIA_READY;
0032     skt->stat[SOC_STAT_RDY].name = "PCMCIA Ready";
0033 
0034     return ret;
0035 }
0036 
0037 static void palmtx_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
0038 {
0039     gpio_free_array(palmtx_pcmcia_gpios, ARRAY_SIZE(palmtx_pcmcia_gpios));
0040 }
0041 
0042 static void palmtx_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
0043                     struct pcmcia_state *state)
0044 {
0045     state->detect = 1; /* always inserted */
0046     state->vs_3v  = 1;
0047     state->vs_Xv  = 0;
0048 }
0049 
0050 static int
0051 palmtx_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
0052                 const socket_state_t *state)
0053 {
0054     gpio_set_value(GPIO_NR_PALMTX_PCMCIA_POWER1, 1);
0055     gpio_set_value(GPIO_NR_PALMTX_PCMCIA_POWER2, 1);
0056     gpio_set_value(GPIO_NR_PALMTX_PCMCIA_RESET,
0057             !!(state->flags & SS_RESET));
0058 
0059     return 0;
0060 }
0061 
0062 static struct pcmcia_low_level palmtx_pcmcia_ops = {
0063     .owner          = THIS_MODULE,
0064 
0065     .first          = 0,
0066     .nr         = 1,
0067 
0068     .hw_init        = palmtx_pcmcia_hw_init,
0069     .hw_shutdown        = palmtx_pcmcia_hw_shutdown,
0070 
0071     .socket_state       = palmtx_pcmcia_socket_state,
0072     .configure_socket   = palmtx_pcmcia_configure_socket,
0073 };
0074 
0075 static struct platform_device *palmtx_pcmcia_device;
0076 
0077 static int __init palmtx_pcmcia_init(void)
0078 {
0079     int ret;
0080 
0081     if (!machine_is_palmtx())
0082         return -ENODEV;
0083 
0084     palmtx_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
0085     if (!palmtx_pcmcia_device)
0086         return -ENOMEM;
0087 
0088     ret = platform_device_add_data(palmtx_pcmcia_device, &palmtx_pcmcia_ops,
0089                     sizeof(palmtx_pcmcia_ops));
0090 
0091     if (!ret)
0092         ret = platform_device_add(palmtx_pcmcia_device);
0093 
0094     if (ret)
0095         platform_device_put(palmtx_pcmcia_device);
0096 
0097     return ret;
0098 }
0099 
0100 static void __exit palmtx_pcmcia_exit(void)
0101 {
0102     platform_device_unregister(palmtx_pcmcia_device);
0103 }
0104 
0105 module_init(palmtx_pcmcia_init);
0106 module_exit(palmtx_pcmcia_exit);
0107 
0108 MODULE_AUTHOR("Marek Vasut <marek.vasut@gmail.com>");
0109 MODULE_DESCRIPTION("PCMCIA support for Palm T|X");
0110 MODULE_ALIAS("platform:pxa2xx-pcmcia");
0111 MODULE_LICENSE("GPL");