^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_mainstone.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Mainstone PCMCIA specific routines.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Created: May 12, 2004
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Author: Nicolas Pitre
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Copyright: MontaVista Software Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/gpio/consumer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/interrupt.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/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <pcmcia/ss.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <asm/mach-types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include "soc_common.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include "max1600.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) static int mst_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) struct device *dev = skt->socket.dev.parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) struct max1600 *m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) skt->stat[SOC_STAT_CD].name = skt->nr ? "bdetect" : "adetect";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) skt->stat[SOC_STAT_BVD1].name = skt->nr ? "bbvd1" : "abvd1";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) skt->stat[SOC_STAT_BVD2].name = skt->nr ? "bbvd2" : "abvd2";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) skt->stat[SOC_STAT_RDY].name = skt->nr ? "bready" : "aready";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) skt->stat[SOC_STAT_VS1].name = skt->nr ? "bvs1" : "avs1";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) skt->stat[SOC_STAT_VS2].name = skt->nr ? "bvs2" : "avs2";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) skt->gpio_reset = devm_gpiod_get(dev, skt->nr ? "breset" : "areset",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) GPIOD_OUT_HIGH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) if (IS_ERR(skt->gpio_reset))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) return PTR_ERR(skt->gpio_reset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) ret = max1600_init(dev, &m, skt->nr ? MAX1600_CHAN_B : MAX1600_CHAN_A,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) MAX1600_CODE_HIGH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) skt->driver_data = m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) return soc_pcmcia_request_gpiods(skt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) static unsigned int mst_pcmcia_bvd1_status[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) static void mst_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) struct pcmcia_state *state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) unsigned int flip = mst_pcmcia_bvd1_status[skt->nr] ^ state->bvd1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * Workaround for STSCHG which can't be deasserted:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * We therefore disable/enable corresponding IRQs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * as needed to avoid IRQ locks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) if (flip) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) mst_pcmcia_bvd1_status[skt->nr] = state->bvd1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) if (state->bvd1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) enable_irq(skt->stat[SOC_STAT_BVD1].irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) disable_irq(skt->stat[SOC_STAT_BVD2].irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) static int mst_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) const socket_state_t *state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) return max1600_configure(skt->driver_data, state->Vcc, state->Vpp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) static struct pcmcia_low_level mst_pcmcia_ops __initdata = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) .hw_init = mst_pcmcia_hw_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) .socket_state = mst_pcmcia_socket_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) .configure_socket = mst_pcmcia_configure_socket,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) .nr = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) static struct platform_device *mst_pcmcia_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) static int __init mst_pcmcia_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) if (!machine_is_mainstone())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) mst_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) if (!mst_pcmcia_device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) ret = platform_device_add_data(mst_pcmcia_device, &mst_pcmcia_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) sizeof(mst_pcmcia_ops));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) if (ret == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) ret = platform_device_add(mst_pcmcia_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) platform_device_put(mst_pcmcia_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static void __exit mst_pcmcia_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) platform_device_unregister(mst_pcmcia_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) fs_initcall(mst_pcmcia_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) module_exit(mst_pcmcia_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) MODULE_ALIAS("platform:pxa2xx-pcmcia");