Help, please, with getting a custom I2C real time clock module to load

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Help, please, with getting a custom I2C real time clock module to load

Lee D
Hi Everyone,

I have written a new I2C driver (for the Xilinx Zynq) and a new real
time clock chip driver (for the ST M41T82) to use with hardware on my
custom board.  This is for 11.0.1.

The I2C driver works fine, but I can't seem to get my RTC driver to
load.  The m41t82_probe() function is never even called.

Both are loaded with kldload at the moment.

I think the problem is something in DRIVER_MODULE macro that is
preventing the kernel from even trying to let it probe.  One clue is
that if I change "iicbus" to "simplebus" in the DRIVER_MODULE macro
of the RTC, it will then at least call m41t82_probe().

It's like the kernel thinks that I have no iicbus driver and thus
won't even try to load the RTC module.

I have turned on "device iic" and "device iicbus" in my kernel config
file.

No messages are given when I try to load the m41t82 module.  It just
silently loads and does nothing.

Here is a code snippet from my I2C driver:
------------------------------------------

static driver_t i2c_driver = {
  "i2c",
  i2c_methods,
  sizeof(struct i2c_softc),
};
static devclass_t  i2c_devclass;

DRIVER_MODULE(iicbus, i2c, iicbus_driver, iicbus_devclass, 0, 0);
DRIVER_MODULE(i2c, simplebus, i2c_driver, i2c_devclass, 0, 0);

And here is a code snippet from my RTC driver:
----------------------------------------------

static device_method_t m41t82_methods[] = {
  DEVMETHOD(device_probe,         m41t82_probe),
  DEVMETHOD(device_attach,        m41t82_attach),
  DEVMETHOD(device_detach,        m41t82_detach),

  DEVMETHOD(clock_gettime,        m41t82_gettime),
  DEVMETHOD(clock_settime,        m41t82_settime),

  DEVMETHOD_END
};

static driver_t m41t82_driver = {
  "m41t82",
  m41t82_methods,
  sizeof(struct m41t82_softc),
};

static devclass_t m41t82_devclass;

DRIVER_MODULE(m41t82, iicbus, m41t82_driver, m41t82_devclass, NULL, NULL);
MODULE_VERSION(m41t82, 1);
MODULE_DEPEND(m41t82, iicbus, 1, 1, 1);

This is the relevant portion of my DTS file:
--------------------------------------------

  ps7io@e0000000 {
    device_type = "soc";
    compatible = "simple-bus";
    #address-cells = <0x1>;
    #size-cells = <0x1>;
    ranges = <0x0 0xe0000000 0x300000>;

    ... Other hardware ...

    i2c@4000 {
      compatible = "xlnx,zy7_i2c";
      status = "okay";
      reg = <0x4000 0x1000>;
      #address-cells = <0x1>;
      #size-cells = <0x0>;

      rtc@d0 {
        status = "okay";
        compatible = "st,m41t82";
        reg = <0xd0>;
      };

    };
 };

Any clues about how to go about debugging this problem would be very
helpful.

Thanks,

Lee
_______________________________________________
[hidden email] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[hidden email]"
Reply | Threaded
Open this post in threaded view
|

Re: Help, please, with getting a custom I2C real time clock module to load

Ian Lepore-3
On Sun, 2018-02-25 at 09:48 -0500, Lee D wrote:

> Hi Everyone,
>
> I have written a new I2C driver (for the Xilinx Zynq) and a new real
> time clock chip driver (for the ST M41T82) to use with hardware on my
> custom board.  This is for 11.0.1.
>
> The I2C driver works fine, but I can't seem to get my RTC driver to
> load.  The m41t82_probe() function is never even called.
>
> Both are loaded with kldload at the moment.
>
> I think the problem is something in DRIVER_MODULE macro that is
> preventing the kernel from even trying to let it probe.  One clue is
> that if I change "iicbus" to "simplebus" in the DRIVER_MODULE macro
> of the RTC, it will then at least call m41t82_probe().
>
> It's like the kernel thinks that I have no iicbus driver and thus
> won't even try to load the RTC module.
>
> I have turned on "device iic" and "device iicbus" in my kernel config
> file.
>
> No messages are given when I try to load the m41t82 module.  It just
> silently loads and does nothing.
>
> Here is a code snippet from my I2C driver:
> ------------------------------------------
>
> static driver_t i2c_driver = {
>   "i2c",
>   i2c_methods,
>   sizeof(struct i2c_softc),
> };
> static devclass_t  i2c_devclass;
>
> DRIVER_MODULE(iicbus, i2c, iicbus_driver, iicbus_devclass, 0, 0);
> DRIVER_MODULE(i2c, simplebus, i2c_driver, i2c_devclass, 0, 0);
>

