Commit 0273038d authored by Rui Miguel Silva's avatar Rui Miguel Silva Committed by Greg Kroah-Hartman
Browse files

greybus: spi: add device_type field to device config



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: default avatarRui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@google.com>
parent 9d4bb6c9
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -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;

+8 −0
Original line number Diff line number Diff line
@@ -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 */
+16 −2
Original line number Diff line number Diff line
@@ -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;
}