Skip to contentSkip to conversation

ARM: OMAP: Add command line option for I2C bus speed

PATCH In review Jarkko Nikula 3 participants 9 messages Feb 8, 2009 – Feb 20, 2009

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

cover ARM: OMAP: Add command line option for I2C bus speed

Hi

I'm reposting this patch[set] adding command line option for I2C bus speed. First version was

http://marc.info/?l=linux-omap&m=123289314421984&w=2

With this set, the option name is now i2c_bus instead of i2c_rate and this version allow to register busses from command line as well. Idea of the set is mostly for EVM boards where bus speed may depend on use case and extra components connected into it.

With this it should be possible to revert one Dirk Behme's patch

commit bae4b6a716ccf3247a1991d3c20b5e58ddd52890

Author: Dirk Behme <[email protected]>
Date:   Tue Aug 5 14:09:15 2008 +0300

ARM: OMAP3: Make I2C bus 2 configurable for BeagleBoard

This is tested only with unmodified Beagle so I'm interested to hear if one has e.g. a Beagle with extra I2C devices connected into second I2C bus and those starts working just by adding "i2c_bus=2,100" on the kernel command line.

Signature · 1 line
Jarkko
#1 lore raw

PATCH 1/1 ARM: OMAP: Add documentation for function omap_register_i2c_bus

From: Jarkko Nikula <[email protected]>

---
 arch/arm/plat-omap/i2c.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)
arch/arm/plat-omap/i2c.c +9 -0
index 467531e..3e95954 100644
@@ -119,6 +119,15 @@ static void __init omap_i2c_mux_pins(int bus)
 	omap_cfg_reg(scl);
 }
 
+/**
+ * omap_register_i2c_bus - register I2C bus with device descriptors
+ * @bus_id: bus id counting from number 1
+ * @clkrate: clock rate of the bus in kHz
+ * @info: pointer into I2C device descriptor table or NULL
+ * @len: number of descriptors in the table
+ *
+ * Returns 0 on success or an error code.
+ */
 int __init omap_register_i2c_bus(int bus_id, u32 clkrate,
 			  struct i2c_board_info const *info,
 			  unsigned len)
Signature · 1 line
1.5.6.5
#2 lore raw

PATCH 1/1 ARM: OMAP: Add command line option for I2C bus speed

From: Jarkko Nikula <[email protected]>

This patch adds a new command line option "i2c_bus=bus_id,clkrate" into I2C bus registration helper. Purpose of the option is to override the default board specific bus speed which is supplied by the omap_register_i2c_bus.

The default bus speed is typically set to speed of slowest I2C chip on the bus and overriding allow to use some experimental configurations or updated chip versions without any kernel modifications.

---
 arch/arm/plat-omap/i2c.c |   54 +++++++++++++++++++++++++++++++++++++--------
 1 files changed, 44 insertions(+), 10 deletions(-)
arch/arm/plat-omap/i2c.c +44 -10
index 3e95954..aa70e43 100644
@@ -119,6 +119,46 @@ static void __init omap_i2c_mux_pins(int bus)
 	omap_cfg_reg(scl);
 }
 
