Moves all the duplicate code to a single function.

Verify for invalid modes and unwanted flags before pass the new flags to
driver.
Make gpio_default_map_gpios() static.  No functional changes.