Skip to content
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

Add support for MAX16150/MAX16169 #2672

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

Conversation

mrcsosa
Copy link

@mrcsosa mrcsosa commented Dec 10, 2024

PR Description

  • Please replace this comment with a summary of your changes, and add any context
    necessary to understand them. List any dependencies required for this change.
  • To check the checkboxes below, insert a 'x' between square brackets (without
    any space), or simply check them after publishing the PR.
  • If you changes include a breaking change, please specify dependent PRs in the
    description and try to push all related PRs simultaneously.

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)

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.

I'm stopping the review for now. Note that you pretty much copied the driver from one subsystem to another without any integration with the input subsystem. Not what was meant.

Please do not rush into opening PRs or having things done. Really try to understand what was asked and seek help if needed 😉

brcm,function = <0>;
brcm,pull = <0>;
};
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks to be very rpi dependent... Typically not needed in bindings AFAIK. But you're definetly missing input properties. Where do you define the key code?

Copy link
Author

Choose a reason for hiding this comment

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

I think the key code is typically used to detect button presses. However, with MAX16150, it sends interrupt signals when certain amount of time the button is pressed.

compatible = "adi,max16150";
adi,variant = "A";

gpio-pb_in = <&gpio 17 1>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't think the above needs to be a gpio. It's a button that you should register with the input subsystem

adi,variant = "A";

gpio-pb_in = <&gpio 17 1>;
gpio-out = <&gpio 18 0>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm also not convinced we need the above...

gpio-pb_in = <&gpio 17 1>;
gpio-out = <&gpio 18 0>;
gpio-clr = <&gpio 22 1>;
gpio-int = <&gpio 23 0>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is an interrupts property and not a gpio


hrtimer_cancel(&data->debounce_timer);
hrtimer_cancel(&data->shutdown_timer);
return 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can be done in a devm_action... Also not sure if we really need hrtimers for this

if (ret) {
dev_err(&pdev->dev, "Failed to request IRQ for PB_IN\n");
return ret;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just use an irq... No need for it to be a gpio

} else {
dev_err(&pdev->dev, "Unknown device type: %s\n", type);
return -EINVAL;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

use proper chip info structure for subtleties in the chips... The above does not scale at al.

return -EINVAL;
}

ret = device_property_read_string(&pdev->dev, "adi,variant", &variant);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not in the bindings and I dunno you need a property for this... You already have compatibles and you can different info structure per compatible.

@mrcsosa mrcsosa marked this pull request as draft December 12, 2024 08:06
Copy link
Contributor

@kister-jimenez kister-jimenez left a comment

Choose a reason for hiding this comment

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

You might want to check out existing input device drivers for reference.


