Skip to contentSkip to conversation

MIPS: OCTEON: Convert some device to use Device Tree.

PATCH Superseded David Daney 5 participants 12 messages Mar 27, 2012 – Apr 18, 2012

Subsystems (7)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover MIPS: OCTEON: Convert some device to use Device Tree.

From: David Daney <[email protected]>

This patch set depends on the previous set to add Device Tree to OCTEON. That set can be found here:

http://www.linux-mips.org/archives/linux-mips/2012-03/msg00170.html

The patches are for drivers scattered throughout the tree, but there is an order dependency as well as the dependency mentioned above, so it may be preferable to merge them all via Ralf's linux-mips.org tree rather that separately via the various device sub-system maintainers.

The mdio-octeon.c and octeon_mgmt patches were already Acked-by davem.

The i2c has been seen before, but to my knowledge was never acked.

The octeon_ethernet patch is in staging and has also been seen before.

The serial patch is new.

David Daney (5):
i2c: Convert i2c-octeon.c to use device tree.
netdev: mdio-octeon.c: Convert to use device tree.
netdev: octeon_mgmt: Convert to use device tree.
staging: octeon_ethernet: Convert to use device tree.
MIPS: Octeon: Use device tree to register serial ports.

 arch/mips/cavium-octeon/octeon-irq.c      |    8 -
 arch/mips/cavium-octeon/octeon-platform.c |  176 ----------------
 arch/mips/cavium-octeon/serial.c          |  134 +++++--------
 arch/mips/include/asm/octeon/octeon.h     |    5 -
 drivers/i2c/busses/i2c-octeon.c           |   94 +++++----
 drivers/net/ethernet/octeon/octeon_mgmt.c |  312 +++++++++++++++++++----------
 drivers/net/phy/mdio-octeon.c             |   92 ++++++---
 drivers/staging/octeon/ethernet-mdio.c    |   28 ++--
 drivers/staging/octeon/ethernet.c         |  153 +++++++++-----
 drivers/staging/octeon/octeon-ethernet.h  |    3 +
 10 files changed, 487 insertions(+), 518 deletions(-)
Cc Greg Kroah-Hartman <[email protected]>
Cc David S. Miller <[email protected]>
Cc "Jean Delvare (PC drivers, core)" <[email protected]>
Cc "Ben Dooks (embedded platforms)" <[email protected]>
Cc "Wolfram Sang (embedded platforms)" <[email protected]>
Signature · 1 line
1.7.2.3
#1 lore raw

PATCH 1/5 i2c: Convert i2c-octeon.c to use device tree.

From: David Daney <[email protected]>

There are three parts to this:

1) Remove the definitions of OCTEON_IRQ_TWSI and OCTEON_IRQ_TWSI2. The interrupts are specified by the device tree and these hard coded irq numbers block the used of the irq lines by the irq_domain code.

2) Remove platform device setup code from octeon-platform.c, it is now unused.

3) Convert i2c-octeon.c to use device tree. Part of this includes using the devm_* functions instead of the raw counterparts, thus simplifying error handling. No functionality is changed.

Cc "Jean Delvare (PC drivers, core)" <[email protected]>
Cc "Ben Dooks (embedded platforms)" <[email protected]>
Cc "Wolfram Sang (embedded platforms)" <[email protected]>

---

Should probably go via Ralf's linux-mips.org tree.

 arch/mips/cavium-octeon/octeon-irq.c      |    2 -
 arch/mips/cavium-octeon/octeon-platform.c |   84 -------------------------
 arch/mips/include/asm/octeon/octeon.h     |    5 --
 drivers/i2c/busses/i2c-octeon.c           |   94 ++++++++++++++++-------------
 4 files changed, 52 insertions(+), 133 deletions(-)
arch/mips/cavium-octeon/octeon-irq.c +0 -2
index 550c03d..7912f96 100644
@@ -1176,13 +1176,11 @@ static void __init octeon_irq_init_ciu(void)
 	for (i = 0; i < 4; i++)
 		octeon_irq_set_ciu_mapping(i + OCTEON_IRQ_PCI_MSI0, 0, i + 40, chip, handle_level_irq);
 
-	octeon_irq_set_ciu_mapping(OCTEON_IRQ_TWSI, 0, 45, chip, handle_level_irq);
 	octeon_irq_set_ciu_mapping(OCTEON_IRQ_RML, 0, 46, chip, handle_level_irq);
 	for (i = 0; i < 4; i++)
 		octeon_irq_set_ciu_mapping(i + OCTEON_IRQ_TIMER0, 0, i + 52, chip, handle_edge_irq);
 
 	octeon_irq_set_ciu_mapping(OCTEON_IRQ_USB0, 0, 56, chip, handle_level_irq);
