Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp934884lqo; Fri, 17 May 2024 06:15:30 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW5spC2hfaIORlkFX1qz0NauG5RO4CsIBYHDv/nhCanqQs4nNilY3JqT0iN3/aXYZmpN1G1nbGs01mRmojJnRqgX8siwipqhNHlOA6IKw== X-Google-Smtp-Source: AGHT+IH8QGx/JF5UIs+sh0EAMba4Xl9hZY7vjFyGmiFb8oU6Bx8lF9JD0ELIuz1sjdckQB0bqUmd X-Received: by 2002:a50:a45b:0:b0:568:32cc:f808 with SMTP id 4fb4d7f45d1cf-5734d5cf9a5mr14494108a12.15.1715951729854; Fri, 17 May 2024 06:15:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715951729; cv=pass; d=google.com; s=arc-20160816; b=viUpkQ6Z+DJKBAWwefwqbQsqyUmOHbGBi+Qod2Lw92Synt5UqLNOIWcj6xk8ylfxeT DlbC2K/P65cq4GSokSSVQ5x00hBrU5IwHIAfhtTHoz79mLwyCXWCKtDd6HxhhcUPAVLO NSH7173m+hqOUb7WU1h5fvPVa1o+pPEYXBl7dHYeHRFXgr91MIjwiJEQbZ4WJIfZCcNr bfBl6gEDxyscOmn71kxF68vX1SXFYzNtXH/RQw3gYK5MwHzNQvlh/nT6WoCOj1opzBlM W2xnszlvWsop2mN74qn9VPncwjeWGm4G5YeS8jg8TwXhY2wUKw4486m6DL83ldKxm33J kkrw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=furiSTSuRDcRd2X5RjG7qZBiz4mVfyegHighaEnbVrw=; fh=eWggdLazXcUXncaZ6QlZnj4lONIov1bc4JkVW6Q/2sw=; b=F9hFveMkyfvLJtA2DQDWDR17MdEWS7jBtlqzrlps1WC7wTwegF+L/mtrcIxYtt077P D+fk5SSeB1pn34ZGbqbHLhyrfo3VhI2SgkOtBFY/JDJ6AOr6AH3DNO0hJxIPCCMwg9gW NhHLn5PKcTUC4H3r5J7kCvS1cLbmuUDsfq6HgbbAiVtxJO+qVwXJUeyl0/aZdY9SB6qR MVd5fwyotw4OKwjxPXePhK2H9EZwOS/WsT5U/N4yIb7ms1K9kjO6VfKxZIOaxLHuO8Pf 7ipbgCbnXvVhKiB533psAjLyawmR5v4igzIrFu8b3WjMwRRQeQ3s1xWk9TawQATbWJ1N yEZg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@pqrs.dk header.s=key1 header.b=JDHKZcgV; arc=pass (i=1 spf=pass spfdomain=pqrs.dk dkim=pass dkdomain=pqrs.dk); spf=pass (google.com: domain of linux-kernel+bounces-182134-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182134-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-5751ba1b7dbsi903002a12.394.2024.05.17.06.15.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 May 2024 06:15:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-182134-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=@pqrs.dk header.s=key1 header.b=JDHKZcgV; arc=pass (i=1 spf=pass spfdomain=pqrs.dk dkim=pass dkdomain=pqrs.dk); spf=pass (google.com: domain of linux-kernel+bounces-182134-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182134-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 6E30A1F21DAB for ; Fri, 17 May 2024 13:15:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B9DA4535D0; Fri, 17 May 2024 13:15:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pqrs.dk header.i=@pqrs.dk header.b="JDHKZcgV" Received: from out-177.mta0.migadu.com (out-177.mta0.migadu.com [91.218.175.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E727652F9A; Fri, 17 May 2024 13:15:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715951716; cv=none; b=Ow5wz3B6DLqq2kky4lEIe7qXpSOS5r67BbSfnZ9dbLwUY92/dqHFos2w4rS1SLBbGPgY7Qih0xiTtDb65Sw8IVq5jLq//xpfhfghsGeCocF3wK4UkhUFM4QJxPSoU9PXcPTeHDGeZL09BKCMbK6rUw4JoD1lPVj0pmGbYh6qWgk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715951716; c=relaxed/simple; bh=RsFQ+OoWI70l8JgaWfMkVQEqy2Jyx6j6QbNtAz2F3Og=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Vm5NRkUEQkKq/2WKI2td+4O+qivZhghIgCAcoXcK9z6H62AwqOzukuv29R2DPPudn46Fd8BrGBFUFKq1mE8x4Pgiz2OPRyiMNfutHCiolMLPmGb4QlbQFjAQ7YuRHvau5Q9WPrtD9TzkQMCkrOcbqKK6T1Yp4nSXYllOw+lNmrA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pqrs.dk; spf=pass smtp.mailfrom=pqrs.dk; dkim=pass (2048-bit key) header.d=pqrs.dk header.i=@pqrs.dk header.b=JDHKZcgV; arc=none smtp.client-ip=91.218.175.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pqrs.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pqrs.dk X-Envelope-To: broonie@kernel.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pqrs.dk; s=key1; t=1715951712; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=furiSTSuRDcRd2X5RjG7qZBiz4mVfyegHighaEnbVrw=; b=JDHKZcgVd02Cb1jDAPb5lrgjO495Vpvj9ji4ic/EfRVzYyJQNEjMkzTNbvvHUEtnaliot9 26zTd5DMIHj+qdqgSOoLzNOrGrBK99F4imlHxN9jhghXnM3Nf8IPXAk+Biawbp2ltvPraM e/jgiNIMiZp7oDb8hfl24NGNfL2OtOhHVDYENNXgJUIHz9kSHpusr4Thc7Xo6iV9m4Yd4I ijir9dYa/zPXHhAHbEV0iJm/d8Vo2BSww8dNlDV8dZY3PeEzwz2Vs/pzPuVEQPasS2A+QG CUyKyKvkMU0R2HdTOnnRDTO1sn/2WvgYyiL8eKWHCioYt6ytpxak/IwW6JWRYg== X-Envelope-To: gregkh@linuxfoundation.org X-Envelope-To: rafael@kernel.org X-Envelope-To: robh@kernel.org X-Envelope-To: krzk+dt@kernel.org X-Envelope-To: conor+dt@kernel.org X-Envelope-To: linus.walleij@linaro.org X-Envelope-To: brgl@bgdev.pl X-Envelope-To: lgirdwood@gmail.com X-Envelope-To: perex@perex.cz X-Envelope-To: tiwai@suse.com X-Envelope-To: mturquette@baylibre.com X-Envelope-To: sboyd@kernel.org X-Envelope-To: andi.shyti@kernel.org X-Envelope-To: saravanak@google.com X-Envelope-To: emas@bang-olufsen.dk X-Envelope-To: linux-kernel@vger.kernel.org X-Envelope-To: devicetree@vger.kernel.org X-Envelope-To: linux-gpio@vger.kernel.org X-Envelope-To: linux-sound@vger.kernel.org X-Envelope-To: linux-clk@vger.kernel.org X-Envelope-To: linux-i2c@vger.kernel.org X-Envelope-To: alsi@bang-olufsen.dk X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: =?utf-8?q?Alvin_=C5=A0ipraga?= Date: Fri, 17 May 2024 15:02:16 +0200 Subject: [PATCH 09/13] i2c: add AD24xx I2C controller driver Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20240517-a2b-v1-9-b8647554c67b@bang-olufsen.dk> References: <20240517-a2b-v1-0-b8647554c67b@bang-olufsen.dk> In-Reply-To: <20240517-a2b-v1-0-b8647554c67b@bang-olufsen.dk> To: Mark Brown , Greg Kroah-Hartman , "Rafael J. Wysocki" , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Linus Walleij , Bartosz Golaszewski , Liam Girdwood , Jaroslav Kysela , Takashi Iwai , Michael Turquette , Stephen Boyd , Andi Shyti , Saravana Kannan Cc: Emil Svendsen , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-gpio@vger.kernel.org, linux-sound@vger.kernel.org, linux-clk@vger.kernel.org, linux-i2c@vger.kernel.org, =?utf-8?q?Alvin_=C5=A0ipraga?= X-Migadu-Flow: FLOW_OUT From: Alvin Šipraga Signed-off-by: Alvin Šipraga --- drivers/a2b/Kconfig | 1 + drivers/clk/Kconfig | 2 +- drivers/i2c/busses/Kconfig | 7 +++ drivers/i2c/busses/Makefile | 1 + drivers/i2c/busses/i2c-ad24xx.c | 121 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 131 insertions(+), 1 deletion(-) diff --git a/drivers/a2b/Kconfig b/drivers/a2b/Kconfig index 08acf5728023..e3c38520a90a 100644 --- a/drivers/a2b/Kconfig +++ b/drivers/a2b/Kconfig @@ -36,6 +36,7 @@ config A2B_AD24XX_NODE imply GPIO_AD24XX imply SND_SOC_AD24XX imply COMMON_CLK_AD24XX + imply I2C_AD24XX help Say Y here to enable support for AD24xx A2B transceiver nodes. This applies to both main nodes and subordinate nodes. Supported models diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig index a3d54b077e68..460762f44434 100644 --- a/drivers/clk/Kconfig +++ b/drivers/clk/Kconfig @@ -258,7 +258,7 @@ config COMMON_CLK_LAN966X within the SoC. config COMMON_CLK_AD24XX - bool "Clock driver for Analog Devices Inc. AD24xx" + tristate "Clock driver for Analog Devices Inc. AD24xx" depends on A2B_AD24XX_NODE help This driver supports the clock output functionality of AD24xx series diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig index fe6e8a1bb607..d1f303bd7c90 100644 --- a/drivers/i2c/busses/Kconfig +++ b/drivers/i2c/busses/Kconfig @@ -1387,6 +1387,13 @@ config I2C_ACORN If you don't know, say Y. +config I2C_AD24XX + tristate "Analog Devices Inc. AD24xx I2C controller support" + depends on A2B_AD24XX_NODE + help + Say yes if you want to support the I2C controller function of AD24xx + A2B transceiver chips. + config I2C_ELEKTOR tristate "Elektor ISA card" depends on ISA && HAS_IOPORT_MAP && BROKEN_ON_SMP diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile index 3d65934f5eb4..892a32b02267 100644 --- a/drivers/i2c/busses/Makefile +++ b/drivers/i2c/busses/Makefile @@ -145,6 +145,7 @@ obj-$(CONFIG_I2C_VIPERBOARD) += i2c-viperboard.o # Other I2C/SMBus bus drivers obj-$(CONFIG_I2C_ACORN) += i2c-acorn.o +obj-$(CONFIG_I2C_AD24XX) += i2c-ad24xx.o obj-$(CONFIG_I2C_BCM_KONA) += i2c-bcm-kona.o obj-$(CONFIG_I2C_BRCMSTB) += i2c-brcmstb.o obj-$(CONFIG_I2C_CROS_EC_TUNNEL) += i2c-cros-ec-tunnel.o diff --git a/drivers/i2c/busses/i2c-ad24xx.c b/drivers/i2c/busses/i2c-ad24xx.c new file mode 100644 index 000000000000..ad9657df25fb --- /dev/null +++ b/drivers/i2c/busses/i2c-ad24xx.c @@ -0,0 +1,121 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * AD24xx I2C controller (master) driver + * + * Copyright (c) 2023-2024 Alvin Šipraga + */ + +#include +#include +#include +#include +#include + +struct ad24xx_i2c_adapter { + struct device *dev; + struct a2b_func *func; + struct a2b_node *node; + struct i2c_adapter adap; +}; + +static int ad24xx_i2c_adapter_xfer(struct i2c_adapter *adap, + struct i2c_msg *msgs, int num) +{ + struct ad24xx_i2c_adapter *ada = i2c_get_adapdata(adap); + struct a2b_node *node = ada->node; + + return a2b_node_i2c_xfer(node, msgs, num); +} + +static u32 ad24xx_i2c_adapter_functionality(struct i2c_adapter *adap) +{ + return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; +} + +static const struct i2c_adapter_quirks ad24xx_i2c_adapter_quirks = { + .flags = I2C_AQ_COMB | I2C_AQ_COMB_SAME_ADDR, +}; + +static const struct i2c_algorithm ad24xx_i2c_adapter_algo = { + .master_xfer = ad24xx_i2c_adapter_xfer, + .functionality = ad24xx_i2c_adapter_functionality, +}; + +static int ad24xx_i2c_adapter_probe(struct device *dev) +{ + struct a2b_func *func = to_a2b_func(dev); + struct device_node *np = dev->of_node; + struct ad24xx_i2c_adapter *ada; + unsigned int val = 0; + u32 bus_speed; + int ret; + + ada = devm_kzalloc(dev, sizeof(*ada), GFP_KERNEL); + if (!ada) + return -ENOMEM; + + ada->dev = dev; + ada->func = func; + ada->node = func->node; + + ada->adap.owner = THIS_MODULE; + ada->adap.algo = &ad24xx_i2c_adapter_algo; + ada->adap.dev.parent = dev; + ada->adap.dev.of_node = dev->of_node; + ada->adap.quirks = &ad24xx_i2c_adapter_quirks; + strscpy(ada->adap.name, dev_name(dev), sizeof(ada->adap.name)); + i2c_set_adapdata(&ada->adap, ada); + + ret = of_property_read_u32(np, "clock-frequency", &bus_speed); + if (ret) + bus_speed = I2C_MAX_STANDARD_MODE_FREQ; + + if (bus_speed != I2C_MAX_STANDARD_MODE_FREQ && + bus_speed != I2C_MAX_FAST_MODE_FREQ) + return -EINVAL; + + val |= FIELD_PREP(A2B_I2CCFG_DATARATE_MASK, + bus_speed == I2C_MAX_FAST_MODE_FREQ ? 1 : 0); + val |= FIELD_PREP(A2B_I2CCFG_FRAMERATE_MASK, + func->node->bus->sff == A2B_SFF_44100 ? 1 : 0); + + ret = a2b_node_write(func->node, A2B_I2CCFG, val); + if (ret) + return ret; + + ret = devm_i2c_add_adapter(dev, &ada->adap); + if (ret) + return ret; + + return 0; +} + +static const struct of_device_id ad24xx_i2c_adapter_of_match_table[] = { + { .compatible = "adi,ad2401-i2c" }, + { .compatible = "adi,ad2402-i2c" }, + { .compatible = "adi,ad2403-i2c" }, + { .compatible = "adi,ad2410-i2c" }, + { .compatible = "adi,ad2420-i2c" }, + { .compatible = "adi,ad2421-i2c" }, + { .compatible = "adi,ad2422-i2c" }, + { .compatible = "adi,ad2425-i2c" }, + { .compatible = "adi,ad2426-i2c" }, + { .compatible = "adi,ad2427-i2c" }, + { .compatible = "adi,ad2428-i2c" }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, ad24xx_i2c_adapter_of_match_table); + +static struct a2b_driver ad24xx_i2c_adapter_driver = { + .driver = { + .name = "ad24xx-i2c-adapter", + .of_match_table = ad24xx_i2c_adapter_of_match_table, + .probe_type = PROBE_PREFER_ASYNCHRONOUS, + }, + .probe = ad24xx_i2c_adapter_probe, +}; +module_a2b_driver(ad24xx_i2c_adapter_driver); + +MODULE_AUTHOR("Alvin Šipraga "); +MODULE_DESCRIPTION("AD24xx I2C controller driver"); +MODULE_LICENSE("GPL"); -- 2.44.0