18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Driver for the LED found on the EBSA110 machine 48c2ecf20Sopenharmony_ci * Based on Versatile and RealView machine LED code 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * Author: Bryan Wu <bryan.wu@canonical.com> 78c2ecf20Sopenharmony_ci */ 88c2ecf20Sopenharmony_ci#include <linux/kernel.h> 98c2ecf20Sopenharmony_ci#include <linux/init.h> 108c2ecf20Sopenharmony_ci#include <linux/io.h> 118c2ecf20Sopenharmony_ci#include <linux/slab.h> 128c2ecf20Sopenharmony_ci#include <linux/leds.h> 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#include <asm/mach-types.h> 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci#include "core.h" 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci#if defined(CONFIG_NEW_LEDS) && defined(CONFIG_LEDS_CLASS) 198c2ecf20Sopenharmony_cistatic void ebsa110_led_set(struct led_classdev *cdev, 208c2ecf20Sopenharmony_ci enum led_brightness b) 218c2ecf20Sopenharmony_ci{ 228c2ecf20Sopenharmony_ci u8 reg = __raw_readb(SOFT_BASE); 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci if (b != LED_OFF) 258c2ecf20Sopenharmony_ci reg |= 0x80; 268c2ecf20Sopenharmony_ci else 278c2ecf20Sopenharmony_ci reg &= ~0x80; 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci __raw_writeb(reg, SOFT_BASE); 308c2ecf20Sopenharmony_ci} 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_cistatic enum led_brightness ebsa110_led_get(struct led_classdev *cdev) 338c2ecf20Sopenharmony_ci{ 348c2ecf20Sopenharmony_ci u8 reg = __raw_readb(SOFT_BASE); 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci return (reg & 0x80) ? LED_FULL : LED_OFF; 378c2ecf20Sopenharmony_ci} 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_cistatic int __init ebsa110_leds_init(void) 408c2ecf20Sopenharmony_ci{ 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci struct led_classdev *cdev; 438c2ecf20Sopenharmony_ci int ret; 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci if (!machine_is_ebsa110()) 468c2ecf20Sopenharmony_ci return -ENODEV; 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci cdev = kzalloc(sizeof(*cdev), GFP_KERNEL); 498c2ecf20Sopenharmony_ci if (!cdev) 508c2ecf20Sopenharmony_ci return -ENOMEM; 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci cdev->name = "ebsa110:0"; 538c2ecf20Sopenharmony_ci cdev->brightness_set = ebsa110_led_set; 548c2ecf20Sopenharmony_ci cdev->brightness_get = ebsa110_led_get; 558c2ecf20Sopenharmony_ci cdev->default_trigger = "heartbeat"; 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci ret = led_classdev_register(NULL, cdev); 588c2ecf20Sopenharmony_ci if (ret < 0) { 598c2ecf20Sopenharmony_ci kfree(cdev); 608c2ecf20Sopenharmony_ci return ret; 618c2ecf20Sopenharmony_ci } 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci return 0; 648c2ecf20Sopenharmony_ci} 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci/* 678c2ecf20Sopenharmony_ci * Since we may have triggers on any subsystem, defer registration 688c2ecf20Sopenharmony_ci * until after subsystem_init. 698c2ecf20Sopenharmony_ci */ 708c2ecf20Sopenharmony_cifs_initcall(ebsa110_leds_init); 718c2ecf20Sopenharmony_ci#endif 72