-	octeon_irq_set_ciu_mapping(OCTEON_IRQ_TWSI2, 0, 59, chip, handle_level_irq);
 	octeon_irq_set_ciu_mapping(OCTEON_IRQ_MII0, 0, 62, chip, handle_level_irq);
 	octeon_irq_set_ciu_mapping(OCTEON_IRQ_BOOTDMA, 0, 63, chip, handle_level_irq);
 
arch/mips/cavium-octeon/octeon-platform.c +0 -84

90 lines not on this page · raw message

arch/mips/include/asm/octeon/octeon.h +0 -5
index f72f768..1e2486e 100644
@@ -215,11 +215,6 @@ struct octeon_cf_data {
 	int		dma_engine;	/* -1 for no DMA */
 };
 
-struct octeon_i2c_data {
-	unsigned int	sys_freq;
-	unsigned int	i2c_freq;
-};
-
 extern void octeon_write_lcd(const char *s);
 extern void octeon_check_cpu_bist(void);
 extern int octeon_get_boot_debug_flag(void);
drivers/i2c/busses/i2c-octeon.c +52 -42

203 lines not on this page · raw message

Signature · 1 line
1.7.2.3
#7 lore raw

PATCH 2/5 netdev: mdio-octeon.c: Convert to use device tree.

In reply to David Daney

From: David Daney <[email protected]>

Get the MDIO bus controller addresses from the device tree, small clean up in use of devm_*

Remove, now unused, platform device setup code.

---

Should probably go via Ralf's linux-mips.org tree.

 arch/mips/cavium-octeon/octeon-platform.c |   30 ---------
 drivers/net/phy/mdio-octeon.c             |   92 ++++++++++++++++++-----------
 2 files changed, 58 insertions(+), 64 deletions(-)
arch/mips/cavium-octeon/octeon-platform.c +0 -30
index f62a40f..66cabc2 100644
@@ -168,36 +168,6 @@ out:
 }
 device_initcall(octeon_rng_device_init);
 
