From patchwork Tue Nov 7 15:17:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 835324 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="HvEcAxEf"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yWY4R6KKkz9s7c for ; Wed, 8 Nov 2017 02:19:19 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752732AbdKGPTS (ORCPT ); Tue, 7 Nov 2017 10:19:18 -0500 Received: from mail-lf0-f65.google.com ([209.85.215.65]:49011 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751844AbdKGPTR (ORCPT ); Tue, 7 Nov 2017 10:19:17 -0500 Received: by mail-lf0-f65.google.com with SMTP id r135so14923334lfe.5 for ; Tue, 07 Nov 2017 07:19:16 -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=QFaF05zvlmH8VXqhqDrfNzKdljGwPc7FS0smtsATLHY=; b=HvEcAxEf5GwbIeFCsxFi7ML/ciHmsVNVdAy8puJnH12q7tU4sFVozXxT0G6ptHw9v0 qHLl7H735rd0sPl7PcNjrVzmh5ajucZCMZLjRXH4PzFZugJBV2GlNKWUIwobhSuWpd8T RURDC1HgvYOuCNnAoMd0hpXQ6E7dFvVgdeei4= 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=QFaF05zvlmH8VXqhqDrfNzKdljGwPc7FS0smtsATLHY=; b=EDQKHICUs/qvpOoZ0kHXZPftqLHLXIKdepBI3/aqUQPp+QV8EplN9ia01SRUNmrFMp siLT7U1BYBJmbZzG8N0QGg/iFBQknSoWdvVvu4ho3lwnuOSxgvCrfiLlW0yVFFHyIxx0 ZwtLqNJ5EM0uZM7Ls8Wr64LLQONiUVtEfTt+5YrPPO57Nojgf+b/JnQjd062AzSzx38E EyVhVKpso/nYrQV2ki6k0kbwO7I6og8IqBUlVe23Yi7b6OwxR+K1s9NLPieg7G2N/+AH vx8MoKUJb2YeHDJZkdwHGkwQf9y5HW8SK6Obf4KCiZYuukUiVCalV1MUmHJxXQwpBSbi aRLg== X-Gm-Message-State: AMCzsaV2wHPQ4XKdEENcSuwi4jf01Af6fbJYl+zqtZZhu1Uwnd695ENU ez02aFcUEU+aMf4A7HbA+F0OZIuzY/g= X-Google-Smtp-Source: ABhQp+RZHvd6FIsl1YDxaS1ibKJP90wcB2l3YsD0QPOgQLPzd+chTsBALawOFg5BcS+IvtHI/8rfoQ== X-Received: by 10.46.95.82 with SMTP id t79mr7111052ljb.63.1510067955894; Tue, 07 Nov 2017 07:19:15 -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 18sm295675ljo.29.2017.11.07.07.19.14 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 07 Nov 2017 07:19:14 -0800 (PST) From: Linus Walleij To: Wolfram Sang , linux-i2c@vger.kernel.org Cc: Linus Walleij , Wolfram Sang , Jochen Friedrich , linux-arm-kernel@lists.infradead.org, Russell King Subject: [PATCH] ARM: sa1100: simpad: Correct I2C GPIO offsets Date: Tue, 7 Nov 2017 16:17:03 +0100 Message-Id: <20171107151703.3847-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: 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 Reported-by: Arnd Bergmann Signed-off-by: Linus Walleij --- 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), }, };