mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-01-09 06:43:09 +00:00
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: Mauro Carvalho Chehab <mchehab+huawei@kernel.org> Link: https://lore.kernel.org/r/9e34400d2cc15ef501a8478f69a95c9abc5c4d8d.1597647359.git.mchehab+huawei@kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
0e0473c838
commit
12ca3b20db
@ -49,7 +49,6 @@ struct hisi_regulator_register_info {
|
||||
struct hisi_regulator {
|
||||
const char *name;
|
||||
struct hisi_regulator_register_info register_info;
|
||||
struct timeval last_off_time;
|
||||
u32 off_on_delay;
|
||||
u32 eco_uA;
|
||||
struct regulator_desc rdesc;
|
||||
@ -57,8 +56,6 @@ struct hisi_regulator {
|
||||
};
|
||||
|
||||
static DEFINE_MUTEX(enable_mutex);
|
||||
struct timeval last_enabled;
|
||||
|
||||
|
||||
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'
|
||||
* 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)
|
||||
{
|
||||
@ -113,13 +89,16 @@ static int hisi_regulator_enable(struct regulator_dev *dev)
|
||||
struct hisi_pmic *pmic = rdev_to_pmic(dev);
|
||||
|
||||
/* 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);
|
||||
|
||||
/* cannot enable more than one regulator at one time */
|
||||
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 */
|
||||
hisi_pmic_rmw(pmic, sreg->register_info.ctrl_reg,
|
||||
@ -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,\
|
||||
sreg->register_info.enable_mask);
|
||||
|
||||
do_gettimeofday(&last_enabled);
|
||||
mutex_unlock(&enable_mutex);
|
||||
|
||||
return 0;
|
||||
@ -143,8 +121,6 @@ static int hisi_regulator_disable(struct regulator_dev *dev)
|
||||
hisi_pmic_rmw(pmic, sreg->register_info.ctrl_reg,
|
||||
sreg->register_info.enable_mask, 0);
|
||||
|
||||
do_gettimeofday(&sreg->last_off_time);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user