Skip to content

Staging/max77840 device driver #2815

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

joan-na-good
Copy link
Collaborator

PR Description

This PR introduces initial support for the MAX77840 PMIC device driver.

The changes include:

  • MFD (Multi-Function Device) parent driver
  • Charger, Regulator, and Fuel Gauge sub-drivers
  • YAML-based Device Tree bindings with validation

All code has been built successfully, passed checkpatch.pl in strict mode. No external dependencies are required.

PR Type

  • Bug fix (a change that fixes an issue)
  • New feature (a change that adds new functionality)
  • Breaking change (a change that affects other repos or cause CIs to fail)

PR Checklist

  • I have conducted a self-review of my own code changes
  • I have tested the changes on the relevant hardware
  • I have updated the documentation outside this repo accordingly (if there is the case)

@joan-na-good joan-na-good force-pushed the staging/max77840-device-driver branch from ac38438 to 2e29b07 Compare June 9, 2025 13:45
Add device tree bindings to support the MAX77840 PMIC and its
submodules, enabling configuration and control through device tree.

Signed-off-by: joan-na-good <joan.na@analog.com>
Implement basic support for the MAX77840 PMIC core, including
initialization, power management, and core functions necessary for
submodules.

Signed-off-by: joan-na-good <joan.na@analog.com>
…uel gauge

This patch adds driver support for the MAX77840 charger, charger-detect,
and fuel gauge functionalities, enabling proper battery management
and monitoring on supported platforms.

Signed-off-by: joan-na-good <joan.na@analog.com>
Add regulator support for the MAX77840 PMIC to control voltage and current
regulation. This enables proper power management features required for
various submodules dependent on this regulator.

Signed-off-by: joan-na-good <joan.na@analog.com>
@joan-na-good joan-na-good force-pushed the staging/max77840-device-driver branch from 2e29b07 to 8cf13d6 Compare June 9, 2025 14:03
Copy link
Collaborator

@nunojsa nunojsa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some general notes from me but this needs a lot of rework before I can do a proper review. This seems like a very old, out of tree, driver which is using a lot of questionable things. Please look at another upstream examples in:

https://elixir.bootlin.com/linux/v6.15/source/drivers/mfd

and rework the drivers so they are modern. Otherwise it gets very time consuming (and difficult) for me to review this.

Also bear in mind that the goal is to send this upstream and get it accepted before merging it in our tree.

@@ -77,6 +77,7 @@ obj-$(CONFIG_CHARGER_MAX14577) += max14577_charger.o
obj-$(CONFIG_CHARGER_DETECTOR_MAX14656) += max14656_charger_detector.o
obj-$(CONFIG_CHARGER_MAX77650) += max77650-charger.o
obj-$(CONFIG_CHARGER_MAX77693) += max77693_charger.o
obj-$(CONFIG_CHARGER_MAX77840) += max77840-charger.o max77840-charger-detect.o max77840-battery.o
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds three different drivers all as part of the supply subsystem? Can't we have just one driver?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MAX77840 is a single chip, it integrates multiple functional blocks — charger, regulator, and fuel gauge.
Therefore, if possible, I’d prefer to maintain the current structure.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MAX77840 is a single chip, it integrates multiple functional blocks — charger, regulator, and fuel gauge.
Therefore, if possible, I’d prefer to maintain the current structure.

Yes, but it is three drivers in the same subsystem... Anyways, if the maintainer accepts this, fine by me. But at least for this review add a driver per commit and not three drivers in one single commit.

int restart_threshold;
int termination_voltage;
int input_current_limit;
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop the above header files if they are only used by the respective source file.

CHG_INT_CHG_I,
CHG_INT_TOPOFF_I,
CHG_INT_CHGIN_I,
CHG_INT_AICL_CHGINI_I,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typically, all the defines, enum, etc, are prefixed with the driver name

// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2020 Maxim Integrated Products, Inc.
* Copyright (C) 2024 Analog Devices, Inc.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess 2025 will also be needed

#ifndef __MAX77840_MFD_H__
#define __MAX77840_MFD_H__

#define __TEST_DEVICE_NODE__
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

#define I2C_ADDR_FUEL_GAUGE (0x6C >> 1) /* Fuel Gauge */

#define __lock(_me) mutex_lock(&(_me)->lock)
#define __unlock(_me) mutex_unlock(&(_me)->lock)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drop the above lock defines. In fact, look at the cleanup.h header

{
return regmap_bulk_write(regmap, (unsigned int)addr, src, (size_t)len);
}
EXPORT_SYMBOL(max77840_bulk_write);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drop the above

/* PMIC */
#define REG_PMICID 0x00

/* Declare Interrupt */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please drop all the unneeded comments

pr_err("<%s> failed to set up interrupt\n",
client->name);
pr_err("<%s> and add sub-device [%d]\n",
client->name, rc);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no pr_err(). Use dev_err()

}

module_init(max77840_init);
module_exit(max77840_exit);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The above is not how it should be done

@joan-na-good
Copy link
Collaborator Author

Some general notes from me but this needs a lot of rework before I can do a proper review. This seems like a very old, out of tree, driver which is using a lot of questionable things. Please look at another upstream examples in:

https://elixir.bootlin.com/linux/v6.15/source/drivers/mfd

and rework the drivers so they are modern. Otherwise it gets very time consuming (and difficult) for me to review this.

Also bear in mind that the goal is to send this upstream and get it accepted before merging it in our tree.

Thank you for the feedback.
Sorry, I was not aware that the driver needs to be upstreamed and approved before it can be merged into the source tree.
I will review the examples you shared and revise the patch to meet the current kernel standards.
And I will proceed with upstreaming and obtaining the necessary approval.

@gastmaier
Copy link
Contributor

@nuno should a mirror for git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd.git (for-mfd-next) be added to the cron.yml?
So Joan can open a draft pr against it to have all the implemented checking?

I did a manual at mirror/lee/mfd/for-mfd-next meanwhile

@nunojsa
Copy link
Collaborator

nunojsa commented Jun 11, 2025

Sorry, I was not aware that the driver needs to be upstreamed and approved before it can be merged into the source tree.
I will review the examples you shared and revise the patch to meet the current kernel standards.
And I will proceed with upstreaming and obtaining the necessary approval.

Yes, the background story is that 99.9% of the times the driver will change after being upstreamed (due to review comments) and then we would need to backport those changes to sync the driver with upstream. Or, in some other cases, we would just forget to sync and then I would get tons of conflicts while updating to a new kernel version. This way, it makes it easier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants