<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>vm-kernel &#187; i2c</title>
	<atom:link href="http://vm-kernel.org/blog/tag/i2c/feed/" rel="self" type="application/rss+xml" />
	<link>http://vm-kernel.org/blog</link>
	<description>All about emulation and virtualization</description>
	<lastBuildDate>Sat, 17 Apr 2010 03:51:46 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>I2C emulation in qemu-loongson</title>
		<link>http://vm-kernel.org/blog/2009/04/22/i2c-emulation-in-qemu-loongson/</link>
		<comments>http://vm-kernel.org/blog/2009/04/22/i2c-emulation-in-qemu-loongson/#comments</comments>
		<pubDate>Wed, 22 Apr 2009 03:52:11 +0000</pubDate>
		<dc:creator>yajin</dc:creator>
				<category><![CDATA[emulation]]></category>
		<category><![CDATA[loongson]]></category>
		<category><![CDATA[gdium]]></category>
		<category><![CDATA[i2c]]></category>
		<category><![CDATA[qemu-loongson]]></category>

		<guid isPermaLink="false">http://vm-kernel.org/blog/2009/04/22/i2c-emulation-in-qemu-loongson/</guid>
		<description><![CDATA[I think most of you may think it is easy to emulate I2C device in qemu, for qemu has provided a framework of i2c, both the master and slave devices. You are right. Emulating the I2C is not difficult in qemu.
What I want to post here is not emulating I2C device directly, but emulating GPIO [...]]]></description>
			<content:encoded><![CDATA[<p>I think most of you may think it is easy to emulate I2C device in qemu, for qemu has provided a framework of i2c, both the master and slave devices. You are right. Emulating the I2C is not difficult in qemu.</p>
<p>What I want to post here is not emulating I2C device directly, but emulating GPIO logic which pmon uses to emulate I2C. A little confused? Me too. Ok, let me talk the story from the began.</p>
<p>In pmon, it uses sm502 gpio pin 6 and 13 to emulate I2C master devices, which communicates with other slave device, such as SPD EEPROM and temperature sensors. I do not know why lemote uses gpio to emulate i2c, instead of using the I2C master in sm502. When the data is written to gpio pins according to I2C state machine, pmon expects the gpio pins acting like the I2C master devices. So qemu needs to emulate the I2C cycle accurate state machine, not only the I2C function.</p>
<p>I summarize the I2C emulation code logic of pmon here for reference.</p>
<p>(1) Start Bit</p>
<p>SCL=0 -&gt; SDA=1 -&gt; SCL=1 -&gt; SDA=0 -&gt; SCL=0</p>
<p>(2)Stop Bit</p>
<p>SCL=0 -&gt; SDA=0 -&gt;SCL=1 -&gt;SDA=1 -&gt; SCL=0</p>
<p>(3)Write a bit</p>
<p>Put data on sda -&gt; SCL=1 -&gt; SCL=0</p>
<p>(4)Write a byte</p>
<p>repeating (3) 8 times -&gt; SDA=1</p>
<p>(5)Recv ACK</p>
<p>SCL=1 -&gt;read sda until sda=0 -&gt; SCL=0</p>
<p>(6)Read a bit</p>
<p>SCL=1 -&gt; read data on SDA -&gt; SCL=0</p>
<p>(7)Read a byte</p>
<p>repeating (6) 8 times</p>
<p>(8)Send ACK</p>
<p>put ACK on sda -&gt; SCL=1 -&gt; SCL=0</p>
<p>(9)Send a buffer</p>
<p>Do the following steps until the buffer is empty</p>
<ol>
<li>START </li>
<li>Send slave address </li>
<li>Recv ACK </li>
<li>Send reg address </li>
<li>Recv ACK </li>
<li>Send one byte </li>
<li>Recv ACK </li>
<li>STOP </li>
</ol>
<p>(10) Recv many bytes from slave deviceDo the following steps until finished </p>
<ol>
<li>START </li>
<li>Send slave address </li>
<li>Recv ACK </li>
<li>Send reg address </li>
<li>Recv ACK</li>
<li>Repeat START </li>
<li>Send slave address+1(tell slave we want to recv) </li>
<li>Recv ACK </li>
<li>Recv a byte </li>
<li>Send ACK </li>
<li>STOP </li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://vm-kernel.org/blog/2009/04/22/i2c-emulation-in-qemu-loongson/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