Right here is where the disconnect is happening.  It's the ofw_iicbus
driver that needs to declared in the first DRIVER_MODULE() instead of
iicbus, because ofw_iicbus is the one that knows to look in the fdt
data for slave devices and add them as children of the bus.  But, the
extern declarations needed to do that didn't exist until I added them
last week in r329526.

What i2c drivers have been doing in the past, and the way to work
around it in the 11.x code you're dealing with, is to leverage one of
the DRIVER_MODULE() declarations that already exists in ofw_iicbus, by
naming your driver "iichb" instead of "i2c".  Like this:

    static driver_t i2c_driver = {
      "iichb",
      i2c_methods,
      sizeof(struct i2c_softc),
    };

Or you could import r329526 into the kernel source you're using and
rebuild the kernel.  I do intend to MFC that change to 11-stable (in
fact, I should probably do that today).

When you've got these new drivers working, please consider putting them
up for review at https://reviews.freebsd.org and we'll get them
committed to freebsd.

-- Ian

_______________________________________________
[hidden email] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[hidden email]"
Reply | Threaded
Open this post in threaded view
|

Re: Help, please, with getting a custom I2C real time clock module to load

Gary Jennejohn-6
In reply to this post by Lee D
On Sun, 25 Feb 2018 09:48:58 -0500
Lee D <[hidden email]> wrote:

> Hi Everyone,
>
> I have written a new I2C driver (for the Xilinx Zynq) and a new real
> time clock chip driver (for the ST M41T82) to use with hardware on my
> custom board.  This is for 11.0.1.
>
> The I2C driver works fine, but I can't seem to get my RTC driver to
> load.  The m41t82_probe() function is never even called.
>
> Both are loaded with kldload at the moment.
>
> I think the problem is something in DRIVER_MODULE macro that is
> preventing the kernel from even trying to let it probe.  One clue is
> that if I change "iicbus" to "simplebus" in the DRIVER_MODULE macro
> of the RTC, it will then at least call m41t82_probe().
>
> It's like the kernel thinks that I have no iicbus driver and thus
> won't even try to load the RTC module.
>
> I have turned on "device iic" and "device iicbus" in my kernel config
> file.
>
> No messages are given when I try to load the m41t82 module.  It just
> silently loads and does nothing.
>
> Here is a code snippet from my I2C driver:
> ------------------------------------------
>
> static driver_t i2c_driver = {
>   "i2c",
>   i2c_methods,
>   sizeof(struct i2c_softc),
> };
> static devclass_t  i2c_devclass;
>
> DRIVER_MODULE(iicbus, i2c, iicbus_driver, iicbus_devclass, 0, 0);
> DRIVER_MODULE(i2c, simplebus, i2c_driver, i2c_devclass, 0, 0);
>

This should give you a clue:

grep DRIVER_MODULE /sys/dev/iicbus/iic.c
DRIVER_MODULE(iic, iicbus, iic_driver, iic_devclass, 0, 0);

grep DRIVER_MODULE /sys/dev/iicbus/rtc8583.c
DRIVER_MODULE(rtc8583, iicbus, rtc8583_driver, rtc8583_devclass, NULL, NULL);

[snip]

--
Gary Jennejohn
_______________________________________________
[hidden email] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[hidden email]"
Reply | Threaded
Open this post in threaded view
|

Re: Help, please, with getting a custom I2C real time clock module to load

Ian Lepore-3
On Sun, 2018-02-25 at 18:42 +0100, Gary Jennejohn wrote:

