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 1OGpe1-0006jh-1s for barebox@lists.infradead.org; Tue, 25 May 2010 08:37:50 +0000 From: =?utf-8?q?Eric=20B=C3=A9nard?= Date: Tue, 25 May 2010 10:37:34 +0200 Message-Id: <1274776657-6117-3-git-send-email-eric@eukrea.com> In-Reply-To: <1274776657-6117-2-git-send-email-eric@eukrea.com> References: <1274776657-6117-1-git-send-email-eric@eukrea.com> <1274776657-6117-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 v4 3/6] commands: add i2c commands To: s.hauer@pengutronix.de Cc: barebox@lists.infradead.org dGhlc2VzIGNvbW1hbmRzIGFsbG93IGxvdyBsZXZlbCBhY2Nlc3MgdG8gaTJjIGJ1cyBhbmQgY2Fu IGJlIHVzZWZ1bAp0byBzZXR1cCBhbiBpMmMgZGV2aWNlIHdpdGhvdXQgaGF2aW5nIHRvIGFkZCBj b2RlLCBjb21waWxlIGFuZCBmbGFzaApiYXJlYm94LgoKU2lnbmVkLW9mZi1ieTogRXJpYyBCw6lu YXJkIDxlcmljQGV1a3JlYS5jb20+Ci0tLQp2NCA6Cgl1cGRhdGVkIGFzIHBlciBTYXNjaGEgYW5k IE1hcmMncyBjb21tZW50cwoJdXNlIGJ1cyAwIGFzIGEgZGVmYXVsdCBmb3IgaTJjX3JlYWQgJiB3 cml0ZQoJcmVwbGFjZSBtYWxsb2Mgd2l0aCB4bWFsbG9jCglmaXggc2ltcGxlX3N0cnRvbCBjb25m aWd1cmF0aW9uIGZvciBwYXJhbWV0ZXJzCnYzIDogCgllbmFib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