[PATCH v7 5/5] MAINTAINERS: add myself for Marvell 88PM886 PMIC

2024-05-31 Thread Karel Balej
Add an entry to MAINTAINERS for the Marvell 88PM886 PMIC MFD, onkey and
regulator drivers.

Signed-off-by: Karel Balej 
---

Notes:
RFC v3:
- Remove onkey bindings file.
RFC v2:
- Only mention 88PM886 in the commit message.
- Add regulator driver.
- Rename the entry.

 MAINTAINERS | 9 +
 1 file changed, 9 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index d6c90161c7bf..9d6c940029b8 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -13295,6 +13295,15 @@ F: drivers/net/dsa/mv88e6xxx/
 F: include/linux/dsa/mv88e6xxx.h
 F: include/linux/platform_data/mv88e6xxx.h
 
+MARVELL 88PM886 PMIC DRIVER
+M: Karel Balej 
+S: Maintained
+F: Documentation/devicetree/bindings/mfd/marvell,88pm886-a1.yaml
+F: drivers/input/misc/88pm886-onkey.c
+F: drivers/mfd/88pm886.c
+F: drivers/regulators/88pm886-regulator.c
+F: include/linux/mfd/88pm886.h
+
 MARVELL ARMADA 3700 PHY DRIVERS
 M: Miquel Raynal 
 S: Maintained
-- 
2.45.1




[PATCH v7 3/5] regulator: add regulators driver for Marvell 88PM886 PMIC

2024-05-31 Thread Karel Balej
Support the LDO and buck regulators of the Marvell 88PM886 PMIC.

Signed-off-by: Karel Balej 
---

Notes:
v7:
- Address Mark's feedback:
  - Drop get_current_limit op, max_uA values and thus unneeded struct
pm886_regulator and adapt the code accordingly.
v6:
- Remove all definitions (now present in the header).
v5:
- Add remaining regulators.
- Clean up includes.
- Address Mark's feedback:
  - Use dedicated regmap config.
RFC v4:
- Initialize regulators regmap in the regulators driver.
- Register all regulators at once.
- Drop regulator IDs.
- Add missing '\n' to dev_err_probe message.
- Fix includes.
- Add ID table.
RFC v3:
- Do not have a variable for each regulator -- define them all in the
  pm886_regulators array.
- Use new regulators regmap index name.
- Use dev_err_probe.
RFC v2:
- Drop of_compatible and related code.
- Drop unused include.
- Remove some abstraction: use only one regmap for all regulators and
  only mention 88PM886 in Kconfig description.
- Reword commit message.

 drivers/regulator/88pm886-regulator.c | 392 ++
 drivers/regulator/Kconfig |   6 +
 drivers/regulator/Makefile|   1 +
 3 files changed, 399 insertions(+)
 create mode 100644 drivers/regulator/88pm886-regulator.c

