blob: 22e04f206304ad96e10cdb9cd551a4e16dd25d17 [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/cs.h>
24#include <pcmcia/cistpl.h>
25#include <pcmcia/cisreg.h>
26#include <pcmcia/ds.h>
27
David Brownell325a4af2006-06-13 09:59:32 -070028#include <linux/usb/sl811.h>
David Brownellc6de2b62005-05-26 05:55:55 -070029
30MODULE_AUTHOR("Botond Botyanszki");
31MODULE_DESCRIPTION("REX-CFU1U PCMCIA driver for 2.6");
32MODULE_LICENSE("GPL");
33
34
35/*====================================================================*/
36/* MACROS */
37/*====================================================================*/
38
David Brownellc6de2b62005-05-26 05:55:55 -070039#define INFO(args...) printk(KERN_INFO "sl811_cs: " args)
40
David Brownellc6de2b62005-05-26 05:55:55 -070041/*====================================================================*/
42/* VARIABLES */
43/*====================================================================*/
44
David Brownellc6de2b62005-05-26 05:55:55 -070045typedef struct local_info_t {
Dominik Brodowskifd238232006-03-05 10:45:09 +010046 struct pcmcia_device *p_dev;
David Brownellc6de2b62005-05-26 05:55:55 -070047} local_info_t;
48
Dominik Brodowskifba395e2006-03-31 17:21:06 +020049static void sl811_cs_release(struct pcmcia_device * link);
Dominik Brodowskicc3b4862005-11-14 21:23:14 +010050
David Brownellc6de2b62005-05-26 05:55:55 -070051/*====================================================================*/
52
53static void release_platform_dev(struct device * dev)
54{
Dominik Brodowski9b44de22009-10-24 15:55:39 +020055 dev_dbg(dev, "sl811_cs platform_dev release\n");
David Brownellc6de2b62005-05-26 05:55:55 -070056 dev->parent = NULL;
57}
58
59static struct sl811_platform_data platform_data = {
60 .potpg = 100,
61 .power = 50, /* == 100mA */
62 // .reset = ... FIXME: invoke CF reset on the card
63};
64
65static struct resource resources[] = {
66 [0] = {
67 .flags = IORESOURCE_IRQ,
68 },
69 [1] = {
70 // .name = "address",
71 .flags = IORESOURCE_IO,
72 },
73 [2] = {
74 // .name = "data",
75 .flags = IORESOURCE_IO,
76 },
77};
78
David Brownella0c53f12006-02-06 12:15:15 -080079extern struct platform_driver sl811h_driver;
David Brownellc6de2b62005-05-26 05:55:55 -070080
81static struct platform_device platform_dev = {
82 .id = -1,
83 .dev = {
84 .platform_data = &platform_data,
85 .release = release_platform_dev,
86 },
87 .resource = resources,
88 .num_resources = ARRAY_SIZE(resources),
89};
90
Dominik Brodowskid39bd562008-08-28 01:05:34 +020091static int sl811_hc_init(struct device *parent, resource_size_t base_addr,
92 int irq)
David Brownellc6de2b62005-05-26 05:55:55 -070093{
94 if (platform_dev.dev.parent)
95 return -EBUSY;
96 platform_dev.dev.parent = parent;
97
98 /* finish seting up the platform device */
99 resources[0].start = irq;
100
101 resources[1].start = base_addr;
102 resources[1].end = base_addr;
103
104 resources[2].start = base_addr + 1;
105 resources[2].end = base_addr + 1;
106
107 /* The driver core will probe for us. We know sl811-hcd has been
David Brownellc9a50cc2005-11-07 20:45:20 -0800108 * initialized already because of the link order dependency created
109 * by referencing "sl811h_driver".
David Brownellc6de2b62005-05-26 05:55:55 -0700110 */
David Brownella0c53f12006-02-06 12:15:15 -0800111 platform_dev.name = sl811h_driver.driver.name;
David Brownellc6de2b62005-05-26 05:55:55 -0700112 return platform_device_register(&platform_dev);
113}
114
115/*====================================================================*/
116
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200117static void sl811_cs_detach(struct pcmcia_device *link)
David Brownellc6de2b62005-05-26 05:55:55 -0700118{
Dominik Brodowski9b44de22009-10-24 15:55:39 +0200119 dev_dbg(&link->dev, "sl811_cs_detach\n");
David Brownellc6de2b62005-05-26 05:55:55 -0700120
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100121 sl811_cs_release(link);
David Brownellc6de2b62005-05-26 05:55:55 -0700122
David Brownellc6de2b62005-05-26 05:55:55 -0700123 /* This points to the parent local_info_t struct */
124 kfree(link->priv);
125}
126
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200127static void sl811_cs_release(struct pcmcia_device * link)
David Brownellc6de2b62005-05-26 05:55:55 -0700128{
Dominik Brodowski9b44de22009-10-24 15:55:39 +0200129 dev_dbg(&link->dev, "sl811_cs_release\n");
David Brownellc6de2b62005-05-26 05:55:55 -0700130
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200131 pcmcia_disable_device(link);
David Brownellc6de2b62005-05-26 05:55:55 -0700132 platform_device_unregister(&platform_dev);
David Brownellc6de2b62005-05-26 05:55:55 -0700133}
134
Dominik Brodowski84e2d342008-07-29 08:38:55 +0200135static int sl811_cs_config_check(struct pcmcia_device *p_dev,
136 cistpl_cftable_entry_t *cfg,
Dominik Brodowski8e2fc392008-08-02 15:30:31 +0200137 cistpl_cftable_entry_t *dflt,
Dominik Brodowskiad913c12008-08-02 16:12:00 +0200138 unsigned int vcc,
Dominik Brodowski84e2d342008-07-29 08:38:55 +0200139 void *priv_data)
140{
Dominik Brodowski84e2d342008-07-29 08:38:55 +0200141 if (cfg->index == 0)
142 return -ENODEV;
143
Dominik Brodowski84e2d342008-07-29 08:38:55 +0200144 /* Use power settings for Vcc and Vpp if present */
145 /* Note that the CIS values need to be rescaled */
146 if (cfg->vcc.present & (1<<CISTPL_POWER_VNOM)) {
Dominik Brodowskiad913c12008-08-02 16:12:00 +0200147 if (cfg->vcc.param[CISTPL_POWER_VNOM]/10000 != vcc)
Dominik Brodowski84e2d342008-07-29 08:38:55 +0200148 return -ENODEV;
Dominik Brodowski8e2fc392008-08-02 15:30:31 +0200149 } else if (dflt->vcc.present & (1<<CISTPL_POWER_VNOM)) {
Dominik Brodowskiad913c12008-08-02 16:12:00 +0200150 if (dflt->vcc.param[CISTPL_POWER_VNOM]/10000 != vcc)
Dominik Brodowski84e2d342008-07-29 08:38:55 +0200151 return -ENODEV;
152 }
153
154 if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM))
155 p_dev->conf.Vpp =
156 cfg->vpp1.param[CISTPL_POWER_VNOM]/10000;
Dominik Brodowski8e2fc392008-08-02 15:30:31 +0200157 else if (dflt->vpp1.present & (1<<CISTPL_POWER_VNOM))
Dominik Brodowski84e2d342008-07-29 08:38:55 +0200158 p_dev->conf.Vpp =
Dominik Brodowski8e2fc392008-08-02 15:30:31 +0200159 dflt->vpp1.param[CISTPL_POWER_VNOM]/10000;
Dominik Brodowski84e2d342008-07-29 08:38:55 +0200160
161 /* we need an interrupt */
Dominik Brodowskieb141202010-03-07 12:21:16 +0100162 p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
Dominik Brodowski84e2d342008-07-29 08:38:55 +0200163
164 /* IO window settings */
165 p_dev->io.NumPorts1 = p_dev->io.NumPorts2 = 0;
Dominik Brodowski8e2fc392008-08-02 15:30:31 +0200166 if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
167 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
Dominik Brodowski84e2d342008-07-29 08:38:55 +0200168
169 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
170 p_dev->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
171 p_dev->io.BasePort1 = io->win[0].base;
172 p_dev->io.NumPorts1 = io->win[0].len;
173
174 return pcmcia_request_io(p_dev, &p_dev->io);
175 }
176 pcmcia_disable_device(p_dev);
177 return -ENODEV;
178}
179
180
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200181static int sl811_cs_config(struct pcmcia_device *link)
David Brownellc6de2b62005-05-26 05:55:55 -0700182{
Dominik Brodowskidd2e5a12009-11-03 10:27:34 +0100183 struct device *parent = &link->dev;
Dominik Brodowski9b44de22009-10-24 15:55:39 +0200184 int ret;
David Brownellc6de2b62005-05-26 05:55:55 -0700185
Dominik Brodowski9b44de22009-10-24 15:55:39 +0200186 dev_dbg(&link->dev, "sl811_cs_config\n");
David Brownellc6de2b62005-05-26 05:55:55 -0700187
Dominik Brodowskiad913c12008-08-02 16:12:00 +0200188 if (pcmcia_loop_config(link, sl811_cs_config_check, NULL))
189 goto failed;
David Brownellc6de2b62005-05-26 05:55:55 -0700190
191 /* require an IRQ and two registers */
Dominik Brodowski9a017a92010-07-24 15:58:54 +0200192 if (resource_size(link->resource[0]) < 2)
Dominik Brodowskiad913c12008-08-02 16:12:00 +0200193 goto failed;
Dominik Brodowskieb141202010-03-07 12:21:16 +0100194
195 if (!link->irq)
Dominik Brodowskiad913c12008-08-02 16:12:00 +0200196 goto failed;
David Brownellc6de2b62005-05-26 05:55:55 -0700197
Dominik Brodowski9b44de22009-10-24 15:55:39 +0200198 ret = pcmcia_request_configuration(link, &link->conf);
199 if (ret)
200 goto failed;
David Brownellc6de2b62005-05-26 05:55:55 -0700201
Dominik Brodowskided6a1a2010-03-20 19:35:12 +0100202 dev_info(&link->dev, "index 0x%02x: ",
203 link->conf.ConfigIndex);
Dominik Brodowski70294b42006-01-15 12:43:16 +0100204 if (link->conf.Vpp)
205 printk(", Vpp %d.%d", link->conf.Vpp/10, link->conf.Vpp%10);
Dominik Brodowskieb141202010-03-07 12:21:16 +0100206 printk(", irq %d", link->irq);
Dominik Brodowski9a017a92010-07-24 15:58:54 +0200207 printk(", io %pR", link->resource[0]);
David Brownellc6de2b62005-05-26 05:55:55 -0700208 printk("\n");
209
Dominik Brodowski9a017a92010-07-24 15:58:54 +0200210 if (sl811_hc_init(parent, link->resource[0]->start, link->irq)
David Brownellc6de2b62005-05-26 05:55:55 -0700211 < 0) {
Dominik Brodowskiad913c12008-08-02 16:12:00 +0200212failed:
213 printk(KERN_WARNING "sl811_cs_config failed\n");
David Brownellc6de2b62005-05-26 05:55:55 -0700214 sl811_cs_release(link);
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200215 return -ENODEV;
David Brownellc6de2b62005-05-26 05:55:55 -0700216 }
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200217 return 0;
David Brownellc6de2b62005-05-26 05:55:55 -0700218}
219
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200220static int sl811_cs_probe(struct pcmcia_device *link)
David Brownellc6de2b62005-05-26 05:55:55 -0700221{
222 local_info_t *local;
David Brownellc6de2b62005-05-26 05:55:55 -0700223
Yoann Padioleaudd00cc42007-07-19 01:49:03 -0700224 local = kzalloc(sizeof(local_info_t), GFP_KERNEL);
David Brownellc6de2b62005-05-26 05:55:55 -0700225 if (!local)
Dominik Brodowskif8cfa612005-11-14 21:25:51 +0100226 return -ENOMEM;
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200227 local->p_dev = link;
David Brownellc6de2b62005-05-26 05:55:55 -0700228 link->priv = local;
229
David Brownellc6de2b62005-05-26 05:55:55 -0700230 link->conf.Attributes = 0;
David Brownellc6de2b62005-05-26 05:55:55 -0700231 link->conf.IntType = INT_MEMORY_AND_IO;
232
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200233 return sl811_cs_config(link);
David Brownellc6de2b62005-05-26 05:55:55 -0700234}
235
David Brownell22f3a8f2005-06-27 16:28:43 -0700236static struct pcmcia_device_id sl811_ids[] = {
237 PCMCIA_DEVICE_MANF_CARD(0xc015, 0x0001), /* RATOC USB HOST CF+ Card */
238 PCMCIA_DEVICE_NULL,
239};
240MODULE_DEVICE_TABLE(pcmcia, sl811_ids);
241
David Brownellc6de2b62005-05-26 05:55:55 -0700242static struct pcmcia_driver sl811_cs_driver = {
243 .owner = THIS_MODULE,
244 .drv = {
Dominik Brodowskiac8b4222010-07-21 22:38:13 +0200245 .name = "sl811_cs",
David Brownellc6de2b62005-05-26 05:55:55 -0700246 },
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200247 .probe = sl811_cs_probe,
Dominik Brodowskicc3b4862005-11-14 21:23:14 +0100248 .remove = sl811_cs_detach,
David Brownell22f3a8f2005-06-27 16:28:43 -0700249 .id_table = sl811_ids,
David Brownellc6de2b62005-05-26 05:55:55 -0700250};
251
252/*====================================================================*/
253
254static int __init init_sl811_cs(void)
255{
256 return pcmcia_register_driver(&sl811_cs_driver);
257}
258module_init(init_sl811_cs);
259
260static void __exit exit_sl811_cs(void)
261{
262 pcmcia_unregister_driver(&sl811_cs_driver);
263}
264module_exit(exit_sl811_cs);