0

I know that the driver and device must have the same name and I've made sure I've done that. However, when modprobe'ing my driver, nothing happens even though I've done a number of printk's in the init function.

When modprobing, I get:

root@localhost:~# dmesg --clear
root@localhost:~# modprobe mcp3202
root@localhost:~# dmesg

[   41.828678] kobject: 'mcp3202' (bf03968c): kobject_add_internal: parent: 'module', set: 'module'
[   41.828747] kobject: 'holders' (ded9d980): kobject_add_internal: parent: 'mcp3202', set: '<NULL>'
[   41.828890] kobject: 'notes' (dd1947c0): kobject_add_internal: parent: 'mcp3202', set: '<NULL>'
[   41.829028] kobject: 'mcp3202' (bf03968c): kobject_uevent_env
[   41.829053] kobject: 'mcp3202' (bf03968c): fill_kobj_path: path = '/module/mcp3202'

root@localhost:~# 

No printk's appear.

My device and driver structures are:

static struct platform_device mcp3202_device = {
    .name = "mcp3202",
    .id = 0,
    .num_resources = 0,
};

static strict of_device_id mcp3202_id[] = {
    { .compatible = "microchip,mcp3202", },
    { }
};

MODULE_DEVICE_TABLE(of,mcp3202_id);

static struct platform_driver mcp3202_driver = {
   .driver = {
            .name = "mcp3202",
            .owner = THIS_MODULE,
            .of_match_table = mcp3202_id,
    },
    .probe = mcp3202_probe,
    .remove = mcp3202_remove,
};

module_init(mcp3202_init);
module_exit(mcp3202_exit);

... and finally, my init function (partial) ...

static int __init mcp3202_init(void)
{
    int init_result;
    struct device *dev;

    printk(KERN_WARNING "mcp3202: reg driver\n");
    .
    .
    .
}

My understanding is as long as the names match (dev/drv), the mcp3202_init will be called regardless of what is defined in the .dts for this device.

Anyone have any clues what I'm missing?

Thanks!

Bryan Wilcutt
  • 335
  • 2
  • 9
  • So the plot thickens. As it turns out, the code is correct-- the problem lies in the Linux Makefile system from what I can tell. – Bryan Wilcutt Nov 25 '15 at 17:05

1 Answers1

0

@Bryan, Kernel make system isn't buggy. Bug in the Makefile you are using, try below Makefile to compile mcp3202 driver and feedback.

There are two options to resolve the issue,

1) Change module name to mcp3202_mod.o as below, Makefile will be,

obj-$(CONFIG_MCP3202) += mcp3202_mod.o
mcp3202_mod-objs := mcp3202.o mcp3202_pru.o

                   (or)

2) Change source file mcp3202.c to mcp3202_<meaningful-name>.c, Makefile will be,

obj-$(CONFIG_MCP3202) += mcp3202.o
mcp3202-objs := mcp3202_<name_provided>.o mcp3202_pru.o

Module name and source file name should not be same, if so then init information will not be present in <module_name.mod.c> and will not be called. Also go through below link,

Building a kernel module from several source files which one of them has the same name as the module

Community
  • 1
  • 1
Gautham Kantharaju
  • 1,735
  • 1
  • 21
  • 24