External RTC (MCP79400) Not Registering on i.MX6 Solo X on Linux

cancel
Showing results for 
Search instead for 
Did you mean: 

External RTC (MCP79400) Not Registering on i.MX6 Solo X on Linux

Jump to solution
1,072 Views
Contributor III

Greetings!

I am trying to implement an external RTC module via i2c3 onto a board with a Solo X chip with a yocto Linux OS (v4.14.98). I'm unable to see this device being registered and the hw clock is not found.

I've followed this thread P1010 & I2C RTC DS1339  and implemented all the drivers mentioned, however, I feel this might be different now since this a 6 year old post. Please see my .config file attached.

My device tree changes are as follows:

&snvs_pwrkey {
    status = "disabled";
};

 &i2c3 {
     clock-frequency = <100000>;
     pinctrl-names = "default";
     pinctrl-0 = <&pinctrl_i2c3>;
     status = "okay";

    rtc@68 {
        compatible = "microchip,mcp7940x";
        reg = <0x68>;
    };
 };

I've disabled the snvs (internal rtc) to only enable the external rtc. The issue still persists when I don't disable the snvs.

I did notice on my defconfig I manually entered in CONFIG_I2C_MPC=y and it does not show up in .config file. I wasn't able to enable I2C_MPC via menuconfig, there wasn't a selection for it. (The .config file I retrieved from /linux-imx/4.14.98-r0/build/, is this correct?)

Please see my attachments for the my config and kernel print out from boot.

Thanks.

Labels (4)
0 Kudos
1 Solution
416 Views
Contributor III

I've found the issue. For some reason the addressing to this device is 0x6F. If you look at the output of my i2c detect tool it shows it communicates with 0x6F address!

root@imx6sx-miltouch:~# i2cdetect -y 2
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 6f

I changed the address to 6F for the rtc in the device tree and it worked. I guess the MCP data sheet is wrong or there was a program error for this specific device.

I appreciate all your help Weidong.

Thank you,

Jon

View solution in original post

0 Kudos
14 Replies
416 Views
Contributor III

One issue I think might be more crucial than I thought, like I mentioned briefly about I2C_MPC driver, is that menuconfig is not allowing me to enable I2C_MPC. It shows up on search but when I select it on search, it doesn't go to the node to enable/disable. Please see pics below:

  Searching:

pastedImage_1.png

After I press 1:

pastedImage_2.png

It doesn't allow me to enable the I2C_MPC driver. How do I fix this?

EDIT: I believe this driver is for PowerPC and not the ARM A9 which is why I can't (and shouldn't need to) enable it.

0 Kudos
416 Views
NXP TechSupport
NXP TechSupport

Hi, Jon,

  I don't know why you want to enable I2C_MPC .

  I checked our linux bsp source code, the driver of your rtc is rtc-ds1307.c, which is in drivers/rtc. below is what I found.

---

./rtc-ds1307.c:259:    { "mcp7940x", mcp794xx },
./rtc-ds1307.c:320:        .compatible = "microchip,mcp7940x",

---

so you need these steps to add it to i.MX6SX:

1. try the configuration in device tree

(1) I2C3 IOMUX

confim your I2C3 pins IOMUX are correct in device tree.

(2) Adding i2c device node

 &i2c3 {
     clock-frequency = <100000>;
     pinctrl-names = "default";
     pinctrl-0 = <&pinctrl_i2c3>;
     status = "okay";

 

   rtc: rtc@68 {
        compatible = "microchip,mcp7940x";
        reg = <0x68>;
    };
 };

2. In linux kernel

you only select RTC_DRV_DS1307, see the Kconfig file in the path drivers/rtc

After compiling kernel, checking if rtc-ds1307.c is compiled.

3.  compiling kernel and program it to Flash on board.

4. boot your board, and check if booting log can show you rtc messages.

Hope above information is helpful for you.

Have a nice day!

B.R,

Weidong

0 Kudos
416 Views
Contributor III

Hi Weidong,

Thanks for your quick reply.

