greybus: spi: add device_type field to device config
authorRui Miguel Silva <rui.silva@linaro.org>
Tue, 2 Feb 2016 14:23:16 +0000 (14:23 +0000)
committerGreg Kroah-Hartman <gregkh@google.com>
Sat, 6 Feb 2016 00:50:20 +0000 (16:50 -0800)
Add device_type field in device config operation to get the type of
device and try to expose less the kernel internal over greybus.
This include the spidev, spi-nor will fetch the correct nor id over
jede and a modalias that will have the previous behavior (name will set
the driver to be loaded).

As at it, fix a trivial error path and return immediately.

Tested: using gbsim and confirming that a spidev and mtd device were
created.

Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
drivers/staging/greybus/greybus_protocols.h
drivers/staging/greybus/kernel_ver.h
drivers/staging/greybus/spi.c

index 89db93282cacad14b543165309781d44bebd011e..cd64ac84dad2388c105a1ec98030276f812a960e 100644 (file)
@@ -737,6 +737,10 @@ struct gb_spi_device_config_response {
        __le16  mode;
        __u8    bits_per_word;
        __le32  max_speed_hz;
+       __u8    device_type;
+#define GB_SPI_SPI_DEV         0x00
+#define GB_SPI_SPI_NOR         0x01
+#define GB_SPI_SPI_MODALIAS    0x02
        __u8    name[32];
 } __packed;
 
index 1f8d6a1bb6da25c0763e09783f4609a3963eb15c..18bf8dff0f86ba24d9fbc2fd271e09bdbf24592c 100644 (file)
@@ -305,4 +305,12 @@ static inline bool led_sysfs_is_disabled(struct led_classdev *led_cdev)
 #define PSY_HAVE_PUT
 #endif
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 16, 0)
+#define SPI_DEV_MODALIAS "spidev"
+#define SPI_NOR_MODALIAS "spi-nor"
+#else
+#define SPI_DEV_MODALIAS "spidev"
+#define SPI_NOR_MODALIAS "m25p80"
+#endif
+
 #endif /* __GREYBUS_KERNEL_VER_H */
index ad4a1d62587dafa1240839e1d6124f3be66523fe..c00492cc632e7bbeb2d2ce4d3d1d75faaf44d08d 100644 (file)
@@ -285,6 +285,7 @@ static int gb_spi_setup_device(struct gb_spi *spi, u8 cs)
        struct spi_board_info spi_board = { {0} };
        struct spi_device *spidev;
        int ret;
+       u8 dev_type;
 
        request.chip_select = cs;
 
@@ -294,7 +295,20 @@ static int gb_spi_setup_device(struct gb_spi *spi, u8 cs)
        if (ret < 0)
                return ret;
 
-       memcpy(spi_board.modalias, response.name, sizeof(spi_board.modalias));
+       dev_type = response.device_type;
+
+       if (dev_type == GB_SPI_SPI_DEV)
+               strlcpy(spi_board.modalias, SPI_DEV_MODALIAS,
+                       sizeof(spi_board.modalias));
+       else if (dev_type == GB_SPI_SPI_NOR)
+               strlcpy(spi_board.modalias, SPI_NOR_MODALIAS,
+                       sizeof(spi_board.modalias));
+       else if (dev_type == GB_SPI_SPI_MODALIAS)
+               memcpy(spi_board.modalias, response.name,
+                      sizeof(spi_board.modalias));
+       else
+               return -EINVAL;
+
        spi_board.mode          = le16_to_cpu(response.mode);
        spi_board.bus_num       = master->bus_num;
        spi_board.chip_select   = cs;
@@ -302,7 +316,7 @@ static int gb_spi_setup_device(struct gb_spi *spi, u8 cs)
 
        spidev = spi_new_device(master, &spi_board);
        if (!spidev)
-               ret = -EINVAL;
+               return -EINVAL;
 
        return 0;
 }