I2C: add CSR SiRFprimaII on-chip I2C controllers driver
Subsystems (3)
PATCH v3 1/1 I2C: add CSR SiRFprimaII on-chip I2C controllers driver
From: Zhiwu Song <[email protected]>
SiRFprimaII is the latest generation application processor from CSR?s multi-function SoC product family.
The SoC support codes are in arch/arm/mach-prima2 from Linux mainline 3.0.
There are two I2C controllers on primaII, features include:
? Two I2C controller modules are on chip
? RISC I/O bus read write register
? Up to 16 bytes data buffer for issuing commands and writing data
at the same time
? Up to 16 commands, and receiving read data 16 bytes at a time ? Error INT report (ACK check)
? No-ACK bus protocols (SCCB bus protocols)
---
-v3:
add lost clk_enable/disable in suspend/resume function while reading/ writing i2c controller registers.
without this, suspend will hang.
arch/arm/mach-prima2/pm.c | 1 + arch/arm/mach-prima2/prima2.c | 1 + drivers/i2c/busses/Kconfig | 7 + drivers/i2c/busses/Makefile | 1 + drivers/i2c/busses/i2c-sirf.c | 438 +++++++++++++++++++++++++++++++++++++++++ drivers/i2c/busses/i2c-sirf.h | 61 ++++++ 6 files changed, 509 insertions(+), 0 deletions(-) create mode 100644 drivers/i2c/busses/i2c-sirf.c create mode 100644 drivers/i2c/busses/i2c-sirf.h
arch/arm/mach-prima2/pm.c +1 -0
@@ -9,6 +9,7 @@#include <linux/kernel.h> #include <linux/suspend.h> #include <linux/slab.h> +#include <linux/module.h> #include <linux/of.h> #include <linux/of_address.h> #include <linux/of_device.h>
arch/arm/mach-prima2/prima2.c +1 -0
@@ -8,6 +8,7 @@#include <linux/init.h> #include <linux/kernel.h> +#include <asm/sizes.h> #include <asm/mach-types.h> #include <asm/mach/arch.h> #include <linux/of.h>
drivers/i2c/busses/Kconfig +7 -0
@@ -618,6 +618,13 @@ config I2C_SH_MOBILE This driver can also be built as a module. If so, the module will be called i2c-sh_mobile. +config I2C_SIRF + tristate "CSR SiRFprimaII I2C interface" + depends on ARCH_PRIMA2 + help + If you say yes to this option, support will be included for the + CSR SiRFprimaII I2C interface. + config I2C_SIMTEC tristate "Simtec Generic I2C interface" select I2C_ALGOBIT
drivers/i2c/busses/Makefile +1 -0
@@ -62,6 +62,7 @@ obj-$(CONFIG_I2C_S3C2410) += i2c-s3c2410.o obj-$(CONFIG_I2C_S6000) += i2c-s6000.o obj-$(CONFIG_I2C_SH7760) += i2c-sh7760.o obj-$(CONFIG_I2C_SH_MOBILE) += i2c-sh_mobile.o +obj-$(CONFIG_I2C_SIRF) += i2c-sirf.o obj-$(CONFIG_I2C_SIMTEC) += i2c-simtec.o obj-$(CONFIG_I2C_STU300) += i2c-stu300.o obj-$(CONFIG_I2C_TEGRA) += i2c-tegra.o
drivers/i2c/busses/i2c-sirf.c new file +438 -0
438 lines not on this page · raw message
drivers/i2c/busses/i2c-sirf.h new file +61 -0
61 lines not on this page · raw message
Signature · 1 line
1.7.0.4
A message that is not in the archive (sent off-list or not yet received): CAM=Q2ct4AKfYSHSu1KwYcW4YZ20QAJsOuHc9fg=oD5Rj7StB7g@mail.gmail.com
PATCH v3 1/1 I2C: add CSR SiRFprimaII on-chip I2C controllers driver
Hi Shubhrajyoti,
Thanks for reviewing
2011/11/18 Shubhrajyoti Datta <[email protected]>:
Quoted 27 lines
Hi Zhiwu,
Quoted 24 lines · Barry Song
From: Zhiwu Song <[email protected]>
SiRFprimaII is the latest generation application processor from CSR?s multi-function SoC product family.
The SoC support codes are inarch/arm/mach-prima2from Linux mainline 3.0.
There are two I2C controllers on primaII, features include:
? Two I2C controller modules are on chip
? RISC I/O bus read write register
? Up to 16 bytes data buffer for issuing commands and writing data ?at the same time
? Up to 16 commands, and receiving read data 16 bytes at a time ? Error INT report (ACK check)
? No-ACK bus protocols (SCCB bus protocols)Signed-off-by Zhiwu Song <[email protected]>Signed-off-by Xiangzhen Ye <[email protected]>Signed-off-by Barry Song <[email protected]>---
?-v3:
?add lost clk_enable/disable in suspend/resume function while reading/ ?writing i2c controller registers.
?without this, suspend will hang.
forgot this fix was done by Yuping Luo <[email protected]>. so he should get a Signed-off-by.
Quoted 26 lines
Quoted 25 lines
?arch/arm/mach-prima2/pm.c ? ? | ? ?1 + ?arch/arm/mach-prima2/prima2.c | ? ?1 + ?drivers/i2c/busses/Kconfig ? ?| ? ?7 + ?drivers/i2c/busses/Makefile ? | ? ?1 + ?drivers/i2c/busses/i2c-sirf.c | ?438+++++++++++++++++++++++++++++++++++++++++
?drivers/i2c/busses/i2c-sirf.h | ? 61 ++++++ ?6 files changed, 509 insertions(+), 0 deletions(-) ?create mode 100644drivers/i2c/busses/i2c-sirf.c?create mode 100644drivers/i2c/busses/i2c-sirf.harch/arm/mach-prima2/pm.c +0
-0@@ -9,6 +9,7 @@?#include <
linux/kernel.h>
?#include <linux/suspend.h>
?#include <linux/slab.h>
+#include <linux/module.h>
?#include <linux/of.h>
?#include <linux/of_address.h>
?#include <linux/of_device.h>arch/arm/mach-prima2/prima2.c +0
-0
Quoted 8 lines
Quoted 6 lines
+config
I2C_SIRF
+ ? ? ? tristate "CSR SiRFprimaII I2C interface"
+ ? ? ? depends onARCH_PRIMA2
+ ? ? ? help
+ ? ? ? ? If you say yes to this option, support will be included for the
+ ? ? ? ? CSR SiRFprimaII I2C interface.Since it is tristate the module ..
this is just a minor issue, if you like some changes, i can make it better.
Quoted 33 lines
Quoted 33 lines
+
?configI2C_SIMTEC
? ? ? ?tristate "Simtec Generic I2C interface"
? ? ? ?selectI2C_ALGOBITdrivers/i2c/busses/Makefile +0
-0@@ -62,6 +62,7 @@ obj-$(CONFIG_I2C_S3C2410) ? ? += i2c-s3c2410.o?obj-$(CONFIG_I2C_S6000) ? ? ? ? ? ? ? ?+= i2c-s6000.o ?obj-$(CONFIG_I2C_SH7760) ? ? ? += i2c-sh7760.o ?obj-$(CONFIG_I2C_SH_MOBILE) ? ?+= i2c-sh_mobile.o +obj-$(CONFIG_I2C_SIRF) ? ? ? ? += i2c-sirf.o ?obj-$(CONFIG_I2C_SIMTEC) ? ? ? += i2c-simtec.o ?obj-$(CONFIG_I2C_STU300) ? ? ? += i2c-stu300.o ?obj-$(CONFIG_I2C_TEGRA) ? ? ? ? ? ? ? ?+= i2c-tegra.o
drivers/i2c/busses/i2c-sirf.c new file +4
-0@@ -0,0 +1,438 @@ +/* +* I2C bus driver for CSR SiRFprimaII +* +* Copyright (c) 2011 Cambridge Silicon Radio Limited, a CSR plc group company.
+ *
+ * Licensed under GPLv2 or later.
+ */
+
Quoted 8 lines
drivers/i2c/busses/i2c-sirf.c line 14
Quoted 6 lines
drivers/i2c/busses/i2c-sirf.c new file +6
-0+#include <linux/interrupt.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/init.h> +#include <linux/sched.h> Are all these files needed?
-#include <linux/init.h>
-#include <linux/sched.h>
Quoted 71 lines
Quoted 71 lines
+ ? ? ? ? ? ? ?
dev_err(&pdev->dev, "Unable to get MEM resource\n");
+ ? ? ? ? ? ? ? err =-EINVAL;
+ ? ? ? ? ? ? ? goto out;
+ ? ? ? }
+
+ ? ? ?siic->base=
+ ? ? ? ? ? ? ?devm_ioremap(&pdev->dev, mem_res->start, (mem_res->end - mem_res->start + 1));
+ ? ? ? if (siic->base== NULL) {
+ ? ? ? ? ? ? ?dev_err(&pdev->dev, "IO remap failed!\n");
+ ? ? ? ? ? ? ? err =-ENOMEM;
+ ? ? ? ? ? ? ? goto out;
+ ? ? ? }drivers/i2c/busses/i2c-sirf.c new file +18
-0+ + ? ? ? siic->irq = platform_get_irq(pdev, 0); + ? ? ? if (!siic->irq) { + ? ? ? ? ? ? ? err = -EINVAL; + ? ? ? ? ? ? ? goto out; + ? ? ? } + ? ? ? err = devm_request_irq(&pdev->dev, siic->irq, i2c_sirfsoc_irq, 0, + ? ? ? ? ? ? ? dev_name(&pdev->dev), siic); + ? ? ? if (err) + ? ? ? ? ? ? ? goto out; + + ? ? ? new_adapter->algo = &i2c_sirfsoc_algo; + ? ? ? new_adapter->algo_data = siic; + + ? ? ? new_adapter->dev.parent = &pdev->dev; + ? ? ? new_adapter->nr = pdev->id; + + ? ? ? strlcpy(new_adapter->name, "sirfsoc-i2c",
sizeof(new_adapter->name));drivers/i2c/busses/i2c-sirf.c new file +39
-0+ + ? ? ? platform_set_drvdata(pdev, new_adapter); + ? ? ? init_completion(&siic->done); + + ? ? ? /* Controller Initalisation */ + + ? ? ? writel(SIRFSOC_I2C_RESET, siic->base + SIRFSOC_I2C_CTRL); + ? ? ? while (readl(siic->base + SIRFSOC_I2C_CTRL) & SIRFSOC_I2C_RESET) + ? ? ? ? ? ? ? cpu_relax(); + ? ? ? writel(SIRFSOC_I2C_CORE_EN | SIRFSOC_I2C_MASTER_MODE, + ? ? ? ? ? ? ? siic->base + SIRFSOC_I2C_CTRL); + + ? ? ? siic->clk = clk; + ? ? ? siic->speed = SIRFSOC_I2C_DEFAULT_SPEED; + ? ? ? if (siic->speed < 100000) + ? ? ? ? ? ? ? regval = + ? ? ? ? ? ? ? ? ? ? ? (2 * ctrl_speed) / (2 * siic->speed * 11); + ? ? ? else + ? ? ? ? ? ? ? regval = ctrl_speed / (siic->speed * 5); + + ? ? ? writel(regval, siic->base + SIRFSOC_I2C_CLK_CTRL); + ? ? ? if (regval > 0xFF) + ? ? ? ? ? ? ? writel(0xFF, siic->base + SIRFSOC_I2C_SDA_DELAY); + ? ? ? else + ? ? ? ? ? ? ? writel(regval, siic->base + SIRFSOC_I2C_SDA_DELAY); + + ? ? ? err = i2c_add_numbered_adapter(new_adapter); + ? ? ? if (err < 0) { + ? ? ? ? ? ? ? dev_err(&pdev->dev, "Can't add new i2c adapter\n"); + ? ? ? ? ? ? ? goto out; + ? ? ? } + + ? ? ? clk_disable(clk); + + ? ? ? dev_info(&pdev->dev, " I2C adapter ready to operate\n"); + + ? ? ? return 0; + +out:
Quoted 8 lines
drivers/i2c/busses/i2c-sirf.c line 356
Quoted 6 lines
+ ? ? ?
clk_disable(clk);drivers/i2c/busses/i2c-sirf.c new file +5
-0+err_clk_en: + ? ? ? clk_unprepare(clk); +err_clk_prep: + ? ? ? clk_put(clk); +err_get_clk:We are not freeing any allocated memories?
you might want to read Jamie's earlier feedback in v1. that is why we move to devm_alloc in v2.
Quoted 59 lines
Quoted 59 lines
+ ? ? ? return err;
drivers/i2c/busses/i2c-sirf.c new file +17
-0+} + +static int __devexit i2c_sirfsoc_remove(struct platform_device *pdev) +{ + ? ? ? struct i2c_adapter *adapter = platform_get_drvdata(pdev); + ? ? ? struct sirfsoc_i2c *siic = adapter->algo_data; + + ? ? ? writel(SIRFSOC_I2C_RESET, siic->base + SIRFSOC_I2C_CTRL); + ? ? ? i2c_del_adapter(adapter); + ? ? ? clk_disable(siic->clk); + ? ? ? clk_unprepare(siic->clk); + ? ? ? clk_put(siic->clk); + ? ? ? return 0; +} + +#ifdef CONFIG_PM +static int i2c_sirfsoc_suspend(struct platform_device *pdev, pm_message_tmsg)
drivers/i2c/busses/i2c-sirf.c new file +31
-0+{ + ? ? ? struct i2c_adapter *adapter = platform_get_drvdata(pdev); + ? ? ? struct sirfsoc_i2c *siic = adapter->algo_data; + + ? ? ? clk_enable(siic->clk); + ? ? ? siic->sda_delay = readl(siic->base + SIRFSOC_I2C_SDA_DELAY); + ? ? ? siic->clk_div = readl(siic->base + SIRFSOC_I2C_CLK_CTRL); + ? ? ? clk_disable(siic->clk); + ? ? ? return 0; +} + +static int i2c_sirfsoc_resume (struct platform_device *pdev) +{ + ? ? ? struct i2c_adapter *adapter = platform_get_drvdata(pdev); + ? ? ? struct sirfsoc_i2c *siic = adapter->algo_data; + + ? ? ? clk_enable(siic->clk); + ? ? ? writel(SIRFSOC_I2C_RESET, siic->base + SIRFSOC_I2C_CTRL); + ? ? ? writel(SIRFSOC_I2C_CORE_EN | SIRFSOC_I2C_MASTER_MODE, + ? ? ? ? ? ? ? siic->base + SIRFSOC_I2C_CTRL); + ? ? ? writel(siic->clk_div, siic->base + SIRFSOC_I2C_CLK_CTRL); + ? ? ? writel(siic->sda_delay, siic->base + SIRFSOC_I2C_SDA_DELAY); + ? ? ? clk_disable(siic->clk); + ? ? ? return 0; +} +#else +#define i2c_sirfsoc_suspend ? ?NULL +#define i2c_sirfsoc_resume ? ? NULL +#endif + +static const struct of_device_id sirfsoc_i2c_of_match[] __devinitconst ={
+ ? ? ? { .compatible = "sirf,prima2-i2c", },
+ ? ? ? {},drivers/i2c/busses/i2c-sirf.c new file +5
-0+}; +MODULE_DEVICE_TABLE (of, sirfsoc_i2c_of_match); + +static struct platform_driver i2c_sirfsoc_driver = { + ? ? ? .driver = {
Quoted 8 lines
Quoted 6 lines
+ ? ? ? ? ? ? ? .name = "
sirfsoc_i2c",
+ ? ? ? ? ? ? ? .owner =THIS_MODULE,
+ ? ? ? ? ? ? ? .of_match_table =sirfsoc_i2c_of_match,
+ ? ? ? },
+ ? ? ? .probe =i2c_sirfsoc_probe,
+ ? ? ? .remove =__devexit_p(i2c_sirfsoc_remove),Could we move to pm ops ?
i prefer to keep the current way as most people are doing.
-barry