Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp411408imw; Wed, 13 Jul 2022 00:08:18 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sIUHfFyxkppJaHLXP2w/OmqF8TEnLNB8PaeZeljoEtnbQ3So1HMJjrQ9RuYHAexyXZM9Dj X-Received: by 2002:a17:903:32c1:b0:16c:35b2:18c3 with SMTP id i1-20020a17090332c100b0016c35b218c3mr1882795plr.126.1657696098554; Wed, 13 Jul 2022 00:08:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657696098; cv=none; d=google.com; s=arc-20160816; b=VumLmYBKiEjh2oxnFNcaQUyk/IYYBPyzACbwBIfZYpc7WWRTS0i4yQEA0PtLQ0iLP/ wV/+yn+QAGbB3f6wCWP/zqY+kROmxT7o4UATOwi5ZzrJEi2Fz06uD1b6OdzZm//2dbne 9yECNnKx0MQTVbD0Kuqt4ZPObK6cal+QqO72gfyazwT8g5uPzhZfFvrN4h2AFB9Ha51J WS+LqkH0zBWKUVcHHlChzEfP18TCwI9JDWA/WKZakh84z/h4YGYrNyGZichJ06PBd7Az 2pATqX635VMxdBoBfvaQAt8pcaT3tCgl29yIM9g2zwhxjjGvPXs7Jog5zRFZUzfRbqA8 bXGw== 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; bh=EFXlmq2T1/QUexMwUuo1OUZBpy9b9iALV/EofUohiog=; b=r7KqRRvjzORPQWh9PNetGmQkN9LC8pxtiSOKSW6DeZh0aYQ5Oh6onRHRPmifqe1BCj jkqO00KYCjA37ynWKS3ToRvie1OQn4wNhbKnzEO8O74gfpwRRr1DpQl7nuPB5u3ERXcV ECeYXxT7bvRflvPFA6X2suv2TO4PgdBMoqDu2V19XBJiwbFBdc4b+dqcQeQHn1l73f7Q H7r0cnsURbN1saQTyP7YX2xd5Bmh4SlWsyJlXOf/2VbHwVZMWxw7mNHXswH37vejvEYz vdoGlJZ56wOFGiK42nIzLgLvnprnEo9Y6e/ZI0yjXaXtd76phGfxQoZoTq8QPAVAOES6 bDzA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id oc4-20020a17090b1c0400b001efc348685fsi1904052pjb.69.2022.07.13.00.08.06; Wed, 13 Jul 2022 00:08:18 -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; 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=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234466AbiGMHFj (ORCPT + 99 others); Wed, 13 Jul 2022 03:05:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230509AbiGMHF3 (ORCPT ); Wed, 13 Jul 2022 03:05:29 -0400 Received: from maillog.nuvoton.com (maillog.nuvoton.com [202.39.227.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id AAC37E2A03; Wed, 13 Jul 2022 00:05:24 -0700 (PDT) Received: from NTHCCAS04.nuvoton.com (NTHCCAS04.nuvoton.com [10.1.8.29]) by maillog.nuvoton.com (Postfix) with ESMTP id 6F7471C80D3B; Wed, 13 Jul 2022 15:05:23 +0800 (CST) Received: from NTHCCAS03.nuvoton.com (10.1.20.28) by NTHCCAS04.nuvoton.com (10.1.8.29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Wed, 13 Jul 2022 15:05:23 +0800 Received: from NTHCCAS04.nuvoton.com (10.1.8.29) by NTHCCAS03.nuvoton.com (10.1.20.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1847.3; Wed, 13 Jul 2022 15:05:22 +0800 Received: from taln60.nuvoton.co.il (10.191.1.180) by NTHCCAS04.nuvoton.com (10.1.12.25) with Microsoft SMTP Server id 15.1.2176.2 via Frontend Transport; Wed, 13 Jul 2022 15:05:22 +0800 Received: by taln60.nuvoton.co.il (Postfix, from userid 10070) id 7FB8F63A4D; Wed, 13 Jul 2022 10:05:21 +0300 (IDT) From: Tomer Maimon To: , , , , , , , , , , , CC: , , , , Tomer Maimon Subject: [PATCH v2 2/2] iio: adc: npcm: Add NPCM8XX support Date: Wed, 13 Jul 2022 10:05:17 +0300 Message-ID: <20220713070517.172852-3-tmaimon77@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220713070517.172852-1-tmaimon77@gmail.com> References: <20220713070517.172852-1-tmaimon77@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=0.5 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FORGED_GMAIL_RCVD,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,NML_ADSP_CUSTOM_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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 Adding ADC NPCM8XX support to NPCM ADC driver. ADC NPCM8XX uses a different resolution and voltage reference. As part of adding NPCM8XX support: - Add NPCM8XX specific compatible string. - Add data to handle architecture-specific ADC parameters. Signed-off-by: Tomer Maimon --- drivers/iio/adc/npcm_adc.c | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/drivers/iio/adc/npcm_adc.c b/drivers/iio/adc/npcm_adc.c index f7bc0bb7f112..406038b5c0d6 100644 --- a/drivers/iio/adc/npcm_adc.c +++ b/drivers/iio/adc/npcm_adc.c @@ -16,6 +16,12 @@ #include #include +struct npcm_adc_info { + u32 data_mask; + u32 internal_vref; + u32 res_bits; +}; + struct npcm_adc { bool int_status; u32 adc_sample_hz; @@ -34,6 +40,7 @@ struct npcm_adc { * has finished. */ struct mutex lock; + struct npcm_adc_info *data; }; /* ADC registers */ @@ -52,13 +59,21 @@ struct npcm_adc { #define NPCM_ADCCON_CH(x) ((x) << 24) #define NPCM_ADCCON_DIV_SHIFT 1 #define NPCM_ADCCON_DIV_MASK GENMASK(8, 1) -#define NPCM_ADC_DATA_MASK(x) ((x) & GENMASK(9, 0)) #define NPCM_ADC_ENABLE (NPCM_ADCCON_ADC_EN | NPCM_ADCCON_ADC_INT_EN) /* ADC General Definition */ -#define NPCM_RESOLUTION_BITS 10 -#define NPCM_INT_VREF_MV 2000 +static const struct npcm_adc_info npxm7xx_adc_info = { + .data_mask = GENMASK(9, 0), + .internal_vref = 2048, + .res_bits = 10, +}; + +static const struct npcm_adc_info npxm8xx_adc_info = { + .data_mask = GENMASK(11, 0), + .internal_vref = 1229, + .res_bits = 12, +}; #define NPCM_ADC_CHAN(ch) { \ .type = IIO_VOLTAGE, \ @@ -129,7 +144,8 @@ static int npcm_adc_read(struct npcm_adc *info, int *val, u8 channel) if (ret < 0) return ret; - *val = NPCM_ADC_DATA_MASK(ioread32(info->regs + NPCM_ADCDATA)); + *val = ioread32(info->regs + NPCM_ADCDATA); + *val &= info->data->data_mask; return 0; } @@ -157,9 +173,9 @@ static int npcm_adc_read_raw(struct iio_dev *indio_dev, vref_uv = regulator_get_voltage(info->vref); *val = vref_uv / 1000; } else { - *val = NPCM_INT_VREF_MV; + *val = info->data->internal_vref; } - *val2 = NPCM_RESOLUTION_BITS; + *val2 = info->data->res_bits; return IIO_VAL_FRACTIONAL_LOG2; case IIO_CHAN_INFO_SAMP_FREQ: *val = info->adc_sample_hz; @@ -176,7 +192,8 @@ static const struct iio_info npcm_adc_iio_info = { }; static const struct of_device_id npcm_adc_match[] = { - { .compatible = "nuvoton,npcm750-adc", }, + { .compatible = "nuvoton,npcm750-adc", .data = &npxm7xx_adc_info}, + { .compatible = "nuvoton,npcm845-adc", .data = &npxm8xx_adc_info}, { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, npcm_adc_match); @@ -196,6 +213,10 @@ static int npcm_adc_probe(struct platform_device *pdev) return -ENOMEM; info = iio_priv(indio_dev); + info->data = (struct npcm_adc_info *)device_get_match_data(dev); + if (!info->data) + return -EINVAL; + mutex_init(&info->lock); info->dev = &pdev->dev; -- 2.33.0