-/* Octeon SMI/MDIO interface.  */
-static int __init octeon_mdiobus_device_init(void)
-{
-	struct platform_device *pd;
-	int ret = 0;
-
-	if (octeon_is_simulation())
-		return 0; /* No mdio in the simulator. */
-
-	/* The bus number is the platform_device id.  */
-	pd = platform_device_alloc("mdio-octeon", 0);
-	if (!pd) {
-		ret = -ENOMEM;
-		goto out;
-	}
-
-	ret = platform_device_add(pd);
-	if (ret)
-		goto fail;
-
-	return ret;
-fail:
-	platform_device_put(pd);
-
-out:
-	return ret;
-
-}
-device_initcall(octeon_mdiobus_device_init);
-
 /* Octeon mgmt port Ethernet interface.  */
 static int __init octeon_mgmt_device_init(void)
 {
drivers/net/phy/mdio-octeon.c +58 -34

189 lines not on this page · raw message

Signature · 1 line
1.7.2.3
#8 lore raw

PATCH 3/5 netdev: octeon_mgmt: Convert to use device tree.

In reply to David Daney

From: David Daney <[email protected]>

The device tree will supply the register bank base addresses, make register addressing relative to those. PHY connection is now described by the device tree.

The OCTEON_IRQ_MII{0,1} symbols are also removed as they are now unused and interfere with the irq_domain used for device tree irq mapping.

---

Should probably go via Ralf's linux-mips.org tree.

 arch/mips/cavium-octeon/octeon-irq.c      |    2 -
 arch/mips/cavium-octeon/octeon-platform.c |   62 ------
 drivers/net/ethernet/octeon/octeon_mgmt.c |  312 +++++++++++++++++++----------
 3 files changed, 207 insertions(+), 169 deletions(-)
arch/mips/cavium-octeon/octeon-irq.c +0 -2
index 7912f96..76f1364 100644
@@ -1181,7 +1181,6 @@ static void __init octeon_irq_init_ciu(void)
 		octeon_irq_set_ciu_mapping(i + OCTEON_IRQ_TIMER0, 0, i + 52, chip, handle_edge_irq);
 
 	octeon_irq_set_ciu_mapping(OCTEON_IRQ_USB0, 0, 56, chip, handle_level_irq);
-	octeon_irq_set_ciu_mapping(OCTEON_IRQ_MII0, 0, 62, chip, handle_level_irq);
 	octeon_irq_set_ciu_mapping(OCTEON_IRQ_BOOTDMA, 0, 63, chip, handle_level_irq);
 
 	/* CIU_1 */
@@ -1190,7 +1189,6 @@ static void __init octeon_irq_init_ciu(void)
 
 	octeon_irq_set_ciu_mapping(OCTEON_IRQ_UART2, 1, 16, chip, handle_level_irq);
 	octeon_irq_set_ciu_mapping(OCTEON_IRQ_USB1, 1, 17, chip, handle_level_irq);
-	octeon_irq_set_ciu_mapping(OCTEON_IRQ_MII1, 1, 18, chip, handle_level_irq);
 
 	gpio_node = of_find_compatible_node(NULL, NULL, "cavium,octeon-3860-gpio");
 	if (gpio_node) {
arch/mips/cavium-octeon/octeon-platform.c +0 -62

68 lines not on this page · raw message

drivers/net/ethernet/octeon/octeon_mgmt.c +207 -105

651 lines not on this page · raw message

Signature · 1 line
1.7.2.3
#9 lore raw

PATCH 4/5 staging: octeon_ethernet: Convert to use device tree.

In reply to David Daney

From: David Daney <[email protected]>

Get MAC address and PHY connection from the device tree. The driver is converted to a platform driver.

---

Should probably go via Ralf's linux-mips.org tree.

 drivers/staging/octeon/ethernet-mdio.c   |   28 +++---
 drivers/staging/octeon/ethernet.c        |  153 +++++++++++++++++++-----------
 drivers/staging/octeon/octeon-ethernet.h |    3 +
 3 files changed, 117 insertions(+), 67 deletions(-)
drivers/staging/octeon/ethernet-mdio.c +15 -13
index e31949c..f15b31b 100644
@@ -28,6 +28,7 @@
 #include <linux/ethtool.h>
 #include <linux/phy.h>
 #include <linux/ratelimit.h>
+#include <linux/of_mdio.h>
 
 #include <net/dst.h>
 
@@ -161,22 +162,23 @@ static void cvm_oct_adjust_link(struct net_device *dev)
 int cvm_oct_phy_setup_device(struct net_device *dev)
 {
 	struct octeon_ethernet *priv = netdev_priv(dev);
+	struct device_node *phy_node;
 
-	int phy_addr = cvmx_helper_board_get_mii_address(priv->port);
-	if (phy_addr != -1) {
-		char phy_id[MII_BUS_ID_SIZE + 3];
+	if (!priv->of_node)
+		return 0;
 
-		snprintf(phy_id, sizeof(phy_id), PHY_ID_FMT, "mdio-octeon-0", phy_addr);
+	phy_node = of_parse_phandle(priv->of_node, "phy-handle", 0);
+	if (!phy_node)
+		return 0;
 
-		priv->phydev = phy_connect(dev, phy_id, cvm_oct_adjust_link, 0,
-					PHY_INTERFACE_MODE_GMII);
+	priv->phydev = of_phy_connect(dev, phy_node, cvm_oct_adjust_link, 0,
+				      PHY_INTERFACE_MODE_GMII);
+
+	if (priv->phydev == NULL)
+		return -ENODEV;
+
+	priv->last_link = 0;
+	phy_start_aneg(priv->phydev);
 
-		if (IS_ERR(priv->phydev)) {
-			priv->phydev = NULL;
-			return -1;
-		}
-		priv->last_link = 0;
-		phy_start_aneg(priv->phydev);
-	}
 	return 0;
 }
drivers/staging/octeon/ethernet.c +99 -54

267 lines not on this page · raw message

drivers/staging/octeon/octeon-ethernet.h +3 -0
index d581925..9360e22 100644
@@ -31,6 +31,8 @@
 #ifndef OCTEON_ETHERNET_H
 #define OCTEON_ETHERNET_H
 
+#include <linux/of.h>
+
 /**
  * This is the definition of the Ethernet driver's private
  * driver state stored in netdev_priv(dev).
@@ -59,6 +61,7 @@ struct octeon_ethernet {
 	void (*poll) (struct net_device *dev);
 	struct delayed_work	port_periodic_work;
 	struct work_struct	port_work;	/* may be unused. */
+	struct device_node	*of_node;
 };
 
 int cvm_oct_free_work(void *work_queue_entry);
Signature · 1 line
1.7.2.3
#11 lore raw

PATCH 5/5 MIPS: Octeon: Use device tree to register serial ports.

In reply to David Daney

From: David Daney <[email protected]>

Switch to using the device tree to register serial ports.

Add all the ports with compatible = "cavium,octeon-3860-uart". Octeon serial ports have their own device type, required port flags, and I/O functions, so using of_serial.c is not indicated.

We need to do this as late_initcall, as the 8250 driver must be initialized before we add any ports. 8250 initialization is done at device_initcall time.

The OCTEON_IRQ_UART{0,1,2} symbols are removed as they are now unused and interfere with irq_domain used by the device tree code.

---

Should probably go via Ralf's linux-mips.org tree.

 arch/mips/cavium-octeon/octeon-irq.c |    4 -
 arch/mips/cavium-octeon/serial.c     |  134 +++++++++++++--------------------
 2 files changed, 53 insertions(+), 85 deletions(-)
arch/mips/cavium-octeon/octeon-irq.c +0 -4
index 76f1364..c7eaa23 100644
@@ -1168,9 +1168,6 @@ static void __init octeon_irq_init_ciu(void)
 	octeon_irq_set_ciu_mapping(OCTEON_IRQ_MBOX0, 0, 32, chip_mbox, handle_percpu_irq);
 	octeon_irq_set_ciu_mapping(OCTEON_IRQ_MBOX1, 0, 33, chip_mbox, handle_percpu_irq);
 
-	octeon_irq_set_ciu_mapping(OCTEON_IRQ_UART0, 0, 34, chip, handle_level_irq);
-	octeon_irq_set_ciu_mapping(OCTEON_IRQ_UART1, 0, 35, chip, handle_level_irq);
-
 	for (i = 0; i < 4; i++)
 		octeon_irq_set_ciu_mapping(i + OCTEON_IRQ_PCI_INT0, 0, i + 36, chip, handle_level_irq);
 	for (i = 0; i < 4; i++)
@@ -1187,7 +1184,6 @@ static void __init octeon_irq_init_ciu(void)
 	for (i = 0; i < 16; i++)
 		octeon_irq_set_ciu_mapping(i + OCTEON_IRQ_WDOG0, 1, i + 0, chip_wd, handle_level_irq);
 
-	octeon_irq_set_ciu_mapping(OCTEON_IRQ_UART2, 1, 16, chip, handle_level_irq);
 	octeon_irq_set_ciu_mapping(OCTEON_IRQ_USB1, 1, 17, chip, handle_level_irq);
 
 	gpio_node = of_find_compatible_node(NULL, NULL, "cavium,octeon-3860-gpio");
arch/mips/cavium-octeon/serial.c +53 -81

148 lines not on this page · raw message

Signature · 1 line
1.7.2.3
Acked-by on v1 1/5
#2 lore raw

Re: [PATCH 1/5] i2c: Convert i2c-octeon.c to use device tree.

In reply to David Daney
Quoted 9 lines · David Daney

From: David Daney <david.daney-YGCgFSpz5w/[email protected]>

There are three parts to this:

1) Remove the definitions of OCTEON_IRQ_TWSI and OCTEON_IRQ_TWSI2. The interrupts are specified by the device tree and these hard coded irq numbers block the used of the irq lines by the irq_domain code.

