blob: 88a9bffe93dfde1d92b421dbaed92e8e52ede2ff [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>
David Brownellc6de2b62005-05-26 05:55:55 -070015#include <linux/ptrace.h>
16#include <linux/slab.h>
17#include <linux/string.h>
18#include <linux/timer.h>
19#include <linux/ioport.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010020#include <linux/platform_device.h>
David Brownellc6de2b62005-05-26 05:55:55 -070021
David Brownellc6de2b62005-05-26 05:55:55 -070022#include <pcmcia/cistpl.h>
23#include <pcmcia/cisreg.h>
24#include <pcmcia/ds.h>
25
David Brownell325a4af2006-06-13 09:59:32 -070026#include <linux/usb/sl811.h>
David Brownellc6de2b62005-05-26 05:55:55 -070027
28MODULE_AUTHOR("Botond Botyanszki");
29MODULE_DESCRIPTION("REX-CFU1U PCMCIA driver for 2.6");
30MODULE_LICENSE("GPL");
31
32
33/*====================================================================*/
34/* MACROS */
35/*====================================================================*/
36
David Brownellc6de2b62005-05-26 05:55:55 -070037#define INFO(args...) printk(KERN_INFO "sl811_cs: " args)
38
David Brownellc6de2b62005-05-26 05:55:55 -070039/*====================================================================*/
40/* VARIABLES */
41/*====================================================================*/
42
David Brownellc6de2b62005-05-26 05:55:55 -070043typedef struct local_info_t {
Dominik Brodowskifd238232006-03-05 10:45:09 +010044 struct pcmcia_device *p_dev;
David Brownellc6de2b62005-05-26 05:55:55 -070045} local_info_t;
46
Dominik Brodowskifba395e2006-03-31 17:21:06 +020047static void sl811_cs_release(struct pcmcia_device * link);
Dominik Brodowskicc3b4862005-11-14 21:23:14 +010048
David Brownellc6de2b62005-05-26 05:55:55 -070049/*====================================================================*/
50
51static void release_platform_dev(struct device * dev)
52{
Dominik Brodowski9b44de22009-10-24 15:55:39 +020053 dev_dbg(dev, "sl811_cs platform_dev release\n");
David Brownellc6de2b62005-05-26 05:55:55 -070054 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
David Brownella0c53f12006-02-06 12:15:15 -080077extern struct platform_driver sl811h_driver;
David Brownellc6de2b62005-05-26 05:55:55 -070078
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
Dominik Brodowskid39bd562008-08-28 01:05:34 +020089static int sl811_hc_init(struct device *parent, resource_size_t base_addr,
90 int irq)
David Brownellc6de2b62005-05-26 05:55:55 -070091{
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
David Brownellc9a50cc2005-11-07 20:45:20 -0800106 * initialized already because of the link order dependency created
107 * by referencing "sl811h_driver".
David Brownellc6de2b62005-05-26 05:55:55 -0700108 */
David Brownella0c53f12006-02-06 12:15:15 -0800109 platform_dev.name = sl811h_driver.driver.name;
David Brownellc6de2b62005-05-26 05:55:55 -0700110 return platform_device_register(&platform_dev);
111}
112
113/*====================================================================*/
114
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200115static void sl811_cs_detach(struct pcmcia_device *link)
David Brownellc6de2b62005-05-26 05:55:55 -0700116{
Dominik Brodowski9b44de22009-10-24 15:55:39 +0200117 dev_dbg(&link->dev, "sl811_cs_detach\n");
David Brownellc6de2b62005-05-26 05:55:55 -0700118
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100119 sl811_cs_release(link);
David Brownellc6de2b62005-05-26 05:55:55 -0700120
David Brownellc6de2b62005-05-26 05:55:55 -0700121 /* This points to the parent local_info_t struct */
122 kfree(link->priv);
123}
124
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200125static void sl811_cs_release(struct pcmcia_device * link)
David Brownellc6de2b62005-05-26 05:55:55 -0700126{
Dominik Brodowski9b44de22009-10-24 15:55:39 +0200127 dev_dbg(&link->dev, "sl811_cs_release\n");
David Brownellc6de2b62005-05-26 05:55:55 -0700128
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200129 pcmcia_disable_device(link);
David Brownellc6de2b62005-05-26 05:55:55 -0700130 platform_device_unregister(&platform_dev);
David Brownellc6de2b62005-05-26 05:55:55 -0700131}
132
Dominik Brodowski00990e72010-07-30 13:13:46 +0200133static int sl811_cs_config_check(struct pcmcia_device *p_dev, void *priv_data)
Dominik Brodowski84e2d342008-07-29 08:38:55 +0200134{
Dominik Brodowski00990e72010-07-30 13:13:46 +0200135 if (p_dev->config_index == 0)
136 return -EINVAL;
Dominik Brodowski84e2d342008-07-29 08:38:55 +0200137
Dominik Brodowski00990e72010-07-30 13:13:46 +0200138 return pcmcia_request_io(p_dev);
Dominik Brodowski84e2d342008-07-29 08:38:55 +0200139}
140
141
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200142static int sl811_cs_config(struct pcmcia_device *link)
David Brownellc6de2b62005-05-26 05:55:55 -0700143{
Dominik Brodowskidd2e5a12009-11-03 10:27:34 +0100144 struct device *parent = &link->dev;
Dominik Brodowski9b44de22009-10-24 15:55:39 +0200145 int ret;
David Brownellc6de2b62005-05-26 05:55:55 -0700146
Dominik Brodowski9b44de22009-10-24 15:55:39 +0200147 dev_dbg(&link->dev, "sl811_cs_config\n");
David Brownellc6de2b62005-05-26 05:55:55 -0700148
Dominik Brodowski440eed42010-07-30 09:51:52 +0200149 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_VPP |
Dominik Brodowski00990e72010-07-30 13:13:46 +0200150 CONF_AUTO_CHECK_VCC | CONF_AUTO_SET_IO;
Dominik Brodowski440eed42010-07-30 09:51:52 +0200151
Dominik Brodowskiad913c12008-08-02 16:12:00 +0200152 if (pcmcia_loop_config(link, sl811_cs_config_check, NULL))
153 goto failed;
David Brownellc6de2b62005-05-26 05:55:55 -0700154
155 /* require an IRQ and two registers */
Dominik Brodowski9a017a92010-07-24 15:58:54 +0200156 if (resource_size(link->resource[0]) < 2)
Dominik Brodowskiad913c12008-08-02 16:12:00 +0200157 goto failed;
Dominik Brodowskieb141202010-03-07 12:21:16 +0100158
159 if (!link->irq)
Dominik Brodowskiad913c12008-08-02 16:12:00 +0200160 goto failed;
David Brownellc6de2b62005-05-26 05:55:55 -0700161
Dominik Brodowski1ac71e52010-07-29 19:27:09 +0200162 ret = pcmcia_enable_device(link);
Dominik Brodowski9b44de22009-10-24 15:55:39 +0200163 if (ret)
164 goto failed;
David Brownellc6de2b62005-05-26 05:55:55 -0700165
Dominik Brodowski9a017a92010-07-24 15:58:54 +0200166 if (sl811_hc_init(parent, link->resource[0]->start, link->irq)
David Brownellc6de2b62005-05-26 05:55:55 -0700167 < 0) {
Dominik Brodowskiad913c12008-08-02 16:12:00 +0200168failed:
169 printk(KERN_WARNING "sl811_cs_config failed\n");
David Brownellc6de2b62005-05-26 05:55:55 -0700170 sl811_cs_release(link);
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200171 return -ENODEV;
David Brownellc6de2b62005-05-26 05:55:55 -0700172 }
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200173 return 0;
David Brownellc6de2b62005-05-26 05:55:55 -0700174}
175
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200176static int sl811_cs_probe(struct pcmcia_device *link)
David Brownellc6de2b62005-05-26 05:55:55 -0700177{
178 local_info_t *local;
David Brownellc6de2b62005-05-26 05:55:55 -0700179
Yoann Padioleaudd00cc42007-07-19 01:49:03 -0700180 local = kzalloc(sizeof(local_info_t), GFP_KERNEL);
David Brownellc6de2b62005-05-26 05:55:55 -0700181 if (!local)
Dominik Brodowskif8cfa612005-11-14 21:25:51 +0100182 return -ENOMEM;
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200183 local->p_dev = link;
David Brownellc6de2b62005-05-26 05:55:55 -0700184 link->priv = local;
185
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200186 return sl811_cs_config(link);
David Brownellc6de2b62005-05-26 05:55:55 -0700187}
188
Joe Perches25f8f542011-05-03 19:29:01 -0700189static const struct pcmcia_device_id sl811_ids[] = {
David Brownell22f3a8f2005-06-27 16:28:43 -0700190 PCMCIA_DEVICE_MANF_CARD(0xc015, 0x0001), /* RATOC USB HOST CF+ Card */
191 PCMCIA_DEVICE_NULL,
192};
193MODULE_DEVICE_TABLE(pcmcia, sl811_ids);
194
David Brownellc6de2b62005-05-26 05:55:55 -0700195static struct pcmcia_driver sl811_cs_driver = {
196 .owner = THIS_MODULE,
Dominik Brodowski2e9b9812010-08-08 11:36:26 +0200197 .name = "sl811_cs",
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200198 .probe = sl811_cs_probe,
Dominik Brodowskicc3b4862005-11-14 21:23:14 +0100199 .remove = sl811_cs_detach,
David Brownell22f3a8f2005-06-27 16:28:43 -0700200 .id_table = sl811_ids,
David Brownellc6de2b62005-05-26 05:55:55 -0700201};
H Hartley Sweeten4c7a45f2013-03-06 11:29:17 -0700202module_pcmcia_driver(sl811_cs_driver);