From ffb59e40deedf68e66bc32743d1688703e4567b6 Mon Sep 17 00:00:00 2001 From: Joy Cho Date: Tue, 19 Dec 2017 17:01:58 +0900 Subject: [PATCH] drivers: hardkernel: add odroid-sysfs including boot mode detection Change-Id: I27a610b0ad3676cb2fa904efc362a532138b7493 --- .../dts/rockchip/rk3399-odroidn1-linux.dts | 5 + arch/arm64/configs/odroidn1_defconfig | 5 + drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/hardkernel/Kconfig | 17 ++ drivers/hardkernel/Makefile | 1 + drivers/hardkernel/odroid-sysfs.c | 177 ++++++++++++++++++ 7 files changed, 208 insertions(+) create mode 100644 drivers/hardkernel/Kconfig create mode 100644 drivers/hardkernel/Makefile create mode 100644 drivers/hardkernel/odroid-sysfs.c diff --git a/arch/arm64/boot/dts/rockchip/rk3399-odroidn1-linux.dts b/arch/arm64/boot/dts/rockchip/rk3399-odroidn1-linux.dts index 293b1b7057e0..39f79c669fc1 100644 --- a/arch/arm64/boot/dts/rockchip/rk3399-odroidn1-linux.dts +++ b/arch/arm64/boot/dts/rockchip/rk3399-odroidn1-linux.dts @@ -237,6 +237,11 @@ rockchip,pwm_id= <2>; rockchip,pwm_voltage = <1000000>; }; + + odroid_sysfs: odroid-sysfs { + status = "okay"; + compatible = "odroid-sysfs"; + }; }; &cluster0_opp { diff --git a/arch/arm64/configs/odroidn1_defconfig b/arch/arm64/configs/odroidn1_defconfig index 60a22f24494f..60ea148dd758 100644 --- a/arch/arm64/configs/odroidn1_defconfig +++ b/arch/arm64/configs/odroidn1_defconfig @@ -4031,6 +4031,11 @@ CONFIG_ROCKCHIP_EFUSE=y # # CONFIG_RK_HEADSET is not set +# +# Hardkernel features +# +CONFIG_ODROIDN1_SYSFS=y + # # Firmware Drivers # diff --git a/drivers/Kconfig b/drivers/Kconfig index 4f5b62381941..092c43ceb4e0 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -206,4 +206,6 @@ source "drivers/rk_nand/Kconfig" source "drivers/headset_observe/Kconfig" +source "drivers/hardkernel/Kconfig" + endmenu diff --git a/drivers/Makefile b/drivers/Makefile index 3aa00384faf6..6e478824e9b7 100644 --- a/drivers/Makefile +++ b/drivers/Makefile @@ -177,3 +177,4 @@ obj-$(CONFIG_FPGA) += fpga/ obj-$(CONFIG_TEE) += tee/ obj-$(CONFIG_RK_NAND) += rk_nand/ obj-$(CONFIG_RK_HEADSET) += headset_observe/ +obj-$(CONFIG_ODROIDN1_SYSFS) += hardkernel/ diff --git a/drivers/hardkernel/Kconfig b/drivers/hardkernel/Kconfig new file mode 100644 index 000000000000..017c460ecc1a --- /dev/null +++ b/drivers/hardkernel/Kconfig @@ -0,0 +1,17 @@ +# +# Hardkernel sysfs configuration +# + +if ARCH_ROCKCHIP + +menu "Hardkernel features" + +config ODROIDN1_SYSFS + bool "Hardkernel ODROID-N1 sysfs Support" + default y + help + Hardkernel sysfs support based on RK3399 + +endmenu + +endif diff --git a/drivers/hardkernel/Makefile b/drivers/hardkernel/Makefile new file mode 100644 index 000000000000..e24acf26abbc --- /dev/null +++ b/drivers/hardkernel/Makefile @@ -0,0 +1 @@ +obj-$(CONFIG_ODROIDN1_SYSFS) += odroid-sysfs.o diff --git a/drivers/hardkernel/odroid-sysfs.c b/drivers/hardkernel/odroid-sysfs.c new file mode 100644 index 000000000000..a14373e96037 --- /dev/null +++ b/drivers/hardkernel/odroid-sysfs.c @@ -0,0 +1,177 @@ +/* + * ODROID sysfs support for extra feature enhancement + * + * Copyright (C) 2014, Hardkernel Co,.Ltd + * Author: Charles Park + * Author: Dongjin Kim + * + * This driver has been modified to support ODROID-N1. + * Modified by Joy Cho + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * 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 + +MODULE_AUTHOR("Hardkernel Co,.Ltd"); +MODULE_DESCRIPTION("SYSFS driver for ODROID hardware"); +MODULE_LICENSE("GPL"); + +static int boot_mode; + +/* + * Discover the boot device within MicroSD or eMMC + * and return 1 for eMMC, otherwise 0. + */ +enum { + BOOT_DEVICE_RESERVED = 0, + BOOT_DEVICE_SD = 1, + BOOT_DEVICE_EMMC = 2, + BOOT_DEVICE_NAND = 3, + BOOT_DEVICE_NVME = 4, + BOOT_DEVICE_USB = 5, + BOOT_DEVICE_SPI = 6, + BOOT_DEVICE_MAX, +}; + +/* + * if boot_mode is emmc, return 1 + * else return 0 + */ +int board_boot_from_emmc(void) +{ + if (boot_mode == BOOT_DEVICE_EMMC) + return 1; + else + return 0; +} +EXPORT_SYMBOL(board_boot_from_emmc); + +static ssize_t show_bootdev(struct class *class, + struct class_attribute *attr, char *buf) +{ + const char *boot_dev_name[BOOT_DEVICE_MAX] = { + "unknown", /* reserved boot device treated as 'unknown' */ + "sd", + "emmc", + "nand", + "nvme", + "usb", + "spi" + }; + + return snprintf(buf, PAGE_SIZE, "%s\n", + boot_dev_name[boot_mode]); +} + +static int __init setup_boot_mode(char *str) +{ + if (strncmp("emmc", str, 4) == 0) + boot_mode = BOOT_DEVICE_EMMC; + else if (strncmp("sd", str, 2) == 0) + boot_mode = BOOT_DEVICE_SD; + else + boot_mode = BOOT_DEVICE_RESERVED; + + return 1; +} +__setup("storagemedia=", setup_boot_mode); + +static struct class_attribute odroid_class_attrs[] = { + __ATTR(bootdev, 0444, show_bootdev, NULL), + __ATTR_NULL, +}; + +static struct class odroid_class = { + .name = "odroid", + .owner = THIS_MODULE, + .class_attrs = odroid_class_attrs, +}; + +static int odroid_sysfs_probe(struct platform_device *pdev) +{ +#ifdef CONFIG_USE_OF + struct device_node *node; + + if (pdev->dev.of_node) + node = pdev->dev.of_node; +#endif + return 0; +} + +static int odroid_sysfs_remove(struct platform_device *pdev) +{ + return 0; +} + +#ifdef CONFIG_PM_SLEEP +static int odroid_sysfs_suspend(struct platform_device *dev, pm_message_t state) +{ + pr_info(KERN_INFO "%s\n", __func__); + + return 0; +} + +static int odroid_sysfs_resume(struct platform_device *dev) +{ + pr_info(KERN_INFO "%s\n", __func__); + + return 0; +} +#endif + +static const struct of_device_id odroid_sysfs_dt[] = { + { .compatible = "odroid-sysfs", }, + { /* sentinel */ }, +}; +MODULE_DEVICE_TABLE(of, odroid_sysfs_dt); + +static struct platform_driver odroid_sysfs_driver = { + .driver = { + .name = "odroid-sysfs", + .owner = THIS_MODULE, + .of_match_table = odroid_sysfs_dt, + }, + .probe = odroid_sysfs_probe, + .remove = odroid_sysfs_remove, +#ifdef CONFIG_PM_SLEEP + .suspend = odroid_sysfs_suspend, + .resume = odroid_sysfs_resume, +#endif +}; + +static int __init odroid_sysfs_init(void) +{ + int error = class_register(&odroid_class); + if (0 > error) + return error; + + return platform_driver_register(&odroid_sysfs_driver); +} + +static void __exit odroid_sysfs_exit(void) +{ + platform_driver_unregister(&odroid_sysfs_driver); + class_unregister(&odroid_class); +} + +module_init(odroid_sysfs_init); +module_exit(odroid_sysfs_exit);