From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-il1-f173.google.com (mail-il1-f173.google.com [209.85.166.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6D86F2D46AF for ; Fri, 25 Jul 2025 12:27:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753446452; cv=none; b=KDYnRGmy/qgLxM+cy9W+DTX9hT5CIYBOlZtIYu5wY931hPDMXsUeIm+5llP83AOxNjQhJvUBV8+A9384ap9kjB4WnINwxWr685b94kyZbaUmapX3iUTYPyjH2KJecilEw2QIsCyy1BkMZsG7qrSZnLzAR/UaTLZJHBIHzPKX9P8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753446452; c=relaxed/simple; bh=Hcy+1FkKcmyE8pc2/30HA2M4yktRO2YfEreRAJCLW5c=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=RxXA+2Dh8VO6DjDEj3seJGplijhopotBzOwa5LMeY7TwX3FtT2xz0RwqQcS8sdgLn9eZY7bGATtnWVp3AzgqRW4gpT1YT2xdlpRKRVyk9e5F001OVgdN48fVWAgFX2Fl1AZOKYGqXBGX1BLTbwW43bMp61ML/zJqbl2vfZaH4EU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=riscstar.com; spf=pass smtp.mailfrom=riscstar.com; dkim=pass (2048-bit key) header.d=riscstar-com.20230601.gappssmtp.com header.i=@riscstar-com.20230601.gappssmtp.com header.b=1VSLg4M0; arc=none smtp.client-ip=209.85.166.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=riscstar.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=riscstar.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=riscstar-com.20230601.gappssmtp.com header.i=@riscstar-com.20230601.gappssmtp.com header.b="1VSLg4M0" Received: by mail-il1-f173.google.com with SMTP id e9e14a558f8ab-3de252f75d7so17252905ab.3 for ; Fri, 25 Jul 2025 05:27:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=riscstar-com.20230601.gappssmtp.com; s=20230601; t=1753446449; x=1754051249; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from:subject:user-agent:mime-version:date:message-id:from:to :cc:subject:date:message-id:reply-to; bh=mXLHt76hrkTzdwesrILbdl/mLwV7e1Au7y/ET7GKzzA=; b=1VSLg4M0As1uRZ0HSlwP2YA9wUNFDo0y8/0IijusydOkvjtDEbGH+GKQ0Z5rlC1zGO cnSEUdTnDUXF8XHZ6Znal8Njx5ZLc44cWIaLfzeTotEO53Nmz3YT8dS4CLL0FD3uqcIF CTvBzw3vyuI9CROAhoGGQw7fCfvO4RqAdsjrrBDciVOftbqZ1JJwrtxFJ3DZ+lz5BIgI datApO63bWk8rBHQ409OsHt+OOw+CHAN1dak+0fAEEkFgVkdoim7f8WlioXymP/YtXFS ElN5EOtwYECTpnqz08sxYvdzk5cBjWWVI95HBjQwJV57LyXfM4L6FzgASngxtZGK5ZKm tysg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753446449; x=1754051249; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=mXLHt76hrkTzdwesrILbdl/mLwV7e1Au7y/ET7GKzzA=; b=TBsUwMwaz6iHuPgM7pMszptj/x7Ok27bZ+c5CjPq7qYKmrFVppo6dx+xtC8G951W0M krur34R9jYdjQDZ9GQMbhcedMTdNQCkujNku+b3pH9HMUBUh0TkrPlY8ohKcepJW6/Fd zXjqUoDxivXcz59Ptuyi2iDfLdZfsbRyFcX6RUjbjNI2agKmsueipl9XjT8VrxHmKJrU hKXiCh6I+PEEcnuYS9wXUKHKkaVlopXf7JSGqz2ZhIQODeuxJNf6zQUQvaQCjAPs+5b0 UsD/RjqyDtZ0Q9exPB6/kj6BT0Kje8o4zeguELzaMq5NUJIyIMPZ1A8lkljJ8eoR9WbS a2wQ== X-Forwarded-Encrypted: i=1; AJvYcCUt8/jWXCYdf20gg23b0dm/JqEcRBdubwGXGguhGytj6MxNS+/FLrSZhsN/fSWeI0Yld1Us7lFo0noy@vger.kernel.org X-Gm-Message-State: AOJu0YxDqZLH5FIjHsU3EzuslLuSgR6p9inmkyWwlROMNnOjfowYLaQc FtInqh3HbLIoeO8fxj3gtzdwLmCPQ0262yajJDFbffpq+kk5CcsqO0jIhR5hFdoTHW8= X-Gm-Gg: ASbGncsn+95F5gwJryT6sxu4ye+G/javd1Oe9wJXhP9qJWK56yu8yCbmugDP6uC+nE6 ZHgZynDTn15yF6fmASg3olXDF7R7wE5sVxacHPI+Lx2ij5ZLqvSV5X/fcZkX4mtxyGw+d8q46z2 z/PiP2UW710QeGExF9hlgvzIhNbJw1Uo8ApCGH3EYNNKKUGxjW2Gk1c38+SqPkxF9Mqd+EfjdIm YM5ApvtP49oE9OVN1zzJnO/pAB3WyoXk+qg3z7HsauRvCTTR+IuhhxZ8hp8z4f3K0LBnLB1v+Ql ib1nLGV0+kQ7MD9MkPCg4ke9jiTdKvW9axWaLsZ2NQVesN2sE8W/g78NQE5YE2ICtD0KYnyxgN1 oBu8qDpaOhT8O07FetpiHqbPYH993q81VGg== X-Google-Smtp-Source: AGHT+IGhO7mEEzu6qStEKP3YhLwseiPFmOnrBPl6/OYfukEuwKgUEIwMH1W9FrN/Z85sZ2BLST8iBQ== X-Received: by 2002:a05:6e02:1a4b:b0:3e3:b7e7:7a67 with SMTP id e9e14a558f8ab-3e3c52b01f6mr23978105ab.14.1753446449421; Fri, 25 Jul 2025 05:27:29 -0700 (PDT) Received: from [10.211.55.5] ([199.59.116.160]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-508aebd545fsm992684173.57.2025.07.25.05.27.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 25 Jul 2025 05:27:28 -0700 (PDT) Message-ID: Date: Fri, 25 Jul 2025 07:27:27 -0500 Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v9 2/8] mfd: simple-mfd-i2c: specify max_register From: Alex Elder To: lee@kernel.org, lgirdwood@gmail.com, broonie@kernel.org, alexandre.belloni@bootlin.com, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org Cc: mat.jonczyk@o2.pl, dlan@gentoo.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr, linux.amoon@gmail.com, troymitchell988@gmail.com, guodong@riscstar.com, linux-rtc@vger.kernel.org, devicetree@vger.kernel.org, linux-riscv@lists.infradead.org, spacemit@lists.linux.dev, linux-kernel@vger.kernel.org References: <20250724202511.499288-1-elder@riscstar.com> <20250724202511.499288-3-elder@riscstar.com> Content-Language: en-US In-Reply-To: <20250724202511.499288-3-elder@riscstar.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 7/24/25 3:25 PM, Alex Elder wrote: > All devices supported by simple MFD use the same 8-bit register 8-bit > value regmap configuration. There is an option available for a device > to specify a custom configuration, but no existing device uses it. > > Rather than requiring a "full" regmap configuration to be provided to > change only the max_register value, Lee Jones suggested allowing > max_register to be specified in the simple_mfd_data structure. The > 8-bit register 8-bit configuration is still used by default, but > max_register is also applied if it is non-zero. > > If both regmap_config and max_register are provided, the max_register > field in the regmap_config structure is ignored. It occurred to me this morning that the regmap_config structure can be freed after the call to devm_regmap_init_i2c(), so I'm going to add a function to free it (if it was dynamically allocated). -Alex > Signed-off-by: Alex Elder > Suggested-by: Lee Jones > --- > v9: - max_register takes precedence over regmap_config in simple_mfd_data > - New function simple_regmap_config() encapsulates providing config > - simple_regmap_config() allocates a regmap_config if necessary > - A small duplicated comment is removed in "simple-mfd-i2c.h" > > drivers/mfd/simple-mfd-i2c.c | 38 +++++++++++++++++++++++++++++++----- > drivers/mfd/simple-mfd-i2c.h | 5 +---- > 2 files changed, 34 insertions(+), 9 deletions(-) > > diff --git a/drivers/mfd/simple-mfd-i2c.c b/drivers/mfd/simple-mfd-i2c.c > index 22159913bea03..f3ba79c112d4e 100644 > --- a/drivers/mfd/simple-mfd-i2c.c > +++ b/drivers/mfd/simple-mfd-i2c.c > @@ -29,6 +29,36 @@ static const struct regmap_config regmap_config_8r_8v = { > .val_bits = 8, > }; > > +/* > + * Determine regmap config to use. If no regmap_config is provided, > + * regmap_config_8r_8v is used. If max_register is specified it is > + * (also) used, whether or not regmap_config is provided. > + */ > +static const struct regmap_config * > +simple_regmap_config(struct device *dev, const struct simple_mfd_data *data) > +{ > + struct regmap_config *regmap_config; > + > + if (!data) > + return ®map_config_8r_8v; > + > + if (data->regmap_config && !data->max_register) > + return data->regmap_config; > + > + regmap_config = devm_kzalloc(dev, sizeof(*regmap_config), GFP_KERNEL); > + if (!regmap_config) > + return NULL; > + > + if (data->regmap_config) > + *regmap_config = *data->regmap_config; > + else > + *regmap_config = regmap_config_8r_8v; > + if (data->max_register) > + regmap_config->max_register = data->max_register; > + > + return regmap_config; > +} > + > static int simple_mfd_i2c_probe(struct i2c_client *i2c) > { > const struct simple_mfd_data *simple_mfd_data; > @@ -38,11 +68,9 @@ static int simple_mfd_i2c_probe(struct i2c_client *i2c) > > simple_mfd_data = device_get_match_data(&i2c->dev); > > - /* If no regmap_config is specified, use the default 8reg and 8val bits */ > - if (!simple_mfd_data || !simple_mfd_data->regmap_config) > - regmap_config = ®map_config_8r_8v; > - else > - regmap_config = simple_mfd_data->regmap_config; > + regmap_config = simple_regmap_config(&i2c->dev, simple_mfd_data); > + if (!regmap_config) > + return -ENOMEM; > > regmap = devm_regmap_init_i2c(i2c, regmap_config); > if (IS_ERR(regmap)) > diff --git a/drivers/mfd/simple-mfd-i2c.h b/drivers/mfd/simple-mfd-i2c.h > index 7cb2bdd347d97..6fa36b3d7a217 100644 > --- a/drivers/mfd/simple-mfd-i2c.h > +++ b/drivers/mfd/simple-mfd-i2c.h > @@ -8,10 +8,6 @@ > * shared by all sub-devices. Children can use their parent's device structure > * (dev.parent) in order to reference it. > * > - * This driver creates a single register map with the intention for it to be > - * shared by all sub-devices. Children can use their parent's device structure > - * (dev.parent) in order to reference it. > - * > * Once the register map has been successfully initialised, any sub-devices > * represented by child nodes in Device Tree or via the MFD cells in the > * associated C file will be subsequently registered. > @@ -25,6 +21,7 @@ > > struct simple_mfd_data { > const struct regmap_config *regmap_config; > + unsigned int max_register; > const struct mfd_cell *mfd_cell; > size_t mfd_cell_size; > };