i2c: add bcm2835 driver
Subsystems (4)
PATCH 1/1 i2c: add bcm2835 driver
This implements a very basic I2C host driver for the BCM2835 SoC. Missing features so far are:
* Clock rate adjustment.
* 10-bit addressing.
* DMA.
--- .../devicetree/bindings/i2c/brcm,bcm2835-i2c.txt | 20 ++ drivers/i2c/busses/Kconfig | 12 + drivers/i2c/busses/Makefile | 1 + drivers/i2c/busses/i2c-bcm2835.c | 331 ++++++++++++++++++++ 4 files changed, 364 insertions(+) create mode 100644 Documentation/devicetree/bindings/i2c/brcm,bcm2835-i2c.txt create mode 100644 drivers/i2c/busses/i2c-bcm2835.c
Documentation/devicetree/bindings/i2c/brcm,bcm2835-i2c.txt new file +20 -0
@@ -0,0 +1,20 @@ +Broadcom BCM2835 I2C controller + +Required properties: +- compatible : Should be "brcm,bcm2835-i2c". +- reg: Should contain register location and length. +- interrupts: Should contain interrupt. +- clocks : The clock feeding the I2C controller. + +Recommended properties: +- clock-frequency : desired I2C bus clock frequency in Hz. + +Example: + +i2c at 20205000 { + compatible = "brcm,bcm2835-i2c"; + reg = <0x7e205000 0x1000>; + interrupts = <2 21>; + clocks = <&clk_i2c>; + clock-frequency = <100000>; +};
drivers/i2c/busses/Kconfig +12 -0
@@ -319,6 +319,18 @@ config I2C_AU1550 This driver can also be built as a module. If so, the module will be called i2c-au1550. +config I2C_BCM2835 + tristate "Broadcom BCM2835 I2C controller" + depends on ARCH_BCM2835 + help + If you say yes to this option, support will be included for the + BCM2835 I2C controller. + + If you don't know what to do here, say N. + + This support is also available as a module. If so, the module + will be called i2c-bcm2835. + config I2C_BLACKFIN_TWI tristate "Blackfin TWI I2C support" depends on BLACKFIN
drivers/i2c/busses/Makefile +1 -0
@@ -30,6 +30,7 @@ obj-$(CONFIG_I2C_POWERMAC) += i2c-powermac.o # Embedded system I2C/SMBus host controller drivers obj-$(CONFIG_I2C_AT91) += i2c-at91.o obj-$(CONFIG_I2C_AU1550) += i2c-au1550.o +obj-$(CONFIG_I2C_BCM2835) += i2c-bcm2835.o obj-$(CONFIG_I2C_BLACKFIN_TWI) += i2c-bfin-twi.o obj-$(CONFIG_I2C_CBUS_GPIO) += i2c-cbus-gpio.o obj-$(CONFIG_I2C_CPM) += i2c-cpm.o
drivers/i2c/busses/i2c-bcm2835.c new file +331 -0
331 lines not on this page · raw message
Signature · 1 line
1.7.10.4
PATCH 1/1 i2c: add bcm2835 driver
Quoted 33 lines · Stephen Warren
This implements a very basic I2C host driver for the BCM2835 SoC. Missing features so far are:
* Clock rate adjustment.
* 10-bit addressing.
* DMA.Signed-off-by Stephen Warren <[email protected]>--- .../devicetree/bindings/i2c/brcm,bcm2835-i2c.txt | 20 ++ drivers/i2c/busses/Kconfig | 12 + drivers/i2c/busses/Makefile | 1 + drivers/i2c/busses/i2c-bcm2835.c | 331 ++++++++++++++++++++ 4 files changed, 364 insertions(+) create mode 100644 Documentation/devicetree/bindings/i2c/brcm,bcm2835-i2c.txt create mode 100644 drivers/i2c/busses/i2c-bcm2835.cDocumentation/devicetree/bindings/i2c/brcm,bcm2835-i2c.txt new file +10
-0@@ -0,0 +1,20 @@ +Broadcom BCM2835 I2C controller + +Required properties: +- compatible : Should be "brcm,bcm2835-i2c". +- reg: Should contain register location and length. +- interrupts: Should contain interrupt. +- clocks : The clock feeding the I2C controller. + +Recommended properties: +- clock-frequency : desired I2C bus clock frequency in Hz.
Documentation/devicetree/bindings/i2c/brcm,bcm2835-i2c.txt line 20
Quoted 10 lines
Documentation/devicetree/bindings/i2c/brcm,bcm2835-i2c.txt new file +10
-0+ +Example: + +i2c at 20205000 { + compatible = "brcm,bcm2835-i2c"; + reg = <0x7e205000 0x1000>; + interrupts = <2 21>; + clocks = <&clk_i2c>; + clock-frequency = <100000>; +};
Looks good.
Quoted 58 lines
Documentation/devicetree/bindings/i2c/brcm,bcm2835-i2c.txt new file +58
-0+static int __devinit bcm2835_i2c_probe(struct platform_device *pdev) +{ + struct bcm2835_i2c_dev *i2c_dev; + struct resource *mem, *requested, *irq; + int ret; + struct i2c_adapter *adap; + + i2c_dev = devm_kzalloc(&pdev->dev, sizeof(*i2c_dev), GFP_KERNEL); + if (!i2c_dev) { + dev_err(&pdev->dev, "Cannot allocate i2c_dev\n"); + return -ENOMEM; + } + platform_set_drvdata(pdev, i2c_dev); + i2c_dev->dev = &pdev->dev; + init_completion(&i2c_dev->completion); + + mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!mem) { + dev_err(&pdev->dev, "No mem resource\n"); + return -ENODEV; + } + + requested = devm_request_mem_region(&pdev->dev, mem->start, + resource_size(mem), + dev_name(&pdev->dev)); + if (!requested) { + dev_err(&pdev->dev, "Could not claim register region\n"); + return -EBUSY; + } + + i2c_dev->regs = devm_ioremap(&pdev->dev, mem->start, + resource_size(mem)); + if (!i2c_dev->regs) { + dev_err(&pdev->dev, "Could not map registers\n"); + return -ENOMEM; + } + + irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); + if (!irq) { + dev_err(&pdev->dev, "No IRQ resource\n"); + return -ENODEV; + } + + ret = devm_request_irq(&pdev->dev, irq->start, bcm2835_i2c_isr, + IRQF_SHARED, dev_name(&pdev->dev), i2c_dev); + if (ret) { + dev_err(&pdev->dev, "Could not request IRQ\n"); + return -ENODEV; + } + + adap = &i2c_dev->adapter; + i2c_set_adapdata(adap, i2c_dev); + adap->owner = THIS_MODULE; + adap->class = I2C_CLASS_HWMON; + strlcpy(adap->name, "bcm2835 I2C adapter", sizeof(adap->name)); + adap->algo = &bcm2835_i2c_algo; + adap->dev.parent = &pdev->dev; + adap->nr = -1;
Documentation/devicetree/bindings/i2c/brcm,bcm2835-i2c.txt
Quoted 10 lines
Documentation/devicetree/bindings/i2c/brcm,bcm2835-i2c.txt new file +10
-0+ + bcm2835_i2c_writel(i2c_dev, BCM2835_I2C_C, 0); + + ret = i2c_add_numbered_adapter(adap); + if (ret) { + dev_err(&pdev->dev, "Could not add adapter\n"); + return ret; + } + + return 0;
The driver core will print a message if things fail here. The above 6 lines can be replaced with simply:
return i2c_add_numbered_adapter(adap);
Quoted 28 lines
Documentation/devicetree/bindings/i2c/brcm,bcm2835-i2c.txt new file +28
-0+} + +static int bcm2835_i2c_remove(struct platform_device *pdev) +{ + struct bcm2835_i2c_dev *i2c_dev = platform_get_drvdata(pdev); + + i2c_del_adapter(&i2c_dev->adapter); + + return 0; +} + +static const struct of_device_id bcm2835_i2c_of_match[] = { + { .compatible = "brcm,bcm2835-i2c" }, + {}, +}; +MODULE_DEVICE_TABLE(of, bcm2835_i2c_of_match); + +static struct platform_driver bcm2835_i2c_driver = { + .probe = bcm2835_i2c_probe, + .remove = bcm2835_i2c_remove, + .driver = { + .name = "i2c-bcm2835", + .owner = THIS_MODULE, + .of_match_table = bcm2835_i2c_of_match, + }, +}; + +static int __init bcm2835_i2c_init_driver(void)
Documentation/devicetree/bindings/i2c/brcm,bcm2835-i2c.txt
Quoted 10 lines
Documentation/devicetree/bindings/i2c/brcm,bcm2835-i2c.txt new file +10
-0+{ + return platform_driver_register(&bcm2835_i2c_driver); +} +module_init(bcm2835_i2c_init_driver); + +static void __exit bcm2835_i2c_exit_driver(void) +{ + platform_driver_unregister(&bcm2835_i2c_driver); +} +module_exit(bcm2835_i2c_exit_driver);
Nit: module_platform_driver()
Otherwise looks pretty tight.
g.