I've successfully executed the steps you provided. However, the problem still persists.

The specific output I get in dmesg for rtc is this:

root@imx6sx-miltouch:~# dmesg | grep rtc
rtc-ds1307 2-0068: read error -6
hctosys: unable to open rtc device (rtc0)

-6 is a device not found error yet the hardware is implemented. Are there any other steps I can take for software?

I've attached my output and config file, please review them.

Thanks.

0 Kudos
416 Views
NXP TechSupport
NXP TechSupport

Hi Jon,

   Add debug messages to the probe function of rtc-ds1307, please!

the purpose is to check if I2C3 enters rtc drivers.

then check if rtc device has been created /dev/rtc0.

Try it , please!

Have a nice day!

B.R,

Weidong

0 Kudos
416 Views
Contributor III

Hi Weidong,

The driver throws the -6 error on line 1541 of rtc-ds1307.c:

./rtc-ds1307.c:1536: read_rtc:
./rtc-ds1307.c:1537:     /* read RTC registers */
./rtc-ds1307.c:1538:     err = regmap_bulk_read(ds1307->regmap, chip->offset, regs,
./rtc-ds1307.c:1539:                    sizeof(regs));
./rtc-ds1307.c:1540:     if (err) {
./rtc-ds1307.c:1541:         dev_dbg(ds1307->dev, "read error %d\n", err);
./rtc-ds1307.c:1542:         goto exit;
./rtc-ds1307.c:1543:    }

Based on this error it can't find the device (errno-base.h):

#define ENXIO   6 /* No such device or address */

No rtc device was created:

root@imx6sx-miltouch:~# ls /dev/rtc0
ls: /dev/rtc0: No such file or directory

I tried probing the i2c3 device via i2cdetect and it was blank with no information. I tried i2cset to write to the device and it was unable to:

root@imx6sx-miltouch:~# i2cdetect -r 2
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-2 using receive byte commands.
I will probe address range 0x03-0x77.
Continue? [Y/n] y
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

root@imx6sx-miltouch:~# i2cset 2 0x68 0x07 0x03
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will write to device file /dev/i2c-2, chip address 0x68, data address
0x07, data 0x03, mode byte.
Continue? [Y/n] y
Error: Write failed

However I have the i2c3 device registered:

root@imx6sx-miltouch:/sys# cat ./devices/soc0/soc/2100000.aips-bus/21a8000.i2c/i2c-2/2-0068/name
mcp7940x

Let me know your thoughts

0 Kudos
416 Views
NXP TechSupport
NXP TechSupport

Hi Jon,

   Would you please show me your schematic here?

   I want to see I2C pins for RTC.

weidong

0 Kudos
416 Views
Contributor III

I attached the RTC circuit and the document of the chip side. This external RTC was a recent addon and isn't in the pdf schematic. Please let me know if this is fine.

Also, in my device tree i mapped SDA and SCL of i2c3 from the schematic as follows:

pinctrl_i2c3: i2c3grp {
   fsl,pins = <
      MX6SX_PAD_KEY_ROW4__I2C3_SDA 0x4001b8b1
      MX6SX_PAD_KEY_COL4__I2C3_SCL 0x4001b8b1
   >;
};

0 Kudos
416 Views
Contributor III

Hi Weidong,

I changed the RTC from register 68 to 57 and same problem:

root@imx6sx-miltouch:~# dmesg|grep rtc
rtc-ds1307 2-0057: read error -6
hctosys: unable to open rtc device (rtc0)

Also no information on i2c device:

root@imx6sx-miltouch:~# i2cdetect 2
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-2.
I will probe address range 0x03-0x77.
Continue? [Y/n] y
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 6f

Let me know your thoughts.

0 Kudos
416 Views
NXP TechSupport
NXP TechSupport

After you changed 0x68 to be 0x57, did it entered into rtc driver's probe?

weidong

0 Kudos
416 Views
Contributor III

Yes it entered the rtc-ds1307 device probe but it failed with -6 error, the same as 0x68.

0 Kudos
416 Views
NXP TechSupport
NXP TechSupport

