1 From: Daniel Golle <daniel@makrotopia.org>
2 Subject: libata: add ledtrig support
4 This adds a LED trigger for each ATA port indicating disk activity.
6 As this is needed only on specific platforms (NAS SoCs and such),
7 these platforms should define ARCH_WANTS_LIBATA_LEDS if there
8 are boards with LED(s) intended to indicate ATA disk activity and
9 need the OS to take care of that.
10 In that way, if not selected, LED trigger support not will be
11 included in libata-core and both, codepaths and structures remain
14 Signed-off-by: Daniel Golle <daniel@makrotopia.org>
16 drivers/ata/Kconfig | 16 ++++++++++++++++
17 drivers/ata/libata-core.c | 41 +++++++++++++++++++++++++++++++++++++++++
18 include/linux/libata.h | 9 +++++++++
19 3 files changed, 66 insertions(+)
21 --- a/drivers/ata/Kconfig
22 +++ b/drivers/ata/Kconfig
23 @@ -46,6 +46,22 @@ config ATA_VERBOSE_ERROR
27 +config ARCH_WANT_LIBATA_LEDS
31 + bool "support ATA port LED triggers"
32 + depends on ARCH_WANT_LIBATA_LEDS
35 + select LEDS_TRIGGERS
38 + This option adds a LED trigger for each registered ATA port.
39 + It is used to drive disk activity leds connected via GPIO.
44 bool "ATA ACPI Support"
46 --- a/drivers/ata/libata-core.c
47 +++ b/drivers/ata/libata-core.c
48 @@ -730,6 +730,19 @@ u64 ata_tf_read_block(const struct ata_t
52 +#ifdef CONFIG_ATA_LEDS
53 +#define LIBATA_BLINK_DELAY 20 /* ms */
54 +static inline void ata_led_act(struct ata_port *ap)
56 + unsigned long led_delay = LIBATA_BLINK_DELAY;
58 + if (unlikely(!ap->ledtrig))
61 + led_trigger_blink_oneshot(ap->ledtrig, &led_delay, &led_delay, 0);
66 * ata_build_rw_tf - Build ATA taskfile for given read/write request
67 * @tf: Target ATA taskfile
68 @@ -5123,6 +5136,9 @@ struct ata_queued_cmd *ata_qc_new_init(s
72 +#ifdef CONFIG_ATA_LEDS
76 qc = __ata_qc_from_tag(ap, tag);
78 @@ -6024,6 +6040,9 @@ struct ata_port *ata_port_alloc(struct a
79 ap->stats.unhandled_irq = 1;
80 ap->stats.idle_irq = 1;
82 +#ifdef CONFIG_ATA_LEDS
83 + ap->ledtrig = kzalloc(sizeof(struct led_trigger), GFP_KERNEL);
85 ata_sff_port_init(ap);
88 @@ -6045,6 +6064,12 @@ static void ata_host_release(struct devi
91 kfree(ap->slave_link);
92 +#ifdef CONFIG_ATA_LEDS
94 + led_trigger_unregister(ap->ledtrig);
99 host->ports[i] = NULL;
101 @@ -6491,7 +6516,23 @@ int ata_host_register(struct ata_host *h
102 host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
103 host->ports[i]->local_port_no = i + 1;
105 +#ifdef CONFIG_ATA_LEDS
106 + for (i = 0; i < host->n_ports; i++) {
107 + if (unlikely(!host->ports[i]->ledtrig))
110 + snprintf(host->ports[i]->ledtrig_name,
111 + sizeof(host->ports[i]->ledtrig_name), "ata%u",
112 + host->ports[i]->print_id);
114 + host->ports[i]->ledtrig->name = host->ports[i]->ledtrig_name;
116 + if (led_trigger_register(host->ports[i]->ledtrig)) {
117 + kfree(host->ports[i]->ledtrig);
118 + host->ports[i]->ledtrig = NULL;
122 /* Create associated sysfs transport objects */
123 for (i = 0; i < host->n_ports; i++) {
124 rc = ata_tport_add(host->dev,host->ports[i]);
125 --- a/include/linux/libata.h
126 +++ b/include/linux/libata.h
128 #include <linux/cdrom.h>
129 #include <linux/sched.h>
130 #include <linux/async.h>
131 +#ifdef CONFIG_ATA_LEDS
132 +#include <linux/leds.h>
136 * Define if arch has non-standard setup. This is a _PCI_ standard
137 @@ -893,6 +896,12 @@ struct ata_port {
138 #ifdef CONFIG_ATA_ACPI
139 struct ata_acpi_gtm __acpi_init_gtm; /* use ata_acpi_init_gtm() */
142 +#ifdef CONFIG_ATA_LEDS
143 + struct led_trigger *ledtrig;
144 + char ledtrig_name[8];
148 u8 sector_buf[ATA_SECT_SIZE] ____cacheline_aligned;