aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLiviu Dudau <Liviu.Dudau@arm.com>2014-10-03 10:33:21 +0100
committerJon Medhurst <tixy@linaro.org>2014-10-08 17:05:44 +0100
commit6ff7163bb901f3b3846163bb567a09f484413135 (patch)
tree901d14e32a82162b18546a892c41b7768e46afad
parent114185e1aae96ceeb55e33a162c7b3580e54a3d9 (diff)
downloadjuno-6ff7163bb901f3b3846163bb567a09f484413135.tar.gz
i2c: designware: Add support for changing the bus rate based on DT info
The Designware I2C driver does not currently support changing the bus speed even if the hardware is capable of switching to a slower frequency. Add support for passing the clock frequency info in the device tree. Only standard (100kHz) or fast (400kHz) speeds are supported. Signed-off-by: Andrew Jackson <Andrew.Jackson@arm.com> Signed-off-by: Liviu Dudau <Liviu.Dudau@arm.com> Signed-off-by: Jon Medhurst <tixy@linaro.org>
-rw-r--r--drivers/i2c/busses/i2c-designware-platdrv.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c
index 65a660f2901..2da574a9f03 100644
--- a/drivers/i2c/busses/i2c-designware-platdrv.c
+++ b/drivers/i2c/busses/i2c-designware-platdrv.c
@@ -87,6 +87,7 @@ static int dw_i2c_probe(struct platform_device *pdev)
struct i2c_adapter *adap;
struct resource *mem;
int irq, r;
+ u32 bus_rate = DW_IC_CON_SPEED_STD;
/* NOTE: driver uses the static register mapping */
mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -137,6 +138,22 @@ static int dw_i2c_probe(struct platform_device *pdev)
of_property_read_u32(pdev->dev.of_node,
"i2c-scl-falling-time-ns",
&dev->scl_falling_time);
+
+ r = of_property_read_u32(pdev->dev.of_node, "clock-frequency",
+ &bus_rate);
+ if (r)
+ bus_rate = 400000; /* default clock rate */
+ switch (bus_rate) {
+ case 400000:
+ bus_rate = DW_IC_CON_SPEED_FAST;
+ break;
+ case 100000:
+ bus_rate = DW_IC_CON_SPEED_STD;
+ break;
+ default:
+ dev_err(&pdev->dev, "Invalid bus speed (not 100kHz or 400kHz)\n");
+ return -EINVAL;
+ }
}
dev->functionality =
@@ -147,7 +164,7 @@ static int dw_i2c_probe(struct platform_device *pdev)
I2C_FUNC_SMBUS_WORD_DATA |
I2C_FUNC_SMBUS_I2C_BLOCK;
dev->master_cfg = DW_IC_CON_MASTER | DW_IC_CON_SLAVE_DISABLE |
- DW_IC_CON_RESTART_EN | DW_IC_CON_SPEED_FAST;
+ DW_IC_CON_RESTART_EN | bus_rate;
/* Try first if we can configure the device from ACPI */
r = dw_i2c_acpi_configure(pdev);