+static int __init omap_i2c_nr_ports(void)
+{
+	int ports = 0;
+
+	if (cpu_class_is_omap1())
+		ports = 1;
+	else if (cpu_is_omap24xx())
+		ports = 2;
+	else if (cpu_is_omap34xx())
+		ports = 3;
+
+	return ports;
+}
+
+/**
+ * omap_i2c_bus_setup - Process command line options for the I2C bus speed
+ * @str: String of options
+ *
+ * This function allow to override the default I2C bus speed for given I2C
+ * bus with a command line option.
+ *
+ * Format: i2c_bus=bus_id,clkrate (in kHz)
+ *
+ * Returns 1 on success, 0 otherwise.
+ */
+static int __init omap_i2c_bus_setup(char *str)
+{
+	int ports;
+	int ints[3];
+
+	ports = omap_i2c_nr_ports();
+	get_options(str, 3, ints);
+	if (ints[0] < 2 || ints[1] < 1 || ints[1] > ports)
+		return 0;
+	i2c_rate[ints[1] - 1] = ints[2];
+
+	return 1;
+}
+__setup("i2c_bus=", omap_i2c_bus_setup);
+
 /**
  * omap_register_i2c_bus - register I2C bus with device descriptors
  * @bus_id: bus id counting from number 1
@@ -132,19 +172,12 @@ int __init omap_register_i2c_bus(int bus_id, u32 clkrate,
 			  struct i2c_board_info const *info,
 			  unsigned len)
 {
-	int ports, err;
+	int err;
 	struct platform_device *pdev;
 	struct resource *res;
 	resource_size_t base, irq;
 
-	if (cpu_class_is_omap1())
-		ports = 1;
-	else if (cpu_is_omap24xx())
-		ports = 2;
-	else if (cpu_is_omap34xx())
-		ports = 3;
-
-	BUG_ON(bus_id < 1 || bus_id > ports);
+	BUG_ON(bus_id < 1 || bus_id > omap_i2c_nr_ports());
 
 	if (info) {
 		err = i2c_register_board_info(bus_id, info, len);
@@ -153,7 +186,8 @@ int __init omap_register_i2c_bus(int bus_id, u32 clkrate,
 	}
 
 	pdev = &omap_i2c_devices[bus_id - 1];
-	*(u32 *)pdev->dev.platform_data = clkrate;
+	if (i2c_rate[bus_id - 1] == 0)
+		i2c_rate[bus_id - 1] = clkrate;
 
 	if (bus_id == 1) {
 		res = pdev->resource;
Signature · 1 line
1.5.6.5
#3 lore raw

PATCH 1/1 ARM: OMAP: Add method to register additional I2C busses on the command line

From: Jarkko Nikula <[email protected]>

This patch extends command line option "i2c_bus=bus_id,clkrate" so that it allow to register additional I2C busses that are not registered with omap_register_i2c_bus from board initialization code.

Purpose of this is to register additional board busses which are routed to external connectors only without any on board I2C devices.

---
 arch/arm/plat-omap/i2c.c |   73 ++++++++++++++++++++++++++++++++-------------
 1 files changed, 52 insertions(+), 21 deletions(-)
arch/arm/plat-omap/i2c.c +52 -21
index aa70e43..a303071 100644
@@ -98,6 +98,8 @@ static const int omap34xx_pins[][2] = {
 static const int omap34xx_pins[][2] = {};
 #endif
 
+#define OMAP_I2C_CMDLINE_SETUP	(BIT(31))
+
 static void __init omap_i2c_mux_pins(int bus)
 {
 	int scl, sda;
@@ -133,6 +135,31 @@ static int __init omap_i2c_nr_ports(void)
 	return ports;
 }
 
+static int __init omap_i2c_add_bus(int bus_id)
+{
+	struct platform_device *pdev;
+	struct resource *res;
+	resource_size_t base, irq;
+
+	pdev = &omap_i2c_devices[bus_id - 1];
+	if (bus_id == 1) {
+		res = pdev->resource;
+		if (cpu_class_is_omap1()) {
+			base = OMAP1_I2C_BASE;
+			irq = INT_I2C;
+		} else {
+			base = OMAP2_I2C_BASE1;
+			irq = INT_24XX_I2C1_IRQ;
+		}
+		res[0].start = base;
+		res[0].end = base + OMAP_I2C_SIZE;
+		res[1].start = irq;
+	}
+
+	omap_i2c_mux_pins(bus_id - 1);
+	return platform_device_register(pdev);
+}
+
 /**
  * omap_i2c_bus_setup - Process command line options for the I2C bus speed
  * @str: String of options
@@ -154,11 +181,33 @@ static int __init omap_i2c_bus_setup(char *str)
 	if (ints[0] < 2 || ints[1] < 1 || ints[1] > ports)
 		return 0;
 	i2c_rate[ints[1] - 1] = ints[2];
+	i2c_rate[ints[1] - 1] |= OMAP_I2C_CMDLINE_SETUP;
 
 	return 1;
 }
 __setup("i2c_bus=", omap_i2c_bus_setup);
 
+/*
+ * Register busses defined in command line but that are not registered with
+ * omap_register_i2c_bus from board initialization code.
+ */
+static int __init omap_register_i2c_bus_cmdline(void)
+{
+	int i, err = 0;
+
+	for (i = 0; i < ARRAY_SIZE(i2c_rate); i++)
+		if (i2c_rate[i] & OMAP_I2C_CMDLINE_SETUP) {
+			i2c_rate[i] &= ~OMAP_I2C_CMDLINE_SETUP;
+			err = omap_i2c_add_bus(i + 1);
+			if (err)
+				goto out;
+		}
+
+out:
+	return err;
+}
+subsys_initcall(omap_register_i2c_bus_cmdline);
+
 /**
  * omap_register_i2c_bus - register I2C bus with device descriptors
  * @bus_id: bus id counting from number 1
@@ -173,9 +222,6 @@ int __init omap_register_i2c_bus(int bus_id, u32 clkrate,
 			  unsigned len)
 {
 	int err;
-	struct platform_device *pdev;
-	struct resource *res;
-	resource_size_t base, irq;
 
 	BUG_ON(bus_id < 1 || bus_id > omap_i2c_nr_ports());
 
@@ -185,24 +231,9 @@ int __init omap_register_i2c_bus(int bus_id, u32 clkrate,
 			return err;
 	}
 
-	pdev = &omap_i2c_devices[bus_id - 1];
-	if (i2c_rate[bus_id - 1] == 0)
+	if (!i2c_rate[bus_id - 1])
 		i2c_rate[bus_id - 1] = clkrate;
+	i2c_rate[bus_id - 1] &= ~OMAP_I2C_CMDLINE_SETUP;
 
-	if (bus_id == 1) {
-		res = pdev->resource;
-		if (cpu_class_is_omap1()) {
-			base = OMAP1_I2C_BASE;
-			irq = INT_I2C;
-		} else {
-			base = OMAP2_I2C_BASE1;
-			irq = INT_24XX_I2C1_IRQ;
-		}
-		res[0].start = base;
-		res[0].end = base + OMAP_I2C_SIZE;
-		res[1].start = irq;
-	}
-
-	omap_i2c_mux_pins(bus_id - 1);
-	return platform_device_register(pdev);
+	return omap_i2c_add_bus(bus_id);
 }
Signature · 1 line
1.5.6.5
#5 lore raw

RFC 1/3 ARM: OMAP: Add documentation for function omap_register_i2c_bus

In reply to Jarkko Nikula
---
 arch/arm/plat-omap/i2c.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)
arch/arm/plat-omap/i2c.c +9 -0
index 467531e..3e95954 100644
@@ -119,6 +119,15 @@ static void __init omap_i2c_mux_pins(int bus)
 	omap_cfg_reg(scl);
 }
 
+/**
+ * omap_register_i2c_bus - register I2C bus with device descriptors
+ * @bus_id: bus id counting from number 1
+ * @clkrate: clock rate of the bus in kHz
+ * @info: pointer into I2C device descriptor table or NULL
+ * @len: number of descriptors in the table
+ *
+ * Returns 0 on success or an error code.
+ */
 int __init omap_register_i2c_bus(int bus_id, u32 clkrate,
 			  struct i2c_board_info const *info,
 			  unsigned len)
