Loading...
1/*
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/ptrace.h>
16#include <linux/slab.h>
17#include <linux/string.h>
18#include <linux/timer.h>
19#include <linux/ioport.h>
20#include <linux/platform_device.h>
21
22#include <pcmcia/cistpl.h>
23#include <pcmcia/cisreg.h>
24#include <pcmcia/ds.h>
25
26#include <linux/usb/sl811.h>
27
28MODULE_AUTHOR("Botond Botyanszki");
29MODULE_DESCRIPTION("REX-CFU1U PCMCIA driver for 2.6");
30MODULE_LICENSE("GPL");
31
32
33/*====================================================================*/
34/* MACROS */
35/*====================================================================*/
36
37#define INFO(args...) printk(KERN_INFO "sl811_cs: " args)
38
39/*====================================================================*/
40/* VARIABLES */
41/*====================================================================*/
42
43typedef struct local_info_t {
44 struct pcmcia_device *p_dev;
45} local_info_t;
46
47static void sl811_cs_release(struct pcmcia_device * link);
48
49/*====================================================================*/
50
51static void release_platform_dev(struct device * dev)
52{
53 dev_dbg(dev, "sl811_cs platform_dev release\n");
54 dev->parent = NULL;
55}
56
57static struct sl811_platform_data platform_data = {
58 .potpg = 100,
59 .power = 50, /* == 100mA */
60 // .reset = ... FIXME: invoke CF reset on the card
61};
62
63static struct resource resources[] = {
64 [0] = {
65 .flags = IORESOURCE_IRQ,
66 },
67 [1] = {
68 // .name = "address",
69 .flags = IORESOURCE_IO,
70 },
71 [2] = {
72 // .name = "data",
73 .flags = IORESOURCE_IO,
74 },
75};
76
77extern struct platform_driver sl811h_driver;
78
79static struct platform_device platform_dev = {
80 .id = -1,
81 .dev = {
82 .platform_data = &platform_data,
83 .release = release_platform_dev,
84 },
85 .resource = resources,
86 .num_resources = ARRAY_SIZE(resources),
87};
88
89static int sl811_hc_init(struct device *parent, resource_size_t base_addr,
90 int irq)
91{
92 if (platform_dev.dev.parent)
93 return -EBUSY;
94 platform_dev.dev.parent = parent;
95
96 /* finish seting up the platform device */
97 resources[0].start = irq;
98
99 resources[1].start = base_addr;
100 resources[1].end = base_addr;
101
102 resources[2].start = base_addr + 1;
103 resources[2].end = base_addr + 1;
104
105 /* The driver core will probe for us. We know sl811-hcd has been
106 * initialized already because of the link order dependency created
107 * by referencing "sl811h_driver".
108 */
109 platform_dev.name = sl811h_driver.driver.name;
110 return platform_device_register(&platform_dev);
111}
112
113/*====================================================================*/
114
115static void sl811_cs_detach(struct pcmcia_device *link)
116{
117 dev_dbg(&link->dev, "sl811_cs_detach\n");
118
119 sl811_cs_release(link);
120
121 /* This points to the parent local_info_t struct */
122 kfree(link->priv);
123}
124
125static void sl811_cs_release(struct pcmcia_device * link)
126{
127 dev_dbg(&link->dev, "sl811_cs_release\n");
128
129 pcmcia_disable_device(link);
130 platform_device_unregister(&platform_dev);
131}
132
133static int sl811_cs_config_check(struct pcmcia_device *p_dev, void *priv_data)
134{
135 if (p_dev->config_index == 0)
136 return -EINVAL;
137
138 return pcmcia_request_io(p_dev);
139}
140
141
142static int sl811_cs_config(struct pcmcia_device *link)
143{
144 struct device *parent = &link->dev;
145 int ret;
146
147 dev_dbg(&link->dev, "sl811_cs_config\n");
148
149 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_VPP |
150 CONF_AUTO_CHECK_VCC | CONF_AUTO_SET_IO;
151
152 if (pcmcia_loop_config(link, sl811_cs_config_check, NULL))
153 goto failed;
154
155 /* require an IRQ and two registers */
156 if (resource_size(link->resource[0]) < 2)
157 goto failed;
158
159 if (!link->irq)
160 goto failed;
161
162 ret = pcmcia_enable_device(link);
163 if (ret)
164 goto failed;
165
166 if (sl811_hc_init(parent, link->resource[0]->start, link->irq)
167 < 0) {
168failed:
169 printk(KERN_WARNING "sl811_cs_config failed\n");
170 sl811_cs_release(link);
171 return -ENODEV;
172 }
173 return 0;
174}
175
176static int sl811_cs_probe(struct pcmcia_device *link)
177{
178 local_info_t *local;
179
180 local = kzalloc(sizeof(local_info_t), GFP_KERNEL);
181 if (!local)
182 return -ENOMEM;
183 local->p_dev = link;
184 link->priv = local;
185
186 return sl811_cs_config(link);
187}
188
189static const struct pcmcia_device_id sl811_ids[] = {
190 PCMCIA_DEVICE_MANF_CARD(0xc015, 0x0001), /* RATOC USB HOST CF+ Card */
191 PCMCIA_DEVICE_NULL,
192};
193MODULE_DEVICE_TABLE(pcmcia, sl811_ids);
194
195static struct pcmcia_driver sl811_cs_driver = {
196 .owner = THIS_MODULE,
197 .name = "sl811_cs",
198 .probe = sl811_cs_probe,
199 .remove = sl811_cs_detach,
200 .id_table = sl811_ids,
201};
202module_pcmcia_driver(sl811_cs_driver);
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * PCMCIA driver for SL811HS (as found in REX-CFU1U)
4 * Filename: sl811_cs.c
5 * Author: Yukio Yamamoto
6 *
7 * Port to sl811-hcd and 2.6.x by
8 * Botond Botyanszki <boti@rocketmail.com>
9 * Simon Pickering
10 *
11 * Last update: 2005-05-12
12 */
13
14#include <linux/kernel.h>
15#include <linux/module.h>
16#include <linux/ptrace.h>
17#include <linux/slab.h>
18#include <linux/string.h>
19#include <linux/timer.h>
20#include <linux/ioport.h>
21#include <linux/platform_device.h>
22
23#include <pcmcia/cistpl.h>
24#include <pcmcia/cisreg.h>
25#include <pcmcia/ds.h>
26
27#include <linux/usb/sl811.h>
28
29MODULE_AUTHOR("Botond Botyanszki");
30MODULE_DESCRIPTION("REX-CFU1U PCMCIA driver for 2.6");
31MODULE_LICENSE("GPL");
32
33
34/*====================================================================*/
35/* MACROS */
36/*====================================================================*/
37
38#define INFO(args...) printk(KERN_INFO "sl811_cs: " args)
39
40/*====================================================================*/
41/* VARIABLES */
42/*====================================================================*/
43
44typedef struct local_info_t {
45 struct pcmcia_device *p_dev;
46} local_info_t;
47
48static void sl811_cs_release(struct pcmcia_device * link);
49
50/*====================================================================*/
51
52static void release_platform_dev(struct device * dev)
53{
54 dev_dbg(dev, "sl811_cs platform_dev release\n");
55 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
78extern struct platform_driver sl811h_driver;
79
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
90static int sl811_hc_init(struct device *parent, resource_size_t base_addr,
91 int irq)
92{
93 if (platform_dev.dev.parent)
94 return -EBUSY;
95 platform_dev.dev.parent = parent;
96
97 /* finish setting 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
107 * initialized already because of the link order dependency created
108 * by referencing "sl811h_driver".
109 */
110 platform_dev.name = sl811h_driver.driver.name;
111 return platform_device_register(&platform_dev);
112}
113
114/*====================================================================*/
115
116static void sl811_cs_detach(struct pcmcia_device *link)
117{
118 dev_dbg(&link->dev, "sl811_cs_detach\n");
119
120 sl811_cs_release(link);
121
122 /* This points to the parent local_info_t struct */
123 kfree(link->priv);
124}
125
126static void sl811_cs_release(struct pcmcia_device * link)
127{
128 dev_dbg(&link->dev, "sl811_cs_release\n");
129
130 pcmcia_disable_device(link);
131 platform_device_unregister(&platform_dev);
132}
133
134static int sl811_cs_config_check(struct pcmcia_device *p_dev, void *priv_data)
135{
136 if (p_dev->config_index == 0)
137 return -EINVAL;
138
139 return pcmcia_request_io(p_dev);
140}
141
142
143static int sl811_cs_config(struct pcmcia_device *link)
144{
145 struct device *parent = &link->dev;
146 int ret;
147
148 dev_dbg(&link->dev, "sl811_cs_config\n");
149
150 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_VPP |
151 CONF_AUTO_CHECK_VCC | CONF_AUTO_SET_IO;
152
153 if (pcmcia_loop_config(link, sl811_cs_config_check, NULL))
154 goto failed;
155
156 /* require an IRQ and two registers */
157 if (resource_size(link->resource[0]) < 2)
158 goto failed;
159
160 if (!link->irq)
161 goto failed;
162
163 ret = pcmcia_enable_device(link);
164 if (ret)
165 goto failed;
166
167 if (sl811_hc_init(parent, link->resource[0]->start, link->irq)
168 < 0) {
169failed:
170 printk(KERN_WARNING "sl811_cs_config failed\n");
171 sl811_cs_release(link);
172 return -ENODEV;
173 }
174 return 0;
175}
176
177static int sl811_cs_probe(struct pcmcia_device *link)
178{
179 local_info_t *local;
180
181 local = kzalloc(sizeof(local_info_t), GFP_KERNEL);
182 if (!local)
183 return -ENOMEM;
184 local->p_dev = link;
185 link->priv = local;
186
187 return sl811_cs_config(link);
188}
189
190static const struct pcmcia_device_id sl811_ids[] = {
191 PCMCIA_DEVICE_MANF_CARD(0xc015, 0x0001), /* RATOC USB HOST CF+ Card */
192 PCMCIA_DEVICE_NULL,
193};
194MODULE_DEVICE_TABLE(pcmcia, sl811_ids);
195
196static struct pcmcia_driver sl811_cs_driver = {
197 .owner = THIS_MODULE,
198 .name = "sl811_cs",
199 .probe = sl811_cs_probe,
200 .remove = sl811_cs_detach,
201 .id_table = sl811_ids,
202};
203module_pcmcia_driver(sl811_cs_driver);