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

Adding Pimidi kernel module. #6482

Merged
merged 3 commits into from
Nov 21, 2024

Conversation

gtrainavicius
Copy link
Contributor

Submitting a new kernel module and its DT overlay for an upcoming Blokas product.

@pelwell
Copy link
Contributor

pelwell commented Nov 20, 2024

Let the auto-builds complete to look for any obvious problems before submitting any changes, but we would appreciate this PR being split into 3 commits: driver (including Kconfig and Makefile), defconfig files, and the overlay files.

@pelwell
Copy link
Contributor

pelwell commented Nov 20, 2024

Note: We're not bothered about long lines in overlays, required changes to the list of MAINTAINERS, or new compatible strings requiring dt-bindings changes, but the other checkpatch errors and warnings should be fixed.

@gtrainavicius
Copy link
Contributor Author

I have split out the changes into the 3 commits as requested, as well as fixed the patch checks. Some warnings about pr_cont and a logging macro remain, but they are harmless for the module code.

instance->stopping = true;
cancel_work_sync(&instance->drdy_handler);
if (irq_initialized)
devm_free_irq(&client->dev, client->irq, instance);
Copy link
Contributor

Choose a reason for hiding this comment

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

It should not be necessary to call devm_free_irq unless you are intended to release the IRQ before the device is released. Returning an error from the probe method is not one of those situations, so you can delete this line (along with all mentions of irq_initialized).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, thank you, I've removed the lines in the latest push.

return;
}

if (gpiod_get_value(instance->data_ready_gpio)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Deciding whether to queue work or enable an interrupt based on the current state of the GPIO feels racy. Are you satisfied that it is safe? I guess it depends on whether the data ready line can spontaneously go high.

I also notice that you are taking care to release the comm_lock mutex before calling this function - why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The DRDY line remains high as set by the Pimidi device until all of its output is exhausted, this is a safe check.

The comm mutex is released to let the kernel module communicate with other Pimidi instances.

goto finalize;
}

pimidi_perform_reset();
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you explain to me why you go to the trouble of resetting the other devices when each instance is probed? I understand that it is a shared reset line, but why can't you just reset when the first instance is probed? Without this, the driver would be much simpler.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This supports the sudo dtoverlay pimidi sel=x usage when the devices must be loaded dynamically. As the reset is shared, each device must be re-initialized.

Copy link
Contributor

Choose a reason for hiding this comment

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

One of us isn't understanding. If the reset is shared, isn't all the hardware reset by the first probe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Each device must be initialized by a special 'handshake' via the DRDY GPIO. When a new device is added dynamically to the device tree, the kernel module can't know what is the current state of the new device, therefore, it must reset and do the 'handshake' procedure to all of them all over again, to ensure the state is consistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Keep in mind that when initial device is added via dtoverlay, the kernel module only knows about 1 of the DRDY pins, and a probe gets executed immediately. When a 2nd device gets added, it now knows about 2 DRDY pins, so it must repeat the procedure, as the new device must be reset, and as the reset is a shared line, it must re-initialize all the devices it knew of up till now.

Signed-off-by: Giedrius Trainavičius <[email protected]>
Signed-off-by: Giedrius Trainavičius <[email protected]>
@pelwell pelwell merged commit 75ab92b into raspberrypi:rpi-6.6.y Nov 21, 2024
11 of 12 checks passed
@gtrainavicius
Copy link
Contributor Author

Thank you! :)

popcornmix added a commit to raspberrypi/firmware that referenced this pull request Nov 25, 2024
kernel: media: i2c: imx477: Fix link frequency menu
See: raspberrypi/linux#6483

kernel: Adding Pimidi kernel module
See: raspberrypi/linux#6482

kernel: Enable Raspberry Touch 2 rotation with overlay
See: raspberrypi/linux#6480
popcornmix added a commit to raspberrypi/rpi-firmware that referenced this pull request Nov 25, 2024
kernel: media: i2c: imx477: Fix link frequency menu
See: raspberrypi/linux#6483

kernel: Adding Pimidi kernel module
See: raspberrypi/linux#6482

kernel: Enable Raspberry Touch 2 rotation with overlay
See: raspberrypi/linux#6480
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