Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp588303lqo; Fri, 10 May 2024 08:43:26 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUYIjGW0q4n69uOdni1oX2dB5ANcNlRWBtGX6G4a+tbwzwgK+yGYzf6wDA40FV+1Zc4APEPPL5pUkuXWsfbPCm+VP6+PdDhs5eL9onvhg== X-Google-Smtp-Source: AGHT+IE78OyC7QhfvbRsV71AF89zmLsZCp4WWyGae9AwjMoXWhgDZNP4MDCdvWR1wFfaiAiT9Wo9 X-Received: by 2002:a05:6a00:39a6:b0:6f4:3d5f:31fb with SMTP id d2e1a72fcca58-6f4c91cd80fmr9444694b3a.9.1715355806436; Fri, 10 May 2024 08:43:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715355806; cv=pass; d=google.com; s=arc-20160816; b=Ys2kwBIpwb6n8241RfHiE/dW3mrywz0kvhK1F/DThHdalrLIbb6T43/vR4CA/CSH7N jcSx+FxyCwApZ3Ya/8gluxkU+HC3df2b5Pfw+cCuxaXrpyY+dELi8/OzbshuskOLDPg9 DQMaqttxN5EpkfxvNW+A9lFKDBk5F9KoOqqqNE4LkofNOD1vhdEXh71OsJT3MPOTVb9/ OH1Tsn20b6DAupbcq9rGFe4zxP+b7R+uviZwhrn5F1EXcWmsz2jyZGoXQN4gsS8l1wby 4AfqPsyhC8mEbIpmusMf2ftubr5vvIFPg5qrupW/RRrR7cwhjiKGyzzvA6BhxSRBmpWi X8fw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=nExPMr6mRgshB3qC7yImXvGaDzKoJT84cXEh3P1y8zg=; fh=poVNEnFNcmCosY3ezhxGNY5f6FBHF0z6mY3tegXKmrk=; b=OkDXpNa0F96jrftbX8A7kcUjWempEYlPPE0VZ4zCnnTwRvxssTAtMbiXn0ZuWYaAPd 7tu20o/gfmWpEPgi5RRyNYG+A1y52tpqMu/bajjtU/E+crOi4pOH8gX4oy/hlf3djS62 jPFH8U40WKBOIsl6x/zE/U1BloTsZxcSALcM5DktbW7rUHXzt5xgSA3SyF/99ZFq0sj+ b3LOfS8iyWpWyhsZeol1Rqgp7muK5N83LWm6IfjvA0Ww4eI3kZ9Gm4ss8GwbLuw3kkcS ZgT1y7mN1EXSYwXRmwtUJWPdDlWNqEowcGth97wjA5eXXzNSrNkcVC98sr6da+a5m+Y+ ibwQ==; 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="jk/YQUKr"; 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-175972-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-175972-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d2e1a72fcca58-6f4d2af11e4si3927186b3a.170.2024.05.10.08.43.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 May 2024 08:43:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-175972-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b="jk/YQUKr"; 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-175972-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-175972-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 88ADC281439 for ; Fri, 10 May 2024 15:43:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 285BD17278D; Fri, 10 May 2024 15:43:05 +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="jk/YQUKr" Received: from mail-lj1-f176.google.com (mail-lj1-f176.google.com [209.85.208.176]) (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 4F477172769 for ; Fri, 10 May 2024 15:43:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715355784; cv=none; b=STem94UDHESlOmy/T5AaF89i6dsOcXYKbjMq3aC+ObihvzabNXm66SeysgnRCZQQtz4yC8UmkBheULB/38ZTZtQ3+wyrcQAZYm8VJEkFlw54VCGW4vQj9dXU6zj9JVF6xLA+AA2N3gwQYS9OGSIPGYLnNNRDs3SvBmhrbbwcL9U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715355784; c=relaxed/simple; bh=EqdbfycLoKL0zt5JGB2DK5UT2ooYiwpHsIvWmqjmTyY=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=ICIYAEDEc/BNOrjMpId28X9oMVg3za2hrpvAJ/5pJrujyR/LLktnpMFaTj+GNrzA2aPg3kjmZSHqdUIiZIzV98ip4UTtdR9fsHL6vGzW56VVF5TyJ5Z4lHU8ETHJT8hwU1E+hsTKo+nr/NENxy9+NCyUBF3pUOhYmRT+ZQK46ss= 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=jk/YQUKr; arc=none smtp.client-ip=209.85.208.176 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-lj1-f176.google.com with SMTP id 38308e7fff4ca-2df83058d48so27614461fa.1 for ; Fri, 10 May 2024 08:43:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1715355780; x=1715960580; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=nExPMr6mRgshB3qC7yImXvGaDzKoJT84cXEh3P1y8zg=; b=jk/YQUKr5y1lG41t7QIUoFanErOwhh5r8CQM5jwTAMdqlMdujfqvOOAAZkuyB5VPaV +qcSXu4VswZe4K0YOYxef84OdKFPK48E4r5WE9yxRuVZoZ+/pQRBAVducCeeQZRpfYBQ DEc+MLBBVDrpop5UWy0Y7ft7L9q/TIU+npv/MDE7BjBlGHo1ffv8aH0X4V4e24D8uIX8 8HXXSWNtXqYZz16fmHEPxQ1wWlQ4A7jMQ7TkYaQxM2cEHkfmyfw3nyQDgXLzutJwqBg6 8wiAJCfOmG51kiXKlNHVxuiNPZFSqMemWfnU4dA25qH5U4hpMxpWlzdKUcEiesLeQ1v8 hlzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715355780; x=1715960580; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nExPMr6mRgshB3qC7yImXvGaDzKoJT84cXEh3P1y8zg=; b=fd+bsqA4l7jR8L+3yIECeibd25KJi76toOQ98Gdcu3FSlpGJk4aE7fr2ZD4aeoVH8L rlSU/lJPgbnyHmC0OAqCkr0kty4cbK7zz3fzE1gtQkakzVt3ZCFHmnWa25MXbSgDHJXY LV5QUEmcgNSai0SiH3sryedjAC8N8qW4aWkUTAS5OWK2ttbV2egppUGlaO7qvZYy4JgD HIvtodF4AavtHjI4btdbSl7hZ0JmAlbJDplgND5XwU1w3TbjKxdMKjb473nlEuUPT6jH H9Cl7tYHovAWQIgLaXkBxsr80NbUm2aaYjYej5dmj5kLq2IyvjrpYIEjtdgInIpgC24M aTTQ== X-Forwarded-Encrypted: i=1; AJvYcCVMQTAyYjdpbP3Tfm0TiSWnt2GsVcwWE5CpJbfgb5fPefIgxoLVeNxne2xO5OpiobziKhBqV/hr9MVSSfkDfQFNohtlLNtR/DOCyYR4 X-Gm-Message-State: AOJu0YxX/rFQ46xWFZb3SNjAxp15aa6CombsQkib6Q+YhDyO+9OLA6gx wE+LmUPvLdfxnly+b1KWsLkWLLXC/jbesswHr8BpLhB4oZ3wk1OGlmVA7uLSNI4gAduqkXWamrc /JIJnPFUdGZCBYM8HEPQepLANliRFuZMhUzUZvA== X-Received: by 2002:a2e:8847:0:b0:2e2:2791:983e with SMTP id 38308e7fff4ca-2e51fd451femr18878401fa.13.1715355780559; Fri, 10 May 2024 08:43:00 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240510141836.1624009-1-adureghello@baylibre.org> <20240510141836.1624009-2-adureghello@baylibre.org> In-Reply-To: <20240510141836.1624009-2-adureghello@baylibre.org> From: David Lechner Date: Fri, 10 May 2024 10:42:49 -0500 Message-ID: Subject: Re: [PATCH 2/3] iio: dac: ad3552r: add support for ad3541r and ad3551r To: Angelo Dureghello Cc: jic23@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, nuno.sa@analog.com, lars@metafoo.de, Michael.Hennerich@analog.com, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, May 10, 2024 at 9:19=E2=80=AFAM Angelo Dureghello wrote: > > From: Angelo Dureghello > > Add support for single-output dac variants. > > Signed-off-by: Angelo Dureghello > --- > drivers/iio/dac/ad3552r.c | 39 +++++++++++++++++++++++++++++---------- > 1 file changed, 29 insertions(+), 10 deletions(-) > > diff --git a/drivers/iio/dac/ad3552r.c b/drivers/iio/dac/ad3552r.c > index a492e8f2fc0f..0dd6f995c3e2 100644 > --- a/drivers/iio/dac/ad3552r.c > +++ b/drivers/iio/dac/ad3552r.c > @@ -140,7 +140,9 @@ enum ad3552r_ch_vref_select { > }; > > enum ad3542r_id { > + AD3541R_ID =3D 0x400b, > AD3542R_ID =3D 0x4009, > + AD3551R_ID =3D 0x400a, > AD3552R_ID =3D 0x4008, > }; > > @@ -745,7 +747,8 @@ static void ad3552r_calc_gain_and_offset(struct ad355= 2r_desc *dac, s32 ch) > } else { > /* Normal range */ > idx =3D dac->ch_data[ch].range; > - if (dac->chip_id =3D=3D AD3542R_ID) { > + if (dac->chip_id =3D=3D AD3541R_ID || > + dac->chip_id =3D=3D AD3542R_ID) { > v_min =3D ad3542r_ch_ranges[idx][0]; > v_max =3D ad3542r_ch_ranges[idx][1]; > } else { > @@ -780,7 +783,7 @@ static int ad3552r_find_range(u16 id, s32 *vals) > int i, len; > const s32 (*ranges)[2]; > > - if (id =3D=3D AD3542R_ID) { > + if (id =3D=3D AD3541R_ID || id =3D=3D AD3542R_ID) { > len =3D ARRAY_SIZE(ad3542r_ch_ranges); > ranges =3D ad3542r_ch_ranges; > } else { > @@ -955,9 +958,10 @@ static int ad3552r_configure_device(struct ad3552r_d= esc *dac) > dev_err(dev, "mandatory reg property missing\n"); > goto put_child; > } > - if (ch >=3D AD3552R_NUM_CH) { > - dev_err(dev, "reg must be less than %d\n", > - AD3552R_NUM_CH); > + if (ch >=3D AD3552R_NUM_CH || > + (dac->chip_id =3D=3D AD3541R_ID && ch) || > + (dac->chip_id =3D=3D AD3551R_ID && ch)) { > + dev_err(dev, "channel %d is not supported\n", ch)= ; > err =3D -EINVAL; > goto put_child; > } > @@ -987,9 +991,10 @@ static int ad3552r_configure_device(struct ad3552r_d= esc *dac) > goto put_child; > > dac->ch_data[ch].range =3D val; > - } else if (dac->chip_id =3D=3D AD3542R_ID) { > + } else if (dac->chip_id =3D=3D AD3541R_ID || > + dac->chip_id =3D=3D AD3542R_ID) { > dev_err(dev, > - "adi,output-range-microvolt is required f= or ad3542r\n"); > + "adi,output-range-microvolt is required f= or ad354xr\n"); > err =3D -EINVAL; > goto put_child; > } else { > @@ -1088,10 +1093,20 @@ static int ad3552r_probe(struct spi_device *spi) > return err; > > /* Config triggered buffer device */ > - if (dac->chip_id =3D=3D AD3552R_ID) > - indio_dev->name =3D "ad3552r"; > - else > + switch (dac->chip_id) { > + case AD3541R_ID: > + indio_dev->name =3D "ad3541r"; > + break; > + case AD3542R_ID: > indio_dev->name =3D "ad3542r"; > + break; > + case AD3551R_ID: > + indio_dev->name =3D "ad3551r"; > + break; > + case AD3552R_ID: > + indio_dev->name =3D "ad3552r"; > + break; > + } > indio_dev->dev.parent =3D &spi->dev; > indio_dev->info =3D &ad3552r_iio_info; > indio_dev->num_channels =3D dac->num_ch; > @@ -1110,14 +1125,18 @@ static int ad3552r_probe(struct spi_device *spi) > } > > static const struct spi_device_id ad3552r_id[] =3D { > + { "ad3541r", AD3541R_ID }, > { "ad3542r", AD3542R_ID }, > + { "ad3551r", AD3551R_ID }, > { "ad3552r", AD3552R_ID }, > { } > }; > MODULE_DEVICE_TABLE(spi, ad3552r_id); > > static const struct of_device_id ad3552r_of_match[] =3D { > + { .compatible =3D "adi,ad3541r"}, > { .compatible =3D "adi,ad3542r"}, > + { .compatible =3D "adi,ad3551r"}, > { .compatible =3D "adi,ad3552r"}, > { } > }; > -- > 2.45.0.rc1 > > It looks like it is time for a chip_info struct here instead of the if and switch statements to get chip-specific data. Most other IIO drivers have this already and it is the preferred way to look up this kind of information in the IIO subsystem. I prefer the drivers that don't put all of the info structs in an array (that way the code is less verbose). So I would suggest looking at e.g. adc/aspeed_adc, starting with aspeed_adc_matches, to see what I mean and how to implement it. (So one patch to add the info structs and a second patch to add the single channel chips)