From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thomas Chou Date: Tue, 20 Apr 2010 23:05:37 +0800 Subject: [U-Boot] [PATCH] nios2: add gpio based status led driver In-Reply-To: <4BCDA9E3.70904@psyent.com> References: <1269665654-2609-1-git-send-email-thomas@wytron.com.tw> <4BCDA9E3.70904@psyent.com> Message-ID: <4BCDC2C1.3040801@wytron.com.tw> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On 04/20/2010 09:19 PM, Scott McNutt wrote: >> +void __led_init(led_id_t mask, int state) >> +{ >> + gpio_direction_output(mask, (state == STATUS_LED_ON) ? 0 : 1); > > > The direction register only exists when the PIO core hardware > is configured in bidirectional mode. > If the PIO core hardware is configured in output-only mode, > reading from data returns an undefined value. > > As I recall, the older designs configured the LED PIO ports > as output only ... which is why board/altera/common/epled.c > was coded in such a manner. > Hi Scott, This is not for Altera PIO interface. I followed the gpio interface of Linux, linux-2.6/Documentation/gpio.txt, and created a trivial bit addressing gpio core, which uses fewer LE and doesn't required interrupt disabled to write a bit. With this core, all output pins are bidirectional and can be read. I used it to access i2c, one-wire, leds, buttons and nand flash busy flag in nios2 linux. I didn't add irq support, because input layer of linux can do debounce. Please look at http://nioswiki.com/GPIO. Best regards, Thomas