blob: a076e41084528cbb666f23ed2e0d7482843e1c1c [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * linux/drivers/pcmcia/pxa2xx_mainstone.c
4 *
5 * Mainstone PCMCIA specific routines.
6 *
7 * Created: May 12, 2004
8 * Author: Nicolas Pitre
9 * Copyright: MontaVista Software Inc.
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 */
Russell King34fdbe62018-11-28 13:57:23 +000011#include <linux/gpio/consumer.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/module.h>
13#include <linux/init.h>
Russell King34fdbe62018-11-28 13:57:23 +000014#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/kernel.h>
16#include <linux/errno.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010017#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
19#include <pcmcia/ss.h>
20
Russell King04ba0f62008-04-24 15:23:25 +010021#include <asm/mach-types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
23#include "soc_common.h"
Russell King34fdbe62018-11-28 13:57:23 +000024#include "max1600.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
Linus Torvalds1da177e2005-04-16 15:20:36 -070026static int mst_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
27{
Russell King34fdbe62018-11-28 13:57:23 +000028 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -070052}
53
Russell King34fdbe62018-11-28 13:57:23 +000054static unsigned int mst_pcmcia_bvd1_status[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
56static void mst_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
57 struct pcmcia_state *state)
58{
Russell King34fdbe62018-11-28 13:57:23 +000059 unsigned int flip = mst_pcmcia_bvd1_status[skt->nr] ^ state->bvd1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
61 /*
62 * Workaround for STSCHG which can't be deasserted:
63 * We therefore disable/enable corresponding IRQs
64 * as needed to avoid IRQ locks.
65 */
66 if (flip) {
Russell King34fdbe62018-11-28 13:57:23 +000067 mst_pcmcia_bvd1_status[skt->nr] = state->bvd1;
68 if (state->bvd1)
69 enable_irq(skt->stat[SOC_STAT_BVD1].irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 else
Russell King34fdbe62018-11-28 13:57:23 +000071 disable_irq(skt->stat[SOC_STAT_BVD2].irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070073}
74
75static int mst_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
76 const socket_state_t *state)
77{
Russell King34fdbe62018-11-28 13:57:23 +000078 return max1600_configure(skt->driver_data, state->Vcc, state->Vpp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079}
80
Russell King4e5e8de2008-04-24 15:28:11 +010081static struct pcmcia_low_level mst_pcmcia_ops __initdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 .owner = THIS_MODULE,
83 .hw_init = mst_pcmcia_hw_init,
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 .socket_state = mst_pcmcia_socket_state,
85 .configure_socket = mst_pcmcia_configure_socket,
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 .nr = 2,
87};
88
89static struct platform_device *mst_pcmcia_device;
90
91static int __init mst_pcmcia_init(void)
92{
93 int ret;
94
Russell King04ba0f62008-04-24 15:23:25 +010095 if (!machine_is_mainstone())
96 return -ENODEV;
97
Richard Purdieb0164502006-01-10 17:16:12 +000098 mst_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 if (!mst_pcmcia_device)
100 return -ENOMEM;
Richard Purdieb0164502006-01-10 17:16:12 +0000101
Russell King4e5e8de2008-04-24 15:28:11 +0100102 ret = platform_device_add_data(mst_pcmcia_device, &mst_pcmcia_ops,
103 sizeof(mst_pcmcia_ops));
104 if (ret == 0)
105 ret = platform_device_add(mst_pcmcia_device);
Richard Purdieb0164502006-01-10 17:16:12 +0000106
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 if (ret)
Richard Purdieb0164502006-01-10 17:16:12 +0000108 platform_device_put(mst_pcmcia_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
110 return ret;
111}
112
113static void __exit mst_pcmcia_exit(void)
114{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 platform_device_unregister(mst_pcmcia_device);
116}
117
Richard Purdief36598ae2005-09-03 19:39:25 +0100118fs_initcall(mst_pcmcia_init);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119module_exit(mst_pcmcia_exit);
120
121MODULE_LICENSE("GPL");
Kay Sievers43cc71e2007-08-18 04:40:39 +0200122MODULE_ALIAS("platform:pxa2xx-pcmcia");