Quoted 6 lines

2) Remove platform device setup code from octeon-platform.c, it is now unused.

3) Convert i2c-octeon.c to use device tree. Part of this includes using the devm_* functions instead of the raw counterparts, thus simplifying error handling. No functionality is changed.

Shouldn't this patch go after converting the platform to DT?

Quoted 14 lines
Cc "Jean Delvare (PC drivers, core)" <[email protected]>
Cc "Ben Dooks (embedded platforms)" <[email protected]>
Cc "Wolfram Sang (embedded platforms)" <[email protected]>

---

Should probably go via Ralf's linux-mips.org tree.

 arch/mips/cavium-octeon/octeon-irq.c      |    2 -
 arch/mips/cavium-octeon/octeon-platform.c |   84 -------------------------
 arch/mips/include/asm/octeon/octeon.h     |    5 --
 drivers/i2c/busses/i2c-octeon.c           |   94 ++++++++++++++++-------------
 4 files changed, 52 insertions(+), 133 deletions(-)

snip

drivers/i2c/busses/i2c-octeon.c static int __devinit octeon_i2c_probe(struct platform_device *pdev) · line 553

Quoted 13 lines
drivers/i2c/busses/i2c-octeon.c +10 -2
-	if (i2c_data == NULL) {
-		dev_err(i2c->dev, "no I2C frequency data\n");
+	/*
+	 * "clock-rate" is a legacy binding, the official binding is
+	 * "clock-frequency".  Try the official one first and then
+	 * fall back if it doesn't exist.
+	 */
+	data = of_get_property(pdev->dev.of_node, "clock-frequency", &len);
+	if (!data || len != sizeof(*data))
+		data = of_get_property(pdev->dev.of_node, "clock-rate", &len);
+	if (data && len == sizeof(*data)) {
+		i2c->twsi_freq = be32_to_cpup(data);

Can't you use of_property_read_u32?

Does the legacy binding really exist as DT support is new?

Otherwise,

Quoted 117 lines
drivers/i2c/busses/i2c-octeon.c +28 -27
+	} else {
+		dev_err(i2c->dev,
+			"no I2C 'clock-rate' or 'clock-frequency' property\n");
 		result = -ENXIO;
-		goto fail_region;
+		goto out;
 	}
 
-	i2c->twsi_phys = res_mem->start;
-	i2c->regsize = resource_size(res_mem);
-	i2c->twsi_freq = i2c_data->i2c_freq;
-	i2c->sys_freq = i2c_data->sys_freq;
+	i2c->sys_freq = octeon_get_io_clock_rate();
 
-	if (!request_mem_region(i2c->twsi_phys, i2c->regsize, res_mem->name)) {
+	if (!devm_request_mem_region(&pdev->dev, i2c->twsi_phys, i2c->regsize,
+				      res_mem->name)) {
 		dev_err(i2c->dev, "request_mem_region failed\n");
-		goto fail_region;
+		goto out;
 	}
-	i2c->twsi_base = ioremap(i2c->twsi_phys, i2c->regsize);
+	i2c->twsi_base = devm_ioremap(&pdev->dev, i2c->twsi_phys, i2c->regsize);
 
 	init_waitqueue_head(&i2c->queue);
 
 	i2c->irq = irq;
 
-	result = request_irq(i2c->irq, octeon_i2c_isr, 0, DRV_NAME, i2c);
+	result = devm_request_irq(&pdev->dev, i2c->irq,
+				  octeon_i2c_isr, 0, DRV_NAME, i2c);
 	if (result < 0) {
 		dev_err(i2c->dev, "failed to attach interrupt\n");
-		goto fail_irq;
+		goto out;
 	}
 
 	result = octeon_i2c_initlowlevel(i2c);
 	if (result) {
 		dev_err(i2c->dev, "init low level failed\n");
-		goto  fail_add;
+		goto  out;
 	}
 
 	result = octeon_i2c_setclock(i2c);
 	if (result) {
 		dev_err(i2c->dev, "clock init failed\n");
-		goto  fail_add;
+		goto  out;
 	}
 
 	i2c->adap = octeon_i2c_ops;
 	i2c->adap.dev.parent = &pdev->dev;
-	i2c->adap.nr = pdev->id >= 0 ? pdev->id : 0;
+	i2c->adap.dev.of_node = pdev->dev.of_node;
 	i2c_set_adapdata(&i2c->adap, i2c);
 	platform_set_drvdata(pdev, i2c);
 
-	result = i2c_add_numbered_adapter(&i2c->adap);
+	result = i2c_add_adapter(&i2c->adap);
 	if (result < 0) {
 		dev_err(i2c->dev, "failed to add adapter\n");
 		goto fail_add;
 	}
-
 	dev_info(i2c->dev, "version %s\n", DRV_VERSION);
 
-	return result;
+	of_i2c_register_devices(&i2c->adap);
+
+	return 0;
 
 fail_add:
 	platform_set_drvdata(pdev, NULL);
-	free_irq(i2c->irq, i2c);
-fail_irq:
-	iounmap(i2c->twsi_base);
-	release_mem_region(i2c->twsi_phys, i2c->regsize);
-fail_region:
-	kfree(i2c);
 out:
 	return result;
 };
@@ -613,19 +619,24 @@ static int __devexit octeon_i2c_remove(struct platform_device *pdev)
 
 	i2c_del_adapter(&i2c->adap);
 	platform_set_drvdata(pdev, NULL);
-	free_irq(i2c->irq, i2c);
-	iounmap(i2c->twsi_base);
-	release_mem_region(i2c->twsi_phys, i2c->regsize);
-	kfree(i2c);
 	return 0;
 };
 
