From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: Received: from smtp3-g21.free.fr ([212.27.42.3]) by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux)) id 1OGXz2-000519-KZ for barebox@lists.infradead.org; Mon, 24 May 2010 13:46:22 +0000 From: =?utf-8?q?Eric=20B=C3=A9nard?= Date: Mon, 24 May 2010 15:46:07 +0200 Message-Id: <1274708768-20607-3-git-send-email-eric@eukrea.com> In-Reply-To: <1274708768-20607-2-git-send-email-eric@eukrea.com> References: <1274708768-20607-1-git-send-email-eric@eukrea.com> <1274708768-20607-2-git-send-email-eric@eukrea.com> MIME-Version: 1.0 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: base64 Sender: barebox-bounces@lists.infradead.org Errors-To: barebox-bounces+u.kleine-koenig=pengutronix.de@lists.infradead.org Subject: [PATCH 3/4] commands: add i2c commands To: s.hauer@pengutronix.de Cc: barebox@lists.infradead.org dGhlc2VzIGNvbW1hbmRzIGFsbG93IGxvdyBsZXZlbCBhY2Nlc3MgdG8gaTJjIGJ1cyBhbmQgY2Fu IGJlIHVzZWZ1bAp0byBzZXR1cCBhbiBpMmMgZGV2aWNlIHdpdGhvdXQgaGF2aW5nIHRvIGFkZCBj b2RlLCBjb21waWxlIGFuZCBmbGFzaApiYXJlYm94LgoKU2lnbmVkLW9mZi1ieTogRXJpYyBCw6lu YXJkIDxlcmljQGV1a3JlYS5jb20+Ci0tLQp2MyA6IAoJZW5hYmxlIGJyYWluIGFuZCBmaXggdjIK CXRlc3RlZCBvbiBpTVgyNwp2MiA6Cgl1cGRhdGVkIGFzIHBlciBTYXNjaGEncyBjb21tZW50cwoK IGNvbW1hbmRzL0tjb25maWcgIHwgICAgOCArKwogY29tbWFuZHMvTWFrZWZpbGUgfCAgICAxICsK IGNvbW1hbmRzL2kyYy5jICAgIHwgIDIxOCArKysrKysrKysrKysrKysrKysrKysrKysrK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UgJ3Yn OgorCQkJdmVyYm9zZSA9IDE7CisJCQlicmVhazsKKwkJfQorCX0KKworCWlmICgoYWRkciA8IDAp IHx8IChyZWcgPCAwKSB8fCAoY291bnQgPT0gMCkgfHwgKGFkZHIgPiAweDdGKSkKKwkJcmV0dXJu IENPTU1BTkRfRVJST1JfVVNBR0U7CisKKwljbGllbnQuYWRkciA9IGFkZHI7CisKKwlidWYgPSBt YWxsb2MoY291bnQpOworCWlmIChidWYpIHsKKwkJcmV0ID0gaTJjX3JlYWRfcmVnKCZjbGllbnQs IHJlZywgYnVmLCBjb3VudCk7CisJCWlmIChyZXQgPT0gY291bnQpIHsKKwkJCWludCBpOworCQkJ aWYgKHZlcmJvc2UpCisJCQkJcHJpbnRmKCJyZWFkICVpIGJ5dGVzIHN0YXJ0aW5nIGF0IHJlZyAw eCUwMnggZnJvbSBpMmNkZXYgMHglMDJ4IG9uIGJ1cyAlaVxuIiwKKwkJCQkJY291bnQsIHJlZywg YWRkciwgYWRhcHRlci0+bnIpOworCQkJZm9yIChpID0gMDsgaSA8IGNvdW50OyBpKyspCisJCQkJ cHJpbnRmKCIweCUwMnggIiwgKihidWYgKyBpKSk7CisJCQlwcmludGYoIlxuIik7CisJCQlmcmVl KGJ1Zik7CisJCQlyZXR1cm4gMDsKKwkJfQorCQlmcmVlKGJ1Zik7CisJfQorCXJldHVybiAxOwor fQorCitzdGF0aWMgY29uc3QgX19tYXliZV91bnVzZWQgY2hhciBjbWRfaTJjX3JlYWRfaGVscFtd ID0KKyJVc2FnZTogaTJjX3JlYWQgW09QVElPTl1cbiIKKyJyZWFkIGkyYyBkZXZpY2UuXG4iCisi ICAtYSAweDxhZGRyPiAgIGkyYyBkZXZpY2UgYWRkcmVzc1xuIgorIiAgLWIgPGJ1c19udW0+ICBp MmMgYnVzIG51bWJlclxuIgorIiAgLXIgMHg8cmVnPiAgICBzdGFydCByZWdpc3RlclxuIgorIiAg LWMgPGNvdW50PiAgICBieXRlIGNvdW50XG4iOworCitC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