From patchwork Fri Nov 24 09:30:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 10073857 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 16BEB60375 for ; Fri, 24 Nov 2017 09:30:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0B0C82A31A for ; Fri, 24 Nov 2017 09:30:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 001772A354; Fri, 24 Nov 2017 09:30:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 99D0E2A31A for ; Fri, 24 Nov 2017 09:30:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752816AbdKXJay (ORCPT ); Fri, 24 Nov 2017 04:30:54 -0500 Received: from mail-lf0-f67.google.com ([209.85.215.67]:39677 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752688AbdKXJax (ORCPT ); Fri, 24 Nov 2017 04:30:53 -0500 Received: by mail-lf0-f67.google.com with SMTP id x76so20102146lfb.6 for ; Fri, 24 Nov 2017 01:30:53 -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:in-reply-to:references; bh=BLM/E4znKAlNdOQWjqTuitwFLoge9b3S7NgfeG+1l1o=; b=g3JjEjF5VodimWnRUUjFMJLLHGDkrrUbmPY67nbLtrxI1uwkHg72c1xBEsUBXLkVyI WQAAGgdoda6bIINH3MRh1cjwVgveTqSk2HULZ7uS4ADSrA0EizeOxhm8c5V9daF8TUZs aXVzgU9Fvglu4tSkygvc45j0mUdIZ6yJngjRI= 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:in-reply-to :references; bh=BLM/E4znKAlNdOQWjqTuitwFLoge9b3S7NgfeG+1l1o=; b=OI9mQ2t9ryU4jiaIz367axfi6Dbt7jwkXqJ6c32bYVK9BbPj0cggD3y+EMVlBl92on sM5acgBCXD9EHsUhiY1zV2ysSouYDdCrMScGwPIicosNP6XLgcVExnmB8djoHnFmUmZB jyuh2K/2NOAlvSHQ5vKtwbf1u2A+TCS+O5ZWlKhNFIL6c/+ZUhEkuvmb42yPv3k9bGQY zulVHSnDA8tljvmMqFNK9dK6VjIGq9KlPyOU9tZ0NxrLwSm+vZtnChtoxMkk5Z9vRIj4 L06GwWWwIf5vPOC0J3zFkLlZMexS3zwt3zmgJBU5UdBvVf5Hqr6xgvg1olTITgmvjdEg X3wQ== X-Gm-Message-State: AJaThX66CwS8Sorfq4p9gFEJOAlRNVOfWXdgNDbmWvs1AzGPGJwqxYHh zj3+xZ1m7eRTcoHz4PYqFFmmgw== X-Google-Smtp-Source: AGs4zMYacL2ChDdqxfyr6um2ssmBv2sPn2a7RrnscuuARFvILOmv0VGQybvts80/jy8So16jMVXyow== X-Received: by 10.46.91.75 with SMTP id p72mr10456843ljb.95.1511515852513; Fri, 24 Nov 2017 01:30:52 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id 19sm4476608ljx.58.2017.11.24.01.30.51 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 24 Nov 2017 01:30:51 -0800 (PST) From: Linus Walleij To: Dmitry Torokhov , linux-input@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, Linus Walleij Subject: [PATCH 2/5] gpio: pca953x: Name the gpiochip after the I2C address Date: Fri, 24 Nov 2017 10:30:42 +0100 Message-Id: <20171124093045.5961-3-linus.walleij@linaro.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20171124093045.5961-1-linus.walleij@linaro.org> References: <20171124093045.5961-1-linus.walleij@linaro.org> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Just putting the name of the I2C device as name for the GPIO chip (label) is ambigous, and makes it hard for us to use GPIO descriptor tables on systems such as DaVinci DA850EVM which has two chips but on I2C address 0x20 and 0x21. Instead, append "-XX" to the GPIOchip name using the I2C address so we get a unique chip name that can be used in descriptor tables, such as "tca6416-20" and "tca6416-21" on the DaVinci DA850EVM. Signed-off-by: Linus Walleij --- drivers/gpio/gpio-pca953x.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c index babb7bd2ba59..bab09f1a6bc9 100644 --- a/drivers/gpio/gpio-pca953x.c +++ b/drivers/gpio/gpio-pca953x.c @@ -413,10 +413,17 @@ static void pca953x_gpio_set_multiple(struct gpio_chip *gc, mutex_unlock(&chip->i2c_lock); } -static void pca953x_setup_gpio(struct pca953x_chip *chip, int gpios) +static int pca953x_setup_gpio(struct pca953x_chip *chip, int gpios) { + struct i2c_client *client = chip->client; struct gpio_chip *gc; + static char *chipname; + /* Gives a chip name from the chip name and I2C address */ + chipname = devm_kasprintf(&client->dev, GFP_KERNEL, "%s-%02x", + client->name, client->addr); + if (!chipname) + return -ENOMEM; gc = &chip->gpio_chip; gc->direction_input = pca953x_gpio_direction_input; @@ -429,10 +436,12 @@ static void pca953x_setup_gpio(struct pca953x_chip *chip, int gpios) gc->base = chip->gpio_start; gc->ngpio = gpios; - gc->label = chip->client->name; + gc->label = chipname; gc->parent = &chip->client->dev; gc->owner = THIS_MODULE; gc->names = chip->names; + + return 0; } #ifdef CONFIG_GPIO_PCA953X_IRQ @@ -848,7 +857,9 @@ static int pca953x_probe(struct i2c_client *client, /* initialize cached registers from their original values. * we can't share this chip with another i2c master. */ - pca953x_setup_gpio(chip, chip->driver_data & PCA_GPIO_MASK); + ret = pca953x_setup_gpio(chip, chip->driver_data & PCA_GPIO_MASK); + if (ret) + goto err_exit; if (chip->gpio_chip.ngpio <= 8) { chip->write_regs = pca953x_write_regs_8;