Fix divisor settings for external devices like wireless devices, thanks sn9
[openwrt/svn-archive/archive.git] / target / linux / ar7 / files / drivers / vlynq / vlynq.c
1 /*
2 * Copyright (C) 2006, 2007 Eugene Konev <ejka@openwrt.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include <linux/init.h>
20 #include <linux/types.h>
21 #include <linux/kernel.h>
22 #include <linux/string.h>
23 #include <linux/device.h>
24 #include <linux/module.h>
25 #include <linux/errno.h>
26 #include <linux/platform_device.h>
27 #include <linux/interrupt.h>
28 #include <linux/device.h>
29 #include <linux/io.h>
30
31 #include <linux/vlynq.h>
32
33 #define VLYNQ_CTRL_PM_ENABLE 0x80000000
34 #define VLYNQ_CTRL_CLOCK_INT 0x00008000
35 #define VLYNQ_CTRL_CLOCK_DIV(x) (((x) & 7) << 16)
36 #define VLYNQ_CTRL_INT_LOCAL 0x00004000
37 #define VLYNQ_CTRL_INT_ENABLE 0x00002000
38 #define VLYNQ_CTRL_INT_VECTOR(x) (((x) & 0x1f) << 8)
39 #define VLYNQ_CTRL_INT2CFG 0x00000080
40 #define VLYNQ_CTRL_RESET 0x00000001
41
42 #define VLYNQ_INT_OFFSET 0x00000014
43 #define VLYNQ_REMOTE_OFFSET 0x00000080
44
45 #define VLYNQ_STATUS_LINK 0x00000001
46 #define VLYNQ_STATUS_LERROR 0x00000080
47 #define VLYNQ_STATUS_RERROR 0x00000100
48
49 #define VINT_ENABLE 0x00000100
50 #define VINT_TYPE_EDGE 0x00000080
51 #define VINT_LEVEL_LOW 0x00000040
52 #define VINT_VECTOR(x) ((x) & 0x1f)
53 #define VINT_OFFSET(irq) (8 * ((irq) % 4))
54
55 #define VLYNQ_AUTONEGO_V2 0x00010000
56
57 struct vlynq_regs {
58 u32 revision;
59 u32 control;
60 u32 status;
61 u32 int_prio;
62 u32 int_status;
63 u32 int_pending;
64 u32 int_ptr;
65 u32 tx_offset;
66 struct vlynq_mapping rx_mapping[4];
67 u32 chip;
68 u32 autonego;
69 u32 unused[6];
70 u32 int_device[8];
71 };
72
73 #define vlynq_reg_read(reg) readl(&(reg))
74 #define vlynq_reg_write(reg, val) writel(val, &(reg))
75
76 static int __vlynq_enable_device(struct vlynq_device *dev);
77
78 #ifdef VLYNQ_DEBUG
79 static void vlynq_dump_regs(struct vlynq_device *dev)
80 {
81 int i;
82 printk(KERN_DEBUG "VLYNQ local=%p remote=%p\n",
83 dev->local, dev->remote);
84 for (i = 0; i < 32; i++) {
85 printk(KERN_DEBUG "VLYNQ: local %d: %08x\n",
86 i + 1, ((u32 *)dev->local)[i]);
87 printk(KERN_DEBUG "VLYNQ: remote %d: %08x\n",
88 i + 1, ((u32 *)dev->remote)[i]);
89 }
90 }
91
92 static void vlynq_dump_mem(u32 *base, int count)
93 {
94 int i;
95 for (i = 0; i < (count + 3) / 4; i++) {
96 if (i % 4 == 0) printk(KERN_DEBUG "\nMEM[0x%04x]:", i * 4);
97 printk(KERN_DEBUG " 0x%08x", *(base + i));
98 }
99 printk(KERN_DEBUG "\n");
100 }
101 #endif
102
103 int vlynq_linked(struct vlynq_device *dev)
104 {
105 int i;
106
107 for (i = 0; i < 100; i++)
108 if (vlynq_reg_read(dev->local->status) & VLYNQ_STATUS_LINK)
109 return 1;
110 else
111 cpu_relax();
112
113 return 0;
114 }
115
116 static void vlynq_irq_unmask(unsigned int irq)
117 {
118 u32 val;
119 struct vlynq_device *dev = get_irq_chip_data(irq);
120 int virq;
121
122 BUG_ON(!dev);
123 virq = irq - dev->irq_start;
124 val = vlynq_reg_read(dev->remote->int_device[virq >> 2]);
125 val |= (VINT_ENABLE | virq) << VINT_OFFSET(virq);
126 vlynq_reg_write(dev->remote->int_device[virq >> 2], val);
127 }
128
129 static void vlynq_irq_mask(unsigned int irq)
130 {
131 u32 val;
132 struct vlynq_device *dev = get_irq_chip_data(irq);
133 int virq;
134
135 BUG_ON(!dev);
136 virq = irq - dev->irq_start;
137 val = vlynq_reg_read(dev->remote->int_device[virq >> 2]);
138 val &= ~(VINT_ENABLE << VINT_OFFSET(virq));
139 vlynq_reg_write(dev->remote->int_device[virq >> 2], val);
140 }
141
142 static int vlynq_irq_type(unsigned int irq, unsigned int flow_type)
143 {
144 u32 val;
145 struct vlynq_device *dev = get_irq_chip_data(irq);
146 int virq;
147
148 BUG_ON(!dev);
149 virq = irq - dev->irq_start;
150 val = vlynq_reg_read(dev->remote->int_device[virq >> 2]);
151 switch (flow_type & IRQ_TYPE_SENSE_MASK) {
152 case IRQ_TYPE_EDGE_RISING:
153 case IRQ_TYPE_EDGE_FALLING:
154 case IRQ_TYPE_EDGE_BOTH:
155 val |= VINT_TYPE_EDGE << VINT_OFFSET(virq);
156 val &= ~(VINT_LEVEL_LOW << VINT_OFFSET(virq));
157 break;
158 case IRQ_TYPE_LEVEL_HIGH:
159 val &= ~(VINT_TYPE_EDGE << VINT_OFFSET(virq));
160 val &= ~(VINT_LEVEL_LOW << VINT_OFFSET(virq));
161 break;
162 case IRQ_TYPE_LEVEL_LOW:
163 val &= ~(VINT_TYPE_EDGE << VINT_OFFSET(virq));
164 val |= VINT_LEVEL_LOW << VINT_OFFSET(virq);
165 break;
166 default:
167 return -EINVAL;
168 }
169 vlynq_reg_write(dev->remote->int_device[virq >> 2], val);
170 return 0;
171 }
172
173 static void vlynq_local_ack(unsigned int irq)
174 {
175 struct vlynq_device *dev = get_irq_chip_data(irq);
176 u32 status = vlynq_reg_read(dev->local->status);
177 if (printk_ratelimit())
178 printk(KERN_DEBUG "%s: local status: 0x%08x\n",
179 dev->dev.bus_id, status);
180 vlynq_reg_write(dev->local->status, status);
181 }
182
183 static void vlynq_remote_ack(unsigned int irq)
184 {
185 struct vlynq_device *dev = get_irq_chip_data(irq);
186 u32 status = vlynq_reg_read(dev->remote->status);
187 if (printk_ratelimit())
188 printk(KERN_DEBUG "%s: remote status: 0x%08x\n",
189 dev->dev.bus_id, status);
190 vlynq_reg_write(dev->remote->status, status);
191 }
192
193 static irqreturn_t vlynq_irq(int irq, void *dev_id)
194 {
195 struct vlynq_device *dev = dev_id;
196 u32 status;
197 int virq = 0;
198
199 status = vlynq_reg_read(dev->local->int_status);
200 vlynq_reg_write(dev->local->int_status, status);
201
202 if (unlikely(!status))
203 spurious_interrupt();
204
205 while (status) {
206 if (status & 1)
207 do_IRQ(dev->irq_start + virq);
208 status >>= 1;
209 virq++;
210 }
211
212 return IRQ_HANDLED;
213 }
214
215 static struct irq_chip vlynq_irq_chip = {
216 .name = "vlynq",
217 .unmask = vlynq_irq_unmask,
218 .mask = vlynq_irq_mask,
219 .set_type = vlynq_irq_type,
220 };
221
222 static struct irq_chip vlynq_local_chip = {
223 .name = "vlynq local error",
224 .unmask = vlynq_irq_unmask,
225 .mask = vlynq_irq_mask,
226 .ack = vlynq_local_ack,
227 };
228
229 static struct irq_chip vlynq_remote_chip = {
230 .name = "vlynq local error",
231 .unmask = vlynq_irq_unmask,
232 .mask = vlynq_irq_mask,
233 .ack = vlynq_remote_ack,
234 };
235
236 static int vlynq_setup_irq(struct vlynq_device *dev)
237 {
238 u32 val;
239 int i, virq;
240
241 if (dev->local_irq == dev->remote_irq) {
242 printk(KERN_ERR
243 "%s: local vlynq irq should be different from remote\n",
244 dev->dev.bus_id);
245 return -EINVAL;
246 }
247
248 /* Clear local and remote error bits */
249 vlynq_reg_write(dev->local->status, vlynq_reg_read(dev->local->status));
250 vlynq_reg_write(dev->remote->status,
251 vlynq_reg_read(dev->remote->status));
252
253 /* Now setup interrupts */
254 val = VLYNQ_CTRL_INT_VECTOR(dev->local_irq);
255 val |= VLYNQ_CTRL_INT_ENABLE | VLYNQ_CTRL_INT_LOCAL |
256 VLYNQ_CTRL_INT2CFG;
257 val |= vlynq_reg_read(dev->local->control);
258 vlynq_reg_write(dev->local->int_ptr, VLYNQ_INT_OFFSET);
259 vlynq_reg_write(dev->local->control, val);
260
261 val = VLYNQ_CTRL_INT_VECTOR(dev->remote_irq);
262 val |= VLYNQ_CTRL_INT_ENABLE;
263 val |= vlynq_reg_read(dev->remote->control);
264 vlynq_reg_write(dev->remote->int_ptr, VLYNQ_INT_OFFSET);
265 vlynq_reg_write(dev->remote->control, val);
266
267 for (i = dev->irq_start; i <= dev->irq_end; i++) {
268 virq = i - dev->irq_start;
269 if (virq == dev->local_irq) {
270 set_irq_chip_and_handler(i, &vlynq_local_chip,
271 handle_level_irq);
272 set_irq_chip_data(i, dev);
273 } else if (virq == dev->remote_irq) {
274 set_irq_chip_and_handler(i, &vlynq_remote_chip,
275 handle_level_irq);
276 set_irq_chip_data(i, dev);
277 } else {
278 set_irq_chip_and_handler(i, &vlynq_irq_chip,
279 handle_simple_irq);
280 set_irq_chip_data(i, dev);
281 vlynq_reg_write(dev->remote->int_device[virq >> 2], 0);
282 }
283 }
284
285 if (request_irq(dev->irq, vlynq_irq, IRQF_SHARED, "vlynq", dev)) {
286 printk(KERN_ERR "%s: request_irq failed\n", dev->dev.bus_id);
287 return -EAGAIN;
288 }
289
290 return 0;
291 }
292
293 static void vlynq_device_release(struct device *dev)
294 {
295 struct vlynq_device *vdev = to_vlynq_device(dev);
296 kfree(vdev);
297 }
298
299 static int vlynq_device_match(struct device *dev,
300 struct device_driver *drv)
301 {
302 struct vlynq_device *vdev = to_vlynq_device(dev);
303 struct vlynq_driver *vdrv = to_vlynq_driver(drv);
304 struct plat_vlynq_ops *ops = dev->platform_data;
305 struct vlynq_device_id *ids = vdrv->id_table;
306 u32 id = 0;
307 int result, flag;
308
309 while (ids->id) {
310 flag = 0;
311 if (ids->divisor != vlynq_div_auto
312 && vdev->divisor == vlynq_div_auto) {
313 flag = 1;
314 vdev->divisor = ids->divisor;
315 result = __vlynq_enable_device(vdev);
316 if (result == 0) {
317 id = vlynq_reg_read(vdev->remote->chip);
318 vlynq_reg_write(vdev->local->control, 0);
319 vlynq_reg_write(vdev->remote->control, 0);
320 ops->off(vdev);
321 } else
322 id = vdev->dev_id;
323 } else
324 id = vdev->dev_id;
325 if (ids->id == id) {
326 vdev->dev_id = id;
327 vlynq_set_drvdata(vdev, ids);
328 printk(KERN_INFO "Driver found for VLYNQ " \
329 "device: %08x\n", id);
330 return 1;
331 }
332 printk(KERN_INFO "Not using the %08x VLYNQ device's " \
333 "driver for VLYNQ device: %08x\n", ids->id, id);
334 ids++;
335 if (flag)
336 vdev->divisor = vlynq_div_auto;
337 }
338 return 0;
339 }
340
341 static int vlynq_device_probe(struct device *dev)
342 {
343 struct vlynq_device *vdev = to_vlynq_device(dev);
344 struct vlynq_driver *drv = to_vlynq_driver(dev->driver);
345 struct vlynq_device_id *id = vlynq_get_drvdata(vdev);
346 int result = -ENODEV;
347
348 get_device(dev);
349 if (drv && drv->probe)
350 result = drv->probe(vdev, id);
351 if (result)
352 put_device(dev);
353 return result;
354 }
355
356 static int vlynq_device_remove(struct device *dev)
357 {
358 struct vlynq_driver *drv = to_vlynq_driver(dev->driver);
359 if (drv && drv->remove)
360 drv->remove(to_vlynq_device(dev));
361 put_device(dev);
362 return 0;
363 }
364
365 int __vlynq_register_driver(struct vlynq_driver *driver, struct module *owner)
366 {
367 driver->driver.name = driver->name;
368 driver->driver.bus = &vlynq_bus_type;
369 return driver_register(&driver->driver);
370 }
371 EXPORT_SYMBOL(__vlynq_register_driver);
372
373 void vlynq_unregister_driver(struct vlynq_driver *driver)
374 {
375 driver_unregister(&driver->driver);
376 }
377 EXPORT_SYMBOL(vlynq_unregister_driver);
378
379 static int __vlynq_enable_device(struct vlynq_device *dev)
380 {
381 int i, result;
382 struct plat_vlynq_ops *ops = dev->dev.platform_data;
383
384 result = ops->on(dev);
385 if (result)
386 return result;
387
388 vlynq_reg_write(dev->local->control, 0);
389 vlynq_reg_write(dev->remote->control, 0);
390 if (vlynq_linked(dev)) {
391 printk(KERN_DEBUG "%s: using external clock\n",
392 dev->dev.bus_id);
393 return 0;
394 }
395
396 switch (dev->divisor) {
397 case vlynq_div_auto:
398 /* Only try locally supplied clock, others cause problems */
399 vlynq_reg_write(dev->local->control, 0);
400 vlynq_reg_write(dev->remote->control, 0);
401 for (i = vlynq_ldiv2; i <= vlynq_ldiv8; i++) {
402 vlynq_reg_write(dev->local->control,
403 VLYNQ_CTRL_CLOCK_INT |
404 VLYNQ_CTRL_CLOCK_DIV(i - vlynq_ldiv1));
405 if (vlynq_linked(dev)) {
406 printk(KERN_DEBUG
407 "%s: using local clock divisor %d\n",
408 dev->dev.bus_id, i - vlynq_ldiv1 + 1);
409 dev->divisor = i;
410 return 0;
411 }
412 }
413 case vlynq_ldiv1: case vlynq_ldiv2: case vlynq_ldiv3: case vlynq_ldiv4:
414 case vlynq_ldiv5: case vlynq_ldiv6: case vlynq_ldiv7: case vlynq_ldiv8:
415 vlynq_reg_write(dev->local->control,
416 VLYNQ_CTRL_CLOCK_INT |
417 VLYNQ_CTRL_CLOCK_DIV(dev->divisor -
418 vlynq_ldiv1));
419 vlynq_reg_write(dev->remote->control, 0);
420 if (vlynq_linked(dev)) {
421 printk(KERN_DEBUG
422 "%s: using local clock divisor %d\n",
423 dev->dev.bus_id, dev->divisor - vlynq_ldiv1 + 1);
424 return 0;
425 }
426 break;
427 case vlynq_rdiv1: case vlynq_rdiv2: case vlynq_rdiv3: case vlynq_rdiv4:
428 case vlynq_rdiv5: case vlynq_rdiv6: case vlynq_rdiv7: case vlynq_rdiv8:
429 vlynq_reg_write(dev->local->control, 0);
430 vlynq_reg_write(dev->remote->control,
431 VLYNQ_CTRL_CLOCK_INT |
432 VLYNQ_CTRL_CLOCK_DIV(dev->divisor -
433 vlynq_rdiv1));
434 if (vlynq_linked(dev)) {
435 printk(KERN_DEBUG
436 "%s: using remote clock divisor %d\n",
437 dev->dev.bus_id, dev->divisor - vlynq_rdiv1 + 1);
438 return 0;
439 }
440 break;
441 }
442
443 ops->off(dev);
444 return -ENODEV;
445 }
446
447 int vlynq_enable_device(struct vlynq_device *dev)
448 {
449 struct plat_vlynq_ops *ops = dev->dev.platform_data;
450 int result = -ENODEV;
451
452 result = __vlynq_enable_device(dev);
453 if (result)
454 return result;
455
456 result = vlynq_setup_irq(dev);
457 if (result)
458 ops->off(dev);
459
460 dev->enabled = !result;
461 return result;
462 }
463 EXPORT_SYMBOL(vlynq_enable_device);
464
465
466 void vlynq_disable_device(struct vlynq_device *dev)
467 {
468 struct plat_vlynq_ops *ops = dev->dev.platform_data;
469
470 dev->enabled = 0;
471 free_irq(dev->irq, dev);
472 ops->off(dev);
473 }
474 EXPORT_SYMBOL(vlynq_disable_device);
475
476 int vlynq_set_local_mapping(struct vlynq_device *dev, u32 tx_offset,
477 struct vlynq_mapping *mapping)
478 {
479 int i;
480
481 if (!dev->enabled)
482 return -ENXIO;
483
484 vlynq_reg_write(dev->local->tx_offset, tx_offset);
485 for (i = 0; i < 4; i++) {
486 vlynq_reg_write(dev->local->rx_mapping[i].offset,
487 mapping[i].offset);
488 vlynq_reg_write(dev->local->rx_mapping[i].size,
489 mapping[i].size);
490 }
491 return 0;
492 }
493 EXPORT_SYMBOL(vlynq_set_local_mapping);
494
495 int vlynq_set_remote_mapping(struct vlynq_device *dev, u32 tx_offset,
496 struct vlynq_mapping *mapping)
497 {
498 int i;
499
500 if (!dev->enabled)
501 return -ENXIO;
502
503 vlynq_reg_write(dev->remote->tx_offset, tx_offset);
504 for (i = 0; i < 4; i++) {
505 vlynq_reg_write(dev->remote->rx_mapping[i].offset,
506 mapping[i].offset);
507 vlynq_reg_write(dev->remote->rx_mapping[i].size,
508 mapping[i].size);
509 }
510 return 0;
511 }
512 EXPORT_SYMBOL(vlynq_set_remote_mapping);
513
514 int vlynq_set_local_irq(struct vlynq_device *dev, int virq)
515 {
516 int irq = dev->irq_start + virq;
517 if (dev->enabled)
518 return -EBUSY;
519
520 if ((irq < dev->irq_start) || (irq > dev->irq_end))
521 return -EINVAL;
522
523 if (virq == dev->remote_irq)
524 return -EINVAL;
525
526 dev->local_irq = virq;
527
528 return 0;
529 }
530 EXPORT_SYMBOL(vlynq_set_local_irq);
531
532 int vlynq_set_remote_irq(struct vlynq_device *dev, int virq)
533 {
534 int irq = dev->irq_start + virq;
535 if (dev->enabled)
536 return -EBUSY;
537
538 if ((irq < dev->irq_start) || (irq > dev->irq_end))
539 return -EINVAL;
540
541 if (virq == dev->local_irq)
542 return -EINVAL;
543
544 dev->remote_irq = virq;
545
546 return 0;
547 }
548 EXPORT_SYMBOL(vlynq_set_remote_irq);
549
550 static int vlynq_probe(struct platform_device *pdev)
551 {
552 struct vlynq_device *dev;
553 struct resource *regs_res, *mem_res, *irq_res;
554 int len, result;
555
556 regs_res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs");
557 if (!regs_res)
558 return -ENODEV;
559
560 mem_res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mem");
561 if (!mem_res)
562 return -ENODEV;
563
564 irq_res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "devirq");
565 if (!irq_res)
566 return -ENODEV;
567
568 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
569 if (!dev) {
570 printk(KERN_ERR
571 "vlynq: failed to allocate device structure\n");
572 return -ENOMEM;
573 }
574
575 dev->id = pdev->id;
576 dev->dev.bus = &vlynq_bus_type;
577 dev->dev.parent = &pdev->dev;
578 snprintf(dev->dev.bus_id, BUS_ID_SIZE, "vlynq%d", dev->id);
579 dev->dev.bus_id[BUS_ID_SIZE - 1] = 0;
580 dev->dev.platform_data = pdev->dev.platform_data;
581 dev->dev.release = vlynq_device_release;
582
583 dev->regs_start = regs_res->start;
584 dev->regs_end = regs_res->end;
585 dev->mem_start = mem_res->start;
586 dev->mem_end = mem_res->end;
587
588 len = regs_res->end - regs_res->start;
589 if (!request_mem_region(regs_res->start, len, dev->dev.bus_id)) {
590 printk(KERN_ERR "%s: Can't request vlynq registers\n",
591 dev->dev.bus_id);
592 result = -ENXIO;
593 goto fail_request;
594 }
595
596 dev->local = ioremap(regs_res->start, len);
597 if (!dev->local) {
598 printk(KERN_ERR "%s: Can't remap vlynq registers\n",
599 dev->dev.bus_id);
600 result = -ENXIO;
601 goto fail_remap;
602 }
603
604 dev->remote = (struct vlynq_regs *)((void *)dev->local +
605 VLYNQ_REMOTE_OFFSET);
606
607 dev->irq = platform_get_irq_byname(pdev, "irq");
608 dev->irq_start = irq_res->start;
609 dev->irq_end = irq_res->end;
610 dev->local_irq = dev->irq_end - dev->irq_start;
611 dev->remote_irq = dev->local_irq - 1;
612
613 if (device_register(&dev->dev))
614 goto fail_register;
615 platform_set_drvdata(pdev, dev);
616
617 printk(KERN_INFO "%s: regs 0x%p, irq %d, mem 0x%p\n",
618 dev->dev.bus_id, (void *)dev->regs_start, dev->irq,
619 (void *)dev->mem_start);
620
621 dev->divisor = vlynq_div_auto;
622 result = __vlynq_enable_device(dev);
623 if (result == 0) {
624 dev->dev_id = vlynq_reg_read(dev->remote->chip);
625 vlynq_reg_write(dev->local->control, 0);
626 vlynq_reg_write(dev->remote->control, 0);
627 ((struct plat_vlynq_ops *)(dev->dev.platform_data))->off(dev);
628 } else
629 dev->dev_id = 0;
630 if (dev->dev_id)
631 printk(KERN_INFO "Found a VLYNQ device: %08x\n", dev->dev_id);
632
633 return 0;
634
635 fail_register:
636 iounmap(dev->local);
637 fail_remap:
638 fail_request:
639 release_mem_region(regs_res->start, len);
640 kfree(dev);
641 return result;
642 }
643
644 static int vlynq_remove(struct platform_device *pdev)
645 {
646 struct vlynq_device *dev = platform_get_drvdata(pdev);
647
648 device_unregister(&dev->dev);
649 iounmap(dev->local);
650 release_mem_region(dev->regs_start, dev->regs_end - dev->regs_start);
651
652 kfree(dev);
653
654 return 0;
655 }
656
657 static struct platform_driver vlynq_platform_driver = {
658 .driver.name = "vlynq",
659 .probe = vlynq_probe,
660 .remove = __devexit_p(vlynq_remove),
661 };
662
663 struct bus_type vlynq_bus_type = {
664 .name = "vlynq",
665 .match = vlynq_device_match,
666 .probe = vlynq_device_probe,
667 .remove = vlynq_device_remove,
668 };
669 EXPORT_SYMBOL(vlynq_bus_type);
670
671 static int __devinit vlynq_init(void)
672 {
673 int res = 0;
674
675 res = bus_register(&vlynq_bus_type);
676 if (res)
677 goto fail_bus;
678
679 res = platform_driver_register(&vlynq_platform_driver);
680 if (res)
681 goto fail_platform;
682
683 return 0;
684
685 fail_platform:
686 bus_unregister(&vlynq_bus_type);
687 fail_bus:
688 return res;
689 }
690
691 static void __devexit vlynq_exit(void)
692 {
693 platform_driver_unregister(&vlynq_platform_driver);
694 bus_unregister(&vlynq_bus_type);
695 }
696
697 module_init(vlynq_init);
698 module_exit(vlynq_exit);