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+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) #include <linux/leds.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #define A500_EC_LED_DELAY_USEC	(100 * 1000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 	REG_RESET_LEDS = 0x40,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 	REG_POWER_LED_ON = 0x42,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 	REG_CHARGE_LED_ON = 0x43,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 	REG_ANDROID_LEDS_OFF = 0x5a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) struct a500_led {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 	struct led_classdev cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 	const struct reg_sequence *enable_seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	struct a500_led *other;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	struct regmap *rmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) static const struct reg_sequence a500_ec_leds_reset_seq[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	REG_SEQ(REG_RESET_LEDS, 0x0, A500_EC_LED_DELAY_USEC),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	REG_SEQ(REG_ANDROID_LEDS_OFF, 0x0, A500_EC_LED_DELAY_USEC),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) static const struct reg_sequence a500_ec_white_led_enable_seq[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	REG_SEQ(REG_POWER_LED_ON, 0x0, A500_EC_LED_DELAY_USEC),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) static const struct reg_sequence a500_ec_orange_led_enable_seq[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	REG_SEQ(REG_CHARGE_LED_ON, 0x0, A500_EC_LED_DELAY_USEC),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) static int a500_ec_led_brightness_set(struct led_classdev *led_cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 				      enum led_brightness value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	struct a500_led *led = container_of(led_cdev, struct a500_led, cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	struct reg_sequence control_seq[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	unsigned int num_regs = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	if (value) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		control_seq[0] = led->enable_seq[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		 * There is no separate controls which can disable LEDs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		 * individually, there is only RESET_LEDS command that turns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		 * off both LEDs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		 * RESET_LEDS turns off both LEDs, thus restore other LED if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		 * it's turned ON.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		if (led->other->cdev.brightness)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 			num_regs = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		control_seq[0] = a500_ec_leds_reset_seq[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		control_seq[1] = led->other->enable_seq[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	return regmap_multi_reg_write(led->rmap, control_seq, num_regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) static int a500_ec_leds_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	struct a500_led *white_led, *orange_led;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	struct regmap *rmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	rmap = dev_get_regmap(pdev->dev.parent, "KB930");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	if (!rmap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	/* reset and turn off LEDs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	regmap_multi_reg_write(rmap, a500_ec_leds_reset_seq, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	white_led = devm_kzalloc(&pdev->dev, sizeof(*white_led), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	if (!white_led)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	white_led->cdev.name = "power:white";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	white_led->cdev.brightness_set_blocking = a500_ec_led_brightness_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	white_led->cdev.flags = LED_CORE_SUSPENDRESUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	white_led->cdev.max_brightness = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	white_led->enable_seq = a500_ec_white_led_enable_seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	white_led->rmap = rmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	orange_led = devm_kzalloc(&pdev->dev, sizeof(*orange_led), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	if (!orange_led)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	orange_led->cdev.name = "power:orange";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	orange_led->cdev.brightness_set_blocking = a500_ec_led_brightness_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	orange_led->cdev.flags = LED_CORE_SUSPENDRESUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	orange_led->cdev.max_brightness = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	orange_led->enable_seq = a500_ec_orange_led_enable_seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	orange_led->rmap = rmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	white_led->other = orange_led;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	orange_led->other = white_led;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	err = devm_led_classdev_register(&pdev->dev, &white_led->cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		dev_err(&pdev->dev, "failed to register white LED\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	err = devm_led_classdev_register(&pdev->dev, &orange_led->cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		dev_err(&pdev->dev, "failed to register orange LED\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) static struct platform_driver a500_ec_leds_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		.name = "acer-a500-iconia-leds",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	.probe = a500_ec_leds_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) module_platform_driver(a500_ec_leds_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) MODULE_DESCRIPTION("LED driver for Acer Iconia Tab A500 Power Button");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) MODULE_AUTHOR("Dmitry Osipenko <digetx@gmail.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) MODULE_ALIAS("platform:acer-a500-iconia-leds");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) MODULE_LICENSE("GPL");