if (data->variant == MAX161X_A && data->out_asserted) {
dev_info(data->dev, "Shutdown time exceeded. Deasserting OUT.");
gpiod_set_value(data->gpio_clr, 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

You should use the input subsystem like input_report_key and input_sync to report the key and the value to the input subsystem and to sync input events.

Comment on lines 138 to 154
case 'A':
data->variant = MAX161X_A;
data->debounce_time = ktime_set(0, 50 * NSEC_PER_MSEC);
data->shutdown_time = (data->type == MAX16150) ? ktime_set(8,
0) : ktime_set(16, 0);
break;
case 'B':
data->variant = MAX161X_B;
data->debounce_time = (data->type == MAX16150) ? ktime_set(2,
0) : ktime_set(50, 0);
data->shutdown_time = ktime_set(16, 0);
break;
case 'C':
data->variant = MAX161X_C;
data->debounce_time = ktime_set(0, 50 * NSEC_PER_MSEC);
data->shutdown_time = ktime_set(16, 0);
break;
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure why you need the debounce time and shutdown time.
Debounce time is for the push button input which should be connected to a push button not the processor system.

Shutdown period is how long the button is pressed before the chip deasserts (in some variant) and pull down the interrupt pin. This is also related to the button side.

dev_info(&pdev->dev, "Detected %s variant %s\n",
(data->type == MAX16150) ? "MAX16150" : "MAX16169", variant);

data->gpio_pb_in = devm_gpiod_get(&pdev->dev, "pb_in", GPIOD_IN);
Copy link
Contributor

Choose a reason for hiding this comment

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

pb_in is not an input to the MPU and is not connected to the MPU. This is connected to the push button.

if (IS_ERR(data->gpio_pb_in))
return PTR_ERR(data->gpio_pb_in);

data->gpio_out = devm_gpiod_get(&pdev->dev, "out", GPIOD_OUT_LOW);
Copy link
Contributor

Choose a reason for hiding this comment

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

Out pin of the device is typically used to control a switch or to gate the power to the device. You don't need this.

if (IS_ERR(data->gpio_clr))
return PTR_ERR(data->gpio_clr);

data->gpio_int = devm_gpiod_get(&pdev->dev, "int", GPIOD_IN);
Copy link
Contributor

Choose a reason for hiding this comment

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

Just use an irq.

Comment on lines 20 to 29
enum max161x_variant {
MAX161X_A,
MAX161X_B,
MAX161X_C,
};

enum max161x_type {
MAX16150,
MAX16169,
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Why don't you just combine these? I think the variant is part of the ordering options for customers to select different timing options?

Comment on lines 89 to 31
if (gpiod_get_value(data->gpio_pb_in)) {
/* Button pressed */
hrtimer_start(&data->debounce_timer, data->debounce_time,
HRTIMER_MODE_REL);
} else {
/* Button released */
if (data->variant == MAX161X_A && data->out_asserted) {
dev_info(data->dev, "Cancelling shutdown timer.");
hrtimer_cancel(&data->shutdown_timer);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

You should use the input subsystem like input_report_key and input_sync to report the key and the value to the input subsystem and to sync input events.

I think what you want is to know the interval between the last irq if you want to distinguish the long press and the short momentary press.

hrtimer_init(&data->shutdown_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
data->shutdown_timer.function = max161x_shutdown_timer_cb;

ret = devm_request_irq(&pdev->dev, gpiod_to_irq(data->gpio_pb_in),
Copy link
Contributor

Choose a reason for hiding this comment

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

The irq pin is the int pin not the pb_in pin.

@mrcsosa mrcsosa marked this pull request as ready for review December 17, 2024 00:00
@mrcsosa mrcsosa marked this pull request as draft January 13, 2025 00:35
@mrcsosa mrcsosa force-pushed the dev/max16150 branch 4 times, most recently from 7aebbf1 to e96094d Compare January 13, 2025 01:26
@mrcsosa
Copy link
Author

mrcsosa commented Jan 13, 2025

Changelogs V2:

  • Converted few functions to use input subsystem
  • Removed unused gpio pins, leaving int pin (to detect 32ms and 128ms interrupts) and clr pin to reset the output for Variant A devices.
  • Removed variants on the driver code and dts

@mrcsosa mrcsosa marked this pull request as ready for review January 13, 2025 02:49
Add documentation for device tree bindings for MAX16150/MAX16169

Signed-off-by: Marc Paolo Sosa <[email protected]>
MAX16150/MAX16169 nanoPower Pushbutton On/Off Controller

Signed-off-by: Marc Paolo Sosa <[email protected]>
Add entry for the MAX16150/MAX16169 driver.

Signed-off-by: Marc Paolo Sosa <[email protected]>
@mrcsosa mrcsosa marked this pull request as draft January 13, 2025 06:45
@mrcsosa mrcsosa marked this pull request as ready for review January 13, 2025 08:27
Comment on lines +14 to +15
#define GPIO_INT 17
#define GPIO_CLR 27
Copy link
Contributor

Choose a reason for hiding this comment

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

Get this from the device tree overlay.

Comment on lines +23 to +33
static irqreturn_t max16150_isr(int irq, void *dev_id)
{
ktime_t now = ktime_get();
ktime_t duration = ktime_sub(now, last_time);

if (duration >= long_pulse)
gpio_set_value(GPIO_CLR, 0);

last_time = now;
return IRQ_HANDLED;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

How will the input event propagate to sysfs?
How can users define different events for the long button press and short button press?

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