From: Sascha Hauer <s.hauer@pengutronix.de>
To: Belisko Marek <marek.belisko@gmail.com>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 4/7] LED: Add LED trigger support
Date: Sat, 18 Dec 2010 18:21:31 +0100 [thread overview]
Message-ID: <20101218172131.GL6017@pengutronix.de> (raw)
In-Reply-To: <AANLkTi=D2uErKO0_HL0poEtcwymgU_E1VfeqUPqe+DW1@mail.gmail.com>
Hi Marek,
On Sat, Dec 18, 2010 at 05:51:56PM +0100, Belisko Marek wrote:
> Hi,
>
> On Sat, Dec 18, 2010 at 4:15 PM, Sascha Hauer <s.hauer@pengutronix.de> wrote:
> > This patch allows to associate LEDs with certain triggers, such
> > as heartbeat or network activity.
> >
> > Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> > ---
> > drivers/led/Kconfig | 3 +++
> > drivers/led/Makefile | 1 +
> > include/led.h | 26 ++++++++++++++++++++++++++
> > include/net.h | 3 +++
> > lib/vsprintf.c | 4 ++++
> > net/eth.c | 20 +++++++++++++++++++-
> > net/net.c | 21 ++++++++++++++++-----
> > 7 files changed, 72 insertions(+), 6 deletions(-)
> >
> > diff --git a/drivers/led/Kconfig b/drivers/led/Kconfig
> > index b5e2f97..d8540c5 100644
> > --- a/drivers/led/Kconfig
> > +++ b/drivers/led/Kconfig
> > @@ -7,4 +7,7 @@ config LED_GPIO
> > bool "gpio LED support"
> > depends on GENERIC_GPIO
> >
> > +config LED_TRIGGERS
> > + bool "LED triggers support"
> > +
> > endif
> > diff --git a/drivers/led/Makefile b/drivers/led/Makefile
> > index 29b9fd5..6aafa6d 100644
> > --- a/drivers/led/Makefile
> > +++ b/drivers/led/Makefile
> > @@ -1,2 +1,3 @@
> > obj-$(CONFIG_LED) += core.o
> > obj-$(CONFIG_LED_GPIO) += led-gpio.o
> > +obj-$(CONFIG_LED_TRIGGERS) += led-triggers.o
> > diff --git a/include/led.h b/include/led.h
> > index 98b8c2e..2dc0f9d 100644
> > --- a/include/led.h
> > +++ b/include/led.h
> > @@ -22,6 +22,32 @@ int led_register(struct led *led);
> > void led_unregister(struct led *led);
> > void led_unregister(struct led *led);
> >
> > +/* LED trigger support */
> > +enum led_trigger {
> > + led_trigger_panic,
> > + led_trigger_heartbeat,
> > + led_trigger_net_rx,
> > + led_trigger_net_tx,
> > + led_trigger_net_txrx,
> > + led_trigger_max,
> > +};
> shouldn't be enums uppercase?
You're right. Will change this.
Sascha
> > +
> > +#ifdef CONFIG_LED_TRIGGERS
> > +int led_set_trigger(enum led_trigger trigger, struct led *led);
> > +void led_trigger(enum led_trigger trigger, bool enable);
> > +#else
> > +static inline int led_set_trigger(enum led_trigger trigger, struct led *led)
> > +{
> > + return 0;
> > +}
> > +
> > +static inline void led_trigger(enum led_trigger trigger, bool enable)
> > +{
> > +}
> > +#endif
> > +
> > +int led_get_trigger(enum led_trigger trigger);
> > +
> > /* gpio LED support */
> > struct gpio_led {
> > int gpio;
> > diff --git a/include/net.h b/include/net.h
> > index c695e5f..71c314e 100644
> > --- a/include/net.h
> > +++ b/include/net.h
> > @@ -18,6 +18,7 @@
> > #include <malloc.h>
> > #include <stdlib.h>
> > #include <clock.h>
> > +#include <led.h>
> > #include <asm/byteorder.h> /* for nton* / ntoh* stuff */
> >
> >
> > @@ -417,4 +418,6 @@ static inline unsigned char *net_udp_get_payload(struct net_connection *con)
> > int net_udp_send(struct net_connection *con, int len);
> > int net_icmp_send(struct net_connection *con, int len);
> >
> > +void led_trigger_network(enum led_trigger trigger, int active);
> > +
> > #endif /* __NET_H__ */
> > diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> > index e2ea84d..6117337 100644
> > --- a/lib/vsprintf.c
> > +++ b/lib/vsprintf.c
> > @@ -17,6 +17,7 @@
> > #include <malloc.h>
> >
> > #include <common.h>
> > +#include <led.h>
> > #include <reloc.h>
> >
> > unsigned long simple_strtoul(const char *cp,char **endp,unsigned int base)
> > @@ -625,6 +626,9 @@ void __noreturn panic(const char *fmt, ...)
> > vprintf(fmt, args);
> > putchar('\n');
> > va_end(args);
> > +
> > + led_trigger(led_trigger_panic, 1);
> > +
> > #if defined (CONFIG_PANIC_HANG)
> > hang();
> > #else
> > diff --git a/net/eth.c b/net/eth.c
> > index a82a263..6ac4f09 100644
> > --- a/net/eth.c
> > +++ b/net/eth.c
> > @@ -77,7 +77,13 @@ int eth_send(void *packet, int length)
> > eth_current->active = 1;
> > }
> >
> > - return eth_current->send(eth_current, packet, length);
> > + led_trigger_network(led_trigger_net_tx, 1);
> > +
> > + ret = eth_current->send(eth_current, packet, length);
> > +
> > + led_trigger_network(led_trigger_net_tx, 0);
> > +
> > + return ret;
> > }
> >
> > int eth_rx(void)
> > @@ -183,4 +189,16 @@ void eth_unregister(struct eth_device *edev)
> > list_del(&edev->list);
> > }
> >
> > +void led_trigger_network(enum led_trigger trigger, int enable)
> > +{
> > + static bool rx_active, tx_active;
> >
> > + led_trigger(trigger, enable);
> > +
> > + if (trigger == led_trigger_net_tx)
> > + tx_active = enable;
> > + if (trigger == led_trigger_net_rx)
> > + rx_active = enable;
> > +
> > + led_trigger(led_trigger_net_txrx, tx_active || rx_active);
> > +}
> > diff --git a/net/net.c b/net/net.c
> > index a613d1d..afd5964 100644
> > --- a/net/net.c
> > +++ b/net/net.c
> > @@ -628,19 +628,30 @@ int net_receive(unsigned char *pkt, int len)
> > {
> > struct ethernet *et = (struct ethernet *)pkt;
> > int et_protlen = ntohs(et->et_protlen);
> > + int ret;
> >
> > - if (len < ETHER_HDR_SIZE)
> > - return 0;
> > + led_trigger_network(led_trigger_net_rx, 1);
> > +
> > + if (len < ETHER_HDR_SIZE) {
> > + ret = 0;
> > + goto out;
> > + }
> >
> > switch (et_protlen) {
> > case PROT_ARP:
> > - return net_handle_arp(pkt, len);
> > + ret = net_handle_arp(pkt, len);
> > + break;
> > case PROT_IP:
> > - return net_handle_ip(pkt, len);
> > + ret = net_handle_ip(pkt, len);
> > + break;
> > default:
> > debug("%s: got unknown protocol type: %d\n", __func__, et_protlen);
> > - return 1;
> > + ret = 1;
> > + break;
> > }
> > +out:
> > + led_trigger_network(led_trigger_net_rx, 0);
> > + return ret;
> > }
> >
> > static int net_init(void)
> > --
> > 1.7.2.3
> >
> >
> > _______________________________________________
> > barebox mailing list
> > barebox@lists.infradead.org
> > http://lists.infradead.org/mailman/listinfo/barebox
> >
>
> thanks,
>
> marek
>
> --
> as simple and primitive as possible
> -------------------------------------------------
> Marek Belisko - OPEN-NANDRA
> Freelance Developer
>
> Ruska Nova Ves 219 | Presov, 08005 Slovak Republic
> Tel: +421 915 052 184
> skype: marekwhite
> icq: 290551086
> web: http://open-nandra.com
>
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2010-12-18 17:21 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-18 15:15 LED framework Sascha Hauer
2010-12-18 15:15 ` [PATCH 1/7] Add generic poll infrastructure Sascha Hauer
2010-12-18 15:28 ` Sascha Hauer
2010-12-18 15:15 ` [PATCH 2/7] basic LED support Sascha Hauer
2010-12-18 16:38 ` Jean-Christophe PLAGNIOL-VILLARD
2010-12-18 17:18 ` Sascha Hauer
2010-12-18 16:48 ` Jean-Christophe PLAGNIOL-VILLARD
2010-12-18 19:06 ` Belisko Marek
2010-12-19 21:31 ` Marc Reilly
2010-12-20 8:27 ` Sascha Hauer
2010-12-18 15:15 ` [PATCH 3/7] LED: Add gpio " Sascha Hauer
2010-12-18 16:41 ` Jean-Christophe PLAGNIOL-VILLARD
2010-12-18 17:18 ` Sascha Hauer
2010-12-18 15:15 ` [PATCH 4/7] LED: Add LED trigger support Sascha Hauer
2010-12-18 16:51 ` Belisko Marek
2010-12-18 17:21 ` Sascha Hauer [this message]
2010-12-18 15:15 ` [PATCH 5/7] LED: Add led command Sascha Hauer
2010-12-18 16:45 ` Jean-Christophe PLAGNIOL-VILLARD
2010-12-18 17:24 ` Sascha Hauer
2010-12-18 15:15 ` [PATCH 6/7] LED: Add trigger command Sascha Hauer
2010-12-18 15:15 ` [PATCH 7/7] pcm038: led testing. Not to be committed Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20101218172131.GL6017@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=marek.belisko@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox