OMAP I2C driver cleanups
Subsystems (6)
RFC PATCH v3 7/8 i2c: omap: Switch to using BIT and GENMASK
In reply to Andrew DavisWe have helpers for setting bit values and masks. Use them.
--- drivers/i2c/busses/i2c-omap.c | 82 +++++++++++++++++------------------ 1 file changed, 41 insertions(+), 41 deletions(-)
drivers/i2c/busses/i2c-omap.c +41 -41
@@ -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)
Signature · 1 line
2.39.2
RFC PATCH v3 8/8 i2c: omap: Add OMAP_I2C_BUF_{TX,RX}TRSH definitions
In reply to Andrew DavisThese were just magic numbers before, give them proper definitions and use those in code.
--- drivers/i2c/busses/i2c-omap.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/i2c/busses/i2c-omap.c +9 -4
@@ -31,6 +31,7 @@#include <linux/pm_runtime.h> #include <linux/pinctrl/consumer.h> #include <linux/property.h> +#include <linux/bitfield.h> /* I2C controller revisions */ #define OMAP_I2C_OMAP1_REV_2 0x20
@@ -97,8 +98,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 +605,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);
Signature · 1 line
2.39.2
RFC PATCH v3 2/8 i2c: omap: Remove unused is_rdr and is_xdr variables
In reply to Andrew DavisThese are passed into omap_i2c_{receive,transmit}_data() but are never used, remove them.
--- drivers/i2c/busses/i2c-omap.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/i2c/busses/i2c-omap.c +6 -8
@@ -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 ;
Signature · 1 line
2.39.2
RFC PATCH v3 6/8 i2c: omap: Make reset bit name match register name
In reply to Andrew DavisThe 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.
--- drivers/i2c/busses/i2c-omap.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-)
drivers/i2c/busses/i2c-omap.c +4 -11
@@ -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" );
Signature · 1 line
2.39.2
RFC PATCH v3 1/8 i2c: omap: Drop bit shift for I2C register addresses
In reply to Andrew DavisThe OMAP7xx devices used a register address shift of 1, but this device has long since been removed from the kernel. So now 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.
--- 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(-)
arch/arm/mach-omap1/i2c.c +0 -4
@@ -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);
drivers/i2c/busses/i2c-omap.c +21 -29
92 lines not on this page · raw message
include/linux/platform_data/i2c-omap.h +0 -5
@@ -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 7struct omap_i2c_bus_platform_data {u32 clkrate;
Signature · 1 line
2.39.2
RFC PATCH v3 3/8 i2c: omap: Use devm_pm_runtime_enable() helper
In reply to Andrew DavisUse device life-cycle managed runtime enable function to simplify probe and exit paths. It will call pm_runtime_dont_use_autosuspend() for us.
--- drivers/i2c/busses/i2c-omap.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/i2c/busses/i2c-omap.c +2 -7
@@ -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)
Signature · 1 line
2.39.2
RFC PATCH v3 4/8 i2c: omap: Combine event flags register definitions
In reply to Andrew DavisThe 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.
--- drivers/i2c/busses/i2c-omap.c | 58 ++++++++++++++--------------------- 1 file changed, 23 insertions(+), 35 deletions(-)
drivers/i2c/busses/i2c-omap.c +23 -35
@@ -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;
Signature · 1 line
2.39.2
v3 cover OMAP I2C driver cleanups
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
Changes for v3:
- Fix OMAP_I2C_STAT_REG value in [1/8] (Sashiko)
- Add Acked-by tag
Changes for v2:
- Seems bitfield.h is not indirectly included for all archs, include it explicitly in patch [8/8]
- Add Reviewed-by tags
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 | 255 +++++++++++-------------- include/linux/platform_data/i2c-omap.h | 5 - 3 files changed, 113 insertions(+), 151 deletions(-)
Signature · 1 line
2.39.2
RFC PATCH v3 5/8 i2c: omap: Use bool for flag values
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.
--- drivers/i2c/busses/i2c-omap.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
drivers/i2c/busses/i2c-omap.c +13 -13
@@ -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 )
Signature · 1 line
2.39.2
Quoted 8 lines · 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
Just noticed this was sent with the wrong tag, not an RFC, let me know if this needs resent with just [PATCH v3] or if your tooling can handle it the same.
Andrew
Quoted 24 lines
Changes for v3:
- FixOMAP_I2C_STAT_REGvalue in [1/8] (Sashiko)
- Add Acked-by tagChanges for v2:
- Seemsbitfield.his not indirectly included for all archs, include it explicitly in patch [8/8]
- Add Reviewed-by tagsAndrew Davis (8):
i2c: omap: Drop bit shift for I2C register addresses
i2c: omap: Remove unusedis_rdrandis_xdrvariables
i2c: omap: Usedevm_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 definitionsarch/arm/mach-omap1/i2c.c | 4 - drivers/i2c/busses/i2c-omap.c | 255 +++++++++++-------------- include/linux/platform_data/i2c-omap.h | 5 - 3 files changed, 113 insertions(+), 151 deletions(-)