Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /*======================================================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)     Common support code for the PCMCIA control functionality of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)     integrated SOCs like the SA-11x0 and PXA2xx microprocessors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)     The contents of this file are subject to the Mozilla Public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)     License Version 1.1 (the "License"); you may not use this file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)     except in compliance with the License. You may obtain a copy of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)     the License at http://www.mozilla.org/MPL/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)     Software distributed under the License is distributed on an "AS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)     IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)     implied. See the License for the specific language governing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)     rights and limitations under the License.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)     The initial developer of the original code is John G. Dorsey
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)     <john+@cs.cmu.edu>.  Portions created by John G. Dorsey are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)     Copyright (C) 1999 John G. Dorsey.  All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)     Alternatively, the contents of this file may be used under the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)     terms of the GNU Public License version 2 (the "GPL"), in which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)     case the provisions of the GPL are applicable instead of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)     above.  If you wish to allow the use of your version of this file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)     only under the terms of the GPL and not to allow others to use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)     your version of this file under the MPL, indicate your decision
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)     by deleting the provisions above and replace them with the notice
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)     and other provisions required by the GPL.  If you do not delete
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)     the provisions above, a recipient may use your version of this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)     file under either the MPL or the GPL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) ======================================================================*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #include <linux/cpufreq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #include <linux/gpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #include <linux/gpio/consumer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #include <linux/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #include <linux/moduleparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #include <linux/regulator/consumer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) #include <mach/hardware.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) #include "soc_common.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) static irqreturn_t soc_common_pcmcia_interrupt(int irq, void *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) #ifdef CONFIG_PCMCIA_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) static int pc_debug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) module_param(pc_debug, int, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) void soc_pcmcia_debug(struct soc_pcmcia_socket *skt, const char *func,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		      int lvl, const char *fmt, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	struct va_format vaf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	va_list args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	if (pc_debug > lvl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		va_start(args, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		vaf.fmt = fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		vaf.va = &args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		printk(KERN_DEBUG "skt%u: %s: %pV", skt->nr, func, &vaf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		va_end(args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) EXPORT_SYMBOL(soc_pcmcia_debug);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) #define to_soc_pcmcia_socket(x)	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	container_of(x, struct soc_pcmcia_socket, socket)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) int soc_pcmcia_regulator_set(struct soc_pcmcia_socket *skt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	struct soc_pcmcia_regulator *r, int v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	bool on;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	if (!r->reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	on = v != 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	if (r->on == on)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	if (on) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		ret = regulator_set_voltage(r->reg, v * 100000, v * 100000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 			int vout = regulator_get_voltage(r->reg) / 100000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 			dev_warn(&skt->socket.dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 				 "CS requested %s=%u.%uV, applying %u.%uV\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 				 r == &skt->vcc ? "Vcc" : "Vpp",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 				 v / 10, v % 10, vout / 10, vout % 10);
^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) 		ret = regulator_enable(r->reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		ret = regulator_disable(r->reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	if (ret == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		r->on = on;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) EXPORT_SYMBOL_GPL(soc_pcmcia_regulator_set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) static unsigned short
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) calc_speed(unsigned short *spds, int num, unsigned short dflt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	unsigned short speed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	for (i = 0; i < num; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		if (speed < spds[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 			speed = spds[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	if (speed == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		speed = dflt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	return speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) void soc_common_pcmcia_get_timing(struct soc_pcmcia_socket *skt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	struct soc_pcmcia_timing *timing)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	timing->io =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		calc_speed(skt->spd_io, MAX_IO_WIN, SOC_PCMCIA_IO_ACCESS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	timing->mem =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		calc_speed(skt->spd_mem, MAX_WIN, SOC_PCMCIA_3V_MEM_ACCESS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	timing->attr =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		calc_speed(skt->spd_attr, MAX_WIN, SOC_PCMCIA_3V_MEM_ACCESS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) EXPORT_SYMBOL(soc_common_pcmcia_get_timing);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) static void __soc_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	unsigned int nr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	for (i = 0; i < nr; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		if (skt->stat[i].irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 			free_irq(skt->stat[i].irq, skt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	if (skt->ops->hw_shutdown)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		skt->ops->hw_shutdown(skt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	clk_disable_unprepare(skt->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) static void soc_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	__soc_pcmcia_hw_shutdown(skt, ARRAY_SIZE(skt->stat));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) int soc_pcmcia_request_gpiods(struct soc_pcmcia_socket *skt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	struct device *dev = skt->socket.dev.parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	struct gpio_desc *desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	for (i = 0; i < ARRAY_SIZE(skt->stat); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		if (!skt->stat[i].name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		desc = devm_gpiod_get(dev, skt->stat[i].name, GPIOD_IN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		if (IS_ERR(desc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 			dev_err(dev, "Failed to get GPIO for %s: %ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 				skt->stat[i].name, PTR_ERR(desc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 			return PTR_ERR(desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		skt->stat[i].desc = desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) EXPORT_SYMBOL_GPL(soc_pcmcia_request_gpiods);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) static int soc_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	int ret = 0, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	ret = clk_prepare_enable(skt->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	if (skt->ops->hw_init) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		ret = skt->ops->hw_init(skt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 			clk_disable_unprepare(skt->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	for (i = 0; i < ARRAY_SIZE(skt->stat); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		if (gpio_is_valid(skt->stat[i].gpio)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 			unsigned long flags = GPIOF_IN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 			/* CD is active low by default */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 			if (i == SOC_STAT_CD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 				flags |= GPIOF_ACTIVE_LOW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 			ret = devm_gpio_request_one(skt->socket.dev.parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 						    skt->stat[i].gpio, flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 						    skt->stat[i].name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 			if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 				__soc_pcmcia_hw_shutdown(skt, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 				return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 			skt->stat[i].desc = gpio_to_desc(skt->stat[i].gpio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		if (i < SOC_STAT_VS1 && skt->stat[i].desc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 			int irq = gpiod_to_irq(skt->stat[i].desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 			if (irq > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 				if (i == SOC_STAT_RDY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 					skt->socket.pci_irq = irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 				else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 					skt->stat[i].irq = irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		if (skt->stat[i].irq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 			ret = request_irq(skt->stat[i].irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 					  soc_common_pcmcia_interrupt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 					  IRQF_TRIGGER_NONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 					  skt->stat[i].name, skt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 			if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 				__soc_pcmcia_hw_shutdown(skt, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 				return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) static void soc_pcmcia_hw_enable(struct soc_pcmcia_socket *skt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	for (i = 0; i < ARRAY_SIZE(skt->stat); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		if (skt->stat[i].irq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 			irq_set_irq_type(skt->stat[i].irq, IRQ_TYPE_EDGE_RISING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 			irq_set_irq_type(skt->stat[i].irq, IRQ_TYPE_EDGE_BOTH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) static void soc_pcmcia_hw_disable(struct soc_pcmcia_socket *skt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	for (i = 0; i < ARRAY_SIZE(skt->stat); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		if (skt->stat[i].irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 			irq_set_irq_type(skt->stat[i].irq, IRQ_TYPE_NONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)  * The CF 3.0 specification says that cards tie VS1 to ground and leave
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)  * VS2 open.  Many implementations do not wire up the VS signals, so we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)  * provide hard-coded values as per the CF 3.0 spec.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) void soc_common_cf_socket_state(struct soc_pcmcia_socket *skt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	struct pcmcia_state *state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	state->vs_3v = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) EXPORT_SYMBOL_GPL(soc_common_cf_socket_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) static unsigned int soc_common_pcmcia_skt_state(struct soc_pcmcia_socket *skt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	struct pcmcia_state state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	unsigned int stat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	memset(&state, 0, sizeof(struct pcmcia_state));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	/* Make battery voltage state report 'good' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	state.bvd1 = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	state.bvd2 = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	if (skt->stat[SOC_STAT_CD].desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		state.detect = !!gpiod_get_value(skt->stat[SOC_STAT_CD].desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	if (skt->stat[SOC_STAT_RDY].desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		state.ready = !!gpiod_get_value(skt->stat[SOC_STAT_RDY].desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	if (skt->stat[SOC_STAT_BVD1].desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		state.bvd1 = !!gpiod_get_value(skt->stat[SOC_STAT_BVD1].desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	if (skt->stat[SOC_STAT_BVD2].desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		state.bvd2 = !!gpiod_get_value(skt->stat[SOC_STAT_BVD2].desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	if (skt->stat[SOC_STAT_VS1].desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		state.vs_3v = !!gpiod_get_value(skt->stat[SOC_STAT_VS1].desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	if (skt->stat[SOC_STAT_VS2].desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		state.vs_Xv = !!gpiod_get_value(skt->stat[SOC_STAT_VS2].desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	skt->ops->socket_state(skt, &state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	stat = state.detect  ? SS_DETECT : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	stat |= state.ready  ? SS_READY  : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	stat |= state.wrprot ? SS_WRPROT : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	stat |= state.vs_3v  ? SS_3VCARD : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	stat |= state.vs_Xv  ? SS_XVCARD : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	/* The power status of individual sockets is not available
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	 * explicitly from the hardware, so we just remember the state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	 * and regurgitate it upon request:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	stat |= skt->cs_state.Vcc ? SS_POWERON : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	if (skt->cs_state.flags & SS_IOCARD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 		stat |= state.bvd1 ? 0 : SS_STSCHG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		if (state.bvd1 == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 			stat |= SS_BATDEAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 		else if (state.bvd2 == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 			stat |= SS_BATWARN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	return stat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)  * soc_common_pcmcia_config_skt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)  * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)  * Convert PCMCIA socket state to our socket configure structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) static int soc_common_pcmcia_config_skt(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	struct soc_pcmcia_socket *skt, socket_state_t *state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	ret = skt->ops->configure_socket(skt, state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 		pr_err("soc_common_pcmcia: unable to configure socket %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 		       skt->nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 		/* restore the previous state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 		WARN_ON(skt->ops->configure_socket(skt, &skt->cs_state));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	if (ret == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 		struct gpio_desc *descs[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 		DECLARE_BITMAP(values, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 		int n = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 		if (skt->gpio_reset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 			descs[n] = skt->gpio_reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 			__assign_bit(n++, values, state->flags & SS_RESET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		if (skt->gpio_bus_enable) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 			descs[n] = skt->gpio_bus_enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 			__assign_bit(n++, values, state->flags & SS_OUTPUT_ENA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 		if (n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 			gpiod_set_array_value_cansleep(n, descs, NULL, values);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 		 * This really needs a better solution.  The IRQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 		 * may or may not be claimed by the driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 		if (skt->irq_state != 1 && state->io_irq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 			skt->irq_state = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 			irq_set_irq_type(skt->socket.pci_irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 					 IRQ_TYPE_EDGE_FALLING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 		} else if (skt->irq_state == 1 && state->io_irq == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 			skt->irq_state = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 			irq_set_irq_type(skt->socket.pci_irq, IRQ_TYPE_NONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 		skt->cs_state = *state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) /* soc_common_pcmcia_sock_init()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)  * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)  * (Re-)Initialise the socket, turning on status interrupts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)  * and PCMCIA bus.  This must wait for power to stabilise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)  * so that the card status signals report correctly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)  * Returns: 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) static int soc_common_pcmcia_sock_init(struct pcmcia_socket *sock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	debug(skt, 2, "initializing socket\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	if (skt->ops->socket_init)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 		skt->ops->socket_init(skt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	soc_pcmcia_hw_enable(skt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)  * soc_common_pcmcia_suspend()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)  * ^^^^^^^^^^^^^^^^^^^^^^^^^^^
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)  * Remove power on the socket, disable IRQs from the card.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414)  * Turn off status interrupts, and disable the PCMCIA bus.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)  * Returns: 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) static int soc_common_pcmcia_suspend(struct pcmcia_socket *sock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	debug(skt, 2, "suspending socket\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	soc_pcmcia_hw_disable(skt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	if (skt->ops->socket_suspend)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 		skt->ops->socket_suspend(skt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) static DEFINE_SPINLOCK(status_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) static void soc_common_check_status(struct soc_pcmcia_socket *skt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	unsigned int events;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	debug(skt, 4, "entering PCMCIA monitoring thread\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 		unsigned int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 		unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 		status = soc_common_pcmcia_skt_state(skt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 		spin_lock_irqsave(&status_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 		events = (status ^ skt->status) & skt->cs_state.csc_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 		skt->status = status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 		spin_unlock_irqrestore(&status_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 		debug(skt, 4, "events: %s%s%s%s%s%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 			events == 0         ? "<NONE>"   : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 			events & SS_DETECT  ? "DETECT "  : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 			events & SS_READY   ? "READY "   : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 			events & SS_BATDEAD ? "BATDEAD " : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 			events & SS_BATWARN ? "BATWARN " : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 			events & SS_STSCHG  ? "STSCHG "  : "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 		if (events)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 			pcmcia_parse_events(&skt->socket, events);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	} while (events);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) /* Let's poll for events in addition to IRQs since IRQ only is unreliable... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) static void soc_common_pcmcia_poll_event(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	struct soc_pcmcia_socket *skt = from_timer(skt, t, poll_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	debug(skt, 4, "polling for events\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	mod_timer(&skt->poll_timer, jiffies + SOC_PCMCIA_POLL_PERIOD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	soc_common_check_status(skt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)  * Service routine for socket driver interrupts (requested by the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)  * low-level PCMCIA init() operation via soc_common_pcmcia_thread()).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478)  * The actual interrupt-servicing work is performed by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)  * soc_common_pcmcia_thread(), largely because the Card Services event-
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480)  * handling code performs scheduling operations which cannot be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481)  * executed from within an interrupt context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) static irqreturn_t soc_common_pcmcia_interrupt(int irq, void *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	struct soc_pcmcia_socket *skt = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	debug(skt, 3, "servicing IRQ %d\n", irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 	soc_common_check_status(skt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)  *  Implements the get_status() operation for the in-kernel PCMCIA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497)  * service (formerly SS_GetStatus in Card Services). Essentially just
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498)  * fills in bits in `status' according to internal driver state or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499)  * the value of the voltage detect chipselect register.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)  * As a debugging note, during card startup, the PCMCIA core issues
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502)  * three set_socket() commands in a row the first with RESET deasserted,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)  * the second with RESET asserted, and the last with RESET deasserted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504)  * again. Following the third set_socket(), a get_status() command will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505)  * be issued. The kernel is looking for the SS_READY flag (see
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506)  * setup_socket(), reset_socket(), and unreset_socket() in cs.c).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508)  * Returns: 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) soc_common_pcmcia_get_status(struct pcmcia_socket *sock, unsigned int *status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 	skt->status = soc_common_pcmcia_skt_state(skt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	*status = skt->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523)  * Implements the set_socket() operation for the in-kernel PCMCIA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524)  * service (formerly SS_SetSocket in Card Services). We more or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525)  * less punt all of this work and let the kernel handle the details
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526)  * of power configuration, reset, &c. We also record the value of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527)  * `state' in order to regurgitate it to the PCMCIA core later.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) static int soc_common_pcmcia_set_socket(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 	struct pcmcia_socket *sock, socket_state_t *state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 	struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	debug(skt, 2, "mask: %s%s%s%s%s%s flags: %s%s%s%s%s%s Vcc %d Vpp %d irq %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 			(state->csc_mask == 0)		? "<NONE> " :	"",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 			(state->csc_mask & SS_DETECT)	? "DETECT " :	"",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 			(state->csc_mask & SS_READY)	? "READY " :	"",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 			(state->csc_mask & SS_BATDEAD)	? "BATDEAD " :	"",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 			(state->csc_mask & SS_BATWARN)	? "BATWARN " :	"",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 			(state->csc_mask & SS_STSCHG)	? "STSCHG " :	"",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 			(state->flags == 0)		? "<NONE> " :	"",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 			(state->flags & SS_PWR_AUTO)	? "PWR_AUTO " :	"",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 			(state->flags & SS_IOCARD)	? "IOCARD " :	"",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 			(state->flags & SS_RESET)	? "RESET " :	"",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 			(state->flags & SS_SPKR_ENA)	? "SPKR_ENA " :	"",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 			(state->flags & SS_OUTPUT_ENA)	? "OUTPUT_ENA " : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 			state->Vcc, state->Vpp, state->io_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 	return soc_common_pcmcia_config_skt(skt, state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554)  * Implements the set_io_map() operation for the in-kernel PCMCIA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555)  * service (formerly SS_SetIOMap in Card Services). We configure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556)  * the map speed as requested, but override the address ranges
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557)  * supplied by Card Services.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559)  * Returns: 0 on success, -1 on error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) static int soc_common_pcmcia_set_io_map(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 	struct pcmcia_socket *sock, struct pccard_io_map *map)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 	struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 	unsigned short speed = map->speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 	debug(skt, 2, "map %u  speed %u start 0x%08llx stop 0x%08llx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 		map->map, map->speed, (unsigned long long)map->start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 		(unsigned long long)map->stop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 	debug(skt, 2, "flags: %s%s%s%s%s%s%s%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 		(map->flags == 0)		? "<NONE>"	: "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 		(map->flags & MAP_ACTIVE)	? "ACTIVE "	: "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 		(map->flags & MAP_16BIT)	? "16BIT "	: "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 		(map->flags & MAP_AUTOSZ)	? "AUTOSZ "	: "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 		(map->flags & MAP_0WS)		? "0WS "	: "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 		(map->flags & MAP_WRPROT)	? "WRPROT "	: "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 		(map->flags & MAP_USE_WAIT)	? "USE_WAIT "	: "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 		(map->flags & MAP_PREFETCH)	? "PREFETCH "	: "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 	if (map->map >= MAX_IO_WIN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 		printk(KERN_ERR "%s(): map (%d) out of range\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 		       map->map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 	if (map->flags & MAP_ACTIVE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 		if (speed == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 			speed = SOC_PCMCIA_IO_ACCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 		speed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 	skt->spd_io[map->map] = speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 	skt->ops->set_timing(skt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 	if (map->stop == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 		map->stop = PAGE_SIZE-1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 	map->stop -= map->start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 	map->stop += skt->socket.io_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 	map->start = skt->socket.io_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608)  * Implements the set_mem_map() operation for the in-kernel PCMCIA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609)  * service (formerly SS_SetMemMap in Card Services). We configure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610)  * the map speed as requested, but override the address ranges
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611)  * supplied by Card Services.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613)  * Returns: 0 on success, -ERRNO on error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) static int soc_common_pcmcia_set_mem_map(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 	struct pcmcia_socket *sock, struct pccard_mem_map *map)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 	struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 	struct resource *res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 	unsigned short speed = map->speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 	debug(skt, 2, "map %u speed %u card_start %08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 		map->map, map->speed, map->card_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 	debug(skt, 2, "flags: %s%s%s%s%s%s%s%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 		(map->flags == 0)		? "<NONE>"	: "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 		(map->flags & MAP_ACTIVE)	? "ACTIVE "	: "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 		(map->flags & MAP_16BIT)	? "16BIT "	: "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 		(map->flags & MAP_AUTOSZ)	? "AUTOSZ "	: "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 		(map->flags & MAP_0WS)		? "0WS "	: "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 		(map->flags & MAP_WRPROT)	? "WRPROT "	: "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 		(map->flags & MAP_ATTRIB)	? "ATTRIB "	: "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 		(map->flags & MAP_USE_WAIT)	? "USE_WAIT "	: "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 	if (map->map >= MAX_WIN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 	if (map->flags & MAP_ACTIVE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 		if (speed == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 			speed = 300;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 		speed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 	if (map->flags & MAP_ATTRIB) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 		res = &skt->res_attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 		skt->spd_attr[map->map] = speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 		skt->spd_mem[map->map] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 		res = &skt->res_mem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 		skt->spd_attr[map->map] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 		skt->spd_mem[map->map] = speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 	skt->ops->set_timing(skt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 	map->static_start = res->start + map->card_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) struct bittbl {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 	unsigned int mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 	const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) static struct bittbl status_bits[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 	{ SS_WRPROT,		"SS_WRPROT"	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 	{ SS_BATDEAD,		"SS_BATDEAD"	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 	{ SS_BATWARN,		"SS_BATWARN"	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 	{ SS_READY,		"SS_READY"	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 	{ SS_DETECT,		"SS_DETECT"	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 	{ SS_POWERON,		"SS_POWERON"	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 	{ SS_STSCHG,		"SS_STSCHG"	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 	{ SS_3VCARD,		"SS_3VCARD"	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 	{ SS_XVCARD,		"SS_XVCARD"	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) static struct bittbl conf_bits[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 	{ SS_PWR_AUTO,		"SS_PWR_AUTO"	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 	{ SS_IOCARD,		"SS_IOCARD"	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 	{ SS_RESET,		"SS_RESET"	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 	{ SS_DMA_MODE,		"SS_DMA_MODE"	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 	{ SS_SPKR_ENA,		"SS_SPKR_ENA"	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 	{ SS_OUTPUT_ENA,	"SS_OUTPUT_ENA"	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) static void dump_bits(char **p, const char *prefix,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 	unsigned int val, struct bittbl *bits, int sz)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 	char *b = *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) 	b += sprintf(b, "%-9s:", prefix);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 	for (i = 0; i < sz; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 		if (val & bits[i].mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 			b += sprintf(b, " %s", bits[i].name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) 	*b++ = '\n';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) 	*p = b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702)  * Implements the /sys/class/pcmcia_socket/??/status file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704)  * Returns: the number of characters added to the buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) static ssize_t show_status(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 	struct device *dev, struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) 	struct soc_pcmcia_socket *skt =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 		container_of(dev, struct soc_pcmcia_socket, socket.dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) 	char *p = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 	p += sprintf(p, "slot     : %d\n", skt->nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) 	dump_bits(&p, "status", skt->status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) 		  status_bits, ARRAY_SIZE(status_bits));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) 	dump_bits(&p, "csc_mask", skt->cs_state.csc_mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) 		  status_bits, ARRAY_SIZE(status_bits));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) 	dump_bits(&p, "cs_flags", skt->cs_state.flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) 		  conf_bits, ARRAY_SIZE(conf_bits));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) 	p += sprintf(p, "Vcc      : %d\n", skt->cs_state.Vcc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) 	p += sprintf(p, "Vpp      : %d\n", skt->cs_state.Vpp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) 	p += sprintf(p, "IRQ      : %d (%d)\n", skt->cs_state.io_irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) 		skt->socket.pci_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) 	if (skt->ops->show_timing)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) 		p += skt->ops->show_timing(skt, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) 	return p-buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) static struct pccard_operations soc_common_pcmcia_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) 	.init			= soc_common_pcmcia_sock_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) 	.suspend		= soc_common_pcmcia_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) 	.get_status		= soc_common_pcmcia_get_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) 	.set_socket		= soc_common_pcmcia_set_socket,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) 	.set_io_map		= soc_common_pcmcia_set_io_map,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) 	.set_mem_map		= soc_common_pcmcia_set_mem_map,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) #ifdef CONFIG_CPU_FREQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) static int soc_common_pcmcia_cpufreq_nb(struct notifier_block *nb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) 	unsigned long val, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) 	struct soc_pcmcia_socket *skt = container_of(nb, struct soc_pcmcia_socket, cpufreq_nb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) 	struct cpufreq_freqs *freqs = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) 	return skt->ops->frequency_change(skt, val, freqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) void soc_pcmcia_init_one(struct soc_pcmcia_socket *skt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) 	const struct pcmcia_low_level *ops, struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) 	skt->ops = ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) 	skt->socket.owner = ops->owner;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) 	skt->socket.dev.parent = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) 	skt->socket.pci_irq = NO_IRQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) 	for (i = 0; i < ARRAY_SIZE(skt->stat); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) 		skt->stat[i].gpio = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) EXPORT_SYMBOL(soc_pcmcia_init_one);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) void soc_pcmcia_remove_one(struct soc_pcmcia_socket *skt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) 	del_timer_sync(&skt->poll_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) 	pcmcia_unregister_socket(&skt->socket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) #ifdef CONFIG_CPU_FREQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) 	if (skt->ops->frequency_change)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) 		cpufreq_unregister_notifier(&skt->cpufreq_nb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) 					    CPUFREQ_TRANSITION_NOTIFIER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) 	soc_pcmcia_hw_shutdown(skt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) 	/* should not be required; violates some lowlevel drivers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) 	soc_common_pcmcia_config_skt(skt, &dead_socket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) 	iounmap(skt->virt_io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) 	skt->virt_io = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) 	release_resource(&skt->res_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) 	release_resource(&skt->res_mem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) 	release_resource(&skt->res_io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) 	release_resource(&skt->res_skt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) EXPORT_SYMBOL(soc_pcmcia_remove_one);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) int soc_pcmcia_add_one(struct soc_pcmcia_socket *skt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) 	skt->cs_state = dead_socket;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) 	timer_setup(&skt->poll_timer, soc_common_pcmcia_poll_event, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) 	skt->poll_timer.expires = jiffies + SOC_PCMCIA_POLL_PERIOD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) 	ret = request_resource(&iomem_resource, &skt->res_skt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) 		goto out_err_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) 	ret = request_resource(&skt->res_skt, &skt->res_io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) 		goto out_err_2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) 	ret = request_resource(&skt->res_skt, &skt->res_mem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) 		goto out_err_3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) 	ret = request_resource(&skt->res_skt, &skt->res_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) 		goto out_err_4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) 	skt->virt_io = ioremap(skt->res_io.start, 0x10000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) 	if (skt->virt_io == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) 		goto out_err_5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) 	 * We initialize default socket timing here, because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) 	 * we are not guaranteed to see a SetIOMap operation at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) 	 * runtime.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) 	skt->ops->set_timing(skt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) 	ret = soc_pcmcia_hw_init(skt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) 		goto out_err_6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) 	skt->socket.ops = &soc_common_pcmcia_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) 	skt->socket.features = SS_CAP_STATIC_MAP|SS_CAP_PCCARD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) 	skt->socket.resource_ops = &pccard_static_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) 	skt->socket.irq_mask = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) 	skt->socket.map_size = PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) 	skt->socket.io_offset = (unsigned long)skt->virt_io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) 	skt->status = soc_common_pcmcia_skt_state(skt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) #ifdef CONFIG_CPU_FREQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) 	if (skt->ops->frequency_change) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) 		skt->cpufreq_nb.notifier_call = soc_common_pcmcia_cpufreq_nb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) 		ret = cpufreq_register_notifier(&skt->cpufreq_nb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) 						CPUFREQ_TRANSITION_NOTIFIER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) 		if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) 			dev_err(skt->socket.dev.parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) 				"unable to register CPU frequency change notifier for PCMCIA (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) 				ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) 	ret = pcmcia_register_socket(&skt->socket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) 		goto out_err_7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) 	ret = device_create_file(&skt->socket.dev, &dev_attr_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) 		goto out_err_8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870)  out_err_8:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) 	del_timer_sync(&skt->poll_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) 	pcmcia_unregister_socket(&skt->socket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874)  out_err_7:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) 	soc_pcmcia_hw_shutdown(skt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876)  out_err_6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) 	iounmap(skt->virt_io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878)  out_err_5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) 	release_resource(&skt->res_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880)  out_err_4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) 	release_resource(&skt->res_mem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882)  out_err_3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) 	release_resource(&skt->res_io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884)  out_err_2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) 	release_resource(&skt->res_skt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886)  out_err_1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) EXPORT_SYMBOL(soc_pcmcia_add_one);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) MODULE_AUTHOR("John Dorsey <john+@cs.cmu.edu>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) MODULE_DESCRIPTION("Linux PCMCIA Card Services: Common SoC support");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) MODULE_LICENSE("Dual MPL/GPL");