diff --git a/MAINTAINERS b/MAINTAINERS index 51f5ddf4bf38..323d86be050e 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -13461,7 +13461,7 @@ M: Yun Cai F: drivers/amlogic/efuse/* F: include/linux/amlogic/efuse.h -AMLOGIC reboot +AMLOGIC reboot for gx and M8b M: Jianxin Pan F: drivers/amlogic/reboot/* diff --git a/arch/arm/boot/dts/amlogic/meson8b.dtsi b/arch/arm/boot/dts/amlogic/meson8b.dtsi index 42b76ab9ec68..e2175af909d1 100644 --- a/arch/arm/boot/dts/amlogic/meson8b.dtsi +++ b/arch/arm/boot/dts/amlogic/meson8b.dtsi @@ -952,5 +952,11 @@ dwc2_b { reg = <0xc110875c 0x4>, <0xc1108764 0x4>; }; + + aml_reboot{ + compatible = "aml, reboot_m8b"; + status = "okay"; + }; + }; /* end of soc*/ }; /* end of / */ diff --git a/arch/arm/configs/meson32_defconfig b/arch/arm/configs/meson32_defconfig index 916ed2539194..f85036ca3b79 100644 --- a/arch/arm/configs/meson32_defconfig +++ b/arch/arm/configs/meson32_defconfig @@ -180,6 +180,8 @@ CONFIG_AMLOGIC_SARADC=y CONFIG_AMLOGIC_REMOTE=y CONFIG_AMLOGIC_MESON_REMOTE=y CONFIG_AMLOGIC_EFUSE=y +CONFIG_AMLOGIC_REBOOT=y +CONFIG_AMLOGIC_M8B_REBOOT=y CONFIG_AMLOGIC_CPU_HOTPLUG=y CONFIG_AMLOGIC_PWM=y CONFIG_AMLOGIC_MMC=y diff --git a/arch/arm64/configs/meson64_defconfig b/arch/arm64/configs/meson64_defconfig index c475fc926ba4..c4850451baa6 100644 --- a/arch/arm64/configs/meson64_defconfig +++ b/arch/arm64/configs/meson64_defconfig @@ -192,6 +192,7 @@ CONFIG_AMLOGIC_REMOTE=y CONFIG_AMLOGIC_MESON_REMOTE=y CONFIG_AMLOGIC_EFUSE=y CONFIG_AMLOGIC_REBOOT=y +CONFIG_AMLOGIC_GX_REBOOT=y CONFIG_AMLOGIC_INTERNAL_PHY=y CONFIG_AMLOGIC_CPU_HOTPLUG=y CONFIG_AMLOGIC_PWM=y diff --git a/drivers/amlogic/reboot/Kconfig b/drivers/amlogic/reboot/Kconfig index 08a40f5838e3..9adffd421194 100644 --- a/drivers/amlogic/reboot/Kconfig +++ b/drivers/amlogic/reboot/Kconfig @@ -8,3 +8,23 @@ config AMLOGIC_REBOOT or poweroff driver. +config AMLOGIC_GX_REBOOT + bool "Amlogic reboot gx" + depends on AMLOGIC_REBOOT + default n + help + This is the Amlogic GX reboot driver. + +config AMLOGIC_M8B_REBOOT + bool "Amlogic reboot m8b" + depends on AMLOGIC_REBOOT + default n + help + This is the Amlogic M8b reboot driver. + +config AMLOGIC_M8B_REBOOT_UBOOT_SUSPEND + bool "Amlogic reboot uboot suspend" + depends on AMLOGIC_M8B_REBOOT + default n + help + This is the Amlogic M8b reboot uboot suspend driver. \ No newline at end of file diff --git a/drivers/amlogic/reboot/Makefile b/drivers/amlogic/reboot/Makefile index 46f57713906e..369e0dfc1879 100644 --- a/drivers/amlogic/reboot/Makefile +++ b/drivers/amlogic/reboot/Makefile @@ -1,5 +1,5 @@ # #Makefile for the RESET dirver # -obj-$(CONFIG_AMLOGIC_REBOOT) += reboot.o - +obj-$(CONFIG_AMLOGIC_GX_REBOOT) += reboot.o +obj-$(CONFIG_AMLOGIC_M8B_REBOOT) += reboot_m8b.o diff --git a/drivers/amlogic/reboot/reboot_m8b.c b/drivers/amlogic/reboot/reboot_m8b.c new file mode 100644 index 000000000000..a3e3e77c089f --- /dev/null +++ b/drivers/amlogic/reboot/reboot_m8b.c @@ -0,0 +1,140 @@ +/* + * drivers/amlogic/reboot/reboot_m8b.c + * + * Copyright (C) 2017 Amlogic, Inc. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + + + +#define WATCHDOG_ENABLE_BIT (1<<19) +#define DUAL_CORE_RESET (3<<24) +#define AO_RTI_STATUS_REG1 ((0x00 << 10) | (0x01 << 2)) +#define VENC_VDAC_SETTING 0x1b7e +#define WATCHDOG_RESET 0x2641 +#define WATCHDOG_TC 0x2640 + +#ifdef AMLOGIC_M8B_REBOOT_UBOOT_SUSPEND +static int reboot_flag; +static int __init do_parse_args(char *line) +{ + if (strcmp(line, "uboot_suspend") == 0) + reboot_flag = 1; + pr_info("reboot_flag=%x\n", reboot_flag); + return 1; +} +__setup("reboot_args=", do_parse_args); +#endif + +static inline void arch_reset(char mode, const char *cmd) +{ + aml_write_cbus(VENC_VDAC_SETTING, 0xf); + aml_write_cbus(WATCHDOG_RESET, 0); + aml_write_cbus(WATCHDOG_TC, + DUAL_CORE_RESET | WATCHDOG_ENABLE_BIT | 100); + while (1) + cpu_do_idle(); +} + + +void meson_common_restart(char mode, const char *cmd) +{ + u32 reboot_reason = MESON_NORMAL_BOOT; + + if (cmd) { + if (strcmp(cmd, "charging_reboot") == 0) + reboot_reason = MESON_CHARGING_REBOOT; + else if (strcmp(cmd, "recovery") == 0 || + strcmp(cmd, "factory_reset") == 0) + reboot_reason = MESON_FACTORY_RESET_REBOOT; + else if (strcmp(cmd, "update") == 0) + reboot_reason = MESON_UPDATE_REBOOT; + else if (strcmp(cmd, "report_crash") == 0) + reboot_reason = MESON_CRASH_REBOOT; + else if (strcmp(cmd, "factory_testl_reboot") == 0) + reboot_reason = MESON_FACTORY_TEST_REBOOT; + else if (strcmp(cmd, "switch_system") == 0) + reboot_reason = MESON_SYSTEM_SWITCH_REBOOT; + else if (strcmp(cmd, "safe_mode") == 0) + reboot_reason = MESON_SAFE_REBOOT; + else if (strcmp(cmd, "lock_system") == 0) + reboot_reason = MESON_LOCK_REBOOT; + else if (strcmp(cmd, "usb_burner_reboot") == 0) + reboot_reason = MESON_USB_BURNER_REBOOT; + else if (strcmp(cmd, "uboot_suspend") == 0) + reboot_reason = MESON_UBOOT_SUSPEND; + } + aml_write_aobus(AO_RTI_STATUS_REG1, reboot_reason); + pr_info("reboot_reason(0x%x) = 0x%x\n", AO_RTI_STATUS_REG1, + aml_read_aobus(AO_RTI_STATUS_REG1)); + arch_reset(mode, cmd); +} + +static void do_aml_restart(enum reboot_mode reboot_mode, const char *cmd) +{ + pr_info("meson power off\n"); +#ifdef AMLOGIC_M8B_REBOOT_UBOOT_SUSPEND + if (reboot_flag) + meson_common_restart('h', "uboot_suspend"); + else +#endif + meson_common_restart('h', "charging_reboot"); +} + +static int aml_restart_probe(struct platform_device *pdev) +{ + arm_pm_restart = do_aml_restart; + return 0; +} + +static const struct of_device_id of_aml_restart_match[] = { + { .compatible = "aml, reboot_m8b", }, + {}, +}; +MODULE_DEVICE_TABLE(of, of_aml_restart_match); + +static struct platform_driver aml_restart_driver = { + .probe = aml_restart_probe, + .driver = { + .name = "aml-restart", + .of_match_table = of_match_ptr(of_aml_restart_match), + }, +}; + +static int __init aml_restart_init(void) +{ + return platform_driver_register(&aml_restart_driver); +} +device_initcall(aml_restart_init); + diff --git a/include/linux/amlogic/reboot_m8b.h b/include/linux/amlogic/reboot_m8b.h new file mode 100644 index 000000000000..a57b59422349 --- /dev/null +++ b/include/linux/amlogic/reboot_m8b.h @@ -0,0 +1,33 @@ +#ifndef __reboot_m8b_h_ +#define __reboot_m8b_h_ +/* + * include/linux/amlogic/reboot_m8b.h + * + * Copyright (C) 2017 Amlogic, Inc. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + */ + +/*******************************************************************/ +#define MESON_CHARGING_REBOOT 0x0 +#define MESON_NORMAL_BOOT 0x01010101 +#define MESON_FACTORY_RESET_REBOOT 0x02020202 +#define MESON_UPDATE_REBOOT 0x03030303 +#define MESON_CRASH_REBOOT 0x04040404 +#define MESON_FACTORY_TEST_REBOOT 0x05050505 +#define MESON_SYSTEM_SWITCH_REBOOT 0x06060606 +#define MESON_SAFE_REBOOT 0x07070707 +#define MESON_LOCK_REBOOT 0x08080808 +#define MESON_USB_BURNER_REBOOT 0x09090909 +#define MESON_UBOOT_SUSPEND 0x0b0b0b0b +#define MESON_REBOOT_CLEAR 0xdeaddead +#endif