hi, I have a question, I’m trying to implement a kernel and device tree module, with the probe function, but it doesn’t match, the probe function doesn’t work, I compiled the dts file, I inserted it in lib/firmware, I inserted it in boot Uenv.txt, the kernel tells me that it has been loaded…
this is module
#include <linux/module.h>
#include <linux/init.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 LKM to parse the device tree for a specific device and its properties”);
/* Declate the probe and remove functions */
static int dt_probe(struct platform_device *pdev);
static int dt_remove(struct platform_device *pdev);
static struct of_device_id my_driver_ids[] = {
{
.compatible = “brightlight,mydev”,
}, { /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, my_driver_ids);
static struct platform_driver my_driver = {
.probe = dt_probe,
.remove = dt_remove,
.driver = {
.name = “my_device_driver”,
.of_match_table = my_driver_ids,
},
};
/**
-
@brief This function is called on loading the driver
*/
static int dt_probe(struct platform_device *pdev) {
struct device *dev = &pdev->dev;
const char *label;
int my_value, ret;printk(“dt_probe - Now I am in the probe function!\n”);
/* Check for device properties */
if(!device_property_present(dev, “label”)) {
printk(“dt_probe - Error! Device property ‘label’ not found!\n”);
return -1;
}
if(!device_property_present(dev, “my_value”)) {
printk(“dt_probe - Error! Device property ‘my_value’ not found!\n”);
return -1;
}/* Read device properties */
ret = device_property_read_string(dev, “label”, &label);
if(ret) {
printk(“dt_probe - Error! Could not read ‘label’\n”);
return -1;
}
printk(“dt_probe - label: %s\n”, label);
ret = device_property_read_u32(dev, “my_value”, &my_value);
if(ret) {
printk(“dt_probe - Error! Could not read ‘my_value’\n”);
return -1;
}
printk(“dt_probe - my_value: %d\n”, my_value);return 0;
}
/dts-v1/;
/plugin/;
/ {
compatible = “ti,beaglebone”, “ti,beaglebone-black”;
/* identification */
part-number = "ADAFRUIT-SPI0";
/* version */
version = "00A0";
fragment@0 {
target = <&am33xx_pinmux>;
__overlay__ {
spi0_pins_s0: spi0_pins_s0 {
pinctrl-single,pins = <
0x150 0x30 /* spi0_sclk, INPUT_PULLUP | MODE0 */
0x154 0x30 /* spi0_d0, INPUT_PULLUP | MODE0 */
0x158 0x10 /* spi0_d1, OUTPUT_PULLUP | MODE0 */
0x15c 0x10 /* spi0_cs0, OUTPUT_PULLUP | MODE0 */
>;
};
};
};
fragment@1 {
target = <&spi0>;
__overlay__ {
#address-cells = <1>;
#size-cells = <0>;
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&spi0_pins_s0>;
spidev@0 {
spi-max-frequency = <24000000>;
reg = <0>;
compatible = "brightlight,mydev";
};
spidev@1 {
spi-max-frequency = <24000000>;
reg = <1>;
compatible = "brightlight,mydev";
};
};
};
};
the module does not probe only init, thanks
static int __init my_init(void) {
printk(“dt_probe - Loading the driver…\n”);
if(platform_driver_register(&my_driver)) {
printk(“dt_probe - Error! Could not load driver\n”);
return -1;
}
return 0;
}
/**
-
@brief This function is called, when the module is removed from the kernel
*/
static void __exit my_exit(void) {
printk(“dt_probe - Unload driver”);
platform_driver_unregister(&my_driver);
}
module_init(my_init);
module_exit(my_exit);