From patchwork Tue Nov 7 20:18:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 835449 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="ic2VOdIa"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yWgmb6YFVz9s74 for ; Wed, 8 Nov 2017 07:21:03 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932901AbdKGUVC (ORCPT ); Tue, 7 Nov 2017 15:21:02 -0500 Received: from mail-lf0-f65.google.com ([209.85.215.65]:52682 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751687AbdKGUVB (ORCPT ); Tue, 7 Nov 2017 15:21:01 -0500 Received: by mail-lf0-f65.google.com with SMTP id b190so517375lfg.9 for ; Tue, 07 Nov 2017 12:21:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=s3FfMbgLLctBUKDJSi3UTbG6+74hq81xVrEFQBkIq9M=; b=ic2VOdIa3NJ7kyj6FvM7HPMaAhnSrx2RsEoHljSbOlo2OJR5LE9RsbqXUnCaF6BVpX mNHXFl0MhkxOgqldbLqV7/y5uWlx5+pkPJHKTN27vQFed7Sxmk9tVROBJO29JxxkFzQB /VFTeM9Vqomwg9ftsj6dgpBxSulXIMbMrWLGE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=s3FfMbgLLctBUKDJSi3UTbG6+74hq81xVrEFQBkIq9M=; b=Z0sMKAg9bRsFwRrMnXGogB96UhguT+aLDkFqWySeZLcmYPr9ukmPeVJQjK0kx1tUk3 VNvMUpSz7I59z7ywdkqucTQHUdIGhdWXm5rYe55gjQn1MfBhlsRGslMZJvHMEfuoqF/a dlXAPMX6MHKZIcMVhfzIJiFgaRq2xYhFuUlGTuCPWEPL2kVnbnBikRUozC9liKr5Oj4u sLPekzYEq5egaw3KIf8V+PLaVwVPwg3O51TRU51vvb+64EWmjZO+xNdvpXvzSdf/IS7q 0gn3ZYGsBUa6dxlbp0s57HMB88nZzVRHa1wmTObk0wTxcA3pF13nU9Z2IyV0aUI1aQ24 B2Qw== X-Gm-Message-State: AMCzsaWyE/Oydb87zGVaCwdK6b03qFJo46aQDB1gU7Gd5c3areYljjxO RnxqcuMj0QwitT4pj41KSIhBdw== X-Google-Smtp-Source: ABhQp+Tcmd64L3HwBrtnhcg172hsa5fzNHww/dmk6iktWZ1Dwk/YYwppNpqMqlqr7RVV9+e9pD2unQ== X-Received: by 10.46.46.12 with SMTP id u12mr8467723lju.65.1510086060269; Tue, 07 Nov 2017 12:21:00 -0800 (PST) Received: from localhost.localdomain (c-567171d5.014-348-6c756e10.cust.bredbandsbolaget.se. [213.113.113.86]) by smtp.gmail.com with ESMTPSA id k68sm420519lje.8.2017.11.07.12.20.58 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 07 Nov 2017 12:20:59 -0800 (PST) From: Linus Walleij To: Wolfram Sang , linux-i2c@vger.kernel.org Cc: Linus Walleij , Jochen Friedrich , linux-arm-kernel@lists.infradead.org, Russell King , Arnd Bergmann Subject: [PATCH v2] ARM: sa1100: simpad: Correct I2C GPIO offsets Date: Tue, 7 Nov 2017 21:18:57 +0100 Message-Id: <20171107201857.5752-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.13.6 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Arnd reported the following build bug bug: In file included from arch/arm/mach-sa1100/simpad.c:20:0: arch/arm/mach-sa1100/include/mach/SA-1100.h:1118:18: error: large integer implicitly truncated to unsigned type [-Werror=overflow] (0x00000001 << (Nb)) ^ include/linux/gpio/machine.h:56:16: note: in definition of macro 'GPIO_LOOKUP_IDX' .chip_hwnum = _chip_hwnum, ^~~~~~~~~~~ arch/arm/mach-sa1100/include/mach/SA-1100.h:1140:21: note: in expansion of macro 'GPIO_GPIO' ^~~~~~~~~ arch/arm/mach-sa1100/simpad.c:331:27: note: in expansion of macro 'GPIO_GPIO21' GPIO_LOOKUP_IDX("gpio", GPIO_GPIO21, NULL, 0, This is what happened: commit b2e63555592f81331c8da3afaa607d8cf83e8138 "i2c: gpio: Convert to use descriptors" commit 4d0ce62c0a02e41a65cfdcfe277f5be430edc371 "i2c: gpio: Augment all boardfiles to use open drain" together uncovered an old bug in the Simpad board file: as theGPIO_LOOKUP_IDX() encodes GPIO offsets on gpiochips in an u16 (see ) these GPIO "numbers" does not fit, since in arch/arm/mach-sa1100/include/mach/SA-1100.h it is defined as: #define GPIO_GPIO(Nb) (0x00000001 << (Nb)) (...) #define GPIO_GPIO21 GPIO_GPIO(21) /* GPIO [21] */ This is however provably wrong, since the i2c-gpio driver uses proper GPIO numbers, albeit earlier from the global number space, whereas this GPIO_GPIO21 is the local line offset in the GPIO register, which is used in other code but certainly not in the gpiolib GPIO driver in drivers/gpio/gpio-sa1100.c, which has code like this: static void sa1100_gpio_set(struct gpio_chip *chip, unsigned offset, int value) { int reg = value ? R_GPSR : R_GPCR; writel_relaxed(BIT(offset), sa1100_gpio_chip(chip)->membase + reg); } So far everything however compiled fine as an unsigned int was used to pass the GPIO numbers in struct i2c_gpio_platform_data. We can trace the actual error back to commit dbd406f9d0a1d33a1303eb75cbe3f9435513d339 "ARM: 7025/1: simpad: add GPIO based device definitions." This added the i2c_gpio with the wrong offsets. This commit was before the SA1100 was converted to use the gpiolib, but as can be seen from the contemporary gpio.c in mach-sa1100, it was already using: static int sa1100_gpio_get(struct gpio_chip *chip, unsigned offset) { return GPLR & GPIO_GPIO(offset); } And GPIO_GPIO() is essentially the BIT() macro. Cc: Wolfram Sang Cc: Jochen Friedrich Cc: linux-arm-kernel@lists.infradead.org Cc: Russell King Cc: Arnd Bergmann Reported-by: Arnd Bergmann Signed-off-by: Linus Walleij Acked-by: Arnd Bergmann --- ChangeLog v1->v2: - Fix the commit message part that got stubbed out because of #define - Correct Wolfram's email address. - Put Arnd on CC. Wolfram: this is in the i2c GPIO refactoring in your tree, please apply it directly as a fix for v4.15 if there are no protests. Jochen: did this ever work? I suspect the patch was simply developed on top of a different kernel. --- arch/arm/mach-sa1100/simpad.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm/mach-sa1100/simpad.c b/arch/arm/mach-sa1100/simpad.c index 9db483a42826..7d4feb8a49ac 100644 --- a/arch/arm/mach-sa1100/simpad.c +++ b/arch/arm/mach-sa1100/simpad.c @@ -328,9 +328,9 @@ static struct platform_device simpad_gpio_leds = { static struct gpiod_lookup_table simpad_i2c_gpiod_table = { .dev_id = "i2c-gpio", .table = { - GPIO_LOOKUP_IDX("gpio", GPIO_GPIO21, NULL, 0, + GPIO_LOOKUP_IDX("gpio", 21, NULL, 0, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), - GPIO_LOOKUP_IDX("gpio", GPIO_GPIO25, NULL, 1, + GPIO_LOOKUP_IDX("gpio", 25, NULL, 1, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), }, };