1*4882a593Smuzhiyun /*======================================================================
2*4882a593Smuzhiyun
3*4882a593Smuzhiyun Device driver for the PCMCIA control functionality of StrongARM
4*4882a593Smuzhiyun SA-1100 microprocessors.
5*4882a593Smuzhiyun
6*4882a593Smuzhiyun The contents of this file are subject to the Mozilla Public
7*4882a593Smuzhiyun License Version 1.1 (the "License"); you may not use this file
8*4882a593Smuzhiyun except in compliance with the License. You may obtain a copy of
9*4882a593Smuzhiyun the License at http://www.mozilla.org/MPL/
10*4882a593Smuzhiyun
11*4882a593Smuzhiyun Software distributed under the License is distributed on an "AS
12*4882a593Smuzhiyun IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
13*4882a593Smuzhiyun implied. See the License for the specific language governing
14*4882a593Smuzhiyun rights and limitations under the License.
15*4882a593Smuzhiyun
16*4882a593Smuzhiyun The initial developer of the original code is John G. Dorsey
17*4882a593Smuzhiyun <john+@cs.cmu.edu>. Portions created by John G. Dorsey are
18*4882a593Smuzhiyun Copyright (C) 1999 John G. Dorsey. All Rights Reserved.
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun Alternatively, the contents of this file may be used under the
21*4882a593Smuzhiyun terms of the GNU Public License version 2 (the "GPL"), in which
22*4882a593Smuzhiyun case the provisions of the GPL are applicable instead of the
23*4882a593Smuzhiyun above. If you wish to allow the use of your version of this file
24*4882a593Smuzhiyun only under the terms of the GPL and not to allow others to use
25*4882a593Smuzhiyun your version of this file under the MPL, indicate your decision
26*4882a593Smuzhiyun by deleting the provisions above and replace them with the notice
27*4882a593Smuzhiyun and other provisions required by the GPL. If you do not delete
28*4882a593Smuzhiyun the provisions above, a recipient may use your version of this
29*4882a593Smuzhiyun file under either the MPL or the GPL.
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun ======================================================================*/
32*4882a593Smuzhiyun
33*4882a593Smuzhiyun #include <linux/module.h>
34*4882a593Smuzhiyun #include <linux/gpio/consumer.h>
35*4882a593Smuzhiyun #include <linux/init.h>
36*4882a593Smuzhiyun #include <linux/regulator/consumer.h>
37*4882a593Smuzhiyun #include <linux/slab.h>
38*4882a593Smuzhiyun #include <linux/platform_device.h>
39*4882a593Smuzhiyun
40*4882a593Smuzhiyun #include <pcmcia/ss.h>
41*4882a593Smuzhiyun
42*4882a593Smuzhiyun #include <asm/hardware/scoop.h>
43*4882a593Smuzhiyun
44*4882a593Smuzhiyun #include "sa1100_generic.h"
45*4882a593Smuzhiyun
46*4882a593Smuzhiyun static const char *sa11x0_cf_gpio_names[] = {
47*4882a593Smuzhiyun [SOC_STAT_CD] = "detect",
48*4882a593Smuzhiyun [SOC_STAT_BVD1] = "bvd1",
49*4882a593Smuzhiyun [SOC_STAT_BVD2] = "bvd2",
50*4882a593Smuzhiyun [SOC_STAT_RDY] = "ready",
51*4882a593Smuzhiyun };
52*4882a593Smuzhiyun
sa11x0_cf_hw_init(struct soc_pcmcia_socket * skt)53*4882a593Smuzhiyun static int sa11x0_cf_hw_init(struct soc_pcmcia_socket *skt)
54*4882a593Smuzhiyun {
55*4882a593Smuzhiyun struct device *dev = skt->socket.dev.parent;
56*4882a593Smuzhiyun int i;
57*4882a593Smuzhiyun
58*4882a593Smuzhiyun skt->gpio_reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
59*4882a593Smuzhiyun if (IS_ERR(skt->gpio_reset))
60*4882a593Smuzhiyun return PTR_ERR(skt->gpio_reset);
61*4882a593Smuzhiyun
62*4882a593Smuzhiyun skt->gpio_bus_enable = devm_gpiod_get_optional(dev, "bus-enable",
63*4882a593Smuzhiyun GPIOD_OUT_HIGH);
64*4882a593Smuzhiyun if (IS_ERR(skt->gpio_bus_enable))
65*4882a593Smuzhiyun return PTR_ERR(skt->gpio_bus_enable);
66*4882a593Smuzhiyun
67*4882a593Smuzhiyun skt->vcc.reg = devm_regulator_get_optional(dev, "vcc");
68*4882a593Smuzhiyun if (IS_ERR(skt->vcc.reg))
69*4882a593Smuzhiyun return PTR_ERR(skt->vcc.reg);
70*4882a593Smuzhiyun
71*4882a593Smuzhiyun if (!skt->vcc.reg)
72*4882a593Smuzhiyun dev_warn(dev,
73*4882a593Smuzhiyun "no Vcc regulator provided, ignoring Vcc controls\n");
74*4882a593Smuzhiyun
75*4882a593Smuzhiyun for (i = 0; i < ARRAY_SIZE(sa11x0_cf_gpio_names); i++) {
76*4882a593Smuzhiyun skt->stat[i].name = sa11x0_cf_gpio_names[i];
77*4882a593Smuzhiyun skt->stat[i].desc = devm_gpiod_get_optional(dev,
78*4882a593Smuzhiyun sa11x0_cf_gpio_names[i], GPIOD_IN);
79*4882a593Smuzhiyun if (IS_ERR(skt->stat[i].desc))
80*4882a593Smuzhiyun return PTR_ERR(skt->stat[i].desc);
81*4882a593Smuzhiyun }
82*4882a593Smuzhiyun return 0;
83*4882a593Smuzhiyun }
84*4882a593Smuzhiyun
sa11x0_cf_configure_socket(struct soc_pcmcia_socket * skt,const socket_state_t * state)85*4882a593Smuzhiyun static int sa11x0_cf_configure_socket(struct soc_pcmcia_socket *skt,
86*4882a593Smuzhiyun const socket_state_t *state)
87*4882a593Smuzhiyun {
88*4882a593Smuzhiyun return soc_pcmcia_regulator_set(skt, &skt->vcc, state->Vcc);
89*4882a593Smuzhiyun }
90*4882a593Smuzhiyun
91*4882a593Smuzhiyun static struct pcmcia_low_level sa11x0_cf_ops = {
92*4882a593Smuzhiyun .owner = THIS_MODULE,
93*4882a593Smuzhiyun .hw_init = sa11x0_cf_hw_init,
94*4882a593Smuzhiyun .socket_state = soc_common_cf_socket_state,
95*4882a593Smuzhiyun .configure_socket = sa11x0_cf_configure_socket,
96*4882a593Smuzhiyun };
97*4882a593Smuzhiyun
98*4882a593Smuzhiyun int __init pcmcia_collie_init(struct device *dev);
99*4882a593Smuzhiyun
100*4882a593Smuzhiyun static int (*sa11x0_pcmcia_legacy_hw_init[])(struct device *dev) = {
101*4882a593Smuzhiyun #if defined(CONFIG_SA1100_H3100) || defined(CONFIG_SA1100_H3600)
102*4882a593Smuzhiyun pcmcia_h3600_init,
103*4882a593Smuzhiyun #endif
104*4882a593Smuzhiyun #ifdef CONFIG_SA1100_SIMPAD
105*4882a593Smuzhiyun pcmcia_simpad_init,
106*4882a593Smuzhiyun #endif
107*4882a593Smuzhiyun #ifdef CONFIG_SA1100_COLLIE
108*4882a593Smuzhiyun pcmcia_collie_init,
109*4882a593Smuzhiyun #endif
110*4882a593Smuzhiyun };
111*4882a593Smuzhiyun
sa11x0_drv_pcmcia_legacy_probe(struct platform_device * dev)112*4882a593Smuzhiyun static int sa11x0_drv_pcmcia_legacy_probe(struct platform_device *dev)
113*4882a593Smuzhiyun {
114*4882a593Smuzhiyun int i, ret = -ENODEV;
115*4882a593Smuzhiyun
116*4882a593Smuzhiyun /*
117*4882a593Smuzhiyun * Initialise any "on-board" PCMCIA sockets.
118*4882a593Smuzhiyun */
119*4882a593Smuzhiyun for (i = 0; i < ARRAY_SIZE(sa11x0_pcmcia_legacy_hw_init); i++) {
120*4882a593Smuzhiyun ret = sa11x0_pcmcia_legacy_hw_init[i](&dev->dev);
121*4882a593Smuzhiyun if (ret == 0)
122*4882a593Smuzhiyun break;
123*4882a593Smuzhiyun }
124*4882a593Smuzhiyun
125*4882a593Smuzhiyun return ret;
126*4882a593Smuzhiyun }
127*4882a593Smuzhiyun
sa11x0_drv_pcmcia_legacy_remove(struct platform_device * dev)128*4882a593Smuzhiyun static int sa11x0_drv_pcmcia_legacy_remove(struct platform_device *dev)
129*4882a593Smuzhiyun {
130*4882a593Smuzhiyun struct skt_dev_info *sinfo = platform_get_drvdata(dev);
131*4882a593Smuzhiyun int i;
132*4882a593Smuzhiyun
133*4882a593Smuzhiyun platform_set_drvdata(dev, NULL);
134*4882a593Smuzhiyun
135*4882a593Smuzhiyun for (i = 0; i < sinfo->nskt; i++)
136*4882a593Smuzhiyun soc_pcmcia_remove_one(&sinfo->skt[i]);
137*4882a593Smuzhiyun
138*4882a593Smuzhiyun return 0;
139*4882a593Smuzhiyun }
140*4882a593Smuzhiyun
sa11x0_drv_pcmcia_probe(struct platform_device * pdev)141*4882a593Smuzhiyun static int sa11x0_drv_pcmcia_probe(struct platform_device *pdev)
142*4882a593Smuzhiyun {
143*4882a593Smuzhiyun struct soc_pcmcia_socket *skt;
144*4882a593Smuzhiyun struct device *dev = &pdev->dev;
145*4882a593Smuzhiyun
146*4882a593Smuzhiyun if (pdev->id == -1)
147*4882a593Smuzhiyun return sa11x0_drv_pcmcia_legacy_probe(pdev);
148*4882a593Smuzhiyun
149*4882a593Smuzhiyun skt = devm_kzalloc(dev, sizeof(*skt), GFP_KERNEL);
150*4882a593Smuzhiyun if (!skt)
151*4882a593Smuzhiyun return -ENOMEM;
152*4882a593Smuzhiyun
153*4882a593Smuzhiyun platform_set_drvdata(pdev, skt);
154*4882a593Smuzhiyun
155*4882a593Smuzhiyun skt->nr = pdev->id;
156*4882a593Smuzhiyun skt->clk = devm_clk_get(dev, NULL);
157*4882a593Smuzhiyun if (IS_ERR(skt->clk))
158*4882a593Smuzhiyun return PTR_ERR(skt->clk);
159*4882a593Smuzhiyun
160*4882a593Smuzhiyun sa11xx_drv_pcmcia_ops(&sa11x0_cf_ops);
161*4882a593Smuzhiyun soc_pcmcia_init_one(skt, &sa11x0_cf_ops, dev);
162*4882a593Smuzhiyun
163*4882a593Smuzhiyun return sa11xx_drv_pcmcia_add_one(skt);
164*4882a593Smuzhiyun }
165*4882a593Smuzhiyun
sa11x0_drv_pcmcia_remove(struct platform_device * dev)166*4882a593Smuzhiyun static int sa11x0_drv_pcmcia_remove(struct platform_device *dev)
167*4882a593Smuzhiyun {
168*4882a593Smuzhiyun struct soc_pcmcia_socket *skt;
169*4882a593Smuzhiyun
170*4882a593Smuzhiyun if (dev->id == -1)
171*4882a593Smuzhiyun return sa11x0_drv_pcmcia_legacy_remove(dev);
172*4882a593Smuzhiyun
173*4882a593Smuzhiyun skt = platform_get_drvdata(dev);
174*4882a593Smuzhiyun
175*4882a593Smuzhiyun soc_pcmcia_remove_one(skt);
176*4882a593Smuzhiyun
177*4882a593Smuzhiyun return 0;
178*4882a593Smuzhiyun }
179*4882a593Smuzhiyun
180*4882a593Smuzhiyun static struct platform_driver sa11x0_pcmcia_driver = {
181*4882a593Smuzhiyun .driver = {
182*4882a593Smuzhiyun .name = "sa11x0-pcmcia",
183*4882a593Smuzhiyun },
184*4882a593Smuzhiyun .probe = sa11x0_drv_pcmcia_probe,
185*4882a593Smuzhiyun .remove = sa11x0_drv_pcmcia_remove,
186*4882a593Smuzhiyun };
187*4882a593Smuzhiyun
188*4882a593Smuzhiyun /* sa11x0_pcmcia_init()
189*4882a593Smuzhiyun * ^^^^^^^^^^^^^^^^^^^^
190*4882a593Smuzhiyun *
191*4882a593Smuzhiyun * This routine performs low-level PCMCIA initialization and then
192*4882a593Smuzhiyun * registers this socket driver with Card Services.
193*4882a593Smuzhiyun *
194*4882a593Smuzhiyun * Returns: 0 on success, -ve error code on failure
195*4882a593Smuzhiyun */
sa11x0_pcmcia_init(void)196*4882a593Smuzhiyun static int __init sa11x0_pcmcia_init(void)
197*4882a593Smuzhiyun {
198*4882a593Smuzhiyun return platform_driver_register(&sa11x0_pcmcia_driver);
199*4882a593Smuzhiyun }
200*4882a593Smuzhiyun
201*4882a593Smuzhiyun /* sa11x0_pcmcia_exit()
202*4882a593Smuzhiyun * ^^^^^^^^^^^^^^^^^^^^
203*4882a593Smuzhiyun * Invokes the low-level kernel service to free IRQs associated with this
204*4882a593Smuzhiyun * socket controller and reset GPIO edge detection.
205*4882a593Smuzhiyun */
sa11x0_pcmcia_exit(void)206*4882a593Smuzhiyun static void __exit sa11x0_pcmcia_exit(void)
207*4882a593Smuzhiyun {
208*4882a593Smuzhiyun platform_driver_unregister(&sa11x0_pcmcia_driver);
209*4882a593Smuzhiyun }
210*4882a593Smuzhiyun
211*4882a593Smuzhiyun MODULE_AUTHOR("John Dorsey <john+@cs.cmu.edu>");
212*4882a593Smuzhiyun MODULE_DESCRIPTION("Linux PCMCIA Card Services: SA-11x0 Socket Controller");
213*4882a593Smuzhiyun MODULE_LICENSE("Dual MPL/GPL");
214*4882a593Smuzhiyun
215*4882a593Smuzhiyun fs_initcall(sa11x0_pcmcia_init);
216*4882a593Smuzhiyun module_exit(sa11x0_pcmcia_exit);
217