0

I'm trying a driver for a custom hardware component, the source code can be found here:

https://github.com/godspeed1989/zedboard/blob/master/led_drv/driver/myled.c

the problem is that when i do:

insmod myled.ko

nothing is shown in the console or in the dmesg log. I'm reading Linux Device Driver 3 and on it is written that you always must do:

module_init(init_function);
module_exit(exit_function);

in the source code there are none of them, instead there is:

module_platform_driver(myled_driver);

But when i load a module with this function nothing is print, instead if I use module_init and module_exit messages appear, what are the difference between this two kind of istructions?

Peter L.
  • 1,041
  • 2
  • 22
  • 26
Luca
  • 1,270
  • 1
  • 18
  • 34
  • Take a look at https://www.kernel.org/doc/Documentation/driver-model/platform.txt and http://stackoverflow.com/questions/22722520/who-calls-probe-function-in-driver-code There might also be a board file which enumerates resources by name. In this case the .name parameter is important as it will be used to bind resources. – Peter L. Nov 07 '14 at 18:55
  • 1
    The latter statement (or macro) can replace the first two: see lxr.free-electrons.com/source/include/linux/platform_device.h#L214 – sawdust Nov 07 '14 at 19:07
  • ok, but why the latter statement doesn't work while the first it's ok? – Luca Nov 07 '14 at 19:23
  • Try removing the __devinit and __devexit_p (section) attributes. Or use them in a consistent manner in both the procedure declarations and the platform_driver structure. Are you ignoring any section mismatch linker errors? – sawdust Nov 07 '14 at 20:16

1 Answers1

0

"but why the latter statement doesn't work while the first it's ok? " The first methond will register the driver to system and bus by module_platform_driver macro. The latter statement will not register your driver to system and bus. To to this, you need register driver in the init_function() routine by calling platform_device_register().

Hunter
  • 1
  • 1
  • How can you claim what *"the first method"* does when you don't know what the arguments are to **module_init()** and **module_exit()** as used by the OP? – sawdust Nov 10 '14 at 00:03
  • Take reference to the link that you have introduced: http://lxr.free-electrons.com/source/include/linux/platform_device.h#L214. The module_platform_driver() marcro will call platform_driver_register(). – Hunter Nov 13 '14 at 08:55
  • You seem to be confused as what is the *"first method"* that the OP and I are referring to, which is `module_init(init_function); module_exit(exit_function);`. `module_platform_driver()` was referred to as the second method. Anyway your guess is wrong, and the OP has solved the problem. – sawdust Nov 13 '14 at 09:19
  • I was misunderstood the OP's comment "but why the latter statement doesn't work while the first it's ok? " as that after OP changed the way of module registration, his new driver did not work any more. It seems that he still asked the original question that why there is no debug message in his old way. – Hunter Nov 14 '14 at 03:31