The regular CAN transceiver interface is targeted at platform devices.

This is a real example how the use a PCA82C251 on a CAN board (softing
PCMCIA, which has 2 such transceivers, with 0 Ohm slope resistor.

The main use of this modification is to serve as an example. This
Softing PCMCIA board is, due to double bus/single interface, not the
easiest board anyway.
I think anyway that the patch is rather small, so anyone could
understand the idea.

Signed-of-by: Kurt Van Dijck <[email protected]>
---
Index: drivers/net/can/softing/softing.h
===================================================================
--- drivers/net/can/softing/softing.h   (revision 1069)
+++ drivers/net/can/softing/softing.h   (working copy)
@@ -64,6 +64,7 @@
 struct softing {
        int nbus;
        struct softing_priv *bus[2];
+       struct can_transceiver *cantr[2];
        spinlock_t       spin; /* protect this structure & DPRAM access */
        ktime_t boot_time;
        u32 sample_at_boot_time;
Index: drivers/net/can/softing/softing_main.c
===================================================================
--- drivers/net/can/softing/softing_main.c      (revision 1069)
+++ drivers/net/can/softing/softing_main.c      (working copy)
@@ -26,6 +26,8 @@
 #include <linux/interrupt.h>
 #include <linux/mutex.h>
 #include <linux/io.h>
+#include <socketcan/can/transceiver.h>
+#include <socketcan/can/platform/pca82c251.h>
 
 #include "softing.h"
 
@@ -696,6 +698,7 @@
                        continue;
                softing_bus_sysfs_remove(card->bus[j]);
                unregister_candev(card->bus[j]->netdev);
+               pca82c251_destroy(card->cantr[j]);
                free_candev(card->bus[j]->netdev);
                card->bus[j] = 0;
        }
@@ -706,6 +709,11 @@
 }
 EXPORT_SYMBOL(rm_softing);
 
+static const struct pca82c251_platform_data transceiver = {
+       .gpio = -1,
+       .slope_resistor = 0,
+};
+
 int mk_softing(struct softing *card)
 {
        int j;
@@ -770,6 +778,14 @@
                card->bus[j]->index = j;
        }
        for (j = 0; j < card->nbus; ++j) {
+               card->cantr[j] = pca82c251_create(card->dev, &transceiver);
+               if (!card->cantr[j])
+                       goto cantr_failed;
+       }
+
+       for (j = 0; j < card->nbus; ++j) {
+               /* assign the trasceiver now */
+               card->bus[j]->can.cantr = card->cantr[j];
                if (reg_netdev(card->bus[j])) {
                        dev_alert(card->dev,
                                "failed to register can[%i]\n", j);
@@ -786,6 +802,13 @@
                softing_bus_sysfs_remove(card->bus[j]);
                unregister_candev(card->bus[j]->netdev);
        }
+cantr_failed:
+       for (j = 0; j < card->nbus; ++j) {
+               if (!card->cantr[j])
+                       continue;
+               pca82c251_destroy(card->cantr[j]);
+               card->cantr[j] = 0;
+       }
 netdev_failed:
        for (j = 0; j < card->nbus; ++j) {
                if (!card->bus[j])
_______________________________________________
Socketcan-core mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/socketcan-core

Reply via email to