Discussion:
Need a clarification regarding I2C bus frequency in FreeBSD
Rajesh Kumar
2018-08-17 06:18:22 UTC
Permalink
Hi,

I am trying to use the I2C designware controller driver available in
FreeBSD (ig4_iic.c) in our boards.

Is there a clean way, I can set the I2C bus frequency from the controller
driver itself, rather than using device hints, FDT, tunables etc.,
Something like, if the driver is loaded for our boards (identified using
the PCI or ACPI ID's), then the frequency of the I2C bus needs to be
hardcoded from driver itself. This is to avoid additional configs from the
config file.

I tried adding a new interface "iicbus_set_frequency" (in line with
iicbus_get_frequency) and tried calling that from the ig4 driver after the
"iicbus" child is added. But, iicbus instance is created only after ig4
driver is loaded. So, calling iicbus_set_frequency after child addition
leads to system panic (as there is no iicbus softc at this point).

Let me know if you need any details.

Thanks,
Rajesh.
Ian Lepore
2018-08-17 16:26:56 UTC
Permalink
Post by Rajesh Kumar
Hi,
I am trying to use the I2C designware controller driver available in
FreeBSD (ig4_iic.c) in our boards.
Is there a clean way, I can set the I2C bus frequency from the controller
driver itself, rather than using device hints, FDT, tunables etc.,
Something like, if the driver is loaded for our boards (identified using
the PCI or ACPI ID's), then the frequency of the I2C bus needs to be
hardcoded from driver itself. This is to avoid additional configs from the
config file.
I tried adding a new interface "iicbus_set_frequency" (in line with
iicbus_get_frequency) and tried calling that from the ig4 driver after the
"iicbus" child is added.  But, iicbus instance is created only after ig4
driver is loaded. So, calling iicbus_set_frequency after child addition
leads to system panic (as there is no iicbus softc at this point).
Let me know if you need any details.
Thanks,
Rajesh.
I don't really understand what you're asking for. The ig4_iic
controller driver doesn't appear to support bus frequency settings at
all, it just loads hard-coded values into the clock high/low registers
and never changes them. If you want to locally modify the driver to run
at a different hard-coded speed for your application, just change lines
589-592 in ig4_iic.c and continue to ignore the speed set by the bus
driver when handling iicbus_reset.

-- Ian
Daniel Braniss
2018-08-19 10:11:15 UTC
Permalink
Post by Ian Lepore
Post by Rajesh Kumar
Hi,
I am trying to use the I2C designware controller driver available in
FreeBSD (ig4_iic.c) in our boards.
Is there a clean way, I can set the I2C bus frequency from the controller
driver itself, rather than using device hints, FDT, tunables etc.,
Something like, if the driver is loaded for our boards (identified using
the PCI or ACPI ID's), then the frequency of the I2C bus needs to be
hardcoded from driver itself. This is to avoid additional configs from the
config file.
I tried adding a new interface "iicbus_set_frequency" (in line with
iicbus_get_frequency) and tried calling that from the ig4 driver after the
"iicbus" child is added. But, iicbus instance is created only after ig4
driver is loaded. So, calling iicbus_set_frequency after child addition
leads to system panic (as there is no iicbus softc at this point).
Let me know if you need any details.
Thanks,
Rajesh.
I don't really understand what you're asking for. The ig4_iic
controller driver doesn't appear to support bus frequency settings at
all, it just loads hard-coded values into the clock high/low registers
and never changes them. If you want to locally modify the driver to run
at a different hard-coded speed for your application, just change lines
589-592 in ig4_iic.c and continue to ignore the speed set by the bus
driver when handling iicbus_reset.
on the arm/allwinner it’s set at 100Khz, and though there are sysctls to change it,
it’s ignored :-)

I could change this, but is there some hidden reason that it’s so?

danny
Emmanuel Vadot
2018-08-19 10:29:07 UTC
Permalink
On Sun, 19 Aug 2018 13:11:15 +0300
Post by Ian Lepore
Post by Rajesh Kumar
Hi,
I am trying to use the I2C designware controller driver available in
FreeBSD (ig4_iic.c) in our boards.
Is there a clean way, I can set the I2C bus frequency from the controller
driver itself, rather than using device hints, FDT, tunables etc.,
Something like, if the driver is loaded for our boards (identified using
the PCI or ACPI ID's), then the frequency of the I2C bus needs to be
hardcoded from driver itself. This is to avoid additional configs from the
config file.
I tried adding a new interface "iicbus_set_frequency" (in line with
iicbus_get_frequency) and tried calling that from the ig4 driver after the
"iicbus" child is added. But, iicbus instance is created only after ig4
driver is loaded. So, calling iicbus_set_frequency after child addition
leads to system panic (as there is no iicbus softc at this point).
Let me know if you need any details.
Thanks,
Rajesh.
I don't really understand what you're asking for. The ig4_iic
controller driver doesn't appear to support bus frequency settings at
all, it just loads hard-coded values into the clock high/low registers
and never changes them. If you want to locally modify the driver to run
at a different hard-coded speed for your application, just change lines
589-592 in ig4_iic.c and continue to ignore the speed set by the bus
driver when handling iicbus_reset.
on the arm/allwinner it?s set at 100Khz, and though there are sysctls to change it,
it?s ignored :-)
It is set at whatever frequency the dts set it and if there is no
frequency in the dts it fallback to 100Khz.
twsi needs to support IICBUS_GET_FREQUENCY though, the main reason I
never really touched twsi is because the same driver is used on Marvell
SoC with hackish support for the clocks. Now that I have a Marvell
board with this i2c controller I'll probably rewrite this driver.
I could change this, but is there some hidden reason that it?s so?
danny
_______________________________________________
https://lists.freebsd.org/mailman/listinfo/freebsd-hackers
--
Emmanuel Vadot <***@bidouilliste.com> <***@freebsd.org>
Rajesh Kumar
2018-08-19 13:57:44 UTC
Permalink
Hi Daniel/Emmanuel,

Basically, I want to set the I2C clock frequency for Designware IP in our
board to 150Mhz. So, I was looking for the way in FreeBSD.

Is this 100Khz in arm/allwinner is same as what I am trying to configure?
Or Is it something different?
Post by Emmanuel Vadot
On Sun, 19 Aug 2018 13:11:15 +0300
Post by Ian Lepore
Post by Rajesh Kumar
Hi,
I am trying to use the I2C designware controller driver available in
FreeBSD (ig4_iic.c) in our boards.
Is there a clean way, I can set the I2C bus frequency from the
controller
Post by Ian Lepore
Post by Rajesh Kumar
driver itself, rather than using device hints, FDT, tunables etc.,
Something like, if the driver is loaded for our boards (identified
using
Post by Ian Lepore
Post by Rajesh Kumar
the PCI or ACPI ID's), then the frequency of the I2C bus needs to be
hardcoded from driver itself. This is to avoid additional configs
from the
Post by Ian Lepore
Post by Rajesh Kumar
config file.
I tried adding a new interface "iicbus_set_frequency" (in line with
iicbus_get_frequency) and tried calling that from the ig4 driver
after the
Post by Ian Lepore
Post by Rajesh Kumar
"iicbus" child is added. But, iicbus instance is created only after
ig4
Post by Ian Lepore
Post by Rajesh Kumar
driver is loaded. So, calling iicbus_set_frequency after child
addition
Post by Ian Lepore
Post by Rajesh Kumar
leads to system panic (as there is no iicbus softc at this point).
Let me know if you need any details.
Thanks,
Rajesh.
I don't really understand what you're asking for. The ig4_iic
controller driver doesn't appear to support bus frequency settings at
all, it just loads hard-coded values into the clock high/low registers
and never changes them. If you want to locally modify the driver to run
at a different hard-coded speed for your application, just change lines
589-592 in ig4_iic.c and continue to ignore the speed set by the bus
driver when handling iicbus_reset.
on the arm/allwinner it?s set at 100Khz, and though there are sysctls to
change it,
it?s ignored :-)
It is set at whatever frequency the dts set it and if there is no
frequency in the dts it fallback to 100Khz.
twsi needs to support IICBUS_GET_FREQUENCY though, the main reason I
never really touched twsi is because the same driver is used on Marvell
SoC with hackish support for the clocks. Now that I have a Marvell
board with this i2c controller I'll probably rewrite this driver.
I could change this, but is there some hidden reason that it?s so?
danny
_______________________________________________
https://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "
--
Rajesh Kumar
2018-08-19 13:53:22 UTC
Permalink
Hi Ian,

Basically, I want to set the I2C clock frequency for Designware IP in our
board to 150Mhz. So, I was looking for the way in FreeBSD.

So, Is this the frequency which is configured through the clock high/low
registers? I see the those register are coded to 100 and 125 currently, I
am not sure how that value is arrived. If it needs to be configured for
150Mhz, how to derive the appropriate values? I looked at the DW_apb_i2c
databook section 3.11 to understand about it. I am still unclear. I see a
comment saying "Program based on 25000 Hz clock". In my case, should they
be programmed based on 150Mhz clock?
Post by Ian Lepore
Post by Rajesh Kumar
Hi,
I am trying to use the I2C designware controller driver available in
FreeBSD (ig4_iic.c) in our boards.
Is there a clean way, I can set the I2C bus frequency from the controller
driver itself, rather than using device hints, FDT, tunables etc.,
Something like, if the driver is loaded for our boards (identified using
the PCI or ACPI ID's), then the frequency of the I2C bus needs to be
hardcoded from driver itself. This is to avoid additional configs from
the
Post by Rajesh Kumar
config file.
I tried adding a new interface "iicbus_set_frequency" (in line with
iicbus_get_frequency) and tried calling that from the ig4 driver after
the
Post by Rajesh Kumar
"iicbus" child is added. But, iicbus instance is created only after ig4
driver is loaded. So, calling iicbus_set_frequency after child addition
leads to system panic (as there is no iicbus softc at this point).
Let me know if you need any details.
Thanks,
Rajesh.
I don't really understand what you're asking for. The ig4_iic
controller driver doesn't appear to support bus frequency settings at
all, it just loads hard-coded values into the clock high/low registers
and never changes them. If you want to locally modify the driver to run
at a different hard-coded speed for your application, just change lines
589-592 in ig4_iic.c and continue to ignore the speed set by the bus
driver when handling iicbus_reset.
-- Ian
Ian Lepore
2018-08-19 18:21:01 UTC
Permalink
Post by Rajesh Kumar
Hi Ian,
Basically, I want to set the I2C clock frequency for Designware IP in our
board to 150Mhz.  So, I was looking for the way in FreeBSD.
So, Is this the frequency which is configured through the clock high/low
registers? I see the those register are coded to 100 and 125 currently, I
am not sure how that value is arrived. If it needs to be configured for
150Mhz, how to derive the appropriate values? I looked at the DW_apb_i2c
databook section 3.11 to understand about it.  I am still unclear.  I see a
comment saying "Program based on 25000 Hz clock". In my case, should they
be programmed based on 150Mhz clock?
Rajesh,

Please bottom-post when replying on freebsd mailing lists, mixed top-
and bottom-posting is too confusing.

What exactly do you mean when you say "the i2c clock frequency"?

The datasheet appears to use a term like that to refer to the internal
clock used to drive the IP block in the chip. That base clock is then
divided down to create the i2c bus frequency on the I2C_SCL line.

The IG4_REG_SS_SCL_HCNT and IG4_REG_SS_SCL_LCNT registers are the
duration in base clock ticks that the SCL line is held high and low for
standard speed. The registers with FS in the name are for high speed
mode.

The comment block and the values our driver programs into those
registers appear to be wildly wrong. There is no way a base clock
running at 25KHz can be divided down to create i2c bus speeds of 100KHz
and 400KHz for standard and fast modes. If the base clock really is
25KHz then the driver currently sets the i2c bus to run at 111Hz.

The hardware default values for the HCNT/LCNT registers, as given in
the datasheet referenced by the driver [1], would be consistant with an
internal base clock speed of 1GHz. The fact that the header file
defines a IG4_REG_CLK_PARMS register, but the datasheet doesn't mention
it, makes me think that on some versions of the hardware the speed is
fixed and the driver has to know what that is based on the version, or
vendor, or something. Other versions of the hardware may have
information about the base clock speed in that IG4_REG_CLK_PARMS
register.

What we need is for someone who has this hardware to put an
oscilliscope on the SCL line and get us some real-world truth.

[1] http://www.intel.com/content/www/us/en/processors/core/4th-gen-core-family-mobile-i-o-datasheet.html?wapkw=datasheets+4th+generation

-- Ian
Daniel Braniss
2018-08-20 06:49:25 UTC
Permalink
Post by Ian Lepore
Post by Rajesh Kumar
Hi Ian,
Basically, I want to set the I2C clock frequency for Designware IP in our
board to 150Mhz. So, I was looking for the way in FreeBSD.
So, Is this the frequency which is configured through the clock high/low
registers? I see the those register are coded to 100 and 125 currently, I
am not sure how that value is arrived. If it needs to be configured for
150Mhz, how to derive the appropriate values? I looked at the DW_apb_i2c
databook section 3.11 to understand about it. I am still unclear. I see a
comment saying "Program based on 25000 Hz clock". In my case, should they
be programmed based on 150Mhz clock?
Rajesh,
Please bottom-post when replying on freebsd mailing lists, mixed top-
and bottom-posting is too confusing.
What exactly do you mean when you say "the i2c clock frequency"?
The datasheet appears to use a term like that to refer to the internal
clock used to drive the IP block in the chip. That base clock is then
divided down to create the i2c bus frequency on the I2C_SCL line.
The IG4_REG_SS_SCL_HCNT and IG4_REG_SS_SCL_LCNT registers are the
duration in base clock ticks that the SCL line is held high and low for
standard speed. The registers with FS in the name are for high speed
mode.
The comment block and the values our driver programs into those
registers appear to be wildly wrong. There is no way a base clock
running at 25KHz can be divided down to create i2c bus speeds of 100KHz
and 400KHz for standard and fast modes. If the base clock really is
25KHz then the driver currently sets the i2c bus to run at 111Hz.
The hardware default values for the HCNT/LCNT registers, as given in
the datasheet referenced by the driver [1], would be consistant with an
internal base clock speed of 1GHz. The fact that the header file
defines a IG4_REG_CLK_PARMS register, but the datasheet doesn't mention
it, makes me think that on some versions of the hardware the speed is
fixed and the driver has to know what that is based on the version, or
vendor, or something. Other versions of the hardware may have
information about the base clock speed in that IG4_REG_CLK_PARMS
register.
What we need is for someone who has this hardware to put an
oscilliscope on the SCL line and get us some real-world truth.
[1] http://www.intel.com/content/www/us/en/processors/core/4th-gen-core-family-mobile-i-o-datasheet.html?wapkw=datasheets+4th+generation <http://www.intel.com/content/www/us/en/processors/core/4th-gen-core-family-mobile-i-o-datasheet.html?wapkw=datasheets+4th+generation>
-- Ian
hi,
I have similar issues with the allwinner/twsi but I do have a Saleae Logic and here is a nice picture:



danny
Daniel Braniss
2018-08-20 08:13:08 UTC
Permalink
Post by Ian Lepore
Post by Rajesh Kumar
Hi Ian,
Basically, I want to set the I2C clock frequency for Designware IP in our
board to 150Mhz. So, I was looking for the way in FreeBSD.
So, Is this the frequency which is configured through the clock high/low
registers? I see the those register are coded to 100 and 125 currently, I
am not sure how that value is arrived. If it needs to be configured for
150Mhz, how to derive the appropriate values? I looked at the DW_apb_i2c
databook section 3.11 to understand about it. I am still unclear. I see a
comment saying "Program based on 25000 Hz clock". In my case, should they
be programmed based on 150Mhz clock?
Rajesh,
Please bottom-post when replying on freebsd mailing lists, mixed top-
and bottom-posting is too confusing.
What exactly do you mean when you say "the i2c clock frequency"?
The datasheet appears to use a term like that to refer to the internal
clock used to drive the IP block in the chip. That base clock is then
divided down to create the i2c bus frequency on the I2C_SCL line.
The IG4_REG_SS_SCL_HCNT and IG4_REG_SS_SCL_LCNT registers are the
duration in base clock ticks that the SCL line is held high and low for
standard speed. The registers with FS in the name are for high speed
mode.
The comment block and the values our driver programs into those
registers appear to be wildly wrong. There is no way a base clock
running at 25KHz can be divided down to create i2c bus speeds of 100KHz
and 400KHz for standard and fast modes. If the base clock really is
25KHz then the driver currently sets the i2c bus to run at 111Hz.
The hardware default values for the HCNT/LCNT registers, as given in
the datasheet referenced by the driver [1], would be consistant with an
internal base clock speed of 1GHz. The fact that the header file
defines a IG4_REG_CLK_PARMS register, but the datasheet doesn't mention
it, makes me think that on some versions of the hardware the speed is
fixed and the driver has to know what that is based on the version, or
vendor, or something. Other versions of the hardware may have
information about the base clock speed in that IG4_REG_CLK_PARMS
register.
What we need is for someone who has this hardware to put an
oscilliscope on the SCL line and get us some real-world truth.
[1] http://www.intel.com/content/www/us/en/processors/core/4th-gen-core-family-mobile-i-o-datasheet.html?wapkw=datasheets+4th+generation <http://www.intel.com/content/www/us/en/processors/core/4th-gen-core-family-mobile-i-o-datasheet.html?wapkw=datasheets+4th+generation><http://www.intel.com/content/www/us/en/processors/core/4th-gen-core-family-mobile-i-o-datasheet.html?wapkw=datasheets+4th+generation <http://www.intel.com/content/www/us/en/processors/core/4th-gen-core-family-mobile-i-o-datasheet.html?wapkw=datasheets+4th+generation>>
-- Ian
hi,
ah, maybe this is better:
Loading Image...
danny
_______________________________________________
https://lists.freebsd.org/mailman/listinfo/freebsd-hackers <https://lists.freebsd.org/mailman/listinfo/freebsd-hackers>
Rajesh Kumar
2018-08-20 09:36:26 UTC
Permalink
Hi Ian/Daniel,

Sorry about the mixed-posting.

By "i2c clock frequency", I mean the internal base frequency only, which
drives the chip. I thought data will be transferred on bus based on the
base frequency. So, thought both bus and base frequency are same. But from
what you said, seems both are different. So, based on the setting in
*_HCNT/LCNT register, the bus frequency (which is the rate at which data is
transferred) will change for a particular base frequency. Is that right?

So, few questions here

1) As you said, we need to have a base frequency of 150 Mhz in our case.
So, do we need to program that IG4_REG_CLK_PARMS to 150 Mhz (0x8F0D180)?
And can this be done at the same time when programming the HCNT/LNCT
registers?
2) Not sure how that 111Hz value is arrived. Can you please explain this
calculation. So, that I can derive the appropriate values for HCNT/LCNT for
different speeds at 150Mhz base clock.
3) "Default HCNT/LCNT register values would be consistent with an internal
base clock speed of 1GHz", Does it mean with those values, all speeds can
be achieved until 1GHz clock?
4) I am quite unfamiliar with the oscilloscope outputs. So, it would be
good if you give some idea about what is shown in that pic?
Post by Rajesh Kumar
Hi Ian,
Basically, I want to set the I2C clock frequency for Designware IP in our
board to 150Mhz. So, I was looking for the way in FreeBSD.
So, Is this the frequency which is configured through the clock high/low
registers? I see the those register are coded to 100 and 125 currently, I
am not sure how that value is arrived. If it needs to be configured for
150Mhz, how to derive the appropriate values? I looked at the DW_apb_i2c
databook section 3.11 to understand about it. I am still unclear. I see a
comment saying "Program based on 25000 Hz clock". In my case, should they
be programmed based on 150Mhz clock?
Rajesh,
Please bottom-post when replying on freebsd mailing lists, mixed top-
and bottom-posting is too confusing.
What exactly do you mean when you say "the i2c clock frequency"?
The datasheet appears to use a term like that to refer to the internal
clock used to drive the IP block in the chip. That base clock is then
divided down to create the i2c bus frequency on the I2C_SCL line.
The IG4_REG_SS_SCL_HCNT and IG4_REG_SS_SCL_LCNT registers are the
duration in base clock ticks that the SCL line is held high and low for
standard speed. The registers with FS in the name are for high speed
mode.
The comment block and the values our driver programs into those
registers appear to be wildly wrong. There is no way a base clock
running at 25KHz can be divided down to create i2c bus speeds of 100KHz
and 400KHz for standard and fast modes. If the base clock really is
25KHz then the driver currently sets the i2c bus to run at 111Hz.
The hardware default values for the HCNT/LCNT registers, as given in
the datasheet referenced by the driver [1], would be consistant with an
internal base clock speed of 1GHz. The fact that the header file
defines a IG4_REG_CLK_PARMS register, but the datasheet doesn't mention
it, makes me think that on some versions of the hardware the speed is
fixed and the driver has to know what that is based on the version, or
vendor, or something. Other versions of the hardware may have
information about the base clock speed in that IG4_REG_CLK_PARMS
register.
What we need is for someone who has this hardware to put an
oscilliscope on the SCL line and get us some real-world truth.
[1]
http://www.intel.com/content/www/us/en/processors/core/4th-gen-core-family-mobile-i-o-datasheet.html?wapkw=datasheets+4th+generation
<
http://www.intel.com/content/www/us/en/processors/core/4th-gen-core-family-mobile-i-o-datasheet.html?wapkw=datasheets+4th+generation
-- Ian
hi,
I have similar issues with the allwinner/twsi but I do have a Saleae Logic
https://cs.huji.ac.il/~danny/Screen%20Shot%202018-08-20%20at%2011.06.43.png
danny
_______________________________________________
https://lists.freebsd.org/mailman/listinfo/freebsd-hackers
Ian Lepore
2018-08-20 13:18:15 UTC
Permalink
Post by Daniel Braniss
Post by Ian Lepore
Post by Rajesh Kumar
Hi Ian,
Basically, I want to set the I2C clock frequency for Designware IP in our
board to 150Mhz.  So, I was looking for the way in FreeBSD.
So, Is this the frequency which is configured through the clock high/low
registers? I see the those register are coded to 100 and 125 currently, I
am not sure how that value is arrived. If it needs to be configured for
150Mhz, how to derive the appropriate values? I looked at the DW_apb_i2c
databook section 3.11 to understand about it.  I am still unclear.  I see a
comment saying "Program based on 25000 Hz clock". In my case, should they
be programmed based on 150Mhz clock?
Rajesh,
Please bottom-post when replying on freebsd mailing lists, mixed top-
and bottom-posting is too confusing.
What exactly do you mean when you say "the i2c clock frequency"?
The datasheet appears to use a term like that to refer to the internal
clock used to drive the IP block in the chip. That base clock is then
divided down to create the i2c bus frequency on the I2C_SCL line.
The IG4_REG_SS_SCL_HCNT and IG4_REG_SS_SCL_LCNT registers are the
duration in base clock ticks that the SCL line is held high and low for
standard speed. The registers with FS in the name are for high speed
mode.
The comment block and the values our driver programs into those
registers appear to be wildly wrong. There is no way a base clock
running at 25KHz can be divided down to create i2c bus speeds of 100KHz
and 400KHz for standard and fast modes. If the base clock really is
25KHz then the driver currently sets the i2c bus to run at 111Hz.
The hardware default values for the HCNT/LCNT registers, as given in
the datasheet referenced by the driver [1], would be consistant with an
internal base clock speed of 1GHz. The fact that the header file
defines a IG4_REG_CLK_PARMS register, but the datasheet doesn't mention
it, makes me think that on some versions of the hardware the speed is
fixed and the driver has to know what that is based on the version, or
vendor, or something. Other versions of the hardware may have
information about the base clock speed in that IG4_REG_CLK_PARMS
register.
What we need is for someone who has this hardware to put an
oscilliscope on the SCL line and get us some real-world truth.
[1] http://www.intel.com/content/www/us/en/processors/core/4th-gen-core-family-mobile-i-o-datasheet.html?wapkw=datasheets+4th+generation >
-- Ian
hi,
https://cs.huji.ac.il/~danny/Screen%20Shot%202018-08-20%20at%2011.06.43.png
danny
This has nothing to do with the twsi driver, this is about the ig4
driver (found in sys/dev/ichiic).

