walid yahia
Posts: 23
Joined: Thu Aug 19, 2021 8:48 am

How to use PCF85063AT with CM4 ?

Mon Jul 25, 2022 2:51 pm

Hi,

I would like to use the RTC functionality of the CM4 IO board, I'm trying to use PCF85063AT RTC, but it doesn't work.

Can you help me :)


PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5276
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: How to use PCF85063AT with CM4 ?

Tue Jul 26, 2022 6:23 am

a.k.a. "dtoverlay -h i2c-rtc".

The setting you need for the CM4 IO board is:

Code: Select all

dtoverlay=i2c-rtc,pcf85063a,i2c_csi_dsi

walid yahia
Posts: 23
Joined: Thu Aug 19, 2021 8:48 am

Re: How to use PCF85063AT with CM4 ?

Tue Jul 26, 2022 2:18 pm

@PhilE
Thank you for your reply :)

I have three questions about rtc and fan:

1- How can I use other Gpios for rtc/fan, because of my hw design is using Gpios 44,55 for an other I2c peripheral ?
2- How to install fan to my CM4 ?
3- Is Linux managing the communication with rtc and fan on the same I2c bus ?

Thank you :)

aBUGSworstnightmare
Posts: 7784
Joined: Tue Jun 30, 2015 1:35 pm

Re: How to use PCF85063AT with CM4 ?

Tue Jul 26, 2022 2:31 pm

walid yahia wrote:
Tue Jul 26, 2022 2:18 pm
@PhilE
Thank you for your reply :)

I have three questions about rtc and fan:

1- How can I use other Gpios for rtc/fan, because of my hw design is using Gpios 44,55 for an other I2c peripheral ?
2- How to install fan to my CM4 ?
3- Is Linux managing the communication with rtc and fan on the same I2c bus ?

Thank you :)
1) You know you can add many devices on a single I2C bus?

2) Do you have a fan controller? How should anyone know which fan you want to mount and how you intend to control it?
I have some of these https://www.waveshare.com/cm4-fan-3007-b.htm which do their job (but have not tested them to much).

3) a single I2C/SMB host can deal with 112 slaves! So yes, that's possible (and done on the CM4IO i.e.).

I2C_fan is a dedicated overlay for fan controllers - see https://github.com/raspberrypi/linux/bl ... ADME#L1585

Include "dtoverlay=i2c-fan,emc2301,i2c_csi_dsi" in your config.txt to enable the kernel fan controller driver (for fan controller IC used on CM4IO!).
Further parameters of minpwm (slowest pwm value 0-255 to run the fan at), maxpwm (max pwm value 0-255 to run the fan at), and midtemp and maxtemp to tune the fan speed vs temperature.

walid yahia
Posts: 23
Joined: Thu Aug 19, 2021 8:48 am

Re: How to use PCF85063AT with CM4 ?

Tue Jul 26, 2022 3:10 pm

aBUGSworstnightmare wrote:
Tue Jul 26, 2022 2:31 pm
walid yahia wrote:
Tue Jul 26, 2022 2:18 pm
@PhilE
Thank you for your reply :)

I have three questions about rtc and fan:

1- How can I use other Gpios for rtc/fan, because of my hw design is using Gpios 44,55 for an other I2c peripheral ?
2- How to install fan to my CM4 ?
3- Is Linux managing the communication with rtc and fan on the same I2c bus ?

Thank you :)
1) You know you can add many devices on a single I2C bus?

2) Do you have a fan controller? How should anyone know which fan you want to mount and how you intend to control it?
I have some of these https://www.waveshare.com/cm4-fan-3007-b.htm which do their job (but have not tested them to much).

3) a single I2C/SMB host can deal with 112 slaves! So yes, that's possible (and done on the CM4IO i.e.).

I2C_fan is a dedicated overlay for fan controllers - see https://github.com/raspberrypi/linux/bl ... ADME#L1585

Include "dtoverlay=i2c-fan,emc2301,i2c_csi_dsi" in your config.txt to enable the kernel fan controller driver (for fan controller IC used on CM4IO!).
Further parameters of minpwm (slowest pwm value 0-255 to run the fan at), maxpwm (max pwm value 0-255 to run the fan at), and midtemp and maxtemp to tune the fan speed vs temperature.
@aBUGSworstnightmare, thank you for reply

1) I know that I can add many devices on the same I2c bus, but my issue is that "Linux will control the communication with rtc on Gpios 44, 45 and at the same time I have an application which communicates with an other chip connected on Gpios 44, 45, So there are two sources will control the same I2c bus (Linux and my application) which may cause conflict"

