Skip to contentSkip to conversation

spi: Master driver for NXP SC18IS602/603

PATCH Applied Guenter Roeck 2 participants 4 messages Aug 18, 2012 – Aug 22, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spi: Master driver for NXP SC18IS602/603

This driver adds support for NXP SC18IS602/603 I2C to SPI bus bridge.

---
There is one checkatch warning:

	WARNING: please write a paragraph that describes the config symbol fully
	#101: FILE: drivers/spi/Kconfig:328:
	+config SPI_SC18IS602

I ignored it to follow the description style of other SPI master drivers.

 .../devicetree/bindings/spi/spi-sc18is602.txt      |   23 ++
 Documentation/spi/spi-sc18is602                    |   36 ++
 drivers/spi/Kconfig                                |    6 +
 drivers/spi/Makefile                               |    1 +
 drivers/spi/spi-sc18is602.c                        |  364 ++++++++++++++++++++
 include/linux/platform_data/sc18is602.h            |   19 +
 6 files changed, 449 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/spi/spi-sc18is602.txt
 create mode 100644 Documentation/spi/spi-sc18is602
 create mode 100644 drivers/spi/spi-sc18is602.c
 create mode 100644 include/linux/platform_data/sc18is602.h
Documentation/devicetree/bindings/spi/spi-sc18is602.txt new file +23 -0
new file mode 100644
index 0000000..02f9033
@@ -0,0 +1,23 @@
+NXP SC18IS602/SCIS603
+
+Required properties:
+	- compatible : Should be one of
+		"nxp,sc18is602"
+		"nxp,sc18is602b"
+		"nxp,sc18is603"
+	- reg: I2C bus address
+
+Optional properties:
+	- clock-frequency : external oscillator clock frequency. If not
+	  specified, the SC18IS602 default frequency (7372000) will be used.
+
+The clock-frequency property is relevant and needed only if the chip has an
+external oscillator (SC18IS603).
+
+Example:
+
+	sc18is603@28 {
+		compatible = "nxp,sc18is603";
+		reg = <0x28>;
+		clock-frequency = <14744000>;
+	}
Documentation/spi/spi-sc18is602 new file +36 -0
new file mode 100644
index 0000000..a457028
@@ -0,0 +1,36 @@
+Kernel driver spi-sc18is602
+===========================
+
+Supported chips:
+  * NXP SI18IS602/602B/603
+    Datasheet: http://www.nxp.com/documents/data_sheet/SC18IS602_602B_603.pdf
+
+Author:
+        Guenter Roeck <[email protected]>
+
+
+Description
+-----------
+
+This driver provides connects a NXP SC18IS602/603 I2C-bus to SPI bridge to the
+kernel's SPI core subsystem.
+
+The driver does not probe for supported chips, since the SI18IS602/603 does not
+support Chip ID registers. You will have to instantiate the devices explicitly.
+Please see Documentation/i2c/instantiating-devices for details.
+
+
+Usage Notes
+-----------
+
+This driver requires the I2C adapter driver to support raw I2C messages. I2C
+adapter drivers which can only handle the SMBus protocol are not supported.
+
+The maximum SPI message size supported by SC18IS602/603 is 200 bytes. Attempts
+to initiate longer transfers will fail with -EINVAL. EEPROM read operations and
+similar large accesses have to be split into multiple chunks of no more than
+200 bytes per SPI message (128 bytes of data per message is recommended). This
+means that programs such as "cp" or "od", which automatically use large block
+sizes to access a device, can not be used directly to read data from EEPROM.
+Programs such as dd, where the block size can be specified, should be used
+instead.
drivers/spi/Kconfig +6 -0
index 5f84b55..920bb4d 100644
@@ -325,6 +325,12 @@ config SPI_S3C64XX
 	help
 	  SPI driver for Samsung S3C64XX and newer SoCs.
 
+config SPI_SC18IS602
+	tristate "NXP SC18IS602/602B/603 I2C to SPI bridge"
+	depends on I2C
+	help
+	  SPI driver for NXP SC18IS602/602B/603 I2C to SPI bridge.
+
 config SPI_SH_MSIOF
 	tristate "SuperH MSIOF SPI controller"
 	depends on SUPERH && HAVE_CLK
drivers/spi/Makefile +1 -0
index 3920dcf..7559c98 100644
@@ -51,6 +51,7 @@ obj-$(CONFIG_SPI_S3C24XX)		+= spi-s3c24xx-hw.o
 spi-s3c24xx-hw-y			:= spi-s3c24xx.o
 spi-s3c24xx-hw-$(CONFIG_SPI_S3C24XX_FIQ) += spi-s3c24xx-fiq.o
 obj-$(CONFIG_SPI_S3C64XX)		+= spi-s3c64xx.o