Hi Jon,

   I checked probe function of rtc-ds1307.c, there is  a case branch like below:

.......

    case mcp794xx:
        /* make sure that the backup battery is enabled */
        if (!(regs[DS1307_REG_WDAY] & MCP794XX_BIT_VBATEN)) {
            regmap_write(ds1307->regmap, DS1307_REG_WDAY,
                     regs[DS1307_REG_WDAY] |
                     MCP794XX_BIT_VBATEN);
        }

        /* clock halted?  turn it on, so clock can tick. */
        if (!(tmp & MCP794XX_BIT_ST)) {
            regmap_write(ds1307->regmap, DS1307_REG_SECS,
                     MCP794XX_BIT_ST);
            dev_warn(ds1307->dev, "SET TIME!\n");
            goto read_rtc;
        }

.......

when you loaded the driver, the case branch should be run, BUT according to your debug messages, source code in the branch wasn't run.  so please check which branch did it enter into!

In addition, probably you should ask rtc provider if MCP79400's driver is rtc-ds1307.c, According to the result I searched driver's name, rtc-ds1307.c should support the rtc chip.

Weidong

0 Kudos
416 Views
Contributor III

Hi Weidong,

Thank you for hanging in there with me.

The driver doesn't get to the code block that you provided. It fails before that switch statement. The error check for the device read (regmap_bulk_read) is where the driver fails. I highlighted where the driver fails and outputs -6. Please see below:

read_rtc:
        /* read RTC registers */
        err = regmap_bulk_read(ds1307->regmap, chip->offset, regs,
                               sizeof(regs));
        if (err) {

                                 dev_dbg(ds1307->dev, "read error %d\n", err);

                goto exit;


        }

        /*
         * minimal sanity checking; some chips (like DS1340) don't
         * specify the extra bits as must-be-zero, but there are
         * still a few values that are clearly out-of-range.
         */
        tmp = regs[DS1307_REG_SECS];
        switch (ds1307->type) {
        case ds_1307:
        case m41t0:
        case m41t00:
                /* clock halted?  turn it on, so clock can tick. */
                if (tmp & DS1307_BIT_CH) {
                        regmap_write(ds1307->regmap, DS1307_REG_SECS, 0);
                        dev_warn(ds1307->dev, "SET TIME!\n");
                        goto read_rtc;
                }
            .
            .
            .
        case mcp794xx:
                /* make sure that the backup battery is enabled */
                if (!(regs[DS1307_REG_WDAY] & MCP794XX_BIT_VBATEN)) {
                        regmap_write(ds1307->regmap, DS1307_REG_WDAY,
                                     regs[DS1307_REG_WDAY] |
                                     MCP794XX_BIT_VBATEN);
                }

                /* clock halted?  turn it on, so clock can tick. */
                if (!(tmp & MCP794XX_BIT_ST)) {
                        regmap_write(ds1307->regmap, DS1307_REG_SECS,
                                     MCP794XX_BIT_ST);
                        dev_warn(ds1307->dev, "SET TIME!\n");
                        goto read_rtc;
                }

                break;
        default:
                break;

I've contacted the supplier but they have not replied back yet.

Thanks,

Jon

 

0 Kudos
417 Views
Contributor III

I've found the issue. For some reason the addressing to this device is 0x6F. If you look at the output of my i2c detect tool it shows it communicates with 0x6F address!

root@imx6sx-miltouch:~# i2cdetect -y 2
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 6f

I changed the address to 6F for the rtc in the device tree and it worked. I guess the MCP data sheet is wrong or there was a program error for this specific device.

I appreciate all your help Weidong.

Thank you,

Jon

View solution in original post

0 Kudos
416 Views
NXP TechSupport
NXP TechSupport

Hi Jon,

I checked schematic, and connections to RTC, no issue was found.

And I checked RTC datasheet.

See datasheet of MCP7940, it seems that I2C address is 0x57,  check it, please!

tpastedImage_1.png

Have a nice day!

B.R,

Weidong

0 Kudos