maverick_24
Posts: 11
Joined: Thu Sep 29, 2022 8:15 am

How to control CAM GPIO of Raspberry Pi 4 from MIPI CSI driver?

Thu Nov 24, 2022 10:51 am

Hello,
I'm trying to stream video from MIPI Camera modules, which officially not supported by RPI, there I want to control CAM GPIO pin present in MIPI CSI interface, so can one tell me how to use this CAM GPIO pin in mipi driver.
I have only idea that, I need to use this function to access GPIO pin.

Code: Select all

struct gpio_desc *devm_gpiod_get_optional(struct device *dev,
						  const char *con_id,
						  enum gpiod_flags flags)


can anyone tell me what lines need to be added in dts file?

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 13531
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: How to control CAM GPIO of Raspberry Pi 4 from MIPI CSI driver?

Thu Nov 24, 2022 11:32 am

Generally it is better to use the regulator framework instead of the GPIO one.

CM4 shares the one CAM_GPIO line between the 2 camera connectors, and similarly you can have both a sensor and lens driver that want to control power on one module.
GPIOs can only be claimed by one driver, therefore you can't use the one line and load 2 drivers for 2 connected sensors (even if it is 2 instances of the same driver). Regulators are designed to be shared, with any user requesting power resulting in (reference counted) control of the GPIO.

In the standard DT you'll find node cam1_reg (and if applicable also cam0_reg for Compute Modules). These are correctly configured for the relevant GPIO on the platform, as it does move between variants of Pi.
If you look at imx219 as an example, you'll see calls to devm_regulator_bulk_get, regulator_bulk_enable, regulator_bulk_disable. Those are the calls you need to replicate in your driver, along with the associated linkage in the dtoverlay.
Software Engineer at Raspberry Pi Ltd. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

maverick_24
Posts: 11
Joined: Thu Sep 29, 2022 8:15 am

Re: How to control CAM GPIO of Raspberry Pi 4 from MIPI CSI driver?

Fri Nov 25, 2022 4:28 am

Can you tell me what is the GPIO number of CAM_GPIO0 in Raspberry Pi 4? I'm able to control GPIO pins present in GPIO headers but not CAM_GPIO0, is CAM_GPIO0 pin number is 133?
and one more thing is I did not found any GPIO pins assigned to CAM_GPIO0 here
https://elinux.org/RPi_BCM2711_GPIOs

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 13531
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: How to control CAM GPIO of Raspberry Pi 4 from MIPI CSI driver?

Fri Nov 25, 2022 8:23 am

maverick_24 wrote:
Fri Nov 25, 2022 4:28 am
Can you tell me what is the GPIO number of CAM_GPIO0 in Raspberry Pi 4? I'm able to control GPIO pins present in GPIO headers but not CAM_GPIO0, is CAM_GPIO0 pin number is 133?
and one more thing is I did not found any GPIO pins assigned to CAM_GPIO0 here
https://elinux.org/RPi_BCM2711_GPIOs
If you're persisting with the GPIO API, then expect problems - memory says the cam1_reg will already have claimed the GPIO, so you won't be able to.

The CAM_GPIO is on an I2C expander, not the main 54 GPIOs of the SoC. The firmware (not kernel) uses an offset of 128 to denote this.
https://github.com/raspberrypi/linux/bl ... b.dts#L546

Code: Select all

gpio = <&expgpio 5 GPIO_ACTIVE_HIGH>;
Software Engineer at Raspberry Pi Ltd. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

maverick_24
Posts: 11
Joined: Thu Sep 29, 2022 8:15 am

Re: How to control CAM GPIO of Raspberry Pi 4 from MIPI CSI driver?

Fri Nov 25, 2022 10:35 am

So can you tell me which function do I need to use to control CAM_GPIO0 pin from driver?

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 13531
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: How to control CAM GPIO of Raspberry Pi 4 from MIPI CSI driver?

Fri Nov 25, 2022 11:28 am

maverick_24 wrote:
Fri Nov 25, 2022 10:35 am
So can you tell me which function do I need to use to control CAM_GPIO0 pin from driver?
I already have - use the regulator framework with devm_regulator_bulk_get, regulator_bulk_enable, and regulator_bulk_disable.

If you really need to use it via the GPIO framework, then you will need to:
- disable cam1_reg in your dtoverlay
- define the GPIO in your device's DT node using the same syntax as I have already quoted is used by cam1_reg. Give it whatever name you require.
- request it by that name in your driver using devm_gpiod_get_optional, and then use gpiod_set_value_cansleep to control it.
Software Engineer at Raspberry Pi Ltd. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

maverick_24
Posts: 11
Joined: Thu Sep 29, 2022 8:15 am

Re: How to control CAM GPIO of Raspberry Pi 4 from MIPI CSI driver?

Fri Nov 25, 2022 12:58 pm

Can you tell me how to disable cam_reg1 overlay?
\

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 13531
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: How to control CAM GPIO of Raspberry Pi 4 from MIPI CSI driver?

Fri Nov 25, 2022 2:20 pm

maverick_24 wrote:
Fri Nov 25, 2022 12:58 pm
Can you tell me how to disable cam_reg1 overlay?
\
https://www.raspberrypi.com/documentati ... parameters
Software Engineer at Raspberry Pi Ltd. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Return to “Interfacing (DSI, CSI, I2C, etc.)”