^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) * Copyright (C) 2012 Paul Parsons <lost.distance@yahoo.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/gpio.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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <asm/mach-types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <mach/hx4700.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) static struct gpio gpios[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) { GPIO114_HX4700_CF_RESET, GPIOF_OUT_INIT_LOW, "CF reset" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) { EGPIO4_CF_3V3_ON, GPIOF_OUT_INIT_LOW, "CF 3.3V enable" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) static int hx4700_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) ret = gpio_request_array(gpios, ARRAY_SIZE(gpios));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * IRQ type must be set before soc_pcmcia_hw_init() calls request_irq().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * The asic3 default IRQ type is level trigger low level detect, exactly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * the the signal present on GPIOD4_CF_nCD when a CF card is inserted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * If the IRQ type is not changed, the asic3 interrupt handler will loop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * repeatedly because it is unable to clear the level trigger interrupt.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) irq_set_irq_type(gpio_to_irq(GPIOD4_CF_nCD), IRQ_TYPE_EDGE_BOTH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) skt->stat[SOC_STAT_CD].gpio = GPIOD4_CF_nCD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) skt->stat[SOC_STAT_CD].name = "PCMCIA CD";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) skt->stat[SOC_STAT_RDY].gpio = GPIO60_HX4700_CF_RNB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) skt->stat[SOC_STAT_RDY].name = "PCMCIA Ready";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) static void hx4700_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) gpio_free_array(gpios, ARRAY_SIZE(gpios));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) static void hx4700_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) struct pcmcia_state *state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) state->vs_3v = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) state->vs_Xv = 0;
^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 hx4700_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 (state->Vcc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) gpio_set_value(EGPIO4_CF_3V3_ON, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) case 33:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) gpio_set_value(EGPIO4_CF_3V3_ON, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) printk(KERN_ERR "pcmcia: Unsupported Vcc: %d\n", state->Vcc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) return -EINVAL;
^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) gpio_set_value(GPIO114_HX4700_CF_RESET, (state->flags & SS_RESET) != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) static struct pcmcia_low_level hx4700_pcmcia_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) .nr = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) .hw_init = hx4700_pcmcia_hw_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) .hw_shutdown = hx4700_pcmcia_hw_shutdown,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) .socket_state = hx4700_pcmcia_socket_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) .configure_socket = hx4700_pcmcia_configure_socket,
^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 *hx4700_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 hx4700_pcmcia_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) struct platform_device *pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) if (!machine_is_h4700())
^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) pdev = platform_device_register_data(NULL, "pxa2xx-pcmcia", -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) &hx4700_pcmcia_ops, sizeof(hx4700_pcmcia_ops));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) if (IS_ERR(pdev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) return PTR_ERR(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) hx4700_pcmcia_device = pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) static void __exit hx4700_pcmcia_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) platform_device_unregister(hx4700_pcmcia_device);
^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) module_init(hx4700_pcmcia_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) module_exit(hx4700_pcmcia_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) MODULE_AUTHOR("Paul Parsons <lost.distance@yahoo.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) MODULE_DESCRIPTION("HP iPAQ hx4700 PCMCIA driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) MODULE_LICENSE("GPL");