2) Yes, I have EMC2301 controller on my board

3) This means that Linux should handle the relation between two the drivers of rtc and fan, Correct ?

aBUGSworstnightmare
Posts: 7784
Joined: Tue Jun 30, 2015 1:35 pm

Re: How to use PCF85063AT with CM4 ?

Tue Jul 26, 2022 5:47 pm

Kernel driver and your app should not share the same I2C bus as this can cause conflicts.

Kernel drivers on the same bus are fine!

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

Re: How to use PCF85063AT with CM4 ?

Tue Jul 26, 2022 6:39 pm

aBUGSworstnightmare wrote:
Tue Jul 26, 2022 5:47 pm
Kernel driver and your app should not share the same I2C bus as this can cause conflicts.

Kernel drivers on the same bus are fine!
Kernel drivers and apps can share the same bus, but they can't share the same address on the same bus.
If a kernel driver is registered on an address, the ioctl(I2C_SLAVE) call to request the address from userspace will fail. You can use ioctl(I2C_SLAVE_FORCE), but that is very bad practice, and can lead to devices misbehaving.
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.

walid yahia
Posts: 23
Joined: Thu Aug 19, 2021 8:48 am

Re: How to use PCF85063AT with CM4 ?

Wed Jul 27, 2022 8:58 am

aBUGSworstnightmare wrote:
Tue Jul 26, 2022 5:47 pm
Kernel driver and your app should not share the same I2C bus as this can cause conflicts.

Kernel drivers on the same bus are fine!
That's good,

looking to my base question "How to make rtc/fan work on pins other than 44, 45 ?"

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

Re: How to use PCF85063AT with CM4 ?

Wed Jul 27, 2022 10:37 am

walid yahia wrote:
Wed Jul 27, 2022 8:58 am
aBUGSworstnightmare wrote:
Tue Jul 26, 2022 5:47 pm
Kernel driver and your app should not share the same I2C bus as this can cause conflicts.

Kernel drivers on the same bus are fine!
That's good,

looking to my base question "How to make rtc/fan work on pins other than 44, 45 ?"
"dtoverlay -h i2c-fan" gives you the help text, sourced from https://github.com/raspberrypi/linux/bl ... ADME#L1585

Code: Select all

Params: addr                    Sets the address for the fan controller. Note
                                that the device must be configured to use the
                                specified address.

        i2c0                    Choose the I2C0 bus on GPIOs 0&1

        i2c_csi_dsi             Choose the I2C0 bus on GPIOs 44&45

        i2c3                    Choose the I2C3 bus (configure with the i2c3
                                overlay - BCM2711 only)

        i2c4                    Choose the I2C3 bus (configure with the i2c3
                                overlay - BCM2711 only)

        i2c5                    Choose the I2C5 bus (configure with the i2c4
                                overlay - BCM2711 only)

        i2c6                    Choose the I2C6 bus (configure with the i2c6
                                overlay - BCM2711 only)

        minpwm                  PWM setting for the fan when the SoC is below
                                mintemp (range 0-255. default 0)
        maxpwm                  PWM setting for the fan when the SoC is above
                                maxtemp (range 0-255. default 255)
        midtemp                 Temperature (in millicelcius) at which the fan
                                begins to speed up (default 50000)

        midtemp_hyst            Temperature delta (in millicelcius) below
                                mintemp at which the fan will drop to minrpm
                                (default 2000)

        maxtemp                 Temperature (in millicelcius) at which the fan
                                will be held at maxrpm (default 70000)

        maxtemp_hyst            Temperature delta (in millicelcius) below
                                maxtemp at which the fan begins to slow down
                                (default 2000)

        emc2301                 Select the Microchip EMC230x controller family
                                - EMC2301, EMC2302, EMC2303, EMC2305.
So add a parameter from that list to choose which I2C interface you wish to use.

Similarly for "dtoverlay -h i2c-rtc"

Code: Select all

