From patchwork Thu May 30 21:50:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 165466 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1519002ili; Thu, 30 May 2019 14:56:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqxWEn99pQxe2mZ2SQ9thIT+JJ0WwK4HBAPFq3lT5khLro9Yts8NeX999fliDyVuswDNfyJW X-Received: by 2002:a62:8c97:: with SMTP id m145mr5917890pfd.62.1559253395907; Thu, 30 May 2019 14:56:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559253395; cv=none; d=google.com; s=arc-20160816; b=uAbUTtnT3c518YJNjf93YvIxzyGr+HxSjFd6/8rszHsfl54+dTS8lOh4hT8HMxsw+f K7NywVvzz0LHvhuFSvZnw3tNcn6+n1Zd8CT5hjGMpfzzcups7lY5stW+LAr+h+FcvHye THpP2ELjZOffuIHAIDTlhzpDNaQYmycfnKlhwoKxsHdXKUKyDWI0j7qA8dAK2UBDoVYK +5xAJbgMfyknDv9WI8Zr6YUAjoIARWqxzb1JAZnstYAubfMLC2hkzq0Qei488jibS/bt sqPDSLPeYkdgIIEAQBIPKLEvqtEpOqRViV3VRriT4nsbvhTi0Nl5oJgclhyNjOLfeClw UrJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=N+D77JZYl7L4JwlmlkCR53sQehR/+WCFO9RDYDI3XJU=; b=n7OxDa3i8Cpo3YPIYJT8p9BBw8ezPDCLmOZlivpJhuM5FmVy0PbP17T6GoNyfk4xSl cIBbJaUimMVJTkqo9xUqKWVjLteqeKdb6Wuhbz2B3BbDR5GWeSa+DgiPPITkZBXEhRsL 5SxmRHqUMeU7ereJ8RY+zCOOq+rRlsVQqi6tBHnA1n3jw6Gd5e+D17QUNJWcn2SeIJYz jQofo4qBOwbeC69lJvPmrW4/rRRK7cCSEQi/JdpAZ7Vocz2nM0NvSxPArTYGD8P9rwWP oEzUCLj0SsT2l23TZlAH3VSxGdOGN2HSOMx2E2a+0xTYbc3FlzwLiUFpVA7ClnMc1RGa yo4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lxCilLef; spf=pass (google.com: best guess record for domain of linux-samsung-soc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-samsung-soc-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 n4si4338939pff.62.2019.05.30.14.56.35; Thu, 30 May 2019 14:56:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-samsung-soc-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=lxCilLef; spf=pass (google.com: best guess record for domain of linux-samsung-soc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-samsung-soc-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 S1726487AbfE3V4f (ORCPT + 3 others); Thu, 30 May 2019 17:56:35 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:45711 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726100AbfE3V4f (ORCPT ); Thu, 30 May 2019 17:56:35 -0400 Received: by mail-wr1-f66.google.com with SMTP id b18so5124175wrq.12 for ; Thu, 30 May 2019 14:56:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=N+D77JZYl7L4JwlmlkCR53sQehR/+WCFO9RDYDI3XJU=; b=lxCilLefv1Tz7C7/PLb8Dl781WsaCZvG7vjg/DEkO53gLw7zbreJkjb6fdJsbHw07S A/OHPUi+3eD7Ss5MPpwYDhrJJP8xvWDt1E030/EL6974jVZ+z4DY2fQa0P/4Ef5CUBTC 2FdGoWb/mcjC9mMiK75Hnt9bGYE5UpRnHwdnXasnRNv4OZwjqqB7Lkkl+1YY9meG00R9 bOcZPSwy9TsG+RdIHQkkyhFEirXj7D3RtNPK4yNhgftYX/jjLzg9Hy/C7qb0HA+dq/Vj 4QeYoCIeHrB69RhQQCYtrHSG/gM1iskiGapShXfYAc9sWJkbP0UGXMTsPD/MXiS4rwy7 q1Bg== 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:mime-version :content-transfer-encoding; bh=N+D77JZYl7L4JwlmlkCR53sQehR/+WCFO9RDYDI3XJU=; b=SBkfWg+0hIiXPG/wy2lPIBgrvxPpOdp0cOSAaAMAHE4FSpsGDLDIouV99BYV5DOQ2p 7Aye6HJqcQ4rw81tD1s5SxPk+Mo4NE2m0rws2DvyPNA/lpoh1BjDqYck13QXrzO7pOCg CN58KzmFeR12ss/hl6YVffvsvIqCTkOu72yyQccUq2z96M3fOjIuHiFzRXK/KXO7E4XJ 0Pd7STBVNaqXuYGGpRM2nEkkdwsYCdEdJVWddcEmuiB9K/lnLAD/0jYkO3WSBumYJVzJ U4YjEftFYiNsqOPSA3Cs6OQ4gtuU5nU97V3d2LXpzlElSviGj2IfONi1031OSmVOfQ7w Z+Eg== X-Gm-Message-State: APjAAAUpmcZpJHxD26553i4xiOwreHKt/u2bryRRloomrfMwGWUtU+Ax BGckvHf/r0MyxYT/tt5DRe2rsQ== X-Received: by 2002:adf:dd52:: with SMTP id u18mr3917442wrm.193.1559253016797; Thu, 30 May 2019 14:50:16 -0700 (PDT) Received: from localhost.localdomain (catv-89-135-96-219.catv.broadband.hu. [89.135.96.219]) by smtp.gmail.com with ESMTPSA id a139sm6177079wmd.18.2019.05.30.14.50.14 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 30 May 2019 14:50:15 -0700 (PDT) From: Linus Walleij To: Wolfram Sang , linux-i2c@vger.kernel.org Cc: Linus Walleij , Kukjin Kim , Krzysztof Kozlowski , linux-samsung-soc@vger.kernel.org Subject: [PATCH] i2c: s3c2410: Convert to use GPIO descriptors Date: Thu, 30 May 2019 23:50:13 +0200 Message-Id: <20190530215013.17806-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org The S3C2410 does some funny dance around its pins: - First try to call back to the platform to get and control some GPIO pins - If this doesn't work, it tries to get a pin control handle - If this doesn't work, it retrieves two GPIOs from the device tree node and does nothing with them If we're gonna retrieve two GPIOs and do nothing with them, we might as well do it using the GPIO descriptor API. When we use the resource management API, the code gets smaller. Cc: Kukjin Kim Cc: Krzysztof Kozlowski Cc: linux-samsung-soc@vger.kernel.org Signed-off-by: Linus Walleij --- drivers/i2c/busses/i2c-s3c2410.c | 47 ++++++-------------------------- 1 file changed, 9 insertions(+), 38 deletions(-) -- 2.20.1 Acked-by: Krzysztof Kozlowski diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c index 53bc021f4a5a..ed06a8535d63 100644 --- a/drivers/i2c/busses/i2c-s3c2410.c +++ b/drivers/i2c/busses/i2c-s3c2410.c @@ -33,7 +33,7 @@ #include #include #include -#include +#include #include #include #include @@ -122,7 +122,7 @@ struct s3c24xx_i2c { struct i2c_adapter adap; struct s3c2410_platform_i2c *pdata; - int gpios[2]; + struct gpio_desc *gpios[2]; struct pinctrl *pctrl; #if defined(CONFIG_ARM_S3C24XX_CPUFREQ) struct notifier_block freq_transition; @@ -956,53 +956,27 @@ static inline void s3c24xx_i2c_deregister_cpufreq(struct s3c24xx_i2c *i2c) #ifdef CONFIG_OF static int s3c24xx_i2c_parse_dt_gpio(struct s3c24xx_i2c *i2c) { - int idx, gpio, ret; + int i; if (i2c->quirks & QUIRK_NO_GPIO) return 0; - for (idx = 0; idx < 2; idx++) { - gpio = of_get_gpio(i2c->dev->of_node, idx); - if (!gpio_is_valid(gpio)) { - dev_err(i2c->dev, "invalid gpio[%d]: %d\n", idx, gpio); - goto free_gpio; - } - i2c->gpios[idx] = gpio; - - ret = gpio_request(gpio, "i2c-bus"); - if (ret) { - dev_err(i2c->dev, "gpio [%d] request failed (%d)\n", - gpio, ret); - goto free_gpio; + for (i = 0; i < 2; i++) { + i2c->gpios[i] = devm_gpiod_get_index(i2c->dev, NULL, + i, GPIOD_ASIS); + if (IS_ERR(i2c->gpios[i])) { + dev_err(i2c->dev, "i2c gpio invalid at index %d\n", i); + return -EINVAL; } } return 0; - -free_gpio: - while (--idx >= 0) - gpio_free(i2c->gpios[idx]); - return -EINVAL; } -static void s3c24xx_i2c_dt_gpio_free(struct s3c24xx_i2c *i2c) -{ - unsigned int idx; - - if (i2c->quirks & QUIRK_NO_GPIO) - return; - - for (idx = 0; idx < 2; idx++) - gpio_free(i2c->gpios[idx]); -} #else static int s3c24xx_i2c_parse_dt_gpio(struct s3c24xx_i2c *i2c) { return 0; } - -static void s3c24xx_i2c_dt_gpio_free(struct s3c24xx_i2c *i2c) -{ -} #endif /* @@ -1231,9 +1205,6 @@ static int s3c24xx_i2c_remove(struct platform_device *pdev) i2c_del_adapter(&i2c->adap); - if (pdev->dev.of_node && IS_ERR(i2c->pctrl)) - s3c24xx_i2c_dt_gpio_free(i2c); - return 0; }