From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Lucas Tanure <tanureal@opensource.cirrus.com>,
Mark Brown <broonie@kernel.org>, Sasha Levin <sashal@kernel.org>
Subject: [PATCH AUTOSEL 5.12 23/80] regmap-i2c: Set regmap max raw r/w from quirks
Date: Sun, 4 Jul 2021 19:05:19 -0400 [thread overview]
Message-ID: <20210704230616.1489200-23-sashal@kernel.org> (raw)
In-Reply-To: <20210704230616.1489200-1-sashal@kernel.org>
From: Lucas Tanure <tanureal@opensource.cirrus.com>
[ 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 <tanureal@opensource.cirrus.com>
Link: https://lore.kernel.org/r/20210512135222.223203-1-tanureal@opensource.cirrus.com
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
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 2cc4ecd36298..2080bba4e84d 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
next prev parent reply other threads:[~2021-07-04 23:11 UTC|newest]
Thread overview: 82+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-04 23:04 [PATCH AUTOSEL 5.12 01/80] spi: Make of_register_spi_device also set the fwnode Sasha Levin
2021-07-04 23:04 ` [PATCH AUTOSEL 5.12 02/80] Add a reference to ucounts for each cred Sasha Levin
2021-07-04 23:04 ` [PATCH AUTOSEL 5.12 03/80] staging: media: rkvdec: fix pm_runtime_get_sync() usage count Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 04/80] media: i2c: imx334: fix the pm runtime get logic Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 05/80] media: marvel-ccic: fix some issues when getting pm_runtime Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 06/80] media: mdk-mdp: fix pm_runtime_get_sync() usage count Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 07/80] media: s5p: " Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 08/80] media: am437x: " Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 09/80] media: sh_vou: " Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 10/80] media: mtk-vcodec: fix PM runtime get logic Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 11/80] media: s5p-jpeg: fix pm_runtime_get_sync() usage count Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 12/80] media: sunxi: " Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 13/80] media: sti/bdisp: " Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 14/80] media: exynos4-is: " Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 15/80] media: exynos-gsc: " Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 16/80] spi: spi-loopback-test: Fix 'tx_buf' might be 'rx_buf' Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 17/80] spi: spi-topcliff-pch: Fix potential double free in pch_spi_process_messages() Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 18/80] spi: omap-100k: Fix the length judgment problem Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 19/80] regulator: uniphier: Add missing MODULE_DEVICE_TABLE Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 20/80] sched/core: Initialize the idle task with preemption disabled Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 21/80] hwrng: exynos - Fix runtime PM imbalance on error Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 22/80] crypto: nx - add missing MODULE_DEVICE_TABLE Sasha Levin
2021-07-04 23:05 ` Sasha Levin [this message]
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 24/80] media: sti: fix obj-$(config) targets Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 25/80] sched: Make the idle task quack like a per-CPU kthread Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 26/80] media: cpia2: fix memory leak in cpia2_usb_probe Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 27/80] media: cobalt: fix race condition in setting HPD Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 28/80] media: hevc: Fix dependent slice segment flags Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 29/80] media: pvrusb2: fix warning in pvr2_i2c_core_done Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 30/80] media: imx: imx7_mipi_csis: Fix logging of only error event counters Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 31/80] crypto: qat - check return code of qat_hal_rd_rel_reg() Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 32/80] crypto: qat - remove unused macro in FW loader Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 33/80] crypto: qce: skcipher: Fix incorrect sg count for dma transfers Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 34/80] arm64: perf: Convert snprintf to sysfs_emit Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 35/80] sched/fair: Fix ascii art by relpacing tabs Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 36/80] ima: Don't remove security.ima if file must not be appraised Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 37/80] media: i2c: ov2659: Use clk_{prepare_enable,disable_unprepare}() to set xvclk on/off Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 38/80] media: bt878: do not schedule tasklet when it is not setup Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 39/80] media: em28xx: Fix possible memory leak of em28xx struct Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 40/80] media: hantro: Fix .buf_prepare Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 41/80] media: cedrus: " Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 42/80] media: v4l2-core: Avoid the dangling pointer in v4l2_fh_release Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 43/80] media: bt8xx: Fix a missing check bug in bt878_probe Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 44/80] media: st-hva: Fix potential NULL pointer dereferences Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 45/80] crypto: hisilicon/sec - fixup 3des minimum key size declaration Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 46/80] Makefile: fix GDB warning with CONFIG_RELR Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 47/80] media: dvd_usb: memory leak in cinergyt2_fe_attach Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 48/80] memstick: rtsx_usb_ms: fix UAF Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 49/80] mmc: sdhci-sprd: use sdhci_sprd_writew Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 50/80] mmc: via-sdmmc: add a check against NULL pointer dereference Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 51/80] mmc: sdhci-of-aspeed: Turn down a phase correction warning Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 52/80] spi: meson-spicc: fix a wrong goto jump for avoiding memory leak Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 53/80] spi: meson-spicc: fix memory leak in meson_spicc_probe Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 54/80] regulator: mt6315: Fix checking return value of devm_regmap_init_spmi_ext Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 55/80] crypto: shash - avoid comparing pointers to exported functions under CFI Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 56/80] media: dvb_net: avoid speculation from net slot Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 57/80] media: dvbdev: fix error logic at dvb_register_device() Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 58/80] media: siano: fix device register error path Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 59/80] media: imx-csi: Skip first few frames from a BT.656 source Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 60/80] hwmon: (max31790) Report correct current pwm duty cycles Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 61/80] hwmon: (max31790) Fix pwmX_enable attributes Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 62/80] sched/fair: Take thermal pressure into account while estimating energy Sasha Levin
2021-07-05 8:13 ` Lukasz Luba
2021-07-05 10:12 ` Sasha Levin
2021-07-04 23:05 ` [PATCH AUTOSEL 5.12 63/80] drivers/perf: fix the missed ida_simple_remove() in ddr_perf_probe() Sasha Levin
2021-07-04 23:06 ` [PATCH AUTOSEL 5.12 64/80] KVM: arm64: Restore PMU configuration on first run Sasha Levin
2021-07-04 23:06 ` [PATCH AUTOSEL 5.12 65/80] KVM: PPC: Book3S HV: Fix TLB management on SMT8 POWER9 and POWER10 processors Sasha Levin
2021-07-04 23:06 ` [PATCH AUTOSEL 5.12 66/80] btrfs: fix error handling in __btrfs_update_delayed_inode Sasha Levin
2021-07-04 23:06 ` [PATCH AUTOSEL 5.12 67/80] btrfs: abort transaction if we fail to update the delayed inode Sasha Levin
2021-07-04 23:06 ` [PATCH AUTOSEL 5.12 68/80] btrfs: always abort the transaction if we abort a trans handle Sasha Levin
2021-07-04 23:06 ` [PATCH AUTOSEL 5.12 69/80] btrfs: sysfs: fix format string for some discard stats Sasha Levin
2021-07-04 23:06 ` [PATCH AUTOSEL 5.12 70/80] btrfs: scrub: fix subpage repair error caused by hard coded PAGE_SIZE Sasha Levin
2021-07-04 23:06 ` [PATCH AUTOSEL 5.12 71/80] btrfs: make Private2 lifespan more consistent Sasha Levin
2021-07-04 23:06 ` [PATCH AUTOSEL 5.12 72/80] btrfs: fix the filemap_range_has_page() call in btrfs_punch_hole_lock_range() Sasha Levin
2021-07-04 23:06 ` [PATCH AUTOSEL 5.12 73/80] btrfs: don't clear page extent mapped if we're not invalidating the full page Sasha Levin
2021-07-04 23:06 ` [PATCH AUTOSEL 5.12 74/80] btrfs: disable build on platforms having page size 256K Sasha Levin
2021-07-04 23:06 ` [PATCH AUTOSEL 5.12 75/80] locking/lockdep: Fix the dep path printing for backwards BFS Sasha Levin
2021-07-04 23:06 ` [PATCH AUTOSEL 5.12 76/80] lockding/lockdep: Avoid to find wrong lock dep path in check_irq_usage() Sasha Levin
2021-07-04 23:06 ` [PATCH AUTOSEL 5.12 77/80] KVM: s390: get rid of register asm usage Sasha Levin
2021-07-04 23:06 ` [PATCH AUTOSEL 5.12 78/80] regulator: mt6358: Fix vdram2 .vsel_mask Sasha Levin
2021-07-04 23:06 ` [PATCH AUTOSEL 5.12 79/80] regulator: da9052: Ensure enough delay time for .set_voltage_time_sel Sasha Levin
2021-07-04 23:06 ` [PATCH AUTOSEL 5.12 80/80] media: Fix Media Controller API config checks Sasha Levin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210704230616.1489200-23-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=broonie@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=tanureal@opensource.cirrus.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox