huangcm
2025-09-01 53d8e046ac1bf2ebe94f671983e3d3be059df91a
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
/*
 * Copyright (C) 2016 Allwinner.
 *
 *
 * SUNXI LEDC Controller Definition
 *
 * SPDX-License-Identifier: GPL-2.0+
 */
 
#ifndef _SUNXI_LEDC_H_
#define _SUNXI_LEDC_H_
 
 
/*interrupt ctrol*/
enum sunxi_ledc_irq_ctrl{
   LEDC_TRANS_FINISH_INT_EN     = (1 << 0),
   LEDC_FIFO_CPUREQ_INT_EN      = (1 << 1),
   LEDC_WAITDATA_TIMEOUT_INT_EN = (1 << 3),
   LEDC_FIFO_OVERFLOW_INT_EN    = (1 << 4),
   LEDC_GLOBAL_INT_EN           = (1 << 5),
};
 
/*interrupt status*/
enum sunxi_ledc_irq_status{
   LEDC_TRANS_FINISH_INT     = (1 << 0),
   LEDC_FIFO_CPUREQ_INT      = (1 << 1),
   LEDC_WAITDATA_TIMEOUT_INT = (1 << 3),
   LEDC_FIFO_OVERFLOW_INT    = (1 << 4),
   LEDC_FIFO_FULL            = (1 << 16),
   LEDC_FIFO_EMPTY           = (1 << 17),
};
 
 
#define LEDC_BASE_ADDR                  0x6700000
#define LEDC_CONTROL_OFFSET             0x50
#define FIFO_SIZE                       128
 
#define LEDC_CLOCK_ADDR                 0x03001BF0
 
struct sunxi_ledc_reg{
    volatile unsigned int ctrl;        /* control */
    volatile unsigned int time01;      /* t01 time */
    volatile unsigned int fnsh_cnt;    /* data finish count */
    volatile unsigned int rst_t;       /* reset time */
    volatile unsigned int t0_ctrl;     /* wait time0 control */
    volatile unsigned int data_reg;    /* LEDC data */
    volatile unsigned int DMA_ctrl;    /* DMA control */
    volatile unsigned int irq_ctrl;    /* interrupt control */
    volatile unsigned int irq_sta;     /* interrupt status */
    volatile unsigned int reserved;    /* reserved */
    volatile unsigned int t1_ctrl;     /* wait time1 control */
    volatile unsigned int version;     /* LEDC version */
    volatile unsigned int fifo;        /* LEDC fifo data */
};
 
struct sunxi_ccmu_reg{
    volatile unsigned int model_clk;     /* 0xBF0 LEDC clock */
    volatile unsigned int reserved1[2];     /* 0xBF4 0xBF8 */
    volatile unsigned int bus_gate;       /* 0xBFC BUS gating */
};
 
int sunxi_ledc_init(void);
 
int sunxi_set_led_brightness(unsigned int length, unsigned int g, unsigned int r, unsigned int b);
 
int sunxi_ledc_exit(void);
#endif