diff --git a/drivers/regulator/88pm886-regulator.c 
b/drivers/regulator/88pm886-regulator.c
new file mode 100644
index ..a38bd4f312b7
--- /dev/null
+++ b/drivers/regulator/88pm886-regulator.c
@@ -0,0 +1,392 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+static const struct regmap_config pm886_regulator_regmap_config = {
+   .reg_bits = 8,
+   .val_bits = 8,
+   .max_register = PM886_REG_BUCK5_VOUT,
+};
+
+static const struct regulator_ops pm886_ldo_ops = {
+   .list_voltage = regulator_list_voltage_table,
+   .map_voltage = regulator_map_voltage_iterate,
+   .set_voltage_sel = regulator_set_voltage_sel_regmap,
+   .get_voltage_sel = regulator_get_voltage_sel_regmap,
+   .enable = regulator_enable_regmap,
+   .disable = regulator_disable_regmap,
+   .is_enabled = regulator_is_enabled_regmap,
+};
+
+static const struct regulator_ops pm886_buck_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 = regulator_get_voltage_sel_regmap,
+   .enable = regulator_enable_regmap,
+   .disable = regulator_disable_regmap,
+   .is_enabled = regulator_is_enabled_regmap,
+};
+
+static const unsigned int pm886_ldo_volt_table1[] = {
+   170, 180, 190, 250, 280, 290, 310, 330,
+};
+
+static const unsigned int pm886_ldo_volt_table2[] = {
+   120, 125, 170, 180, 185, 190, 250, 260,
+   270, 275, 280, 285, 290, 300, 310, 330,
+};
+
+static const unsigned int pm886_ldo_volt_table3[] = {
+   170, 180, 190, 200, 210, 250, 270, 280,
+};
+
+static const struct linear_range pm886_buck_volt_ranges1[] = {
+   REGULATOR_LINEAR_RANGE(60, 0, 79, 12500),
+   REGULATOR_LINEAR_RANGE(160, 80, 84, 5),
+};
+
+static const struct linear_range pm886_buck_volt_ranges2[] = {
+   REGULATOR_LINEAR_RANGE(60, 0, 79, 12500),
+   REGULATOR_LINEAR_RANGE(160, 80, 114, 5),
+};
+
+static struct regulator_desc pm886_regulators[] = {
+   {
+   .name = "LDO1",
+   .regulators_node = "regulators",
+   .of_match = "ldo1",
+   .ops = _ldo_ops,
+   .type = REGULATOR_VOLTAGE,
+   .enable_reg = PM886_REG_LDO_EN1,
+   .enable_mask = BIT(0),
+   .volt_table = pm886_ldo_volt_table1,
+   .n_voltages = ARRAY_SIZE(pm886_ldo_volt_table1),
+   .vsel_reg = PM886_REG_LDO1_VOUT,
+   .vsel_mask = PM886_LDO_VSEL_MASK,
+   },
+   {
+   .name = "LDO2",
+   .regulators_node = "regulators",
+   .of_match = "ldo2",
+   .ops = _ldo_ops,
+   .type = REGULATOR_VOLTAGE,
+   .enable_reg = PM886_REG_LDO_EN1,
+   .enable_mask = BIT(1),
+   .volt_table = pm886_ldo_volt_table1,
+   .n_voltages = ARRAY_SIZE(pm886_ldo_volt_table1),
+   .vsel_reg = PM886_REG_LDO2_VOUT,
+   .vsel_mask = PM886_LDO_VSEL_MASK,
+   },
+   {
+   .name = "LDO3",
+   .regulators_node = "regulators",
+   .of_match = "ldo3",
+   .ops = _ldo_ops,
+   .type = REGULATOR_VOLT

[PATCH v7 4/5] input: add onkey driver for Marvell 88PM886 PMIC

2024-05-31 Thread Karel Balej
Marvell 88PM886 PMIC provides onkey among other things. Add client
driver to handle it. The driver currently only provides a basic support
omitting additional functions found in the vendor version, such as long
onkey and GPIO integration.

Acked-by: Dmitry Torokhov 
Signed-off-by: Karel Balej 
---

Notes:
v5:
- Remove kernel.h include.
RFC v4:
- Reflect MFD driver changes:
  - chip->regmaps[...] -> chip->regmap
- Address Dmitry's feedback:
  - Add ID table.
  - Add Ack.
RFC v3:
- Drop wakeup-source.
RFC v2:
- Address Dmitry's feedback:
  - Sort includes alphabetically.
  - Drop onkey->irq.
  - ret -> err in irq_handler and no initialization.
  - Break long lines and other formatting.
  - Do not clobber platform_get_irq error.
  - Do not set device parent manually.
  - Use input_set_capability.
  - Use the wakeup-source DT property.
  - Drop of_match_table.
  - Use more temporaries.
  - Use dev_err_probe.
- Modify Kconfig description.

 drivers/input/misc/88pm886-onkey.c | 98 ++
 drivers/input/misc/Kconfig |  7 +++
 drivers/input/misc/Makefile|  1 +
 3 files changed, 106 insertions(+)
 create mode 100644 drivers/input/misc/88pm886-onkey.c

diff --git a/drivers/input/misc/88pm886-onkey.c 
b/drivers/input/misc/88pm886-onkey.c
new file mode 100644
index ..284ff5190b6e
--- /dev/null
+++ b/drivers/input/misc/88pm886-onkey.c
@@ -0,0 +1,98 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+struct pm886_onkey {
+   struct input_dev *idev;
+   struct pm886_chip *chip;
+};
+
+static irqreturn_t pm886_onkey_irq_handler(int irq, void *data)
+{
+   struct pm886_onkey *onkey = data;
+   struct regmap *regmap = onkey->chip->regmap;
+   struct input_dev *idev = onkey->idev;
+   struct device *parent = idev->dev.parent;
+   unsigned int val;
+   int err;
+
+   err = regmap_read(regmap, PM886_REG_STATUS1, );
+   if (err) {
+   dev_err(parent, "Failed to read status: %d\n", err);
+   return IRQ_NONE;
+   }
+   val &= PM886_ONKEY_STS1;
+
+   input_report_key(idev, KEY_POWER, val);
+   input_sync(idev);
+
+   return IRQ_HANDLED;
+}
+
+static int pm886_onkey_probe(struct platform_device *pdev)
+{
+   struct pm886_chip *chip = dev_get_drvdata(pdev->dev.parent);
+   struct device *dev = >dev;
+   struct pm886_onkey *onkey;
+   struct input_dev *idev;
+   int irq, err;
+
+   onkey = devm_kzalloc(dev, sizeof(*onkey), GFP_KERNEL);
+   if (!onkey)
+   return -ENOMEM;
+
+   onkey->chip = chip;
+
+   irq = platform_get_irq(pdev, 0);
+   if (irq < 0)
+   return dev_err_probe(dev, irq, "Failed to get IRQ\n");
+
+   idev = devm_input_allocate_device(dev);
+   if (!idev) {
+   dev_err(dev, "Failed to allocate input device\n");
+   return -ENOMEM;
+   }
+   onkey->idev = idev;
+
+   idev->name = "88pm886-onkey";
+   idev->phys = "88pm886-onkey/input0";
+   idev->id.bustype = BUS_I2C;
+
+   input_set_capability(idev, EV_KEY, KEY_POWER);
+
+   err = devm_request_threaded_irq(dev, irq, NULL, pm886_onkey_irq_handler,
+   IRQF_ONESHOT | IRQF_NO_SUSPEND, "onkey",
+   onkey);
+   if (err)
+   return dev_err_probe(dev, err, "Failed to request IRQ\n");
+
+   err = input_register_device(idev);
+   if (err)
+   return dev_err_probe(dev, err, "Failed to register input 
device\n");
+
+   return 0;
+}
+
+static const struct platform_device_id pm886_onkey_id_table[] = {
+   { "88pm886-onkey", },
+   { }
+};
+MODULE_DEVICE_TABLE(platform, pm886_onkey_id_table);
+
+static struct platform_driver pm886_onkey_driver = {
+   .driver = {
+   .name = "88pm886-onkey",
+   },
+   .probe = pm886_onkey_probe,
+   .id_table = pm886_onkey_id_table,
+};
+module_platform_driver(pm886_onkey_driver);
+
+MODULE_DESCRIPTION("Marvell 88PM886 onkey driver");
+MODULE_AUTHOR("Karel Balej ");
+MODULE_LICENSE("GPL");
diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index 6ba984d7f0b1..16a079d9f0f2 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -33,6 +33,13 @@ config INPUT_88PM80X_ONKEY
  To compile this driver as a module, choose M here: the module
  will be called 88pm80x_onkey.
 
+config INPUT_88PM886_ONKEY
+   tristate "Marvell 88PM886 onkey support"
+   depends on MFD_88PM886_PMIC
+   help
+ Support the onkey of Marvell 88PM886 PMIC a

[PATCH v7 2/5] mfd: add driver for Marvell 88PM886 PMIC

2024-05-31 Thread Karel Balej
Marvell 88PM886 is a PMIC which provides various functions such as
onkey, battery, charger and regulators. It is found for instance in the
samsung,coreprimevelte smartphone with which this was tested. Implement
basic support to allow for the use of regulators and onkey.

Signed-off-by: Karel Balej 
---

Notes:
v6:
- Address Lee's comments:
  - Don't break long line in the power off handler.
  - Set PLATFORM_DEVID_NONE. This should be safe with respect to
collisions since there are no known devices with more than one of
these PMICs, plus given their general purpose nature it is unlikely
that there would ever be. Also include the corresponding header.
  - Move all defines to the header.
- Give the base page's maximum register its real name.
- Set irq_base to 0.
v5:
- Address Mark's feedback:
  - Move regmap config back out of the header and rename it. Also lower
its maximum register based on what's actually used in the downstream
code.
RFC v4:
- Use MFD_CELL_* macros.
- Address Lee's feedback:
  - Do not define regmap_config.val_bits and .reg_bits.
  - Drop everything regulator related except mfd_cell (regmap
initialization, IDs enum etc.). Drop pm886_initialize_subregmaps.
  - Do not store regmap pointers as an array as there is now only one
regmap. Also drop the corresponding enum.
  - Move regmap_config to the header as it is needed in the regulators
driver.
  - pm886_chip.whoami -> chip_id
  - Reword chip ID mismatch error message and print the ID as
hexadecimal.
  - Fix includes in include/linux/88pm886.h.
  - Drop the pm886_irq_number enum and define the (for the moment) only
IRQ explicitly.
- Have only one MFD cell for all regulators as they are now registered
  all at once in the regulators driver.
- Reword commit message.
- Make device table static and remove comma after the sentinel to signal
  that nothing should come after it.
RFC v3:
- Drop onkey cell .of_compatible.
- Rename LDO page offset and regmap to REGULATORS.
RFC v2:
- Remove some abstraction.
- Sort includes alphabetically and add linux/of.h.
- Depend on OF, remove of_match_ptr and add MODULE_DEVICE_TABLE.
- Use more temporaries and break long lines.
- Do not initialize ret in probe.
- Use the wakeup-source DT property.
- Rename ret to err.
- Address Lee's comments:
  - Drop patched in presets for base regmap and related defines.
  - Use full sentences in comments.
  - Remove IRQ comment.
  - Define regmap_config member values.
  - Rename data to sys_off_data.
  - Add _PMIC suffix to Kconfig.
  - Use dev_err_probe.
  - Do not store irq_data.
  - s/WHOAMI/CHIP_ID
  - Drop LINUX part of include guard name.
  - Merge in the regulator series modifications in order to have more
devices and modify the commit message accordingly. Changes with
respect to the original regulator series patches:
- ret -> err
- Add temporary for dev in pm88x_initialize_subregmaps.
- Drop of_compatible for the regulators.
- Do not duplicate LDO regmap for bucks.
- Rewrite commit message.

Friday late afternoon counts as a weekend too...

 drivers/mfd/88pm886.c   | 148 
 drivers/mfd/Kconfig |  12 +++
 drivers/mfd/Makefile|   1 +
 include/linux/mfd/88pm886.h |  69 +
 4 files changed, 230 insertions(+)
 create mode 100644 drivers/mfd/88pm886.c
 create mode 100644 include/linux/mfd/88pm886.h

diff --git a/drivers/mfd/88pm886.c b/drivers/mfd/88pm886.c
new file mode 100644
index ..dbe9efc027d2
--- /dev/null
+++ b/drivers/mfd/88pm886.c
@@ -0,0 +1,148 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+static const struct regmap_config pm886_regmap_config = {
+   .reg_bits = 8,
+   .val_bits = 8,
+   .max_register = PM886_REG_RTC_SPARE6,
+};
+
+static struct regmap_irq pm886_regmap_irqs[] = {
+   REGMAP_IRQ_REG(PM886_IRQ_ONKEY, 0, PM886_INT_ENA1_ONKEY),
+};
+
+static struct regmap_irq_chip pm886_regmap_irq_chip = {
+   .name = "88pm886",
+   .irqs = pm886_regmap_irqs,
+   .num_irqs = ARRAY_SIZE(pm886_regmap_irqs),
+   .num_regs = 4,
+   .status_base = PM886_REG_INT_STATUS1,
+   .ack_base = PM886_REG_INT_STATUS1,
+   .unmask_base = PM886_REG_INT_ENA_1,
+};
+
+static struct resource pm886_onkey_resources[] = {
+   DEFINE_RES_IRQ_NAMED(PM886_IRQ_ONKEY, "88pm886-onkey"),
+};
+
+static struct mfd_cell pm886_devs[] = {
+   MFD_CELL_RES("88pm886-onkey", pm886_onkey_resources),
+   MFD_CELL_NAME("88pm886-regulator"),
+};
+
+static int pm886_power_off_handler(struct sys_off_data *sy

[PATCH v7 1/5] dt-bindings: mfd: add entry for Marvell 88PM886 PMIC

2024-05-31 Thread Karel Balej
Marvell 88PM886 is a PMIC with several subdevices such as onkey,
regulators or battery and charger. It comes in at least two revisions,
A0 and A1 -- only A1 is described here at the moment.

Reviewed-by: Krzysztof Kozlowski 
Signed-off-by: Karel Balej 
---

Notes:
RFC v4:
- Address Krzysztof's comments:
  - Fix regulators indentation.
  - Add Krzysztof's trailer.
RFC v3:
- Add wakeup-source property.
- Address Rob's feedback:
  - Move regulators into the MFD file.
  - Remove interrupt-controller and #interrupt-cells properties.
RFC v2:
- Address Rob's feedback:
  - Drop mention of 88PM880.
  - Make sure the file passes bindings check (add the necessary header
and fix `interrupt-cells`).
  - Other small changes.
- Add regulators. Changes with respect to the regulator RFC series:
  - Address Krzysztof's comments:
- Drop unused compatible.
- Fix sub-node pattern.

 .../bindings/mfd/marvell,88pm886-a1.yaml  | 76 +++
 1 file changed, 76 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/mfd/marvell,88pm886-a1.yaml

diff --git a/Documentation/devicetree/bindings/mfd/marvell,88pm886-a1.yaml 
b/Documentation/devicetree/bindings/mfd/marvell,88pm886-a1.yaml
new file mode 100644
index ..d6a71c912b76
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/marvell,88pm886-a1.yaml
@@ -0,0 +1,76 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/marvell,88pm886-a1.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Marvell 88PM886 PMIC core
+
+maintainers:
+  - Karel Balej 
+
+description:
+  Marvell 88PM886 is a PMIC providing several functions such as onkey,
+  regulators or battery and charger.
+
+properties:
+  compatible:
+const: marvell,88pm886-a1
+
+  reg:
+maxItems: 1
+
+  interrupts:
+maxItems: 1
+
+  wakeup-source: true
+
+  regulators:
+type: object
+additionalProperties: false
+patternProperties:
+  "^(ldo(1[0-6]|[1-9])|buck[1-5])$":
+type: object
+$ref: /schemas/regulator/regulator.yaml#
+description: LDO or buck regulator.
+unevaluatedProperties: false
+
+required:
+  - compatible
+  - reg
+  - interrupts
+
+additionalProperties: false
+
+examples:
+  - |
+#include 
+i2c {
+  #address-cells = <1>;
+  #size-cells = <0>;
+  pmic@30 {
+compatible = "marvell,88pm886-a1";
+reg = <0x30>;
+interrupts = <0 4 IRQ_TYPE_LEVEL_HIGH>;
+interrupt-parent = <>;
+wakeup-source;
+
+regulators {
+  ldo2: ldo2 {
+regulator-min-microvolt = <310>;
+regulator-max-microvolt = <330>;
+  };
+
+  ldo15: ldo15 {
+regulator-min-microvolt = <330>;
+regulator-max-microvolt = <330>;
+  };
+
+  buck2: buck2 {
+regulator-min-microvolt = <180>;
+regulator-max-microvolt = <180>;
+  };
+};
+  };
+};
+...
-- 
2.45.1




[PATCH v7 0/5] initial support for Marvell 88PM886 PMIC

2024-05-31 Thread Karel Balej
Hello,

the following implements basic support for Marvell's 88PM886 PMIC which
is found for instance as a component of the samsung,coreprimevelte
smartphone which inspired this and also serves as a testing platform.

The code for the MFD is based primarily on this old series [1] with the
addition of poweroff based on the smartphone's downstream kernel tree
[2]. The onkey and regulators drivers are based on the latter. I am not
in possesion of the datasheet.

[1] 
https://lore.kernel.org/all/1434098601-3498-1-git-send-email-yizh...@marvell.com/
[2] https://github.com/CoderCharmander/g361f-kernel

Thank you, kind regards,
K. B.
---
v7:
- Rebase to v6.10-rc1.
- v6: https://lore.kernel.org/r/20240504194632.2456-1-bal...@matfyz.cz/
v6:
- Rebase to v6.9-rc6.
- Fix patchset versioning: the previous version was marked as v1 because I
  considered RFC to be its own thing. Thank you to Krzysztof for
  explaining that that is not the case. The previous version is thus now
  marked as v5 and this is v6, sorry for any confusion.
- v5: https://lore.kernel.org/r/20240331105608.7338-2-bal...@matfyz.cz/
v5:
- RFC v4: 
https://lore.kernel.org/r/20240311160110.32185-1-kar...@gimli.ms.mff.cuni.cz/
- Rebase to v6.9-rc1.
- Thank you to everybody for their feedback on the RFC!
RFC v4:
- RFC v3: 
https://lore.kernel.org/all/20240303101506.4187-1-kar...@gimli.ms.mff.cuni.cz/
RFC v3:
- Address Rob's feedback:
  - Drop onkey bindings patch.
- Rename PM88X -> PM886 everywhere.
- RFC v2: 
https://lore.kernel.org/all/20240211094609.2223-1-kar...@gimli.ms.mff.cuni.cz/
RFC v2:
- Merge with the regulators series to have multiple devices and thus
  justify the use of the MFD framework.
- Rebase on v6.8-rc3.
- Reorder patches.
- MFD RFC v1: 
https://lore.kernel.org/all/20231217131838.7569-1-kar...@gimli.ms.mff.cuni.cz/
- regulators RFC v1: 
https://lore.kernel.org/all/20231228100208.2932-1-kar...@gimli.ms.mff.cuni.cz/

Karel Balej (5):
  dt-bindings: mfd: add entry for Marvell 88PM886 PMIC
  mfd: add driver for Marvell 88PM886 PMIC
  regulator: add regulators driver for Marvell 88PM886 PMIC
  input: add onkey driver for Marvell 88PM886 PMIC
  MAINTAINERS: add myself for Marvell 88PM886 PMIC

 .../bindings/mfd/marvell,88pm886-a1.yaml  |  76 
 MAINTAINERS   |   9 +
 drivers/input/misc/88pm886-onkey.c|  98 +
 drivers/input/misc/Kconfig|   7 +
 drivers/input/misc/Makefile   |   1 +
 drivers/mfd/88pm886.c | 148 +++
 drivers/mfd/Kconfig   |  12 +
 drivers/mfd/Makefile  |   1 +
 drivers/regulator/88pm886-regulator.c | 392 ++
 drivers/regulator/Kconfig |   6 +
 drivers/regulator/Makefile|   1 +
 include/linux/mfd/88pm886.h   |  69 +++
 12 files changed, 820 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/mfd/marvell,88pm886-a1.yaml
 create mode 100644 drivers/input/misc/88pm886-onkey.c
 create mode 100644 drivers/mfd/88pm886.c
 create mode 100644 drivers/regulator/88pm886-regulator.c
 create mode 100644 include/linux/mfd/88pm886.h

-- 
2.45.1




Re: [PATCH v6 2/5] mfd: add driver for Marvell 88PM886 PMIC

2024-05-31 Thread Karel Balej
Lee Jones, 2024-05-31T11:24:52+01:00:
> Are you planning on seeing to Mark's review comments?

Indeed, I'm hoping that I will be able to send it over the weekend.

K. B.



Re: [PATCH v6 3/5] regulator: add regulators driver for Marvell 88PM886 PMIC

2024-05-05 Thread Karel Balej
Mark Brown, 2024-05-06T00:15:01+09:00:
> On Sat, May 04, 2024 at 09:37:06PM +0200, Karel Balej wrote:
>
> > +static const struct regulator_ops pm886_ldo_ops = {
> > +   .list_voltage = regulator_list_voltage_table,
> > +   .map_voltage = regulator_map_voltage_iterate,
> > +   .set_voltage_sel = regulator_set_voltage_sel_regmap,
> > +   .get_voltage_sel = regulator_get_voltage_sel_regmap,
> > +   .enable = regulator_enable_regmap,
> > +   .disable = regulator_disable_regmap,
> > +   .is_enabled = regulator_is_enabled_regmap,
> > +   .get_current_limit = pm886_regulator_get_ilim,
>
> Do these regulators actually enforce this limit or is this just a spec
> limit beyond which regulation may fail?  If it's just a spec limit I'd
> not expect this operation to be provided, it's more for a hard limit
> where the regulator will detect and act on issues.  I don't see an error
> interrupt or anything and this would be an unusual feature for a LDO.

I'm afraid I don't have the answer -- my only reference is the vendor
version of the driver and I don't see anything there based on which I
would be able to tell.

But based on what you write, my guess would be that it's just a spec limit.

Should I then drop this op and the max_uA values from all the
regulators?

Thank you,
K. B.



[PATCH v6 1/5] dt-bindings: mfd: add entry for Marvell 88PM886 PMIC

2024-05-04 Thread Karel Balej
Marvell 88PM886 is a PMIC with several subdevices such as onkey,
regulators or battery and charger. It comes in at least two revisions,
A0 and A1 -- only A1 is described here at the moment.

Reviewed-by: Krzysztof Kozlowski 
Signed-off-by: Karel Balej 
---

Notes:
RFC v4:
- Address Krzysztof's comments:
  - Fix regulators indentation.
  - Add Krzysztof's trailer.
RFC v3:
- Add wakeup-source property.
- Address Rob's feedback:
  - Move regulators into the MFD file.
  - Remove interrupt-controller and #interrupt-cells properties.
RFC v2:
- Address Rob's feedback:
  - Drop mention of 88PM880.
  - Make sure the file passes bindings check (add the necessary header
and fix `interrupt-cells`).
  - Other small changes.
- Add regulators. Changes with respect to the regulator RFC series:
  - Address Krzysztof's comments:
- Drop unused compatible.
- Fix sub-node pattern.

 .../bindings/mfd/marvell,88pm886-a1.yaml  | 76 +++
 1 file changed, 76 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/mfd/marvell,88pm886-a1.yaml

diff --git a/Documentation/devicetree/bindings/mfd/marvell,88pm886-a1.yaml 
b/Documentation/devicetree/bindings/mfd/marvell,88pm886-a1.yaml
new file mode 100644
index ..d6a71c912b76
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/marvell,88pm886-a1.yaml
@@ -0,0 +1,76 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/marvell,88pm886-a1.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Marvell 88PM886 PMIC core
+
+maintainers:
+  - Karel Balej 
+
+description:
+  Marvell 88PM886 is a PMIC providing several functions such as onkey,
+  regulators or battery and charger.
+
+properties:
+  compatible:
+const: marvell,88pm886-a1
+
+  reg:
+maxItems: 1
+
+  interrupts:
+maxItems: 1
+
+  wakeup-source: true
+
+  regulators:
+type: object
+additionalProperties: false
+patternProperties:
+  "^(ldo(1[0-6]|[1-9])|buck[1-5])$":
+type: object
+$ref: /schemas/regulator/regulator.yaml#
+description: LDO or buck regulator.
+unevaluatedProperties: false
+
+required:
+  - compatible
+  - reg
+  - interrupts
+
+additionalProperties: false
+
+examples:
+  - |
+#include 
+i2c {
+  #address-cells = <1>;
+  #size-cells = <0>;
+  pmic@30 {
+compatible = "marvell,88pm886-a1";
+reg = <0x30>;
+interrupts = <0 4 IRQ_TYPE_LEVEL_HIGH>;
+interrupt-parent = <>;
+wakeup-source;
+
+regulators {
+  ldo2: ldo2 {
+regulator-min-microvolt = <310>;
+regulator-max-microvolt = <330>;
+  };
+
+  ldo15: ldo15 {
+regulator-min-microvolt = <330>;
+regulator-max-microvolt = <330>;
+  };
+
+  buck2: buck2 {
+regulator-min-microvolt = <180>;
+regulator-max-microvolt = <180>;
+  };
+};
+  };
+};
+...
-- 
2.45.0




[PATCH v6 0/5] initial support for Marvell 88PM886 PMIC

2024-05-04 Thread Karel Balej
Hello,

the following implements basic support for Marvell's 88PM886 PMIC which
is found for instance as a component of the samsung,coreprimevelte
smartphone which inspired this and also serves as a testing platform.

The code for the MFD is based primarily on this old series [1] with the
addition of poweroff based on the smartphone's downstream kernel tree
[2]. The onkey and regulators drivers are based on the latter. I am not
in possesion of the datasheet.

[1] 
https://lore.kernel.org/all/1434098601-3498-1-git-send-email-yizh...@marvell.com/
[2] https://github.com/CoderCharmander/g361f-kernel

Thank you and kind regards,
K. B.
---
v6:
- Rebase to v6.9-rc6.
- Fix patchset versioning: the previous version was marked as v1 because I
  considered RFC to be its own thing. Thank you to Krzysztof for
  explaining that that is not the case. The previous version is thus now
  marked as v5 and this is v6, sorry for any confusion.
- v5: https://lore.kernel.org/r/20240331105608.7338-2-bal...@matfyz.cz/
v5:
- RFC v4: 
https://lore.kernel.org/r/20240311160110.32185-1-kar...@gimli.ms.mff.cuni.cz/
- Rebase to v6.9-rc1.
- Thank you to everybody for their feedback on the RFC!
RFC v4:
- RFC v3: 
https://lore.kernel.org/all/20240303101506.4187-1-kar...@gimli.ms.mff.cuni.cz/
RFC v3:
- Address Rob's feedback:
  - Drop onkey bindings patch.
- Rename PM88X -> PM886 everywhere.
- RFC v2: 
https://lore.kernel.org/all/20240211094609.2223-1-kar...@gimli.ms.mff.cuni.cz/
RFC v2:
- Merge with the regulators series to have multiple devices and thus
  justify the use of the MFD framework.
- Rebase on v6.8-rc3.
- Reorder patches.
- MFD RFC v1: 
https://lore.kernel.org/all/20231217131838.7569-1-kar...@gimli.ms.mff.cuni.cz/
- regulators RFC v1: 
https://lore.kernel.org/all/20231228100208.2932-1-kar...@gimli.ms.mff.cuni.cz/

Karel Balej (5):
  dt-bindings: mfd: add entry for Marvell 88PM886 PMIC
  mfd: add driver for Marvell 88PM886 PMIC
  regulator: add regulators driver for Marvell 88PM886 PMIC
  input: add onkey driver for Marvell 88PM886 PMIC
  MAINTAINERS: add myself for Marvell 88PM886 PMIC

 .../bindings/mfd/marvell,88pm886-a1.yaml  |  76 +++
 MAINTAINERS   |   9 +
 drivers/input/misc/88pm886-onkey.c|  98 
 drivers/input/misc/Kconfig|   7 +
 drivers/input/misc/Makefile   |   1 +
 drivers/mfd/88pm886.c | 148 ++
 drivers/mfd/Kconfig   |  12 +
 drivers/mfd/Makefile  |   1 +
 drivers/regulator/88pm886-regulator.c | 476 ++
 drivers/regulator/Kconfig |   6 +
 drivers/regulator/Makefile|   1 +
 include/linux/mfd/88pm886.h   |  69 +++
 12 files changed, 904 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/mfd/marvell,88pm886-a1.yaml
 create mode 100644 drivers/input/misc/88pm886-onkey.c
 create mode 100644 drivers/mfd/88pm886.c
 create mode 100644 drivers/regulator/88pm886-regulator.c
 create mode 100644 include/linux/mfd/88pm886.h

-- 
2.45.0




[PATCH v6 5/5] MAINTAINERS: add myself for Marvell 88PM886 PMIC

2024-05-04 Thread Karel Balej
Add an entry to MAINTAINERS for the Marvell 88PM886 PMIC MFD, onkey and
regulator drivers.

Signed-off-by: Karel Balej 
---

Notes:
RFC v3:
- Remove onkey bindings file.
RFC v2:
- Only mention 88PM886 in the commit message.
- Add regulator driver.
- Rename the entry.

 MAINTAINERS | 9 +
 1 file changed, 9 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index f6dc90559341..e1a0e02e098d 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -13044,6 +13044,15 @@ F: drivers/net/dsa/mv88e6xxx/
 F: include/linux/dsa/mv88e6xxx.h
 F: include/linux/platform_data/mv88e6xxx.h
 
+MARVELL 88PM886 PMIC DRIVER
+M: Karel Balej 
+S: Maintained
+F: Documentation/devicetree/bindings/mfd/marvell,88pm886-a1.yaml
+F: drivers/input/misc/88pm886-onkey.c
+F: drivers/mfd/88pm886.c
+F: drivers/regulators/88pm886-regulator.c
+F: include/linux/mfd/88pm886.h
+
 MARVELL ARMADA 3700 PHY DRIVERS
 M: Miquel Raynal 
 S: Maintained
-- 
2.45.0




[PATCH v6 4/5] input: add onkey driver for Marvell 88PM886 PMIC

2024-05-04 Thread Karel Balej
Marvell 88PM886 PMIC provides onkey among other things. Add client
driver to handle it. The driver currently only provides a basic support
omitting additional functions found in the vendor version, such as long
onkey and GPIO integration.

Acked-by: Dmitry Torokhov 
Signed-off-by: Karel Balej 
---

Notes:
v5:
- Remove kernel.h include.
RFC v4:
- Reflect MFD driver changes:
  - chip->regmaps[...] -> chip->regmap
- Address Dmitry's feedback:
  - Add ID table.
  - Add Ack.
RFC v3:
- Drop wakeup-source.
RFC v2:
- Address Dmitry's feedback:
  - Sort includes alphabetically.
  - Drop onkey->irq.
  - ret -> err in irq_handler and no initialization.
  - Break long lines and other formatting.
  - Do not clobber platform_get_irq error.
  - Do not set device parent manually.
  - Use input_set_capability.
  - Use the wakeup-source DT property.
  - Drop of_match_table.
  - Use more temporaries.
  - Use dev_err_probe.
- Modify Kconfig description.

 drivers/input/misc/88pm886-onkey.c | 98 ++
 drivers/input/misc/Kconfig |  7 +++
 drivers/input/misc/Makefile|  1 +
 3 files changed, 106 insertions(+)
 create mode 100644 drivers/input/misc/88pm886-onkey.c

diff --git a/drivers/input/misc/88pm886-onkey.c 
b/drivers/input/misc/88pm886-onkey.c
new file mode 100644
index ..284ff5190b6e
--- /dev/null
+++ b/drivers/input/misc/88pm886-onkey.c
@@ -0,0 +1,98 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+struct pm886_onkey {
+   struct input_dev *idev;
+   struct pm886_chip *chip;
+};
+
+static irqreturn_t pm886_onkey_irq_handler(int irq, void *data)
+{
+   struct pm886_onkey *onkey = data;
+   struct regmap *regmap = onkey->chip->regmap;
+   struct input_dev *idev = onkey->idev;
+   struct device *parent = idev->dev.parent;
+   unsigned int val;
+   int err;
+
+   err = regmap_read(regmap, PM886_REG_STATUS1, );
+   if (err) {
+   dev_err(parent, "Failed to read status: %d\n", err);
+   return IRQ_NONE;
+   }
+   val &= PM886_ONKEY_STS1;
+
+   input_report_key(idev, KEY_POWER, val);
+   input_sync(idev);
+
+   return IRQ_HANDLED;
+}
+
+static int pm886_onkey_probe(struct platform_device *pdev)
+{
+   struct pm886_chip *chip = dev_get_drvdata(pdev->dev.parent);
+   struct device *dev = >dev;
+   struct pm886_onkey *onkey;
+   struct input_dev *idev;
+   int irq, err;
+
+   onkey = devm_kzalloc(dev, sizeof(*onkey), GFP_KERNEL);
+   if (!onkey)
+   return -ENOMEM;
+
+   onkey->chip = chip;
+
+   irq = platform_get_irq(pdev, 0);
+   if (irq < 0)
+   return dev_err_probe(dev, irq, "Failed to get IRQ\n");
+
+   idev = devm_input_allocate_device(dev);
+   if (!idev) {
+   dev_err(dev, "Failed to allocate input device\n");
+   return -ENOMEM;
+   }
+   onkey->idev = idev;
+
+   idev->name = "88pm886-onkey";
+   idev->phys = "88pm886-onkey/input0";
+   idev->id.bustype = BUS_I2C;
+
+   input_set_capability(idev, EV_KEY, KEY_POWER);
+
+   err = devm_request_threaded_irq(dev, irq, NULL, pm886_onkey_irq_handler,
+   IRQF_ONESHOT | IRQF_NO_SUSPEND, "onkey",
+   onkey);
+   if (err)
+   return dev_err_probe(dev, err, "Failed to request IRQ\n");
+
+   err = input_register_device(idev);
+   if (err)
+   return dev_err_probe(dev, err, "Failed to register input 
device\n");
+
+   return 0;
+}
+
+static const struct platform_device_id pm886_onkey_id_table[] = {
+   { "88pm886-onkey", },
+   { }
+};
+MODULE_DEVICE_TABLE(platform, pm886_onkey_id_table);
+
+static struct platform_driver pm886_onkey_driver = {
+   .driver = {
+   .name = "88pm886-onkey",
+   },
+   .probe = pm886_onkey_probe,
+   .id_table = pm886_onkey_id_table,
+};
+module_platform_driver(pm886_onkey_driver);
+
+MODULE_DESCRIPTION("Marvell 88PM886 onkey driver");
+MODULE_AUTHOR("Karel Balej ");
+MODULE_LICENSE("GPL");
diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index 6ba984d7f0b1..16a079d9f0f2 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -33,6 +33,13 @@ config INPUT_88PM80X_ONKEY
  To compile this driver as a module, choose M here: the module
  will be called 88pm80x_onkey.
 
+config INPUT_88PM886_ONKEY
+   tristate "Marvell 88PM886 onkey support"
+   depends on MFD_88PM886_PMIC
+   help
+ Support the onkey of Marvell 88PM886 PMIC a

[PATCH v6 3/5] regulator: add regulators driver for Marvell 88PM886 PMIC

2024-05-04 Thread Karel Balej
Support the LDO and buck regulators of the Marvell 88PM886 PMIC.

Signed-off-by: Karel Balej 
---

Notes:
v6:
- Remove all definitions (now present in the header).
v5:
- Add remaining regulators.
- Clean up includes.
- Address Mark's feedback:
  - Use dedicated regmap config.
RFC v4:
- Initialize regulators regmap in the regulators driver.
- Register all regulators at once.
- Drop regulator IDs.
- Add missing '\n' to dev_err_probe message.
- Fix includes.
- Add ID table.
RFC v3:
- Do not have a variable for each regulator -- define them all in the
  pm886_regulators array.
- Use new regulators regmap index name.
- Use dev_err_probe.
RFC v2:
- Drop of_compatible and related code.
- Drop unused include.
- Remove some abstraction: use only one regmap for all regulators and
  only mention 88PM886 in Kconfig description.
- Reword commit message.

 drivers/regulator/88pm886-regulator.c | 476 ++
 drivers/regulator/Kconfig |   6 +
 drivers/regulator/Makefile|   1 +
 3 files changed, 483 insertions(+)
 create mode 100644 drivers/regulator/88pm886-regulator.c

diff --git a/drivers/regulator/88pm886-regulator.c 
b/drivers/regulator/88pm886-regulator.c
new file mode 100644
index ..7d6e113c93b3
--- /dev/null
+++ b/drivers/regulator/88pm886-regulator.c
@@ -0,0 +1,476 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+static const struct regmap_config pm886_regulator_regmap_config = {
+   .reg_bits = 8,
+   .val_bits = 8,
+   .max_register = PM886_REG_BUCK5_VOUT,
+};
+
+struct pm886_regulator {
+   struct regulator_desc desc;
+   int max_uA;
+};
+
+static int pm886_regulator_get_ilim(struct regulator_dev *rdev)
+{
+   struct pm886_regulator *data = rdev_get_drvdata(rdev);
+
+   if (!data) {
+   dev_err(>dev, "Failed to get regulator data\n");
+   return -EINVAL;
+   }
+   return data->max_uA;
+}
+
+static const struct regulator_ops pm886_ldo_ops = {
+   .list_voltage = regulator_list_voltage_table,
+   .map_voltage = regulator_map_voltage_iterate,
+   .set_voltage_sel = regulator_set_voltage_sel_regmap,
+   .get_voltage_sel = regulator_get_voltage_sel_regmap,
+   .enable = regulator_enable_regmap,
+   .disable = regulator_disable_regmap,
+   .is_enabled = regulator_is_enabled_regmap,
+   .get_current_limit = pm886_regulator_get_ilim,
+};
+
+static const struct regulator_ops pm886_buck_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 = regulator_get_voltage_sel_regmap,
+   .enable = regulator_enable_regmap,
+   .disable = regulator_disable_regmap,
+   .is_enabled = regulator_is_enabled_regmap,
+   .get_current_limit = pm886_regulator_get_ilim,
+};
+
+static const unsigned int pm886_ldo_volt_table1[] = {
+   170, 180, 190, 250, 280, 290, 310, 330,
+};
+
+static const unsigned int pm886_ldo_volt_table2[] = {
+   120, 125, 170, 180, 185, 190, 250, 260,
+   270, 275, 280, 285, 290, 300, 310, 330,
+};
+
+static const unsigned int pm886_ldo_volt_table3[] = {
+   170, 180, 190, 200, 210, 250, 270, 280,
+};
+
+static const struct linear_range pm886_buck_volt_ranges1[] = {
+   REGULATOR_LINEAR_RANGE(60, 0, 79, 12500),
+   REGULATOR_LINEAR_RANGE(160, 80, 84, 5),
+};
+
+static const struct linear_range pm886_buck_volt_ranges2[] = {
+   REGULATOR_LINEAR_RANGE(60, 0, 79, 12500),
+   REGULATOR_LINEAR_RANGE(160, 80, 114, 5),
+};
+
+static struct pm886_regulator pm886_regulators[] = {
+   {
+   .desc = {
+   .name = "LDO1",
+   .regulators_node = "regulators",
+   .of_match = "ldo1",
+   .ops = _ldo_ops,
+   .type = REGULATOR_VOLTAGE,
+   .enable_reg = PM886_REG_LDO_EN1,
+   .enable_mask = BIT(0),
+   .volt_table = pm886_ldo_volt_table1,
+   .n_voltages = ARRAY_SIZE(pm886_ldo_volt_table1),
+   .vsel_reg = PM886_REG_LDO1_VOUT,
+   .vsel_mask = PM886_LDO_VSEL_MASK,
+   },
+   .max_uA = 10,
+   },
+   {
+   .desc = {
+   .name = "LDO2",
+   .regulators_node = "regulators",
+   .of_match = "ldo2",
+   .ops = _ldo_ops,
+ 

[PATCH v6 2/5] mfd: add driver for Marvell 88PM886 PMIC

2024-05-04 Thread Karel Balej
Marvell 88PM886 is a PMIC which provides various functions such as
onkey, battery, charger and regulators. It is found for instance in the
samsung,coreprimevelte smartphone with which this was tested. Implement
basic support to allow for the use of regulators and onkey.

Signed-off-by: Karel Balej 
---

Notes:
v6:
- Address Lee's comments:
  - Don't break long line in the power off handler.
  - Set PLATFORM_DEVID_NONE. This should be safe with respect to
collisions since there are no known devices with more than one of
these PMICs, plus given their general purpose nature it is unlikely
that there would ever be. Also include the corresponding header.
  - Move all defines to the header.
- Give the base page's maximum register its real name.
- Set irq_base to 0.
v5:
- Address Mark's feedback:
  - Move regmap config back out of the header and rename it. Also lower
its maximum register based on what's actually used in the downstream
code.
RFC v4:
- Use MFD_CELL_* macros.
- Address Lee's feedback:
  - Do not define regmap_config.val_bits and .reg_bits.
  - Drop everything regulator related except mfd_cell (regmap
initialization, IDs enum etc.). Drop pm886_initialize_subregmaps.
  - Do not store regmap pointers as an array as there is now only one
regmap. Also drop the corresponding enum.
  - Move regmap_config to the header as it is needed in the regulators
driver.
  - pm886_chip.whoami -> chip_id
  - Reword chip ID mismatch error message and print the ID as
hexadecimal.
  - Fix includes in include/linux/88pm886.h.
  - Drop the pm886_irq_number enum and define the (for the moment) only
IRQ explicitly.
- Have only one MFD cell for all regulators as they are now registered
  all at once in the regulators driver.
- Reword commit message.
- Make device table static and remove comma after the sentinel to signal
  that nothing should come after it.
RFC v3:
- Drop onkey cell .of_compatible.
- Rename LDO page offset and regmap to REGULATORS.
RFC v2:
- Remove some abstraction.
- Sort includes alphabetically and add linux/of.h.
- Depend on OF, remove of_match_ptr and add MODULE_DEVICE_TABLE.
- Use more temporaries and break long lines.
- Do not initialize ret in probe.
- Use the wakeup-source DT property.
- Rename ret to err.
- Address Lee's comments:
  - Drop patched in presets for base regmap and related defines.
  - Use full sentences in comments.
  - Remove IRQ comment.
  - Define regmap_config member values.
  - Rename data to sys_off_data.
  - Add _PMIC suffix to Kconfig.
  - Use dev_err_probe.
  - Do not store irq_data.
  - s/WHOAMI/CHIP_ID
  - Drop LINUX part of include guard name.
  - Merge in the regulator series modifications in order to have more
devices and modify the commit message accordingly. Changes with
respect to the original regulator series patches:
- ret -> err
- Add temporary for dev in pm88x_initialize_subregmaps.
- Drop of_compatible for the regulators.
- Do not duplicate LDO regmap for bucks.
- Rewrite commit message.

 drivers/mfd/88pm886.c   | 148 
 drivers/mfd/Kconfig |  12 +++
 drivers/mfd/Makefile|   1 +
 include/linux/mfd/88pm886.h |  69 +
 4 files changed, 230 insertions(+)
 create mode 100644 drivers/mfd/88pm886.c
 create mode 100644 include/linux/mfd/88pm886.h

diff --git a/drivers/mfd/88pm886.c b/drivers/mfd/88pm886.c
new file mode 100644
index ..dbe9efc027d2
--- /dev/null
+++ b/drivers/mfd/88pm886.c
@@ -0,0 +1,148 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+static const struct regmap_config pm886_regmap_config = {
+   .reg_bits = 8,
+   .val_bits = 8,
+   .max_register = PM886_REG_RTC_SPARE6,
+};
+
+static struct regmap_irq pm886_regmap_irqs[] = {
+   REGMAP_IRQ_REG(PM886_IRQ_ONKEY, 0, PM886_INT_ENA1_ONKEY),
+};
+
+static struct regmap_irq_chip pm886_regmap_irq_chip = {
+   .name = "88pm886",
+   .irqs = pm886_regmap_irqs,
+   .num_irqs = ARRAY_SIZE(pm886_regmap_irqs),
+   .num_regs = 4,
+   .status_base = PM886_REG_INT_STATUS1,
+   .ack_base = PM886_REG_INT_STATUS1,
+   .unmask_base = PM886_REG_INT_ENA_1,
+};
+
+static struct resource pm886_onkey_resources[] = {
+   DEFINE_RES_IRQ_NAMED(PM886_IRQ_ONKEY, "88pm886-onkey"),
+};
+
+static struct mfd_cell pm886_devs[] = {
+   MFD_CELL_RES("88pm886-onkey", pm886_onkey_resources),
+   MFD_CELL_NAME("88pm886-regulator"),
+};
+
+static int pm886_power_off_handler(struct sys_off_data *sys_off_data)
+{
+   struct pm886_chip *chip 

Re: [PATCH 2/5] mfd: add driver for Marvell 88PM886 PMIC

2024-04-11 Thread Karel Balej
Lee Jones, 2024-04-11T12:37:26+01:00:
[...]
> > diff --git a/drivers/mfd/88pm886.c b/drivers/mfd/88pm886.c
> > new file mode 100644
> > index ..e06d418a5da9
> > --- /dev/null
> > +++ b/drivers/mfd/88pm886.c
> > @@ -0,0 +1,157 @@
> > +// SPDX-License-Identifier: GPL-2.0-only
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +#include 
> > +
> > +#define PM886_REG_INT_STATUS1  0x05
> > +
> > +#define PM886_REG_INT_ENA_10x0a
> > +#define PM886_INT_ENA1_ONKEY   BIT(0)
> > +
> > +#define PM886_IRQ_ONKEY0
> > +
> > +#define PM886_REGMAP_CONF_MAX_REG  0xef
>
> Why have you split the defines up between here and the header?

I tried to keep defines tied to the code which uses them and only put
defines needed in multiple places in the header. With the exception of
closely related things, such as register bits which I am keeping
together with the respective register definitions for clarity. Does that
not make sense?

> Please place them all in the header.

Would you then also have me move all the definitions from the regulators
driver there?

[...]

> > +   err = devm_mfd_add_devices(dev, 0, pm886_devs, ARRAY_SIZE(pm886_devs),
>
> Why 0?

PLATFORM_DEVID_AUTO then? Or will PLATFORM_DEVID_NONE suffice since the
cells all have different names now (it would probably cause problems
though if the driver was used multiple times for some reason, wouldn't
it?)?

Thank you,
K. B.



[PATCH 5/5] MAINTAINERS: add myself for Marvell 88PM886 PMIC

2024-03-31 Thread Karel Balej
Add an entry to MAINTAINERS for the Marvell 88PM886 PMIC MFD, onkey and
regulator drivers.

Signed-off-by: Karel Balej 
---

Notes:
RFC v3:
- Remove onkey bindings file.
RFC v2:
- Only mention 88PM886 in the commit message.
- Add regulator driver.
- Rename the entry.

 MAINTAINERS | 9 +
 1 file changed, 9 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index aa3b947fb080..c6bdf93ea3a7 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -13048,6 +13048,15 @@ F: drivers/net/dsa/mv88e6xxx/
 F: include/linux/dsa/mv88e6xxx.h
 F: include/linux/platform_data/mv88e6xxx.h
 
+MARVELL 88PM886 PMIC DRIVER
+M: Karel Balej 
+S: Maintained
+F: Documentation/devicetree/bindings/mfd/marvell,88pm886-a1.yaml
+F: drivers/input/misc/88pm886-onkey.c
+F: drivers/mfd/88pm886.c
+F: drivers/regulators/88pm886-regulator.c
+F: include/linux/mfd/88pm886.h
+
 MARVELL ARMADA 3700 PHY DRIVERS
 M: Miquel Raynal 
 S: Maintained
-- 
2.44.0




[PATCH 4/5] input: add onkey driver for Marvell 88PM886 PMIC

2024-03-31 Thread Karel Balej
Marvell 88PM886 PMIC provides onkey among other things. Add client
driver to handle it. The driver currently only provides a basic support
omitting additional functions found in the vendor version, such as long
onkey and GPIO integration.

Acked-by: Dmitry Torokhov 
Signed-off-by: Karel Balej 
---

Notes:
v1:
- Remove kernel.h include.
RFC v4:
- Reflect MFD driver changes:
  - chip->regmaps[...] -> chip->regmap
- Address Dmitry's feedback:
  - Add ID table.
  - Add Ack.
RFC v3:
- Drop wakeup-source.
RFC v2:
- Address Dmitry's feedback:
  - Sort includes alphabetically.
  - Drop onkey->irq.
  - ret -> err in irq_handler and no initialization.
  - Break long lines and other formatting.
  - Do not clobber platform_get_irq error.
  - Do not set device parent manually.
  - Use input_set_capability.
  - Use the wakeup-source DT property.
  - Drop of_match_table.
  - Use more temporaries.
  - Use dev_err_probe.
- Modify Kconfig description.

 drivers/input/misc/88pm886-onkey.c | 98 ++
 drivers/input/misc/Kconfig |  7 +++
 drivers/input/misc/Makefile|  1 +
 3 files changed, 106 insertions(+)
 create mode 100644 drivers/input/misc/88pm886-onkey.c

diff --git a/drivers/input/misc/88pm886-onkey.c 
b/drivers/input/misc/88pm886-onkey.c
new file mode 100644
index ..284ff5190b6e
--- /dev/null
+++ b/drivers/input/misc/88pm886-onkey.c
@@ -0,0 +1,98 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+struct pm886_onkey {
+   struct input_dev *idev;
+   struct pm886_chip *chip;
+};
+
+static irqreturn_t pm886_onkey_irq_handler(int irq, void *data)
+{
+   struct pm886_onkey *onkey = data;
+   struct regmap *regmap = onkey->chip->regmap;
+   struct input_dev *idev = onkey->idev;
+   struct device *parent = idev->dev.parent;
+   unsigned int val;
+   int err;
+
+   err = regmap_read(regmap, PM886_REG_STATUS1, );
+   if (err) {
+   dev_err(parent, "Failed to read status: %d\n", err);
+   return IRQ_NONE;
+   }
+   val &= PM886_ONKEY_STS1;
+
+   input_report_key(idev, KEY_POWER, val);
+   input_sync(idev);
+
+   return IRQ_HANDLED;
+}
+
+static int pm886_onkey_probe(struct platform_device *pdev)
+{
+   struct pm886_chip *chip = dev_get_drvdata(pdev->dev.parent);
+   struct device *dev = >dev;
+   struct pm886_onkey *onkey;
+   struct input_dev *idev;
+   int irq, err;
+
+   onkey = devm_kzalloc(dev, sizeof(*onkey), GFP_KERNEL);
+   if (!onkey)
+   return -ENOMEM;
+
+   onkey->chip = chip;
+
+   irq = platform_get_irq(pdev, 0);
+   if (irq < 0)
+   return dev_err_probe(dev, irq, "Failed to get IRQ\n");
+
+   idev = devm_input_allocate_device(dev);
+   if (!idev) {
+   dev_err(dev, "Failed to allocate input device\n");
+   return -ENOMEM;
+   }
+   onkey->idev = idev;
+
+   idev->name = "88pm886-onkey";
+   idev->phys = "88pm886-onkey/input0";
+   idev->id.bustype = BUS_I2C;
+
+   input_set_capability(idev, EV_KEY, KEY_POWER);
+
+   err = devm_request_threaded_irq(dev, irq, NULL, pm886_onkey_irq_handler,
+   IRQF_ONESHOT | IRQF_NO_SUSPEND, "onkey",
+   onkey);
+   if (err)
+   return dev_err_probe(dev, err, "Failed to request IRQ\n");
+
+   err = input_register_device(idev);
+   if (err)
+   return dev_err_probe(dev, err, "Failed to register input 
device\n");
+
+   return 0;
+}
+
+static const struct platform_device_id pm886_onkey_id_table[] = {
+   { "88pm886-onkey", },
+   { }
+};
+MODULE_DEVICE_TABLE(platform, pm886_onkey_id_table);
+
+static struct platform_driver pm886_onkey_driver = {
+   .driver = {
+   .name = "88pm886-onkey",
+   },
+   .probe = pm886_onkey_probe,
+   .id_table = pm886_onkey_id_table,
+};
+module_platform_driver(pm886_onkey_driver);
+
+MODULE_DESCRIPTION("Marvell 88PM886 onkey driver");
+MODULE_AUTHOR("Karel Balej ");
+MODULE_LICENSE("GPL");
diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index 6ba984d7f0b1..16a079d9f0f2 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -33,6 +33,13 @@ config INPUT_88PM80X_ONKEY
  To compile this driver as a module, choose M here: the module
  will be called 88pm80x_onkey.
 
+config INPUT_88PM886_ONKEY
+   tristate "Marvell 88PM886 onkey support"
+   depends on MFD_88PM886_PMIC
+   help
+ Support the onkey of Marvell 88PM886 PMIC a

[PATCH 3/5] regulator: add regulators driver for Marvell 88PM886 PMIC

2024-03-31 Thread Karel Balej
Support the LDO and buck regulators of the Marvell 88PM886 PMIC.

Signed-off-by: Karel Balej 
---

Notes:
v1:
- Add remaining regulators.
- Clean up includes.
- Address Mark's feedback:
  - Use dedicated regmap config.
RFC v4:
- Initialize regulators regmap in the regulators driver.
- Register all regulators at once.
- Drop regulator IDs.
- Add missing '\n' to dev_err_probe message.
- Fix includes.
- Add ID table.
RFC v3:
- Do not have a variable for each regulator -- define them all in the
  pm886_regulators array.
- Use new regulators regmap index name.
- Use dev_err_probe.
RFC v2:
- Drop of_compatible and related code.
- Drop unused include.
- Remove some abstraction: use only one regmap for all regulators and
  only mention 88PM886 in Kconfig description.
- Reword commit message.

 drivers/regulator/88pm886-regulator.c | 509 ++
 drivers/regulator/Kconfig |   6 +
 drivers/regulator/Makefile|   1 +
 3 files changed, 516 insertions(+)
 create mode 100644 drivers/regulator/88pm886-regulator.c

diff --git a/drivers/regulator/88pm886-regulator.c 
b/drivers/regulator/88pm886-regulator.c
new file mode 100644
index ..05d24bf444cb
--- /dev/null
+++ b/drivers/regulator/88pm886-regulator.c
@@ -0,0 +1,509 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#define PM886_PAGE_OFFSET_REGULATORS   1
+
+#define PM886_REG_LDO_EN1  0x09
+#define PM886_REG_LDO_EN2  0x0a
+
+#define PM886_REG_BUCK_EN  0x08
+
+#define PM886_REG_LDO1_VOUT0x20
+#define PM886_REG_LDO2_VOUT0x26
+#define PM886_REG_LDO3_VOUT0x2c
+#define PM886_REG_LDO4_VOUT0x32
+#define PM886_REG_LDO5_VOUT0x38
+#define PM886_REG_LDO6_VOUT0x3e
+#define PM886_REG_LDO7_VOUT0x44
+#define PM886_REG_LDO8_VOUT0x4a
+#define PM886_REG_LDO9_VOUT0x50
+#define PM886_REG_LDO10_VOUT   0x56
+#define PM886_REG_LDO11_VOUT   0x5c
+#define PM886_REG_LDO12_VOUT   0x62
+#define PM886_REG_LDO13_VOUT   0x68
+#define PM886_REG_LDO14_VOUT   0x6e
+#define PM886_REG_LDO15_VOUT   0x74
+#define PM886_REG_LDO16_VOUT   0x7a
+
+#define PM886_REG_BUCK1_VOUT   0xa5
+#define PM886_REG_BUCK2_VOUT   0xb3
+#define PM886_REG_BUCK3_VOUT   0xc1
+#define PM886_REG_BUCK4_VOUT   0xcf
+#define PM886_REG_BUCK5_VOUT   0xdd
+
+#define PM886_LDO_VSEL_MASK0x0f
+#define PM886_BUCK_VSEL_MASK   0x7f
+
+static const struct regmap_config pm886_regulator_regmap_config = {
+   .reg_bits = 8,
+   .val_bits = 8,
+   .max_register = PM886_REG_BUCK5_VOUT,
+};
+
+struct pm886_regulator {
+   struct regulator_desc desc;
+   int max_uA;
+};
+
+static int pm886_regulator_get_ilim(struct regulator_dev *rdev)
+{
+   struct pm886_regulator *data = rdev_get_drvdata(rdev);
+
+   if (!data) {
+   dev_err(>dev, "Failed to get regulator data\n");
+   return -EINVAL;
+   }
+   return data->max_uA;
+}
+
+static const struct regulator_ops pm886_ldo_ops = {
+   .list_voltage = regulator_list_voltage_table,
+   .map_voltage = regulator_map_voltage_iterate,
+   .set_voltage_sel = regulator_set_voltage_sel_regmap,
+   .get_voltage_sel = regulator_get_voltage_sel_regmap,
+   .enable = regulator_enable_regmap,
+   .disable = regulator_disable_regmap,
+   .is_enabled = regulator_is_enabled_regmap,
+   .get_current_limit = pm886_regulator_get_ilim,
+};
+
+static const struct regulator_ops pm886_buck_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 = regulator_get_voltage_sel_regmap,
+   .enable = regulator_enable_regmap,
+   .disable = regulator_disable_regmap,
+   .is_enabled = regulator_is_enabled_regmap,
+   .get_current_limit = pm886_regulator_get_ilim,
+};
+
+static const unsigned int pm886_ldo_volt_table1[] = {
+   170, 180, 190, 250, 280, 290, 310, 330,
+};
+
+static const unsigned int pm886_ldo_volt_table2[] = {
+   120, 125, 170, 180, 185, 190, 250, 260,
+   270, 275, 280, 285, 290, 300, 310, 330,
+};
+
+static const unsigned int pm886_ldo_volt_table3[] = {
+   170, 180, 190, 200, 210, 250, 270, 280,
+};
+
+static const struct linear_range pm886_buck_volt_ranges1[] = {
+   REGULATOR_LINEAR_RANGE(60, 0, 79, 12500),
+   REGULATOR_LINEAR_RANGE(160, 80, 84, 5),
+};
+
+static const struct linear_range pm886_b

[PATCH 1/5] dt-bindings: mfd: add entry for Marvell 88PM886 PMIC

2024-03-31 Thread Karel Balej
Marvell 88PM886 is a PMIC with several subdevices such as onkey,
regulators or battery and charger. It comes in at least two revisions,
A0 and A1 -- only A1 is described here at the moment.

Reviewed-by: Krzysztof Kozlowski 
Signed-off-by: Karel Balej 
---

Notes:
RFC v4:
- Address Krzysztof's comments:
  - Fix regulators indentation.
  - Add Krzysztof's trailer.
RFC v3:
- Add wakeup-source property.
- Address Rob's feedback:
  - Move regulators into the MFD file.
  - Remove interrupt-controller and #interrupt-cells properties.
RFC v2:
- Address Rob's feedback:
  - Drop mention of 88PM880.
  - Make sure the file passes bindings check (add the necessary header
and fix `interrupt-cells`).
  - Other small changes.
- Add regulators. Changes with respect to the regulator RFC series:
  - Address Krzysztof's comments:
- Drop unused compatible.
- Fix sub-node pattern.

 .../bindings/mfd/marvell,88pm886-a1.yaml  | 76 +++
 1 file changed, 76 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/mfd/marvell,88pm886-a1.yaml

diff --git a/Documentation/devicetree/bindings/mfd/marvell,88pm886-a1.yaml 
b/Documentation/devicetree/bindings/mfd/marvell,88pm886-a1.yaml
new file mode 100644
index ..d6a71c912b76
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/marvell,88pm886-a1.yaml
@@ -0,0 +1,76 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/marvell,88pm886-a1.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Marvell 88PM886 PMIC core
+
+maintainers:
+  - Karel Balej 
+
+description:
+  Marvell 88PM886 is a PMIC providing several functions such as onkey,
+  regulators or battery and charger.
+
+properties:
+  compatible:
+const: marvell,88pm886-a1
+
+  reg:
+maxItems: 1
+
+  interrupts:
+maxItems: 1
+
+  wakeup-source: true
+
+  regulators:
+type: object
+additionalProperties: false
+patternProperties:
+  "^(ldo(1[0-6]|[1-9])|buck[1-5])$":
+type: object
+$ref: /schemas/regulator/regulator.yaml#
+description: LDO or buck regulator.
+unevaluatedProperties: false
+
+required:
+  - compatible
+  - reg
+  - interrupts
+
+additionalProperties: false
+
+examples:
+  - |
+#include 
+i2c {
+  #address-cells = <1>;
+  #size-cells = <0>;
+  pmic@30 {
+compatible = "marvell,88pm886-a1";
+reg = <0x30>;
+interrupts = <0 4 IRQ_TYPE_LEVEL_HIGH>;
+interrupt-parent = <>;
+wakeup-source;
+
+regulators {
+  ldo2: ldo2 {
+regulator-min-microvolt = <310>;
+regulator-max-microvolt = <330>;
+  };
+
+  ldo15: ldo15 {
+regulator-min-microvolt = <330>;
+regulator-max-microvolt = <330>;
+  };
+
+  buck2: buck2 {
+regulator-min-microvolt = <180>;
+regulator-max-microvolt = <180>;
+  };
+};
+  };
+};
+...
-- 
2.44.0




[PATCH 2/5] mfd: add driver for Marvell 88PM886 PMIC

2024-03-31 Thread Karel Balej
Marvell 88PM886 is a PMIC which provides various functions such as
onkey, battery, charger and regulators. It is found for instance in the
samsung,coreprimevelte smartphone with which this was tested. Implement
basic support to allow for the use of regulators and onkey.

Signed-off-by: Karel Balej 
---

Notes:
v1:
- Address Mark's feedback:
  - Move regmap config back out of the header and rename it. Also lower
its maximum register based on what's actually used in the downstream
code.
RFC v4:
- Use MFD_CELL_* macros.
- Address Lee's feedback:
  - Do not define regmap_config.val_bits and .reg_bits.
  - Drop everything regulator related except mfd_cell (regmap
initialization, IDs enum etc.). Drop pm886_initialize_subregmaps.
  - Do not store regmap pointers as an array as there is now only one
regmap. Also drop the corresponding enum.
  - Move regmap_config to the header as it is needed in the regulators
driver.
  - pm886_chip.whoami -> chip_id
  - Reword chip ID mismatch error message and print the ID as
hexadecimal.
  - Fix includes in include/linux/88pm886.h.
  - Drop the pm886_irq_number enum and define the (for the moment) only
IRQ explicitly.
- Have only one MFD cell for all regulators as they are now registered
  all at once in the regulators driver.
- Reword commit message.
- Make device table static and remove comma after the sentinel to signal
  that nothing should come after it.
RFC v3:
- Drop onkey cell .of_compatible.
- Rename LDO page offset and regmap to REGULATORS.
RFC v2:
- Remove some abstraction.
- Sort includes alphabetically and add linux/of.h.
- Depend on OF, remove of_match_ptr and add MODULE_DEVICE_TABLE.
- Use more temporaries and break long lines.
- Do not initialize ret in probe.
- Use the wakeup-source DT property.
- Rename ret to err.
- Address Lee's comments:
  - Drop patched in presets for base regmap and related defines.
  - Use full sentences in comments.
  - Remove IRQ comment.
  - Define regmap_config member values.
  - Rename data to sys_off_data.
  - Add _PMIC suffix to Kconfig.
  - Use dev_err_probe.
  - Do not store irq_data.
  - s/WHOAMI/CHIP_ID
  - Drop LINUX part of include guard name.
  - Merge in the regulator series modifications in order to have more
devices and modify the commit message accordingly. Changes with
respect to the original regulator series patches:
- ret -> err
- Add temporary for dev in pm88x_initialize_subregmaps.
- Drop of_compatible for the regulators.
- Do not duplicate LDO regmap for bucks.
- Rewrite commit message.

 drivers/mfd/88pm886.c   | 157 
 drivers/mfd/Kconfig |  12 +++
 drivers/mfd/Makefile|   1 +
 include/linux/mfd/88pm886.h |  30 +++
 4 files changed, 200 insertions(+)
 create mode 100644 drivers/mfd/88pm886.c
 create mode 100644 include/linux/mfd/88pm886.h

diff --git a/drivers/mfd/88pm886.c b/drivers/mfd/88pm886.c
new file mode 100644
index ..e06d418a5da9
--- /dev/null
+++ b/drivers/mfd/88pm886.c
@@ -0,0 +1,157 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#define PM886_REG_INT_STATUS1  0x05
+
+#define PM886_REG_INT_ENA_10x0a
+#define PM886_INT_ENA1_ONKEY   BIT(0)
+
+#define PM886_IRQ_ONKEY0
+
+#define PM886_REGMAP_CONF_MAX_REG  0xef
+
+static const struct regmap_config pm886_regmap_config = {
+   .reg_bits = 8,
+   .val_bits = 8,
+   .max_register = PM886_REGMAP_CONF_MAX_REG,
+};
+
+static struct regmap_irq pm886_regmap_irqs[] = {
+   REGMAP_IRQ_REG(PM886_IRQ_ONKEY, 0, PM886_INT_ENA1_ONKEY),
+};
+
+static struct regmap_irq_chip pm886_regmap_irq_chip = {
+   .name = "88pm886",
+   .irqs = pm886_regmap_irqs,
+   .num_irqs = ARRAY_SIZE(pm886_regmap_irqs),
+   .num_regs = 4,
+   .status_base = PM886_REG_INT_STATUS1,
+   .ack_base = PM886_REG_INT_STATUS1,
+   .unmask_base = PM886_REG_INT_ENA_1,
+};
+
+static struct resource pm886_onkey_resources[] = {
+   DEFINE_RES_IRQ_NAMED(PM886_IRQ_ONKEY, "88pm886-onkey"),
+};
+
+static struct mfd_cell pm886_devs[] = {
+   MFD_CELL_RES("88pm886-onkey", pm886_onkey_resources),
+   MFD_CELL_NAME("88pm886-regulator"),
+};
+
+static int pm886_power_off_handler(struct sys_off_data *sys_off_data)
+{
+   struct pm886_chip *chip = sys_off_data->cb_data;
+   struct regmap *regmap = chip->regmap;
+   struct device *dev = >client->dev;
+   int err;
+
+   err = regmap_update_bits(regmap, PM886_REG_MISC_CONFIG1, PM886_SW_PDOWN,
+ 

[PATCH 0/5] initial support for Marvell 88PM886 PMIC

2024-03-31 Thread Karel Balej
Hello,

the following implements basic support for Marvell's 88PM886 PMIC which
is found for instance as a component of the samsung,coreprimevelte
smartphone which inspired this and also serves as a testing platform.

The code for the MFD is based primarily on this old series [1] with the
addition of poweroff based on the smartphone's downstream kernel tree
[2]. The onkey and regulators drivers are based on the latter. I am not
in possesion of the datasheet.

[1] 
https://lore.kernel.org/all/1434098601-3498-1-git-send-email-yizh...@marvell.com/
[2] https://github.com/CoderCharmander/g361f-kernel

Thank you and kind regards,
K. B.
---
v1:
- RFC v4: 
https://lore.kernel.org/r/20240311160110.32185-1-kar...@gimli.ms.mff.cuni.cz/
- Rebase to v6.9-rc1.
- Thank you to everybody for their feedback on the RFC!
RFC v4:
- RFC v3: 
https://lore.kernel.org/all/20240303101506.4187-1-kar...@gimli.ms.mff.cuni.cz/
RFC v3:
- Address Rob's feedback:
  - Drop onkey bindings patch.
- Rename PM88X -> PM886 everywhere.
- RFC v2: 
https://lore.kernel.org/all/20240211094609.2223-1-kar...@gimli.ms.mff.cuni.cz/
RFC v2:
- Merge with the regulators series to have multiple devices and thus
  justify the use of the MFD framework.
- Rebase on v6.8-rc3.
- Reorder patches.
- MFD RFC v1: 
https://lore.kernel.org/all/20231217131838.7569-1-kar...@gimli.ms.mff.cuni.cz/
- regulators RFC v1: 
https://lore.kernel.org/all/20231228100208.2932-1-kar...@gimli.ms.mff.cuni.cz/

Karel Balej (5):
  dt-bindings: mfd: add entry for Marvell 88PM886 PMIC
  mfd: add driver for Marvell 88PM886 PMIC
  regulator: add regulators driver for Marvell 88PM886 PMIC
  input: add onkey driver for Marvell 88PM886 PMIC
  MAINTAINERS: add myself for Marvell 88PM886 PMIC

 .../bindings/mfd/marvell,88pm886-a1.yaml  |  76 +++
 MAINTAINERS   |   9 +
 drivers/input/misc/88pm886-onkey.c|  98 
 drivers/input/misc/Kconfig|   7 +
 drivers/input/misc/Makefile   |   1 +
 drivers/mfd/88pm886.c | 157 ++
 drivers/mfd/Kconfig   |  12 +
 drivers/mfd/Makefile  |   1 +
 drivers/regulator/88pm886-regulator.c | 509 ++
 drivers/regulator/Kconfig |   6 +
 drivers/regulator/Makefile|   1 +
 include/linux/mfd/88pm886.h   |  30 ++
 12 files changed, 907 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/mfd/marvell,88pm886-a1.yaml
 create mode 100644 drivers/input/misc/88pm886-onkey.c
 create mode 100644 drivers/mfd/88pm886.c
 create mode 100644 drivers/regulator/88pm886-regulator.c
 create mode 100644 include/linux/mfd/88pm886.h

-- 
2.44.0




Re: [RFC PATCH v4 2/5] mfd: add driver for Marvell 88PM886 PMIC

2024-03-21 Thread Karel Balej
Mark Brown, 2024-03-21T19:00:24+00:00:
> On Thu, Mar 21, 2024 at 07:16:43PM +0100, Karel Balej wrote:
> > Mark Brown, 2024-03-21T17:48:28+00:00:
>
> > > > They do according to the downstream driver which is my only reference.
> > > > In fact, there the driver defines the configs separately for each regmap
> > > > but with the same values.
>
> > > This is a downstream driver - are you sure it's got the best code
> > > quality?
>
> > No, that is why I have rewritten it and tried to improve on this. But
> > like I said, it is my only reference. Is there some other way to verify
> > this value (besides perhaps the datasheet)?
>
> The maximum register is whatever the maximum register we know about for
> the device is, the datasheet is generally a good reference there.
>
> > > I'm not seeing any references to registers with numbers as high as the
> > > maximum register that's there in your driver for example.
>
> > Indeed, I have performed the same check with the same findings. But that
> > doesn't necessarily mean that the maximum should be lower, no?
>
> > Do you have some specific modifications of my code in mind regarding
> > this?
>
> I would expect that if you have two separate register maps they would
> have separate configurations that describe the corresponding physical
> register maps, as far as I can tell this driver is just making up a
> maximum register number.

Alright, so I should just use a separate config for each regmap and set
the max_register value for each to whatever I can find is actually the
highest used value in the downstream code -- correct?

Thank you,
K. B.



Re: [RFC PATCH v4 2/5] mfd: add driver for Marvell 88PM886 PMIC

2024-03-21 Thread Karel Balej
Mark Brown, 2024-03-21T17:48:28+00:00:
> On Thu, Mar 21, 2024 at 06:32:03PM +0100, Karel Balej wrote:
> > Mark Brown, 2024-03-21T17:17:40+00:00:
>
> > > Do they both genuinely have the same maximum register?
>
> > They do according to the downstream driver which is my only reference.
> > In fact, there the driver defines the configs separately for each regmap
> > but with the same values.
>
> This is a downstream driver - are you sure it's got the best code
> quality?

No, that is why I have rewritten it and tried to improve on this. But
like I said, it is my only reference. Is there some other way to verify
this value (besides perhaps the datasheet)?

> I'm not seeing any references to registers with numbers as high as the
> maximum register that's there in your driver for example.

Indeed, I have performed the same check with the same findings. But that
doesn't necessarily mean that the maximum should be lower, no?

Do you have some specific modifications of my code in mind regarding
this?

Thank you,
K. B.



Re: [RFC PATCH v4 2/5] mfd: add driver for Marvell 88PM886 PMIC

2024-03-21 Thread Karel Balej
Mark Brown, 2024-03-21T17:17:40+00:00:
> On Thu, Mar 21, 2024 at 06:08:16PM +0100, Karel Balej wrote:
> > Mark Brown, 2024-03-21T16:58:44+00:00:
>
> > > > > > > > +static const struct regmap_config pm886_i2c_regmap = {
> > > > > > > > +   .reg_bits = 8,
> > > > > > > > +   .val_bits = 8,
> > > > > > > > +   .max_register = PM886_REGMAP_CONF_MAX_REG,
> > > > > > > > +};
>
> ...
>
> > > You shouldn't be creating two regmaps for the same set of registers,
> > > that just opens the potential for confusion.
>
> > Just the regmap config is the same. Otherwise, each regmap lives at a
> > different I2C address.
>
> Do they both genuinely have the same maximum register?

They do according to the downstream driver which is my only reference.
In fact, there the driver defines the configs separately for each regmap
but with the same values.



Re: [RFC PATCH v4 2/5] mfd: add driver for Marvell 88PM886 PMIC

2024-03-21 Thread Karel Balej
Mark Brown, 2024-03-21T16:58:44+00:00:
> On Thu, Mar 21, 2024 at 05:55:17PM +0100, Karel Balej wrote:
> > Lee Jones, 2024-03-21T16:20:45+00:00:
> > > On Thu, 21 Mar 2024, Karel Balej wrote:
>
> > > > > > +static const struct regmap_config pm886_i2c_regmap = {
> > > > > > +   .reg_bits = 8,
> > > > > > +   .val_bits = 8,
> > > > > > +   .max_register = PM886_REGMAP_CONF_MAX_REG,
> > > > > > +};
>
> > > > > Why is this in here?
>
> > > > Because since I moved the regulators regmap initialization into the
> > > > regulators driver, I need to access it from there.
>
> > > So move it into the regulators driver?
>
> > It is used in the MFD driver too for the base regmap.
>
> You shouldn't be creating two regmaps for the same set of registers,
> that just opens the potential for confusion.

Just the regmap config is the same. Otherwise, each regmap lives at a
different I2C address.

Regards,
K. B.



Re: [RFC PATCH v4 2/5] mfd: add driver for Marvell 88PM886 PMIC

2024-03-21 Thread Karel Balej
Lee Jones, 2024-03-21T16:20:45+00:00:
> On Thu, 21 Mar 2024, Karel Balej wrote:
>
> > Lee Jones, 2024-03-21T15:42:11+00:00:
> > > On Mon, 11 Mar 2024, Karel Balej wrote:
> > > > diff --git a/include/linux/mfd/88pm886.h b/include/linux/mfd/88pm886.h
> > > > new file mode 100644
> > > > index ..a5e6524bb19d
> > > > --- /dev/null
> > > > +++ b/include/linux/mfd/88pm886.h
> > > > @@ -0,0 +1,38 @@
> > > > +/* SPDX-License-Identifier: GPL-2.0-only */
> > > > +#ifndef __MFD_88PM886_H
> > > > +#define __MFD_88PM886_H
> > > > +
> > > > +#include 
> > > > +#include 
> > > > +
> > > > +#define PM886_A1_CHIP_ID   0xa1
> > > > +
> > > > +#define PM886_REGMAP_CONF_MAX_REG  0xfe
> > > > +
> > > > +#define PM886_REG_ID   0x00
> > > > +
> > > > +#define PM886_REG_STATUS1  0x01
> > > > +#define PM886_ONKEY_STS1   BIT(0)
> > > > +
> > > > +#define PM886_REG_MISC_CONFIG1 0x14
> > > > +#define PM886_SW_PDOWN BIT(5)
> > > > +
> > > > +#define PM886_REG_MISC_CONFIG2 0x15
> > > > +#define PM886_INT_INV  BIT(0)
> > > > +#define PM886_INT_CLEARBIT(1)
> > > > +#define PM886_INT_RC   0x00
> > > > +#define PM886_INT_WC   BIT(1)
> > > > +#define PM886_INT_MASK_MODEBIT(2)
> > > > +
> > > > +struct pm886_chip {
> > > > +   struct i2c_client *client;
> > > > +   unsigned int chip_id;
> > > > +   struct regmap *regmap;
> > > > +};
> > > > +
> > > > +static const struct regmap_config pm886_i2c_regmap = {
> > > > +   .reg_bits = 8,
> > > > +   .val_bits = 8,
> > > > +   .max_register = PM886_REGMAP_CONF_MAX_REG,
> > > > +};
> > >
> > > Why is this in here?
> > 
> > Because since I moved the regulators regmap initialization into the
> > regulators driver, I need to access it from there.
>
> So move it into the regulators driver?

It is used in the MFD driver too for the base regmap.

K. B.



Re: [RFC PATCH v4 2/5] mfd: add driver for Marvell 88PM886 PMIC

2024-03-21 Thread Karel Balej
Lee Jones, 2024-03-21T15:42:11+00:00:
> On Mon, 11 Mar 2024, Karel Balej wrote:
>
> > From: Karel Balej 
> > 
> > Marvell 88PM886 is a PMIC which provides various functions such as
> > onkey, battery, charger and regulators. It is found for instance in the
> > samsung,coreprimevelte smartphone with which this was tested. Implement
> > basic support to allow for the use of regulators and onkey.
> > 
> > Signed-off-by: Karel Balej 
> > ---
> > 
> > Notes:
> > RFC v4:
> > - Use MFD_CELL_* macros.
> > - Address Lee's feedback:
> >   - Do not define regmap_config.val_bits and .reg_bits.
> >   - Drop everything regulator related except mfd_cell (regmap
> > initialization, IDs enum etc.). Drop pm886_initialize_subregmaps.
> >   - Do not store regmap pointers as an array as there is now only one
> > regmap. Also drop the corresponding enum.
> >   - Move regmap_config to the header as it is needed in the regulators
> > driver.
> >   - pm886_chip.whoami -> chip_id
> >   - Reword chip ID mismatch error message and print the ID as
> > hexadecimal.
> >   - Fix includes in include/linux/88pm886.h.
> >   - Drop the pm886_irq_number enum and define the (for the moment) only
> > IRQ explicitly.
> > - Have only one MFD cell for all regulators as they are now registered
> >   all at once in the regulators driver.
> > - Reword commit message.
> > - Make device table static and remove comma after the sentinel to signal
> >   that nothing should come after it.
> > RFC v3:
> > - Drop onkey cell .of_compatible.
> > - Rename LDO page offset and regmap to REGULATORS.
> > RFC v2:
> > - Remove some abstraction.
> > - Sort includes alphabetically and add linux/of.h.
> > - Depend on OF, remove of_match_ptr and add MODULE_DEVICE_TABLE.
> > - Use more temporaries and break long lines.
> > - Do not initialize ret in probe.
> > - Use the wakeup-source DT property.
> > - Rename ret to err.
> > - Address Lee's comments:
> >   - Drop patched in presets for base regmap and related defines.
> >   - Use full sentences in comments.
> >   - Remove IRQ comment.
> >   - Define regmap_config member values.
> >   - Rename data to sys_off_data.
> >   - Add _PMIC suffix to Kconfig.
> >   - Use dev_err_probe.
> >   - Do not store irq_data.
> >   - s/WHOAMI/CHIP_ID
> >   - Drop LINUX part of include guard name.
> >   - Merge in the regulator series modifications in order to have more
> > devices and modify the commit message accordingly. Changes with
> > respect to the original regulator series patches:
> > - ret -> err
> > - Add temporary for dev in pm88x_initialize_subregmaps.
> > - Drop of_compatible for the regulators.
> > - Do not duplicate LDO regmap for bucks.
> > - Rewrite commit message.
> > 
> >  drivers/mfd/88pm886.c   | 149 
> >  drivers/mfd/Kconfig |  12 +++
> >  drivers/mfd/Makefile|   1 +
> >  include/linux/mfd/88pm886.h |  38 +
> >  4 files changed, 200 insertions(+)
> >  create mode 100644 drivers/mfd/88pm886.c
> >  create mode 100644 include/linux/mfd/88pm886.h
>
> Looks mostly okay.
>
> > diff --git a/include/linux/mfd/88pm886.h b/include/linux/mfd/88pm886.h
> > new file mode 100644
> > index ..a5e6524bb19d
> > --- /dev/null
> > +++ b/include/linux/mfd/88pm886.h
> > @@ -0,0 +1,38 @@
> > +/* SPDX-License-Identifier: GPL-2.0-only */
> > +#ifndef __MFD_88PM886_H
> > +#define __MFD_88PM886_H
> > +
> > +#include 
> > +#include 
> > +
> > +#define PM886_A1_CHIP_ID   0xa1
> > +
> > +#define PM886_REGMAP_CONF_MAX_REG  0xfe
> > +
> > +#define PM886_REG_ID   0x00
> > +
> > +#define PM886_REG_STATUS1  0x01
> > +#define PM886_ONKEY_STS1   BIT(0)
> > +
> > +#define PM886_REG_MISC_CONFIG1 0x14
> > +#define PM886_SW_PDOWN BIT(5)
> > +
> > +#define PM886_REG_MISC_CONFIG2 0x15
> > +#define PM886_INT_INV  BIT(0)
> > +#define PM886_INT_CLEARBIT(1)
> > +#define PM886_INT_RC   0x00
> > +#define PM886_INT_WC   BIT(1)
> > +#define PM886_INT_MASK_MODE  

[RFC PATCH v4 5/5] MAINTAINERS: add myself for Marvell 88PM886 PMIC

2024-03-11 Thread Karel Balej
From: Karel Balej 

Add an entry to MAINTAINERS for the Marvell 88PM886 PMIC MFD, onkey and
regulator drivers.

Signed-off-by: Karel Balej 
---

Notes:
RFC v3:
- Remove onkey bindings file.
RFC v2:
- Only mention 88PM886 in the commit message.
- Add regulator driver.
- Rename the entry.

 MAINTAINERS | 9 +
 1 file changed, 9 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 960512bec428..944f88c92df6 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -12949,6 +12949,15 @@ F: drivers/net/dsa/mv88e6xxx/
 F: include/linux/dsa/mv88e6xxx.h
 F: include/linux/platform_data/mv88e6xxx.h
 
+MARVELL 88PM886 PMIC DRIVER
+M: Karel Balej 
+S: Maintained
+F: Documentation/devicetree/bindings/mfd/marvell,88pm886-a1.yaml
+F: drivers/input/misc/88pm886-onkey.c
+F: drivers/mfd/88pm886.c
+F: drivers/regulators/88pm886-regulator.c
+F: include/linux/mfd/88pm886.h
+
 MARVELL ARMADA 3700 PHY DRIVERS
 M: Miquel Raynal 
 S: Maintained
-- 
2.44.0




[RFC PATCH v4 4/5] input: add onkey driver for Marvell 88PM886 PMIC

2024-03-11 Thread Karel Balej
From: Karel Balej 

Marvell 88PM886 PMIC provides onkey among other things. Add client
driver to handle it. The driver currently only provides a basic support
omitting additional functions found in the vendor version, such as long
onkey and GPIO integration.

Acked-by: Dmitry Torokhov 
Signed-off-by: Karel Balej 
---

Notes:
RFC v4:
- Reflect MFD driver changes:
  - chip->regmaps[...] -> chip->regmap
- Address Dmitry's feedback:
  - Add ID table.
  - Add Ack.
RFC v3:
- Drop wakeup-source.
RFC v2:
- Address Dmitry's feedback:
  - Sort includes alphabetically.
  - Drop onkey->irq.
  - ret -> err in irq_handler and no initialization.
  - Break long lines and other formatting.
  - Do not clobber platform_get_irq error.
  - Do not set device parent manually.
  - Use input_set_capability.
  - Use the wakeup-source DT property.
  - Drop of_match_table.
  - Use more temporaries.
  - Use dev_err_probe.
- Modify Kconfig description.

 drivers/input/misc/88pm886-onkey.c | 99 ++
 drivers/input/misc/Kconfig |  7 +++
 drivers/input/misc/Makefile|  1 +
 3 files changed, 107 insertions(+)
 create mode 100644 drivers/input/misc/88pm886-onkey.c

diff --git a/drivers/input/misc/88pm886-onkey.c 
b/drivers/input/misc/88pm886-onkey.c
new file mode 100644
index ..b0bfbd57d826
--- /dev/null
+++ b/drivers/input/misc/88pm886-onkey.c
@@ -0,0 +1,99 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+struct pm886_onkey {
+   struct input_dev *idev;
+   struct pm886_chip *chip;
+};
+
+static irqreturn_t pm886_onkey_irq_handler(int irq, void *data)
+{
+   struct pm886_onkey *onkey = data;
+   struct regmap *regmap = onkey->chip->regmap;
+   struct input_dev *idev = onkey->idev;
+   struct device *parent = idev->dev.parent;
+   unsigned int val;
+   int err;
+
+   err = regmap_read(regmap, PM886_REG_STATUS1, );
+   if (err) {
+   dev_err(parent, "Failed to read status: %d\n", err);
+   return IRQ_NONE;
+   }
+   val &= PM886_ONKEY_STS1;
+
+   input_report_key(idev, KEY_POWER, val);
+   input_sync(idev);
+
+   return IRQ_HANDLED;
+}
+
+static int pm886_onkey_probe(struct platform_device *pdev)
+{
+   struct pm886_chip *chip = dev_get_drvdata(pdev->dev.parent);
+   struct device *dev = >dev;
+   struct pm886_onkey *onkey;
+   struct input_dev *idev;
+   int irq, err;
+
+   onkey = devm_kzalloc(dev, sizeof(*onkey), GFP_KERNEL);
+   if (!onkey)
+   return -ENOMEM;
+
+   onkey->chip = chip;
+
+   irq = platform_get_irq(pdev, 0);
+   if (irq < 0)
+   return dev_err_probe(dev, irq, "Failed to get IRQ\n");
+
+   idev = devm_input_allocate_device(dev);
+   if (!idev) {
+   dev_err(dev, "Failed to allocate input device\n");
+   return -ENOMEM;
+   }
+   onkey->idev = idev;
+
+   idev->name = "88pm886-onkey";
+   idev->phys = "88pm886-onkey/input0";
+   idev->id.bustype = BUS_I2C;
+
+   input_set_capability(idev, EV_KEY, KEY_POWER);
+
+   err = devm_request_threaded_irq(dev, irq, NULL, pm886_onkey_irq_handler,
+   IRQF_ONESHOT | IRQF_NO_SUSPEND, "onkey",
+   onkey);
+   if (err)
+   return dev_err_probe(dev, err, "Failed to request IRQ\n");
+
+   err = input_register_device(idev);
+   if (err)
+   return dev_err_probe(dev, err, "Failed to register input 
device\n");
+
+   return 0;
+}
+
+static const struct platform_device_id pm886_onkey_id_table[] = {
+   { "88pm886-onkey", },
+   { }
+};
+MODULE_DEVICE_TABLE(platform, pm886_onkey_id_table);
+
+static struct platform_driver pm886_onkey_driver = {
+   .driver = {
+   .name = "88pm886-onkey",
+   },
+   .probe = pm886_onkey_probe,
+   .id_table = pm886_onkey_id_table,
+};
+module_platform_driver(pm886_onkey_driver);
+
+MODULE_DESCRIPTION("Marvell 88PM886 onkey driver");
+MODULE_AUTHOR("Karel Balej ");
+MODULE_LICENSE("GPL");
diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index 6ba984d7f0b1..16a079d9f0f2 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -33,6 +33,13 @@ config INPUT_88PM80X_ONKEY
  To compile this driver as a module, choose M here: the module
  will be called 88pm80x_onkey.
 
+config INPUT_88PM886_ONKEY
+   tristate "Marvell 88PM886 onkey support"
+   depends on MFD_88PM886_PMIC
+   help
+ Support the onkey of Marvell 88PM886 PMIC as an input 

[RFC PATCH v4 3/5] regulator: add regulators driver for Marvell 88PM886 PMIC

2024-03-11 Thread Karel Balej
From: Karel Balej 

Support the LDO and buck regulators of the Marvell 88PM886 PMIC.

Signed-off-by: Karel Balej 
---
Please note that most of the regulators are not yet described: the
descriptions will be added to pm886_regulators in the same manner as the
already present ones before the series leaves the RFC state. In the
meantime, general comments on the driver will be appreciated.

Notes:
RFC v4:
- Initialize regulators regmap in the regulators driver.
- Register all regulators at once.
- Drop regulator IDs.
- Add missing '\n' to dev_err_probe message.
- Fix includes.
- Add ID table.
RFC v3:
- Do not have a variable for each regulator -- define them all in the
  pm886_regulators array.
- Use new regulators regmap index name.
- Use dev_err_probe.
RFC v2:
- Drop of_compatible and related code.
- Drop unused include.
- Remove some abstraction: use only one regmap for all regulators and
  only mention 88PM886 in Kconfig description.
- Reword commit message.

 drivers/regulator/88pm886-regulator.c | 215 ++
 drivers/regulator/Kconfig |   6 +
 drivers/regulator/Makefile|   1 +
 3 files changed, 222 insertions(+)
 create mode 100644 drivers/regulator/88pm886-regulator.c

diff --git a/drivers/regulator/88pm886-regulator.c 
b/drivers/regulator/88pm886-regulator.c
new file mode 100644
index ..6a2ddb11a28a
--- /dev/null
+++ b/drivers/regulator/88pm886-regulator.c
@@ -0,0 +1,215 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#define PM886_PAGE_OFFSET_REGULATORS   1
+
+#define PM886_REG_LDO_EN1  0x09
+#define PM886_REG_LDO_EN2  0x0a
+
+#define PM886_REG_BUCK_EN  0x08
+
+#define PM886_REG_LDO1_VOUT0x20
+#define PM886_REG_LDO2_VOUT0x26
+#define PM886_REG_LDO3_VOUT0x2c
+#define PM886_REG_LDO4_VOUT0x32
+#define PM886_REG_LDO5_VOUT0x38
+#define PM886_REG_LDO6_VOUT0x3e
+#define PM886_REG_LDO7_VOUT0x44
+#define PM886_REG_LDO8_VOUT0x4a
+#define PM886_REG_LDO9_VOUT0x50
+#define PM886_REG_LDO10_VOUT   0x56
+#define PM886_REG_LDO11_VOUT   0x5c
+#define PM886_REG_LDO12_VOUT   0x62
+#define PM886_REG_LDO13_VOUT   0x68
+#define PM886_REG_LDO14_VOUT   0x6e
+#define PM886_REG_LDO15_VOUT   0x74
+#define PM886_REG_LDO16_VOUT   0x7a
+
+#define PM886_REG_BUCK1_VOUT   0xa5
+#define PM886_REG_BUCK2_VOUT   0xb3
+#define PM886_REG_BUCK3_VOUT   0xc1
+#define PM886_REG_BUCK4_VOUT   0xcf
+#define PM886_REG_BUCK5_VOUT   0xdd
+
+#define PM886_LDO_VSEL_MASK0x0f
+#define PM886_BUCK_VSEL_MASK   0x7f
+
+struct pm886_regulator {
+   struct regulator_desc desc;
+   int max_uA;
+};
+
+static int pm886_regulator_get_ilim(struct regulator_dev *rdev)
+{
+   struct pm886_regulator *data = rdev_get_drvdata(rdev);
+
+   if (!data) {
+   dev_err(>dev, "Failed to get regulator data\n");
+   return -EINVAL;
+   }
+   return data->max_uA;
+}
+
+static const struct regulator_ops pm886_ldo_ops = {
+   .list_voltage = regulator_list_voltage_table,
+   .map_voltage = regulator_map_voltage_iterate,
+   .set_voltage_sel = regulator_set_voltage_sel_regmap,
+   .get_voltage_sel = regulator_get_voltage_sel_regmap,
+   .enable = regulator_enable_regmap,
+   .disable = regulator_disable_regmap,
+   .is_enabled = regulator_is_enabled_regmap,
+   .get_current_limit = pm886_regulator_get_ilim,
+};
+
+static const struct regulator_ops pm886_buck_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 = regulator_get_voltage_sel_regmap,
+   .enable = regulator_enable_regmap,
+   .disable = regulator_disable_regmap,
+   .is_enabled = regulator_is_enabled_regmap,
+   .get_current_limit = pm886_regulator_get_ilim,
+};
+
+static const unsigned int pm886_ldo_volt_table1[] = {
+   170, 180, 190, 250, 280, 290, 310, 330,
+};
+
+static const unsigned int pm886_ldo_volt_table2[] = {
+   120, 125, 170, 180, 185, 190, 250, 260,
+   270, 275, 280, 285, 290, 300, 310, 330,
+};
+
+static const unsigned int pm886_ldo_volt_table3[] = {
+   170, 180, 190, 200, 210, 250, 270, 280,
+};
+
+static const struct linear_range pm886_buck_volt_ranges1[] = {
+   REGULATOR_LINEAR_RANGE(60, 0, 79, 12500),
+   REGULATOR_LINEAR_RANGE(160, 80, 84, 5),
+};
+
+static const str

[RFC PATCH v4 2/5] mfd: add driver for Marvell 88PM886 PMIC

2024-03-11 Thread Karel Balej
From: Karel Balej 

Marvell 88PM886 is a PMIC which provides various functions such as
onkey, battery, charger and regulators. It is found for instance in the
samsung,coreprimevelte smartphone with which this was tested. Implement
basic support to allow for the use of regulators and onkey.

Signed-off-by: Karel Balej 
---

Notes:
RFC v4:
- Use MFD_CELL_* macros.
- Address Lee's feedback:
  - Do not define regmap_config.val_bits and .reg_bits.
  - Drop everything regulator related except mfd_cell (regmap
initialization, IDs enum etc.). Drop pm886_initialize_subregmaps.
  - Do not store regmap pointers as an array as there is now only one
regmap. Also drop the corresponding enum.
  - Move regmap_config to the header as it is needed in the regulators
driver.
  - pm886_chip.whoami -> chip_id
  - Reword chip ID mismatch error message and print the ID as
hexadecimal.
  - Fix includes in include/linux/88pm886.h.
  - Drop the pm886_irq_number enum and define the (for the moment) only
IRQ explicitly.
- Have only one MFD cell for all regulators as they are now registered
  all at once in the regulators driver.
- Reword commit message.
- Make device table static and remove comma after the sentinel to signal
  that nothing should come after it.
RFC v3:
- Drop onkey cell .of_compatible.
- Rename LDO page offset and regmap to REGULATORS.
RFC v2:
- Remove some abstraction.
- Sort includes alphabetically and add linux/of.h.
- Depend on OF, remove of_match_ptr and add MODULE_DEVICE_TABLE.
- Use more temporaries and break long lines.
- Do not initialize ret in probe.
- Use the wakeup-source DT property.
- Rename ret to err.
- Address Lee's comments:
  - Drop patched in presets for base regmap and related defines.
  - Use full sentences in comments.
  - Remove IRQ comment.
  - Define regmap_config member values.
  - Rename data to sys_off_data.
  - Add _PMIC suffix to Kconfig.
  - Use dev_err_probe.
  - Do not store irq_data.
  - s/WHOAMI/CHIP_ID
  - Drop LINUX part of include guard name.
  - Merge in the regulator series modifications in order to have more
devices and modify the commit message accordingly. Changes with
respect to the original regulator series patches:
- ret -> err
- Add temporary for dev in pm88x_initialize_subregmaps.
- Drop of_compatible for the regulators.
- Do not duplicate LDO regmap for bucks.
- Rewrite commit message.

 drivers/mfd/88pm886.c   | 149 
 drivers/mfd/Kconfig |  12 +++
 drivers/mfd/Makefile|   1 +
 include/linux/mfd/88pm886.h |  38 +
 4 files changed, 200 insertions(+)
 create mode 100644 drivers/mfd/88pm886.c
 create mode 100644 include/linux/mfd/88pm886.h

diff --git a/drivers/mfd/88pm886.c b/drivers/mfd/88pm886.c
new file mode 100644
index ..88f21f813ec1
--- /dev/null
+++ b/drivers/mfd/88pm886.c
@@ -0,0 +1,149 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#define PM886_REG_INT_STATUS1  0x05
+
+#define PM886_REG_INT_ENA_10x0a
+#define PM886_INT_ENA1_ONKEY   BIT(0)
+
+#define PM886_IRQ_ONKEY0
+
+static struct regmap_irq pm886_regmap_irqs[] = {
+   REGMAP_IRQ_REG(PM886_IRQ_ONKEY, 0, PM886_INT_ENA1_ONKEY),
+};
+
+static struct regmap_irq_chip pm886_regmap_irq_chip = {
+   .name = "88pm886",
+   .irqs = pm886_regmap_irqs,
+   .num_irqs = ARRAY_SIZE(pm886_regmap_irqs),
+   .num_regs = 4,
+   .status_base = PM886_REG_INT_STATUS1,
+   .ack_base = PM886_REG_INT_STATUS1,
+   .unmask_base = PM886_REG_INT_ENA_1,
+};
+
+static struct resource pm886_onkey_resources[] = {
+   DEFINE_RES_IRQ_NAMED(PM886_IRQ_ONKEY, "88pm886-onkey"),
+};
+
+static struct mfd_cell pm886_devs[] = {
+   MFD_CELL_RES("88pm886-onkey", pm886_onkey_resources),
+   MFD_CELL_NAME("88pm886-regulator"),
+};
+
+static int pm886_power_off_handler(struct sys_off_data *sys_off_data)
+{
+   struct pm886_chip *chip = sys_off_data->cb_data;
+   struct regmap *regmap = chip->regmap;
+   struct device *dev = >client->dev;
+   int err;
+
+   err = regmap_update_bits(regmap, PM886_REG_MISC_CONFIG1, PM886_SW_PDOWN,
+   PM886_SW_PDOWN);
+   if (err) {
+   dev_err(dev, "Failed to power off the device: %d\n", err);
+   return NOTIFY_BAD;
+   }
+   return NOTIFY_DONE;
+}
+
+static int pm886_setup_irq(struct pm886_chip *chip,
+   struct regmap_irq_chip_data **irq_data)
+{
+   struct regmap *regmap = chip->regmap;
+   struct device *dev = 

[RFC PATCH v4 0/5] initial support for Marvell 88PM886 PMIC

2024-03-11 Thread Karel Balej
From: Karel Balej 

Hello,

the following implements basic support for Marvell's 88PM886 PMIC which
is found for instance as a component of the samsung,coreprimevelte
smartphone which inspired this and also serves as a testing platform.

The code for the MFD is based primarily on this old series [1] with the
addition of poweroff based on the smartphone's downstream kernel tree
[2]. The onkey and regulators drivers are based on the latter. I am not
in possesion of the datasheet.

[1] 
https://lore.kernel.org/all/1434098601-3498-1-git-send-email-yizh...@marvell.com/
[2] https://github.com/CoderCharmander/g361f-kernel

Thank you and kind regards,
K. B.
---
RFC v4:
- RFC v3: 
https://lore.kernel.org/all/20240303101506.4187-1-kar...@gimli.ms.mff.cuni.cz/
RFC v3:
- Address Rob's feedback:
  - Drop onkey bindings patch.
- Rename PM88X -> PM886 everywhere.
- RFC v2: 
https://lore.kernel.org/all/20240211094609.2223-1-kar...@gimli.ms.mff.cuni.cz/
RFC v2:
- Merge with the regulators series to have multiple devices and thus
  justify the use of the MFD framework.
- Rebase on v6.8-rc3.
- Reorder patches.
- MFD RFC v1: 
https://lore.kernel.org/all/20231217131838.7569-1-kar...@gimli.ms.mff.cuni.cz/
- regulators RFC v1: 
https://lore.kernel.org/all/20231228100208.2932-1-kar...@gimli.ms.mff.cuni.cz/

Karel Balej (5):
  dt-bindings: mfd: add entry for Marvell 88PM886 PMIC
  mfd: add driver for Marvell 88PM886 PMIC
  regulator: add regulators driver for Marvell 88PM886 PMIC
  input: add onkey driver for Marvell 88PM886 PMIC
  MAINTAINERS: add myself for Marvell 88PM886 PMIC

 .../bindings/mfd/marvell,88pm886-a1.yaml  |  76 +++
 MAINTAINERS   |   9 +
 drivers/input/misc/88pm886-onkey.c|  99 
 drivers/input/misc/Kconfig|   7 +
 drivers/input/misc/Makefile   |   1 +
 drivers/mfd/88pm886.c | 149 
 drivers/mfd/Kconfig   |  12 +
 drivers/mfd/Makefile  |   1 +
 drivers/regulator/88pm886-regulator.c | 215 ++
 drivers/regulator/Kconfig |   6 +
 drivers/regulator/Makefile|   1 +
 include/linux/mfd/88pm886.h   |  38 
 12 files changed, 614 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/mfd/marvell,88pm886-a1.yaml
 create mode 100644 drivers/input/misc/88pm886-onkey.c
 create mode 100644 drivers/mfd/88pm886.c
 create mode 100644 drivers/regulator/88pm886-regulator.c
 create mode 100644 include/linux/mfd/88pm886.h

-- 
2.44.0




[RFC PATCH v4 1/5] dt-bindings: mfd: add entry for Marvell 88PM886 PMIC

2024-03-11 Thread Karel Balej
From: Karel Balej 

Marvell 88PM886 is a PMIC with several subdevices such as onkey,
regulators or battery and charger. It comes in at least two revisions,
A0 and A1 -- only A1 is described here at the moment.

Reviewed-by: Krzysztof Kozlowski 
Signed-off-by: Karel Balej 
---

Notes:
RFC v4:
- Address Krzysztof's comments:
  - Fix regulators indentation.
  - Add Krzysztof's trailer.
RFC v3:
- Add wakeup-source property.
- Address Rob's feedback:
  - Move regulators into the MFD file.
  - Remove interrupt-controller and #interrupt-cells properties.
RFC v2:
- Address Rob's feedback:
  - Drop mention of 88PM880.
  - Make sure the file passes bindings check (add the necessary header
and fix `interrupt-cells`).
  - Other small changes.
- Add regulators. Changes with respect to the regulator RFC series:
  - Address Krzysztof's comments:
- Drop unused compatible.
- Fix sub-node pattern.

 .../bindings/mfd/marvell,88pm886-a1.yaml  | 76 +++
 1 file changed, 76 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/mfd/marvell,88pm886-a1.yaml

diff --git a/Documentation/devicetree/bindings/mfd/marvell,88pm886-a1.yaml 
b/Documentation/devicetree/bindings/mfd/marvell,88pm886-a1.yaml
new file mode 100644
index ..d6a71c912b76
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/marvell,88pm886-a1.yaml
@@ -0,0 +1,76 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/marvell,88pm886-a1.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Marvell 88PM886 PMIC core
+
+maintainers:
+  - Karel Balej 
+
+description:
+  Marvell 88PM886 is a PMIC providing several functions such as onkey,
+  regulators or battery and charger.
+
+properties:
+  compatible:
+const: marvell,88pm886-a1
+
+  reg:
+maxItems: 1
+
+  interrupts:
+maxItems: 1
+
+  wakeup-source: true
+
+  regulators:
+type: object
+additionalProperties: false
+patternProperties:
+  "^(ldo(1[0-6]|[1-9])|buck[1-5])$":
+type: object
+$ref: /schemas/regulator/regulator.yaml#
+description: LDO or buck regulator.
+unevaluatedProperties: false
+
+required:
+  - compatible
+  - reg
+  - interrupts
+
+additionalProperties: false
+
+examples:
+  - |
+#include 
+i2c {
+  #address-cells = <1>;
+  #size-cells = <0>;
+  pmic@30 {
+compatible = "marvell,88pm886-a1";
+reg = <0x30>;
+interrupts = <0 4 IRQ_TYPE_LEVEL_HIGH>;
+interrupt-parent = <>;
+wakeup-source;
+
+regulators {
+  ldo2: ldo2 {
+regulator-min-microvolt = <310>;
+regulator-max-microvolt = <330>;
+  };
+
+  ldo15: ldo15 {
+regulator-min-microvolt = <330>;
+regulator-max-microvolt = <330>;
+  };
+
+  buck2: buck2 {
+regulator-min-microvolt = <180>;
+regulator-max-microvolt = <180>;
+  };
+};
+  };
+};
+...
-- 
2.44.0




Re: [RFC PATCH v3 4/5] input: add onkey driver for Marvell 88PM886 PMIC

2024-03-11 Thread Karel Balej
Krzysztof Kozlowski, 2024-03-11T11:41:53+01:00:
> On 11/03/2024 11:26, Karel Balej wrote:
> > Krzysztof Kozlowski, 2024-03-10T21:35:36+01:00:
> >> On 10/03/2024 12:35, Karel Balej wrote:
> >>> Dmitry Torokhov, 2024-03-04T17:10:59-08:00:
> >>>> On Mon, Mar 04, 2024 at 09:28:45PM +0100, Karel Balej wrote:
> >>>>> Dmitry,
> >>>>>
> >>>>> Dmitry Torokhov, 2024-03-03T12:39:46-08:00:
> >>>>>> On Sun, Mar 03, 2024 at 11:04:25AM +0100, Karel Balej wrote:
> >>>>>>> From: Karel Balej 
> >>>>>>>
> >>>>>>> Marvell 88PM886 PMIC provides onkey among other things. Add client
> >>>>>>> driver to handle it. The driver currently only provides a basic 
> >>>>>>> support
> >>>>>>> omitting additional functions found in the vendor version, such as 
> >>>>>>> long
> >>>>>>> onkey and GPIO integration.
> >>>>>>>
> >>>>>>> Signed-off-by: Karel Balej 
> >>>>>>> ---
> >>>>>>>
> >>>>>>> Notes:
> >>>>>>> RFC v3:
> >>>>>>> - Drop wakeup-source.
> >>>>>>> RFC v2:
> >>>>>>> - Address Dmitry's feedback:
> >>>>>>>   - Sort includes alphabetically.
> >>>>>>>   - Drop onkey->irq.
> >>>>>>>   - ret -> err in irq_handler and no initialization.
> >>>>>>>   - Break long lines and other formatting.
> >>>>>>>   - Do not clobber platform_get_irq error.
> >>>>>>>   - Do not set device parent manually.
> >>>>>>>   - Use input_set_capability.
> >>>>>>>   - Use the wakeup-source DT property.
> >>>>>>>   - Drop of_match_table.
> >>>>>>
> >>>>>> I only said that you should not be using of_match_ptr(), but you still
> >>>>>> need to have of_match_table set and have MODULE_DEVICE_TABLE() for the
> >>>>>> proper module loading support.
> >>>>>
> >>>>> I removed of_match_table because I no longer need compatible for this --
> >>>>> there are no device tree properties and the driver is being instantiated
> >>>>> by the MFD driver.
> >>>>>
> >>>>> Is the MODULE_DEVICE_TABLE() entry needed for the driver to probe when
> >>>>> compiled as module? If that is the case, given what I write above, am I
> >>>>> correct that MODULE_DEVICE_TABLE(platform,...) would be the right thing
> >>>>> to use here?
> >>>>
> >>>> Yes, if uevent generated for the device is "platform:" then
> >>>> MODULE_DEVICE_TABLE(platform,...) will suffice. I am not sure how MFD
> >>>> sets it up (OF modalias or platform), but you should be able to check
> >>>> the format looking at the "uevent" attribute for your device in sysfs
> >>>> (/sys/devices/bus/platform/...). 
> >>>
> >>> The uevent is indeed platform.
> >>>
> >>> But since there is only one device, perhaps having a device table is
> >>> superfluous and using `MODULE_ALIAS("platform:88pm886-onkey")` is more
> >>> fitting?
> >>
> >> Adding aliases for standard IDs and standard cases is almost never
> >> correct. If you need module alias, it means your ID table is wrong (or
> >> missing, which is usually wrong).
> >>
> >>>
> >>> Although I don't understand why this is even necessary when the driver
> >>> name is such and the module is registered using
> >>> `module_platform_driver`...
> >>
> >> ID table and MODULE_DEVICE_TABLE() are necessary for modprobe to work.
> > 
> > I think I understand the practical reasons. My point was that I would
> > expect the alias to be added automatically even in the case that the
> > device table is absent based solely on the driver name and the
> > registration method (*module*_*platform*_driver). Why is that not the
> > case? Obviously the driver name matching the mfd_cell name is sufficient
>
> You mean add it automatically by macro-magic based on presence of
> id_table and/or of_match_table?

Yes, that plus: if id_table is

Re: [RFC PATCH v3 4/5] input: add onkey driver for Marvell 88PM886 PMIC

2024-03-11 Thread Karel Balej
Krzysztof Kozlowski, 2024-03-10T21:35:36+01:00:
> On 10/03/2024 12:35, Karel Balej wrote:
> > Dmitry Torokhov, 2024-03-04T17:10:59-08:00:
> >> On Mon, Mar 04, 2024 at 09:28:45PM +0100, Karel Balej wrote:
> >>> Dmitry,
> >>>
> >>> Dmitry Torokhov, 2024-03-03T12:39:46-08:00:
> >>>> On Sun, Mar 03, 2024 at 11:04:25AM +0100, Karel Balej wrote:
> >>>>> From: Karel Balej 
> >>>>>
> >>>>> Marvell 88PM886 PMIC provides onkey among other things. Add client
> >>>>> driver to handle it. The driver currently only provides a basic support
> >>>>> omitting additional functions found in the vendor version, such as long
> >>>>> onkey and GPIO integration.
> >>>>>
> >>>>> Signed-off-by: Karel Balej 
> >>>>> ---
> >>>>>
> >>>>> Notes:
> >>>>> RFC v3:
> >>>>> - Drop wakeup-source.
> >>>>> RFC v2:
> >>>>> - Address Dmitry's feedback:
> >>>>>   - Sort includes alphabetically.
> >>>>>   - Drop onkey->irq.
> >>>>>   - ret -> err in irq_handler and no initialization.
> >>>>>   - Break long lines and other formatting.
> >>>>>   - Do not clobber platform_get_irq error.
> >>>>>   - Do not set device parent manually.
> >>>>>   - Use input_set_capability.
> >>>>>   - Use the wakeup-source DT property.
> >>>>>   - Drop of_match_table.
> >>>>
> >>>> I only said that you should not be using of_match_ptr(), but you still
> >>>> need to have of_match_table set and have MODULE_DEVICE_TABLE() for the
> >>>> proper module loading support.
> >>>
> >>> I removed of_match_table because I no longer need compatible for this --
> >>> there are no device tree properties and the driver is being instantiated
> >>> by the MFD driver.
> >>>
> >>> Is the MODULE_DEVICE_TABLE() entry needed for the driver to probe when
> >>> compiled as module? If that is the case, given what I write above, am I
> >>> correct that MODULE_DEVICE_TABLE(platform,...) would be the right thing
> >>> to use here?
> >>
> >> Yes, if uevent generated for the device is "platform:" then
> >> MODULE_DEVICE_TABLE(platform,...) will suffice. I am not sure how MFD
> >> sets it up (OF modalias or platform), but you should be able to check
> >> the format looking at the "uevent" attribute for your device in sysfs
> >> (/sys/devices/bus/platform/...). 
> > 
> > The uevent is indeed platform.
> > 
> > But since there is only one device, perhaps having a device table is
> > superfluous and using `MODULE_ALIAS("platform:88pm886-onkey")` is more
> > fitting?
>
> Adding aliases for standard IDs and standard cases is almost never
> correct. If you need module alias, it means your ID table is wrong (or
> missing, which is usually wrong).
>
> > 
> > Although I don't understand why this is even necessary when the driver
> > name is such and the module is registered using
> > `module_platform_driver`...
>
> ID table and MODULE_DEVICE_TABLE() are necessary for modprobe to work.

I think I understand the practical reasons. My point was that I would
expect the alias to be added automatically even in the case that the
device table is absent based solely on the driver name and the
registration method (*module*_*platform*_driver). Why is that not the
case? Obviously the driver name matching the mfd_cell name is sufficient
for the driver to probe when it is built in so the name does seem to
serve as some identification for the device just as a device table entry
would.

Furthermore, drivers/input/serio/ioc3kbd.c does not seem to have an ID
table either, nor a MODULE_ALIAS -- is that a mistake? If not, what
mechanism causes the driver to probe when compiled as a module? It seems
to me to effectively be the same setup as with my driver and that does
not load automatically (because of the missing alias).

> Just run `modinfo`.

Thank you very much,
K. B.



Re: [RFC PATCH v3 4/5] input: add onkey driver for Marvell 88PM886 PMIC

2024-03-10 Thread Karel Balej
Dmitry Torokhov, 2024-03-04T17:10:59-08:00:
> On Mon, Mar 04, 2024 at 09:28:45PM +0100, Karel Balej wrote:
> > Dmitry,
> > 
> > Dmitry Torokhov, 2024-03-03T12:39:46-08:00:
> > > On Sun, Mar 03, 2024 at 11:04:25AM +0100, Karel Balej wrote:
> > > > From: Karel Balej 
> > > > 
> > > > Marvell 88PM886 PMIC provides onkey among other things. Add client
> > > > driver to handle it. The driver currently only provides a basic support
> > > > omitting additional functions found in the vendor version, such as long
> > > > onkey and GPIO integration.
> > > > 
> > > > Signed-off-by: Karel Balej 
> > > > ---
> > > > 
> > > > Notes:
> > > > RFC v3:
> > > > - Drop wakeup-source.
> > > > RFC v2:
> > > > - Address Dmitry's feedback:
> > > >   - Sort includes alphabetically.
> > > >   - Drop onkey->irq.
> > > >   - ret -> err in irq_handler and no initialization.
> > > >   - Break long lines and other formatting.
> > > >   - Do not clobber platform_get_irq error.
> > > >   - Do not set device parent manually.
> > > >   - Use input_set_capability.
> > > >   - Use the wakeup-source DT property.
> > > >   - Drop of_match_table.
> > >
> > > I only said that you should not be using of_match_ptr(), but you still
> > > need to have of_match_table set and have MODULE_DEVICE_TABLE() for the
> > > proper module loading support.
> > 
> > I removed of_match_table because I no longer need compatible for this --
> > there are no device tree properties and the driver is being instantiated
> > by the MFD driver.
> > 
> > Is the MODULE_DEVICE_TABLE() entry needed for the driver to probe when
> > compiled as module? If that is the case, given what I write above, am I
> > correct that MODULE_DEVICE_TABLE(platform,...) would be the right thing
> > to use here?
>
> Yes, if uevent generated for the device is "platform:" then
> MODULE_DEVICE_TABLE(platform,...) will suffice. I am not sure how MFD
> sets it up (OF modalias or platform), but you should be able to check
> the format looking at the "uevent" attribute for your device in sysfs
> (/sys/devices/bus/platform/...). 

The uevent is indeed platform.

But since there is only one device, perhaps having a device table is
superfluous and using `MODULE_ALIAS("platform:88pm886-onkey")` is more
fitting?

Although I don't understand why this is even necessary when the driver
name is such and the module is registered using
`module_platform_driver`...

Thank you, best regards,
K. B.



Re: [RFC PATCH v3 2/5] mfd: add driver for Marvell 88PM886 PMIC

2024-03-05 Thread Karel Balej
Lee Jones, 2024-03-05T11:44:18+00:00:
> > +static struct mfd_cell pm886_devs[] = {
> > +   {
> > +   .name = "88pm886-onkey",
> > +   .num_resources = ARRAY_SIZE(pm886_onkey_resources),
> > +   .resources = pm886_onkey_resources,
> > +   },
> > +   {
> > +   .name = "88pm886-regulator",
> > +   .id = PM886_REGULATOR_ID_LDO2,
>
> Why doesn't PLATFORM_DEVID_AUTO work for this device?

Because I am using the IDs in the regulator driver to determine which
regulator data to use/which regulator to register.

> > +static int pm886_initialize_subregmaps(struct pm886_chip *chip)
> > +{
> > +   struct device *dev = >client->dev;
> > +   struct i2c_client *page;
> > +   struct regmap *regmap;
> > +   int err;
> > +
> > +   /* regulators page */
> > +   page = devm_i2c_new_dummy_device(dev, chip->client->adapter,
> > +   chip->client->addr + 
> > PM886_PAGE_OFFSET_REGULATORS);
> > +   if (IS_ERR(page)) {
> > +   err = PTR_ERR(page);
> > +   dev_err(dev, "Failed to initialize regulators client: %d\n", 
> > err);
> > +   return err;
> > +   }
> > +   regmap = devm_regmap_init_i2c(page, _i2c_regmap);
> > +   if (IS_ERR(regmap)) {
> > +   err = PTR_ERR(regmap);
> > +   dev_err(dev, "Failed to initialize regulators regmap: %d\n", 
> > err);
> > +   return err;
> > +   }
> > +   chip->regmaps[PM886_REGMAP_REGULATORS] = regmap;
>
> Except for the regulator driver, where else is the regulators regmap used?

Nowhere, at least as of now. So you are saying that I should initialize
the regmap in the regulator driver?

Thank you,
K. B.



Re: [RFC PATCH v3 4/5] input: add onkey driver for Marvell 88PM886 PMIC

2024-03-04 Thread Karel Balej
Dmitry,

Dmitry Torokhov, 2024-03-03T12:39:46-08:00:
> On Sun, Mar 03, 2024 at 11:04:25AM +0100, Karel Balej wrote:
> > From: Karel Balej 
> > 
> > Marvell 88PM886 PMIC provides onkey among other things. Add client
> > driver to handle it. The driver currently only provides a basic support
> > omitting additional functions found in the vendor version, such as long
> > onkey and GPIO integration.
> > 
> > Signed-off-by: Karel Balej 
> > ---
> > 
> > Notes:
> > RFC v3:
> > - Drop wakeup-source.
> > RFC v2:
> > - Address Dmitry's feedback:
> >   - Sort includes alphabetically.
> >   - Drop onkey->irq.
> >   - ret -> err in irq_handler and no initialization.
> >   - Break long lines and other formatting.
> >   - Do not clobber platform_get_irq error.
> >   - Do not set device parent manually.
> >   - Use input_set_capability.
> >   - Use the wakeup-source DT property.
> >   - Drop of_match_table.
>
> I only said that you should not be using of_match_ptr(), but you still
> need to have of_match_table set and have MODULE_DEVICE_TABLE() for the
> proper module loading support.

I removed of_match_table because I no longer need compatible for this --
there are no device tree properties and the driver is being instantiated
by the MFD driver.

Is the MODULE_DEVICE_TABLE() entry needed for the driver to probe when
compiled as module? If that is the case, given what I write above, am I
correct that MODULE_DEVICE_TABLE(platform,...) would be the right thing
to use here?

Thank you, kind regards,
K. B.



[RFC PATCH v3 5/5] MAINTAINERS: add myself for Marvell 88PM886 PMIC

2024-03-03 Thread Karel Balej
From: Karel Balej 

Add an entry to MAINTAINERS for the Marvell 88PM886 PMIC MFD, onkey and
regulator drivers.

Signed-off-by: Karel Balej 
---

Notes:
RFC v3:
- Remove onkey bindings file.
RFC v2:
- Only mention 88PM886 in the commit message.
- Add regulator driver.
- Rename the entry.

 MAINTAINERS | 9 +
 1 file changed, 9 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 960512bec428..944f88c92df6 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -12949,6 +12949,15 @@ F: drivers/net/dsa/mv88e6xxx/
 F: include/linux/dsa/mv88e6xxx.h
 F: include/linux/platform_data/mv88e6xxx.h
 
+MARVELL 88PM886 PMIC DRIVER
+M: Karel Balej 
+S: Maintained
+F: Documentation/devicetree/bindings/mfd/marvell,88pm886-a1.yaml
+F: drivers/input/misc/88pm886-onkey.c
+F: drivers/mfd/88pm886.c
+F: drivers/regulators/88pm886-regulator.c
+F: include/linux/mfd/88pm886.h
+
 MARVELL ARMADA 3700 PHY DRIVERS
 M: Miquel Raynal 
 S: Maintained
-- 
2.44.0




[RFC PATCH v3 4/5] input: add onkey driver for Marvell 88PM886 PMIC

2024-03-03 Thread Karel Balej
From: Karel Balej 

Marvell 88PM886 PMIC provides onkey among other things. Add client
driver to handle it. The driver currently only provides a basic support
omitting additional functions found in the vendor version, such as long
onkey and GPIO integration.

Signed-off-by: Karel Balej 
---

Notes:
RFC v3:
- Drop wakeup-source.
RFC v2:
- Address Dmitry's feedback:
  - Sort includes alphabetically.
  - Drop onkey->irq.
  - ret -> err in irq_handler and no initialization.
  - Break long lines and other formatting.
  - Do not clobber platform_get_irq error.
  - Do not set device parent manually.
  - Use input_set_capability.
  - Use the wakeup-source DT property.
  - Drop of_match_table.
  - Use more temporaries.
  - Use dev_err_probe.
- Modify Kconfig description.

 drivers/input/misc/88pm886-onkey.c | 92 ++
 drivers/input/misc/Kconfig |  7 +++
 drivers/input/misc/Makefile|  1 +
 3 files changed, 100 insertions(+)
 create mode 100644 drivers/input/misc/88pm886-onkey.c

diff --git a/drivers/input/misc/88pm886-onkey.c 
b/drivers/input/misc/88pm886-onkey.c
new file mode 100644
index ..2e5df21cd11b
--- /dev/null
+++ b/drivers/input/misc/88pm886-onkey.c
@@ -0,0 +1,92 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+struct pm886_onkey {
+   struct input_dev *idev;
+   struct pm886_chip *chip;
+};
+
+static irqreturn_t pm886_onkey_irq_handler(int irq, void *data)
+{
+   struct pm886_onkey *onkey = data;
+   struct regmap *regmap = onkey->chip->regmaps[PM886_REGMAP_BASE];
+   struct input_dev *idev = onkey->idev;
+   struct device *parent = idev->dev.parent;
+   unsigned int val;
+   int err;
+
+   err = regmap_read(regmap, PM886_REG_STATUS1, );
+   if (err) {
+   dev_err(parent, "Failed to read status: %d\n", err);
+   return IRQ_NONE;
+   }
+   val &= PM886_ONKEY_STS1;
+
+   input_report_key(idev, KEY_POWER, val);
+   input_sync(idev);
+
+   return IRQ_HANDLED;
+}
+
+static int pm886_onkey_probe(struct platform_device *pdev)
+{
+   struct pm886_chip *chip = dev_get_drvdata(pdev->dev.parent);
+   struct device *dev = >dev;
+   struct pm886_onkey *onkey;
+   struct input_dev *idev;
+   int irq, err;
+
+   onkey = devm_kzalloc(dev, sizeof(*onkey), GFP_KERNEL);
+   if (!onkey)
+   return -ENOMEM;
+
+   onkey->chip = chip;
+
+   irq = platform_get_irq(pdev, 0);
+   if (irq < 0)
+   return dev_err_probe(dev, irq, "Failed to get IRQ\n");
+
+   idev = devm_input_allocate_device(dev);
+   if (!idev) {
+   dev_err(dev, "Failed to allocate input device\n");
+   return -ENOMEM;
+   }
+   onkey->idev = idev;
+
+   idev->name = "88pm886-onkey";
+   idev->phys = "88pm886-onkey/input0";
+   idev->id.bustype = BUS_I2C;
+
+   input_set_capability(idev, EV_KEY, KEY_POWER);
+
+   err = devm_request_threaded_irq(dev, irq, NULL, pm886_onkey_irq_handler,
+   IRQF_ONESHOT | IRQF_NO_SUSPEND, "onkey",
+   onkey);
+   if (err)
+   return dev_err_probe(dev, err, "Failed to request IRQ\n");
+
+   err = input_register_device(idev);
+   if (err)
+   return dev_err_probe(dev, err, "Failed to register input 
device\n");
+
+   return 0;
+}
+
+static struct platform_driver pm886_onkey_driver = {
+   .driver = {
+   .name = "88pm886-onkey",
+   },
+   .probe = pm886_onkey_probe,
+};
+module_platform_driver(pm886_onkey_driver);
+
+MODULE_DESCRIPTION("Marvell 88PM886 onkey driver");
+MODULE_AUTHOR("Karel Balej ");
+MODULE_LICENSE("GPL");
diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index 6ba984d7f0b1..16a079d9f0f2 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -33,6 +33,13 @@ config INPUT_88PM80X_ONKEY
  To compile this driver as a module, choose M here: the module
  will be called 88pm80x_onkey.
 
+config INPUT_88PM886_ONKEY
+   tristate "Marvell 88PM886 onkey support"
+   depends on MFD_88PM886_PMIC
+   help
+ Support the onkey of Marvell 88PM886 PMIC as an input device
+ reporting power button status.
+
 config INPUT_AB8500_PONKEY
tristate "AB8500 Pon (PowerOn) Key"
depends on AB8500_CORE
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
index 04296a4abe8e..054a6dc1ac27 100644
--- a/drivers/input/misc/Makefile
+++ b/drivers/input/misc/Makefile
@@ -7,6 +7,7 @@
 
 obj-$(CONFIG_INPUT_88PM860X_ONKEY) +

[RFC PATCH v3 1/5] dt-bindings: mfd: add entry for Marvell 88PM886 PMIC

2024-03-03 Thread Karel Balej
From: Karel Balej 

Marvell 88PM886 is a PMIC with several subdevices such as onkey,
regulators or battery and charger. It comes in at least two revisions,
A0 and A1 -- only A1 is described here at the moment.

Signed-off-by: Karel Balej 
---

Notes:
RFC v3:
- Add wakeup-source property.
- Address Rob's feedback:
  - Move regulators into the MFD file.
  - Remove interrupt-controller and #interrupt-cells properties.
RFC v2:
- Address Rob's feedback:
  - Drop mention of 88PM880.
  - Make sure the file passes bindings check (add the necessary header
and fix `interrupt-cells`).
  - Other small changes.
- Add regulators. Changes with respect to the regulator RFC series:
  - Address Krzysztof's comments:
- Drop unused compatible.
- Fix sub-node pattern.

 .../bindings/mfd/marvell,88pm886-a1.yaml  | 76 +++
 1 file changed, 76 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/mfd/marvell,88pm886-a1.yaml

diff --git a/Documentation/devicetree/bindings/mfd/marvell,88pm886-a1.yaml 
b/Documentation/devicetree/bindings/mfd/marvell,88pm886-a1.yaml
new file mode 100644
index ..61ffbf669e90
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/marvell,88pm886-a1.yaml
@@ -0,0 +1,76 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/marvell,88pm886-a1.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Marvell 88PM886 PMIC core
+
+maintainers:
+  - Karel Balej 
+
+description:
+  Marvell 88PM886 is a PMIC providing several functions such as onkey,
+  regulators or battery and charger.
+
+properties:
+  compatible:
+const: marvell,88pm886-a1
+
+  reg:
+maxItems: 1
+
+  interrupts:
+maxItems: 1
+
+  wakeup-source: true
+
+  regulators:
+type: object
+additionalProperties: false
+patternProperties:
+  "^(ldo(1[0-6]|[1-9])|buck[1-5])$":
+type: object
+$ref: /schemas/regulator/regulator.yaml#
+description: LDO or buck regulator.
+unevaluatedProperties: false
+
+required:
+  - compatible
+  - reg
+  - interrupts
+
+additionalProperties: false
+
+examples:
+  - |
+#include 
+i2c {
+  #address-cells = <1>;
+  #size-cells = <0>;
+  pmic@30 {
+compatible = "marvell,88pm886-a1";
+reg = <0x30>;
+interrupts = <0 4 IRQ_TYPE_LEVEL_HIGH>;
+interrupt-parent = <>;
+wakeup-source;
+
+regulators {
+  ldo2: ldo2 {
+regulator-min-microvolt = <310>;
+regulator-max-microvolt = <330>;
+};
+
+  ldo15: ldo15 {
+regulator-min-microvolt = <330>;
+regulator-max-microvolt = <330>;
+};
+
+  buck2: buck2 {
+regulator-min-microvolt = <180>;
+regulator-max-microvolt = <180>;
+};
+};
+  };
+};
+...
-- 
2.44.0




[RFC PATCH v3 3/5] regulator: add regulators driver for Marvell 88PM886 PMIC

2024-03-03 Thread Karel Balej
From: Karel Balej 

Support the LDO and buck regulators of the Marvell 88PM886 PMIC.

Signed-off-by: Karel Balej 
---

Notes:
RFC v3:
- Do not have a variable for each regulator -- define them all in the
  pm886_regulators array.
- Use new regulators regmap index name.
- Use dev_err_probe.
RFC v2:
- Drop of_compatible and related code.
- Drop unused include.
- Remove some abstraction: use only one regmap for all regulators and
  only mention 88PM886 in Kconfig description.
- Reword commit message.

 drivers/regulator/88pm886-regulator.c | 195 ++
 drivers/regulator/Kconfig |   6 +
 drivers/regulator/Makefile|   1 +
 3 files changed, 202 insertions(+)
 create mode 100644 drivers/regulator/88pm886-regulator.c

diff --git a/drivers/regulator/88pm886-regulator.c 
b/drivers/regulator/88pm886-regulator.c
new file mode 100644
index ..73f6ce413dc3
--- /dev/null
+++ b/drivers/regulator/88pm886-regulator.c
@@ -0,0 +1,195 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#define PM886_REG_LDO_EN1  0x09
+#define PM886_REG_LDO_EN2  0x0a
+
+#define PM886_REG_BUCK_EN  0x08
+
+#define PM886_REG_LDO1_VOUT0x20
+#define PM886_REG_LDO2_VOUT0x26
+#define PM886_REG_LDO3_VOUT0x2c
+#define PM886_REG_LDO4_VOUT0x32
+#define PM886_REG_LDO5_VOUT0x38
+#define PM886_REG_LDO6_VOUT0x3e
+#define PM886_REG_LDO7_VOUT0x44
+#define PM886_REG_LDO8_VOUT0x4a
+#define PM886_REG_LDO9_VOUT0x50
+#define PM886_REG_LDO10_VOUT   0x56
+#define PM886_REG_LDO11_VOUT   0x5c
+#define PM886_REG_LDO12_VOUT   0x62
+#define PM886_REG_LDO13_VOUT   0x68
+#define PM886_REG_LDO14_VOUT   0x6e
+#define PM886_REG_LDO15_VOUT   0x74
+#define PM886_REG_LDO16_VOUT   0x7a
+
+#define PM886_REG_BUCK1_VOUT   0xa5
+#define PM886_REG_BUCK2_VOUT   0xb3
+#define PM886_REG_BUCK3_VOUT   0xc1
+#define PM886_REG_BUCK4_VOUT   0xcf
+#define PM886_REG_BUCK5_VOUT   0xdd
+
+#define PM886_LDO_VSEL_MASK0x0f
+#define PM886_BUCK_VSEL_MASK   0x7f
+
+struct pm886_regulator {
+   struct regulator_desc desc;
+   int max_uA;
+};
+
+static int pm886_regulator_get_ilim(struct regulator_dev *rdev)
+{
+   struct pm886_regulator *data = rdev_get_drvdata(rdev);
+
+   if (!data) {
+   dev_err(>dev, "Failed to get regulator data\n");
+   return -EINVAL;
+   }
+   return data->max_uA;
+}
+
+static const struct regulator_ops pm886_ldo_ops = {
+   .list_voltage = regulator_list_voltage_table,
+   .map_voltage = regulator_map_voltage_iterate,
+   .set_voltage_sel = regulator_set_voltage_sel_regmap,
+   .get_voltage_sel = regulator_get_voltage_sel_regmap,
+   .enable = regulator_enable_regmap,
+   .disable = regulator_disable_regmap,
+   .is_enabled = regulator_is_enabled_regmap,
+   .get_current_limit = pm886_regulator_get_ilim,
+};
+
+static const struct regulator_ops pm886_buck_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 = regulator_get_voltage_sel_regmap,
+   .enable = regulator_enable_regmap,
+   .disable = regulator_disable_regmap,
+   .is_enabled = regulator_is_enabled_regmap,
+   .get_current_limit = pm886_regulator_get_ilim,
+};
+
+static const unsigned int pm886_ldo_volt_table1[] = {
+   170, 180, 190, 250, 280, 290, 310, 330,
+};
+
+static const unsigned int pm886_ldo_volt_table2[] = {
+   120, 125, 170, 180, 185, 190, 250, 260,
+   270, 275, 280, 285, 290, 300, 310, 330,
+};
+
+static const unsigned int pm886_ldo_volt_table3[] = {
+   170, 180, 190, 200, 210, 250, 270, 280,
+};
+
+static const struct linear_range pm886_buck_volt_ranges1[] = {
+   REGULATOR_LINEAR_RANGE(60, 0, 79, 12500),
+   REGULATOR_LINEAR_RANGE(160, 80, 84, 5),
+};
+
+static const struct linear_range pm886_buck_volt_ranges2[] = {
+   REGULATOR_LINEAR_RANGE(60, 0, 79, 12500),
+   REGULATOR_LINEAR_RANGE(160, 80, 114, 5),
+};
+
+static struct pm886_regulator pm886_regulators[] = {
+   [PM886_REGULATOR_ID_LDO2] = {
+   .desc = {
+   .name = "LDO2",
+   .id = PM886_REGULATOR_ID_LDO2,
+   .regulators_node = "regulators",
+   .of_match = "ldo2",
+   .ops = _ldo_ops,
+  

[RFC PATCH v3 2/5] mfd: add driver for Marvell 88PM886 PMIC

2024-03-03 Thread Karel Balej
From: Karel Balej 

Marvell 88PM886 is a PMIC which provides various functions such as
onkey, battery, charger and regulators. It is found for instance in the
samsung,coreprimevelte smartphone with which this was tested.

Only implement basic support to allow for the use of regulators and
onkey omitting the currently unused register definitions and I2C
subclients which should thus be added with the subdevice drivers which
need them.

Signed-off-by: Karel Balej 
---

Notes:
RFC v3:
- Drop onkey cell .of_compatible.
- Rename LDO page offset and regmap to REGULATORS.
RFC v2:
- Remove some abstraction.
- Sort includes alphabetically and add linux/of.h.
- Depend on OF, remove of_match_ptr and add MODULE_DEVICE_TABLE.
- Use more temporaries and break long lines.
- Do not initialize ret in probe.
- Use the wakeup-source DT property.
- Rename ret to err.
- Address Lee's comments:
  - Drop patched in presets for base regmap and related defines.
  - Use full sentences in comments.
  - Remove IRQ comment.
  - Define regmap_config member values.
  - Rename data to sys_off_data.
  - Add _PMIC suffix to Kconfig.
  - Use dev_err_probe.
  - Do not store irq_data.
  - s/WHOAMI/CHIP_ID
  - Drop LINUX part of include guard name.
  - Merge in the regulator series modifications in order to have more
devices and modify the commit message accordingly. Changes with
respect to the original regulator series patches:
- ret -> err
- Add temporary for dev in pm88x_initialize_subregmaps.
- Drop of_compatible for the regulators.
- Do not duplicate LDO regmap for bucks.
- Rewrite commit message.

 drivers/mfd/88pm886.c   | 210 
 drivers/mfd/Kconfig |  12 +++
 drivers/mfd/Makefile|   1 +
 include/linux/mfd/88pm886.h |  46 
 4 files changed, 269 insertions(+)
 create mode 100644 drivers/mfd/88pm886.c
 create mode 100644 include/linux/mfd/88pm886.h

diff --git a/drivers/mfd/88pm886.c b/drivers/mfd/88pm886.c
new file mode 100644
index ..c17220e1b7e2
--- /dev/null
+++ b/drivers/mfd/88pm886.c
@@ -0,0 +1,210 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#define PM886_REG_INT_STATUS1  0x05
+
+#define PM886_REG_INT_ENA_10x0a
+#define PM886_INT_ENA1_ONKEY   BIT(0)
+
+#define PM886_REGMAP_CONF_REG_BITS 8
+#define PM886_REGMAP_CONF_VAL_BITS 8
+#define PM886_REGMAP_CONF_MAX_REG  0xfe
+
+enum pm886_irq_number {
+   PM886_IRQ_ONKEY,
+
+   PM886_MAX_IRQ
+};
+
+static struct regmap_irq pm886_regmap_irqs[] = {
+   REGMAP_IRQ_REG(PM886_IRQ_ONKEY, 0, PM886_INT_ENA1_ONKEY),
+};
+
+static struct regmap_irq_chip pm886_regmap_irq_chip = {
+   .name = "88pm886",
+   .irqs = pm886_regmap_irqs,
+   .num_irqs = ARRAY_SIZE(pm886_regmap_irqs),
+   .num_regs = 4,
+   .status_base = PM886_REG_INT_STATUS1,
+   .ack_base = PM886_REG_INT_STATUS1,
+   .unmask_base = PM886_REG_INT_ENA_1,
+};
+
+static struct resource pm886_onkey_resources[] = {
+   DEFINE_RES_IRQ_NAMED(PM886_IRQ_ONKEY, "88pm886-onkey"),
+};
+
+static struct mfd_cell pm886_devs[] = {
+   {
+   .name = "88pm886-onkey",
+   .num_resources = ARRAY_SIZE(pm886_onkey_resources),
+   .resources = pm886_onkey_resources,
+   },
+   {
+   .name = "88pm886-regulator",
+   .id = PM886_REGULATOR_ID_LDO2,
+   },
+   {
+   .name = "88pm886-regulator",
+   .id = PM886_REGULATOR_ID_LDO15,
+   },
+   {
+   .name = "88pm886-regulator",
+   .id = PM886_REGULATOR_ID_BUCK2,
+   },
+};
+
+static const struct regmap_config pm886_i2c_regmap = {
+   .reg_bits = PM886_REGMAP_CONF_REG_BITS,
+   .val_bits = PM886_REGMAP_CONF_VAL_BITS,
+   .max_register = PM886_REGMAP_CONF_MAX_REG,
+};
+
+static int pm886_power_off_handler(struct sys_off_data *sys_off_data)
+{
+   struct pm886_chip *chip = sys_off_data->cb_data;
+   struct regmap *regmap = chip->regmaps[PM886_REGMAP_BASE];
+   struct device *dev = >client->dev;
+   int err;
+
+   err = regmap_update_bits(regmap, PM886_REG_MISC_CONFIG1, PM886_SW_PDOWN,
+   PM886_SW_PDOWN);
+   if (err) {
+   dev_err(dev, "Failed to power off the device: %d\n", err);
+   return NOTIFY_BAD;
+   }
+   return NOTIFY_DONE;
+}
+
+static int pm886_initialize_subregmaps(struct pm886_chip *chip)
+{
+   struct device *dev = >client->dev;
+   struct i2c_client *page;
+   struct regmap *regmap;
+   int err;
+
+ 

[RFC PATCH v3 0/5] initial support for Marvell 88PM886 PMIC

2024-03-03 Thread Karel Balej
From: Karel Balej 

Hello,

the following implements basic support for Marvell's 88PM886 PMIC which
is found for instance as a component of the samsung,coreprimevelte
smartphone which inspired this and also serves as a testing platform.

The code for the MFD is based primarily on this old series [1] with the
addition of poweroff based on the smartphone's downstream kernel tree
[2]. The onkey and regulators drivers are based on the latter. I am not
in possesion of the datasheet.

[1] 
https://lore.kernel.org/all/1434098601-3498-1-git-send-email-yizh...@marvell.com/
[2] https://github.com/CoderCharmander/g361f-kernel

Thank you and kind regards,
K. B.
---
RFC v3:
- Address Rob's feedback:
  - Drop onkey bindings patch.
- Rename PM88X -> PM886 everywhere.
- RFC v2: 
https://lore.kernel.org/all/20240211094609.2223-1-kar...@gimli.ms.mff.cuni.cz/
RFC v2:
- Merge with the regulators series to have multiple devices and thus
  justify the use of the MFD framework.
- Rebase on v6.8-rc3.
- Reorder patches.
- MFD RFC v1: 
https://lore.kernel.org/all/20231217131838.7569-1-kar...@gimli.ms.mff.cuni.cz/
- regulators RFC v1: 
https://lore.kernel.org/all/20231228100208.2932-1-kar...@gimli.ms.mff.cuni.cz/

Karel Balej (5):
  dt-bindings: mfd: add entry for Marvell 88PM886 PMIC
  mfd: add driver for Marvell 88PM886 PMIC
  regulator: add regulators driver for Marvell 88PM886 PMIC
  input: add onkey driver for Marvell 88PM886 PMIC
  MAINTAINERS: add myself for Marvell 88PM886 PMIC

 .../bindings/mfd/marvell,88pm886-a1.yaml  |  76 +++
 MAINTAINERS   |   9 +
 drivers/input/misc/88pm886-onkey.c|  92 
 drivers/input/misc/Kconfig|   7 +
 drivers/input/misc/Makefile   |   1 +
 drivers/mfd/88pm886.c | 210 ++
 drivers/mfd/Kconfig   |  12 +
 drivers/mfd/Makefile  |   1 +
 drivers/regulator/88pm886-regulator.c | 195 
 drivers/regulator/Kconfig |   6 +
 drivers/regulator/Makefile|   1 +
 include/linux/mfd/88pm886.h   |  46 
 12 files changed, 656 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/mfd/marvell,88pm886-a1.yaml
 create mode 100644 drivers/input/misc/88pm886-onkey.c
 create mode 100644 drivers/mfd/88pm886.c
 create mode 100644 drivers/regulator/88pm886-regulator.c
 create mode 100644 include/linux/mfd/88pm886.h

-- 
2.44.0




[RESEND PATCH v5 5/5] input/touchscreen: imagis: add support for IST3032C

2024-03-01 Thread Karel Balej
From: Karel Balej 

IST3032C is a touchscreen chip used for instance in the
samsung,coreprimevelte smartphone, with which this was tested. Add the
chip specific information to the driver.

Reviewed-by: Markuss Broks 
Signed-off-by: Karel Balej 
---

Notes:
v4:
* Change the WHOAMI definition position to preserve alphanumerical order
  of the definitions.
* Add Markuss' Reviewed-by trailer.

 drivers/input/touchscreen/imagis.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/drivers/input/touchscreen/imagis.c 
b/drivers/input/touchscreen/imagis.c
index 9af8a6332ae6..e1fafa561ee3 100644
--- a/drivers/input/touchscreen/imagis.c
+++ b/drivers/input/touchscreen/imagis.c
@@ -11,6 +11,8 @@
 #include 
 #include 
 
+#define IST3032C_WHOAMI0x32c
+
 #define IST3038B_REG_STATUS0x20
 #define IST3038B_REG_CHIPID0x30
 #define IST3038B_WHOAMI0x30380b
@@ -363,6 +365,13 @@ static int imagis_resume(struct device *dev)
 
 static DEFINE_SIMPLE_DEV_PM_OPS(imagis_pm_ops, imagis_suspend, imagis_resume);
 
+static const struct imagis_properties imagis_3032c_data = {
+   .interrupt_msg_cmd = IST3038C_REG_INTR_MESSAGE,
+   .touch_coord_cmd = IST3038C_REG_TOUCH_COORD,
+   .whoami_cmd = IST3038C_REG_CHIPID,
+   .whoami_val = IST3032C_WHOAMI,
+};
+
 static const struct imagis_properties imagis_3038b_data = {
.interrupt_msg_cmd = IST3038B_REG_STATUS,
.touch_coord_cmd = IST3038B_REG_STATUS,
@@ -380,6 +389,7 @@ static const struct imagis_properties imagis_3038c_data = {
 
 #ifdef CONFIG_OF
 static const struct of_device_id imagis_of_match[] = {
+   { .compatible = "imagis,ist3032c", .data = _3032c_data },
{ .compatible = "imagis,ist3038b", .data = _3038b_data },
{ .compatible = "imagis,ist3038c", .data = _3038c_data },
{ },
-- 
2.44.0




[RESEND PATCH v5 4/5] dt-bindings: input/touchscreen: imagis: add compatible for IST3032C

2024-03-01 Thread Karel Balej
From: Karel Balej 

IST3032C is a touchscreen IC which seems mostly compatible with IST3038C
except that it reports a different chip ID value.

Acked-by: Rob Herring 
Signed-off-by: Karel Balej 
---

Notes:
v5:
- Add Rob's trailer.
v4:
- Reword commit description to mention how this IC differs from the
  already supported.

 .../devicetree/bindings/input/touchscreen/imagis,ist3038c.yaml   | 1 +
 1 file changed, 1 insertion(+)

diff --git 
a/Documentation/devicetree/bindings/input/touchscreen/imagis,ist3038c.yaml 
b/Documentation/devicetree/bindings/input/touchscreen/imagis,ist3038c.yaml
index b5372c4eae56..2af71cbcc97d 100644
--- a/Documentation/devicetree/bindings/input/touchscreen/imagis,ist3038c.yaml
+++ b/Documentation/devicetree/bindings/input/touchscreen/imagis,ist3038c.yaml
@@ -18,6 +18,7 @@ properties:
 
   compatible:
 enum:
+  - imagis,ist3032c
   - imagis,ist3038b
   - imagis,ist3038c
 
-- 
2.44.0




[RESEND PATCH v5 3/5] input/touchscreen: imagis: Add support for Imagis IST3038B

2024-03-01 Thread Karel Balej
From: Markuss Broks 

Imagis IST3038B is another variant of Imagis IST3038 IC, which has
a different register interface from IST3038C (possibly firmware defined).
This should also work for IST3044B (though untested), however other
variants using this interface/protocol(IST3026, IST3032, IST3026B,
IST3032B) have a different format for coordinates, and they'd need
additional effort to be supported by this driver.

Signed-off-by: Markuss Broks 
Signed-off-by: Karel Balej 
---

Notes:
v4:
* Sort the definitions in alphanumerical order.

 drivers/input/touchscreen/imagis.c | 58 --
 1 file changed, 47 insertions(+), 11 deletions(-)

diff --git a/drivers/input/touchscreen/imagis.c 
b/drivers/input/touchscreen/imagis.c
index e67fd3011027..9af8a6332ae6 100644
--- a/drivers/input/touchscreen/imagis.c
+++ b/drivers/input/touchscreen/imagis.c
@@ -11,9 +11,13 @@
 #include 
 #include 
 
+#define IST3038B_REG_STATUS0x20
+#define IST3038B_REG_CHIPID0x30
+#define IST3038B_WHOAMI0x30380b
+
 #define IST3038C_HIB_ACCESS(0x800B << 16)
 #define IST3038C_DIRECT_ACCESS BIT(31)
-#define IST3038C_REG_CHIPID0x40001000
+#define IST3038C_REG_CHIPID(0x40001000 | IST3038C_DIRECT_ACCESS)
 #define IST3038C_REG_HIB_BASE  0x3100
 #define IST3038C_REG_TOUCH_STATUS  (IST3038C_REG_HIB_BASE | 
IST3038C_HIB_ACCESS)
 #define IST3038C_REG_TOUCH_COORD   (IST3038C_REG_HIB_BASE | 
IST3038C_HIB_ACCESS | 0x8)
@@ -31,8 +35,17 @@
 #define IST3038C_FINGER_COUNT_SHIFT12
 #define IST3038C_FINGER_STATUS_MASKGENMASK(9, 0)
 
+struct imagis_properties {
+   unsigned int interrupt_msg_cmd;
+   unsigned int touch_coord_cmd;
+   unsigned int whoami_cmd;
+   unsigned int whoami_val;
+   bool protocol_b;
+};
+
 struct imagis_ts {
struct i2c_client *client;
+   const struct imagis_properties *tdata;
struct input_dev *input_dev;
struct touchscreen_properties prop;
struct regulator_bulk_data supplies[2];
@@ -84,8 +97,7 @@ static irqreturn_t imagis_interrupt(int irq, void *dev_id)
int i;
int error;
 
-   error = imagis_i2c_read_reg(ts, IST3038C_REG_INTR_MESSAGE,
-   _message);
+   error = imagis_i2c_read_reg(ts, ts->tdata->interrupt_msg_cmd, 
_message);
if (error) {
dev_err(>client->dev,
"failed to read the interrupt message: %d\n", error);
@@ -104,9 +116,13 @@ static irqreturn_t imagis_interrupt(int irq, void *dev_id)
finger_pressed = intr_message & IST3038C_FINGER_STATUS_MASK;
 
for (i = 0; i < finger_count; i++) {
-   error = imagis_i2c_read_reg(ts,
-   IST3038C_REG_TOUCH_COORD + (i * 4),
-   _status);
+   if (ts->tdata->protocol_b)
+   error = imagis_i2c_read_reg(ts,
+   ts->tdata->touch_coord_cmd, 
_status);
+   else
+   error = imagis_i2c_read_reg(ts,
+   ts->tdata->touch_coord_cmd 
+ (i * 4),
+   _status);
if (error) {
dev_err(>client->dev,
"failed to read coordinates for finger %d: 
%d\n",
@@ -261,6 +277,12 @@ static int imagis_probe(struct i2c_client *i2c)
 
ts->client = i2c;
 
+   ts->tdata = device_get_match_data(dev);
+   if (!ts->tdata) {
+   dev_err(dev, "missing chip data\n");
+   return -EINVAL;
+   }
+
error = imagis_init_regulators(ts);
if (error) {
dev_err(dev, "regulator init error: %d\n", error);
@@ -279,15 +301,13 @@ static int imagis_probe(struct i2c_client *i2c)
return error;
}
 
-   error = imagis_i2c_read_reg(ts,
-   IST3038C_REG_CHIPID | IST3038C_DIRECT_ACCESS,
-   _id);
+   error = imagis_i2c_read_reg(ts, ts->tdata->whoami_cmd, _id);
if (error) {
dev_err(dev, "chip ID read failure: %d\n", error);
return error;
}
 
-   if (chip_id != IST3038C_WHOAMI) {
+   if (chip_id != ts->tdata->whoami_val) {
dev_err(dev, "unknown chip ID: 0x%x\n", chip_id);
return -EINVAL;
}
@@ -343,9 +363,25 @@ static int imagis_resume(struct device *dev)
 
 static DEFINE_SIMPLE_DEV_PM_OPS(imagis_pm_ops, imagis_suspend, imagis_resume);
 
+static const struct imagis_properties imagis_3038b_data = {
+   .interrupt_msg_cmd = IST3038B_REG_STATUS,
+   .touch_coord_cmd = IST3038B_REG_STATUS,
+ 

[RESEND PATCH v5 2/5] dt-bindings: input/touchscreen: Add compatible for IST3038B

2024-03-01 Thread Karel Balej
From: Markuss Broks 

Imagis IST3038B is a variant (firmware?) of Imagis IST3038 IC
differing from IST3038C in its register interface. Add the
compatible for it to the IST3038C bindings.

Signed-off-by: Markuss Broks 
Acked-by: Conor Dooley 
[bal...@matfyz.cz: elaborate chip differences in the commit message]
Signed-off-by: Karel Balej 
---

Notes:
v4:
* Mention how the chip is different in terms of the programming model in
  the commit message.
* Add Conor's trailer.

 .../devicetree/bindings/input/touchscreen/imagis,ist3038c.yaml   | 1 +
 1 file changed, 1 insertion(+)

diff --git 
a/Documentation/devicetree/bindings/input/touchscreen/imagis,ist3038c.yaml 
b/Documentation/devicetree/bindings/input/touchscreen/imagis,ist3038c.yaml
index 0d6b033fd5fb..b5372c4eae56 100644
--- a/Documentation/devicetree/bindings/input/touchscreen/imagis,ist3038c.yaml
+++ b/Documentation/devicetree/bindings/input/touchscreen/imagis,ist3038c.yaml
@@ -18,6 +18,7 @@ properties:
 
   compatible:
 enum:
+  - imagis,ist3038b
   - imagis,ist3038c
 
   reg:
-- 
2.44.0




[RESEND PATCH v5 0/5] input/touchscreen: imagis: add support for IST3032C

2024-03-01 Thread Karel Balej
From: Karel Balej 

Hello,

this patch series generalizes the Imagis touchscreen driver to support
other Imagis chips, namely IST3038B and IST3032C.

The motivation for IST3032C is the samsung,coreprimevelte smartphone
with which this series has been tested. However, the support for this
device is not yet in-tree, the effort is happening at [1]. Preliminary
version of the regulator driver needed to use the touchscreen on this
phone can be found here [2].

Note that this is a prerequisite for (at least a part of) this series
[3] which among other things implements support for touch keys for
Imagis touchscreens that have it.

[1] 
https://lore.kernel.org/all/20240110-pxa1908-lkml-v8-0-fea768a59...@skole.hr/
[2] 
https://lore.kernel.org/all/20240211094609.2223-1-kar...@gimli.ms.mff.cuni.cz/
[3] 
https://lore.kernel.org/all/20240120-b4-imagis-keys-v2-0-d7fc16f2e...@skole.hr/

Best regards,
K. B.
---
v5:
- Rebase to v6.8-rc3.
- v4: 
https://lore.kernel.org/all/20240120191940.3631-1-kar...@gimli.ms.mff.cuni.cz/
v4:
- Rebase to v6.7.
- v3: 
https://lore.kernel.org/all/20231202125948.10345-1-kar...@gimli.ms.mff.cuni.cz/
- Address feedback and add trailers.
v3:
- Rebase to v6.7-rc3.
- v2: 
https://lore.kernel.org/all/20231003133440.4696-1-kar...@gimli.ms.mff.cuni.cz/
v2:
- Do not rename the driver.
- Do not hardcode voltage required by the IST3032C.
- Use Markuss' series which generalizes the driver. Link to the original
  series: 
https://lore.kernel.org/all/20220504152406.8730-1-markuss.br...@gmail.com/
- Separate bindings into separate patch.
- v1: https://lore.kernel.org/all/20230926173531.18715-1-bal...@matfyz.cz/

Karel Balej (2):
  dt-bindings: input/touchscreen: imagis: add compatible for IST3032C
  input/touchscreen: imagis: add support for IST3032C

Markuss Broks (3):
  input/touchscreen: imagis: Correct the maximum touch area value
  dt-bindings: input/touchscreen: Add compatible for IST3038B
  input/touchscreen: imagis: Add support for Imagis IST3038B

 .../input/touchscreen/imagis,ist3038c.yaml|  2 +
 drivers/input/touchscreen/imagis.c| 70 +++
 2 files changed, 60 insertions(+), 12 deletions(-)

-- 
2.44.0




[RESEND PATCH v5 1/5] input/touchscreen: imagis: Correct the maximum touch area value

2024-03-01 Thread Karel Balej
From: Markuss Broks 

As specified in downstream IST3038B driver and proved by testing,
the correct maximum reported value of touch area is 16.

Signed-off-by: Markuss Broks 
Signed-off-by: Karel Balej 
---
 drivers/input/touchscreen/imagis.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/input/touchscreen/imagis.c 
b/drivers/input/touchscreen/imagis.c
index 07111ca24455..e67fd3011027 100644
--- a/drivers/input/touchscreen/imagis.c
+++ b/drivers/input/touchscreen/imagis.c
@@ -210,7 +210,7 @@ static int imagis_init_input_dev(struct imagis_ts *ts)
 
input_set_capability(input_dev, EV_ABS, ABS_MT_POSITION_X);
input_set_capability(input_dev, EV_ABS, ABS_MT_POSITION_Y);
-   input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
+   input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, 16, 0, 0);
 
touchscreen_parse_properties(input_dev, true, >prop);
if (!ts->prop.max_x || !ts->prop.max_y) {
-- 
2.44.0




Re: [RFC PATCH v2 1/6] dt-bindings: mfd: add entry for Marvell 88PM886 PMIC

2024-02-18 Thread Karel Balej
Rob Herring, 2024-02-15T08:20:52-06:00:
> >  .../bindings/mfd/marvell,88pm88x.yaml | 74 +++
>
> Filename should match the compatible.
>
> In general, drop the 'x' wildcard.

By "in general", do you mean for the drivers code also?

As I have mentioned in the commit message for the driver, the other
device is very similar and if the support for it was ever to be added
(which I personally currently have no interest in), I believe it would
make sense to extend this driver. Is it then still prefered to call it
all just 88pm886 now?

> > +properties:
> > +  compatible:
> > +const: marvell,88pm886-a1

So the file should be called marvell,88pm886-a1.yaml, correct? Again, is
it prefered to call it like this even if the other revision could
eventually be added (again, I am not interested in that right now
personally)? I mean, if I was implementing support for both revisions
right now, it would make sense to name it just marvell,88pm886.yaml, no?

Thank you, kind regards,
K. B.



[RFC PATCH v2 6/6] MAINTAINERS: add myself for Marvell 88PM886 PMIC

2024-02-11 Thread Karel Balej
From: Karel Balej 

Add an entry to MAINTAINERS for the Marvell 88PM886 PMIC MFD, onkey and
regulator drivers.

Signed-off-by: Karel Balej 
---

Notes:
RFC v2:
- Only mention 88PM886 in the commit message.
- Add regulator driver.
- Rename the entry.

 MAINTAINERS | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 960512bec428..c8628b9c633d 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -12949,6 +12949,17 @@ F: drivers/net/dsa/mv88e6xxx/
 F: include/linux/dsa/mv88e6xxx.h
 F: include/linux/platform_data/mv88e6xxx.h
 
+MARVELL 88PM886 PMIC DRIVER
+M: Karel Balej 
+S: Maintained
+F: Documentation/devicetree/bindings/input/marvell,88pm88x-onkey.yaml
+F: Documentation/devicetree/bindings/mfd/marvell,88pm88x.yaml
+F: 
Documentation/devicetree/bindings/regulator/marvell,88pm88x-regulator.yaml
+F: drivers/input/misc/88pm88x-onkey.c
+F: drivers/mfd/88pm88x.c
+F: drivers/regulators/88pm88x-regulator.c
+F: include/linux/mfd/88pm88x.h
+
 MARVELL ARMADA 3700 PHY DRIVERS
 M: Miquel Raynal 
 S: Maintained
-- 
2.43.0




[RFC PATCH v2 5/6] input: add onkey driver for Marvell 88PM88X PMICs

2024-02-11 Thread Karel Balej
From: Karel Balej 

Marvell 88PM88X PMICs provide onkey among other things. Add client
driver to handle it. The driver currently only provides a basic support
omitting additional functions found in the vendor version, such as long
onkey and GPIO integration.

Signed-off-by: Karel Balej 
---

Notes:
RFC v2:
- Address Dmitry's feedback:
  - Sort includes alphabetically.
  - Drop onkey->irq.
  - ret -> err in irq_handler and no initialization.
  - Break long lines and other formatting.
  - Do not clobber platform_get_irq error.
  - Do not set device parent manually.
  - Use input_set_capability.
  - Use the wakeup-source DT property.
  - Drop of_match_table.
  - Use more temporaries.
  - Use dev_err_probe.
- Modify Kconfig description.

 drivers/input/misc/88pm88x-onkey.c | 95 ++
 drivers/input/misc/Kconfig |  7 +++
 drivers/input/misc/Makefile|  1 +
 3 files changed, 103 insertions(+)
 create mode 100644 drivers/input/misc/88pm88x-onkey.c

diff --git a/drivers/input/misc/88pm88x-onkey.c 
b/drivers/input/misc/88pm88x-onkey.c
new file mode 100644
index ..2a0bd63a63a7
--- /dev/null
+++ b/drivers/input/misc/88pm88x-onkey.c
@@ -0,0 +1,95 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+struct pm88x_onkey {
+   struct input_dev *idev;
+   struct pm88x_chip *chip;
+};
+
+static irqreturn_t pm88x_onkey_irq_handler(int irq, void *data)
+{
+   struct pm88x_onkey *onkey = data;
+   struct regmap *regmap = onkey->chip->regmaps[PM88X_REGMAP_BASE];
+   struct input_dev *idev = onkey->idev;
+   struct device *parent = idev->dev.parent;
+   unsigned int val;
+   int err;
+
+   err = regmap_read(regmap, PM88X_REG_STATUS1, );
+   if (err) {
+   dev_err(parent, "Failed to read status: %d\n", err);
+   return IRQ_NONE;
+   }
+   val &= PM88X_ONKEY_STS1;
+
+   input_report_key(idev, KEY_POWER, val);
+   input_sync(idev);
+
+   return IRQ_HANDLED;
+}
+
+static int pm88x_onkey_probe(struct platform_device *pdev)
+{
+   struct pm88x_chip *chip = dev_get_drvdata(pdev->dev.parent);
+   struct device *dev = >dev;
+   struct pm88x_onkey *onkey;
+   struct input_dev *idev;
+   int irq, err;
+
+   onkey = devm_kzalloc(dev, sizeof(*onkey), GFP_KERNEL);
+   if (!onkey)
+   return -ENOMEM;
+
+   onkey->chip = chip;
+
+   irq = platform_get_irq(pdev, 0);
+   if (irq < 0)
+   return dev_err_probe(dev, irq, "Failed to get IRQ\n");
+
+   idev = devm_input_allocate_device(dev);
+   if (!idev) {
+   dev_err(dev, "Failed to allocate input device\n");
+   return -ENOMEM;
+   }
+   onkey->idev = idev;
+
+   idev->name = "88pm88x-onkey";
+   idev->phys = "88pm88x-onkey/input0";
+   idev->id.bustype = BUS_I2C;
+
+   input_set_capability(idev, EV_KEY, KEY_POWER);
+
+   err = devm_request_threaded_irq(dev, irq, NULL, pm88x_onkey_irq_handler,
+   IRQF_ONESHOT | IRQF_NO_SUSPEND, "onkey",
+   onkey);
+   if (err)
+   return dev_err_probe(dev, err, "Failed to request IRQ\n");
+
+   err = input_register_device(idev);
+   if (err)
+   return dev_err_probe(dev, err, "Failed to register input 
device\n");
+
+   device_init_wakeup(dev, device_property_read_bool(dev, 
"wakeup-source"));
+
+   return 0;
+}
+
+static struct platform_driver pm88x_onkey_driver = {
+   .driver = {
+   .name = "88pm88x-onkey",
+   },
+   .probe = pm88x_onkey_probe,
+};
+module_platform_driver(pm88x_onkey_driver);
+
+MODULE_DESCRIPTION("Marvell 88PM88X onkey driver");
+MODULE_AUTHOR("Karel Balej ");
+MODULE_LICENSE("GPL");
diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index 6ba984d7f0b1..97a1ff83e8df 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -33,6 +33,13 @@ config INPUT_88PM80X_ONKEY
  To compile this driver as a module, choose M here: the module
  will be called 88pm80x_onkey.
 
+config INPUT_88PM88X_ONKEY
+   tristate "Marvell 88PM88X onkey support"
+   depends on MFD_88PM88X_PMIC
+   help
+ Support the onkey of Marvell 88PM88X PMICs as an input device
+ reporting power button status.
+
 config INPUT_AB8500_PONKEY
tristate "AB8500 Pon (PowerOn) Key"
depends on AB8500_CORE
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
index 04296a4abe8e..eab7a364188c 100644
--- a/drivers/input/misc/Makefile
+++ b/dr

[RFC PATCH v2 4/6] dt-bindings: input: add entry for Marvell 88PM88X PMICs onkey

2024-02-11 Thread Karel Balej
From: Karel Balej 

Marvell 88PM88X PMICs provide onkey functionality -- add the bindings.

Signed-off-by: Karel Balej 
---

Notes:
RFC v2:
- Add wakeup-source property and reference onkey schema from MFD.
- Reword commit message.

 .../bindings/input/marvell,88pm88x-onkey.yaml | 32 +++
 .../bindings/mfd/marvell,88pm88x.yaml |  8 +
 2 files changed, 40 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/input/marvell,88pm88x-onkey.yaml

diff --git a/Documentation/devicetree/bindings/input/marvell,88pm88x-onkey.yaml 
b/Documentation/devicetree/bindings/input/marvell,88pm88x-onkey.yaml
new file mode 100644
index ..5d3d451d0e1f
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/marvell,88pm88x-onkey.yaml
@@ -0,0 +1,32 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/input/marvell,88pm88x-onkey.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Onkey driver for Marvell 88PM88X PMICs.
+
+maintainers:
+  - Karel Balej 
+
+description: |
+  This module is part of the 88PM88X MFD device. For more details
+  see Documentation/devicetree/bindings/mfd/marvell,88pm88x.yaml.
+
+  The onkey controller is represented as a sub-node of the PMIC node in
+  the device tree.
+
+allOf:
+  - $ref: input.yaml#
+
+properties:
+  compatible:
+const: marvell,88pm88x-onkey
+
+  wakeup-source: true
+
+required:
+  - compatible
+
+additionalProperties: false
+...
diff --git a/Documentation/devicetree/bindings/mfd/marvell,88pm88x.yaml 
b/Documentation/devicetree/bindings/mfd/marvell,88pm88x.yaml
index 29ab979862d5..2507a73d4dc3 100644
--- a/Documentation/devicetree/bindings/mfd/marvell,88pm88x.yaml
+++ b/Documentation/devicetree/bindings/mfd/marvell,88pm88x.yaml
@@ -28,6 +28,9 @@ properties:
   "#interrupt-cells":
 const: 1
 
+  onkey:
+$ref: /schemas/input/marvell,88pm88x-onkey.yaml
+
   regulators:
 $ref: /schemas/regulator/marvell,88pm88x-regulator.yaml#
 
@@ -53,6 +56,11 @@ examples:
 interrupt-controller;
 #interrupt-cells = <1>;
 
+onkey {
+  compatible = "marvell,88pm88x-onkey";
+  wakeup-source;
+};
+
 regulators {
   ldo2: ldo2 {
 regulator-min-microvolt = <310>;
-- 
2.43.0




[RFC PATCH v2 3/6] regulator: add regulators driver for Marvell 88PM886 PMIC

2024-02-11 Thread Karel Balej
From: Karel Balej 

Support the LDO and buck regulators of the Marvell 88PM886 PMIC.

88PM886 LDOs match those of 88PM880 which also has several more of them.
88PM880 buck regulators descriptions do not match and they sit on a
different register page and thus need a separate I2C client and regmap.

Signed-off-by: Karel Balej 
---

Notes:
RFC v2:
- Drop of_compatible and related code.
- Drop unused include.
- Remove some abstraction: use only one regmap for all regulators and
  only mention 88PM886 in Kconfig description.
- Reword commit message.

 drivers/regulator/88pm88x-regulator.c | 206 ++
 drivers/regulator/Kconfig |   6 +
 drivers/regulator/Makefile|   1 +
 3 files changed, 213 insertions(+)
 create mode 100644 drivers/regulator/88pm88x-regulator.c

diff --git a/drivers/regulator/88pm88x-regulator.c 
b/drivers/regulator/88pm88x-regulator.c
new file mode 100644
index ..fd84b9604ac6
--- /dev/null
+++ b/drivers/regulator/88pm88x-regulator.c
@@ -0,0 +1,206 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#define PM88X_REG_LDO_EN1  0x09
+#define PM88X_REG_LDO_EN2  0x0a
+
+#define PM88X_REG_BUCK_EN  0x08
+
+#define PM88X_REG_LDO1_VOUT0x20
+#define PM88X_REG_LDO2_VOUT0x26
+#define PM88X_REG_LDO3_VOUT0x2c
+#define PM88X_REG_LDO4_VOUT0x32
+#define PM88X_REG_LDO5_VOUT0x38
+#define PM88X_REG_LDO6_VOUT0x3e
+#define PM88X_REG_LDO7_VOUT0x44
+#define PM88X_REG_LDO8_VOUT0x4a
+#define PM88X_REG_LDO9_VOUT0x50
+#define PM88X_REG_LDO10_VOUT   0x56
+#define PM88X_REG_LDO11_VOUT   0x5c
+#define PM88X_REG_LDO12_VOUT   0x62
+#define PM88X_REG_LDO13_VOUT   0x68
+#define PM88X_REG_LDO14_VOUT   0x6e
+#define PM88X_REG_LDO15_VOUT   0x74
+#define PM88X_REG_LDO16_VOUT   0x7a
+
+#define PM886_REG_BUCK1_VOUT   0xa5
+#define PM886_REG_BUCK2_VOUT   0xb3
+#define PM886_REG_BUCK3_VOUT   0xc1
+#define PM886_REG_BUCK4_VOUT   0xcf
+#define PM886_REG_BUCK5_VOUT   0xdd
+
+#define PM88X_LDO_VSEL_MASK0x0f
+#define PM88X_BUCK_VSEL_MASK   0x7f
+
+struct pm88x_regulator {
+   struct regulator_desc desc;
+   int max_uA;
+};
+
+static int pm88x_regulator_get_ilim(struct regulator_dev *rdev)
+{
+   struct pm88x_regulator *data = rdev_get_drvdata(rdev);
+
+   if (!data) {
+   dev_err(>dev, "Failed to get regulator data\n");
+   return -EINVAL;
+   }
+   return data->max_uA;
+}
+
+static const struct regulator_ops pm88x_ldo_ops = {
+   .list_voltage = regulator_list_voltage_table,
+   .map_voltage = regulator_map_voltage_iterate,
+   .set_voltage_sel = regulator_set_voltage_sel_regmap,
+   .get_voltage_sel = regulator_get_voltage_sel_regmap,
+   .enable = regulator_enable_regmap,
+   .disable = regulator_disable_regmap,
+   .is_enabled = regulator_is_enabled_regmap,
+   .get_current_limit = pm88x_regulator_get_ilim,
+};
+
+static const struct regulator_ops pm88x_buck_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 = regulator_get_voltage_sel_regmap,
+   .enable = regulator_enable_regmap,
+   .disable = regulator_disable_regmap,
+   .is_enabled = regulator_is_enabled_regmap,
+   .get_current_limit = pm88x_regulator_get_ilim,
+};
+
+static const unsigned int pm88x_ldo_volt_table1[] = {
+   170, 180, 190, 250, 280, 290, 310, 330,
+};
+
+static const unsigned int pm88x_ldo_volt_table2[] = {
+   120, 125, 170, 180, 185, 190, 250, 260,
+   270, 275, 280, 285, 290, 300, 310, 330,
+};
+
+static const unsigned int pm88x_ldo_volt_table3[] = {
+   170, 180, 190, 200, 210, 250, 270, 280,
+};
+
+static const struct linear_range pm88x_buck_volt_ranges1[] = {
+   REGULATOR_LINEAR_RANGE(60, 0, 79, 12500),
+   REGULATOR_LINEAR_RANGE(160, 80, 84, 5),
+};
+
+static const struct linear_range pm88x_buck_volt_ranges2[] = {
+   REGULATOR_LINEAR_RANGE(60, 0, 79, 12500),
+   REGULATOR_LINEAR_RANGE(160, 80, 114, 5),
+};
+
+static struct pm88x_regulator pm88x_ldo2 = {
+   .desc = {
+   .name = "LDO2",
+   .id = PM88X_REGULATOR_ID_LDO2,
+   .regulators_node = "regulators",
+   .of_match = "ldo2",
+   .ops = _ldo_ops,
+   .type = REGULATOR_VOLTAGE,
+   .enable_reg = PM88X_REG

[RFC PATCH v2 1/6] dt-bindings: mfd: add entry for Marvell 88PM886 PMIC

2024-02-11 Thread Karel Balej
From: Karel Balej 

Marvell 88PM886 is a PMIC with several subdevices such as onkey,
regulators or battery and charger. It comes in at least two revisions,
A0 and A1 -- only A1 is described here at the moment.

Signed-off-by: Karel Balej 
---

Notes:
RFC v2:
- Address Rob's feedback:
  - Drop mention of 88PM880.
  - Make sure the file passes bindings check (add the necessary header
and fix `interrupt-cells`).
  - Other small changes.
- Add regulators. Changes with respect to the regulator RFC series:
  - Address Krzysztof's comments:
- Drop unused compatible.
- Fix sub-node pattern.

 .../bindings/mfd/marvell,88pm88x.yaml | 74 +++
 .../regulator/marvell,88pm88x-regulator.yaml  | 28 +++
 2 files changed, 102 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/marvell,88pm88x.yaml
 create mode 100644 
Documentation/devicetree/bindings/regulator/marvell,88pm88x-regulator.yaml

diff --git a/Documentation/devicetree/bindings/mfd/marvell,88pm88x.yaml 
b/Documentation/devicetree/bindings/mfd/marvell,88pm88x.yaml
new file mode 100644
index ..29ab979862d5
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/marvell,88pm88x.yaml
@@ -0,0 +1,74 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/marvell,88pm88x.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Marvell 88PM88X PMIC core
+
+maintainers:
+  - Karel Balej 
+
+description:
+  Marvell 88PM886 is a PMIC providing several functions such as onkey,
+  regulators or battery and charger.
+
+properties:
+  compatible:
+const: marvell,88pm886-a1
+
+  reg:
+maxItems: 1
+
+  interrupt-controller: true
+
+  interrupts:
+maxItems: 1
+
+  "#interrupt-cells":
+const: 1
+
+  regulators:
+$ref: /schemas/regulator/marvell,88pm88x-regulator.yaml#
+
+required:
+  - compatible
+  - reg
+  - interrupt-controller
+  - interrupts
+
+additionalProperties: false
+
+examples:
+  - |
+#include 
+i2c {
+  #address-cells = <1>;
+  #size-cells = <0>;
+  pmic@30 {
+compatible = "marvell,88pm886-a1";
+reg = <0x30>;
+interrupts = <0 4 IRQ_TYPE_LEVEL_HIGH>;
+interrupt-parent = <>;
+interrupt-controller;
+#interrupt-cells = <1>;
+
+regulators {
+  ldo2: ldo2 {
+regulator-min-microvolt = <310>;
+regulator-max-microvolt = <330>;
+};
+
+  ldo15: ldo15 {
+regulator-min-microvolt = <330>;
+regulator-max-microvolt = <330>;
+};
+
+  buck2: buck2 {
+regulator-min-microvolt = <180>;
+regulator-max-microvolt = <180>;
+};
+};
+  };
+};
+...
diff --git 
a/Documentation/devicetree/bindings/regulator/marvell,88pm88x-regulator.yaml 
b/Documentation/devicetree/bindings/regulator/marvell,88pm88x-regulator.yaml
new file mode 100644
index ..1b4b5f1b4932
--- /dev/null
+++ b/Documentation/devicetree/bindings/regulator/marvell,88pm88x-regulator.yaml
@@ -0,0 +1,28 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/regulator/marvell,88pm88x-regulator.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Regulators of Marvell 88PM88X PMICs.
+
+maintainers:
+  - Karel Balej 
+
+description: |
+  This is a part of device tree bindings for Marvell 88PM88X MFD.
+
+  The regulators node is represented as a sub-node of the PMIC node on the
+  device tree.
+
+  See also Documentation/devicetree/bindings/mfd/marvell,88pm88x.yaml for
+  additional information and example.
+
+patternProperties:
+  "^(ldo(1[0-6]|[1-9])|buck[1-5])$":
+type: object
+$ref: /schemas/regulator/regulator.yaml#
+description: LDO or buck regulator.
+unevaluatedProperties: false
+
+additionalProperties: false
-- 
2.43.0




[RFC PATCH v2 0/6] support for Marvell 88PM886 PMIC

2024-02-11 Thread Karel Balej
From: Karel Balej 

Hello,

the following implements basic support for Marvell's 88PM886 PMIC which
is found for instance as a component of the samsung,coreprimevelte
smartphone which inspired this and also serves as a testing platform.

The code for the MFD is based primarily on this old series [1] with the
addition of poweroff based on the smartphone's downstream kernel tree
[2]. The onkey and regulators drivers are based on the latter. I am not
in possesion of the datasheet.

[1] 
https://lore.kernel.org/all/1434098601-3498-1-git-send-email-yizh...@marvell.com/
[2] https://github.com/CoderCharmander/g361f-kernel

Thank you and kind regards,
K. B.
---
RFC v2:
- Merge with the regulators series to have multiple devices and thus
  justify the use of the MFD framework.
- Rebase on v6.8-rc3.
- Reorder patches.
- MFD RFC v1: 
https://lore.kernel.org/all/20231217131838.7569-1-kar...@gimli.ms.mff.cuni.cz/
- regulators RFC v1: 
https://lore.kernel.org/all/20231228100208.2932-1-kar...@gimli.ms.mff.cuni.cz/

Karel Balej (6):
  dt-bindings: mfd: add entry for Marvell 88PM886 PMIC
  mfd: add driver for Marvell 88PM886 PMIC
  regulator: add regulators driver for Marvell 88PM886 PMIC
  dt-bindings: input: add entry for Marvell 88PM88X PMICs onkey
  input: add onkey driver for Marvell 88PM88X PMICs
  MAINTAINERS: add myself for Marvell 88PM886 PMIC

 .../bindings/input/marvell,88pm88x-onkey.yaml |  32 +++
 .../bindings/mfd/marvell,88pm88x.yaml |  82 +++
 .../regulator/marvell,88pm88x-regulator.yaml  |  28 +++
 MAINTAINERS   |  11 +
 drivers/input/misc/88pm88x-onkey.c|  95 
 drivers/input/misc/Kconfig|   7 +
 drivers/input/misc/Makefile   |   1 +
 drivers/mfd/88pm88x.c | 211 ++
 drivers/mfd/Kconfig   |  12 +
 drivers/mfd/Makefile  |   1 +
 drivers/regulator/88pm88x-regulator.c | 206 +
 drivers/regulator/Kconfig |   6 +
 drivers/regulator/Makefile|   1 +
 include/linux/mfd/88pm88x.h   |  46 
 14 files changed, 739 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/input/marvell,88pm88x-onkey.yaml
 create mode 100644 Documentation/devicetree/bindings/mfd/marvell,88pm88x.yaml
 create mode 100644 
Documentation/devicetree/bindings/regulator/marvell,88pm88x-regulator.yaml
 create mode 100644 drivers/input/misc/88pm88x-onkey.c
 create mode 100644 drivers/mfd/88pm88x.c
 create mode 100644 drivers/regulator/88pm88x-regulator.c
 create mode 100644 include/linux/mfd/88pm88x.h

-- 
2.43.0




[RFC PATCH v2 2/6] mfd: add driver for Marvell 88PM886 PMIC

2024-02-11 Thread Karel Balej
From: Karel Balej 

Marvell 88PM886 is a PMIC which provides various functions such as
onkey, battery, charger and regulators. It is found for instance in the
samsung,coreprimevelte smartphone with which this was tested.

Only implement basic support to allow for the use of regulators and
onkey omitting the currently unused register definitions and I2C
subclients which should thus be added with the subdevice drivers which
need them.

The register mapping and functions of 88PM886 are very similar to those
of 88PM880 and the downstream version of the driver handles both of
these devices. Possible future efforts to support 88PM880 should thus
make use of this driver.

Signed-off-by: Karel Balej 
---

Notes:
RFC v2:
- Remove some abstraction.
- Sort includes alphabetically and add linux/of.h.
- Depend on OF, remove of_match_ptr and add MODULE_DEVICE_TABLE.
- Use more temporaries and break long lines.
- Do not initialize ret in probe.
- Use the wakeup-source DT property.
- Rename ret to err.
- Address Lee's comments:
  - Drop patched in presets for base regmap and related defines.
  - Use full sentences in comments.
  - Remove IRQ comment.
  - Define regmap_config member values.
  - Rename data to sys_off_data.
  - Add _PMIC suffix to Kconfig.
  - Use dev_err_probe.
  - Do not store irq_data.
  - s/WHOAMI/CHIP_ID
  - Drop LINUX part of include guard name.
  - Merge in the regulator series modifications in order to have more
devices and modify the commit message accordingly. Changes with
respect to the original regulator series patches:
- ret -> err
- Add temporary for dev in pm88x_initialize_subregmaps.
- Drop of_compatible for the regulators.
- Do not duplicate LDO regmap for bucks.
- Rewrite commit message.

 drivers/mfd/88pm88x.c   | 211 
 drivers/mfd/Kconfig |  12 ++
 drivers/mfd/Makefile|   1 +
 include/linux/mfd/88pm88x.h |  46 
 4 files changed, 270 insertions(+)
 create mode 100644 drivers/mfd/88pm88x.c
 create mode 100644 include/linux/mfd/88pm88x.h

diff --git a/drivers/mfd/88pm88x.c b/drivers/mfd/88pm88x.c
new file mode 100644
index ..301e3e8f26f4
--- /dev/null
+++ b/drivers/mfd/88pm88x.c
@@ -0,0 +1,211 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#define PM88X_REG_INT_STATUS1  0x05
+
+#define PM88X_REG_INT_ENA_10x0a
+#define PM88X_INT_ENA1_ONKEY   BIT(0)
+
+#define PM88X_REGMAP_CONF_REG_BITS 8
+#define PM88X_REGMAP_CONF_VAL_BITS 8
+#define PM88X_REGMAP_CONF_MAX_REG  0xfe
+
+enum pm88x_irq_number {
+   PM88X_IRQ_ONKEY,
+
+   PM88X_MAX_IRQ
+};
+
+static struct regmap_irq pm88x_regmap_irqs[] = {
+   REGMAP_IRQ_REG(PM88X_IRQ_ONKEY, 0, PM88X_INT_ENA1_ONKEY),
+};
+
+static struct regmap_irq_chip pm88x_regmap_irq_chip = {
+   .name = "88pm88x",
+   .irqs = pm88x_regmap_irqs,
+   .num_irqs = ARRAY_SIZE(pm88x_regmap_irqs),
+   .num_regs = 4,
+   .status_base = PM88X_REG_INT_STATUS1,
+   .ack_base = PM88X_REG_INT_STATUS1,
+   .unmask_base = PM88X_REG_INT_ENA_1,
+};
+
+static struct resource pm88x_onkey_resources[] = {
+   DEFINE_RES_IRQ_NAMED(PM88X_IRQ_ONKEY, "88pm88x-onkey"),
+};
+
+static struct mfd_cell pm886_devs[] = {
+   {
+   .name = "88pm88x-onkey",
+   .of_compatible = "marvell,88pm88x-onkey",
+   .num_resources = ARRAY_SIZE(pm88x_onkey_resources),
+   .resources = pm88x_onkey_resources,
+   },
+   {
+   .name = "88pm88x-regulator",
+   .id = PM88X_REGULATOR_ID_LDO2,
+   },
+   {
+   .name = "88pm88x-regulator",
+   .id = PM88X_REGULATOR_ID_LDO15,
+   },
+   {
+   .name = "88pm88x-regulator",
+   .id = PM886_REGULATOR_ID_BUCK2,
+   },
+};
+
+static const struct regmap_config pm88x_i2c_regmap = {
+   .reg_bits = PM88X_REGMAP_CONF_REG_BITS,
+   .val_bits = PM88X_REGMAP_CONF_VAL_BITS,
+   .max_register = PM88X_REGMAP_CONF_MAX_REG,
+};
+
+static int pm88x_power_off_handler(struct sys_off_data *sys_off_data)
+{
+   struct pm88x_chip *chip = sys_off_data->cb_data;
+   struct regmap *regmap = chip->regmaps[PM88X_REGMAP_BASE];
+   struct device *dev = >client->dev;
+   int err;
+
+   err = regmap_update_bits(regmap, PM88X_REG_MISC_CONFIG1, PM88X_SW_PDOWN,
+   PM88X_SW_PDOWN);
+   if (err) {
+   dev_err(dev, "Failed to power off the device: %d\n", err);
+   return NOTIFY_BAD;
+   }
+   return NOTIFY_DONE;
+}
+
+static int pm88x_initialize_s

[PATCH v5 0/5] input/touchscreen: imagis: add support for IST3032C

2024-02-09 Thread Karel Balej
From: Karel Balej 

Hello,

this patch series generalizes the Imagis touchscreen driver to support
other Imagis chips, namely IST3038B and IST3032C, which use a slightly
different protocol.

The motivation for IST3032C is the samsung,coreprimevelte smartphone
with which this series has been tested. However, the support for this
device is not yet in-tree, the effort is happening at [1]. Preliminary
version of the regulator driver needed to use the touchscreen on this
phone can be found here [2].

Note that this is a prerequisite for (at least a part of) this series
[3] which among other things implements support for touch keys for
Imagis touchscreens that have it.

[1] 
https://lore.kernel.org/all/20240110-pxa1908-lkml-v8-0-fea768a59...@skole.hr/
[2] 
https://lore.kernel.org/all/20231228100208.2932-1-kar...@gimli.ms.mff.cuni.cz/
[3] 
https://lore.kernel.org/all/20240120-b4-imagis-keys-v2-0-d7fc16f2e...@skole.hr/
---
v5:
- Rebase to v6.8-rc3.
- v4: 
https://lore.kernel.org/all/20240120191940.3631-1-kar...@gimli.ms.mff.cuni.cz/
v4:
- Rebase to v6.7.
- v3: 
https://lore.kernel.org/all/20231202125948.10345-1-kar...@gimli.ms.mff.cuni.cz/
- Address feedback and add trailers.
v3:
- Rebase to v6.7-rc3.
- v2: 
https://lore.kernel.org/all/20231003133440.4696-1-kar...@gimli.ms.mff.cuni.cz/
v2:
- Do not rename the driver.
- Do not hardcode voltage required by the IST3032C.
- Use Markuss' series which generalizes the driver. Link to the original
  series: 
https://lore.kernel.org/all/20220504152406.8730-1-markuss.br...@gmail.com/
- Separate bindings into separate patch.
- v1: https://lore.kernel.org/all/20230926173531.18715-1-bal...@matfyz.cz/

Karel Balej (2):
  dt-bindings: input/touchscreen: imagis: add compatible for IST3032C
  input/touchscreen: imagis: add support for IST3032C

Markuss Broks (3):
  input/touchscreen: imagis: Correct the maximum touch area value
  dt-bindings: input/touchscreen: Add compatible for IST3038B
  input/touchscreen: imagis: Add support for Imagis IST3038B

 .../input/touchscreen/imagis,ist3038c.yaml|  2 +
 drivers/input/touchscreen/imagis.c| 70 +++
 2 files changed, 60 insertions(+), 12 deletions(-)

-- 
2.43.0




[PATCH v5 3/5] input/touchscreen: imagis: Add support for Imagis IST3038B

2024-02-09 Thread Karel Balej
From: Markuss Broks 

Imagis IST3038B is another variant of Imagis IST3038 IC, which has
a different register interface from IST3038C (possibly firmware defined).
This should also work for IST3044B (though untested), however other
variants using this interface/protocol(IST3026, IST3032, IST3026B,
IST3032B) have a different format for coordinates, and they'd need
additional effort to be supported by this driver.

Signed-off-by: Markuss Broks 
Signed-off-by: Karel Balej 
---

Notes:
v4:
* Sort the definitions in alphanumerical order.

 drivers/input/touchscreen/imagis.c | 58 --
 1 file changed, 47 insertions(+), 11 deletions(-)

diff --git a/drivers/input/touchscreen/imagis.c 
b/drivers/input/touchscreen/imagis.c
index e67fd3011027..9af8a6332ae6 100644
--- a/drivers/input/touchscreen/imagis.c
+++ b/drivers/input/touchscreen/imagis.c
@@ -11,9 +11,13 @@
 #include 
 #include 
 
+#define IST3038B_REG_STATUS0x20
+#define IST3038B_REG_CHIPID0x30
+#define IST3038B_WHOAMI0x30380b
+
 #define IST3038C_HIB_ACCESS(0x800B << 16)
 #define IST3038C_DIRECT_ACCESS BIT(31)
-#define IST3038C_REG_CHIPID0x40001000
+#define IST3038C_REG_CHIPID(0x40001000 | IST3038C_DIRECT_ACCESS)
 #define IST3038C_REG_HIB_BASE  0x3100
 #define IST3038C_REG_TOUCH_STATUS  (IST3038C_REG_HIB_BASE | 
IST3038C_HIB_ACCESS)
 #define IST3038C_REG_TOUCH_COORD   (IST3038C_REG_HIB_BASE | 
IST3038C_HIB_ACCESS | 0x8)
@@ -31,8 +35,17 @@
 #define IST3038C_FINGER_COUNT_SHIFT12
 #define IST3038C_FINGER_STATUS_MASKGENMASK(9, 0)
 
+struct imagis_properties {
+   unsigned int interrupt_msg_cmd;
+   unsigned int touch_coord_cmd;
+   unsigned int whoami_cmd;
+   unsigned int whoami_val;
+   bool protocol_b;
+};
+
 struct imagis_ts {
struct i2c_client *client;
+   const struct imagis_properties *tdata;
struct input_dev *input_dev;
struct touchscreen_properties prop;
struct regulator_bulk_data supplies[2];
@@ -84,8 +97,7 @@ static irqreturn_t imagis_interrupt(int irq, void *dev_id)
int i;
int error;
 
-   error = imagis_i2c_read_reg(ts, IST3038C_REG_INTR_MESSAGE,
-   _message);
+   error = imagis_i2c_read_reg(ts, ts->tdata->interrupt_msg_cmd, 
_message);
if (error) {
dev_err(>client->dev,
"failed to read the interrupt message: %d\n", error);
@@ -104,9 +116,13 @@ static irqreturn_t imagis_interrupt(int irq, void *dev_id)
finger_pressed = intr_message & IST3038C_FINGER_STATUS_MASK;
 
for (i = 0; i < finger_count; i++) {
-   error = imagis_i2c_read_reg(ts,
-   IST3038C_REG_TOUCH_COORD + (i * 4),
-   _status);
+   if (ts->tdata->protocol_b)
+   error = imagis_i2c_read_reg(ts,
+   ts->tdata->touch_coord_cmd, 
_status);
+   else
+   error = imagis_i2c_read_reg(ts,
+   ts->tdata->touch_coord_cmd 
+ (i * 4),
+   _status);
if (error) {
dev_err(>client->dev,
"failed to read coordinates for finger %d: 
%d\n",
@@ -261,6 +277,12 @@ static int imagis_probe(struct i2c_client *i2c)
 
ts->client = i2c;
 
+   ts->tdata = device_get_match_data(dev);
+   if (!ts->tdata) {
+   dev_err(dev, "missing chip data\n");
+   return -EINVAL;
+   }
+
error = imagis_init_regulators(ts);
if (error) {
dev_err(dev, "regulator init error: %d\n", error);
@@ -279,15 +301,13 @@ static int imagis_probe(struct i2c_client *i2c)
return error;
}
 
-   error = imagis_i2c_read_reg(ts,
-   IST3038C_REG_CHIPID | IST3038C_DIRECT_ACCESS,
-   _id);
+   error = imagis_i2c_read_reg(ts, ts->tdata->whoami_cmd, _id);
if (error) {
dev_err(dev, "chip ID read failure: %d\n", error);
return error;
}
 
-   if (chip_id != IST3038C_WHOAMI) {
+   if (chip_id != ts->tdata->whoami_val) {
dev_err(dev, "unknown chip ID: 0x%x\n", chip_id);
return -EINVAL;
}
@@ -343,9 +363,25 @@ static int imagis_resume(struct device *dev)
 
 static DEFINE_SIMPLE_DEV_PM_OPS(imagis_pm_ops, imagis_suspend, imagis_resume);
 
+static const struct imagis_properties imagis_3038b_data = {
+   .interrupt_msg_cmd = IST3038B_REG_STATUS,
+   .touch_coord_cmd = IST3038B_REG_STATUS,
+ 

[PATCH v5 4/5] dt-bindings: input/touchscreen: imagis: add compatible for IST3032C

2024-02-09 Thread Karel Balej
From: Karel Balej 

IST3032C is a touchscreen IC which seems mostly compatible with IST3038C
except that it reports a different chip ID value.

Acked-by: Rob Herring 
Signed-off-by: Karel Balej 
---

Notes:
v5:
- Add Rob's trailer.
v4:
- Reword commit description to mention how this IC differs from the
  already supported.

 .../devicetree/bindings/input/touchscreen/imagis,ist3038c.yaml   | 1 +
 1 file changed, 1 insertion(+)

diff --git 
a/Documentation/devicetree/bindings/input/touchscreen/imagis,ist3038c.yaml 
b/Documentation/devicetree/bindings/input/touchscreen/imagis,ist3038c.yaml
index b5372c4eae56..2af71cbcc97d 100644
--- a/Documentation/devicetree/bindings/input/touchscreen/imagis,ist3038c.yaml
+++ b/Documentation/devicetree/bindings/input/touchscreen/imagis,ist3038c.yaml
@@ -18,6 +18,7 @@ properties:
 
   compatible:
 enum:
+  - imagis,ist3032c
   - imagis,ist3038b
   - imagis,ist3038c
 
-- 
2.43.0




[PATCH v5 2/5] dt-bindings: input/touchscreen: Add compatible for IST3038B

2024-02-09 Thread Karel Balej
From: Markuss Broks 

Imagis IST3038B is a variant (firmware?) of Imagis IST3038 IC
differing from IST3038C in its register interface. Add the
compatible for it to the IST3038C bindings.

Signed-off-by: Markuss Broks 
Acked-by: Conor Dooley 
[bal...@matfyz.cz: elaborate chip differences in the commit message]
Signed-off-by: Karel Balej 
---

Notes:
v4:
* Mention how the chip is different in terms of the programming model in
  the commit message.
* Add Conor's trailer.

 .../devicetree/bindings/input/touchscreen/imagis,ist3038c.yaml   | 1 +
 1 file changed, 1 insertion(+)

diff --git 
a/Documentation/devicetree/bindings/input/touchscreen/imagis,ist3038c.yaml 
b/Documentation/devicetree/bindings/input/touchscreen/imagis,ist3038c.yaml
index 0d6b033fd5fb..b5372c4eae56 100644
--- a/Documentation/devicetree/bindings/input/touchscreen/imagis,ist3038c.yaml
+++ b/Documentation/devicetree/bindings/input/touchscreen/imagis,ist3038c.yaml
@@ -18,6 +18,7 @@ properties:
 
   compatible:
 enum:
+  - imagis,ist3038b
   - imagis,ist3038c
 
   reg:
-- 
2.43.0




[PATCH v5 1/5] input/touchscreen: imagis: Correct the maximum touch area value

2024-02-09 Thread Karel Balej
From: Markuss Broks 

As specified in downstream IST3038B driver and proved by testing,
the correct maximum reported value of touch area is 16.

Signed-off-by: Markuss Broks 
Signed-off-by: Karel Balej 
---
 drivers/input/touchscreen/imagis.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/input/touchscreen/imagis.c 
b/drivers/input/touchscreen/imagis.c
index 07111ca24455..e67fd3011027 100644
--- a/drivers/input/touchscreen/imagis.c
+++ b/drivers/input/touchscreen/imagis.c
@@ -210,7 +210,7 @@ static int imagis_init_input_dev(struct imagis_ts *ts)
 
input_set_capability(input_dev, EV_ABS, ABS_MT_POSITION_X);
input_set_capability(input_dev, EV_ABS, ABS_MT_POSITION_Y);
-   input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
+   input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, 16, 0, 0);
 
touchscreen_parse_properties(input_dev, true, >prop);
if (!ts->prop.max_x || !ts->prop.max_y) {
-- 
2.43.0




[PATCH v5 5/5] input/touchscreen: imagis: add support for IST3032C

2024-02-09 Thread Karel Balej
From: Karel Balej 

IST3032C is a touchscreen chip used for instance in the
samsung,coreprimevelte smartphone, with which this was tested. Add the
chip specific information to the driver.

Reviewed-by: Markuss Broks 
Signed-off-by: Karel Balej 
---

Notes:
v4:
* Change the WHOAMI definition position to preserve alphanumerical order
  of the definitions.
* Add Markuss' Reviewed-by trailer.

 drivers/input/touchscreen/imagis.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/drivers/input/touchscreen/imagis.c 
b/drivers/input/touchscreen/imagis.c
index 9af8a6332ae6..e1fafa561ee3 100644
--- a/drivers/input/touchscreen/imagis.c
+++ b/drivers/input/touchscreen/imagis.c
@@ -11,6 +11,8 @@
 #include 
 #include 
 
+#define IST3032C_WHOAMI0x32c
+
 #define IST3038B_REG_STATUS0x20
 #define IST3038B_REG_CHIPID0x30
 #define IST3038B_WHOAMI0x30380b
@@ -363,6 +365,13 @@ static int imagis_resume(struct device *dev)
 
 static DEFINE_SIMPLE_DEV_PM_OPS(imagis_pm_ops, imagis_suspend, imagis_resume);
 
+static const struct imagis_properties imagis_3032c_data = {
+   .interrupt_msg_cmd = IST3038C_REG_INTR_MESSAGE,
+   .touch_coord_cmd = IST3038C_REG_TOUCH_COORD,
+   .whoami_cmd = IST3038C_REG_CHIPID,
+   .whoami_val = IST3032C_WHOAMI,
+};
+
 static const struct imagis_properties imagis_3038b_data = {
.interrupt_msg_cmd = IST3038B_REG_STATUS,
.touch_coord_cmd = IST3038B_REG_STATUS,
@@ -380,6 +389,7 @@ static const struct imagis_properties imagis_3038c_data = {
 
 #ifdef CONFIG_OF
 static const struct of_device_id imagis_of_match[] = {
+   { .compatible = "imagis,ist3032c", .data = _3032c_data },
{ .compatible = "imagis,ist3038b", .data = _3038b_data },
{ .compatible = "imagis,ist3038c", .data = _3038c_data },
{ },
-- 
2.43.0




Re: [RFC PATCH 2/5] mfd: add 88pm88x driver

2024-02-02 Thread Karel Balej
Lee Jones, 2024-02-02T12:45:50+00:00:
> On Thu, 01 Feb 2024, Karel Balej wrote:
>
> > Lee Jones, 2024-01-31T11:03:11+00:00:
> > > On Sun, 28 Jan 2024, Karel Balej wrote:
> > > > > > +   /* GPIO1: DVC, GPIO0: input */
> > > > > > +   REG_SEQ0(PM88X_REG_GPIO_CTRL1, 0x40),
> > > > >
> > > > > Shouldn't you set these up using Pintrl?
> > > > 
> > > > You mean to add a new MFD cell for the pins and write the respective
> > > > driver? The downstream implementation has no such thing so I'm not sure
> > > > if I would be able to do that from scratch.
> > >
> > > This is not a Pinctrl driver.
> > >
> > > Isn't there a generic API you can use?
> > 
> > I'm sorry, I don't think I understand what you mean.
>
> Perhaps I misunderstand the code.  It looks like this regmap patch hack
> is configuring pins and a bunch of other things.  Would that be a
> correct assessment?

Yes, that sounds correct.

> If so, where do we draw the line here?  Do we accept a 1000 line driver
> which configures a large SoC with a bunch of bespoke register writes?

I understand, I just don't know what you mean by "a generic API". I'm
also not clear on whether what you have in mind is simply adding a
dedicated driver for the pins as a new subdevice of this MFD.

Thanks,
K. B.



Re: [RFC PATCH 2/5] mfd: add 88pm88x driver

2024-02-01 Thread Karel Balej
Lee Jones, 2024-01-31T11:03:11+00:00:
> On Sun, 28 Jan 2024, Karel Balej wrote:
> > > > +   /* GPIO1: DVC, GPIO0: input */
> > > > +   REG_SEQ0(PM88X_REG_GPIO_CTRL1, 0x40),
> > >
> > > Shouldn't you set these up using Pintrl?
> > 
> > You mean to add a new MFD cell for the pins and write the respective
> > driver? The downstream implementation has no such thing so I'm not sure
> > if I would be able to do that from scratch.
>
> This is not a Pinctrl driver.
>
> Isn't there a generic API you can use?

I'm sorry, I don't think I understand what you mean.

Thank you,
K. B.



Re: [RFC PATCH 2/5] mfd: add 88pm88x driver

2024-01-28 Thread Karel Balej
Lee,

thank you for your feedback.

On Thu Jan 25, 2024 at 1:26 PM CET, Lee Jones wrote:

[...]

> > +#define PM88X_REG_INT_STATUS1  0x05
> > +
> > +#define PM88X_REG_INT_ENA_10x0a
> > +#define PM88X_INT_ENA1_ONKEY   BIT(0)
> > +
> > +enum pm88x_irq_number {
> > +   PM88X_IRQ_ONKEY,
> > +
> > +   PM88X_MAX_IRQ
> > +};
>
> An enum for a single IRQ?

There will be a lot more IRQs but I have only added this one so far as
it is the only one used by this series -- is that OK?

> > +static struct reg_sequence pm886_presets[] = {
> > +   /* disable watchdog */
> > +   REG_SEQ0(PM88X_REG_WDOG, 0x01),
>
> Easier to read if you place spaces between them.
>
> > +   /* GPIO1: DVC, GPIO0: input */
> > +   REG_SEQ0(PM88X_REG_GPIO_CTRL1, 0x40),
>
> Shouldn't you set these up using Pintrl?

You mean to add a new MFD cell for the pins and write the respective
driver? The downstream implementation has no such thing so I'm not sure
if I would be able to do that from scratch.

> > +   /* GPIO2: input */
> > +   REG_SEQ0(PM88X_REG_GPIO_CTRL2, 0x00),
> > +   /* DVC2, DVC1 */
>
> Please unify all of the comments.
>
> They all use a different structure.
>
> > +   REG_SEQ0(PM88X_REG_GPIO_CTRL3, 0x44),
> > +   /* GPIO5V_1:input, GPIO5V_2: input */
> > +   REG_SEQ0(PM88X_REG_GPIO_CTRL4, 0x00),
> > +   /* output 32 kHz from XO */
> > +   REG_SEQ0(PM88X_REG_AON_CTRL2, 0x2a),
> > +   /* OSC_FREERUN = 1, to lock FLL */
> > +   REG_SEQ0(PM88X_REG_BK_OSC_CTRL1, 0x0f),
> > +   /* XO_LJ = 1, enable low jitter for 32 kHz */
> > +   REG_SEQ0(PM88X_REG_LOWPOWER2, 0x20),
> > +   /* OV_VSYS and UV_VSYS1 comparators on VSYS disabled, VSYS_OVER_TH : 
> > 5.6V */
> > +   REG_SEQ0(PM88X_REG_LOWPOWER4, 0xc8),
> > +   /* set the duty cycle of charger DC/DC to max */
> > +   REG_SEQ0(PM88X_REG_BK_OSC_CTRL3, 0xc0),
>
> These all looks like they should be handled in their respective drivers?
>
> "patch"ing these in seems like a hack.

To be honest, I don't really know why these are required and what effect
they have -- the comments above taken from the downstream version are
the only thing I have to go by. I might try removing them to see if
there is any noticable change and whether they could be added only later
with the respective drivers.

>
> > +};
>
> Why this instead of 

What are you refering to here please?

> > +static struct resource onkey_resources[] = {
> > +   DEFINE_RES_IRQ_NAMED(PM88X_IRQ_ONKEY, "88pm88x-onkey"),
> > +};
> > +
> > +static struct mfd_cell pm88x_devs[] = {
> > +   {
> > +   .name = "88pm88x-onkey",
> > +   .num_resources = ARRAY_SIZE(onkey_resources),
> > +   .resources = onkey_resources,
> > +   .id = -1,
> > +   },
> > +};
>
> It's not an MFD if it only supports a single device.

As I have noted above with respect to the IRQ enum and also in the
commit message, I have so far only added the parts which there is
already use for. I intend to add the other parts along with the
respective subdevice drivers, please see my regulator series [1] for an
example.

I thought this approach would make for shorter and simpler patches and
also would allow me to make more informed decisions as I familiarize
myself with the downstream subdevice drivers more closely one by one.

> > +   i2c_set_clientdata(client, chip);
> > +
> > +   device_init_wakeup(>dev, 1);
> > +
> > +   chip->regmaps[PM88X_REGMAP_BASE] = devm_regmap_init_i2c(client, 
> > _i2c_regmap);
> > +   if (IS_ERR(chip->regmaps[PM88X_REGMAP_BASE])) {
>
> Just define different regmaps if you really need them.

You mean not to use an array of regmaps but add new struct members
instead? One for each regmap?

> > diff --git a/include/linux/mfd/88pm88x.h b/include/linux/mfd/88pm88x.h
> > new file mode 100644
> > index ..a34c57447827
> > --- /dev/null
> > +++ b/include/linux/mfd/88pm88x.h

[...]

> > +#define PM88X_REG_ID   0x00
> > +
> > +#define PM88X_REG_STATUS1  0x01
> > +#define PM88X_ONKEY_STS1   BIT(0)
> > +
> > +#define PM88X_REG_MISC_CONFIG1 0x14
> > +#define PM88X_SW_PDOWN BIT(5)
> > +
> > +#define PM88X_REG_MISC_CONFIG2 0x15
> > +#define PM88X_INT_INV  BIT(0)
> > +#define PM88X_INT_CLEARBIT(1)
> > +#define PM88X_INT_RC   0x00
> > +#define PM88X_INT_WC   BIT(1)
> > +#define PM88X_INT_MASK_MODEBIT(2)
> > +
> > +#define PM88X_REG_WDOG 0x1d
> > +
> > +#define PM88X_REG_LOWPOWER20x21
> > +#define PM88X_REG_LOWPOWER40x23
> > +
> > +#define PM88X_REG_GPIO_CTRL1   0x30
>
> These don't really need to be spaced out, do they?

I have spaced them out already as I expect to add some related
definitions to each of these in the future and thought it would then
perhaps be more easily readable like this.

[1] 

[PATCH v4 5/5] input/touchscreen: imagis: add support for IST3032C

2024-01-20 Thread Karel Balej
From: Karel Balej 

IST3032C is a touchscreen chip used for instance in the
samsung,coreprimevelte smartphone, with which this was tested. Add the
chip specific information to the driver.

Reviewed-by: Markuss Broks 
Signed-off-by: Karel Balej 
---

Notes:
v4:
* Change the WHOAMI definition position to preserve alphanumerical order
  of the definitions.
* Add Markuss' Reviewed-by trailer.

 drivers/input/touchscreen/imagis.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/drivers/input/touchscreen/imagis.c 
b/drivers/input/touchscreen/imagis.c
index 9af8a6332ae6..e1fafa561ee3 100644
--- a/drivers/input/touchscreen/imagis.c
+++ b/drivers/input/touchscreen/imagis.c
@@ -11,6 +11,8 @@
 #include 
 #include 
 
+#define IST3032C_WHOAMI0x32c
+
 #define IST3038B_REG_STATUS0x20
 #define IST3038B_REG_CHIPID0x30
 #define IST3038B_WHOAMI0x30380b
@@ -363,6 +365,13 @@ static int imagis_resume(struct device *dev)
 
 static DEFINE_SIMPLE_DEV_PM_OPS(imagis_pm_ops, imagis_suspend, imagis_resume);
 
+static const struct imagis_properties imagis_3032c_data = {
+   .interrupt_msg_cmd = IST3038C_REG_INTR_MESSAGE,
+   .touch_coord_cmd = IST3038C_REG_TOUCH_COORD,
+   .whoami_cmd = IST3038C_REG_CHIPID,
+   .whoami_val = IST3032C_WHOAMI,
+};
+
 static const struct imagis_properties imagis_3038b_data = {
.interrupt_msg_cmd = IST3038B_REG_STATUS,
.touch_coord_cmd = IST3038B_REG_STATUS,
@@ -380,6 +389,7 @@ static const struct imagis_properties imagis_3038c_data = {
 
 #ifdef CONFIG_OF
 static const struct of_device_id imagis_of_match[] = {
+   { .compatible = "imagis,ist3032c", .data = _3032c_data },
{ .compatible = "imagis,ist3038b", .data = _3038b_data },
{ .compatible = "imagis,ist3038c", .data = _3038c_data },
{ },
-- 
2.43.0




[PATCH v4 4/5] dt-bindings: input/touchscreen: imagis: add compatible for IST3032C

2024-01-20 Thread Karel Balej
From: Karel Balej 

IST3032C is a touchscreen IC which seems mostly compatible with IST3038C
except that it reports a different chip ID value.

Signed-off-by: Karel Balej 
---

Notes:
v4:
* Reword commit description to mention how this IC differs from the
  already supported.

 .../devicetree/bindings/input/touchscreen/imagis,ist3038c.yaml   | 1 +
 1 file changed, 1 insertion(+)

diff --git 
a/Documentation/devicetree/bindings/input/touchscreen/imagis,ist3038c.yaml 
b/Documentation/devicetree/bindings/input/touchscreen/imagis,ist3038c.yaml
index b5372c4eae56..2af71cbcc97d 100644
--- a/Documentation/devicetree/bindings/input/touchscreen/imagis,ist3038c.yaml
+++ b/Documentation/devicetree/bindings/input/touchscreen/imagis,ist3038c.yaml
@@ -18,6 +18,7 @@ properties:
 
   compatible:
 enum:
+  - imagis,ist3032c
   - imagis,ist3038b
   - imagis,ist3038c
 
-- 
2.43.0




[PATCH v4 3/5] input/touchscreen: imagis: Add support for Imagis IST3038B

2024-01-20 Thread Karel Balej
From: Markuss Broks 

Imagis IST3038B is another variant of Imagis IST3038 IC, which has
a different register interface from IST3038C (possibly firmware defined).
This should also work for IST3044B (though untested), however other
variants using this interface/protocol(IST3026, IST3032, IST3026B,
IST3032B) have a different format for coordinates, and they'd need
additional effort to be supported by this driver.

Signed-off-by: Markuss Broks 
Signed-off-by: Karel Balej 
---

Notes:
v4:
* Sort the definitions in alphanumerical order.

 drivers/input/touchscreen/imagis.c | 58 --
 1 file changed, 47 insertions(+), 11 deletions(-)

diff --git a/drivers/input/touchscreen/imagis.c 
b/drivers/input/touchscreen/imagis.c
index e67fd3011027..9af8a6332ae6 100644
--- a/drivers/input/touchscreen/imagis.c
+++ b/drivers/input/touchscreen/imagis.c
@@ -11,9 +11,13 @@
 #include 
 #include 
 
+#define IST3038B_REG_STATUS0x20
+#define IST3038B_REG_CHIPID0x30
+#define IST3038B_WHOAMI0x30380b
+
 #define IST3038C_HIB_ACCESS(0x800B << 16)
 #define IST3038C_DIRECT_ACCESS BIT(31)
-#define IST3038C_REG_CHIPID0x40001000
+#define IST3038C_REG_CHIPID(0x40001000 | IST3038C_DIRECT_ACCESS)
 #define IST3038C_REG_HIB_BASE  0x3100
 #define IST3038C_REG_TOUCH_STATUS  (IST3038C_REG_HIB_BASE | 
IST3038C_HIB_ACCESS)
 #define IST3038C_REG_TOUCH_COORD   (IST3038C_REG_HIB_BASE | 
IST3038C_HIB_ACCESS | 0x8)
@@ -31,8 +35,17 @@
 #define IST3038C_FINGER_COUNT_SHIFT12
 #define IST3038C_FINGER_STATUS_MASKGENMASK(9, 0)
 
+struct imagis_properties {
+   unsigned int interrupt_msg_cmd;
+   unsigned int touch_coord_cmd;
+   unsigned int whoami_cmd;
+   unsigned int whoami_val;
+   bool protocol_b;
+};
+
 struct imagis_ts {
struct i2c_client *client;
+   const struct imagis_properties *tdata;
struct input_dev *input_dev;
struct touchscreen_properties prop;
struct regulator_bulk_data supplies[2];
@@ -84,8 +97,7 @@ static irqreturn_t imagis_interrupt(int irq, void *dev_id)
int i;
int error;
 
-   error = imagis_i2c_read_reg(ts, IST3038C_REG_INTR_MESSAGE,
-   _message);
+   error = imagis_i2c_read_reg(ts, ts->tdata->interrupt_msg_cmd, 
_message);
if (error) {
dev_err(>client->dev,
"failed to read the interrupt message: %d\n", error);
@@ -104,9 +116,13 @@ static irqreturn_t imagis_interrupt(int irq, void *dev_id)
finger_pressed = intr_message & IST3038C_FINGER_STATUS_MASK;
 
for (i = 0; i < finger_count; i++) {
-   error = imagis_i2c_read_reg(ts,
-   IST3038C_REG_TOUCH_COORD + (i * 4),
-   _status);
+   if (ts->tdata->protocol_b)
+   error = imagis_i2c_read_reg(ts,
+   ts->tdata->touch_coord_cmd, 
_status);
+   else
+   error = imagis_i2c_read_reg(ts,
+   ts->tdata->touch_coord_cmd 
+ (i * 4),
+   _status);
if (error) {
dev_err(>client->dev,
"failed to read coordinates for finger %d: 
%d\n",
@@ -261,6 +277,12 @@ static int imagis_probe(struct i2c_client *i2c)
 
ts->client = i2c;
 
+   ts->tdata = device_get_match_data(dev);
+   if (!ts->tdata) {
+   dev_err(dev, "missing chip data\n");
+   return -EINVAL;
+   }
+
error = imagis_init_regulators(ts);
if (error) {
dev_err(dev, "regulator init error: %d\n", error);
@@ -279,15 +301,13 @@ static int imagis_probe(struct i2c_client *i2c)
return error;
}
 
-   error = imagis_i2c_read_reg(ts,
-   IST3038C_REG_CHIPID | IST3038C_DIRECT_ACCESS,
-   _id);
+   error = imagis_i2c_read_reg(ts, ts->tdata->whoami_cmd, _id);
if (error) {
dev_err(dev, "chip ID read failure: %d\n", error);
return error;
}
 
-   if (chip_id != IST3038C_WHOAMI) {
+   if (chip_id != ts->tdata->whoami_val) {
dev_err(dev, "unknown chip ID: 0x%x\n", chip_id);
return -EINVAL;
}
@@ -343,9 +363,25 @@ static int imagis_resume(struct device *dev)
 
 static DEFINE_SIMPLE_DEV_PM_OPS(imagis_pm_ops, imagis_suspend, imagis_resume);
 
+static const struct imagis_properties imagis_3038b_data = {
+   .interrupt_msg_cmd = IST3038B_REG_STATUS,
+   .touch_coord_cmd = IST3038B_REG_STATUS,
+ 

[PATCH v4 2/5] dt-bindings: input/touchscreen: Add compatible for IST3038B

2024-01-20 Thread Karel Balej
From: Markuss Broks 

Imagis IST3038B is a variant (firmware?) of Imagis IST3038 IC
differing from IST3038C in its register interface. Add the
compatible for it to the IST3038C bindings.

Signed-off-by: Markuss Broks 
Acked-by: Conor Dooley 
[bal...@matfyz.cz: elaborate chip differences in the commit message]
Signed-off-by: Karel Balej 
---

Notes:
v4:
* Mention how the chip is different in terms of the programming model in
  the commit message.
* Add Conor's trailer.

 .../devicetree/bindings/input/touchscreen/imagis,ist3038c.yaml   | 1 +
 1 file changed, 1 insertion(+)

diff --git 
a/Documentation/devicetree/bindings/input/touchscreen/imagis,ist3038c.yaml 
b/Documentation/devicetree/bindings/input/touchscreen/imagis,ist3038c.yaml
index 0d6b033fd5fb..b5372c4eae56 100644
--- a/Documentation/devicetree/bindings/input/touchscreen/imagis,ist3038c.yaml
+++ b/Documentation/devicetree/bindings/input/touchscreen/imagis,ist3038c.yaml
@@ -18,6 +18,7 @@ properties:
 
   compatible:
 enum:
+  - imagis,ist3038b
   - imagis,ist3038c
 
   reg:
-- 
2.43.0




[PATCH v4 1/5] input/touchscreen: imagis: Correct the maximum touch area value

2024-01-20 Thread Karel Balej
From: Markuss Broks 

As specified in downstream IST3038B driver and proved by testing,
the correct maximum reported value of touch area is 16.

Signed-off-by: Markuss Broks 
Signed-off-by: Karel Balej 
---
 drivers/input/touchscreen/imagis.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/input/touchscreen/imagis.c 
b/drivers/input/touchscreen/imagis.c
index 07111ca24455..e67fd3011027 100644
--- a/drivers/input/touchscreen/imagis.c
+++ b/drivers/input/touchscreen/imagis.c
@@ -210,7 +210,7 @@ static int imagis_init_input_dev(struct imagis_ts *ts)
 
input_set_capability(input_dev, EV_ABS, ABS_MT_POSITION_X);
input_set_capability(input_dev, EV_ABS, ABS_MT_POSITION_Y);
-   input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
+   input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, 16, 0, 0);
 
touchscreen_parse_properties(input_dev, true, >prop);
if (!ts->prop.max_x || !ts->prop.max_y) {
-- 
2.43.0




[PATCH v4 0/5] input/touchscreen: imagis: add support for IST3032C

2024-01-20 Thread Karel Balej
From: Karel Balej 

Hello,

this patch series generalizes the Imagis touchscreen driver to support
other Imagis chips, namely IST3038B and IST3032C, which use a slightly
different protocol.

It also adds necessary information to the driver so that the IST3032C
touchscreen can be used with it. The motivation for this is the
samsung,coreprimevelte smartphone with which this series has been
tested. However, the support for this device is not yet in-tree, the
effort is happening at [1]. Preliminary version of the regulator driver
needed to use the touchscreen on this phone can be found here [2].

Note that this is a prerequisite for this patch [3] which implements
support for touch keys for Imagis touchscreens that have it.

[1] 
https://lore.kernel.org/all/20240110-pxa1908-lkml-v8-0-fea768a59...@skole.hr/
[2] 
https://lore.kernel.org/all/20231228100208.2932-1-kar...@gimli.ms.mff.cuni.cz/
[3] https://lore.kernel.org/all/20231112194124.24916-1-duje.mihano...@skole.hr/
---
v4:
- Rebase to v6.7.
- v3: 
https://lore.kernel.org/all/20231202125948.10345-1-kar...@gimli.ms.mff.cuni.cz/
- Address feedback and add trailers.
v3:
- Rebase to v6.7-rc3.
- v2: 
https://lore.kernel.org/all/20231003133440.4696-1-kar...@gimli.ms.mff.cuni.cz/
v2:
- Do not rename the driver.
- Do not hardcode voltage required by the IST3032C.
- Use Markuss' series which generalizes the driver. Link to the original
  series: 
https://lore.kernel.org/all/20220504152406.8730-1-markuss.br...@gmail.com/
- Separate bindings into separate patch.
- v1: https://lore.kernel.org/all/20230926173531.18715-1-bal...@matfyz.cz/

Karel Balej (2):
  dt-bindings: input/touchscreen: imagis: add compatible for IST3032C
  input/touchscreen: imagis: add support for IST3032C

Markuss Broks (3):
  input/touchscreen: imagis: Correct the maximum touch area value
  dt-bindings: input/touchscreen: Add compatible for IST3038B
  input/touchscreen: imagis: Add support for Imagis IST3038B

 .../input/touchscreen/imagis,ist3038c.yaml|  2 +
 drivers/input/touchscreen/imagis.c| 70 +++
 2 files changed, 60 insertions(+), 12 deletions(-)

-- 
2.43.0




Re: [RFC PATCH 1/5] mfd: 88pm88x: differences with respect to the PMIC RFC series

2024-01-11 Thread Karel Balej
On Thu Jan 11, 2024 at 4:25 PM CET, Lee Jones wrote:

[...]

> > > > diff --git a/include/linux/mfd/88pm88x.h b/include/linux/mfd/88pm88x.h
> > > > index a34c57447827..9a335f6b9c07 100644
> > > > --- a/include/linux/mfd/88pm88x.h
> > > > +++ b/include/linux/mfd/88pm88x.h
> > > > @@ -49,6 +49,8 @@ struct pm88x_data {
> > > > unsigned int whoami;
> > > > struct reg_sequence *presets;
> > > > unsigned int num_presets;
> > > > +   struct mfd_cell *devs;
> > > > +   unsigned int num_devs;
> > >
> > > Why are you adding extra abstraction?
> > 
> > Right, this is probably not necessary now since I'm only implementing
> > support for one of the chips - it's just that I keep thinking about it
> > as a driver for both of them and thus tend to write it a bit more
> > abstractly. Shall I then drop this and also the `presets` member which
> > is also chip-specific?
>
> Even if you were to support multiple devices, this strategy is unusual
> and isn't likely to be accepted.

May I please ask what the recommended strategy is then? `switch`ing on
the chip ID? I have taken this approach because it seemed to produce a
cleaner/more straightforward code in comparison to that. Or are you only
talking about the chip cells/subdevices in particular?

Thank you,
K. B.



Re: [RFC PATCH 1/5] mfd: 88pm88x: differences with respect to the PMIC RFC series

2024-01-11 Thread Karel Balej
Lee,

On Thu Jan 11, 2024 at 11:54 AM CET, Lee Jones wrote:
> The subject needs work.  Please tell us what the patches is doing.
>
> On Thu, 28 Dec 2023, Karel Balej wrote:
>
> > From: Karel Balej 
>
> A full an complete commit message is a must.

I have not provided a detailed description here because as I have noted
in the cover letter, this patch will be squashed into the MFD series. I
sent it only as a bridge between the two series, sorry for the
confusion.

> > diff --git a/include/linux/mfd/88pm88x.h b/include/linux/mfd/88pm88x.h
> > index a34c57447827..9a335f6b9c07 100644
> > --- a/include/linux/mfd/88pm88x.h
> > +++ b/include/linux/mfd/88pm88x.h
> > @@ -49,6 +49,8 @@ struct pm88x_data {
> > unsigned int whoami;
> > struct reg_sequence *presets;
> > unsigned int num_presets;
> > +   struct mfd_cell *devs;
> > +   unsigned int num_devs;
>
> Why are you adding extra abstraction?

Right, this is probably not necessary now since I'm only implementing
support for one of the chips - it's just that I keep thinking about it
as a driver for both of them and thus tend to write it a bit more
abstractly. Shall I then drop this and also the `presets` member which
is also chip-specific?

Thank you, best regards,
K. B.



Re: [RFC PATCH 4/5] regulator: add 88pm88x regulators driver

2024-01-07 Thread Karel Balej
On Sun Jan 7, 2024 at 11:35 AM CET, Krzysztof Kozlowski wrote:
> On 28/12/2023 10:39, Karel Balej wrote:
> > diff --git a/drivers/mfd/88pm88x.c b/drivers/mfd/88pm88x.c
> > index 69a8e39d43b3..999d0539b720 100644
> > --- a/drivers/mfd/88pm88x.c
> > +++ b/drivers/mfd/88pm88x.c
> > @@ -68,6 +68,21 @@ static struct mfd_cell pm886_devs[] = {
> > .num_resources = ARRAY_SIZE(pm88x_onkey_resources),
> > .resources = pm88x_onkey_resources,
> > },
> > +   {
> > +   .name = "88pm88x-regulator",
> > +   .id = PM88X_REGULATOR_ID_LDO2,
> > +   .of_compatible = "marvell,88pm88x-regulator",
> > +   },
> > +   {
> > +   .name = "88pm88x-regulator",
> > +   .id = PM88X_REGULATOR_ID_LDO15,
> > +   .of_compatible = "marvell,88pm88x-regulator",
> > +   },
> > +   {
> > +   .name = "88pm88x-regulator",
> > +   .id = PM886_REGULATOR_ID_BUCK2,
> > +   .of_compatible = "marvell,88pm88x-regulator",
>
> Same compatible per each regulator looks suspicious, if not even wrong.
> What are these?

The original attempt for upstreaming this MFD had a different compatible
for each regulator which was not correct according to the reviewers at
the time. I have thus used the same compatible for all regulators and
make the distinction in the regulator driver (using the .id property).
But I think that the problem here is again that I have confused the
purpose of .name and .of_compatible properties of struct mfd_cell - if a
driver is probed due to the .name property then I indeed should not need
compatible for the regulator driver at all.

>
> Best regards,
> Krzysztof

Best regards,
K. B.



Re: [RFC PATCH 4/5] regulator: add 88pm88x regulators driver

2024-01-07 Thread Karel Balej
Krzysztof,

On Sun Jan 7, 2024 at 11:34 AM CET, Krzysztof Kozlowski wrote:
> On 07/01/2024 10:49, Karel Balej wrote:
> > Mark,
> > 
> > On Fri Jan 5, 2024 at 4:18 PM CET, Mark Brown wrote:
> >> On Thu, Dec 28, 2023 at 10:39:13AM +0100, Karel Balej wrote:
> >>
> >>> @@ -68,6 +68,21 @@ static struct mfd_cell pm886_devs[] = {
> >>>   .num_resources = ARRAY_SIZE(pm88x_onkey_resources),
> >>>   .resources = pm88x_onkey_resources,
> >>>   },
> >>> + {
> >>> + .name = "88pm88x-regulator",
> >>> + .id = PM88X_REGULATOR_ID_LDO2,
> >>> + .of_compatible = "marvell,88pm88x-regulator",
> >>> + },
> >>
> >> Why are we adding an of_compatible here?  It's redundant, the MFD split
> >> is a feature of Linux internals not of the hardware, and the existing
> >> 88pm8xx MFD doesn't use them.
> > 
> > in a feedback to my MFD series, Rob Herring pointed out that there is no
> > need to have a devicetree node for a subdevice if it only contains
> > "compatible" as the MFD driver can instantiate subdevices itself. I
> > understood that this is what he was referring to, but now I suspect that
> > it is sufficient for the mfd_cell.name to be set to the subdevice driver
> > name for this - is that correct?
>
> I think Rob was only referring to "no need to have a devicetree node".

yes, but I thought the presence of the compatible in the node is what
triggers instantiation of the driver and that adding it here instead was
necessary for that to happen if the node was to be removed. But like I
said, now I think only the .name property is relevant for that.

> But you added here a devicetree node, plus probably undocumented compatible.
>
> Does it even pass the checkpatch?

It does, but you were correct in your previous messages that I have not
run `make dt_binding_check` for this (or I assume that was what you
meant when you said that I did not test this) because I was not aware of
it when sending the MFD series and because this one would fail with the
same problems as Rob pointed out for that one, which is the main reason
why I only asked for feedback on the new parts. Sorry about that, next
time I will be sure to first fix all already known problems before
building on something.
>
> Best regards,
> Krzysztof

Thank you,
K. B.



Re: [RFC PATCH 4/5] regulator: add 88pm88x regulators driver

2024-01-07 Thread Karel Balej
Mark,

On Fri Jan 5, 2024 at 4:18 PM CET, Mark Brown wrote:
> On Thu, Dec 28, 2023 at 10:39:13AM +0100, Karel Balej wrote:
>
> > @@ -68,6 +68,21 @@ static struct mfd_cell pm886_devs[] = {
> > .num_resources = ARRAY_SIZE(pm88x_onkey_resources),
> > .resources = pm88x_onkey_resources,
> > },
> > +   {
> > +   .name = "88pm88x-regulator",
> > +   .id = PM88X_REGULATOR_ID_LDO2,
> > +   .of_compatible = "marvell,88pm88x-regulator",
> > +   },
>
> Why are we adding an of_compatible here?  It's redundant, the MFD split
> is a feature of Linux internals not of the hardware, and the existing
> 88pm8xx MFD doesn't use them.

in a feedback to my MFD series, Rob Herring pointed out that there is no
need to have a devicetree node for a subdevice if it only contains
"compatible" as the MFD driver can instantiate subdevices itself. I
understood that this is what he was referring to, but now I suspect that
it is sufficient for the mfd_cell.name to be set to the subdevice driver
name for this - is that correct?

Thank you,
K. B.



[RFC PATCH 5/5] MAINTAINERS: add entries for the 88pm88x regulators driver

2023-12-28 Thread Karel Balej
From: Karel Balej 

List the related files under the Marvell 88PM88X PMICs entry.

Signed-off-by: Karel Balej 
---
 MAINTAINERS | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index f35ec0f186a9..f9676aec7397 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -12743,8 +12743,10 @@ M: Karel Balej 
 S: Maintained
 F: Documentation/devicetree/bindings/input/marvell,88pm88x-onkey.yaml
 F: Documentation/devicetree/bindings/mfd/marvell,88pm88x.yaml
+F: 
Documentation/devicetree/bindings/regulator/marvell,88pm88x-regulator.yaml
 F: drivers/input/misc/88pm88x-onkey.c
 F: drivers/mfd/88pm88x.c
+F: drivers/regulators/88pm88x-regulator.c
 F: include/linux/mfd/88pm88x.h
 
 MARVELL ARMADA 3700 PHY DRIVERS
-- 
2.43.0




[RFC PATCH 4/5] regulator: add 88pm88x regulators driver

2023-12-28 Thread Karel Balej
From: Karel Balej 

Support the LDO and buck regulators of the Marvell 88PM886 PMIC. Support
for 88PM880 is not included but should be easy to implement being just a
matter of defining the additional LDOs and all bucks and modifying the
88PM88X MFD driver appropriately.

Signed-off-by: Karel Balej 
---
 drivers/mfd/88pm88x.c |  15 ++
 drivers/regulator/88pm88x-regulator.c | 214 ++
 drivers/regulator/Kconfig |   6 +
 drivers/regulator/Makefile|   1 +
 include/linux/mfd/88pm88x.h   |  11 ++
 5 files changed, 247 insertions(+)
 create mode 100644 drivers/regulator/88pm88x-regulator.c

diff --git a/drivers/mfd/88pm88x.c b/drivers/mfd/88pm88x.c
index 69a8e39d43b3..999d0539b720 100644
--- a/drivers/mfd/88pm88x.c
+++ b/drivers/mfd/88pm88x.c
@@ -68,6 +68,21 @@ static struct mfd_cell pm886_devs[] = {
.num_resources = ARRAY_SIZE(pm88x_onkey_resources),
.resources = pm88x_onkey_resources,
},
+   {
+   .name = "88pm88x-regulator",
+   .id = PM88X_REGULATOR_ID_LDO2,
+   .of_compatible = "marvell,88pm88x-regulator",
+   },
+   {
+   .name = "88pm88x-regulator",
+   .id = PM88X_REGULATOR_ID_LDO15,
+   .of_compatible = "marvell,88pm88x-regulator",
+   },
+   {
+   .name = "88pm88x-regulator",
+   .id = PM886_REGULATOR_ID_BUCK2,
+   .of_compatible = "marvell,88pm88x-regulator",
+   },
 };
 
 static struct pm88x_data pm886_a1_data = {
diff --git a/drivers/regulator/88pm88x-regulator.c 
b/drivers/regulator/88pm88x-regulator.c
new file mode 100644
index ..8b55e1365387
--- /dev/null
+++ b/drivers/regulator/88pm88x-regulator.c
@@ -0,0 +1,214 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#define PM88X_REG_LDO_EN1  0x09
+#define PM88X_REG_LDO_EN2  0x0a
+
+#define PM88X_REG_BUCK_EN  0x08
+
+#define PM88X_REG_LDO1_VOUT0x20
+#define PM88X_REG_LDO2_VOUT0x26
+#define PM88X_REG_LDO3_VOUT0x2c
+#define PM88X_REG_LDO4_VOUT0x32
+#define PM88X_REG_LDO5_VOUT0x38
+#define PM88X_REG_LDO6_VOUT0x3e
+#define PM88X_REG_LDO7_VOUT0x44
+#define PM88X_REG_LDO8_VOUT0x4a
+#define PM88X_REG_LDO9_VOUT0x50
+#define PM88X_REG_LDO10_VOUT   0x56
+#define PM88X_REG_LDO11_VOUT   0x5c
+#define PM88X_REG_LDO12_VOUT   0x62
+#define PM88X_REG_LDO13_VOUT   0x68
+#define PM88X_REG_LDO14_VOUT   0x6e
+#define PM88X_REG_LDO15_VOUT   0x74
+#define PM88X_REG_LDO16_VOUT   0x7a
+
+#define PM886_REG_BUCK1_VOUT   0xa5
+#define PM886_REG_BUCK2_VOUT   0xb3
+#define PM886_REG_BUCK3_VOUT   0xc1
+#define PM886_REG_BUCK4_VOUT   0xcf
+#define PM886_REG_BUCK5_VOUT   0xdd
+
+#define PM88X_LDO_VSEL_MASK0x0f
+#define PM88X_BUCK_VSEL_MASK   0x7f
+
+struct pm88x_regulator {
+   struct regulator_desc desc;
+   int max_uA;
+};
+
+static int pm88x_regulator_get_ilim(struct regulator_dev *rdev)
+{
+   struct pm88x_regulator *data = rdev_get_drvdata(rdev);
+
+   if (!data) {
+   dev_err(>dev, "Failed to get regulator data\n");
+   return -EINVAL;
+   }
+   return data->max_uA;
+}
+
+static const struct regulator_ops pm88x_ldo_ops = {
+   .list_voltage = regulator_list_voltage_table,
+   .map_voltage = regulator_map_voltage_iterate,
+   .set_voltage_sel = regulator_set_voltage_sel_regmap,
+   .get_voltage_sel = regulator_get_voltage_sel_regmap,
+   .enable = regulator_enable_regmap,
+   .disable = regulator_disable_regmap,
+   .is_enabled = regulator_is_enabled_regmap,
+   .get_current_limit = pm88x_regulator_get_ilim,
+};
+
+static const struct regulator_ops pm88x_buck_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 = regulator_get_voltage_sel_regmap,
+   .enable = regulator_enable_regmap,
+   .disable = regulator_disable_regmap,
+   .is_enabled = regulator_is_enabled_regmap,
+   .get_current_limit = pm88x_regulator_get_ilim,
+};
+
+static const unsigned int pm88x_ldo_volt_table1[] = {
+   170, 180, 190, 250, 280, 290, 310, 330,
+};
+
+static const unsigned int pm88x_ldo_volt_table2[] = {
+   120, 125, 170, 180, 185, 190, 250, 260,
+   270, 275, 280, 285, 290, 300, 310, 330,
+};
+
+static const unsigned int pm88x_ldo_volt_table3[] = {
+ 

[RFC PATCH 3/5] dt-bindings: regulator: add documentation entry for 88pm88x-regulator

2023-12-28 Thread Karel Balej
From: Karel Balej 

The Marvell 88PM88X PMICs provide regulators among other things.
Document how to use them.

Signed-off-by: Karel Balej 
---
 .../bindings/mfd/marvell,88pm88x.yaml | 17 +++
 .../regulator/marvell,88pm88x-regulator.yaml  | 28 +++
 2 files changed, 45 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/regulator/marvell,88pm88x-regulator.yaml

diff --git a/Documentation/devicetree/bindings/mfd/marvell,88pm88x.yaml 
b/Documentation/devicetree/bindings/mfd/marvell,88pm88x.yaml
index 115b41c9f22c..e6944369fc5c 100644
--- a/Documentation/devicetree/bindings/mfd/marvell,88pm88x.yaml
+++ b/Documentation/devicetree/bindings/mfd/marvell,88pm88x.yaml
@@ -54,6 +54,23 @@ examples:
 onkey {
   compatible = "marvell,88pm88x-onkey";
 };
+
+regulators {
+  ldo2: ldo2 {
+regulator-min-microvolt = <310>;
+regulator-max-microvolt = <330>;
+};
+
+  ldo15: ldo15 {
+regulator-min-microvolt = <330>;
+regulator-max-microvolt = <330>;
+};
+
+  buck2: buck2 {
+regulator-min-microvolt = <180>;
+regulator-max-microvolt = <180>;
+};
+};
   };
 };
 ...
diff --git 
a/Documentation/devicetree/bindings/regulator/marvell,88pm88x-regulator.yaml 
b/Documentation/devicetree/bindings/regulator/marvell,88pm88x-regulator.yaml
new file mode 100644
index ..c6ac17b113e7
--- /dev/null
+++ b/Documentation/devicetree/bindings/regulator/marvell,88pm88x-regulator.yaml
@@ -0,0 +1,28 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/regulator/marvell,88pm88x-regulator.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Marvell 88PM88X PMICs regulators
+
+maintainers:
+  - Karel Balej 
+
+description: |
+  This module is part of the Marvell 88PM88X MFD device. For more details
+  see Documentation/devicetree/bindings/mfd/marvell,88pm88x.yaml.
+
+  The regulator controller is represented as a sub-node of the PMIC node
+  in the device tree.
+
+  The valid names for 88PM886 regulator nodes are ldo[1-9], ldo1[0-6], 
buck[1-5].
+
+patternProperties:
+  "^(ldo|buck)[0-9]+$":
+type: object
+description:
+  Properties for single regulator.
+$ref: regulator.yaml#
+
+additionalProperties: false
-- 
2.43.0




[RFC PATCH 2/5] mfd: 88pm88x: initialize the regulators regmaps

2023-12-28 Thread Karel Balej
From: Karel Balej 

The regulators registers are accessed via a different I2C address than
the already implemented functionality. Initialize the new regmap for the
regulator driver to use. For 88PM886 the buck regmap is the same as LDO
regmap, however this is not the case for 88PM880.

Signed-off-by: Karel Balej 
---
 drivers/mfd/88pm88x.c   | 33 +
 include/linux/mfd/88pm88x.h |  4 
 2 files changed, 37 insertions(+)

diff --git a/drivers/mfd/88pm88x.c b/drivers/mfd/88pm88x.c
index 3424d88a58f6..69a8e39d43b3 100644
--- a/drivers/mfd/88pm88x.c
+++ b/drivers/mfd/88pm88x.c
@@ -98,6 +98,35 @@ static int pm88x_power_off_handler(struct sys_off_data *data)
return NOTIFY_DONE;
 }
 
+static int pm88x_initialize_subregmaps(struct pm88x_chip *chip)
+{
+   struct i2c_client *page;
+   struct regmap *regmap;
+   int ret;
+
+   /* LDO page */
+   page = devm_i2c_new_dummy_device(>client->dev, 
chip->client->adapter,
+   chip->client->addr + 
PM88X_PAGE_OFFSET_LDO);
+   if (IS_ERR(page)) {
+   ret = PTR_ERR(page);
+   dev_err(>client->dev, "Failed to initialize LDO client: 
%d\n",
+   ret);
+   return ret;
+   }
+   regmap = devm_regmap_init_i2c(page, _i2c_regmap);
+   if (IS_ERR(regmap)) {
+   ret = PTR_ERR(regmap);
+   dev_err(>client->dev, "Failed to initialize LDO regmap: 
%d\n",
+   ret);
+   return ret;
+   }
+   chip->regmaps[PM88X_REGMAP_LDO] = regmap;
+   /* buck regmap is the same as LDO */
+   chip->regmaps[PM88X_REGMAP_BUCK] = regmap;
+
+   return 0;
+}
+
 static int pm88x_setup_irq(struct pm88x_chip *chip)
 {
int ret;
@@ -155,6 +184,10 @@ static int pm88x_probe(struct i2c_client *client)
return -EINVAL;
}
 
+   ret = pm88x_initialize_subregmaps(chip);
+   if (ret)
+   return ret;
+
ret = pm88x_setup_irq(chip);
if (ret)
return ret;
diff --git a/include/linux/mfd/88pm88x.h b/include/linux/mfd/88pm88x.h
index 9a335f6b9c07..703e6104c1d8 100644
--- a/include/linux/mfd/88pm88x.h
+++ b/include/linux/mfd/88pm88x.h
@@ -39,8 +39,12 @@
 
 #define PM88X_REG_AON_CTRL20xe2
 
+#define PM88X_PAGE_OFFSET_LDO  1
+
 enum pm88x_regmap_index {
PM88X_REGMAP_BASE,
+   PM88X_REGMAP_LDO,
+   PM88X_REGMAP_BUCK,
 
PM88X_REGMAP_NR
 };
-- 
2.43.0




[RFC PATCH 1/5] mfd: 88pm88x: differences with respect to the PMIC RFC series

2023-12-28 Thread Karel Balej
From: Karel Balej 

Signed-off-by: Karel Balej 
---
 drivers/mfd/88pm88x.c   | 14 --
 include/linux/mfd/88pm88x.h |  2 ++
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/mfd/88pm88x.c b/drivers/mfd/88pm88x.c
index 5db6c65b667d..3424d88a58f6 100644
--- a/drivers/mfd/88pm88x.c
+++ b/drivers/mfd/88pm88x.c
@@ -57,16 +57,16 @@ static struct reg_sequence pm886_presets[] = {
REG_SEQ0(PM88X_REG_BK_OSC_CTRL3, 0xc0),
 };
 
-static struct resource onkey_resources[] = {
+static struct resource pm88x_onkey_resources[] = {
DEFINE_RES_IRQ_NAMED(PM88X_IRQ_ONKEY, "88pm88x-onkey"),
 };
 
-static struct mfd_cell pm88x_devs[] = {
+static struct mfd_cell pm886_devs[] = {
{
.name = "88pm88x-onkey",
-   .num_resources = ARRAY_SIZE(onkey_resources),
-   .resources = onkey_resources,
-   .id = -1,
+   .of_compatible = "marvell,88pm88x-onkey",
+   .num_resources = ARRAY_SIZE(pm88x_onkey_resources),
+   .resources = pm88x_onkey_resources,
},
 };
 
@@ -74,6 +74,8 @@ static struct pm88x_data pm886_a1_data = {
.whoami = PM886_A1_WHOAMI,
.presets = pm886_presets,
.num_presets = ARRAY_SIZE(pm886_presets),
+   .devs = pm886_devs,
+   .num_devs = ARRAY_SIZE(pm886_devs),
 };
 
 static const struct regmap_config pm88x_i2c_regmap = {
@@ -157,7 +159,7 @@ static int pm88x_probe(struct i2c_client *client)
if (ret)
return ret;
 
-   ret = devm_mfd_add_devices(>dev, 0, pm88x_devs, 
ARRAY_SIZE(pm88x_devs),
+   ret = devm_mfd_add_devices(>dev, 0, chip->data->devs, 
chip->data->num_devs,
NULL, 0, regmap_irq_get_domain(chip->irq_data));
if (ret) {
dev_err(>dev, "Failed to add devices: %d\n", ret);
diff --git a/include/linux/mfd/88pm88x.h b/include/linux/mfd/88pm88x.h
index a34c57447827..9a335f6b9c07 100644
--- a/include/linux/mfd/88pm88x.h
+++ b/include/linux/mfd/88pm88x.h
@@ -49,6 +49,8 @@ struct pm88x_data {
unsigned int whoami;
struct reg_sequence *presets;
unsigned int num_presets;
+   struct mfd_cell *devs;
+   unsigned int num_devs;
 };
 
 struct pm88x_chip {
-- 
2.43.0




[RFC PATCH 0/5] regulator: support for Marvell 88PM886 LDOs and bucks

2023-12-28 Thread Karel Balej
From: Karel Balej 

Hello,

the following adds the regulators driver for Marvell 88PM88X PMICs
implementing only the 88PM886 specific parts - however extension for
88PM880 should be trivial. The series adding MFD driver for these PMICs
is available here [1]. Please note that this series depends on that
one.

The motivation and testing platform for this is the
samsung,coreprimevelte smartphone for which the initial support efforts
are ongoing here [2]. This PMIC is also found in at least two other
devices with the PXA1908 SoC, such as samsung,xcover3lte and
samsung,grandprimevelte.

As the only reference for this driver served the smartphone's downstream
kernel tree which is available here [3].

Please note that the first patch of this series is just a joining step
with respect to series [1] and will be amalgated with future versions of
it and dropped here. Also please note that that this series has the same
defects as the MFD one and thus please only review the new parts.
Lastly, as I would like to get some feedback on whether the approach I
have taken here is OK, I have only defined descriptions for three
regulators so far, the remaining eighteen will be defined in the same
style and will of course be added when this series leaves the RFC state
at the latest.

[1] 
https://lore.kernel.org/all/20231217131838.7569-1-kar...@gimli.ms.mff.cuni.cz/
[2] 
https://lore.kernel.org/all/20231102-pxa1908-lkml-v7-0-cabb1a0cb...@skole.hr/
[3] https://github.com/CoderCharmander/g361f-kernel

Thank you,
K. B.

Karel Balej (5):
  mfd: 88pm88x: differences with respect to the PMIC RFC series
  mfd: 88pm88x: initialize the regulators regmaps
  dt-bindings: regulator: add documentation entry for 88pm88x-regulator
  regulator: add 88pm88x regulators driver
  MAINTAINERS: add entries for the 88pm88x regulators driver

 .../bindings/mfd/marvell,88pm88x.yaml |  17 ++
 .../regulator/marvell,88pm88x-regulator.yaml  |  28 +++
 MAINTAINERS   |   2 +
 drivers/mfd/88pm88x.c |  62 -
 drivers/regulator/88pm88x-regulator.c | 214 ++
 drivers/regulator/Kconfig |   6 +
 drivers/regulator/Makefile|   1 +
 include/linux/mfd/88pm88x.h   |  17 ++
 8 files changed, 341 insertions(+), 6 deletions(-)
 create mode 100644 
Documentation/devicetree/bindings/regulator/marvell,88pm88x-regulator.yaml
 create mode 100644 drivers/regulator/88pm88x-regulator.c

-- 
2.43.0




Re: [PATCH v3 2/5] dt-bindings: input/touchscreen: Add compatible for IST3038B

2023-12-27 Thread Karel Balej
Markuss,

On Sat Dec 9, 2023 at 11:58 AM CET, Conor Dooley wrote:
> On Sat, Dec 09, 2023 at 10:05:27AM +0100, Karel Balej wrote:
> > On Mon Dec 4, 2023 at 1:52 PM CET, Conor Dooley wrote:
> > > On Mon, Dec 04, 2023 at 02:40:44PM +0200, Markuss Broks wrote:
> > > > On 12/3/23 13:20, Conor Dooley wrote:
> > > > > On Sat, Dec 02, 2023 at 01:48:33PM +0100, Karel Balej wrote:
> > > > > > From: Markuss Broks 
> > > > > > 
> > > > > > Imagis IST3038B is a variant (firmware?) of Imagis IST3038 IC,
> > > > > > add the compatible for it to the IST3038C bindings.
> > > > > This one is better, but would be well served by mentioning what
> > > > > specifically is different (register addresses or firmware commands?)
> > > > 
> > > > I don't think anyone knows this other than Imagis itself. I would guess 
> > > > it's
> > > > different hardware, since register addresses are indeed different, but 
> > > > on
> > > > the other hand, there is a possibility that firmware on the MCU could be
> > > > responding to those commands. I suppose "... IST3038B is a hardware 
> > > > variant
> > > > of ... IST3038" would be more correct.
> > >
> > > Only Imagis might know the specifics, but you (plural) have made driver
> > > changes so you know what is different in terms of the programming model.
> > > I'm just asking for you to mention how the programming model varies in
> > > the commit message. Otherwise I can't know whether you should have added
> > > a fallback compatible, without going and reading your driver change. The
> > > commit message for the bindings should stand on its own merit in that
> > > regard.
> > > "Variant" alone does not suffice, as many variants of devices have a
> > > compatible programming model, be that for a subset of features or
> > > complete compatibility.
> > >
> > > > The reason why I think it could be firmware-defined is because we have 
> > > > a lot
> > > > of variants (30xxA, 30xxB, 30xxC, plain 30xx), and the numbers usually 
> > > > mean
> > > > feature level/completeness, e.g. some don't support the touch pressure 
> > > > or
> > > > touchkeys, and we don't know what A/B/C/none means.
> > >
> > > Ultimately whether it is due to firmware or the hardware isn't
> > > particular important, just mention what is incompatibly different.
> > 
> > I propose to update the commit description as such:
> > 
> > Imagis IST3038B is a variant (firmware?) of Imagis IST3038 IC
> > differing from IST3038C in its register interface. Add the
> > compatible for it to the IST3038C bindings.

is this change OK with you?

>
>
> SGTM. You can add
> Acked-by: Conor Dooley 
> with that commit message update.
>
> Thanks,
> Conor.

Kind regards,
K. B.



Re: [RFC PATCH 1/5] dt-bindings: mfd: add entry for the Marvell 88PM88X PMICs

2023-12-22 Thread Karel Balej
Rob,

thank you very much for your feedback.

On Mon Dec 18, 2023 at 4:17 PM CET, Rob Herring wrote:
> > +  Marvell 88PM880 and 88PM886 are two similar PMICs providing
> > +  several functions such as onkey, regulators or battery and
> > +  charger. Both seem to come in two revisions -- A0 and A1.
> > +
> > +properties:
> > +  compatible:
> > +const: marvell,88pm886-a1
>
> The description talks about 4 different devices, but only 1 here. 
>
> Do you expect to need A0 support? Devices with these PMICs should be 
> known and few, right? 

I know of three smartphones which have 88PM886 and all of them (at least
the revisions that have been tested) seem to use A1. So no, I don't know
of any device that would need A0, but I wanted have the driver ready in
case somebody needed to add it later. What change do you then suggest?

Thank you and kind regards,
K. B.



[RFC PATCH 0/5] support for Marvell 88PM886 PMIC

2023-12-17 Thread Karel Balej
From: Karel Balej 

Hello,

the following implements basic support for Marvell's 88PM886 PMIC which
is found for instance as a component of the samsung,coreprimevelte
smartphone which inspired this and also serves as a testing platform.

The code for the MFD is based primarily on this old series [1] with the
addition of poweroff based on the smartphone's downstream kernel tree
[2]. The onkey driver is based on the latter. I am not in possesion of
the datasheet.

The vendor version of this driver includes support for a similar chip:
88PM880. While that is not included here it was written with it in mind
and it should be quite straighforward to add it.

[1] 
https://lore.kernel.org/all/1434098601-3498-1-git-send-email-yizh...@marvell.com/
[2] https://github.com/CoderCharmander/g361f-kernel

Thank you and kind regards,
K. B.

Karel Balej (5):
  dt-bindings: mfd: add entry for the Marvell 88PM88X PMICs
  mfd: add 88pm88x driver
  dt-bindings: input: add entry for 88pm88x-onkey
  input: add onkey driver for Marvell 88PM88X PMICs
  MAINTAINERS: add myself for Marvell 88PM88X PMICs

 .../bindings/input/marvell,88pm88x-onkey.yaml |  30 +++
 .../bindings/mfd/marvell,88pm88x.yaml |  59 ++
 MAINTAINERS   |   9 +
 drivers/input/misc/88pm88x-onkey.c| 103 +
 drivers/input/misc/Kconfig|  10 +
 drivers/input/misc/Makefile   |   1 +
 drivers/mfd/88pm88x.c | 199 ++
 drivers/mfd/Kconfig   |  11 +
 drivers/mfd/Makefile  |   1 +
 include/linux/mfd/88pm88x.h   |  60 ++
 10 files changed, 483 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/input/marvell,88pm88x-onkey.yaml
 create mode 100644 Documentation/devicetree/bindings/mfd/marvell,88pm88x.yaml
 create mode 100644 drivers/input/misc/88pm88x-onkey.c
 create mode 100644 drivers/mfd/88pm88x.c
 create mode 100644 include/linux/mfd/88pm88x.h

-- 
2.43.0




[RFC PATCH 5/5] MAINTAINERS: add myself for Marvell 88PM88X PMICs

2023-12-17 Thread Karel Balej
From: Karel Balej 

Add an entry to MAINTAINERS for the Marvell 88PM88X PMICs MFD and onkey
drivers.

Signed-off-by: Karel Balej 
---
 MAINTAINERS | 9 +
 1 file changed, 9 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index e2c6187a3ac8..eb0171cd2323 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -12737,6 +12737,15 @@ F: drivers/net/dsa/mv88e6xxx/
 F: include/linux/dsa/mv88e6xxx.h
 F: include/linux/platform_data/mv88e6xxx.h
 
+MARVELL 88PM88X PMIC MFD DRIVER
+M: Karel Balej 
+S: Maintained
+F: Documentation/devicetree/bindings/input/marvell,88pm88x-onkey.yaml
+F: Documentation/devicetree/bindings/mfd/marvell,88pm88x.yaml
+F: drivers/input/misc/88pm88x-onkey.c
+F: drivers/mfd/88pm88x.c
+F: include/linux/mfd/88pm88x.h
+
 MARVELL ARMADA 3700 PHY DRIVERS
 M: Miquel Raynal 
 S: Maintained
-- 
2.43.0




[RFC PATCH 4/5] input: add onkey driver for Marvell 88PM88X PMICs

2023-12-17 Thread Karel Balej
From: Karel Balej 

The Marvell 88PM88X PMICs provide onkey among other things. Add client
driver to handle it. The driver currently only provides a basic support
omitting additional functions found in the vendor version, such as long
onkey and GPIO integration.

Signed-off-by: Karel Balej 
---
 drivers/input/misc/88pm88x-onkey.c | 103 +
 drivers/input/misc/Kconfig |  10 +++
 drivers/input/misc/Makefile|   1 +
 3 files changed, 114 insertions(+)
 create mode 100644 drivers/input/misc/88pm88x-onkey.c

diff --git a/drivers/input/misc/88pm88x-onkey.c 
b/drivers/input/misc/88pm88x-onkey.c
new file mode 100644
index ..0d6056a3cab2
--- /dev/null
+++ b/drivers/input/misc/88pm88x-onkey.c
@@ -0,0 +1,103 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+struct pm88x_onkey {
+   struct input_dev *idev;
+   struct pm88x_chip *chip;
+   int irq;
+};
+
+static irqreturn_t pm88x_onkey_irq_handler(int irq, void *data)
+{
+   struct pm88x_onkey *onkey = data;
+   unsigned int val;
+   int ret = 0;
+
+   ret = regmap_read(onkey->chip->regmaps[PM88X_REGMAP_BASE], 
PM88X_REG_STATUS1, );
+   if (ret) {
+   dev_err(onkey->idev->dev.parent, "Failed to read status: %d\n", 
ret);
+   return IRQ_NONE;
+   }
+   val &= PM88X_ONKEY_STS1;
+
+   input_report_key(onkey->idev, KEY_POWER, val);
+   input_sync(onkey->idev);
+
+   return IRQ_HANDLED;
+}
+
+static int pm88x_onkey_probe(struct platform_device *pdev)
+{
+   struct pm88x_chip *chip = dev_get_drvdata(pdev->dev.parent);
+   struct pm88x_onkey *onkey;
+   int err;
+
+   onkey = devm_kzalloc(>dev, sizeof(*onkey), GFP_KERNEL);
+   if (!onkey)
+   return -ENOMEM;
+
+   onkey->chip = chip;
+
+   onkey->irq = platform_get_irq(pdev, 0);
+   if (onkey->irq < 0) {
+   dev_err(>dev, "Failed to get IRQ\n");
+   return -EINVAL;
+   }
+
+   onkey->idev = devm_input_allocate_device(>dev);
+   if (!onkey->idev) {
+   dev_err(>dev, "Failed to allocate input device\n");
+   return -ENOMEM;
+   }
+
+   onkey->idev->name = "88pm88x-onkey";
+   onkey->idev->phys = "88pm88x-onkey/input0";
+   onkey->idev->id.bustype = BUS_I2C;
+   onkey->idev->dev.parent = >dev;
+   onkey->idev->evbit[0] = BIT_MASK(EV_KEY);
+   onkey->idev->keybit[BIT_WORD(KEY_POWER)] = BIT_MASK(KEY_POWER);
+
+   err = devm_request_threaded_irq(>dev, onkey->irq, NULL, 
pm88x_onkey_irq_handler,
+   IRQF_ONESHOT | IRQF_NO_SUSPEND, "onkey", onkey);
+   if (err) {
+   dev_err(>dev, "Failed to request IRQ: %d\n", err);
+   return err;
+   }
+
+   err = input_register_device(onkey->idev);
+   if (err) {
+   dev_err(>dev, "Failed to register input device: %d\n", 
err);
+   return err;
+   }
+
+   device_init_wakeup(>dev, 1);
+
+   return 0;
+}
+
+static const struct of_device_id pm88x_onkey_of_match[] = {
+   { .compatible = "marvell,88pm88x-onkey", },
+   { },
+};
+MODULE_DEVICE_TABLE(of, pm88x_onkey_of_match);
+
+static struct platform_driver pm88x_onkey_driver = {
+   .driver = {
+   .name = "88pm88x-onkey",
+   .of_match_table = of_match_ptr(pm88x_onkey_of_match),
+   },
+   .probe = pm88x_onkey_probe,
+};
+module_platform_driver(pm88x_onkey_driver);
+
+MODULE_DESCRIPTION("Marvell 88PM88X onkey driver");
+MODULE_AUTHOR("Karel Balej ");
+MODULE_LICENSE("GPL");
diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index 6ba984d7f0b1..fdfa3e23c3cf 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -33,6 +33,16 @@ config INPUT_88PM80X_ONKEY
  To compile this driver as a module, choose M here: the module
  will be called 88pm80x_onkey.
 
+config INPUT_88PM88X_ONKEY
+   tristate "Marvell 88PM88X onkey support"
+   depends on MFD_88PM88X
+   help
+ Support the onkey of Marvell 88PM88X PMICs as an input device
+ reporting power button status.
+
+ To compile this driver as a module, choose M here: the module
+ will be called 88pm88x-onkey.
+
 config INPUT_AB8500_PONKEY
tristate "AB8500 Pon (PowerOn) Key"
depends on AB8500_CORE
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
index 04296a4abe8e..eab7a364188c 100644
--- a/drivers/input/misc/Makefile
+++ b/drivers/input/misc/Makefile
@@ -7,6 +7,7 @@
 
 obj-$(CONFIG_INPUT_88PM860X_ONKEY) += 88pm860x_onkey

[RFC PATCH 3/5] dt-bindings: input: add entry for 88pm88x-onkey

2023-12-17 Thread Karel Balej
From: Karel Balej 

Marvell 88PM88X PMICs provide onkey functionality. Document it.

Signed-off-by: Karel Balej 
---
 .../bindings/input/marvell,88pm88x-onkey.yaml | 30 +++
 .../bindings/mfd/marvell,88pm88x.yaml |  4 +++
 2 files changed, 34 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/input/marvell,88pm88x-onkey.yaml

diff --git a/Documentation/devicetree/bindings/input/marvell,88pm88x-onkey.yaml 
b/Documentation/devicetree/bindings/input/marvell,88pm88x-onkey.yaml
new file mode 100644
index ..aeb7673189f8
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/marvell,88pm88x-onkey.yaml
@@ -0,0 +1,30 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/input/marvell,88pm88x-onkey.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Onkey driver for Marvell 88PM88X PMICs.
+
+maintainers:
+  - Karel Balej 
+
+description: |
+  This module is part of the 88PM88X MFD device. For more details
+  see Documentation/devicetree/bindings/mfd/marvell,88pm88x.yaml.
+
+  The onkey controller is represented as a sub-node of the PMIC node in
+  the device tree.
+
+allOf:
+  - $ref: input.yaml#
+
+properties:
+  compatible:
+const: marvell,88pm88x-onkey
+
+required:
+  - compatible
+
+additionalProperties: false
+...
diff --git a/Documentation/devicetree/bindings/mfd/marvell,88pm88x.yaml 
b/Documentation/devicetree/bindings/mfd/marvell,88pm88x.yaml
index e075729c360f..115b41c9f22c 100644
--- a/Documentation/devicetree/bindings/mfd/marvell,88pm88x.yaml
+++ b/Documentation/devicetree/bindings/mfd/marvell,88pm88x.yaml
@@ -50,6 +50,10 @@ examples:
 interrupt-parent = <>;
 interrupt-controller;
 #interrupt-cells = <1>;
+
+onkey {
+  compatible = "marvell,88pm88x-onkey";
+};
   };
 };
 ...
-- 
2.43.0




[RFC PATCH 2/5] mfd: add 88pm88x driver

2023-12-17 Thread Karel Balej
From: Karel Balej 

Marvell 88PM880 and 8PM886 are two similar PMICs with mostly matching
register mapping. They provide various functions such as onkey, battery,
charger and regulators.

Add support for 88PM886 found for instance in the samsung,coreprimevelte
smartphone with which this was tested. Support for 88PM880 is not
implemented here but should be straightforward to add.

Implement only the most basic support omitting the currently unused
registers and I2C subclients which should thus be added with the
respective subdevices. However, add support for the onkey already.

Signed-off-by: Karel Balej 
---
 drivers/mfd/88pm88x.c   | 199 
 drivers/mfd/Kconfig |  11 ++
 drivers/mfd/Makefile|   1 +
 include/linux/mfd/88pm88x.h |  60 +++
 4 files changed, 271 insertions(+)
 create mode 100644 drivers/mfd/88pm88x.c
 create mode 100644 include/linux/mfd/88pm88x.h

diff --git a/drivers/mfd/88pm88x.c b/drivers/mfd/88pm88x.c
new file mode 100644
index ..5db6c65b667d
--- /dev/null
+++ b/drivers/mfd/88pm88x.c
@@ -0,0 +1,199 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+/* interrupt status registers */
+#define PM88X_REG_INT_STATUS1  0x05
+
+#define PM88X_REG_INT_ENA_10x0a
+#define PM88X_INT_ENA1_ONKEY   BIT(0)
+
+enum pm88x_irq_number {
+   PM88X_IRQ_ONKEY,
+
+   PM88X_MAX_IRQ
+};
+
+static struct regmap_irq pm88x_regmap_irqs[] = {
+   REGMAP_IRQ_REG(PM88X_IRQ_ONKEY, 0, PM88X_INT_ENA1_ONKEY),
+};
+
+static struct regmap_irq_chip pm88x_regmap_irq_chip = {
+   .name = "88pm88x",
+   .irqs = pm88x_regmap_irqs,
+   .num_irqs = ARRAY_SIZE(pm88x_regmap_irqs),
+   .num_regs = 4,
+   .status_base = PM88X_REG_INT_STATUS1,
+   .ack_base = PM88X_REG_INT_STATUS1,
+   .unmask_base = PM88X_REG_INT_ENA_1,
+};
+
+static struct reg_sequence pm886_presets[] = {
+   /* disable watchdog */
+   REG_SEQ0(PM88X_REG_WDOG, 0x01),
+   /* GPIO1: DVC, GPIO0: input */
+   REG_SEQ0(PM88X_REG_GPIO_CTRL1, 0x40),
+   /* GPIO2: input */
+   REG_SEQ0(PM88X_REG_GPIO_CTRL2, 0x00),
+   /* DVC2, DVC1 */
+   REG_SEQ0(PM88X_REG_GPIO_CTRL3, 0x44),
+   /* GPIO5V_1:input, GPIO5V_2: input */
+   REG_SEQ0(PM88X_REG_GPIO_CTRL4, 0x00),
+   /* output 32 kHz from XO */
+   REG_SEQ0(PM88X_REG_AON_CTRL2, 0x2a),
+   /* OSC_FREERUN = 1, to lock FLL */
+   REG_SEQ0(PM88X_REG_BK_OSC_CTRL1, 0x0f),
+   /* XO_LJ = 1, enable low jitter for 32 kHz */
+   REG_SEQ0(PM88X_REG_LOWPOWER2, 0x20),
+   /* OV_VSYS and UV_VSYS1 comparators on VSYS disabled, VSYS_OVER_TH : 
5.6V */
+   REG_SEQ0(PM88X_REG_LOWPOWER4, 0xc8),
+   /* set the duty cycle of charger DC/DC to max */
+   REG_SEQ0(PM88X_REG_BK_OSC_CTRL3, 0xc0),
+};
+
+static struct resource onkey_resources[] = {
+   DEFINE_RES_IRQ_NAMED(PM88X_IRQ_ONKEY, "88pm88x-onkey"),
+};
+
+static struct mfd_cell pm88x_devs[] = {
+   {
+   .name = "88pm88x-onkey",
+   .num_resources = ARRAY_SIZE(onkey_resources),
+   .resources = onkey_resources,
+   .id = -1,
+   },
+};
+
+static struct pm88x_data pm886_a1_data = {
+   .whoami = PM886_A1_WHOAMI,
+   .presets = pm886_presets,
+   .num_presets = ARRAY_SIZE(pm886_presets),
+};
+
+static const struct regmap_config pm88x_i2c_regmap = {
+   .reg_bits = 8,
+   .val_bits = 8,
+   .max_register = 0xfe,
+};
+
+static int pm88x_power_off_handler(struct sys_off_data *data)
+{
+   struct pm88x_chip *chip = data->cb_data;
+   int ret;
+
+   ret = regmap_update_bits(chip->regmaps[PM88X_REGMAP_BASE], 
PM88X_REG_MISC_CONFIG1,
+   PM88X_SW_PDOWN, PM88X_SW_PDOWN);
+   if (ret) {
+   dev_err(>client->dev, "Failed to power off the device: 
%d\n", ret);
+   return NOTIFY_BAD;
+   }
+   return NOTIFY_DONE;
+}
+
+static int pm88x_setup_irq(struct pm88x_chip *chip)
+{
+   int ret;
+
+   /* set interrupt clearing mode to clear on write */
+   ret = regmap_update_bits(chip->regmaps[PM88X_REGMAP_BASE], 
PM88X_REG_MISC_CONFIG2,
+   PM88X_INT_INV | PM88X_INT_CLEAR | PM88X_INT_MASK_MODE,
+   PM88X_INT_WC);
+   if (ret) {
+   dev_err(>client->dev, "Failed to set interrupt clearing 
mode: %d\n", ret);
+   return ret;
+   }
+
+   ret = devm_regmap_add_irq_chip(>client->dev, 
chip->regmaps[PM88X_REGMAP_BASE],
+   chip->client->irq, IRQF_ONESHOT, -1, 
_regmap_irq_chip,
+   >irq_data);
+   if (ret) {
+   dev_err(>client->dev, "Failed to request IRQ: %d\n", ret);
+   return ret;
+   }
+
+  

[RFC PATCH 1/5] dt-bindings: mfd: add entry for the Marvell 88PM88X PMICs

2023-12-17 Thread Karel Balej
From: Karel Balej 

Marvell 88PM880 and 88PM886 are two similar PMICs with mostly matching
register mapping and subdevices such as onkey, regulators or battery and
charger. Both seem to come in two revisions which seem to be handled
slightly differently in some subdevice drivers.

Signed-off-by: Karel Balej 
---
 .../bindings/mfd/marvell,88pm88x.yaml | 55 +++
 1 file changed, 55 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/marvell,88pm88x.yaml

diff --git a/Documentation/devicetree/bindings/mfd/marvell,88pm88x.yaml 
b/Documentation/devicetree/bindings/mfd/marvell,88pm88x.yaml
new file mode 100644
index ..e075729c360f
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/marvell,88pm88x.yaml
@@ -0,0 +1,55 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/marvell,88pm88x.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Marvell 88PM88X PMIC core MFD
+
+maintainers:
+  - Karel Balej 
+
+description: |
+  Marvell 88PM880 and 88PM886 are two similar PMICs providing
+  several functions such as onkey, regulators or battery and
+  charger. Both seem to come in two revisions -- A0 and A1.
+
+properties:
+  compatible:
+const: marvell,88pm886-a1
+
+  reg:
+description: I2C device address
+maxItems: 1
+
+  interrupt-controller: true
+
+  interrupts:
+maxItems: 1
+
+  "#interrupt-cells":
+const: 2
+
+required:
+  - compatible
+  - reg
+  - interrupt-controller
+  - interrupts
+
+additionalProperties: false
+
+examples:
+  - |
+i2c {
+  #address-cells = <1>;
+  #size-cells = <0>;
+  pmic0: 88pm886@30 {
+compatible = "marvell,88pm886-a1";
+reg = <0x30>;
+interrupts = <0 4 IRQ_TYPE_LEVEL_HIGH>;
+interrupt-parent = <>;
+interrupt-controller;
+#interrupt-cells = <1>;
+  };
+};
+...
-- 
2.43.0




Re: [PATCH v3 2/5] dt-bindings: input/touchscreen: Add compatible for IST3038B

2023-12-09 Thread Karel Balej
On Mon Dec 4, 2023 at 1:52 PM CET, Conor Dooley wrote:
> On Mon, Dec 04, 2023 at 02:40:44PM +0200, Markuss Broks wrote:
> > On 12/3/23 13:20, Conor Dooley wrote:
> > > On Sat, Dec 02, 2023 at 01:48:33PM +0100, Karel Balej wrote:
> > > > From: Markuss Broks 
> > > > 
> > > > Imagis IST3038B is a variant (firmware?) of Imagis IST3038 IC,
> > > > add the compatible for it to the IST3038C bindings.
> > > This one is better, but would be well served by mentioning what
> > > specifically is different (register addresses or firmware commands?)
> > 
> > I don't think anyone knows this other than Imagis itself. I would guess it's
> > different hardware, since register addresses are indeed different, but on
> > the other hand, there is a possibility that firmware on the MCU could be
> > responding to those commands. I suppose "... IST3038B is a hardware variant
> > of ... IST3038" would be more correct.
>
> Only Imagis might know the specifics, but you (plural) have made driver
> changes so you know what is different in terms of the programming model.
> I'm just asking for you to mention how the programming model varies in
> the commit message. Otherwise I can't know whether you should have added
> a fallback compatible, without going and reading your driver change. The
> commit message for the bindings should stand on its own merit in that
> regard.
> "Variant" alone does not suffice, as many variants of devices have a
> compatible programming model, be that for a subset of features or
> complete compatibility.
>
> > The reason why I think it could be firmware-defined is because we have a lot
> > of variants (30xxA, 30xxB, 30xxC, plain 30xx), and the numbers usually mean
> > feature level/completeness, e.g. some don't support the touch pressure or
> > touchkeys, and we don't know what A/B/C/none means.
>
> Ultimately whether it is due to firmware or the hardware isn't
> particular important, just mention what is incompatibly different.

I propose to update the commit description as such:

Imagis IST3038B is a variant (firmware?) of Imagis IST3038 IC
    differing from IST3038C in its register interface. Add the
compatible for it to the IST3038C bindings.

>
> Cheers,
> Conor.
>
>
> > > > Signed-off-by: Markuss Broks 
> > > > Signed-off-by: Karel Balej 
> > > > ---
> > > >   .../devicetree/bindings/input/touchscreen/imagis,ist3038c.yaml   | 1 +
> > > >   1 file changed, 1 insertion(+)
> > > > 
> > > > diff --git 
> > > > a/Documentation/devicetree/bindings/input/touchscreen/imagis,ist3038c.yaml
> > > >  
> > > > b/Documentation/devicetree/bindings/input/touchscreen/imagis,ist3038c.yaml
> > > > index 0d6b033fd5fb..b5372c4eae56 100644
> > > > --- 
> > > > a/Documentation/devicetree/bindings/input/touchscreen/imagis,ist3038c.yaml
> > > > +++ 
> > > > b/Documentation/devicetree/bindings/input/touchscreen/imagis,ist3038c.yaml
> > > > @@ -18,6 +18,7 @@ properties:
> > > > compatible:
> > > >   enum:
> > > > +  - imagis,ist3038b
> > > > - imagis,ist3038c
> > > > reg:
> > > > -- 
> > > > 2.43.0
> > > > 
> > - Markuss

Kind regards,
K. B.



Re: [PATCH v3 5/5] input/touchscreen: imagis: add support for IST3032C

2023-12-08 Thread Karel Balej
Markuss,

thank you for the review.

> > diff --git a/drivers/input/touchscreen/imagis.c 
> > b/drivers/input/touchscreen/imagis.c
> > index 84a02672ac47..41f28e6e9cb1 100644
> > --- a/drivers/input/touchscreen/imagis.c
> > +++ b/drivers/input/touchscreen/imagis.c
> > @@ -35,6 +35,8 @@
> >   #define IST3038B_REG_CHIPID   0x30
> >   #define IST3038B_WHOAMI   0x30380b
> >   
> > +#define IST3032C_WHOAMI0x32c
> > +

> Perhaps it should be ordered in alphabetic/alphanumeric order, 
> alternatively, the chip ID values could be grouped.

Here I followed suit and just started a new section for the new chip,
except there is only one entry. I do agree that it would be better to
sort the chips alphanumerically and I am actually surprised that I
didn't do that - but now I see that the chips that you added are not
sorted either, so it might be because of that.

I propose to definitely swap the order of the sections, putting 32C
first, then 38B and 38C at the end (from top to bottom). The chip ID
values could then still be grouped in a new section, but I think I would
actually prefer to keep them as parts of the respective sections as it
is now, although it is in no way a strong preference.

Please let me know whether you agree with this or have a different
preference. And if the former, please confirm that I can add your
Reviewed-by trailer to the patch modified in such a way.

Best regards,
K. B.



[PATCH v3 2/5] dt-bindings: input/touchscreen: Add compatible for IST3038B

2023-12-02 Thread Karel Balej
From: Markuss Broks 

Imagis IST3038B is a variant (firmware?) of Imagis IST3038 IC,
add the compatible for it to the IST3038C bindings.

Signed-off-by: Markuss Broks 
Signed-off-by: Karel Balej 
---
 .../devicetree/bindings/input/touchscreen/imagis,ist3038c.yaml   | 1 +
 1 file changed, 1 insertion(+)

diff --git 
a/Documentation/devicetree/bindings/input/touchscreen/imagis,ist3038c.yaml 
b/Documentation/devicetree/bindings/input/touchscreen/imagis,ist3038c.yaml
index 0d6b033fd5fb..b5372c4eae56 100644
--- a/Documentation/devicetree/bindings/input/touchscreen/imagis,ist3038c.yaml
+++ b/Documentation/devicetree/bindings/input/touchscreen/imagis,ist3038c.yaml
@@ -18,6 +18,7 @@ properties:
 
   compatible:
 enum:
+  - imagis,ist3038b
   - imagis,ist3038c
 
   reg:
-- 
2.43.0




[PATCH v3 0/5] input/touchscreen: imagis: add support for IST3032C

2023-12-02 Thread Karel Balej
From: Karel Balej 

This patch series generalizes the Imagis touchscreen driver to support
other Imagis chips, namely IST3038B, which use a slightly different
protocol.

It also adds necessary information to the driver so that the IST3032C
touchscreen can be used with it. The motivation for this is the
samsung,coreprimevelte smartphone with which this series has been
tested. However, the support for this device is not yet in-tree, the
effort is happening at [1]. In particular, the driver for the regulator
needed by the touchscreen on this device has not been rewritten for
mainline yet.

Note that this is a prerequisite for this patch [2] which implements
support for touch keys for Imagis touchscreens that have it.

[1] 
https://lore.kernel.org/all/20231102-pxa1908-lkml-v7-0-cabb1a0cb...@skole.hr/
[2] https://lore.kernel.org/all/20231112194124.24916-1-duje.mihano...@skole.hr/
---
v3:
- Rebase to v6.7-rc3.
- v2: 
https://lore.kernel.org/all/20231003133440.4696-1-kar...@gimli.ms.mff.cuni.cz/
v2:
- Do not rename the driver.
- Do not hardcode voltage required by the IST3032C.
- Use Markuss' series which generalizes the driver. Link to the original
  series: 
https://lore.kernel.org/all/20220504152406.8730-1-markuss.br...@gmail.com/
- Separate bindings into separate patch.
- v1: https://lore.kernel.org/all/20230926173531.18715-1-bal...@matfyz.cz/
---

Karel Balej (2):
  dt-bindings: input/touchscreen: imagis: add compatible for IST3032C
  input/touchscreen: imagis: add support for IST3032C

Markuss Broks (3):
  input/touchscreen: imagis: Correct the maximum touch area value
  dt-bindings: input/touchscreen: Add compatible for IST3038B
  input/touchscreen: imagis: Add support for Imagis IST3038B

 .../input/touchscreen/imagis,ist3038c.yaml|  2 +
 drivers/input/touchscreen/imagis.c| 70 +++
 2 files changed, 60 insertions(+), 12 deletions(-)

-- 
2.43.0




[PATCH v3 3/5] input/touchscreen: imagis: Add support for Imagis IST3038B

2023-12-02 Thread Karel Balej
From: Markuss Broks 

Imagis IST3038B is another variant of Imagis IST3038 IC, which has
a different register interface from IST3038C (possibly firmware defined).
This should also work for IST3044B (though untested), however other
variants using this interface/protocol(IST3026, IST3032, IST3026B,
IST3032B) have a different format for coordinates, and they'd need
additional effort to be supported by this driver.

Signed-off-by: Markuss Broks 
Signed-off-by: Karel Balej 
---
 drivers/input/touchscreen/imagis.c | 58 --
 1 file changed, 47 insertions(+), 11 deletions(-)

diff --git a/drivers/input/touchscreen/imagis.c 
b/drivers/input/touchscreen/imagis.c
index e67fd3011027..84a02672ac47 100644
--- a/drivers/input/touchscreen/imagis.c
+++ b/drivers/input/touchscreen/imagis.c
@@ -13,7 +13,7 @@
 
 #define IST3038C_HIB_ACCESS(0x800B << 16)
 #define IST3038C_DIRECT_ACCESS BIT(31)
-#define IST3038C_REG_CHIPID0x40001000
+#define IST3038C_REG_CHIPID(0x40001000 | IST3038C_DIRECT_ACCESS)
 #define IST3038C_REG_HIB_BASE  0x3100
 #define IST3038C_REG_TOUCH_STATUS  (IST3038C_REG_HIB_BASE | 
IST3038C_HIB_ACCESS)
 #define IST3038C_REG_TOUCH_COORD   (IST3038C_REG_HIB_BASE | 
IST3038C_HIB_ACCESS | 0x8)
@@ -31,8 +31,21 @@
 #define IST3038C_FINGER_COUNT_SHIFT12
 #define IST3038C_FINGER_STATUS_MASKGENMASK(9, 0)
 
+#define IST3038B_REG_STATUS0x20
+#define IST3038B_REG_CHIPID0x30
+#define IST3038B_WHOAMI0x30380b
+
+struct imagis_properties {
+   unsigned int interrupt_msg_cmd;
+   unsigned int touch_coord_cmd;
+   unsigned int whoami_cmd;
+   unsigned int whoami_val;
+   bool protocol_b;
+};
+
 struct imagis_ts {
struct i2c_client *client;
+   const struct imagis_properties *tdata;
struct input_dev *input_dev;
struct touchscreen_properties prop;
struct regulator_bulk_data supplies[2];
@@ -84,8 +97,7 @@ static irqreturn_t imagis_interrupt(int irq, void *dev_id)
int i;
int error;
 
-   error = imagis_i2c_read_reg(ts, IST3038C_REG_INTR_MESSAGE,
-   _message);
+   error = imagis_i2c_read_reg(ts, ts->tdata->interrupt_msg_cmd, 
_message);
if (error) {
dev_err(>client->dev,
"failed to read the interrupt message: %d\n", error);
@@ -104,9 +116,13 @@ static irqreturn_t imagis_interrupt(int irq, void *dev_id)
finger_pressed = intr_message & IST3038C_FINGER_STATUS_MASK;
 
for (i = 0; i < finger_count; i++) {
-   error = imagis_i2c_read_reg(ts,
-   IST3038C_REG_TOUCH_COORD + (i * 4),
-   _status);
+   if (ts->tdata->protocol_b)
+   error = imagis_i2c_read_reg(ts,
+   ts->tdata->touch_coord_cmd, 
_status);
+   else
+   error = imagis_i2c_read_reg(ts,
+   ts->tdata->touch_coord_cmd 
+ (i * 4),
+   _status);
if (error) {
dev_err(>client->dev,
"failed to read coordinates for finger %d: 
%d\n",
@@ -261,6 +277,12 @@ static int imagis_probe(struct i2c_client *i2c)
 
ts->client = i2c;
 
+   ts->tdata = device_get_match_data(dev);
+   if (!ts->tdata) {
+   dev_err(dev, "missing chip data\n");
+   return -EINVAL;
+   }
+
error = imagis_init_regulators(ts);
if (error) {
dev_err(dev, "regulator init error: %d\n", error);
@@ -279,15 +301,13 @@ static int imagis_probe(struct i2c_client *i2c)
return error;
}
 
-   error = imagis_i2c_read_reg(ts,
-   IST3038C_REG_CHIPID | IST3038C_DIRECT_ACCESS,
-   _id);
+   error = imagis_i2c_read_reg(ts, ts->tdata->whoami_cmd, _id);
if (error) {
dev_err(dev, "chip ID read failure: %d\n", error);
return error;
}
 
-   if (chip_id != IST3038C_WHOAMI) {
+   if (chip_id != ts->tdata->whoami_val) {
dev_err(dev, "unknown chip ID: 0x%x\n", chip_id);
return -EINVAL;
}
@@ -343,9 +363,25 @@ static int imagis_resume(struct device *dev)
 
 static DEFINE_SIMPLE_DEV_PM_OPS(imagis_pm_ops, imagis_suspend, imagis_resume);
 
+static const struct imagis_properties imagis_3038b_data = {
+   .interrupt_msg_cmd = IST3038B_REG_STATUS,
+   .touch_coord_cmd = IST3038B_REG_STATUS,
+   .whoami_cmd = IST3038B_REG_CHIPID,
+   .whoami_val = IST3038B_WHOAMI,
+   .protocol_b

[PATCH v3 5/5] input/touchscreen: imagis: add support for IST3032C

2023-12-02 Thread Karel Balej
From: Karel Balej 

IST3032C is a touchscreen chip used for instance in the
samsung,coreprimevelte smartphone, with which this was tested. Add the
chip specific information to the driver.

Signed-off-by: Karel Balej 
---
 drivers/input/touchscreen/imagis.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/drivers/input/touchscreen/imagis.c 
b/drivers/input/touchscreen/imagis.c
index 84a02672ac47..41f28e6e9cb1 100644
--- a/drivers/input/touchscreen/imagis.c
+++ b/drivers/input/touchscreen/imagis.c
@@ -35,6 +35,8 @@
 #define IST3038B_REG_CHIPID0x30
 #define IST3038B_WHOAMI0x30380b
 
+#define IST3032C_WHOAMI0x32c
+
 struct imagis_properties {
unsigned int interrupt_msg_cmd;
unsigned int touch_coord_cmd;
@@ -363,6 +365,13 @@ static int imagis_resume(struct device *dev)
 
 static DEFINE_SIMPLE_DEV_PM_OPS(imagis_pm_ops, imagis_suspend, imagis_resume);
 
+static const struct imagis_properties imagis_3032c_data = {
+   .interrupt_msg_cmd = IST3038C_REG_INTR_MESSAGE,
+   .touch_coord_cmd = IST3038C_REG_TOUCH_COORD,
+   .whoami_cmd = IST3038C_REG_CHIPID,
+   .whoami_val = IST3032C_WHOAMI,
+};
+
 static const struct imagis_properties imagis_3038b_data = {
.interrupt_msg_cmd = IST3038B_REG_STATUS,
.touch_coord_cmd = IST3038B_REG_STATUS,
@@ -380,6 +389,7 @@ static const struct imagis_properties imagis_3038c_data = {
 
 #ifdef CONFIG_OF
 static const struct of_device_id imagis_of_match[] = {
+   { .compatible = "imagis,ist3032c", .data = _3032c_data },
{ .compatible = "imagis,ist3038b", .data = _3038b_data },
{ .compatible = "imagis,ist3038c", .data = _3038c_data },
{ },
-- 
2.43.0




[PATCH v3 4/5] dt-bindings: input/touchscreen: imagis: add compatible for IST3032C

2023-12-02 Thread Karel Balej
From: Karel Balej 

Document possible usage of the Imagis driver with the IST3032C
touchscreen.

Signed-off-by: Karel Balej 
---
 .../devicetree/bindings/input/touchscreen/imagis,ist3038c.yaml   | 1 +
 1 file changed, 1 insertion(+)

diff --git 
a/Documentation/devicetree/bindings/input/touchscreen/imagis,ist3038c.yaml 
b/Documentation/devicetree/bindings/input/touchscreen/imagis,ist3038c.yaml
index b5372c4eae56..2af71cbcc97d 100644
--- a/Documentation/devicetree/bindings/input/touchscreen/imagis,ist3038c.yaml
+++ b/Documentation/devicetree/bindings/input/touchscreen/imagis,ist3038c.yaml
@@ -18,6 +18,7 @@ properties:
 
   compatible:
 enum:
+  - imagis,ist3032c
   - imagis,ist3038b
   - imagis,ist3038c
 
-- 
2.43.0




[PATCH v3 1/5] input/touchscreen: imagis: Correct the maximum touch area value

2023-12-02 Thread Karel Balej
From: Markuss Broks 

As specified in downstream IST3038B driver and proved by testing,
the correct maximum reported value of touch area is 16.

Signed-off-by: Markuss Broks 
Signed-off-by: Karel Balej 
---
 drivers/input/touchscreen/imagis.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/input/touchscreen/imagis.c 
b/drivers/input/touchscreen/imagis.c
index 07111ca24455..e67fd3011027 100644
--- a/drivers/input/touchscreen/imagis.c
+++ b/drivers/input/touchscreen/imagis.c
@@ -210,7 +210,7 @@ static int imagis_init_input_dev(struct imagis_ts *ts)
 
input_set_capability(input_dev, EV_ABS, ABS_MT_POSITION_X);
input_set_capability(input_dev, EV_ABS, ABS_MT_POSITION_Y);
-   input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
+   input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, 16, 0, 0);
 
touchscreen_parse_properties(input_dev, true, >prop);
if (!ts->prop.max_x || !ts->prop.max_y) {
-- 
2.43.0




  1   2   >