Commit 12ca3b20 authored by Mauro Carvalho Chehab's avatar Mauro Carvalho Chehab Committed by Greg Kroah-Hartman

staging: regulator: hi6421v600-regulator: port it to upstream

The driver was originally written for Kernel 4.9. It needs to
be ported to upstream:

	- Got rid of timeval;
	- Removed a bogus dependency;
	- Did cleanups at the header file.
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Link: https://lore.kernel.org/r/9e34400d2cc15ef501a8478f69a95c9abc5c4d8d.1597647359.git.mchehab+huawei@kernel.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 0e0473c8
...@@ -49,7 +49,6 @@ struct hisi_regulator_register_info { ...@@ -49,7 +49,6 @@ struct hisi_regulator_register_info {
struct hisi_regulator { struct hisi_regulator {
const char *name; const char *name;
struct hisi_regulator_register_info register_info; struct hisi_regulator_register_info register_info;
struct timeval last_off_time;
u32 off_on_delay; u32 off_on_delay;
u32 eco_uA; u32 eco_uA;
struct regulator_desc rdesc; struct regulator_desc rdesc;
...@@ -57,8 +56,6 @@ struct hisi_regulator { ...@@ -57,8 +56,6 @@ struct hisi_regulator {
}; };
static DEFINE_MUTEX(enable_mutex); static DEFINE_MUTEX(enable_mutex);
struct timeval last_enabled;
static inline struct hisi_pmic *rdev_to_pmic(struct regulator_dev *dev) static inline struct hisi_pmic *rdev_to_pmic(struct regulator_dev *dev)
{ {
...@@ -72,27 +69,6 @@ static inline struct hisi_pmic *rdev_to_pmic(struct regulator_dev *dev) ...@@ -72,27 +69,6 @@ static inline struct hisi_pmic *rdev_to_pmic(struct regulator_dev *dev)
/* helper function to ensure when it returns it is at least 'delay_us' /* helper function to ensure when it returns it is at least 'delay_us'
* microseconds after 'since'. * microseconds after 'since'.
*/ */
static void ensured_time_after(struct timeval since, u32 delay_us)
{
struct timeval now;
u64 elapsed_ns64, delay_ns64;
u32 actual_us32;
delay_ns64 = delay_us * NSEC_PER_USEC;
do_gettimeofday(&now);
elapsed_ns64 = timeval_to_ns(&now) - timeval_to_ns(&since);
if (delay_ns64 > elapsed_ns64) {
actual_us32 = ((u32)(delay_ns64 - elapsed_ns64) /
NSEC_PER_USEC);
if (actual_us32 >= 1000) {
mdelay(actual_us32 / 1000); /*lint !e647 */
udelay(actual_us32 % 1000);
} else if (actual_us32 > 0) {
udelay(actual_us32);
}
}
return;
}
static int hisi_regulator_is_enabled(struct regulator_dev *dev) static int hisi_regulator_is_enabled(struct regulator_dev *dev)
{ {
...@@ -113,13 +89,16 @@ static int hisi_regulator_enable(struct regulator_dev *dev) ...@@ -113,13 +89,16 @@ static int hisi_regulator_enable(struct regulator_dev *dev)
struct hisi_pmic *pmic = rdev_to_pmic(dev); struct hisi_pmic *pmic = rdev_to_pmic(dev);
/* keep a distance of off_on_delay from last time disabled */ /* keep a distance of off_on_delay from last time disabled */
ensured_time_after(sreg->last_off_time, sreg->off_on_delay); usleep_range(sreg->off_on_delay, sreg->off_on_delay + 1000);
pr_debug("<[%s]: off_on_delay=%dus>\n", __func__, sreg->off_on_delay); pr_debug("<[%s]: off_on_delay=%dus>\n", __func__, sreg->off_on_delay);
/* cannot enable more than one regulator at one time */ /* cannot enable more than one regulator at one time */
mutex_lock(&enable_mutex); mutex_lock(&enable_mutex);
ensured_time_after(last_enabled, HISI_REGS_ENA_PROTECT_TIME); usleep_range(HISI_REGS_ENA_PROTECT_TIME,
HISI_REGS_ENA_PROTECT_TIME + 1000);
/* set enable register */ /* set enable register */
hisi_pmic_rmw(pmic, sreg->register_info.ctrl_reg, hisi_pmic_rmw(pmic, sreg->register_info.ctrl_reg,
...@@ -128,7 +107,6 @@ static int hisi_regulator_enable(struct regulator_dev *dev) ...@@ -128,7 +107,6 @@ static int hisi_regulator_enable(struct regulator_dev *dev)
pr_debug("<[%s]: ctrl_reg=0x%x,enable_mask=0x%x>\n", __func__, sreg->register_info.ctrl_reg,\ pr_debug("<[%s]: ctrl_reg=0x%x,enable_mask=0x%x>\n", __func__, sreg->register_info.ctrl_reg,\
sreg->register_info.enable_mask); sreg->register_info.enable_mask);
do_gettimeofday(&last_enabled);
mutex_unlock(&enable_mutex); mutex_unlock(&enable_mutex);
return 0; return 0;
...@@ -143,8 +121,6 @@ static int hisi_regulator_disable(struct regulator_dev *dev) ...@@ -143,8 +121,6 @@ static int hisi_regulator_disable(struct regulator_dev *dev)
hisi_pmic_rmw(pmic, sreg->register_info.ctrl_reg, hisi_pmic_rmw(pmic, sreg->register_info.ctrl_reg,
sreg->register_info.enable_mask, 0); sreg->register_info.enable_mask, 0);
do_gettimeofday(&sreg->last_off_time);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment