Skip to contentSkip to conversation

Add support for MT6315 regulator

PATCH Applied Hsin-Hsiung Wang 4 participants 8 messages Oct 20, 2020 – Dec 3, 2020

Subsystems (5)

v2 of 4 Applied Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover Add support for MT6315 regulator

This patch series add support for MediaTek PMIC MT6315 regulator driver, which adds MT6315 related buck voltage data to the driver.

changes since v1:
- update binding document in DT schema format.
- add mtk,combined-regulator properity to show the relationship of MT6315 bucks.
- ignore the regulator registration of combined buck in probe.

Hsin-Hsiung Wang (3):
spmi: Add driver shutdown support
dt-bindings: regulator: document binding for MT6315 regulator
regulator: mt6315: Add support for MT6315 regulator

 .../regulator/mtk,mt6315-regulator.yaml       |  88 +++++
 drivers/regulator/Kconfig                     |  10 +
 drivers/regulator/Makefile                    |   1 +
 drivers/regulator/mt6315-regulator.c          | 364 ++++++++++++++++++
 drivers/spmi/spmi.c                           |   9 +
 include/dt-bindings/regulator/mtk,mt6315.h    |  17 +
 include/linux/regulator/mt6315-regulator.h    |  37 ++
 include/linux/spmi.h                          |   1 +
 8 files changed, 527 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/regulator/mtk,mt6315-regulator.yaml
 create mode 100644 drivers/regulator/mt6315-regulator.c
 create mode 100644 include/dt-bindings/regulator/mtk,mt6315.h
 create mode 100644 include/linux/regulator/mt6315-regulator.h
Signature · 1 line
2.18.0
#1 lore raw

PATCH v2 1/3 spmi: Add driver shutdown support

Add new shutdown() method. Use it in the standard driver model style.

---
 drivers/spmi/spmi.c  | 9 +++++++++
 include/linux/spmi.h | 1 +
 2 files changed, 10 insertions(+)
drivers/spmi/spmi.c +9 -0
index c16b60f645a4..161a48ca4acc 100644
@@ -357,6 +357,14 @@ static int spmi_drv_remove(struct device *dev)
 	return 0;
 }
 
