diff options
author | Ganesan Ramalingam <ganesanr@broadcom.com> | 2012-07-13 09:44:23 -0400 |
---|---|---|
committer | Wolfram Sang <w.sang@pengutronix.de> | 2012-07-14 07:30:24 -0400 |
commit | 8bb986a816148d6e8fbaae23be0fee33d6a1ae3f (patch) | |
tree | 1b1bee995a60cc6be9d87ce9bbe711b26746cedf | |
parent | 9ae97a8996a6d6f66e2fbc221906e2406d6c261f (diff) |
i2c: i2c-ocores: Use reg-shift property
Deprecate 'regstep' property and use the standard 'reg-shift' property
for register offset shifts. 'regstep' will still be supported as an
optional property, but will give a warning when used.
Signed-off-by: Ganesan Ramalingam <ganesanr@broadcom.com>
Signed-off-by: Jayachandran C <jayachandranc@netlogicmicro.com>
Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
-rw-r--r-- | Documentation/devicetree/bindings/i2c/i2c-ocores.txt | 8 | ||||
-rw-r--r-- | drivers/i2c/busses/i2c-ocores.c | 36 | ||||
-rw-r--r-- | include/linux/i2c-ocores.h | 2 |
3 files changed, 29 insertions, 17 deletions
diff --git a/Documentation/devicetree/bindings/i2c/i2c-ocores.txt b/Documentation/devicetree/bindings/i2c/i2c-ocores.txt index bfec8941509c..1c9334bfc39c 100644 --- a/Documentation/devicetree/bindings/i2c/i2c-ocores.txt +++ b/Documentation/devicetree/bindings/i2c/i2c-ocores.txt | |||
@@ -4,11 +4,14 @@ Required properties: | |||
4 | - compatible : "opencores,i2c-ocores" | 4 | - compatible : "opencores,i2c-ocores" |
5 | - reg : bus address start and address range size of device | 5 | - reg : bus address start and address range size of device |
6 | - interrupts : interrupt number | 6 | - interrupts : interrupt number |
7 | - regstep : size of device registers in bytes | ||
8 | - clock-frequency : frequency of bus clock in Hz | 7 | - clock-frequency : frequency of bus clock in Hz |
9 | - #address-cells : should be <1> | 8 | - #address-cells : should be <1> |
10 | - #size-cells : should be <0> | 9 | - #size-cells : should be <0> |
11 | 10 | ||
11 | Optional properties: | ||
12 | - reg-shift : device register offsets are shifted by this value | ||
13 | - regstep : deprecated, use reg-shift above | ||
14 | |||
12 | Example: | 15 | Example: |
13 | 16 | ||
14 | i2c0: ocores@a0000000 { | 17 | i2c0: ocores@a0000000 { |
@@ -17,9 +20,10 @@ Example: | |||
17 | compatible = "opencores,i2c-ocores"; | 20 | compatible = "opencores,i2c-ocores"; |
18 | reg = <0xa0000000 0x8>; | 21 | reg = <0xa0000000 0x8>; |
19 | interrupts = <10>; | 22 | interrupts = <10>; |
20 | regstep = <1>; | ||
21 | clock-frequency = <20000000>; | 23 | clock-frequency = <20000000>; |
22 | 24 | ||
25 | reg-shift = <0>; /* 8 bit registers */ | ||
26 | |||
23 | dummy@60 { | 27 | dummy@60 { |
24 | compatible = "dummy"; | 28 | compatible = "dummy"; |
25 | reg = <0x60>; | 29 | reg = <0x60>; |
diff --git a/drivers/i2c/busses/i2c-ocores.c b/drivers/i2c/busses/i2c-ocores.c index f6e7ad9f60e9..9e0709d5fb36 100644 --- a/drivers/i2c/busses/i2c-ocores.c +++ b/drivers/i2c/busses/i2c-ocores.c | |||
@@ -25,10 +25,11 @@ | |||
25 | #include <linux/slab.h> | 25 | #include <linux/slab.h> |
26 | #include <linux/io.h> | 26 | #include <linux/io.h> |
27 | #include <linux/of_i2c.h> | 27 | #include <linux/of_i2c.h> |
28 | #include <linux/log2.h> | ||
28 | 29 | ||
29 | struct ocores_i2c { | 30 | struct ocores_i2c { |
30 | void __iomem *base; | 31 | void __iomem *base; |
31 | int regstep; | 32 | u32 reg_shift; |
32 | wait_queue_head_t wait; | 33 | wait_queue_head_t wait; |
33 | struct i2c_adapter adap; | 34 | struct i2c_adapter adap; |
34 | struct i2c_msg *msg; | 35 | struct i2c_msg *msg; |
@@ -71,12 +72,12 @@ struct ocores_i2c { | |||
71 | 72 | ||
72 | static inline void oc_setreg(struct ocores_i2c *i2c, int reg, u8 value) | 73 | static inline void oc_setreg(struct ocores_i2c *i2c, int reg, u8 value) |
73 | { | 74 | { |
74 | iowrite8(value, i2c->base + reg * i2c->regstep); | 75 | iowrite8(value, i2c->base + (reg << i2c->reg_shift)); |
75 | } | 76 | } |
76 | 77 | ||
77 | static inline u8 oc_getreg(struct ocores_i2c *i2c, int reg) | 78 | static inline u8 oc_getreg(struct ocores_i2c *i2c, int reg) |
78 | { | 79 | { |
79 | return ioread8(i2c->base + reg * i2c->regstep); | 80 | return ioread8(i2c->base + (reg << i2c->reg_shift)); |
80 | } | 81 | } |
81 | 82 | ||
82 | static void ocores_process(struct ocores_i2c *i2c) | 83 | static void ocores_process(struct ocores_i2c *i2c) |
@@ -219,22 +220,29 @@ static struct i2c_adapter ocores_adapter = { | |||
219 | static int ocores_i2c_of_probe(struct platform_device *pdev, | 220 | static int ocores_i2c_of_probe(struct platform_device *pdev, |
220 | struct ocores_i2c *i2c) | 221 | struct ocores_i2c *i2c) |
221 | { | 222 | { |
222 | const __be32* val; | 223 | struct device_node *np = pdev->dev.of_node; |
223 | 224 | u32 val; | |
224 | val = of_get_property(pdev->dev.of_node, "regstep", NULL); | 225 | |
225 | if (!val) { | 226 | if (of_property_read_u32(np, "reg-shift", &i2c->reg_shift)) { |
226 | dev_err(&pdev->dev, "Missing required parameter 'regstep'\n"); | 227 | /* no 'reg-shift', check for deprecated 'regstep' */ |
227 | return -ENODEV; | 228 | if (!of_property_read_u32(np, "regstep", &val)) { |
229 | if (!is_power_of_2(val)) { | ||
230 | dev_err(&pdev->dev, "invalid regstep %d\n", | ||
231 | val); | ||
232 | return -EINVAL; | ||
233 | } | ||
234 | i2c->reg_shift = ilog2(val); | ||
235 | dev_warn(&pdev->dev, | ||
236 | "regstep property deprecated, use reg-shift\n"); | ||
237 | } | ||
228 | } | 238 | } |
229 | i2c->regstep = be32_to_cpup(val); | ||
230 | 239 | ||
231 | val = of_get_property(pdev->dev.of_node, "clock-frequency", NULL); | 240 | if (of_property_read_u32(np, "clock-frequency", &val)) { |
232 | if (!val) { | ||
233 | dev_err(&pdev->dev, | 241 | dev_err(&pdev->dev, |
234 | "Missing required parameter 'clock-frequency'\n"); | 242 | "Missing required parameter 'clock-frequency'\n"); |
235 | return -ENODEV; | 243 | return -ENODEV; |
236 | } | 244 | } |
237 | i2c->clock_khz = be32_to_cpup(val) / 1000; | 245 | i2c->clock_khz = val / 1000; |
238 | 246 | ||
239 | return 0; | 247 | return 0; |
240 | } | 248 | } |
@@ -277,7 +285,7 @@ static int __devinit ocores_i2c_probe(struct platform_device *pdev) | |||
277 | 285 | ||
278 | pdata = pdev->dev.platform_data; | 286 | pdata = pdev->dev.platform_data; |
279 | if (pdata) { | 287 | if (pdata) { |
280 | i2c->regstep = pdata->regstep; | 288 | i2c->reg_shift = pdata->reg_shift; |
281 | i2c->clock_khz = pdata->clock_khz; | 289 | i2c->clock_khz = pdata->clock_khz; |
282 | } else { | 290 | } else { |
283 | ret = ocores_i2c_of_probe(pdev, i2c); | 291 | ret = ocores_i2c_of_probe(pdev, i2c); |
diff --git a/include/linux/i2c-ocores.h b/include/linux/i2c-ocores.h index 4d5e57ff6614..5d95df2436f4 100644 --- a/include/linux/i2c-ocores.h +++ b/include/linux/i2c-ocores.h | |||
@@ -12,7 +12,7 @@ | |||
12 | #define _LINUX_I2C_OCORES_H | 12 | #define _LINUX_I2C_OCORES_H |
13 | 13 | ||
14 | struct ocores_i2c_platform_data { | 14 | struct ocores_i2c_platform_data { |
15 | u32 regstep; /* distance between registers */ | 15 | u32 reg_shift; /* register offset shift value */ |
16 | u32 clock_khz; /* input clock in kHz */ | 16 | u32 clock_khz; /* input clock in kHz */ |
17 | u8 num_devices; /* number of devices in the devices list */ | 17 | u8 num_devices; /* number of devices in the devices list */ |
18 | struct i2c_board_info const *devices; /* devices connected to the bus */ | 18 | struct i2c_board_info const *devices; /* devices connected to the bus */ |