From patchwork Thu Mar 7 15:28:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Popa X-Patchwork-Id: 10843207 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C01331390 for ; Thu, 7 Mar 2019 15:29:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AA2A32DAA1 for ; Thu, 7 Mar 2019 15:29:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9BF152DED9; Thu, 7 Mar 2019 15:29:08 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 9F95B2DAA1 for ; Thu, 7 Mar 2019 15:29:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726415AbfCGP3H (ORCPT ); Thu, 7 Mar 2019 10:29:07 -0500 Received: from mail-eopbgr740084.outbound.protection.outlook.com ([40.107.74.84]:9114 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726294AbfCGP3H (ORCPT ); Thu, 7 Mar 2019 10:29:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=analog.onmicrosoft.com; s=selector1-analog-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=EDvUUatkmMXxI+RdV2cY2CDoFUP6eD8k3dBd/yOiLcA=; b=skrYXAjPEV7Z6Ahp94Hrflh4YQNwKFKly+NuNFyGX+J1veVPSuScyJhm74p1Dvq2KYaYeWaAlfnFXkA+ZUOGI7HLircfpsA23weJ4/YDn5pqwOUawWxraCFpDMtKT4GCxAr6A+wxw4SXOR91Y7bf5V7ztqryi0ybizWN/zlP4UY= Received: from DM5PR03CA0035.namprd03.prod.outlook.com (2603:10b6:4:3b::24) by SN2PR03MB2272.namprd03.prod.outlook.com (2603:10b6:804:d::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1665.19; Thu, 7 Mar 2019 15:28:58 +0000 Received: from BL2NAM02FT056.eop-nam02.prod.protection.outlook.com (2a01:111:f400:7e46::207) by DM5PR03CA0035.outlook.office365.com (2603:10b6:4:3b::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1686.16 via Frontend Transport; Thu, 7 Mar 2019 15:28:57 +0000 Authentication-Results: spf=pass (sender IP is 137.71.25.55) smtp.mailfrom=analog.com; gmx.de; dkim=none (message not signed) header.d=none;gmx.de; dmarc=bestguesspass action=none header.from=analog.com; Received-SPF: Pass (protection.outlook.com: domain of analog.com designates 137.71.25.55 as permitted sender) receiver=protection.outlook.com; client-ip=137.71.25.55; helo=nwd2mta1.analog.com; Received: from nwd2mta1.analog.com (137.71.25.55) by BL2NAM02FT056.mail.protection.outlook.com (10.152.77.221) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.1643.11 via Frontend Transport; Thu, 7 Mar 2019 15:28:57 +0000 Received: from NWD2HUBCAS7.ad.analog.com (nwd2hubcas7.ad.analog.com [10.64.69.107]) by nwd2mta1.analog.com (8.13.8/8.13.8) with ESMTP id x27FSubI019369 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=OK); Thu, 7 Mar 2019 07:28:57 -0800 Received: from linux.analog.com (10.32.224.122) by NWD2HUBCAS7.ad.analog.com (10.64.69.107) with Microsoft SMTP Server id 14.3.408.0; Thu, 7 Mar 2019 10:28:56 -0500 From: Stefan Popa To: CC: , , , , , , Stefan Popa Subject: [PATCH 1/2] iio: imu: adis16480: Add support for external clock Date: Thu, 7 Mar 2019 17:28:32 +0200 Message-ID: <1551972512-15041-1-git-send-email-stefan.popa@analog.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-ADIRoutedOnPrem: True X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:137.71.25.55;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(396003)(346002)(39860400002)(376002)(136003)(2980300002)(189003)(199004)(47776003)(6916009)(7696005)(336012)(186003)(7636002)(50226002)(8676002)(246002)(5660300002)(6666004)(305945005)(44832011)(426003)(486006)(30864003)(2616005)(476003)(126002)(356004)(8936002)(48376002)(2906002)(72206003)(106002)(54906003)(478600001)(316002)(16586007)(50466002)(77096007)(51416003)(26005)(4326008)(107886003)(36756003)(53416004)(106466001)(2351001);DIR:OUT;SFP:1101;SCL:1;SRVR:SN2PR03MB2272;H:nwd2mta1.analog.com;FPR:;SPF:Pass;LANG:en;PTR:nwd2mail10.analog.com;MX:1;A:1; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6165e84a-0460-4dca-107d-08d6a3119dda X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(5600127)(711020)(4605104)(4608103)(4709054)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060);SRVR:SN2PR03MB2272; X-MS-TrafficTypeDiagnostic: SN2PR03MB2272: X-Microsoft-Exchange-Diagnostics: 1;SN2PR03MB2272;20:vSd9bnc3a5RY248SaZAF+PMfl7M6hmZfv4J5aNcMMi0crvUM7+QKnX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SZ71R5ezS584VPvr1SBlBa7FeiZSpWO5tEXmGpb7FaAcK4d6ZcDNrK0kUOJ2FJRE+C2uLVhVAQFDTi3q2HmalWujxNmXKjY65Sq8NnwEXOuyTjn9bANiLUgYebmlzCCmMw/bYCz9UjmlddD1dbDmU0q11lFxquBEjFTjB0Ba8SpSEtkrKa+XmFuJfdza4rfdjZKoSILjES3FX6n53f5i3o0fhJr86OhjAcns/fp4cT3vwAnl6QbmeZC2ujA+TCSmZ3pbu8JDu4wm4+LhWu/UbED6ldVa6i/bNpMLHrZeMj1GYjqYG9h29yPv5wDNLa2SRAvUuVT/1ePAsb1PMVm87oucw2XMg0PDRqqFNl0WnbjKlqXjzyfuddmVyfgIKKN0OSHFpAIJ2r+8tE4W4tUxH5xtkM0/r7vv8nsEvY9FDjMBo35brbM1l9h9NscKKiRYiStdFPPAQs29rSHYjzzCWUu9NIA6i+qDidfvvMIjB/YOuQ== X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: F1oZxKwMvCJNhg7puwZ6cxrWfeTLwRXFwSLimSQK7FG92DDhZMz/sG+dvRBCua7CsNkF0XyFDjA4LUL3EjUgPqN/mr1tWMai4zQQ52c6+3Uu4Ivl30Swt7Lun8mmkRwUkBTftLELHafN3pZm7JtCjxTEXTc431ldGgoSRKfxRVhRgjX/8sBPFJ+VpRMvM8pVI5TP7cd8IJrU15+OH6pEanG2F4foNCnvE3K5ZbZ42vcdy3td0qnvzvBhf0/BB4swB5FMSNkWHSLcA85MU7gx3MwT3d+lUmj0JYvcVB07qdg1Bd0ULr6Yke7V9ABaIvzqFUzyoFLpGqPc+b37K8/d+5B+U7xTEVHf5sb/cHUNJuzwGffp/kc5QlyJ/2fLrst90DmmXra326UsaAuZlmfkXaZSHJTrnMXBMJVPzzTK7Oc= X-OriginatorOrg: analog.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Mar 2019 15:28:57.6508 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6165e84a-0460-4dca-107d-08d6a3119dda X-MS-Exchange-CrossTenant-Id: eaa689b4-8f87-40e0-9c6f-7228de4d754a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=eaa689b4-8f87-40e0-9c6f-7228de4d754a;Ip=[137.71.25.55];Helo=[nwd2mta1.analog.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN2PR03MB2272 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Inertial sensor data collection and processing can be controlled by configuring one of the DIOx lines as an external clock input. This option is available for all devices supported by this driver. However, only adis1649x devices support different modes for the external clock. Sync mode is supported by all devices. In this mode, the output data rate is equal with the clock frequency divided by DEC_RATE + 1. This mode of calculation is similar with the case when the internal clock is used. Pulse Per Second (PPS) Mode, is only supported by adis1649x devices. In this mode, the output data rate is equal to the product of the external clock frequency and the scale factor in the SYNC_SCALE register. This patch uses the "clock-names" property to enable the external clock in one of the two supported modes: "sync" or "pps". This property is optional. If it is not specified, the internal clock is used. This patch also offers the option to select the DIOx line to be used as an external clock input via the custom "adi,ext-clk-pin" property. If this field is left empty, DIO2 is assigned as default external clock input pin. Each DIOx pin supports only one function at a time (data ready line selection or external clock input). Signed-off-by: Stefan Popa --- drivers/iio/imu/adis16480.c | 186 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 179 insertions(+), 7 deletions(-) diff --git a/drivers/iio/imu/adis16480.c b/drivers/iio/imu/adis16480.c index 28cece3..3a93a85 100644 --- a/drivers/iio/imu/adis16480.c +++ b/drivers/iio/imu/adis16480.c @@ -9,6 +9,7 @@ * */ +#include #include #include #include @@ -99,6 +100,12 @@ #define ADIS16480_REG_FIRM_DM ADIS16480_REG(0x03, 0x7A) #define ADIS16480_REG_FIRM_Y ADIS16480_REG(0x03, 0x7C) +/* + * External clock scaling in PPS mode. + * Available only for ADIS1649x devices + */ +#define ADIS16495_REG_SYNC_SCALE ADIS16480_REG(0x03, 0x10) + #define ADIS16480_REG_SERIAL_NUM ADIS16480_REG(0x04, 0x20) /* Each filter coefficent bank spans two pages */ @@ -116,6 +123,12 @@ #define ADIS16480_DRDY_POL(x) FIELD_PREP(ADIS16480_DRDY_POL_MSK, x) #define ADIS16480_DRDY_EN_MSK BIT(3) #define ADIS16480_DRDY_EN(x) FIELD_PREP(ADIS16480_DRDY_EN_MSK, x) +#define ADIS16480_SYNC_SEL_MSK GENMASK(5, 4) +#define ADIS16480_SYNC_SEL(x) FIELD_PREP(ADIS16480_SYNC_SEL_MSK, x) +#define ADIS16480_SYNC_EN_MSK BIT(7) +#define ADIS16480_SYNC_EN(x) FIELD_PREP(ADIS16480_SYNC_EN_MSK, x) +#define ADIS16480_SYNC_MODE_MSK BIT(8) +#define ADIS16480_SYNC_MODE(x) FIELD_PREP(ADIS16480_SYNC_MODE_MSK, x) struct adis16480_chip_info { unsigned int num_channels; @@ -128,6 +141,7 @@ struct adis16480_chip_info { unsigned int int_clk; unsigned int max_dec_rate; const unsigned int *filter_freqs; + bool has_pps_clk_mode; }; enum adis16480_int_pin { @@ -137,10 +151,19 @@ enum adis16480_int_pin { ADIS16480_PIN_DIO4 }; +enum adis16480_clock_mode { + ADIS16480_CLK_SYNC, + ADIS16480_CLK_PPS, + ADIS16480_CLK_INT +}; + struct adis16480 { const struct adis16480_chip_info *chip_info; struct adis adis; + struct clk *ext_clk; + enum adis16480_clock_mode clk_mode; + unsigned int clk_freq; }; static const char * const adis16480_int_pin_names[4] = { @@ -296,20 +319,34 @@ static int adis16480_debugfs_init(struct iio_dev *indio_dev) static int adis16480_set_freq(struct iio_dev *indio_dev, int val, int val2) { struct adis16480 *st = iio_priv(indio_dev); - unsigned int t; + unsigned int t, reg; t = val * 1000 + val2 / 1000; if (t <= 0) return -EINVAL; - t = st->chip_info->int_clk / t; + /* + * When using PPS mode, the rate of data collection is equal to the + * product of the external clock frequency and the scale factor in the + * SYNC_SCALE register. + * When using sync mode, or internal clock, the output data rate is + * equal with the clock frequency divided by DEC_RATE + 1. + */ + if (st->clk_mode == ADIS16480_CLK_PPS) { + t = t / st->clk_freq; + reg = ADIS16495_REG_SYNC_SCALE; + } else { + t = st->clk_freq / t; + reg = ADIS16480_REG_DEC_RATE; + } + if (t > st->chip_info->max_dec_rate) t = st->chip_info->max_dec_rate; - if (t != 0) + if ((t != 0) && (st->clk_mode != ADIS16480_CLK_PPS)) t--; - return adis_write_reg_16(&st->adis, ADIS16480_REG_DEC_RATE, t); + return adis_write_reg_16(&st->adis, reg, t); } static int adis16480_get_freq(struct iio_dev *indio_dev, int *val, int *val2) @@ -318,12 +355,29 @@ static int adis16480_get_freq(struct iio_dev *indio_dev, int *val, int *val2) uint16_t t; int ret; unsigned freq; + unsigned int reg; + + if (st->clk_mode == ADIS16480_CLK_PPS) + reg = ADIS16495_REG_SYNC_SCALE; + else + reg = ADIS16480_REG_DEC_RATE; - ret = adis_read_reg_16(&st->adis, ADIS16480_REG_DEC_RATE, &t); + ret = adis_read_reg_16(&st->adis, reg, &t); if (ret < 0) return ret; - freq = st->chip_info->int_clk / (t + 1); + /* + * When using PPS mode, the rate of data collection is equal to the + * product of the external clock frequency and the scale factor in the + * SYNC_SCALE register. + * When using sync mode, or internal clock, the output data rate is + * equal with the clock frequency divided by DEC_RATE + 1. + */ + if (st->clk_mode == ADIS16480_CLK_PPS) + freq = st->clk_freq * t; + else + freq = st->clk_freq / (t + 1); + *val = freq / 1000; *val2 = (freq % 1000) * 1000; @@ -793,6 +847,7 @@ static const struct adis16480_chip_info adis16480_chip_info[] = { .int_clk = 4250000, .max_dec_rate = 4250, .filter_freqs = adis16495_def_filter_freqs, + .has_pps_clk_mode = true, }, [ADIS16495_2] = { .channels = adis16485_channels, @@ -805,6 +860,7 @@ static const struct adis16480_chip_info adis16480_chip_info[] = { .int_clk = 4250000, .max_dec_rate = 4250, .filter_freqs = adis16495_def_filter_freqs, + .has_pps_clk_mode = true, }, [ADIS16495_3] = { .channels = adis16485_channels, @@ -817,6 +873,7 @@ static const struct adis16480_chip_info adis16480_chip_info[] = { .int_clk = 4250000, .max_dec_rate = 4250, .filter_freqs = adis16495_def_filter_freqs, + .has_pps_clk_mode = true, }, [ADIS16497_1] = { .channels = adis16485_channels, @@ -829,6 +886,7 @@ static const struct adis16480_chip_info adis16480_chip_info[] = { .int_clk = 4250000, .max_dec_rate = 4250, .filter_freqs = adis16495_def_filter_freqs, + .has_pps_clk_mode = true, }, [ADIS16497_2] = { .channels = adis16485_channels, @@ -841,6 +899,7 @@ static const struct adis16480_chip_info adis16480_chip_info[] = { .int_clk = 4250000, .max_dec_rate = 4250, .filter_freqs = adis16495_def_filter_freqs, + .has_pps_clk_mode = true, }, [ADIS16497_3] = { .channels = adis16485_channels, @@ -853,6 +912,7 @@ static const struct adis16480_chip_info adis16480_chip_info[] = { .int_clk = 4250000, .max_dec_rate = 4250, .filter_freqs = adis16495_def_filter_freqs, + .has_pps_clk_mode = true, }, }; @@ -1027,6 +1087,100 @@ static int adis16480_config_irq_pin(struct device_node *of_node, return adis_write_reg_16(&st->adis, ADIS16480_REG_FNCTIO_CTRL, val); } +static int adis16480_of_get_ext_clk_pin(struct adis16480 *st, + struct device_node *of_node) +{ + const char *ext_clk_pin; + enum adis16480_int_pin pin; + int i; + + pin = ADIS16480_PIN_DIO2; + if (of_property_read_string(of_node, "adi,ext-clk-pin", &ext_clk_pin)) + goto clk_input_not_found; + + for (i = 0; i < ARRAY_SIZE(adis16480_int_pin_names); i++) { + if (strcasecmp(ext_clk_pin, adis16480_int_pin_names[i]) == 0) + return i; + } + +clk_input_not_found: + dev_info(&st->adis.spi->dev, + "clk input line not specified, using DIO2\n"); + return pin; +} + +static int adis16480_ext_clk_config(struct adis16480 *st, + struct device_node *of_node, + bool enable) +{ + unsigned int mode, mask; + enum adis16480_int_pin pin; + uint16_t val; + int ret; + + ret = adis_read_reg_16(&st->adis, ADIS16480_REG_FNCTIO_CTRL, &val); + if (ret < 0) + return ret; + + pin = adis16480_of_get_ext_clk_pin(st, of_node); + /* + * Each DIOx pin supports only one function at a time. When a single pin + * has two assignments, the enable bit for a lower priority function + * automatically resets to zero (disabling the lower priority function). + */ + if (pin == (val & ADIS16480_DRDY_SEL_MSK)) + dev_warn(&st->adis.spi->dev, + "DIO%x pin supports only one function at a time\n", + pin + 1); + + mode = ADIS16480_SYNC_EN(enable) | ADIS16480_SYNC_SEL(pin); + mask = ADIS16480_SYNC_EN_MSK | ADIS16480_SYNC_SEL_MSK; + /* Only ADIS1649x devices support pps ext clock mode */ + if (st->chip_info->has_pps_clk_mode) { + mode |= ADIS16480_SYNC_MODE(st->clk_mode); + mask |= ADIS16480_SYNC_MODE_MSK; + } + + val &= ~mask; + val |= mode; + + ret = adis_write_reg_16(&st->adis, ADIS16480_REG_FNCTIO_CTRL, val); + if (ret < 0) + return ret; + + return clk_prepare_enable(st->ext_clk); +} + +static int adis16480_get_ext_clocks(struct adis16480 *st) +{ + st->clk_mode = ADIS16480_CLK_INT; + st->ext_clk = devm_clk_get(&st->adis.spi->dev, "sync"); + if (!IS_ERR_OR_NULL(st->ext_clk)) { + st->clk_mode = ADIS16480_CLK_SYNC; + return 0; + } + + if (PTR_ERR(st->ext_clk) != -ENOENT) { + dev_err(&st->adis.spi->dev, "failed to get ext clk\n"); + return PTR_ERR(st->ext_clk); + } + + if (st->chip_info->has_pps_clk_mode) { + st->ext_clk = devm_clk_get(&st->adis.spi->dev, "pps"); + if (!IS_ERR_OR_NULL(st->ext_clk)) { + st->clk_mode = ADIS16480_CLK_PPS; + return 0; + } + + if (PTR_ERR(st->ext_clk) != -ENOENT) { + dev_err(&st->adis.spi->dev, "failed to get ext clk\n"); + return PTR_ERR(st->ext_clk); + } + } + + return 0; +} + static int adis16480_probe(struct spi_device *spi) { const struct spi_device_id *id = spi_get_device_id(spi); @@ -1058,10 +1212,25 @@ static int adis16480_probe(struct spi_device *spi) if (ret) return ret; - ret = adis_setup_buffer_and_trigger(&st->adis, indio_dev, NULL); + ret = adis16480_get_ext_clocks(st); if (ret) return ret; + if (!IS_ERR_OR_NULL(st->ext_clk)) { + ret = adis16480_ext_clk_config(st, spi->dev.of_node, true); + if (ret) + return ret; + + st->clk_freq = clk_get_rate(st->ext_clk); + st->clk_freq *= 1000; /* micro */ + } else { + st->clk_freq = st->chip_info->int_clk; + } + + ret = adis_setup_buffer_and_trigger(&st->adis, indio_dev, NULL); + if (ret) + goto error_clk_disable_unprepare; + ret = adis16480_initial_setup(indio_dev); if (ret) goto error_cleanup_buffer; @@ -1078,6 +1247,8 @@ static int adis16480_probe(struct spi_device *spi) adis16480_stop_device(indio_dev); error_cleanup_buffer: adis_cleanup_buffer_and_trigger(&st->adis, indio_dev); +error_clk_disable_unprepare: + clk_disable_unprepare(st->ext_clk); return ret; } @@ -1090,6 +1261,7 @@ static int adis16480_remove(struct spi_device *spi) adis16480_stop_device(indio_dev); adis_cleanup_buffer_and_trigger(&st->adis, indio_dev); + clk_disable_unprepare(st->ext_clk); return 0; } From patchwork Thu Mar 7 15:29:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Popa X-Patchwork-Id: 10843213 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BA2B01390 for ; Thu, 7 Mar 2019 15:29:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A86122DC52 for ; Thu, 7 Mar 2019 15:29:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 952312DC94; Thu, 7 Mar 2019 15:29:35 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 18B0D2F379 for ; Thu, 7 Mar 2019 15:29:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726591AbfCGP3e (ORCPT ); Thu, 7 Mar 2019 10:29:34 -0500 Received: from mail-eopbgr760043.outbound.protection.outlook.com ([40.107.76.43]:12256 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726207AbfCGP3e (ORCPT ); Thu, 7 Mar 2019 10:29:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=analog.onmicrosoft.com; s=selector1-analog-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=D39DnnMBHoC6J6je8tfkFf7qjQ2chsBCBjg8HlhBB2M=; b=GpyElGXe33YRT+trZCCHNqrkaUuwsnvuixpfkFH9qJQ9AG140NqJW04BSmbldYyADaiGzgQ9MLL1qO91TqC9OTj8+IiCA4TjCheBNOlTLSTXHB5fzT1nUVcdYLPO1fNFurK1rJSJhZDtWC3CPE50A9UY7B5VyC6LEP3GLtIHMp8= Received: from DM6PR03CA0055.namprd03.prod.outlook.com (2603:10b6:5:100::32) by CO2PR03MB2263.namprd03.prod.outlook.com (2603:10b6:102:a::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1665.19; Thu, 7 Mar 2019 15:29:28 +0000 Received: from CY1NAM02FT025.eop-nam02.prod.protection.outlook.com (2a01:111:f400:7e45::203) by DM6PR03CA0055.outlook.office365.com (2603:10b6:5:100::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1665.18 via Frontend Transport; Thu, 7 Mar 2019 15:29:28 +0000 Authentication-Results: spf=pass (sender IP is 137.71.25.55) smtp.mailfrom=analog.com; gmx.de; dkim=none (message not signed) header.d=none;gmx.de; dmarc=bestguesspass action=none header.from=analog.com; Received-SPF: Pass (protection.outlook.com: domain of analog.com designates 137.71.25.55 as permitted sender) receiver=protection.outlook.com; client-ip=137.71.25.55; helo=nwd2mta1.analog.com; Received: from nwd2mta1.analog.com (137.71.25.55) by CY1NAM02FT025.mail.protection.outlook.com (10.152.75.148) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.1643.11 via Frontend Transport; Thu, 7 Mar 2019 15:29:27 +0000 Received: from NWD2HUBCAS7.ad.analog.com (nwd2hubcas7.ad.analog.com [10.64.69.107]) by nwd2mta1.analog.com (8.13.8/8.13.8) with ESMTP id x27FTQf9019485 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=OK); Thu, 7 Mar 2019 07:29:26 -0800 Received: from linux.analog.com (10.32.224.122) by NWD2HUBCAS7.ad.analog.com (10.64.69.107) with Microsoft SMTP Server id 14.3.408.0; Thu, 7 Mar 2019 10:29:25 -0500 From: Stefan Popa To: , CC: , , , , , , , , , Subject: [PATCH 2/2] dt-bindings: iio: imu: adis16480: Document external clock Date: Thu, 7 Mar 2019 17:29:19 +0200 Message-ID: <1551972559-15148-1-git-send-email-stefan.popa@analog.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-ADIRoutedOnPrem: True X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:137.71.25.55;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(39860400002)(136003)(376002)(346002)(396003)(2980300002)(189003)(199004)(50466002)(2616005)(36756003)(426003)(126002)(316002)(48376002)(8936002)(54906003)(107886003)(186003)(51416003)(77096007)(26005)(305945005)(7636002)(14444005)(8676002)(476003)(47776003)(110136005)(486006)(53416004)(50226002)(16586007)(72206003)(106466001)(7696005)(106002)(7416002)(356004)(478600001)(6666004)(44832011)(2906002)(4326008)(5660300002)(336012)(246002);DIR:OUT;SFP:1101;SCL:1;SRVR:CO2PR03MB2263;H:nwd2mta1.analog.com;FPR:;SPF:Pass;LANG:en;PTR:nwd2mail10.analog.com;MX:1;A:1; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 68665768-0aa9-4180-1155-08d6a311afea X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600127)(711020)(4605104)(4608103)(4709054)(2017052603328)(7153060);SRVR:CO2PR03MB2263; X-MS-TrafficTypeDiagnostic: CO2PR03MB2263: X-Microsoft-Exchange-Diagnostics: 1;CO2PR03MB2263;20:l+u/Z90s8yjRMJFjBELVYSCH1Wbk7mP5Fcnvo9PQIeByJaMoS7/BGJVlFcimyNN96GduKuopD2V9YMgUy80ZVtNIfQL9DRCIET4RD6rqLXIUkghQZwTU3ZhOUk6YBiCYg83lidDZqSibFYiOyNYvVvHENMP3rvnn7ZpdDbIkca3z/e73BlPlti04plR+j9KIjJ7jOxIXspssozRgWDMa9RZBSWUTEPKPk3BtBXb3YZ9dYaeI2SApm810l500zWLoo4ni3UySSqmVG9+oJuNNIdjTmZ9Ix+B+VQd6Ex7KRLemkaDJ4BHmRqTz0y+uDVdGsiFbukVOL7uBh0SDyQMBqi3aJFsVgJQm+kTMjtxTfbk03hkZcC7Aq6XfMewkiaBGkAnaGTj/SN9nc4A7sd67sLRjUyNa8bEJ8wS7M9hDcxEEuO1e1GZMBDzFeFrDYkEH/l59LWprwHAsaxTcnwbP2vwLY2i3dVq+rqvwaia8EE7k13+V0cdVljt1lgcoaR9Q X-Microsoft-Antispam-PRVS: X-Forefront-PRVS: 096943F07A X-Microsoft-Exchange-Diagn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-Antispam-Message-Info: WPqnljI1GPrLEAuQg7tWuB0yZhQOH87ZtTHPD5DMrqkueFNqoy/yfVCnFLBmLN/yzgQGXVjHXQfNUfjCdwEzMZQ3nr6gN1UjSJn1/i8fBkxnrkjYeA8vkYTg8MLjQHBTi45Qu7Wdxm//xXrDiMNgFdOgVh3bdMjH3Y2BnPTmlKT8zSSxcXBHMxdRSkRR2PbBQ3RFCLuQ65979DWiLK1X+z2nCHnff0p8RWK4gSAnNokEHqnM0NmkbP3VmXRhbyFaoTnEH0gVOtS54S74FYMKjA+RpD78rl9OFsbB8ysZ9XQXf3YcFmU8Iv2uh6TZ4bd1Bo2k1QEQE6SQbl4slFlWaQSdkAHb7tFudN/pD9WwelXkxdLy8nZybMrnpMm7I6vEUB4MQQIXu3AjgVwk7y79rCI5kKwewahkP5ICWqnoHB8= X-OriginatorOrg: analog.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Mar 2019 15:29:27.0459 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 68665768-0aa9-4180-1155-08d6a311afea X-MS-Exchange-CrossTenant-Id: eaa689b4-8f87-40e0-9c6f-7228de4d754a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=eaa689b4-8f87-40e0-9c6f-7228de4d754a;Ip=[137.71.25.55];Helo=[nwd2mta1.analog.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO2PR03MB2263 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add documentation for optional use of external clock. All devices supported by this driver can work with an external clock in sync mode. Another mode, called Pulse Per Second (PPS) is supported only by adis1649x devices. The mode is selected by using the "clock-names" property. The pin which is used as external clock input is selected by using a custom optional property called "adi,ext-clk-pin". If this field is left empty, DIO2 is assigned as default external clock input pin. Signed-off-by: Stefan Popa --- .../devicetree/bindings/iio/imu/adi,adis16480.txt | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/Documentation/devicetree/bindings/iio/imu/adi,adis16480.txt b/Documentation/devicetree/bindings/iio/imu/adi,adis16480.txt index 39ab016..9e2fcd4 100644 --- a/Documentation/devicetree/bindings/iio/imu/adi,adis16480.txt +++ b/Documentation/devicetree/bindings/iio/imu/adi,adis16480.txt @@ -34,6 +34,37 @@ Optional properties: signal. - reset-gpios: must be the device tree identifier of the RESET pin. As the line is active low, it should be marked GPIO_ACTIVE_LOW. +- clocks: phandle to the external clock. Should be set according to + "clock-names". + If this field is left empty, the internal clock is used. +- clock-names: The name of the external clock to be used. Valid values are: + * sync: In sync mode, the internal clock is disabled and the frequency + of the external clock signal establishes therate of data + collection and processing. See Fig 14 and 15 in the datasheet. + The clock-frequency must be: + * 3000 to 4500 Hz for adis1649x devices. + * 700 to 2400 Hz for adis1648x devices. + * pps: In Pulse Per Second (PPS) Mode, the rate of data collection and + production is equal to the product of the external clock + frequency and the scale factor in the SYNC_SCALE register, see + Table 154 in the datasheet. + The clock-frequency must be: + * 1 to 128 Hz for adis1649x devices. + * This mode is not supported by adis1648x devices. + If this field is left empty, the internal clock is used. +- adi,ext-clk-pin: The DIOx line to be used as an external clock input. + Valid values are: + * DIO1 + * DIO2 + * DIO3 + * DIO4 + Each DIOx pin supports only one function at a time (data ready line + selection or external clock input). When a single pin has two + two assignments, the enable bit for the lower priority function + automatically resets to zero (disabling the lower priority function). + Data ready has highest priority. + If this field is left empty, DIO2 is assigned as default external clock + input pin. Example: @@ -46,4 +77,7 @@ Example: interrupts = <25 IRQF_TRIGGER_FALLING>; interrupt-parent = <&gpio>; interrupt-names = "DIO2"; + clocks = <&adis16495_sync>; + clock-names = "sync"; + adi,ext-clk-pin = "DIO1"; };