That screenshot seems to show a bus running at 100KHz like it should
(although the 62:38 duty cycle is a bit suspicious).

-- Ian
Mark Millard via freebsd-hackers
2018-08-20 14:16:15 UTC
Permalink
Post by Ian Lepore
Post by Daniel Braniss
. . .
hi,
https://cs.huji.ac.il/~danny/Screen%20Shot%202018-08-20%20at%2011.06.43.png
. . .
This has nothing to do with the twsi driver, this is about the ig4
driver (found in sys/dev/ichiic).
That screenshot seems to show a bus running at 100KHz like it should
(although the 62:38 duty cycle is a bit suspicious).
Being a logic analyzer display, it my just be that the threshold
was off from the optimal value. The waveform shape is not really
visible.

The logic analyzer output also shows a thick "rising" edge without the
uparrow symbol. My guess would be that is a rising/falling/rising
sequence that on the scale in use does not show space between edges. In
other words: a glitch on the leading edge side of the intended pulse.
This too might be tied to the threshold used vs . the actual signal
properties: no way to tell from what is shown.

===
Mark Millard
marklmi at yahoo.com
( dsl-only.net went
away in early 2018-Mar)
Mark Millard via freebsd-hackers
2018-08-20 16:00:17 UTC
Permalink
[Resend to (just the list) from the right account.]
Post by Ian Lepore
Post by Daniel Braniss
. . .
hi,
https://cs.huji.ac.il/~danny/Screen%20Shot%202018-08-20%20at%2011.06.43.png
. . .
This has nothing to do with the twsi driver, this is about the ig4
driver (found in sys/dev/ichiic).
That screenshot seems to show a bus running at 100KHz like it should
(although the 62:38 duty cycle is a bit suspicious).
Being a logic analyzer display, it my just be that the threshold
was off from the optimal value. The waveform shape is not really
visible.

