^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/pxa2xx_stargate2.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Stargate 2 PCMCIA specific routines.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Created: December 6, 2005
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Author: Ed C. Epp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Copyright: Intel Corp 2005
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Jonathan Cameron <jic23@cam.ac.uk> 2009
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/gpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <pcmcia/ss.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <asm/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <asm/mach-types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include "soc_common.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define SG2_S0_POWER_CTL 108
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define SG2_S0_GPIO_RESET 82
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define SG2_S0_GPIO_DETECT 53
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define SG2_S0_GPIO_READY 81
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) static struct gpio sg2_pcmcia_gpios[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) { SG2_S0_GPIO_RESET, GPIOF_OUT_INIT_HIGH, "PCMCIA Reset" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) { SG2_S0_POWER_CTL, GPIOF_OUT_INIT_HIGH, "PCMCIA Power Ctrl" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) static int sg2_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) skt->stat[SOC_STAT_CD].gpio = SG2_S0_GPIO_DETECT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) skt->stat[SOC_STAT_CD].name = "PCMCIA0 CD";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) skt->stat[SOC_STAT_RDY].gpio = SG2_S0_GPIO_READY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) skt->stat[SOC_STAT_RDY].name = "PCMCIA0 RDY";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) static void sg2_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) struct pcmcia_state *state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) state->bvd1 = 0; /* not available - battery detect on card */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) state->bvd2 = 0; /* not available */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) state->vs_3v = 1; /* not available - voltage detect for card */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) state->vs_Xv = 0; /* not available */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) static int sg2_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) const socket_state_t *state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) /* Enable card power */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) switch (state->Vcc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) /* sets power ctl register high */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) gpio_set_value(SG2_S0_POWER_CTL, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) case 33:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) case 50:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) /* sets power control register low (clear) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) gpio_set_value(SG2_S0_POWER_CTL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) msleep(100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) pr_err("%s(): bad Vcc %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) __func__, state->Vcc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) /* reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) gpio_set_value(SG2_S0_GPIO_RESET, !!(state->flags & SS_RESET));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) static struct pcmcia_low_level sg2_pcmcia_ops __initdata = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) .hw_init = sg2_pcmcia_hw_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) .socket_state = sg2_pcmcia_socket_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) .configure_socket = sg2_pcmcia_configure_socket,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) .nr = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) static struct platform_device *sg2_pcmcia_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) static int __init sg2_pcmcia_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) if (!machine_is_stargate2())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) sg2_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) if (!sg2_pcmcia_device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) ret = gpio_request_array(sg2_pcmcia_gpios, ARRAY_SIZE(sg2_pcmcia_gpios));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) goto error_put_platform_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) ret = platform_device_add_data(sg2_pcmcia_device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) &sg2_pcmcia_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) sizeof(sg2_pcmcia_ops));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) goto error_free_gpios;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) ret = platform_device_add(sg2_pcmcia_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) goto error_free_gpios;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) error_free_gpios:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) gpio_free_array(sg2_pcmcia_gpios, ARRAY_SIZE(sg2_pcmcia_gpios));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) error_put_platform_device:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) platform_device_put(sg2_pcmcia_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) static void __exit sg2_pcmcia_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) platform_device_unregister(sg2_pcmcia_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) gpio_free_array(sg2_pcmcia_gpios, ARRAY_SIZE(sg2_pcmcia_gpios));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) fs_initcall(sg2_pcmcia_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) module_exit(sg2_pcmcia_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) MODULE_ALIAS("platform:pxa2xx-pcmcia");