2 * MEN 14F021P00 Board Management Controller (BMC) LEDs Driver.
4 * This is the core LED driver of the MEN 14F021P00 BMC.
5 * There are four LEDs available which can be switched on and off.
6 * STATUS LED, HOT SWAP LED, USER LED 1, USER LED 2
8 * Copyright (C) 2014 MEN Mikro Elektronik Nuernberg GmbH
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2 of the License, or (at your
13 * option) any later version.
16 #include <linux/module.h>
17 #include <linux/kernel.h>
18 #include <linux/platform_device.h>
19 #include <linux/leds.h>
20 #include <linux/i2c.h>
22 #define BMC_CMD_LED_GET_SET 0xA0
23 #define BMC_BIT_LED_STATUS BIT(0)
24 #define BMC_BIT_LED_HOTSWAP BIT(1)
25 #define BMC_BIT_LED_USER1 BIT(2)
26 #define BMC_BIT_LED_USER2 BIT(3)
28 struct menf21bmc_led
{
29 struct led_classdev cdev
;
32 struct i2c_client
*i2c_client
;
35 static struct menf21bmc_led leds
[] = {
37 .name
= "menf21bmc:led_status",
38 .led_bit
= BMC_BIT_LED_STATUS
,
41 .name
= "menf21bmc:led_hotswap",
42 .led_bit
= BMC_BIT_LED_HOTSWAP
,
45 .name
= "menf21bmc:led_user1",
46 .led_bit
= BMC_BIT_LED_USER1
,
49 .name
= "menf21bmc:led_user2",
50 .led_bit
= BMC_BIT_LED_USER2
,
54 static DEFINE_MUTEX(led_lock
);
57 menf21bmc_led_set(struct led_classdev
*led_cdev
, enum led_brightness value
)
60 struct menf21bmc_led
*led
= container_of(led_cdev
,
61 struct menf21bmc_led
, cdev
);
63 mutex_lock(&led_lock
);
64 led_val
= i2c_smbus_read_byte_data(led
->i2c_client
,
70 led_val
&= ~led
->led_bit
;
72 led_val
|= led
->led_bit
;
74 i2c_smbus_write_byte_data(led
->i2c_client
,
75 BMC_CMD_LED_GET_SET
, led_val
);
77 mutex_unlock(&led_lock
);
80 static int menf21bmc_led_probe(struct platform_device
*pdev
)
84 struct i2c_client
*i2c_client
= to_i2c_client(pdev
->dev
.parent
);
86 for (i
= 0; i
< ARRAY_SIZE(leds
); i
++) {
87 leds
[i
].cdev
.name
= leds
[i
].name
;
88 leds
[i
].cdev
.brightness_set
= menf21bmc_led_set
;
89 leds
[i
].i2c_client
= i2c_client
;
90 ret
= led_classdev_register(&pdev
->dev
, &leds
[i
].cdev
);
94 dev_info(&pdev
->dev
, "MEN 140F21P00 BMC LED device enabled\n");
99 dev_err(&pdev
->dev
, "failed to register LED device\n");
101 for (i
= i
- 1; i
>= 0; i
--)
102 led_classdev_unregister(&leds
[i
].cdev
);
107 static int menf21bmc_led_remove(struct platform_device
*pdev
)
111 for (i
= 0; i
< ARRAY_SIZE(leds
); i
++)
112 led_classdev_unregister(&leds
[i
].cdev
);
117 static struct platform_driver menf21bmc_led
= {
118 .probe
= menf21bmc_led_probe
,
119 .remove
= menf21bmc_led_remove
,
121 .name
= "menf21bmc_led",
125 module_platform_driver(menf21bmc_led
);
127 MODULE_AUTHOR("Andreas Werner <andreas.werner@men.de>");
128 MODULE_DESCRIPTION("MEN 14F021P00 BMC led driver");
129 MODULE_LICENSE("GPL v2");
130 MODULE_ALIAS("platform:menf21bmc_led");