Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3524391pxj; Tue, 15 Jun 2021 02:52:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwMoyFbeKFimzDBU+/5LnpklQfHU15kFahUV2p7WAhgXQsHMKC7Xy17ldFppxxJPts5D2m3 X-Received: by 2002:a17:907:207c:: with SMTP id qp28mr2938715ejb.311.1623750741461; Tue, 15 Jun 2021 02:52:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623750741; cv=none; d=google.com; s=arc-20160816; b=g6nqhOyNVcN9Io1IbRtDj0hADvlQ0EidaP2XEQhXMPMGVzSKyLG6KmCZAJGljUpjSY tPYc6s0w5HUrulw8/RCxP0tyRCmgGooW78zhhtt1xSJvjAHvHSI8dAoz1gU4NTAVxIPC Jlp5noKdKUQJ9FecB7POW3C35OImhy1snCR9c8pcVHUVSXDPQzqM1uBzCf9wev66Ebbo ZLxlSNBf0wGhEo8sbm5RJ/Ago6w9s1Jua3zCGnISo1b9Ykfk3EzDa59oN/mgKQopj2jb LF3XfKVNVxCzEYIi/0OXdCvD8jBWA2WA75Csjh8kOiaAb3AQWOggIuApFztKJSvmBdMM 85Ew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=JCWe2Pppm54xIbq3MRVedz6t/yAOYnrWI/3oKnXOGhw=; b=pT4QVRhEdxGBjiOaTa3zwvPRr7MwnGsWb0+RdJI06lXI211aTjykOgKpnDi4mHqb3w A1wJuTUmKe5RiFSpIEMFZE3RkHhABRM7Up6rCT0hTvITXVbjQ0Ab8PcQ10JaSVQSnxvT R6GRU9jUHJQAnhgHFKWcYbyN+avnrEjfTZIofVWURYIKyR8n3ZiyO5InIvMGiTfH1eD2 0UOcCj0pKJ3hwaT+6jy1p0iVYzChsHdwL9XVN118uUlJ1A1nqzS7dBxhXW7y5eY5xfhs grejcozpZPHu5eRDatflMMDMuDfbNqhnRsx0whgKeONJUwQvqGHqt/eDe98OHNQdvvaW NcUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@denx.de header.s=phobos-20191101 header.b=zLt7bq3h; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 1si12994479ejm.532.2021.06.15.02.51.58; Tue, 15 Jun 2021 02:52:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@denx.de header.s=phobos-20191101 header.b=zLt7bq3h; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231393AbhFOJwr (ORCPT + 99 others); Tue, 15 Jun 2021 05:52:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231374AbhFOJwq (ORCPT ); Tue, 15 Jun 2021 05:52:46 -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 0B90FC061574 for ; Tue, 15 Jun 2021 02:50:42 -0700 (PDT) Received: from localhost (dslb-084-062-104-230.084.062.pools.vodafone-ip.de [84.62.104.230]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: ch@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id B9400826AA; Tue, 15 Jun 2021 11:50:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1623750637; bh=JCWe2Pppm54xIbq3MRVedz6t/yAOYnrWI/3oKnXOGhw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=zLt7bq3hJ7+bB/4f6Kr64VKtk39m+q6KDJD6hItaQJpB4piprrOnfwnxsu5oWFzdb 951Yb7DUrEtfXueIjm93SWGH+tunvlbyX9PNp1fEk+x31EmJi/5t33lRrgQQgC9LG4 7cJrTMk0n7Hpc2X91YIQdmazyko2jx5W2LG1Y8WP3SwJ725NgnownyWHvEqYi8fwT9 nOH6DCxfnATcxZ9RFiRcCFiYfXQ+xBOHlvUR/Q0vEQDNgtXnlke2VHnPSOwSedtv2r 8LTWrb7jOrl2J5FF6dMERRmSBg/0nDHjIw44JHIl2O5AEiqInnl6h4VPLUsIEoQW3C 3VJCXBiU3PTZA== From: Claudius Heine To: Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai , alsa-devel@alsa-project.org, Marek Vasut , Claudius Heine , Kuninori Morimoto , Sia Jee Heng , Pierre-Louis Bossart , Michael Sit Wei Hong , Miquel Raynal , Annaliese McDermond , Matthias Schiffer , linux-kernel@vger.kernel.org (open list) Subject: [PATCH 1/3] ASoC: tlv320aic32x4: prepare driver for different device variants Date: Tue, 15 Jun 2021 11:49:30 +0200 Message-Id: <20210615094933.3076392-2-ch@denx.de> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210615094933.3076392-1-ch@denx.de> References: <20210615094933.3076392-1-ch@denx.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With this change it will be possible to add different code paths for similar devices. Signed-off-by: Claudius Heine --- sound/soc/codecs/tlv320aic32x4-i2c.c | 20 ++++++++++++++++---- sound/soc/codecs/tlv320aic32x4-spi.c | 23 +++++++++++++++++++---- sound/soc/codecs/tlv320aic32x4.c | 3 +++ sound/soc/codecs/tlv320aic32x4.h | 5 +++++ 4 files changed, 43 insertions(+), 8 deletions(-) diff --git a/sound/soc/codecs/tlv320aic32x4-i2c.c b/sound/soc/codecs/tlv320aic32x4-i2c.c index 6d54cbf70a0b..247fb1e13674 100644 --- a/sound/soc/codecs/tlv320aic32x4-i2c.c +++ b/sound/soc/codecs/tlv320aic32x4-i2c.c @@ -16,6 +16,8 @@ #include "tlv320aic32x4.h" +static const struct of_device_id aic32x4_of_id[]; + static int aic32x4_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { @@ -27,6 +29,16 @@ static int aic32x4_i2c_probe(struct i2c_client *i2c, config.val_bits = 8; regmap = devm_regmap_init_i2c(i2c, &config); + + if (i2c->dev.of_node) { + const struct of_device_id *oid; + + oid = of_match_node(aic32x4_of_id, i2c->dev.of_node); + dev_set_drvdata(&i2c->dev, (void *)oid->data); + } else if (id) { + dev_set_drvdata(&i2c->dev, (void *)id->driver_data); + } + return aic32x4_probe(&i2c->dev, regmap); } @@ -36,15 +48,15 @@ static int aic32x4_i2c_remove(struct i2c_client *i2c) } static const struct i2c_device_id aic32x4_i2c_id[] = { - { "tlv320aic32x4", 0 }, - { "tlv320aic32x6", 1 }, + { "tlv320aic32x4", (kernel_ulong_t)AIC32X4_TYPE_AIC32X4 }, + { "tlv320aic32x6", (kernel_ulong_t)AIC32X4_TYPE_AIC32X6 }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(i2c, aic32x4_i2c_id); static const struct of_device_id aic32x4_of_id[] = { - { .compatible = "ti,tlv320aic32x4", }, - { .compatible = "ti,tlv320aic32x6", }, + { .compatible = "ti,tlv320aic32x4", .data = (void *)AIC32X4_TYPE_AIC32X4 }, + { .compatible = "ti,tlv320aic32x6", .data = (void *)AIC32X4_TYPE_AIC32X6 }, { /* senitel */ } }; MODULE_DEVICE_TABLE(of, aic32x4_of_id); diff --git a/sound/soc/codecs/tlv320aic32x4-spi.c b/sound/soc/codecs/tlv320aic32x4-spi.c index a22e7700bfc8..e81c72958a82 100644 --- a/sound/soc/codecs/tlv320aic32x4-spi.c +++ b/sound/soc/codecs/tlv320aic32x4-spi.c @@ -16,6 +16,8 @@ #include "tlv320aic32x4.h" +static const struct of_device_id aic32x4_of_id[]; + static int aic32x4_spi_probe(struct spi_device *spi) { struct regmap *regmap; @@ -28,6 +30,19 @@ static int aic32x4_spi_probe(struct spi_device *spi) config.read_flag_mask = 0x01; regmap = devm_regmap_init_spi(spi, &config); + + if (spi->dev.of_node) { + const struct of_device_id *oid; + + oid = of_match_node(aic32x4_of_id, spi->dev.of_node); + dev_set_drvdata(&spi->dev, (void *)oid->data); + } else { + const struct spi_device_id *id_entry; + + id_entry = spi_get_device_id(spi); + dev_set_drvdata(&spi->dev, (void *)id_entry->driver_data); + } + return aic32x4_probe(&spi->dev, regmap); } @@ -37,15 +52,15 @@ static int aic32x4_spi_remove(struct spi_device *spi) } static const struct spi_device_id aic32x4_spi_id[] = { - { "tlv320aic32x4", 0 }, - { "tlv320aic32x6", 1 }, + { "tlv320aic32x4", (kernel_ulong_t)AIC32X4_TYPE_AIC32X4 }, + { "tlv320aic32x6", (kernel_ulong_t)AIC32X4_TYPE_AIC32X6 }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(spi, aic32x4_spi_id); static const struct of_device_id aic32x4_of_id[] = { - { .compatible = "ti,tlv320aic32x4", }, - { .compatible = "ti,tlv320aic32x6", }, + { .compatible = "ti,tlv320aic32x4", .data = (void *)AIC32X4_TYPE_AIC32X4 }, + { .compatible = "ti,tlv320aic32x6", .data = (void *)AIC32X4_TYPE_AIC32X6 }, { /* senitel */ } }; MODULE_DEVICE_TABLE(of, aic32x4_of_id); diff --git a/sound/soc/codecs/tlv320aic32x4.c b/sound/soc/codecs/tlv320aic32x4.c index b689f26fc4be..70a1574fb72a 100644 --- a/sound/soc/codecs/tlv320aic32x4.c +++ b/sound/soc/codecs/tlv320aic32x4.c @@ -48,6 +48,7 @@ struct aic32x4_priv { struct aic32x4_setup_data *setup; struct device *dev; + enum aic32x4_type type; }; static int aic32x4_reset_adc(struct snd_soc_dapm_widget *w, @@ -1198,6 +1199,8 @@ int aic32x4_probe(struct device *dev, struct regmap *regmap) return -ENOMEM; aic32x4->dev = dev; + aic32x4->type = (enum aic32x4_type)dev_get_drvdata(dev); + dev_set_drvdata(dev, aic32x4); if (pdata) { diff --git a/sound/soc/codecs/tlv320aic32x4.h b/sound/soc/codecs/tlv320aic32x4.h index 7550122e9f8a..8a18dbec76a6 100644 --- a/sound/soc/codecs/tlv320aic32x4.h +++ b/sound/soc/codecs/tlv320aic32x4.h @@ -10,6 +10,11 @@ struct device; struct regmap_config; +enum aic32x4_type { + AIC32X4_TYPE_AIC32X4 = 0, + AIC32X4_TYPE_AIC32X6, +}; + extern const struct regmap_config aic32x4_regmap_config; int aic32x4_probe(struct device *dev, struct regmap *regmap); int aic32x4_remove(struct device *dev); -- 2.32.0