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/init.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/cs.h> 24#include <pcmcia/cistpl.h> 25#include <pcmcia/cisreg.h> 26#include <pcmcia/ds.h> 27 28#include <linux/usb/sl811.h> 29 30MODULE_AUTHOR("Botond Botyanszki"); 31MODULE_DESCRIPTION("REX-CFU1U PCMCIA driver for 2.6"); 32MODULE_LICENSE("GPL"); 33 34 35/*====================================================================*/ 36/* MACROS */ 37/*====================================================================*/ 38 39#define INFO(args...) printk(KERN_INFO "sl811_cs: " args) 40 41/*====================================================================*/ 42/* VARIABLES */ 43/*====================================================================*/ 44 45typedef struct local_info_t { 46 struct pcmcia_device *p_dev; 47} local_info_t; 48 49static void sl811_cs_release(struct pcmcia_device * link); 50 51/*====================================================================*/ 52 53static void release_platform_dev(struct device * dev) 54{ 55 dev_dbg(dev, "sl811_cs platform_dev release\n"); 56 dev->parent = NULL; 57} 58 59static struct sl811_platform_data platform_data = { 60 .potpg = 100, 61 .power = 50, /* == 100mA */ 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 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 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, 135 cistpl_cftable_entry_t *cfg, 136 cistpl_cftable_entry_t *dflt, 137 unsigned int vcc, 138 void *priv_data) 139{ 140 if (cfg->index == 0) 141 return -ENODEV; 142 143 /* Use power settings for Vcc and Vpp if present */ 144 /* Note that the CIS values need to be rescaled */ 145 if (cfg->vcc.present & (1<<CISTPL_POWER_VNOM)) { 146 if (cfg->vcc.param[CISTPL_POWER_VNOM]/10000 != vcc) 147 return -ENODEV; 148 } else if (dflt->vcc.present & (1<<CISTPL_POWER_VNOM)) { 149 if (dflt->vcc.param[CISTPL_POWER_VNOM]/10000 != vcc) 150 return -ENODEV; 151 } 152 153 if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM)) 154 p_dev->conf.Vpp = 155 cfg->vpp1.param[CISTPL_POWER_VNOM]/10000; 156 else if (dflt->vpp1.present & (1<<CISTPL_POWER_VNOM)) 157 p_dev->conf.Vpp = 158 dflt->vpp1.param[CISTPL_POWER_VNOM]/10000; 159 160 /* we need an interrupt */ 161 p_dev->conf.Attributes |= CONF_ENABLE_IRQ; 162 163 /* IO window settings */ 164 p_dev->resource[0]->end = p_dev->resource[1]->end = 0; 165 if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) { 166 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io; 167 p_dev->io_lines = io->flags & CISTPL_IO_LINES_MASK; 168 169 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8; 170 p_dev->resource[0]->start = io->win[0].base; 171 p_dev->resource[0]->end = io->win[0].len; 172 173 return pcmcia_request_io(p_dev); 174 } 175 pcmcia_disable_device(p_dev); 176 return -ENODEV; 177} 178 179 180static int sl811_cs_config(struct pcmcia_device *link) 181{ 182 struct device *parent = &link->dev; 183 int ret; 184 185 dev_dbg(&link->dev, "sl811_cs_config\n"); 186 187 if (pcmcia_loop_config(link, sl811_cs_config_check, NULL)) 188 goto failed; 189 190 /* require an IRQ and two registers */ 191 if (resource_size(link->resource[0]) < 2) 192 goto failed; 193 194 if (!link->irq) 195 goto failed; 196 197 ret = pcmcia_request_configuration(link, &link->conf); 198 if (ret) 199 goto failed; 200 201 dev_info(&link->dev, "index 0x%02x: ", 202 link->conf.ConfigIndex); 203 if (link->conf.Vpp) 204 printk(", Vpp %d.%d", link->conf.Vpp/10, link->conf.Vpp%10); 205 printk(", irq %d", link->irq); 206 printk(", io %pR", link->resource[0]); 207 printk("\n"); 208 209 if (sl811_hc_init(parent, link->resource[0]->start, link->irq) 210 < 0) { 211failed: 212 printk(KERN_WARNING "sl811_cs_config failed\n"); 213 sl811_cs_release(link); 214 return -ENODEV; 215 } 216 return 0; 217} 218 219static int sl811_cs_probe(struct pcmcia_device *link) 220{ 221 local_info_t *local; 222 223 local = kzalloc(sizeof(local_info_t), GFP_KERNEL); 224 if (!local) 225 return -ENOMEM; 226 local->p_dev = link; 227 link->priv = local; 228 229 link->conf.Attributes = 0; 230 link->conf.IntType = INT_MEMORY_AND_IO; 231 232 return sl811_cs_config(link); 233} 234 235static struct pcmcia_device_id sl811_ids[] = { 236 PCMCIA_DEVICE_MANF_CARD(0xc015, 0x0001), /* RATOC USB HOST CF+ Card */ 237 PCMCIA_DEVICE_NULL, 238}; 239MODULE_DEVICE_TABLE(pcmcia, sl811_ids); 240 241static struct pcmcia_driver sl811_cs_driver = { 242 .owner = THIS_MODULE, 243 .drv = { 244 .name = "sl811_cs", 245 }, 246 .probe = sl811_cs_probe, 247 .remove = sl811_cs_detach, 248 .id_table = sl811_ids, 249}; 250 251/*====================================================================*/ 252 253static int __init init_sl811_cs(void) 254{ 255 return pcmcia_register_driver(&sl811_cs_driver); 256} 257module_init(init_sl811_cs); 258 259static void __exit exit_sl811_cs(void) 260{ 261 pcmcia_unregister_driver(&sl811_cs_driver); 262} 263module_exit(exit_sl811_cs); 264