Skip to content

Commit 512b7d3

Browse files
committed
Merge tag 'mfd-next-5.8' of git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd
Pull MFD updates from Lee Jones: "Core Frameworks: - Constify 'properties' attribute in core header file New Drivers: - Add support for Gateworks System Controller - Add support for MediaTek MT6358 PMIC - Add support for Mediatek MT6360 PMIC - Add support for Monolithic Power Systems MP2629 ADC and Battery charger Fix-ups: - Use new I2C API in htc-i2cpld - Remove superfluous code in sprd-sc27xx-spi - Improve error handling in stm32-timers - Device Tree additions/fixes in mt6397 - Defer probe betterment in wm8994-core - Improve module handling in wm8994-core - Staticify in stpmic1 - Trivial (spelling, formatting) in tqmx86 Bug Fixes: - Fix incorrect register/PCI IDs in intel-lpss-pci - Fix unbalanced Regulator API calls in wm8994-core - Fix double free() in wcd934x - Remove IRQ domain on failure in stmfx - Reset chip on resume in stmfx - Disable/enable IRQs on suspend/resume in stmfx - Do not use bulk writes on H/W which does not support them in max77620" * tag 'mfd-next-5.8' of git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd: (29 commits) mfd: mt6360: Remove duplicate REGMAP_IRQ_REG_LINE() entry mfd: Add support for PMIC MT6360 mfd: max77620: Use single-byte writes on MAX77620 mfd: wcd934x: Drop kfree for memory allocated with devm_kzalloc mfd: stmfx: Disable IRQ in suspend to avoid spurious interrupt mfd: stmfx: Fix stmfx_irq_init error path mfd: stmfx: Reset chip on resume as supply was disabled mfd: wm8994: Silence warning about supplies during deferred probe mfd: wm8994: Fix unbalanced calls to regulator_bulk_disable() mfd: wm8994: Fix driver operation if loaded as modules dt-bindings: mfd: mediatek: Add MT6397 Pin Controller mfd: Constify properties in mfd_cell mfd: stm32-timers: Use dma_request_chan() instead dma_request_slave_channel() mfd: sprd: Remove unnecessary spi_bus_type setting mfd: intel-lpss: Update LPSS UART #2 PCI ID for Jasper Lake mfd: tqmx86: Fix a typo in MODULE_DESCRIPTION mfd: stpmic1: Make stpmic1_regmap_config static mfd: htc-i2cpld: Convert to use i2c_new_client_device() MAINTAINERS: Add entry for mp2629 Battery Charger driver power: supply: mp2629: Add impedance compensation config ...
2 parents acf25aa + 098c4ad commit 512b7d3

37 files changed

+2630
-83
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
What: /sys/class/power_supply/mp2629_battery/batt_impedance_compen
2+
Date: April 2020
3+
KernelVersion: 5.7
4+
Description:
5+
Represents a battery impedance compensation to accelerate charging.
6+
7+
Access: Read, Write
8+
Valid values: Represented in milli-ohms. Valid range is [0, 140].
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
2+
%YAML 1.2
3+
---
4+
$id: http://devicetree.org/schemas/mfd/mps,mp2629.yaml#
5+
$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+
title: MP2629 Battery Charger PMIC from Monolithic Power System.
8+
9+
maintainers:
10+
- Saravanan Sekar <[email protected]>
11+
12+
description: |
13+
MP2629 is a PMIC providing battery charging and power supply for smartphones,
14+
wireless camera and portable devices. Chip is controlled over I2C.
15+
16+
The battery charge management device handles battery charger controller and
17+
ADC IIO device for battery, system voltage
18+
19+
properties:
20+
compatible:
21+
const: mps,mp2629
22+
23+
reg:
24+
maxItems: 1
25+
26+
interrupts:
27+
maxItems: 1
28+
29+
interrupt-controller: true
30+
31+
"#interrupt-cells":
32+
const: 2
33+
description:
34+
The first cell is the IRQ number, the second cell is the trigger type.
35+
36+
required:
37+
- compatible
38+
- reg
39+
- interrupts
40+
- interrupt-controller
41+
- "#interrupt-cells"
42+
43+
additionalProperties: false
44+
45+
examples:
46+
- |
47+
#include <dt-bindings/interrupt-controller/irq.h>
48+
#include <dt-bindings/input/linux-event-codes.h>
49+
i2c {
50+
#address-cells = <1>;
51+
#size-cells = <0>;
52+
53+
pmic@4b {
54+
compatible = "mps,mp2629";
55+
reg = <0x4b>;
56+
57+
interrupt-controller;
58+
interrupt-parent = <&gpio2>;
59+
#interrupt-cells = <2>;
60+
interrupts = <3 IRQ_TYPE_LEVEL_HIGH>;
61+
};
62+
};

