^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * drivers/pcmcia/sa1100_h3600.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * PCMCIA implementation routines for H3600
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/gpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <mach/hardware.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <asm/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <asm/mach-types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <mach/h3xxx.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include "sa1100_generic.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) static int h3600_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) skt->stat[SOC_STAT_CD].name = skt->nr ? "pcmcia1-detect" : "pcmcia0-detect";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) skt->stat[SOC_STAT_RDY].name = skt->nr ? "pcmcia1-ready" : "pcmcia0-ready";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) err = soc_pcmcia_request_gpiods(skt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) switch (skt->nr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) err = gpio_request(H3XXX_EGPIO_OPT_NVRAM_ON, "OPT NVRAM ON");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) goto err01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) err = gpio_direction_output(H3XXX_EGPIO_OPT_NVRAM_ON, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) goto err03;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) err = gpio_request(H3XXX_EGPIO_OPT_ON, "OPT ON");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) goto err03;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) err = gpio_direction_output(H3XXX_EGPIO_OPT_ON, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) goto err04;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) err = gpio_request(H3XXX_EGPIO_OPT_RESET, "OPT RESET");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) goto err04;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) err = gpio_direction_output(H3XXX_EGPIO_OPT_RESET, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) goto err05;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) err = gpio_request(H3XXX_EGPIO_CARD_RESET, "PCMCIA CARD RESET");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) goto err05;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) err = gpio_direction_output(H3XXX_EGPIO_CARD_RESET, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) goto err06;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) err06: gpio_free(H3XXX_EGPIO_CARD_RESET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) err05: gpio_free(H3XXX_EGPIO_OPT_RESET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) err04: gpio_free(H3XXX_EGPIO_OPT_ON);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) err03: gpio_free(H3XXX_EGPIO_OPT_NVRAM_ON);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) err01: gpio_free(H3XXX_GPIO_PCMCIA_IRQ0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) return err;
^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) static void h3600_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) switch (skt->nr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) /* Disable CF bus: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) gpio_set_value(H3XXX_EGPIO_OPT_NVRAM_ON, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) gpio_set_value(H3XXX_EGPIO_OPT_ON, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) gpio_set_value(H3XXX_EGPIO_OPT_RESET, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) gpio_free(H3XXX_EGPIO_CARD_RESET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) gpio_free(H3XXX_EGPIO_OPT_RESET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) gpio_free(H3XXX_EGPIO_OPT_ON);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) gpio_free(H3XXX_EGPIO_OPT_NVRAM_ON);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) h3600_pcmcia_socket_state(struct soc_pcmcia_socket *skt, struct pcmcia_state *state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) state->bvd1 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) state->bvd2 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) state->vs_3v = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) state->vs_Xv = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) h3600_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, const socket_state_t *state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) if (state->Vcc != 0 && state->Vcc != 33 && state->Vcc != 50) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) printk(KERN_ERR "h3600_pcmcia: unrecognized Vcc %u.%uV\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) state->Vcc / 10, state->Vcc % 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) gpio_set_value(H3XXX_EGPIO_CARD_RESET, !!(state->flags & SS_RESET));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) /* Silently ignore Vpp, output enable, speaker enable. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) return 0;
^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) static void h3600_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) /* Enable CF bus: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) gpio_set_value(H3XXX_EGPIO_OPT_NVRAM_ON, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) gpio_set_value(H3XXX_EGPIO_OPT_ON, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) gpio_set_value(H3XXX_EGPIO_OPT_RESET, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) msleep(10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) static void h3600_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) * FIXME: This doesn't fit well. We don't have the mechanism in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) * the generic PCMCIA layer to deal with the idea of two sockets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) * on one bus. We rely on the cs.c behaviour shutting down
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) * socket 0 then socket 1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) if (skt->nr == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) gpio_set_value(H3XXX_EGPIO_OPT_ON, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) gpio_set_value(H3XXX_EGPIO_OPT_NVRAM_ON, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) /* hmm, does this suck power? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) gpio_set_value(H3XXX_EGPIO_OPT_RESET, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) struct pcmcia_low_level h3600_pcmcia_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) .hw_init = h3600_pcmcia_hw_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) .hw_shutdown = h3600_pcmcia_hw_shutdown,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) .socket_state = h3600_pcmcia_socket_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) .configure_socket = h3600_pcmcia_configure_socket,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) .socket_init = h3600_pcmcia_socket_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) .socket_suspend = h3600_pcmcia_socket_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) int pcmcia_h3600_init(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) int ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) if (machine_is_h3600() || machine_is_h3100())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) ret = sa11xx_drv_pcmcia_probe(dev, &h3600_pcmcia_ops, 0, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }