From patchwork Mon Oct 31 20:37:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Bergin X-Patchwork-Id: 13432 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2536087wru; Mon, 31 Oct 2022 13:42:30 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4dy2j/j4gEUZpT/mGhfP6gc3ePxUaReXfxnhmfL+TMcbyKWWvHa1RjuCZc7FlKnwZBDf1s X-Received: by 2002:a17:90b:3149:b0:213:63d0:88d6 with SMTP id ip9-20020a17090b314900b0021363d088d6mr16698119pjb.145.1667248950659; Mon, 31 Oct 2022 13:42:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667248950; cv=none; d=google.com; s=arc-20160816; b=KihNde5ZmTsuD+YmRujMQLyzTWDHy71+fGILCa+xdFr/IUZOIvFTRpLlZN9zGlZYO8 h1wYt/fzxjiVukNLJxoSW3xCCdPLOTGd1nIQtmZbSPIa9tVMCn9v/jGg842IQkgYRoqj jVwVw1oYBBTl0nxaNSq2fFXAOlEbhn0tSwIChohVx7rThoHAE7TMrpT5T3KZbbT7ulF5 0F+ulgXdkjDXwhaeI4kGTpnqNOSAokxJBPrb9e8/QzEBWgaKn1qlFzf1xkm4ANUwN8I6 4wKq9oUCyWY29I2FYL0vmgHfzFxSlN6a8u/eDp204ZgaEc8EZPSFTivcq0nnvu8JlfTm vGIg== 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 :message-id:date:subject:cc:to:from:dkim-signature:dkim-signature; bh=LZgWzj1DV2YwhApqlnR9pyjFzmdX/olcHYd6kth181k=; b=TOu8JbqwdI2JsET9txihs/qQaMgVw2ocHgBDtnfrERXgFrb0GAZMEZyqrP+1S9fD2j JN9kt3zsIyPNxG2BFFZRpSjZ74iA3+8CKGo2DI1WSYuuBNjEagBqclOtJ0IhNSQzQZhm rqh4YRzHzGD9nbcnEbZUwPr87FoyVDjOeTIhbdY3tqhMItqHEzvWGMQ4TWw8MVCkAhdr s4kcZJ9qREmIqOkFvJsP5wur4R/u2nJ/rQlgx/NpNZvdbkl5N+RaGQXsg3tXfLK68HOs 40xFDBEJxsWDjmFazz/gp+Mn4bBoKFbflfGHhZKlJq8J6nCb4j9uFyynD9Ah4qkDiN9u SVjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@berginkonsult.se header.s=rsa1 header.b=cw2wtB63; dkim=neutral (no key) header.i=@berginkonsult.se header.s=ed1 header.b=UUbWdtHD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t27-20020a056a00139b00b00561fb77aed3si11039607pfg.368.2022.10.31.13.42.17; Mon, 31 Oct 2022 13:42:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@berginkonsult.se header.s=rsa1 header.b=cw2wtB63; dkim=neutral (no key) header.i=@berginkonsult.se header.s=ed1 header.b=UUbWdtHD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229991AbiJaUiQ (ORCPT + 99 others); Mon, 31 Oct 2022 16:38:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229973AbiJaUiN (ORCPT ); Mon, 31 Oct 2022 16:38:13 -0400 Received: from mailrelay3-1.pub.mailoutpod1-cph3.one.com (mailrelay3-1.pub.mailoutpod1-cph3.one.com [46.30.210.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B58B113D22 for ; Mon, 31 Oct 2022 13:38:11 -0700 (PDT) Received: from mailrelay2.pub.mailoutpod2-cph3.one.com (mailrelay2.pub.mailoutpod2-cph3.one.com [104.37.34.7]) by mailrelay3.pub.mailoutpod1-cph3.one.com (Halon) with ESMTPS id ee750666-595b-11ed-be8b-d0431ea8bb03; Mon, 31 Oct 2022 20:38:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=berginkonsult.se; s=rsa1; h=content-transfer-encoding:mime-version:message-id:date:subject:cc:to:from: from; bh=LZgWzj1DV2YwhApqlnR9pyjFzmdX/olcHYd6kth181k=; b=cw2wtB63eQ+YbjTSWFVI8qwuoAoCJohU00hA1XaMa2wXrQu3zg25SPFjm4GGlsXrMLgBNpGqd330d dHtflKrhHaNMLn+JSoQbAxSGT4Tohjem9mssfmPp/NDhfJE0f2Yke5qYXTsViEkfSHn13tmeO/HhLW 5QcZ1VOCZ1ZrgRj8+OCvhmN0moTXy4dc/aK3UuO8/Xuwoj9bvn4DEbAkYRA9exkjo5ddjsxjSrZsJn Z1bjpztiRvE3rNZPk74c+hYESJkZQ4ayGCQzwZ7BLMCWOCeD52ZeOOB3qrAyAUS2VIL416ddxgE4D8 pfaVe3GtG/AD1nURqI/QKRMY5Q86h1A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=berginkonsult.se; s=ed1; h=content-transfer-encoding:mime-version:message-id:date:subject:cc:to:from: from; bh=LZgWzj1DV2YwhApqlnR9pyjFzmdX/olcHYd6kth181k=; b=UUbWdtHD61jjgMwJMFUmB3eL3k7QZloqeKzvNRGODN8Lc60htWCV6rB42a0H1XAKOJuNFgaggEZQm 98DANqXDQ== X-HalOne-ID: ec594405-595b-11ed-a68e-335755252108 Received: from pbergin-7420.. (ua-213-113-159-147.bbcust.telenor.se [213.113.159.147]) by mailrelay2 (Halon) with ESMTPSA id ec594405-595b-11ed-a68e-335755252108; Mon, 31 Oct 2022 20:38:09 +0000 (UTC) From: Peter Bergin To: james.schulman@cirrus.com, david.rhodes@cirrus.com, tanureal@opensource.cirrus.com, rf@opensource.cirrus.com, broonie@kernel.org, ckeepax@opensource.cirrus.com Cc: Peter Bergin , Liam Girdwood , Jaroslav Kysela , Takashi Iwai , alsa-devel@alsa-project.org, patches@opensource.cirrus.com, linux-kernel@vger.kernel.org Subject: [PATCH v3] ASoC: cs42xx8-i2c.c: add module device table for of Date: Mon, 31 Oct 2022 21:37:23 +0100 Message-Id: <20221031203723.168177-1-peter@berginkonsult.se> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748237235746234962?= X-GMAIL-MSGID: =?utf-8?q?1748237235746234962?= When trying to connect the device with the driver through device-tree it is not working. The of_device_id is defined in cs42xx8.c but is not correctly included in cs42xx8-i2c.c. Move of_device_id table to cs42xx8-i2c.c. Get cs42xx8_driver_data in cs42xx8_i2c_probe() and pass as argument to cs42xx8_probe(). Move error check if no driver data found to cs42xx8_i2c_probe(). Signed-off-by: Peter Bergin Acked-by: Charles Keepax --- v3: Revert new funtionality in _probe and not changing behavior. Move back data structs to common module to be able to use for other interfaces later. v2: reworked and removed duplication of cs42xx8_of_match sound/soc/codecs/cs42xx8-i2c.c | 28 +++++++++++++++++++++++++--- sound/soc/codecs/cs42xx8.c | 22 +++------------------- sound/soc/codecs/cs42xx8.h | 3 +-- 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/sound/soc/codecs/cs42xx8-i2c.c b/sound/soc/codecs/cs42xx8-i2c.c index bd80e9fc907f..052ffb7dcfc6 100644 --- a/sound/soc/codecs/cs42xx8-i2c.c +++ b/sound/soc/codecs/cs42xx8-i2c.c @@ -12,15 +12,30 @@ #include #include +#include #include #include #include "cs42xx8.h" +static const struct of_device_id cs42xx8_of_match[]; + static int cs42xx8_i2c_probe(struct i2c_client *i2c) { - int ret = cs42xx8_probe(&i2c->dev, - devm_regmap_init_i2c(i2c, &cs42xx8_regmap_config)); + int ret; + struct cs42xx8_driver_data *drvdata; + const struct of_device_id *of_id; + + of_id = of_match_device(cs42xx8_of_match, &i2c->dev); + if (!of_id) { + dev_err(&i2c->dev, "failed to find driver data\n"); + return -EINVAL; + } + + drvdata = (struct cs42xx8_driver_data *)of_id->data; + + ret = cs42xx8_probe(&i2c->dev, + devm_regmap_init_i2c(i2c, &cs42xx8_regmap_config), drvdata); if (ret) return ret; @@ -35,7 +50,14 @@ static void cs42xx8_i2c_remove(struct i2c_client *i2c) pm_runtime_disable(&i2c->dev); } -static struct i2c_device_id cs42xx8_i2c_id[] = { +static const struct of_device_id cs42xx8_of_match[] = { + { .compatible = "cirrus,cs42448", .data = &cs42448_data, }, + { .compatible = "cirrus,cs42888", .data = &cs42888_data, }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, cs42xx8_of_match); + +static const struct i2c_device_id cs42xx8_i2c_id[] = { {"cs42448", (kernel_ulong_t)&cs42448_data}, {"cs42888", (kernel_ulong_t)&cs42888_data}, {} diff --git a/sound/soc/codecs/cs42xx8.c b/sound/soc/codecs/cs42xx8.c index d14eb2f6e1dd..4558ec38a7ac 100644 --- a/sound/soc/codecs/cs42xx8.c +++ b/sound/soc/codecs/cs42xx8.c @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include @@ -511,17 +510,8 @@ const struct cs42xx8_driver_data cs42888_data = { }; EXPORT_SYMBOL_GPL(cs42888_data); -const struct of_device_id cs42xx8_of_match[] = { - { .compatible = "cirrus,cs42448", .data = &cs42448_data, }, - { .compatible = "cirrus,cs42888", .data = &cs42888_data, }, - { /* sentinel */ } -}; -MODULE_DEVICE_TABLE(of, cs42xx8_of_match); -EXPORT_SYMBOL_GPL(cs42xx8_of_match); - -int cs42xx8_probe(struct device *dev, struct regmap *regmap) +int cs42xx8_probe(struct device *dev, struct regmap *regmap, struct cs42xx8_driver_data *drvdata) { - const struct of_device_id *of_id; struct cs42xx8_priv *cs42xx8; int ret, val, i; @@ -535,17 +525,11 @@ int cs42xx8_probe(struct device *dev, struct regmap *regmap) if (cs42xx8 == NULL) return -ENOMEM; - cs42xx8->regmap = regmap; dev_set_drvdata(dev, cs42xx8); - of_id = of_match_device(cs42xx8_of_match, dev); - if (of_id) - cs42xx8->drvdata = of_id->data; + cs42xx8->regmap = regmap; - if (!cs42xx8->drvdata) { - dev_err(dev, "failed to find driver data\n"); - return -EINVAL; - } + cs42xx8->drvdata = drvdata; cs42xx8->gpiod_reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); diff --git a/sound/soc/codecs/cs42xx8.h b/sound/soc/codecs/cs42xx8.h index d36c61b6df74..342389e8b1a8 100644 --- a/sound/soc/codecs/cs42xx8.h +++ b/sound/soc/codecs/cs42xx8.h @@ -22,8 +22,7 @@ extern const struct dev_pm_ops cs42xx8_pm; extern const struct cs42xx8_driver_data cs42448_data; extern const struct cs42xx8_driver_data cs42888_data; extern const struct regmap_config cs42xx8_regmap_config; -extern const struct of_device_id cs42xx8_of_match[]; -int cs42xx8_probe(struct device *dev, struct regmap *regmap); +int cs42xx8_probe(struct device *dev, struct regmap *regmap, struct cs42xx8_driver_data *drvdata); /* CS42888 register map */ #define CS42XX8_CHIPID 0x01 /* Chip ID */