kernel: bump 6.6 to 6.6.24
[openwrt/staging/xback.git] / target / linux / generic / pending-6.6 / 834-ledtrig-libata.patch
1 From: Daniel Golle <daniel@makrotopia.org>
2 Subject: libata: add ledtrig support
3
4 This adds a LED trigger for each ATA port indicating disk activity.
5
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
12 untouched.
13
14 Signed-off-by: Daniel Golle <daniel@makrotopia.org>
15 ---
16 drivers/ata/Kconfig | 16 ++++++++++++++++
17 drivers/ata/libata-core.c | 41 +++++++++++++++++++++++++++++++++++++++++
18 include/linux/libata.h | 9 +++++++++
19 3 files changed, 66 insertions(+)
20
21 --- a/drivers/ata/Kconfig
22 +++ b/drivers/ata/Kconfig
23 @@ -67,6 +67,22 @@ config ATA_FORCE
24
25 If unsure, say Y.
26
27 +config ARCH_WANT_LIBATA_LEDS
28 + bool
29 +
30 +config ATA_LEDS
31 + bool "support ATA port LED triggers"
32 + depends on ARCH_WANT_LIBATA_LEDS
33 + select NEW_LEDS
34 + select LEDS_CLASS
35 + select LEDS_TRIGGERS
36 + default y
37 + help
38 + This option adds a LED trigger for each registered ATA port.
39 + It is used to drive disk activity leds connected via GPIO.
40 +
41 + If unsure, say N.
42 +
43 config ATA_ACPI
44 bool "ATA ACPI Support"
45 depends on ACPI
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;
50 }
51
52 +#ifdef CONFIG_ATA_LEDS
53 +#define LIBATA_BLINK_DELAY 20 /* ms */
54 +static inline void ata_led_act(struct ata_port *ap)
55 +{
56 + if (unlikely(!ap->ledtrig))
57 + return;
58 +
59 + led_trigger_blink_oneshot(ap->ledtrig, LIBATA_BLINK_DELAY, LIBATA_BLINK_DELAY, 0);
60 +}
61 +#endif
62 +
63 /**
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--;
69 }
70 +#ifdef CONFIG_ATA_LEDS
71 + ata_led_act(ap);
72 +#endif
73
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;
79 #endif
80 +#ifdef CONFIG_ATA_LEDS
81 + ap->ledtrig = kzalloc(sizeof(struct led_trigger), GFP_KERNEL);
82 +#endif
83 ata_sff_port_init(ap);
84
85 return ap;
86 @@ -5530,6 +5547,12 @@ static void ata_host_release(struct kref
87 kfree(ap->pmp_link);
88 kfree(ap->slave_link);
89 kfree(ap->ncq_sense_buf);
90 +#ifdef CONFIG_ATA_LEDS
91 + if (ap->ledtrig) {
92 + led_trigger_unregister(ap->ledtrig);
93 + kfree(ap->ledtrig);
94 + };
95 +#endif
96 kfree(ap);
97 host->ports[i] = NULL;
98 }
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;
102 }
103 +#ifdef CONFIG_ATA_LEDS
104 + for (i = 0; i < host->n_ports; i++) {
105 + if (unlikely(!host->ports[i]->ledtrig))
106 + continue;
107
108 + snprintf(host->ports[i]->ledtrig_name,
109 + sizeof(host->ports[i]->ledtrig_name), "ata%u",
110 + host->ports[i]->print_id);
111 +
112 + host->ports[i]->ledtrig->name = host->ports[i]->ledtrig_name;
113 +
114 + if (led_trigger_register(host->ports[i]->ledtrig)) {
115 + kfree(host->ports[i]->ledtrig);
116 + host->ports[i]->ledtrig = NULL;
117 + }
118 + }
119 +#endif
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
125 @@ -23,6 +23,9 @@
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>
131 +#endif
132
133 /*
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() */
138 #endif
139 +
140 +#ifdef CONFIG_ATA_LEDS
141 + struct led_trigger *ledtrig;
142 + char ledtrig_name[8];
143 +#endif
144 +
145 /* owned by EH */
146 u8 *ncq_sense_buf;
147 u8 sector_buf[ATA_SECT_SIZE] ____cacheline_aligned;