--- zzzz-none-000/linux-4.4.271/drivers/ata/libata-core.c 2021-06-03 06:22:09.000000000 +0000 +++ hawkeye-5590-750/linux-4.4.271/drivers/ata/libata-core.c 2023-04-19 10:22:28.000000000 +0000 @@ -727,6 +727,19 @@ return block; } +#ifdef CONFIG_ATA_LEDS +#define LIBATA_BLINK_DELAY 20 /* ms */ +static inline void ata_led_act(struct ata_port *ap) +{ + unsigned long led_delay = LIBATA_BLINK_DELAY; + + if (unlikely(!ap->ledtrig)) + return; + + led_trigger_blink_oneshot(ap->ledtrig, &led_delay, &led_delay, 0); +} +#endif + /** * ata_build_rw_tf - Build ATA taskfile for given read/write request * @tf: Target ATA taskfile @@ -4817,6 +4830,9 @@ if (tag < 0) return NULL; } +#ifdef CONFIG_ATA_LEDS + ata_led_act(ap); +#endif qc = __ata_qc_from_tag(ap, tag); qc->tag = tag; @@ -5715,6 +5731,9 @@ ap->stats.unhandled_irq = 1; ap->stats.idle_irq = 1; #endif +#ifdef CONFIG_ATA_LEDS + ap->ledtrig = kzalloc(sizeof(struct led_trigger), GFP_KERNEL); +#endif ata_sff_port_init(ap); return ap; @@ -5736,6 +5755,12 @@ kfree(ap->pmp_link); kfree(ap->slave_link); +#ifdef CONFIG_ATA_LEDS + if (ap->ledtrig) { + led_trigger_unregister(ap->ledtrig); + kfree(ap->ledtrig); + }; +#endif kfree(ap); host->ports[i] = NULL; } @@ -6182,7 +6207,23 @@ host->ports[i]->print_id = atomic_inc_return(&ata_print_id); host->ports[i]->local_port_no = i + 1; } +#ifdef CONFIG_ATA_LEDS + for (i = 0; i < host->n_ports; i++) { + if (unlikely(!host->ports[i]->ledtrig)) + continue; + snprintf(host->ports[i]->ledtrig_name, + sizeof(host->ports[i]->ledtrig_name), "ata%u", + host->ports[i]->print_id); + + host->ports[i]->ledtrig->name = host->ports[i]->ledtrig_name; + + if (led_trigger_register(host->ports[i]->ledtrig)) { + kfree(host->ports[i]->ledtrig); + host->ports[i]->ledtrig = NULL; + } + } +#endif /* Create associated sysfs transport objects */ for (i = 0; i < host->n_ports; i++) { rc = ata_tport_add(host->dev,host->ports[i]);