public inbox for linux-can@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH can-next/b4 1/2] dummyxl: update config possibilities and rename dummyxl_priv
@ 2025-07-06 13:35 Oliver Hartkopp
  2025-07-06 13:35 ` [PATCH can-next/b4 2/2] dummyxl: print ctrlmode and PWM values Oliver Hartkopp
  0 siblings, 1 reply; 5+ messages in thread
From: Oliver Hartkopp @ 2025-07-06 13:35 UTC (permalink / raw)
  To: linux-can; +Cc: Oliver Hartkopp

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
---
 drivers/net/can/dummyxl.c | 55 +++++++++++++++++++++++++--------------
 1 file changed, 35 insertions(+), 20 deletions(-)

diff --git a/drivers/net/can/dummyxl.c b/drivers/net/can/dummyxl.c
index ac1b579b4c1f..c61f27b93e9f 100644
--- a/drivers/net/can/dummyxl.c
+++ b/drivers/net/can/dummyxl.c
@@ -10,16 +10,17 @@
 #include <linux/units.h>
 #include <linux/can.h>
 #include <linux/can/dev.h>
 #include <linux/can/skb.h>
 
-struct dummyxl {
+struct dummyxl_priv {
 	struct can_priv can;
 	struct net_device *dev;
 };
 
-static struct dummyxl *dummyxl;
+/* pointer to our single dummy device (for removal) */
+static struct net_device *dummyxl_dev = NULL;
 
 static const struct can_bittiming_const dummyxl_bittiming_const = {
 	.name = "dummyxl nominal",
 	.tseg1_min = 2,
 	.tseg1_max = 256,
@@ -71,11 +72,12 @@ static const struct can_tdc_const dummyxl_xl_tdc_const = {
 	.tdco_max = 127,
 	.tdcf_min = 0,
 	.tdcf_max = 127
 };
 
-static void dummyxl_print_bittiming(struct net_device *dev, struct can_bittiming *bt)
+static void dummyxl_print_bittiming(struct net_device *dev,
+				    struct can_bittiming *bt)
 {
 	netdev_info(dev, "\tbitrate: %u\n", bt->bitrate);
 	netdev_info(dev, "\tsample_point: %u\n", bt->sample_point);
 	netdev_info(dev, "\ttq: %u\n", bt->tq);
 	netdev_info(dev, "\tprop_seg: %u\n", bt->prop_seg);
@@ -90,15 +92,14 @@ static void dummyxl_print_tdc(struct net_device *dev, struct can_tdc *tdc)
 	netdev_info(dev, "\t\ttdcv: %u\n", tdc->tdcv);
 	netdev_info(dev, "\t\ttdco: %u\n", tdc->tdco);
 	netdev_info(dev, "\t\ttdcf: %u\n", tdc->tdcf);
 }
 
-static int dummyxl_netdev_open(struct net_device *dev)
+static void dummyxl_print_config(struct net_device *dev)
 {
-	struct dummyxl *priv = netdev_priv(dev);
+	struct dummyxl_priv *priv = netdev_priv(dev);
 	struct can_priv *can_priv = &priv->can;
-	int ret;
 
 	netdev_info(dev, "CAN control mode/supported : %08X/%08X\n",
 		    can_priv->ctrlmode, can_priv->ctrlmode_supported);
 	netdev_info(dev, "CAN CC nominal bittiming:\n");
 	dummyxl_print_bittiming(dev, &can_priv->bittiming);
@@ -129,10 +130,17 @@ static int dummyxl_netdev_open(struct net_device *dev)
 		}
 	} else {
 		netdev_info(dev, "CAN XL is off\n");
 	}
 	netdev_info(dev, "\n");
+}
+
+static int dummyxl_netdev_open(struct net_device *dev)
+{
+	int ret;
+
+	dummyxl_print_config(dev);
 
 	ret = open_candev(dev);
 	if (ret)
 		return ret;
 	netif_start_queue(dev);
@@ -174,50 +182,57 @@ static const struct net_device_ops dummyxl_netdev_ops = {
 };
 
 static int __init dummyxl_init(void)
 {
 	struct net_device *dev;
-	struct dummyxl *priv;
+	struct dummyxl_priv *priv;
 	int ret;
 
-	dev = alloc_candev(sizeof(struct dummyxl), 0);
+	dev = alloc_candev(sizeof(struct dummyxl_priv), 0);
 	if (!dev)
 		return -ENOMEM;
 
 	dev->netdev_ops = &dummyxl_netdev_ops;
 	priv = netdev_priv(dev);
 	priv->can.bittiming_const = &dummyxl_bittiming_const;
-	priv->can.bitrate_max = 8 * MEGA /* BPS */;
-	priv->can.clock.freq = 80 * MEGA /* Hz */;
+	priv->can.bitrate_max = 20 * MEGA /* BPS */;
+	priv->can.clock.freq = 160 * MEGA /* Hz */;
 	priv->can.fd.data_bittiming_const = &dummyxl_fd_databittiming_const;
 	priv->can.fd.tdc_const = &dummyxl_fd_tdc_const;
 	priv->can.xl.data_bittiming_const = &dummyxl_xl_databittiming_const;
 	priv->can.xl.tdc_const = &dummyxl_xl_tdc_const;
-	priv->can.ctrlmode_supported = CAN_CTRLMODE_LISTENONLY |
-		CAN_CTRLMODE_FD | CAN_CTRLMODE_TDC_AUTO |
-		CAN_CTRLMODE_XL | CAN_CTRLMODE_XL_TDC_AUTO;
+	priv->can.ctrlmode_supported =
+		CAN_CTRLMODE_LISTENONLY | CAN_CTRLMODE_CC_LEN8_DLC |
+		CAN_CTRLMODE_FD |
+		CAN_CTRLMODE_TDC_AUTO | CAN_CTRLMODE_TDC_MANUAL |
+		CAN_CTRLMODE_XL |
+		CAN_CTRLMODE_XL_TDC_AUTO | CAN_CTRLMODE_XL_TDC_MANUAL |
+		CAN_CTRLMODE_XL_RRS | CAN_CTRLMODE_XL_TRX |
+		CAN_CTRLMODE_XL_ERR_SIGNAL;
 	priv->dev = dev;
 
-	ret = register_candev(priv->dev);
+	ret = register_candev(dev);
 	if (ret) {
-		free_candev(priv->dev);
+		free_candev(dev);
 		return ret;
 	}
 
-	dummyxl = priv;
+	dummyxl_dev = dev;
 	netdev_info(dev, "dummyxl OK\n");
 
 	return 0;
 }
 
 static void __exit dummyxl_exit(void)
 {
-	struct net_device *dev = dummyxl->dev;
+	struct net_device *dev = dummyxl_dev;
 
-	netdev_info(dev, "dummyxl bye bye\n");
-	unregister_candev(dev);
-	free_candev(dev);
+	if (dev) {
+		netdev_info(dev, "dummyxl bye bye\n");
+		unregister_candev(dev);
+		free_candev(dev);
+	}
 }
 
 module_init(dummyxl_init);
 module_exit(dummyxl_exit);
 
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-07-15 10:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-06 13:35 [PATCH can-next/b4 1/2] dummyxl: update config possibilities and rename dummyxl_priv Oliver Hartkopp
2025-07-06 13:35 ` [PATCH can-next/b4 2/2] dummyxl: print ctrlmode and PWM values Oliver Hartkopp
2025-07-13 17:25   ` Vincent Mailhol
2025-07-15 10:06     ` Marc Kleine-Budde
2025-07-15 10:58       ` Vincent Mailhol

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox