From patchwork Tue Aug 8 11:04:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcus Folkesson X-Patchwork-Id: 132706 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp2325030vqr; Tue, 8 Aug 2023 11:47:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH5zv2WfnfEtYwDyfm+1GlFlFOSsEgXk5ycxNEULNW2s/4eOdr4MzePTOkj0y85bd/nv6KQ X-Received: by 2002:a05:6a20:f3b0:b0:133:2a73:fdd5 with SMTP id qr48-20020a056a20f3b000b001332a73fdd5mr331233pzb.32.1691520467409; Tue, 08 Aug 2023 11:47:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691520467; cv=none; d=google.com; s=arc-20160816; b=fiSjHBp/BJH4CHVyWpO023WVj4I2TGj04ad6Z0Y8DqSlf6lcy73IlxES6v8woSUX8Q 5PCmzpfR0OqnnciQwM/p9EoDljm3PG96HPGuVgLlLfblbe59YBJv9luB8EwvrZAu67pS YY8H9Wn+20ny/TvtNUavfvGY082Y7BfSO6xQBen0KiywWIA3Tuww3cVr8Nq56NuLI0BG AAoYnGtvvo91ZpFWyM0Hmgoc8dVVGRu5J1Vf0EW6LooXZlZlHiyf+NqhfPuXM/miGpx4 8gyC2m/SQ4/F5Pcxe4imkXhPc4nDbj479KFbQO8vd6HEAg0pTNjk5VSuqGcD9WJYuzoG jfgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=N77XCzPazpBok51u5jWouG3TfNUMbwqAhma/4DQhYGI=; fh=5Be87yMw2nKXKY3Zw+dG4yOhAHCMghE6yywjWWsbu2k=; b=xl28rpB/b6EazlmXg17If+KYpCSLB9j9MOYfGBzRkCCYVkMb4OTZQqLEnVqmRVosU/ nrxGDeMjAXdoA63iscNBXkzM0GXHVJcoGdEt5QqMUzXMGMx6Yz1rWK2CoQJlu6IesDZz b67Q9gLP71nTZUD6KsaBc9ZVstLY2IAvizoJuHwDn5zVcjrVRKcAZI7bicsXZjJhrt60 rylVM4TECGyr1Ho+UA+15319QHQBRBLSvO7gNHKI62JHntj2rk34n3fzFRyyPm/r8AQd vw+WmJuu0Y3ehB0XnlA/KCl6xN8a45jZpghGX7rZ5+OSyEnemncBkTzD9PB8MHk8sTkQ 9+Qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=fIuQVJV7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l191-20020a6388c8000000b00563e6fd0bf6si7470980pgd.792.2023.08.08.11.47.33; Tue, 08 Aug 2023 11:47:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=fIuQVJV7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233893AbjHHRIB (ORCPT + 99 others); Tue, 8 Aug 2023 13:08:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234107AbjHHRHP (ORCPT ); Tue, 8 Aug 2023 13:07:15 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3575CE7D; Tue, 8 Aug 2023 09:02:58 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-3176a439606so4478539f8f.3; Tue, 08 Aug 2023 09:02:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691510549; x=1692115349; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=N77XCzPazpBok51u5jWouG3TfNUMbwqAhma/4DQhYGI=; b=fIuQVJV7UoBTVdWJIV18mnPWXHYesbhQyN7e1gPr2Z98Zvf+xtUuMZ02EOkHMvwUVS 6samL0MKW3KjC9H5VBIyD8L3678pH6Pev7c2xQOs0MsNDPf40E1W2rcvb+oYXcCTZHwS cYdVL4EmpXZ/7NVHFSx76iNrm9VGbTM4TEb6oKiVsokPlGZi/3bE9/1m9aI/tdkulu0S OwawWwWDmyX8sty9mmauYwrSHMgdS5d25gdFB7+NovtwPxo/GaGCujsk9GKPDAT12Z9N jZcft4Ab8C//BQJGzhxg3RWNOXJgoXzQu7kalR3KUcuZ7ZGWpQ8GeYJDZO0q3ze7vP3H aC/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691510549; x=1692115349; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=N77XCzPazpBok51u5jWouG3TfNUMbwqAhma/4DQhYGI=; b=btghqHelNexVgaiBE/LvEspyGU0FxMoj4DtZNxw06tgyiFAwUfwWa30+KYf6UMA0XK 3TZp0iPCnWnJblRD8uas3LtA2rxxdGKxLJPTw07HfpNL2HWXgfwu6Sjr9kceSCqGLe0G YEPHaGl0g9PetRbIeOOQMqHlIoH2VOxOAxYf77NOoDPUl4SLOrQOLcsX95FfRePMu9L7 ocvBEJhTymWLm2RX5jHt+SpFO0mX2szPI1md5I3h/cg2HNjXZDbcREwrN/2rV9pUGoVw QBpB6rsUO926Bsql5RGZRfYWVE/YK+8fmqyRk8TTe6Z4l0nfG5+z2QoxZp4bPA8jktKk Y83g== X-Gm-Message-State: AOJu0YwbcPJLWvJbsQd+pe+5fWtMnVcWXpjbk45GxSN+fPMR86uy7oie b9WIhDpogtfK6Vz1YSGAo/iglRHeTisgsDCe X-Received: by 2002:a05:6512:31d1:b0:4fe:49d:6ae2 with SMTP id j17-20020a05651231d100b004fe049d6ae2mr9290985lfe.0.1691492568213; Tue, 08 Aug 2023 04:02:48 -0700 (PDT) Received: from localhost.localdomain (83-233-6-197.cust.bredband2.com. [83.233.6.197]) by smtp.gmail.com with ESMTPSA id q10-20020ac246ea000000b004fbad682ffesm1826587lfo.88.2023.08.08.04.02.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Aug 2023 04:02:47 -0700 (PDT) From: Marcus Folkesson To: Marcus Folkesson , Kent Gustavsson , Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Andy Shevchenko , Cosmin Tanislav , Arnd Bergmann , ChiYuan Huang , Haibo Chen , Ramona Bolboaca , Ibrahim Tilki , ChiaEn Wu , William Breathitt Gray Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Krzysztof Kozlowski Subject: [PATCH v4 1/4] dt-bindings: iio: adc: mcp3911: add support for the whole MCP39xx family Date: Tue, 8 Aug 2023 13:04:29 +0200 Message-Id: <20230808110432.240773-1-marcus.folkesson@gmail.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773687765415181036 X-GMAIL-MSGID: 1773687765415181036 Microchip does have many similar chips, add those to the compatible string as the driver support is extended. The new supported chips are: - microchip,mcp3910 - microchip,mcp3912 - microchip,mcp3913 - microchip,mcp3914 - microchip,mcp3918 - microchip,mcp3919 Signed-off-by: Marcus Folkesson Reviewed-by: Krzysztof Kozlowski --- Notes: v2: - No changes v3: - No changes v4: - No changes .../devicetree/bindings/iio/adc/microchip,mcp3911.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Documentation/devicetree/bindings/iio/adc/microchip,mcp3911.yaml b/Documentation/devicetree/bindings/iio/adc/microchip,mcp3911.yaml index f7b3fde4115a..06951ec5f5da 100644 --- a/Documentation/devicetree/bindings/iio/adc/microchip,mcp3911.yaml +++ b/Documentation/devicetree/bindings/iio/adc/microchip,mcp3911.yaml @@ -18,7 +18,13 @@ description: | properties: compatible: enum: + - microchip,mcp3910 - microchip,mcp3911 + - microchip,mcp3912 + - microchip,mcp3913 + - microchip,mcp3914 + - microchip,mcp3918 + - microchip,mcp3919 reg: maxItems: 1 From patchwork Tue Aug 8 11:04:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcus Folkesson X-Patchwork-Id: 132724 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp2328442vqr; Tue, 8 Aug 2023 11:54:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGyy/prPbgUtuCbYoIkZiyaA4F9QCClkdcyuRUb+R1p2fmjK5QiQqlvpGUmhbyOs44l7gjR X-Received: by 2002:a05:6e02:1be2:b0:345:d3bc:8882 with SMTP id y2-20020a056e021be200b00345d3bc8882mr674594ilv.24.1691520895572; Tue, 08 Aug 2023 11:54:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691520895; cv=none; d=google.com; s=arc-20160816; b=aYk1KZkjHv+DFNsOEbbNI35FRENjRarLv15q4ADzEjhGGx31tNSyjTTrac3OLET4Ws VbbJD2a64p5xHt0nJkVm0hWPKFr4sfT5f0sZlzzUWAx368wYn41JlXAOs/kKSfzl403z u0F7wQhkv/TicnG/KSmZwAuvWRd/lKHv+uuSqKbcx67PX/Lbp5etTfhb9Tr72fNGzAKS 1+DmBQZPnyEpiv9Umipc4vg9gj94hTDlY5hkkM5N2DDnavP52yZ5WDCRNyIN4Usqt4El k0GFpDAFy64naC8KWuqPpAESRoiH4aMn3TwSjvdGDOJOZz+zlGN0lZ2f0/SjZKu+BeWD 6HoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=OElZr8BTpJ7JNneHnhrzYnj3mSvt2d3fP42MAZf4FtQ=; fh=eoE64ugdk+S+1Ybc433G5Fz1KDZWL7DmgOSbU69JQKk=; b=USPXoaS6NUKL9cxjMrOncmWo73HBI150TwS2pEausbWY9UjFqjMhvMcT/XrbBQ3y++ OrachPIuzMDQME9YD1ELdLULfYweEhGCC1zgIkIkhUWsW0FYuEyPwxH7oTTlt9nPDOOB v9yvbh1tczmi/XI4rLO/rsL6ADqe4fzOn2aXaszN0puVC9McT479MnwXuJpaFv7EfK8Y NY0yuNIKJ3wTTHgq+UxY/0grby1Z8sYbQ0J8CO8fTHH7lXJ355FBjxJhkZCtkJxq0rrJ kPfY9nMLNmp+1e8I7qz12q3YLxG7ESVNeQBlADUBtyluu8OXQmYB9q1E+jf7PX56RO1K dzhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b="aWQU4B/4"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 67-20020a630246000000b005633776f01csi7394517pgc.793.2023.08.08.11.54.42; Tue, 08 Aug 2023 11:54:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b="aWQU4B/4"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230216AbjHHRaW (ORCPT + 99 others); Tue, 8 Aug 2023 13:30:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234472AbjHHR3t (ORCPT ); Tue, 8 Aug 2023 13:29:49 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DAA077D92; Tue, 8 Aug 2023 09:12:52 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-3179ed1dfbbso5027768f8f.1; Tue, 08 Aug 2023 09:12:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691511138; x=1692115938; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=OElZr8BTpJ7JNneHnhrzYnj3mSvt2d3fP42MAZf4FtQ=; b=aWQU4B/4bA9BeO/gkbRGrnBvv3RiFnqPVL5h442qBPhaI2BOCz1lwgedWS2CVdPvv7 QowLNtjpwOTs1uStm9MRTlJTelwrWbvy1P4J7XCzcEMAMmqCd10zUqr90dAZqxWLC7tl XWkSvjDoHFsj3ZXpBVN8guI4gG7KenN6lY7k23H/vU0YiGCT+hy8HwqYjvW8DL6gPSqZ VE/KQmaoGad2G4O4w2nmXXorJr1SF136oFvpmEBppwd89DSCjf9Z38u6IMCi4qmZCa4+ SwMXKNCJbCCmIGgl5ry+Hk1+wcrBUApcTlBIJ/QmxvwBSpZR7R5KPn+uuXff6JeTWtJY gKwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691511138; x=1692115938; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OElZr8BTpJ7JNneHnhrzYnj3mSvt2d3fP42MAZf4FtQ=; b=mE36iJ0fOaMnhBB8JzOrE2X+UbpCng0UbThYHsHjsKf5qX0/Yg0KScFQnhlPFPV6Gv R0ANY/iIT+EdxpGAyzqqcmJS2qZItpkoO2c+oon5Vi2/jhUKFafCKvcrLmN8PNpleYbB lsnTZWtTy2ejvgA9MxqlKX0SOv4H0wkIZ9j4QXTnvUJA5uSLj/Q0+fCKO1YONGQzjJVs aMJEhI4kc7AyJjYnYUvFwhbfcd0VD+R3Gw1fhcchJao/euSyYkk/8KbTIXpY52xhQ9kt DMAa3TNh6zsrENV+YBRBQ3DQcul4OozIC8DpP52AnxL1+BK4MqYASuiQoN/wJ8icYmGp ZhaQ== X-Gm-Message-State: AOJu0YziolYwrK2fTJ4CUdsVOO44VBk1qs5XArzFDKa0tFhIGkMYqaI4 Th3BMIXmitCMSkrEBJrMuMKf6oIHIxZqgfYC X-Received: by 2002:a05:6512:31cd:b0:4fc:265d:fc62 with SMTP id j13-20020a05651231cd00b004fc265dfc62mr8564067lfe.18.1691492570400; Tue, 08 Aug 2023 04:02:50 -0700 (PDT) Received: from localhost.localdomain (83-233-6-197.cust.bredband2.com. [83.233.6.197]) by smtp.gmail.com with ESMTPSA id q10-20020ac246ea000000b004fbad682ffesm1826587lfo.88.2023.08.08.04.02.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Aug 2023 04:02:48 -0700 (PDT) From: Marcus Folkesson To: Marcus Folkesson , Kent Gustavsson , Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Andy Shevchenko , Cosmin Tanislav , Arnd Bergmann , ChiYuan Huang , Haibo Chen , Ramona Bolboaca , Ibrahim Tilki , ChiaEn Wu , William Breathitt Gray Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 2/4] iio: adc: mcp3911: simplify usage of spi->dev in probe function Date: Tue, 8 Aug 2023 13:04:30 +0200 Message-Id: <20230808110432.240773-2-marcus.folkesson@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230808110432.240773-1-marcus.folkesson@gmail.com> References: <20230808110432.240773-1-marcus.folkesson@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773687864213508208 X-GMAIL-MSGID: 1773688214558288860 Replace the usage of adc->spi->dev with spi->dev to make the code prettier. Signed-off-by: Marcus Folkesson --- Notes: v4: - New patch in this series drivers/iio/adc/mcp3911.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/iio/adc/mcp3911.c b/drivers/iio/adc/mcp3911.c index 974c5bd923a6..8bbf2f7c839e 100644 --- a/drivers/iio/adc/mcp3911.c +++ b/drivers/iio/adc/mcp3911.c @@ -477,12 +477,12 @@ static int mcp3911_probe(struct spi_device *spi) adc = iio_priv(indio_dev); adc->spi = spi; - adc->vref = devm_regulator_get_optional(&adc->spi->dev, "vref"); + adc->vref = devm_regulator_get_optional(&spi->dev, "vref"); if (IS_ERR(adc->vref)) { if (PTR_ERR(adc->vref) == -ENODEV) { adc->vref = NULL; } else { - dev_err(&adc->spi->dev, + dev_err(&spi->dev, "failed to get regulator (%ld)\n", PTR_ERR(adc->vref)); return PTR_ERR(adc->vref); @@ -499,12 +499,12 @@ static int mcp3911_probe(struct spi_device *spi) return ret; } - adc->clki = devm_clk_get_enabled(&adc->spi->dev, NULL); + adc->clki = devm_clk_get_enabled(&spi->dev, NULL); if (IS_ERR(adc->clki)) { if (PTR_ERR(adc->clki) == -ENOENT) { adc->clki = NULL; } else { - dev_err(&adc->spi->dev, + dev_err(&spi->dev, "failed to get adc clk (%ld)\n", PTR_ERR(adc->clki)); return PTR_ERR(adc->clki); @@ -515,7 +515,7 @@ static int mcp3911_probe(struct spi_device *spi) if (ret) return ret; - if (device_property_read_bool(&adc->spi->dev, "microchip,data-ready-hiz")) + if (device_property_read_bool(&spi->dev, "microchip,data-ready-hiz")) ret = mcp3911_update(adc, MCP3911_REG_STATUSCOM, MCP3911_STATUSCOM_DRHIZ, 0, 2); else @@ -579,7 +579,7 @@ static int mcp3911_probe(struct spi_device *spi) if (ret) return ret; - return devm_iio_device_register(&adc->spi->dev, indio_dev); + return devm_iio_device_register(&spi->dev, indio_dev); } static const struct of_device_id mcp3911_dt_ids[] = { From patchwork Tue Aug 8 11:04:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcus Folkesson X-Patchwork-Id: 132842 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp2375129vqr; Tue, 8 Aug 2023 13:24:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGWOGuAM2KWrxea++1tyDrXt+8ihdqclF85ETVRpskCPyZ4RZc+Ipce8kiWFSkUFxOsJU2O X-Received: by 2002:a05:6808:10cb:b0:3a7:96e5:6a58 with SMTP id s11-20020a05680810cb00b003a796e56a58mr990469ois.18.1691526264754; Tue, 08 Aug 2023 13:24:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691526264; cv=none; d=google.com; s=arc-20160816; b=r20hKX9He9AM9e1kG4godqg8lxRUlFakK1zSsahKcCdY2bsVyJd1n1fBF4vY2/gWHz mldp2O0aopmBJ4WgYUJbD1kLnno1aRcbvnkwVyXaHoTwCnlvsHaoYWxxxfIQaLQ4Le3B 49RxRAPCTn4MVaFcAJh41og7IUSa+PdO7XcmHzq4j9NaDywycdUEeOQdOfCmlWo0yo12 Gm45IC4KhQ0Gr+I/nVaqVtKCXjIFNjMEVbxTQXius0G5eG5BugELOxUWz62XpsgkyBrm Z6X9jGPm4Pv++KFhk+yHXZqzKMN69SXrTyyHyBCdj5l9SteY0mQaHxYLXAKJ7ZKrg29H Gxug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=SkJoIl6bqN5V/arz35UqS7vxqymZsvhTQ0NmSaBWTpc=; fh=eoE64ugdk+S+1Ybc433G5Fz1KDZWL7DmgOSbU69JQKk=; b=DZo8cdPB5TsStGBOd4T93+MFywVaq6P4EhuJPxdhrxiY0iQ9QX0AFYvZg+QLxIzLCe Crk80GNUes0F7Nq/0h/aERctqeq/uKRWPlaYqtBC57kNi0sf7fkMH8V78oqgbaRXXkkH BPVIvNnWc7md50cGyK9yWe3tpj4sP9iW5jUyPSGLsdLWqiKrHjKR2iqttwWl3XoCuBsm a0HalGlv+CEPVV/ddHixRiyLIuUfgzB4UvI2ZqZvFD33w42hzOgnmaG8Uk+nNFZhiOek /FkN6nkdaySmZMx9YIPEkY+4RJnkOAAVog1Id9n8QupB3yTXb1gI3+028M10w/0Ys4Dv 9+pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=aWTCoVkG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lb8-20020a17090b4a4800b0026829e2a84bsi11456022pjb.97.2023.08.08.13.24.11; Tue, 08 Aug 2023 13:24:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=aWTCoVkG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234980AbjHHTN0 (ORCPT + 99 others); Tue, 8 Aug 2023 15:13:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234814AbjHHTNL (ORCPT ); Tue, 8 Aug 2023 15:13:11 -0400 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A325351D3; Tue, 8 Aug 2023 09:35:39 -0700 (PDT) Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-99bc512526cso855135766b.1; Tue, 08 Aug 2023 09:35:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691512502; x=1692117302; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SkJoIl6bqN5V/arz35UqS7vxqymZsvhTQ0NmSaBWTpc=; b=aWTCoVkGvg4zYFRtsVweX3Y1ZWkJ6IdzZGpjekBCTjqBYnGSn/T4rteLMQwje2pSpg FMYUu645hm7Ud2fgruVlMuhPxHMrIHHhC7jt39y6evuTau2WHegCxIPhN0dcapaj/ruT jSegFBzbnBjnbWdWU+W5BQB+FITxUDC2jCgxbVvyygOVOnrg8IWsGnFz7/INgxnkY+NK 8i6Qmckdneg2sdqCAzIsoZaoSAIEu5s9oPHIuEfSHNnDAQQhqXjbc8C8SZsNaHoOByC2 NuobX5ztpxbNBLu+F5zwefRN0/m2EY2hIKBqmmGovM8VwTvx0qmocL9o18QSBUYo7bm7 KUHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691512502; x=1692117302; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SkJoIl6bqN5V/arz35UqS7vxqymZsvhTQ0NmSaBWTpc=; b=DnmleRf8VD7RP42jG6mlWexo+C9PpGyROXWPPy18UcUMSfuqKFIhX1coo5NuJaT/Ao U0AWO6fyd/5lziBf5oCUBq4Z+M/kvgrq2zdy95ImWwdem3Hiray7gxLte/uHBI5oi9E/ SAKjwf9AMeb1HCVLxP1/ohIzksdTXrSwX46Gopp3pZUS9jUCKPd69RD836CuWkf/Q8ej Xyl/dQIwoRRobCbQ4Fv0g5Oa276eFCH0VEM4HlBk5E4mTyRB1OWcN4R8pfKUDAZ4+e0Q dN+SJxBVldgxk1R+ovIuqviddIXjpS82pOQ7GJqfvnC7ZDUCgNmR8ZvQhtPc+Rn3AC0a w2bA== X-Gm-Message-State: AOJu0YxAS2ID7K7WQbwUmw0q/TytvsnOfE2p/461mVQy+Ydv8j4OiOHy BspOwA7woG65ckmW45UythVNretWgUBwtHF4 X-Received: by 2002:a05:6512:31d6:b0:4f8:7772:3dfd with SMTP id j22-20020a05651231d600b004f877723dfdmr8655721lfe.11.1691492572360; Tue, 08 Aug 2023 04:02:52 -0700 (PDT) Received: from localhost.localdomain (83-233-6-197.cust.bredband2.com. [83.233.6.197]) by smtp.gmail.com with ESMTPSA id q10-20020ac246ea000000b004fbad682ffesm1826587lfo.88.2023.08.08.04.02.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Aug 2023 04:02:51 -0700 (PDT) From: Marcus Folkesson To: Marcus Folkesson , Kent Gustavsson , Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Andy Shevchenko , Cosmin Tanislav , Arnd Bergmann , ChiYuan Huang , Haibo Chen , Ramona Bolboaca , Ibrahim Tilki , ChiaEn Wu , William Breathitt Gray Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 3/4] iio: adc: mcp3911: fix indentation Date: Tue, 8 Aug 2023 13:04:31 +0200 Message-Id: <20230808110432.240773-3-marcus.folkesson@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230808110432.240773-1-marcus.folkesson@gmail.com> References: <20230808110432.240773-1-marcus.folkesson@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773693618657005038 X-GMAIL-MSGID: 1773693844270489980 The file does not make use of indentation properly. Fix that. Signed-off-by: Marcus Folkesson --- Notes: v4: - New patch in this series drivers/iio/adc/mcp3911.c | 97 ++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 48 deletions(-) diff --git a/drivers/iio/adc/mcp3911.c b/drivers/iio/adc/mcp3911.c index 8bbf2f7c839e..8b465d2aad1a 100644 --- a/drivers/iio/adc/mcp3911.c +++ b/drivers/iio/adc/mcp3911.c @@ -33,7 +33,7 @@ #define MCP3911_GAIN_VAL(ch, val) ((val << 3 * ch) & MCP3911_GAIN_MASK(ch)) #define MCP3911_REG_STATUSCOM 0x0a -#define MCP3911_STATUSCOM_DRHIZ BIT(12) +#define MCP3911_STATUSCOM_DRHIZ BIT(12) #define MCP3911_STATUSCOM_READ GENMASK(7, 6) #define MCP3911_STATUSCOM_CH1_24WIDTH BIT(4) #define MCP3911_STATUSCOM_CH0_24WIDTH BIT(3) @@ -112,7 +112,7 @@ static int mcp3911_write(struct mcp3911 *adc, u8 reg, u32 val, u8 len) } static int mcp3911_update(struct mcp3911 *adc, u8 reg, u32 mask, - u32 val, u8 len) + u32 val, u8 len) { u32 tmp; int ret; @@ -127,8 +127,8 @@ static int mcp3911_update(struct mcp3911 *adc, u8 reg, u32 mask, } static int mcp3911_write_raw_get_fmt(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - long mask) + struct iio_chan_spec const *chan, + long mask) { switch (mask) { case IIO_CHAN_INFO_SCALE: @@ -141,9 +141,9 @@ static int mcp3911_write_raw_get_fmt(struct iio_dev *indio_dev, } static int mcp3911_read_avail(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - const int **vals, int *type, int *length, - long info) + struct iio_chan_spec const *chan, + const int **vals, int *type, int *length, + long info) { switch (info) { case IIO_CHAN_INFO_OVERSAMPLING_RATIO: @@ -212,8 +212,8 @@ static int mcp3911_read_raw(struct iio_dev *indio_dev, } static int mcp3911_write_raw(struct iio_dev *indio_dev, - struct iio_chan_spec const *channel, int val, - int val2, long mask) + struct iio_chan_spec const *channel, int val, + int val2, long mask) { struct mcp3911 *adc = iio_priv(indio_dev); int ret = -EINVAL; @@ -223,12 +223,12 @@ static int mcp3911_write_raw(struct iio_dev *indio_dev, case IIO_CHAN_INFO_SCALE: for (int i = 0; i < MCP3911_NUM_SCALES; i++) { if (val == mcp3911_scale_table[i][0] && - val2 == mcp3911_scale_table[i][1]) { + val2 == mcp3911_scale_table[i][1]) { adc->gain[channel->channel] = BIT(i); ret = mcp3911_update(adc, MCP3911_REG_GAIN, - MCP3911_GAIN_MASK(channel->channel), - MCP3911_GAIN_VAL(channel->channel, i), 1); + MCP3911_GAIN_MASK(channel->channel), + MCP3911_GAIN_VAL(channel->channel, i), 1); } } break; @@ -246,8 +246,8 @@ static int mcp3911_write_raw(struct iio_dev *indio_dev, /* Enable offset*/ ret = mcp3911_update(adc, MCP3911_REG_STATUSCOM, - MCP3911_STATUSCOM_EN_OFFCAL, - MCP3911_STATUSCOM_EN_OFFCAL, 2); + MCP3911_STATUSCOM_EN_OFFCAL, + MCP3911_STATUSCOM_EN_OFFCAL, 2); break; case IIO_CHAN_INFO_OVERSAMPLING_RATIO: @@ -255,7 +255,7 @@ static int mcp3911_write_raw(struct iio_dev *indio_dev, if (val == mcp3911_osr_table[i]) { val = FIELD_PREP(MCP3911_CONFIG_OSR, i); ret = mcp3911_update(adc, MCP3911_REG_CONFIG, MCP3911_CONFIG_OSR, - val, 2); + val, 2); break; } } @@ -279,7 +279,7 @@ static int mcp3911_calc_scale_table(struct mcp3911 *adc) if (ret < 0) { dev_err(&adc->spi->dev, "failed to get vref voltage: %d\n", - ret); + ret); return ret; } @@ -305,25 +305,25 @@ static int mcp3911_calc_scale_table(struct mcp3911 *adc) return 0; } -#define MCP3911_CHAN(idx) { \ - .type = IIO_VOLTAGE, \ - .indexed = 1, \ - .channel = idx, \ - .scan_index = idx, \ - .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ - BIT(IIO_CHAN_INFO_OFFSET) | \ - BIT(IIO_CHAN_INFO_SCALE), \ - .info_mask_shared_by_type_available = \ - BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ - .info_mask_separate_available = \ - BIT(IIO_CHAN_INFO_SCALE), \ - .scan_type = { \ - .sign = 's', \ - .realbits = 24, \ - .storagebits = 32, \ - .endianness = IIO_BE, \ - }, \ +#define MCP3911_CHAN(idx) { \ + .type = IIO_VOLTAGE, \ + .indexed = 1, \ + .channel = idx, \ + .scan_index = idx, \ + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_OFFSET) | \ + BIT(IIO_CHAN_INFO_SCALE), \ + .info_mask_shared_by_type_available = \ + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ + .info_mask_separate_available = \ + BIT(IIO_CHAN_INFO_SCALE), \ + .scan_type = { \ + .sign = 's', \ + .realbits = 24, \ + .storagebits = 32, \ + .endianness = IIO_BE, \ + }, \ } static const struct iio_chan_spec mcp3911_channels[] = { @@ -355,7 +355,7 @@ static irqreturn_t mcp3911_trigger_handler(int irq, void *p) ret = spi_sync_transfer(adc->spi, xfer, ARRAY_SIZE(xfer)); if (ret < 0) { dev_warn(&adc->spi->dev, - "failed to get conversion data\n"); + "failed to get conversion data\n"); goto out; } @@ -494,7 +494,7 @@ static int mcp3911_probe(struct spi_device *spi) return ret; ret = devm_add_action_or_reset(&spi->dev, - mcp3911_cleanup_regulator, adc->vref); + mcp3911_cleanup_regulator, adc->vref); if (ret) return ret; } @@ -517,10 +517,10 @@ static int mcp3911_probe(struct spi_device *spi) if (device_property_read_bool(&spi->dev, "microchip,data-ready-hiz")) ret = mcp3911_update(adc, MCP3911_REG_STATUSCOM, MCP3911_STATUSCOM_DRHIZ, - 0, 2); + 0, 2); else ret = mcp3911_update(adc, MCP3911_REG_STATUSCOM, MCP3911_STATUSCOM_DRHIZ, - MCP3911_STATUSCOM_DRHIZ, 2); + MCP3911_STATUSCOM_DRHIZ, 2); if (ret) return ret; @@ -528,12 +528,12 @@ static int mcp3911_probe(struct spi_device *spi) if (ret) return ret; - /* Set gain to 1 for all channels */ + /* Set gain to 1 for all channels */ for (int i = 0; i < MCP3911_NUM_CHANNELS; i++) { adc->gain[i] = 1; ret = mcp3911_update(adc, MCP3911_REG_GAIN, - MCP3911_GAIN_MASK(i), - MCP3911_GAIN_VAL(i, 0), 1); + MCP3911_GAIN_MASK(i), + MCP3911_GAIN_VAL(i, 0), 1); if (ret) return ret; } @@ -550,8 +550,8 @@ static int mcp3911_probe(struct spi_device *spi) if (spi->irq > 0) { adc->trig = devm_iio_trigger_alloc(&spi->dev, "%s-dev%d", - indio_dev->name, - iio_device_id(indio_dev)); + indio_dev->name, + iio_device_id(indio_dev)); if (!adc->trig) return -ENOMEM; @@ -567,15 +567,16 @@ static int mcp3911_probe(struct spi_device *spi) * don't enable the interrupt to avoid extra load on the system. */ ret = devm_request_irq(&spi->dev, spi->irq, - &iio_trigger_generic_data_rdy_poll, IRQF_NO_AUTOEN | IRQF_ONESHOT, - indio_dev->name, adc->trig); + &iio_trigger_generic_data_rdy_poll, + IRQF_NO_AUTOEN | IRQF_ONESHOT, + indio_dev->name, adc->trig); if (ret) return ret; } ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev, - NULL, - mcp3911_trigger_handler, NULL); + NULL, + mcp3911_trigger_handler, NULL); if (ret) return ret; From patchwork Tue Aug 8 11:04:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcus Folkesson X-Patchwork-Id: 132591 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp2281352vqr; Tue, 8 Aug 2023 10:32:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHj2DDH9/NDu5c3xu+yYshKV47Q1mwckItpXej7gv0tDBTR8O0hEABtMeixamVcqNvDmn7k X-Received: by 2002:a17:907:78c1:b0:99b:499d:4635 with SMTP id kv1-20020a17090778c100b0099b499d4635mr206729ejc.75.1691515957093; Tue, 08 Aug 2023 10:32:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691515957; cv=none; d=google.com; s=arc-20160816; b=DvVHPXqfVE0i/8OJY3iRp0oLnH3qGUO0TaRsqj9pu0gliKYOeYnri3DAX2iD8l/82e MqntCcZUFWmA7AolXV759lf/1wq9j4aPF/771mzuEJC5vhCp7waAezWYrRxj6WkHsT9S NDlQL/pm981rxBqSM0Zy+8VCRy7NS4FbwMb5MNza7ghKQ+M8+YyQYGbF8R9k/NiwIkz6 bYbpGmdMN6KzdyekpYMqrwZkz30ZSi7hminm+VMUTrozSg6AeUAlJEnMw6oca8SO+wYh +1ECJjofzzMOjiS5RzO0FpZGYIrueHwFLGB90P/EmxpCFqODwJtScxubjxFE8QLju+TM H9/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=9XzHVfLhym0LuqU00BeE231PkgNHJaWfk33DM2IsORI=; fh=eoE64ugdk+S+1Ybc433G5Fz1KDZWL7DmgOSbU69JQKk=; b=wTh5Tk6nejsvgRCKHUQfst8eCjyPkApgPAl1FntyHZvmxFvCXoBmgnSF4V+8tNgsEs o2xFGVFJ/AHxUoL1Khh9u1e4cWZZKRXDho7kSS1PmzfFBXVVO6JQigbhuDUAVPy9hgIN zVeX60a1PH0bNuyBFm6eSVyNjTJqGyaWVE+KWHZXZosgkJnxviza3iaJAQmEMJ1vSKt0 MFL0s7fiaaaD7/6IUTZpCew9i06m4tYHkeU4G9p5vFAJRNaWN8k73/8YKXaz2RPnFhoA pCss/EhVIsmXn1azB1VMLw8LmQZ0KFzcmIugG2rJFW7g1QdOw+4S5wRX7nBm1S/NW9eO 7Z4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=enf3BrMM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z22-20020a170906715600b0099367350a8asi7875699ejj.899.2023.08.08.10.32.11; Tue, 08 Aug 2023 10:32:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=enf3BrMM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232674AbjHHQ0Y (ORCPT + 99 others); Tue, 8 Aug 2023 12:26:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231124AbjHHQY4 (ORCPT ); Tue, 8 Aug 2023 12:24:56 -0400 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6125CA24A; Tue, 8 Aug 2023 08:50:12 -0700 (PDT) Received: by mail-lf1-x132.google.com with SMTP id 2adb3069b0e04-4fe15bfb1adso9697855e87.0; Tue, 08 Aug 2023 08:50:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691509810; x=1692114610; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9XzHVfLhym0LuqU00BeE231PkgNHJaWfk33DM2IsORI=; b=enf3BrMMmAGArbTlryg9Vvltd9hvwZJlzyL4e83xsmj/oGQUB0m8oTyEaSTnwcrIlT ebOJv3KhV1gKKLN/RnUA0FdksW3VZS72JrhdXCeODY9PrTnLX0ObgP4aAxNQ+0RqHFgv tFx5j7+Lx1Wmjf0pUtoQ6472H+gqJKsW9prjzDJb8lnqRtj7GCUG0RTcaf5A5eL9W2up cjTm4cjLSMIxEHod0wHilmKeaIaQmX7m3vW6ACp31KsnbJFmlxh/YHZnPYGaCPJAmFHI I+LsFiS7zrhN/Lp7KaDzjmEq3pnlNGPfTNy/l5JK9flKRk5Gpg1x2a67ZxMlNsh3f9L+ 9+Rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691509810; x=1692114610; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9XzHVfLhym0LuqU00BeE231PkgNHJaWfk33DM2IsORI=; b=XS6dpjrMSb0CXpnjdBA4UGjqAOGDeq/bGAqFO4ep6C2E71UiH0rVPcnCRfOaNnV+B6 pSouuMhkkOWsQ08+rdHQmm/TpWod0xig2PITwkdlGasmPslKH9qRnHP4OLwRz9wmbivL gCIfhgQx5jN5odOXIZi1tnewJ+s3SF8R2NEJte74pj1zjaa5zLBfdyEKAww8VlCZ7u9M osdtkqC3qs9TloaYzoYij88Je1YaEA84z8YzRyERnpoVV0bs4smFMqeQ2tEkEhIgFQXP 8/JNQRzg0FGF5L/I1QgKPHUOMM66j5t8wDQdl/VR92OAh03pp73i4lhCG9769FweC+wa 8wdw== X-Gm-Message-State: AOJu0Yz1TsxMf1eWHa/PYq1QY0Eg4C6A777Jk+idPA2YlJsroMIc1fRY rU0+Cy+v5uNwuG6HV+ZJQ4MuJ0n7BzaHdiGq X-Received: by 2002:a05:6512:34d2:b0:4f8:7513:8cac with SMTP id w18-20020a05651234d200b004f875138cacmr6669366lfr.48.1691492574218; Tue, 08 Aug 2023 04:02:54 -0700 (PDT) Received: from localhost.localdomain (83-233-6-197.cust.bredband2.com. [83.233.6.197]) by smtp.gmail.com with ESMTPSA id q10-20020ac246ea000000b004fbad682ffesm1826587lfo.88.2023.08.08.04.02.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Aug 2023 04:02:53 -0700 (PDT) From: Marcus Folkesson To: Marcus Folkesson , Kent Gustavsson , Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Andy Shevchenko , Cosmin Tanislav , Arnd Bergmann , ChiYuan Huang , Haibo Chen , Ramona Bolboaca , Ibrahim Tilki , ChiaEn Wu , William Breathitt Gray Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 4/4] iio: adc: mcp3911: add support for the whole MCP39xx family Date: Tue, 8 Aug 2023 13:04:32 +0200 Message-Id: <20230808110432.240773-4-marcus.folkesson@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230808110432.240773-1-marcus.folkesson@gmail.com> References: <20230808110432.240773-1-marcus.folkesson@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773683036166808414 X-GMAIL-MSGID: 1773683036166808414 Microchip does have many similar chips, add support for those. The new supported chips are: - microchip,mcp3910 - microchip,mcp3912 - microchip,mcp3913 - microchip,mcp3914 - microchip,mcp3918 - microchip,mcp3919 Signed-off-by: Marcus Folkesson --- Notes: v2: - Use callbacks rather than matching against enum for determine chip variants v3: - Fix cosmetics v4: - Do not pollute output variable upon error in *_get_osr() functions. - Fix cosmetics drivers/iio/adc/Kconfig | 5 +- drivers/iio/adc/mcp3911.c | 459 +++++++++++++++++++++++++++++++++----- 2 files changed, 405 insertions(+), 59 deletions(-) diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig index eb2b09ef5d5b..9a9838430530 100644 --- a/drivers/iio/adc/Kconfig +++ b/drivers/iio/adc/Kconfig @@ -774,8 +774,9 @@ config MCP3911 select IIO_BUFFER select IIO_TRIGGERED_BUFFER help - Say yes here to build support for Microchip Technology's MCP3911 - analog to digital converter. + Say yes here to build support for Microchip Technology's MCP3910, + MCP3911, MCP3912, MCP3913, MCP3914, MCP3918 and MCP3919 + analog to digital converters. This driver can also be built as a module. If so, the module will be called mcp3911. diff --git a/drivers/iio/adc/mcp3911.c b/drivers/iio/adc/mcp3911.c index 8b465d2aad1a..c033e6d29650 100644 --- a/drivers/iio/adc/mcp3911.c +++ b/drivers/iio/adc/mcp3911.c @@ -61,12 +61,55 @@ #define MCP3911_REG_WRITE(reg, id) ((((reg) << 1) | ((id) << 6) | (0 << 0)) & 0xff) #define MCP3911_REG_MASK GENMASK(4, 1) -#define MCP3911_NUM_CHANNELS 2 #define MCP3911_NUM_SCALES 6 +/* Registers compatible with MCP3910 */ +#define MCP3910_REG_STATUSCOM 0x0c +#define MCP3910_STATUSCOM_READ GENMASK(23, 22) +#define MCP3910_STATUSCOM_DRHIZ BIT(20) + +#define MCP3910_REG_GAIN 0x0b + +#define MCP3910_REG_CONFIG0 0x0d +#define MCP3910_CONFIG0_EN_OFFCAL BIT(23) +#define MCP3910_CONFIG0_OSR GENMASK(15, 13) + +#define MCP3910_REG_CONFIG1 0x0e +#define MCP3910_CONFIG1_CLKEXT BIT(6) +#define MCP3910_CONFIG1_VREFEXT BIT(7) + +#define MCP3910_REG_OFFCAL_CH0 0x0f +#define MCP3910_OFFCAL(x) (MCP3910_REG_OFFCAL_CH0 + x * 6) + +/* Maximal number of channels used by the MCP39XX family */ +#define MCP39XX_MAX_NUM_CHANNELS 8 + static const int mcp3911_osr_table[] = { 32, 64, 128, 256, 512, 1024, 2048, 4096 }; static u32 mcp3911_scale_table[MCP3911_NUM_SCALES][2]; +enum mcp3911_id { + MCP3910, + MCP3911, + MCP3912, + MCP3913, + MCP3914, + MCP3918, + MCP3919, +}; + +struct mcp3911; +struct mcp3911_chip_info { + const struct iio_chan_spec *channels; + unsigned int num_channels; + + int (*config)(struct mcp3911 *adc); + int (*get_osr)(struct mcp3911 *adc, int *val); + int (*set_osr)(struct mcp3911 *adc, int val); + int (*get_offset)(struct mcp3911 *adc, int channel, int *val); + int (*set_offset)(struct mcp3911 *adc, int channel, int val); + int (*set_scale)(struct mcp3911 *adc, int channel, int val); +}; + struct mcp3911 { struct spi_device *spi; struct mutex lock; @@ -74,14 +117,15 @@ struct mcp3911 { struct clk *clki; u32 dev_addr; struct iio_trigger *trig; - u32 gain[MCP3911_NUM_CHANNELS]; + u32 gain[MCP39XX_MAX_NUM_CHANNELS]; + const struct mcp3911_chip_info *chip; struct { - u32 channels[MCP3911_NUM_CHANNELS]; + u32 channels[MCP39XX_MAX_NUM_CHANNELS]; s64 ts __aligned(8); } scan; u8 tx_buf __aligned(IIO_DMA_MINALIGN); - u8 rx_buf[MCP3911_NUM_CHANNELS * 3]; + u8 rx_buf[MCP39XX_MAX_NUM_CHANNELS * 3]; }; static int mcp3911_read(struct mcp3911 *adc, u8 reg, u32 *val, u8 len) @@ -126,6 +170,104 @@ static int mcp3911_update(struct mcp3911 *adc, u8 reg, u32 mask, return mcp3911_write(adc, reg, val, len); } +static int mcp3910_get_offset(struct mcp3911 *adc, int channel, int *val) +{ + return mcp3911_read(adc, MCP3910_OFFCAL(channel), val, 3); +} + +static int mcp3910_set_offset(struct mcp3911 *adc, int channel, int val) +{ + int ret; + + /* Write offset */ + ret = mcp3911_write(adc, MCP3910_OFFCAL(channel), val, 3); + if (ret) + return ret; + + /* Enable offset*/ + return mcp3911_update(adc, MCP3910_REG_CONFIG0, + MCP3910_CONFIG0_EN_OFFCAL, + MCP3910_CONFIG0_EN_OFFCAL, 3); +} + +static int mcp3911_get_offset(struct mcp3911 *adc, int channel, int *val) +{ + return mcp3911_read(adc, MCP3911_OFFCAL(channel), val, 3); +} + +static int mcp3911_set_offset(struct mcp3911 *adc, int channel, int val) +{ + int ret; + + /* Write offset */ + ret = mcp3911_write(adc, MCP3911_OFFCAL(channel), val, 3); + if (ret) + return ret; + + /* Enable offset */ + return mcp3911_update(adc, MCP3911_REG_STATUSCOM, + MCP3911_STATUSCOM_EN_OFFCAL, + MCP3911_STATUSCOM_EN_OFFCAL, 2); +} + +static int mcp3910_get_osr(struct mcp3911 *adc, int *val) +{ + int ret, osr; + + ret = mcp3911_read(adc, MCP3910_REG_CONFIG0, val, 3); + if (ret) + return ret; + + osr = FIELD_GET(MCP3910_CONFIG0_OSR, *val); + *val = 32 << osr; + return ret; +} + +static int mcp3910_set_osr(struct mcp3911 *adc, int val) +{ + int osr; + + osr = FIELD_PREP(MCP3910_CONFIG0_OSR, val); + return mcp3911_update(adc, MCP3910_REG_CONFIG0, + MCP3910_CONFIG0_OSR, osr, 3); +} + +static int mcp3911_set_osr(struct mcp3911 *adc, int val) +{ + int osr; + + osr = FIELD_PREP(MCP3911_CONFIG_OSR, val); + return mcp3911_update(adc, MCP3911_REG_CONFIG, + MCP3911_CONFIG_OSR, osr, 2); +} + +static int mcp3911_get_osr(struct mcp3911 *adc, int *val) +{ + int ret, osr; + + ret = mcp3911_read(adc, MCP3911_REG_CONFIG, val, 2); + if (ret) + return ret; + + osr = FIELD_GET(MCP3911_CONFIG_OSR, *val); + *val = 32 << osr; + return ret; +} + +static int mcp3910_set_scale(struct mcp3911 *adc, int channel, int val) +{ + return mcp3911_update(adc, MCP3910_REG_GAIN, + MCP3911_GAIN_MASK(channel), + MCP3911_GAIN_VAL(channel, val), 3); +} + +static int mcp3911_set_scale(struct mcp3911 *adc, int channel, int val) +{ + return mcp3911_update(adc, MCP3911_REG_GAIN, + MCP3911_GAIN_MASK(channel), + MCP3911_GAIN_VAL(channel, val), 1); +} + static int mcp3911_write_raw_get_fmt(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, long mask) @@ -182,20 +324,18 @@ static int mcp3911_read_raw(struct iio_dev *indio_dev, break; case IIO_CHAN_INFO_OFFSET: - ret = mcp3911_read(adc, - MCP3911_OFFCAL(channel->channel), val, 3); + + ret = adc->chip->get_offset(adc, channel->channel, val); if (ret) goto out; ret = IIO_VAL_INT; break; case IIO_CHAN_INFO_OVERSAMPLING_RATIO: - ret = mcp3911_read(adc, MCP3911_REG_CONFIG, val, 2); + ret = adc->chip->get_osr(adc, val); if (ret) goto out; - *val = FIELD_GET(MCP3911_CONFIG_OSR, *val); - *val = 32 << *val; ret = IIO_VAL_INT; break; @@ -226,9 +366,7 @@ static int mcp3911_write_raw(struct iio_dev *indio_dev, val2 == mcp3911_scale_table[i][1]) { adc->gain[channel->channel] = BIT(i); - ret = mcp3911_update(adc, MCP3911_REG_GAIN, - MCP3911_GAIN_MASK(channel->channel), - MCP3911_GAIN_VAL(channel->channel, i), 1); + ret = adc->chip->set_scale(adc, channel->channel, i); } } break; @@ -238,24 +376,13 @@ static int mcp3911_write_raw(struct iio_dev *indio_dev, goto out; } - /* Write offset */ - ret = mcp3911_write(adc, MCP3911_OFFCAL(channel->channel), val, - 3); - if (ret) - goto out; - - /* Enable offset*/ - ret = mcp3911_update(adc, MCP3911_REG_STATUSCOM, - MCP3911_STATUSCOM_EN_OFFCAL, - MCP3911_STATUSCOM_EN_OFFCAL, 2); + ret = adc->chip->set_offset(adc, channel->channel, val); break; case IIO_CHAN_INFO_OVERSAMPLING_RATIO: for (int i = 0; i < ARRAY_SIZE(mcp3911_osr_table); i++) { if (val == mcp3911_osr_table[i]) { - val = FIELD_PREP(MCP3911_CONFIG_OSR, i); - ret = mcp3911_update(adc, MCP3911_REG_CONFIG, MCP3911_CONFIG_OSR, - val, 2); + ret = adc->chip->set_osr(adc, i); break; } } @@ -326,12 +453,60 @@ static int mcp3911_calc_scale_table(struct mcp3911 *adc) }, \ } +static const struct iio_chan_spec mcp3910_channels[] = { + MCP3911_CHAN(0), + MCP3911_CHAN(1), + IIO_CHAN_SOFT_TIMESTAMP(2), +}; + static const struct iio_chan_spec mcp3911_channels[] = { MCP3911_CHAN(0), MCP3911_CHAN(1), IIO_CHAN_SOFT_TIMESTAMP(2), }; +static const struct iio_chan_spec mcp3912_channels[] = { + MCP3911_CHAN(0), + MCP3911_CHAN(1), + MCP3911_CHAN(2), + MCP3911_CHAN(3), + IIO_CHAN_SOFT_TIMESTAMP(4), +}; + +static const struct iio_chan_spec mcp3913_channels[] = { + MCP3911_CHAN(0), + MCP3911_CHAN(1), + MCP3911_CHAN(2), + MCP3911_CHAN(3), + MCP3911_CHAN(4), + MCP3911_CHAN(5), + IIO_CHAN_SOFT_TIMESTAMP(6), +}; + +static const struct iio_chan_spec mcp3914_channels[] = { + MCP3911_CHAN(0), + MCP3911_CHAN(1), + MCP3911_CHAN(2), + MCP3911_CHAN(3), + MCP3911_CHAN(4), + MCP3911_CHAN(5), + MCP3911_CHAN(6), + MCP3911_CHAN(7), + IIO_CHAN_SOFT_TIMESTAMP(8), +}; + +static const struct iio_chan_spec mcp3918_channels[] = { + MCP3911_CHAN(0), + IIO_CHAN_SOFT_TIMESTAMP(1), +}; + +static const struct iio_chan_spec mcp3919_channels[] = { + MCP3911_CHAN(0), + MCP3911_CHAN(1), + MCP3911_CHAN(2), + IIO_CHAN_SOFT_TIMESTAMP(3), +}; + static irqreturn_t mcp3911_trigger_handler(int irq, void *p) { struct iio_poll_func *pf = p; @@ -343,7 +518,7 @@ static irqreturn_t mcp3911_trigger_handler(int irq, void *p) .len = 1, }, { .rx_buf = adc->rx_buf, - .len = sizeof(adc->rx_buf), + .len = (adc->chip->num_channels - 1) * 3, }, }; int scan_index; @@ -383,26 +558,9 @@ static const struct iio_info mcp3911_info = { static int mcp3911_config(struct mcp3911 *adc) { - struct device *dev = &adc->spi->dev; u32 regval; int ret; - ret = device_property_read_u32(dev, "microchip,device-addr", &adc->dev_addr); - - /* - * Fallback to "device-addr" due to historical mismatch between - * dt-bindings and implementation - */ - if (ret) - device_property_read_u32(dev, "device-addr", &adc->dev_addr); - if (adc->dev_addr > 3) { - dev_err(&adc->spi->dev, - "invalid device address (%i). Must be in range 0-3.\n", - adc->dev_addr); - return -EINVAL; - } - dev_dbg(&adc->spi->dev, "use device address %i\n", adc->dev_addr); - ret = mcp3911_read(adc, MCP3911_REG_CONFIG, ®val, 2); if (ret) return ret; @@ -439,7 +597,101 @@ static int mcp3911_config(struct mcp3911 *adc) regval &= ~MCP3911_STATUSCOM_READ; regval |= FIELD_PREP(MCP3911_STATUSCOM_READ, 0x02); - return mcp3911_write(adc, MCP3911_REG_STATUSCOM, regval, 2); + regval &= ~MCP3911_STATUSCOM_DRHIZ; + if (device_property_read_bool(&adc->spi->dev, "microchip,data-ready-hiz")) + regval |= FIELD_PREP(MCP3911_STATUSCOM_DRHIZ, 0); + else + regval |= FIELD_PREP(MCP3911_STATUSCOM_DRHIZ, 1); + + /* Disable offset to ignore any old values in offset register*/ + regval &= ~MCP3911_STATUSCOM_EN_OFFCAL; + + ret = mcp3911_write(adc, MCP3911_REG_STATUSCOM, regval, 2); + if (ret) + return ret; + + /* Set gain to 1 for all channels */ + ret = mcp3911_read(adc, MCP3911_REG_GAIN, ®val, 1); + if (ret) + return ret; + + for (int i = 0; i < adc->chip->num_channels - 1; i++) { + adc->gain[i] = 1; + regval &= ~MCP3911_GAIN_MASK(i); + } + + return mcp3911_write(adc, MCP3911_REG_GAIN, regval, 1); +} + +static int mcp3910_config(struct mcp3911 *adc) +{ + u32 regval; + int ret; + + ret = mcp3911_read(adc, MCP3910_REG_CONFIG1, ®val, 3); + if (ret) + return ret; + + regval &= ~MCP3910_CONFIG1_VREFEXT; + if (adc->vref) { + dev_dbg(&adc->spi->dev, "use external voltage reference\n"); + regval |= FIELD_PREP(MCP3910_CONFIG1_VREFEXT, 1); + } else { + dev_dbg(&adc->spi->dev, + "use internal voltage reference (1.2V)\n"); + regval |= FIELD_PREP(MCP3910_CONFIG1_VREFEXT, 0); + } + + regval &= ~MCP3910_CONFIG1_CLKEXT; + if (adc->clki) { + dev_dbg(&adc->spi->dev, "use external clock as clocksource\n"); + regval |= FIELD_PREP(MCP3910_CONFIG1_CLKEXT, 1); + } else { + dev_dbg(&adc->spi->dev, + "use crystal oscillator as clocksource\n"); + regval |= FIELD_PREP(MCP3910_CONFIG1_CLKEXT, 0); + } + + ret = mcp3911_write(adc, MCP3910_REG_CONFIG1, regval, 3); + if (ret) + return ret; + + ret = mcp3911_read(adc, MCP3910_REG_STATUSCOM, ®val, 3); + if (ret) + return ret; + + /* Address counter incremented, cycle through register types */ + regval &= ~MCP3910_STATUSCOM_READ; + regval |= FIELD_PREP(MCP3910_STATUSCOM_READ, 0x02); + + + regval &= ~MCP3910_STATUSCOM_DRHIZ; + if (device_property_read_bool(&adc->spi->dev, "microchip,data-ready-hiz")) + regval |= FIELD_PREP(MCP3910_STATUSCOM_DRHIZ, 0); + else + regval |= FIELD_PREP(MCP3910_STATUSCOM_DRHIZ, 1); + + ret = mcp3911_write(adc, MCP3910_REG_STATUSCOM, regval, 3); + if (ret) + return ret; + + /* Set gain to 1 for all channels */ + ret = mcp3911_read(adc, MCP3910_REG_GAIN, ®val, 3); + if (ret) + return ret; + + for (int i = 0; i < adc->chip->num_channels - 1; i++) { + adc->gain[i] = 1; + regval &= ~MCP3911_GAIN_MASK(i); + } + ret = mcp3911_write(adc, MCP3910_REG_GAIN, regval, 3); + if (ret) + return ret; + + /* Disable offset to ignore any old values in offset register */ + return mcp3911_update(adc, MCP3910_REG_CONFIG0, + MCP3910_CONFIG0_EN_OFFCAL, + MCP3910_CONFIG0_EN_OFFCAL, 3); } static void mcp3911_cleanup_regulator(void *vref) @@ -476,6 +728,7 @@ static int mcp3911_probe(struct spi_device *spi) adc = iio_priv(indio_dev); adc->spi = spi; + adc->chip = spi_get_device_match_data(spi); adc->vref = devm_regulator_get_optional(&spi->dev, "vref"); if (IS_ERR(adc->vref)) { @@ -511,16 +764,24 @@ static int mcp3911_probe(struct spi_device *spi) } } - ret = mcp3911_config(adc); + ret = device_property_read_u32(&spi->dev, "microchip,device-addr", &adc->dev_addr); + + /* + * Fallback to "device-addr" due to historical mismatch between + * dt-bindings and implementation. + */ if (ret) - return ret; + device_property_read_u32(&spi->dev, "device-addr", &adc->dev_addr); + if (adc->dev_addr > 3) { + dev_err(&spi->dev, + "invalid device address (%i). Must be in range 0-3.\n", + adc->dev_addr); + return -EINVAL; + } + dev_dbg(&spi->dev, "use device address %i\n", adc->dev_addr); - if (device_property_read_bool(&spi->dev, "microchip,data-ready-hiz")) - ret = mcp3911_update(adc, MCP3911_REG_STATUSCOM, MCP3911_STATUSCOM_DRHIZ, - 0, 2); - else - ret = mcp3911_update(adc, MCP3911_REG_STATUSCOM, MCP3911_STATUSCOM_DRHIZ, - MCP3911_STATUSCOM_DRHIZ, 2); + + ret = adc->chip->config(adc); if (ret) return ret; @@ -529,7 +790,7 @@ static int mcp3911_probe(struct spi_device *spi) return ret; /* Set gain to 1 for all channels */ - for (int i = 0; i < MCP3911_NUM_CHANNELS; i++) { + for (int i = 0; i < adc->chip->num_channels - 1; i++) { adc->gain[i] = 1; ret = mcp3911_update(adc, MCP3911_REG_GAIN, MCP3911_GAIN_MASK(i), @@ -543,8 +804,8 @@ static int mcp3911_probe(struct spi_device *spi) indio_dev->info = &mcp3911_info; spi_set_drvdata(spi, indio_dev); - indio_dev->channels = mcp3911_channels; - indio_dev->num_channels = ARRAY_SIZE(mcp3911_channels); + indio_dev->channels = adc->chip->channels; + indio_dev->num_channels = adc->chip->num_channels; mutex_init(&adc->lock); @@ -583,14 +844,98 @@ static int mcp3911_probe(struct spi_device *spi) return devm_iio_device_register(&spi->dev, indio_dev); } +static const struct mcp3911_chip_info mcp3911_chip_info[] = { + [MCP3910] = { + .channels = mcp3910_channels, + .num_channels = ARRAY_SIZE(mcp3910_channels), + .config = mcp3910_config, + .get_osr = mcp3910_get_osr, + .set_osr = mcp3910_set_osr, + .get_offset = mcp3910_get_offset, + .set_offset = mcp3910_set_offset, + .set_scale = mcp3910_set_scale, + }, + [MCP3911] = { + .channels = mcp3911_channels, + .num_channels = ARRAY_SIZE(mcp3911_channels), + .config = mcp3911_config, + .get_osr = mcp3911_get_osr, + .set_osr = mcp3911_set_osr, + .get_offset = mcp3911_get_offset, + .set_offset = mcp3911_set_offset, + .set_scale = mcp3911_set_scale, + }, + [MCP3912] = { + .channels = mcp3912_channels, + .num_channels = ARRAY_SIZE(mcp3912_channels), + .config = mcp3910_config, + .get_osr = mcp3910_get_osr, + .set_osr = mcp3910_set_osr, + .get_offset = mcp3910_get_offset, + .set_offset = mcp3910_set_offset, + .set_scale = mcp3910_set_scale, + }, + [MCP3913] = { + .channels = mcp3913_channels, + .num_channels = ARRAY_SIZE(mcp3913_channels), + .config = mcp3910_config, + .get_osr = mcp3910_get_osr, + .set_osr = mcp3910_set_osr, + .get_offset = mcp3910_get_offset, + .set_offset = mcp3910_set_offset, + .set_scale = mcp3910_set_scale, + }, + [MCP3914] = { + .channels = mcp3914_channels, + .num_channels = ARRAY_SIZE(mcp3914_channels), + .config = mcp3910_config, + .get_osr = mcp3910_get_osr, + .set_osr = mcp3910_set_osr, + .get_offset = mcp3910_get_offset, + .set_offset = mcp3910_set_offset, + .set_scale = mcp3910_set_scale, + }, + [MCP3918] = { + .channels = mcp3918_channels, + .num_channels = ARRAY_SIZE(mcp3918_channels), + .config = mcp3910_config, + .get_osr = mcp3910_get_osr, + .set_osr = mcp3910_set_osr, + .get_offset = mcp3910_get_offset, + .set_offset = mcp3910_set_offset, + .set_scale = mcp3910_set_scale, + }, + [MCP3919] = { + .channels = mcp3919_channels, + .num_channels = ARRAY_SIZE(mcp3919_channels), + .config = mcp3910_config, + .get_osr = mcp3910_get_osr, + .set_osr = mcp3910_set_osr, + .get_offset = mcp3910_get_offset, + .set_offset = mcp3910_set_offset, + .set_scale = mcp3910_set_scale, + }, +}; static const struct of_device_id mcp3911_dt_ids[] = { - { .compatible = "microchip,mcp3911" }, + { .compatible = "microchip,mcp3910", .data = &mcp3911_chip_info[MCP3910] }, + { .compatible = "microchip,mcp3911", .data = &mcp3911_chip_info[MCP3911] }, + { .compatible = "microchip,mcp3912", .data = &mcp3911_chip_info[MCP3912] }, + { .compatible = "microchip,mcp3913", .data = &mcp3911_chip_info[MCP3913] }, + { .compatible = "microchip,mcp3914", .data = &mcp3911_chip_info[MCP3914] }, + { .compatible = "microchip,mcp3918", .data = &mcp3911_chip_info[MCP3918] }, + { .compatible = "microchip,mcp3919", .data = &mcp3911_chip_info[MCP3919] }, { } }; MODULE_DEVICE_TABLE(of, mcp3911_dt_ids); static const struct spi_device_id mcp3911_id[] = { - { "mcp3911", 0 }, + { "mcp3910", (kernel_ulong_t)&mcp3911_chip_info[MCP3910] }, + { "mcp3911", (kernel_ulong_t)&mcp3911_chip_info[MCP3911] }, + { "mcp3912", (kernel_ulong_t)&mcp3911_chip_info[MCP3912] }, + { "mcp3913", (kernel_ulong_t)&mcp3911_chip_info[MCP3913] }, + { "mcp3914", (kernel_ulong_t)&mcp3911_chip_info[MCP3914] }, + { "mcp3918", (kernel_ulong_t)&mcp3911_chip_info[MCP3918] }, + { "mcp3919", (kernel_ulong_t)&mcp3911_chip_info[MCP3919] }, { } }; MODULE_DEVICE_TABLE(spi, mcp3911_id);