Params: abx80x                  Select one of the ABx80x family:
                                  AB0801, AB0803, AB0804, AB0805,
                                  AB1801, AB1803, AB1804, AB1805

        bq32000                 Select the TI BQ32000 device

        ds1307                  Select the DS1307 device

        ds1339                  Select the DS1339 device

        ds1340                  Select the DS1340 device

        ds3231                  Select the DS3231 device

        m41t62                  Select the M41T62 device

        mcp7940x                Select the MCP7940x device

        mcp7941x                Select the MCP7941x device

        pcf2127                 Select the PCF2127 device

        pcf2129                 Select the PCF2129 device

        pcf85063                Select the PCF85063 device

        pcf85063a               Select the PCF85063A device

        pcf8523                 Select the PCF8523 device

        pcf85363                Select the PCF85363 device

        pcf8563                 Select the PCF8563 device

        rv1805                  Select the Micro Crystal RV1805 device

        rv3028                  Select the Micro Crystal RV3028 device

        rv8803                  Select the Micro Crystal RV8803 device

        sd3078                  Select the ZXW Shenzhen whwave SD3078 device

        s35390a                 Select the ABLIC S35390A device

        i2c0                    Choose the I2C0 bus on GPIOs 0&1

        i2c_csi_dsi             Choose the I2C0 bus on GPIOs 44&45

        i2c3                    Choose the I2C3 bus (configure with the i2c3
                                overlay - BCM2711 only)

        i2c4                    Choose the I2C3 bus (configure with the i2c3
                                overlay - BCM2711 only)

        i2c5                    Choose the I2C5 bus (configure with the i2c4
                                overlay - BCM2711 only)

        i2c6                    Choose the I2C6 bus (configure with the i2c6
                                overlay - BCM2711 only)

        addr                    Sets the address for the RTC. Note that the
                                device must be configured to use the specified
                                address.

        trickle-diode-disable   Do not use the internal trickle charger diode
                                (BQ32000 only)

        trickle-diode-type      Diode type for trickle charge - "standard" or
                                "schottky" (ABx80x and RV1805 only)

        trickle-resistor-ohms   Resistor value for trickle charge (DS1339,
                                ABx80x, RV1805, RV3028)

        wakeup-source           Specify that the RTC can be used as a wakeup
                                source

        backup-switchover-mode  Backup power supply switch mode. Must be 0 for
                                off or 1 for Vdd < VBackup (RV3028 only)
If you want the RTC on generic GPIOs with a bit-bashed I2C interface, then i2c-rtc-gpio is almost the same as i2c-rtc, but adds

Code: Select all

        i2c_gpio_sda            GPIO used for I2C data (default "23")

        i2c_gpio_scl            GPIO used for I2C clock (default "24")

        i2c_gpio_delay_us       Clock delay in microseconds
                                (default "2" = ~100kHz)
to allow you to define which GPIOs and at what speed.

There isn't an equivalent GPIO based I2C overlay for i2c-fan at present.
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.

walid yahia
Posts: 23
Joined: Thu Aug 19, 2021 8:48 am

Re: How to use PCF85063AT with CM4 ?

Wed Jul 27, 2022 12:38 pm

6by9 wrote:
Wed Jul 27, 2022 10:37 am
walid yahia wrote:
Wed Jul 27, 2022 8:58 am
aBUGSworstnightmare wrote:
Tue Jul 26, 2022 5:47 pm
Kernel driver and your app should not share the same I2C bus as this can cause conflicts.

Kernel drivers on the same bus are fine!
That's good,

looking to my base question "How to make rtc/fan work on pins other than 44, 45 ?"
"dtoverlay -h i2c-fan" gives you the help text, sourced from https://github.com/raspberrypi/linux/bl ... ADME#L1585

Code: Select all

Params: addr                    Sets the address for the fan controller. Note
                                that the device must be configured to use the
                                specified address.

        i2c0                    Choose the I2C0 bus on GPIOs 0&1

        i2c_csi_dsi             Choose the I2C0 bus on GPIOs 44&45

        i2c3                    Choose the I2C3 bus (configure with the i2c3
                                overlay - BCM2711 only)

        i2c4                    Choose the I2C3 bus (configure with the i2c3
                                overlay - BCM2711 only)

        i2c5                    Choose the I2C5 bus (configure with the i2c4
                                overlay - BCM2711 only)

        i2c6                    Choose the I2C6 bus (configure with the i2c6
                                overlay - BCM2711 only)

        minpwm                  PWM setting for the fan when the SoC is below
                                mintemp (range 0-255. default 0)
        maxpwm                  PWM setting for the fan when the SoC is above
                                maxtemp (range 0-255. default 255)
        midtemp                 Temperature (in millicelcius) at which the fan
                                begins to speed up (default 50000)

        midtemp_hyst            Temperature delta (in millicelcius) below
                                mintemp at which the fan will drop to minrpm
                                (default 2000)

        maxtemp                 Temperature (in millicelcius) at which the fan
                                will be held at maxrpm (default 70000)

        maxtemp_hyst            Temperature delta (in millicelcius) below
                                maxtemp at which the fan begins to slow down
                                (default 2000)

        emc2301                 Select the Microchip EMC230x controller family
                                - EMC2301, EMC2302, EMC2303, EMC2305.