The logic analyzer output also shows a thick "rising" edge without the
uparrow symbol. My guess would be that is a rising/falling/rising
sequence that on the scale in use does not show space between edges. In
other words: a glitch on the leading edge side of the intended pulse.
This too might be tied to the threshold used vs . the actual signal
properties: no way to tell from what is shown.



===
Mark Millard
marklmi at yahoo.com
( dsl-only.net went
away in early 2018-Mar)
Gary Jennejohn
2018-08-20 16:13:22 UTC
Permalink
On Mon, 20 Aug 2018 07:16:15 -0700
Post by Mark Millard via freebsd-hackers
Post by Ian Lepore
Post by Daniel Braniss
. . .
hi,
https://cs.huji.ac.il/~danny/Screen%20Shot%202018-08-20%20at%2011.06.43.png
. . .
This has nothing to do with the twsi driver, this is about the ig4
driver (found in sys/dev/ichiic).
That screenshot seems to show a bus running at 100KHz like it should
(although the 62:38 duty cycle is a bit suspicious).
Being a logic analyzer display, it my just be that the threshold
was off from the optimal value. The waveform shape is not really
visible.
The logic analyzer output also shows a thick "rising" edge without the
uparrow symbol. My guess would be that is a rising/falling/rising
sequence that on the scale in use does not show space between edges. In
other words: a glitch on the leading edge side of the intended pulse.
This too might be tied to the threshold used vs . the actual signal
properties: no way to tell from what is shown.
I have two of these logic analyzers and they definitely do a
major clean up of the signals displayed.

