mfd: mt6397: Add initial support for MT6328

The MT6328 PMIC is commonly used with the MT6735 SoC. Add initial
support for this PMIC.

Signed-off-by: Yassine Oudjana <y.oudjana@protonmail.com>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Link: https://lore.kernel.org/r/20241018081050.23592-5-y.oudjana@protonmail.com
Signed-off-by: Lee Jones <lee@kernel.org>
This commit is contained in:
Yassine Oudjana
2024-10-18 11:10:46 +03:00
committed by Lee Jones
parent 577f6c2c59
commit 6e31bb8d3a
5 changed files with 936 additions and 5 deletions

View File

@@ -13,12 +13,14 @@
#include <linux/regmap.h>
#include <linux/mfd/core.h>
#include <linux/mfd/mt6323/core.h>
#include <linux/mfd/mt6328/core.h>
#include <linux/mfd/mt6331/core.h>
#include <linux/mfd/mt6357/core.h>
#include <linux/mfd/mt6358/core.h>
#include <linux/mfd/mt6359/core.h>
#include <linux/mfd/mt6397/core.h>
#include <linux/mfd/mt6323/registers.h>
#include <linux/mfd/mt6328/registers.h>
#include <linux/mfd/mt6331/registers.h>
#include <linux/mfd/mt6357/registers.h>
#include <linux/mfd/mt6358/registers.h>
@@ -87,6 +89,13 @@ static const struct resource mt6323_keys_resources[] = {
DEFINE_RES_IRQ_NAMED(MT6323_IRQ_STATUS_FCHRKEY, "homekey"),
};
static const struct resource mt6328_keys_resources[] = {
DEFINE_RES_IRQ_NAMED(MT6328_IRQ_STATUS_PWRKEY, "powerkey"),
DEFINE_RES_IRQ_NAMED(MT6328_IRQ_STATUS_HOMEKEY, "homekey"),
DEFINE_RES_IRQ_NAMED(MT6328_IRQ_STATUS_PWRKEY_R, "powerkey_r"),
DEFINE_RES_IRQ_NAMED(MT6328_IRQ_STATUS_HOMEKEY_R, "homekey_r"),
};
static const struct resource mt6357_keys_resources[] = {
DEFINE_RES_IRQ_NAMED(MT6357_IRQ_PWRKEY, "powerkey"),
DEFINE_RES_IRQ_NAMED(MT6357_IRQ_HOMEKEY, "homekey"),
@@ -133,6 +142,18 @@ static const struct mfd_cell mt6323_devs[] = {
},
};
static const struct mfd_cell mt6328_devs[] = {
{
.name = "mt6328-regulator",
.of_compatible = "mediatek,mt6328-regulator"
}, {
.name = "mtk-pmic-keys",
.num_resources = ARRAY_SIZE(mt6328_keys_resources),
.resources = mt6328_keys_resources,
.of_compatible = "mediatek,mt6328-keys"
},
};
static const struct mfd_cell mt6357_devs[] = {
{
.name = "mt6359-auxadc",
@@ -262,6 +283,14 @@ static const struct chip_data mt6323_core = {
.irq_init = mt6397_irq_init,
};
static const struct chip_data mt6328_core = {
.cid_addr = MT6328_HWCID,
.cid_shift = 0,
.cells = mt6328_devs,
.cell_size = ARRAY_SIZE(mt6328_devs),
.irq_init = mt6397_irq_init,
};
static const struct chip_data mt6357_core = {
.cid_addr = MT6357_SWCID,
.cid_shift = 8,
@@ -360,6 +389,9 @@ static const struct of_device_id mt6397_of_match[] = {
{
.compatible = "mediatek,mt6323",
.data = &mt6323_core,
}, {
.compatible = "mediatek,mt6328",
.data = &mt6328_core,
}, {
.compatible = "mediatek,mt6331",
.data = &mt6331_mt6332_core,

View File

@@ -11,6 +11,8 @@
#include <linux/suspend.h>
#include <linux/mfd/mt6323/core.h>
#include <linux/mfd/mt6323/registers.h>
#include <linux/mfd/mt6328/core.h>
#include <linux/mfd/mt6328/registers.h>
#include <linux/mfd/mt6331/core.h>
#include <linux/mfd/mt6331/registers.h>
#include <linux/mfd/mt6397/core.h>
@@ -31,6 +33,9 @@ static void mt6397_irq_sync_unlock(struct irq_data *data)
mt6397->irq_masks_cur[0]);
regmap_write(mt6397->regmap, mt6397->int_con[1],
mt6397->irq_masks_cur[1]);
if (mt6397->int_con[2])
regmap_write(mt6397->regmap, mt6397->int_con[2],
mt6397->irq_masks_cur[2]);
mutex_unlock(&mt6397->irqlock);
}
@@ -105,6 +110,8 @@ static irqreturn_t mt6397_irq_thread(int irq, void *data)
mt6397_irq_handle_reg(mt6397, mt6397->int_status[0], 0);
mt6397_irq_handle_reg(mt6397, mt6397->int_status[1], 16);
if (mt6397->int_status[2])
mt6397_irq_handle_reg(mt6397, mt6397->int_status[2], 32);
return IRQ_HANDLED;
}
@@ -138,6 +145,9 @@ static int mt6397_irq_pm_notifier(struct notifier_block *notifier,
chip->int_con[0], chip->wake_mask[0]);
regmap_write(chip->regmap,
chip->int_con[1], chip->wake_mask[1]);
if (chip->int_con[2])
regmap_write(chip->regmap,
chip->int_con[2], chip->wake_mask[2]);
enable_irq_wake(chip->irq);
break;
@@ -146,6 +156,9 @@ static int mt6397_irq_pm_notifier(struct notifier_block *notifier,
chip->int_con[0], chip->irq_masks_cur[0]);
regmap_write(chip->regmap,
chip->int_con[1], chip->irq_masks_cur[1]);
if (chip->int_con[2])
regmap_write(chip->regmap,
chip->int_con[2], chip->irq_masks_cur[2]);
disable_irq_wake(chip->irq);
break;
@@ -169,6 +182,14 @@ int mt6397_irq_init(struct mt6397_chip *chip)
chip->int_status[0] = MT6323_INT_STATUS0;
chip->int_status[1] = MT6323_INT_STATUS1;
break;
case MT6328_CHIP_ID:
chip->int_con[0] = MT6328_INT_CON0;
chip->int_con[1] = MT6328_INT_CON1;
chip->int_con[2] = MT6328_INT_CON2;
chip->int_status[0] = MT6328_INT_STATUS0;
chip->int_status[1] = MT6328_INT_STATUS1;
chip->int_status[2] = MT6328_INT_STATUS2;
break;
case MT6331_CHIP_ID:
chip->int_con[0] = MT6331_INT_CON0;
chip->int_con[1] = MT6331_INT_CON1;
@@ -191,6 +212,8 @@ int mt6397_irq_init(struct mt6397_chip *chip)
/* Mask all interrupt sources */
regmap_write(chip->regmap, chip->int_con[0], 0x0);
regmap_write(chip->regmap, chip->int_con[1], 0x0);
if (chip->int_con[2])
regmap_write(chip->regmap, chip->int_con[2], 0x0);
chip->pm_nb.notifier_call = mt6397_irq_pm_notifier;
chip->irq_domain = irq_domain_add_linear(chip->dev->of_node,

View File

@@ -0,0 +1,53 @@
/* SPDX-License-Identifier: GPL-2.0-only */
/*
* Copyright (c) 2015 MediaTek Inc.
* Copyright (c) 2022 Yassine Oudjana <y.oudjana@protonmail.com>
*/
#ifndef __MFD_MT6328_CORE_H__
#define __MFD_MT6328_CORE_H__
enum mt6328_irq_status_numbers {
MT6328_IRQ_STATUS_PWRKEY = 0,
MT6328_IRQ_STATUS_HOMEKEY,
MT6328_IRQ_STATUS_PWRKEY_R,
MT6328_IRQ_STATUS_HOMEKEY_R,
MT6328_IRQ_STATUS_THR_H,
MT6328_IRQ_STATUS_THR_L,
MT6328_IRQ_STATUS_BAT_H,
MT6328_IRQ_STATUS_BAT_L,
MT6328_IRQ_STATUS_RTC,
MT6328_IRQ_STATUS_AUDIO,
MT6328_IRQ_STATUS_ACCDET,
MT6328_IRQ_STATUS_ACCDET_EINT,
MT6328_IRQ_STATUS_ACCDET_NEGV,
MT6328_IRQ_STATUS_NI_LBAT_INT,
MT6328_IRQ_STATUS_VPROC_OC = 16,
MT6328_IRQ_STATUS_VSYS_OC,
MT6328_IRQ_STATUS_VLTE_OC,
MT6328_IRQ_STATUS_VCORE_OC,
MT6328_IRQ_STATUS_VPA_OC,
MT6328_IRQ_STATUS_LDO_OC,
MT6328_IRQ_STATUS_BAT2_H,
MT6328_IRQ_STATUS_BAT2_L,
MT6328_IRQ_STATUS_VISMPS0_H,
MT6328_IRQ_STATUS_VISMPS0_L,
MT6328_IRQ_STATUS_AUXADC_IMP,
MT6328_IRQ_STATUS_OV = 32,
MT6328_IRQ_STATUS_BVALID_DET,
MT6328_IRQ_STATUS_VBATON_HV,
MT6328_IRQ_STATUS_VBATON_UNDET,
MT6328_IRQ_STATUS_WATCHDOG,
MT6328_IRQ_STATUS_PCHR_CM_VDEC,
MT6328_IRQ_STATUS_CHRDET,
MT6328_IRQ_STATUS_PCHR_CM_VINC,
MT6328_IRQ_STATUS_FG_BAT_H,
MT6328_IRQ_STATUS_FG_BAT_L,
MT6328_IRQ_STATUS_FG_CUR_H,
MT6328_IRQ_STATUS_FG_CUR_L,
MT6328_IRQ_STATUS_FG_ZCV,
MT6328_IRQ_STATUS_SPKL_D,
MT6328_IRQ_STATUS_SPKL_AB,
};
#endif /* __MFD_MT6323_CORE_H__ */

File diff suppressed because it is too large Load Diff

View File

@@ -12,6 +12,7 @@
enum chip_id {
MT6323_CHIP_ID = 0x23,
MT6328_CHIP_ID = 0x30,
MT6331_CHIP_ID = 0x20,
MT6332_CHIP_ID = 0x20,
MT6357_CHIP_ID = 0x57,
@@ -65,11 +66,11 @@ struct mt6397_chip {
int irq;
struct irq_domain *irq_domain;
struct mutex irqlock;
u16 wake_mask[2];
u16 irq_masks_cur[2];
u16 irq_masks_cache[2];
u16 int_con[2];
u16 int_status[2];
u16 wake_mask[3];
u16 irq_masks_cur[3];
u16 irq_masks_cache[3];
u16 int_con[3];
u16 int_status[3];
u16 chip_id;
void *irq_data;
};