linux/drivers/leds/leds-clevo-mail.c
<<
>>
Prefs
   1#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
   2
   3#include <linux/module.h>
   4
   5#include <linux/platform_device.h>
   6#include <linux/err.h>
   7#include <linux/leds.h>
   8
   9#include <linux/io.h>
  10#include <linux/dmi.h>
  11
  12#include <linux/i8042.h>
  13
  14#define CLEVO_MAIL_LED_OFF              0x0084
  15#define CLEVO_MAIL_LED_BLINK_1HZ        0x008A
  16#define CLEVO_MAIL_LED_BLINK_0_5HZ      0x0083
  17
  18MODULE_AUTHOR("Márton Németh <nm127@freemail.hu>");
  19MODULE_DESCRIPTION("Clevo mail LED driver");
  20MODULE_LICENSE("GPL");
  21
  22static bool __initdata nodetect;
  23module_param_named(nodetect, nodetect, bool, 0);
  24MODULE_PARM_DESC(nodetect, "Skip DMI hardware detection");
  25
  26static struct platform_device *pdev;
  27
  28static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
  29{
  30        pr_info("'%s' found\n", id->ident);
  31        return 1;
  32}
  33
  34/*
  35 * struct clevo_mail_led_dmi_table - List of known good models
  36 *
  37 * Contains the known good models this driver is compatible with.
  38 * When adding a new model try to be as strict as possible. This
  39 * makes it possible to keep the false positives (the model is
  40 * detected as working, but in reality it is not) as low as
  41 * possible.
  42 */
  43static struct dmi_system_id __initdata clevo_mail_led_dmi_table[] = {
  44        {
  45                .callback = clevo_mail_led_dmi_callback,
  46                .ident = "Clevo D410J",
  47                .matches = {
  48                        DMI_MATCH(DMI_SYS_VENDOR, "VIA"),
  49                        DMI_MATCH(DMI_PRODUCT_NAME, "K8N800"),
  50                        DMI_MATCH(DMI_PRODUCT_VERSION, "VT8204B")
  51                }
  52        },
  53        {
  54                .callback = clevo_mail_led_dmi_callback,
  55                .ident = "Clevo M5x0N",
  56                .matches = {
  57                        DMI_MATCH(DMI_SYS_VENDOR, "CLEVO Co."),
  58                        DMI_MATCH(DMI_PRODUCT_NAME, "M5x0N")
  59                }
  60        },
  61        {
  62                .callback = clevo_mail_led_dmi_callback,
  63                .ident = "Clevo M5x0V",
  64                .matches = {
  65                        DMI_MATCH(DMI_BOARD_VENDOR, "CLEVO Co. "),
  66                        DMI_MATCH(DMI_BOARD_NAME, "M5X0V "),
  67                        DMI_MATCH(DMI_PRODUCT_VERSION, "VT6198")
  68                }
  69        },
  70        {
  71                .callback = clevo_mail_led_dmi_callback,
  72                .ident = "Clevo D400P",
  73                .matches = {
  74                        DMI_MATCH(DMI_BOARD_VENDOR, "Clevo"),
  75                        DMI_MATCH(DMI_BOARD_NAME, "D400P"),
  76                        DMI_MATCH(DMI_BOARD_VERSION, "Rev.A"),
  77                        DMI_MATCH(DMI_PRODUCT_VERSION, "0106")
  78                }
  79        },
  80        {
  81                .callback = clevo_mail_led_dmi_callback,
  82                .ident = "Clevo D410V",
  83                .matches = {
  84                        DMI_MATCH(DMI_BOARD_VENDOR, "Clevo, Co."),
  85                        DMI_MATCH(DMI_BOARD_NAME, "D400V/D470V"),
  86                        DMI_MATCH(DMI_BOARD_VERSION, "SS78B"),
  87                        DMI_MATCH(DMI_PRODUCT_VERSION, "Rev. A1")
  88                }
  89        },
  90        { }
  91};
  92MODULE_DEVICE_TABLE(dmi, clevo_mail_led_dmi_table);
  93
  94static void clevo_mail_led_set(struct led_classdev *led_cdev,
  95                                enum led_brightness value)
  96{
  97        i8042_lock_chip();
  98
  99        if (value == LED_OFF)
 100                i8042_command(NULL, CLEVO_MAIL_LED_OFF);
 101        else if (value <= LED_HALF)
 102                i8042_command(NULL, CLEVO_MAIL_LED_BLINK_0_5HZ);
 103        else
 104                i8042_command(NULL, CLEVO_MAIL_LED_BLINK_1HZ);
 105
 106        i8042_unlock_chip();
 107
 108}
 109
 110static int clevo_mail_led_blink(struct led_classdev *led_cdev,
 111                                unsigned long *delay_on,
 112                                unsigned long *delay_off)
 113{
 114        int status = -EINVAL;
 115
 116        i8042_lock_chip();
 117
 118        if (*delay_on == 0 /* ms */ && *delay_off == 0 /* ms */) {
 119                /* Special case: the leds subsystem requested us to
 120                 * chose one user friendly blinking of the LED, and
 121                 * start it. Let's blink the led slowly (0.5Hz).
 122                 */
 123                *delay_on = 1000; /* ms */
 124                *delay_off = 1000; /* ms */
 125                i8042_command(NULL, CLEVO_MAIL_LED_BLINK_0_5HZ);
 126                status = 0;
 127
 128        } else if (*delay_on == 500 /* ms */ && *delay_off == 500 /* ms */) {
 129                /* blink the led with 1Hz */
 130                i8042_command(NULL, CLEVO_MAIL_LED_BLINK_1HZ);
 131                status = 0;
 132
 133        } else if (*delay_on == 1000 /* ms */ && *delay_off == 1000 /* ms */) {
 134                /* blink the led with 0.5Hz */
 135                i8042_command(NULL, CLEVO_MAIL_LED_BLINK_0_5HZ);
 136                status = 0;
 137
 138        } else {
 139                pr_debug("clevo_mail_led_blink(..., %lu, %lu),"
 140                       " returning -EINVAL (unsupported)\n",
 141                       *delay_on, *delay_off);
 142        }
 143
 144        i8042_unlock_chip();
 145
 146        return status;
 147}
 148
 149static struct led_classdev clevo_mail_led = {
 150        .name                   = "clevo::mail",
 151        .brightness_set         = clevo_mail_led_set,
 152        .blink_set              = clevo_mail_led_blink,
 153        .flags                  = LED_CORE_SUSPENDRESUME,
 154};
 155
 156static int clevo_mail_led_probe(struct platform_device *pdev)
 157{
 158        return led_classdev_register(&pdev->dev, &clevo_mail_led);
 159}
 160
 161static int clevo_mail_led_ail_le(struct platform_device *pdev)
 157{
  63 return led_clunassdev_register(&clevo_mail_led);
  64         = 0;
 159}
 59}
  26static struct plahref=lassdev   68        .              = clevo_mail_led_prUME,
  69        .              = clevo_mail_led_ailUME,
 150        .          = {
  71                .name           = KBUILD_MODNUME,
  72                .              = ,
  73        },
 154};
 155
 156static int __init  157{
  78 static int status = 0;
  79 static int  160
  81          82 } el!      .nodet) {
  83         ic int dmi_device" class=al_leheckef">dmicommand(clevo_mail_led_dmi_table);
  84        } else {
  85         ic int   86                &qup rett;Skrdware deLEVO Co. "turn 1;
  87                ug(  88                ug(  49                ug(ge.net/il_jares/s/leds-cles/l/ported)\n");
  90 159}
  11
  82 } el!      .  83                 = - us;
  95 e *ptus      .platformlassdev_r_simpdmi_table" class="sref">platformlassdev_r_simpdmcommand(KBUILD_MODNU -1ULL, NULl, 0);
  82 } el!      .(pd) {
  87         ic int statusstruct   58                 49                u    = clevo_mail_led_pr, 0);
  49           else if (sta) {
 100          95 e *);
 111                       .platformlunassdev_register" class="sref">platformlunassdev_rcommand(pd/span>);
 102         159}
 133       59}
 104                statusstruct (pd/span>);
 105
 146        return sta/span>);
 147}
 148
 149static void  span>) {
 111       .platformlunassdev_register" class="sref">platformlunassdev_rcommand(pd/span>);
 112 struct plahref=aunassdev_register(& 143
 148
  90 159}
 159}
EINVAL;
2a hre21"drivers/leds/leds-clevo-maail.c#L651" id="L65" 2class="li2e" name="L115"> 115
2a hre21"drivers/leds/leds-clevo-maiil.c#L16"  id="L16"2ass="sref2>i8042_lock_chip();
2a hre2="drive" 1name=1L90">modulea href="+code=__init" class="sref">__init< hs="line"ormlunass90 159}
 117
2a hre2="drive" 1name=1L90">modulestatus      .a href=__exde=__init" class="sexde>__init< hs="line"ormlunass90 159}
/* ms */) {
2a hre2="driv


/* ms fooss="> T 88riginal LXR soft by"> 8="line"ore" 1name=1849"> 49 lx=">LXR aailu__iys="linthis experil.c#al nassion by"="line"ora hrto:lx=@*/lx=@*/ /* ms subfooss="> lx=.*/Redpill L/< ASs="lin vider L/ s sinceef="5.