Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp816669rwd; Sat, 27 May 2023 06:59:34 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5rLFS682IxVyxAau8YuFW2fYUYSJ/wX5I0owDkrYh7v2SeADnkPyMzu3nxZODNdFTrn5YH X-Received: by 2002:a05:6a00:1395:b0:64f:4812:8c7e with SMTP id t21-20020a056a00139500b0064f48128c7emr7675101pfg.19.1685195974266; Sat, 27 May 2023 06:59:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685195974; cv=none; d=google.com; s=arc-20160816; b=RuS5/JXpxZU+e/GDZdBVdNb0OOBIQpu9cCol/Ii8aD0U6weKT/d1m9J7S2VZqL1kDb n6/HTiO09pe/DxKkBC1hfFzQEX1kIJQrrDdTkxkZHTsZ5ed2ZrEHjXJ07q73L9y/o25V CM5JjQt34kZ3Vb8/f939JMYNRNCCzzLlvMGMFVqk8FLQzJtJ0Q1CX4KVU9SUwN9onxVp 1Noein0GeITDseb/bnaWHRQ5ye1SDmA0i2v4Dw8rutGANqoVF7OqFslD2lh9mMSlZGlS CeVMPsdSnKvuEdH1PFxHNTdc4rwUvWO38ugVfH5kF265YNoJ7cUdzyvFT0GuCMI6HE1f Qe0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=8L7nqC0DBDah+I2jD68gVa4TxQD1VnT8COCmiiTDCyM=; b=cBg741P4hIkDYKlvBmErC3PAjG+BM4rU8I0+g7uzvjS0dMlOstITmKsiGi4GUVv1Cy pAQvQ/y6Aw9N/GjNbx4ihK5uWPgmW+/f0ReNSsmDc8cLDxFMckrHMBqlpXURrWnXCuDq 3P9oRRu595KQX2sHalCTFp6WtN6rLt97Og68bc0RmXE6wTCnCzmkBzHKL5dQA16SFxV8 ZBZBwVPVslZDMhFp3RW3H4rt8DGHhGqZH3/ERW3x2ADX4b7S5N0vv6brb6Nb/BNj3vJZ JhKgv9aCtPyLrVzpj4Y7wb1Hs2b8G6a+xMKKROJIEnJLutt1qLaZRaauU2h6A4fjsOGo IySA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=mCXFZ9nY; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g5-20020aa79f05000000b00640f213b6fesi6518550pfr.240.2023.05.27.06.59.20; Sat, 27 May 2023 06:59:34 -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=@intel.com header.s=Intel header.b=mCXFZ9nY; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231760AbjE0NkI (ORCPT + 99 others); Sat, 27 May 2023 09:40:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231872AbjE0Njw (ORCPT ); Sat, 27 May 2023 09:39:52 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D24DC3; Sat, 27 May 2023 06:39:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685194791; x=1716730791; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=qfjzqpAYgR3XMV316cfjMosBmC4HWLJh7OuqlZd9VwU=; b=mCXFZ9nYE+15llGvC5G39coFF7EeAZKzyvb4JDuivif5tvLD7m0UW92x 1O/0nxKXaIhhGsqOS26BYrPmKbKnsGke1VUIbEvGxJK6jv+xnzZeu4SZ7 qHv/dCV15iG095zhABJxUlK86YUfesm8W0O/erbCSN0x2ouH6J35C46x3 zszu/RMaFSi+54lWXGRnOP9u+n+2+BCzUHQgLvFAGal/xo79Ew/yaxsEh SY/Ddvg3j+4Q5oksLVEWdEh2nE4sr7Ebv7eL870GHg4vnOz0m2FpnvRRu xmYDTW3ZDVMayTeJlrXiZhnqROq/dCybskIU+3UD2cgcqj/0KQ3K+wSBL A==; X-IronPort-AV: E=McAfee;i="6600,9927,10723"; a="343896226" X-IronPort-AV: E=Sophos;i="6.00,197,1681196400"; d="scan'208";a="343896226" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 May 2023 06:39:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10723"; a="829811418" X-IronPort-AV: E=Sophos;i="6.00,197,1681196400"; d="scan'208";a="829811418" Received: from smile.fi.intel.com ([10.237.72.54]) by orsmga004.jf.intel.com with ESMTP; 27 May 2023 06:39:48 -0700 Received: from andy by smile.fi.intel.com with local (Exim 4.96) (envelope-from ) id 1q2u94-000J3h-2y; Sat, 27 May 2023 16:39:46 +0300 Date: Sat, 27 May 2023 16:39:46 +0300 From: Andy Shevchenko To: Mehdi Djait Cc: jic23@kernel.org, mazziesaccount@gmail.com, krzysztof.kozlowski+dt@linaro.org, robh+dt@kernel.org, lars@metafoo.de, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Subject: Re: [PATCH v4 5/7] iio: accel: kionix-kx022a: Refactor driver and add chip_info structure Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE 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 On Fri, May 26, 2023 at 04:30:46PM +0200, Mehdi Djait wrote: > Add the chip_info structure to the driver's private data to hold all > the device specific infos. > Refactor the kx022a driver implementation to make it more generic and > extensible. ... > - regmap = devm_regmap_init_i2c(i2c, &kx022a_regmap); > + chip_info = device_get_match_data(&i2c->dev); > + if (!chip_info) { > + const struct i2c_device_id *id = i2c_client_get_device_id(i2c); > + chip_info = (const struct kx022a_chip_info *)id->driver_data; > + } And if still no chip_info available?.. > + regmap = devm_regmap_init_i2c(i2c, chip_info->regmap_config); > if (IS_ERR(regmap)) > return dev_err_probe(dev, PTR_ERR(regmap), > "Failed to initialize Regmap\n"); ... > - if (val > KX022A_FIFO_LENGTH) > - val = KX022A_FIFO_LENGTH; > + if (val > data->chip_info->fifo_length) > + val = data->chip_info->fifo_length; min()/min_t() ? ... > + ret = regmap_noinc_read(data->regmap, data->chip_info->buf_read, > + &data->fifo_buffer[0], fifo_bytes); data->fifo_buffer will suffice. > if (ret) > goto renable_out; ... > + data->fifo_buffer = kmalloc(data->chip_info->fifo_length * > + KX022A_FIFO_SAMPLES_SIZE_BYTES, GFP_KERNEL); > + Redundant blank line. > + if (!data->fifo_buffer) > + return -ENOMEM; ... > +struct kx022a_chip_info { > + const char *name; > + const struct regmap_config *regmap_config; > + const struct iio_chan_spec *channels; > + unsigned int num_channels; > + unsigned int fifo_length; > + u8 who; > + u8 id; > + u8 cntl; > + u8 cntl2; > + u8 odcntl; > + u8 buf_cntl1; > + u8 buf_cntl2; > + u8 buf_clear; > + u8 buf_status1; Here is the gap since it's not a packed structure. Can we avoid it? > + u16 buf_smp_lvl_mask; > + u8 buf_read; > + u8 inc1; > + u8 inc4; > + u8 inc5; > + u8 inc6; > + u8 xout_l; > +}; -- With Best Regards, Andy Shevchenko