diff mbox

[U-Boot,1/2] dm: imx: i2c: Use gpio_request() to request GPIOs

Message ID 1412259444-11959-2-git-send-email-nikita@compulab.co.il
State Awaiting Upstream
Delegated to: Simon Glass
Headers show

Commit Message

Nikita Kiryanov Oct. 2, 2014, 2:17 p.m. UTC
From: Simon Glass <sjg@chromium.org>

GPIOs should be requested before use. Without this, driver model will
not permit the GPIO to be used.

Cc: Igor Grinberg <grinberg@compulab.co.il>
Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>
---
 arch/arm/imx-common/i2c-mxv7.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

Comments

Igor Grinberg Oct. 3, 2014, 6:39 a.m. UTC | #1
On 10/02/14 17:17, Nikita Kiryanov wrote:
> From: Simon Glass <sjg@chromium.org>
> 
> GPIOs should be requested before use. Without this, driver model will
> not permit the GPIO to be used.
> 
> Cc: Igor Grinberg <grinberg@compulab.co.il>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>

I like the "small functionality oriented changes" much more.

Acked-by: Igor Grinberg <grinberg@compulab.co.il>
Simon Glass Oct. 14, 2014, 7:25 a.m. UTC | #2
Hi Stefan,

On 3 October 2014 08:39, Igor Grinberg <grinberg@compulab.co.il> wrote:
>
> On 10/02/14 17:17, Nikita Kiryanov wrote:
> > From: Simon Glass <sjg@chromium.org>
> >
> > GPIOs should be requested before use. Without this, driver model will
> > not permit the GPIO to be used.
> >
> > Cc: Igor Grinberg <grinberg@compulab.co.il>
> > Signed-off-by: Simon Glass <sjg@chromium.org>
> > Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>
>
> I like the "small functionality oriented changes" much more.
>
> Acked-by: Igor Grinberg <grinberg@compulab.co.il>

I plan to pull these two patches from Nikita into u-boot-dm along with
my other IMX and DM patches. It needs to come after SPI and there are
about 8 series in the line. Is that OK with you?

Regards,
Simon
Igor Grinberg Oct. 21, 2014, 9:51 a.m. UTC | #3
Hi Simon,

I'm sorry for that late reply, I've had email problems during the
conference...
Finally, I have the email working again and going through the stuff...
I guess, it is better late than never..

On 10/14/14 10:25, Simon Glass wrote:
> Hi Stefan,
> 
> On 3 October 2014 08:39, Igor Grinberg <grinberg@compulab.co.il> wrote:
>>
>> On 10/02/14 17:17, Nikita Kiryanov wrote:
>>> From: Simon Glass <sjg@chromium.org>
>>>
>>> GPIOs should be requested before use. Without this, driver model will
>>> not permit the GPIO to be used.
>>>
>>> Cc: Igor Grinberg <grinberg@compulab.co.il>
>>> Signed-off-by: Simon Glass <sjg@chromium.org>
>>> Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>
>>
>> I like the "small functionality oriented changes" much more.
>>
>> Acked-by: Igor Grinberg <grinberg@compulab.co.il>
> 
> I plan to pull these two patches from Nikita into u-boot-dm along with
> my other IMX and DM patches. It needs to come after SPI and there are
> about 8 series in the line. Is that OK with you?

Yep, this is fine. Thanks!
Simon Glass Oct. 23, 2014, 3:06 a.m. UTC | #4
On 21 October 2014 03:51, Igor Grinberg <grinberg@compulab.co.il> wrote:
> Hi Simon,
>
> I'm sorry for that late reply, I've had email problems during the
> conference...
> Finally, I have the email working again and going through the stuff...
> I guess, it is better late than never..
>
> On 10/14/14 10:25, Simon Glass wrote:
>> Hi Stefan,
>>
>> On 3 October 2014 08:39, Igor Grinberg <grinberg@compulab.co.il> wrote:
>>>
>>> On 10/02/14 17:17, Nikita Kiryanov wrote:
>>>> From: Simon Glass <sjg@chromium.org>
>>>>
>>>> GPIOs should be requested before use. Without this, driver model will
>>>> not permit the GPIO to be used.
>>>>
>>>> Cc: Igor Grinberg <grinberg@compulab.co.il>
>>>> Signed-off-by: Simon Glass <sjg@chromium.org>
>>>> Signed-off-by: Nikita Kiryanov <nikita@compulab.co.il>
>>>
>>> I like the "small functionality oriented changes" much more.
>>>
>>> Acked-by: Igor Grinberg <grinberg@compulab.co.il>
>>
>> I plan to pull these two patches from Nikita into u-boot-dm along with
>> my other IMX and DM patches. It needs to come after SPI and there are
>> about 8 series in the line. Is that OK with you?
>
> Yep, this is fine. Thanks!

Applied to u-boot-dm/master, thanks!
diff mbox

Patch

diff --git a/arch/arm/imx-common/i2c-mxv7.c b/arch/arm/imx-common/i2c-mxv7.c
index 70cff5c..34f5387 100644
--- a/arch/arm/imx-common/i2c-mxv7.c
+++ b/arch/arm/imx-common/i2c-mxv7.c
@@ -4,6 +4,7 @@ 
  * SPDX-License-Identifier:	GPL-2.0+
  */
 #include <common.h>
+#include <malloc.h>
 #include <asm/arch/clock.h>
 #include <asm/arch/imx-regs.h>
 #include <asm/errno.h>
@@ -72,10 +73,27 @@  static void * const i2c_bases[] = {
 int setup_i2c(unsigned i2c_index, int speed, int slave_addr,
 	      struct i2c_pads_info *p)
 {
+	char *name1, *name2;
 	int ret;
 
 	if (i2c_index >= ARRAY_SIZE(i2c_bases))
 		return -EINVAL;
+
+	name1 = malloc(9);
+	name2 = malloc(9);
+	if (!name1 || !name2)
+		return -ENOMEM;
+
+	sprintf(name1, "i2c_sda%d", i2c_index);
+	sprintf(name2, "i2c_scl%d", i2c_index);
+	ret = gpio_request(p->sda.gp, name1);
+	if (ret)
+		goto err_req1;
+
+	ret = gpio_request(p->scl.gp, name2);
+	if (ret)
+		goto err_req2;
+
 	/* Enable i2c clock */
 	ret = enable_i2c_clk(1, i2c_index);
 	if (ret)
@@ -93,5 +111,12 @@  int setup_i2c(unsigned i2c_index, int speed, int slave_addr,
 
 err_idle:
 err_clk:
+	gpio_free(p->scl.gp);
+err_req2:
+	gpio_free(p->sda.gp);
+err_req1:
+	free(name1);
+	free(name2);
+
 	return ret;
 }