Signature · 1 line
1.5.6.5
#6 lore raw

RFC 2/3 ARM: OMAP: Add command line option for I2C bus speed

This patch adds a new command line option "i2c_bus=bus_id,clkrate" into I2C bus registration helper. Purpose of the option is to override the default board specific bus speed which is supplied by the omap_register_i2c_bus.

The default bus speed is typically set to speed of slowest I2C chip on the bus and overriding allow to use some experimental configurations or updated chip versions without any kernel modifications.

---
 arch/arm/plat-omap/i2c.c |   54 +++++++++++++++++++++++++++++++++++++--------
 1 files changed, 44 insertions(+), 10 deletions(-)
arch/arm/plat-omap/i2c.c +44 -10
index 3e95954..aa70e43 100644
@@ -119,6 +119,46 @@ static void __init omap_i2c_mux_pins(int bus)
 	omap_cfg_reg(scl);
 }
 
+static int __init omap_i2c_nr_ports(void)
+{
+	int ports = 0;
+
+	if (cpu_class_is_omap1())
+		ports = 1;
+	else if (cpu_is_omap24xx())
+		ports = 2;
+	else if (cpu_is_omap34xx())
+		ports = 3;
+
+	return ports;
+}
+
+/**
+ * omap_i2c_bus_setup - Process command line options for the I2C bus speed
+ * @str: String of options
+ *
+ * This function allow to override the default I2C bus speed for given I2C
+ * bus with a command line option.
+ *
+ * Format: i2c_bus=bus_id,clkrate (in kHz)
+ *
+ * Returns 1 on success, 0 otherwise.
+ */
+static int __init omap_i2c_bus_setup(char *str)
+{
+	int ports;
+	int ints[3];
+
+	ports = omap_i2c_nr_ports();
+	get_options(str, 3, ints);
+	if (ints[0] < 2 || ints[1] < 1 || ints[1] > ports)
+		return 0;
+	i2c_rate[ints[1] - 1] = ints[2];
+
+	return 1;
+}
+__setup("i2c_bus=", omap_i2c_bus_setup);
+
 /**
  * omap_register_i2c_bus - register I2C bus with device descriptors
  * @bus_id: bus id counting from number 1
@@ -132,19 +172,12 @@ int __init omap_register_i2c_bus(int bus_id, u32 clkrate,
 			  struct i2c_board_info const *info,
 			  unsigned len)
 {
-	int ports, err;
+	int err;
 	struct platform_device *pdev;
 	struct resource *res;
 	resource_size_t base, irq;
 
-	if (cpu_class_is_omap1())
-		ports = 1;
-	else if (cpu_is_omap24xx())
-		ports = 2;
-	else if (cpu_is_omap34xx())
-		ports = 3;
-
-	BUG_ON(bus_id < 1 || bus_id > ports);
+	BUG_ON(bus_id < 1 || bus_id > omap_i2c_nr_ports());
 
 	if (info) {
 		err = i2c_register_board_info(bus_id, info, len);
@@ -153,7 +186,8 @@ int __init omap_register_i2c_bus(int bus_id, u32 clkrate,
 	}
 
 	pdev = &omap_i2c_devices[bus_id - 1];
-	*(u32 *)pdev->dev.platform_data = clkrate;
+	if (i2c_rate[bus_id - 1] == 0)
+		i2c_rate[bus_id - 1] = clkrate;
 
 	if (bus_id == 1) {
 		res = pdev->resource;
Signature · 1 line
1.5.6.5
#7 lore raw

RFC 3/3 ARM: OMAP: Add method to register additional I2C busses on the command line

This patch extends command line option "i2c_bus=bus_id,clkrate" so that it allow to register additional I2C busses that are not registered with omap_register_i2c_bus from board initialization code.

Purpose of this is to register additional board busses which are routed to external connectors only without any on board I2C devices.

---
 arch/arm/plat-omap/i2c.c |   73 ++++++++++++++++++++++++++++++++-------------
 1 files changed, 52 insertions(+), 21 deletions(-)
arch/arm/plat-omap/i2c.c +52 -21
index aa70e43..a303071 100644
@@ -98,6 +98,8 @@ static const int omap34xx_pins[][2] = {
 static const int omap34xx_pins[][2] = {};
 #endif
 
+#define OMAP_I2C_CMDLINE_SETUP	(BIT(31))
+
 static void __init omap_i2c_mux_pins(int bus)
 {
 	int scl, sda;
@@ -133,6 +135,31 @@ static int __init omap_i2c_nr_ports(void)
 	return ports;
 }
 
+static int __init omap_i2c_add_bus(int bus_id)
+{
+	struct platform_device *pdev;
+	struct resource *res;
+	resource_size_t base, irq;
+
+	pdev = &omap_i2c_devices[bus_id - 1];
+	if (bus_id == 1) {
+		res = pdev->resource;
+		if (cpu_class_is_omap1()) {
+			base = OMAP1_I2C_BASE;
+			irq = INT_I2C;
+		} else {
+			base = OMAP2_I2C_BASE1;
+			irq = INT_24XX_I2C1_IRQ;
+		}
+		res[0].start = base;
+		res[0].end = base + OMAP_I2C_SIZE;
+		res[1].start = irq;
+	}
+
+	omap_i2c_mux_pins(bus_id - 1);
+	return platform_device_register(pdev);
+}
+
 /**
  * omap_i2c_bus_setup - Process command line options for the I2C bus speed
  * @str: String of options
@@ -154,11 +181,33 @@ static int __init omap_i2c_bus_setup(char *str)
 	if (ints[0] < 2 || ints[1] < 1 || ints[1] > ports)
 		return 0;
 	i2c_rate[ints[1] - 1] = ints[2];
+	i2c_rate[ints[1] - 1] |= OMAP_I2C_CMDLINE_SETUP;
 
 	return 1;
 }
 __setup("i2c_bus=", omap_i2c_bus_setup);
 
+/*
+ * Register busses defined in command line but that are not registered with
+ * omap_register_i2c_bus from board initialization code.
+ */
+static int __init omap_register_i2c_bus_cmdline(void)
+{
+	int i, err = 0;
+
+	for (i = 0; i < ARRAY_SIZE(i2c_rate); i++)
+		if (i2c_rate[i] & OMAP_I2C_CMDLINE_SETUP) {
+			i2c_rate[i] &= ~OMAP_I2C_CMDLINE_SETUP;
+			err = omap_i2c_add_bus(i + 1);
+			if (err)
+				goto out;
+		}
+
+out:
+	return err;
+}
+subsys_initcall(omap_register_i2c_bus_cmdline);
+
 /**
  * omap_register_i2c_bus - register I2C bus with device descriptors
  * @bus_id: bus id counting from number 1
@@ -173,9 +222,6 @@ int __init omap_register_i2c_bus(int bus_id, u32 clkrate,
 			  unsigned len)
 {
 	int err;
-	struct platform_device *pdev;
-	struct resource *res;
-	resource_size_t base, irq;
 
 	BUG_ON(bus_id < 1 || bus_id > omap_i2c_nr_ports());
 
@@ -185,24 +231,9 @@ int __init omap_register_i2c_bus(int bus_id, u32 clkrate,
 			return err;
 	}
 
-	pdev = &omap_i2c_devices[bus_id - 1];
-	if (i2c_rate[bus_id - 1] == 0)
+	if (!i2c_rate[bus_id - 1])
 		i2c_rate[bus_id - 1] = clkrate;
+	i2c_rate[bus_id - 1] &= ~OMAP_I2C_CMDLINE_SETUP;
 
-	if (bus_id == 1) {
-		res = pdev->resource;
-		if (cpu_class_is_omap1()) {
-			base = OMAP1_I2C_BASE;
-			irq = INT_I2C;
-		} else {
-			base = OMAP2_I2C_BASE1;
-			irq = INT_24XX_I2C1_IRQ;
-		}
-		res[0].start = base;
-		res[0].end = base + OMAP_I2C_SIZE;
-		res[1].start = irq;
-	}
-
-	omap_i2c_mux_pins(bus_id - 1);
-	return platform_device_register(pdev);
+	return omap_i2c_add_bus(bus_id);
 }
Signature · 1 line
1.5.6.5
#8 lore raw

Re: [RFC 3/3] ARM: OMAP: Add method to register additional I2C busses on the command line

Quoted 6 lines · Jarkko Nikula

This patch extends command line option "i2c_bus=bus_id,clkrate" so that it allow to register additional I2C busses that are not registered with omap_register_i2c_bus from board initialization code.

Purpose of this is to register additional board busses which are routed to external connectors only without any on board I2C devices.

Adding all three to omap-upstream and pushing to linux-omap.

Tony

Quoted 129 lines
---
 arch/arm/plat-omap/i2c.c |   73 ++++++++++++++++++++++++++++++++-------------
 1 files changed, 52 insertions(+), 21 deletions(-)
arch/arm/plat-omap/i2c.c +52 -21
index aa70e43..a303071 100644
@@ -98,6 +98,8 @@ static const int omap34xx_pins[][2] = {
 static const int omap34xx_pins[][2] = {};
 #endif
 
+#define OMAP_I2C_CMDLINE_SETUP	(BIT(31))
+
 static void __init omap_i2c_mux_pins(int bus)
 {
 	int scl, sda;
@@ -133,6 +135,31 @@ static int __init omap_i2c_nr_ports(void)
 	return ports;
 }
 
+static int __init omap_i2c_add_bus(int bus_id)
+{
+	struct platform_device *pdev;
+	struct resource *res;
+	resource_size_t base, irq;
+
+	pdev = &omap_i2c_devices[bus_id - 1];
+	if (bus_id == 1) {
+		res = pdev->resource;
+		if (cpu_class_is_omap1()) {
+			base = OMAP1_I2C_BASE;
+			irq = INT_I2C;
+		} else {
+			base = OMAP2_I2C_BASE1;
+			irq = INT_24XX_I2C1_IRQ;
+		}
+		res[0].start = base;
+		res[0].end = base + OMAP_I2C_SIZE;
+		res[1].start = irq;
+	}
+
+	omap_i2c_mux_pins(bus_id - 1);
+	return platform_device_register(pdev);
+}
+
 /**
  * omap_i2c_bus_setup - Process command line options for the I2C bus speed
  * @str: String of options
@@ -154,11 +181,33 @@ static int __init omap_i2c_bus_setup(char *str)
 	if (ints[0] < 2 || ints[1] < 1 || ints[1] > ports)
 		return 0;
 	i2c_rate[ints[1] - 1] = ints[2];
+	i2c_rate[ints[1] - 1] |= OMAP_I2C_CMDLINE_SETUP;
 
 	return 1;
 }
 __setup("i2c_bus=", omap_i2c_bus_setup);
 
+/*
+ * Register busses defined in command line but that are not registered with
+ * omap_register_i2c_bus from board initialization code.
+ */
+static int __init omap_register_i2c_bus_cmdline(void)
+{
+	int i, err = 0;
+
+	for (i = 0; i < ARRAY_SIZE(i2c_rate); i++)
+		if (i2c_rate[i] & OMAP_I2C_CMDLINE_SETUP) {
+			i2c_rate[i] &= ~OMAP_I2C_CMDLINE_SETUP;
+			err = omap_i2c_add_bus(i + 1);
+			if (err)
+				goto out;
+		}
+
+out:
+	return err;
+}
+subsys_initcall(omap_register_i2c_bus_cmdline);
+
 /**
  * omap_register_i2c_bus - register I2C bus with device descriptors
  * @bus_id: bus id counting from number 1
@@ -173,9 +222,6 @@ int __init omap_register_i2c_bus(int bus_id, u32 clkrate,
 			  unsigned len)
 {
 	int err;
-	struct platform_device *pdev;
-	struct resource *res;
-	resource_size_t base, irq;
 
 	BUG_ON(bus_id < 1 || bus_id > omap_i2c_nr_ports());
 
@@ -185,24 +231,9 @@ int __init omap_register_i2c_bus(int bus_id, u32 clkrate,
 			return err;
 	}
 
-	pdev = &omap_i2c_devices[bus_id - 1];
-	if (i2c_rate[bus_id - 1] == 0)
+	if (!i2c_rate[bus_id - 1])
 		i2c_rate[bus_id - 1] = clkrate;
+	i2c_rate[bus_id - 1] &= ~OMAP_I2C_CMDLINE_SETUP;
 
-	if (bus_id == 1) {
-		res = pdev->resource;
-		if (cpu_class_is_omap1()) {
-			base = OMAP1_I2C_BASE;
-			irq = INT_I2C;
-		} else {
-			base = OMAP2_I2C_BASE1;
-			irq = INT_24XX_I2C1_IRQ;
-		}
-		res[0].start = base;
-		res[0].end = base + OMAP_I2C_SIZE;
-		res[1].start = irq;
-	}
-
-	omap_i2c_mux_pins(bus_id - 1);
-	return platform_device_register(pdev);
+	return omap_i2c_add_bus(bus_id);
 }
Signature · 6 lines
1.5.6.5

--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html