Merge branch 'topic/usb' into for-linus
[firewire-audio.git] / drivers / vlynq / vlynq.c
blobf2d9e667972da120d3c39ab87965566fe5c13506
1 /*
2 * Copyright (C) 2006, 2007 Eugene Konev <ejka@openwrt.org>
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.
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.
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
18 * Parts of the VLYNQ specification can be found here:
19 * http://www.ti.com/litv/pdf/sprue36a
22 #include <linux/init.h>
23 #include <linux/types.h>
24 #include <linux/kernel.h>
25 #include <linux/string.h>
26 #include <linux/device.h>
27 #include <linux/module.h>
28 #include <linux/errno.h>
29 #include <linux/platform_device.h>
30 #include <linux/interrupt.h>
31 #include <linux/delay.h>
32 #include <linux/io.h>
33 #include <linux/slab.h>
35 #include <linux/vlynq.h>
37 #define VLYNQ_CTRL_PM_ENABLE 0x80000000
38 #define VLYNQ_CTRL_CLOCK_INT 0x00008000
39 #define VLYNQ_CTRL_CLOCK_DIV(x) (((x) & 7) << 16)
40 #define VLYNQ_CTRL_INT_LOCAL 0x00004000
41 #define VLYNQ_CTRL_INT_ENABLE 0x00002000
42 #define VLYNQ_CTRL_INT_VECTOR(x) (((x) & 0x1f) << 8)
43 #define VLYNQ_CTRL_INT2CFG 0x00000080
44 #define VLYNQ_CTRL_RESET 0x00000001
46 #define VLYNQ_CTRL_CLOCK_MASK (0x7 << 16)
48 #define VLYNQ_INT_OFFSET 0x00000014
49 #define VLYNQ_REMOTE_OFFSET 0x00000080
51 #define VLYNQ_STATUS_LINK 0x00000001
52 #define VLYNQ_STATUS_LERROR 0x00000080
53 #define VLYNQ_STATUS_RERROR 0x00000100
55 #define VINT_ENABLE 0x00000100
56 #define VINT_TYPE_EDGE 0x00000080
57 #define VINT_LEVEL_LOW 0x00000040
58 #define VINT_VECTOR(x) ((x) & 0x1f)
59 #define VINT_OFFSET(irq) (8 * ((irq) % 4))
61 #define VLYNQ_AUTONEGO_V2 0x00010000
63 struct vlynq_regs {
64 u32 revision;
65 u32 control;
66 u32 status;
67 u32 int_prio;
68 u32 int_status;
69 u32 int_pending;
70 u32 int_ptr;
71 u32 tx_offset;
72 struct vlynq_mapping rx_mapping[4];
73 u32 chip;
74 u32 autonego;
75 u32 unused[6];
76 u32 int_device[8];
79 #ifdef CONFIG_VLYNQ_DEBUG
80 static void vlynq_dump_regs(struct vlynq_device *dev)
82 int i;
84 printk(KERN_DEBUG "VLYNQ local=%p remote=%p\n",
85 dev->local, dev->remote);
86 for (i = 0; i < 32; i++) {
87 printk(KERN_DEBUG "VLYNQ: local %d: %08x\n",
88 i + 1, ((u32 *)dev->local)[i]);
89 printk(KERN_DEBUG "VLYNQ: remote %d: %08x\n",
90 i + 1, ((u32 *)dev->remote)[i]);
94 static void vlynq_dump_mem(u32 *base, int count)
96 int i;
98 for (i = 0; i < (count + 3) / 4; i++) {
99 if (i % 4 == 0)
100 printk(KERN_DEBUG "\nMEM[0x%04x]:", i * 4);
101 printk(KERN_DEBUG " 0x%08x", *(base + i));
103 printk(KERN_DEBUG "\n");
105 #endif
107 /* Check the VLYNQ link status with a given device */
108 static int vlynq_linked(struct vlynq_device *dev)
110 int i;
112 for (i = 0; i < 100; i++)
113 if (readl(&dev->local->status) & VLYNQ_STATUS_LINK)
114 return 1;
115 else
116 cpu_relax();
118 return 0;
121 static void vlynq_reset(struct vlynq_device *dev)
123 writel(readl(&dev->local->control) | VLYNQ_CTRL_RESET,
124 &dev->local->control);
126 /* Wait for the devices to finish resetting */
127 msleep(5);
129 /* Remove reset bit */
130 writel(readl(&dev->local->control) & ~VLYNQ_CTRL_RESET,
131 &dev->local->control);
133 /* Give some time for the devices to settle */
134 msleep(5);
137 static void vlynq_irq_unmask(unsigned int irq)
139 u32 val;
140 struct vlynq_device *dev = get_irq_chip_data(irq);
141 int virq;
143 BUG_ON(!dev);
144 virq = irq - dev->irq_start;
145 val = readl(&dev->remote->int_device[virq >> 2]);
146 val |= (VINT_ENABLE | virq) << VINT_OFFSET(virq);
147 writel(val, &dev->remote->int_device[virq >> 2]);
150 static void vlynq_irq_mask(unsigned int irq)
152 u32 val;
153 struct vlynq_device *dev = get_irq_chip_data(irq);
154 int virq;
156 BUG_ON(!dev);
157 virq = irq - dev->irq_start;
158 val = readl(&dev->remote->int_device[virq >> 2]);
159 val &= ~(VINT_ENABLE << VINT_OFFSET(virq));
160 writel(val, &dev->remote->int_device[virq >> 2]);
163 static int vlynq_irq_type(unsigned int irq, unsigned int flow_type)
165 u32 val;
166 struct vlynq_device *dev = get_irq_chip_data(irq);
167 int virq;
169 BUG_ON(!dev);
170 virq = irq - dev->irq_start;
171 val = readl(&dev->remote->int_device[virq >> 2]);
172 switch (flow_type & IRQ_TYPE_SENSE_MASK) {
173 case IRQ_TYPE_EDGE_RISING:
174 case IRQ_TYPE_EDGE_FALLING:
175 case IRQ_TYPE_EDGE_BOTH:
176 val |= VINT_TYPE_EDGE << VINT_OFFSET(virq);
177 val &= ~(VINT_LEVEL_LOW << VINT_OFFSET(virq));
178 break;
179 case IRQ_TYPE_LEVEL_HIGH:
180 val &= ~(VINT_TYPE_EDGE << VINT_OFFSET(virq));
181 val &= ~(VINT_LEVEL_LOW << VINT_OFFSET(virq));
182 break;
183 case IRQ_TYPE_LEVEL_LOW:
184 val &= ~(VINT_TYPE_EDGE << VINT_OFFSET(virq));
185 val |= VINT_LEVEL_LOW << VINT_OFFSET(virq);
186 break;
187 default:
188 return -EINVAL;
190 writel(val, &dev->remote->int_device[virq >> 2]);
191 return 0;
194 static void vlynq_local_ack(unsigned int irq)
196 struct vlynq_device *dev = get_irq_chip_data(irq);
198 u32 status = readl(&dev->local->status);
200 pr_debug("%s: local status: 0x%08x\n",
201 dev_name(&dev->dev), status);
202 writel(status, &dev->local->status);
205 static void vlynq_remote_ack(unsigned int irq)
207 struct vlynq_device *dev = get_irq_chip_data(irq);
209 u32 status = readl(&dev->remote->status);
211 pr_debug("%s: remote status: 0x%08x\n",
212 dev_name(&dev->dev), status);
213 writel(status, &dev->remote->status);
216 static irqreturn_t vlynq_irq(int irq, void *dev_id)
218 struct vlynq_device *dev = dev_id;
219 u32 status;
220 int virq = 0;
222 status = readl(&dev->local->int_status);
223 writel(status, &dev->local->int_status);
225 if (unlikely(!status))
226 spurious_interrupt();
228 while (status) {
229 if (status & 1)
230 do_IRQ(dev->irq_start + virq);
231 status >>= 1;
232 virq++;
235 return IRQ_HANDLED;
238 static struct irq_chip vlynq_irq_chip = {
239 .name = "vlynq",
240 .unmask = vlynq_irq_unmask,
241 .mask = vlynq_irq_mask,
242 .set_type = vlynq_irq_type,
245 static struct irq_chip vlynq_local_chip = {
246 .name = "vlynq local error",
247 .unmask = vlynq_irq_unmask,
248 .mask = vlynq_irq_mask,
249 .ack = vlynq_local_ack,
252 static struct irq_chip vlynq_remote_chip = {
253 .name = "vlynq local error",
254 .unmask = vlynq_irq_unmask,
255 .mask = vlynq_irq_mask,
256 .ack = vlynq_remote_ack,
259 static int vlynq_setup_irq(struct vlynq_device *dev)
261 u32 val;
262 int i, virq;
264 if (dev->local_irq == dev->remote_irq) {
265 printk(KERN_ERR
266 "%s: local vlynq irq should be different from remote\n",
267 dev_name(&dev->dev));
268 return -EINVAL;
271 /* Clear local and remote error bits */
272 writel(readl(&dev->local->status), &dev->local->status);
273 writel(readl(&dev->remote->status), &dev->remote->status);
275 /* Now setup interrupts */
276 val = VLYNQ_CTRL_INT_VECTOR(dev->local_irq);
277 val |= VLYNQ_CTRL_INT_ENABLE | VLYNQ_CTRL_INT_LOCAL |
278 VLYNQ_CTRL_INT2CFG;
279 val |= readl(&dev->local->control);
280 writel(VLYNQ_INT_OFFSET, &dev->local->int_ptr);
281 writel(val, &dev->local->control);
283 val = VLYNQ_CTRL_INT_VECTOR(dev->remote_irq);
284 val |= VLYNQ_CTRL_INT_ENABLE;
285 val |= readl(&dev->remote->control);
286 writel(VLYNQ_INT_OFFSET, &dev->remote->int_ptr);
287 writel(val, &dev->remote->int_ptr);
288 writel(val, &dev->remote->control);
290 for (i = dev->irq_start; i <= dev->irq_end; i++) {
291 virq = i - dev->irq_start;
292 if (virq == dev->local_irq) {
293 set_irq_chip_and_handler(i, &vlynq_local_chip,
294 handle_level_irq);
295 set_irq_chip_data(i, dev);
296 } else if (virq == dev->remote_irq) {
297 set_irq_chip_and_handler(i, &vlynq_remote_chip,
298 handle_level_irq);
299 set_irq_chip_data(i, dev);
300 } else {
301 set_irq_chip_and_handler(i, &vlynq_irq_chip,
302 handle_simple_irq);
303 set_irq_chip_data(i, dev);
304 writel(0, &dev->remote->int_device[virq >> 2]);
308 if (request_irq(dev->irq, vlynq_irq, IRQF_SHARED, "vlynq", dev)) {
309 printk(KERN_ERR "%s: request_irq failed\n",
310 dev_name(&dev->dev));
311 return -EAGAIN;
314 return 0;
317 static void vlynq_device_release(struct device *dev)
319 struct vlynq_device *vdev = to_vlynq_device(dev);
320 kfree(vdev);
323 static int vlynq_device_match(struct device *dev,
324 struct device_driver *drv)
326 struct vlynq_device *vdev = to_vlynq_device(dev);
327 struct vlynq_driver *vdrv = to_vlynq_driver(drv);
328 struct vlynq_device_id *ids = vdrv->id_table;
330 while (ids->id) {
331 if (ids->id == vdev->dev_id) {
332 vdev->divisor = ids->divisor;
333 vlynq_set_drvdata(vdev, ids);
334 printk(KERN_INFO "Driver found for VLYNQ "
335 "device: %08x\n", vdev->dev_id);
336 return 1;
338 printk(KERN_DEBUG "Not using the %08x VLYNQ device's driver"
339 " for VLYNQ device: %08x\n", ids->id, vdev->dev_id);
340 ids++;
342 return 0;
345 static int vlynq_device_probe(struct device *dev)
347 struct vlynq_device *vdev = to_vlynq_device(dev);
348 struct vlynq_driver *drv = to_vlynq_driver(dev->driver);
349 struct vlynq_device_id *id = vlynq_get_drvdata(vdev);
350 int result = -ENODEV;
352 if (drv->probe)
353 result = drv->probe(vdev, id);
354 if (result)
355 put_device(dev);
356 return result;
359 static int vlynq_device_remove(struct device *dev)
361 struct vlynq_driver *drv = to_vlynq_driver(dev->driver);
363 if (drv->remove)
364 drv->remove(to_vlynq_device(dev));
366 return 0;
369 int __vlynq_register_driver(struct vlynq_driver *driver, struct module *owner)
371 driver->driver.name = driver->name;
372 driver->driver.bus = &vlynq_bus_type;
373 return driver_register(&driver->driver);
375 EXPORT_SYMBOL(__vlynq_register_driver);
377 void vlynq_unregister_driver(struct vlynq_driver *driver)
379 driver_unregister(&driver->driver);
381 EXPORT_SYMBOL(vlynq_unregister_driver);
384 * A VLYNQ remote device can clock the VLYNQ bus master
385 * using a dedicated clock line. In that case, both the
386 * remove device and the bus master should have the same
387 * serial clock dividers configured. Iterate through the
388 * 8 possible dividers until we actually link with the
389 * device.
391 static int __vlynq_try_remote(struct vlynq_device *dev)
393 int i;
395 vlynq_reset(dev);
396 for (i = dev->dev_id ? vlynq_rdiv2 : vlynq_rdiv8; dev->dev_id ?
397 i <= vlynq_rdiv8 : i >= vlynq_rdiv2;
398 dev->dev_id ? i++ : i--) {
400 if (!vlynq_linked(dev))
401 break;
403 writel((readl(&dev->remote->control) &
404 ~VLYNQ_CTRL_CLOCK_MASK) |
405 VLYNQ_CTRL_CLOCK_INT |
406 VLYNQ_CTRL_CLOCK_DIV(i - vlynq_rdiv1),
407 &dev->remote->control);
408 writel((readl(&dev->local->control)
409 & ~(VLYNQ_CTRL_CLOCK_INT |
410 VLYNQ_CTRL_CLOCK_MASK)) |
411 VLYNQ_CTRL_CLOCK_DIV(i - vlynq_rdiv1),
412 &dev->local->control);
414 if (vlynq_linked(dev)) {
415 printk(KERN_DEBUG
416 "%s: using remote clock divisor %d\n",
417 dev_name(&dev->dev), i - vlynq_rdiv1 + 1);
418 dev->divisor = i;
419 return 0;
420 } else {
421 vlynq_reset(dev);
425 return -ENODEV;
429 * A VLYNQ remote device can be clocked by the VLYNQ bus
430 * master using a dedicated clock line. In that case, only
431 * the bus master configures the serial clock divider.
432 * Iterate through the 8 possible dividers until we
433 * actually get a link with the device.
435 static int __vlynq_try_local(struct vlynq_device *dev)
437 int i;
439 vlynq_reset(dev);
441 for (i = dev->dev_id ? vlynq_ldiv2 : vlynq_ldiv8; dev->dev_id ?
442 i <= vlynq_ldiv8 : i >= vlynq_ldiv2;
443 dev->dev_id ? i++ : i--) {
445 writel((readl(&dev->local->control) &
446 ~VLYNQ_CTRL_CLOCK_MASK) |
447 VLYNQ_CTRL_CLOCK_INT |
448 VLYNQ_CTRL_CLOCK_DIV(i - vlynq_ldiv1),
449 &dev->local->control);
451 if (vlynq_linked(dev)) {
452 printk(KERN_DEBUG
453 "%s: using local clock divisor %d\n",
454 dev_name(&dev->dev), i - vlynq_ldiv1 + 1);
455 dev->divisor = i;
456 return 0;
457 } else {
458 vlynq_reset(dev);
462 return -ENODEV;
466 * When using external clocking method, serial clock
467 * is supplied by an external oscillator, therefore we
468 * should mask the local clock bit in the clock control
469 * register for both the bus master and the remote device.
471 static int __vlynq_try_external(struct vlynq_device *dev)
473 vlynq_reset(dev);
474 if (!vlynq_linked(dev))
475 return -ENODEV;
477 writel((readl(&dev->remote->control) &
478 ~VLYNQ_CTRL_CLOCK_INT),
479 &dev->remote->control);
481 writel((readl(&dev->local->control) &
482 ~VLYNQ_CTRL_CLOCK_INT),
483 &dev->local->control);
485 if (vlynq_linked(dev)) {
486 printk(KERN_DEBUG "%s: using external clock\n",
487 dev_name(&dev->dev));
488 dev->divisor = vlynq_div_external;
489 return 0;
492 return -ENODEV;
495 static int __vlynq_enable_device(struct vlynq_device *dev)
497 int result;
498 struct plat_vlynq_ops *ops = dev->dev.platform_data;
500 result = ops->on(dev);
501 if (result)
502 return result;
504 switch (dev->divisor) {
505 case vlynq_div_external:
506 case vlynq_div_auto:
507 /* When the device is brought from reset it should have clock
508 * generation negotiated by hardware.
509 * Check which device is generating clocks and perform setup
510 * accordingly */
511 if (vlynq_linked(dev) && readl(&dev->remote->control) &
512 VLYNQ_CTRL_CLOCK_INT) {
513 if (!__vlynq_try_remote(dev) ||
514 !__vlynq_try_local(dev) ||
515 !__vlynq_try_external(dev))
516 return 0;
517 } else {
518 if (!__vlynq_try_external(dev) ||
519 !__vlynq_try_local(dev) ||
520 !__vlynq_try_remote(dev))
521 return 0;
523 break;
524 case vlynq_ldiv1:
525 case vlynq_ldiv2:
526 case vlynq_ldiv3:
527 case vlynq_ldiv4:
528 case vlynq_ldiv5:
529 case vlynq_ldiv6:
530 case vlynq_ldiv7:
531 case vlynq_ldiv8:
532 writel(VLYNQ_CTRL_CLOCK_INT |
533 VLYNQ_CTRL_CLOCK_DIV(dev->divisor -
534 vlynq_ldiv1), &dev->local->control);
535 writel(0, &dev->remote->control);
536 if (vlynq_linked(dev)) {
537 printk(KERN_DEBUG
538 "%s: using local clock divisor %d\n",
539 dev_name(&dev->dev),
540 dev->divisor - vlynq_ldiv1 + 1);
541 return 0;
543 break;
544 case vlynq_rdiv1:
545 case vlynq_rdiv2:
546 case vlynq_rdiv3:
547 case vlynq_rdiv4:
548 case vlynq_rdiv5:
549 case vlynq_rdiv6:
550 case vlynq_rdiv7:
551 case vlynq_rdiv8:
552 writel(0, &dev->local->control);
553 writel(VLYNQ_CTRL_CLOCK_INT |
554 VLYNQ_CTRL_CLOCK_DIV(dev->divisor -
555 vlynq_rdiv1), &dev->remote->control);
556 if (vlynq_linked(dev)) {
557 printk(KERN_DEBUG
558 "%s: using remote clock divisor %d\n",
559 dev_name(&dev->dev),
560 dev->divisor - vlynq_rdiv1 + 1);
561 return 0;
563 break;
566 ops->off(dev);
567 return -ENODEV;
570 int vlynq_enable_device(struct vlynq_device *dev)
572 struct plat_vlynq_ops *ops = dev->dev.platform_data;
573 int result = -ENODEV;
575 result = __vlynq_enable_device(dev);
576 if (result)
577 return result;
579 result = vlynq_setup_irq(dev);
580 if (result)
581 ops->off(dev);
583 dev->enabled = !result;
584 return result;
586 EXPORT_SYMBOL(vlynq_enable_device);
589 void vlynq_disable_device(struct vlynq_device *dev)
591 struct plat_vlynq_ops *ops = dev->dev.platform_data;
593 dev->enabled = 0;
594 free_irq(dev->irq, dev);
595 ops->off(dev);
597 EXPORT_SYMBOL(vlynq_disable_device);
599 int vlynq_set_local_mapping(struct vlynq_device *dev, u32 tx_offset,
600 struct vlynq_mapping *mapping)
602 int i;
604 if (!dev->enabled)
605 return -ENXIO;
607 writel(tx_offset, &dev->local->tx_offset);
608 for (i = 0; i < 4; i++) {
609 writel(mapping[i].offset, &dev->local->rx_mapping[i].offset);
610 writel(mapping[i].size, &dev->local->rx_mapping[i].size);
612 return 0;
614 EXPORT_SYMBOL(vlynq_set_local_mapping);
616 int vlynq_set_remote_mapping(struct vlynq_device *dev, u32 tx_offset,
617 struct vlynq_mapping *mapping)
619 int i;
621 if (!dev->enabled)
622 return -ENXIO;
624 writel(tx_offset, &dev->remote->tx_offset);
625 for (i = 0; i < 4; i++) {
626 writel(mapping[i].offset, &dev->remote->rx_mapping[i].offset);
627 writel(mapping[i].size, &dev->remote->rx_mapping[i].size);
629 return 0;
631 EXPORT_SYMBOL(vlynq_set_remote_mapping);
633 int vlynq_set_local_irq(struct vlynq_device *dev, int virq)
635 int irq = dev->irq_start + virq;
636 if (dev->enabled)
637 return -EBUSY;
639 if ((irq < dev->irq_start) || (irq > dev->irq_end))
640 return -EINVAL;
642 if (virq == dev->remote_irq)
643 return -EINVAL;
645 dev->local_irq = virq;
647 return 0;
649 EXPORT_SYMBOL(vlynq_set_local_irq);
651 int vlynq_set_remote_irq(struct vlynq_device *dev, int virq)
653 int irq = dev->irq_start + virq;
654 if (dev->enabled)
655 return -EBUSY;
657 if ((irq < dev->irq_start) || (irq > dev->irq_end))
658 return -EINVAL;
660 if (virq == dev->local_irq)
661 return -EINVAL;
663 dev->remote_irq = virq;
665 return 0;
667 EXPORT_SYMBOL(vlynq_set_remote_irq);
669 static int vlynq_probe(struct platform_device *pdev)
671 struct vlynq_device *dev;
672 struct resource *regs_res, *mem_res, *irq_res;
673 int len, result;
675 regs_res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs");
676 if (!regs_res)
677 return -ENODEV;
679 mem_res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mem");
680 if (!mem_res)
681 return -ENODEV;
683 irq_res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "devirq");
684 if (!irq_res)
685 return -ENODEV;
687 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
688 if (!dev) {
689 printk(KERN_ERR
690 "vlynq: failed to allocate device structure\n");
691 return -ENOMEM;
694 dev->id = pdev->id;
695 dev->dev.bus = &vlynq_bus_type;
696 dev->dev.parent = &pdev->dev;
697 dev_set_name(&dev->dev, "vlynq%d", dev->id);
698 dev->dev.platform_data = pdev->dev.platform_data;
699 dev->dev.release = vlynq_device_release;
701 dev->regs_start = regs_res->start;
702 dev->regs_end = regs_res->end;
703 dev->mem_start = mem_res->start;
704 dev->mem_end = mem_res->end;
706 len = resource_size(regs_res);
707 if (!request_mem_region(regs_res->start, len, dev_name(&dev->dev))) {
708 printk(KERN_ERR "%s: Can't request vlynq registers\n",
709 dev_name(&dev->dev));
710 result = -ENXIO;
711 goto fail_request;
714 dev->local = ioremap(regs_res->start, len);
715 if (!dev->local) {
716 printk(KERN_ERR "%s: Can't remap vlynq registers\n",
717 dev_name(&dev->dev));
718 result = -ENXIO;
719 goto fail_remap;
722 dev->remote = (struct vlynq_regs *)((void *)dev->local +
723 VLYNQ_REMOTE_OFFSET);
725 dev->irq = platform_get_irq_byname(pdev, "irq");
726 dev->irq_start = irq_res->start;
727 dev->irq_end = irq_res->end;
728 dev->local_irq = dev->irq_end - dev->irq_start;
729 dev->remote_irq = dev->local_irq - 1;
731 if (device_register(&dev->dev))
732 goto fail_register;
733 platform_set_drvdata(pdev, dev);
735 printk(KERN_INFO "%s: regs 0x%p, irq %d, mem 0x%p\n",
736 dev_name(&dev->dev), (void *)dev->regs_start, dev->irq,
737 (void *)dev->mem_start);
739 dev->dev_id = 0;
740 dev->divisor = vlynq_div_auto;
741 result = __vlynq_enable_device(dev);
742 if (result == 0) {
743 dev->dev_id = readl(&dev->remote->chip);
744 ((struct plat_vlynq_ops *)(dev->dev.platform_data))->off(dev);
746 if (dev->dev_id)
747 printk(KERN_INFO "Found a VLYNQ device: %08x\n", dev->dev_id);
749 return 0;
751 fail_register:
752 iounmap(dev->local);
753 fail_remap:
754 fail_request:
755 release_mem_region(regs_res->start, len);
756 kfree(dev);
757 return result;
760 static int vlynq_remove(struct platform_device *pdev)
762 struct vlynq_device *dev = platform_get_drvdata(pdev);
764 device_unregister(&dev->dev);
765 iounmap(dev->local);
766 release_mem_region(dev->regs_start, dev->regs_end - dev->regs_start);
768 kfree(dev);
770 return 0;
773 static struct platform_driver vlynq_platform_driver = {
774 .driver.name = "vlynq",
775 .probe = vlynq_probe,
776 .remove = __devexit_p(vlynq_remove),
779 struct bus_type vlynq_bus_type = {
780 .name = "vlynq",
781 .match = vlynq_device_match,
782 .probe = vlynq_device_probe,
783 .remove = vlynq_device_remove,
785 EXPORT_SYMBOL(vlynq_bus_type);
787 static int __devinit vlynq_init(void)
789 int res = 0;
791 res = bus_register(&vlynq_bus_type);
792 if (res)
793 goto fail_bus;
795 res = platform_driver_register(&vlynq_platform_driver);
796 if (res)
797 goto fail_platform;
799 return 0;
801 fail_platform:
802 bus_unregister(&vlynq_bus_type);
803 fail_bus:
804 return res;
807 static void __devexit vlynq_exit(void)
809 platform_driver_unregister(&vlynq_platform_driver);
810 bus_unregister(&vlynq_bus_type);
813 module_init(vlynq_init);
814 module_exit(vlynq_exit);