lin
2025-01-10 9ec4e21f2f615ef95b70a249569906799e36bace
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// SPDX-License-Identifier: GPL-2.0+
 
#include <common.h>
#include <fdt_support.h>
#include <asm/gpio.h>
#include <asm/arch/timer.h>
#include <pwm.h>
#ifdef CONFIG_SUNXI_LEDC
#include <sunxi_ledc.h>
#endif
 
static void sunxi_update_remind_GPIO_LED(int node)
{
   int i;
   u32 gpio_led_port[8];
   u32 led_port;
 
   if (fdt_getprop_u32(working_fdt, node, "gpio_led_port", gpio_led_port) < 0) {
       printf("can't get gpio_led_port\n");
   } else {
       led_port = (gpio_led_port[1] << 5) | gpio_led_port[2];
       gpio_direction_output(led_port, 1);
       for (i = 3; i > 0; i--) {
           __msdelay(1000);
           gpio_direction_output(led_port, 0);
           __msdelay(1000);
           gpio_direction_output(led_port, 1);
       }
   }
}
 
#define PWM_LED_PERIOD (10000)
#define MAX_VALUE (255)
 
struct pwm_led {
   int pwm_num;
   int value;
   char label[16];
};
 
static int _set_one_pwm_led(struct pwm_led led)
{
   unsigned int duty_ns, period_ns, level;
   if (led.value != 0) {
       period_ns = PWM_LED_PERIOD;
       level = MAX_VALUE - led.value;
       if (level == 0) /* for pwm, duty_ns shoule not be zero */
       level = 1;
       duty_ns = (period_ns * level) / MAX_VALUE;
       pwm_config(led.pwm_num, duty_ns, period_ns);
       pwm_enable(led.pwm_num);
   } else {
       pwm_disable(led.pwm_num);
   }
   return 0;
}
 
static void sunxi_update_remind_PWM_LED(int node)
{
   int i;
   struct pwm_led remind_pwm_led;
   u32 pwm_channel;
   if (fdt_getprop_u32(working_fdt, node, "pwm_led_channel", &pwm_channel) < 0) {
       printf("can't get pwm_channel\n");
       return;
   } else {
       pwm_init();
       remind_pwm_led.pwm_num = pwm_channel;
       pwm_request(remind_pwm_led.pwm_num, "pwm_led");
 
       remind_pwm_led.value = 255;
       _set_one_pwm_led(remind_pwm_led);
 
       for (i = 3; i > 0; i--) {
           __msdelay(1000);
           remind_pwm_led.value = 0;
           _set_one_pwm_led(remind_pwm_led);
           __msdelay(1000);
           remind_pwm_led.value = 255;
           _set_one_pwm_led(remind_pwm_led);
       }
   }
}
 
#ifdef CONFIG_SUNXI_LEDC
 
static void sunxi_update_remind_LEDC_LED(int node)
{
   int i;
   int led_count = 1;
   int led_g1 = 255, led_r1 = 0, led_b1 = 0;
   int led_g2 = 0, led_r2 = 0, led_b2 = 0;
 
   sunxi_ledc_init();
 
   sunxi_set_led_brightness(led_count, led_g1, led_r1, led_b1);
   for (i = 3; i > 0; i--) {
       __msdelay(1000);
       sunxi_set_led_brightness(led_count, led_g2, led_r2, led_b2);
       __msdelay(1000);
       sunxi_set_led_brightness(led_count, led_g1, led_r1, led_b1);
   }
}
 
#endif
 
void sunxi_update_remind(void)
{
   printf("==================================================\n");
   printf("|                                                |\n");
   printf("|                 update  finish                 |\n");
   printf("|                                                |\n");
   printf("==================================================\n");
   int nodeoffset;
   char *remind_type = NULL;
   nodeoffset = fdt_path_offset(working_fdt, "/soc/update_remind");
   if (nodeoffset > 0) {
           fdt_getprop_string(working_fdt, nodeoffset, "remind_type", &remind_type);
           if (strcmp(remind_type, "GPIO_LED") == 0) {
               printf("remind_type : %s\n", remind_type);
               sunxi_update_remind_GPIO_LED(nodeoffset);
           } else if (strcmp(remind_type, "PWM_LED") == 0) {
               printf("remind_type : %s\n", remind_type);
               sunxi_update_remind_PWM_LED(nodeoffset);
#ifdef CONFIG_SUNXI_LEDC
           } else if (strcmp(remind_type, "LEDC_LED") == 0) {
               printf("remind_type : %s\n", remind_type);
               sunxi_update_remind_LEDC_LED(nodeoffset);
#endif
           } else {
               printf("remind_type : other\n");
               //If you use other reminders, you need to implement them yourself.
           }
   }
}