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: 118204 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp4426447qgn; Tue, 7 Nov 2017 12:21:03 -0800 (PST) X-Google-Smtp-Source: ABhQp+T5yHAE5kckHtxkkbwfhk3IC5RtcXpc4YNluMBImlrvACQEAj87LCHIu7smLZtJ2lDJHm1h X-Received: by 10.101.78.210 with SMTP id w18mr19480404pgq.337.1510086063331; Tue, 07 Nov 2017 12:21:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510086063; cv=none; d=google.com; s=arc-20160816; b=dHGydAwg0zw8uVzlGtp69gHFftXu8LU9vYTXsApxbhqOX/kHUYdEyHsAgthlvAsHvi msUJltSCEQb1wLCHKL2IBMZYWym30cj8Pyq//7PNskInzf+Zh+3++AtmQLEvD9eqVpxj kmHgWa5jM/v1k3kp8b4ZkHowThLbFrX4Hvqmka2HvPOwVMl3Imx/7/7fUdrHFxFWwPCr ew/CTSOmtmN8ANvughmQcPLLE2MdNs+LwfRoVgVLgBtvbUASJ4XEJSeI9LcRSG3hRSYH 1Hon+2bW/L/hLkKR6uuPouU5znCEovEtc87bUZIg4UF9qxkZdrSCdfg8pgmHeIpM94va Xp6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=s3FfMbgLLctBUKDJSi3UTbG6+74hq81xVrEFQBkIq9M=; b=eH6Oh7+qVPUGoCDSxlngF0oEKlMNDoBJMxKxvxGTYyMP1Oo80uo6S/I9Zyo0rLtUN2 T7OgNfHiFu0gSzqhWMXzk2BMZV3yyj7Y/WDwRNrjbdRcyeoIIok37YsMRHnWuxSB8e82 u4pKKBe5D9Fgb+v/hsGuVQ5VW+gmBUyieomJDlZpDjSsPcs6qn8Y395SonXUsKQKJ8r1 pZ5NmkfkFpTkrQi41srw3WfaU6PcicsjtvC68BOP0+9rBDjhgjo5xNBua1db6E7pCtmh AStTLkBFFiI8OGne5DJPYf5vw42WGNEJBVnRoUXOMZekcLXmJs6JQiCOGPeqysY6VoKx ms+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ic2VOdIa; spf=pass (google.com: best guess record for domain of linux-i2c-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-i2c-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n25si1992504pgc.242.2017.11.07.12.21.03; Tue, 07 Nov 2017 12:21:03 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-i2c-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ic2VOdIa; spf=pass (google.com: best guess record for domain of linux-i2c-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-i2c-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932901AbdKGUVC (ORCPT + 3 others); 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-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 --- 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(-) -- 2.13.6 Acked-by: Arnd Bergmann 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), }, };