I want to write a minimal serdev Linux driver on a Raspberry Pi. Therefore I have to enable the kernel option SERIAL_DEV_CTRL_TTYPORT, but I don't know how. I have tried various options, but my Kernel Module never reaches the Probe function...
Here is what I got already:
I tried to enable the option by changing the /boot/cmdline.txt to:
SERIAL_DEV_CTRL_TTYPORT SERIAL_DEV_CTRL_TTYPORT=y SERIAL_DEV_CTRL_TTYPORT=yes root=PARTUUID=8d696e29-02 rootfstype=ext4 fsck.repair=yes rootwait modules-load=dwc2,g_ether
The device tree overlay:
/dts-v1/;
/plugin/;
/ {
compatible = "brcm,bcm2835";
fragment@0 {
target = <&uart0>;
status = "okay";
__overlay__ {
my_device {
compatible = "brightlight,echodev";
status = "okay";
};
};
};
};
The Kernel Module:
#include <linux/module.h>
#include <linux/init.h>
#include <linux/serdev.h>
#include <linux/mod_devicetable.h>
#include <linux/property.h>
#include <linux/platform_device.h>
#include <linux/of_device.h>
/* Meta Information */
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Johannes 4 GNU/Linux");
MODULE_DESCRIPTION("A simple serdev example");
/* Declate the probe and remove functions */
static int dt_probe(struct serdev_device *serdev);
static void dt_remove(struct serdev_device *serdev);
static struct of_device_id my_driver_ids[] = {
{
.compatible = "brightlight,echodev",
}, { /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, my_driver_ids);
static struct serdev_device_driver my_driver = {
.probe = dt_probe,
.remove = dt_remove,
.driver = {
.name = "echodev",
.of_match_table = my_driver_ids,
},
};
/**
* @brief This function is called on loading the driver
*/
static int dt_probe(struct serdev_device *serdev) {
printk("my_serdev - Now I am in the probe function!");
return 0;
}
/**
* @brief This function is called on unloading the driver
*/
static void dt_remove(struct serdev_device *serdev) {
printk("my_serdev - Now I am in the remove function\n");
}
module_serdev_device_driver(my_driver);
Do you have any tips?
UPDATE 1:
I checked my Kernel .config file and found out, that CONFIG_SERIAL_DEV_CTRL_TTYPORT is already set and enabled. I double checked it with
pi@raspberrypi:~ $ sudo modprobe configs
pi@raspberrypi:~ $ gzip -d /proc/config.gz --stdout | grep SERIAL_DEV
CONFIG_SERIAL_DEV_BUS=y
CONFIG_SERIAL_DEV_CTRL_TTYPORT=y
But then, why does my module never reaches the probe function???
Best regards, Johannes
CodePudding user response:
Ok, I got it, but I don't know exactly why it is working know.
When posting this example, I used dtoverlay
to load the device tree overlay:
sudo dtoverlay testoverlay.dtbo
When doing so, I couldn't reach the probe function. Then I copied my overlay to /boot/overlays and added it to /boot/config.txt:
dtoverlay=testoverlay
And after a reboot, I inserted my kernel module and it reached the probe function. Does anyone know why this works now but not before?