Documentation/devicetree/bindings/mfd/mt6397.txt

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,30 @@ See the following for pwarp node definitions:
1818
This document describes the binding for MFD device and its sub module.
1919

2020
Required properties:
21-
compatible: "mediatek,mt6397" or "mediatek,mt6323"
21+
compatible:
22+
"mediatek,mt6323" for PMIC MT6323
23+
"mediatek,mt6358" for PMIC MT6358
24+
"mediatek,mt6397" for PMIC MT6397
2225

2326
Optional subnodes:
2427

2528
- rtc
2629
Required properties: Should be one of follows
2730
- compatible: "mediatek,mt6323-rtc"
31+
- compatible: "mediatek,mt6358-rtc"
2832
- compatible: "mediatek,mt6397-rtc"
2933
For details, see ../rtc/rtc-mt6397.txt
3034
- regulators
3135
Required properties:
32-
- compatible: "mediatek,mt6397-regulator"
33-
see ../regulator/mt6397-regulator.txt
3436
- compatible: "mediatek,mt6323-regulator"
3537
see ../regulator/mt6323-regulator.txt
38+
- compatible: "mediatek,mt6358-regulator"
39+
see ../regulator/mt6358-regulator.txt
40+
- compatible: "mediatek,mt6397-regulator"
41+
see ../regulator/mt6397-regulator.txt
3642
- codec
3743
Required properties:
38-
- compatible: "mediatek,mt6397-codec"
44+
- compatible: "mediatek,mt6397-codec" or "mediatek,mt6358-sound"
3945
- clk
4046
Required properties:
4147
- compatible: "mediatek,mt6397-clk"
@@ -54,6 +60,11 @@ Optional subnodes:
5460
- compatible: "mediatek,mt6323-pwrc"
5561
For details, see ../power/reset/mt6323-poweroff.txt
5662

