2018-03-02 06:50:00 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "utils.h"
|
|
|
|
#include "car.h"
|
|
|
|
#include "timers.h"
|
|
|
|
|
2018-03-05 22:59:46 +00:00
|
|
|
static inline uint32_t get_special_clk_reg(CarDevice dev) {
|
2018-03-02 06:50:00 +00:00
|
|
|
switch (dev) {
|
|
|
|
case CARDEVICE_UARTA: return 0x178;
|
|
|
|
case CARDEVICE_UARTB: return 0x17C;
|
|
|
|
case CARDEVICE_I2C1: return 0x124;
|
|
|
|
case CARDEVICE_I2C5: return 0x128;
|
|
|
|
case CARDEVICE_BPMP: return 0;
|
|
|
|
default: generic_panic();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-05 22:59:46 +00:00
|
|
|
static inline uint32_t get_special_clk_val(CarDevice dev) {
|
2018-03-02 06:50:00 +00:00
|
|
|
switch (dev) {
|
|
|
|
case CARDEVICE_UARTA: return 0;
|
|
|
|
case CARDEVICE_UARTB: return 0;
|
|
|
|
case CARDEVICE_I2C1: return (6 << 29);
|
|
|
|
case CARDEVICE_I2C5: return (6 << 29);
|
|
|
|
case CARDEVICE_BPMP: return 0;
|
|
|
|
default: generic_panic();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-09 23:40:11 +00:00
|
|
|
static uint32_t g_clk_reg_offsets[NUM_CAR_BANKS] = {0x010, 0x014, 0x018, 0x360, 0x364, 0x280, 0x298};
|
|
|
|
static uint32_t g_rst_reg_offsets[NUM_CAR_BANKS] = {0x004, 0x008, 0x00C, 0x358, 0x35C, 0x28C, 0x2A4};
|
2018-03-02 06:50:00 +00:00
|
|
|
|
2018-03-05 22:59:46 +00:00
|
|
|
void clk_enable(CarDevice dev) {
|
2018-03-02 06:50:00 +00:00
|
|
|
uint32_t special_reg;
|
|
|
|
if ((special_reg = get_special_clk_reg(dev))) {
|
|
|
|
MAKE_CAR_REG(special_reg) = get_special_clk_val(dev);
|
|
|
|
}
|
2018-03-04 13:04:49 +00:00
|
|
|
MAKE_CAR_REG(g_clk_reg_offsets[dev >> 5]) |= BIT(dev & 0x1F);
|
2018-03-02 06:50:00 +00:00
|
|
|
}
|
|
|
|
|
2018-03-05 22:59:46 +00:00
|
|
|
void clk_disable(CarDevice dev) {
|
2018-03-09 23:40:11 +00:00
|
|
|
MAKE_CAR_REG(g_clk_reg_offsets[dev >> 5]) &= ~(BIT(dev & 0x1F));
|
2018-03-02 06:50:00 +00:00
|
|
|
}
|
|
|
|
|
2018-03-05 22:59:46 +00:00
|
|
|
void rst_enable(CarDevice dev) {
|
2018-03-04 13:04:49 +00:00
|
|
|
MAKE_CAR_REG(g_rst_reg_offsets[dev >> 5]) |= BIT(dev & 0x1F);
|
2018-03-02 06:50:00 +00:00
|
|
|
}
|
|
|
|
|
2018-03-05 22:59:46 +00:00
|
|
|
void rst_disable(CarDevice dev) {
|
2018-03-09 23:40:11 +00:00
|
|
|
MAKE_CAR_REG(g_rst_reg_offsets[dev >> 5]) &= ~(BIT(dev & 0x1F));
|
2018-03-02 06:50:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-05 22:59:46 +00:00
|
|
|
void clkrst_enable(CarDevice dev) {
|
2018-03-02 06:50:00 +00:00
|
|
|
clk_enable(dev);
|
|
|
|
rst_disable(dev);
|
|
|
|
}
|
|
|
|
|
2018-03-05 22:59:46 +00:00
|
|
|
void clkrst_disable(CarDevice dev) {
|
2018-03-02 06:50:00 +00:00
|
|
|
rst_enable(dev);
|
|
|
|
clk_disable(dev);
|
|
|
|
}
|
|
|
|
|
2018-03-05 22:59:46 +00:00
|
|
|
void clkrst_reboot(CarDevice dev) {
|
2018-03-02 06:50:00 +00:00
|
|
|
clkrst_disable(dev);
|
|
|
|
clkrst_enable(dev);
|
|
|
|
}
|