Each device driver gets the opportunity to initialize itself and its hardware at system boot time. For character device drivers, this is achieved by having an initialization function (init()) in the driver and then placing a call to this function into the kernel chr_dev_init() function. The chr_dev_init() function is contained in the file.
/usr/src/linux/drivers/char/mem.c
assuming that your kernel sources are in the default location /usr/src/linux.
Suppose your device driver has the name prefix tdd_ then the init() routine would be called tdd_init(). For kernels up to 1.1.32 you would need to add the line:
mem_start = tdd_init(mem_start);
to the end of the chr_dev_init() function just before the return mem_start; line.
For kernels from 1.1.33 onwards you would need to add the line:
tdd_init();
to the end of the chr_dev_init() function just before the return(); line
One of the main jobs performed by the driver init() function is to register the device driver with the kernel. This involves telling the kernel which major device number the driver will use and also giving the kernel a pointer to the driver's fi1e_operations structure so that the kernel can enter this pointer in the appropriate character driver table entry. The registration is performed by calling the kernel's register_chrdev() function as follows:
register_chrdev(major, name, fi1e_op)
where major is the major device number to be used by this driver (or zero to get the kernel to allocate a free major number) name is a string that gives the name of the driver, and file_op is a pointer to the driver's fi1e_operations structure.
The return value from register_chrdev() is negative if the registration is un-successful. If major is given as zero and the registration is successful then the function returns the kernel allocated major device number. If major is specified and the registration is successful then the value zero is returned.
As you will see in the next section, for kernels up to 1.1.32, the mem_start parameter value passed into the driver's init() function can be used to allocate some working memory for the driver to use during its execution.