+obj-$(CONFIG_SPI_SC18IS602)		+= spi-sc18is602.o
 obj-$(CONFIG_SPI_SH)			+= spi-sh.o
 obj-$(CONFIG_SPI_SH_HSPI)		+= spi-sh-hspi.o
 obj-$(CONFIG_SPI_SH_MSIOF)		+= spi-sh-msiof.o
drivers/spi/spi-sc18is602.c new file +364 -0

364 lines not on this page · raw message

include/linux/platform_data/sc18is602.h new file +19 -0
new file mode 100644
index 0000000..997b066
@@ -0,0 +1,19 @@
+/*
+ * Platform data for NXP SC18IS602/603
+ *
+ * Copyright (C) 2012 Guenter Roeck <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * For further information, see the Documentation/spi/sc18is602 file.
+ */
+
+/**
+ * struct sc18is602_platform_data - sc18is602 info
+ * @clock_frequency		SC18IS603 oscillator frequency
+ */
+struct sc18is602_platform_data {
+	u32 clock_frequency;
+};
Signature · 1 line
1.7.9.7
Applied
#1 lore raw
Quoted 3 lines · Guenter Roeck

This driver adds support for NXP SC18IS602/603 I2C to SPI bus bridge.

Applied, thanks. One small thing:

drivers/spi/spi-sc18is602.c line 278

Quoted 13 lines
drivers/spi/spi-sc18is602.c new file +13 -0
+static int sc18is602_probe(struct i2c_client *client,
+			   const struct i2c_device_id *id)
+{
+	struct device *dev = &client->dev;
+	struct device_node *np = dev->of_node;
+	struct sc18is602_platform_data *pdata = dev_get_platdata(dev);
+	struct sc18is602 *hw;
+	struct spi_master *master;
+	int error;
+
+	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C |
+				     I2C_FUNC_SMBUS_WRITE_BYTE_DATA))
+		return -ENODEV;

This feels like the wrong thing to do here: given that the user needs to explicitly ask for the device to be instantiated we really ought to be one the right bus so this should be more of an error. Not sure what I can constructively sugget except for an error message and perhaps returning -EINVAL though.

#2 lore raw
Quoted 18 lines · Mark Brown
Quoted 3 lines · Guenter Roeck

This driver adds support for NXP SC18IS602/603 I2C to SPI bus bridge.

Applied, thanks. One small thing:

Quoted 11 lines
drivers/spi/spi-sc18is602.c new file +11 -0
+static int sc18is602_probe(struct i2c_client *client,
+			   const struct i2c_device_id *id)
+{
+	struct device *dev = &client->dev;
+	struct device_node *np = dev->of_node;
+	struct sc18is602_platform_data *pdata = dev_get_platdata(dev);
+	struct sc18is602 *hw;
+	struct spi_master *master;
+	int error;
+
+	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C |
Quoted 8 lines

drivers/spi/spi-sc18is602.c line 278

Quoted 2 lines
drivers/spi/spi-sc18is602.c new file +2 -0
+				     I2C_FUNC_SMBUS_WRITE_BYTE_DATA))
+		return -ENODEV;

This feels like the wrong thing to do here: given that the user needs to explicitly ask for the device to be instantiated we really ought to be one the right bus so this should be more of an error. Not sure what I can constructively sugget except for an error message and perhaps returning -EINVAL though.

Hi Mark,

Makes sense. Changing the return value to -EINVAL results in the following warning message from the driver subsystem.

sc18is602: probe of 7-0010 failed with error -22

I think this should be good enough, as there are other possible reasons for the call to fail which result in similar messages. Do you want to make that change, or should I change it and resubmit ?

Thanks,
Guenter

#3 lore raw
Quoted 8 lines · Guenter Roeck
Quoted 5 lines · Mark Brown

This feels like the wrong thing to do here: given that the user needs to explicitly ask for the device to be instantiated we really ought to be one the right bus so this should be more of an error. Not sure what I can constructively sugget except for an error message and perhaps returning -EINVAL though.

Quoted 8 lines

Makes sense. Changing the return value to -EINVAL results in the following warning message from the driver subsystem.

sc18is602: probe of 7-0010 failed with error -22

I think this should be good enough, as there are other possible reasons for the call to fail which result in similar messages. Do you want to make that change, or should I change it and resubmit ?

The above looks good, we don't need to go overboard - so long as it's not a silent fail I think we're OK. Please send an incremental change.