Things like overshoot and ringing, which can be seen on an
oscilloscope, do not appear on what the logic analyzer displays.

I suspect the purpose of the trace was simply to show the 100KHz
SCL.
--
Gary Jennejohn
Rajesh Kumar
2018-08-20 17:55:33 UTC
Permalink
Hi,

Re-posting the questions, just in case if its missed in other conversation.

By "i2c clock frequency", I mean the internal base frequency only, which
drives the chip. I thought data will be transferred on bus based on the
base frequency. So, thought both bus and base frequency are same. But from
what you said, seems both are different. So, based on the setting in
*_HCNT/LCNT register, the bus frequency (which is the rate at which data is
transferred) will change for a particular base frequency. Is that right?

So, few questions here

1) As you said, we need to have a base frequency of 150 Mhz in our case.
So, do we need to program that IG4_REG_CLK_PARMS to 150 Mhz (0x8F0D180)?
And can this be done at the same time when programming the HCNT/LNCT
registers?
2) Not sure how that 111Hz value is arrived. Can you please explain this
calculation. So, that I can derive the appropriate values for HCNT/LCNT for
different speeds at 150Mhz base clock.
3) "Default HCNT/LCNT register values would be consistent with an internal
base clock speed of 1GHz", Does it mean with those values, all speeds can
be achieved until 1GHz clock?
Post by Gary Jennejohn
On Mon, 20 Aug 2018 07:16:15 -0700
Post by Mark Millard via freebsd-hackers
Post by Ian Lepore
Post by Daniel Braniss
. . .
hi,
I have similar issues with the allwinner/twsi but I do have a Saleae
https://cs.huji.ac.il/~danny/Screen%20Shot%202018-08-20%20at%2011.06.43.png
Post by Mark Millard via freebsd-hackers
Post by Ian Lepore
. . .
This has nothing to do with the twsi driver, this is about the ig4
driver (found in sys/dev/ichiic).
That screenshot seems to show a bus running at 100KHz like it should
(although the 62:38 duty cycle is a bit suspicious).
Being a logic analyzer display, it my just be that the threshold
was off from the optimal value. The waveform shape is not really
visible.
The logic analyzer output also shows a thick "rising" edge without the
uparrow symbol. My guess would be that is a rising/falling/rising
sequence that on the scale in use does not show space between edges. In
other words: a glitch on the leading edge side of the intended pulse.
This too might be tied to the threshold used vs . the actual signal
properties: no way to tell from what is shown.
I have two of these logic analyzers and they definitely do a
major clean up of the signals displayed.
Things like overshoot and ringing, which can be seen on an
oscilloscope, do not appear on what the logic analyzer displays.
I suspect the purpose of the trace was simply to show the 100KHz
SCL.
--
Gary Jennejohn
Ian Lepore
2018-08-21 14:33:00 UTC
Permalink
Post by Rajesh Kumar
Hi,
Re-posting the questions, just in case if its missed in other conversation.
By "i2c clock frequency", I mean the internal base frequency only, which
drives the chip.  I thought data will be transferred on bus based on the
base frequency. So, thought both bus and base frequency are same. But from
what you said, seems both are different. So, based on the setting in
*_HCNT/LCNT register, the bus frequency (which is the rate at which data is
transferred) will change for a particular base frequency. Is that right?
So, few questions here
1)  As you said, we need to have a base frequency of 150 Mhz in our case.
So, do we need to program that IG4_REG_CLK_PARMS to 150 Mhz (0x8F0D180)?
And can this be done at the same time when programming the HCNT/LNCT
registers?
I don't have this hardware, and I don't have a datasheet that describes
the IG4_REG_CLK_PARMS register mentioned in the driver, so I don't
really have an answer. I suspect the hardware should set that register
with information that lets the driver know what the base clock speed
is. Using that information, the driver could calculate the proper
values for HCNT/LCNT.

