diff options
author | Silvan Wicki <linux_wi@tinag.ch> | 2015-06-18 05:10:11 -0400 |
---|---|---|
committer | Wolfram Sang <wsa@the-dreams.de> | 2015-06-23 13:55:19 -0400 |
commit | a294aba164389a3d2c40dfcf5f3989a3bbfe38a2 (patch) | |
tree | 079f75628fa91e1e19807aece7509912cb512b14 /drivers/i2c | |
parent | 365322fb32e82b20758e8a18e3aa94692ce2a3d1 (diff) |
i2c: busses: i2c-bcm2835: limits cdiv to allowed values
Checks if the cdiv value is in between min (0x2) and max (0xFFFE)
supported values by the bcm2835. If not, it returns -ENODEV.
See page 33/34 of BCM2835-ARM-Peripherals.pdf for the DIV register.
https://www.raspberrypi.org/wp-content/uploads/2012/02/BCM2835-ARM-Peripherals.pdf
Signed-off-by: Silvan Wicki <linux_wi@tinag.ch>
[wsa: resolved a merge conflict]
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
Diffstat (limited to 'drivers/i2c')
-rw-r--r-- | drivers/i2c/busses/i2c-bcm2835.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/drivers/i2c/busses/i2c-bcm2835.c b/drivers/i2c/busses/i2c-bcm2835.c index aa06da17e30e..3032b89ac60b 100644 --- a/drivers/i2c/busses/i2c-bcm2835.c +++ b/drivers/i2c/busses/i2c-bcm2835.c | |||
@@ -52,6 +52,9 @@ | |||
52 | 52 | ||
53 | #define BCM2835_I2C_BITMSK_S 0x03FF | 53 | #define BCM2835_I2C_BITMSK_S 0x03FF |
54 | 54 | ||
55 | #define BCM2835_I2C_CDIV_MIN 0x0002 | ||
56 | #define BCM2835_I2C_CDIV_MAX 0xFFFE | ||
57 | |||
55 | #define BCM2835_I2C_TIMEOUT (msecs_to_jiffies(1000)) | 58 | #define BCM2835_I2C_TIMEOUT (msecs_to_jiffies(1000)) |
56 | 59 | ||
57 | struct bcm2835_i2c_dev { | 60 | struct bcm2835_i2c_dev { |
@@ -261,6 +264,11 @@ static int bcm2835_i2c_probe(struct platform_device *pdev) | |||
261 | */ | 264 | */ |
262 | if (divider & 1) | 265 | if (divider & 1) |
263 | divider++; | 266 | divider++; |
267 | if ((divider < BCM2835_I2C_CDIV_MIN) || | ||
268 | (divider > BCM2835_I2C_CDIV_MAX)) { | ||
269 | dev_err(&pdev->dev, "Invalid clock-frequency\n"); | ||
270 | return -ENODEV; | ||
271 | } | ||
264 | bcm2835_i2c_writel(i2c_dev, BCM2835_I2C_DIV, divider); | 272 | bcm2835_i2c_writel(i2c_dev, BCM2835_I2C_DIV, divider); |
265 | 273 | ||
266 | irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); | 274 | irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |