^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * linux/drivers/pcmcia/pxa/pxa_cm_x255.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Compulab Ltd., 2003, 2007, 2008
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Mike Rapoport <mike@compulab.co.il>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/gpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include "soc_common.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define GPIO_PCMCIA_SKTSEL (54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define GPIO_PCMCIA_S0_CD_VALID (16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define GPIO_PCMCIA_S1_CD_VALID (17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define GPIO_PCMCIA_S0_RDYINT (6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define GPIO_PCMCIA_S1_RDYINT (8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define GPIO_PCMCIA_RESET (9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) static int cmx255_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) int ret = gpio_request(GPIO_PCMCIA_RESET, "PCCard reset");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) gpio_direction_output(GPIO_PCMCIA_RESET, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) if (skt->nr == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) skt->stat[SOC_STAT_CD].gpio = GPIO_PCMCIA_S0_CD_VALID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) skt->stat[SOC_STAT_CD].name = "PCMCIA0 CD";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) skt->stat[SOC_STAT_RDY].gpio = GPIO_PCMCIA_S0_RDYINT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) skt->stat[SOC_STAT_RDY].name = "PCMCIA0 RDY";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) skt->stat[SOC_STAT_CD].gpio = GPIO_PCMCIA_S1_CD_VALID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) skt->stat[SOC_STAT_CD].name = "PCMCIA1 CD";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) skt->stat[SOC_STAT_RDY].gpio = GPIO_PCMCIA_S1_RDYINT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) skt->stat[SOC_STAT_RDY].name = "PCMCIA1 RDY";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) static void cmx255_pcmcia_shutdown(struct soc_pcmcia_socket *skt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) gpio_free(GPIO_PCMCIA_RESET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) static void cmx255_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) struct pcmcia_state *state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) state->vs_3v = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) state->vs_Xv = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) static int cmx255_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) const socket_state_t *state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) switch (skt->nr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) if (state->flags & SS_RESET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) gpio_set_value(GPIO_PCMCIA_SKTSEL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) udelay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) gpio_set_value(GPIO_PCMCIA_RESET, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) udelay(10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) gpio_set_value(GPIO_PCMCIA_RESET, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) if (state->flags & SS_RESET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) gpio_set_value(GPIO_PCMCIA_SKTSEL, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) udelay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) gpio_set_value(GPIO_PCMCIA_RESET, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) udelay(10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) gpio_set_value(GPIO_PCMCIA_RESET, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) static struct pcmcia_low_level cmx255_pcmcia_ops __initdata = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) .hw_init = cmx255_pcmcia_hw_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) .hw_shutdown = cmx255_pcmcia_shutdown,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) .socket_state = cmx255_pcmcia_socket_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) .configure_socket = cmx255_pcmcia_configure_socket,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) .nr = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) static struct platform_device *cmx255_pcmcia_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) int __init cmx255_pcmcia_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) cmx255_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) if (!cmx255_pcmcia_device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) ret = platform_device_add_data(cmx255_pcmcia_device, &cmx255_pcmcia_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) sizeof(cmx255_pcmcia_ops));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) if (ret == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) printk(KERN_INFO "Registering cm-x255 PCMCIA interface.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) ret = platform_device_add(cmx255_pcmcia_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) platform_device_put(cmx255_pcmcia_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) void __exit cmx255_pcmcia_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) platform_device_unregister(cmx255_pcmcia_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }