From patchwork Mon Feb 7 10:34:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 12737130 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 5AA22C433FE for ; Mon, 7 Feb 2022 10:44:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232607AbiBGKne (ORCPT ); Mon, 7 Feb 2022 05:43:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235808AbiBGKes (ORCPT ); Mon, 7 Feb 2022 05:34:48 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1F7C7C043181 for ; Mon, 7 Feb 2022 02:34:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644230086; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=ibN6/eDkPg06FmKcOZnz2iN/4NPbggkjDC87Ud75vSU=; b=KDp2dPrynwOgpI14Gc0PtuCNnw/fhGgxzkV0HQwF3c7ATMPdvpuQyEabUJjD7GU86EpHpd MtYxan9E3e8Wziwo3tCfES8B5v5Hkcrmza+E8zhqEUcP+A158tRviE2nbI98PsusxvPLq/ owVXuMv6UVm1KCu2rKwK3WdaxgUJX6w= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-277-2LwQpE5iP5SwIcEonMbkGQ-1; Mon, 07 Feb 2022 05:34:23 -0500 X-MC-Unique: 2LwQpE5iP5SwIcEonMbkGQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E2A22814243; Mon, 7 Feb 2022 10:34:21 +0000 (UTC) Received: from x1.localdomain.com (unknown [10.39.194.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5BD6E4F867; Mon, 7 Feb 2022 10:34:20 +0000 (UTC) From: Hans de Goede To: Jonathan Cameron Cc: Hans de Goede , Lars-Peter Clausen , Dan Carpenter , linux-iio@vger.kernel.org Subject: [PATCH v2 1/2] iio: mma8452: Fix probe failing when an i2c_device_id is used Date: Mon, 7 Feb 2022 11:34:18 +0100 Message-Id: <20220207103419.309032-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org The mma8452_driver declares both of_match_table and i2c_driver.id_table match-tables, but its probe() function only checked for of matches. Add support for i2c_device_id matches. This fixes the driver not loading on some x86 tablets (e.g. the Nextbook Ares 8) where the i2c_client is instantiated by platform code using an i2c_device_id. Signed-off-by: Hans de Goede --- Changes in v2: - Fix the following smatch warning: drivers/iio/accel/mma8452.c:1595 mma8452_probe() error: we previously assumed 'id' could be null (see line 1536) Reported-by: kernel test robot Reported-by: Dan Carpenter --- drivers/iio/accel/mma8452.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c index 64b82b4503ad..eaa236cfbabb 100644 --- a/drivers/iio/accel/mma8452.c +++ b/drivers/iio/accel/mma8452.c @@ -1523,12 +1523,7 @@ static int mma8452_probe(struct i2c_client *client, struct iio_dev *indio_dev; int ret; const struct of_device_id *match; - - match = of_match_device(mma8452_dt_ids, &client->dev); - if (!match) { - dev_err(&client->dev, "unknown device model\n"); - return -ENODEV; - } + const char *compatible; indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); if (!indio_dev) @@ -1537,7 +1532,19 @@ static int mma8452_probe(struct i2c_client *client, data = iio_priv(indio_dev); data->client = client; mutex_init(&data->lock); - data->chip_info = match->data; + + if (id) { + compatible = id->name; + data->chip_info = &mma_chip_info_table[id->driver_data]; + } else { + match = of_match_device(mma8452_dt_ids, &client->dev); + if (!match) { + dev_err(&client->dev, "unknown device model\n"); + return -ENODEV; + } + compatible = match->compatible; + data->chip_info = match->data; + } data->vdd_reg = devm_regulator_get(&client->dev, "vdd"); if (IS_ERR(data->vdd_reg)) @@ -1581,11 +1588,11 @@ static int mma8452_probe(struct i2c_client *client, } dev_info(&client->dev, "registering %s accelerometer; ID 0x%x\n", - match->compatible, data->chip_info->chip_id); + compatible, data->chip_info->chip_id); i2c_set_clientdata(client, indio_dev); indio_dev->info = &mma8452_info; - indio_dev->name = id->name; + indio_dev->name = compatible; indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->channels = data->chip_info->channels; indio_dev->num_channels = data->chip_info->num_channels; From patchwork Mon Feb 7 10:34:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 12737131 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 9B028C433F5 for ; Mon, 7 Feb 2022 10:45:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235808AbiBGKoF (ORCPT ); Mon, 7 Feb 2022 05:44:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235129AbiBGKeg (ORCPT ); Mon, 7 Feb 2022 05:34:36 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 201FBC043189 for ; Mon, 7 Feb 2022 02:34:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644230068; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Mt0kWAaOiV6B2Df2y8mWKQRZyhcrEoomyGQcX6ARqqg=; b=iaiAOLjdXeaevFWTc3ICz1cjewoKN+5Bbym7p6aP1soEO2LOvTpQXSChemY6yKMiySByN8 PilGZ8evCw13RQ+c+i5/mi2Atd10iLs5LzX/rgGPHdjSpQgeoV+HSLOvOmFa+F9qmNMTRh addo4aT+7xlfe4WIUmP/cYfGYvIyX8w= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-449-YFZ-tMOFNHevo4trVAicvA-1; Mon, 07 Feb 2022 05:34:25 -0500 X-MC-Unique: YFZ-tMOFNHevo4trVAicvA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D65962F45; Mon, 7 Feb 2022 10:34:23 +0000 (UTC) Received: from x1.localdomain.com (unknown [10.39.194.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id 645E96D033; Mon, 7 Feb 2022 10:34:22 +0000 (UTC) From: Hans de Goede To: Jonathan Cameron Cc: Hans de Goede , Lars-Peter Clausen , Dan Carpenter , linux-iio@vger.kernel.org Subject: [PATCH v2 2/2] iio: mma8452: Add support for the "mount-matrix" device property Date: Mon, 7 Feb 2022 11:34:19 +0100 Message-Id: <20220207103419.309032-2-hdegoede@redhat.com> In-Reply-To: <20220207103419.309032-1-hdegoede@redhat.com> References: <20220207103419.309032-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Add support for the standard "mount-matrix" device property to the mma8452 driver. Signed-off-by: Hans de Goede --- Note this applies on top of the following recent patch from me: "iio: mma8452: Fix probe failing when an i2c_device_id is used" --- drivers/iio/accel/mma8452.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c index eaa236cfbabb..3b9a0ef410ad 100644 --- a/drivers/iio/accel/mma8452.c +++ b/drivers/iio/accel/mma8452.c @@ -104,6 +104,7 @@ struct mma8452_data { struct i2c_client *client; struct mutex lock; + struct iio_mount_matrix orientation; u8 ctrl_reg1; u8 data_cfg; const struct mma_chip_info *chip_info; @@ -1189,6 +1190,20 @@ static const struct attribute_group mma8452_event_attribute_group = { .attrs = mma8452_event_attributes, }; +static const struct iio_mount_matrix * +mma8452_get_mount_matrix(const struct iio_dev *indio_dev, + const struct iio_chan_spec *chan) +{ + struct mma8452_data *data = iio_priv(indio_dev); + + return &data->orientation; +} + +static const struct iio_chan_spec_ext_info mma8452_ext_info[] = { + IIO_MOUNT_MATRIX(IIO_SHARED_BY_TYPE, mma8452_get_mount_matrix), + { } +}; + #define MMA8452_FREEFALL_CHANNEL(modifier) { \ .type = IIO_ACCEL, \ .modified = 1, \ @@ -1227,6 +1242,7 @@ static const struct attribute_group mma8452_event_attribute_group = { }, \ .event_spec = mma8452_transient_event, \ .num_event_specs = ARRAY_SIZE(mma8452_transient_event), \ + .ext_info = mma8452_ext_info, \ } #define MMA8652_CHANNEL(axis, idx, bits) { \ @@ -1248,6 +1264,7 @@ static const struct attribute_group mma8452_event_attribute_group = { }, \ .event_spec = mma8452_motion_event, \ .num_event_specs = ARRAY_SIZE(mma8452_motion_event), \ + .ext_info = mma8452_ext_info, \ } static const struct iio_chan_spec mma8451_channels[] = { @@ -1546,6 +1563,10 @@ static int mma8452_probe(struct i2c_client *client, data->chip_info = match->data; } + ret = iio_read_mount_matrix(&client->dev, &data->orientation); + if (ret) + return ret; + data->vdd_reg = devm_regulator_get(&client->dev, "vdd"); if (IS_ERR(data->vdd_reg)) return dev_err_probe(&client->dev, PTR_ERR(data->vdd_reg),