* [PATCH v2 0/3] Add support for MT6315 regulator @ 2020-10-20 9:56 Hsin-Hsiung Wang 2020-10-20 9:56 ` [PATCH v2 1/3] spmi: Add driver shutdown support Hsin-Hsiung Wang ` (2 more replies) 0 siblings, 3 replies; 8+ messages in thread From: Hsin-Hsiung Wang @ 2020-10-20 9:56 UTC (permalink / raw) To: Liam Girdwood, Mark Brown, Rob Herring, Matthias Brugger, Stephen Boyd Cc: linux-kernel, devicetree, linux-arm-kernel, linux-mediatek, linux-arm-msm, srv_heupstream, Hsin-Hsiung Wang 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 -- 2.18.0 ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 1/3] spmi: Add driver shutdown support 2020-10-20 9:56 [PATCH v2 0/3] Add support for MT6315 regulator Hsin-Hsiung Wang @ 2020-10-20 9:56 ` Hsin-Hsiung Wang 2020-12-03 8:00 ` Stephen Boyd 2020-10-20 9:56 ` [PATCH v2 2/3] dt-bindings: regulator: document binding for MT6315 regulator Hsin-Hsiung Wang 2020-10-20 9:56 ` [PATCH v2 3/3] regulator: mt6315: Add support " Hsin-Hsiung Wang 2 siblings, 1 reply; 8+ messages in thread From: Hsin-Hsiung Wang @ 2020-10-20 9:56 UTC (permalink / raw) To: Liam Girdwood, Mark Brown, Rob Herring, Matthias Brugger, Stephen Boyd Cc: linux-kernel, devicetree, linux-arm-kernel, linux-mediatek, linux-arm-msm, srv_heupstream, Hsin-Hsiung Wang Add new shutdown() method. Use it in the standard driver model style. Signed-off-by: Hsin-Hsiung Wang <hsin-hsiung.wang@mediatek.com> --- drivers/spmi/spmi.c | 9 +++++++++ include/linux/spmi.h | 1 + 2 files changed, 10 insertions(+) diff --git a/drivers/spmi/spmi.c b/drivers/spmi/spmi.c index c16b60f645a4..161a48ca4acc 100644 --- a/drivers/spmi/spmi.c +++ b/drivers/spmi/spmi.c @@ -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, }; diff --git a/include/linux/spmi.h b/include/linux/spmi.h index 394a3f68bad5..729bcbf9f5ad 100644 --- a/include/linux/spmi.h +++ b/include/linux/spmi.h @@ -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) -- 2.18.0 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v2 1/3] spmi: Add driver shutdown support 2020-10-20 9:56 ` [PATCH v2 1/3] spmi: Add driver shutdown support Hsin-Hsiung Wang @ 2020-12-03 8:00 ` Stephen Boyd 0 siblings, 0 replies; 8+ messages in thread From: Stephen Boyd @ 2020-12-03 8:00 UTC (permalink / raw) To: Hsin-Hsiung Wang, Liam Girdwood, Mark Brown, Matthias Brugger, Rob Herring Cc: linux-kernel, devicetree, linux-arm-kernel, linux-mediatek, linux-arm-msm, srv_heupstream, Hsin-Hsiung Wang Quoting Hsin-Hsiung Wang (2020-10-20 02:56:48) > Add new shutdown() method. Use it in the standard driver model style. > > Signed-off-by: Hsin-Hsiung Wang <hsin-hsiung.wang@mediatek.com> > --- Applied to spmi-next. The line endings are all confused still though. ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 2/3] dt-bindings: regulator: document binding for MT6315 regulator 2020-10-20 9:56 [PATCH v2 0/3] Add support for MT6315 regulator Hsin-Hsiung Wang 2020-10-20 9:56 ` [PATCH v2 1/3] spmi: Add driver shutdown support Hsin-Hsiung Wang @ 2020-10-20 9:56 ` Hsin-Hsiung Wang 2020-10-20 15:31 ` Rob Herring 2020-10-20 15:37 ` Rob Herring 2020-10-20 9:56 ` [PATCH v2 3/3] regulator: mt6315: Add support " Hsin-Hsiung Wang 2 siblings, 2 replies; 8+ messages in thread From: Hsin-Hsiung Wang @ 2020-10-20 9:56 UTC (permalink / raw) To: Liam Girdwood, Mark Brown, Rob Herring, Matthias Brugger, Stephen Boyd Cc: linux-kernel, devicetree, linux-arm-kernel, linux-mediatek, linux-arm-msm, srv_heupstream, Hsin-Hsiung Wang Add device tree binding information for MT6315 regulator driver. Example bindings for MT6315 are added. Signed-off-by: Hsin-Hsiung Wang <hsin-hsiung.wang@mediatek.com> --- .../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 diff --git a/Documentation/devicetree/bindings/regulator/mtk,mt6315-regulator.yaml b/Documentation/devicetree/bindings/regulator/mtk,mt6315-regulator.yaml new file mode 100644 index 000000000000..457606800d5b --- /dev/null +++ b/Documentation/devicetree/bindings/regulator/mtk,mt6315-regulator.yaml @@ -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 <hsin-hsiung.wang@mediatek.com> + +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>; + }; + }; + }; diff --git a/include/dt-bindings/regulator/mtk,mt6315.h b/include/dt-bindings/regulator/mtk,mt6315.h new file mode 100644 index 000000000000..6ed9b2b121db --- /dev/null +++ b/include/dt-bindings/regulator/mtk,mt6315.h @@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (c) 2020 MediaTek Inc. + * Author: Hsin-Hsiung Wang <hsin-hsiung.wang@mediatek.com> + */ + +#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 */ -- 2.18.0 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v2 2/3] dt-bindings: regulator: document binding for MT6315 regulator 2020-10-20 9:56 ` [PATCH v2 2/3] dt-bindings: regulator: document binding for MT6315 regulator Hsin-Hsiung Wang @ 2020-10-20 15:31 ` Rob Herring 2020-10-20 15:37 ` Rob Herring 1 sibling, 0 replies; 8+ messages in thread From: Rob Herring @ 2020-10-20 15:31 UTC (permalink / raw) To: Hsin-Hsiung Wang Cc: Mark Brown, linux-kernel, Liam Girdwood, linux-arm-kernel, Rob Herring, Matthias Brugger, linux-mediatek, linux-arm-msm, devicetree, Stephen Boyd, srv_heupstream On Tue, 20 Oct 2020 17:56:49 +0800, Hsin-Hsiung Wang wrote: > Add device tree binding information for MT6315 regulator driver. > Example bindings for MT6315 are added. > > Signed-off-by: Hsin-Hsiung Wang <hsin-hsiung.wang@mediatek.com> > --- > .../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. ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 2/3] dt-bindings: regulator: document binding for MT6315 regulator 2020-10-20 9:56 ` [PATCH v2 2/3] dt-bindings: regulator: document binding for MT6315 regulator Hsin-Hsiung Wang 2020-10-20 15:31 ` Rob Herring @ 2020-10-20 15:37 ` Rob Herring 1 sibling, 0 replies; 8+ messages in thread From: Rob Herring @ 2020-10-20 15:37 UTC (permalink / raw) To: Hsin-Hsiung Wang Cc: Liam Girdwood, Mark Brown, Matthias Brugger, Stephen Boyd, linux-kernel, devicetree, linux-arm-kernel, linux-mediatek, linux-arm-msm, srv_heupstream On Tue, Oct 20, 2020 at 05:56:49PM +0800, Hsin-Hsiung Wang wrote: > Add device tree binding information for MT6315 regulator driver. > Example bindings for MT6315 are added. > > Signed-off-by: Hsin-Hsiung Wang <hsin-hsiung.wang@mediatek.com> > --- > .../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 > > diff --git a/Documentation/devicetree/bindings/regulator/mtk,mt6315-regulator.yaml b/Documentation/devicetree/bindings/regulator/mtk,mt6315-regulator.yaml > new file mode 100644 > index 000000000000..457606800d5b > --- /dev/null > +++ b/Documentation/devicetree/bindings/regulator/mtk,mt6315-regulator.yaml > @@ -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 <hsin-hsiung.wang@mediatek.com> > + > +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... > + > +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? > + > + reg: > + maxItems: 1 > + > + regulators: > + type: object > + description: List of regulators and its properties > + > + patternProperties: > + "^vbuck[1-4]$": > + type: object regulator.yaml ref goes here. > + > + 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. > + 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. > + > +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 { pmic@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>; > + }; > + }; > + }; > diff --git a/include/dt-bindings/regulator/mtk,mt6315.h b/include/dt-bindings/regulator/mtk,mt6315.h > new file mode 100644 > index 000000000000..6ed9b2b121db > --- /dev/null > +++ b/include/dt-bindings/regulator/mtk,mt6315.h > @@ -0,0 +1,17 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > +/* > + * Copyright (c) 2020 MediaTek Inc. > + * Author: Hsin-Hsiung Wang <hsin-hsiung.wang@mediatek.com> > + */ > + > +#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. > +#define MT6315_VBUCK_MAX 5 > + > +#endif /* _DT_BINDINGS_REGULATOR_MTK_MT6315_H */ > -- > 2.18.0 ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 3/3] regulator: mt6315: Add support for MT6315 regulator 2020-10-20 9:56 [PATCH v2 0/3] Add support for MT6315 regulator Hsin-Hsiung Wang 2020-10-20 9:56 ` [PATCH v2 1/3] spmi: Add driver shutdown support Hsin-Hsiung Wang 2020-10-20 9:56 ` [PATCH v2 2/3] dt-bindings: regulator: document binding for MT6315 regulator Hsin-Hsiung Wang @ 2020-10-20 9:56 ` Hsin-Hsiung Wang 2020-11-11 4:41 ` Nicolas Boichat 2 siblings, 1 reply; 8+ messages in thread From: Hsin-Hsiung Wang @ 2020-10-20 9:56 UTC (permalink / raw) To: Liam Girdwood, Mark Brown, Rob Herring, Matthias Brugger, Stephen Boyd Cc: linux-kernel, devicetree, linux-arm-kernel, linux-mediatek, linux-arm-msm, srv_heupstream, 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. Signed-off-by: Hsin-Hsiung Wang <hsin-hsiung.wang@mediatek.com> --- 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 diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index de17ef7e18f0..59544918034e 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig @@ -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 diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile index d8d3ecf526a8..5488e563c60a 100644 --- a/drivers/regulator/Makefile +++ b/drivers/regulator/Makefile @@ -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 diff --git a/drivers/regulator/mt6315-regulator.c b/drivers/regulator/mt6315-regulator.c new file mode 100644 index 000000000000..8e3accb2e36f --- /dev/null +++ b/drivers/regulator/mt6315-regulator.c @@ -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 + +#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; + u32 lp_mode_mask; + u32 lp_mode_shift; + u32 modeset_reg; + u32 qi; +}; + +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, ®_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, ®_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, ®val); + 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, ®val); + 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; + 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, val, curr_mode; + 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: + 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; + } + +err_mode: + if (ret != 0) { + dev_notice(&rdev->dev, "Failed to set mode: %d\n", ret); + return ret; + } + + 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; + u32 regval = 0; + + info = &init->regulator_info[rdev_get_id(rdev)]; + ret = regmap_read(rdev->regmap, info->da_reg, ®val); + if (ret != 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, + .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", + }, { + /* sentinel */ + }, +}; +MODULE_DEVICE_TABLE(of, mt6315_of_match); + +static void mt6315_parsing_dt(struct regulator_dev *rdev, u32 *arr) +{ + struct device_node *np; + struct mt_regulator_init_data *init = rdev_get_drvdata(rdev); + u32 buck_id, *modeset; + int i, icount; + + 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)]; + 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 */ + *(arr + buck_id) = 1; + /* add modeset bit of combined-regulator */ + *modeset += BIT(buck_id - 1); + } + } +} + +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}; + + 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 <hsin-hsiung.wang@mediatek.com>"); +MODULE_DESCRIPTION("Regulator Driver for MediaTek MT6315 PMIC"); +MODULE_LICENSE("GPL"); diff --git a/include/linux/regulator/mt6315-regulator.h b/include/linux/regulator/mt6315-regulator.h new file mode 100644 index 000000000000..4b3bd172cba1 --- /dev/null +++ b/include/linux/regulator/mt6315-regulator.h @@ -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 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v2 3/3] regulator: mt6315: Add support for MT6315 regulator 2020-10-20 9:56 ` [PATCH v2 3/3] regulator: mt6315: Add support " Hsin-Hsiung Wang @ 2020-11-11 4:41 ` Nicolas Boichat 0 siblings, 0 replies; 8+ messages in thread From: Nicolas Boichat @ 2020-11-11 4:41 UTC (permalink / raw) To: Hsin-Hsiung Wang Cc: Liam Girdwood, Mark Brown, Rob Herring, Matthias Brugger, Stephen Boyd, lkml, Devicetree List, linux-arm Mailing List, moderated list:ARM/Mediatek SoC support, linux-arm-msm, srv_heupstream A number of comments, we might need another pass after you address Rob's comments too. On Tue, Oct 20, 2020 at 5:57 PM Hsin-Hsiung Wang <hsin-hsiung.wang@mediatek.com> wrote: > > 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. > > Signed-off-by: Hsin-Hsiung Wang <hsin-hsiung.wang@mediatek.com> > --- > 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 > > diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig > index de17ef7e18f0..59544918034e 100644 > --- a/drivers/regulator/Kconfig > +++ b/drivers/regulator/Kconfig > @@ -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 > diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile > index d8d3ecf526a8..5488e563c60a 100644 > --- a/drivers/regulator/Makefile > +++ b/drivers/regulator/Makefile > @@ -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 > diff --git a/drivers/regulator/mt6315-regulator.c b/drivers/regulator/mt6315-regulator.c > new file mode 100644 > index 000000000000..8e3accb2e36f > --- /dev/null > +++ b/drivers/regulator/mt6315-regulator.c > @@ -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 > + > +#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? > + u32 lp_mode_mask; > + u32 lp_mode_shift; > + u32 modeset_reg; ditto, always MT6315_BUCK_TOP_4PHASE_ANA_CON42. > + 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). > +}; > + > +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, ®_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, ®_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, ®val); > + 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, ®val); > + 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; > + 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; > + 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: > + 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. > + } > + > +err_mode: > + if (ret != 0) { > + dev_notice(&rdev->dev, "Failed to set mode: %d\n", ret); > + return ret; > + } > + > + 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. > + u32 regval = 0; > + > + info = &init->regulator_info[rdev_get_id(rdev)]; > + ret = regmap_read(rdev->regmap, info->da_reg, ®val); > + if (ret != 0) { < 0 ? Just want to make sure we don't accidentally return a positive value. > + 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, > + .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) > + }, { > + /* 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? > , u32 *arr) u32 *used_vbuck_list > +{ > + struct device_node *np; > + struct mt_regulator_init_data *init = rdev_get_drvdata(rdev); > + u32 buck_id, *modeset; > + int i, icount; combined_count? > + > + 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); > + 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 */ > + *(arr + buck_id) = 1; used_vbuck_list[buck_id] = 1; And maybe first check that used_vbuck_list[buck_id] == 0? > + /* add modeset bit of combined-regulator */ > + *modeset += BIT(buck_id - 1); |= > + } > + } > +} > + > +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 > + > + 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 <hsin-hsiung.wang@mediatek.com>"); > +MODULE_DESCRIPTION("Regulator Driver for MediaTek MT6315 PMIC"); > +MODULE_LICENSE("GPL"); > diff --git a/include/linux/regulator/mt6315-regulator.h b/include/linux/regulator/mt6315-regulator.h > new file mode 100644 > index 000000000000..4b3bd172cba1 > --- /dev/null > +++ b/include/linux/regulator/mt6315-regulator.h > @@ -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 ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2020-12-03 8:01 UTC | newest] Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2020-10-20 9:56 [PATCH v2 0/3] Add support for MT6315 regulator Hsin-Hsiung Wang 2020-10-20 9:56 ` [PATCH v2 1/3] spmi: Add driver shutdown support Hsin-Hsiung Wang 2020-12-03 8:00 ` Stephen Boyd 2020-10-20 9:56 ` [PATCH v2 2/3] dt-bindings: regulator: document binding for MT6315 regulator Hsin-Hsiung Wang 2020-10-20 15:31 ` Rob Herring 2020-10-20 15:37 ` Rob Herring 2020-10-20 9:56 ` [PATCH v2 3/3] regulator: mt6315: Add support " Hsin-Hsiung Wang 2020-11-11 4:41 ` Nicolas Boichat
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).