Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp1248009lqt; Fri, 7 Jun 2024 12:13:51 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUac0IuiI9HhaO9TAQ66iVliOWAgV39Kqhm5BuOQYiwVjBGhdTqp2XS8MlgRXKJ/swVjB63poJfdCeUf4viE7JFzGi6L/al2LlB7xa3rQ== X-Google-Smtp-Source: AGHT+IH3zjTCQ8WyOqxP8R+4YNsoSPwG0jmxwz8dO91uCzgqGJzlSqpipNS7XZ5BTUJvThAIC1Zv X-Received: by 2002:a50:ab45:0:b0:57a:234d:abc0 with SMTP id 4fb4d7f45d1cf-57c5085344dmr2605396a12.1.1717787631235; Fri, 07 Jun 2024 12:13:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717787631; cv=pass; d=google.com; s=arc-20160816; b=k17oLvxt2lezlKU0O2LboFjWhv0FcGtLjiDBDatAp2GYCGDR1YGBDGsCzMyZkKM648 +Hl23i2asFl/eKXKfHbBEHhag6tGMKz0U9ju/x7/Q9TZJjbkMeT8QkKMJ5NiIJwBgubB htEEFVLWdksgM9HbFvtku4tn7en8x7y9hMfthDiNvfsV2oLPU6SWeyukuc+at3hhrB7J y7bcJ7B7isKl3q12TAbm3RgCbXkC1m0O78G3UfpLj2IgRczQkitQhiCLT5kqg4hzn3HO Jj3/rR6rMNs9DLWUttv+7XpQvezokfBgKyShgXkUCEkzL78rQtfLdhOaKxh1+BgAQtkq BMkA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=q3sLjneVKNLVUsJ1Sg3YJK9+pNgg6awuADOkTmlppuU=; fh=FH2jfsWzKKcjm9MnqilNTkYq0TxatE+W/iC3QLuT31o=; b=gW+HOTN72zxHqHMF/KMxrWOgaRfUS+387PUdzKFmw8qBcEJZDNQ9c4ZnZ3V75PuH48 cN2gqXlYuZ1N4zHg+kpv7JexfqpTAHKqVh52I7qcMEh6ny5J/FO15KbvzJOaNdOPTywd xuhJakzkoOFfVqE9NLcvFZZrI6iN6QdqGaYJ2E2gFYPffpla11qLbZhQ2ZZZzxxXinoC 1TN307TXshWWLdp8bQW+3cv4/HYd5Gp7MFbd5ygMZJwCzHiQNBo3pSHDAVhvqnEexp/h 7XfelrSmF8nm60du2QpGWMsSaX7LiWSEoiTrLYCLo5UKotSL94TU9I+CaI/1CCHQMyCG V9hA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=dEaQi6HZ; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-206649-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-206649-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57aae28caf1si2093603a12.657.2024.06.07.12.13.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jun 2024 12:13:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-206649-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=dEaQi6HZ; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-206649-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-206649-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id BC6321F236C2 for ; Fri, 7 Jun 2024 19:13:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1CF03149C77; Fri, 7 Jun 2024 19:13:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="dEaQi6HZ" Received: from mail-oi1-f175.google.com (mail-oi1-f175.google.com [209.85.167.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CB393145341 for ; Fri, 7 Jun 2024 19:13:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717787621; cv=none; b=gcmfVn4kQWpEbAU92e440g6IxhnWu07gzvEAE5twbj1meQ4KeAADG0DVWAwje5MBrgvV02nPoSw/aoI8oxgAEj5vQi8yaHIF84NvZQ/xOu+LJwGSnjAaHIJeZ05/x6HdMDLzDO0Gqj3iQ6Ppw6sPO6m7MMDnUFrHeMnAlw4Oukk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717787621; c=relaxed/simple; bh=cEDTgMrXlgD0YchbLBGmUJQMZeBVMnlvkFJQntt8S1E=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=DQx9cpuI/pv41jC+swvb3F9c00bm7DKWrB/Dw70o+QcZqxQcWeigBar7o6MbNaOPZaMBm4I56sUxo1Cr6hsyzP+nM1sU2LcMEAGytdp0OtWfs12aZnR95OvO5TZ2W1vukqNU7fxwLCZ6uD/Dp9TOe9aAx6FGvFcq/B9ONCLNZmA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=dEaQi6HZ; arc=none smtp.client-ip=209.85.167.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Received: by mail-oi1-f175.google.com with SMTP id 5614622812f47-3d1fd550811so1415411b6e.2 for ; Fri, 07 Jun 2024 12:13:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1717787618; x=1718392418; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=q3sLjneVKNLVUsJ1Sg3YJK9+pNgg6awuADOkTmlppuU=; b=dEaQi6HZsj0Ka1JKn17qhYe3ROuPYOQA/B4KJGey47kG4p8NRO2FAjMchyFbyBcuhk iImZW0Dh+s9w5aFXU+zC4dtreTpvTjE6VzzEafLLuikV/hBT4s44blP8njg1GI6YVokR IvwscBKQKYvel+XGI0hnZlNUERE3K4VoLIN0unrPGiWvu7j3TX80pL07Z8fdi+dkyG/U b6989J+a4bKskx4W27GgyO2qt2uMcimTo3W+hjmBfobIAsArJLX+M3t/cCL0EVYLTyJW dDFYvKg5pcmeUUaFpuOHYKCR9aZgUUSefBElqQBJWKJwlyYTator0BPlIJRRY+VuHRui WBBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717787618; x=1718392418; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=q3sLjneVKNLVUsJ1Sg3YJK9+pNgg6awuADOkTmlppuU=; b=lWIevqXiEVC636mlvJBOG4+2jccHaYMTK2SDO8ThD4+Oqm4x/Mo4wVUkQv1UWIYdId nvSAhx9+F9mjwTHpoMnv/caqBPMxOTSoIa4NmnWZw7HP6mNGgNb29d4OkHmKCKr4kiLI G3DgdWpbcE7U8UbD/Q0Fl+6TyzqYxwLPgshQTwhyK7cxHjVQYccIy45rv+tca1ApJT0v q3tYrA+MJ3sfyGuTJ2VJFycWB+wNJfeA2+0oPRfx4qW3eGUKErmJV58BdmmnUA+n8Xy6 BtC+CHKiaY813TJDmF2KfBx6Zziim+HObqe/eoALmjCaiTgl5/264yJFBctfgJFwvEfZ mmAQ== X-Forwarded-Encrypted: i=1; AJvYcCUuozARjy4ai+4IdPHT4AWXFVZWpaR02Yw/kcc3BK752UYy8/0rd+k/PwykySe1fx0mDp2gv25mG35cblLTKvpox3rgF/3nw4Gyu79u X-Gm-Message-State: AOJu0YzKellT73lWTCGSJqJf8JxzLflQhc5K2iar9J+QgMZVkUJfS+1h 3IgDZnna9f+p05LyElYNlujJ2w3GPgxolBTGboeJKis1+QLirDFrTSaBkAHyDQ4= X-Received: by 2002:a05:6808:1b10:b0:3d1:dfd0:6aa3 with SMTP id 5614622812f47-3d210f5200emr4165117b6e.51.1717787617690; Fri, 07 Jun 2024 12:13:37 -0700 (PDT) Received: from [192.168.0.142] (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id 5614622812f47-3d20b69f2f2sm747128b6e.33.2024.06.07.12.13.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 07 Jun 2024 12:13:37 -0700 (PDT) Message-ID: Date: Fri, 7 Jun 2024 14:13:36 -0500 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 5/5] iio: dac: ltc2664: Add driver for LTC2664 and LTC2672 To: "Paller, Kim Seer" , "linux-kernel@vger.kernel.org" , "linux-iio@vger.kernel.org" , "devicetree@vger.kernel.org" Cc: Jonathan Cameron , Lars-Peter Clausen , Liam Girdwood , Mark Brown , Dimitri Fedrau , Krzysztof Kozlowski , Rob Herring , Conor Dooley , "Hennerich, Michael" , =?UTF-8?Q?Nuno_S=C3=A1?= , kernel test robot References: <20240603012200.16589-1-kimseer.paller@analog.com> <20240603012200.16589-6-kimseer.paller@analog.com> <408aa030-23df-418d-a04d-a5551119624b@baylibre.com> Content-Language: en-US From: David Lechner In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 6/6/24 10:49 AM, Paller, Kim Seer wrote: >>> +#define LTC2664_CHANNEL(_chan) { \ >>> + .indexed = 1, \ >>> + .output = 1, \ >>> + .channel = (_chan), \ >>> + .info_mask_separate = BIT(IIO_CHAN_INFO_SCALE) | \ >>> + BIT(IIO_CHAN_INFO_OFFSET) | BIT(IIO_CHAN_INFO_RAW), >> \ >>> + .info_mask_separate_available = BIT(IIO_CHAN_INFO_RAW), >> \ >>> + .ext_info = ltc2664_ext_info, \ >>> +} >>> + >>> +static const struct iio_chan_spec ltc2664_channels[] = { >>> + LTC2664_CHANNEL(0), >>> + LTC2664_CHANNEL(1), >>> + LTC2664_CHANNEL(2), >>> + LTC2664_CHANNEL(3), >>> +}; >>> + >>> +static const struct iio_chan_spec ltc2672_channels[] = { >>> + LTC2664_CHANNEL(0), >>> + LTC2664_CHANNEL(1), >>> + LTC2664_CHANNEL(2), >>> + LTC2664_CHANNEL(3), >>> + LTC2664_CHANNEL(4), >>> +}; >> >> Do we really need these since they are only used as a template anyway? >> We could just have a single template for one channel and copy it as >> manay times as needed. > > Yes, from what I can see we need separate channel specs for both devices > since they have a differing number of channels. As for your suggestion about > having a single template for one channel and copying it as many times as > needed, I'm not entirely sure how to implement it in this context. Could you > provide something like a code snippet to illustrate this? > Instead of the #define and arrays above, just have a single static struct: static const struct iio_chan_spec ltc2664_channel_template = { .indexed = 1, .output = 1, .info_mask_separate = BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OFFSET) | BIT(IIO_CHAN_INFO_RAW), .info_mask_separate_available = BIT(IIO_CHAN_INFO_RAW), .ext_info = ltc2664_ext_info, }; >>> +static int ltc2664_setup(struct ltc2664_state *st, struct regulator *vref) >>> +{ >>> + const struct ltc2664_chip_info *chip_info = st->chip_info; >>> + struct gpio_desc *gpio; >>> + int ret; >>> + >>> + /* If we have a clr/reset pin, use that to reset the chip. */ >>> + gpio = devm_gpiod_get_optional(&st->spi->dev, "reset", GPIOD_OUT_HIGH); >>> + if (IS_ERR(gpio)) >>> + return dev_err_probe(&st->spi->dev, PTR_ERR(gpio), >>> + "Failed to get reset gpio"); >>> + if (gpio) { >>> + usleep_range(1000, 1200); >>> + gpiod_set_value_cansleep(gpio, 0); >>> + } >>> + >>> + /* >>> + * Duplicate the default channel configuration as it can change during >>> + * @ltc2664_channel_config() >>> + */ >>> + st->iio_channels = devm_kmemdup(&st->spi->dev, chip_info->iio_chan, >>> + (chip_info->num_channels + 1) * >>> + sizeof(*chip_info->iio_chan), >>> + GFP_KERNEL); Then here, instead of devm_kmemdup(): st->iio_channels = devm_kcalloc(&st->spi->dev, chip_info->num_channels, sizeof(struct iio_chan_spec), GFP_KERNEL); if (!st->iio_channels) return -ENOMEM; for (i = 0; i < chip_info->num_channels; i++) { st->iio_channels[i] = ltc2664_channel_template; st->iio_channels[i].type = chip_info->measurement_type; st->iio_channels[i].channel = i; } Note: the original code was missing the error check and I think num_channels + 1 was 1 too many, so I fixed both of those in the example as well. This also replaces: st->iio_channels[chan].type = chip_info->measurement_type; from ltc2664_set_span() as it seems a bit out of place there. >>> + >>> + ret = ltc2664_channel_config(st); >>> + if (ret) >>> + return ret; >>> + >>> + if (!vref) >>> + return 0; >>> + >>> + return regmap_set_bits(st->regmap, LTC2664_CMD_CONFIG, LTC2664_REF_DISABLE); >>> +}