1 // SPDX-License-Identifier: GPL-2.0
3 * LED Driver for SGI Octane machines
6 #include <linux/module.h>
7 #include <linux/kernel.h>
8 #include <linux/platform_device.h>
9 #include <linux/leds.h>
11 #define IP30_LED_SYSTEM 0
12 #define IP30_LED_FAULT 1
15 struct led_classdev cdev
;
19 static void ip30led_set(struct led_classdev
*led_cdev
,
20 enum led_brightness value
)
22 struct ip30_led
*led
= container_of(led_cdev
, struct ip30_led
, cdev
);
24 writel(value
, led
->reg
);
27 static int ip30led_create(struct platform_device
*pdev
, int num
)
30 struct ip30_led
*data
;
32 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, num
);
36 data
= devm_kzalloc(&pdev
->dev
, sizeof(*data
), GFP_KERNEL
);
40 data
->reg
= devm_ioremap_resource(&pdev
->dev
, res
);
41 if (IS_ERR(data
->reg
))
42 return PTR_ERR(data
->reg
);
47 data
->cdev
.name
= "white:power";
50 data
->cdev
.name
= "red:fault";
56 data
->cdev
.brightness
= readl(data
->reg
);
57 data
->cdev
.max_brightness
= 1;
58 data
->cdev
.brightness_set
= ip30led_set
;
60 return devm_led_classdev_register(&pdev
->dev
, &data
->cdev
);
63 static int ip30led_probe(struct platform_device
*pdev
)
67 ret
= ip30led_create(pdev
, IP30_LED_SYSTEM
);
71 return ip30led_create(pdev
, IP30_LED_FAULT
);
74 static struct platform_driver ip30led_driver
= {
75 .probe
= ip30led_probe
,
81 module_platform_driver(ip30led_driver
);
83 MODULE_AUTHOR("Thomas Bogendoerfer <tbogendoerfer@suse.de>");
84 MODULE_DESCRIPTION("SGI Octane LED driver");
85 MODULE_LICENSE("GPL");
86 MODULE_ALIAS("platform:ip30-leds");