+static struct of_device_id octeon_i2c_match[] = {
+	{
+		.compatible = "cavium,octeon-3860-twsi",
+	},
+	{},
+};
+MODULE_DEVICE_TABLE(of, octeon_i2c_match);
+
 static struct platform_driver octeon_i2c_driver = {
 	.probe		= octeon_i2c_probe,
 	.remove		= __devexit_p(octeon_i2c_remove),
 	.driver		= {
 		.owner	= THIS_MODULE,
 		.name	= DRV_NAME,
+		.of_match_table = octeon_i2c_match,
 	},
 };
 
@@ -635,4 +646,3 @@ MODULE_AUTHOR("Michael Lawnick <[email protected]>");
 MODULE_DESCRIPTION("I2C-Bus adapter for Cavium OCTEON processors");
 MODULE_LICENSE("GPL");
 MODULE_VERSION(DRV_VERSION);
-MODULE_ALIAS("platform:" DRV_NAME);
#3 lore raw

Re: [PATCH 1/5] i2c: Convert i2c-octeon.c to use device tree.

Quoted 10 lines · Rob Herring
Quoted 9 lines · David Daney

From: David Daney <david.daney-YGCgFSpz5w/[email protected]>

There are three parts to this:

1) Remove the definitions of OCTEON_IRQ_TWSI and OCTEON_IRQ_TWSI2. The interrupts are specified by the device tree and these hard coded irq numbers block the used of the irq lines by the irq_domain code.

