blob: ccb219c3876170fe7e6580c791472a7e716aa461 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*======================================================================
2
3 Device driver for the PCMCIA control functionality of StrongARM
4 SA-1100 microprocessors.
5
6 The contents of this file are subject to the Mozilla Public
7 License Version 1.1 (the "License"); you may not use this file
8 except in compliance with the License. You may obtain a copy of
9 the License at http://www.mozilla.org/MPL/
10
11 Software distributed under the License is distributed on an "AS
12 IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
13 implied. See the License for the specific language governing
14 rights and limitations under the License.
15
16 The initial developer of the original code is John G. Dorsey
17 <john+@cs.cmu.edu>. Portions created by John G. Dorsey are
18 Copyright (C) 1999 John G. Dorsey. All Rights Reserved.
19
20 Alternatively, the contents of this file may be used under the
21 terms of the GNU Public License version 2 (the "GPL"), in which
22 case the provisions of the GPL are applicable instead of the
23 above. If you wish to allow the use of your version of this file
24 only under the terms of the GPL and not to allow others to use
25 your version of this file under the MPL, indicate your decision
26 by deleting the provisions above and replace them with the notice
27 and other provisions required by the GPL. If you do not delete
28 the provisions above, a recipient may use your version of this
29 file under either the MPL or the GPL.
30
31======================================================================*/
32
33#include <linux/module.h>
Russell King7be893a2016-08-31 08:49:47 +010034#include <linux/gpio/consumer.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <linux/init.h>
Russell King7be893a2016-08-31 08:49:47 +010036#include <linux/regulator/consumer.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090037#include <linux/slab.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010038#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <pcmcia/ss.h>
41
Pavel Machek77bb86a2005-10-30 23:39:02 +000042#include <asm/hardware/scoop.h>
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include "sa1100_generic.h"
45
Russell King7be893a2016-08-31 08:49:47 +010046static const char *sa11x0_cf_gpio_names[] = {
47 [SOC_STAT_CD] = "detect",
48 [SOC_STAT_BVD1] = "bvd1",
49 [SOC_STAT_BVD2] = "bvd2",
50 [SOC_STAT_RDY] = "ready",
51};
52
53static int sa11x0_cf_hw_init(struct soc_pcmcia_socket *skt)
54{
55 struct device *dev = skt->socket.dev.parent;
56 int i;
57
58 skt->gpio_reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
59 if (IS_ERR(skt->gpio_reset))
60 return PTR_ERR(skt->gpio_reset);
61
62 skt->gpio_bus_enable = devm_gpiod_get_optional(dev, "bus-enable",
63 GPIOD_OUT_HIGH);
64 if (IS_ERR(skt->gpio_bus_enable))
65 return PTR_ERR(skt->gpio_bus_enable);
66
67 skt->vcc.reg = devm_regulator_get_optional(dev, "vcc");
68 if (IS_ERR(skt->vcc.reg))
69 return PTR_ERR(skt->vcc.reg);
70
71 if (!skt->vcc.reg)
72 dev_warn(dev,
73 "no Vcc regulator provided, ignoring Vcc controls\n");
74
75 for (i = 0; i < ARRAY_SIZE(sa11x0_cf_gpio_names); i++) {
76 skt->stat[i].name = sa11x0_cf_gpio_names[i];
77 skt->stat[i].desc = devm_gpiod_get_optional(dev,
78 sa11x0_cf_gpio_names[i], GPIOD_IN);
79 if (IS_ERR(skt->stat[i].desc))
80 return PTR_ERR(skt->stat[i].desc);
81 }
82 return 0;
83}
84
85static int sa11x0_cf_configure_socket(struct soc_pcmcia_socket *skt,
86 const socket_state_t *state)
87{
88 return soc_pcmcia_regulator_set(skt, &skt->vcc, state->Vcc);
89}
90
91static struct pcmcia_low_level sa11x0_cf_ops = {
92 .owner = THIS_MODULE,
93 .hw_init = sa11x0_cf_hw_init,
94 .socket_state = soc_common_cf_socket_state,
95 .configure_socket = sa11x0_cf_configure_socket,
96};
97
Pavel Machek77bb86a2005-10-30 23:39:02 +000098int __init pcmcia_collie_init(struct device *dev);
99
Russell King7be893a2016-08-31 08:49:47 +0100100static int (*sa11x0_pcmcia_legacy_hw_init[])(struct device *dev) = {
Arnd Bergmann9a9e1be2022-09-29 15:26:06 +0200101#ifdef CONFIG_SA1100_H3600
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 pcmcia_h3600_init,
103#endif
Pavel Machek77bb86a2005-10-30 23:39:02 +0000104#ifdef CONFIG_SA1100_COLLIE
105 pcmcia_collie_init,
106#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107};
108
Russell King7be893a2016-08-31 08:49:47 +0100109static int sa11x0_drv_pcmcia_legacy_probe(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110{
111 int i, ret = -ENODEV;
112
113 /*
114 * Initialise any "on-board" PCMCIA sockets.
115 */
Russell King7be893a2016-08-31 08:49:47 +0100116 for (i = 0; i < ARRAY_SIZE(sa11x0_pcmcia_legacy_hw_init); i++) {
117 ret = sa11x0_pcmcia_legacy_hw_init[i](&dev->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 if (ret == 0)
119 break;
120 }
121
122 return ret;
123}
124
Uwe Kleine-König09b2c102022-07-14 23:45:34 +0200125static void sa11x0_drv_pcmcia_legacy_remove(struct platform_device *dev)
Ming Lei7a192ec2009-02-06 23:40:12 +0800126{
Russell King - ARM Linuxbe854582009-03-26 22:21:18 +0000127 struct skt_dev_info *sinfo = platform_get_drvdata(dev);
128 int i;
129
130 platform_set_drvdata(dev, NULL);
131
132 for (i = 0; i < sinfo->nskt; i++)
133 soc_pcmcia_remove_one(&sinfo->skt[i]);
Ming Lei7a192ec2009-02-06 23:40:12 +0800134}
135
Russell King7be893a2016-08-31 08:49:47 +0100136static int sa11x0_drv_pcmcia_probe(struct platform_device *pdev)
137{
138 struct soc_pcmcia_socket *skt;
139 struct device *dev = &pdev->dev;
140
141 if (pdev->id == -1)
142 return sa11x0_drv_pcmcia_legacy_probe(pdev);
143
144 skt = devm_kzalloc(dev, sizeof(*skt), GFP_KERNEL);
145 if (!skt)
146 return -ENOMEM;
147
148 platform_set_drvdata(pdev, skt);
149
150 skt->nr = pdev->id;
151 skt->clk = devm_clk_get(dev, NULL);
152 if (IS_ERR(skt->clk))
153 return PTR_ERR(skt->clk);
154
155 sa11xx_drv_pcmcia_ops(&sa11x0_cf_ops);
156 soc_pcmcia_init_one(skt, &sa11x0_cf_ops, dev);
157
158 return sa11xx_drv_pcmcia_add_one(skt);
159}
160
Uwe Kleine-Königc1991d42023-12-08 17:08:11 +0100161static void sa11x0_drv_pcmcia_remove(struct platform_device *dev)
Russell King7be893a2016-08-31 08:49:47 +0100162{
163 struct soc_pcmcia_socket *skt;
164
Uwe Kleine-König09b2c102022-07-14 23:45:34 +0200165 if (dev->id == -1) {
166 sa11x0_drv_pcmcia_legacy_remove(dev);
Uwe Kleine-Königc1991d42023-12-08 17:08:11 +0100167 return;
Uwe Kleine-König09b2c102022-07-14 23:45:34 +0200168 }
Russell King7be893a2016-08-31 08:49:47 +0100169
170 skt = platform_get_drvdata(dev);
171
172 soc_pcmcia_remove_one(skt);
Russell King7be893a2016-08-31 08:49:47 +0100173}
174
Ming Lei7a192ec2009-02-06 23:40:12 +0800175static struct platform_driver sa11x0_pcmcia_driver = {
176 .driver = {
177 .name = "sa11x0-pcmcia",
Ming Lei7a192ec2009-02-06 23:40:12 +0800178 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 .probe = sa11x0_drv_pcmcia_probe,
Uwe Kleine-Königc1991d42023-12-08 17:08:11 +0100180 .remove_new = sa11x0_drv_pcmcia_remove,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181};
182
183/* sa11x0_pcmcia_init()
184 * ^^^^^^^^^^^^^^^^^^^^
185 *
186 * This routine performs low-level PCMCIA initialization and then
187 * registers this socket driver with Card Services.
188 *
189 * Returns: 0 on success, -ve error code on failure
190 */
191static int __init sa11x0_pcmcia_init(void)
192{
Ming Lei7a192ec2009-02-06 23:40:12 +0800193 return platform_driver_register(&sa11x0_pcmcia_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194}
195
196/* sa11x0_pcmcia_exit()
197 * ^^^^^^^^^^^^^^^^^^^^
198 * Invokes the low-level kernel service to free IRQs associated with this
199 * socket controller and reset GPIO edge detection.
200 */
201static void __exit sa11x0_pcmcia_exit(void)
202{
Ming Lei7a192ec2009-02-06 23:40:12 +0800203 platform_driver_unregister(&sa11x0_pcmcia_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204}
205
206MODULE_AUTHOR("John Dorsey <john+@cs.cmu.edu>");
207MODULE_DESCRIPTION("Linux PCMCIA Card Services: SA-11x0 Socket Controller");
208MODULE_LICENSE("Dual MPL/GPL");
209
Richard Purdief36598ae2005-09-03 19:39:25 +0100210fs_initcall(sa11x0_pcmcia_init);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211module_exit(sa11x0_pcmcia_exit);