blob: 3b6f50eaec9134f596cd15958464578fea8ae1e6 [file] [log] [blame]
David Brownellc6de2b62005-05-26 05:55:55 -07001/*
2 * PCMCIA driver for SL811HS (as found in REX-CFU1U)
3 * Filename: sl811_cs.c
4 * Author: Yukio Yamamoto
5 *
6 * Port to sl811-hcd and 2.6.x by
7 * Botond Botyanszki <boti@rocketmail.com>
8 * Simon Pickering
9 *
10 * Last update: 2005-05-12
11 */
12
13#include <linux/kernel.h>
14#include <linux/module.h>
15#include <linux/init.h>
David Brownellc6de2b62005-05-26 05:55:55 -070016#include <linux/ptrace.h>
17#include <linux/slab.h>
18#include <linux/string.h>
19#include <linux/timer.h>
20#include <linux/ioport.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010021#include <linux/platform_device.h>
David Brownellc6de2b62005-05-26 05:55:55 -070022
David Brownellc6de2b62005-05-26 05:55:55 -070023#include <pcmcia/cistpl.h>
24#include <pcmcia/cisreg.h>
25#include <pcmcia/ds.h>
26
David Brownell325a4af2006-06-13 09:59:32 -070027#include <linux/usb/sl811.h>
David Brownellc6de2b62005-05-26 05:55:55 -070028
29MODULE_AUTHOR("Botond Botyanszki");
30MODULE_DESCRIPTION("REX-CFU1U PCMCIA driver for 2.6");
31MODULE_LICENSE("GPL");
32
33
34/*====================================================================*/
35/* MACROS */
36/*====================================================================*/
37
David Brownellc6de2b62005-05-26 05:55:55 -070038#define INFO(args...) printk(KERN_INFO "sl811_cs: " args)
39
David Brownellc6de2b62005-05-26 05:55:55 -070040/*====================================================================*/
41/* VARIABLES */
42/*====================================================================*/
43
David Brownellc6de2b62005-05-26 05:55:55 -070044typedef struct local_info_t {
Dominik Brodowskifd238232006-03-05 10:45:09 +010045 struct pcmcia_device *p_dev;
David Brownellc6de2b62005-05-26 05:55:55 -070046} local_info_t;
47
Dominik Brodowskifba395e2006-03-31 17:21:06 +020048static void sl811_cs_release(struct pcmcia_device * link);
Dominik Brodowskicc3b4862005-11-14 21:23:14 +010049
David Brownellc6de2b62005-05-26 05:55:55 -070050/*====================================================================*/
51
52static void release_platform_dev(struct device * dev)
53{
Dominik Brodowski9b44de22009-10-24 15:55:39 +020054 dev_dbg(dev, "sl811_cs platform_dev release\n");
David Brownellc6de2b62005-05-26 05:55:55 -070055 dev->parent = NULL;
56}
57
58static struct sl811_platform_data platform_data = {
59 .potpg = 100,
60 .power = 50, /* == 100mA */
61 // .reset = ... FIXME: invoke CF reset on the card
62};
63
64static struct resource resources[] = {
65 [0] = {
66 .flags = IORESOURCE_IRQ,
67 },
68 [1] = {
69 // .name = "address",
70 .flags = IORESOURCE_IO,
71 },
72 [2] = {
73 // .name = "data",
74 .flags = IORESOURCE_IO,
75 },
76};
77
David Brownella0c53f12006-02-06 12:15:15 -080078extern struct platform_driver sl811h_driver;
David Brownellc6de2b62005-05-26 05:55:55 -070079
80static struct platform_device platform_dev = {
81 .id = -1,
82 .dev = {
83 .platform_data = &platform_data,
84 .release = release_platform_dev,
85 },
86 .resource = resources,
87 .num_resources = ARRAY_SIZE(resources),
88};
89
Dominik Brodowskid39bd562008-08-28 01:05:34 +020090static int sl811_hc_init(struct device *parent, resource_size_t base_addr,
91 int irq)
David Brownellc6de2b62005-05-26 05:55:55 -070092{
93 if (platform_dev.dev.parent)
94 return -EBUSY;
95 platform_dev.dev.parent = parent;
96
97 /* finish seting up the platform device */
98 resources[0].start = irq;
99
100 resources[1].start = base_addr;
101 resources[1].end = base_addr;
102
103 resources[2].start = base_addr + 1;
104 resources[2].end = base_addr + 1;
105
106 /* The driver core will probe for us. We know sl811-hcd has been
David Brownellc9a50cc2005-11-07 20:45:20 -0800107 * initialized already because of the link order dependency created
108 * by referencing "sl811h_driver".
David Brownellc6de2b62005-05-26 05:55:55 -0700109 */
David Brownella0c53f12006-02-06 12:15:15 -0800110 platform_dev.name = sl811h_driver.driver.name;
David Brownellc6de2b62005-05-26 05:55:55 -0700111 return platform_device_register(&platform_dev);
112}
113
114/*====================================================================*/
115
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200116static void sl811_cs_detach(struct pcmcia_device *link)
David Brownellc6de2b62005-05-26 05:55:55 -0700117{
Dominik Brodowski9b44de22009-10-24 15:55:39 +0200118 dev_dbg(&link->dev, "sl811_cs_detach\n");
David Brownellc6de2b62005-05-26 05:55:55 -0700119
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100120 sl811_cs_release(link);
David Brownellc6de2b62005-05-26 05:55:55 -0700121
David Brownellc6de2b62005-05-26 05:55:55 -0700122 /* This points to the parent local_info_t struct */
123 kfree(link->priv);
124}
125
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200126static void sl811_cs_release(struct pcmcia_device * link)
David Brownellc6de2b62005-05-26 05:55:55 -0700127{
Dominik Brodowski9b44de22009-10-24 15:55:39 +0200128 dev_dbg(&link->dev, "sl811_cs_release\n");
David Brownellc6de2b62005-05-26 05:55:55 -0700129
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200130 pcmcia_disable_device(link);
David Brownellc6de2b62005-05-26 05:55:55 -0700131 platform_device_unregister(&platform_dev);
David Brownellc6de2b62005-05-26 05:55:55 -0700132}
133
Dominik Brodowski00990e72010-07-30 13:13:46 +0200134static int sl811_cs_config_check(struct pcmcia_device *p_dev, void *priv_data)
Dominik Brodowski84e2d342008-07-29 08:38:55 +0200135{
Dominik Brodowski00990e72010-07-30 13:13:46 +0200136 if (p_dev->config_index == 0)
137 return -EINVAL;
Dominik Brodowski84e2d342008-07-29 08:38:55 +0200138
Dominik Brodowski00990e72010-07-30 13:13:46 +0200139 return pcmcia_request_io(p_dev);
Dominik Brodowski84e2d342008-07-29 08:38:55 +0200140}
141
142
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200143static int sl811_cs_config(struct pcmcia_device *link)
David Brownellc6de2b62005-05-26 05:55:55 -0700144{
Dominik Brodowskidd2e5a12009-11-03 10:27:34 +0100145 struct device *parent = &link->dev;
Dominik Brodowski9b44de22009-10-24 15:55:39 +0200146 int ret;
David Brownellc6de2b62005-05-26 05:55:55 -0700147
Dominik Brodowski9b44de22009-10-24 15:55:39 +0200148 dev_dbg(&link->dev, "sl811_cs_config\n");
David Brownellc6de2b62005-05-26 05:55:55 -0700149
Dominik Brodowski440eed42010-07-30 09:51:52 +0200150 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_VPP |
Dominik Brodowski00990e72010-07-30 13:13:46 +0200151 CONF_AUTO_CHECK_VCC | CONF_AUTO_SET_IO;
Dominik Brodowski440eed42010-07-30 09:51:52 +0200152
Dominik Brodowskiad913c12008-08-02 16:12:00 +0200153 if (pcmcia_loop_config(link, sl811_cs_config_check, NULL))
154 goto failed;
David Brownellc6de2b62005-05-26 05:55:55 -0700155
156 /* require an IRQ and two registers */
Dominik Brodowski9a017a92010-07-24 15:58:54 +0200157 if (resource_size(link->resource[0]) < 2)
Dominik Brodowskiad913c12008-08-02 16:12:00 +0200158 goto failed;
Dominik Brodowskieb141202010-03-07 12:21:16 +0100159
160 if (!link->irq)
Dominik Brodowskiad913c12008-08-02 16:12:00 +0200161 goto failed;
David Brownellc6de2b62005-05-26 05:55:55 -0700162
Dominik Brodowski1ac71e52010-07-29 19:27:09 +0200163 ret = pcmcia_enable_device(link);
Dominik Brodowski9b44de22009-10-24 15:55:39 +0200164 if (ret)
165 goto failed;
David Brownellc6de2b62005-05-26 05:55:55 -0700166
Dominik Brodowski9a017a92010-07-24 15:58:54 +0200167 if (sl811_hc_init(parent, link->resource[0]->start, link->irq)
David Brownellc6de2b62005-05-26 05:55:55 -0700168 < 0) {
Dominik Brodowskiad913c12008-08-02 16:12:00 +0200169failed:
170 printk(KERN_WARNING "sl811_cs_config failed\n");
David Brownellc6de2b62005-05-26 05:55:55 -0700171 sl811_cs_release(link);
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200172 return -ENODEV;
David Brownellc6de2b62005-05-26 05:55:55 -0700173 }
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200174 return 0;
David Brownellc6de2b62005-05-26 05:55:55 -0700175}
176
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200177static int sl811_cs_probe(struct pcmcia_device *link)
David Brownellc6de2b62005-05-26 05:55:55 -0700178{
179 local_info_t *local;
David Brownellc6de2b62005-05-26 05:55:55 -0700180
Yoann Padioleaudd00cc42007-07-19 01:49:03 -0700181 local = kzalloc(sizeof(local_info_t), GFP_KERNEL);
David Brownellc6de2b62005-05-26 05:55:55 -0700182 if (!local)
Dominik Brodowskif8cfa612005-11-14 21:25:51 +0100183 return -ENOMEM;
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200184 local->p_dev = link;
David Brownellc6de2b62005-05-26 05:55:55 -0700185 link->priv = local;
186
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200187 return sl811_cs_config(link);
David Brownellc6de2b62005-05-26 05:55:55 -0700188}
189
Joe Perches25f8f542011-05-03 19:29:01 -0700190static const struct pcmcia_device_id sl811_ids[] = {
David Brownell22f3a8f2005-06-27 16:28:43 -0700191 PCMCIA_DEVICE_MANF_CARD(0xc015, 0x0001), /* RATOC USB HOST CF+ Card */
192 PCMCIA_DEVICE_NULL,
193};
194MODULE_DEVICE_TABLE(pcmcia, sl811_ids);
195
David Brownellc6de2b62005-05-26 05:55:55 -0700196static struct pcmcia_driver sl811_cs_driver = {
197 .owner = THIS_MODULE,
Dominik Brodowski2e9b9812010-08-08 11:36:26 +0200198 .name = "sl811_cs",
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200199 .probe = sl811_cs_probe,
Dominik Brodowskicc3b4862005-11-14 21:23:14 +0100200 .remove = sl811_cs_detach,
David Brownell22f3a8f2005-06-27 16:28:43 -0700201 .id_table = sl811_ids,
David Brownellc6de2b62005-05-26 05:55:55 -0700202};
203
204/*====================================================================*/
205
206static int __init init_sl811_cs(void)
207{
208 return pcmcia_register_driver(&sl811_cs_driver);
209}
210module_init(init_sl811_cs);
211
212static void __exit exit_sl811_cs(void)
213{
214 pcmcia_unregister_driver(&sl811_cs_driver);
215}
216module_exit(exit_sl811_cs);