From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: Received: from mail-pa0-x241.google.com ([2607:f8b0:400e:c03::241]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aNwcL-0004iL-Qk for barebox@lists.infradead.org; Tue, 26 Jan 2016 05:56:45 +0000 Received: by mail-pa0-x241.google.com with SMTP id gi1so7538721pac.2 for ; Mon, 25 Jan 2016 21:56:23 -0800 (PST) From: Andrey Smirnov Date: Mon, 25 Jan 2016 21:55:58 -0800 Message-Id: <1453787758-12688-7-git-send-email-andrew.smirnov@gmail.com> In-Reply-To: <1453787758-12688-1-git-send-email-andrew.smirnov@gmail.com> References: <1453787758-12688-1-git-send-email-andrew.smirnov@gmail.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" Errors-To: barebox-bounces+u.kleine-koenig=pengutronix.de@lists.infradead.org Subject: [PATCH 7/7] commands: Add mdio_read and mdio_write To: barebox@lists.infradead.org Cc: Andrey Smirnov QWRkIGNvbW1hbmRzIGZvciBsb3ctbGV2ZWwgYWNjZXNzIHRvIE1ESU8gYnVzLgoKU2lnbmVkLW9m Zi1ieTogQW5kcmV5IFNtaXJub3YgPGFuZHJldy5zbWlybm92QGdtYWlsLmNvbT4KLS0tCiBjb21t YW5kcy9LY29uZmlnICB8ICAyOCArKysrKysrKysKIGNvbW1hbmRzL01ha2VmaWxlIHwgICAxICsK IGNvbW1hbmRzL21kaW8uYyAgIHwgMTgyICsrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysr KysrKysrKysrKysrKysrKysrKysrKwogMyBmaWxlcyBjaGFuZ2VkLCAyMTEgaW5zZXJ0aW9ucygr KQogY3JlYXRlIG1vZGUgMTAwNjQ0IGNvbW1hbmRzL21kaW8uYwoKZGlmZiAtLWdpdCBhL2NvbW1h bmRzL0tjb25maWcgYi9jb21tYW5kcy9L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