* [PATCH v5] i2c: busses: i2c-bcm2835: limits cdiv to allowed values
@ 2015-06-18 9:10 Silvan Wicki
[not found] ` <1434618611-16062-1-git-send-email-linux_wi-ADq4ffItWIY@public.gmane.org>
0 siblings, 1 reply; 2+ messages in thread
From: Silvan Wicki @ 2015-06-18 9:10 UTC (permalink / raw)
To: wsa-z923LK4zBo2bacvFa/9K2g
Cc: linux-rpi-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
linux-i2c-u79uwXL29TY76Z2rM5mHXA, linux_wi-ADq4ffItWIY
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-ADq4ffItWIY@public.gmane.org>
---
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(+)
diff --git a/drivers/i2c/busses/i2c-bcm2835.c b/drivers/i2c/busses/i2c-bcm2835.c
index c9336a3..6411bfa 100644
--- a/drivers/i2c/busses/i2c-bcm2835.c
+++ b/drivers/i2c/busses/i2c-bcm2835.c
@@ -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);
--
2.1.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v5] i2c: busses: i2c-bcm2835: limits cdiv to allowed values
[not found] ` <1434618611-16062-1-git-send-email-linux_wi-ADq4ffItWIY@public.gmane.org>
@ 2015-06-23 17:58 ` Wolfram Sang
0 siblings, 0 replies; 2+ messages in thread
From: Wolfram Sang @ 2015-06-23 17:58 UTC (permalink / raw)
To: Silvan Wicki
Cc: swarren-3lzwWm7+Weoh9ZMKESR00Q, linux-i2c-u79uwXL29TY76Z2rM5mHXA,
linux-rpi-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
[-- Attachment #1: Type: text/plain, Size: 623 bytes --]
On Thu, Jun 18, 2015 at 11:10:11AM +0200, Silvan Wicki wrote:
> 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-ADq4ffItWIY@public.gmane.org>
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.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-06-23 17:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-18 9:10 [PATCH v5] i2c: busses: i2c-bcm2835: limits cdiv to allowed values Silvan Wicki
[not found] ` <1434618611-16062-1-git-send-email-linux_wi-ADq4ffItWIY@public.gmane.org>
2015-06-23 17:58 ` Wolfram Sang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).