From f4d30232d88d7741f56eb5075834311d95f25dfd Mon Sep 17 00:00:00 2001 From: Joel Stanley Date: Wed, 10 Feb 2016 12:49:20 +1030 Subject: [PATCH] i2c/aspeed: Set pdev name corresponding to bus Our device name is derived from the address the peripheral sits at in mmio space; this is not useful for users. Instead name it after the i2c bus. Milton explains why this is important for IRQ debugging: The aspeed i2c controller has an irq per bus and this has been exposed as an irq domain. However, each irq is requested the same device name, leaving one to guess which irq in /proc/interrupts corresponds to which device. While the controller irq number is unique and happens to match, it is not obvious that there is no offset. The driver registers the bus with the numbered bus api, so the global bus number is known an we can predict it before registering. The information that this is from an ast-i2c bus is in the irq controller name or could be found from the matching i2c bus device in sysfs. Excerpt of /proc/interrupts before this patch: 220: 1094 ast-i2c 0 Edge ast-i2c-bus 221: 0 ast-i2c 1 Edge ast-i2c-bus 222: 9438 ast-i2c 2 Edge ast-i2c-bus 223: 26480 ast-i2c 3 Edge ast-i2c-bus New excerpt from /proc/interrupts: 220: 1094 ast-i2c 0 Edge i2c-0 221: 0 ast-i2c 1 Edge i2c-1 222: 9438 ast-i2c 2 Edge i2c-2 223: 26480 ast-i2c 3 Edge i2c-3 224: 0 ast-i2c 4 Edge i2c-4 New example proc/irq/ directory: /proc/irq/222: i2c-2 spurious Signed-off-by: Joel Stanley --- drivers/i2c/busses/i2c-aspeed.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/i2c/busses/i2c-aspeed.c b/drivers/i2c/busses/i2c-aspeed.c index 1f301e65b4234d..5488233886dac0 100644 --- a/drivers/i2c/busses/i2c-aspeed.c +++ b/drivers/i2c/busses/i2c-aspeed.c @@ -693,6 +693,13 @@ static int ast_i2c_probe_bus(struct platform_device *pdev) if (ret) return -ENXIO; + /* + * Set a useful name derived from the bus number; the device tree + * should provide us with one that corresponds to the hardware + * numbering + */ + dev_set_name(&pdev->dev, "i2c-%d", bus_num); + bus->pclk = devm_clk_get(&pdev->dev, NULL); if (IS_ERR(bus->pclk)) { dev_dbg(&pdev->dev, "clk_get failed\n"); @@ -711,7 +718,7 @@ static int ast_i2c_probe_bus(struct platform_device *pdev) } ret = devm_request_irq(&pdev->dev, bus->irq, ast_i2c_bus_irq, - 0, "ast-i2c-bus", bus); + 0, dev_name(&pdev->dev), bus); if (ret) { dev_err(&pdev->dev, "devm_request_irq failed\n"); return -ENXIO; @@ -727,8 +734,8 @@ static int ast_i2c_probe_bus(struct platform_device *pdev) bus->adap.algo_data = bus; bus->adap.dev.parent = &pdev->dev; bus->adap.dev.of_node = pdev->dev.of_node; - snprintf(bus->adap.name, sizeof(bus->adap.name), "Aspeed i2c at %p", - bus->base); + snprintf(bus->adap.name, sizeof(bus->adap.name), "Aspeed i2c-%d", + bus_num); bus->dev = &pdev->dev;