So add a parameter from that list to choose which I2C interface you wish to use.

Similarly for "dtoverlay -h i2c-rtc"

Code: Select all

Params: abx80x                  Select one of the ABx80x family:
                                  AB0801, AB0803, AB0804, AB0805,
                                  AB1801, AB1803, AB1804, AB1805

        bq32000                 Select the TI BQ32000 device

        ds1307                  Select the DS1307 device

        ds1339                  Select the DS1339 device

        ds1340                  Select the DS1340 device

        ds3231                  Select the DS3231 device

        m41t62                  Select the M41T62 device

        mcp7940x                Select the MCP7940x device

        mcp7941x                Select the MCP7941x device

        pcf2127                 Select the PCF2127 device

        pcf2129                 Select the PCF2129 device

        pcf85063                Select the PCF85063 device

        pcf85063a               Select the PCF85063A device

        pcf8523                 Select the PCF8523 device

        pcf85363                Select the PCF85363 device

        pcf8563                 Select the PCF8563 device

        rv1805                  Select the Micro Crystal RV1805 device

        rv3028                  Select the Micro Crystal RV3028 device

        rv8803                  Select the Micro Crystal RV8803 device

        sd3078                  Select the ZXW Shenzhen whwave SD3078 device

        s35390a                 Select the ABLIC S35390A device

        i2c0                    Choose the I2C0 bus on GPIOs 0&1

        i2c_csi_dsi             Choose the I2C0 bus on GPIOs 44&45

        i2c3                    Choose the I2C3 bus (configure with the i2c3
                                overlay - BCM2711 only)

        i2c4                    Choose the I2C3 bus (configure with the i2c3
                                overlay - BCM2711 only)

        i2c5                    Choose the I2C5 bus (configure with the i2c4
                                overlay - BCM2711 only)

        i2c6                    Choose the I2C6 bus (configure with the i2c6
                                overlay - BCM2711 only)

        addr                    Sets the address for the RTC. Note that the
                                device must be configured to use the specified
                                address.

        trickle-diode-disable   Do not use the internal trickle charger diode
                                (BQ32000 only)

        trickle-diode-type      Diode type for trickle charge - "standard" or
                                "schottky" (ABx80x and RV1805 only)

        trickle-resistor-ohms   Resistor value for trickle charge (DS1339,
                                ABx80x, RV1805, RV3028)

        wakeup-source           Specify that the RTC can be used as a wakeup
                                source

        backup-switchover-mode  Backup power supply switch mode. Must be 0 for
                                off or 1 for Vdd < VBackup (RV3028 only)
If you want the RTC on generic GPIOs with a bit-bashed I2C interface, then i2c-rtc-gpio is almost the same as i2c-rtc, but adds

Code: Select all

        i2c_gpio_sda            GPIO used for I2C data (default "23")

        i2c_gpio_scl            GPIO used for I2C clock (default "24")

        i2c_gpio_delay_us       Clock delay in microseconds
                                (default "2" = ~100kHz)
to allow you to define which GPIOs and at what speed.

There isn't an equivalent GPIO based I2C overlay for i2c-fan at present.
Thank you for reply to my post @6by9

Now, I have another issue, the system doesn't control the fan (i.e. fan still running at the same speed, doesn't stop or change speed)
My config file content:

dtparam=i2c_vc=on
dtparam=i2c_arm=on

dtoverlay=i2c-rtc,pcf85063a,i2c_csi_dsi
dtoverlay=i2c-fan,emc2301,i2c_csi_dsi
dtoverlay=i2c-fan,minpwm=0,maxpwm=255,midtemp=60000,maxtemp=70000,midtemp_hyst=55000

What is the error or missing config data ?

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

Re: How to use PCF85063AT with CM4 ?

Wed Jul 27, 2022 2:08 pm

Code: Select all

dtoverlay=i2c-rtc,pcf85063a,i2c_csi_dsi
dtoverlay=i2c-fan,emc2301,i2c_csi_dsi
dtparam=minpwm=0,maxpwm=255,midtemp=60000,maxtemp=70000,midtemp_hyst=55000 
A new dtoverlay line applies the previous overlay and starts a new one. dtparam amends the overlay currently in scope.
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 “Compute Module”