title: Linux device driver with optional multiple platform driver interfaces
body: <p>Suppose I have a chip that has multiple options for interfacing with it, for example, the chip may have an I2C interface and a SPI interface and I can choose one of these interfaces and wire the device accordingly. How would I write a linux device driver for such device?</p>
  
  <p>A chip with this behavior is ssd1307, which already has a driver implementation in the mainline linux kernel (<a href="https://github.com/torvalds/linux/blob/master/drivers/video/fbdev/ssd1307fb.c" rel="nofollow noreferrer">https://github.com/torvalds/linux/blob/master/drivers/video/fbdev/ssd1307fb.c</a>), implemented only for its I2C interface (the chip also has a 3/4 Wire SPI Interface). As you can see in the code, the probe function relies heavily on the fact that it is an I2C interface, so in order to use the SPI interface I would need to write an entirely new driver, repeating a lot of common code, or insert a lot of #ifdefs, which don't seem to be good approaches to me.</p>