| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * linux/drivers/pcmcia/pxa2xx_mainstone.c |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 6 | 7 | * Created: May 12, 2004 |
|---|
| 7 | 8 | * Author: Nicolas Pitre |
|---|
| 8 | 9 | * Copyright: MontaVista Software Inc. |
|---|
| 9 | | - * |
|---|
| 10 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 11 | | - * it under the terms of the GNU General Public License version 2 as |
|---|
| 12 | | - * published by the Free Software Foundation. |
|---|
| 13 | 10 | */ |
|---|
| 14 | | - |
|---|
| 11 | +#include <linux/gpio/consumer.h> |
|---|
| 15 | 12 | #include <linux/module.h> |
|---|
| 16 | 13 | #include <linux/init.h> |
|---|
| 14 | +#include <linux/interrupt.h> |
|---|
| 17 | 15 | #include <linux/kernel.h> |
|---|
| 18 | 16 | #include <linux/errno.h> |
|---|
| 19 | | -#include <linux/interrupt.h> |
|---|
| 20 | 17 | #include <linux/platform_device.h> |
|---|
| 21 | 18 | |
|---|
| 22 | 19 | #include <pcmcia/ss.h> |
|---|
| 23 | 20 | |
|---|
| 24 | 21 | #include <asm/mach-types.h> |
|---|
| 25 | | -#include <asm/irq.h> |
|---|
| 26 | | - |
|---|
| 27 | | -#include <mach/pxa2xx-regs.h> |
|---|
| 28 | | -#include <mach/mainstone.h> |
|---|
| 29 | 22 | |
|---|
| 30 | 23 | #include "soc_common.h" |
|---|
| 31 | | - |
|---|
| 24 | +#include "max1600.h" |
|---|
| 32 | 25 | |
|---|
| 33 | 26 | static int mst_pcmcia_hw_init(struct soc_pcmcia_socket *skt) |
|---|
| 34 | 27 | { |
|---|
| 35 | | - /* |
|---|
| 36 | | - * Setup default state of GPIO outputs |
|---|
| 37 | | - * before we enable them as outputs. |
|---|
| 38 | | - */ |
|---|
| 39 | | - if (skt->nr == 0) { |
|---|
| 40 | | - skt->socket.pci_irq = MAINSTONE_S0_IRQ; |
|---|
| 41 | | - skt->stat[SOC_STAT_CD].irq = MAINSTONE_S0_CD_IRQ; |
|---|
| 42 | | - skt->stat[SOC_STAT_CD].name = "PCMCIA0 CD"; |
|---|
| 43 | | - skt->stat[SOC_STAT_BVD1].irq = MAINSTONE_S0_STSCHG_IRQ; |
|---|
| 44 | | - skt->stat[SOC_STAT_BVD1].name = "PCMCIA0 STSCHG"; |
|---|
| 45 | | - } else { |
|---|
| 46 | | - skt->socket.pci_irq = MAINSTONE_S1_IRQ; |
|---|
| 47 | | - skt->stat[SOC_STAT_CD].irq = MAINSTONE_S1_CD_IRQ; |
|---|
| 48 | | - skt->stat[SOC_STAT_CD].name = "PCMCIA1 CD"; |
|---|
| 49 | | - skt->stat[SOC_STAT_BVD1].irq = MAINSTONE_S1_STSCHG_IRQ; |
|---|
| 50 | | - skt->stat[SOC_STAT_BVD1].name = "PCMCIA1 STSCHG"; |
|---|
| 51 | | - } |
|---|
| 52 | | - return 0; |
|---|
| 28 | + struct device *dev = skt->socket.dev.parent; |
|---|
| 29 | + struct max1600 *m; |
|---|
| 30 | + int ret; |
|---|
| 31 | + |
|---|
| 32 | + skt->stat[SOC_STAT_CD].name = skt->nr ? "bdetect" : "adetect"; |
|---|
| 33 | + skt->stat[SOC_STAT_BVD1].name = skt->nr ? "bbvd1" : "abvd1"; |
|---|
| 34 | + skt->stat[SOC_STAT_BVD2].name = skt->nr ? "bbvd2" : "abvd2"; |
|---|
| 35 | + skt->stat[SOC_STAT_RDY].name = skt->nr ? "bready" : "aready"; |
|---|
| 36 | + skt->stat[SOC_STAT_VS1].name = skt->nr ? "bvs1" : "avs1"; |
|---|
| 37 | + skt->stat[SOC_STAT_VS2].name = skt->nr ? "bvs2" : "avs2"; |
|---|
| 38 | + |
|---|
| 39 | + skt->gpio_reset = devm_gpiod_get(dev, skt->nr ? "breset" : "areset", |
|---|
| 40 | + GPIOD_OUT_HIGH); |
|---|
| 41 | + if (IS_ERR(skt->gpio_reset)) |
|---|
| 42 | + return PTR_ERR(skt->gpio_reset); |
|---|
| 43 | + |
|---|
| 44 | + ret = max1600_init(dev, &m, skt->nr ? MAX1600_CHAN_B : MAX1600_CHAN_A, |
|---|
| 45 | + MAX1600_CODE_HIGH); |
|---|
| 46 | + if (ret) |
|---|
| 47 | + return ret; |
|---|
| 48 | + |
|---|
| 49 | + skt->driver_data = m; |
|---|
| 50 | + |
|---|
| 51 | + return soc_pcmcia_request_gpiods(skt); |
|---|
| 53 | 52 | } |
|---|
| 54 | 53 | |
|---|
| 55 | | -static unsigned long mst_pcmcia_status[2]; |
|---|
| 54 | +static unsigned int mst_pcmcia_bvd1_status[2]; |
|---|
| 56 | 55 | |
|---|
| 57 | 56 | static void mst_pcmcia_socket_state(struct soc_pcmcia_socket *skt, |
|---|
| 58 | 57 | struct pcmcia_state *state) |
|---|
| 59 | 58 | { |
|---|
| 60 | | - unsigned long status, flip; |
|---|
| 61 | | - |
|---|
| 62 | | - status = (skt->nr == 0) ? MST_PCMCIA0 : MST_PCMCIA1; |
|---|
| 63 | | - flip = (status ^ mst_pcmcia_status[skt->nr]) & MST_PCMCIA_nSTSCHG_BVD1; |
|---|
| 59 | + unsigned int flip = mst_pcmcia_bvd1_status[skt->nr] ^ state->bvd1; |
|---|
| 64 | 60 | |
|---|
| 65 | 61 | /* |
|---|
| 66 | 62 | * Workaround for STSCHG which can't be deasserted: |
|---|
| .. | .. |
|---|
| 68 | 64 | * as needed to avoid IRQ locks. |
|---|
| 69 | 65 | */ |
|---|
| 70 | 66 | if (flip) { |
|---|
| 71 | | - mst_pcmcia_status[skt->nr] = status; |
|---|
| 72 | | - if (status & MST_PCMCIA_nSTSCHG_BVD1) |
|---|
| 73 | | - enable_irq( (skt->nr == 0) ? MAINSTONE_S0_STSCHG_IRQ |
|---|
| 74 | | - : MAINSTONE_S1_STSCHG_IRQ ); |
|---|
| 67 | + mst_pcmcia_bvd1_status[skt->nr] = state->bvd1; |
|---|
| 68 | + if (state->bvd1) |
|---|
| 69 | + enable_irq(skt->stat[SOC_STAT_BVD1].irq); |
|---|
| 75 | 70 | else |
|---|
| 76 | | - disable_irq( (skt->nr == 0) ? MAINSTONE_S0_STSCHG_IRQ |
|---|
| 77 | | - : MAINSTONE_S1_STSCHG_IRQ ); |
|---|
| 71 | + disable_irq(skt->stat[SOC_STAT_BVD2].irq); |
|---|
| 78 | 72 | } |
|---|
| 79 | | - |
|---|
| 80 | | - state->detect = (status & MST_PCMCIA_nCD) ? 0 : 1; |
|---|
| 81 | | - state->ready = (status & MST_PCMCIA_nIRQ) ? 1 : 0; |
|---|
| 82 | | - state->bvd1 = (status & MST_PCMCIA_nSTSCHG_BVD1) ? 1 : 0; |
|---|
| 83 | | - state->bvd2 = (status & MST_PCMCIA_nSPKR_BVD2) ? 1 : 0; |
|---|
| 84 | | - state->vs_3v = (status & MST_PCMCIA_nVS1) ? 0 : 1; |
|---|
| 85 | | - state->vs_Xv = (status & MST_PCMCIA_nVS2) ? 0 : 1; |
|---|
| 86 | 73 | } |
|---|
| 87 | 74 | |
|---|
| 88 | 75 | static int mst_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, |
|---|
| 89 | 76 | const socket_state_t *state) |
|---|
| 90 | 77 | { |
|---|
| 91 | | - unsigned long power = 0; |
|---|
| 92 | | - int ret = 0; |
|---|
| 93 | | - |
|---|
| 94 | | - switch (state->Vcc) { |
|---|
| 95 | | - case 0: power |= MST_PCMCIA_PWR_VCC_0; break; |
|---|
| 96 | | - case 33: power |= MST_PCMCIA_PWR_VCC_33; break; |
|---|
| 97 | | - case 50: power |= MST_PCMCIA_PWR_VCC_50; break; |
|---|
| 98 | | - default: |
|---|
| 99 | | - printk(KERN_ERR "%s(): bad Vcc %u\n", |
|---|
| 100 | | - __func__, state->Vcc); |
|---|
| 101 | | - ret = -1; |
|---|
| 102 | | - } |
|---|
| 103 | | - |
|---|
| 104 | | - switch (state->Vpp) { |
|---|
| 105 | | - case 0: power |= MST_PCMCIA_PWR_VPP_0; break; |
|---|
| 106 | | - case 120: power |= MST_PCMCIA_PWR_VPP_120; break; |
|---|
| 107 | | - default: |
|---|
| 108 | | - if(state->Vpp == state->Vcc) { |
|---|
| 109 | | - power |= MST_PCMCIA_PWR_VPP_VCC; |
|---|
| 110 | | - } else { |
|---|
| 111 | | - printk(KERN_ERR "%s(): bad Vpp %u\n", |
|---|
| 112 | | - __func__, state->Vpp); |
|---|
| 113 | | - ret = -1; |
|---|
| 114 | | - } |
|---|
| 115 | | - } |
|---|
| 116 | | - |
|---|
| 117 | | - if (state->flags & SS_RESET) |
|---|
| 118 | | - power |= MST_PCMCIA_RESET; |
|---|
| 119 | | - |
|---|
| 120 | | - switch (skt->nr) { |
|---|
| 121 | | - case 0: MST_PCMCIA0 = power; break; |
|---|
| 122 | | - case 1: MST_PCMCIA1 = power; break; |
|---|
| 123 | | - default: ret = -1; |
|---|
| 124 | | - } |
|---|
| 125 | | - |
|---|
| 126 | | - return ret; |
|---|
| 78 | + return max1600_configure(skt->driver_data, state->Vcc, state->Vpp); |
|---|
| 127 | 79 | } |
|---|
| 128 | 80 | |
|---|
| 129 | 81 | static struct pcmcia_low_level mst_pcmcia_ops __initdata = { |
|---|