Skip to contentSkip to conversation

Add-Broadcom-Kona-I2C-Support

PATCH RESEND Superseded Tim Kryger 4 participants 13 messages Oct 16, 2013 – Nov 7, 2013

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Tim Kryger

author
#0 lore raw

cover Add-Broadcom-Kona-I2C-Support

This series adds support for the Kona I2C bus found on Broadcom mobile SoCs like the bcm11351 (aka bcm281xx) and enables it on the bcm28155-ap board.

It depends upon the following commits:
https://lkml.org/lkml/2013/10/7/481
http://www.spinics.net/lists/arm-kernel/msg274964.html

Tim Kryger (4):
i2c: i2c-bcm-kona: Introduce Broadcom I2C Driver
i2c: i2c-bcm-kona: Add support for high-speed mode
ARM: dts: bcm281xx: Add i2c busses
ARM: dts: bcm28155-ap: Enable all the i2c busses

 .../devicetree/bindings/i2c/i2c-bcm-kona.txt       |  30 +
 arch/arm/boot/dts/bcm11351.dtsi                    |  40 +
 arch/arm/boot/dts/bcm28155-ap.dts                  |  20 +
 drivers/i2c/busses/Kconfig                         |  10 +
 drivers/i2c/busses/Makefile                        |   1 +
 drivers/i2c/busses/i2c-bcm-kona.c                  | 936 +++++++++++++++++++++
 6 files changed, 1037 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/i2c/i2c-bcm-kona.txt
 create mode 100644 drivers/i2c/busses/i2c-bcm-kona.c
Signature · 1 line
1.8.0.1
author
#1 lore raw

PATCH RESEND 1/4 i2c: i2c-bcm-kona: Introduce Broadcom I2C Driver

Introduce support for Broadcom Serial Controller (BSC) I2C bus found in the Kona family of Mobile SoCs. FIFO hardware is utilized but only standard mode (100kHz), fast mode (400kHz), and fast mode plus (1MHz) bus speeds are supported.

---
 .../devicetree/bindings/i2c/i2c-bcm-kona.txt       |  30 +
 drivers/i2c/busses/Kconfig                         |  10 +
 drivers/i2c/busses/Makefile                        |   1 +
 drivers/i2c/busses/i2c-bcm-kona.c                  | 820 +++++++++++++++++++++
 4 files changed, 861 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/i2c/i2c-bcm-kona.txt
 create mode 100644 drivers/i2c/busses/i2c-bcm-kona.c
Documentation/devicetree/bindings/i2c/i2c-bcm-kona.txt new file +30 -0
new file mode 100644
index 0000000..fc71a60
@@ -0,0 +1,30 @@
+Broadcom Kona Family I2C
+=========================
+
+This I2C controller is used in the following Broadcom SoCs:
+
+  BCM11130
+  BCM11140
+  BCM11351
+  BCM28145
+  BCM28155
+
+Required Properties
+-------------------
+- compatible: "brcm,bcm11351-i2c", "brcm,kona-i2c"
+- reg: Physical base address and length of controller registers
+- interrupts: The interrupt number used by the controller
+- clock-frequency: The I2C bus frequency in Hz
+- #address-cells: Should be <1>
+- #size-cells: Should be <0>
+
+Example:
+
+i2c at 3e016000 {
+	compatible = "brcm,bcm11351-i2c","brcm,kona-i2c";
+	reg = <0x3e016000 0x80>;
+	interrupts = <GIC_SPI 103 IRQ_TYPE_LEVEL_HIGH>;
+	clock-frequency = <400000>;
+	#address-cells = <1>;
+	#size-cells = <0>;
+};
drivers/i2c/busses/Kconfig +10 -0
index cdcbd83..41a3f34 100644
@@ -963,4 +963,14 @@ config SCx200_ACB
 	  This support is also available as a module.  If so, the module
 	  will be called scx200_acb.
 
+config I2C_BCM_KONA
+	tristate "BCM Kona I2C adapter"
+	depends on ARCH_BCM_MOBILE
+	default y
+	help
+	  If you say yes to this option, support will be included for the
+	  I2C interface on the Broadcom Kona family of processors.
+
+	  If you do not need KONA I2C inteface, say N.
+
 endmenu
drivers/i2c/busses/Makefile +1 -0
index d00997f..91de826 100644
@@ -87,6 +87,7 @@ obj-$(CONFIG_I2C_VIPERBOARD)	+= i2c-viperboard.o
 
 # Other I2C/SMBus bus drivers
 obj-$(CONFIG_I2C_ACORN)		+= i2c-acorn.o
+obj-$(CONFIG_I2C_BCM_KONA)	+= i2c-bcm-kona.o
 obj-$(CONFIG_I2C_ELEKTOR)	+= i2c-elektor.o
 obj-$(CONFIG_I2C_PCA_ISA)	+= i2c-pca-isa.o
 obj-$(CONFIG_I2C_SIBYTE)	+= i2c-sibyte.o
