aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c/busses
diff options
context:
space:
mode:
authorLee Jones <lee.jones@linaro.org>2012-08-06 06:09:57 -0400
committerWolfram Sang <w.sang@pengutronix.de>2012-10-06 07:20:33 -0400
commit43fea5813c56e4327371fd3c2209791ef7822de2 (patch)
tree6473edc6e3e3d84ff050393c18b5e3a65a50c8f6 /drivers/i2c/busses
parenta76e7c6821b5dddf69db9d76ec282819545f5b73 (diff)
i2c: nomadik: Add Device Tree support to the Nomadik I2C driver
Here we apply the bindings required for successful Device Tree probing of the i2c-nomadik driver. Signed-off-by: Lee Jones <lee.jones@linaro.org> Acked-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
Diffstat (limited to 'drivers/i2c/busses')
-rw-r--r--drivers/i2c/busses/i2c-nomadik.c35
1 files changed, 32 insertions, 3 deletions
diff --git a/drivers/i2c/busses/i2c-nomadik.c b/drivers/i2c/busses/i2c-nomadik.c
index 1b898b647ec2..698d7acb0f08 100644
--- a/drivers/i2c/busses/i2c-nomadik.c
+++ b/drivers/i2c/busses/i2c-nomadik.c
@@ -24,6 +24,8 @@
24#include <linux/io.h> 24#include <linux/io.h>
25#include <linux/pm_runtime.h> 25#include <linux/pm_runtime.h>
26#include <linux/platform_data/i2c-nomadik.h> 26#include <linux/platform_data/i2c-nomadik.h>
27#include <linux/of.h>
28#include <linux/of_i2c.h>
27 29
28#define DRIVER_NAME "nmk-i2c" 30#define DRIVER_NAME "nmk-i2c"
29 31
@@ -913,18 +915,42 @@ static struct nmk_i2c_controller u8500_i2c = {
913 .sm = I2C_FREQ_MODE_FAST, 915 .sm = I2C_FREQ_MODE_FAST,
914}; 916};
915 917
918static void nmk_i2c_of_probe(struct device_node *np,
919 struct nmk_i2c_controller *pdata)
920{
921 of_property_read_u32(np, "clock-frequency", &pdata->clk_freq);
922
923 /* This driver only supports 'standard' and 'fast' modes of operation. */
924 if (pdata->clk_freq <= 100000)
925 pdata->sm = I2C_FREQ_MODE_STANDARD;
926 else
927 pdata->sm = I2C_FREQ_MODE_FAST;
928}
929
916static atomic_t adapter_id = ATOMIC_INIT(0); 930static atomic_t adapter_id = ATOMIC_INIT(0);
917 931
918static int nmk_i2c_probe(struct amba_device *adev, const struct amba_id *id) 932static int nmk_i2c_probe(struct amba_device *adev, const struct amba_id *id)
919{ 933{
920 int ret = 0; 934 int ret = 0;
921 struct nmk_i2c_controller *pdata = adev->dev.platform_data; 935 struct nmk_i2c_controller *pdata = adev->dev.platform_data;
936 struct device_node *np = adev->dev.of_node;
922 struct nmk_i2c_dev *dev; 937 struct nmk_i2c_dev *dev;
923 struct i2c_adapter *adap; 938 struct i2c_adapter *adap;
924 939
925 if (!pdata) 940 if (!pdata) {
926 /* No i2c configuration found, using the default. */ 941 if (np) {
927 pdata = &u8500_i2c; 942 pdata = devm_kzalloc(&adev->dev, sizeof(*pdata), GFP_KERNEL);
943 if (!pdata) {
944 ret = -ENOMEM;
945 goto err_no_mem;
946 }
947 /* Provide the default configuration as a base. */
948 memcpy(pdata, &u8500_i2c, sizeof(struct nmk_i2c_controller));
949 nmk_i2c_of_probe(np, pdata);
950 } else
951 /* No i2c configuration found, using the default. */
952 pdata = &u8500_i2c;
953 }
928 954
929 dev = kzalloc(sizeof(struct nmk_i2c_dev), GFP_KERNEL); 955 dev = kzalloc(sizeof(struct nmk_i2c_dev), GFP_KERNEL);
930 if (!dev) { 956 if (!dev) {
@@ -960,6 +986,7 @@ static int nmk_i2c_probe(struct amba_device *adev, const struct amba_id *id)
960 } 986 }
961 987
962 adap = &dev->adap; 988 adap = &dev->adap;
989 adap->dev.of_node = np;
963 adap->dev.parent = &adev->dev; 990 adap->dev.parent = &adev->dev;
964 adap->owner = THIS_MODULE; 991 adap->owner = THIS_MODULE;
965 adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD; 992 adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
@@ -989,6 +1016,8 @@ static int nmk_i2c_probe(struct amba_device *adev, const struct amba_id *id)
989 goto err_add_adap; 1016 goto err_add_adap;
990 } 1017 }
991 1018
1019 of_i2c_register_devices(adap);
1020
992 pm_runtime_put(&adev->dev); 1021 pm_runtime_put(&adev->dev);
993 1022
994 return 0; 1023 return 0;