Moved redundant/generic code into a new module

A lot of the code used by different drivers was redundant.  This patch
moves redundant/generic code into a new module that is imported by
switch specific driver modules.