Skip to contentSkip to conversation

i2c: busses: i2c-bcm2835: limits cdiv to allowed values

PATCH Applied Silvan Wicki 2 participants 2 messages Jun 18, 2015 – Jun 23, 2015 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 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

---
PATCH v5: instead of falling back to a supported clock speed, return an error.

 drivers/i2c/busses/i2c-bcm2835.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/i2c/busses/i2c-bcm2835.c +8 -0
index c9336a3..6411bfa 100644
@@ -50,6 +50,9 @@
 #define BCM2835_I2C_S_CLKT	BIT(9)
 #define BCM2835_I2C_S_LEN	BIT(10) /* Fake bit for SW error reporting */
 
+#define BCM2835_I2C_CDIV_MIN	0x0002
+#define BCM2835_I2C_CDIV_MAX	0xFFFE
+
 #define BCM2835_I2C_TIMEOUT (msecs_to_jiffies(1000))
 
 struct bcm2835_i2c_dev {
@@ -258,6 +261,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);
Signature · 1 line
2.1.4

A message that is not in the archive (sent off-list or not yet received): 1434618611-16062-1-git-send-email-linux_wi-ADq4ffItWIY@public.gmane.org

Applied
#2 lore raw
Quoted 7 lines · Silvan Wicki

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

Applied to for-next, thanks!

But I needed to rebase on top of your "i2c: bcm2835: clear reserved bits in S-Register" patch. A small patch series would have been a good choice here.