i2c: busses: i2c-bcm2835: limits cdiv to allowed values
authorSilvan Wicki <linux_wi@tinag.ch>
Thu, 18 Jun 2015 09:10:11 +0000 (11:10 +0200)
committerWolfram Sang <wsa@the-dreams.de>
Tue, 23 Jun 2015 17:55:19 +0000 (19:55 +0200)
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>
drivers/i2c/busses/i2c-bcm2835.c

index aa06da17e30e7b6b0e95c60fbc31ca76365f2510..3032b89ac60b5212c0e918abdf1d68c6381ff002 100644 (file)
@@ -52,6 +52,9 @@
 
 #define BCM2835_I2C_BITMSK_S   0x03FF
 
+#define BCM2835_I2C_CDIV_MIN   0x0002
+#define BCM2835_I2C_CDIV_MAX   0xFFFE
+
 #define BCM2835_I2C_TIMEOUT (msecs_to_jiffies(1000))
 
 struct bcm2835_i2c_dev {
@@ -261,6 +264,11 @@ static int bcm2835_i2c_probe(struct platform_device *pdev)
         */
        if (divider & 1)
                divider++;
+       if ((divider < BCM2835_I2C_CDIV_MIN) ||
+           (divider > BCM2835_I2C_CDIV_MAX)) {
+               dev_err(&pdev->dev, "Invalid clock-frequency\n");
+               return -ENODEV;
+       }
        bcm2835_i2c_writel(i2c_dev, BCM2835_I2C_DIV, divider);
 
        irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);