Right now the driver lacks *any* support for changing bus speeds. That
will be easy to fix, once we figure out:

 1. What is in the IG4_REG_CLK_PARMS register?
 2. What do we do about versions of the hardware that don't support
that register? 
Post by Rajesh Kumar
2)  Not sure how that 111Hz value is arrived.  Can you please explain this
calculation. So, that I can derive the appropriate values for HCNT/LCNT for
different speeds at 150Mhz base clock.
It's based on the comment (which I feel certain must be wrong) that the
base clock is 25,000 Hz. With HCNT,LCNT set to 100,125, one cycle of
the SCL line will last 225 base clock cycles. 1/25000 = 0.000040, that
times 225 is 0.009 seconds per SCL cycle. 1/.009 = 111.111 Hz.

FWIW, an i2c bus will run fine at 111Hz, it'll just take forever to get
anything done. But I don't think the bus is really running at 111Hz,
because I don't think the base clock is really 25KHz, I think the
comment block is just wrong about all of that.
Post by Rajesh Kumar
3)  "Default HCNT/LCNT register values would be consistent with an internal
base clock speed of 1GHz",  Does it mean with those values, all speeds can
be achieved until 1GHz clock?
Well, the defaults I mentioned are from the datasheet cited in the
driver code. Those defaults made me think the base clock was 1GHz on
that particular hardware. I just realized that I was off by an order of
magnitude, I think I was mixing numbers from the driver and numbers
from the datasheet in my head.  The default HCNT,LCNT in that datasheet
are 612+706=1318 base cycles to give an SCL rate of 100KHz. So
1318*100000 is 131.8MHz, a very reasonable number.

