int phy_led_triggers_register(struct phy_device *phy) { int i, err; unsigned int speeds[50]; phy->phy_num_led_triggers = phy_supported_speeds(phy, speeds, ARRAY_SIZE(speeds)); if (!phy->phy_num_led_triggers) return 0; phy->led_link_trigger = devm_kzalloc(&phy->mdio.dev, sizeof(*phy->led_link_trigger), GFP_KERNEL); if (!phy->led_link_trigger) { err = -ENOMEM; goto out_clear; } phy_led_trigger_format_name(phy, phy->led_link_trigger->name, sizeof(phy->led_link_trigger->name), "link"); phy->led_link_trigger->trigger.name = phy->led_link_trigger->name; err = led_trigger_register(&phy->led_link_trigger->trigger); if (err) goto out_free_link; phy->phy_led_triggers = devm_kcalloc(&phy->mdio.dev, phy->phy_num_led_triggers, sizeof(struct phy_led_trigger), GFP_KERNEL); if (!phy->phy_led_triggers) { err = -ENOMEM; goto out_unreg_link; } for (i = 0; i < phy->phy_num_led_triggers; i++) { err = phy_led_trigger_register(phy, &phy->phy_led_triggers[i], speeds[i]); if (err) goto out_unreg; } phy->last_triggered = NULL; phy_led_trigger_change_speed(phy); return 0; out_unreg: while (i--) phy_led_trigger_unregister(&phy->phy_led_triggers[i]); devm_kfree(&phy->mdio.dev, phy->phy_led_triggers); out_unreg_link: phy_led_trigger_unregister(phy->led_link_trigger); out_free_link: devm_kfree(&phy->mdio.dev, phy->led_link_trigger); phy->led_link_trigger = NULL; out_clear: phy->phy_num_led_triggers = 0; return err; }
void ieee80211_led_init(struct ieee80211_local *local) { local->rx_led = kzalloc(sizeof(struct led_trigger), GFP_KERNEL); if (local->rx_led) { snprintf(local->rx_led_name, sizeof(local->rx_led_name), "%srx", wiphy_name(local->hw.wiphy)); local->rx_led->name = local->rx_led_name; if (led_trigger_register(local->rx_led)) { kfree(local->rx_led); local->rx_led = NULL; } } local->tx_led = kzalloc(sizeof(struct led_trigger), GFP_KERNEL); if (local->tx_led) { snprintf(local->tx_led_name, sizeof(local->tx_led_name), "%stx", wiphy_name(local->hw.wiphy)); local->tx_led->name = local->tx_led_name; if (led_trigger_register(local->tx_led)) { kfree(local->tx_led); local->tx_led = NULL; } } local->assoc_led = kzalloc(sizeof(struct led_trigger), GFP_KERNEL); if (local->assoc_led) { snprintf(local->assoc_led_name, sizeof(local->assoc_led_name), "%sassoc", wiphy_name(local->hw.wiphy)); local->assoc_led->name = local->assoc_led_name; if (led_trigger_register(local->assoc_led)) { kfree(local->assoc_led); local->assoc_led = NULL; } } local->radio_led = kzalloc(sizeof(struct led_trigger), GFP_KERNEL); if (local->radio_led) { snprintf(local->radio_led_name, sizeof(local->radio_led_name), "%sradio", wiphy_name(local->hw.wiphy)); local->radio_led->name = local->radio_led_name; if (led_trigger_register(local->radio_led)) { kfree(local->radio_led); local->radio_led = NULL; } } }
void ieee80211_led_init(struct ieee80211_local *local) { local->rx_led = kzalloc(sizeof(struct led_trigger), GFP_KERNEL); if (local->rx_led) { local->rx_led->name = local->rx_led_name; if (led_trigger_register(local->rx_led)) { kfree(local->rx_led); local->rx_led = NULL; } } local->tx_led = kzalloc(sizeof(struct led_trigger), GFP_KERNEL); if (local->tx_led) { local->tx_led->name = local->tx_led_name; if (led_trigger_register(local->tx_led)) { kfree(local->tx_led); local->tx_led = NULL; } } local->assoc_led = kzalloc(sizeof(struct led_trigger), GFP_KERNEL); if (local->assoc_led) { local->assoc_led->name = local->assoc_led_name; if (led_trigger_register(local->assoc_led)) { kfree(local->assoc_led); local->assoc_led = NULL; } } local->radio_led = kzalloc(sizeof(struct led_trigger), GFP_KERNEL); if (local->radio_led) { local->radio_led->name = local->radio_led_name; if (led_trigger_register(local->radio_led)) { kfree(local->radio_led); local->radio_led = NULL; } } if (local->tpt_led_trigger) { if (led_trigger_register(&local->tpt_led_trigger->trig)) { kfree(local->tpt_led_trigger); local->tpt_led_trigger = NULL; } } }
void ieee80211_led_init(struct ieee80211_local *local) { atomic_set(&local->rx_led_active, 0); local->rx_led.activate = ieee80211_rx_led_activate; local->rx_led.deactivate = ieee80211_rx_led_deactivate; if (local->rx_led.name && led_trigger_register(&local->rx_led)) { kfree(local->rx_led.name); local->rx_led.name = NULL; } atomic_set(&local->tx_led_active, 0); local->tx_led.activate = ieee80211_tx_led_activate; local->tx_led.deactivate = ieee80211_tx_led_deactivate; if (local->tx_led.name && led_trigger_register(&local->tx_led)) { kfree(local->tx_led.name); local->tx_led.name = NULL; } atomic_set(&local->assoc_led_active, 0); local->assoc_led.activate = ieee80211_assoc_led_activate; local->assoc_led.deactivate = ieee80211_assoc_led_deactivate; if (local->assoc_led.name && led_trigger_register(&local->assoc_led)) { kfree(local->assoc_led.name); local->assoc_led.name = NULL; } atomic_set(&local->radio_led_active, 0); local->radio_led.activate = ieee80211_radio_led_activate; local->radio_led.deactivate = ieee80211_radio_led_deactivate; if (local->radio_led.name && led_trigger_register(&local->radio_led)) { kfree(local->radio_led.name); local->radio_led.name = NULL; } atomic_set(&local->tpt_led_active, 0); if (local->tpt_led_trigger) { local->tpt_led.activate = ieee80211_tpt_led_activate; local->tpt_led.deactivate = ieee80211_tpt_led_deactivate; if (led_trigger_register(&local->tpt_led)) { kfree(local->tpt_led_trigger); local->tpt_led_trigger = NULL; } } }
/* A new input device with potential LEDs to connect. */ int input_led_connect(struct input_dev *dev) { int i, error = 0; struct led_classdev *leds; dev->leds = leds = kcalloc(LED_CNT, sizeof(*leds), GFP_KERNEL); if (!dev->leds) return -ENOMEM; /* lazily register missing VT LEDs */ mutex_lock(&vt_led_registered_lock); for (i = 0; i < LED_CNT; i++) if (vt_leds[i].name && test_bit(i, dev->ledbit)) { if (!vt_led_references[i]) { led_trigger_register(&vt_led_triggers[i]); /* This keyboard is first to have led i, * try to register it */ if (!led_classdev_register(NULL, &vt_leds[i])) vt_led_references[i] = 1; else led_trigger_unregister(&vt_led_triggers[i]); } else vt_led_references[i]++; } mutex_unlock(&vt_led_registered_lock); /* and register this device's LEDs */ for (i = 0; i < LED_CNT; i++) if (vt_leds[i].name && test_bit(i, dev->ledbit)) { leds[i].name = kasprintf(GFP_KERNEL, "%s::%s", dev_name(&dev->dev), vt_led_names[i]); if (!leds[i].name) { error = -ENOMEM; goto err; } leds[i].max_brightness = 1; leds[i].brightness_set = perdevice_input_led_set; leds[i].default_trigger = vt_led_triggers[i].name; } /* No issue so far, we can register for real. */ for (i = 0; i < LED_CNT; i++) if (leds[i].name) { led_classdev_register(&dev->dev, &leds[i]); leds[i].dev->platform_data = dev; perdevice_input_led_set(&leds[i], vt_leds[i].brightness); } return 0; err: input_led_delete(dev); return error; }
static int __init heartbeat_trig_init(void) { int rc = led_trigger_register(&heartbeat_led_trigger); if (!rc) { atomic_notifier_chain_register(&panic_notifier_list, &heartbeat_panic_nb); register_reboot_notifier(&heartbeat_reboot_nb); } return rc; }
static int phy_led_trigger_register(struct phy_device *phy, struct phy_led_trigger *plt, unsigned int speed) { plt->speed = speed; phy_led_trigger_format_name(phy, plt->name, sizeof(plt->name), phy_speed_to_str(speed)); plt->trigger.name = plt->name; return led_trigger_register(&plt->trigger); }
void led_trigger_register_hwtimer(const char *name, struct led_trigger **trig) { struct led_trigger *tmptrig; tmptrig = kzalloc(sizeof(struct led_trigger), GFP_KERNEL); if (tmptrig) { tmptrig->name = name; tmptrig->activate = hwtimer_trig_activate; tmptrig->deactivate = hwtimer_trig_deactivate; tmptrig->is_led_supported = hwtimer_trig_led_supported; led_trigger_register(tmptrig); } *trig = tmptrig; return; }
static bool led_tg_check(const struct xt_tgchk_param *par) { struct xt_led_info *ledinfo = par->targinfo; struct xt_led_info_internal *ledinternal; int err; if (ledinfo->id[0] == '\0') { printk(KERN_ERR KBUILD_MODNAME ": No 'id' parameter given.\n"); return false; } ledinternal = kzalloc(sizeof(struct xt_led_info_internal), GFP_KERNEL); if (!ledinternal) { printk(KERN_CRIT KBUILD_MODNAME ": out of memory\n"); return false; } ledinternal->netfilter_led_trigger.name = ledinfo->id; err = led_trigger_register(&ledinternal->netfilter_led_trigger); if (err) { printk(KERN_CRIT KBUILD_MODNAME ": led_trigger_register() failed\n"); if (err == -EEXIST) printk(KERN_ERR KBUILD_MODNAME ": Trigger name is already in use.\n"); goto exit_alloc; } /* See if we need to set up a timer */ if (ledinfo->delay > 0) setup_timer(&ledinternal->timer, led_timeout_callback, (unsigned long)ledinfo); ledinfo->internal_data = ledinternal; return true; exit_alloc: kfree(ledinternal); return false; }
static int __init touchwake_control_init(void) { int ret; touchwake_enabled = false; touch_disabled = false; device_suspended = false; timed_out = true; touchoff_delay = DEF_TOUCHOFF_DELAY; powerkey_flag = 0; pr_info("%s misc_register(%s)\n", __func__, touchwake_device.name); ret = misc_register(&touchwake_device); if (ret) { pr_err("%s misc_register(%s) fail\n", __func__, touchwake_device.name); return 1; } register_early_suspend(&touchwake_suspend_data); wake_lock_init(&touchwake_wake_lock, WAKE_LOCK_SUSPEND, "touchwake_wake"); if (sysfs_create_group(&touchwake_device.this_device->kobj, &touchwake_notification_group) < 0) { pr_err("%s sysfs_create_group fail\n", __func__); pr_err("Failed to create sysfs group for device (%s)!\n", touchwake_device.name); } do_gettimeofday(&last_powerkeypress); powerkey_flag = 0; ret = led_trigger_register(&touchwake_led_trigger); return 0; }
static int phy_led_trigger_register(struct phy_device *phy, struct phy_led_trigger *plt, unsigned int speed) { char name_suffix[PHY_LED_TRIGGER_SPEED_SUFFIX_SIZE]; plt->speed = speed; if (speed < SPEED_1000) snprintf(name_suffix, sizeof(name_suffix), "%dMbps", speed); else if (speed == SPEED_2500) snprintf(name_suffix, sizeof(name_suffix), "2.5Gbps"); else snprintf(name_suffix, sizeof(name_suffix), "%dGbps", DIV_ROUND_CLOSEST(speed, 1000)); snprintf(plt->name, sizeof(plt->name), PHY_ID_FMT ":%s", phy->mdio.bus->id, phy->mdio.addr, name_suffix); plt->trigger.name = plt->name; return led_trigger_register(&plt->trigger); }
static int heartbeat_pm_notifier(struct notifier_block *nb, unsigned long pm_event, void *unused) { int rc; switch (pm_event) { case PM_SUSPEND_PREPARE: case PM_HIBERNATION_PREPARE: case PM_RESTORE_PREPARE: led_trigger_unregister(&heartbeat_led_trigger); break; case PM_POST_SUSPEND: case PM_POST_HIBERNATION: case PM_POST_RESTORE: rc = led_trigger_register(&heartbeat_led_trigger); if (rc) pr_err("could not re-register heartbeat trigger\n"); break; default: break; } return NOTIFY_DONE; }
static int rt_timer_probe(struct platform_device *pdev) { struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0); const __be32 *divisor; struct rt_timer *rt; struct clk *clk; int ret; rt = devm_kzalloc(&pdev->dev, sizeof(*rt), GFP_KERNEL); if (!rt) { dev_err(&pdev->dev, "failed to allocate memory\n"); return -ENOMEM; } rt->irq = platform_get_irq(pdev, 0); if (!rt->irq) { dev_err(&pdev->dev, "failed to load irq\n"); return -ENOENT; } rt->membase = devm_ioremap_resource(&pdev->dev, res); if (IS_ERR(rt->membase)) return PTR_ERR(rt->membase); clk = devm_clk_get(&pdev->dev, NULL); if (IS_ERR(clk)) { dev_err(&pdev->dev, "failed get clock rate\n"); return PTR_ERR(clk); } rt->timer_freq = clk_get_rate(clk) / TMR0CTL_PRESCALE_DIV; if (!rt->timer_freq) return -EINVAL; rt->duty_cycle = 100; rt->dev = &pdev->dev; platform_set_drvdata(pdev, rt); ret = rt_timer_request(rt); if (ret) return ret; divisor = of_get_property(pdev->dev.of_node, "ralink,divisor", NULL); if (divisor) rt_timer_config(rt, be32_to_cpu(*divisor)); else rt_timer_config(rt, 200); rt->led_trigger.name = "pwmtimer", rt->led_trigger.activate = rt_timer_trig_activate, rt->led_trigger.deactivate = rt_timer_trig_deactivate, ret = led_trigger_register(&rt->led_trigger); if (ret) return ret; INIT_LIST_HEAD(&rt->gpios); dev_info(&pdev->dev, "maximum frequncy is %luHz\n", rt->timer_freq); return 0; }
static int __init wifi_trig_init(void) { return led_trigger_register(&wifi_led_trigger); }
static int __init countdown_trig_init(void) { return led_trigger_register(&countdown_led_trigger); }
static ssize_t usbdev_trig_name_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { struct led_classdev *led_cdev = dev_get_drvdata(dev); struct usbdev_trig_data *td = led_cdev->trigger_data; if (size < 0 || size >= DEV_BUS_ID_SIZE) return -EINVAL; write_lock(&td->lock); strcpy(td->device_name, buf); if (size > 0 && td->device_name[size - 1] == '\n') td->device_name[size - 1] = 0; if (td->device_name[0] != 0) { struct usbdev_trig_match match = { .device_name = td->device_name, }; /* check for existing device to update from */ usb_for_each_dev(&match, usbdev_trig_find_usb_dev); if (match.usb_dev) { if (td->usb_dev) usb_put_dev(td->usb_dev); td->usb_dev = match.usb_dev; td->last_urbnum = atomic_read(&match.usb_dev->urbnum); } /* updates LEDs, may start timers */ usbdev_trig_update_state(td); } write_unlock(&td->lock); return size; } static DEVICE_ATTR(device_name, 0644, usbdev_trig_name_show, usbdev_trig_name_store); static ssize_t usbdev_trig_interval_show(struct device *dev, struct device_attribute *attr, char *buf) { struct led_classdev *led_cdev = dev_get_drvdata(dev); struct usbdev_trig_data *td = led_cdev->trigger_data; read_lock(&td->lock); sprintf(buf, "%u\n", jiffies_to_msecs(td->interval)); read_unlock(&td->lock); return strlen(buf) + 1; } static ssize_t usbdev_trig_interval_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { struct led_classdev *led_cdev = dev_get_drvdata(dev); struct usbdev_trig_data *td = led_cdev->trigger_data; int ret = -EINVAL; char *after; unsigned long value = simple_strtoul(buf, &after, 10); size_t count = after - buf; if (*after && isspace(*after)) count++; if (count == size && value <= 10000) { write_lock(&td->lock); td->interval = msecs_to_jiffies(value); usbdev_trig_update_state(td); /* resets timer */ write_unlock(&td->lock); ret = count; } return ret; } static DEVICE_ATTR(activity_interval, 0644, usbdev_trig_interval_show, usbdev_trig_interval_store); static int usbdev_trig_notify(struct notifier_block *nb, unsigned long evt, void *data) { struct usb_device *usb_dev; struct usbdev_trig_data *td; if (evt != USB_DEVICE_ADD && evt != USB_DEVICE_REMOVE) return NOTIFY_DONE; usb_dev = data; td = container_of(nb, struct usbdev_trig_data, notifier); write_lock(&td->lock); if (strcmp(dev_name(&usb_dev->dev), td->device_name)) goto done; if (evt == USB_DEVICE_ADD) { usb_get_dev(usb_dev); if (td->usb_dev != NULL) usb_put_dev(td->usb_dev); td->usb_dev = usb_dev; td->last_urbnum = atomic_read(&usb_dev->urbnum); } else if (evt == USB_DEVICE_REMOVE) { if (td->usb_dev != NULL) { usb_put_dev(td->usb_dev); td->usb_dev = NULL; } } usbdev_trig_update_state(td); done: write_unlock(&td->lock); return NOTIFY_DONE; } /* here's the real work! */ static void usbdev_trig_timer(unsigned long arg) { struct usbdev_trig_data *td = (struct usbdev_trig_data *)arg; int new_urbnum; write_lock(&td->lock); if (!td->usb_dev || td->interval == 0) { /* * we don't need to do timer work, just reflect device presence */ if (td->usb_dev) led_set_brightness(td->led_cdev, LED_FULL); else led_set_brightness(td->led_cdev, LED_OFF); goto no_restart; } if (td->interval) new_urbnum = atomic_read(&td->usb_dev->urbnum); else new_urbnum = 0; if (td->usb_dev) { /* * Base state is ON (device is present). If there's no device, * we don't get this far and the LED is off. * OFF -> ON always * ON -> OFF on activity */ if (td->led_cdev->brightness == LED_OFF) led_set_brightness(td->led_cdev, LED_FULL); else if (td->last_urbnum != new_urbnum) led_set_brightness(td->led_cdev, LED_OFF); } else { /* * base state is OFF * ON -> OFF always * OFF -> ON on activity */ if (td->led_cdev->brightness == LED_FULL) led_set_brightness(td->led_cdev, LED_OFF); else if (td->last_urbnum != new_urbnum) led_set_brightness(td->led_cdev, LED_FULL); } td->last_urbnum = new_urbnum; mod_timer(&td->timer, jiffies + td->interval); no_restart: write_unlock(&td->lock); } static void usbdev_trig_activate(struct led_classdev *led_cdev) { struct usbdev_trig_data *td; int rc; td = kzalloc(sizeof(struct usbdev_trig_data), GFP_KERNEL); if (!td) return; rwlock_init(&td->lock); td->notifier.notifier_call = usbdev_trig_notify; td->notifier.priority = 10; setup_timer(&td->timer, usbdev_trig_timer, (unsigned long) td); td->led_cdev = led_cdev; td->interval = msecs_to_jiffies(50); led_cdev->trigger_data = td; rc = device_create_file(led_cdev->dev, &dev_attr_device_name); if (rc) goto err_out; rc = device_create_file(led_cdev->dev, &dev_attr_activity_interval); if (rc) goto err_out_device_name; usb_register_notify(&td->notifier); return; err_out_device_name: device_remove_file(led_cdev->dev, &dev_attr_device_name); err_out: led_cdev->trigger_data = NULL; kfree(td); } static void usbdev_trig_deactivate(struct led_classdev *led_cdev) { struct usbdev_trig_data *td = led_cdev->trigger_data; if (td) { usb_unregister_notify(&td->notifier); device_remove_file(led_cdev->dev, &dev_attr_device_name); device_remove_file(led_cdev->dev, &dev_attr_activity_interval); write_lock(&td->lock); if (td->usb_dev) { usb_put_dev(td->usb_dev); td->usb_dev = NULL; } write_unlock(&td->lock); del_timer_sync(&td->timer); kfree(td); } } static struct led_trigger usbdev_led_trigger = { .name = "usbdev", .activate = usbdev_trig_activate, .deactivate = usbdev_trig_deactivate, }; static int __init usbdev_trig_init(void) { return led_trigger_register(&usbdev_led_trigger); } static void __exit usbdev_trig_exit(void) { led_trigger_unregister(&usbdev_led_trigger); } module_init(usbdev_trig_init); module_exit(usbdev_trig_exit); MODULE_AUTHOR("Gabor Juhos <*****@*****.**>"); MODULE_DESCRIPTION("USB device LED trigger"); MODULE_LICENSE("GPL v2");
static int __init defon_trig_init(void) { return led_trigger_register(&defon_led_trigger); }
static int __init ledtrig_network_init(void) { led_trigger_register(&ledtrig_eth); led_trigger_register(&ledtrig_wifi); return 0; }
static int __init timer_trig_init(void) { //wake_lock_init(&led_blink_wake_lock, WAKE_LOCK_SUSPEND, "svc_led_blink"); // hanapark_DF25 return led_trigger_register(&timer_led_trigger); }
static int __init transient_trig_init(void) { return led_trigger_register(&transient_trigger); }
static int __init netdev_trig_init(void) { return led_trigger_register(&netdev_led_trigger); }
static int __init heartbeat_trig_init(void) { return led_trigger_register(&heartbeat_led_trigger); }
static int __init oneshot_trig_init(void) { return led_trigger_register(&oneshot_led_trigger); }
static int __init gpio_trig_init(void) { return led_trigger_register(&gpio_led_trigger); }
static int __init timer_trig_init(void) { return led_trigger_register(&timer_led_trigger); }
static int __init notification_trig_init(void) { return led_trigger_register(¬ification_led_trigger); }