I'm currently learning about device developement for linux, I have glaced at some books such as LLD3, .. but I still can't understand what happen when we plug a device into computer, That's my imagination: When we plugs a device into a port, in a magic way, Linux kernel will know what device type and call to appropriate module's probe function to determine if it is exactly device which module need, and the next is magic .... Can anyone correction this?
It's not really magic, it's hardware. Information about peripheral events comes to the CPU thru the front side bus, which is the gateway to other hardware; programmatically (in kernel code) these are dealt with via the concept of the interrupt request (IRQ).
Have a look at these in order:
Now consider that the kernel is what determines what goes on in the CPU. Next:
To get more specific WRT the linux kernel code, it uses handlers which fire on receipt of an interrupt request. The basic parts of this are done with architecture specific asm code, a lot of which you will find in (eg)