In your world you want the 150MHz base clock to generate the 100Hz SCL,
so 150000000/100000 = 1500. My inclination would be to split that in
half and have HCNT,LCNT be 750,750, but for some reason there seems to
be a bias on this hardware for having HCNT be slightly longer than
LCNT, so maybe 775,725. Maybe that's an attempt to compensate for the
fact that high levels on the clock line are accomplished with a pullup
resistor, and it takes slightly longer for the line to "drift up" to a
high state via the pullup, compared to being driven low which would
happen quickly.

I would expect the default values of the HCNT/LCNT registers would be
right for any given hardware... whoever configures the IP block in a
SoC would configure the base clock value and the default HCNT/LCNT
values to match each other. Putting it that way makes me think that
maybe the right thing to do in the driver is just stop setting
HCNT/LCNT at all, and rely on the hardware to be configured correctly
by default. It's worth a try.

It would also be interesting to just print out those values. In the
driver on lines 571-575 the code reads all those registers and does
nothing with them. If you look in the dragonflybsd version of the
driver it printed out all those values after reading them; whoever
imported the driver to freebsd just deleted all the kprintf() lines and
left the register reads.

-- Ian
Gary Jennejohn
2018-08-21 15:16:26 UTC
Permalink
On Tue, 21 Aug 2018 08:33:00 -0600
Post by Ian Lepore
Post by Rajesh Kumar
Hi,
Re-posting the questions, just in case if its missed in other conversation.
By "i2c clock frequency", I mean the internal base frequency only, which
drives the chip.____I thought data will be transferred on bus based on the
base frequency. So, thought both bus and base frequency are same. But from
what you said, seems both are different. So, based on the setting in
*_HCNT/LCNT register, the bus frequency (which is the rate at which data is
transferred) will change for a particular base frequency. Is that right?
So, few questions here
1)____As you said, we need to have a base frequency of 150 Mhz in our case.
So, do we need to program that IG4_REG_CLK_PARMS to 150 Mhz (0x8F0D180)?
And can this be done at the same time when programming the HCNT/LNCT
registers?
I don't have this hardware, and I don't have a datasheet that describes
the__IG4_REG_CLK_PARMS register mentioned in the driver, so I don't
really have an answer. I suspect the hardware should set that register
with information that lets the driver know what the base clock speed
is. Using that information, the driver could calculate the proper
values for HCNT/LCNT.
Right now the driver lacks *any* support for changing bus speeds. That
__1. What is in the IG4_REG_CLK_PARMS register?
__2. What do we do about versions of the hardware that don't support
that register?__
Post by Rajesh Kumar
2)____Not sure how that 111Hz value is arrived.____Can you please explain this
calculation. So, that I can derive the appropriate values for HCNT/LCNT for
different speeds at 150Mhz base clock.
It's based on the comment (which I feel certain must be wrong) that the
base clock is 25,000 Hz. With HCNT,LCNT set to 100,125, one cycle of
the SCL line will last 225 base clock cycles. 1/25000 = 0.000040, that
times 225 is 0.009 seconds per SCL cycle. 1/.009 = 111.111 Hz.
FWIW, an i2c bus will run fine at 111Hz, it'll just take forever to get
anything done. But I don't think the bus is really running at 111Hz,
because I don't think the base clock is really 25KHz, I think the
comment block is just wrong about all of that.
Post by Rajesh Kumar
3)____"Default HCNT/LCNT register values would be consistent with an internal
base clock speed of 1GHz",____Does it mean with those values, all speeds can
be achieved until 1GHz clock?
Well, the defaults I mentioned are from the datasheet cited in the
driver code. Those defaults made me think the base clock was 1GHz on
that particular hardware. I just realized that I was off by an order of
magnitude, I think I was mixing numbers from the driver and numbers
from the datasheet in my head. __The default HCNT,LCNT in that datasheet
are 612+706=1318 base cycles to give an SCL rate of 100KHz. So
1318*100000 is 131.8MHz, a very reasonable number.
In your world you want the 150MHz base clock to generate the 100Hz SCL,
so 150000000/100000 = 1500. My inclination would be to split that in
half and have HCNT,LCNT be 750,750, but for some reason there seems to
be a bias on this hardware for having HCNT be slightly longer than
LCNT, so maybe 775,725. Maybe that's an attempt to compensate for the
fact that high levels on the clock line are accomplished with a pullup
resistor, and it takes slightly longer for the line to "drift up" to a
high state via the pullup, compared to being driven low which would
happen quickly.
Just a remark.