> On Sun, 25 Feb 2018 09:48:58 -0500
> Lee D <[hidden email]> wrote:
>
> >
> > Hi Everyone,
> >
> > I have written a new I2C driver (for the Xilinx Zynq) and a new real
> > time clock chip driver (for the ST M41T82) to use with hardware on my
> > custom board.  This is for 11.0.1.
> >
> > The I2C driver works fine, but I can't seem to get my RTC driver to
> > load.  The m41t82_probe() function is never even called.
> >
> > Both are loaded with kldload at the moment.
> >
> > I think the problem is something in DRIVER_MODULE macro that is
> > preventing the kernel from even trying to let it probe.  One clue is
> > that if I change "iicbus" to "simplebus" in the DRIVER_MODULE macro
> > of the RTC, it will then at least call m41t82_probe().
> >
> > It's like the kernel thinks that I have no iicbus driver and thus
> > won't even try to load the RTC module.
> >
> > I have turned on "device iic" and "device iicbus" in my kernel config
> > file.
> >
> > No messages are given when I try to load the m41t82 module.  It just
> > silently loads and does nothing.
> >
> > Here is a code snippet from my I2C driver:
> > ------------------------------------------
> >
> > static driver_t i2c_driver = {
> >   "i2c",
> >   i2c_methods,
> >   sizeof(struct i2c_softc),
> > };
> > static devclass_t  i2c_devclass;
> >
> > DRIVER_MODULE(iicbus, i2c, iicbus_driver, iicbus_devclass, 0, 0);
> > DRIVER_MODULE(i2c, simplebus, i2c_driver, i2c_devclass, 0, 0);
> >
> This should give you a clue:
>
> grep DRIVER_MODULE /sys/dev/iicbus/iic.c
> DRIVER_MODULE(iic, iicbus, iic_driver, iic_devclass, 0, 0);
>

Nope, not applicable.  Lee's problem was due to not getting ofw_iicbus
connected to his new host controller driver so that the children of
iicbus would get enumerated.  iic.c is not an i2c host controller whose
child is an iicbus, it is itself a child of iicbus.

The real problem is that until last week it was impossible for an FDT-
based host controller driver to have the proper DRIVER_MODULE()
statement because some extern declarations were missing, and the way
existing drivers had been working around that was to set their name to
"iichb".

-- Ian

> grep DRIVER_MODULE /sys/dev/iicbus/rtc8583.c
> DRIVER_MODULE(rtc8583, iicbus, rtc8583_driver, rtc8583_devclass, NULL, NULL);
>
> [snip]
>
_______________________________________________
[hidden email] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[hidden email]"
Reply | Threaded
Open this post in threaded view
|

Re: Help, please, with getting a custom I2C real time clock module to load

Ian Lepore-3
In reply to this post by Lee D
On Sun, 2018-02-25 at 09:48 -0500, Lee D wrote:
> Hi Everyone,
>
> I have written a new I2C driver (for the Xilinx Zynq) and a new real
> time clock chip driver (for the ST M41T82) to use with hardware on my
> custom board.  This is for 11.0.1.
> [...]

I just remembered... another piece of non-obvious magic that is
required to be an i2c host controller whose bus is managed by
ofw_iicbus is that your driver has to implement the ofw_bus_get_node
method.  The implementation is trivial, just grab the one out of
arm/freescale/imx/imx_i2c.c.

-- Ian

_______________________________________________
[hidden email] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[hidden email]"
Reply | Threaded
Open this post in threaded view
|

Re: Help, please, with getting a custom I2C real time clock module to load

Lee D
In reply to this post by Ian Lepore-3
On Sun, Feb 25, 2018 at 12:23 PM, Ian Lepore <[hidden email]> wrote:
> On Sun, 2018-02-25 at 09:48 -0500, Lee D wrote:
>> Hi Everyone,
>>
>> I have written a new I2C driver (for the Xilinx Zynq) and a new real
>> time clock chip driver (for the ST M41T82) to use with hardware on my
>> custom board.  This is for 11.0.1.

>
> Right here is where the disconnect is happening.  It's the ofw_iicbus
> driver that needs to declared in the first DRIVER_MODULE() instead of
> iicbus, because ofw_iicbus is the one that knows to look in the fdt
> data for slave devices and add them as children of the bus.  But, the
> extern declarations needed to do that didn't exist until I added them
> last week in r329526.
>
> What i2c drivers have been doing in the past, and the way to work
> around it in the 11.x code you're dealing with, is to leverage one of
> the DRIVER_MODULE() declarations that already exists in ofw_iicbus, by
> naming your driver "iichb" instead of "i2c".  Like this:
>
>     static driver_t i2c_driver = {
>       "iichb",
>       i2c_methods,
>       sizeof(struct i2c_softc),
>     };
>
> Or you could import r329526 into the kernel source you're using and
> rebuild the kernel.  I do intend to MFC that change to 11-stable (in
> fact, I should probably do that today).
>
> When you've got these new drivers working, please consider putting them
> up for review at https://reviews.freebsd.org and we'll get them
> committed to freebsd.
>
> -- Ian
>

Thanks so much for the advice, I was able to get the RTC driver to
load using the iichb trick.  I would be happy to contribute the code
assuming I can get it to work.   I will probably move to 11.1 in the
near future.

Lee
_______________________________________________
[hidden email] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[hidden email]"