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 @@ -67,6 +67,22 @@ config ATA_FORCE
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 @@ -685,6 +685,17 @@ static inline void ata_set_tf_cdl(struct
49 qc->flags |= ATA_QCFLAG_HAS_CDL | ATA_QCFLAG_RESULT_TF;
52 +#ifdef CONFIG_ATA_LEDS
53 +#define LIBATA_BLINK_DELAY 20 /* ms */
54 +static inline void ata_led_act(struct ata_port *ap)
56 + if (unlikely(!ap->ledtrig))
59 + led_trigger_blink_oneshot(ap->ledtrig, LIBATA_BLINK_DELAY, LIBATA_BLINK_DELAY, 0);
64 * ata_build_rw_tf - Build ATA taskfile for given read/write request
65 * @qc: Metadata associated with the taskfile to build
66 @@ -4771,6 +4782,9 @@ void __ata_qc_complete(struct ata_queued
67 link->active_tag = ATA_TAG_POISON;
68 ap->nr_active_links--;
70 +#ifdef CONFIG_ATA_LEDS
74 /* clear exclusive status */
75 if (unlikely(qc->flags & ATA_QCFLAG_CLEAR_EXCL &&
76 @@ -5494,6 +5508,9 @@ struct ata_port *ata_port_alloc(struct a
77 ap->stats.unhandled_irq = 1;
78 ap->stats.idle_irq = 1;
80 +#ifdef CONFIG_ATA_LEDS
81 + ap->ledtrig = kzalloc(sizeof(struct led_trigger), GFP_KERNEL);
83 ata_sff_port_init(ap);
86 @@ -5530,6 +5547,12 @@ static void ata_host_release(struct kref
88 kfree(ap->slave_link);
89 kfree(ap->ncq_sense_buf);
90 +#ifdef CONFIG_ATA_LEDS
92 + led_trigger_unregister(ap->ledtrig);
97 host->ports[i] = NULL;
99 @@ -5920,7 +5943,23 @@ int ata_host_register(struct ata_host *h
100 host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
101 host->ports[i]->local_port_no = i + 1;
103 +#ifdef CONFIG_ATA_LEDS
104 + for (i = 0; i < host->n_ports; i++) {
105 + if (unlikely(!host->ports[i]->ledtrig))
108 + snprintf(host->ports[i]->ledtrig_name,
109 + sizeof(host->ports[i]->ledtrig_name), "ata%u",
110 + host->ports[i]->print_id);
112 + host->ports[i]->ledtrig->name = host->ports[i]->ledtrig_name;
114 + if (led_trigger_register(host->ports[i]->ledtrig)) {
115 + kfree(host->ports[i]->ledtrig);
116 + host->ports[i]->ledtrig = NULL;
120 /* Create associated sysfs transport objects */
121 for (i = 0; i < host->n_ports; i++) {
122 rc = ata_tport_add(host->dev,host->ports[i]);
123 --- a/include/linux/libata.h
124 +++ b/include/linux/libata.h
126 #include <linux/cdrom.h>
127 #include <linux/sched.h>
128 #include <linux/async.h>
129 +#ifdef CONFIG_ATA_LEDS
130 +#include <linux/leds.h>
134 * Define if arch has non-standard setup. This is a _PCI_ standard
135 @@ -875,6 +878,12 @@ struct ata_port {
136 #ifdef CONFIG_ATA_ACPI
137 struct ata_acpi_gtm __acpi_init_gtm; /* use ata_acpi_init_gtm() */
140 +#ifdef CONFIG_ATA_LEDS
141 + struct led_trigger *ledtrig;
142 + char ledtrig_name[8];
147 u8 sector_buf[ATA_SECT_SIZE] ____cacheline_aligned;