commit
51b4a639e4
@ -0,0 +1,19 @@ |
||||
#ifndef __REBOOT_MODE_H |
||||
#define __REBOOT_MODE_H |
||||
|
||||
/* high 24 bits is tag, low 8 bits is type */ |
||||
#define REBOOT_FLAG 0x5242C300 |
||||
/* normal boot */ |
||||
#define BOOT_NORMAL (REBOOT_FLAG + 0) |
||||
/* enter loader rockusb mode */ |
||||
#define BOOT_LOADER (REBOOT_FLAG + 1) |
||||
/* enter recovery */ |
||||
#define BOOT_RECOVERY (REBOOT_FLAG + 3) |
||||
/* enter fastboot mode */ |
||||
#define BOOT_FASTBOOT (REBOOT_FLAG + 9) |
||||
/* enter charging mode */ |
||||
#define BOOT_CHARGING (REBOOT_FLAG + 11) |
||||
/* enter usb mass storage mode */ |
||||
#define BOOT_UMS (REBOOT_FLAG + 12) |
||||
|
||||
#endif |
@ -0,0 +1,122 @@ |
||||
/*
|
||||
* (C) Copyright 2015 Rockchip Electronics Co., Ltd |
||||
* |
||||
* SPDX-License-Identifier: GPL-2.0+ |
||||
*/ |
||||
|
||||
#include <common.h> |
||||
#include <clk.h> |
||||
#include <dm.h> |
||||
#include <ram.h> |
||||
#include <asm/io.h> |
||||
#include <asm/arch/clock.h> |
||||
#include <asm/arch/periph.h> |
||||
#include <asm/arch/grf_rk3036.h> |
||||
#include <asm/arch/boot_mode.h> |
||||
#include <asm/arch/sdram_rk3036.h> |
||||
#include <asm/gpio.h> |
||||
#include <dm/pinctrl.h> |
||||
|
||||
DECLARE_GLOBAL_DATA_PTR; |
||||
|
||||
#define GRF_BASE 0x20008000 |
||||
|
||||
static void setup_boot_mode(void) |
||||
{ |
||||
struct rk3036_grf *const grf = (void *)GRF_BASE; |
||||
int boot_mode = readl(&grf->os_reg[4]); |
||||
|
||||
debug("boot mode %x.\n", boot_mode); |
||||
|
||||
/* Clear boot mode */ |
||||
writel(BOOT_NORMAL, &grf->os_reg[4]); |
||||
|
||||
switch (boot_mode) { |
||||
case BOOT_FASTBOOT: |
||||
printf("enter fastboot!\n"); |
||||
setenv("preboot", "setenv preboot; fastboot usb0"); |
||||
break; |
||||
case BOOT_UMS: |
||||
printf("enter UMS!\n"); |
||||
setenv("preboot", "setenv preboot; ums mmc 0"); |
||||
break; |
||||
} |
||||
} |
||||
|
||||
__weak int rk_board_late_init(void) |
||||
{ |
||||
return 0; |
||||
} |
||||
|
||||
int board_late_init(void) |
||||
{ |
||||
setup_boot_mode(); |
||||
|
||||
return rk_board_late_init(); |
||||
} |
||||
|
||||
int board_init(void) |
||||
{ |
||||
return 0; |
||||
} |
||||
|
||||
int dram_init(void) |
||||
{ |
||||
gd->ram_size = sdram_size(); |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
#ifndef CONFIG_SYS_DCACHE_OFF |
||||
void enable_caches(void) |
||||
{ |
||||
/* Enable D-cache. I-cache is already enabled in start.S */ |
||||
dcache_enable(); |
||||
} |
||||
#endif |
||||
|
||||
#if defined(CONFIG_USB_GADGET) && defined(CONFIG_USB_GADGET_DWC2_OTG) |
||||
#include <usb.h> |
||||
#include <usb/dwc2_udc.h> |
||||
|
||||
static struct dwc2_plat_otg_data rk3036_otg_data = { |
||||
.rx_fifo_sz = 512, |
||||
.np_tx_fifo_sz = 16, |
||||
.tx_fifo_sz = 128, |
||||
}; |
||||
|
||||
int board_usb_init(int index, enum usb_init_type init) |
||||
{ |
||||
int node; |
||||
const char *mode; |
||||
bool matched = false; |
||||
const void *blob = gd->fdt_blob; |
||||
|
||||
/* find the usb_otg node */ |
||||
node = fdt_node_offset_by_compatible(blob, -1, |
||||
"rockchip,rk3288-usb"); |
||||
|
||||
while (node > 0) { |
||||
mode = fdt_getprop(blob, node, "dr_mode", NULL); |
||||
if (mode && strcmp(mode, "otg") == 0) { |
||||
matched = true; |
||||
break; |
||||
} |
||||
|
||||
node = fdt_node_offset_by_compatible(blob, node, |
||||
"rockchip,rk3288-usb"); |
||||
} |
||||
if (!matched) { |
||||
debug("Not found usb_otg device\n"); |
||||
return -ENODEV; |
||||
} |
||||
rk3036_otg_data.regs_otg = fdtdec_get_addr(blob, node, "reg"); |
||||
|
||||
return dwc2_udc_probe(&rk3036_otg_data); |
||||
} |
||||
|
||||
int board_usb_cleanup(int index, enum usb_init_type init) |
||||
{ |
||||
return 0; |
||||
} |
||||
#endif |
@ -0,0 +1,159 @@ |
||||
/*
|
||||
* Copyright (C) 2016 Rockchip Electronics Co., Ltd |
||||
* |
||||
* Based on kernel drivers/regulator/pwm-regulator.c |
||||
* Copyright (C) 2014 - STMicroelectronics Inc. |
||||
* Author: Lee Jones <lee.jones@linaro.org> |
||||
* |
||||
* SPDX-License-Identifier: GPL-2.0+ |
||||
*/ |
||||
|
||||
#include <common.h> |
||||
#include <dm.h> |
||||
#include <errno.h> |
||||
#include <pwm.h> |
||||
#include <power/regulator.h> |
||||
#include <libfdt.h> |
||||
#include <fdt_support.h> |
||||
#include <fdtdec.h> |
||||
|
||||
DECLARE_GLOBAL_DATA_PTR; |
||||
|
||||
struct pwm_regulator_info { |
||||
/* pwm id corresponding to the PWM driver */ |
||||
int pwm_id; |
||||
/* the period of one PWM cycle */ |
||||
int period_ns; |
||||
struct udevice *pwm; |
||||
/* initialize voltage of regulator */ |
||||
unsigned int init_voltage; |
||||
/* the maximum voltage of regulator */ |
||||
unsigned int max_voltage; |
||||
/* the minimum voltage of regulator */ |
||||
unsigned int min_voltage; |
||||
/* the current voltage of regulator */ |
||||
unsigned int volt_uV; |
||||
}; |
||||
|
||||
static int pwm_regulator_enable(struct udevice *dev, bool enable) |
||||
{ |
||||
struct pwm_regulator_info *priv = dev_get_priv(dev); |
||||
|
||||
return pwm_set_enable(priv->pwm, priv->pwm_id, enable); |
||||
} |
||||
|
||||
static int pwm_voltage_to_duty_cycle_percentage(struct udevice *dev, int req_uV) |
||||
{ |
||||
struct pwm_regulator_info *priv = dev_get_priv(dev); |
||||
int min_uV = priv->min_voltage; |
||||
int max_uV = priv->max_voltage; |
||||
int diff = max_uV - min_uV; |
||||
|
||||
return 100 - (((req_uV * 100) - (min_uV * 100)) / diff); |
||||
} |
||||
|
||||
static int pwm_regulator_get_voltage(struct udevice *dev) |
||||
{ |
||||
struct pwm_regulator_info *priv = dev_get_priv(dev); |
||||
|
||||
return priv->volt_uV; |
||||
} |
||||
|
||||
static int pwm_regulator_set_voltage(struct udevice *dev, int uvolt) |
||||
{ |
||||
struct pwm_regulator_info *priv = dev_get_priv(dev); |
||||
int duty_cycle; |
||||
int ret = 0; |
||||
|
||||
duty_cycle = pwm_voltage_to_duty_cycle_percentage(dev, uvolt); |
||||
|
||||
ret = pwm_set_config(priv->pwm, priv->pwm_id, |
||||
(priv->period_ns / 100) * duty_cycle, priv->period_ns); |
||||
if (ret) { |
||||
dev_err(dev, "Failed to configure PWM\n"); |
||||
return ret; |
||||
} |
||||
|
||||
ret = pwm_set_enable(priv->pwm, priv->pwm_id, true); |
||||
if (ret) { |
||||
dev_err(dev, "Failed to enable PWM\n"); |
||||
return ret; |
||||
} |
||||
priv->volt_uV = uvolt; |
||||
return ret; |
||||
} |
||||
|
||||
static int pwm_regulator_ofdata_to_platdata(struct udevice *dev) |
||||
{ |
||||
struct pwm_regulator_info *priv = dev_get_priv(dev); |
||||
struct fdtdec_phandle_args args; |
||||
const void *blob = gd->fdt_blob; |
||||
int node = dev->of_offset; |
||||
int ret; |
||||
|
||||
ret = fdtdec_parse_phandle_with_args(blob, node, "pwms", "#pwm-cells", |
||||
0, 0, &args); |
||||
if (ret) { |
||||
debug("%s: Cannot get PWM phandle: ret=%d\n", __func__, ret); |
||||
return ret; |
||||
} |
||||
/* TODO: pwm_id here from device tree if needed */ |
||||
|
||||
priv->period_ns = args.args[1]; |
||||
|
||||
priv->init_voltage = fdtdec_get_int(blob, node, |
||||
"regulator-init-microvolt", -1); |
||||
if (priv->init_voltage < 0) { |
||||
printf("Cannot find regulator pwm init_voltage\n"); |
||||
return -EINVAL; |
||||
} |
||||
|
||||
ret = uclass_get_device_by_of_offset(UCLASS_PWM, args.node, &priv->pwm); |
||||
if (ret) { |
||||
debug("%s: Cannot get PWM: ret=%d\n", __func__, ret); |
||||
return ret; |
||||
} |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
static int pwm_regulator_probe(struct udevice *dev) |
||||
{ |
||||
struct pwm_regulator_info *priv = dev_get_priv(dev); |
||||
struct dm_regulator_uclass_platdata *uc_pdata; |
||||
|
||||
uc_pdata = dev_get_uclass_platdata(dev); |
||||
|
||||
uc_pdata->type = REGULATOR_TYPE_BUCK; |
||||
uc_pdata->mode_count = 0; |
||||
priv->max_voltage = uc_pdata->max_uV; |
||||
priv->min_voltage = uc_pdata->min_uV; |
||||
|
||||
if (priv->init_voltage) |
||||
pwm_regulator_set_voltage(dev, priv->init_voltage); |
||||
|
||||
pwm_regulator_enable(dev, 1); |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
static const struct dm_regulator_ops pwm_regulator_ops = { |
||||
.get_value = pwm_regulator_get_voltage, |
||||
.set_value = pwm_regulator_set_voltage, |
||||
.set_enable = pwm_regulator_enable, |
||||
}; |
||||
|
||||
static const struct udevice_id pwm_regulator_ids[] = { |
||||
{ .compatible = "pwm-regulator" }, |
||||
{ } |
||||
}; |
||||
|
||||
U_BOOT_DRIVER(pwm_regulator) = { |
||||
.name = "pwm_regulator", |
||||
.id = UCLASS_REGULATOR, |
||||
.ops = &pwm_regulator_ops, |
||||
.probe = pwm_regulator_probe, |
||||
.of_match = pwm_regulator_ids, |
||||
.ofdata_to_platdata = pwm_regulator_ofdata_to_platdata, |
||||
.priv_auto_alloc_size = sizeof(struct pwm_regulator_info), |
||||
}; |
Loading…
Reference in new issue