63+
- pin-controller
64+
Required properties:
65+
- compatible: "mediatek,mt6397-pinctrl"
66+
For details, see ../pinctrl/pinctrl-mt65xx.txt
67+
5768
Example:
5869
pwrap: pwrap@1000f000 {
5970
compatible = "mediatek,mt8135-pwrap";

MAINTAINERS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11474,10 +11474,15 @@ F: kernel/module.c
1147411474
MONOLITHIC POWER SYSTEM PMIC DRIVER
1147511475
M: Saravanan Sekar <[email protected]>
1147611476
S: Maintained
11477+
F: Documentation/devicetree/bindings/mfd/mps,mp2629.yaml
1147711478
F: Documentation/devicetree/bindings/regulator/mps,mp*.yaml
11479+
F: drivers/iio/adc/mp2629_adc.c
11480+
F: drivers/mfd/mp2629.c
11481+
F: drivers/power/supply/mp2629_charger.c
1147811482
F: drivers/regulator/mp5416.c
1147911483
F: drivers/regulator/mpq7920.c
1148011484
F: drivers/regulator/mpq7920.h
11485+
F: include/linux/mfd/mp2629.h
1148111486

1148211487
MOTION EYE VAIO PICTUREBOOK CAMERA DRIVER
1148311488
S: Orphan

drivers/iio/adc/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,16 @@ config MESON_SARADC
692692
To compile this driver as a module, choose M here: the
693693
module will be called meson_saradc.
694694

695+
config MP2629_ADC
696+
tristate "Monolithic MP2629 ADC driver"
697+
depends on MFD_MP2629
698+
help
699+
Say yes to have support for battery charger IC MP2629 ADC device
700+
accessed over I2C.
701+
702+
This driver provides ADC conversion of system, input power supply
703+
and battery voltage & current information.
704+
695705
config NAU7802
696706
tristate "Nuvoton NAU7802 ADC driver"
697707
depends on I2C

drivers/iio/adc/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ obj-$(CONFIG_MCP3911) += mcp3911.o
6565
obj-$(CONFIG_MEDIATEK_MT6577_AUXADC) += mt6577_auxadc.o
6666
obj-$(CONFIG_MEN_Z188_ADC) += men_z188_adc.o
6767
obj-$(CONFIG_MESON_SARADC) += meson_saradc.o
68+
obj-$(CONFIG_MP2629_ADC) += mp2629_adc.o
6869
obj-$(CONFIG_MXS_LRADC_ADC) += mxs-lradc-adc.o
6970
obj-$(CONFIG_NAU7802) += nau7802.o
7071
obj-$(CONFIG_NPCM_ADC) += npcm_adc.o

drivers/iio/adc/mp2629_adc.c

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
/*
3+
* MP2629 Driver for ADC
4+
*
5+
* Copyright 2020 Monolithic Power Systems, Inc
6+
*
7+
* Author: Saravanan Sekar <[email protected]>
8+
*/
9+
10+
#include <linux/iio/driver.h>
11+
#include <linux/iio/iio.h>
12+
#include <linux/iio/machine.h>
13+
#include <linux/mfd/mp2629.h>
14+
#include <linux/module.h>
15+
#include <linux/mutex.h>
16+
#include <linux/platform_device.h>
17+
#include <linux/regmap.h>
18+
19+
#define MP2629_REG_ADC_CTRL 0x03
20+
#define MP2629_REG_BATT_VOLT 0x0e
21+
#define MP2629_REG_SYSTEM_VOLT 0x0f
22+
#define MP2629_REG_INPUT_VOLT 0x11
23+
#define MP2629_REG_BATT_CURRENT 0x12
24+
#define MP2629_REG_INPUT_CURRENT 0x13
25+
26+
#define MP2629_ADC_START BIT(7)
27+
#define MP2629_ADC_CONTINUOUS BIT(6)
28+
29+
#define MP2629_MAP(_mp, _mpc) IIO_MAP(#_mp, "mp2629_charger", "mp2629-"_mpc)
30+
31+
#define MP2629_ADC_CHAN(_ch, _type) { \
32+
.type = _type, \
33+
.indexed = 1, \
34+
.datasheet_name = #_ch, \
35+
.channel = MP2629_ ## _ch, \
36+
.address = MP2629_REG_ ## _ch, \
37+
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
38+
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
39+
}
40+
41+
struct mp2629_adc {
42+
struct regmap *regmap;
43+
struct device *dev;
44+
};
45+
46+
static struct iio_chan_spec mp2629_channels[] = {
47+
MP2629_ADC_CHAN(BATT_VOLT, IIO_VOLTAGE),
48+
MP2629_ADC_CHAN(SYSTEM_VOLT, IIO_VOLTAGE),
49+
MP2629_ADC_CHAN(INPUT_VOLT, IIO_VOLTAGE),
50+
MP2629_ADC_CHAN(BATT_CURRENT, IIO_CURRENT),
51+
MP2629_ADC_CHAN(INPUT_CURRENT, IIO_CURRENT)
52+
};
53+
54+
static struct iio_map mp2629_adc_maps[] = {
55+
MP2629_MAP(BATT_VOLT, "batt-volt"),
56+
MP2629_MAP(SYSTEM_VOLT, "system-volt"),
57+
MP2629_MAP(INPUT_VOLT, "input-volt"),
58+
MP2629_MAP(BATT_CURRENT, "batt-current"),
59+
MP2629_MAP(INPUT_CURRENT, "input-current")
60+
};
61+
62+
static int mp2629_read_raw(struct iio_dev *indio_dev,
63+
struct iio_chan_spec const *chan,
64+
int *val, int *val2, long mask)
65+
{
66+
struct mp2629_adc *info = iio_priv(indio_dev);
67+
unsigned int rval;
68+
int ret;
69+
70+
switch (mask) {
71+
case IIO_CHAN_INFO_RAW:
72+
ret = regmap_read(info->regmap, chan->address, &rval);
73+
if (ret)
74+
return ret;
75+
76+
if (chan->address == MP2629_INPUT_VOLT)
77+
rval &= GENMASK(6, 0);
78+
*val = rval;
79+
return IIO_VAL_INT;
80+
81+
case IIO_CHAN_INFO_SCALE:
82+
switch (chan->channel) {
83+
case MP2629_BATT_VOLT:
84+
case MP2629_SYSTEM_VOLT:
85+
*val = 20;
86+
return IIO_VAL_INT;
87+
88+
case MP2629_INPUT_VOLT:
89+
*val = 60;
90+
return IIO_VAL_INT;
91+
92+
case MP2629_BATT_CURRENT:
93+
*val = 175;
94+
*val2 = 10;
95+
return IIO_VAL_FRACTIONAL;
96+
97+
case MP2629_INPUT_CURRENT:
98+
*val = 133;
99+
*val2 = 10;
100+
return IIO_VAL_FRACTIONAL;
101+
102+
default:
103+
return -EINVAL;
104+
}
105+
106+
default:
107+
return -EINVAL;
108+
}
109+
}
110+
111+
static const struct iio_info mp2629_adc_info = {
112+
.read_raw = &mp2629_read_raw,
113+
};
114+
115+
static int mp2629_adc_probe(struct platform_device *pdev)
116+
{
117+
struct device *dev = &pdev->dev;
118+
struct mp2629_data *ddata = dev_get_drvdata(dev->parent);
119+
struct mp2629_adc *info;
120+
struct iio_dev *indio_dev;
121+
int ret;
122+
123+
indio_dev = devm_iio_device_alloc(dev, sizeof(*info));
124+
if (!indio_dev)
125+
return -ENOMEM;
126+
127+
info = iio_priv(indio_dev);
128+
info->regmap = ddata->regmap;
129+
info->dev = dev;
130+
platform_set_drvdata(pdev, indio_dev);
131+
132+
ret = regmap_update_bits(info->regmap, MP2629_REG_ADC_CTRL,
133+
MP2629_ADC_START | MP2629_ADC_CONTINUOUS,
134+
MP2629_ADC_START | MP2629_ADC_CONTINUOUS);
135+
if (ret) {
136+
dev_err(dev, "adc enable fail: %d\n", ret);
137+
return ret;
138+
}
139+
140+
ret = iio_map_array_register(indio_dev, mp2629_adc_maps);
141+
if (ret) {
142+
dev_err(dev, "IIO maps register fail: %d\n", ret);
143+
goto fail_disable;
144+
}
145+
146+
indio_dev->name = "mp2629-adc";
147+
indio_dev->dev.parent = dev;
148+
indio_dev->channels = mp2629_channels;
149+
indio_dev->num_channels = ARRAY_SIZE(mp2629_channels);
150+
indio_dev->modes = INDIO_DIRECT_MODE;
151+
indio_dev->info = &mp2629_adc_info;
152+
153+
ret = iio_device_register(indio_dev);
154+
if (ret) {
155+
dev_err(dev, "IIO device register fail: %d\n", ret);
156+
goto fail_map_unregister;
157+
}
158+
159+
return 0;
160+
161+
fail_map_unregister:
162+
iio_map_array_unregister(indio_dev);
163+
164+
fail_disable:
165+
regmap_update_bits(info->regmap, MP2629_REG_ADC_CTRL,
166+
MP2629_ADC_CONTINUOUS, 0);
167+
regmap_update_bits(info->regmap, MP2629_REG_ADC_CTRL,
168+
MP2629_ADC_START, 0);
169+
170+
return ret;
171+
}
172+
173+
static int mp2629_adc_remove(struct platform_device *pdev)
174+
{
175+
struct iio_dev *indio_dev = platform_get_drvdata(pdev);
176+
struct mp2629_adc *info = iio_priv(indio_dev);
177+
178+
iio_device_unregister(indio_dev);
179+
180+
iio_map_array_unregister(indio_dev);
181+
182+
regmap_update_bits(info->regmap, MP2629_REG_ADC_CTRL,
183+
MP2629_ADC_CONTINUOUS, 0);
184+
regmap_update_bits(info->regmap, MP2629_REG_ADC_CTRL,
185+
MP2629_ADC_START, 0);
186+
187+
return 0;
188+
}
189+
190+
static const struct of_device_id mp2629_adc_of_match[] = {
191+
{ .compatible = "mps,mp2629_adc"},
192+
{}
193+
};
194+
MODULE_DEVICE_TABLE(of, mp2629_adc_of_match);
195+
196+
static struct platform_driver mp2629_adc_driver = {
197+
.driver = {
198+
.name = "mp2629_adc",
199+
.of_match_table = mp2629_adc_of_match,
200+
},
201+
.probe = mp2629_adc_probe,
202+
.remove = mp2629_adc_remove,
203+
};
204+
module_platform_driver(mp2629_adc_driver);
205+
206+
MODULE_AUTHOR("Saravanan Sekar <[email protected]>");
207+
MODULE_DESCRIPTION("MP2629 ADC driver");
208+
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)