Quoted 8 lines
Quoted 6 lines

2) Remove platform device setup code from octeon-platform.c, it is now unused.

3) Convert i2c-octeon.c to use device tree. Part of this includes using the devm_* functions instead of the raw counterparts, thus simplifying error handling. No functionality is changed.

Shouldn't this patch go after converting the platform to DT?

Nevermind this comment...

Quoted 158 lines
Quoted 15 lines
Cc "Jean Delvare (PC drivers, core)" <[email protected]>
Cc "Ben Dooks (embedded platforms)" <[email protected]>
Cc "Wolfram Sang (embedded platforms)" <[email protected]>

---

Should probably go via Ralf's linux-mips.org tree.

 arch/mips/cavium-octeon/octeon-irq.c      |    2 -
 arch/mips/cavium-octeon/octeon-platform.c |   84 -------------------------
 arch/mips/include/asm/octeon/octeon.h     |    5 --
 drivers/i2c/busses/i2c-octeon.c           |   94 ++++++++++++++++-------------
 4 files changed, 52 insertions(+), 133 deletions(-)

snip

drivers/i2c/busses/i2c-octeon.c static int __devinit octeon_i2c_probe(struct platform_device *pdev) · line 553

Quoted 13 lines
drivers/i2c/busses/i2c-octeon.c +10 -2
-	if (i2c_data == NULL) {
-		dev_err(i2c->dev, "no I2C frequency data\n");
+	/*
+	 * "clock-rate" is a legacy binding, the official binding is
+	 * "clock-frequency".  Try the official one first and then
+	 * fall back if it doesn't exist.
+	 */
+	data = of_get_property(pdev->dev.of_node, "clock-frequency", &len);
+	if (!data || len != sizeof(*data))
+		data = of_get_property(pdev->dev.of_node, "clock-rate", &len);
+	if (data && len == sizeof(*data)) {
+		i2c->twsi_freq = be32_to_cpup(data);

Can't you use of_property_read_u32?

Does the legacy binding really exist as DT support is new?

Otherwise,

Quoted 117 lines
drivers/i2c/busses/i2c-octeon.c +28 -27
+	} else {
+		dev_err(i2c->dev,
+			"no I2C 'clock-rate' or 'clock-frequency' property\n");
 		result = -ENXIO;
-		goto fail_region;
+		goto out;
 	}
 
-	i2c->twsi_phys = res_mem->start;
-	i2c->regsize = resource_size(res_mem);
-	i2c->twsi_freq = i2c_data->i2c_freq;
-	i2c->sys_freq = i2c_data->sys_freq;
+	i2c->sys_freq = octeon_get_io_clock_rate();
 
-	if (!request_mem_region(i2c->twsi_phys, i2c->regsize, res_mem->name)) {
+	if (!devm_request_mem_region(&pdev->dev, i2c->twsi_phys, i2c->regsize,
+				      res_mem->name)) {
 		dev_err(i2c->dev, "request_mem_region failed\n");
-		goto fail_region;
+		goto out;
 	}
-	i2c->twsi_base = ioremap(i2c->twsi_phys, i2c->regsize);
+	i2c->twsi_base = devm_ioremap(&pdev->dev, i2c->twsi_phys, i2c->regsize);
 
 	init_waitqueue_head(&i2c->queue);
 
 	i2c->irq = irq;
 
-	result = request_irq(i2c->irq, octeon_i2c_isr, 0, DRV_NAME, i2c);
+	result = devm_request_irq(&pdev->dev, i2c->irq,
+				  octeon_i2c_isr, 0, DRV_NAME, i2c);
 	if (result < 0) {
 		dev_err(i2c->dev, "failed to attach interrupt\n");
-		goto fail_irq;
+		goto out;
 	}
 
 	result = octeon_i2c_initlowlevel(i2c);
 	if (result) {
 		dev_err(i2c->dev, "init low level failed\n");
-		goto  fail_add;
+		goto  out;
 	}
 
 	result = octeon_i2c_setclock(i2c);
 	if (result) {
 		dev_err(i2c->dev, "clock init failed\n");
-		goto  fail_add;
+		goto  out;
 	}
 
 	i2c->adap = octeon_i2c_ops;
 	i2c->adap.dev.parent = &pdev->dev;
-	i2c->adap.nr = pdev->id >= 0 ? pdev->id : 0;
+	i2c->adap.dev.of_node = pdev->dev.of_node;
 	i2c_set_adapdata(&i2c->adap, i2c);
 	platform_set_drvdata(pdev, i2c);
 
-	result = i2c_add_numbered_adapter(&i2c->adap);
+	result = i2c_add_adapter(&i2c->adap);
 	if (result < 0) {
 		dev_err(i2c->dev, "failed to add adapter\n");
 		goto fail_add;
 	}
-
 	dev_info(i2c->dev, "version %s\n", DRV_VERSION);
 
-	return result;
+	of_i2c_register_devices(&i2c->adap);
+
+	return 0;
 
 fail_add:
 	platform_set_drvdata(pdev, NULL);
-	free_irq(i2c->irq, i2c);
-fail_irq:
-	iounmap(i2c->twsi_base);
-	release_mem_region(i2c->twsi_phys, i2c->regsize);
-fail_region:
-	kfree(i2c);
 out:
 	return result;
 };
@@ -613,19 +619,24 @@ static int __devexit octeon_i2c_remove(struct platform_device *pdev)
 
 	i2c_del_adapter(&i2c->adap);
 	platform_set_drvdata(pdev, NULL);
-	free_irq(i2c->irq, i2c);
-	iounmap(i2c->twsi_base);
-	release_mem_region(i2c->twsi_phys, i2c->regsize);
-	kfree(i2c);
 	return 0;
 };
 
