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: Add driver for Marvell 88PM886 PMIC

Marvell 88PM886 is a PMIC which provides various functions such as
onkey, battery, charger and regulators. It is found for instance in the
samsung,coreprimevelte smartphone with which this was tested. Implement
basic support to allow for the use of regulators and onkey.

Signed-off-by: Karel Balej <balejk@matfyz.cz>
Link: https://lore.kernel.org/r/20240531175109.15599-3-balejk@matfyz.cz
Signed-off-by: Lee Jones <lee@kernel.org>

authored by

Karel Balej and committed by
Lee Jones
860f8e3b c4725350

+230
+148
drivers/mfd/88pm886.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + #include <linux/i2c.h> 3 + #include <linux/mfd/core.h> 4 + #include <linux/module.h> 5 + #include <linux/notifier.h> 6 + #include <linux/of.h> 7 + #include <linux/platform_device.h> 8 + #include <linux/reboot.h> 9 + #include <linux/regmap.h> 10 + 11 + #include <linux/mfd/88pm886.h> 12 + 13 + static const struct regmap_config pm886_regmap_config = { 14 + .reg_bits = 8, 15 + .val_bits = 8, 16 + .max_register = PM886_REG_RTC_SPARE6, 17 + }; 18 + 19 + static struct regmap_irq pm886_regmap_irqs[] = { 20 + REGMAP_IRQ_REG(PM886_IRQ_ONKEY, 0, PM886_INT_ENA1_ONKEY), 21 + }; 22 + 23 + static struct regmap_irq_chip pm886_regmap_irq_chip = { 24 + .name = "88pm886", 25 + .irqs = pm886_regmap_irqs, 26 + .num_irqs = ARRAY_SIZE(pm886_regmap_irqs), 27 + .num_regs = 4, 28 + .status_base = PM886_REG_INT_STATUS1, 29 + .ack_base = PM886_REG_INT_STATUS1, 30 + .unmask_base = PM886_REG_INT_ENA_1, 31 + }; 32 + 33 + static struct resource pm886_onkey_resources[] = { 34 + DEFINE_RES_IRQ_NAMED(PM886_IRQ_ONKEY, "88pm886-onkey"), 35 + }; 36 + 37 + static struct mfd_cell pm886_devs[] = { 38 + MFD_CELL_RES("88pm886-onkey", pm886_onkey_resources), 39 + MFD_CELL_NAME("88pm886-regulator"), 40 + }; 41 + 42 + static int pm886_power_off_handler(struct sys_off_data *sys_off_data) 43 + { 44 + struct pm886_chip *chip = sys_off_data->cb_data; 45 + struct regmap *regmap = chip->regmap; 46 + struct device *dev = &chip->client->dev; 47 + int err; 48 + 49 + err = regmap_update_bits(regmap, PM886_REG_MISC_CONFIG1, PM886_SW_PDOWN, PM886_SW_PDOWN); 50 + if (err) { 51 + dev_err(dev, "Failed to power off the device: %d\n", err); 52 + return NOTIFY_BAD; 53 + } 54 + return NOTIFY_DONE; 55 + } 56 + 57 + static int pm886_setup_irq(struct pm886_chip *chip, 58 + struct regmap_irq_chip_data **irq_data) 59 + { 60 + struct regmap *regmap = chip->regmap; 61 + struct device *dev = &chip->client->dev; 62 + int err; 63 + 64 + /* Set interrupt clearing mode to clear on write. */ 65 + err = regmap_update_bits(regmap, PM886_REG_MISC_CONFIG2, 66 + PM886_INT_INV | PM886_INT_CLEAR | PM886_INT_MASK_MODE, 67 + PM886_INT_WC); 68 + if (err) { 69 + dev_err(dev, "Failed to set interrupt clearing mode: %d\n", err); 70 + return err; 71 + } 72 + 73 + err = devm_regmap_add_irq_chip(dev, regmap, chip->client->irq, 74 + IRQF_ONESHOT, 0, &pm886_regmap_irq_chip, 75 + irq_data); 76 + if (err) { 77 + dev_err(dev, "Failed to request IRQ: %d\n", err); 78 + return err; 79 + } 80 + 81 + return 0; 82 + } 83 + 84 + static int pm886_probe(struct i2c_client *client) 85 + { 86 + struct regmap_irq_chip_data *irq_data; 87 + struct device *dev = &client->dev; 88 + struct pm886_chip *chip; 89 + struct regmap *regmap; 90 + unsigned int chip_id; 91 + int err; 92 + 93 + chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); 94 + if (!chip) 95 + return -ENOMEM; 96 + 97 + chip->client = client; 98 + chip->chip_id = (uintptr_t)device_get_match_data(dev); 99 + i2c_set_clientdata(client, chip); 100 + 101 + regmap = devm_regmap_init_i2c(client, &pm886_regmap_config); 102 + if (IS_ERR(regmap)) 103 + return dev_err_probe(dev, PTR_ERR(regmap), "Failed to initialize regmap\n"); 104 + chip->regmap = regmap; 105 + 106 + err = regmap_read(regmap, PM886_REG_ID, &chip_id); 107 + if (err) 108 + return dev_err_probe(dev, err, "Failed to read chip ID\n"); 109 + 110 + if (chip->chip_id != chip_id) 111 + return dev_err_probe(dev, -EINVAL, "Unsupported chip: 0x%x\n", chip_id); 112 + 113 + err = pm886_setup_irq(chip, &irq_data); 114 + if (err) 115 + return err; 116 + 117 + err = devm_mfd_add_devices(dev, PLATFORM_DEVID_NONE, pm886_devs, ARRAY_SIZE(pm886_devs), 118 + NULL, 0, regmap_irq_get_domain(irq_data)); 119 + if (err) 120 + return dev_err_probe(dev, err, "Failed to add devices\n"); 121 + 122 + err = devm_register_power_off_handler(dev, pm886_power_off_handler, chip); 123 + if (err) 124 + return dev_err_probe(dev, err, "Failed to register power off handler\n"); 125 + 126 + device_init_wakeup(dev, device_property_read_bool(dev, "wakeup-source")); 127 + 128 + return 0; 129 + } 130 + 131 + static const struct of_device_id pm886_of_match[] = { 132 + { .compatible = "marvell,88pm886-a1", .data = (void *)PM886_A1_CHIP_ID }, 133 + { } 134 + }; 135 + MODULE_DEVICE_TABLE(of, pm886_of_match); 136 + 137 + static struct i2c_driver pm886_i2c_driver = { 138 + .driver = { 139 + .name = "88pm886", 140 + .of_match_table = pm886_of_match, 141 + }, 142 + .probe = pm886_probe, 143 + }; 144 + module_i2c_driver(pm886_i2c_driver); 145 + 146 + MODULE_DESCRIPTION("Marvell 88PM886 PMIC driver"); 147 + MODULE_AUTHOR("Karel Balej <balejk@matfyz.cz>"); 148 + MODULE_LICENSE("GPL");
+12
drivers/mfd/Kconfig
··· 794 794 select individual components like voltage regulators, RTC and 795 795 battery-charger under the corresponding menus. 796 796 797 + config MFD_88PM886_PMIC 798 + bool "Marvell 88PM886 PMIC" 799 + depends on I2C=y 800 + depends on OF 801 + select REGMAP_I2C 802 + select REGMAP_IRQ 803 + select MFD_CORE 804 + help 805 + This enables support for Marvell 88PM886 Power Management IC. 806 + This includes the I2C driver and the core APIs _only_, you have to 807 + select individual components like onkey under the corresponding menus. 808 + 797 809 config MFD_MAX14577 798 810 tristate "Maxim Semiconductor MAX14577/77836 MUIC + Charger Support" 799 811 depends on I2C
+1
drivers/mfd/Makefile
··· 7 7 obj-$(CONFIG_MFD_88PM860X) += 88pm860x.o 8 8 obj-$(CONFIG_MFD_88PM800) += 88pm800.o 88pm80x.o 9 9 obj-$(CONFIG_MFD_88PM805) += 88pm805.o 88pm80x.o 10 + obj-$(CONFIG_MFD_88PM886_PMIC) += 88pm886.o 10 11 obj-$(CONFIG_MFD_ACT8945A) += act8945a.o 11 12 obj-$(CONFIG_MFD_SM501) += sm501.o 12 13 obj-$(CONFIG_ARCH_BCM2835) += bcm2835-pm.o
+69
include/linux/mfd/88pm886.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-only */ 2 + #ifndef __MFD_88PM886_H 3 + #define __MFD_88PM886_H 4 + 5 + #include <linux/i2c.h> 6 + #include <linux/regmap.h> 7 + 8 + #define PM886_A1_CHIP_ID 0xa1 9 + 10 + #define PM886_IRQ_ONKEY 0 11 + 12 + #define PM886_PAGE_OFFSET_REGULATORS 1 13 + 14 + #define PM886_REG_ID 0x00 15 + 16 + #define PM886_REG_STATUS1 0x01 17 + #define PM886_ONKEY_STS1 BIT(0) 18 + 19 + #define PM886_REG_INT_STATUS1 0x05 20 + 21 + #define PM886_REG_INT_ENA_1 0x0a 22 + #define PM886_INT_ENA1_ONKEY BIT(0) 23 + 24 + #define PM886_REG_MISC_CONFIG1 0x14 25 + #define PM886_SW_PDOWN BIT(5) 26 + 27 + #define PM886_REG_MISC_CONFIG2 0x15 28 + #define PM886_INT_INV BIT(0) 29 + #define PM886_INT_CLEAR BIT(1) 30 + #define PM886_INT_RC 0x00 31 + #define PM886_INT_WC BIT(1) 32 + #define PM886_INT_MASK_MODE BIT(2) 33 + 34 + #define PM886_REG_RTC_SPARE6 0xef 35 + 36 + #define PM886_REG_BUCK_EN 0x08 37 + #define PM886_REG_LDO_EN1 0x09 38 + #define PM886_REG_LDO_EN2 0x0a 39 + #define PM886_REG_LDO1_VOUT 0x20 40 + #define PM886_REG_LDO2_VOUT 0x26 41 + #define PM886_REG_LDO3_VOUT 0x2c 42 + #define PM886_REG_LDO4_VOUT 0x32 43 + #define PM886_REG_LDO5_VOUT 0x38 44 + #define PM886_REG_LDO6_VOUT 0x3e 45 + #define PM886_REG_LDO7_VOUT 0x44 46 + #define PM886_REG_LDO8_VOUT 0x4a 47 + #define PM886_REG_LDO9_VOUT 0x50 48 + #define PM886_REG_LDO10_VOUT 0x56 49 + #define PM886_REG_LDO11_VOUT 0x5c 50 + #define PM886_REG_LDO12_VOUT 0x62 51 + #define PM886_REG_LDO13_VOUT 0x68 52 + #define PM886_REG_LDO14_VOUT 0x6e 53 + #define PM886_REG_LDO15_VOUT 0x74 54 + #define PM886_REG_LDO16_VOUT 0x7a 55 + #define PM886_REG_BUCK1_VOUT 0xa5 56 + #define PM886_REG_BUCK2_VOUT 0xb3 57 + #define PM886_REG_BUCK3_VOUT 0xc1 58 + #define PM886_REG_BUCK4_VOUT 0xcf 59 + #define PM886_REG_BUCK5_VOUT 0xdd 60 + 61 + #define PM886_LDO_VSEL_MASK 0x0f 62 + #define PM886_BUCK_VSEL_MASK 0x7f 63 + 64 + struct pm886_chip { 65 + struct i2c_client *client; 66 + unsigned int chip_id; 67 + struct regmap *regmap; 68 + }; 69 + #endif /* __MFD_88PM886_H */