According to Table 10 in Chapter 6 of the I2C standard from NXP,
SCL low must satisfy a minimum of 4.7 uS and SCL high must
satisfy a minimum of 4.0 uS when running SCL at 100KHz. At
400KHz the values are respectively 1.3uS and 0.6uS.

725 results in 4.83uS, which would be OK for the low phase if it
gets pulled low quite quickly. 775 results in 5.17uS, which is
also acceptable, especially if it takes rather long for it to be
pulled up.

750 results in 5.0uS for each, of course. This may theoreticalluy
be a safer value, but it doesn't reflect any odd behavior which the
real hardware may exhibit.
Post by Ian Lepore
I would expect the default values of the HCNT/LCNT registers would be
right for any given hardware... whoever configures the IP block in a
SoC would configure the base clock value and the default HCNT/LCNT
values to match each other. Putting it that way makes me think that
maybe the right thing to do in the driver is just stop setting
HCNT/LCNT at all, and rely on the hardware to be configured correctly
by default. It's worth a try.
It would also be interesting to just print out those values. In the
driver on lines 571-575 the code reads all those registers and does
nothing with them. If you look in the dragonflybsd version of the
driver it printed out all those values after reading them; whoever
imported the driver to freebsd just deleted all the kprintf() lines and
left the register reads.
--
Gary Jennejohn
Rajesh Kumar
2018-08-23 11:22:36 UTC
Permalink
Hi Ian/Gary,

Thanks for such a detailed explanation. It helps me understand some basics.
Post by Ian Lepore
Right now the driver lacks *any* support for changing bus speeds. That
__1. What is in the IG4_REG_CLK_PARMS register?
__2. What do we do about versions of the hardware that don't support
that register?__
I tested with my hardware and it seems it doesn't have the
IG4_REG_CLK_PARMS registers. When I try to read that offset, it's
returning 0x63636363 (looks like some junk value?) Also, I don't see any
register which specifies the base clock frequency directly, so that we can
change the HCNT/LCNT as needed (which I belive you mean by changing the bus
frequency here)
Post by Ian Lepore
It would also be interesting to just print out those values. In the
driver on lines 571-575 the code reads all those registers and does
nothing with them. If you look in the dragonflybsd version of the
driver it printed out all those values after reading them; whoever
imported the driver to freebsd just deleted all the kprintf() lines and
left the register reads.
I dumped few registers (during ig4iic_attach) and below are the details.
Looks like in my case SS HCNT/LCNT default is 645/855 ( total - 1500). So,
the base frequency seems to be configured to 150Mhz by default. Also, FS
HCNT/LCNT default is 0x87/0xF0 (total - 375), which also proves the base
frequency to be 150Mhz. So, my base requirement is satisfied. But, as I
mentioned earlier, there is no direct way to get (or) configure the base
frequency from the driver.

IG4_REG_CTL 00000063
IG4_REG_SS_SCL_HCNT 00000285
IG4_REG_SS_SCL_LCNT 00000357
IG4_REG_FS_SCL_HCNT 00000087
IG4_REG_FS_SCL_LCNT 000000f0
IG4_REG_INTR_STAT 00000000
IG4_REG_INTR_MASK 00000000
IG4_REG_RAW_INTR_STAT 000000
IG4_REG_CLK_PARMS 63636363
IG4_REG_GENERAL 55555555
Post by Ian Lepore
According to Table 10 in Chapter 6 of the I2C standard from NXP,
SCL low must satisfy a minimum of 4.7 uS and SCL high must
satisfy a minimum of 4.0 uS when running SCL at 100KHz. At
400KHz the values are respectively 1.3uS and 0.6uS.
The above HCNT/LCNT numbers seems to match the minium requirements for SCL
both in SS and FS case.