+static struct of_device_id octeon_i2c_match[] = {
+	{
+		.compatible = "cavium,octeon-3860-twsi",
+	},
+	{},
+};
+MODULE_DEVICE_TABLE(of, octeon_i2c_match);
+
 static struct platform_driver octeon_i2c_driver = {
 	.probe		= octeon_i2c_probe,
 	.remove		= __devexit_p(octeon_i2c_remove),
 	.driver		= {
 		.owner	= THIS_MODULE,
 		.name	= DRV_NAME,
+		.of_match_table = octeon_i2c_match,
 	},
 };
 
@@ -635,4 +646,3 @@ MODULE_AUTHOR("Michael Lawnick <[email protected]>");
 MODULE_DESCRIPTION("I2C-Bus adapter for Cavium OCTEON processors");
 MODULE_LICENSE("GPL");
 MODULE_VERSION(DRV_VERSION);
-MODULE_ALIAS("platform:" DRV_NAME);
#4 lore raw

Re: [PATCH 1/5] i2c: Convert i2c-octeon.c to use device tree.

In reply to Rob Herring

On 03/26/2012 06:20 PM, Rob Herring wrote:
[...]

Quoted 13 lines
Quoted 9 lines

---

Should probably go via Ralf's linux-mips.org tree.

  arch/mips/cavium-octeon/octeon-irq.c      |    2 -
  arch/mips/cavium-octeon/octeon-platform.c |   84 -------------------------
  arch/mips/include/asm/octeon/octeon.h     |    5 --
  drivers/i2c/busses/i2c-octeon.c           |   94 ++++++++++++++++-------------
  4 files changed, 52 insertions(+), 133 deletions(-)

