aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c/i2c-core.c
diff options
context:
space:
mode:
authorWolfram Sang <wsa+renesas@sang-engineering.com>2015-12-08 04:37:46 -0500
committerWolfram Sang <wsa@the-dreams.de>2015-12-14 04:51:07 -0500
commite1dba01ca620bb0b3864d5237c1c597d9e012ebf (patch)
tree44b4a1e51fbb14fc803f2cbd18a13c0509eda207 /drivers/i2c/i2c-core.c
parent99b809d7bdd17de7a68f1625a8973052c8311657 (diff)
i2c: add generic routine to parse DT for timing information
Inspired from the i2c-rk3x driver (thanks guys!) but refactored and extended. See built-in docs for further information. Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com> Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
Diffstat (limited to 'drivers/i2c/i2c-core.c')
-rw-r--r--drivers/i2c/i2c-core.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index ba8eb087f224..b34c412bd2c2 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -53,6 +53,7 @@
53#include <linux/jump_label.h> 53#include <linux/jump_label.h>
54#include <asm/uaccess.h> 54#include <asm/uaccess.h>
55#include <linux/err.h> 55#include <linux/err.h>
56#include <linux/property.h>
56 57
57#include "i2c-core.h" 58#include "i2c-core.h"
58 59
@@ -1438,6 +1439,58 @@ static void of_i2c_register_devices(struct i2c_adapter *adap)
1438 } 1439 }
1439} 1440}
1440 1441
1442/**
1443 * i2c_parse_fw_timings - get I2C related timing parameters from firmware
1444 * @dev: The device to scan for I2C timing properties
1445 * @t: the i2c_timings struct to be filled with values
1446 * @use_defaults: bool to use sane defaults derived from the I2C specification
1447 * when properties are not found, otherwise use 0
1448 *
1449 * Scan the device for the generic I2C properties describing timing parameters
1450 * for the signal and fill the given struct with the results. If a property was
1451 * not found and use_defaults was true, then maximum timings are assumed which
1452 * are derived from the I2C specification. If use_defaults is not used, the
1453 * results will be 0, so drivers can apply their own defaults later. The latter
1454 * is mainly intended for avoiding regressions of existing drivers which want
1455 * to switch to this function. New drivers almost always should use the defaults.
1456 */
1457
1458void i2c_parse_fw_timings(struct device *dev, struct i2c_timings *t, bool use_defaults)
1459{
1460 int ret;
1461
1462 memset(t, 0, sizeof(*t));
1463
1464 ret = device_property_read_u32(dev, "clock-frequency", &t->bus_freq_hz);
1465 if (ret && use_defaults)
1466 t->bus_freq_hz = 100000;
1467
1468 ret = device_property_read_u32(dev, "i2c-scl-rising-time-ns", &t->scl_rise_ns);
1469 if (ret && use_defaults) {
1470 if (t->bus_freq_hz <= 100000)
1471 t->scl_rise_ns = 1000;
1472 else if (t->bus_freq_hz <= 400000)
1473 t->scl_rise_ns = 300;
1474 else
1475 t->scl_rise_ns = 120;
1476 }
1477
1478 ret = device_property_read_u32(dev, "i2c-scl-falling-time-ns", &t->scl_fall_ns);
1479 if (ret && use_defaults) {
1480 if (t->bus_freq_hz <= 400000)
1481 t->scl_fall_ns = 300;
1482 else
1483 t->scl_fall_ns = 120;
1484 }
1485
1486 device_property_read_u32(dev, "i2c-scl-internal-delay-ns", &t->scl_int_delay_ns);
1487
1488 ret = device_property_read_u32(dev, "i2c-sda-falling-time-ns", &t->sda_fall_ns);
1489 if (ret && use_defaults)
1490 t->sda_fall_ns = t->scl_fall_ns;
1491}
1492EXPORT_SYMBOL_GPL(i2c_parse_fw_timings);
1493
1441static int of_dev_node_match(struct device *dev, void *data) 1494static int of_dev_node_match(struct device *dev, void *data)
1442{ 1495{
1443 return dev->of_node == data; 1496 return dev->of_node == data;