diff options
| author | Lee Jones <lee.jones@linaro.org> | 2012-08-06 06:09:57 -0400 |
|---|---|---|
| committer | Wolfram Sang <w.sang@pengutronix.de> | 2012-10-06 07:20:33 -0400 |
| commit | 43fea5813c56e4327371fd3c2209791ef7822de2 (patch) | |
| tree | 6473edc6e3e3d84ff050393c18b5e3a65a50c8f6 | |
| parent | a76e7c6821b5dddf69db9d76ec282819545f5b73 (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>
| -rw-r--r-- | Documentation/devicetree/bindings/i2c/nomadik.txt | 23 | ||||
| -rw-r--r-- | drivers/i2c/busses/i2c-nomadik.c | 35 | ||||
| -rw-r--r-- | include/linux/platform_data/i2c-nomadik.h | 2 |
3 files changed, 56 insertions, 4 deletions
diff --git a/Documentation/devicetree/bindings/i2c/nomadik.txt b/Documentation/devicetree/bindings/i2c/nomadik.txt new file mode 100644 index 000000000000..72065b0ff680 --- /dev/null +++ b/Documentation/devicetree/bindings/i2c/nomadik.txt | |||
| @@ -0,0 +1,23 @@ | |||
| 1 | I2C for Nomadik based systems | ||
| 2 | |||
| 3 | Required (non-standard) properties: | ||
| 4 | - Nil | ||
| 5 | |||
| 6 | Recommended (non-standard) properties: | ||
| 7 | - clock-frequency : Maximum bus clock frequency for the device | ||
| 8 | |||
| 9 | Optional (non-standard) properties: | ||
| 10 | - Nil | ||
| 11 | |||
| 12 | Example : | ||
| 13 | |||
| 14 | i2c@80004000 { | ||
| 15 | compatible = "stericsson,db8500-i2c", "st,nomadik-i2c"; | ||
| 16 | reg = <0x80004000 0x1000>; | ||
| 17 | interrupts = <0 21 0x4>; | ||
| 18 | #address-cells = <1>; | ||
| 19 | #size-cells = <0>; | ||
| 20 | v-i2c-supply = <&db8500_vape_reg>; | ||
| 21 | |||
| 22 | clock-frequency = <400000>; | ||
| 23 | }; | ||
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 | ||
| 918 | static 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 | |||
| 916 | static atomic_t adapter_id = ATOMIC_INIT(0); | 930 | static atomic_t adapter_id = ATOMIC_INIT(0); |
| 917 | 931 | ||
| 918 | static int nmk_i2c_probe(struct amba_device *adev, const struct amba_id *id) | 932 | static 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; |
diff --git a/include/linux/platform_data/i2c-nomadik.h b/include/linux/platform_data/i2c-nomadik.h index c2303c3e4803..3a8be9cdc95c 100644 --- a/include/linux/platform_data/i2c-nomadik.h +++ b/include/linux/platform_data/i2c-nomadik.h | |||
| @@ -28,7 +28,7 @@ enum i2c_freq_mode { | |||
| 28 | * @sm: speed mode | 28 | * @sm: speed mode |
| 29 | */ | 29 | */ |
| 30 | struct nmk_i2c_controller { | 30 | struct nmk_i2c_controller { |
| 31 | unsigned long clk_freq; | 31 | u32 clk_freq; |
| 32 | unsigned short slsu; | 32 | unsigned short slsu; |
| 33 | unsigned char tft; | 33 | unsigned char tft; |
| 34 | unsigned char rft; | 34 | unsigned char rft; |
