From patchwork Tue Mar 22 22:02:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 12789319 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 21058C433EF for ; Tue, 22 Mar 2022 22:02:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237338AbiCVWEE (ORCPT ); Tue, 22 Mar 2022 18:04:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237302AbiCVWED (ORCPT ); Tue, 22 Mar 2022 18:04:03 -0400 Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0598C6F4B8 for ; Tue, 22 Mar 2022 15:02:35 -0700 (PDT) Received: from tr.lan (ip-89-176-112-137.net.upcbroadband.cz [89.176.112.137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id A470483B4F; Tue, 22 Mar 2022 23:02:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1647986552; bh=tKp1TSbcIOnDRMfttqNjLguSZ4QobwHq0RRX5+B/Vrs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=icFAh5bDZxESwQ5S82dnIssgWuPZIbTnkad2ZugBlORhh+ljbOr1jt+63DEoQwfBa PxdiV75KXWOd8F8j6GP+oIm5rsVSCi52TVGZDSZVieBGunbmR00L3fmCnTqaVpKRis 4b0gXsYLWYL4F5AOSYhBDyB/tZsgEXiDsnCwRvE9ZFEqk+rZkDuC7pDxgW3Lj7Oy9r YUqBokppb0WZY8kW7ic4X9CDDeT7MpehjpGO5KoupaL5MJv323LRCzE+hwXmn7UClu CL4rhFOioCZcDQKNVkcMTk4zZVrswvVGqc86ah/93435yOvqq9nnX/g8PZp4fe5ZXG 62ECzj9UPundw== From: Marek Vasut To: linux-iio@vger.kernel.org Cc: Marek Vasut , Andy Shevchenko , Daniel Baluta , Jonathan Cameron Subject: [PATCH v4 06/10] iio: adc: ti-ads1015: Add TLA2024 support Date: Tue, 22 Mar 2022 23:02:06 +0100 Message-Id: <20220322220210.207454-6-marex@denx.de> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220322220210.207454-1-marex@denx.de> References: <20220322220210.207454-1-marex@denx.de> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Add support for TI TLA2024 ADC. This chip is compatible with ADS1015 except it has no comparator in it, hence the comparator configuration bits are missing in Configuration Register and the Hi_Thresh/Lo_Thresh registers are missing as well and so is event support. Signed-off-by: Marek Vasut Cc: Andy Shevchenko Cc: Daniel Baluta Cc: Jonathan Cameron --- V2: No change V3: Use ADS1015 attr group, that's the correct one for this part V4: No change --- drivers/iio/adc/ti-ads1015.c | 53 ++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c index 7d0c0552f425c..51ab8bb3d9f1d 100644 --- a/drivers/iio/adc/ti-ads1015.c +++ b/drivers/iio/adc/ti-ads1015.c @@ -80,6 +80,7 @@ enum chip_ids { ADSXXXX = 0, ADS1015, ADS1115, + TLA2024, }; enum ads1015_channels { @@ -247,6 +248,22 @@ static const struct regmap_config ads1015_regmap_config = { .wr_table = &ads1015_writeable_table, }; +static const struct regmap_range tla2024_writeable_ranges[] = { + regmap_reg_range(ADS1015_CFG_REG, ADS1015_CFG_REG), +}; + +static const struct regmap_access_table tla2024_writeable_table = { + .yes_ranges = tla2024_writeable_ranges, + .n_yes_ranges = ARRAY_SIZE(tla2024_writeable_ranges), +}; + +static const struct regmap_config tla2024_regmap_config = { + .reg_bits = 8, + .val_bits = 16, + .max_register = ADS1015_CFG_REG, + .wr_table = &tla2024_writeable_table, +}; + static const struct iio_chan_spec ads1015_channels[] = { ADS1015_V_DIFF_CHAN(0, 1, ADS1015_AIN0_AIN1, 12, 4, ads1015_events, ARRAY_SIZE(ads1015_events)), @@ -287,6 +304,19 @@ static const struct iio_chan_spec ads1115_channels[] = { IIO_CHAN_SOFT_TIMESTAMP(ADS1015_TIMESTAMP), }; +static const struct iio_chan_spec tla2024_channels[] = { + ADS1015_V_DIFF_CHAN(0, 1, ADS1015_AIN0_AIN1, 12, 4, NULL, 0), + ADS1015_V_DIFF_CHAN(0, 3, ADS1015_AIN0_AIN3, 12, 4, NULL, 0), + ADS1015_V_DIFF_CHAN(1, 3, ADS1015_AIN1_AIN3, 12, 4, NULL, 0), + ADS1015_V_DIFF_CHAN(2, 3, ADS1015_AIN2_AIN3, 12, 4, NULL, 0), + ADS1015_V_CHAN(0, ADS1015_AIN0, 12, 4, NULL, 0), + ADS1015_V_CHAN(1, ADS1015_AIN1, 12, 4, NULL, 0), + ADS1015_V_CHAN(2, ADS1015_AIN2, 12, 4, NULL, 0), + ADS1015_V_CHAN(3, ADS1015_AIN3, 12, 4, NULL, 0), + IIO_CHAN_SOFT_TIMESTAMP(ADS1015_TIMESTAMP), +}; + + #ifdef CONFIG_PM static int ads1015_set_power_state(struct ads1015_data *data, bool on) { @@ -823,6 +853,12 @@ static const struct iio_info ads1115_info = { .attrs = &ads1115_attribute_group, }; +static const struct iio_info tla2024_info = { + .read_raw = ads1015_read_raw, + .write_raw = ads1015_write_raw, + .attrs = &ads1015_attribute_group, +}; + static int ads1015_client_get_channels_config(struct i2c_client *client) { struct iio_dev *indio_dev = i2c_get_clientdata(client); @@ -937,6 +973,12 @@ static int ads1015_probe(struct i2c_client *client, indio_dev->info = &ads1115_info; data->data_rate = (unsigned int *) &ads1115_data_rate; break; + case TLA2024: + indio_dev->channels = tla2024_channels; + indio_dev->num_channels = ARRAY_SIZE(tla2024_channels); + indio_dev->info = &tla2024_info; + data->data_rate = (unsigned int *) &ads1015_data_rate; + break; default: dev_err(&client->dev, "Unknown chip %d\n", chip); return -EINVAL; @@ -957,7 +999,9 @@ static int ads1015_probe(struct i2c_client *client, /* we need to keep this ABI the same as used by hwmon ADS1015 driver */ ads1015_get_channels_config(client); - data->regmap = devm_regmap_init_i2c(client, &ads1015_regmap_config); + data->regmap = devm_regmap_init_i2c(client, (chip == TLA2024) ? + &tla2024_regmap_config : + &ads1015_regmap_config); if (IS_ERR(data->regmap)) { dev_err(&client->dev, "Failed to allocate register map\n"); return PTR_ERR(data->regmap); @@ -971,7 +1015,7 @@ static int ads1015_probe(struct i2c_client *client, return ret; } - if (client->irq) { + if (client->irq && chip != TLA2024) { unsigned long irq_trig = irqd_get_trigger_type(irq_get_irq_data(client->irq)); unsigned int cfg_comp_mask = ADS1015_CFG_COMP_QUE_MASK | @@ -1073,6 +1117,7 @@ static const struct dev_pm_ops ads1015_pm_ops = { static const struct i2c_device_id ads1015_id[] = { {"ads1015", ADS1015}, {"ads1115", ADS1115}, + {"tla2024", TLA2024}, {} }; MODULE_DEVICE_TABLE(i2c, ads1015_id); @@ -1086,6 +1131,10 @@ static const struct of_device_id ads1015_of_match[] = { .compatible = "ti,ads1115", .data = (void *)ADS1115 }, + { + .compatible = "ti,tla2024", + .data = (void *)TLA2024 + }, {} }; MODULE_DEVICE_TABLE(of, ads1015_of_match);