Skip to content

Commit 5549eee

Browse files
akemnadelag-linaro
authored andcommitted
mfd: rohm-bd71828: Add power off functionality
Since the chip can power off the system, add the corresponding functionality. Based on https://github.com/kobolabs/Kobo-Reader/raw/master/hw/imx6sll-clara2e/kernel.tar.bz2 Signed-off-by: Andreas Kemnade <[email protected]> Acked-by: Matti Vaittinen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Lee Jones <[email protected]>
1 parent 714ae2a commit 5549eee

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

drivers/mfd/rohm-bd71828.c

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,27 @@ static int set_clk_mode(struct device *dev, struct regmap *regmap,
464464
OUT32K_MODE_CMOS);
465465
}
466466

467+
static struct i2c_client *bd71828_dev;
468+
static void bd71828_power_off(void)
469+
{
470+
while (true) {
471+
s32 val;
472+
473+
/* We are not allowed to sleep, so do not use regmap involving mutexes here. */
474+
val = i2c_smbus_read_byte_data(bd71828_dev, BD71828_REG_PS_CTRL_1);
475+
if (val >= 0)
476+
i2c_smbus_write_byte_data(bd71828_dev,
477+
BD71828_REG_PS_CTRL_1,
478+
BD71828_MASK_STATE_HBNT | (u8)val);
479+
mdelay(500);
480+
}
481+
}
482+
483+
static void bd71828_remove_poweroff(void *data)
484+
{
485+
pm_power_off = NULL;
486+
}
487+
467488
static int bd71828_i2c_probe(struct i2c_client *i2c)
468489
{
469490
struct regmap_irq_chip_data *irq_data;
@@ -542,7 +563,20 @@ static int bd71828_i2c_probe(struct i2c_client *i2c)
542563
ret = devm_mfd_add_devices(&i2c->dev, PLATFORM_DEVID_AUTO, mfd, cells,
543564
NULL, 0, regmap_irq_get_domain(irq_data));
544565
if (ret)
545-
dev_err_probe(&i2c->dev, ret, "Failed to create subdevices\n");
566+
return dev_err_probe(&i2c->dev, ret, "Failed to create subdevices\n");
567+
568+
if (of_device_is_system_power_controller(i2c->dev.of_node) &&
569+
chip_type == ROHM_CHIP_TYPE_BD71828) {
570+
if (!pm_power_off) {
571+
bd71828_dev = i2c;
572+
pm_power_off = bd71828_power_off;
573+
ret = devm_add_action_or_reset(&i2c->dev,
574+
bd71828_remove_poweroff,
575+
NULL);
576+
} else {
577+
dev_warn(&i2c->dev, "Poweroff callback already assigned\n");
578+
}
579+
}
546580

547581
return ret;
548582
}

include/linux/mfd/rohm-bd71828.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#ifndef __LINUX_MFD_BD71828_H__
55
#define __LINUX_MFD_BD71828_H__
66

7+
#include <linux/bits.h>
78
#include <linux/mfd/rohm-generic.h>
89
#include <linux/mfd/rohm-shared.h>
910

@@ -41,6 +42,8 @@ enum {
4142
#define BD71828_REG_PS_CTRL_2 0x05
4243
#define BD71828_REG_PS_CTRL_3 0x06
4344

45+
#define BD71828_MASK_STATE_HBNT BIT(1)
46+
4447
//#define BD71828_REG_SWRESET 0x06
4548
#define BD71828_MASK_RUN_LVL_CTRL 0x30
4649

0 commit comments

Comments
 (0)