Dynamically changing the loaded device tree is not what we usually do, although it is possible.
As I understand it, you do not care about the device tree for this new device.
I suggest you create a new module to add your device and, after loading it (after insmod ing), insmod your driver module. Actually, the order doesn't matter. When you add a device, all drivers will be checked, and those that match will be examined, and when you add a driver, all devices will be checked for it.
To create a device, you first select it:
struct platform_device *pdev; int inst_id = 1; pdev = platform_device_alloc("unique_name_here", inst_id);
Then you will want to create at least one resource for the memory mapped range. To do this, create and populate the struct resource array. A struct resource pretty simple. Here is an example of how to fill a memory resource:
struct resource res = { .start = 0x50000000, .end = 0x50001fff, .name = "some_name", .flags = IORESOURCE_MEM, };
After that, add it to the platform device you are creating:
platform_device_add_resources(pdev, &res, 1);
Make sure res not on the stack (make it global or kzalloc and kfree when unloading the module).
You are now ready to add the platform device:
platform_device_add(pdev);
Drop the device to the side, platform devices are mapped to platform drivers by the "platform bus" (and not by the actual actual physical bus) by name. Therefore, your platform driver will need to provide an equivalent name ( unique_name_here here). Your platform driver will have something like:
static struct platform_driver my_platform_driver = { .probe = my_probe, .remove = my_remove, .driver = { .name = "unique_name_here", .owner = THIS_MODULE, }, }; module_platform_driver(my_platform_driver);
and voila. Your driver should be checked if a single-board platform device is added.
Drivers using the device tree will add another member to .driver , which is .of_match_table . Here is a correspondence table (array of strings). Then the match uses the compatible property of the nodes of the device tree.