drivers/i2c/busses/i2c-bcm-kona.c new file +820 -0

820 lines not on this page · raw message

Signature · 1 line
1.8.0.1
#2 lore raw

Re: [RESEND PATCH 1/4] i2c: i2c-bcm-kona: Introduce Broadcom I2C Driver

Quoted 8 lines · Tim Kryger

Introduce support for Broadcom Serial Controller (BSC) I2C bus found in the Kona family of Mobile SoCs. FIFO hardware is utilized but only standard mode (100kHz), fast mode (400kHz), and fast mode plus (1MHz) bus speeds are supported.

Looks mostly good, some remarks:

Quoted 15 lines
drivers/i2c/busses/i2c-bcm-kona.c new file +15 -0
+struct bcm_kona_i2c_dev {
+	/* Pointer to linux device struct */
+	struct device *device;
+
+	/* Virtual address where registers are mapped */
+	void __iomem *base;
+
+	/* Interrupt */
+	int irq;
+
+	/* Standard Speed configuration */
+	const struct bus_speed_cfg *std_cfg;
+
+	/* Linux I2C adapter struct */
+	struct i2c_adapter adapter;

drivers/i2c/busses/i2c-bcm-kona.c line 151

Quoted 10 lines
drivers/i2c/busses/i2c-bcm-kona.c new file +10 -0
+
+	/* Lock for the I2C device */
+	struct mutex i2c_bcm_lock;
+
+	/* Completion to signal an operation finished */
+	struct completion done;
+
+	/* Handle for external clock */
+	struct clk *external_clk;
+};

IMO most of the comments could go. Kind of stating the obvious :)

drivers/i2c/busses/i2c-bcm-kona.c line 316

