units: Add SI metric prefix definitions
Subsystems (3)
Andy Shevchenko
reviewerPATCH v3 1/3 units: Add SI metric prefix definitions
Sometimes it's useful to have well-defined SI metric prefix to be used to self-describe the formulas or equations.
List most popular ones in the units.h.
---
v3: converted to be unsigned values (Joe)
include/linux/units.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
include/linux/units.h +16 -0
@@ -4,6 +4,22 @@#include <linux/math.h> +/* Metric prefixes in accordance with Système international (d'unités) */ +#define PETA 1000000000000000ULL +#define TERA 1000000000000ULL +#define GIGA 1000000000UL +#define MEGA 1000000UL +#define KILO 1000UL +#define HECTO 100UL +#define DECA 10UL +#define DECI 10UL +#define CENTI 100UL +#define MILLI 1000UL +#define MICRO 1000000UL +#define NANO 1000000000UL +#define PICO 1000000000000ULL +#define FEMTO 1000000000000000ULL +#define MILLIWATT_PER_WATT 1000L#define MICROWATT_PER_MILLIWATT 1000L#define MICROWATT_PER_WATT 1000000L
Signature · 1 line
2.30.2
Andy Shevchenko
reviewerPATCH v3 2/3 i2c: designware: Use DIV_ROUND_CLOSEST() macro
Instead of open-coding DIV_ROUND_CLOSEST() and similar use the macros directly. While at it, replace numbers with predefined SI metric prefixes.
No functional change intended.
---
v3: no changes
drivers/i2c/busses/i2c-designware-common.c | 8 ++++---- drivers/i2c/busses/i2c-designware-platdrv.c | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-)
drivers/i2c/busses/i2c-designware-common.c +4 -4
@@ -24,6 +24,7 @@#include <linux/regmap.h> #include <linux/swab.h> #include <linux/types.h> +#include <linux/units.h> #include "i2c-designware-core.h"
@@ -350,7 +351,7 @@ u32 i2c_dw_scl_hcnt(u32 ic_clk, u32 tSYMBOL, u32 tf, int cond, int offset)* * If your hardware is free from tHD;STA issue, try this one. */ -return (ic_clk * tSYMBOL +500000 ) /1000000 -8 + offset; +return DIV_ROUND_CLOSEST (ic_clk * tSYMBOL,MICRO ) -8 + offset; else/* * Conditional expression:
@@ -366,8 +367,7 @@ u32 i2c_dw_scl_hcnt(u32 ic_clk, u32 tSYMBOL, u32 tf, int cond, int offset)* The reason why we need to take into account "tf" here, * is the same as described in i2c_dw_scl_lcnt(). */ -return (ic_clk * (tSYMBOL + tf) +500000 ) /1000000 - -3 + offset; +return DIV_ROUND_CLOSEST (ic_clk * (tSYMBOL + tf),MICRO ) -3 + offset; }u32 i2c_dw_scl_lcnt (u32 ic_clk,u32 tLOW,u32 tf,int offset)
@@ -383,7 +383,7 @@ u32 i2c_dw_scl_lcnt(u32 ic_clk, u32 tLOW, u32 tf, int offset)* account the fall time of SCL signal (tf). Default tf value * should be 0.3 us, for safety. */ -return ((ic_clk * (tLOW + tf) +500000 ) /1000000 ) -1 + offset; +return DIV_ROUND_CLOSEST (ic_clk * (tLOW + tf),MICRO ) -1 + offset; }int i2c_dw_set_sda_hold (struct dw_i2c_dev *dev)
drivers/i2c/busses/i2c-designware-platdrv.c +3 -2
@@ -31,12 +31,13 @@#include <linux/sched.h> #include <linux/slab.h> #include <linux/suspend.h> +#include <linux/units.h> #include "i2c-designware-core.h" static u32 i2c_dw_get_clk_rate_khz (struct dw_i2c_dev *dev) { -return clk_get_rate (dev->clk)/1000 ; +return clk_get_rate (dev->clk) /KILO ; }#ifdef CONFIG_ACPI
@@ -270,7 +271,7 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)if (!dev->sda_hold_time && t->sda_hold_ns) dev->sda_hold_time = -div_u64 (clk_khz * t->sda_hold_ns +500000 ,1000000 ); +DIV_S64_ROUND_CLOSEST (clk_khz * t->sda_hold_ns,MICRO ); } adap = &dev->adapter;
Signature · 1 line
2.30.2
Wolfram Sang
AppliedRe: [PATCH v3 2/3] i2c: designware: Use DIV_ROUND_CLOSEST() macro
Quoted 6 lines · Andy Shevchenko
Instead of open-coding
DIV_ROUND_CLOSEST()and similar use the macros directly. While at it, replace numbers with predefined SI metric prefixes.No functional change intended.
Signed-off-by Andy Shevchenko <[email protected]>
Applied to for-next, thanks!
Andy Shevchenko
reviewerPATCH v3 3/3 i2c: designware: Fix indentation in the header
In reply to Andy ShevchenkoIn couple of places the indentation makes harder to read the code. Fix it to be sane.
---
v3: no changes
drivers/i2c/busses/i2c-designware-core.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-designware-core.h +2 -2
@@ -117,7 +117,7 @@#define DW_IC_ERR_TX_ABRT 0x1 -#define DW_IC_TAR_10BITADDR_MASTER BIT(12) +#define DW_IC_TAR_10BITADDR_MASTER BIT(12)#define DW_IC_COMP_PARAM_1_SPEED_MODE_HIGH (BIT(2) | BIT(3))#define DW_IC_COMP_PARAM_1_SPEED_MODE_MASK GENMASK(3, 2)
@@ -245,7 +245,7 @@ struct dw_i2c_dev {struct clk *clk;struct clk *pclk;struct reset_control *rst; -struct i2c_client *slave; +struct i2c_client *slave;u32 (*get_clk_rate_khz) (struct dw_i2c_dev *dev);int cmd_err;struct i2c_msg *msgs;
Signature · 1 line
2.30.2
Wolfram Sang
AppliedRe: [PATCH v3 3/3] i2c: designware: Fix indentation in the header
Quoted 4 lines · Andy Shevchenko
In couple of places the indentation makes harder to read the code. Fix it to be sane.
Signed-off-by Andy Shevchenko <[email protected]>
Applied to for-next, thanks!
Andy Shevchenko
reviewerQuoted 4 lines · Andy Shevchenko
Sometimes it's useful to have well-defined SI metric prefix to be used to self-describe the formulas or equations.
List most popular ones in the
units.h.
Wolfram, can we have this applied or commented? It seems we are going to have more users of these definitions (I have recently reviewed one of IIO driver where two of them are in use).
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 9 lines · Andy Shevchenko
Quoted 4 lines · Andy Shevchenko
Sometimes it's useful to have well-defined SI metric prefix to be used to self-describe the formulas or equations.
List most popular ones in the
units.h.Wolfram, can we have this applied or commented? It seems we are going to have more users of these definitions (I have recently reviewed one of IIO driver where two of them are in use).
Okay, seems there won't be one to ack the units.h changes. Doesn't really matter, I think. Will apply now.
Wolfram Sang
AppliedQuoted 6 lines · Andy Shevchenko
Sometimes it's useful to have well-defined SI metric prefix to be used to self-describe the formulas or equations.
List most popular ones in the
units.h.Signed-off-by Andy Shevchenko <[email protected]>
Applied to for-next, thanks!