Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <andreas@kemnade.info>
Acked-by: Matti Vaittinen <mazziesaccount@gmail.com>
Link: https://lore.kernel.org/r/20240402111700.494004-3-andreas@kemnade.info
Signed-off-by: Lee Jones <lee@kernel.org>

authored by

Andreas Kemnade and committed by
Lee Jones
5549eeed 714ae2ab

+38 -1
+35 -1
drivers/mfd/rohm-bd71828.c
··· 464 464 OUT32K_MODE_CMOS); 465 465 } 466 466 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 + 467 488 static int bd71828_i2c_probe(struct i2c_client *i2c) 468 489 { 469 490 struct regmap_irq_chip_data *irq_data; ··· 563 542 ret = devm_mfd_add_devices(&i2c->dev, PLATFORM_DEVID_AUTO, mfd, cells, 564 543 NULL, 0, regmap_irq_get_domain(irq_data)); 565 544 if (ret) 566 - dev_err_probe(&i2c->dev, ret, "Failed to create subdevices\n"); 545 + return dev_err_probe(&i2c->dev, ret, "Failed to create subdevices\n"); 546 + 547 + if (of_device_is_system_power_controller(i2c->dev.of_node) && 548 + chip_type == ROHM_CHIP_TYPE_BD71828) { 549 + if (!pm_power_off) { 550 + bd71828_dev = i2c; 551 + pm_power_off = bd71828_power_off; 552 + ret = devm_add_action_or_reset(&i2c->dev, 553 + bd71828_remove_poweroff, 554 + NULL); 555 + } else { 556 + dev_warn(&i2c->dev, "Poweroff callback already assigned\n"); 557 + } 558 + } 567 559 568 560 return ret; 569 561 }
+3
include/linux/mfd/rohm-bd71828.h
··· 4 4 #ifndef __LINUX_MFD_BD71828_H__ 5 5 #define __LINUX_MFD_BD71828_H__ 6 6 7 + #include <linux/bits.h> 7 8 #include <linux/mfd/rohm-generic.h> 8 9 #include <linux/mfd/rohm-shared.h> 9 10 ··· 41 40 #define BD71828_REG_PS_CTRL_1 0x04 42 41 #define BD71828_REG_PS_CTRL_2 0x05 43 42 #define BD71828_REG_PS_CTRL_3 0x06 43 + 44 + #define BD71828_MASK_STATE_HBNT BIT(1) 44 45 45 46 //#define BD71828_REG_SWRESET 0x06 46 47 #define BD71828_MASK_RUN_LVL_CTRL 0x30