On Fri, 20 Jun 2025, Alex Elder wrote:
On 6/19/25 9:40 AM, Lee Jones wrote:
On Fri, 13 Jun 2025, Alex Elder wrote:
Add support for SpacemiT PMICs. Initially only the P1 PMIC is supported
but the driver is structured to allow support for others to be added.
The P1 PMIC is controlled by I2C, and is normally implemented with the
SpacemiT K1 SoC. This PMIC provides six buck converters and 12 LDO
six or 12. Please pick a format and remain consistent.
"Numbers smaller than ten should be spelled out."
Never heard of that before Googling it. Formal writing is odd. :)
But I'll use 6 and 12.
+/* The name field defines the *driver* name that should bind to the device */
This comment is superfluous.
I'll delete it.
I was expecting the driver to recognize the device, not
the device specifying what driver to use, but I guess
I'm used to the DT model.
Even in DT, the *driver* compatible is specified.
.driver.of_match_table->compatible
+ /* We currently have no need for a device-specific structure */
Then why are we adding one?
I don't understand, but it might be moot once I add support
for another (sub)device.
There are 2 rules in play here:
- Only add what you need, when you need it
- MFDs must contain more than 1 device
... and you're right. The second rule moots the first here.
+static const struct of_device_id spacemit_pmic_match[] = {
+ {
+ .compatible = "spacemit,p1",
+ .data = &p1_pmic_data,
Ah, now I see.
We do not allow one data from registration mechanism (MFD) to be piped
through another (OF). If you have to match platform data to device (you
don't), then pass through identifiers and match on those in a switch()
statement instead.
I haven't done an MFD driver before and it took some time
to get this working. I'll tell you what led me to it.
I used code posted by Troy Mitchell (plus downstream) as a
starting point.
https://lore.kernel.org/lkml/20241230-k1-p1-v1-0-aa4e02b9f993@xxxxxxxxx/
Krzysztof Kozlowski made this comment on Troy's DT binding:
Drop compatible, regulators are not re-usable blocks.
So my goal was to have the PMIC regulators get bound to a
driver without specifying a DT compatible string, and I
found this worked.
You say I don't need to match platform data to device, but
if I did I would pass through identifiers. Can you refer
me to an example of code that correctly does what I should
be doing instead?
git grep -A5 compatible -- drivers/mfd | grep -E "\.data = .*[A-Z]+"
Those identifiers are usually matched in a swtich() statement.
One other comment/question:
This driver is structured as if it could support a different
PMIC (in addition to P1). Should I *not* do that, and simply
make a source file hard-coded for this one PMIC?
This comes back to the "add only what you need, when you need it" rule.
+module_init(spacemit_pmic_init);
+module_exit(spacemit_pmic_exit);
Are you sure there isn't some boiler plate to do all of this?
Ah ha:
module_i2c_driver()
Thanks for Googling that for me. And thank you very much
for the review.
`git grep` is my bestie! =:-)