Merge tag 'trace-v5.11-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt...
[linux/fpc-iii.git] / drivers / vlynq / vlynq.c
blobe966981c021504fb2ac54648f7a6ce561133ffe8
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (C) 2006, 2007 Eugene Konev <ejka@openwrt.org>
5 * Parts of the VLYNQ specification can be found here:
6 * http://www.ti.com/litv/pdf/sprue36a
7 */
9 #include <linux/init.h>
10 #include <linux/types.h>
11 #include <linux/kernel.h>
12 #include <linux/string.h>
13 #include <linux/device.h>
14 #include <linux/module.h>
15 #include <linux/errno.h>
16 #include <linux/platform_device.h>
17 #include <linux/interrupt.h>
18 #include <linux/delay.h>
19 #include <linux/io.h>
20 #include <linux/slab.h>
21 #include <linux/irq.h>
23 #include <linux/vlynq.h>
25 #define VLYNQ_CTRL_PM_ENABLE 0x80000000
26 #define VLYNQ_CTRL_CLOCK_INT 0x00008000
27 #define VLYNQ_CTRL_CLOCK_DIV(x) (((x) & 7) << 16)
28 #define VLYNQ_CTRL_INT_LOCAL 0x00004000
29 #define VLYNQ_CTRL_INT_ENABLE 0x00002000
30 #define VLYNQ_CTRL_INT_VECTOR(x) (((x) & 0x1f) << 8)
31 #define VLYNQ_CTRL_INT2CFG 0x00000080
32 #define VLYNQ_CTRL_RESET 0x00000001
34 #define VLYNQ_CTRL_CLOCK_MASK (0x7 << 16)
36 #define VLYNQ_INT_OFFSET 0x00000014
37 #define VLYNQ_REMOTE_OFFSET 0x00000080
39 #define VLYNQ_STATUS_LINK 0x00000001
40 #define VLYNQ_STATUS_LERROR 0x00000080
41 #define VLYNQ_STATUS_RERROR 0x00000100
43 #define VINT_ENABLE 0x00000100
44 #define VINT_TYPE_EDGE 0x00000080
45 #define VINT_LEVEL_LOW 0x00000040
46 #define VINT_VECTOR(x) ((x) & 0x1f)
47 #define VINT_OFFSET(irq) (8 * ((irq) % 4))
49 #define VLYNQ_AUTONEGO_V2 0x00010000
51 struct vlynq_regs {
52 u32 revision;
53 u32 control;
54 u32 status;
55 u32 int_prio;
56 u32 int_status;
57 u32 int_pending;
58 u32 int_ptr;
59 u32 tx_offset;
60 struct vlynq_mapping rx_mapping[4];
61 u32 chip;
62 u32 autonego;
63 u32 unused[6];
64 u32 int_device[8];
67 #ifdef CONFIG_VLYNQ_DEBUG
68 static void vlynq_dump_regs(struct vlynq_device *dev)
70 int i;
72 printk(KERN_DEBUG "VLYNQ local=%p remote=%p\n",
73 dev->local, dev->remote);
74 for (i = 0; i < 32; i++) {
75 printk(KERN_DEBUG "VLYNQ: local %d: %08x\n",
76 i + 1, ((u32 *)dev->local)[i]);
77 printk(KERN_DEBUG "VLYNQ: remote %d: %08x\n",
78 i + 1, ((u32 *)dev->remote)[i]);
82 static void vlynq_dump_mem(u32 *base, int count)
84 int i;
86 for (i = 0; i < (count + 3) / 4; i++) {
87 if (i % 4 == 0)
88 printk(KERN_DEBUG "\nMEM[0x%04x]:", i * 4);
89 printk(KERN_DEBUG " 0x%08x", *(base + i));
91 printk(KERN_DEBUG "\n");
93 #endif
95 /* Check the VLYNQ link status with a given device */
96 static int vlynq_linked(struct vlynq_device *dev)
98 int i;
100 for (i = 0; i < 100; i++)
101 if (readl(&dev->local->status) & VLYNQ_STATUS_LINK)
102 return 1;
103 else
104 cpu_relax();
106 return 0;
109 static void vlynq_reset(struct vlynq_device *dev)
111 writel(readl(&dev->local->control) | VLYNQ_CTRL_RESET,
112 &dev->local->control);
114 /* Wait for the devices to finish resetting */
115 msleep(5);
117 /* Remove reset bit */
118 writel(readl(&dev->local->control) & ~VLYNQ_CTRL_RESET,
119 &dev->local->control);
121 /* Give some time for the devices to settle */
122 msleep(5);
125 static void vlynq_irq_unmask(struct irq_data *d)
127 struct vlynq_device *dev = irq_data_get_irq_chip_data(d);
128 int virq;
129 u32 val;
131 BUG_ON(!dev);
132 virq = d->irq - dev->irq_start;
133 val = readl(&dev->remote->int_device[virq >> 2]);
134 val |= (VINT_ENABLE | virq) << VINT_OFFSET(virq);
135 writel(val, &dev->remote->int_device[virq >> 2]);
138 static void vlynq_irq_mask(struct irq_data *d)
140 struct vlynq_device *dev = irq_data_get_irq_chip_data(d);
141 int virq;
142 u32 val;
144 BUG_ON(!dev);
145 virq = d->irq - dev->irq_start;
146 val = readl(&dev->remote->int_device[virq >> 2]);
147 val &= ~(VINT_ENABLE << VINT_OFFSET(virq));
148 writel(val, &dev->remote->int_device[virq >> 2]);
151 static int vlynq_irq_type(struct irq_data *d, unsigned int flow_type)
153 struct vlynq_device *dev = irq_data_get_irq_chip_data(d);
154 int virq;
155 u32 val;
157 BUG_ON(!dev);
158 virq = d->irq - dev->irq_start;
159 val = readl(&dev->remote->int_device[virq >> 2]);
160 switch (flow_type & IRQ_TYPE_SENSE_MASK) {
161 case IRQ_TYPE_EDGE_RISING:
162 case IRQ_TYPE_EDGE_FALLING:
163 case IRQ_TYPE_EDGE_BOTH:
164 val |= VINT_TYPE_EDGE << VINT_OFFSET(virq);
165 val &= ~(VINT_LEVEL_LOW << VINT_OFFSET(virq));
166 break;
167 case IRQ_TYPE_LEVEL_HIGH:
168 val &= ~(VINT_TYPE_EDGE << VINT_OFFSET(virq));
169 val &= ~(VINT_LEVEL_LOW << VINT_OFFSET(virq));
170 break;
171 case IRQ_TYPE_LEVEL_LOW:
172 val &= ~(VINT_TYPE_EDGE << VINT_OFFSET(virq));
173 val |= VINT_LEVEL_LOW << VINT_OFFSET(virq);
174 break;
175 default:
176 return -EINVAL;
178 writel(val, &dev->remote->int_device[virq >> 2]);
179 return 0;
182 static void vlynq_local_ack(struct irq_data *d)
184 struct vlynq_device *dev = irq_data_get_irq_chip_data(d);
185 u32 status = readl(&dev->local->status);
187 pr_debug("%s: local status: 0x%08x\n",
188 dev_name(&dev->dev), status);
189 writel(status, &dev->local->status);
192 static void vlynq_remote_ack(struct irq_data *d)
194 struct vlynq_device *dev = irq_data_get_irq_chip_data(d);
195 u32 status = readl(&dev->remote->status);
197 pr_debug("%s: remote status: 0x%08x\n",
198 dev_name(&dev->dev), status);
199 writel(status, &dev->remote->status);
202 static irqreturn_t vlynq_irq(int irq, void *dev_id)
204 struct vlynq_device *dev = dev_id;
205 u32 status;
206 int virq = 0;
208 status = readl(&dev->local->int_status);
209 writel(status, &dev->local->int_status);
211 if (unlikely(!status))
212 spurious_interrupt();
214 while (status) {
215 if (status & 1)
216 do_IRQ(dev->irq_start + virq);
217 status >>= 1;
218 virq++;
221 return IRQ_HANDLED;
224 static struct irq_chip vlynq_irq_chip = {
225 .name = "vlynq",
226 .irq_unmask = vlynq_irq_unmask,
227 .irq_mask = vlynq_irq_mask,
228 .irq_set_type = vlynq_irq_type,
231 static struct irq_chip vlynq_local_chip = {
232 .name = "vlynq local error",
233 .irq_unmask = vlynq_irq_unmask,
234 .irq_mask = vlynq_irq_mask,
235 .irq_ack = vlynq_local_ack,
238 static struct irq_chip vlynq_remote_chip = {
239 .name = "vlynq local error",
240 .irq_unmask = vlynq_irq_unmask,
241 .irq_mask = vlynq_irq_mask,
242 .irq_ack = vlynq_remote_ack,
245 static int vlynq_setup_irq(struct vlynq_device *dev)
247 u32 val;
248 int i, virq;
250 if (dev->local_irq == dev->remote_irq) {
251 printk(KERN_ERR
252 "%s: local vlynq irq should be different from remote\n",
253 dev_name(&dev->dev));
254 return -EINVAL;
257 /* Clear local and remote error bits */
258 writel(readl(&dev->local->status), &dev->local->status);
259 writel(readl(&dev->remote->status), &dev->remote->status);
261 /* Now setup interrupts */
262 val = VLYNQ_CTRL_INT_VECTOR(dev->local_irq);
263 val |= VLYNQ_CTRL_INT_ENABLE | VLYNQ_CTRL_INT_LOCAL |
264 VLYNQ_CTRL_INT2CFG;
265 val |= readl(&dev->local->control);
266 writel(VLYNQ_INT_OFFSET, &dev->local->int_ptr);
267 writel(val, &dev->local->control);
269 val = VLYNQ_CTRL_INT_VECTOR(dev->remote_irq);
270 val |= VLYNQ_CTRL_INT_ENABLE;
271 val |= readl(&dev->remote->control);
272 writel(VLYNQ_INT_OFFSET, &dev->remote->int_ptr);
273 writel(val, &dev->remote->int_ptr);
274 writel(val, &dev->remote->control);
276 for (i = dev->irq_start; i <= dev->irq_end; i++) {
277 virq = i - dev->irq_start;
278 if (virq == dev->local_irq) {
279 irq_set_chip_and_handler(i, &vlynq_local_chip,
280 handle_level_irq);
281 irq_set_chip_data(i, dev);
282 } else if (virq == dev->remote_irq) {
283 irq_set_chip_and_handler(i, &vlynq_remote_chip,
284 handle_level_irq);
285 irq_set_chip_data(i, dev);
286 } else {
287 irq_set_chip_and_handler(i, &vlynq_irq_chip,
288 handle_simple_irq);
289 irq_set_chip_data(i, dev);
290 writel(0, &dev->remote->int_device[virq >> 2]);
294 if (request_irq(dev->irq, vlynq_irq, IRQF_SHARED, "vlynq", dev)) {
295 printk(KERN_ERR "%s: request_irq failed\n",
296 dev_name(&dev->dev));
297 return -EAGAIN;
300 return 0;
303 static void vlynq_device_release(struct device *dev)
305 struct vlynq_device *vdev = to_vlynq_device(dev);
306 kfree(vdev);
309 static int vlynq_device_match(struct device *dev,
310 struct device_driver *drv)
312 struct vlynq_device *vdev = to_vlynq_device(dev);
313 struct vlynq_driver *vdrv = to_vlynq_driver(drv);
314 struct vlynq_device_id *ids = vdrv->id_table;
316 while (ids->id) {
317 if (ids->id == vdev->dev_id) {
318 vdev->divisor = ids->divisor;
319 vlynq_set_drvdata(vdev, ids);
320 printk(KERN_INFO "Driver found for VLYNQ "
321 "device: %08x\n", vdev->dev_id);
322 return 1;
324 printk(KERN_DEBUG "Not using the %08x VLYNQ device's driver"
325 " for VLYNQ device: %08x\n", ids->id, vdev->dev_id);
326 ids++;
328 return 0;
331 static int vlynq_device_probe(struct device *dev)
333 struct vlynq_device *vdev = to_vlynq_device(dev);
334 struct vlynq_driver *drv = to_vlynq_driver(dev->driver);
335 struct vlynq_device_id *id = vlynq_get_drvdata(vdev);
336 int result = -ENODEV;
338 if (drv->probe)
339 result = drv->probe(vdev, id);
340 if (result)
341 put_device(dev);
342 return result;
345 static int vlynq_device_remove(struct device *dev)
347 struct vlynq_driver *drv = to_vlynq_driver(dev->driver);
349 if (drv->remove)
350 drv->remove(to_vlynq_device(dev));
352 return 0;
355 int __vlynq_register_driver(struct vlynq_driver *driver, struct module *owner)
357 driver->driver.name = driver->name;
358 driver->driver.bus = &vlynq_bus_type;
359 return driver_register(&driver->driver);
361 EXPORT_SYMBOL(__vlynq_register_driver);
363 void vlynq_unregister_driver(struct vlynq_driver *driver)
365 driver_unregister(&driver->driver);
367 EXPORT_SYMBOL(vlynq_unregister_driver);
370 * A VLYNQ remote device can clock the VLYNQ bus master
371 * using a dedicated clock line. In that case, both the
372 * remove device and the bus master should have the same
373 * serial clock dividers configured. Iterate through the
374 * 8 possible dividers until we actually link with the
375 * device.
377 static int __vlynq_try_remote(struct vlynq_device *dev)
379 int i;
381 vlynq_reset(dev);
382 for (i = dev->dev_id ? vlynq_rdiv2 : vlynq_rdiv8; dev->dev_id ?
383 i <= vlynq_rdiv8 : i >= vlynq_rdiv2;
384 dev->dev_id ? i++ : i--) {
386 if (!vlynq_linked(dev))
387 break;
389 writel((readl(&dev->remote->control) &
390 ~VLYNQ_CTRL_CLOCK_MASK) |
391 VLYNQ_CTRL_CLOCK_INT |
392 VLYNQ_CTRL_CLOCK_DIV(i - vlynq_rdiv1),
393 &dev->remote->control);
394 writel((readl(&dev->local->control)
395 & ~(VLYNQ_CTRL_CLOCK_INT |
396 VLYNQ_CTRL_CLOCK_MASK)) |
397 VLYNQ_CTRL_CLOCK_DIV(i - vlynq_rdiv1),
398 &dev->local->control);
400 if (vlynq_linked(dev)) {
401 printk(KERN_DEBUG
402 "%s: using remote clock divisor %d\n",
403 dev_name(&dev->dev), i - vlynq_rdiv1 + 1);
404 dev->divisor = i;
405 return 0;
406 } else {
407 vlynq_reset(dev);
411 return -ENODEV;
415 * A VLYNQ remote device can be clocked by the VLYNQ bus
416 * master using a dedicated clock line. In that case, only
417 * the bus master configures the serial clock divider.
418 * Iterate through the 8 possible dividers until we
419 * actually get a link with the device.
421 static int __vlynq_try_local(struct vlynq_device *dev)
423 int i;
425 vlynq_reset(dev);
427 for (i = dev->dev_id ? vlynq_ldiv2 : vlynq_ldiv8; dev->dev_id ?
428 i <= vlynq_ldiv8 : i >= vlynq_ldiv2;
429 dev->dev_id ? i++ : i--) {
431 writel((readl(&dev->local->control) &
432 ~VLYNQ_CTRL_CLOCK_MASK) |
433 VLYNQ_CTRL_CLOCK_INT |
434 VLYNQ_CTRL_CLOCK_DIV(i - vlynq_ldiv1),
435 &dev->local->control);
437 if (vlynq_linked(dev)) {
438 printk(KERN_DEBUG
439 "%s: using local clock divisor %d\n",
440 dev_name(&dev->dev), i - vlynq_ldiv1 + 1);
441 dev->divisor = i;
442 return 0;
443 } else {
444 vlynq_reset(dev);
448 return -ENODEV;
452 * When using external clocking method, serial clock
453 * is supplied by an external oscillator, therefore we
454 * should mask the local clock bit in the clock control
455 * register for both the bus master and the remote device.
457 static int __vlynq_try_external(struct vlynq_device *dev)
459 vlynq_reset(dev);
460 if (!vlynq_linked(dev))
461 return -ENODEV;
463 writel((readl(&dev->remote->control) &
464 ~VLYNQ_CTRL_CLOCK_INT),
465 &dev->remote->control);
467 writel((readl(&dev->local->control) &
468 ~VLYNQ_CTRL_CLOCK_INT),
469 &dev->local->control);
471 if (vlynq_linked(dev)) {
472 printk(KERN_DEBUG "%s: using external clock\n",
473 dev_name(&dev->dev));
474 dev->divisor = vlynq_div_external;
475 return 0;
478 return -ENODEV;
481 static int __vlynq_enable_device(struct vlynq_device *dev)
483 int result;
484 struct plat_vlynq_ops *ops = dev->dev.platform_data;
486 result = ops->on(dev);
487 if (result)
488 return result;
490 switch (dev->divisor) {
491 case vlynq_div_external:
492 case vlynq_div_auto:
493 /* When the device is brought from reset it should have clock
494 * generation negotiated by hardware.
495 * Check which device is generating clocks and perform setup
496 * accordingly */
497 if (vlynq_linked(dev) && readl(&dev->remote->control) &
498 VLYNQ_CTRL_CLOCK_INT) {
499 if (!__vlynq_try_remote(dev) ||
500 !__vlynq_try_local(dev) ||
501 !__vlynq_try_external(dev))
502 return 0;
503 } else {
504 if (!__vlynq_try_external(dev) ||
505 !__vlynq_try_local(dev) ||
506 !__vlynq_try_remote(dev))
507 return 0;
509 break;
510 case vlynq_ldiv1:
511 case vlynq_ldiv2:
512 case vlynq_ldiv3:
513 case vlynq_ldiv4:
514 case vlynq_ldiv5:
515 case vlynq_ldiv6:
516 case vlynq_ldiv7:
517 case vlynq_ldiv8:
518 writel(VLYNQ_CTRL_CLOCK_INT |
519 VLYNQ_CTRL_CLOCK_DIV(dev->divisor -
520 vlynq_ldiv1), &dev->local->control);
521 writel(0, &dev->remote->control);
522 if (vlynq_linked(dev)) {
523 printk(KERN_DEBUG
524 "%s: using local clock divisor %d\n",
525 dev_name(&dev->dev),
526 dev->divisor - vlynq_ldiv1 + 1);
527 return 0;
529 break;
530 case vlynq_rdiv1:
531 case vlynq_rdiv2:
532 case vlynq_rdiv3:
533 case vlynq_rdiv4:
534 case vlynq_rdiv5:
535 case vlynq_rdiv6:
536 case vlynq_rdiv7:
537 case vlynq_rdiv8:
538 writel(0, &dev->local->control);
539 writel(VLYNQ_CTRL_CLOCK_INT |
540 VLYNQ_CTRL_CLOCK_DIV(dev->divisor -
541 vlynq_rdiv1), &dev->remote->control);
542 if (vlynq_linked(dev)) {
543 printk(KERN_DEBUG
544 "%s: using remote clock divisor %d\n",
545 dev_name(&dev->dev),
546 dev->divisor - vlynq_rdiv1 + 1);
547 return 0;
549 break;
552 ops->off(dev);
553 return -ENODEV;
556 int vlynq_enable_device(struct vlynq_device *dev)
558 struct plat_vlynq_ops *ops = dev->dev.platform_data;
559 int result = -ENODEV;
561 result = __vlynq_enable_device(dev);
562 if (result)
563 return result;
565 result = vlynq_setup_irq(dev);
566 if (result)
567 ops->off(dev);
569 dev->enabled = !result;
570 return result;
572 EXPORT_SYMBOL(vlynq_enable_device);
575 void vlynq_disable_device(struct vlynq_device *dev)
577 struct plat_vlynq_ops *ops = dev->dev.platform_data;
579 dev->enabled = 0;
580 free_irq(dev->irq, dev);
581 ops->off(dev);
583 EXPORT_SYMBOL(vlynq_disable_device);
585 int vlynq_set_local_mapping(struct vlynq_device *dev, u32 tx_offset,
586 struct vlynq_mapping *mapping)
588 int i;
590 if (!dev->enabled)
591 return -ENXIO;
593 writel(tx_offset, &dev->local->tx_offset);
594 for (i = 0; i < 4; i++) {
595 writel(mapping[i].offset, &dev->local->rx_mapping[i].offset);
596 writel(mapping[i].size, &dev->local->rx_mapping[i].size);
598 return 0;
600 EXPORT_SYMBOL(vlynq_set_local_mapping);
602 int vlynq_set_remote_mapping(struct vlynq_device *dev, u32 tx_offset,
603 struct vlynq_mapping *mapping)
605 int i;
607 if (!dev->enabled)
608 return -ENXIO;
610 writel(tx_offset, &dev->remote->tx_offset);
611 for (i = 0; i < 4; i++) {
612 writel(mapping[i].offset, &dev->remote->rx_mapping[i].offset);
613 writel(mapping[i].size, &dev->remote->rx_mapping[i].size);
615 return 0;
617 EXPORT_SYMBOL(vlynq_set_remote_mapping);
619 int vlynq_set_local_irq(struct vlynq_device *dev, int virq)
621 int irq = dev->irq_start + virq;
622 if (dev->enabled)
623 return -EBUSY;
625 if ((irq < dev->irq_start) || (irq > dev->irq_end))
626 return -EINVAL;
628 if (virq == dev->remote_irq)
629 return -EINVAL;
631 dev->local_irq = virq;
633 return 0;
635 EXPORT_SYMBOL(vlynq_set_local_irq);
637 int vlynq_set_remote_irq(struct vlynq_device *dev, int virq)
639 int irq = dev->irq_start + virq;
640 if (dev->enabled)
641 return -EBUSY;
643 if ((irq < dev->irq_start) || (irq > dev->irq_end))
644 return -EINVAL;
646 if (virq == dev->local_irq)
647 return -EINVAL;
649 dev->remote_irq = virq;
651 return 0;
653 EXPORT_SYMBOL(vlynq_set_remote_irq);
655 static int vlynq_probe(struct platform_device *pdev)
657 struct vlynq_device *dev;
658 struct resource *regs_res, *mem_res, *irq_res;
659 int len, result;
661 regs_res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs");
662 if (!regs_res)
663 return -ENODEV;
665 mem_res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mem");
666 if (!mem_res)
667 return -ENODEV;
669 irq_res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "devirq");
670 if (!irq_res)
671 return -ENODEV;
673 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
674 if (!dev) {
675 printk(KERN_ERR
676 "vlynq: failed to allocate device structure\n");
677 return -ENOMEM;
680 dev->id = pdev->id;
681 dev->dev.bus = &vlynq_bus_type;
682 dev->dev.parent = &pdev->dev;
683 dev_set_name(&dev->dev, "vlynq%d", dev->id);
684 dev->dev.platform_data = pdev->dev.platform_data;
685 dev->dev.release = vlynq_device_release;
687 dev->regs_start = regs_res->start;
688 dev->regs_end = regs_res->end;
689 dev->mem_start = mem_res->start;
690 dev->mem_end = mem_res->end;
692 len = resource_size(regs_res);
693 if (!request_mem_region(regs_res->start, len, dev_name(&dev->dev))) {
694 printk(KERN_ERR "%s: Can't request vlynq registers\n",
695 dev_name(&dev->dev));
696 result = -ENXIO;
697 goto fail_request;
700 dev->local = ioremap(regs_res->start, len);
701 if (!dev->local) {
702 printk(KERN_ERR "%s: Can't remap vlynq registers\n",
703 dev_name(&dev->dev));
704 result = -ENXIO;
705 goto fail_remap;
708 dev->remote = (struct vlynq_regs *)((void *)dev->local +
709 VLYNQ_REMOTE_OFFSET);
711 dev->irq = platform_get_irq_byname(pdev, "irq");
712 dev->irq_start = irq_res->start;
713 dev->irq_end = irq_res->end;
714 dev->local_irq = dev->irq_end - dev->irq_start;
715 dev->remote_irq = dev->local_irq - 1;
717 if (device_register(&dev->dev))
718 goto fail_register;
719 platform_set_drvdata(pdev, dev);
721 printk(KERN_INFO "%s: regs 0x%p, irq %d, mem 0x%p\n",
722 dev_name(&dev->dev), (void *)dev->regs_start, dev->irq,
723 (void *)dev->mem_start);
725 dev->dev_id = 0;
726 dev->divisor = vlynq_div_auto;
727 result = __vlynq_enable_device(dev);
728 if (result == 0) {
729 dev->dev_id = readl(&dev->remote->chip);
730 ((struct plat_vlynq_ops *)(dev->dev.platform_data))->off(dev);
732 if (dev->dev_id)
733 printk(KERN_INFO "Found a VLYNQ device: %08x\n", dev->dev_id);
735 return 0;
737 fail_register:
738 iounmap(dev->local);
739 fail_remap:
740 fail_request:
741 release_mem_region(regs_res->start, len);
742 kfree(dev);
743 return result;
746 static int vlynq_remove(struct platform_device *pdev)
748 struct vlynq_device *dev = platform_get_drvdata(pdev);
750 device_unregister(&dev->dev);
751 iounmap(dev->local);
752 release_mem_region(dev->regs_start,
753 dev->regs_end - dev->regs_start + 1);
755 kfree(dev);
757 return 0;
760 static struct platform_driver vlynq_platform_driver = {
761 .driver.name = "vlynq",
762 .probe = vlynq_probe,
763 .remove = vlynq_remove,
766 struct bus_type vlynq_bus_type = {
767 .name = "vlynq",
768 .match = vlynq_device_match,
769 .probe = vlynq_device_probe,
770 .remove = vlynq_device_remove,
772 EXPORT_SYMBOL(vlynq_bus_type);
774 static int vlynq_init(void)
776 int res = 0;
778 res = bus_register(&vlynq_bus_type);
779 if (res)
780 goto fail_bus;
782 res = platform_driver_register(&vlynq_platform_driver);
783 if (res)
784 goto fail_platform;
786 return 0;
788 fail_platform:
789 bus_unregister(&vlynq_bus_type);
790 fail_bus:
791 return res;
794 static void vlynq_exit(void)
796 platform_driver_unregister(&vlynq_platform_driver);
797 bus_unregister(&vlynq_bus_type);
800 module_init(vlynq_init);
801 module_exit(vlynq_exit);