diff options
author | George Hung <george.hung@quantatw.com> | 2020-07-16 17:03:39 +0300 |
---|---|---|
committer | Andrew Geissler <geissonator@yahoo.com> | 2020-08-04 03:51:56 +0300 |
commit | a9f5ff596a1f9ddcdd4c041c4c442fc84009929a (patch) | |
tree | 3ec69861064c8ec2943c9286b7a2a4b875e5d4b1 /meta-quanta | |
parent | 1e04fb62abb23c794d84c646bee3a75e9327d515 (diff) | |
download | openbmc-a9f5ff596a1f9ddcdd4c041c4c442fc84009929a.tar.xz |
meta-quanta: gbs: add kernel config and drivers
1. set kernel config for GBS machine
2. add AMD CPU temperature hwmon driver
3. add seven segment display drivers
(From meta-quanta rev: d9f9d7eb3809821b07887c2adf4e45103582eefa)
Signed-off-by: George Hung <george.hung@quantatw.com>
Change-Id: If2f42e43e043ea277a455a208968927b7053d2c0
Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
Diffstat (limited to 'meta-quanta')
6 files changed, 1013 insertions, 0 deletions
diff --git a/meta-quanta/meta-gbs/recipes-kernel/linux/linux-nuvoton/0003-Add-basic-support-for-SB-TSI-sensors.patch b/meta-quanta/meta-gbs/recipes-kernel/linux/linux-nuvoton/0003-Add-basic-support-for-SB-TSI-sensors.patch new file mode 100644 index 0000000000..b690a9813d --- /dev/null +++ b/meta-quanta/meta-gbs/recipes-kernel/linux/linux-nuvoton/0003-Add-basic-support-for-SB-TSI-sensors.patch @@ -0,0 +1,327 @@ +SB Temperature Sensor Interface (SB-TSI) is an SMBus compatible +interface that reports AMD SoC's Ttcl (normalized temperature), +and resembles a typical 8-pin remote temperature sensor's I2C interface +to BMC. + +This commit adds basic support using this interface to read CPU +temperature, and read/write high/low CPU temp thresholds. + +To instantiate this driver on an AMD CPU with SB-TSI +support, the i2c bus number would be the bus connected from the board +management controller (BMC) to the CPU. The i2c address is specified in +Section 6.3.1 of the spec [1]: The SB-TSI address is normally 98h for socket 0 +and 90h for socket 1, but it could vary based on hardware address select pins. + +[1]: https://www.amd.com/system/files/TechDocs/56255_OSRR.pdf + +Test status: tested reading temp1_input, and reading/writing +temp1_max/min. + +Signed-off-by: Kun Yi <kunyi at google.com> +--- + drivers/hwmon/Kconfig | 10 ++ + drivers/hwmon/Makefile | 1 + + drivers/hwmon/sbtsi_temp.c | 259 +++++++++++++++++++++++++++++++++++++ + 3 files changed, 270 insertions(+) + create mode 100644 drivers/hwmon/sbtsi_temp.c + +diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig +index 05a30832c6ba..9585dcd01d1b 100644 +--- a/drivers/hwmon/Kconfig ++++ b/drivers/hwmon/Kconfig +@@ -1412,6 +1412,16 @@ config SENSORS_RASPBERRYPI_HWMON + This driver can also be built as a module. If so, the module + will be called raspberrypi-hwmon. + ++config SENSORS_SBTSI ++ tristate "Emulated SB-TSI temperature sensor" ++ depends on I2C ++ help ++ If you say yes here you get support for emulated temperature ++ sensors on AMD SoCs with SB-TSI interface connected to a BMC device. ++ ++ This driver can also be built as a module. If so, the module will ++ be called sbtsi_temp. ++ + config SENSORS_SHT15 + tristate "Sensiron humidity and temperature sensors. SHT15 and compat." + depends on GPIOLIB || COMPILE_TEST +diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile +index b0b9c8e57176..cd109f003ce4 100644 +--- a/drivers/hwmon/Makefile ++++ b/drivers/hwmon/Makefile +@@ -152,6 +152,7 @@ obj-$(CONFIG_SENSORS_POWR1220) += powr1220.o + obj-$(CONFIG_SENSORS_PWM_FAN) += pwm-fan.o + obj-$(CONFIG_SENSORS_RASPBERRYPI_HWMON) += raspberrypi-hwmon.o + obj-$(CONFIG_SENSORS_S3C) += s3c-hwmon.o ++obj-$(CONFIG_SENSORS_SBTSI) += sbtsi_temp.o + obj-$(CONFIG_SENSORS_SCH56XX_COMMON)+= sch56xx-common.o + obj-$(CONFIG_SENSORS_SCH5627) += sch5627.o + obj-$(CONFIG_SENSORS_SCH5636) += sch5636.o +diff --git a/drivers/hwmon/sbtsi_temp.c b/drivers/hwmon/sbtsi_temp.c +new file mode 100644 +index 000000000000..e3ad6a9f7ec1 +--- /dev/null ++++ b/drivers/hwmon/sbtsi_temp.c +@@ -0,0 +1,259 @@ ++// SPDX-License-Identifier: GPL-2.0-or-later ++/* ++ * sbtsi_temp.c - hwmon driver for a SBI Temperature Sensor Interface (SB-TSI) ++ * compliant AMD SoC temperature device. ++ * ++ * Copyright (c) 2020, Google Inc. ++ * Copyright (c) 2020, Kun Yi <kunyi at google.com> ++ */ ++ ++#include <linux/err.h> ++#include <linux/i2c.h> ++#include <linux/init.h> ++#include <linux/hwmon.h> ++#include <linux/module.h> ++#include <linux/mutex.h> ++#include <linux/of_device.h> ++#include <linux/of.h> ++ ++/* ++ * SB-TSI registers only support SMBus byte data access. "_INT" registers are ++ * the integer part of a temperature value or limit, and "_DEC" registers are ++ * corresponding decimal parts. ++ */ ++#define SBTSI_REG_TEMP_INT 0x01 /* RO */ ++#define SBTSI_REG_STATUS 0x02 /* RO */ ++#define SBTSI_REG_CONFIG 0x03 /* RO */ ++#define SBTSI_REG_TEMP_HIGH_INT 0x07 /* RW */ ++#define SBTSI_REG_TEMP_LOW_INT 0x08 /* RW */ ++#define SBTSI_REG_TEMP_DEC 0x10 /* RW */ ++#define SBTSI_REG_TEMP_HIGH_DEC 0x13 /* RW */ ++#define SBTSI_REG_TEMP_LOW_DEC 0x14 /* RW */ ++#define SBTSI_REG_REV 0xFF /* RO */ ++ ++#define SBTSI_CONFIG_READ_ORDER_SHIFT 5 ++ ++#define SBTSI_TEMP_MIN 0 ++#define SBTSI_TEMP_MAX 255875 ++#define SBTSI_REV_MAX_VALID_ID 4 ++ ++/* Each client has this additional data */ ++struct sbtsi_data { ++ struct i2c_client *client; ++ struct mutex lock; ++}; ++ ++/* ++ * From SB-TSI spec: CPU temperature readings and limit registers encode the ++ * temperature in increments of 0.125 from 0 to 255.875. The "high byte" ++ * register encodes the base-2 of the integer portion, and the upper 3 bits of ++ * the "low byte" encode in base-2 the decimal portion. ++ * ++ * e.g. INT=0x19, DEC=0x20 represents 25.125 degrees Celsius ++ * ++ * Therefore temperature in millidegree Celsius = ++ * (INT + DEC / 256) * 1000 = (INT * 8 + DEC / 32) * 125 ++ */ ++static inline int sbtsi_reg_to_mc(s32 integer, s32 decimal) ++{ ++ return ((integer << 3) + (decimal >> 5)) * 125; ++} ++ ++/* ++ * Inversely, given temperature in millidegree Celsius ++ * INT = (TEMP / 125) / 8 ++ * DEC = ((TEMP / 125) % 8) * 32 ++ * Caller have to make sure temp doesn't exceed 255875, the max valid value. ++ */ ++static inline void sbtsi_mc_to_reg(s32 temp, u8 *integer, u8 *decimal) ++{ ++ temp /= 125; ++ *integer = temp >> 3; ++ *decimal = (temp & 0x7) << 5; ++} ++ ++static int sbtsi_read(struct device *dev, enum hwmon_sensor_types type, ++ u32 attr, int channel, long *val) ++{ ++ struct sbtsi_data *data = dev_get_drvdata(dev); ++ s32 temp_int, temp_dec; ++ int err, reg_int, reg_dec; ++ u8 read_order; ++ ++ if (type != hwmon_temp) ++ return -EINVAL; ++ ++ read_order = 0; ++ switch (attr) { ++ case hwmon_temp_input: ++ /* ++ * ReadOrder bit specifies the reading order of integer and ++ * decimal part of CPU temp for atomic reads. If bit == 0, ++ * reading integer part triggers latching of the decimal part, ++ * so integer part should be read first. If bit == 1, read ++ * order should be reversed. ++ */ ++ err = i2c_smbus_read_byte_data(data->client, SBTSI_REG_CONFIG); ++ if (err < 0) ++ return err; ++ ++ read_order = (u8)err & BIT(SBTSI_CONFIG_READ_ORDER_SHIFT); ++ reg_int = SBTSI_REG_TEMP_INT; ++ reg_dec = SBTSI_REG_TEMP_DEC; ++ break; ++ case hwmon_temp_max: ++ reg_int = SBTSI_REG_TEMP_HIGH_INT; ++ reg_dec = SBTSI_REG_TEMP_HIGH_DEC; ++ break; ++ case hwmon_temp_min: ++ reg_int = SBTSI_REG_TEMP_LOW_INT; ++ reg_dec = SBTSI_REG_TEMP_LOW_DEC; ++ break; ++ default: ++ return -EINVAL; ++ } ++ ++ if (read_order == 0) { ++ temp_int = i2c_smbus_read_byte_data(data->client, reg_int); ++ temp_dec = i2c_smbus_read_byte_data(data->client, reg_dec); ++ } else { ++ temp_dec = i2c_smbus_read_byte_data(data->client, reg_dec); ++ temp_int = i2c_smbus_read_byte_data(data->client, reg_int); ++ } ++ ++ if (temp_int < 0) ++ return temp_int; ++ if (temp_dec < 0) ++ return temp_dec; ++ ++ *val = sbtsi_reg_to_mc(temp_int, temp_dec); ++ ++ return 0; ++} ++ ++static int sbtsi_write(struct device *dev, enum hwmon_sensor_types type, ++ u32 attr, int channel, long val) ++{ ++ struct sbtsi_data *data = dev_get_drvdata(dev); ++ int reg_int, reg_dec, err; ++ u8 temp_int, temp_dec; ++ ++ if (type != hwmon_temp) ++ return -EINVAL; ++ ++ switch (attr) { ++ case hwmon_temp_max: ++ reg_int = SBTSI_REG_TEMP_HIGH_INT; ++ reg_dec = SBTSI_REG_TEMP_HIGH_DEC; ++ break; ++ case hwmon_temp_min: ++ reg_int = SBTSI_REG_TEMP_LOW_INT; ++ reg_dec = SBTSI_REG_TEMP_LOW_DEC; ++ break; ++ default: ++ return -EINVAL; ++ } ++ ++ val = clamp_val(val, SBTSI_TEMP_MIN, SBTSI_TEMP_MAX); ++ mutex_lock(&data->lock); ++ sbtsi_mc_to_reg(val, &temp_int, &temp_dec); ++ err = i2c_smbus_write_byte_data(data->client, reg_int, temp_int); ++ if (err) ++ goto exit; ++ ++ err = i2c_smbus_write_byte_data(data->client, reg_dec, temp_dec); ++exit: ++ mutex_unlock(&data->lock); ++ return err; ++} ++ ++static umode_t sbtsi_is_visible(const void *data, ++ enum hwmon_sensor_types type, ++ u32 attr, int channel) ++{ ++ switch (type) { ++ case hwmon_temp: ++ switch (attr) { ++ case hwmon_temp_input: ++ return 0444; ++ case hwmon_temp_min: ++ return 0644; ++ case hwmon_temp_max: ++ return 0644; ++ } ++ break; ++ default: ++ break; ++ } ++ return 0; ++} ++ ++static const struct hwmon_channel_info *sbtsi_info[] = { ++ HWMON_CHANNEL_INFO(chip, ++ HWMON_C_REGISTER_TZ), ++ HWMON_CHANNEL_INFO(temp, ++ HWMON_T_INPUT | HWMON_T_MIN | HWMON_T_MAX), ++ NULL ++}; ++ ++static const struct hwmon_ops sbtsi_hwmon_ops = { ++ .is_visible = sbtsi_is_visible, ++ .read = sbtsi_read, ++ .write = sbtsi_write, ++}; ++ ++static const struct hwmon_chip_info sbtsi_chip_info = { ++ .ops = &sbtsi_hwmon_ops, ++ .info = sbtsi_info, ++}; ++ ++static int sbtsi_probe(struct i2c_client *client, ++ const struct i2c_device_id *id) ++{ ++ struct device *dev = &client->dev; ++ struct device *hwmon_dev; ++ struct sbtsi_data *data; ++ ++ data = devm_kzalloc(dev, sizeof(struct sbtsi_data), GFP_KERNEL); ++ if (!data) ++ return -ENOMEM; ++ ++ data->client = client; ++ mutex_init(&data->lock); ++ ++ hwmon_dev = ++ devm_hwmon_device_register_with_info(dev, client->name, data, ++ &sbtsi_chip_info, NULL); ++ ++ return PTR_ERR_OR_ZERO(hwmon_dev); ++} ++ ++static const struct i2c_device_id sbtsi_id[] = { ++ {"sbtsi", 0}, ++ {} ++}; ++MODULE_DEVICE_TABLE(i2c, sbtsi_id); ++ ++static const struct of_device_id __maybe_unused sbtsi_of_match[] = { ++ { ++ .compatible = "amd,sbtsi", ++ }, ++ { }, ++}; ++MODULE_DEVICE_TABLE(of, sbtsi_of_match); ++ ++static struct i2c_driver sbtsi_driver = { ++ .class = I2C_CLASS_HWMON, ++ .driver = { ++ .name = "sbtsi", ++ .of_match_table = of_match_ptr(sbtsi_of_match), ++ }, ++ .probe = sbtsi_probe, ++ .id_table = sbtsi_id, ++}; ++ ++module_i2c_driver(sbtsi_driver); ++ ++MODULE_AUTHOR("Kun Yi <kunyi at google.com>"); ++MODULE_DESCRIPTION("Hwmon driver for AMD SB-TSI emulated sensor"); ++MODULE_LICENSE("GPL"); +-- +2.26.0.292.g33ef6b2f38-goog
\ No newline at end of file diff --git a/meta-quanta/meta-gbs/recipes-kernel/linux/linux-nuvoton/0004-Add-kernel-seven-seg-display-support.patch b/meta-quanta/meta-gbs/recipes-kernel/linux/linux-nuvoton/0004-Add-kernel-seven-seg-display-support.patch new file mode 100644 index 0000000000..a21707d8a0 --- /dev/null +++ b/meta-quanta/meta-gbs/recipes-kernel/linux/linux-nuvoton/0004-Add-kernel-seven-seg-display-support.patch @@ -0,0 +1,10 @@ +diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile +index b9e6d4c3e906..aa7ce9d72d2c 100644 +--- a/drivers/misc/Makefile ++++ b/drivers/misc/Makefile +@@ -59,3 +59,5 @@ obj-$(CONFIG_HABANA_AI) += habanalabs/ + obj-$(CONFIG_XILINX_SDFEC) += xilinx_sdfec.o + obj-$(CONFIG_NPCM7XX_LPC_BPC) += npcm7xx-lpc-bpc.o + obj-$(CONFIG_NPCM7XX_PCI_MBOX) += npcm7xx-pci-mbox.o ++obj-$(CONFIG_SEVEN_SEGMENT_DISPLAY) += seven_seg_disp.o ++obj-$(CONFIG_SEVEN_SEGMENT_GPIO) += seven_seg_gpio.o diff --git a/meta-quanta/meta-gbs/recipes-kernel/linux/linux-nuvoton/0004-ben-drivers-misc-Character-device-driver-for-seven-segme.patch b/meta-quanta/meta-gbs/recipes-kernel/linux/linux-nuvoton/0004-ben-drivers-misc-Character-device-driver-for-seven-segme.patch new file mode 100644 index 0000000000..8ae624a514 --- /dev/null +++ b/meta-quanta/meta-gbs/recipes-kernel/linux/linux-nuvoton/0004-ben-drivers-misc-Character-device-driver-for-seven-segme.patch @@ -0,0 +1,293 @@ +From 2d46e81d9bbb624695bac8400a4ac41b7f116ec4 Mon Sep 17 00:00:00 2001 +From: Jaghathiswari Rankappagounder Natarajan <jaghu@google.com> +Date: Fri, 27 Jul 2018 12:34:54 -0700 +Subject: [PATCH 2/3] drivers: misc: Character device driver for seven segment + display + +Character device driver which implements the user-space +API for letting a user write to two 7-segment displays including +any conversion methods necessary to map the user input +to two 7-segment displays. + +Signed-off-by: Jaghathiswari Rankappagounder Natarajan <jaghu@google.com> +Signed-off-by: Kun Yi <kunyi@google.com> +Signed-off-by: Benjamin Fair <benjaminfair@google.com> +--- + drivers/misc/Kconfig | 8 ++ + drivers/misc/Makefile | 1 + + drivers/misc/seven_seg_disp.c | 201 ++++++++++++++++++++++++++++++++++ + drivers/misc/seven_seg_disp.h | 34 ++++++ + 4 files changed, 244 insertions(+) + create mode 100644 drivers/misc/seven_seg_disp.c + create mode 100644 drivers/misc/seven_seg_disp.h + +diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig +index 9d96469fb41c..d443de886346 100644 +--- a/drivers/misc/Kconfig ++++ b/drivers/misc/Kconfig +@@ -473,6 +473,14 @@ config VEXPRESS_SYSCFG + bus. System Configuration interface is one of the possible means + of generating transactions on this bus. + ++config SEVEN_SEGMENT_DISPLAY ++ tristate "Character driver for seven segment display support" ++ help ++ Character device driver which implements the user-space ++ API for letting a user write to two 7-segment displays including ++ any conversion methods necessary to map the user input ++ to two 7-segment displays. ++ + config PCI_ENDPOINT_TEST + depends on PCI + select CRC32 + +diff --git a/drivers/misc/seven_seg_disp.c b/drivers/misc/seven_seg_disp.c +new file mode 100644 +index 000000000000..db1c571f68e5 +--- /dev/null ++++ b/drivers/misc/seven_seg_disp.c +@@ -0,0 +1,201 @@ ++/* ++ * Copyright (c) 2016 Google, Inc ++ * ++ * This program is free software; you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License version 2 or later as ++ * published by the Free Software Foundation. ++ */ ++ ++#include <linux/module.h> ++#include <linux/version.h> ++#include <linux/kernel.h> ++#include <linux/types.h> ++#include <linux/kdev_t.h> ++#include <linux/fs.h> ++#include <linux/uaccess.h> ++#include <linux/ctype.h> ++#include <linux/of.h> ++#include <linux/io.h> ++#include <linux/slab.h> ++#include <linux/platform_device.h> ++ ++#include "seven_seg_disp.h" ++ ++#define LED_DOT 0x01 ++ ++/* ++ * 0 1 2 3 4 5 6 7 8 9 A B C D E F ++ * _ _ _ _ _ _ _ _ _ _ _ _ ++ * | | | _| _| |_| |_ |_ | |_| |_| |_| |_ | _| |_ |_ ++ * |_| | |_ _| | _| |_| | |_| | | | |_| |_ |_| |_ | ++ * ++ * data[7:1] = led[a:g] ++ */ ++const u8 seven_seg_bits[] = { ++ 0xFC, 0x60, 0xDA, 0xF2, 0x66, 0xB6, 0xBE, 0xE0, ++ 0xFE, 0xF6, 0xEE, 0x3E, 0x9C, 0x7A, 0x9E, 0x8E ++ }; ++ ++/* ++ * 0 1 2 3 4 5 6 7 8 9 A B C D E F ++ * _ _ _ _ _ ++ * | |_ |_| |_ _ _ _ _ _ _ _ |_ _| _| | | ++ * |_ |_ | | _| |_| |_| | | ++ * ++ * data[7:1] = led[a:g] ++ */ ++const u8 special_seven_seg_bits[] = { ++ 0x00, 0x9C, 0x1E, 0xCE, 0x8E, 0x02, 0x02, 0x02, ++ 0x02, 0x02, 0x02, 0x02, 0xB6, 0x7A, 0x7A, 0xEC ++ }; ++ ++static dev_t seven_seg_devno; ++static struct class *seven_seg_disp_class; ++ ++static int seven_seg_disp_open(struct inode *inode, struct file *filp) ++{ ++ struct seven_seg_disp_dev *disp_dev; ++ ++ disp_dev = container_of(inode->i_cdev, ++ struct seven_seg_disp_dev, cdev); ++ filp->private_data = disp_dev; ++ return 0; ++} ++ ++static int seven_seg_disp_close(struct inode *inode, struct file *filp) ++{ ++ filp->private_data = NULL; ++ return 0; ++} ++ ++static ssize_t seven_seg_disp_read(struct file *filp, char __user *buf, size_t ++ len, loff_t *off) ++{ ++ struct seven_seg_disp_dev *disp_dev = filp->private_data; ++ ++ if (disp_dev->disp_data_valid) ++ return -EINVAL; ++ ++ if (copy_to_user(buf, disp_dev->seven_seg_disp_data_array, ++ MAX_DISP_CHAR_SIZE) != 0) { ++ return -EFAULT; ++ } ++ ++ return 0; ++} ++ ++static u16 convert_to_disp_data(char *buf) ++{ ++ u8 low_display; ++ u8 high_display; ++ u16 led_value; ++ ++ low_display = seven_seg_bits[hex_to_bin(buf[2])]; ++ ++ high_display = (buf[0] == '1') ? ++ special_seven_seg_bits[hex_to_bin(buf[1])] : ++ seven_seg_bits[hex_to_bin(buf[1])]; ++ ++ led_value = low_display | (high_display << 8); ++ if (buf[0] == '1') ++ led_value |= LED_DOT | (LED_DOT << 8); ++ ++ return led_value; ++} ++ ++static ssize_t seven_seg_disp_write(struct file *filp, const char __user *buf, ++ size_t len, loff_t *off) ++{ ++ int length = len - 1; ++ int i; ++ ++ struct seven_seg_disp_dev *disp_dev = filp->private_data; ++ ++ if (length != MAX_DISP_CHAR_SIZE) ++ return -EINVAL; ++ ++ if (copy_from_user(disp_dev->seven_seg_disp_data_array, ++ buf, length) != 0) { ++ return -EFAULT; ++ } ++ ++ for (i = 0; i < MAX_DISP_CHAR_SIZE; i++) { ++ if (!isxdigit(disp_dev->seven_seg_disp_data_array[i])) ++ return -EINVAL; ++ } ++ ++ disp_dev->current_seven_seg_disp_data = convert_to_disp_data( ++ disp_dev->seven_seg_disp_data_array); ++ disp_dev->disp_data_valid = true; ++ disp_dev->update_seven_seg_data(&disp_dev->parent, ++ disp_dev->current_seven_seg_disp_data); ++ ++ return len; ++} ++ ++static const struct file_operations seven_seg_disp_fops = { ++ ++ .owner = THIS_MODULE, ++ .open = seven_seg_disp_open, ++ .release = seven_seg_disp_close, ++ .read = seven_seg_disp_read, ++ .write = seven_seg_disp_write ++}; ++ ++void seven_seg_rem_cdev(struct seven_seg_disp_dev *disp_dev) ++{ ++ cdev_del(&disp_dev->cdev); ++ device_destroy(seven_seg_disp_class, seven_seg_devno); ++} ++ ++int seven_seg_setup_cdev(struct seven_seg_disp_dev *disp_dev, ++ void (*update_disp_data)(struct device *, u16 data)) ++{ ++ struct device *dev; ++ int err; ++ ++ dev = device_create(seven_seg_disp_class, NULL, ++ seven_seg_devno, ++ NULL, "seven_seg_disp_val"); ++ if (dev == NULL) ++ return -EIO; ++ disp_dev->dev = dev; ++ disp_dev->update_seven_seg_data = update_disp_data; ++ disp_dev->disp_data_valid = false; ++ ++ cdev_init(&disp_dev->cdev, &seven_seg_disp_fops); ++ err = cdev_add(&disp_dev->cdev, seven_seg_devno, 1); ++ if (err) ++ device_destroy(seven_seg_disp_class, seven_seg_devno); ++ return err; ++} ++ ++static int __init seven_seg_disp_init(void) ++{ ++ int err = alloc_chrdev_region(&seven_seg_devno, 0, 1, "disp_state"); ++ ++ if (err < 0) ++ return err; ++ ++ seven_seg_disp_class = class_create(THIS_MODULE, "disp_state"); ++ if (seven_seg_disp_class == NULL) ++ goto unreg_chrdev; ++ ++ return 0; ++ ++unreg_chrdev: ++ unregister_chrdev_region(seven_seg_devno, 1); ++ return -EIO; ++} ++ ++static void __exit seven_seg_disp_exit(void) ++{ ++ class_destroy(seven_seg_disp_class); ++ unregister_chrdev_region(seven_seg_devno, 1); ++} ++ ++module_init(seven_seg_disp_init); ++module_exit(seven_seg_disp_exit); ++MODULE_LICENSE("GPL"); ++MODULE_AUTHOR("Jaghathiswari Rankappagounder Natarajan <jaghu@google.com>"); ++MODULE_DESCRIPTION("Seven segment display character driver"); +diff --git a/drivers/misc/seven_seg_disp.h b/drivers/misc/seven_seg_disp.h +new file mode 100644 +index 000000000000..0ebed0802747 +--- /dev/null ++++ b/drivers/misc/seven_seg_disp.h +@@ -0,0 +1,34 @@ ++/* ++ * Copyright (c) 2016 Google, Inc ++ * ++ * This program is free software; you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License version 2 or later as ++ * published by the Free Software Foundation. ++ */ ++ ++#ifndef SEVEN_SEG_DISP_H ++#define SEVEN_SEG_DISP_H ++ ++#include <linux/device.h> ++#include <linux/cdev.h> ++ ++#define MAX_DISP_CHAR_SIZE 3 ++ ++#define DEFAULT_REFRESH_INTERVAL_MS 600 ++ ++struct seven_seg_disp_dev { ++ bool disp_data_valid; ++ u16 current_seven_seg_disp_data; ++ char seven_seg_disp_data_array[MAX_DISP_CHAR_SIZE]; ++ struct device parent; ++ struct device *dev; ++ struct cdev cdev; ++ void (*update_seven_seg_data)(struct device *, u16 data); ++}; ++ ++int seven_seg_setup_cdev(struct seven_seg_disp_dev *disp_dev, ++ void (*update_disp_data)(struct device *, u16 data)); ++ ++void seven_seg_rem_cdev(struct seven_seg_disp_dev *disp_dev); ++ ++#endif +-- +2.22.0.770.g0f2c4a37fd-goog + diff --git a/meta-quanta/meta-gbs/recipes-kernel/linux/linux-nuvoton/0004-ben-drivers-misc-Platform-driver-for-seven-segment-displ.patch b/meta-quanta/meta-gbs/recipes-kernel/linux/linux-nuvoton/0004-ben-drivers-misc-Platform-driver-for-seven-segment-displ.patch new file mode 100644 index 0000000000..b166c78b81 --- /dev/null +++ b/meta-quanta/meta-gbs/recipes-kernel/linux/linux-nuvoton/0004-ben-drivers-misc-Platform-driver-for-seven-segment-displ.patch @@ -0,0 +1,267 @@ +From ea3e732d2c4a609e621346a96d37713820640196 Mon Sep 17 00:00:00 2001 +From: Jaghathiswari Rankappagounder Natarajan <jaghu@google.com> +Date: Fri, 27 Jul 2018 12:36:24 -0700 +Subject: [PATCH 3/3] drivers: misc: Platform driver for seven segment display + support + +Platform device driver which provides an API for displaying on two +7-segment displays, and implements the required bit-banging. +The hardware assumed is 74HC164 wired to two 7-segment displays. + +Signed-off-by: Jaghathiswari Rankappagounder Natarajan <jaghu@google.com> +Signed-off-by: Kun Yi <kunyi@google.com> +Signed-off-by: Benjamin Fair <benjaminfair@google.com> +--- + drivers/misc/Kconfig | 8 ++ +# drivers/misc/Makefile | 2 ++ + drivers/misc/seven_seg_gpio.c | 205 ++++++++++++++++++++++++++++++++++ + 3 files changed, 215 insertions(+) + create mode 100644 drivers/misc/seven_seg_gpio.c + +diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig +index d443de886346..e10984e3288f 100644 +--- a/drivers/misc/Kconfig ++++ b/drivers/misc/Kconfig +@@ -481,6 +481,14 @@ config SEVEN_SEGMENT_DISPLAY + any conversion methods necessary to map the user input + to two 7-segment displays. + ++config SEVEN_SEGMENT_GPIO ++ tristate "Platform driver to update seven segment display" ++ depends on SEVEN_SEGMENT_DISPLAY ++ help ++ Platform device driver which provides an API for displaying on two ++ 7-segment displays, and implements the required bit-banging. ++ The hardware assumed is 74HC164 wired to two 7-segment displays. ++ + config PCI_ENDPOINT_TEST + depends on PCI + select CRC32 +# diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile +# index 402bcc3c9961..f39bec664d92 100644 +# --- a/drivers/misc/Makefile +# +++ b/drivers/misc/Makefile +# @@ -53,6 +53,8 @@ obj-$(CONFIG_GENWQE) += genwqe/ +# obj-$(CONFIG_ECHO) += echo/ +# obj-$(CONFIG_VEXPRESS_SYSCFG) += vexpress-syscfg.o +# obj-$(CONFIG_CXL_BASE) += cxl/ +# +obj-$(CONFIG_SEVEN_SEGMENT_DISPLAY) += seven_seg_disp.o +# +obj-$(CONFIG_SEVEN_SEGMENT_GPIO) += seven_seg_gpio.o +# obj-$(CONFIG_ASPEED_LPC_CTRL) += aspeed-lpc-ctrl.o +# obj-$(CONFIG_ASPEED_LPC_SNOOP) += aspeed-lpc-snoop.o +# obj-$(CONFIG_ASPEED_LPC_MBOX) += aspeed-lpc-mbox.o + +diff --git a/drivers/misc/seven_seg_gpio.c b/drivers/misc/seven_seg_gpio.c +new file mode 100644 +index 000000000000..e03ea7f8b848 +--- /dev/null ++++ b/drivers/misc/seven_seg_gpio.c +@@ -0,0 +1,205 @@ ++/* ++ * Copyright (C) 2016 Google, Inc ++ * ++ * This program is free software; you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License version 2 or later as ++ * published by the Free Software Foundation. ++ */ ++ ++#include <linux/kernel.h> ++#include <linux/module.h> ++#include <linux/timer.h> ++#include <linux/jiffies.h> ++#include <linux/sizes.h> ++#include <linux/io.h> ++#include <linux/delay.h> ++#include <linux/uaccess.h> ++#include <linux/mutex.h> ++#include <linux/of_platform.h> ++#include <linux/gpio/consumer.h> ++ ++#include "seven_seg_disp.h" ++ ++#define DELAY_INTVL_US 1 ++ ++#define CLOCK_GPIO_NAME "clock" ++#define DATA_GPIO_NAME "data" ++#define CLEAR_GPIO_NAME "clear" ++ ++struct seven_seg_gpio_info { ++ u16 curr_disp_value; ++ u16 refresh_interval; ++ struct timer_list update_timer; ++ struct gpio_desc *clock_gpio; ++ struct gpio_desc *data_gpio; ++ struct gpio_desc *clear_gpio; ++}; ++ ++static void update_seven_seg_gpio_data(struct device *dev, u16 data) ++{ ++ struct platform_device *pdev; ++ struct seven_seg_gpio_info *gpio_info; ++ ++ pdev = container_of(dev, struct platform_device, dev); ++ if (pdev == NULL) { ++ pr_err("invalid NULL platform_device\n"); ++ return; ++ } ++ ++ gpio_info = platform_get_drvdata(pdev); ++ if (gpio_info == NULL) { ++ pr_err("invalid NULL gpio_info\n"); ++ return; ++ } ++ ++ gpio_info->curr_disp_value = data; ++} ++ ++static void clear_seven_seg_gpio_data(struct device *dev, u16 data) ++{ ++ struct platform_device *pdev; ++ struct seven_seg_gpio_info *gpio_info; ++ ++ pdev = container_of(dev, struct platform_device, dev); ++ if (pdev == NULL) { ++ pr_err("invalid NULL platform_device\n"); ++ return; ++ } ++ ++ gpio_info = platform_get_drvdata(pdev); ++ if (gpio_info == NULL) { ++ pr_err("invalid NULL gpio_info\n"); ++ return; ++ } ++ ++ gpio_info->curr_disp_value = 0; ++} ++ ++static void send_seven_seg_gpio_data(u16 disp_data, ++ struct seven_seg_gpio_info *gpio_info) ++{ ++ int i; ++ ++ gpiod_set_value(gpio_info->clear_gpio, 0); ++ udelay(DELAY_INTVL_US); ++ gpiod_set_value(gpio_info->clear_gpio, 1); ++ udelay(DELAY_INTVL_US); ++ ++ for (i = 0; i < 16; i++) { ++ if (disp_data & 0x01) ++ gpiod_set_value(gpio_info->data_gpio, 1); ++ else ++ gpiod_set_value(gpio_info->data_gpio, 0); ++ ++ udelay(DELAY_INTVL_US); ++ ++ gpiod_set_value(gpio_info->clock_gpio, 0); ++ udelay(DELAY_INTVL_US); ++ gpiod_set_value(gpio_info->clock_gpio, 1); ++ udelay(DELAY_INTVL_US); ++ ++ disp_data >>= 1; ++ } ++} ++ ++static void disp_refresh_timer_handler(struct timer_list *t) ++{ ++ u16 disp_data; ++ struct seven_seg_gpio_info *gpio_info = ++ from_timer(gpio_info, t, update_timer); ++ disp_data = gpio_info->curr_disp_value; ++ ++ send_seven_seg_gpio_data(disp_data, gpio_info); ++ mod_timer(&gpio_info->update_timer, ++ jiffies + msecs_to_jiffies(gpio_info->refresh_interval)); ++} ++ ++static const struct of_device_id of_seven_seg_gpio_match[] = { ++ { .compatible = "seven-seg-gpio-dev" }, ++ {}, ++}; ++ ++MODULE_DEVICE_TABLE(of, of_seven_seg_gpio_match); ++ ++static int seven_seg_gpio_probe(struct platform_device *pdev) ++{ ++ u16 interval; ++ int result; ++ struct seven_seg_gpio_info *gpio_info; ++ struct device *dev = &pdev->dev; ++ struct seven_seg_disp_dev *disp_dev; ++ ++ gpio_info = devm_kzalloc(dev, ++ sizeof(struct seven_seg_gpio_info), ++ GFP_KERNEL); ++ if (gpio_info == NULL) ++ return -ENOMEM; ++ ++ /* Requesting the clock gpio */ ++ gpio_info->clock_gpio = devm_gpiod_get(dev, CLOCK_GPIO_NAME, ++ GPIOD_OUT_HIGH); ++ if (IS_ERR(gpio_info->clock_gpio)) ++ return PTR_ERR(gpio_info->clock_gpio); ++ ++ /* Requesting the data gpio */ ++ gpio_info->data_gpio = devm_gpiod_get(dev, DATA_GPIO_NAME, ++ GPIOD_OUT_HIGH); ++ if (IS_ERR(gpio_info->data_gpio)) ++ return PTR_ERR(gpio_info->data_gpio); ++ ++ /* Requesting the clear gpio */ ++ gpio_info->clear_gpio = devm_gpiod_get(dev, CLEAR_GPIO_NAME, ++ GPIOD_OUT_HIGH); ++ if (IS_ERR(gpio_info->clear_gpio)) ++ return PTR_ERR(gpio_info->clear_gpio); ++ ++ result = of_property_read_u16(pdev->dev.of_node, ++ "refresh-interval-ms", &interval); ++ gpio_info->refresh_interval = result ? DEFAULT_REFRESH_INTERVAL_MS : ++ interval; ++ ++ /* Start timer to update seven segment display every second */ ++ timer_setup(&gpio_info->update_timer, disp_refresh_timer_handler, 0); ++ result = mod_timer(&gpio_info->update_timer, ++ jiffies + ++ msecs_to_jiffies(gpio_info->refresh_interval)); ++ if (result) ++ return result; ++ ++ gpio_info->curr_disp_value = 0; ++ ++ platform_set_drvdata(pdev, gpio_info); ++ ++ disp_dev = devm_kzalloc(dev, sizeof(struct seven_seg_disp_dev), ++ GFP_KERNEL); ++ disp_dev->parent = *dev; ++ seven_seg_setup_cdev(disp_dev, &update_seven_seg_gpio_data); ++ return 0; ++} ++ ++static int seven_seg_gpio_remove(struct platform_device *pdev) ++{ ++ struct seven_seg_gpio_info *gpio_info = platform_get_drvdata(pdev); ++ struct seven_seg_disp_dev *disp_dev = ++ container_of(&pdev->dev, ++ struct seven_seg_disp_dev, parent); ++ seven_seg_rem_cdev(disp_dev); ++ del_timer_sync(&gpio_info->update_timer); ++ platform_set_drvdata(pdev, NULL); ++ return 0; ++} ++ ++static struct platform_driver seven_seg_gpio_driver = { ++ .probe = seven_seg_gpio_probe, ++ .remove = seven_seg_gpio_remove, ++ .driver = { ++ .name = "seven-seg-gpio", ++ .of_match_table = of_seven_seg_gpio_match, ++ }, ++}; ++ ++module_platform_driver(seven_seg_gpio_driver); ++ ++MODULE_LICENSE("GPL"); ++MODULE_AUTHOR("Jaghathiswari Rankappagounder Natarajan <jaghu@google.com>"); ++MODULE_DESCRIPTION("Seven segment display driver using GPIO config"); +-- +2.22.0.770.g0f2c4a37fd-goog + diff --git a/meta-quanta/meta-gbs/recipes-kernel/linux/linux-nuvoton/gbs.cfg b/meta-quanta/meta-gbs/recipes-kernel/linux/linux-nuvoton/gbs.cfg new file mode 100644 index 0000000000..edd009c473 --- /dev/null +++ b/meta-quanta/meta-gbs/recipes-kernel/linux/linux-nuvoton/gbs.cfg @@ -0,0 +1,110 @@ +# Support full 1G memory for userspace on BMC +CONFIG_VMSPLIT_3G_OPT=y +CONFIG_NET_NCSI=y +# Enable available sensors +CONFIG_HWMON=y +CONFIG_PMBUS=y +CONFIG_SENSORS_PMBUS=y +CONFIG_SENSORS_MAX34440=y +CONFIG_SENSORS_LM75=y +CONFIG_SENSORS_SBTSI=y +CONFIG_SENSORS_ISL68137=y +CONFIG_SENSORS_ADM1275=y +CONFIG_NPCM7XX_ADC=y +CONFIG_SENSORS_IIO_HWMON=y +CONFIG_SENSORS_FAN=y +CONFIG_SENSORS_JC42=y +CONFIG_SENSORS_MAX31790=y +CONFIG_SENSORS_UCD9000=y + +# Enable for firmware update LPC. +CONFIG_DEVMEM=y + +# Enable seven seg display +CONFIG_SEVEN_SEGMENT_DISPLAY=y +CONFIG_SEVEN_SEGMENT_GPIO=y + +# Enable GPIO LEDS +CONFIG_NEW_LEDS=y +CONFIG_LEDS_CLASS=y +CONFIG_LEDS_GPIO=y +CONFIG_LEDS_TRIGGERS=y +CONFIG_LEDS_TRIGGER_TIMER=y // Allow userspace to blink LEDs +CONFIG_LEDS_TRIGGER_PANIC=y // Blink BMC fault when kernel panics +CONFIG_LEDS_TRIGGER_DEFAULT_ON=y +CONFIG_LEDS_TRIGGER_HEARTBEAT=y + +# Enable pstore(ramoops) to capture kernel panics +CONFIG_PSTORE=y +CONFIG_PSTORE_RAM=y +CONFIG_PSTORE_DEFLATE_COMPRESS=y + +# Enable Nuvoton ECC +CONFIG_EDAC_ATOMIC_SCRUB=y +CONFIG_EDAC_DEBUG=y +CONFIG_EDAC_LEGACY_SYSFS=y +CONFIG_EDAC_NPCM7XX=y +CONFIG_EDAC_SUPPORT=y +CONFIG_EDAC=y +CONFIG_RAS=y + +# Enable Nuvoton JTAG +CONFIG_NPCM7XX_JTAG_MASTER=y + +# USB +CONFIG_USB_CONFIGFS_ECM_SUBSET=y +CONFIG_USB_CONFIGFS_ECM=y +CONFIG_USB_CONFIGFS_EEM=y +CONFIG_USB_CONFIGFS_F_HID=y +CONFIG_USB_CONFIGFS_MASS_STORAGE=y +CONFIG_USB_CONFIGFS_RNDIS=y +CONFIG_USB_CONFIGFS=y +CONFIG_USB_F_ECM=y +CONFIG_USB_F_EEM=y +CONFIG_USB_F_MASS_STORAGE=y +CONFIG_USB_F_RNDIS=y +CONFIG_USB_F_SUBSET=y +CONFIG_USB_GADGET_NPCM_USB2=y +CONFIG_USB_NPCM_UDC=y +CONFIG_USB_OHCI_HCD_NPCM7XX=y +CONFIG_USB_SERIAL_CP210X=y +CONFIG_USB_U_ETHER=y + +#SPI +CONFIG_SPI=y +CONFIG_SPI_NPCM_FIU=y +CONFIG_SPI_NPCM_PSPI=y + +#I2C support +CONFIG_I2C_MUX_LTC4306=y +CONFIG_I2C_MUX_PCA954x=y +CONFIG_I2C_MUX=y +CONFIG_I2C_SLAVE_EEPROM=y +CONFIG_I2C_SLAVE_MQUEUE=y +CONFIG_I2C_SLAVE=y + +#I2C GPIO expanders +CONFIG_GPIO_PCA953X_IRQ=y +CONFIG_GPIO_PCA953X=y +CONFIG_GPIO_PCF857X=y + +# Misc +CONFIG_OVERLAY_FS=y +CONFIG_JFFS2_FS=y +CONFIG_SQUASHFS_XZ=y +CONFIG_SQUASHFS=y +CONFIG_RESET_CONTROLLER=y +CONFIG_RESET_NPCM=y +CONFIG_IPVLAN=y +CONFIG_VLAN_8021Q=y +CONFIG_DEVKMEM=y +CONFIG_EEPROM_AT24=y +CONFIG_FORCE_MAX_ZONEORDER=12 +CONFIG_IIO_MUX=y +CONFIG_IIO=y +CONFIG_MEDIA_SUPPORT=y +CONFIG_MFD_SYSCON=y +CONFIG_MTD_M25P80=y +CONFIG_MUX_MMIO=y +CONFIG_NPCM7XX_LPC_BPC=y +CONFIG_MTD_PARTITIONED_MASTER=y diff --git a/meta-quanta/meta-gbs/recipes-kernel/linux/linux-nuvoton_%.bbappend b/meta-quanta/meta-gbs/recipes-kernel/linux/linux-nuvoton_%.bbappend new file mode 100644 index 0000000000..6347ff6384 --- /dev/null +++ b/meta-quanta/meta-gbs/recipes-kernel/linux/linux-nuvoton_%.bbappend @@ -0,0 +1,6 @@ +FILESEXTRAPATHS_prepend_gbs := "${THISDIR}/linux-nuvoton:" +SRC_URI_append_gbs = " file://gbs.cfg" +SRC_URI_append_gbs = " file://0003-Add-basic-support-for-SB-TSI-sensors.patch" +SRC_URI_append_gbs = " file://0004-Add-kernel-seven-seg-display-support.patch" +SRC_URI_append_gbs = " file://0004-ben-drivers-misc-Character-device-driver-for-seven-segme.patch" +SRC_URI_append_gbs = " file://0004-ben-drivers-misc-Platform-driver-for-seven-segment-displ.patch" |