Seems, this driver is written initially for controllers in Intel SoC's.
Now, as we need this driver for other SoC's like in my case, can we
generalize this driver by removing unnecessary checks for the "version" to
be ATOM/HASWELL/SKYWELL/APL etc., If there is no concern regarding this, I
will try to make the necessary changes.
Post by Ian Lepore
On Tue, 21 Aug 2018 08:33:00 -0600
Post by Ian Lepore
Post by Rajesh Kumar
Hi,
Re-posting the questions, just in case if its missed in other
conversation.
Post by Ian Lepore
Post by Rajesh Kumar
By "i2c clock frequency", I mean the internal base frequency only,
which
Post by Ian Lepore
Post by Rajesh Kumar
drives the chip.____I thought data will be transferred on bus based on
the
Post by Ian Lepore
Post by Rajesh Kumar
base frequency. So, thought both bus and base frequency are same. But
from
Post by Ian Lepore
Post by Rajesh Kumar
what you said, seems both are different. So, based on the setting in
*_HCNT/LCNT register, the bus frequency (which is the rate at which
data is
Post by Ian Lepore
Post by Rajesh Kumar
transferred) will change for a particular base frequency. Is that
right?
Post by Ian Lepore
Post by Rajesh Kumar
So, few questions here
1)____As you said, we need to have a base frequency of 150 Mhz in our
case.
Post by Ian Lepore
Post by Rajesh Kumar
So, do we need to program that IG4_REG_CLK_PARMS to 150 Mhz
(0x8F0D180)?
Post by Ian Lepore
Post by Rajesh Kumar
And can this be done at the same time when programming the HCNT/LNCT
registers?
I don't have this hardware, and I don't have a datasheet that describes
the__IG4_REG_CLK_PARMS register mentioned in the driver, so I don't
really have an answer. I suspect the hardware should set that register
with information that lets the driver know what the base clock speed
is. Using that information, the driver could calculate the proper
values for HCNT/LCNT.
Right now the driver lacks *any* support for changing bus speeds. That
__1. What is in the IG4_REG_CLK_PARMS register?
__2. What do we do about versions of the hardware that don't support
that register?__
Post by Rajesh Kumar
2)____Not sure how that 111Hz value is arrived.____Can you please
explain this
Post by Ian Lepore
Post by Rajesh Kumar
calculation. So, that I can derive the appropriate values for
HCNT/LCNT for
Post by Ian Lepore
Post by Rajesh Kumar
different speeds at 150Mhz base clock.
It's based on the comment (which I feel certain must be wrong) that the
base clock is 25,000 Hz. With HCNT,LCNT set to 100,125, one cycle of
the SCL line will last 225 base clock cycles. 1/25000 = 0.000040, that
times 225 is 0.009 seconds per SCL cycle. 1/.009 = 111.111 Hz.
FWIW, an i2c bus will run fine at 111Hz, it'll just take forever to get
anything done. But I don't think the bus is really running at 111Hz,
because I don't think the base clock is really 25KHz, I think the
comment block is just wrong about all of that.
Post by Rajesh Kumar
3)____"Default HCNT/LCNT register values would be consistent with an
internal
Post by Ian Lepore
Post by Rajesh Kumar
base clock speed of 1GHz",____Does it mean with those values, all
speeds can
Post by Ian Lepore
Post by Rajesh Kumar
be achieved until 1GHz clock?
Well, the defaults I mentioned are from the datasheet cited in the
driver code. Those defaults made me think the base clock was 1GHz on
that particular hardware. I just realized that I was off by an order of
magnitude, I think I was mixing numbers from the driver and numbers
from the datasheet in my head. __The default HCNT,LCNT in that datasheet
are 612+706=1318 base cycles to give an SCL rate of 100KHz. So
1318*100000 is 131.8MHz, a very reasonable number.
In your world you want the 150MHz base clock to generate the 100Hz SCL,
so 150000000/100000 = 1500. My inclination would be to split that in
half and have HCNT,LCNT be 750,750, but for some reason there seems to
be a bias on this hardware for having HCNT be slightly longer than
LCNT, so maybe 775,725. Maybe that's an attempt to compensate for the
fact that high levels on the clock line are accomplished with a pullup
resistor, and it takes slightly longer for the line to "drift up" to a
high state via the pullup, compared to being driven low which would
happen quickly.
Just a remark.
According to Table 10 in Chapter 6 of the I2C standard from NXP,
SCL low must satisfy a minimum of 4.7 uS and SCL high must
satisfy a minimum of 4.0 uS when running SCL at 100KHz. At
400KHz the values are respectively 1.3uS and 0.6uS.
725 results in 4.83uS, which would be OK for the low phase if it
gets pulled low quite quickly. 775 results in 5.17uS, which is
also acceptable, especially if it takes rather long for it to be
pulled up.
750 results in 5.0uS for each, of course. This may theoreticalluy
be a safer value, but it doesn't reflect any odd behavior which the
real hardware may exhibit.
Post by Ian Lepore
I would expect the default values of the HCNT/LCNT registers would be
right for any given hardware... whoever configures the IP block in a
SoC would configure the base clock value and the default HCNT/LCNT
values to match each other. Putting it that way makes me think that
maybe the right thing to do in the driver is just stop setting
HCNT/LCNT at all, and rely on the hardware to be configured correctly
by default. It's worth a try.
It would also be interesting to just print out those values. In the
driver on lines 571-575 the code reads all those registers and does
nothing with them. If you look in the dragonflybsd version of the
driver it printed out all those values after reading them; whoever
imported the driver to freebsd just deleted all the kprintf() lines and
left the register reads.
--
Gary Jennejohn
Daniel Braniss
2018-08-21 05:14:11 UTC
Permalink
Post by Gary Jennejohn
On Mon, 20 Aug 2018 07:16:15 -0700
Post by Mark Millard via freebsd-hackers
Post by Ian Lepore
Post by Daniel Braniss
. . .
hi,
https://cs.huji.ac.il/~danny/Screen%20Shot%202018-08-20%20at%2011.06.43.png
. . .
This has nothing to do with the twsi driver, this is about the ig4
driver (found in sys/dev/ichiic).
That screenshot seems to show a bus running at 100KHz like it should
(although the 62:38 duty cycle is a bit suspicious).
Being a logic analyzer display, it my just be that the threshold
was off from the optimal value. The waveform shape is not really
visible.
The logic analyzer output also shows a thick "rising" edge without the
uparrow symbol. My guess would be that is a rising/falling/rising
sequence that on the scale in use does not show space between edges. In
other words: a glitch on the leading edge side of the intended pulse.
This too might be tied to the threshold used vs . the actual signal
properties: no way to tell from what is shown.
I have two of these logic analyzers and they definitely do a
major clean up of the signals displayed.
Things like overshoot and ringing, which can be seen on an
oscilloscope, do not appear on what the logic analyzer displays.
I suspect the purpose of the trace was simply to show the 100KHz
SCL.
yup, I connected the logic analyzer to check the frequency, which
was not changing, later I confirmed by looking at the source that it’s set
at a constant 100KHz.
Post by Gary Jennejohn
--
Gary Jennejohn
Loading...