Quoted 8 lines
drivers/i2c/busses/i2c-bcm-kona.c new file +8 -0
+/* Read any amount of data using the RX FIFO from the i2c bus */
+static int bcm_kona_i2c_read_fifo(struct bcm_kona_i2c_dev *dev,
+				  struct i2c_msg *msg)
+{
+	unsigned int bytes_to_read = MAX_RX_FIFO_SIZE;
+	unsigned int last_byte_nak = 0;
+	unsigned int bytes_read = 0;
+	unsigned int rc;

Should be signed.

drivers/i2c/busses/i2c-bcm-kona.c line 440

Quoted 7 lines
drivers/i2c/busses/i2c-bcm-kona.c new file +7 -0
+/* Write any amount of data using TX FIFO to the i2c bus */
+static int bcm_kona_i2c_write_fifo(struct bcm_kona_i2c_dev *dev,
+				   struct i2c_msg *msg)
+{
+	unsigned int bytes_to_write = MAX_TX_FIFO_SIZE;
+	unsigned int bytes_written = 0;
+	unsigned int rc;

Ditto signed.

drivers/i2c/busses/i2c-bcm-kona.c line 532

Quoted 10 lines
drivers/i2c/busses/i2c-bcm-kona.c new file +10 -0
+/* Master transfer function */
+static int bcm_kona_i2c_xfer(struct i2c_adapter *adapter,
+			     struct i2c_msg msgs[], int num)
+{
+	struct bcm_kona_i2c_dev *dev = i2c_get_adapdata(adapter);
+	struct i2c_msg *pmsg;
+	int rc = 0;
+	int i;
+
+	mutex_lock(&dev->i2c_bcm_lock);

Huh? Why do you need that? The core has locks per bus.

Quoted 14 lines
drivers/i2c/busses/i2c-bcm-kona.c new file +14 -0
+static int bcm_kona_i2c_assign_bus_speed(struct bcm_kona_i2c_dev *dev)
+{
+	unsigned int bus_speed;
+	int ret = of_property_read_u32(dev->device->of_node, "clock-frequency",
+				       &bus_speed);
+	if (ret < 0) {
+		dev_err(dev->device, "missing clock-frequency property\n");
+		return -ENODEV;
+	}
+
+	switch (bus_speed) {
+	case 100000:
+		dev->std_cfg = &std_cfg_table[BCM_SPD_100K];
+		break;

drivers/i2c/busses/i2c-bcm-kona.c line 648

Quoted 10 lines
drivers/i2c/busses/i2c-bcm-kona.c new file +10 -0
+	case 400000:
+		dev->std_cfg = &std_cfg_table[BCM_SPD_400K];
+		break;
+	case 1000000:
+		dev->std_cfg = &std_cfg_table[BCM_SPD_1MHZ];
+		break;
+	default:
+		pr_err("%d hz bus speed not supported\n", bus_speed);
+		return -EINVAL;
+	};

Unneeded semicolon.

Quoted 6 lines
drivers/i2c/busses/i2c-bcm-kona.c new file +6 -0
+
+	return 0;
+}
+
+static int bcm_kona_i2c_probe(struct platform_device *pdev)
+{

drivers/i2c/busses/i2c-bcm-kona.c line 664

Quoted 10 lines
drivers/i2c/busses/i2c-bcm-kona.c new file +10 -0
+	int rc = 0;
+	struct bcm_kona_i2c_dev *dev;
+	struct i2c_adapter *adap;
+	struct resource *iomem;
+
+	/* Allocate memory for private data structure */
+	dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
+	if (!dev) {
+		rc = -ENOMEM;
+		goto probe_return;

I'd prefer simply return -Esomething. The printout at probe_return is also available via driver core.

...

drivers/i2c/busses/i2c-bcm-kona.c line 765

Quoted 5 lines
drivers/i2c/busses/i2c-bcm-kona.c new file +5 -0
+	/* Add the i2c adapter */
+	adap = &dev->adapter;
+	i2c_set_adapdata(adap, dev);
+	adap->owner = THIS_MODULE;
+	adap->class = UINT_MAX;	/* can be used by any I2C device */

Why do you need class based instantiation. It will most likely cost boot-time and you have devicetree means for doing instantiation.

drivers/i2c/busses/i2c-bcm-kona.c line 772

Quoted 7 lines
drivers/i2c/busses/i2c-bcm-kona.c new file +7 -0
+	strlcpy(adap->name, "Broadcom I2C adapter", sizeof(adap->name));
+	adap->algo = &bcm_algo;
+	adap->dev.parent = &pdev->dev;
+	adap->nr = pdev->id;
+	adap->dev.of_node = pdev->dev.of_node;
+
+	rc = i2c_add_numbered_adapter(adap);

Maybe you want simply i2c_add_adapter here since the core has no built-in support for of aliases?

drivers/i2c/busses/i2c-bcm-kona.c line 818

Quoted 2 lines
drivers/i2c/busses/i2c-bcm-kona.c new file +2 -0
+
+MODULE_AUTHOR("Broadcom");

Some email address please.

drivers/i2c/busses/i2c-bcm-kona.c line 820

Quoted 2 lines
drivers/i2c/busses/i2c-bcm-kona.c new file +2 -0
+MODULE_DESCRIPTION("Broadcom Kona I2C Driver");
+MODULE_LICENSE("GPL v2");

Thanks,

Wolfram

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20131101/3fae3248/attachment.sig>

author
#3 lore raw

Re: [RESEND PATCH 1/4] i2c: i2c-bcm-kona: Introduce Broadcom I2C Driver

Quoted 31 lines · Wolfram Sang
Quoted 8 lines · Tim Kryger

Introduce support for Broadcom Serial Controller (BSC) I2C bus found in the Kona family of Mobile SoCs. FIFO hardware is utilized but only standard mode (100kHz), fast mode (400kHz), and fast mode plus (1MHz) bus speeds are supported.

Looks mostly good, some remarks:

Quoted 19 lines
drivers/i2c/busses/i2c-bcm-kona.c new file +19 -0
+struct bcm_kona_i2c_dev {
+     /* Pointer to linux device struct */
+     struct device *device;
+
+     /* Virtual address where registers are mapped */
+     void __iomem *base;
+
+     /* Interrupt */
+     int irq;
+
+     /* Standard Speed configuration */
+     const struct bus_speed_cfg *std_cfg;
+
+     /* Linux I2C adapter struct */
+     struct i2c_adapter adapter;
+
+     /* Lock for the I2C device */
+     struct mutex i2c_bcm_lock;
+
Quoted 8 lines

drivers/i2c/busses/i2c-bcm-kona.c line 151

Quoted 6 lines
drivers/i2c/busses/i2c-bcm-kona.c new file +6 -0
+     /* Completion to signal an operation finished */
+     struct completion done;
+
+     /* Handle for external clock */
+     struct clk *external_clk;
+};

IMO most of the comments could go. Kind of stating the obvious :)

Sure thing.

Quoted 11 lines

drivers/i2c/busses/i2c-bcm-kona.c line 316

Quoted 9 lines
drivers/i2c/busses/i2c-bcm-kona.c new file +8 -0
+/* Read any amount of data using the RX FIFO from the i2c bus */
+static int bcm_kona_i2c_read_fifo(struct bcm_kona_i2c_dev *dev,
+                               struct i2c_msg *msg)
+{
+     unsigned int bytes_to_read = MAX_RX_FIFO_SIZE;
+     unsigned int last_byte_nak = 0;
+     unsigned int bytes_read = 0;
+     unsigned int rc;

Should be signed.

Absolutely. Thanks for catching this one.

Quoted 10 lines

drivers/i2c/busses/i2c-bcm-kona.c line 440

Quoted 8 lines
drivers/i2c/busses/i2c-bcm-kona.c new file +7 -0
+/* Write any amount of data using TX FIFO to the i2c bus */
+static int bcm_kona_i2c_write_fifo(struct bcm_kona_i2c_dev *dev,
+                                struct i2c_msg *msg)
+{
+     unsigned int bytes_to_write = MAX_TX_FIFO_SIZE;
+     unsigned int bytes_written = 0;
+     unsigned int rc;

Ditto signed.

I shall fix it.

Quoted 13 lines

drivers/i2c/busses/i2c-bcm-kona.c line 532

Quoted 11 lines
drivers/i2c/busses/i2c-bcm-kona.c new file +10 -0
+/* Master transfer function */
+static int bcm_kona_i2c_xfer(struct i2c_adapter *adapter,
+                          struct i2c_msg msgs[], int num)
+{
+     struct bcm_kona_i2c_dev *dev = i2c_get_adapdata(adapter);
+     struct i2c_msg *pmsg;
+     int rc = 0;
+     int i;
+
+     mutex_lock(&dev->i2c_bcm_lock);

Huh? Why do you need that? The core has locks per bus.

In that case, I will remove the local mutex.

Quoted 18 lines
Quoted 18 lines
drivers/i2c/busses/i2c-bcm-kona.c new file +18 -0
+static int bcm_kona_i2c_assign_bus_speed(struct bcm_kona_i2c_dev *dev)
+{
+     unsigned int bus_speed;
+     int ret = of_property_read_u32(dev->device->of_node, "clock-frequency",
+                                    &bus_speed);
+     if (ret < 0) {
+             dev_err(dev->device, "missing clock-frequency property\n");
+             return -ENODEV;
+     }
+
+     switch (bus_speed) {
+     case 100000:
+             dev->std_cfg = &std_cfg_table[BCM_SPD_100K];
+             break;
+     case 400000:
+             dev->std_cfg = &std_cfg_table[BCM_SPD_400K];
+             break;
+     case 1000000:
Quoted 9 lines

drivers/i2c/busses/i2c-bcm-kona.c line 648

Quoted 6 lines
drivers/i2c/busses/i2c-bcm-kona.c new file +6 -0
+             dev->std_cfg = &std_cfg_table[BCM_SPD_1MHZ];
+             break;
+     default:
+             pr_err("%d hz bus speed not supported\n", bus_speed);
+             return -EINVAL;
+     };

Unneeded semicolon.

Sure. It will be removed.

Quoted 11 lines
Quoted 11 lines
drivers/i2c/busses/i2c-bcm-kona.c new file +11 -0
+
+     return 0;
+}
+
+static int bcm_kona_i2c_probe(struct platform_device *pdev)
+{
+     int rc = 0;
+     struct bcm_kona_i2c_dev *dev;
+     struct i2c_adapter *adap;
+     struct resource *iomem;
+
Quoted 8 lines

drivers/i2c/busses/i2c-bcm-kona.c line 664

Quoted 5 lines
drivers/i2c/busses/i2c-bcm-kona.c new file +5 -0
+     /* Allocate memory for private data structure */
+     dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
+     if (!dev) {
+             rc = -ENOMEM;
+             goto probe_return;

I'd prefer simply return -Esomething. The printout at probe_return is also available via driver core.

Agreed.

Quoted 12 lines

...

drivers/i2c/busses/i2c-bcm-kona.c line 765

Quoted 5 lines
drivers/i2c/busses/i2c-bcm-kona.c new file +5 -0
+     /* Add the i2c adapter */
+     adap = &dev->adapter;
+     i2c_set_adapdata(adap, dev);
+     adap->owner = THIS_MODULE;
+     adap->class = UINT_MAX; /* can be used by any I2C device */

Why do you need class based instantiation. It will most likely cost boot-time and you have devicetree means for doing instantiation.

Agreed.

Quoted 11 lines

drivers/i2c/busses/i2c-bcm-kona.c line 772

Quoted 7 lines
drivers/i2c/busses/i2c-bcm-kona.c new file +7 -0
+     strlcpy(adap->name, "Broadcom I2C adapter", sizeof(adap->name));
+     adap->algo = &bcm_algo;
+     adap->dev.parent = &pdev->dev;
+     adap->nr = pdev->id;
+     adap->dev.of_node = pdev->dev.of_node;
+
+     rc = i2c_add_numbered_adapter(adap);

Maybe you want simply i2c_add_adapter here since the core has no built-in support for of aliases?

Okay. I will switch to i2c_add_adapter and remove the adap->nr assignment.

Quoted 12 lines

drivers/i2c/busses/i2c-bcm-kona.c line 818

Quoted 2 lines
drivers/i2c/busses/i2c-bcm-kona.c new file +2 -0
+
+MODULE_AUTHOR("Broadcom");

Some email address please.

drivers/i2c/busses/i2c-bcm-kona.c line 820

Quoted 2 lines
drivers/i2c/busses/i2c-bcm-kona.c new file +2 -0
+MODULE_DESCRIPTION("Broadcom Kona I2C Driver");
+MODULE_LICENSE("GPL v2");

Thanks,

Wolfram

author
#4 lore raw

PATCH RESEND 2/4 i2c: i2c-bcm-kona: Add support for high-speed mode

In reply to Tim Kryger

Add support for I2C high-speed mode (3.4 MHz).

---
 drivers/i2c/busses/i2c-bcm-kona.c | 116 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 116 insertions(+)
drivers/i2c/busses/i2c-bcm-kona.c +116 -0
index 2936acf..458714f 100644
@@ -77,6 +77,9 @@
 
 #define HSTIM_OFFSET				0x00000058
 #define HSTIM_HS_MODE_MASK			0x00008000
+#define HSTIM_HS_HOLD_SHIFT			10
+#define HSTIM_HS_HIGH_PHASE_SHIFT		5
+#define HSTIM_HS_SETUP_SHIFT			0
 
 #define PADCTL_OFFSET				0x0000005c
 #define PADCTL_PAD_OUT_EN_MASK			0x00000004
@@ -91,6 +94,9 @@
 #define MAX_TX_FIFO_SIZE		64U /* bytes */
 
 #define STD_EXT_CLK_FREQ		13000000UL
+#define HS_EXT_CLK_FREQ			104000000UL
+
+#define MASTERCODE			0x08 /* Mastercodes are 0000_1xxxb */
 
 #define I2C_TIMEOUT			100 /* msecs */
 
@@ -108,6 +114,10 @@ enum bus_speed_index {
 	BCM_SPD_1MHZ,
 };
 
+enum hs_bus_speed_index {
+	BCM_SPD_3P4MHZ = 0,
+};
+
 /* Internal divider settings for standard mode, fast mode and fast mode plus */
 struct bus_speed_cfg {
 	uint8_t time_m;		/* Number of cycles for setup time */
@@ -118,12 +128,30 @@ struct bus_speed_cfg {
 	uint8_t time_div;	/* Post-prescale divider */
 };
 
+/* Internal divider settings for high-speed mode */
+struct hs_bus_speed_cfg {
+	uint8_t hs_hold;	/* Number of clock cycles SCL stays low until
+				   the end of bit period */
+	uint8_t hs_high_phase;	/* Number of clock cycles SCL stays high
+				   before it falls */
+	uint8_t hs_setup;	/* Number of clock cycles SCL stays low
+				   before it rises  */
+	uint8_t prescale;	/* Prescale divider */
+	uint8_t time_p;		/* Timing coefficient */
+	uint8_t no_div;		/* Disable clock divider */
+	uint8_t time_div;	/* Post-prescale divider */
+};
+
 static const struct bus_speed_cfg std_cfg_table[] = {
 	[BCM_SPD_100K] = {0x01, 0x01, 0x03, 0x06, 0x00, 0x02},
 	[BCM_SPD_400K] = {0x05, 0x01, 0x03, 0x05, 0x01, 0x02},
 	[BCM_SPD_1MHZ] = {0x01, 0x01, 0x03, 0x01, 0x01, 0x03},
 };
 
+static const struct hs_bus_speed_cfg hs_cfg_table[] = {
+	[BCM_SPD_3P4MHZ] = {0x01, 0x08, 0x14, 0x00, 0x06, 0x01, 0x00},
+};
+
 struct bcm_kona_i2c_dev {
 	/* Pointer to linux device struct */
 	struct device *device;
@@ -137,6 +165,9 @@ struct bcm_kona_i2c_dev {
 	/* Standard Speed configuration */
 	const struct bus_speed_cfg *std_cfg;
 
+	/* High Speed configuration (if applicable) */
+	const struct hs_bus_speed_cfg *hs_cfg;
+
 	/* Linux I2C adapter struct */
 	struct i2c_adapter adapter;
 
@@ -520,6 +551,72 @@ static void bcm_kona_i2c_config_timing(struct bcm_kona_i2c_dev *dev)
 	       dev->base + CLKEN_OFFSET);
 }
 
+static void bcm_kona_i2c_config_timing_hs(struct bcm_kona_i2c_dev *dev)
+{
+	writel((dev->hs_cfg->prescale << TIM_PRESCALE_SHIFT) |
+	       (dev->hs_cfg->time_p << TIM_P_SHIFT) |
+	       (dev->hs_cfg->no_div << TIM_NO_DIV_SHIFT) |
+	       (dev->hs_cfg->time_div << TIM_DIV_SHIFT),
+	       dev->base + TIM_OFFSET);
+
+	writel((dev->hs_cfg->hs_hold << HSTIM_HS_HOLD_SHIFT) |
+	       (dev->hs_cfg->hs_high_phase << HSTIM_HS_HIGH_PHASE_SHIFT) |
+	       (dev->hs_cfg->hs_setup << HSTIM_HS_SETUP_SHIFT),
+	       dev->base + HSTIM_OFFSET);
+
+	writel(readl(dev->base + HSTIM_OFFSET) | HSTIM_HS_MODE_MASK,
+	       dev->base + HSTIM_OFFSET);
+}
+
+static int bcm_kona_i2c_switch_to_hs(struct bcm_kona_i2c_dev *dev)
+{
+	int rc;
+
+	/* Send mastercode at standard speed */
+	rc = bcm_kona_i2c_write_byte(dev, MASTERCODE, 1);
+	if (rc < 0) {
+		pr_err("High speed handshake failed\n");
+		return rc;
+	}
+
+	/* Configure external clock to higher frequency */
+	rc = clk_set_rate(dev->external_clk, HS_EXT_CLK_FREQ);
+	if (rc) {
+		dev_err(dev->device, "%s: clk_set_rate returned %d\n",
+			__func__, rc);
+		return rc;
+	}
+
+	/* Reconfigure internal dividers */
+	bcm_kona_i2c_config_timing_hs(dev);
+
+	/* Send a restart command */
+	rc = bcm_kona_send_i2c_cmd(dev, BCM_CMD_RESTART);
+	if (rc < 0) {
+		dev_err(dev->device,
+		"High speed restart command failed rc = %d\n", rc);
+	}
+
+	return rc;
+}
+
+static int bcm_kona_i2c_switch_to_std(struct bcm_kona_i2c_dev *dev)
+{
+	int rc;
+
+	/* Reconfigure internal dividers */
+	bcm_kona_i2c_config_timing(dev);
+
+	/* Configure external clock to lower frequency */
+	rc = clk_set_rate(dev->external_clk, STD_EXT_CLK_FREQ);
+	if (rc) {
+		dev_err(dev->device, "%s: clk_set_rate returned %d\n",
+			__func__, rc);
+	}
+
+	return rc;
+}
+
 /* Master transfer function */
 static int bcm_kona_i2c_xfer(struct i2c_adapter *adapter,
 			     struct i2c_msg msgs[], int num)
@@ -551,6 +648,13 @@ static int bcm_kona_i2c_xfer(struct i2c_adapter *adapter,
 		goto xfer_disable_pad;
 	}
 
+	/* Switch to high speed if applicable */
+	if (dev->hs_cfg) {
+		rc = bcm_kona_i2c_switch_to_hs(dev);
+		if (rc < 0)
+			goto xfer_send_stop;
+	}
+
 	/* Loop through all messages */
 	for (i = 0; i < num; i++) {
 		pmsg = &msgs[i];
@@ -598,6 +702,13 @@ xfer_send_stop:
 	/* Send a STOP command */
 	bcm_kona_send_i2c_cmd(dev, BCM_CMD_STOP);
 
+	/* Return from high speed if applicable */
+	if (dev->hs_cfg) {
+		int hs_rc = bcm_kona_i2c_switch_to_std(dev);
+		if (hs_rc)
+			rc = hs_rc;
+	}
+
 xfer_disable_pad:
 	/* Disable pad output */
 	writel(PADCTL_PAD_OUT_EN_MASK, dev->base + PADCTL_OFFSET);
@@ -642,6 +753,11 @@ static int bcm_kona_i2c_assign_bus_speed(struct bcm_kona_i2c_dev *dev)
 	case 1000000:
 		dev->std_cfg = &std_cfg_table[BCM_SPD_1MHZ];
 		break;
+	case 3400000:
+		/* Send mastercode at 100k */
+		dev->std_cfg = &std_cfg_table[BCM_SPD_100K];
+		dev->hs_cfg = &hs_cfg_table[BCM_SPD_3P4MHZ];
+		break;
 	default:
 		pr_err("%d hz bus speed not supported\n", bus_speed);
 		return -EINVAL;
Signature · 1 line
1.8.0.1
#5 lore raw

Re: [RESEND PATCH 2/4] i2c: i2c-bcm-kona: Add support for high-speed mode

Quoted 5 lines · Tim Kryger

Add support for I2C high-speed mode (3.4 MHz).

Mostly good as well:

drivers/i2c/busses/i2c-bcm-kona.c enum bus_speed_index { · line 119

Quoted 3 lines
drivers/i2c/busses/i2c-bcm-kona.c +3 -0
+enum hs_bus_speed_index {
+	BCM_SPD_3P4MHZ = 0,
+};

I just realized that you should update both patches to add the supported bus speeds to the binding documentation.

Thanks,

Wolfram

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20131101/4fa35ef6/attachment.sig>

author
#6 lore raw

Re: [RESEND PATCH 2/4] i2c: i2c-bcm-kona: Add support for high-speed mode

Quoted 7 lines · Wolfram Sang
Quoted 5 lines · Tim Kryger

Add support for I2C high-speed mode (3.4 MHz).

Quoted 8 lines

Mostly good as well:

drivers/i2c/busses/i2c-bcm-kona.c enum bus_speed_index { · line 119

Quoted 3 lines
drivers/i2c/busses/i2c-bcm-kona.c +3 -0
+enum hs_bus_speed_index {
+     BCM_SPD_3P4MHZ = 0,
+};

I just realized that you should update both patches to add the supported bus speeds to the binding documentation.

While the bus speed property is really a configuration parameter (and not a true description of of the hardware) it seems improper to put driver specific details into the binding document.

Please let me know how you would like me to proceed.

I should mention that I plan to break out the binding into its own patch as this seems to be the latest best practice just in case that influences your decision.

Thanks,
Tim Kryger

#7 lore raw

Re: [RESEND PATCH 2/4] i2c: i2c-bcm-kona: Add support for high-speed mode

Quoted 4 lines

While the bus speed property is really a configuration parameter (and not a true description of of the hardware) it seems improper to put driver specific details into the binding document.

OK. Then please change the error message for unsupported bus speeds to contain the supported ones. I don't think it is good practice to force users to look into the sourcecode to find this information.

Regards,

Wolfram

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20131107/276be82b/attachment.sig>

author
#8 lore raw

Re: [RESEND PATCH 2/4] i2c: i2c-bcm-kona: Add support for high-speed mode

Quoted 3 lines · Wolfram Sang

OK. Then please change the error message for unsupported bus speeds to contain the supported ones. I don't think it is good practice to force users to look into the sourcecode to find this information.

That works for me. Thanks.

-Tim

author
#9 lore raw

PATCH RESEND 3/4 ARM: dts: bcm281xx: Add i2c busses

In reply to Tim Kryger

Add the DTS nodes for all the i2c busses in the SoC.

---
 arch/arm/boot/dts/bcm11351.dtsi | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
arch/arm/boot/dts/bcm11351.dtsi +40 -0
index 1246885..4bfd7e3 100644
@@ -146,6 +146,46 @@
 		status = "disabled";
 	};
 
+	i2c at 3e016000 {
+		compatible = "brcm,bcm11351-i2c", "brcm,kona-i2c";
+		reg = <0x3e016000 0x80>;
+		interrupts = <GIC_SPI 103 IRQ_TYPE_LEVEL_HIGH>;
+		#address-cells = <1>;
+		#size-cells = <0>;
+		clocks = <&bsc1_clk>;
+		status = "disabled";
+	};
+
+	i2c at 3e017000 {
+		compatible = "brcm,bcm11351-i2c", "brcm,kona-i2c";
+		reg = <0x3e017000 0x80>;
+		interrupts = <GIC_SPI 102 IRQ_TYPE_LEVEL_HIGH>;
+		#address-cells = <1>;
+		#size-cells = <0>;
+		clocks = <&bsc2_clk>;
+		status = "disabled";
+	};
+
+	i2c at 3e018000 {
+		compatible = "brcm,bcm11351-i2c", "brcm,kona-i2c";
+		reg = <0x3e018000 0x80>;
+		interrupts = <GIC_SPI 169 IRQ_TYPE_LEVEL_HIGH>;
+		#address-cells = <1>;
+		#size-cells = <0>;
+		clocks = <&bsc3_clk>;
+		status = "disabled";
+	};
+
+	i2c at 3500d000 {
+		compatible = "brcm,bcm11351-i2c", "brcm,kona-i2c";
+		reg = <0x3500d000 0x80>;
+		interrupts = <GIC_SPI 14 IRQ_TYPE_LEVEL_HIGH>;
+		#address-cells = <1>;
+		#size-cells = <0>;
+		clocks = <&pmu_bsc_clk>;
+		status = "disabled";
+	};
+
 	clocks {
 		bsc1_clk: bsc1 {
 			compatible = "fixed-clock";
Signature · 1 line
1.8.0.1
#10 lore raw

Re: [RESEND PATCH 3/4] ARM: dts: bcm281xx: Add i2c busses

Hi Tim,
This patch does not work as it relies on the yet-unmerged clock code
for bcm11351. This patch does not apply to -rc, and when tweaked it does not compile as it references non-existent bsc_clks.
Has the clk patches been submitted yet ? Applying this will have to
wait until those have been accepted.

thanks,
csd

Quoted 65 lines · Tim Kryger

Add the DTS nodes for all the i2c busses in the SoC.

---
 arch/arm/boot/dts/bcm11351.dtsi | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
arch/arm/boot/dts/bcm11351.dtsi +40 -1
index 1246885..4bfd7e3 100644
@@ -146,6 +146,46 @@
                status = "disabled";
        };
 
+       i2c at 3e016000 {
+               compatible = "brcm,bcm11351-i2c", "brcm,kona-i2c";
+               reg = <0x3e016000 0x80>;
+               interrupts = <GIC_SPI 103 IRQ_TYPE_LEVEL_HIGH>;
+               #address-cells = <1>;
+               #size-cells = <0>;
+               clocks = <&bsc1_clk>;
+               status = "disabled";
+       };
+
+       i2c at 3e017000 {
+               compatible = "brcm,bcm11351-i2c", "brcm,kona-i2c";
+               reg = <0x3e017000 0x80>;
+               interrupts = <GIC_SPI 102 IRQ_TYPE_LEVEL_HIGH>;
+               #address-cells = <1>;
+               #size-cells = <0>;
+               clocks = <&bsc2_clk>;
+               status = "disabled";
+       };
+
+       i2c at 3e018000 {
+               compatible = "brcm,bcm11351-i2c", "brcm,kona-i2c";
+               reg = <0x3e018000 0x80>;
+               interrupts = <GIC_SPI 169 IRQ_TYPE_LEVEL_HIGH>;
+               #address-cells = <1>;
+               #size-cells = <0>;
+               clocks = <&bsc3_clk>;
+               status = "disabled";
+       };
+
+       i2c at 3500d000 {
+               compatible = "brcm,bcm11351-i2c", "brcm,kona-i2c";
+               reg = <0x3500d000 0x80>;
+               interrupts = <GIC_SPI 14 IRQ_TYPE_LEVEL_HIGH>;
+               #address-cells = <1>;
+               #size-cells = <0>;
+               clocks = <&pmu_bsc_clk>;
+               status = "disabled";
+       };
+
        clocks {
                bsc1_clk: bsc1 {
                        compatible = "fixed-clock";
--

1.8.0.1

#11 lore raw

Re: [RESEND PATCH 3/4] ARM: dts: bcm281xx: Add i2c busses

Quoted 6 lines · Christian Daudt

Hi Tim,
This patch does not work as it relies on the yet-unmerged clock code
for bcm11351. This patch does not apply to -rc, and when tweaked it does not compile as it references non-existent bsc_clks.
Has the clk patches been submitted yet ? Applying this will have to
wait until those have been accepted.

Hi Christian, Tim mentioned the dependencies in the cover letter. Sebastian's series, for which the pull request is already sent, and then Tim's own fixed clock series that is pending some review.

-Matt

Quoted 71 lines · Tim Kryger
Quoted 62 lines

Add the DTS nodes for all the i2c busses in the SoC.

---
 arch/arm/boot/dts/bcm11351.dtsi | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
arch/arm/boot/dts/bcm11351.dtsi +40 -1
index 1246885..4bfd7e3 100644
@@ -146,6 +146,46 @@
                status = "disabled";
        };
 
+       i2c at 3e016000 {
+               compatible = "brcm,bcm11351-i2c", "brcm,kona-i2c";
+               reg = <0x3e016000 0x80>;
+               interrupts = <GIC_SPI 103 IRQ_TYPE_LEVEL_HIGH>;
+               #address-cells = <1>;
+               #size-cells = <0>;
+               clocks = <&bsc1_clk>;
+               status = "disabled";
+       };
+
+       i2c at 3e017000 {
+               compatible = "brcm,bcm11351-i2c", "brcm,kona-i2c";
+               reg = <0x3e017000 0x80>;
+               interrupts = <GIC_SPI 102 IRQ_TYPE_LEVEL_HIGH>;
+               #address-cells = <1>;
+               #size-cells = <0>;
+               clocks = <&bsc2_clk>;
+               status = "disabled";
+       };
+
+       i2c at 3e018000 {
+               compatible = "brcm,bcm11351-i2c", "brcm,kona-i2c";
+               reg = <0x3e018000 0x80>;
+               interrupts = <GIC_SPI 169 IRQ_TYPE_LEVEL_HIGH>;
+               #address-cells = <1>;
+               #size-cells = <0>;
+               clocks = <&bsc3_clk>;
+               status = "disabled";
+       };
+
+       i2c at 3500d000 {
+               compatible = "brcm,bcm11351-i2c", "brcm,kona-i2c";
+               reg = <0x3500d000 0x80>;
+               interrupts = <GIC_SPI 14 IRQ_TYPE_LEVEL_HIGH>;
+               #address-cells = <1>;
+               #size-cells = <0>;
+               clocks = <&pmu_bsc_clk>;
+               status = "disabled";
+       };
+
        clocks {
                bsc1_clk: bsc1 {
                        compatible = "fixed-clock";
--
Quoted 3 lines

1.8.0.1

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

author
#12 lore raw

PATCH RESEND 4/4 ARM: dts: bcm28155-ap: Enable all the i2c busses

In reply to Tim Kryger

Enable all available i2c busses.

---
 arch/arm/boot/dts/bcm28155-ap.dts | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
arch/arm/boot/dts/bcm28155-ap.dts +20 -0
index 08e47c2..bab302d 100644
@@ -27,6 +27,26 @@
 		status = "okay";
 	};
 
+	i2c at 3e016000 {
+		status="okay";
+		clock-frequency = <400000>;
+	};
+
+	i2c at 3e017000 {
+		status="okay";
+		clock-frequency = <400000>;
+	};
+
+	i2c at 3e018000 {
+		status="okay";
+		clock-frequency = <400000>;
+	};
+
+	i2c at 3500d000 {
+		status="okay";
+		clock-frequency = <400000>;
+	};
+
 	sdio1: sdio at 3f180000 {
 		max-frequency = <48000000>;
 		status = "okay";
Signature · 1 line
1.8.0.1