From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: Received: from smtp2-g21.free.fr ([212.27.42.2]) by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux)) id 1OGqxC-000443-KO for barebox@lists.infradead.org; Tue, 25 May 2010 10:01:44 +0000 From: =?utf-8?q?Eric=20B=C3=A9nard?= Date: Tue, 25 May 2010 12:01:27 +0200 Message-Id: <1274781690-9022-3-git-send-email-eric@eukrea.com> In-Reply-To: <1274781690-9022-2-git-send-email-eric@eukrea.com> References: <1274781690-9022-1-git-send-email-eric@eukrea.com> <1274781690-9022-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 v6 3/6] commands: add i2c commands To: s.hauer@pengutronix.de Cc: barebox@lists.infradead.org dGhlc2VzIGNvbW1hbmRzIGFsbG93IGxvdyBsZXZlbCBhY2Nlc3MgdG8gaTJjIGJ1cyBhbmQgY2Fu IGJlIHVzZWZ1bAp0byBzZXR1cCBhbiBpMmMgZGV2aWNlIHdpdGhvdXQgaGF2aW5nIHRvIGFkZCBj b2RlLCBjb21waWxlIGFuZCBmbGFzaApiYXJlYm94LgoKU2lnbmVkLW9mZi1ieTogRXJpYyBCw6lu YXJkIDxlcmljQGV1a3JlYS5jb20+Ci0tLQp2NiA6CglhZGQgbG9nIGJlZm9yZSBleGl0aW5nIHdo ZW4gaTJjIGJ1cyBkb2Vzbid0IGV4aXN0CnY1IDoKCXVwZGF0ZWQgYXMgcGVyIE1hcmMncyBjb21t ZW50cwoJYmV0dGVyIGVycm9yIGhhbmRsaW5nIGluIHdyaXRlCgliZXR0ZXIgZGVmYXVsdCBidXMg aGFuZGxpbmcgaW4gcmVhZCAmIHdyaXRlCnY0IDoKCXVwZGF0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