Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * linux/drivers/pcmcia/pxa2xx_trizeps4.c
0004  *
0005  * TRIZEPS PCMCIA specific routines.
0006  *
0007  * Author:  Jürgen Schindele
0008  * Created: 20 02, 2006
0009  * Copyright:   Jürgen Schindele
0010  */
0011 
0012 #include <linux/module.h>
0013 #include <linux/init.h>
0014 #include <linux/kernel.h>
0015 #include <linux/gpio.h>
0016 #include <linux/interrupt.h>
0017 #include <linux/platform_device.h>
0018 
0019 #include <asm/mach-types.h>
0020 #include <asm/irq.h>
0021 
0022 #include "pxa2xx-regs.h"
0023 #include "trizeps4.h"
0024 
0025 #include <pcmcia/soc_common.h>
0026 
0027 extern void board_pcmcia_power(int power);
0028 
0029 static int trizeps_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
0030 {
0031     /* we dont have voltage/card/ready detection
0032      * so we dont need interrupts for it
0033      */
0034     switch (skt->nr) {
0035     case 0:
0036         skt->stat[SOC_STAT_CD].gpio = GPIO_PCD;
0037         skt->stat[SOC_STAT_CD].name = "cs0_cd";
0038         skt->stat[SOC_STAT_RDY].gpio = GPIO_PRDY;
0039         skt->stat[SOC_STAT_RDY].name = "cs0_rdy";
0040         break;
0041     default:
0042         break;
0043     }
0044     /* release the reset of this card */
0045     pr_debug("%s: sock %d irq %d\n", __func__, skt->nr, skt->socket.pci_irq);
0046 
0047     return 0;
0048 }
0049 
0050 static unsigned long trizeps_pcmcia_status[2];
0051 
0052 static void trizeps_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
0053                 struct pcmcia_state *state)
0054 {
0055     unsigned short status = 0, change;
0056     status = CFSR_readw();
0057     change = (status ^ trizeps_pcmcia_status[skt->nr]) &
0058                 ConXS_CFSR_BVD_MASK;
0059     if (change) {
0060         trizeps_pcmcia_status[skt->nr] = status;
0061         if (status & ConXS_CFSR_BVD1) {
0062             /* enable_irq empty */
0063         } else {
0064             /* disable_irq empty */
0065         }
0066     }
0067 
0068     switch (skt->nr) {
0069     case 0:
0070         /* just fill in fix states */
0071         state->bvd1   = (status & ConXS_CFSR_BVD1) ? 1 : 0;
0072         state->bvd2   = (status & ConXS_CFSR_BVD2) ? 1 : 0;
0073         state->vs_3v  = (status & ConXS_CFSR_VS1) ? 0 : 1;
0074         state->vs_Xv  = (status & ConXS_CFSR_VS2) ? 0 : 1;
0075         break;
0076 
0077 #ifndef CONFIG_MACH_TRIZEPS_CONXS
0078     /* on ConXS we only have one slot. Second is inactive */
0079     case 1:
0080         state->detect = 0;
0081         state->ready  = 0;
0082         state->bvd1   = 0;
0083         state->bvd2   = 0;
0084         state->vs_3v  = 0;
0085         state->vs_Xv  = 0;
0086         break;
0087 
0088 #endif
0089     }
0090 }
0091 
0092 static int trizeps_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
0093                 const socket_state_t *state)
0094 {
0095     int ret = 0;
0096     unsigned short power = 0;
0097 
0098     /* we do nothing here just check a bit */
0099     switch (state->Vcc) {
0100     case 0:  power &= 0xfc; break;
0101     case 33: power |= ConXS_BCR_S0_VCC_3V3; break;
0102     case 50:
0103         pr_err("%s(): Vcc 5V not supported in socket\n", __func__);
0104         break;
0105     default:
0106         pr_err("%s(): bad Vcc %u\n", __func__, state->Vcc);
0107         ret = -1;
0108     }
0109 
0110     switch (state->Vpp) {
0111     case 0:  power &= 0xf3; break;
0112     case 33: power |= ConXS_BCR_S0_VPP_3V3; break;
0113     case 120:
0114         pr_err("%s(): Vpp 12V not supported in socket\n", __func__);
0115         break;
0116     default:
0117         if (state->Vpp != state->Vcc) {
0118             pr_err("%s(): bad Vpp %u\n", __func__, state->Vpp);
0119             ret = -1;
0120         }
0121     }
0122 
0123     switch (skt->nr) {
0124     case 0:          /* we only have 3.3V */
0125         board_pcmcia_power(power);
0126         break;
0127 
0128 #ifndef CONFIG_MACH_TRIZEPS_CONXS
0129     /* on ConXS we only have one slot. Second is inactive */
0130     case 1:
0131 #endif
0132     default:
0133         break;
0134     }
0135 
0136     return ret;
0137 }
0138 
0139 static void trizeps_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
0140 {
0141     /* default is on */
0142     board_pcmcia_power(0x9);
0143 }
0144 
0145 static void trizeps_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
0146 {
0147     board_pcmcia_power(0x0);
0148 }
0149 
0150 static struct pcmcia_low_level trizeps_pcmcia_ops = {
0151     .owner          = THIS_MODULE,
0152     .hw_init        = trizeps_pcmcia_hw_init,
0153     .socket_state       = trizeps_pcmcia_socket_state,
0154     .configure_socket   = trizeps_pcmcia_configure_socket,
0155     .socket_init        = trizeps_pcmcia_socket_init,
0156     .socket_suspend     = trizeps_pcmcia_socket_suspend,
0157 #ifdef CONFIG_MACH_TRIZEPS_CONXS
0158     .nr         = 1,
0159 #else
0160     .nr         = 2,
0161 #endif
0162     .first          = 0,
0163 };
0164 
0165 static struct platform_device *trizeps_pcmcia_device;
0166 
0167 static int __init trizeps_pcmcia_init(void)
0168 {
0169     int ret;
0170 
0171     if (!machine_is_trizeps4() && !machine_is_trizeps4wl())
0172         return -ENODEV;
0173 
0174     trizeps_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
0175     if (!trizeps_pcmcia_device)
0176         return -ENOMEM;
0177 
0178     ret = platform_device_add_data(trizeps_pcmcia_device,
0179             &trizeps_pcmcia_ops, sizeof(trizeps_pcmcia_ops));
0180 
0181     if (ret == 0)
0182         ret = platform_device_add(trizeps_pcmcia_device);
0183 
0184     if (ret)
0185         platform_device_put(trizeps_pcmcia_device);
0186 
0187     return ret;
0188 }
0189 
0190 static void __exit trizeps_pcmcia_exit(void)
0191 {
0192     platform_device_unregister(trizeps_pcmcia_device);
0193 }
0194 
0195 fs_initcall(trizeps_pcmcia_init);
0196 module_exit(trizeps_pcmcia_exit);
0197 
0198 MODULE_LICENSE("GPL");
0199 MODULE_AUTHOR("Juergen Schindele");
0200 MODULE_ALIAS("platform:pxa2xx-pcmcia");