snip

Quoted 1 line
Quoted 14 lines

drivers/i2c/busses/i2c-octeon.c static int __devinit octeon_i2c_probe(struct platform_device *pdev) · line 553

Quoted 12 lines
drivers/i2c/busses/i2c-octeon.c +10 -2
-	if (i2c_data == NULL) {
-		dev_err(i2c->dev, "no I2C frequency data\n");
+	/*
+	 * "clock-rate" is a legacy binding, the official binding is
+	 * "clock-frequency".  Try the official one first and then
+	 * fall back if it doesn't exist.
+	 */
+	data = of_get_property(pdev->dev.of_node, "clock-frequency",&len);
+	if (!data || len != sizeof(*data))
+		data = of_get_property(pdev->dev.of_node, "clock-rate",&len);
+	if (data&&  len == sizeof(*data)) {
+		i2c->twsi_freq = be32_to_cpup(data);

Can't you use of_property_read_u32?

I will investigate, and use it if possible.

Quoted 3 lines

Does the legacy binding really exist as DT support is new?

Yes, unfortunately some bootloaders escaped into the wild with the "clock-rate" binding.

Quoted 4 lines

Otherwise,

Thanks,

maintainer Acked-by on v1 4/5
#10 lore raw

Re: [PATCH 4/5] staging: octeon_ethernet: Convert to use device tree.

In reply to David Daney
Quoted 11 lines · David Daney

From: David Daney <[email protected]>

Get MAC address and PHY connection from the device tree. The driver is converted to a platform driver.

---

Should probably go via Ralf's linux-mips.org tree.

That's fine with me:

#5 lore raw

Re: [PATCH 1/5] i2c: Convert i2c-octeon.c to use device tree.

In reply to David Daney
Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
drivers/i2c/busses/i2c-octeon.c +4 -2
-	if (i2c_data == NULL) {
-		dev_err(i2c->dev, "no I2C frequency data\n");
+	/*
+	 * "clock-rate" is a legacy binding, the official binding is
+	 * "clock-frequency".  Try the official one first and then
+	 * fall back if it doesn't exist.
Quoted 8 lines

drivers/i2c/busses/i2c-octeon.c static int __devinit octeon_i2c_probe(struct platform_device *pdev) · line 553

Quoted 6 lines
drivers/i2c/busses/i2c-octeon.c +6 -0
+	 */
+	data = of_get_property(pdev->dev.of_node, "clock-frequency",&len);
+	if (!data || len != sizeof(*data))
+		data = of_get_property(pdev->dev.of_node, "clock-rate",&len);
+	if (data&&  len == sizeof(*data)) {
+		i2c->twsi_freq = be32_to_cpup(data);

Can't you use of_property_read_u32?

Quoted 1 line

I will investigate, and use it if possible.

Any outcome?

And shouldn't the bindings be documented? Or are they only standard and we hide the legacy one?

Regards,

Wolfram

Signature · 2 lines
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
#6 lore raw

Re: [PATCH 1/5] i2c: Convert i2c-octeon.c to use device tree.

Quoted 15 lines · Wolfram Sang
Quoted 15 lines
Quoted 14 lines

drivers/i2c/busses/i2c-octeon.c static int __devinit octeon_i2c_probe(struct platform_device *pdev) · line 553

Quoted 12 lines
drivers/i2c/busses/i2c-octeon.c +10 -2
-	if (i2c_data == NULL) {
-		dev_err(i2c->dev, "no I2C frequency data\n");
+	/*
+	 * "clock-rate" is a legacy binding, the official binding is
+	 * "clock-frequency".  Try the official one first and then
+	 * fall back if it doesn't exist.
+	 */
+	data = of_get_property(pdev->dev.of_node, "clock-frequency",&len);
+	if (!data || len != sizeof(*data))
+		data = of_get_property(pdev->dev.of_node, "clock-rate",&len);
+	if (data&&   len == sizeof(*data)) {
+		i2c->twsi_freq = be32_to_cpup(data);

Can't you use of_property_read_u32?

Quoted 3 lines
Quoted 1 line

I will investigate, and use it if possible.

Any outcome?

Yes, I have implemented Rob's suggestions. A new patch set reflecting this is coming soon.

Quoted 4 lines

And shouldn't the bindings be documented? Or are they only standard and we hide the legacy one?

Yes, they are documented here:

http://patchwork.linux-mips.org/patch/3536/

look in the cavium-i2c.txt file.

Thanks,
David Daney