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 1OGWFf-0000rV-1N for barebox@lists.infradead.org; Mon, 24 May 2010 11:55:24 +0000 From: =?utf-8?q?Eric=20B=C3=A9nard?= Date: Mon, 24 May 2010 13:55:13 +0200 Message-Id: <1274702114-11772-2-git-send-email-eric@eukrea.com> In-Reply-To: <1274702114-11772-1-git-send-email-eric@eukrea.com> References: <1274702114-11772-1-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 2/3] commands: add i2c commands To: s.hauer@pengutronix.de Cc: barebox@lists.infradead.org dGhlc2VzIGNvbW1hbmRzIGFsbG93IGxvdyBsZXZlbCBhY2Nlc3MgdG8gaTJjIGJ1cyBhbmQgY2Fu IGJlIHVzZWZ1bAp0byBzZXR1cCBhbiBpMmMgZGV2aWNlIHdpdGhvdXQgaGF2aW5nIHRvIGFkZCBj b2RlLCBjb21waWxlIGFuZCBmbGFzaApiYXJlYm94LgoKU2lnbmVkLW9mZi1ieTogRXJpYyBCw6lu YXJkIDxlcmljQGV1a3JlYS5jb20+Ci0tLQogY29tbWFuZHMvS2NvbmZpZyAgfCAgICA4ICsrCiBj b21tYW5kcy9NYWtlZmlsZSB8ICAgIDEgKwogY29tbWFuZHMvaTJjLmMgICAgfCAgMjE4ICsrKysr KysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrCiAzIGZpbGVz IGNoYW5nZWQsIDIyNyBpbnNlcnRpb25zKCspLCAwIGRlbGV0aW9ucygtKQogY3JlYXRlIG1vZGUg MTAwNjQ0IGNvbW1hbmRzL2k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fX19f X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fXwpiYXJlYm94IG1haWxpbmcgbGlz dApiYXJlYm94QGxpc3RzLmluZnJhZGVhZC5vcmcKaHR0cDovL2xpc3RzLmluZnJhZGVhZC5vcmcv bWFpbG1hbi9saXN0aW5mby9iYXJlYm94Cg==