From owner-freebsd-hackers@freebsd.org Thu Aug 23 11:22:50 2018 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 90E12108A7BF; Thu, 23 Aug 2018 11:22:50 +0000 (UTC) (envelope-from rajfbsd@gmail.com) Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id F0ABC8DE75; Thu, 23 Aug 2018 11:22:49 +0000 (UTC) (envelope-from rajfbsd@gmail.com) Received: by mail-wr1-x435.google.com with SMTP id a108-v6so4297687wrc.13; Thu, 23 Aug 2018 04:22:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=K0CCUDKUjPX78vxmx2ZMfgDUXgzP82QYi4td2QI4D3s=; b=QT/zidTcJB0xdkH5S67hk1RFPAOAkMdFubOMHC2Rc/JcecP/QTyYrKCi7BasiFAvZ2 M5vOcXSTdYyIqkr5qL+aiyv/q3iuVkwPJW67rhuAjWGtVjBpzXHQH9UGmbw1xKRFR3s3 sn1Zja2JdEn3vJRSpT8zf5WWhKC/hapLy9c7Js5PX3OsFcam8ed1S2c9wg+gjdCYU2lE gW1N+x+NsD/ZZjKeRuKapOEjzbH1+gcxnUu0FLRLRMtgwlj2l8VJTX9X9xf1i9zjYYCi 7/Gdhga3n6drU2KYYr36x+jkkNi2UzE2b+Ywk0SAhnpNUxlOFVP2Yox3G0/G9tRXMUUB skrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=K0CCUDKUjPX78vxmx2ZMfgDUXgzP82QYi4td2QI4D3s=; b=L6LxgZuUTWHaRnk+Zd/rsEFhJQskapHBPNgczXNMTWUXU2lqUKTYIS2CkyQ/UiwB+G BNMhjUkTgXfLJg+tbeQsknwi3jLBtbR56Y1zBkzGkgPX/4/DQAvrGKH+N2ie9p+8G9Ft gPx7Y7bcQZE+YH4CIaMkYuq0Gs5I0N98wFCmz9uYytmkqQgDdbfbF+TW4zonwHeKJYxa J27mNQ2xfFZKmJ0PrfPT8qpEfVvk8s190Zmm7nQGXHbHqv6md9Ee2SsGVuUUjw+jeZF9 pYcXNBKN8jkF9l3HGDLzkfw9ZnoMGUi2TYS5IWButBMrpbq6MSWQ2dJpsrpLdnA+87Fb xfbw== X-Gm-Message-State: APzg51BBbU/hdEzvMnj3qbw6LGx0nlevO6lFAIjQChOcJ0zwtls8eazL uWMvhcypbJftv4vPxopiqdKEfh/mXPPVoHMlb9TTDorx X-Google-Smtp-Source: ANB0VdZdfDnGzY5OnpNKqzEs69ryYd8Sg3TenDSPxJebFWJwE/8q1ijU/tvNuV3rfrL92x5OIIYYwszDpH3tSYWtZ/w= X-Received: by 2002:adf:806d:: with SMTP id 100-v6mr14504681wrk.23.1535023368497; Thu, 23 Aug 2018 04:22:48 -0700 (PDT) MIME-Version: 1.0 References: <1534523216.27158.17.camel@freebsd.org> <1534702861.27158.36.camel@freebsd.org> <1534771095.27158.46.camel@freebsd.org> <35F2C250-B4CB-4C53-BF8F-43C338022E34@yahoo.com> <20180820181322.71607854@ernst.home> <1534861980.27158.145.camel@freebsd.org> <20180821171626.49951728@ernst.home> In-Reply-To: <20180821171626.49951728@ernst.home> From: Rajesh Kumar Date: Thu, 23 Aug 2018 16:52:36 +0530 Message-ID: Subject: Re: Need a clarification regarding I2C bus frequency in FreeBSD To: gljennjohn@gmail.com Cc: ian@freebsd.org, freebsd-hackers@freebsd.org, freebsd-drivers@freebsd.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.27 X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Aug 2018 11:22:50 -0000 Hi Ian/Gary, Thanks for such a detailed explanation. It helps me understand some basics. > 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?__ 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) > 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 > 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. On Tue, Aug 21, 2018 at 8:46 PM Gary Jennejohn wrote: > On Tue, 21 Aug 2018 08:33:00 -0600 > Ian Lepore wrote: > > > On Mon, 2018-08-20 at 23:25 +0530, Rajesh Kumar wrote: > > > 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?__ > > > > > 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. > > > > > 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. > > > 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 >