* [PATCH 0/8] OMAP I2C driver cleanups
@ 2026-09-04 13:12 Andrew Davis
2026-09-04 13:12 ` [PATCH 1/8] i2c: omap: Drop bit shift for I2C register addresses Andrew Davis
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: Andrew Davis @ 2026-09-04 13:12 UTC (permalink / raw)
To: Tony Lindgren, Vignesh R, Andreas Kemnade, Kevin Hilman,
Roger Quadros, Andi Shyti
Cc: linux-omap, linux-arm-kernel, linux-i2c, linux-kernel,
Andrew Davis
Hello all,
Some hopefully simple cleanups and updates found while using this driver
as reference when porting the same over to Zephyr. No functional changes.
Thanks,
Andrew
Andrew Davis (8):
i2c: omap: Drop bit shift for I2C register addresses
i2c: omap: Remove unused is_rdr and is_xdr variables
i2c: omap: Use devm_pm_runtime_enable() helper
i2c: omap: Combine event flags register definitions
i2c: omap: Use bool for flag values
i2c: omap: Make reset bit name match register name
i2c: omap: Switch to using BIT and GENMASK
i2c: omap: Add OMAP_I2C_BUF_{TX,RX}TRSH definitions
arch/arm/mach-omap1/i2c.c | 4 -
drivers/i2c/busses/i2c-omap.c | 254 +++++++++++--------------
include/linux/platform_data/i2c-omap.h | 5 -
3 files changed, 112 insertions(+), 151 deletions(-)
--
2.39.2
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 1/8] i2c: omap: Drop bit shift for I2C register addresses
2026-09-04 13:12 [PATCH 0/8] OMAP I2C driver cleanups Andrew Davis
@ 2026-09-04 13:12 ` Andrew Davis
2026-09-04 13:12 ` [PATCH 2/8] i2c: omap: Remove unused is_rdr and is_xdr variables Andrew Davis
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Andrew Davis @ 2026-09-04 13:12 UTC (permalink / raw)
To: Tony Lindgren, Vignesh R, Andreas Kemnade, Kevin Hilman,
Roger Quadros, Andi Shyti
Cc: linux-omap, linux-arm-kernel, linux-i2c, linux-kernel,
Andrew Davis
No remaining board device uses a shift other than 2, and no DT supported
platform ever did. We can drop this flag and use the pre-shifted register
addresses. This simplifies the register access.
Signed-off-by: Andrew Davis <afd@ti.com>
---
arch/arm/mach-omap1/i2c.c | 4 ---
drivers/i2c/busses/i2c-omap.c | 50 +++++++++++---------------
include/linux/platform_data/i2c-omap.h | 5 ---
3 files changed, 21 insertions(+), 38 deletions(-)
diff --git a/arch/arm/mach-omap1/i2c.c b/arch/arm/mach-omap1/i2c.c
index 94d3e7883e027..bc7828a858941 100644
--- a/arch/arm/mach-omap1/i2c.c
+++ b/arch/arm/mach-omap1/i2c.c
@@ -61,10 +61,6 @@ int __init omap_i2c_add_bus(struct omap_i2c_bus_platform_data *pdata,
OMAP_I2C_FLAG_16BIT_DATA_REG |
OMAP_I2C_FLAG_ALWAYS_ARMXOR_CLK;
- /* how the cpu bus is wired up differs for 7xx only */
-
- pdata->flags |= OMAP_I2C_FLAG_BUS_SHIFT_2;
-
pdev->dev.platform_data = pdata;
return platform_device_register(pdev);
diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
index f02d294db42a6..72f979eec7311 100644
--- a/drivers/i2c/busses/i2c-omap.c
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -180,7 +180,6 @@ struct omap_i2c_dev {
struct device *dev;
void __iomem *base; /* virtual */
int irq;
- int reg_shift; /* bit shift for I2C register addresses */
struct completion cmd_complete;
struct resource *ioarea;
u32 latency; /* maximum mpu wkup latency */
@@ -217,23 +216,23 @@ struct omap_i2c_dev {
static const u8 reg_map_ip_v1[] = {
[OMAP_I2C_REV_REG] = 0x00,
- [OMAP_I2C_IE_REG] = 0x01,
- [OMAP_I2C_STAT_REG] = 0x02,
- [OMAP_I2C_IV_REG] = 0x03,
- [OMAP_I2C_WE_REG] = 0x03,
- [OMAP_I2C_SYSS_REG] = 0x04,
- [OMAP_I2C_BUF_REG] = 0x05,
- [OMAP_I2C_CNT_REG] = 0x06,
- [OMAP_I2C_DATA_REG] = 0x07,
- [OMAP_I2C_SYSC_REG] = 0x08,
- [OMAP_I2C_CON_REG] = 0x09,
- [OMAP_I2C_OA_REG] = 0x0a,
- [OMAP_I2C_SA_REG] = 0x0b,
- [OMAP_I2C_PSC_REG] = 0x0c,
- [OMAP_I2C_SCLL_REG] = 0x0d,
- [OMAP_I2C_SCLH_REG] = 0x0e,
- [OMAP_I2C_SYSTEST_REG] = 0x0f,
- [OMAP_I2C_BUFSTAT_REG] = 0x10,
+ [OMAP_I2C_IE_REG] = 0x04,
+ [OMAP_I2C_STAT_REG] = 0x0c,
+ [OMAP_I2C_IV_REG] = 0x0c,
+ [OMAP_I2C_WE_REG] = 0x0c,
+ [OMAP_I2C_SYSS_REG] = 0x10,
+ [OMAP_I2C_BUF_REG] = 0x14,
+ [OMAP_I2C_CNT_REG] = 0x18,
+ [OMAP_I2C_DATA_REG] = 0x1c,
+ [OMAP_I2C_SYSC_REG] = 0x20,
+ [OMAP_I2C_CON_REG] = 0x24,
+ [OMAP_I2C_OA_REG] = 0x28,
+ [OMAP_I2C_SA_REG] = 0x2c,
+ [OMAP_I2C_PSC_REG] = 0x30,
+ [OMAP_I2C_SCLL_REG] = 0x34,
+ [OMAP_I2C_SCLH_REG] = 0x38,
+ [OMAP_I2C_SYSTEST_REG] = 0x3c,
+ [OMAP_I2C_BUFSTAT_REG] = 0x40,
};
static const u8 reg_map_ip_v2[] = {
@@ -267,14 +266,12 @@ static int omap_i2c_xfer_data(struct omap_i2c_dev *omap);
static inline void omap_i2c_write_reg(struct omap_i2c_dev *omap,
int reg, u16 val)
{
- writew_relaxed(val, omap->base +
- (omap->regs[reg] << omap->reg_shift));
+ writew_relaxed(val, omap->base + omap->regs[reg]);
}
static inline u16 omap_i2c_read_reg(struct omap_i2c_dev *omap, int reg)
{
- return readw_relaxed(omap->base +
- (omap->regs[reg] << omap->reg_shift));
+ return readw_relaxed(omap->base + omap->regs[reg]);
}
static void __omap_i2c_init(struct omap_i2c_dev *omap)
@@ -1214,19 +1211,16 @@ static struct omap_i2c_bus_platform_data omap2420_pdata = {
.rev = OMAP_I2C_IP_VERSION_1,
.flags = OMAP_I2C_FLAG_NO_FIFO |
OMAP_I2C_FLAG_SIMPLE_CLOCK |
- OMAP_I2C_FLAG_16BIT_DATA_REG |
- OMAP_I2C_FLAG_BUS_SHIFT_2,
+ OMAP_I2C_FLAG_16BIT_DATA_REG,
};
static struct omap_i2c_bus_platform_data omap2430_pdata = {
.rev = OMAP_I2C_IP_VERSION_1,
- .flags = OMAP_I2C_FLAG_BUS_SHIFT_2 |
- OMAP_I2C_FLAG_FORCE_19200_INT_CLK,
+ .flags = OMAP_I2C_FLAG_FORCE_19200_INT_CLK,
};
static struct omap_i2c_bus_platform_data omap3_pdata = {
.rev = OMAP_I2C_IP_VERSION_1,
- .flags = OMAP_I2C_FLAG_BUS_SHIFT_2,
};
static struct omap_i2c_bus_platform_data omap4_pdata = {
@@ -1384,8 +1378,6 @@ omap_i2c_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, omap);
init_completion(&omap->cmd_complete);
- omap->reg_shift = (omap->flags >> OMAP_I2C_FLAG_BUS_SHIFT__SHIFT) & 3;
-
pm_runtime_enable(omap->dev);
pm_runtime_set_autosuspend_delay(omap->dev, OMAP_I2C_PM_TIMEOUT);
pm_runtime_use_autosuspend(omap->dev);
diff --git a/include/linux/platform_data/i2c-omap.h b/include/linux/platform_data/i2c-omap.h
index 3444265ee8ee7..fe6753cd17bf5 100644
--- a/include/linux/platform_data/i2c-omap.h
+++ b/include/linux/platform_data/i2c-omap.h
@@ -23,11 +23,6 @@
#define OMAP_I2C_FLAG_16BIT_DATA_REG BIT(2)
#define OMAP_I2C_FLAG_ALWAYS_ARMXOR_CLK BIT(5)
#define OMAP_I2C_FLAG_FORCE_19200_INT_CLK BIT(6)
-/* how the CPU address bus must be translated for I2C unit access */
-#define OMAP_I2C_FLAG_BUS_SHIFT_NONE 0
-#define OMAP_I2C_FLAG_BUS_SHIFT_1 BIT(7)
-#define OMAP_I2C_FLAG_BUS_SHIFT_2 BIT(8)
-#define OMAP_I2C_FLAG_BUS_SHIFT__SHIFT 7
struct omap_i2c_bus_platform_data {
u32 clkrate;
--
2.39.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/8] i2c: omap: Remove unused is_rdr and is_xdr variables
2026-09-04 13:12 [PATCH 0/8] OMAP I2C driver cleanups Andrew Davis
2026-09-04 13:12 ` [PATCH 1/8] i2c: omap: Drop bit shift for I2C register addresses Andrew Davis
@ 2026-09-04 13:12 ` Andrew Davis
2026-09-04 13:12 ` [PATCH 3/8] i2c: omap: Use devm_pm_runtime_enable() helper Andrew Davis
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Andrew Davis @ 2026-09-04 13:12 UTC (permalink / raw)
To: Tony Lindgren, Vignesh R, Andreas Kemnade, Kevin Hilman,
Roger Quadros, Andi Shyti
Cc: linux-omap, linux-arm-kernel, linux-i2c, linux-kernel,
Andrew Davis
These are passed into omap_i2c_{receive,transmit}_data() but are never
used, remove them.
Signed-off-by: Andrew Davis <afd@ti.com>
---
drivers/i2c/busses/i2c-omap.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
index 72f979eec7311..68b0a043f1e51 100644
--- a/drivers/i2c/busses/i2c-omap.c
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -993,8 +993,7 @@ static int errata_omap3_i462(struct omap_i2c_dev *omap)
return 0;
}
-static void omap_i2c_receive_data(struct omap_i2c_dev *omap, u8 num_bytes,
- bool is_rdr)
+static void omap_i2c_receive_data(struct omap_i2c_dev *omap, u8 num_bytes)
{
u16 w;
@@ -1014,8 +1013,7 @@ static void omap_i2c_receive_data(struct omap_i2c_dev *omap, u8 num_bytes,
}
}
-static int omap_i2c_transmit_data(struct omap_i2c_dev *omap, u8 num_bytes,
- bool is_xdr)
+static int omap_i2c_transmit_data(struct omap_i2c_dev *omap, u8 num_bytes)
{
u16 w;
@@ -1119,7 +1117,7 @@ static int omap_i2c_xfer_data(struct omap_i2c_dev *omap)
OMAP_I2C_BUFSTAT_REG) >> 8) & 0x3F;
}
- omap_i2c_receive_data(omap, num_bytes, true);
+ omap_i2c_receive_data(omap, num_bytes);
omap_i2c_ack_stat(omap, OMAP_I2C_STAT_RDR);
continue;
}
@@ -1130,7 +1128,7 @@ static int omap_i2c_xfer_data(struct omap_i2c_dev *omap)
if (omap->threshold)
num_bytes = omap->threshold;
- omap_i2c_receive_data(omap, num_bytes, false);
+ omap_i2c_receive_data(omap, num_bytes);
omap_i2c_ack_stat(omap, OMAP_I2C_STAT_RRDY);
continue;
}
@@ -1142,7 +1140,7 @@ static int omap_i2c_xfer_data(struct omap_i2c_dev *omap)
if (omap->fifo_size)
num_bytes = omap->buf_len;
- ret = omap_i2c_transmit_data(omap, num_bytes, true);
+ ret = omap_i2c_transmit_data(omap, num_bytes);
if (ret < 0)
break;
@@ -1157,7 +1155,7 @@ static int omap_i2c_xfer_data(struct omap_i2c_dev *omap)
if (omap->threshold)
num_bytes = omap->threshold;
- ret = omap_i2c_transmit_data(omap, num_bytes, false);
+ ret = omap_i2c_transmit_data(omap, num_bytes);
if (ret < 0)
break;
--
2.39.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 3/8] i2c: omap: Use devm_pm_runtime_enable() helper
2026-09-04 13:12 [PATCH 0/8] OMAP I2C driver cleanups Andrew Davis
2026-09-04 13:12 ` [PATCH 1/8] i2c: omap: Drop bit shift for I2C register addresses Andrew Davis
2026-09-04 13:12 ` [PATCH 2/8] i2c: omap: Remove unused is_rdr and is_xdr variables Andrew Davis
@ 2026-09-04 13:12 ` Andrew Davis
2026-09-04 13:12 ` [PATCH 4/8] i2c: omap: Combine event flags register definitions Andrew Davis
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Andrew Davis @ 2026-09-04 13:12 UTC (permalink / raw)
To: Tony Lindgren, Vignesh R, Andreas Kemnade, Kevin Hilman,
Roger Quadros, Andi Shyti
Cc: linux-omap, linux-arm-kernel, linux-i2c, linux-kernel,
Andrew Davis
Use device life-cycle managed runtime enable function to simplify probe
and exit paths. It will call pm_runtime_dont_use_autosuspend() for us.
Signed-off-by: Andrew Davis <afd@ti.com>
---
drivers/i2c/busses/i2c-omap.c | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
index 68b0a043f1e51..e03519d939755 100644
--- a/drivers/i2c/busses/i2c-omap.c
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -1376,13 +1376,13 @@ omap_i2c_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, omap);
init_completion(&omap->cmd_complete);
- pm_runtime_enable(omap->dev);
+ devm_pm_runtime_enable(omap->dev);
pm_runtime_set_autosuspend_delay(omap->dev, OMAP_I2C_PM_TIMEOUT);
pm_runtime_use_autosuspend(omap->dev);
r = pm_runtime_resume_and_get(omap->dev);
if (r < 0)
- goto err_disable_pm;
+ return r;
/*
* Read the Rev hi bit-[15:14] ie scheme this is 1 indicates ver2.
@@ -1496,9 +1496,6 @@ omap_i2c_probe(struct platform_device *pdev)
omap_i2c_write_reg(omap, OMAP_I2C_CON_REG, 0);
err_put_pm:
pm_runtime_put_sync(omap->dev);
-err_disable_pm:
- pm_runtime_dont_use_autosuspend(omap->dev);
- pm_runtime_disable(&pdev->dev);
return r;
}
@@ -1519,9 +1516,7 @@ static void omap_i2c_remove(struct platform_device *pdev)
else
omap_i2c_write_reg(omap, OMAP_I2C_CON_REG, 0);
- pm_runtime_dont_use_autosuspend(&pdev->dev);
pm_runtime_put_sync(&pdev->dev);
- pm_runtime_disable(&pdev->dev);
}
static int omap_i2c_runtime_suspend(struct device *dev)
--
2.39.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 4/8] i2c: omap: Combine event flags register definitions
2026-09-04 13:12 [PATCH 0/8] OMAP I2C driver cleanups Andrew Davis
` (2 preceding siblings ...)
2026-09-04 13:12 ` [PATCH 3/8] i2c: omap: Use devm_pm_runtime_enable() helper Andrew Davis
@ 2026-09-04 13:12 ` Andrew Davis
2026-09-04 13:12 ` [PATCH 5/8] i2c: omap: Use bool for flag values Andrew Davis
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Andrew Davis @ 2026-09-04 13:12 UTC (permalink / raw)
To: Tony Lindgren, Vignesh R, Andreas Kemnade, Kevin Hilman,
Roger Quadros, Andi Shyti
Cc: linux-omap, linux-arm-kernel, linux-i2c, linux-kernel,
Andrew Davis
The position of the status, interrupt enable, and wakeup enable bits for
each event are the same in each of their respective registers. We only
need one set of offset definitions that can be shared.
Signed-off-by: Andrew Davis <afd@ti.com>
---
drivers/i2c/busses/i2c-omap.c | 58 ++++++++++++++---------------------
1 file changed, 23 insertions(+), 35 deletions(-)
diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
index e03519d939755..cc65dc90770d1 100644
--- a/drivers/i2c/busses/i2c-omap.c
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -78,16 +78,7 @@ enum {
OMAP_I2C_IP_V2_IRQENABLE_CLR,
};
-/* I2C Interrupt Enable Register (OMAP_I2C_IE): */
-#define OMAP_I2C_IE_XDR (1 << 14) /* TX Buffer drain int enable */
-#define OMAP_I2C_IE_RDR (1 << 13) /* RX Buffer drain int enable */
-#define OMAP_I2C_IE_XRDY (1 << 4) /* TX data ready int enable */
-#define OMAP_I2C_IE_RRDY (1 << 3) /* RX data ready int enable */
-#define OMAP_I2C_IE_ARDY (1 << 2) /* Access ready int enable */
-#define OMAP_I2C_IE_NACK (1 << 1) /* No ack interrupt enable */
-#define OMAP_I2C_IE_AL (1 << 0) /* Arbitration lost int ena */
-
-/* I2C Status Register (OMAP_I2C_STAT): */
+/* I2C Status bits (OMAP_I2C_IE, OMAP_I2C_STAT, OMAP_I2C_WE) */
#define OMAP_I2C_STAT_XDR (1 << 14) /* TX Buffer draining */
#define OMAP_I2C_STAT_RDR (1 << 13) /* RX Buffer draining */
#define OMAP_I2C_STAT_BB (1 << 12) /* Bus busy */
@@ -95,29 +86,13 @@ enum {
#define OMAP_I2C_STAT_XUDF (1 << 10) /* Transmit underflow */
#define OMAP_I2C_STAT_AAS (1 << 9) /* Address as slave */
#define OMAP_I2C_STAT_BF (1 << 8) /* Bus Free */
+#define OMAP_I2C_STAT_STC (1 << 6) /* Start condition */
+#define OMAP_I2C_STAT_GC (1 << 5) /* General call */
#define OMAP_I2C_STAT_XRDY (1 << 4) /* Transmit data ready */
#define OMAP_I2C_STAT_RRDY (1 << 3) /* Receive data ready */
#define OMAP_I2C_STAT_ARDY (1 << 2) /* Register access ready */
-#define OMAP_I2C_STAT_NACK (1 << 1) /* No ack interrupt enable */
-#define OMAP_I2C_STAT_AL (1 << 0) /* Arbitration lost int ena */
-
-/* I2C WE wakeup enable register */
-#define OMAP_I2C_WE_XDR_WE (1 << 14) /* TX drain wakup */
-#define OMAP_I2C_WE_RDR_WE (1 << 13) /* RX drain wakeup */
-#define OMAP_I2C_WE_AAS_WE (1 << 9) /* Address as slave wakeup*/
-#define OMAP_I2C_WE_BF_WE (1 << 8) /* Bus free wakeup */
-#define OMAP_I2C_WE_STC_WE (1 << 6) /* Start condition wakeup */
-#define OMAP_I2C_WE_GC_WE (1 << 5) /* General call wakeup */
-#define OMAP_I2C_WE_DRDY_WE (1 << 3) /* TX/RX data ready wakeup */
-#define OMAP_I2C_WE_ARDY_WE (1 << 2) /* Reg access ready wakeup */
-#define OMAP_I2C_WE_NACK_WE (1 << 1) /* No acknowledgment wakeup */
-#define OMAP_I2C_WE_AL_WE (1 << 0) /* Arbitration lost wakeup */
-
-#define OMAP_I2C_WE_ALL (OMAP_I2C_WE_XDR_WE | OMAP_I2C_WE_RDR_WE | \
- OMAP_I2C_WE_AAS_WE | OMAP_I2C_WE_BF_WE | \
- OMAP_I2C_WE_STC_WE | OMAP_I2C_WE_GC_WE | \
- OMAP_I2C_WE_DRDY_WE | OMAP_I2C_WE_ARDY_WE | \
- OMAP_I2C_WE_NACK_WE | OMAP_I2C_WE_AL_WE)
+#define OMAP_I2C_STAT_NACK (1 << 1) /* No ack */
+#define OMAP_I2C_STAT_AL (1 << 0) /* Arbitration lost */
/* I2C Buffer Configuration Register (OMAP_I2C_BUF): */
#define OMAP_I2C_BUF_RDMA_EN (1 << 15) /* RX DMA channel enable */
@@ -360,7 +335,16 @@ static int omap_i2c_init(struct omap_i2c_dev *omap)
* WFI instruction.
* REVISIT: Some wkup sources might not be needed.
*/
- omap->westate = OMAP_I2C_WE_ALL;
+ omap->westate = (OMAP_I2C_STAT_XDR |
+ OMAP_I2C_STAT_RDR |
+ OMAP_I2C_STAT_AAS |
+ OMAP_I2C_STAT_BF |
+ OMAP_I2C_STAT_STC |
+ OMAP_I2C_STAT_GC |
+ OMAP_I2C_STAT_RRDY |
+ OMAP_I2C_STAT_ARDY |
+ OMAP_I2C_STAT_NACK |
+ OMAP_I2C_STAT_AL);
}
if (omap->flags & OMAP_I2C_FLAG_ALWAYS_ARMXOR_CLK) {
@@ -459,10 +443,14 @@ static int omap_i2c_init(struct omap_i2c_dev *omap)
sclh = fclk_rate / (omap->speed * 2) - 7 + psc;
}
- omap->iestate = (OMAP_I2C_IE_XRDY | OMAP_I2C_IE_RRDY |
- OMAP_I2C_IE_ARDY | OMAP_I2C_IE_NACK |
- OMAP_I2C_IE_AL) | ((omap->fifo_size) ?
- (OMAP_I2C_IE_RDR | OMAP_I2C_IE_XDR) : 0);
+ omap->iestate = (OMAP_I2C_STAT_XRDY |
+ OMAP_I2C_STAT_RRDY |
+ OMAP_I2C_STAT_ARDY |
+ OMAP_I2C_STAT_NACK |
+ OMAP_I2C_STAT_AL);
+
+ if (omap->fifo_size)
+ omap->iestate |= (OMAP_I2C_STAT_RDR | OMAP_I2C_STAT_XDR);
omap->pscstate = psc;
omap->scllstate = scll;
--
2.39.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 5/8] i2c: omap: Use bool for flag values
2026-09-04 13:12 [PATCH 0/8] OMAP I2C driver cleanups Andrew Davis
` (3 preceding siblings ...)
2026-09-04 13:12 ` [PATCH 4/8] i2c: omap: Combine event flags register definitions Andrew Davis
@ 2026-09-04 13:12 ` Andrew Davis
2026-09-04 13:12 ` [PATCH 6/8] i2c: omap: Make reset bit name match register name Andrew Davis
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Andrew Davis @ 2026-09-04 13:12 UTC (permalink / raw)
To: Tony Lindgren, Vignesh R, Andreas Kemnade, Kevin Hilman,
Roger Quadros, Andi Shyti
Cc: linux-omap, linux-arm-kernel, linux-i2c, linux-kernel,
Andrew Davis
C bit fields are weird, use bool for single bit flags. The compiler will
set these to an aligned size in the structs in either case.
Signed-off-by: Andrew Davis <afd@ti.com>
---
drivers/i2c/busses/i2c-omap.c | 26 +++++++++++++-------------
1 file changed, 13 insertions(+), 13 deletions(-)
diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
index cc65dc90770d1..dc75780f76c96 100644
--- a/drivers/i2c/busses/i2c-omap.c
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -174,11 +174,11 @@ struct omap_i2c_dev {
* if set, should be trsh+1
*/
u32 rev;
- unsigned b_hw:1; /* bad h/w fixes */
- unsigned bb_valid:1; /* true when BB-bit reflects
+ bool b_hw; /* bad h/w fixes */
+ bool bb_valid; /* true when BB-bit reflects
* the I2C bus state
*/
- unsigned receiver:1; /* true when we're in receiver mode */
+ bool receiver; /* true when we're in receiver mode */
u16 iestate; /* Saved interrupt register */
u16 pscstate;
u16 scllstate;
@@ -313,7 +313,7 @@ static int omap_i2c_reset(struct omap_i2c_dev *omap)
if (omap->rev > OMAP_I2C_REV_ON_3430_3530) {
/* Schedule I2C-bus monitoring on the next transfer */
- omap->bb_valid = 0;
+ omap->bb_valid = false;
}
}
@@ -458,7 +458,7 @@ static int omap_i2c_init(struct omap_i2c_dev *omap)
if (omap->rev <= OMAP_I2C_REV_ON_3430_3530) {
/* Not implemented */
- omap->bb_valid = 1;
+ omap->bb_valid = true;
}
__omap_i2c_init(omap);
@@ -531,7 +531,7 @@ static int omap_i2c_wait_for_bb_valid(struct omap_i2c_dev *omap)
{
unsigned long bus_free_timeout = 0;
unsigned long timeout;
- int bus_free = 0;
+ bool bus_free = false;
u16 stat, systest;
if (omap->bb_valid)
@@ -558,7 +558,7 @@ static int omap_i2c_wait_for_bb_valid(struct omap_i2c_dev *omap)
if (!bus_free) {
bus_free_timeout = jiffies +
OMAP_I2C_BUS_FREE_TIMEOUT;
- bus_free = 1;
+ bus_free = true;
}
/*
@@ -569,7 +569,7 @@ static int omap_i2c_wait_for_bb_valid(struct omap_i2c_dev *omap)
if (time_after(jiffies, bus_free_timeout))
break;
} else {
- bus_free = 0;
+ bus_free = false;
}
if (time_after(jiffies, timeout)) {
@@ -585,7 +585,7 @@ static int omap_i2c_wait_for_bb_valid(struct omap_i2c_dev *omap)
msleep(1);
}
- omap->bb_valid = 1;
+ omap->bb_valid = true;
return 0;
}
@@ -620,7 +620,7 @@ static void omap_i2c_resize_fifo(struct omap_i2c_dev *omap, u8 size, bool is_rx)
omap_i2c_write_reg(omap, OMAP_I2C_BUF_REG, buf);
if (omap->rev < OMAP_I2C_REV_ON_3630)
- omap->b_hw = 1; /* Enable hardware fixes */
+ omap->b_hw = true; /* Enable hardware fixes */
/* calculate wakeup latency constraint for MPU */
if (omap->set_mpu_wkup_lat != NULL)
@@ -644,7 +644,7 @@ static void omap_i2c_wait(struct omap_i2c_dev *omap)
* Low level master read/write transaction.
*/
static int omap_i2c_xfer_msg(struct i2c_adapter *adap,
- struct i2c_msg *msg, int stop, bool polling)
+ struct i2c_msg *msg, bool stop, bool polling)
{
struct omap_i2c_dev *omap = i2c_get_adapdata(adap);
unsigned long time_left;
@@ -684,7 +684,7 @@ static int omap_i2c_xfer_msg(struct i2c_adapter *adap,
w |= OMAP_I2C_CON_OPMODE_HS;
if (msg->flags & I2C_M_STOP)
- stop = 1;
+ stop = true;
if (msg->flags & I2C_M_TEN)
w |= OMAP_I2C_CON_XA;
if (!(msg->flags & I2C_M_RD))
@@ -1423,7 +1423,7 @@ omap_i2c_probe(struct platform_device *pdev)
omap->fifo_size = (omap->fifo_size / 2);
if (omap->rev < OMAP_I2C_REV_ON_3630)
- omap->b_hw = 1; /* Enable hardware fixes */
+ omap->b_hw = true; /* Enable hardware fixes */
/* calculate wakeup latency constraint for MPU */
if (omap->set_mpu_wkup_lat != NULL)
--
2.39.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 6/8] i2c: omap: Make reset bit name match register name
2026-09-04 13:12 [PATCH 0/8] OMAP I2C driver cleanups Andrew Davis
` (4 preceding siblings ...)
2026-09-04 13:12 ` [PATCH 5/8] i2c: omap: Use bool for flag values Andrew Davis
@ 2026-09-04 13:12 ` Andrew Davis
2026-09-04 13:12 ` [PATCH 7/8] i2c: omap: Switch to using BIT and GENMASK Andrew Davis
2026-09-04 13:12 ` [PATCH 8/8] i2c: omap: Add OMAP_I2C_BUF_{TX,RX}TRSH definitions Andrew Davis
7 siblings, 0 replies; 9+ messages in thread
From: Andrew Davis @ 2026-09-04 13:12 UTC (permalink / raw)
To: Tony Lindgren, Vignesh R, Andreas Kemnade, Kevin Hilman,
Roger Quadros, Andi Shyti
Cc: linux-omap, linux-arm-kernel, linux-i2c, linux-kernel,
Andrew Davis
The bit definitions usually match the register name definition to make
matching bits to registers more clear. Do this for the bits inside
OMAP_I2C_SYSS_REG and OMAP_I2C_SYSC_REG registers. Remove unused bits.
Signed-off-by: Andrew Davis <afd@ti.com>
---
drivers/i2c/busses/i2c-omap.c | 15 ++++-----------
1 file changed, 4 insertions(+), 11 deletions(-)
diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
index dc75780f76c96..a50cf195c28cf 100644
--- a/drivers/i2c/busses/i2c-omap.c
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -133,17 +133,10 @@ enum {
#define OMAP_I2C_SYSTEST_SDA_O (1 << 0) /* SDA line drive out */
/* OCP_SYSSTATUS bit definitions */
-#define SYSS_RESETDONE_MASK (1 << 0)
+#define OMAP_I2C_SYSS_RESETDONE (1 << 0)
/* OCP_SYSCONFIG bit definitions */
-#define SYSC_CLOCKACTIVITY_MASK (0x3 << 8)
-#define SYSC_SIDLEMODE_MASK (0x3 << 3)
-#define SYSC_ENAWAKEUP_MASK (1 << 2)
-#define SYSC_SOFTRESET_MASK (1 << 1)
-#define SYSC_AUTOIDLE_MASK (1 << 0)
-
-#define SYSC_IDLEMODE_SMART 0x2
-#define SYSC_CLOCKACTIVITY_FCLK 0x2
+#define OMAP_I2C_SYSC_SOFTRESET (1 << 1)
/* Errata definitions */
#define I2C_OMAP_ERRATA_I207 (1 << 0)
@@ -293,13 +286,13 @@ static int omap_i2c_reset(struct omap_i2c_dev *omap)
omap_i2c_read_reg(omap, OMAP_I2C_CON_REG) &
~(OMAP_I2C_CON_EN));
- omap_i2c_write_reg(omap, OMAP_I2C_SYSC_REG, SYSC_SOFTRESET_MASK);
+ omap_i2c_write_reg(omap, OMAP_I2C_SYSC_REG, OMAP_I2C_SYSC_SOFTRESET);
/* For some reason we need to set the EN bit before the
* reset done bit gets set. */
timeout = jiffies + OMAP_I2C_TIMEOUT;
omap_i2c_write_reg(omap, OMAP_I2C_CON_REG, OMAP_I2C_CON_EN);
while (!(omap_i2c_read_reg(omap, OMAP_I2C_SYSS_REG) &
- SYSS_RESETDONE_MASK)) {
+ OMAP_I2C_SYSS_RESETDONE)) {
if (time_after(jiffies, timeout)) {
dev_warn(omap->dev, "timeout waiting "
"for controller reset\n");
--
2.39.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 7/8] i2c: omap: Switch to using BIT and GENMASK
2026-09-04 13:12 [PATCH 0/8] OMAP I2C driver cleanups Andrew Davis
` (5 preceding siblings ...)
2026-09-04 13:12 ` [PATCH 6/8] i2c: omap: Make reset bit name match register name Andrew Davis
@ 2026-09-04 13:12 ` Andrew Davis
2026-09-04 13:12 ` [PATCH 8/8] i2c: omap: Add OMAP_I2C_BUF_{TX,RX}TRSH definitions Andrew Davis
7 siblings, 0 replies; 9+ messages in thread
From: Andrew Davis @ 2026-09-04 13:12 UTC (permalink / raw)
To: Tony Lindgren, Vignesh R, Andreas Kemnade, Kevin Hilman,
Roger Quadros, Andi Shyti
Cc: linux-omap, linux-arm-kernel, linux-i2c, linux-kernel,
Andrew Davis
We have helpers for setting bit values and masks. Use them.
Signed-off-by: Andrew Davis <afd@ti.com>
---
drivers/i2c/busses/i2c-omap.c | 82 +++++++++++++++++------------------
1 file changed, 41 insertions(+), 41 deletions(-)
diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
index a50cf195c28cf..41464f92da046 100644
--- a/drivers/i2c/busses/i2c-omap.c
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -79,64 +79,64 @@ enum {
};
/* I2C Status bits (OMAP_I2C_IE, OMAP_I2C_STAT, OMAP_I2C_WE) */
-#define OMAP_I2C_STAT_XDR (1 << 14) /* TX Buffer draining */
-#define OMAP_I2C_STAT_RDR (1 << 13) /* RX Buffer draining */
-#define OMAP_I2C_STAT_BB (1 << 12) /* Bus busy */
-#define OMAP_I2C_STAT_ROVR (1 << 11) /* Receive overrun */
-#define OMAP_I2C_STAT_XUDF (1 << 10) /* Transmit underflow */
-#define OMAP_I2C_STAT_AAS (1 << 9) /* Address as slave */
-#define OMAP_I2C_STAT_BF (1 << 8) /* Bus Free */
-#define OMAP_I2C_STAT_STC (1 << 6) /* Start condition */
-#define OMAP_I2C_STAT_GC (1 << 5) /* General call */
-#define OMAP_I2C_STAT_XRDY (1 << 4) /* Transmit data ready */
-#define OMAP_I2C_STAT_RRDY (1 << 3) /* Receive data ready */
-#define OMAP_I2C_STAT_ARDY (1 << 2) /* Register access ready */
-#define OMAP_I2C_STAT_NACK (1 << 1) /* No ack */
-#define OMAP_I2C_STAT_AL (1 << 0) /* Arbitration lost */
+#define OMAP_I2C_STAT_XDR BIT(14) /* TX Buffer draining */
+#define OMAP_I2C_STAT_RDR BIT(13) /* RX Buffer draining */
+#define OMAP_I2C_STAT_BB BIT(12) /* Bus busy */
+#define OMAP_I2C_STAT_ROVR BIT(11) /* Receive overrun */
+#define OMAP_I2C_STAT_XUDF BIT(10) /* Transmit underflow */
+#define OMAP_I2C_STAT_AAS BIT(9) /* Address as slave */
+#define OMAP_I2C_STAT_BF BIT(8) /* Bus Free */
+#define OMAP_I2C_STAT_STC BIT(6) /* Start condition */
+#define OMAP_I2C_STAT_GC BIT(5) /* General call */
+#define OMAP_I2C_STAT_XRDY BIT(4) /* Transmit data ready */
+#define OMAP_I2C_STAT_RRDY BIT(3) /* Receive data ready */
+#define OMAP_I2C_STAT_ARDY BIT(2) /* Register access ready */
+#define OMAP_I2C_STAT_NACK BIT(1) /* No ack */
+#define OMAP_I2C_STAT_AL BIT(0) /* Arbitration lost */
/* I2C Buffer Configuration Register (OMAP_I2C_BUF): */
-#define OMAP_I2C_BUF_RDMA_EN (1 << 15) /* RX DMA channel enable */
-#define OMAP_I2C_BUF_RXFIF_CLR (1 << 14) /* RX FIFO Clear */
-#define OMAP_I2C_BUF_XDMA_EN (1 << 7) /* TX DMA channel enable */
-#define OMAP_I2C_BUF_TXFIF_CLR (1 << 6) /* TX FIFO Clear */
+#define OMAP_I2C_BUF_RDMA_EN BIT(15) /* RX DMA channel enable */
+#define OMAP_I2C_BUF_RXFIF_CLR BIT(14) /* RX FIFO Clear */
+#define OMAP_I2C_BUF_XDMA_EN BIT(7) /* TX DMA channel enable */
+#define OMAP_I2C_BUF_TXFIF_CLR BIT(6) /* TX FIFO Clear */
/* I2C Configuration Register (OMAP_I2C_CON): */
-#define OMAP_I2C_CON_EN (1 << 15) /* I2C module enable */
-#define OMAP_I2C_CON_BE (1 << 14) /* Big endian mode */
-#define OMAP_I2C_CON_OPMODE_HS (1 << 12) /* High Speed support */
-#define OMAP_I2C_CON_STB (1 << 11) /* Start byte mode (master) */
-#define OMAP_I2C_CON_MST (1 << 10) /* Master/slave mode */
-#define OMAP_I2C_CON_TRX (1 << 9) /* TX/RX mode (master only) */
-#define OMAP_I2C_CON_XA (1 << 8) /* Expand address */
-#define OMAP_I2C_CON_RM (1 << 2) /* Repeat mode (master only) */
-#define OMAP_I2C_CON_STP (1 << 1) /* Stop cond (master only) */
-#define OMAP_I2C_CON_STT (1 << 0) /* Start condition (master) */
+#define OMAP_I2C_CON_EN BIT(15) /* I2C module enable */
+#define OMAP_I2C_CON_BE BIT(14) /* Big endian mode */
+#define OMAP_I2C_CON_OPMODE_HS BIT(12) /* High Speed support */
+#define OMAP_I2C_CON_STB BIT(11) /* Start byte mode (master) */
+#define OMAP_I2C_CON_MST BIT(10) /* Master/slave mode */
+#define OMAP_I2C_CON_TRX BIT(9) /* TX/RX mode (master only) */
+#define OMAP_I2C_CON_XA BIT(8) /* Expand address */
+#define OMAP_I2C_CON_RM BIT(2) /* Repeat mode (master only) */
+#define OMAP_I2C_CON_STP BIT(1) /* Stop cond (master only) */
+#define OMAP_I2C_CON_STT BIT(0) /* Start condition (master) */
/* I2C SCL time value when Master */
#define OMAP_I2C_SCLL_HSSCLL 8
#define OMAP_I2C_SCLH_HSSCLH 8
/* I2C System Test Register (OMAP_I2C_SYSTEST): */
-#define OMAP_I2C_SYSTEST_ST_EN (1 << 15) /* System test enable */
-#define OMAP_I2C_SYSTEST_FREE (1 << 14) /* Free running mode */
-#define OMAP_I2C_SYSTEST_TMODE_MASK (3 << 12) /* Test mode select */
+#define OMAP_I2C_SYSTEST_ST_EN BIT(15) /* System test enable */
+#define OMAP_I2C_SYSTEST_FREE BIT(14) /* Free running mode */
+#define OMAP_I2C_SYSTEST_TMODE_MASK GENMASK(13, 12) /* Test mode select */
#define OMAP_I2C_SYSTEST_TMODE_SHIFT (12) /* Test mode select */
/* Functional mode */
-#define OMAP_I2C_SYSTEST_SCL_I_FUNC (1 << 8) /* SCL line input value */
-#define OMAP_I2C_SYSTEST_SCL_O_FUNC (1 << 7) /* SCL line output value */
-#define OMAP_I2C_SYSTEST_SDA_I_FUNC (1 << 6) /* SDA line input value */
-#define OMAP_I2C_SYSTEST_SDA_O_FUNC (1 << 5) /* SDA line output value */
+#define OMAP_I2C_SYSTEST_SCL_I_FUNC BIT(8) /* SCL line input value */
+#define OMAP_I2C_SYSTEST_SCL_O_FUNC BIT(7) /* SCL line output value */
+#define OMAP_I2C_SYSTEST_SDA_I_FUNC BIT(6) /* SDA line input value */
+#define OMAP_I2C_SYSTEST_SDA_O_FUNC BIT(5) /* SDA line output value */
/* SDA/SCL IO mode */
-#define OMAP_I2C_SYSTEST_SCL_I (1 << 3) /* SCL line sense in */
-#define OMAP_I2C_SYSTEST_SCL_O (1 << 2) /* SCL line drive out */
-#define OMAP_I2C_SYSTEST_SDA_I (1 << 1) /* SDA line sense in */
-#define OMAP_I2C_SYSTEST_SDA_O (1 << 0) /* SDA line drive out */
+#define OMAP_I2C_SYSTEST_SCL_I BIT(3) /* SCL line sense in */
+#define OMAP_I2C_SYSTEST_SCL_O BIT(2) /* SCL line drive out */
+#define OMAP_I2C_SYSTEST_SDA_I BIT(1) /* SDA line sense in */
+#define OMAP_I2C_SYSTEST_SDA_O BIT(0) /* SDA line drive out */
/* OCP_SYSSTATUS bit definitions */
-#define OMAP_I2C_SYSS_RESETDONE (1 << 0)
+#define OMAP_I2C_SYSS_RESETDONE BIT(0)
/* OCP_SYSCONFIG bit definitions */
-#define OMAP_I2C_SYSC_SOFTRESET (1 << 1)
+#define OMAP_I2C_SYSC_SOFTRESET BIT(1)
/* Errata definitions */
#define I2C_OMAP_ERRATA_I207 (1 << 0)
--
2.39.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 8/8] i2c: omap: Add OMAP_I2C_BUF_{TX,RX}TRSH definitions
2026-09-04 13:12 [PATCH 0/8] OMAP I2C driver cleanups Andrew Davis
` (6 preceding siblings ...)
2026-09-04 13:12 ` [PATCH 7/8] i2c: omap: Switch to using BIT and GENMASK Andrew Davis
@ 2026-09-04 13:12 ` Andrew Davis
7 siblings, 0 replies; 9+ messages in thread
From: Andrew Davis @ 2026-09-04 13:12 UTC (permalink / raw)
To: Tony Lindgren, Vignesh R, Andreas Kemnade, Kevin Hilman,
Roger Quadros, Andi Shyti
Cc: linux-omap, linux-arm-kernel, linux-i2c, linux-kernel,
Andrew Davis
These were just magic numbers before, give them proper definitions
and use those in code.
Signed-off-by: Andrew Davis <afd@ti.com>
---
drivers/i2c/busses/i2c-omap.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
index 41464f92da046..669d931928fb6 100644
--- a/drivers/i2c/busses/i2c-omap.c
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -97,8 +97,10 @@ enum {
/* I2C Buffer Configuration Register (OMAP_I2C_BUF): */
#define OMAP_I2C_BUF_RDMA_EN BIT(15) /* RX DMA channel enable */
#define OMAP_I2C_BUF_RXFIF_CLR BIT(14) /* RX FIFO Clear */
+#define OMAP_I2C_BUF_RXTRSH GENMASK(13, 8) /* RX FIFO Threshold */
#define OMAP_I2C_BUF_XDMA_EN BIT(7) /* TX DMA channel enable */
#define OMAP_I2C_BUF_TXFIF_CLR BIT(6) /* TX FIFO Clear */
+#define OMAP_I2C_BUF_TXTRSH GENMASK(5, 0) /* TX FIFO Threshold */
/* I2C Configuration Register (OMAP_I2C_CON): */
#define OMAP_I2C_CON_EN BIT(15) /* I2C module enable */
@@ -602,12 +604,14 @@ static void omap_i2c_resize_fifo(struct omap_i2c_dev *omap, u8 size, bool is_rx)
if (is_rx) {
/* Clear RX Threshold */
- buf &= ~(0x3f << 8);
- buf |= ((omap->threshold - 1) << 8) | OMAP_I2C_BUF_RXFIF_CLR;
+ buf &= ~OMAP_I2C_BUF_RXTRSH;
+ buf |= FIELD_PREP(OMAP_I2C_BUF_RXTRSH, (omap->threshold - 1));
+ buf |= OMAP_I2C_BUF_RXFIF_CLR;
} else {
/* Clear TX Threshold */
- buf &= ~0x3f;
- buf |= (omap->threshold - 1) | OMAP_I2C_BUF_TXFIF_CLR;
+ buf &= ~OMAP_I2C_BUF_TXTRSH;
+ buf |= FIELD_PREP(OMAP_I2C_BUF_TXTRSH, (omap->threshold - 1));
+ buf |= OMAP_I2C_BUF_TXFIF_CLR;
}
omap_i2c_write_reg(omap, OMAP_I2C_BUF_REG, buf);
--
2.39.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-09-04 13:13 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-04 13:12 [PATCH 0/8] OMAP I2C driver cleanups Andrew Davis
2026-09-04 13:12 ` [PATCH 1/8] i2c: omap: Drop bit shift for I2C register addresses Andrew Davis
2026-09-04 13:12 ` [PATCH 2/8] i2c: omap: Remove unused is_rdr and is_xdr variables Andrew Davis
2026-09-04 13:12 ` [PATCH 3/8] i2c: omap: Use devm_pm_runtime_enable() helper Andrew Davis
2026-09-04 13:12 ` [PATCH 4/8] i2c: omap: Combine event flags register definitions Andrew Davis
2026-09-04 13:12 ` [PATCH 5/8] i2c: omap: Use bool for flag values Andrew Davis
2026-09-04 13:12 ` [PATCH 6/8] i2c: omap: Make reset bit name match register name Andrew Davis
2026-09-04 13:12 ` [PATCH 7/8] i2c: omap: Switch to using BIT and GENMASK Andrew Davis
2026-09-04 13:12 ` [PATCH 8/8] i2c: omap: Add OMAP_I2C_BUF_{TX,RX}TRSH definitions Andrew Davis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox