From patchwork Mon Aug 14 21:52:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 1821132 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=RJdNvY1f; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4RPp880PNGz1yfZ for ; Tue, 15 Aug 2023 07:54:16 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232530AbjHNVxn (ORCPT ); Mon, 14 Aug 2023 17:53:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233037AbjHNVxM (ORCPT ); Mon, 14 Aug 2023 17:53:12 -0400 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C107E110; Mon, 14 Aug 2023 14:52:59 -0700 (PDT) Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1bc0d39b52cso29423805ad.2; Mon, 14 Aug 2023 14:52:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692049979; x=1692654779; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ErgZTsUwfqdgH6PT40mXFD/nQxIBR8WLnzNxCoXWjK4=; b=RJdNvY1f9I1BtI8sV0sMl4Eb42DKVZPFjPf9Cr9/YoNUN7PCQ3aOV9W1ALK4celB43 +8dZM7EvQVBExS1Kz5vFQOtY+OmOfc5FL3Kodm6WouLcaGqE9aQQyjbCDMKjjPuKuHY3 /335eAsXcheUkGoB3WOcEEWKqmNaxdECa4LYNhstlWJBXUsgENQyY4wLX4ICuQckx2Ed Fr3uV/ygcN1z3PfmV/BelQTkEWlVsxz3O7RQiFVpPTW9mnlLwHXkQ3MNk8pY1nhuV3VW iI2HscxZ036zWX0AR3wW9LUiblkpZ55utxA5poaOc8pNyqbkKQ1dWZ3p870xERXeAOPT mVaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692049979; x=1692654779; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ErgZTsUwfqdgH6PT40mXFD/nQxIBR8WLnzNxCoXWjK4=; b=TyNJwJRyKDU1KJ7hw4enNVQTmSkjdXLN9wZsGNhtHiOpv7jhLpYWb2rQxejkCkZbTy iskKoy+2UIyS+hWhHVSOsU0CNu5AxPGx5p+4lpMy+33+Khwx8iXn2Rd2CHWT/1KXQggl 3xX7hutbvqIIlPN/rnoVxy3/fKPUCPnKCHJ0xCphvUatQntT9+HBzqGCUhoEQNOsXixp OHRgpvgPW5PxNF66gJYv4TSQ4IK4nzJtCSXFQIVSWgS7Ft/5CAHX7uiWovOvaKVIfSjl xy13+yCcKv18nf5jPp7UTup1S8VOVdo5zL6p6r6GppklDYJTO+YU8jOXOWOLynRUWcQG O8JA== X-Gm-Message-State: AOJu0Yy8TniN43CTKYWkQ/GGUAEeTqMn1lj6M+Asp49Fb9mRdIwcaWCf 5RfM5cKywgiHujcKoUQzYm7LV65qp2E= X-Google-Smtp-Source: AGHT+IEVw7epAZaGmdKs4S4+6bnGSCjZvUmKj71sKSJdD67WcJnHn4gnF0UzRNsj8Pkw81yfC3qGRQ== X-Received: by 2002:a17:902:d481:b0:1bc:69d0:a024 with SMTP id c1-20020a170902d48100b001bc69d0a024mr12124180plg.33.1692049978951; Mon, 14 Aug 2023 14:52:58 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:9d:2:6c34:7c96:4b56:4eca]) by smtp.gmail.com with ESMTPSA id ij13-20020a170902ab4d00b001b02bd00c61sm10056065plb.237.2023.08.14.14.52.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Aug 2023 14:52:58 -0700 (PDT) From: Dmitry Torokhov To: Wolfram Sang , Andy Shevchenko , Andi Shyti , Biju Das , Jonathan Cameron , Michael Hennerich , Peter Rosin Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH RFC 1/4] i2c: start migrating to a pointer in i2c_device_id Date: Mon, 14 Aug 2023 14:52:49 -0700 Message-ID: <20230814-i2c-id-rework-v1-1-3e5bc71c49ee@gmail.com> X-Mailer: git-send-email 2.41.0.694.ge786442a9b-goog In-Reply-To: <20230814-i2c-id-rework-v1-0-3e5bc71c49ee@gmail.com> References: <20230814-i2c-id-rework-v1-0-3e5bc71c49ee@gmail.com> MIME-Version: 1.0 X-Mailer: b4 0.13-dev-099c9 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS 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-i2c@vger.kernel.org The of_device_id structure uses a void pointer to associate additional driver-private data with device id, most commonly used to refer to a structure containing additional characteristics of a particular chip. However i2c_device_id uses an unsigned long. While it can easily be converted to a pointer, several drivers use it to store a scalar (and it is possible to use a pointer in of_device_id to store a scalar value as well). The worst case comes when OF part of a driver uses pointers, while legacy part is using scalars, causing constructs like: data = device_get_match_data(...); if (!data) data = &some_array[i2c_match_id(...)->data]; ... To avoid this introduce a const void "data" pointer to i2c_device_id as well, so that we can convert drivers one by one, and drop driver_data member in the end. The end goal is to clean up all helpers and make device_get_match_data() work universally for all ACPI, DT, and legacy variants. Signed-off-by: Dmitry Torokhov --- drivers/i2c/i2c-core-base.c | 2 +- include/linux/mod_devicetable.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index 60746652fd52..75d12d79d8f1 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -126,7 +126,7 @@ const void *i2c_get_match_data(const struct i2c_client *client) if (!match) return NULL; - data = (const void *)match->driver_data; + data = match->data ?: (const void *)match->driver_data; } return data; diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h index b0678b093cb2..21ac2a96e828 100644 --- a/include/linux/mod_devicetable.h +++ b/include/linux/mod_devicetable.h @@ -477,7 +477,8 @@ struct rpmsg_device_id { struct i2c_device_id { char name[I2C_NAME_SIZE]; - kernel_ulong_t driver_data; /* Data private to the driver */ + kernel_ulong_t driver_data; /* This field is obsolete */ + const void *data; /* Data private to the driver */ }; /* pci_epf */ From patchwork Mon Aug 14 21:52:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 1821136 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=CjlFlGLt; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4RPp891xq1z1yfb for ; Tue, 15 Aug 2023 07:54:17 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233037AbjHNVxo (ORCPT ); Mon, 14 Aug 2023 17:53:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233043AbjHNVxM (ORCPT ); Mon, 14 Aug 2023 17:53:12 -0400 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA515171B; Mon, 14 Aug 2023 14:53:00 -0700 (PDT) Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1bbf8cb61aeso30663075ad.2; Mon, 14 Aug 2023 14:53:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692049980; x=1692654780; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Ph6jaZNygycT+NmQDqvrcJyASoOlD1NZE1SWPIDmnUE=; b=CjlFlGLt2nV4v+VkWQOVwqOhiWkT9TUDLcyVPELByZQzZptpYai1y+UDeiXWC0Irxn 8NXUv6nOyoUvUMQ6CVaLwDGSOiSxvzCUbeFuE+5T+8TWtQdlRxzhaacN59ei4DAnhj4X TudHl8X247+6067HY6UgDMZLuGV4RtlafmrHRtphlqDPOsdVetkpip31axOMbfCb/Rii UP+j4fnAHugT+l3N4etQifx241EBQoi8n7/Arw4XmeCxHlwLV810XsckWQj5ujgdJwrr x5A1W4pkn0Pednf2QzgoLWOYjVUKBeUXZ45PvUQjT9cex6cRe+bSnDxoqjw0m6nmJq1J Yncg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692049980; x=1692654780; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ph6jaZNygycT+NmQDqvrcJyASoOlD1NZE1SWPIDmnUE=; b=R+m7uMWpeJw9tPFAdmVW0g792fZwL2dNNW6dP1EbJpku47P2O1Pobowa6BW4l1FRbr AjFIr+TNzsy4haEHnT/CMsGg7W0ONe4A0790jswazPJfrn2JMIiUXX/ilsf+8BBjuxaY zduKNuOnQCa1wtwbHJHi69j4H03Vor6pCnHU9f+1BlAntGpNn6J/PGA5uu1KBMuHtHbH FCY6E7wPrjUv2gJefH6d7+wQtZ2xIcJ+yBGFb+P2xc0yVk5Am8XhGQ5PbRZmsjcUOSZd 8GYcVTtF9l9Tuof9WjTrf4kNEc8S6lMlC8rGrONIoNYgw6ApL6nDpn+K7Xw2EnW8Lg5T IGgA== X-Gm-Message-State: AOJu0YxJdKaZij7jwRnzkbyLHjov6UO7gscr1v9Pv679Gn3YWYt14lRP hP0TaCSzJSLZ7FEbQHgmImA= X-Google-Smtp-Source: AGHT+IFUEOeLZ4GR9+X9bbRDKX6hp6Z0WTVJrqCQ6U7hZGq9AEniZfLSRTb//QafStFBM+rK5Y23Bg== X-Received: by 2002:a17:902:dad1:b0:1bb:9675:8c06 with SMTP id q17-20020a170902dad100b001bb96758c06mr10342970plx.35.1692049980053; Mon, 14 Aug 2023 14:53:00 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:9d:2:6c34:7c96:4b56:4eca]) by smtp.gmail.com with ESMTPSA id ij13-20020a170902ab4d00b001b02bd00c61sm10056065plb.237.2023.08.14.14.52.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Aug 2023 14:52:59 -0700 (PDT) From: Dmitry Torokhov To: Wolfram Sang , Andy Shevchenko , Andi Shyti , Biju Das , Jonathan Cameron , Michael Hennerich , Peter Rosin Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH RFC 2/4] i2c: mux: ltc4306: convert to using a pointer in i2c_device_id Date: Mon, 14 Aug 2023 14:52:50 -0700 Message-ID: <20230814-i2c-id-rework-v1-2-3e5bc71c49ee@gmail.com> X-Mailer: git-send-email 2.41.0.694.ge786442a9b-goog In-Reply-To: <20230814-i2c-id-rework-v1-0-3e5bc71c49ee@gmail.com> References: <20230814-i2c-id-rework-v1-0-3e5bc71c49ee@gmail.com> MIME-Version: 1.0 X-Mailer: b4 0.13-dev-099c9 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS 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-i2c@vger.kernel.org Switch the driver to use newly added "data" pointer in i2c_device_id to streamline DT and legacy flows. Signed-off-by: Dmitry Torokhov --- drivers/i2c/muxes/i2c-mux-ltc4306.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/i2c/muxes/i2c-mux-ltc4306.c b/drivers/i2c/muxes/i2c-mux-ltc4306.c index 637e25506490..17b9ed9ceef3 100644 --- a/drivers/i2c/muxes/i2c-mux-ltc4306.c +++ b/drivers/i2c/muxes/i2c-mux-ltc4306.c @@ -192,8 +192,8 @@ static int ltc4306_deselect_mux(struct i2c_mux_core *muxc, u32 chan) } static const struct i2c_device_id ltc4306_id[] = { - { "ltc4305", ltc_4305 }, - { "ltc4306", ltc_4306 }, + { "ltc4305", .data = &chips[ltc_4305] }, + { "ltc4306", .data = &chips[ltc_4306] }, { } }; MODULE_DEVICE_TABLE(i2c, ltc4306_id); @@ -217,9 +217,8 @@ static int ltc4306_probe(struct i2c_client *client) int num, ret; chip = of_device_get_match_data(&client->dev); - if (!chip) - chip = &chips[i2c_match_id(ltc4306_id, client)->driver_data]; + chip = i2c_match_id(ltc4306_id, client)->data; idle_disc = device_property_read_bool(&client->dev, "i2c-mux-idle-disconnect"); From patchwork Mon Aug 14 21:52:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 1821135 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=jX2kuvTB; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4RPp886z6Wz1yfZ for ; Tue, 15 Aug 2023 07:54:16 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233070AbjHNVxo (ORCPT ); Mon, 14 Aug 2023 17:53:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233048AbjHNVxM (ORCPT ); Mon, 14 Aug 2023 17:53:12 -0400 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1C5F171F; Mon, 14 Aug 2023 14:53:01 -0700 (PDT) Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1bc7e65ea44so32472265ad.1; Mon, 14 Aug 2023 14:53:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692049981; x=1692654781; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LlzwqrLSxr+d/fmguNZGigijFXvKVx5gs0X7gBK/frI=; b=jX2kuvTB5Zn/b0h4gbQ83XnwaX+08yun9vCz/nPT1qszkkkATNJDFoslQnQff9/Fyn yCIvmF1EaOxZ8IRX3LLZaRFN6giM3ZWK2QAhG8201qPoSF4DjVtj9ivDDPVKitJcCBaY epR6uUtN/QaWyOTjXi9u+qDZ1ODUv4SL3r3dGIMWtS4GpIz3g4R45cnRKdajZMkun2m1 AKaceFgZA4jpgDyENGKrJYfuu3C7srHeo0UQbrjzWFkI84VC0m0XZhA+XQaqrQBn8Yvc eHY3ViwkB4uez/E4SY4lmJVPnG0xGVdUQNuFSY+3H0Tqf4IXg/2aT8e59bqJwySFbYLX 7uhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692049981; x=1692654781; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LlzwqrLSxr+d/fmguNZGigijFXvKVx5gs0X7gBK/frI=; b=a/YlrYLbIHsZ5Nr8l6sCKSLsVMIlLw2DmSfa8IB6f+X1oTMpdg2nQUlX3AYIbtILDc yYYHlYDOYZMNMfi6i7+hsGNhM1nw5dhMSB5PRIWb/JhJzwVrf//fszoBcqd9yR+w1TZx cajaeSW9avo5VbT19QPpcwMIz9hzvJl0eCSOh9WPwfpA4PaaI+PDjhTU4737De09wl3E PewdDhsSlS164V9uDLEqTzdc/zErt9QItStS4cG75iQYibo+29MalkTCUvAAptZkSliK pFC8cdyvrYrKiNiAeUbjkSfadHt2r4anF3RnZNXShUfyytRncTPd9pSvyEh4RuU/UjPi YmBA== X-Gm-Message-State: AOJu0YznD+p6OFhRTevXtZKo8jL8cpfb02TC1g/WfO//41x8XjtJ1hag YHfxI12Jewry3enm4WGVOxI= X-Google-Smtp-Source: AGHT+IFOgBS3GLoMnjEuhGA2p00hBi2mTODATf2Gq3m6heKXdGS9F5l5wItCfO7gRT+ScTGNlfKwFQ== X-Received: by 2002:a17:903:41d2:b0:1b3:b84b:9008 with SMTP id u18-20020a17090341d200b001b3b84b9008mr237134ple.5.1692049981264; Mon, 14 Aug 2023 14:53:01 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:9d:2:6c34:7c96:4b56:4eca]) by smtp.gmail.com with ESMTPSA id ij13-20020a170902ab4d00b001b02bd00c61sm10056065plb.237.2023.08.14.14.53.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Aug 2023 14:53:00 -0700 (PDT) From: Dmitry Torokhov To: Wolfram Sang , Andy Shevchenko , Andi Shyti , Biju Das , Jonathan Cameron , Michael Hennerich , Peter Rosin Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH RFC 3/4] i2c: mux: pca954x: convert to using a pointer in i2c_device_id Date: Mon, 14 Aug 2023 14:52:51 -0700 Message-ID: <20230814-i2c-id-rework-v1-3-3e5bc71c49ee@gmail.com> X-Mailer: git-send-email 2.41.0.694.ge786442a9b-goog In-Reply-To: <20230814-i2c-id-rework-v1-0-3e5bc71c49ee@gmail.com> References: <20230814-i2c-id-rework-v1-0-3e5bc71c49ee@gmail.com> MIME-Version: 1.0 X-Mailer: b4 0.13-dev-099c9 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS 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-i2c@vger.kernel.org Switch the driver to use newly added "data" pointer in i2c_device_id to streamline DT and legacy flows. Signed-off-by: Dmitry Torokhov --- drivers/i2c/muxes/i2c-mux-pca954x.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/drivers/i2c/muxes/i2c-mux-pca954x.c b/drivers/i2c/muxes/i2c-mux-pca954x.c index 6965bf4c2348..c8540e4ca660 100644 --- a/drivers/i2c/muxes/i2c-mux-pca954x.c +++ b/drivers/i2c/muxes/i2c-mux-pca954x.c @@ -177,18 +177,18 @@ static const struct chip_desc chips[] = { }; static const struct i2c_device_id pca954x_id[] = { - { "pca9540", pca_9540 }, - { "pca9542", pca_9542 }, - { "pca9543", pca_9543 }, - { "pca9544", pca_9544 }, - { "pca9545", pca_9545 }, - { "pca9546", pca_9546 }, - { "pca9547", pca_9547 }, - { "pca9548", pca_9548 }, - { "pca9846", pca_9846 }, - { "pca9847", pca_9847 }, - { "pca9848", pca_9848 }, - { "pca9849", pca_9849 }, + { "pca9540", .data = &chips[pca_9540] }, + { "pca9542", .data = &chips[pca_9542] }, + { "pca9543", .data = &chips[pca_9543] }, + { "pca9544", .data = &chips[pca_9544] }, + { "pca9545", .data = &chips[pca_9545] }, + { "pca9546", .data = &chips[pca_9546] }, + { "pca9547", .data = &chips[pca_9547] }, + { "pca9548", .data = &chips[pca_9548] }, + { "pca9846", .data = &chips[pca_9846] }, + { "pca9847", .data = &chips[pca_9847] }, + { "pca9848", .data = &chips[pca_9848] }, + { "pca9849", .data = &chips[pca_9849] }, { } }; MODULE_DEVICE_TABLE(i2c, pca954x_id); @@ -206,7 +206,7 @@ static const struct of_device_id pca954x_of_match[] = { { .compatible = "nxp,pca9847", .data = &chips[pca_9847] }, { .compatible = "nxp,pca9848", .data = &chips[pca_9848] }, { .compatible = "nxp,pca9849", .data = &chips[pca_9849] }, - {} + { } }; MODULE_DEVICE_TABLE(of, pca954x_of_match); @@ -447,7 +447,7 @@ static int pca954x_probe(struct i2c_client *client) data->chip = device_get_match_data(dev); if (!data->chip) - data->chip = &chips[id->driver_data]; + data->chip = id->data; if (data->chip->id.manufacturer_id != I2C_DEVICE_ID_NONE) { struct i2c_device_identity id; From patchwork Mon Aug 14 21:52:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 1821133 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=EZAQidJ0; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4RPp882VGGz1yfb for ; Tue, 15 Aug 2023 07:54:16 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233052AbjHNVxn (ORCPT ); Mon, 14 Aug 2023 17:53:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233054AbjHNVxN (ORCPT ); Mon, 14 Aug 2023 17:53:13 -0400 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33A35E77; Mon, 14 Aug 2023 14:53:03 -0700 (PDT) Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1bb84194bf3so29415075ad.3; Mon, 14 Aug 2023 14:53:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692049982; x=1692654782; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0QmZQPGtJPE55mi80G8Q09KHrGIMEsU19IuSGHDLtYc=; b=EZAQidJ00yQ6WEvkdfTtNaL6XoQjiwuctJKMwYJFSWfPAHTfa5GjQH0jFnxjrTbeNo CZho1ZXs6gvnlkURHru3r4flI7ZNq/XZz36VO8vQduLWJUG6UXXaQfIMk1cZg3yEXSiw HXlRErnW6MpdGKdueRGMuXg+LJkZbWUp2mg8QX8s5Crek+bz8kUXLa1DZ5BzRyrwVtpp 4Ko9Xq02Nrdu7ZC28vmXibRBqNX/4NyyvTCs/Xq2UQk1So9YhxbnRYtE4kMPx3aZpdAV SlzlPRK23hMGq5zUkb2owhh1QwHJFI8xsw1OxCnFqeHX7CtORj6ncNAvR7Lj3zpCH1g1 rRWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692049982; x=1692654782; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0QmZQPGtJPE55mi80G8Q09KHrGIMEsU19IuSGHDLtYc=; b=JU/t1DOl+kdFhNkqsDF4/PGZXqffY6inofvuZPnJmL7x40wJbORv0tTV092QrqXGjo K/m992DZgfkGO0qrIdJiTnMx/uIppio2wSkYLdY5xKMQxd/yLom9Ye0HfSYmBLLRiP86 0fy41qXsJoujPrZfnU7izBTP0f9CLKeZyBAjHudcw0CkcpFL0oMCtOMfJ3aXNmV49hCc kbSDwGhEyPMYWN4EysJA44hDBu0sF8zCeICFcZQz7qww1ALzrZeXCvjfvh6hIXQMiVfw 0Uzkb91bUro0YX+nu6TMKh7pbNmNHqWHix7b1Jp0yuKCwKD66gwMGGW1/5GsgdOt4vXg JbfQ== X-Gm-Message-State: AOJu0Yzu1UaRIov6pi2raL0OWLdZDbw2rBRIPW3L6Ceh/AgN02gvBAAy BceSibs4yoEGEpQyTxHN3zwc6BWdlE4= X-Google-Smtp-Source: AGHT+IHs1Crk98fAQ/oKvEsFi6Q+6CAA+GEzaVUQE27FCAmez5YTrZsNUhPSxMeg1Q1+nNv9Ast+tQ== X-Received: by 2002:a17:902:ecc1:b0:1bd:f7d7:3bd0 with SMTP id a1-20020a170902ecc100b001bdf7d73bd0mr716639plh.5.1692049982482; Mon, 14 Aug 2023 14:53:02 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:9d:2:6c34:7c96:4b56:4eca]) by smtp.gmail.com with ESMTPSA id ij13-20020a170902ab4d00b001b02bd00c61sm10056065plb.237.2023.08.14.14.53.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Aug 2023 14:53:02 -0700 (PDT) From: Dmitry Torokhov To: Wolfram Sang , Andy Shevchenko , Andi Shyti , Biju Das , Jonathan Cameron , Michael Hennerich , Peter Rosin Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH RFC 4/4] i2c: slave-eeprom: convert to using a pointer in i2c_device_id Date: Mon, 14 Aug 2023 14:52:52 -0700 Message-ID: <20230814-i2c-id-rework-v1-4-3e5bc71c49ee@gmail.com> X-Mailer: git-send-email 2.41.0.694.ge786442a9b-goog In-Reply-To: <20230814-i2c-id-rework-v1-0-3e5bc71c49ee@gmail.com> References: <20230814-i2c-id-rework-v1-0-3e5bc71c49ee@gmail.com> MIME-Version: 1.0 X-Mailer: b4 0.13-dev-099c9 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS 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-i2c@vger.kernel.org Switch the driver to use newly added "data" pointer in i2c_device_id and introduce struct eeprom_chip to describe chip's characteristics instead of cramming it all into an unisigned long and then decipher. Signed-off-by: Dmitry Torokhov --- drivers/i2c/i2c-slave-eeprom.c | 99 ++++++++++++++++++++++++++++-------------- 1 file changed, 66 insertions(+), 33 deletions(-) diff --git a/drivers/i2c/i2c-slave-eeprom.c b/drivers/i2c/i2c-slave-eeprom.c index 5946c0d0aef9..1d2340da5a70 100644 --- a/drivers/i2c/i2c-slave-eeprom.c +++ b/drivers/i2c/i2c-slave-eeprom.c @@ -16,32 +16,29 @@ * EEPROMs, though. We currently use the 8 bit as a valid address. */ -#include #include #include #include #include -#include #include #include #include +struct eeprom_chip { + u16 address_mask; + u8 num_address_bytes; + bool read_only; +}; + struct eeprom_data { + const struct eeprom_chip *chip; struct bin_attribute bin; spinlock_t buffer_lock; u16 buffer_idx; - u16 address_mask; - u8 num_address_bytes; u8 idx_write_cnt; - bool read_only; u8 buffer[]; }; -#define I2C_SLAVE_BYTELEN GENMASK(15, 0) -#define I2C_SLAVE_FLAG_ADDR16 BIT(16) -#define I2C_SLAVE_FLAG_RO BIT(17) -#define I2C_SLAVE_DEVICE_MAGIC(_len, _flags) ((_flags) | ((_len) - 1)) - static int i2c_slave_eeprom_slave_cb(struct i2c_client *client, enum i2c_slave_event event, u8 *val) { @@ -49,17 +46,15 @@ static int i2c_slave_eeprom_slave_cb(struct i2c_client *client, switch (event) { case I2C_SLAVE_WRITE_RECEIVED: - if (eeprom->idx_write_cnt < eeprom->num_address_bytes) { + if (eeprom->idx_write_cnt < eeprom->chip->num_address_bytes) { if (eeprom->idx_write_cnt == 0) eeprom->buffer_idx = 0; eeprom->buffer_idx = *val | (eeprom->buffer_idx << 8); eeprom->idx_write_cnt++; - } else { - if (!eeprom->read_only) { - spin_lock(&eeprom->buffer_lock); - eeprom->buffer[eeprom->buffer_idx++ & eeprom->address_mask] = *val; - spin_unlock(&eeprom->buffer_lock); - } + } else if (!eeprom->chip->read_only) { + spin_lock(&eeprom->buffer_lock); + eeprom->buffer[eeprom->buffer_idx++ & eeprom->chip->address_mask] = *val; + spin_unlock(&eeprom->buffer_lock); } break; @@ -69,7 +64,7 @@ static int i2c_slave_eeprom_slave_cb(struct i2c_client *client, fallthrough; case I2C_SLAVE_READ_REQUESTED: spin_lock(&eeprom->buffer_lock); - *val = eeprom->buffer[eeprom->buffer_idx & eeprom->address_mask]; + *val = eeprom->buffer[eeprom->buffer_idx & eeprom->chip->address_mask]; spin_unlock(&eeprom->buffer_lock); /* * Do not increment buffer_idx here, because we don't know if @@ -142,19 +137,25 @@ static int i2c_slave_init_eeprom_data(struct eeprom_data *eeprom, struct i2c_cli static int i2c_slave_eeprom_probe(struct i2c_client *client) { - const struct i2c_device_id *id = i2c_client_get_device_id(client); + const struct i2c_device_id *id; + const struct eeprom_chip *chip; struct eeprom_data *eeprom; int ret; - unsigned int size = FIELD_GET(I2C_SLAVE_BYTELEN, id->driver_data) + 1; - unsigned int flag_addr16 = FIELD_GET(I2C_SLAVE_FLAG_ADDR16, id->driver_data); + unsigned int size; + + id = i2c_client_get_device_id(client); + if (!id) + return -EINVAL; + + chip = id->data; + size = chip->address_mask + 1; - eeprom = devm_kzalloc(&client->dev, sizeof(struct eeprom_data) + size, GFP_KERNEL); + eeprom = devm_kzalloc(&client->dev, struct_size(eeprom, buffer, size), + GFP_KERNEL); if (!eeprom) return -ENOMEM; - eeprom->num_address_bytes = flag_addr16 ? 2 : 1; - eeprom->address_mask = size - 1; - eeprom->read_only = FIELD_GET(I2C_SLAVE_FLAG_RO, id->driver_data); + eeprom->chip = chip; spin_lock_init(&eeprom->buffer_lock); i2c_set_clientdata(client, eeprom); @@ -190,15 +191,47 @@ static void i2c_slave_eeprom_remove(struct i2c_client *client) sysfs_remove_bin_file(&client->dev.kobj, &eeprom->bin); } +static const struct eeprom_chip chip_24c02 = { + .address_mask = 2048 / 8 - 1, .num_address_bytes = 1, +}; + +static const struct eeprom_chip chip_24c02ro = { + .address_mask = 2048 / 8 - 1, .num_address_bytes = 1, .read_only = true, +}; + +static const struct eeprom_chip chip_24c32 = { + .address_mask = 32768 / 8 - 1, .num_address_bytes = 2, +}; + +static const struct eeprom_chip chip_24c32ro = { + .address_mask = 32768 / 8 - 1, .num_address_bytes = 2, .read_only = true, +}; + +static const struct eeprom_chip chip_24c64 = { + .address_mask = 65536 / 8 - 1, .num_address_bytes = 2, +}; + +static const struct eeprom_chip chip_24c64ro = { + .address_mask = 65536 / 8 - 1, .num_address_bytes = 2, .read_only = true, +}; + +static const struct eeprom_chip chip_24c512 = { + .address_mask = 524288 / 8 - 1, .num_address_bytes = 2, +}; + +static const struct eeprom_chip chip_24c512ro = { + .address_mask = 524288 / 8 - 1, .num_address_bytes = 2, .read_only = true, +}; + static const struct i2c_device_id i2c_slave_eeprom_id[] = { - { "slave-24c02", I2C_SLAVE_DEVICE_MAGIC(2048 / 8, 0) }, - { "slave-24c02ro", I2C_SLAVE_DEVICE_MAGIC(2048 / 8, I2C_SLAVE_FLAG_RO) }, - { "slave-24c32", I2C_SLAVE_DEVICE_MAGIC(32768 / 8, I2C_SLAVE_FLAG_ADDR16) }, - { "slave-24c32ro", I2C_SLAVE_DEVICE_MAGIC(32768 / 8, I2C_SLAVE_FLAG_ADDR16 | I2C_SLAVE_FLAG_RO) }, - { "slave-24c64", I2C_SLAVE_DEVICE_MAGIC(65536 / 8, I2C_SLAVE_FLAG_ADDR16) }, - { "slave-24c64ro", I2C_SLAVE_DEVICE_MAGIC(65536 / 8, I2C_SLAVE_FLAG_ADDR16 | I2C_SLAVE_FLAG_RO) }, - { "slave-24c512", I2C_SLAVE_DEVICE_MAGIC(524288 / 8, I2C_SLAVE_FLAG_ADDR16) }, - { "slave-24c512ro", I2C_SLAVE_DEVICE_MAGIC(524288 / 8, I2C_SLAVE_FLAG_ADDR16 | I2C_SLAVE_FLAG_RO) }, + { "slave-24c02", .data = &chip_24c02 }, + { "slave-24c02ro", .data = &chip_24c02ro }, + { "slave-24c32", .data = &chip_24c32 }, + { "slave-24c32ro", .data = &chip_24c32ro }, + { "slave-24c64", .data = &chip_24c64 }, + { "slave-24c64ro", .data = &chip_24c64ro }, + { "slave-24c512", .data = &chip_24c512 }, + { "slave-24c512ro", .data = &chip_24c512ro }, { } }; MODULE_DEVICE_TABLE(i2c, i2c_slave_eeprom_id);