i2c: QUP based bus driver for Qualcomm MSM chipsets
Subsystems (4)
PATCH v3 1/1 i2c: QUP based bus driver for Qualcomm MSM chipsets
This bus driver supports the QUP i2c hardware controller in the Qualcomm MSM SOCs. The Qualcomm Universal Peripheral Engine (QUP) is a general purpose data path engine with input/output FIFOs and an embedded i2c mini-core. The driver supports FIFO mode (for low bandwidth applications) and block mode (interrupt generated for each block-size data transfer). The driver currently does not support DMA transfers.
---
v3: uses DIV_ROUND_UP() as recommended by linus.walleij at stericsson.com
v2: incorporated feedback from the following people:
ben-linux at fluff.org
srinidhi.kasagar at stericsson.com
tsoni at codeaurora.org
The header file defines the platform data used by the QUP driver. This file can be picked up by the i2c maintainers but also needs to be Acked by the msm maintainers (linux-arm-msm).
--- arch/arm/mach-msm/include/mach/msm_qup_i2c.h | 28 + drivers/i2c/busses/Kconfig | 12 + drivers/i2c/busses/Makefile | 1 + drivers/i2c/busses/i2c-qup.c | 1085 ++++++++++++++++++++++++++ 4 files changed, 1126 insertions(+), 0 deletions(-) create mode 100644 arch/arm/mach-msm/include/mach/msm_qup_i2c.h create mode 100644 drivers/i2c/busses/i2c-qup.c
arch/arm/mach-msm/include/mach/msm_qup_i2c.h new file +28 -0
@@ -0,0 +1,28 @@ +/* +* Qualcomm MSM QUP i2c Controller Platform Data +* +* Copyright (c) 2010, Code Aurora Forum. All rights reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 and +* only version 2 as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +* 02110-1301, USA. +*/ +#ifndef __MSM_QUP_I2C_MSM_H +#define __MSM_QUP_I2C_MSM_H + +struct msm_i2c_platform_data { +int bus_freq;/* I2C bus frequency (Hz) */ +int src_clk_rate;/* I2C controller clock rate (Hz) */ +}; + +#endif /* __MSM_QUP_I2C_MSM_H */
drivers/i2c/busses/Kconfig +12 -0
@@ -521,6 +521,18 @@ config I2C_PXA_SLAVE is necessary for systems where the PXA may be a target on the I2C bus. +config I2C_QUP + tristate "Qualcomm MSM QUP I2C Controller" + depends on (ARCH_MSM7X30 || ARCH_MSM8X60 || \ + (ARCH_QSD8X50 && MSM_SOC_REV_A)) + help + If you say yes to this option, support will be included for the + built-in QUP I2C interface on Qualcomm MSM family processors. + + The Qualcomm Universal Peripheral Engine (QUP) is a general + purpose data path engine with input/output FIFOs and an + embedded I2C mini-core. + config I2C_S3C2410 tristate "S3C2410 I2C Driver" depends on ARCH_S3C2410 || ARCH_S3C64XX
drivers/i2c/busses/Makefile +1 -0
@@ -50,6 +50,7 @@ obj-$(CONFIG_I2C_PCA_PLATFORM) += i2c-pca-platform.o obj-$(CONFIG_I2C_PMCMSP) += i2c-pmcmsp.o obj-$(CONFIG_I2C_PNX) += i2c-pnx.o obj-$(CONFIG_I2C_PXA) += i2c-pxa.o +obj-$(CONFIG_I2C_QUP) += i2c-qup.o obj-$(CONFIG_I2C_S3C2410) += i2c-s3c2410.o obj-$(CONFIG_I2C_S6000) += i2c-s6000.o obj-$(CONFIG_I2C_SH7760) += i2c-sh7760.o
drivers/i2c/busses/i2c-qup.c new file +1085 -0
1,085 lines not on this page · raw message
Signature · 4 lines
1.7.1.1 -- Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
Quoted 7 lines · Kenneth Heitke
This bus driver supports the QUP i2c hardware controller in the Qualcomm MSM SOCs. The Qualcomm Universal Peripheral Engine (QUP) is a general purpose data path engine with input/output FIFOs and an embedded i2c mini-core. The driver supports FIFO mode (for low bandwidth applications) and block mode (interrupt generated for each block-size data transfer). The driver currently does not support DMA transfers.
Quoted 7 lines
Signed-off-by Kenneth Heitke <[email protected]>---
v3: usesDIV_ROUND_UP()as recommended by linus.walleij at stericsson.com
v2: incorporated feedback from the following people:
ben-linux at fluff.org
srinidhi.kasagar at stericsson.com
tsoni at codeaurora.org
Looks good to me.
---Trilok Soni
Signature · 2 lines
Sent by a consultant of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
Hi Kenneth,
just some error codes and leaks if I am right :)
drivers/i2c/busses/i2c-qup.c
Quoted 10 lines · Kenneth Heitke
drivers/i2c/busses/i2c-qup.c new file +10
-0+ +static int __devinit +qup_i2c_probe (struct platform_device *pdev) +{ + + ? ? ? qup_mem = platform_get_resource_byname(pdev, IORESOURCE_MEM, + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? "qup_phys_addr"); + ? ? ? if (!qup_mem) { + ? ? ? ? ? ? ? dev_err(&pdev->dev, "no qup mem resource?\n"); + ? ? ? ? ? ? ? return -ENODEV;
I think this should be -ENXIO instead of -ENODEV?
Quoted 5 lines
+ ? ? ?
gsbi_mem= platform_get_resource_byname(pdev,IORESOURCE_MEM,
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? "gsbi_qup_i2c_addr");
+ ? ? ? if (!gsbi_mem) {
+ ? ? ? ? ? ? ?dev_err(&pdev->dev, "no gsbi mem resource?\n");
+ ? ? ? ? ? ? ? return-ENODEV;
Ditto here.
Review
Quoted 12 lines
+ ? ? ?
in_irq= platform_get_resource_byname(pdev,IORESOURCE_IRQ,
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? "qup_in_intr");(quoted diff) +10
-0+ + ? ? ? out_irq = platform_get_resource_byname(pdev, IORESOURCE_IRQ, + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? "qup_out_intr"); + + ? ? ? err_irq = platform_get_resource_byname(pdev, IORESOURCE_IRQ, + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? "qup_err_intr"); + ? ? ? if (!err_irq) { + ? ? ? ? ? ? ? dev_err(&pdev->dev, "no error irq resource?\n"); + ? ? ? ? ? ? ? return -ENODEV; + ? ? ? }
All the same here too?
Quoted 16 lines
(quoted diff) +16
-0+ + ? ? ? qup_io = devm_request_mem_region(&pdev->dev, qup_mem->start, + ? ? ? ? ? ? ? ? ? ? ? resource_size(qup_mem), pdev->name); + ? ? ? if (!qup_io) { + ? ? ? ? ? ? ? dev_err(&pdev->dev, "QUP region already claimed\n"); + ? ? ? ? ? ? ? return -EBUSY; + ? ? ? } + + ? ? ? gsbi_io = devm_request_mem_region(&pdev->dev, gsbi_mem->start, + ? ? ? ? ? ? ? ? ? ? ? resource_size(gsbi_mem), pdev->name); + ? ? ? if (!gsbi_io) { + ? ? ? ? ? ? ? dev_err(&pdev->dev, "GSBI region already claimed\n"); + ? ? ? ? ? ? ? return -EBUSY; + ? ? ? } + + ? ? ? dev = devm_kzalloc(&pdev->dev, sizeof(struct qup_i2c_dev), GFP_KERNEL);
[..]
Quoted 2 lines
+ ? ? ? if (!dev->base)
+ ? ? ? ? ? ? ? return-ENOMEM;
Missing *_kzfree whilst returning?
Quoted 10 lines
+ ? ? ?
dev->gsbi= devm_ioremap(&pdev->dev,
+ ? ? ? ? ? ? ? ? ? ? ?gsbi_mem->start,resource_size(gsbi_mem));
+ ? ? ? if (!dev->gsbi)
+ ? ? ? ? ? ? ? return-ENOMEM;
+
+ ? ? ? clk =clk_get(&pdev->dev, "qup_clk");
+ ? ? ? if (IS_ERR(clk)) {
+ ? ? ? ? ? ? ?dev_err(&pdev->dev, "Could not get clock\n");
+ ? ? ? ? ? ? ? ret =PTR_ERR(clk);
+ ? ? ? ? ? ? ? gotoerr_clk_get_failed;
Will not the devm_iounmap be needed here?
Thanx!
Sundar
Quoted 76 lines · Sundar
Hi Kenneth,
just some error codes and leaks if I am right :)
drivers/i2c/busses/i2c-qup.c line 839
Quoted 10 lines · Kenneth Heitke
drivers/i2c/busses/i2c-qup.c new file +10
-0+ +static int __devinit +qup_i2c_probe (struct platform_device *pdev) +{ + + qup_mem =platform_get_resource_byname (pdev,IORESOURCE_MEM , +"qup_phys_addr" ); +if (!qup_mem) { +dev_err (&pdev->dev,"no qup mem resource?\n" ); +return -ENODEV ;I think this should be
-ENXIOinstead of-ENODEV?drivers/i2c/busses/i2c-qup.c line 846
Quoted 5 lines
drivers/i2c/busses/i2c-qup.c new file +5
-0+ gsbi_mem =platform_get_resource_byname (pdev,IORESOURCE_MEM , +"gsbi_qup_i2c_addr" ); +if (!gsbi_mem) { +dev_err (&pdev->dev,"no gsbi mem resource?\n" ); +return -ENODEV ;Ditto here.
drivers/i2c/busses/i2c-qup.c line 864
Quoted 12 lines
drivers/i2c/busses/i2c-qup.c new file +12
-0+ in_irq =platform_get_resource_byname (pdev,IORESOURCE_IRQ , +"qup_in_intr" ); + + out_irq =platform_get_resource_byname (pdev,IORESOURCE_IRQ , +"qup_out_intr" ); + + err_irq =platform_get_resource_byname (pdev,IORESOURCE_IRQ , +"qup_err_intr" ); +if (!err_irq) { +dev_err (&pdev->dev,"no error irq resource?\n" ); +return -ENODEV ; + }All the same here too?
Quoted 16 lines
drivers/i2c/busses/i2c-qup.c new file +16
-0+ + qup_io =devm_request_mem_region (&pdev->dev, qup_mem->start, +resource_size (qup_mem), pdev->name); +if (!qup_io) { +dev_err (&pdev->dev,"QUP region already claimed\n" ); +return -EBUSY ; + } + + gsbi_io =devm_request_mem_region (&pdev->dev, gsbi_mem->start, +resource_size (gsbi_mem), pdev->name); +if (!gsbi_io) { +dev_err (&pdev->dev,"GSBI region already claimed\n" ); +return -EBUSY ; + } + + dev =devm_kzalloc (&pdev->dev,sizeof (struct qup_i2c_dev ),GFP_KERNEL );[..]
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (!dev->base) + return -ENOMEM;Missing
*_kzfreewhilst returning?drivers/i2c/busses/i2c-qup.c line 899
Quoted 10 lines
drivers/i2c/busses/i2c-qup.c new file +10
-0+ dev->gsbi =devm_ioremap (&pdev->dev, + gsbi_mem->start,resource_size (gsbi_mem)); +if (!dev->gsbi) +return -ENOMEM ; + + clk =clk_get (&pdev->dev,"qup_clk" ); +if (IS_ERR (clk)) { +dev_err (&pdev->dev,"Could not get clock\n" ); + ret =PTR_ERR (clk); + goto err_clk_get_failed;
Quoted 5 lines
Will not the
devm_iounmapbe needed here?Thanx!
Sundar
Hopefully no leaks since I am using the devm_ calls. The resources should be freed up automatically on device release and if the probe function fails. Please let me know if this assumption is not correct.
Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
Quoted 5 lines · Sundar
Hi Kenneth,
just some error codes and leaks if I am right :)
On Wed, Sep 8, 2010 at 6:29 AM, Kenneth Heitke <[email protected]> wrote:
Quoted 12 lines
drivers/i2c/busses/i2c-qup.c line 839
Quoted 10 lines
drivers/i2c/busses/i2c-qup.c new file +10
-0+ +static int __devinit +qup_i2c_probe (struct platform_device *pdev) +{ + + qup_mem =platform_get_resource_byname (pdev,IORESOURCE_MEM , +"qup_phys_addr" ); +if (!qup_mem) { +dev_err (&pdev->dev,"no qup mem resource?\n" ); +return -ENODEV ;I think this should be
-ENXIOinstead of-ENODEV?
I think both are inappropriate here, -ENXIO is an IO failure and -ENODEV is 'device is not here'. However, some people don't like the use of things like -ENOENT (filesystem errors) for this sort of situation. ENOTSUP might be something you could use.
As a note, both ENXIO and ENODEV will be taken by the device framework as a device is not there at-all and not display any error to the user (which is annoying if you then forget to do anything about it)
As a note, you may want to have a look at devres to offload the tracking of the requested and mapped resources.