Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp1253856rwi; Mon, 31 Oct 2022 13:43:12 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6GVQ1D3qGiidA9CKLui3+YppZckyaFCBDtrTSNWc5XM5sG1ssHruywz5f5UlKQv1+hoYUK X-Received: by 2002:a17:902:da82:b0:186:ee5a:47c7 with SMTP id j2-20020a170902da8200b00186ee5a47c7mr16242732plx.82.1667248991178; Mon, 31 Oct 2022 13:43:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667248991; cv=none; d=google.com; s=arc-20160816; b=E7CaFVGLp4RC24qhpGouHt5Mum1vjr8GJTWAEgvrpmlNu32r62vb2OduKfHxExk+la nXiXUGfF9Y7YcaD8Ew9xl8XO5oF/5Wd39NOJhlsfwWDGtfhADUJPTWsLMoFzWxw1V6Y8 DGTiXfCsHkpJ95dTAz9bkHMPV6YuX9G18O2WlxrmPdEMIlPfArzBmBBY7PKVORk1P9KB DrcyGJaD3ali0o2rUxRMhqeu3MVfYC8d1mlSwCFZ6NZm6ahfjuXf2SB7+R1q2HvxODZO X1vlYnjESZqjspeZFDdiGoro/EmfgwJDV/U4Qj9V853p2zjJZvrreF1D7cwU5TViUvdj jPSg== 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 Return-Path: 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.56; Mon, 31 Oct 2022 13:43:11 -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 Content-Transfer-Encoding: 8bit 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 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 --- 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 */ -- 2.34.1