It's a shaker motor.
Yes you do it in the game's driver. Typically mame already has the input/output memory regions mapped out. What I do, which probably isn't the best way to do it, is to take the entire output bank and hook it up as an output and compile mame. Then I run mamehooker and monitor the debug window from mamehooker. For lamps 90% of the time it's a single byte with some bitmasking.... aka if the byte at address contains a 4, start 1 lamp is on, if it contains an 8, start 2 is on, ect....
Also test menus in games are your friend. While it's often difficult to part out individual bit masks/bytes while playing the game, most of your games have a test menu (press f2) and if you are lucky an "output test" section, which makes things really easy as it'll tell you which output is getting fired as you monitor memory locations.