+static void spmi_drv_shutdown(struct device *dev)
+{
+	const struct spmi_driver *sdrv = to_spmi_driver(dev->driver);
+
+	if (sdrv && sdrv->shutdown)
+		sdrv->shutdown(to_spmi_device(dev));
+}
+
 static int spmi_drv_uevent(struct device *dev, struct kobj_uevent_env *env)
 {
 	int ret;
@@ -373,6 +381,7 @@ static struct bus_type spmi_bus_type = {
 	.match		= spmi_device_match,
 	.probe		= spmi_drv_probe,
 	.remove		= spmi_drv_remove,
+	.shutdown	= spmi_drv_shutdown,
 	.uevent		= spmi_drv_uevent,
 };
 
include/linux/spmi.h +1 -0
index 394a3f68bad5..729bcbf9f5ad 100644
@@ -138,6 +138,7 @@ struct spmi_driver {
 	struct device_driver driver;
 	int	(*probe)(struct spmi_device *sdev);
 	void	(*remove)(struct spmi_device *sdev);
+	void	(*shutdown)(struct spmi_device *sdev);
 };
 
 static inline struct spmi_driver *to_spmi_driver(struct device_driver *d)
Signature · 1 line
2.18.0
maintainer Applied
#2 lore raw

Re: [PATCH v2 1/3] spmi: Add driver shutdown support

Quoting Hsin-Hsiung Wang (2020-10-20 02:56:48)

Quoted 4 lines

Add new shutdown() method. Use it in the standard driver model style.

---

Applied to spmi-next. The line endings are all confused still though.

_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek

#3 lore raw

PATCH v2 2/3 dt-bindings: regulator: document binding for MT6315 regulator

In reply to Hsin-Hsiung Wang

Add device tree binding information for MT6315 regulator driver. Example bindings for MT6315 are added.

---
 .../regulator/mtk,mt6315-regulator.yaml       | 88 +++++++++++++++++++
 include/dt-bindings/regulator/mtk,mt6315.h    | 17 ++++
 2 files changed, 105 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/regulator/mtk,mt6315-regulator.yaml
 create mode 100644 include/dt-bindings/regulator/mtk,mt6315.h
Documentation/devicetree/bindings/regulator/mtk,mt6315-regulator.yaml new file +88 -0
new file mode 100644
index 000000000000..457606800d5b
@@ -0,0 +1,88 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/regulator/mtk,mt6315-regulator.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Mediatek MT6315 Regulator
+
+maintainers:
+  - Hsin-Hsiung Wang <[email protected]>
+
+description: |
+  The MT6315 is a power management IC (PMIC) configurable with SPMI.
+  that contains 4 BUCKs output which can combine with each other
+  by different efuse settings.
+
+allOf:
+  - $ref: "regulator.yaml#"
+
+properties:
+  $nodename:
+    pattern: "mt6315@[0-9]"
+  compatible:
+    enum:
+      - mediatek,mt6315_3-regulator
+      - mediatek,mt6315_6-regulator
+      - mediatek,mt6315_7-regulator
+
+  reg:
+    maxItems: 1
+
+  regulators:
+    type: object
+    description: List of regulators and its properties
+
+    patternProperties:
+      "^vbuck[1-4]$":
+        type: object
+
+        properties:
+          regulator-name:
+            pattern: "^vbuck[1-4]$"
+            description:
+              should be "vbuck1", ..., "vbuck4"
+
+          mtk,combined-regulator:
+            $ref: "/schemas/types.yaml#/definitions/uint32-array"
+            description: |
+              defines other bucks combined with this buck, must contain the following
+              values MT6315_VBUCK1, MT6315_VBUCK2, MT6315_VBUCK3, MT6315_VBUCK4
+
+    unevaluatedProperties: false
+
+required:
+  - compatible
+  - reg
+  - regulators
+
+additionalProperties: false
+
+examples:
+  - |
+    /* This example shows that buck2 and buck4 are combined into buck1. */
+    #include <dt-bindings/regulator/mtk,mt6315.h>
+
+    mt6315@6 {
+      compatible = "mediatek,mt6315_6-regulator";
+      reg = <0x6 0 0xb 1>;
+
+      regulators {
+        vbuck1 {
+          regulator-compatible = "vbuck1";
+          regulator-min-microvolt = <300000>;
+          regulator-max-microvolt = <1193750>;
+          regulator-enable-ramp-delay = <256>;
+          regulator-allowed-modes = <0 1 2 4>;
+          mtk,combined-regulator = <MT6315_VBUCK2 MT6315_VBUCK4>;
+        };
+
+        vbuck3 {
+          regulator-compatible = "vbuck3";
+          regulator-min-microvolt = <300000>;
+          regulator-max-microvolt = <1193750>;
+          regulator-enable-ramp-delay = <256>;
+          regulator-allowed-modes = <0 1 2 4>;
+        };
+      };
+    };
include/dt-bindings/regulator/mtk,mt6315.h new file +17 -0
new file mode 100644
index 000000000000..6ed9b2b121db
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (c) 2020 MediaTek Inc.
+ * Author: Hsin-Hsiung Wang <[email protected]>
+ */
+
+#ifndef _DT_BINDINGS_REGULATOR_MTK_MT6315_H
+#define _DT_BINDINGS_REGULATOR_MTK_MT6315_H
+
+/* Regulator ID */
+#define MT6315_VBUCK1	1
+#define MT6315_VBUCK2	2
+#define MT6315_VBUCK3	3
+#define MT6315_VBUCK4	4
+#define MT6315_VBUCK_MAX	5
+
+#endif /* _DT_BINDINGS_REGULATOR_MTK_MT6315_H */
Signature · 1 line
2.18.0
maintainer
#4 lore raw

Re: [PATCH v2 2/3] dt-bindings: regulator: document binding for MT6315 regulator

Quoted 11 lines · Hsin-Hsiung Wang

Add device tree binding information for MT6315 regulator driver. Example bindings for MT6315 are added.

---
 .../regulator/mtk,mt6315-regulator.yaml       | 88 +++++++++++++++++++
 include/dt-bindings/regulator/mtk,mt6315.h    | 17 ++++
 2 files changed, 105 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/regulator/mtk,mt6315-regulator.yaml
 create mode 100644 include/dt-bindings/regulator/mtk,mt6315.h

My bot found errors running 'make dt_binding_check' on your patch:

/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/regulator/mtk,mt6315-regulator.example.dt.yaml: example-0: mt6315@6:reg:0: [6, 0, 11, 1] is too long
From schema: /usr/local/lib/python3.8/dist-packages/dtschema/schemas/reg.yaml
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/regulator/mtk,mt6315-regulator.example.dt.yaml: vbuck1: 'mtk,combined-regulator' does not match any of the regexes: '^#.*', '^(at25|devbus|dmacap|dsa|exynos|fsi[ab]|gpio-fan|gpio|gpmc|hdmi|i2c-gpio),.*', '^(keypad|m25p|max8952|max8997|max8998|mpmc),.*', '^(pinctrl-single|#pinctrl-single|PowerPC),.*', '^(pl022|pxa-mmc|rcar_sound|rotary-encoder|s5m8767|sdhci),.*', '^(simple-audio-card|st-plgpio|st-spics|ts),.*', '^70mai,.*', '^GEFanuc,.*', '^ORCL,.*', '^SUNW,.*', '^[a-zA-Z0-9#_][a-zA-Z0-9+\\-._@]{0,63}$', '^[a-zA-Z0-9+\\-._]*@[0-9a-zA-Z,]*$', '^abilis,.*', '^abracon,.*', '^acer,.*', '^acme,.*', '^actions,.*', '^active-semi,.*', '^ad,.*', '^adafruit,.*', '^adapteva,.*', '^adaptrum,.*', '^adh,.*', '^adi,.*', '^advantech,.*', '^aeroflexgaisler,.*', '^al,.*', '^allegro,.*', '^allo,.*', '^allwinner,.*', '^alphascale,.*', '^alps,.*', '^altr,.*', '^amarula,.*', '^amazon,.*', '^amcc,.*', '^amd,.*', '^amediatech,.*', '^amlogic
,.*', '^ampire,.*', '^ams,.*', '^amstaos,.*', '^analogix,.*', '^andestech,.*', '^anvo,.*', '^apm,.*', '^aptina,.*', '^arasan,.*', '^archermind,.*', '^arctic,.*', '^arcx,.*', '^aries,.*', '^arm,.*', '^armadeus,.*', '^arrow,.*', '^artesyn,.*', '^asahi-kasei,.*', '^asc,.*', '^aspeed,.*', '^asus,.*', '^atlas,.*', '^atmel,.*', '^auo,.*', '^auvidea,.*', '^avago,.*', '^avia,.*', '^avic,.*', '^avnet,.*', '^awinic,.*', '^axentia,.*', '^axis,.*', '^azoteq,.*', '^azw,.*', '^baikal,.*', '^bananapi,.*', '^beacon,.*', '^beagle,.*', '^bhf,.*', '^bitmain,.*', '^boe,.*', '^bosch,.*', '^boundary,.*', '^brcm,.*', '^broadmobi,.*', '^bticino,.*', '^buffalo,.*', '^bur,.*', '^calaosystems,.*', '^calxeda,.*', '^capella,.*', '^cascoda,.*', '^catalyst,.*', '^cavium,.*', '^cdns,.*', '^cdtech,.*', '^cellwise,.*', '^ceva,.*', '^checkpoint,.*', '^chipidea,.*', '^chipone,.*', '^chipspark,.*', '^chrontel,.*', '^chrp,.*', '^chunghwa,.*', '^chuwi,.*', '^ciaa,.*', '^cirrus,.*', '^cloudengines,.*', '^cnm,.*', '^cnxt,. *', '^colorfly,.*', '^compulab,.*', '^coreriver,.*', '^corpro,.*', '^cortina,.*', '^cosmic,.*', '^crane,.*', '^creative,.*', '^crystalfontz,.*', '^csky,.*', '^csq,.*', '^cubietech,.*', '^cypress,.*', '^cznic,.*', '^dallas,.*', '^dataimage,.*', '^davicom,.*', '^dell,.*', '^delta,.*', '^denx,.*', '^devantech,.*', '^dfi,.*', '^dh,.*', '^difrnce,.*', '^digi,.*', '^digilent,.*', '^dioo,.*', '^dlc,.*', '^dlg,.*', '^dlink,.*', '^dmo,.*', '^domintech,.*', '^dongwoon,.*', '^dptechnics,.*', '^dragino,.*', '^dserve,.*', '^dynaimage,.*', '^ea,.*', '^ebs-systart,.*', '^ebv,.*', '^eckelmann,.*', '^edt,.*', '^eeti,.*', '^einfochips,.*', '^elan,.*', '^elgin,.*', '^elida,.*', '^embest,.*', '^emlid,.*', '^emmicro,.*', '^empire-electronix,.*', '^emtrion,.*', '^endless,.*', '^ene,.*', '^energymicro,.*', '^engicam,.*', '^epcos,.*', '^epfl,.*', '^epson,.*', '^esp,.*', '^est,.*', '^ettus,.*', '^eukrea,.*', '^everest,.*', '^everspin,.*', '^evervision,.*', '^exar,.*', '^excito,.*', '^ezchip,.*', '^facebook, .*', '^fairphone,.*', '^faraday,.*', '^fastrax,.*', '^fcs,.*', '^feixin,.*', '^feiyang,.*', '^firefly,.*', '^focaltech,.*', '^frida,.*', '^friendlyarm,.*', '^fsl,.*', '^fujitsu,.*', '^gardena,.*', '^gateworks,.*', '^gcw,.*', '^ge,.*', '^geekbuying,.*', '^gef,.*', '^gemei,.*', '^geniatech,.*', '^giantec,.*', '^giantplus,.*', '^globalscale,.*', '^globaltop,.*', '^gmt,.*', '^goodix,.*', '^google,.*', '^grinn,.*', '^grmn,.*', '^gumstix,.*', '^gw,.*', '^hannstar,.*', '^haoyu,.*', '^hardkernel,.*', '^hideep,.*', '^himax,.*', '^hisilicon,.*', '^hit,.*', '^hitex,.*', '^holt,.*', '^holtek,.*', '^honeywell,.*', '^hoperun,.*', '^hp,.*', '^hsg,.*', '^hugsun,.*', '^hwacom,.*', '^hydis,.*', '^hyundai,.*', '^i2se,.*', '^ibm,.*', '^icplus,.*', '^idt,.*', '^ifi,.*', '^ilitek,.*', '^img,.*', '^imi,.*', '^incircuit,.*', '^inet-tek,.*', '^infineon,.*', '^inforce,.*', '^ingenic,.*', '^innolux,.*', '^inside-secure,.*', '^inspur,.*', '^intel,.*', '^intercontrol,.*', '^invensense,.*', '^inversepath,.*', '^ iom,.*', '^isee,.*', '^isil,.*', '^issi,.*', '^ite,.*', '^itead,.*', '^ivo,.*', '^iwave,.*', '^jdi,.*', '^jedec,.*', '^jesurun,.*', '^jianda,.*', '^kam,.*', '^karo,.*', '^keithkoep,.*', '^keymile,.*', '^khadas,.*', '^kiebackpeter,.*', '^kinetic,.*', '^kingdisplay,.*', '^kingnovel,.*', '^kionix,.*', '^kobo,.*', '^koe,.*', '^kontron,.*', '^kosagi,.*', '^kyo,.*', '^lacie,.*', '^laird,.*', '^lamobo,.*', '^lantiq,.*', '^lattice,.*', '^leadtek,.*', '^leez,.*', '^lego,.*', '^lemaker,.*', '^lenovo,.*', '^lg,.*', '^lgphilips,.*', '^libretech,.*', '^licheepi,.*', '^linaro,.*', '^linksprite,.*', '^linksys,.*', '^linutronix,.*', '^linux,.*', '^linx,.*', '^lltc,.*', '^logicpd,.*', '^logictechno,.*', '^longcheer,.*', '^loongson,.*', '^lsi,.*', '^lwn,.*', '^lxa,.*', '^macnica,.*', '^mapleboard,.*', '^marvell,.*', '^maxbotix,.*', '^maxim,.*', '^mbvl,.*', '^mcube,.*', '^meas,.*', '^mecer,.*', '^mediatek,.*', '^megachips,.*', '^mele,.*', '^melexis,.*', '^melfas,.*', '^mellanox,.*', '^memsic,.*', '^me nlo,.*', '^meraki,.*', '^merrii,.*', '^micrel,.*', '^microchip,.*', '^microcrystal,.*', '^micron,.*', '^microsoft,.*', '^mikroe,.*', '^mikrotik,.*', '^miniand,.*', '^minix,.*', '^miramems,.*', '^mitsubishi,.*', '^mosaixtech,.*', '^motorola,.*', '^moxa,.*', '^mpl,.*', '^mps,.*', '^mqmaker,.*', '^mrvl,.*', '^mscc,.*', '^msi,.*', '^mstar,.*', '^mti,.*', '^multi-inno,.*', '^mundoreader,.*', '^murata,.*', '^mxicy,.*', '^myir,.*', '^national,.*', '^nec,.*', '^neonode,.*', '^netgear,.*', '^netlogic,.*', '^netron-dy,.*', '^netxeon,.*', '^neweast,.*', '^newhaven,.*', '^nexbox,.*', '^nextthing,.*', '^ni,.*', '^nintendo,.*', '^nlt,.*', '^nokia,.*', '^nordic,.*', '^novtech,.*', '^nutsboard,.*', '^nuvoton,.*', '^nvd,.*', '^nvidia,.*', '^nxp,.*', '^oceanic,.*', '^okaya,.*', '^oki,.*', '^olimex,.*', '^olpc,.*', '^onion,.*', '^onnn,.*', '^ontat,.*', '^opalkelly,.*', '^opencores,.*', '^openrisc,.*', '^option,.*', '^oranth,.*', '^orisetech,.*', '^ortustech,.*', '^osddisplays,.*', '^overkiz,.*', '^ovt i,.*', '^oxsemi,.*', '^ozzmaker,.*', '^panasonic,.*', '^parade,.*', '^parallax,.*', '^pda,.*', '^pericom,.*', '^pervasive,.*', '^phicomm,.*', '^phytec,.*', '^picochip,.*', '^pine64,.*', '^pineriver,.*', '^pixcir,.*', '^plantower,.*', '^plathome,.*', '^plda,.*', '^plx,.*', '^pni,.*', '^pocketbook,.*', '^polaroid,.*', '^portwell,.*', '^poslab,.*', '^pov,.*', '^powervr,.*', '^primux,.*', '^probox2,.*', '^prt,.*', '^pulsedlight,.*', '^purism,.*', '^qca,.*', '^qcom,.*', '^qemu,.*', '^qi,.*', '^qiaodian,.*', '^qihua,.*', '^qnap,.*', '^radxa,.*', '^raidsonic,.*', '^ralink,.*', '^ramtron,.*', '^raspberrypi,.*', '^raydium,.*', '^rda,.*', '^realtek,.*', '^renesas,.*', '^rervision,.*', '^rex,.*', '^richtek,.*', '^ricoh,.*', '^rikomagic,.*', '^riot,.*', '^riscv,.*', '^rockchip,.*', '^rocktech,.*', '^rohm,.*', '^ronbo,.*', '^roofull,.*', '^samsung,.*', '^samtec,.*', '^sancloud,.*', '^sandisk,.*', '^satoz,.*', '^sbs,.*', '^schindler,.*', '^seagate,.*', '^seirobotics,.*', '^semtech,.*', '^sensirio n,.*', '^sensortek,.*', '^sff,.*', '^sgd,.*', '^sgmicro,.*', '^sgx,.*', '^sharp,.*', '^shimafuji,.*', '^shiratech,.*', '^si-en,.*', '^si-linux,.*', '^sifive,.*', '^sigma,.*', '^sii,.*', '^sil,.*', '^silabs,.*', '^silead,.*', '^silergy,.*', '^silex-insight,.*', '^siliconmitus,.*', '^simtek,.*', '^sinlinx,.*', '^sinovoip,.*', '^sipeed,.*', '^sirf,.*', '^sis,.*', '^sitronix,.*', '^skyworks,.*', '^smartlabs,.*', '^smsc,.*', '^snps,.*', '^sochip,.*', '^socionext,.*', '^solidrun,.*', '^solomon,.*', '^sony,.*', '^spansion,.*', '^sprd,.*', '^sst,.*', '^sstar,.*', '^st,.*', '^st-ericsson,.*', '^starry,.*', '^startek,.*', '^ste,.*', '^stericsson,.*', '^summit,.*', '^sunchip,.*', '^swir,.*', '^syna,.*', '^synology,.*', '^tbs,.*', '^tbs-biometrics,.*', '^tcg,.*', '^tcl,.*', '^technexion,.*', '^technologic,.*', '^techstar,.*', '^tempo,.*', '^terasic,.*', '^tfc,.*', '^thine,.*', '^thingyjp,.*', '^ti,.*', '^tianma,.*', '^tlm,.*', '^tmt,.*', '^topeet,.*', '^toppoly,.*', '^topwise,.*', '^toradex,.*' , '^toshiba,.*', '^toumaz,.*', '^tpk,.*', '^tplink,.*', '^tpo,.*', '^tq,.*', '^tronfy,.*', '^tronsmart,.*', '^truly,.*', '^tsd,.*', '^tyan,.*', '^u-blox,.*', '^u-boot,.*', '^ubnt,.*', '^ucrobotics,.*', '^udoo,.*', '^ugoos,.*', '^uniwest,.*', '^upisemi,.*', '^urt,.*', '^usi,.*', '^utoo,.*', '^v3,.*', '^vaisala,.*', '^vamrs,.*', '^variscite,.*', '^via,.*', '^videostrong,.*', '^virtio,.*', '^vishay,.*', '^visionox,.*', '^vitesse,.*', '^vivante,.*', '^vocore,.*', '^voipac,.*', '^vot,.*', '^vxt,.*', '^wand,.*', '^waveshare,.*', '^wd,.*', '^we,.*', '^wetek,.*', '^wexler,.*', '^whwave,.*', '^wi2wi,.*', '^winbond,.*', '^winstar,.*', '^wits,.*', '^wlf,.*', '^wm,.*', '^wobo,.*', '^x-powers,.*', '^xes,.*', '^xiaomi,.*', '^xillybus,.*', '^xingbangda,.*', '^xinpeng,.*', '^xlnx,.*', '^xnano,.*', '^xunlong,.*', '^xylon,.*', '^ylm,.*', '^yna,.*', '^yones-toptech,.*', '^ysoft,.*', '^zarlink,.*', '^zealz,.*', '^zeitec,.*', '^zidoo,.*', '^zii,.*', '^zte,.*', '^zyxel,.*'
From schema: /builds/robherring/linux-dt-review/Documentation/devicetree/bindings/vendor-prefixes.yaml

See https://patchwork.ozlabs.org/patch/1384771

If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure dt-schema is up to date:

pip3 install git+https://github.com/devicetree-org/dt-schema.git@master --upgrade

Please check and re-submit.

maintainer
#5 lore raw

Re: [PATCH v2 2/3] dt-bindings: regulator: document binding for MT6315 regulator

In reply to Hsin-Hsiung Wang
Quoted 25 lines · Hsin-Hsiung Wang

Add device tree binding information for MT6315 regulator driver. Example bindings for MT6315 are added.

---
 .../regulator/mtk,mt6315-regulator.yaml       | 88 +++++++++++++++++++
 include/dt-bindings/regulator/mtk,mt6315.h    | 17 ++++
 2 files changed, 105 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/regulator/mtk,mt6315-regulator.yaml
 create mode 100644 include/dt-bindings/regulator/mtk,mt6315.h
Documentation/devicetree/bindings/regulator/mtk,mt6315-regulator.yaml new file +8 -0
new file mode 100644
index 000000000000..457606800d5b
@@ -0,0 +1,88 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/regulator/mtk,mt6315-regulator.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Mediatek MT6315 Regulator
+

Documentation/devicetree/bindings/regulator/mtk,mt6315-regulator.yaml line 18

Quoted 10 lines
Documentation/devicetree/bindings/regulator/mtk,mt6315-regulator.yaml new file +10 -0
+maintainers:
+  - Hsin-Hsiung Wang <[email protected]>
+
+description: |
+  The MT6315 is a power management IC (PMIC) configurable with SPMI.
+  that contains 4 BUCKs output which can combine with each other
+  by different efuse settings.
+
+allOf:
+  - $ref: "regulator.yaml#"

This doesn't go here, but...

Documentation/devicetree/bindings/regulator/mtk,mt6315-regulator.yaml line 27

Quoted 9 lines
Documentation/devicetree/bindings/regulator/mtk,mt6315-regulator.yaml new file +9 -0
+
+properties:
+  $nodename:
+    pattern: "mt6315@[0-9]"
+  compatible:
+    enum:
+      - mediatek,mt6315_3-regulator
+      - mediatek,mt6315_6-regulator
+      - mediatek,mt6315_7-regulator

What's 3, 6, 7 mean?

Documentation/devicetree/bindings/regulator/mtk,mt6315-regulator.yaml line 38

Quoted 11 lines
Documentation/devicetree/bindings/regulator/mtk,mt6315-regulator.yaml new file +11 -0
+
+  reg:
+    maxItems: 1
+
+  regulators:
+    type: object
+    description: List of regulators and its properties
+
+    patternProperties:
+      "^vbuck[1-4]$":
+        type: object

regulator.yaml ref goes here.

Documentation/devicetree/bindings/regulator/mtk,mt6315-regulator.yaml line 47

Quoted 9 lines
Documentation/devicetree/bindings/regulator/mtk,mt6315-regulator.yaml new file +9 -0
+
+        properties:
+          regulator-name:
+            pattern: "^vbuck[1-4]$"
+            description:
+              should be "vbuck1", ..., "vbuck4"
+
+          mtk,combined-regulator:
+            $ref: "/schemas/types.yaml#/definitions/uint32-array"

Wouldn't a phandle make more sense. And we have coupled regulator binding that this may work for.

Documentation/devicetree/bindings/regulator/mtk,mt6315-regulator.yaml line 52

Quoted 5 lines
Documentation/devicetree/bindings/regulator/mtk,mt6315-regulator.yaml new file +5 -0
+            description: |
+              defines other bucks combined with this buck, must contain the following
+              values MT6315_VBUCK1, MT6315_VBUCK2, MT6315_VBUCK3, MT6315_VBUCK4
+
+    unevaluatedProperties: false

'additionalProperties: false' would be better here.

Quoted 4 lines
Documentation/devicetree/bindings/regulator/mtk,mt6315-regulator.yaml new file +4 -0
+
+required:
+  - compatible
+  - reg

Documentation/devicetree/bindings/regulator/mtk,mt6315-regulator.yaml line 66

Quoted 10 lines
Documentation/devicetree/bindings/regulator/mtk,mt6315-regulator.yaml new file +10 -0
+  - regulators
+
+additionalProperties: false
+
+examples:
+  - |
+    /* This example shows that buck2 and buck4 are combined into buck1. */
+    #include <dt-bindings/regulator/mtk,mt6315.h>
+
+    mt6315@6 {

pmic@6

Quoted 32 lines
Documentation/devicetree/bindings/regulator/mtk,mt6315-regulator.yaml new file +22 -0
+      compatible = "mediatek,mt6315_6-regulator";
+      reg = <0x6 0 0xb 1>;
+
+      regulators {
+        vbuck1 {
+          regulator-compatible = "vbuck1";
+          regulator-min-microvolt = <300000>;
+          regulator-max-microvolt = <1193750>;
+          regulator-enable-ramp-delay = <256>;
+          regulator-allowed-modes = <0 1 2 4>;
+          mtk,combined-regulator = <MT6315_VBUCK2 MT6315_VBUCK4>;
+        };
+
+        vbuck3 {
+          regulator-compatible = "vbuck3";
+          regulator-min-microvolt = <300000>;
+          regulator-max-microvolt = <1193750>;
+          regulator-enable-ramp-delay = <256>;
+          regulator-allowed-modes = <0 1 2 4>;
+        };
+      };
+    };
include/dt-bindings/regulator/mtk,mt6315.h new file +4 -0
new file mode 100644
index 000000000000..6ed9b2b121db
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (c) 2020 MediaTek Inc.
+ * Author: Hsin-Hsiung Wang <[email protected]>

include/dt-bindings/regulator/mtk,mt6315.h line 14

Quoted 10 lines
include/dt-bindings/regulator/mtk,mt6315.h new file +10 -0
+ */
+
+#ifndef _DT_BINDINGS_REGULATOR_MTK_MT6315_H
+#define _DT_BINDINGS_REGULATOR_MTK_MT6315_H
+
+/* Regulator ID */
+#define MT6315_VBUCK1	1
+#define MT6315_VBUCK2	2
+#define MT6315_VBUCK3	3
+#define MT6315_VBUCK4	4

I don't find these defines to be that helpful.

Quoted 5 lines
include/dt-bindings/regulator/mtk,mt6315.h new file +3 -0
+#define MT6315_VBUCK_MAX	5
+
+#endif /* _DT_BINDINGS_REGULATOR_MTK_MT6315_H */
Signature · 1 line
2.18.0
#6 lore raw

PATCH v2 3/3 regulator: mt6315: Add support for MT6315 regulator

In reply to Hsin-Hsiung Wang

The MT6315 is a regulator found on boards based on MediaTek MT8192 and probably other SoCs. It connects as a slave to SoC using SPMI.

---
 drivers/regulator/Kconfig                  |  10 +
 drivers/regulator/Makefile                 |   1 +
 drivers/regulator/mt6315-regulator.c       | 364 +++++++++++++++++++++
 include/linux/regulator/mt6315-regulator.h |  37 +++
 4 files changed, 412 insertions(+)
 create mode 100644 drivers/regulator/mt6315-regulator.c
 create mode 100644 include/linux/regulator/mt6315-regulator.h
drivers/regulator/Kconfig +10 -0
index de17ef7e18f0..59544918034e 100644
@@ -693,6 +693,16 @@ config REGULATOR_MT6311
 	  This driver supports the control of different power rails of device
 	  through regulator interface.
 
+config REGULATOR_MT6315
+	tristate "MediaTek MT6315 PMIC"
+	depends on SPMI
+	select REGMAP_SPMI
+	help
+	  Say y here to select this option to enable the power regulator of
+	  MediaTek MT6315 PMIC.
+	  This driver supports the control of different power rails of device
+	  through regulator interface.
+
 config REGULATOR_MT6323
 	tristate "MediaTek MT6323 PMIC"
 	depends on MFD_MT6397
drivers/regulator/Makefile +1 -0
index d8d3ecf526a8..5488e563c60a 100644
@@ -86,6 +86,7 @@ obj-$(CONFIG_REGULATOR_MP8859) += mp8859.o
 obj-$(CONFIG_REGULATOR_MP886X) += mp886x.o
 obj-$(CONFIG_REGULATOR_MPQ7920) += mpq7920.o
 obj-$(CONFIG_REGULATOR_MT6311) += mt6311-regulator.o
+obj-$(CONFIG_REGULATOR_MT6315) += mt6315-regulator.o
 obj-$(CONFIG_REGULATOR_MT6323)	+= mt6323-regulator.o
 obj-$(CONFIG_REGULATOR_MT6358)	+= mt6358-regulator.o
 obj-$(CONFIG_REGULATOR_MT6380)	+= mt6380-regulator.o
drivers/regulator/mt6315-regulator.c new file +364 -0

364 lines not on this page · raw message

include/linux/regulator/mt6315-regulator.h new file +37 -0
new file mode 100644
index 000000000000..4b3bd172cba1
@@ -0,0 +1,37 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2020 MediaTek Inc.
+ */
+
+#ifndef __LINUX_REGULATOR_MT6315_H
+#define __LINUX_REGULATOR_MT6315_H
+
+#define MT6315_SLAVE_ID_3	3
+#define MT6315_SLAVE_ID_6	6
+#define MT6315_SLAVE_ID_7	7
+
+/* Register */
+#define MT6315_SWCID_H				0xb
+#define MT6315_TOP2_ELR7			0x139
+#define MT6315_TOP_TMA_KEY			0x39f
+#define MT6315_TOP_TMA_KEY_H			0x3a0
+#define MT6315_BUCK_TOP_CON0			0x1440
+#define MT6315_BUCK_TOP_CON1			0x1443
+#define MT6315_BUCK_TOP_ELR0			0x1449
+#define MT6315_BUCK_TOP_ELR2			0x144b
+#define MT6315_BUCK_TOP_ELR4			0x144d
+#define MT6315_BUCK_TOP_ELR6			0x144f
+#define MT6315_VBUCK1_DBG0			0x1499
+#define MT6315_VBUCK1_DBG4			0x149d
+#define MT6315_VBUCK2_DBG0			0x1519
+#define MT6315_VBUCK2_DBG4			0x151d
+#define MT6315_VBUCK3_DBG0			0x1599
+#define MT6315_VBUCK3_DBG4			0x159d
+#define MT6315_VBUCK4_DBG0			0x1619
+#define MT6315_VBUCK4_DBG4			0x161d
+#define MT6315_BUCK_TOP_4PHASE_ANA_CON42	0x16b1
+
+#define PROTECTION_KEY_H			0x9C
+#define PROTECTION_KEY				0xEA
+
+#endif /* __LINUX_REGULATOR_MT6315_H */
Signature · 1 line
2.18.0
#7 lore raw

Re: [PATCH v2 3/3] regulator: mt6315: Add support for MT6315 regulator

A number of comments, we might need another pass after you address Rob's comments too.

Quoted 71 lines · Hsin-Hsiung Wang

The MT6315 is a regulator found on boards based on MediaTek MT8192 and probably other SoCs. It connects as a slave to SoC using SPMI.

---
 drivers/regulator/Kconfig                  |  10 +
 drivers/regulator/Makefile                 |   1 +
 drivers/regulator/mt6315-regulator.c       | 364 +++++++++++++++++++++
 include/linux/regulator/mt6315-regulator.h |  37 +++
 4 files changed, 412 insertions(+)
 create mode 100644 drivers/regulator/mt6315-regulator.c
 create mode 100644 include/linux/regulator/mt6315-regulator.h
drivers/regulator/Kconfig +10 -0
index de17ef7e18f0..59544918034e 100644
@@ -693,6 +693,16 @@ config REGULATOR_MT6311
          This driver supports the control of different power rails of device
          through regulator interface.
 
+config REGULATOR_MT6315
+       tristate "MediaTek MT6315 PMIC"
+       depends on SPMI
+       select REGMAP_SPMI
+       help
+         Say y here to select this option to enable the power regulator of
+         MediaTek MT6315 PMIC.
+         This driver supports the control of different power rails of device
+         through regulator interface.
+
 config REGULATOR_MT6323
        tristate "MediaTek MT6323 PMIC"
        depends on MFD_MT6397
drivers/regulator/Makefile +1 -0
index d8d3ecf526a8..5488e563c60a 100644
@@ -86,6 +86,7 @@ obj-$(CONFIG_REGULATOR_MP8859) += mp8859.o
 obj-$(CONFIG_REGULATOR_MP886X) += mp886x.o
 obj-$(CONFIG_REGULATOR_MPQ7920) += mpq7920.o
 obj-$(CONFIG_REGULATOR_MT6311) += mt6311-regulator.o
+obj-$(CONFIG_REGULATOR_MT6315) += mt6315-regulator.o
 obj-$(CONFIG_REGULATOR_MT6323) += mt6323-regulator.o
 obj-$(CONFIG_REGULATOR_MT6358) += mt6358-regulator.o
 obj-$(CONFIG_REGULATOR_MT6380) += mt6380-regulator.o
drivers/regulator/mt6315-regulator.c new file +18 -0
new file mode 100644
index 000000000000..8e3accb2e36f
@@ -0,0 +1,364 @@
+// SPDX-License-Identifier: GPL-2.0
+//
+// Copyright (c) 2020 MediaTek Inc.
+
+#include <dt-bindings/regulator/mtk,mt6315.h>
+#include <linux/interrupt.h>
+#include <linux/module.h>
+#include <linux/of_device.h>
+#include <linux/of_irq.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+#include <linux/regulator/driver.h>
+#include <linux/regulator/machine.h>
+#include <linux/regulator/mt6315-regulator.h>
+#include <linux/regulator/of_regulator.h>
+#include <linux/spmi.h>
+
+#define MT6315_REG_WIDTH       8

drivers/regulator/mt6315-regulator.c line 28

Quoted 10 lines
drivers/regulator/mt6315-regulator.c new file +10 -0
+
+#define MT6315_BUCK_MODE_AUTO          0
+#define MT6315_BUCK_MODE_FORCE_PWM     1
+#define MT6315_BUCK_MODE_LP            2
+
+struct mt6315_regulator_info {
+       struct regulator_desc desc;
+       u32 da_vsel_reg;
+       u32 da_reg;
+       u32 lp_mode_reg;

Always MT6315_BUCK_TOP_CON1, do you really need a field for that?

drivers/regulator/mt6315-regulator.c line 31

Quoted 3 lines
drivers/regulator/mt6315-regulator.c new file +3 -0
+       u32 lp_mode_mask;
+       u32 lp_mode_shift;
+       u32 modeset_reg;

ditto, always MT6315_BUCK_TOP_4PHASE_ANA_CON42.

drivers/regulator/mt6315-regulator.c line 32

Quoted 1 line
drivers/regulator/mt6315-regulator.c new file +1 -0
+       u32 qi;

qi always seems to be BIT(0), do you really need this field?

If so, please use a better name than qi (I'm not sure what that means).

Quoted 112 lines
drivers/regulator/mt6315-regulator.c new file +112 -0
+};
+
+struct mt_regulator_init_data {
+       const struct mt6315_regulator_info *regulator_info;
+       u32 modeset_mask[MT6315_VBUCK_MAX];
+};
+
+struct mt6315_chip {
+       struct device *dev;
+       struct regmap *regmap;
+};
+
+#define MT_BUCK(_name, _bid, _vsel)                            \
+[_bid] = {                                                     \
+       .desc = {                                               \
+               .name = _name,                                  \
+               .of_match = of_match_ptr(_name),                \
+               .regulators_node = "regulators",                \
+               .ops = &mt6315_volt_range_ops,                  \
+               .type = REGULATOR_VOLTAGE,                      \
+               .id = _bid,                                     \
+               .owner = THIS_MODULE,                           \
+               .n_voltages = 0xbf,                             \
+               .linear_ranges = mt_volt_range1,                \
+               .n_linear_ranges = ARRAY_SIZE(mt_volt_range1),  \
+               .vsel_reg = _vsel,                              \
+               .vsel_mask = 0xff,                              \
+               .enable_reg = MT6315_BUCK_TOP_CON0,             \
+               .enable_mask = BIT(_bid - 1),                   \
+               .of_map_mode = mt6315_map_mode,                 \
+       },                                                      \
+       .da_vsel_reg = _bid##_DBG0,                             \
+       .da_reg = _bid##_DBG4,                                  \
+       .lp_mode_reg = MT6315_BUCK_TOP_CON1,                    \
+       .lp_mode_mask = BIT(_bid - 1),                          \
+       .lp_mode_shift = _bid - 1,                              \
+       .modeset_reg = MT6315_BUCK_TOP_4PHASE_ANA_CON42,        \
+       .qi = BIT(0),                                           \
+}
+
+static const struct linear_range mt_volt_range1[] = {
+       REGULATOR_LINEAR_RANGE(0, 0, 0xbf, 6250),
+};
+
+static unsigned int mt6315_map_mode(u32 mode)
+{
+       switch (mode) {
+       case MT6315_BUCK_MODE_AUTO:
+               return REGULATOR_MODE_NORMAL;
+       case MT6315_BUCK_MODE_FORCE_PWM:
+               return REGULATOR_MODE_FAST;
+       case MT6315_BUCK_MODE_LP:
+               return REGULATOR_MODE_IDLE;
+       default:
+               return -EINVAL;
+       }
+}
+
+static int mt6315_regulator_get_voltage_sel(struct regulator_dev *rdev)
+{
+       struct mt_regulator_init_data *init = rdev_get_drvdata(rdev);
+       const struct mt6315_regulator_info *info;
+       int ret, reg_addr, reg_val = 0, reg_en = 0;
+
+       info = &init->regulator_info[rdev_get_id(rdev)];
+       ret = regmap_read(rdev->regmap, info->da_reg, &reg_en);
+       if (ret != 0) {
+               dev_notice(&rdev->dev, "Failed to get enable reg: %d\n", ret);
+               return ret;
+       }
+
+       if (reg_en & info->qi)
+               reg_addr = info->da_vsel_reg;
+       else
+               reg_addr = rdev->desc->vsel_reg;
+
+       ret = regmap_read(rdev->regmap, reg_addr, &reg_val);
+       if (ret != 0) {
+               dev_notice(&rdev->dev, "Failed to get voltage: %d\n", ret);
+               return ret;
+       }
+
+       ret = reg_val & rdev->desc->vsel_mask;
+       return ret;
+}
+
+static unsigned int mt6315_regulator_get_mode(struct regulator_dev *rdev)
+{
+       struct mt_regulator_init_data *init = rdev_get_drvdata(rdev);
+       const struct mt6315_regulator_info *info;
+       int ret = 0, regval = 0;
+       u32 modeset_mask;
+
+       info = &init->regulator_info[rdev_get_id(rdev)];
+       modeset_mask = init->modeset_mask[rdev_get_id(rdev)];
+       ret = regmap_read(rdev->regmap, info->modeset_reg, &regval);
+       if (ret != 0) {
+               dev_notice(&rdev->dev, "Failed to get mode: %d\n", ret);
+               return ret;
+       }
+
+       if ((regval & modeset_mask) == modeset_mask)
+               return REGULATOR_MODE_FAST;
+
+       ret = regmap_read(rdev->regmap, info->lp_mode_reg, &regval);
+       if (ret != 0) {
+               dev_notice(&rdev->dev, "Failed to get lp mode: %d\n", ret);
+               return ret;
+       }
+
+       if (regval & info->lp_mode_mask)
+               return REGULATOR_MODE_IDLE;

drivers/regulator/mt6315-regulator.c

Quoted 10 lines
drivers/regulator/mt6315-regulator.c new file +10 -0
+       else
+               return REGULATOR_MODE_NORMAL;
+}
+
+static int mt6315_regulator_set_mode(struct regulator_dev *rdev,
+                                    u32 mode)
+{
+       struct mt_regulator_init_data *init = rdev_get_drvdata(rdev);
+       const struct mt6315_regulator_info *info;
+       int ret = 0

No need to set ret to 0 (it allows the compiler to figure out that ret is set in all paths, which is good).

, val, curr_mode;

Quoted 27 lines
drivers/regulator/mt6315-regulator.c new file +27 -0
+       u32 modeset_mask;
+
+       info = &init->regulator_info[rdev_get_id(rdev)];
+       modeset_mask = init->modeset_mask[rdev_get_id(rdev)];
+       curr_mode = mt6315_regulator_get_mode(rdev);
+       switch (mode) {
+       case REGULATOR_MODE_FAST:
+               ret = regmap_update_bits(rdev->regmap,
+                                        info->modeset_reg,
+                                        modeset_mask,
+                                        modeset_mask);
+               break;
+       case REGULATOR_MODE_NORMAL:
+               if (curr_mode == REGULATOR_MODE_FAST) {
+                       ret = regmap_update_bits(rdev->regmap,
+                                                info->modeset_reg,
+                                                modeset_mask,
+                                                0);
+               } else if (curr_mode == REGULATOR_MODE_IDLE) {
+                       ret = regmap_update_bits(rdev->regmap,
+                                                info->lp_mode_reg,
+                                                info->lp_mode_mask,
+                                                0);
+                       usleep_range(100, 110);
+               }
+               break;
+       case REGULATOR_MODE_IDLE:

drivers/regulator/mt6315-regulator.c line 191

Quoted 10 lines
drivers/regulator/mt6315-regulator.c new file +10 -0
+               val = MT6315_BUCK_MODE_LP >> 1;
+               val <<= info->lp_mode_shift;
+               ret = regmap_update_bits(rdev->regmap,
+                                        info->lp_mode_reg,
+                                        info->lp_mode_mask,
+                                        val);
+               break;
+       default:
+               ret = -EINVAL;
+               goto err_mode;

Not needed, just break and let it continue.

Quoted 6 lines
drivers/regulator/mt6315-regulator.c new file +6 -0
+       }
+
+err_mode:
+       if (ret != 0) {
+               dev_notice(&rdev->dev, "Failed to set mode: %d\n", ret);
+               return ret;

drivers/regulator/mt6315-regulator.c line 207

Quoted 10 lines
drivers/regulator/mt6315-regulator.c new file +10 -0
+       }
+
+       return 0;
+}
+
+static int mt6315_get_status(struct regulator_dev *rdev)
+{
+       struct mt_regulator_init_data *init = rdev_get_drvdata(rdev);
+       const struct mt6315_regulator_info *info;
+       int ret = 0;

No need to set to 0.

drivers/regulator/mt6315-regulator.c line 212

Quoted 5 lines
drivers/regulator/mt6315-regulator.c new file +5 -0
+       u32 regval = 0;
+
+       info = &init->regulator_info[rdev_get_id(rdev)];
+       ret = regmap_read(rdev->regmap, info->da_reg, &regval);
+       if (ret != 0) {

< 0 ? Just want to make sure we don't accidentally return a positive value.

Quoted 32 lines
drivers/regulator/mt6315-regulator.c new file +32 -0
+               dev_notice(&rdev->dev, "Failed to get enable reg: %d\n", ret);
+               return ret;
+       }
+
+       return (regval & info->qi) ? REGULATOR_STATUS_ON : REGULATOR_STATUS_OFF;
+}
+
+static const struct regulator_ops mt6315_volt_range_ops = {
+       .list_voltage = regulator_list_voltage_linear_range,
+       .map_voltage = regulator_map_voltage_linear_range,
+       .set_voltage_sel = regulator_set_voltage_sel_regmap,
+       .get_voltage_sel = mt6315_regulator_get_voltage_sel,
+       .set_voltage_time_sel = regulator_set_voltage_time_sel,
+       .enable = regulator_enable_regmap,
+       .disable = regulator_disable_regmap,
+       .is_enabled = regulator_is_enabled_regmap,
+       .get_status = mt6315_get_status,
+       .set_mode = mt6315_regulator_set_mode,
+       .get_mode = mt6315_regulator_get_mode,
+};
+
+static const struct mt6315_regulator_info mt6315_regulators[MT6315_VBUCK_MAX] = {
+       MT_BUCK("vbuck1", MT6315_VBUCK1, MT6315_BUCK_TOP_ELR0),
+       MT_BUCK("vbuck2", MT6315_VBUCK2, MT6315_BUCK_TOP_ELR2),
+       MT_BUCK("vbuck3", MT6315_VBUCK3, MT6315_BUCK_TOP_ELR4),
+       MT_BUCK("vbuck4", MT6315_VBUCK4, MT6315_BUCK_TOP_ELR6),
+};
+
+static const struct regmap_config mt6315_regmap_config = {
+       .reg_bits       = 16,
+       .val_bits       = 8,
+       .max_register   = 0x16d0,

drivers/regulator/mt6315-regulator.c line 254

Quoted 10 lines
drivers/regulator/mt6315-regulator.c new file +10 -0
+       .fast_io        = true,
+};
+
+static const struct of_device_id mt6315_of_match[] = {
+       {
+               .compatible = "mediatek,mt6315_3-regulator",
+       }, {
+               .compatible = "mediatek,mt6315_6-regulator",
+       }, {
+               .compatible = "mediatek,mt6315_7-regulator",

Rob already commented on the binding, but I don't think you need 3 compatibles if you don't do anything different for any of them.

(and as I highlighted before, the compatible name should, IMHO, be the part number, not the address)

drivers/regulator/mt6315-regulator.c

Quoted 7 lines
drivers/regulator/mt6315-regulator.c new file +7 -0
+       }, {
+               /* sentinel */
+       },
+};
+MODULE_DEVICE_TABLE(of, mt6315_of_match);
+
+static void mt6315_parsing_dt(struct regulator_dev *rdev

mt6315_parse_dt

Or maybe mt6315_parse_vbuck_dt since this acts on a single regulator/buck?

Quoted 1 line

, u32 *arr)

u32 *used_vbuck_list

drivers/regulator/mt6315-regulator.c line 266

Quoted 5 lines
drivers/regulator/mt6315-regulator.c new file +5 -0
+{
+       struct device_node *np;
+       struct mt_regulator_init_data *init = rdev_get_drvdata(rdev);
+       u32 buck_id, *modeset;
+       int i, icount;

combined_count?

drivers/regulator/mt6315-regulator.c line 276

Quoted 10 lines
drivers/regulator/mt6315-regulator.c new file +10 -0
+
+       np = rdev->dev.of_node;
+       if (!np)
+               return;
+
+       icount = of_property_count_elems_of_size(np, "mtk,combined-regulator", sizeof(u32));
+       if (icount <= 0)
+               return;
+
+       modeset = &init->modeset_mask[rdev_get_id(rdev)];

That's not super readable IMHO.

I'd just

int main_id = rdev_get_id(rdev);
then
init->modeset_mask[main_id] |= BIT(buck_id - 1);

drivers/regulator/mt6315-regulator.c line 282

Quoted 6 lines
drivers/regulator/mt6315-regulator.c new file +6 -0
+       for (i = 0; i < icount; i++) {
+               if (of_property_read_u32_index(np, "mtk,combined-regulator", i, &buck_id))
+                       return;
+
+               if (buck_id < MT6315_VBUCK_MAX) {
+                       /* white list */

/* mark as used */

Quoted 1 line

+ *(arr + buck_id) = 1;

used_vbuck_list[buck_id] = 1;

And maybe first check that used_vbuck_list[buck_id] == 0?

drivers/regulator/mt6315-regulator.c line 285

Quoted 2 lines
drivers/regulator/mt6315-regulator.c new file +2 -0
+                       /* add modeset bit of combined-regulator */
+                       *modeset += BIT(buck_id - 1);

|=

Quoted 4 lines
drivers/regulator/mt6315-regulator.c new file +4 -0
+               }
+       }
+}
+

drivers/regulator/mt6315-regulator.c line 299

Quoted 10 lines
drivers/regulator/mt6315-regulator.c new file +10 -0
+static int mt6315_regulator_probe(struct spmi_device *pdev)
+{
+       struct device *dev = &pdev->dev;
+       struct regmap *regmap;
+       struct mt6315_chip *chip;
+       struct mt_regulator_init_data *init_data;
+       struct regulator_config config = {};
+       struct regulator_dev *rdev;
+       int i;
+       u32 mt6315_dt_list[MT6315_VBUCK_MAX] = {0};

used_vbuck_list

Quoted 110 lines
drivers/regulator/mt6315-regulator.c new file +65 -0
+
+       regmap = devm_regmap_init_spmi_ext(pdev, &mt6315_regmap_config);
+       if (!regmap)
+               return -ENODEV;
+
+       chip = devm_kzalloc(dev, sizeof(struct mt6315_chip), GFP_KERNEL);
+       if (!chip)
+               return -ENOMEM;
+
+       init_data = devm_kzalloc(dev, sizeof(struct mt_regulator_init_data), GFP_KERNEL);
+       if (!init_data)
+               return -ENOMEM;
+
+       chip->dev = dev;
+       chip->regmap = regmap;
+       dev_set_drvdata(dev, chip);
+
+       config.dev = dev;
+       config.regmap = regmap;
+       init_data->regulator_info = mt6315_regulators;
+       for (i = MT6315_VBUCK1; i < MT6315_VBUCK_MAX; i++) {
+               if (mt6315_dt_list[i])
+                       continue;
+
+               init_data->modeset_mask[i] = 1 << (i - 1);
+               config.driver_data = init_data;
+               rdev = devm_regulator_register(dev, &mt6315_regulators[i].desc, &config);
+               if (IS_ERR(rdev)) {
+                       dev_notice(dev, "Failed to register %s\n", mt6315_regulators[i].desc.name);
+                       continue;
+               }
+               mt6315_parsing_dt(rdev, mt6315_dt_list);
+       }
+       return 0;
+}
+
+static void mt6315_regulator_shutdown(struct spmi_device *pdev)
+{
+       struct mt6315_chip *chip = dev_get_drvdata(&pdev->dev);
+       int ret = 0;
+
+       ret |= regmap_write(chip->regmap, MT6315_TOP_TMA_KEY_H, PROTECTION_KEY_H);
+       ret |= regmap_write(chip->regmap, MT6315_TOP_TMA_KEY, PROTECTION_KEY);
+       ret |= regmap_update_bits(chip->regmap, MT6315_TOP2_ELR7, 1, 1);
+       ret |= regmap_write(chip->regmap, MT6315_TOP_TMA_KEY, 0);
+       ret |= regmap_write(chip->regmap, MT6315_TOP_TMA_KEY_H, 0);
+       if (ret < 0)
+               dev_notice(&pdev->dev, "[%#x] Failed to enable power off sequence. %d\n",
+                          pdev->usid, ret);
+}
+
+static struct spmi_driver mt6315_regulator_driver = {
+       .driver         = {
+               .name   = "mt6315-regulator",
+               .of_match_table = mt6315_of_match,
+       },
+       .probe = mt6315_regulator_probe,
+       .shutdown = mt6315_regulator_shutdown,
+};
+
+module_spmi_driver(mt6315_regulator_driver);
+
+MODULE_AUTHOR("Hsin-Hsiung Wang <[email protected]>");
+MODULE_DESCRIPTION("Regulator Driver for MediaTek MT6315 PMIC");
+MODULE_LICENSE("GPL");
include/linux/regulator/mt6315-regulator.h new file +37 -1
new file mode 100644
index 000000000000..4b3bd172cba1
@@ -0,0 +1,37 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2020 MediaTek Inc.
+ */
+
+#ifndef __LINUX_REGULATOR_MT6315_H
+#define __LINUX_REGULATOR_MT6315_H
+
+#define MT6315_SLAVE_ID_3      3
+#define MT6315_SLAVE_ID_6      6
+#define MT6315_SLAVE_ID_7      7
+
+/* Register */
+#define MT6315_SWCID_H                         0xb
+#define MT6315_TOP2_ELR7                       0x139
+#define MT6315_TOP_TMA_KEY                     0x39f
+#define MT6315_TOP_TMA_KEY_H                   0x3a0
+#define MT6315_BUCK_TOP_CON0                   0x1440
+#define MT6315_BUCK_TOP_CON1                   0x1443
+#define MT6315_BUCK_TOP_ELR0                   0x1449
+#define MT6315_BUCK_TOP_ELR2                   0x144b
+#define MT6315_BUCK_TOP_ELR4                   0x144d
+#define MT6315_BUCK_TOP_ELR6                   0x144f
+#define MT6315_VBUCK1_DBG0                     0x1499
+#define MT6315_VBUCK1_DBG4                     0x149d
+#define MT6315_VBUCK2_DBG0                     0x1519
+#define MT6315_VBUCK2_DBG4                     0x151d
+#define MT6315_VBUCK3_DBG0                     0x1599
+#define MT6315_VBUCK3_DBG4                     0x159d
+#define MT6315_VBUCK4_DBG0                     0x1619
+#define MT6315_VBUCK4_DBG4                     0x161d
+#define MT6315_BUCK_TOP_4PHASE_ANA_CON42       0x16b1
+
+#define PROTECTION_KEY_H                       0x9C
+#define PROTECTION_KEY                         0xEA
+
+#endif /* __LINUX_REGULATOR_MT6315_H */
--

2.18.0