Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3343831pxv; Sun, 4 Jul 2021 16:06:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJydwGWrCRd/Pfr2zw/Ka5sYjyipd+Ec/ls6aRBXio7GWzK4xyXozwPHvMBYy7pU+UK9OsGI X-Received: by 2002:a6b:e807:: with SMTP id f7mr9727984ioh.2.1625439972191; Sun, 04 Jul 2021 16:06:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625439972; cv=none; d=google.com; s=arc-20160816; b=invLF/qJE6OeGhBxoVs4Ct8Nw1ec+V7eComy8oks7jVm3vPchYEvs+Pz5PJ6OLnCW7 rqCGZSGzIShw90HeF+CK9Wj2zHFFGRcQL3SyxP45mmIwRRRmzcQOVyT60f0opzCviF5x Es0T94adzKakSTrgprIt5d1A0twf1VpXtuX0b/MjVcU5laB7Ca3HrC9Wmq6Ud7nrcUmq 9jGTQic4oFuk8Bg4h1Zze/HPJD8fr4aXdlhvjXdO8J/0g+Rr2tTiTvJkxPyoT1Khr6Yw IlCALjCbzC4hHnRdb4Llwg49OIAFKOsAQ+Z8O2gZJwLT6E/84DwRW39OC3weSVazLn/6 zSTA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=9k5Es54Xs+JkIG0OkXhg3WIZb1aATf1Cr6v9MYbyvmQ=; b=YZII3WTFGaEWqVXOZiekMivzJkRsRq5qeB/GTFjpSC2oOOy5OozsJmy4t/CYjDqcdd tHImaDLbg5NWtcnA565jYWxaQBOIeEc38h3/uahILOt441HstayXaolLaaqtLKWlCjMJ +gqNGKaFE2qJC4Yrcdo6ByKugdxytPHiR2CYjYFfdnnV+oF9s60oQd81xtf2p/GbWQ+k c/+HdC2exYubCUdKZk5WYMRA3bl2TbLPZVNJQyxsLF3Uehk2J4bEGjQOE0URNwvLomIK 1IwkhOYPVB0sxvCeN70Xu389yhgfucFKthhl1JbFrH6kRVjxVocfrNFnM0zQcEpvltGG Z9qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=r0zyjcz4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h4si3291693ilq.151.2021.07.04.16.06.00; Sun, 04 Jul 2021 16:06:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=r0zyjcz4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230348AbhGDXHp (ORCPT + 99 others); Sun, 4 Jul 2021 19:07:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:45780 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230181AbhGDXH3 (ORCPT ); Sun, 4 Jul 2021 19:07:29 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id F01F3611ED; Sun, 4 Jul 2021 23:04:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625439893; bh=LSWH/woqNWIjGDaCBkBIa1h0TErufIHLKuaj3Mebucg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r0zyjcz4YyUvhqL5x48YYyz0YDgfNSuZemxlzdbEvKDET/q9TDOQMnlfKLXjuA5Mi VXA1XPOsktDNG9tjQaxRDhIKX30vWX7FZhTerpXpuvnnNSzN3gU8B30w6XGWgV73Nx KZ9OshtVjE2IZy3J6fzo+ZW3bEt6Ucemb5vlrFsW5gACMd2rvbuLvAZU2D5LQY5UQN q9/NgObsTXWv8D8P9VF/XLx5forAyxmE3YhrNneQDZGlcv17+3b9BI43Znf+xgTlYd NmXFVEhDPWiJ7ILl9TNVOi9pVV5V9hC0QzIfZwBeZT92vdOMQ9AHeM4qx0iWCqFtzZ 6L/XcP+kg3w8g== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Lucas Tanure , Mark Brown , Sasha Levin Subject: [PATCH AUTOSEL 5.13 23/85] regmap-i2c: Set regmap max raw r/w from quirks Date: Sun, 4 Jul 2021 19:03:18 -0400 Message-Id: <20210704230420.1488358-23-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210704230420.1488358-1-sashal@kernel.org> References: <20210704230420.1488358-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lucas Tanure [ Upstream commit ea030ca688193462b8d612c1628c37129aa30072 ] Set regmap raw read/write from i2c quirks max read/write so regmap_raw_read/write can split the access into chunks Signed-off-by: Lucas Tanure Link: https://lore.kernel.org/r/20210512135222.223203-1-tanureal@opensource.cirrus.com Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- drivers/base/regmap/regmap-i2c.c | 45 +++++++++++++++++++++++++++----- drivers/base/regmap/regmap.c | 2 ++ include/linux/regmap.h | 2 ++ 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/drivers/base/regmap/regmap-i2c.c b/drivers/base/regmap/regmap-i2c.c index 62b95a9212ae..980e5ce6a3a3 100644 --- a/drivers/base/regmap/regmap-i2c.c +++ b/drivers/base/regmap/regmap-i2c.c @@ -306,33 +306,64 @@ static const struct regmap_bus regmap_i2c_smbus_i2c_block_reg16 = { static const struct regmap_bus *regmap_get_i2c_bus(struct i2c_client *i2c, const struct regmap_config *config) { + const struct i2c_adapter_quirks *quirks; + const struct regmap_bus *bus = NULL; + struct regmap_bus *ret_bus; + u16 max_read = 0, max_write = 0; + if (i2c_check_functionality(i2c->adapter, I2C_FUNC_I2C)) - return ®map_i2c; + bus = ®map_i2c; else if (config->val_bits == 8 && config->reg_bits == 8 && i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) - return ®map_i2c_smbus_i2c_block; + bus = ®map_i2c_smbus_i2c_block; else if (config->val_bits == 8 && config->reg_bits == 16 && i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) - return ®map_i2c_smbus_i2c_block_reg16; + bus = ®map_i2c_smbus_i2c_block_reg16; else if (config->val_bits == 16 && config->reg_bits == 8 && i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_WORD_DATA)) switch (regmap_get_val_endian(&i2c->dev, NULL, config)) { case REGMAP_ENDIAN_LITTLE: - return ®map_smbus_word; + bus = ®map_smbus_word; + break; case REGMAP_ENDIAN_BIG: - return ®map_smbus_word_swapped; + bus = ®map_smbus_word_swapped; + break; default: /* everything else is not supported */ break; } else if (config->val_bits == 8 && config->reg_bits == 8 && i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) - return ®map_smbus_byte; + bus = ®map_smbus_byte; + + if (!bus) + return ERR_PTR(-ENOTSUPP); + + quirks = i2c->adapter->quirks; + if (quirks) { + if (quirks->max_read_len && + (bus->max_raw_read == 0 || bus->max_raw_read > quirks->max_read_len)) + max_read = quirks->max_read_len; + + if (quirks->max_write_len && + (bus->max_raw_write == 0 || bus->max_raw_write > quirks->max_write_len)) + max_write = quirks->max_write_len; + + if (max_read || max_write) { + ret_bus = kmemdup(bus, sizeof(*bus), GFP_KERNEL); + if (!ret_bus) + return ERR_PTR(-ENOMEM); + ret_bus->free_on_exit = true; + ret_bus->max_raw_read = max_read; + ret_bus->max_raw_write = max_write; + bus = ret_bus; + } + } - return ERR_PTR(-ENOTSUPP); + return bus; } struct regmap *__regmap_init_i2c(struct i2c_client *i2c, diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index 297e95be25b3..0d185ec018a5 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c @@ -1496,6 +1496,8 @@ void regmap_exit(struct regmap *map) mutex_destroy(&map->mutex); kfree_const(map->name); kfree(map->patch); + if (map->bus && map->bus->free_on_exit) + kfree(map->bus); kfree(map); } EXPORT_SYMBOL_GPL(regmap_exit); diff --git a/include/linux/regmap.h b/include/linux/regmap.h index f87a11a5cc4a..8c16e6fa0f66 100644 --- a/include/linux/regmap.h +++ b/include/linux/regmap.h @@ -502,6 +502,7 @@ typedef void (*regmap_hw_free_context)(void *context); * DEFAULT, BIG is assumed. * @max_raw_read: Max raw read size that can be used on the bus. * @max_raw_write: Max raw write size that can be used on the bus. + * @free_on_exit: kfree this on exit of regmap */ struct regmap_bus { bool fast_io; @@ -519,6 +520,7 @@ struct regmap_bus { enum regmap_endian val_format_endian_default; size_t max_raw_read; size_t max_raw_write; + bool free_on_exit; }; /* -- 2.30.2