You can type lsusb and it will give you a hexadecimal code for the product Id and vendor Id http://www.linuxnix.com/2013/05/find-usb-device-details-in-linuxunix-using-lsusb-command.html
Retroarch creates a configuration file based off of the lsusb identification. Some people have added their configuration files to the retroarch source code here:
When you run retroarch joyconfig it will create a gamepad.cfg file in
opt/retropie/emulators/retroarch/configs/yourgamepad.cfg and as you’ll see all the aforementioned configs are there plus your newly created gamepad.cfg file. I’m sure there is a setting somewhere related to autoenable that remembers your gamepad.cfg, otherwise you can override those associations by manually editing the retroarch.cfg files for each or all emulators in
/opt/retropie/configs I don’t know everything but hopefully that will give you an idea.