Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * h3xxx atmel micro companion support, notification LED subdevice
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Author : Linus Walleij <linus.walleij@linaro.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/mfd/ipaq-micro.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/leds.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #define LED_YELLOW	0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #define LED_GREEN	0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #define LED_EN       (1 << 4) /* LED ON/OFF 0:off, 1:on                       */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #define LED_AUTOSTOP (1 << 5) /* LED ON/OFF auto stop set 0:disable, 1:enable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #define LED_ALWAYS   (1 << 6) /* LED Interrupt Mask 0:No mask, 1:mask         */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) static int micro_leds_brightness_set(struct led_classdev *led_cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 				      enum led_brightness value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	struct ipaq_micro *micro = dev_get_drvdata(led_cdev->dev->parent->parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	 * In this message:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	 * Byte 0 = LED color: 0 = yellow, 1 = green
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	 *          yellow LED is always ~30 blinks per minute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	 * Byte 1 = duration (flags?) appears to be ignored
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	 * Byte 2 = green ontime in 1/10 sec (deciseconds)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	 *          1 = 1/10 second
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	 *          0 = 256/10 second
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	 * Byte 3 = green offtime in 1/10 sec (deciseconds)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	 *          1 = 1/10 second
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	 *          0 = 256/10 seconds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	struct ipaq_micro_msg msg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 		.id = MSG_NOTIFY_LED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 		.tx_len = 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	msg.tx_data[0] = LED_GREEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	msg.tx_data[1] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	if (value) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		msg.tx_data[2] = 0; /* Duty cycle 256 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		msg.tx_data[3] = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		msg.tx_data[2] = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		msg.tx_data[3] = 0; /* Duty cycle 256 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	return ipaq_micro_tx_msg_sync(micro, &msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) /* Maximum duty cycle in ms 256/10 sec = 25600 ms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) #define IPAQ_LED_MAX_DUTY 25600
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) static int micro_leds_blink_set(struct led_classdev *led_cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 				unsigned long *delay_on,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 				unsigned long *delay_off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	struct ipaq_micro *micro = dev_get_drvdata(led_cdev->dev->parent->parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	 * In this message:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	 * Byte 0 = LED color: 0 = yellow, 1 = green
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	 *          yellow LED is always ~30 blinks per minute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	 * Byte 1 = duration (flags?) appears to be ignored
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	 * Byte 2 = green ontime in 1/10 sec (deciseconds)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	 *          1 = 1/10 second
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	 *          0 = 256/10 second
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	 * Byte 3 = green offtime in 1/10 sec (deciseconds)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	 *          1 = 1/10 second
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	 *          0 = 256/10 seconds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	struct ipaq_micro_msg msg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		.id = MSG_NOTIFY_LED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		.tx_len = 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	msg.tx_data[0] = LED_GREEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	if (*delay_on > IPAQ_LED_MAX_DUTY ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	    *delay_off > IPAQ_LED_MAX_DUTY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	if (*delay_on == 0 && *delay_off == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		*delay_on = 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		*delay_off = 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	msg.tx_data[1] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	if (*delay_on >= IPAQ_LED_MAX_DUTY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		msg.tx_data[2] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		msg.tx_data[2] = (u8) DIV_ROUND_CLOSEST(*delay_on, 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	if (*delay_off >= IPAQ_LED_MAX_DUTY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		msg.tx_data[3] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		msg.tx_data[3] = (u8) DIV_ROUND_CLOSEST(*delay_off, 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	return ipaq_micro_tx_msg_sync(micro, &msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) static struct led_classdev micro_led = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	.name			= "led-ipaq-micro",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	.brightness_set_blocking = micro_leds_brightness_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	.blink_set		= micro_leds_blink_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	.flags			= LED_CORE_SUSPENDRESUME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) static int micro_leds_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	ret = devm_led_classdev_register(&pdev->dev, &micro_led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		dev_err(&pdev->dev, "registering led failed: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	dev_info(&pdev->dev, "iPAQ micro notification LED driver\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) static struct platform_driver micro_leds_device_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		.name    = "ipaq-micro-leds",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	.probe   = micro_leds_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) module_platform_driver(micro_leds_device_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) MODULE_DESCRIPTION("driver for iPAQ Atmel micro leds");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) MODULE_ALIAS("platform:ipaq-micro-leds");