Also, "use the Source, Luke!"
If you install the source-packages, Linux installations will have a directory such as /usr/src/linux which contains the actual source-code of the system. In it, you will find not only documentation but copious examples of just how all of this voodoo is done.
In the case of a device, every device driver must provide a set of standard routines to support read, write, ioctl, and so-on. Device drivers "register themselves" with the kernel, providing (among other things) a table which points to their respective versions of these (and other) routines. Higher-level routines within the kernel use these tables to pass control to the appropriate driver routines at the appropriate times.