mfd: mt6360: add pmic mt6360 driver
Subsystems (2)
PATCH v6 1/1 mfd: mt6360: add pmic mt6360 driver
From: Gene Chen <[email protected]>
Add mfd driver for mt6360 pmic chip include
Battery Charger/USB_PD/Flash LED/RGB LED/LDO/Buck
--- drivers/mfd/Kconfig | 12 + drivers/mfd/Makefile | 1 + drivers/mfd/mt6360-core.c | 426 +++++++++++++++++++++++++++++ include/linux/mfd/mt6360-private.h | 217 +++++++++++++++ include/linux/mfd/mt6360.h | 32 +++ 5 files changed, 688 insertions(+) create mode 100644 drivers/mfd/mt6360-core.c create mode 100644 include/linux/mfd/mt6360-private.h create mode 100644 include/linux/mfd/mt6360.h
changelogs between v1 & v2
- include missing header file
changelogs between v2 & v3
- add changelogs
changelogs between v3 & v4
- fix Kconfig description
- replace mt6360_pmu_info with mt6360_pmu_data
- replace probe with probe_new
- remove unnecessary irq_chip variable
- remove annotation
- replace MT6360_MFD_CELL with OF_MFD_CELL
changelogs between v4 & v5
- remove unnecessary parse dt function
- use devm_i2c_new_dummy_device
- add base-commit message
changelogs between v5 & v6
- review return value
- remove i2c id_table
- use GPL license v2
drivers/mfd/Kconfig +12 -0
@@ -856,6 +856,18 @@ config MFD_MAX8998 additional drivers must be enabled in order to use the functionality of the device. +config MFD_MT6360 + tristate "Mediatek MT6360 SubPMIC" + select MFD_CORE + select REGMAP_I2C + select REGMAP_IRQ + depends on I2C + help + Say Y here to enable MT6360 PMU/PMIC/LDO functional support. + PMU part includes Charger, Flashlight, RGB LED + PMIC part includes 2-channel BUCKs and 2-channel LDOs + LDO part includes 4-channel LDOs + config MFD_MT6397 tristate "MediaTek MT6397 PMIC Support" select MFD_CORE
drivers/mfd/Makefile +1 -0
@@ -237,6 +237,7 @@ obj-$(CONFIG_INTEL_SOC_PMIC) += intel-soc-pmic.o obj-$(CONFIG_INTEL_SOC_PMIC_BXTWC) += intel_soc_pmic_bxtwc.o obj-$(CONFIG_INTEL_SOC_PMIC_CHTWC) += intel_soc_pmic_chtwc.o obj-$(CONFIG_INTEL_SOC_PMIC_CHTDC_TI) += intel_soc_pmic_chtdc_ti.o +obj-$(CONFIG_MFD_MT6360) += mt6360-core.o mt6397-objs := mt6397-core.o mt6397-irq.o obj-$(CONFIG_MFD_MT6397) += mt6397.o obj-$(CONFIG_INTEL_SOC_PMIC_MRFLD) += intel_soc_pmic_mrfld.o
drivers/mfd/mt6360-core.c new file +426 -0
426 lines not on this page · raw message
include/linux/mfd/mt6360-private.h new file +217 -0
217 lines not on this page · raw message
include/linux/mfd/mt6360.h new file +32 -0
@@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2019 MediaTek Inc. +*/ + +#ifndef __MT6360_H__ +#define __MT6360_H__ + +#include <linux/regmap.h> + +enum { +MT6360_SLAVE_PMU =0 , +MT6360_SLAVE_PMIC , +MT6360_SLAVE_LDO , +MT6360_SLAVE_TCPC , +MT6360_SLAVE_MAX , +}; + +#define MT6360_PMU_SLAVEID (0x34) +#define MT6360_PMIC_SLAVEID (0x1A) +#define MT6360_LDO_SLAVEID (0x64) +#define MT6360_TCPC_SLAVEID (0x4E) + +struct mt6360_pmu_data { +struct i2c_client *i2c[MT6360_SLAVE_MAX ]; +struct device *dev; +struct regmap *regmap; +struct regmap_irq_chip_data *irq_data; +unsigned int chip_rev; +}; + +#endif /* __MT6360_H__ */
Signature · 1 line
2.23.0
kbuild test robot
build botThank you for the patch! Yet something to improve:
Hi Gene,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on ljones-mfd/for-mfd-next]
[also build test ERROR on v5.5-rc3 next-20191220]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Gene-Chen/mfd-mt6360-add-pmic-mt6360-driver/20191226-040639 base: https://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd.git for-mfd-next config: m68k-allmodconfig (attached as .config) compiler: m68k-linux-gcc (GCC) 7.5.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.5.0 make.cross ARCH=m68k
If you fix the issue, kindly add following tag
All errors (new ones prefixed by >>):
drivers//mfd/mt6360-core.c: In function 'mt6360_pmu_probe':
>> drivers//mfd/mt6360-core.c:352:12: error: 'IRQF_TRIGGER_FALLING' undeclared (first use in this function); did you mean 'IRQD_TRIGGER_MASK'?
IRQF_TRIGGER_FALLING, 0,
^~~~~~~~~~~~~~~~~~~~
IRQD_TRIGGER_MASK
drivers//mfd/mt6360-core.c:352:12: note: each undeclared identifier is reported only once for each function it appears in
drivers//mfd/mt6360-core.c: In function 'mt6360_pmu_suspend':
>> drivers//mfd/mt6360-core.c:390:3: error: implicit declaration of function 'enable_irq_wake'; did you mean 'local_irq_save'? [-Werror=implicit-function-declaration]
enable_irq_wake(i2c->irq);
^~~~~~~~~~~~~~~
local_irq_save
drivers//mfd/mt6360-core.c: In function 'mt6360_pmu_resume':
>> drivers//mfd/mt6360-core.c:401:3: error: implicit declaration of function 'disable_irq_wake'; did you mean 'local_irq_save'? [-Werror=implicit-function-declaration]
disable_irq_wake(i2c->irq);
^~~~~~~~~~~~~~~~
local_irq_savecc1: some warnings being treated as errors
vim +352 drivers//mfd/mt6360-core.c
318
319 static int mt6360_pmu_probe(struct i2c_client *client)
320 {
321 struct mt6360_pmu_data *mpd;
322 unsigned int reg_data;
323 int i, ret;
324
325 mpd = devm_kzalloc(&client->dev, sizeof(*mpd), GFP_KERNEL);
326 if (!mpd)
327 return -ENOMEM;
328
329 mpd->dev = &client->dev;
330 i2c_set_clientdata(client, mpd);
331
332 mpd->regmap = devm_regmap_init_i2c(client, &mt6360_pmu_regmap_config);
333 if (IS_ERR(mpd->regmap)) {
334 dev_err(&client->dev, "Failed to register regmap\n");
335 return PTR_ERR(mpd->regmap);
336 }
337
338 ret = regmap_read(mpd->regmap, MT6360_PMU_DEV_INFO, ®_data);
339 if (ret) {
340 dev_err(&client->dev, "Device not found\n");
341 return ret;
342 }
343
344 mpd->chip_rev = reg_data & CHIP_REV_MASK;
345 if (mpd->chip_rev != CHIP_VEN_MT6360) {
346 dev_err(&client->dev, "Device not supported\n");
347 return -ENODEV;
348 }
349
350 mt6360_pmu_irq_chip.irq_drv_data = mpd;
351 ret = devm_regmap_add_irq_chip(&client->dev, mpd->regmap, client->irq,
> 352 IRQF_TRIGGER_FALLING, 0,
353 &mt6360_pmu_irq_chip, &mpd->irq_data);
354 if (ret) {
355 dev_err(&client->dev, "Failed to add Regmap IRQ Chip\n");
356 return ret;
357 }
358
359 mpd->i2c[0] = client;
360 for (i = 1; i < MT6360_SLAVE_MAX; i++) {
361 mpd->i2c[i] = devm_i2c_new_dummy_device(&client->dev,
362 client->adapter,
363 mt6360_slave_addr[i]);
364 if (IS_ERR(mpd->i2c[i])) {
365 dev_err(&client->dev,
366 "Failed to get new dummy I2C device for address 0x%x",
367 mt6360_slave_addr[i]);
368 return PTR_ERR(mpd->i2c[i]);
369 }
370 i2c_set_clientdata(mpd->i2c[i], mpd);
371 }
372
373 ret = devm_mfd_add_devices(&client->dev, PLATFORM_DEVID_AUTO,
374 mt6360_devs, ARRAY_SIZE(mt6360_devs), NULL,
375 0, regmap_irq_get_domain(mpd->irq_data));
376 if (ret) {
377 dev_err(&client->dev,
378 "Failed to register subordinate devices\n");
379 return ret;
380 }
381
382 return 0;
383 }
384
385 static int __maybe_unused mt6360_pmu_suspend(struct device *dev)
386 {
387 struct i2c_client *i2c = to_i2c_client(dev);
388
389 if (device_may_wakeup(dev))
> 390 enable_irq_wake(i2c->irq);
391
392 return 0;
393 }
394
395 static int __maybe_unused mt6360_pmu_resume(struct device *dev)
396 {
397
398 struct i2c_client *i2c = to_i2c_client(dev);
399
400 if (device_may_wakeup(dev))
> 401 disable_irq_wake(i2c->irq); 402
403 return 0;
404 }
405
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org Intel Corporation
Quoted 82 lines · Gene Chen
From: Gene Chen <[email protected]>
Add mfd driver for mt6360 pmic chip include
Battery Charger/USB_PD/Flash LED/RGB LED/LDO/BuckSigned-off-by Gene Chen <[email protected]--- drivers/mfd/Kconfig | 12 + drivers/mfd/Makefile | 1 + drivers/mfd/mt6360-core.c | 426 +++++++++++++++++++++++++++++ include/linux/mfd/mt6360-private.h | 217 +++++++++++++++ include/linux/mfd/mt6360.h | 32 +++ 5 files changed, 688 insertions(+) create mode 100644 drivers/mfd/mt6360-core.c create mode 100644 include/linux/mfd/mt6360-private.h create mode 100644 include/linux/mfd/mt6360.hchangelogs between v1 & v2
- include missing header filechangelogs between v2 & v3
- add changelogschangelogs between v3 & v4
- fixKconfigdescription
- replacemt6360_pmu_infowithmt6360_pmu_data
- replace probe withprobe_new
- remove unnecessaryirq_chipvariable
- remove annotation
- replaceMT6360_MFD_CELLwithOF_MFD_CELLchangelogs between v4 & v5
- remove unnecessary parse dt function
- usedevm_i2c_new_dummy_device
- add base-commit messagechangelogs between v5 & v6
- review return value
- remove i2cid_table
- use GPL license v2drivers/mfd/Kconfig +12
-0@@ -856,6 +856,18 @@ config MFD_MAX8998 additional drivers must be enabled in order to use the functionality of the device. +config MFD_MT6360 + tristate "Mediatek MT6360 SubPMIC" + select MFD_CORE + select REGMAP_I2C + select REGMAP_IRQ + depends on I2C + help + Say Y here to enable MT6360 PMU/PMIC/LDO functional support. + PMU part includes Charger, Flashlight, RGB LED + PMIC part includes 2-channel BUCKs and 2-channel LDOs + LDO part includes 4-channel LDOs + config MFD_MT6397 tristate "MediaTek MT6397 PMIC Support" select MFD_COREdrivers/mfd/Makefile +1
-0@@ -237,6 +237,7 @@ obj-$(CONFIG_INTEL_SOC_PMIC) += intel-soc-pmic.o obj-$(CONFIG_INTEL_SOC_PMIC_BXTWC) += intel_soc_pmic_bxtwc.o obj-$(CONFIG_INTEL_SOC_PMIC_CHTWC) += intel_soc_pmic_chtwc.o obj-$(CONFIG_INTEL_SOC_PMIC_CHTDC_TI) += intel_soc_pmic_chtdc_ti.o +obj-$(CONFIG_MFD_MT6360) += mt6360-core.o mt6397-objs := mt6397-core.o mt6397-irq.o obj-$(CONFIG_MFD_MT6397) += mt6397.o obj-$(CONFIG_INTEL_SOC_PMIC_MRFLD) += intel_soc_pmic_mrfld.odrivers/mfd/mt6360-core.c new file +0
-0
drivers/mfd/mt6360-core.c line 3
Quoted 3 lines
drivers/mfd/mt6360-core.c new file +3
-0@@ -0,0 +1,426 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2019 MediaTek Inc.
No author?
Quoted 13 lines
drivers/mfd/mt6360-core.c new file +13
-0+*/ + +#include <linux/i2c.h> +#include <linux/init.h> +#include <linux/kernel.h> +#include <linux/mfd/core.h> +#include <linux/module.h> +#include <linux/of_irq.h> +#include <linux/of_platform.h> +#include <linux/version.h> + +#include <linux/mfd/mt6360.h> +#include <linux/mfd/mt6360-private.h>
[...]
drivers/mfd/mt6360-core.c line 122
Quoted 2 lines
drivers/mfd/mt6360-core.c new file +2
-0+#define MT6360_REGMAP_IRQ_REG (_irq_evt) \ + REGMAP_IRQ_REG(_irq_evt, (_irq_evt) / 8, BIT((_irq_evt) % 8))
No need to roll your own macros for this. I think REGMAP_IRQ_REG_LINE() is what you're looking for.
Quoted 1 line
+static const struct
regmap_irqmt6360_pmu_irqs[] = {
REGMAP_IRQ_REG_LINE(MT6360_CHG_TREG_EVT, 8),
... etc.
Quoted 2 lines
drivers/mfd/mt6360-core.c new file +2
-0+MT6360_REGMAP_IRQ_REG (MT6360_CHG_TREG_EVT ), + MT6360_REGMAP_IRQ_REG(MT6360_CHG_AICR_EVT),
[...]
Quoted 2 lines
drivers/mfd/mt6360-core.c new file +2
-0+ MT6360_REGMAP_IRQ_REG(MT6360_LDO7_PGB_EVT), +};
[...]
include/linux/mfd/mt6360-private.h
Quoted 5 lines
include/linux/mfd/mt6360-private.h new file +0
-0
As there are only appropriately namespaced macros in here, I would move them to the normal header file and dispose of this one.
Quoted 12 lines
include/linux/mfd/mt6360-private.h new file +11
-0@@ -0,0 +1,217 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2019 MediaTek Inc. +*/ + +#ifndef __MT6360_PRIVATE_H__ +#define __MT6360_PRIVATE_H__ + +/* PMU register defininition */ +#define MT6360_PMU_DEV_INFO (0x00) +#define MT6360_PMU_CORE_CTRL1 (0x01)
[...]
Quoted 12 lines
include/linux/mfd/mt6360-private.h new file +12
-0+#define MT6360_PMU_LDO_MASK2 (0xFF) +#define MT6360_PMU_MAXREG (MT6360_PMU_LDO_MASK2) + +/* MT6360_PMU_IRQ_SET */ +#define MT6360_PMU_IRQ_REGNUM (MT6360_PMU_LDO_IRQ2 - MT6360_PMU_CHG_IRQ1 + 1) +#define MT6360_IRQ_RETRIG BIT(2) + +#define CHIP_VEN_MASK (0xF0) +#define CHIP_VEN_MT6360 (0x50) +#define CHIP_REV_MASK (0x0F) + +#endif /* __MT6360_PRIVATE_H__ */
Signature · 4 lines
Lee Jones [李琼斯] Linaro Services Technical Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog