From patchwork Wed Mar 6 12:01:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yifeng Li X-Patchwork-Id: 10841039 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3F755922 for ; Wed, 6 Mar 2019 12:01:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 29BDF2D77F for ; Wed, 6 Mar 2019 12:01:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 27C672D78A; Wed, 6 Mar 2019 12:01:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BE95D2D77F for ; Wed, 6 Mar 2019 12:01:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729322AbfCFMBw (ORCPT ); Wed, 6 Mar 2019 07:01:52 -0500 Received: from tomli.me ([153.92.126.73]:46566 "EHLO tomli.me" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728931AbfCFMBv (ORCPT ); Wed, 6 Mar 2019 07:01:51 -0500 Received: from tomli.me (localhost [127.0.0.1]) by tomli.me (OpenSMTPD) with ESMTP id b1805f05; Wed, 6 Mar 2019 12:01:47 +0000 (UTC) X-HELO: localhost.lan Authentication-Results: tomli.me; auth=pass (login) smtp.auth=tomli Received: from Unknown (HELO localhost.lan) (2402:f000:1:1501:200:5efe:72f4:b31) by tomli.me (qpsmtpd/0.95) with ESMTPSA (DHE-RSA-CHACHA20-POLY1305 encrypted); Wed, 06 Mar 2019 12:01:47 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=tomli.me; h=from:to:cc:subject:date:message-id:in-reply-to:references:mime-version:content-transfer-encoding; s=1490979754; bh=6UP7evsB5DiA1c51E/dcR3ifoH0kTZtCTScpZbR12YE=; b=jZhhdyW0pZQEun25S6lQG2cSmoisvqEDtiVplLc/NmUImTuk2epwOeRGefnk2qfaZqW/ajqtRkn8jutM7G3OLjCCDgh/3QhsCVjrHyRZg+07T7cChDrywBCzIhOwG5zDvxAPcova6Mr84cwLimNMWsrV/Nj9cudAJ1+rDllgvnTIQzJzr//JQAJyJkfwdIHpUIgnh/N14XnfMfOZ4h1OqVOB/sOnZY+6Erev1vm/DahdYOWuqFtcYDEOpvinSm118F0XZSXdzIg6gf7AssUrzhtitMQiUF5T/DjVYqeYrJ+zEfNQrOqYWBbC7upa0QTQGPU7oDnbzyWl5fQZfZlJsw== From: Yifeng Li To: Lee Jones , linux-mips@vger.kernel.org, Paul Burton Cc: Yifeng Li , Jiaxun Yang , Huacai Chen , Ralf Baechle , James Hogan , linux-kernel@vger.kernel.org Subject: [PATCH v3 1/7] mfd: yeeloong_kb3310b: support KB3310B EC for Lemote Yeeloong laptops. Date: Wed, 6 Mar 2019 20:01:07 +0800 Message-Id: <20190306120113.648-2-tomli@tomli.me> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190306120113.648-1-tomli@tomli.me> References: <20190306120113.648-1-tomli@tomli.me> MIME-Version: 1.0 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Lemote Yeeloong is a laptop powered by Loongson 2F MIPS processor, primarily a demo platform for hobbyists and developers. It uses an ENE KB3310B Embedded Controller with customized firmware to implement hardware and power management. A monolithic platform driver code for those functionality has existed out-of-tree for many years. This commit creates a MFD driver for the EC chip on Yeeloong laptop to isolate EC-related code from core MIPS code, and serves as the foundation of various subdrivers. NOTE: A regmap could be the reasonable abstraction for I/O, but (1) it requires some additional refactoring to convert the shutdown/wakeup routines in board files to subdrivers, and (2) we're only using simple reads/writes, repmap only adds boilerplates to the existing files without additional benefits. We simply export the EC-related functions for now, until we come back to refactor the board files. Signed-off-by: Yifeng Li --- MAINTAINERS | 7 + drivers/mfd/Kconfig | 10 ++ drivers/mfd/Makefile | 1 + drivers/mfd/yeeloong_kb3310b.c | 200 +++++++++++++++++++++++++ include/linux/mfd/yeeloong_kb3310b.h | 211 +++++++++++++++++++++++++++ 5 files changed, 429 insertions(+) create mode 100644 drivers/mfd/yeeloong_kb3310b.c create mode 100644 include/linux/mfd/yeeloong_kb3310b.h diff --git a/MAINTAINERS b/MAINTAINERS index 51029a425dbe..208f19801a23 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -16839,6 +16839,13 @@ S: Maintained F: Documentation/input/devices/yealink.rst F: drivers/input/misc/yealink.* +YEELOONG ENE KB3310B MFD DRIVER +M: Tom Li +L: linux-mips@vger.kernel.org +S: Maintained +F: drivers/mfd/yeeloong_kb3310b.c +F: include/linux/mfd/yeeloong_kb3310b.h + Z8530 DRIVER FOR AX.25 M: Joerg Reuter W: http://yaina.de/jreuter/ diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index f461460a2aeb..a6da8cce72fc 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig @@ -1872,6 +1872,16 @@ config MFD_STM32_TIMERS for PWM and IIO Timer. This driver allow to share the registers between the others drivers. +config MFD_YEELOONG_KB3310B + bool "ENE KB3310B Embedded Controller on Lemote Yeeloong laptops" + depends on (MIPS && LEMOTE_MACH2F) || COMPILE_TEST + select MFD_CORE + help + Select this option to enable ENE KB3310B Embedded Controller + driver used on Lemote Yeeloong laptops, providing power, battery + and backlight services. This is a mandatory dependency for + Lemote 2F systems. + menu "Multimedia Capabilities Port drivers" depends on ARCH_SA1100 diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile index 12980a4ad460..a3446ce7c384 100644 --- a/drivers/mfd/Makefile +++ b/drivers/mfd/Makefile @@ -224,6 +224,7 @@ obj-$(CONFIG_MFD_HI655X_PMIC) += hi655x-pmic.o obj-$(CONFIG_MFD_DLN2) += dln2.o obj-$(CONFIG_MFD_RT5033) += rt5033.o obj-$(CONFIG_MFD_SKY81452) += sky81452.o +obj-$(CONFIG_MFD_YEELOONG_KB3310B) += yeeloong_kb3310b.o intel-soc-pmic-objs := intel_soc_pmic_core.o intel_soc_pmic_crc.o obj-$(CONFIG_INTEL_SOC_PMIC) += intel-soc-pmic.o diff --git a/drivers/mfd/yeeloong_kb3310b.c b/drivers/mfd/yeeloong_kb3310b.c new file mode 100644 index 000000000000..423d5ced2f65 --- /dev/null +++ b/drivers/mfd/yeeloong_kb3310b.c @@ -0,0 +1,200 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +/* + * MFD driver for ENE KB3310B embedded controller on Lemote Yeeloong laptops + * + * Copyright (C) 2008 Lemote Inc. + * Author: liujl , 2008-04-20 + * + * Copyright (C) 2019 Yifeng Li + * Author: Yifeng Li + * + * This is a MFD driver for the ENE KB3310B Embedded Controller for Lemote + * Yeeloong laptops to provide utility functions to access the chip from + * subdrivers, and handle events and interrupts in board files. This is a + * special-purpose driver, and it's only used on Lemote Yeeloong laptops, + * and is a mandatory dependency. + * + * NOTE: A regmap could be the reasonable abstraction for I/O, but (1) + * it requires some additional refactoring to convert the shutdown/wakeup + * routines in board files to subdrivers, and (2) we're only using simple + * reads/writes, repmap only adds boilerplates to the existing files without + * additional benefits. We simply export the EC-related functions for now, + * until we come back to refactor the board files. + */ + +#include +#include +#include +#include +#include + +#include + +#ifdef pr_fmt +#undef pr_fmt +#endif + +#define DRV_NAME "yeeloong_kb3310b" +#define pr_fmt(fmt) DRV_NAME ": " fmt + +/* + * Most drivers, such as battery or backlight drivers, uses the I/O ports to + * access the Index Registers to obtain hardware status and information from + * EC chip. + */ +static struct kb3310b_chip *kb3310b_fwinfo; + +static const struct mfd_cell kb3310b_cells[] = { + { .name = "yeeloong_sci" }, + { .name = "yeeloong_hwmon" }, + { .name = "yeeloong_battery" }, + { .name = "yeeloong_backlight" }, + { .name = "yeeloong_lcd" }, + { .name = "yeeloong_hotkey" }, +}; + +static DEFINE_SPINLOCK(kb3310b_index_lock); + +u8 kb3310b_read(u16 reg) +{ + unsigned long flags; + u8 val; + + spin_lock_irqsave(&kb3310b_index_lock, flags); + + outb((reg & 0xff00) >> 8, KB3310B_IO_PORT_HIGH); + outb((reg & 0x00ff), KB3310B_IO_PORT_LOW); + val = inb(KB3310B_IO_PORT_DATA); + + spin_unlock_irqrestore(&kb3310b_index_lock, flags); + + return val; +} +EXPORT_SYMBOL_GPL(kb3310b_read); + +void kb3310b_write(u16 reg, u8 val) +{ + unsigned long flags; + + spin_lock_irqsave(&kb3310b_index_lock, flags); + + outb((reg & 0xff00) >> 8, KB3310B_IO_PORT_HIGH); + outb((reg & 0x00ff), KB3310B_IO_PORT_LOW); + outb(val, KB3310B_IO_PORT_DATA); + inb(KB3310B_IO_PORT_DATA); /* flush pending writes */ + + spin_unlock_irqrestore(&kb3310b_index_lock, flags); +} +EXPORT_SYMBOL_GPL(kb3310b_write); + +bool kb3310b_fw_earlier(char *version) +{ + return (strncasecmp(kb3310b_fwinfo->version, + version, KB3310B_VERSION_LEN) < 0); +} +EXPORT_SYMBOL_GPL(kb3310b_fw_earlier); + +static int kb3310b_probe(struct platform_device *pdev) +{ + kb3310b_fwinfo = dev_get_platdata(&pdev->dev); + pr_info("firmware version %s", kb3310b_fwinfo->version); + + return devm_mfd_add_devices(&pdev->dev, -1, kb3310b_cells, + ARRAY_SIZE(kb3310b_cells), NULL, 0, NULL); +} + +static struct platform_driver kb3310b_driver = { + .driver = { + .name = "yeeloong_kb3310b", + }, + .probe = kb3310b_probe, +}; +builtin_platform_driver(kb3310b_driver); + +/* + * For interrupt handling and power management, the EC chip is also needed to + * be queried from the board file at arch/mips/loongson64, through a separate + * command port. + */ + +/* + * This function is used for EC command writes and corresponding status queries. + */ +int kb3310b_query_seq(unsigned char cmd) +{ + int timeout; + unsigned char status; + + static DEFINE_SPINLOCK(kb3310b_command_lock); + unsigned long flags; + + spin_lock_irqsave(&kb3310b_command_lock, flags); + + /* make chip goto reset mode */ + udelay(KB3310B_REG_UDELAY); + outb(cmd, KB3310B_CMD_PORT); + udelay(KB3310B_REG_UDELAY); + + /* check if the command is received by EC */ + timeout = KB3310B_CMD_TIMEOUT; + status = inb(KB3310B_STS_PORT); + while (timeout-- && (status & (1 << 1))) { + status = inb(KB3310B_STS_PORT); + udelay(KB3310B_REG_UDELAY); + } + + spin_unlock_irqrestore(&kb3310b_command_lock, flags); + + if (timeout <= 0) { + pr_err("(%x/NA) failed to issue command %d, no response!\n", + timeout, cmd); + return -EINVAL; + } + + pr_info("(%x/%x) issued command %d, status: 0x%x\n", + timeout, KB3310B_CMD_TIMEOUT - timeout, + cmd, status); + + return 0; +} +EXPORT_SYMBOL_GPL(kb3310b_query_seq); + +/* + * Send query command to EC to get the proper event number. + */ +int kb3310b_query_event_num(void) +{ + return kb3310b_query_seq(KB3310B_CMD_GET_EVENT_NUM); +} +EXPORT_SYMBOL_GPL(kb3310b_query_event_num); + +/* + * Get event number from EC. + * + * NOTE: This routine must follow the query_event_num function in the + * interrupt. + */ +int kb3310b_get_event_num(void) +{ + int timeout = 100; + unsigned char value; + unsigned char status; + + udelay(KB3310B_REG_UDELAY); + status = inb(KB3310B_STS_PORT); + udelay(KB3310B_REG_UDELAY); + while (timeout-- && !(status & (1 << 0))) { + status = inb(KB3310B_STS_PORT); + udelay(KB3310B_REG_UDELAY); + } + if (timeout <= 0) { + pr_info("%s: get event number timeout.\n", __func__); + return -EINVAL; + } + value = inb(KB3310B_DAT_PORT); + udelay(KB3310B_REG_UDELAY); + + return value; +} +EXPORT_SYMBOL_GPL(kb3310b_get_event_num); diff --git a/include/linux/mfd/yeeloong_kb3310b.h b/include/linux/mfd/yeeloong_kb3310b.h new file mode 100644 index 000000000000..ba8b82153bcd --- /dev/null +++ b/include/linux/mfd/yeeloong_kb3310b.h @@ -0,0 +1,211 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +/* + * MFD driver for ENE KB3310B embedded controller on Lemote Yeeloong laptops + * + * Copyright (C) 2008 Lemote Inc. + * Author: liujl , 2008-04-20 + * + * Copyright (C) 2019 Yifeng Li + * Author: Yifeng Li + */ + +#ifndef __LINUX_MFD_YEELOONG_KB3310B_H +#define __LINUX_MFD_YEELOONG_KB3310B_H + +extern u8 kb3310b_read(u16 reg); +extern void kb3310b_write(u16 reg, u8 val); +extern bool kb3310b_fw_earlier(char *version); +extern int kb3310b_query_seq(unsigned char cmd); +extern int kb3310b_query_event_num(void); +extern int kb3310b_get_event_num(void); + +typedef int (*sci_handler) (int status); + +extern int yeeloong_sci_register_notify(struct notifier_block *nb); +extern int yeeloong_sci_unregister_notify(struct notifier_block *nb); + +#define KB3310B_VERSION_LEN 8 + +struct kb3310b_chip { + char version[KB3310B_VERSION_LEN]; +}; + +#define KB3310B_SCI_IRQ_NUM 0x0A + +/* + * The following registers are determined by the EC index configuration. + * 1, fill the PORT_HIGH as EC register high part. + * 2, fill the PORT_LOW as EC register low part. + * 3, fill the PORT_DATA as EC register write data or get the data from it. + */ +#define KB3310B_IO_PORT_HIGH 0x0381 +#define KB3310B_IO_PORT_LOW 0x0382 +#define KB3310B_IO_PORT_DATA 0x0383 + +/* + * EC delay time is 500us for register and status access + */ +#define KB3310B_REG_UDELAY 500 +#define KB3310B_CMD_TIMEOUT 0x1000 + +/* + * EC access port for SCI communication + */ +#define KB3310B_CMD_PORT 0x66 +#define KB3310B_STS_PORT 0x66 +#define KB3310B_DAT_PORT 0x62 +#define KB3310B_CMD_INIT_IDLE_MODE 0xdd +#define KB3310B_CMD_EXIT_IDLE_MODE 0xdf +#define KB3310B_CMD_INIT_RESET_MODE 0xd8 +#define KB3310B_CMD_REBOOT_SYSTEM 0x8c +#define KB3310B_CMD_GET_EVENT_NUM 0x84 +#define KB3310B_CMD_PROGRAM_PIECE 0xda + +/* temperature & fan registers */ +#define KB3310B_REG_TEMPERATURE_VALUE 0xF458 +#define KB3310B_REG_FAN_AUTO_MAN_SWITCH 0xF459 +#define KB3310B_BIT_FAN_AUTO 0 +#define KB3310B_BIT_FAN_MANUAL 1 +#define KB3310B_REG_FAN_CONTROL 0xF4D2 +#define KB3310B_BIT_FAN_CONTROL_ON (1 << 0) +#define KB3310B_BIT_FAN_CONTROL_OFF (0 << 0) +#define KB3310B_REG_FAN_STATUS 0xF4DA +#define KB3310B_BIT_FAN_STATUS_ON (1 << 0) +#define KB3310B_BIT_FAN_STATUS_OFF (0 << 0) +#define KB3310B_REG_FAN_SPEED_HIGH 0xFE22 +#define KB3310B_REG_FAN_SPEED_LOW 0xFE23 +#define KB3310B_REG_FAN_SPEED_LEVEL 0xF4CC + +/* fan speed divider */ +#define KB3310B_FAN_SPEED_DIVIDER 480000 /* (60*1000*1000/62.5/2)*/ + +/* battery registers */ +#define KB3310B_REG_BAT_DESIGN_CAP_HIGH 0xF77D +#define KB3310B_REG_BAT_DESIGN_CAP_LOW 0xF77E +#define KB3310B_REG_BAT_FULLCHG_CAP_HIGH 0xF780 +#define KB3310B_REG_BAT_FULLCHG_CAP_LOW 0xF781 +#define KB3310B_REG_BAT_DESIGN_VOL_HIGH 0xF782 +#define KB3310B_REG_BAT_DESIGN_VOL_LOW 0xF783 +#define KB3310B_REG_BAT_CURRENT_HIGH 0xF784 +#define KB3310B_REG_BAT_CURRENT_LOW 0xF785 +#define KB3310B_REG_BAT_VOLTAGE_HIGH 0xF786 +#define KB3310B_REG_BAT_VOLTAGE_LOW 0xF787 +#define KB3310B_REG_BAT_TEMPERATURE_HIGH 0xF788 +#define KB3310B_REG_BAT_TEMPERATURE_LOW 0xF789 +#define KB3310B_REG_BAT_RELATIVE_CAP_HIGH 0xF492 +#define KB3310B_REG_BAT_RELATIVE_CAP_LOW 0xF493 +#define KB3310B_REG_BAT_VENDOR 0xF4C4 +#define KB3310B_FLAG_BAT_VENDOR_SANYO 0x01 +#define KB3310B_FLAG_BAT_VENDOR_SIMPLO 0x02 +#define KB3310B_REG_BAT_CELL_COUNT 0xF4C6 +#define KB3310B_FLAG_BAT_CELL_3S1P 0x03 +#define KB3310B_FLAG_BAT_CELL_3S2P 0x06 +#define KB3310B_REG_BAT_CHARGE 0xF4A2 +#define KB3310B_FLAG_BAT_CHARGE_DISCHARGE 0x01 +#define KB3310B_FLAG_BAT_CHARGE_CHARGE 0x02 +#define KB3310B_FLAG_BAT_CHARGE_ACPOWER 0x00 +#define KB3310B_REG_BAT_STATUS 0xF4B0 +#define KB3310B_BIT_BAT_STATUS_LOW (1 << 5) +#define KB3310B_BIT_BAT_STATUS_DESTROY (1 << 2) +#define KB3310B_BIT_BAT_STATUS_FULL (1 << 1) +#define KB3310B_BIT_BAT_STATUS_IN (1 << 0) +#define KB3310B_REG_BAT_CHARGE_STATUS 0xF4B1 +#define KB3310B_BIT_BAT_CHARGE_STATUS_OVERTEMP (1 << 2) +#define KB3310B_BIT_BAT_CHARGE_STATUS_PRECHG (1 << 1) +#define KB3310B_REG_BAT_STATE 0xF482 +#define KB3310B_BIT_BAT_STATE_CHARGING (1 << 1) +#define KB3310B_BIT_BAT_STATE_DISCHARGING (1 << 0) +#define KB3310B_REG_BAT_POWER 0xF440 +#define KB3310B_BIT_BAT_POWER_S3 (1 << 2) +#define KB3310B_BIT_BAT_POWER_ON (1 << 1) +#define KB3310B_BIT_BAT_POWER_ACIN (1 << 0) + +/* other registers */ + +/* Audio: rd/wr */ +#define KB3310B_REG_AUDIO_VOLUME 0xF46C +#define KB3310B_REG_AUDIO_MUTE 0xF4E7 +#define KB3310B_REG_AUDIO_BEEP 0xF4D0 + +/* USB port power or not: rd/wr */ +#define KB3310B_REG_USB0_FLAG 0xF461 +#define KB3310B_REG_USB1_FLAG 0xF462 +#define KB3310B_REG_USB2_FLAG 0xF463 +#define KB3310B_BIT_USB_FLAG_ON 1 +#define KB3310B_BIT_USB_FLAG_OFF 0 + +/* LID */ +#define KB3310B_REG_LID_DETECT 0xF4BD +#define KB3310B_BIT_LID_DETECT_ON 1 +#define KB3310B_BIT_LID_DETECT_OFF 0 + +/* CRT */ +#define KB3310B_REG_CRT_DETECT 0xF4AD +#define KB3310B_BIT_CRT_DETECT_PLUG 1 +#define KB3310B_BIT_CRT_DETECT_UNPLUG 0 + +/* LCD backlight brightness adjust: 9 levels */ +#define KB3310B_REG_DISPLAY_BRIGHTNESS 0xF4F5 + +/* Black screen status */ +#define KB3310B_REG_DISPLAY_LCD 0xF79F +#define KB3310B_BIT_DISPLAY_LCD_ON 1 +#define KB3310B_BIT_DISPLAY_LCD_OFF 0 + +/* LCD backlight control: off/restore */ +#define KB3310B_REG_BACKLIGHT_CTRL 0xF7BD +#define KB3310B_BIT_BACKLIGHT_ON 1 +#define KB3310B_BIT_BACKLIGHT_OFF 0 + +/* Reset the machine auto-clear: rd/wr */ +#define KB3310B_REG_RESET 0xF4EC +#define KB3310B_BIT_RESET_ON 1 + +/* Light the LED: rd/wr */ +#define KB3310B_REG_LED 0xF4C8 +#define KB3310B_BIT_LED_RED_POWER (1 << 0) +#define KB3310B_BIT_LED_ORANGE_POWER (1 << 1) +#define KB3310B_BIT_LED_GREEN_CHARGE (1 << 2) +#define KB3310B_BIT_LED_RED_CHARGE (1 << 3) +#define KB3310B_BIT_LED_NUMLOCK (1 << 4) + +/* Test LED mode, all LED on/off */ +#define KB3310B_REG_LED_TEST 0xF4C2 +#define KB3310B_BIT_LED_TEST_IN 1 +#define KB3310B_BIT_LED_TEST_OUT 0 + +/* Camera on/off */ +#define KB3310B_REG_CAMERA_STATUS 0xF46A +#define KB3310B_BIT_CAMERA_STATUS_ON 1 +#define KB3310B_BIT_CAMERA_STATUS_OFF 0 +#define KB3310B_REG_CAMERA_CONTROL 0xF7B7 +#define KB3310B_BIT_CAMERA_CONTROL_OFF 0 +#define KB3310B_BIT_CAMERA_CONTROL_ON 1 + +/* WLAN Status */ +#define KB3310B_REG_WLAN 0xF4FA +#define KB3310B_BIT_WLAN_ON 1 +#define KB3310B_BIT_WLAN_OFF 0 + +/* SCI Event Number from EC */ +enum { + KB3310B_EVENT_START = 0x22, + KB3310B_EVENT_LID = 0x23, /* LID open/close */ + KB3310B_EVENT_DISPLAY_TOGGLE, /* Fn+F3 for display switch */ + KB3310B_EVENT_SLEEP, /* Fn+F1 for entering sleep mode */ + KB3310B_EVENT_OVERTEMP, /* Over-temperature occurred */ + KB3310B_EVENT_CRT_DETECT, /* CRT is connected */ + KB3310B_EVENT_CAMERA, /* Camera on/off */ + KB3310B_EVENT_USB_OC2, /* USB2 Overcurrent occurred */ + KB3310B_EVENT_USB_OC0, /* USB0 Overcurrent occurred */ + KB3310B_EVENT_BLACK_SCREEN, /* Turn on/off backlight */ + KB3310B_EVENT_AUDIO_MUTE, /* Mute on/off */ + KB3310B_EVENT_DISPLAY_BRIGHTNESS, /* LCD backlight brightness adjust */ + KB3310B_EVENT_AC_BAT, /* AC & Battery relative issue */ + KB3310B_EVENT_AUDIO_VOLUME, /* Volume adjust */ + KB3310B_EVENT_WLAN, /* WLAN on/off */ + KB3310B_EVENT_END +}; + +#endif /* !__LINUX_MFD_YEELOONG_KB3310B_H */ From patchwork Wed Mar 6 12:01:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yifeng Li X-Patchwork-Id: 10841041 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C2421922 for ; Wed, 6 Mar 2019 12:01:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B03D62D771 for ; Wed, 6 Mar 2019 12:01:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AE9272D780; Wed, 6 Mar 2019 12:01:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 639082D768 for ; Wed, 6 Mar 2019 12:01:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728931AbfCFMB4 (ORCPT ); Wed, 6 Mar 2019 07:01:56 -0500 Received: from tomli.me ([153.92.126.73]:46566 "EHLO tomli.me" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729354AbfCFMBz (ORCPT ); Wed, 6 Mar 2019 07:01:55 -0500 Received: from tomli.me (localhost [127.0.0.1]) by tomli.me (OpenSMTPD) with ESMTP id d71f245c; Wed, 6 Mar 2019 12:01:52 +0000 (UTC) X-HELO: localhost.lan Authentication-Results: tomli.me; auth=pass (login) smtp.auth=tomli Received: from Unknown (HELO localhost.lan) (2402:f000:1:1501:200:5efe:72f4:b31) by tomli.me (qpsmtpd/0.95) with ESMTPSA (DHE-RSA-CHACHA20-POLY1305 encrypted); Wed, 06 Mar 2019 12:01:52 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=tomli.me; h=from:to:cc:subject:date:message-id:in-reply-to:references:mime-version:content-transfer-encoding; s=1490979754; bh=g98gt4epZhMmQBBYY5nZu5LNFHdlzQA76yj3bYjm22E=; b=pvcxLtZ5upQUQlbRhuHtkjB8wLRWrNAI0a/IHL6jA3GIw2plPJpJw835p+mhCDuOAhuQK7gm83df7Bgrv51/0QLCdwTrzWZuN/sl/KQrJN5hUqBWW20d2naibhz9zRQhFEa6oP9jOXn9RFwurxMwKYVyBOb+xRwNEXXcN1Klkk3ycLTbmhrgU/D7JlGq//kGVhTraTg7+78e3C/sMVzvJlsLqG1Ay9BDEgkOMppxgv2xs8FKAteLP6OdDAJqojuy+E+Ga7A6yfTxwVAspCnNc5ZLZbkOEDZ3IzmultAON8ZevKwoGFxDx4v8FQNk6FHg+zV2jc1LXE2zvAPKddhOfg== From: Yifeng Li To: Lee Jones , linux-mips@vger.kernel.org, Paul Burton Cc: Yifeng Li , Jiaxun Yang , Huacai Chen , Ralf Baechle , James Hogan , linux-kernel@vger.kernel.org Subject: [PATCH v3 2/7] mips: loongson64: select MFD_YEELOONG_KB3310B for LEMOTE_MACH2F. Date: Wed, 6 Mar 2019 20:01:08 +0800 Message-Id: <20190306120113.648-3-tomli@tomli.me> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190306120113.648-1-tomli@tomli.me> References: <20190306120113.648-1-tomli@tomli.me> MIME-Version: 1.0 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP To ease the support of platform drivers on Lemote Yeeloong laptop, code for accessing the embedded controller has been separated from arch/mips, as a MFD driver. Since the board files here still need to access the EC directly to handle reboot/shutdown and interrupts, we make MFD_YEELOONG_KB3310B as a mandatory dependency. Signed-off-by: Yifeng Li --- arch/mips/loongson64/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/mips/loongson64/Kconfig b/arch/mips/loongson64/Kconfig index 4c14a11525f4..b423d5bba812 100644 --- a/arch/mips/loongson64/Kconfig +++ b/arch/mips/loongson64/Kconfig @@ -56,6 +56,7 @@ config LEMOTE_MACH2F select SYS_SUPPORTS_HIGHMEM select SYS_SUPPORTS_LITTLE_ENDIAN select LOONGSON_MC146818 + select MFD_YEELOONG_KB3310B help Lemote Loongson 2F family machines utilize the 2F revision of Loongson processor and the AMD CS5536 south bridge. From patchwork Wed Mar 6 12:01:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yifeng Li X-Patchwork-Id: 10841043 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CAD3F922 for ; Wed, 6 Mar 2019 12:02:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B33A52D77F for ; Wed, 6 Mar 2019 12:02:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B13652D79A; Wed, 6 Mar 2019 12:02:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8E5E72D78A for ; Wed, 6 Mar 2019 12:02:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729486AbfCFMCC (ORCPT ); Wed, 6 Mar 2019 07:02:02 -0500 Received: from tomli.me ([153.92.126.73]:46566 "EHLO tomli.me" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729434AbfCFMCB (ORCPT ); Wed, 6 Mar 2019 07:02:01 -0500 Received: from tomli.me (localhost [127.0.0.1]) by tomli.me (OpenSMTPD) with ESMTP id 9367809d; Wed, 6 Mar 2019 12:01:57 +0000 (UTC) X-HELO: localhost.lan Authentication-Results: tomli.me; auth=pass (login) smtp.auth=tomli Received: from Unknown (HELO localhost.lan) (2402:f000:1:1501:200:5efe:72f4:b31) by tomli.me (qpsmtpd/0.95) with ESMTPSA (DHE-RSA-CHACHA20-POLY1305 encrypted); Wed, 06 Mar 2019 12:01:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=tomli.me; h=from:to:cc:subject:date:message-id:in-reply-to:references:mime-version:content-transfer-encoding; s=1490979754; bh=uMmr+paLH3oxbIjnf44KpHw1/0fMpGkylyvaTPhBq3U=; b=KKo6NelW0sv6Xw/PqkehXS3OjYD/PJrRwMicq6IeoL7Uxh1zljCm+ev5VgSEqoIrz/Lh1sICdBr3SWflQ70UBmvrmwkHBFD9+IeHNTurksZ5v0FfNfdxvi4lC+bNf/LRonF51Smau4ogQIjwX/zsYGNeOK1oNIzc/BNyA3jdFgphwzF0w7ptHL8ThIGLTYg6A12C8lhc9tzh4HBj0Miso+CG/gnEdcMsOdgEFXkeI+DFZ8DMAQMPSWhRhhWIfok4fvEMo/gfTRMZiDn8J9kiaW5IILy+7gyrXu7/rQP0p1+CWLMMIH0EzQD1KHl7XQKbaQtspUe3Xvth1bz/+IQV6A== From: Yifeng Li To: Lee Jones , linux-mips@vger.kernel.org, Paul Burton Cc: Yifeng Li , Jiaxun Yang , Huacai Chen , Ralf Baechle , James Hogan , linux-kernel@vger.kernel.org Subject: [PATCH v3 3/7] mips: loongson64: remove ec_kb3310b.c, use MFD driver. Date: Wed, 6 Mar 2019 20:01:09 +0800 Message-Id: <20190306120113.648-4-tomli@tomli.me> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190306120113.648-1-tomli@tomli.me> References: <20190306120113.648-1-tomli@tomli.me> MIME-Version: 1.0 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We have already converted the supporting code for ENE KB3310B embedded controller as a separate MFD driver, and select it as a dependency of LEMOTE_MACH2F. This commit removes the original implementation of ec_kb3310b.c, and converts all EC operations to use the utility function provided by the yeeloong_kb3310b MFD driver instead. Signed-off-by: Yifeng Li --- arch/mips/loongson64/lemote-2f/Makefile | 2 +- arch/mips/loongson64/lemote-2f/ec_kb3310b.c | 129 -------------- arch/mips/loongson64/lemote-2f/ec_kb3310b.h | 188 -------------------- arch/mips/loongson64/lemote-2f/pm.c | 18 +- arch/mips/loongson64/lemote-2f/reset.c | 4 +- 5 files changed, 12 insertions(+), 329 deletions(-) delete mode 100644 arch/mips/loongson64/lemote-2f/ec_kb3310b.c delete mode 100644 arch/mips/loongson64/lemote-2f/ec_kb3310b.h diff --git a/arch/mips/loongson64/lemote-2f/Makefile b/arch/mips/loongson64/lemote-2f/Makefile index b5792c334cd5..ac97f14ea2b7 100644 --- a/arch/mips/loongson64/lemote-2f/Makefile +++ b/arch/mips/loongson64/lemote-2f/Makefile @@ -2,7 +2,7 @@ # Makefile for lemote loongson2f family machines # -obj-y += clock.o machtype.o irq.o reset.o dma.o ec_kb3310b.o +obj-y += clock.o machtype.o irq.o reset.o dma.o # # Suspend Support diff --git a/arch/mips/loongson64/lemote-2f/ec_kb3310b.c b/arch/mips/loongson64/lemote-2f/ec_kb3310b.c deleted file mode 100644 index 321822997e76..000000000000 --- a/arch/mips/loongson64/lemote-2f/ec_kb3310b.c +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Basic KB3310B Embedded Controller support for the YeeLoong 2F netbook - * - * Copyright (C) 2008 Lemote Inc. - * Author: liujl , 2008-04-20 - * - * 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. - */ - -#include -#include -#include -#include - -#include "ec_kb3310b.h" - -static DEFINE_SPINLOCK(index_access_lock); -static DEFINE_SPINLOCK(port_access_lock); - -unsigned char ec_read(unsigned short addr) -{ - unsigned char value; - unsigned long flags; - - spin_lock_irqsave(&index_access_lock, flags); - outb((addr & 0xff00) >> 8, EC_IO_PORT_HIGH); - outb((addr & 0x00ff), EC_IO_PORT_LOW); - value = inb(EC_IO_PORT_DATA); - spin_unlock_irqrestore(&index_access_lock, flags); - - return value; -} -EXPORT_SYMBOL_GPL(ec_read); - -void ec_write(unsigned short addr, unsigned char val) -{ - unsigned long flags; - - spin_lock_irqsave(&index_access_lock, flags); - outb((addr & 0xff00) >> 8, EC_IO_PORT_HIGH); - outb((addr & 0x00ff), EC_IO_PORT_LOW); - outb(val, EC_IO_PORT_DATA); - /* flush the write action */ - inb(EC_IO_PORT_DATA); - spin_unlock_irqrestore(&index_access_lock, flags); -} -EXPORT_SYMBOL_GPL(ec_write); - -/* - * This function is used for EC command writes and corresponding status queries. - */ -int ec_query_seq(unsigned char cmd) -{ - int timeout; - unsigned char status; - unsigned long flags; - int ret = 0; - - spin_lock_irqsave(&port_access_lock, flags); - - /* make chip goto reset mode */ - udelay(EC_REG_DELAY); - outb(cmd, EC_CMD_PORT); - udelay(EC_REG_DELAY); - - /* check if the command is received by ec */ - timeout = EC_CMD_TIMEOUT; - status = inb(EC_STS_PORT); - while (timeout-- && (status & (1 << 1))) { - status = inb(EC_STS_PORT); - udelay(EC_REG_DELAY); - } - - spin_unlock_irqrestore(&port_access_lock, flags); - - if (timeout <= 0) { - printk(KERN_ERR "%s: deadable error : timeout...\n", __func__); - ret = -EINVAL; - } else - printk(KERN_INFO - "(%x/%d)ec issued command %d status : 0x%x\n", - timeout, EC_CMD_TIMEOUT - timeout, cmd, status); - - return ret; -} -EXPORT_SYMBOL_GPL(ec_query_seq); - -/* - * Send query command to EC to get the proper event number - */ -int ec_query_event_num(void) -{ - return ec_query_seq(CMD_GET_EVENT_NUM); -} -EXPORT_SYMBOL(ec_query_event_num); - -/* - * Get event number from EC - * - * NOTE: This routine must follow the query_event_num function in the - * interrupt. - */ -int ec_get_event_num(void) -{ - int timeout = 100; - unsigned char value; - unsigned char status; - - udelay(EC_REG_DELAY); - status = inb(EC_STS_PORT); - udelay(EC_REG_DELAY); - while (timeout-- && !(status & (1 << 0))) { - status = inb(EC_STS_PORT); - udelay(EC_REG_DELAY); - } - if (timeout <= 0) { - pr_info("%s: get event number timeout.\n", __func__); - - return -EINVAL; - } - value = inb(EC_DAT_PORT); - udelay(EC_REG_DELAY); - - return value; -} -EXPORT_SYMBOL(ec_get_event_num); diff --git a/arch/mips/loongson64/lemote-2f/ec_kb3310b.h b/arch/mips/loongson64/lemote-2f/ec_kb3310b.h deleted file mode 100644 index 5a3f1860d4d2..000000000000 --- a/arch/mips/loongson64/lemote-2f/ec_kb3310b.h +++ /dev/null @@ -1,188 +0,0 @@ -/* - * KB3310B Embedded Controller - * - * Copyright (C) 2008 Lemote Inc. - * Author: liujl , 2008-03-14 - * - * 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. - */ - -#ifndef _EC_KB3310B_H -#define _EC_KB3310B_H - -extern unsigned char ec_read(unsigned short addr); -extern void ec_write(unsigned short addr, unsigned char val); -extern int ec_query_seq(unsigned char cmd); -extern int ec_query_event_num(void); -extern int ec_get_event_num(void); - -typedef int (*sci_handler) (int status); -extern sci_handler yeeloong_report_lid_status; - -#define SCI_IRQ_NUM 0x0A - -/* - * The following registers are determined by the EC index configuration. - * 1, fill the PORT_HIGH as EC register high part. - * 2, fill the PORT_LOW as EC register low part. - * 3, fill the PORT_DATA as EC register write data or get the data from it. - */ -#define EC_IO_PORT_HIGH 0x0381 -#define EC_IO_PORT_LOW 0x0382 -#define EC_IO_PORT_DATA 0x0383 - -/* - * EC delay time is 500us for register and status access - */ -#define EC_REG_DELAY 500 /* unit : us */ -#define EC_CMD_TIMEOUT 0x1000 - -/* - * EC access port for SCI communication - */ -#define EC_CMD_PORT 0x66 -#define EC_STS_PORT 0x66 -#define EC_DAT_PORT 0x62 -#define CMD_INIT_IDLE_MODE 0xdd -#define CMD_EXIT_IDLE_MODE 0xdf -#define CMD_INIT_RESET_MODE 0xd8 -#define CMD_REBOOT_SYSTEM 0x8c -#define CMD_GET_EVENT_NUM 0x84 -#define CMD_PROGRAM_PIECE 0xda - -/* temperature & fan registers */ -#define REG_TEMPERATURE_VALUE 0xF458 -#define REG_FAN_AUTO_MAN_SWITCH 0xF459 -#define BIT_FAN_AUTO 0 -#define BIT_FAN_MANUAL 1 -#define REG_FAN_CONTROL 0xF4D2 -#define BIT_FAN_CONTROL_ON (1 << 0) -#define BIT_FAN_CONTROL_OFF (0 << 0) -#define REG_FAN_STATUS 0xF4DA -#define BIT_FAN_STATUS_ON (1 << 0) -#define BIT_FAN_STATUS_OFF (0 << 0) -#define REG_FAN_SPEED_HIGH 0xFE22 -#define REG_FAN_SPEED_LOW 0xFE23 -#define REG_FAN_SPEED_LEVEL 0xF4CC -/* fan speed divider */ -#define FAN_SPEED_DIVIDER 480000 /* (60*1000*1000/62.5/2)*/ - -/* battery registers */ -#define REG_BAT_DESIGN_CAP_HIGH 0xF77D -#define REG_BAT_DESIGN_CAP_LOW 0xF77E -#define REG_BAT_FULLCHG_CAP_HIGH 0xF780 -#define REG_BAT_FULLCHG_CAP_LOW 0xF781 -#define REG_BAT_DESIGN_VOL_HIGH 0xF782 -#define REG_BAT_DESIGN_VOL_LOW 0xF783 -#define REG_BAT_CURRENT_HIGH 0xF784 -#define REG_BAT_CURRENT_LOW 0xF785 -#define REG_BAT_VOLTAGE_HIGH 0xF786 -#define REG_BAT_VOLTAGE_LOW 0xF787 -#define REG_BAT_TEMPERATURE_HIGH 0xF788 -#define REG_BAT_TEMPERATURE_LOW 0xF789 -#define REG_BAT_RELATIVE_CAP_HIGH 0xF492 -#define REG_BAT_RELATIVE_CAP_LOW 0xF493 -#define REG_BAT_VENDOR 0xF4C4 -#define FLAG_BAT_VENDOR_SANYO 0x01 -#define FLAG_BAT_VENDOR_SIMPLO 0x02 -#define REG_BAT_CELL_COUNT 0xF4C6 -#define FLAG_BAT_CELL_3S1P 0x03 -#define FLAG_BAT_CELL_3S2P 0x06 -#define REG_BAT_CHARGE 0xF4A2 -#define FLAG_BAT_CHARGE_DISCHARGE 0x01 -#define FLAG_BAT_CHARGE_CHARGE 0x02 -#define FLAG_BAT_CHARGE_ACPOWER 0x00 -#define REG_BAT_STATUS 0xF4B0 -#define BIT_BAT_STATUS_LOW (1 << 5) -#define BIT_BAT_STATUS_DESTROY (1 << 2) -#define BIT_BAT_STATUS_FULL (1 << 1) -#define BIT_BAT_STATUS_IN (1 << 0) -#define REG_BAT_CHARGE_STATUS 0xF4B1 -#define BIT_BAT_CHARGE_STATUS_OVERTEMP (1 << 2) -#define BIT_BAT_CHARGE_STATUS_PRECHG (1 << 1) -#define REG_BAT_STATE 0xF482 -#define BIT_BAT_STATE_CHARGING (1 << 1) -#define BIT_BAT_STATE_DISCHARGING (1 << 0) -#define REG_BAT_POWER 0xF440 -#define BIT_BAT_POWER_S3 (1 << 2) -#define BIT_BAT_POWER_ON (1 << 1) -#define BIT_BAT_POWER_ACIN (1 << 0) - -/* other registers */ -/* Audio: rd/wr */ -#define REG_AUDIO_VOLUME 0xF46C -#define REG_AUDIO_MUTE 0xF4E7 -#define REG_AUDIO_BEEP 0xF4D0 -/* USB port power or not: rd/wr */ -#define REG_USB0_FLAG 0xF461 -#define REG_USB1_FLAG 0xF462 -#define REG_USB2_FLAG 0xF463 -#define BIT_USB_FLAG_ON 1 -#define BIT_USB_FLAG_OFF 0 -/* LID */ -#define REG_LID_DETECT 0xF4BD -#define BIT_LID_DETECT_ON 1 -#define BIT_LID_DETECT_OFF 0 -/* CRT */ -#define REG_CRT_DETECT 0xF4AD -#define BIT_CRT_DETECT_PLUG 1 -#define BIT_CRT_DETECT_UNPLUG 0 -/* LCD backlight brightness adjust: 9 levels */ -#define REG_DISPLAY_BRIGHTNESS 0xF4F5 -/* Black screen Status */ -#define BIT_DISPLAY_LCD_ON 1 -#define BIT_DISPLAY_LCD_OFF 0 -/* LCD backlight control: off/restore */ -#define REG_BACKLIGHT_CTRL 0xF7BD -#define BIT_BACKLIGHT_ON 1 -#define BIT_BACKLIGHT_OFF 0 -/* Reset the machine auto-clear: rd/wr */ -#define REG_RESET 0xF4EC -#define BIT_RESET_ON 1 -/* Light the led: rd/wr */ -#define REG_LED 0xF4C8 -#define BIT_LED_RED_POWER (1 << 0) -#define BIT_LED_ORANGE_POWER (1 << 1) -#define BIT_LED_GREEN_CHARGE (1 << 2) -#define BIT_LED_RED_CHARGE (1 << 3) -#define BIT_LED_NUMLOCK (1 << 4) -/* Test led mode, all led on/off */ -#define REG_LED_TEST 0xF4C2 -#define BIT_LED_TEST_IN 1 -#define BIT_LED_TEST_OUT 0 -/* Camera on/off */ -#define REG_CAMERA_STATUS 0xF46A -#define BIT_CAMERA_STATUS_ON 1 -#define BIT_CAMERA_STATUS_OFF 0 -#define REG_CAMERA_CONTROL 0xF7B7 -#define BIT_CAMERA_CONTROL_OFF 0 -#define BIT_CAMERA_CONTROL_ON 1 -/* Wlan Status */ -#define REG_WLAN 0xF4FA -#define BIT_WLAN_ON 1 -#define BIT_WLAN_OFF 0 -#define REG_DISPLAY_LCD 0xF79F - -/* SCI Event Number from EC */ -enum { - EVENT_LID = 0x23, /* LID open/close */ - EVENT_DISPLAY_TOGGLE, /* Fn+F3 for display switch */ - EVENT_SLEEP, /* Fn+F1 for entering sleep mode */ - EVENT_OVERTEMP, /* Over-temperature happened */ - EVENT_CRT_DETECT, /* CRT is connected */ - EVENT_CAMERA, /* Camera on/off */ - EVENT_USB_OC2, /* USB2 Over Current occurred */ - EVENT_USB_OC0, /* USB0 Over Current occurred */ - EVENT_BLACK_SCREEN, /* Turn on/off backlight */ - EVENT_AUDIO_MUTE, /* Mute on/off */ - EVENT_DISPLAY_BRIGHTNESS,/* LCD backlight brightness adjust */ - EVENT_AC_BAT, /* AC & Battery relative issue */ - EVENT_AUDIO_VOLUME, /* Volume adjust */ - EVENT_WLAN, /* Wlan on/off */ - EVENT_END -}; - -#endif /* !_EC_KB3310B_H */ diff --git a/arch/mips/loongson64/lemote-2f/pm.c b/arch/mips/loongson64/lemote-2f/pm.c index 6859e934862d..4ee7e9864700 100644 --- a/arch/mips/loongson64/lemote-2f/pm.c +++ b/arch/mips/loongson64/lemote-2f/pm.c @@ -23,7 +23,7 @@ #include #include -#include "ec_kb3310b.h" +#include #define I8042_KBD_IRQ 1 #define I8042_CTR_KBDINT 0x01 @@ -70,7 +70,7 @@ void setup_wakeup_events(void) /* Wakeup CPU via SCI lid open event */ outb(irq_mask & ~(1 << PIC_CASCADE_IR), PIC_MASTER_IMR); inb(PIC_MASTER_IMR); - outb(0xff & ~(1 << (SCI_IRQ_NUM - 8)), PIC_SLAVE_IMR); + outb(0xff & ~(1 << (KB3310B_SCI_IRQ_NUM - 8)), PIC_SLAVE_IMR); inb(PIC_SLAVE_IMR); break; @@ -88,7 +88,7 @@ EXPORT_SYMBOL(yeeloong_report_lid_status); static void yeeloong_lid_update_task(struct work_struct *work) { if (yeeloong_report_lid_status) - yeeloong_report_lid_status(BIT_LID_DETECT_ON); + yeeloong_report_lid_status(KB3310B_BIT_LID_DETECT_ON); } int wakeup_loongson(void) @@ -104,21 +104,21 @@ int wakeup_loongson(void) if (irq == I8042_KBD_IRQ) return 1; - else if (irq == SCI_IRQ_NUM) { + else if (irq == KB3310B_SCI_IRQ_NUM) { int ret, sci_event; /* query the event number */ - ret = ec_query_seq(CMD_GET_EVENT_NUM); + ret = kb3310b_query_seq(KB3310B_CMD_GET_EVENT_NUM); if (ret < 0) return 0; - sci_event = ec_get_event_num(); + sci_event = kb3310b_get_event_num(); if (sci_event < 0) return 0; - if (sci_event == EVENT_LID) { + if (sci_event == KB3310B_EVENT_LID) { int lid_status; /* check the LID status */ - lid_status = ec_read(REG_LID_DETECT); + lid_status = kb3310b_read(KB3310B_REG_LID_DETECT); /* wakeup cpu when people open the LID */ - if (lid_status == BIT_LID_DETECT_ON) { + if (lid_status == KB3310B_BIT_LID_DETECT_ON) { /* If we call it directly here, the WARNING * will be sent out by getnstimeofday * via "WARN_ON(timekeeping_suspended);" diff --git a/arch/mips/loongson64/lemote-2f/reset.c b/arch/mips/loongson64/lemote-2f/reset.c index a26ca7fcd7e0..c5e2afbb8121 100644 --- a/arch/mips/loongson64/lemote-2f/reset.c +++ b/arch/mips/loongson64/lemote-2f/reset.c @@ -20,7 +20,7 @@ #include #include -#include "ec_kb3310b.h" +#include static void reset_cpu(void) { @@ -81,7 +81,7 @@ static void ml2f_reboot(void) reset_cpu(); /* sending an reset signal to EC(embedded controller) */ - ec_write(REG_RESET, BIT_RESET_ON); + kb3310b_write(KB3310B_REG_RESET, KB3310B_BIT_RESET_ON); } #define yl2f89_reboot ml2f_reboot From patchwork Wed Mar 6 12:01:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yifeng Li X-Patchwork-Id: 10841051 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B3B53180E for ; Wed, 6 Mar 2019 12:02:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9FBBE2D7CD for ; Wed, 6 Mar 2019 12:02:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9E0EA2D7A7; Wed, 6 Mar 2019 12:02:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3B1DE2D786 for ; Wed, 6 Mar 2019 12:02:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729434AbfCFMCF (ORCPT ); Wed, 6 Mar 2019 07:02:05 -0500 Received: from tomli.me ([153.92.126.73]:46566 "EHLO tomli.me" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729498AbfCFMCE (ORCPT ); Wed, 6 Mar 2019 07:02:04 -0500 Received: from tomli.me (localhost [127.0.0.1]) by tomli.me (OpenSMTPD) with ESMTP id 8ef2bf1e; Wed, 6 Mar 2019 12:02:02 +0000 (UTC) X-HELO: localhost.lan Authentication-Results: tomli.me; auth=pass (login) smtp.auth=tomli Received: from Unknown (HELO localhost.lan) (2402:f000:1:1501:200:5efe:72f4:b31) by tomli.me (qpsmtpd/0.95) with ESMTPSA (DHE-RSA-CHACHA20-POLY1305 encrypted); Wed, 06 Mar 2019 12:02:02 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=tomli.me; h=from:to:cc:subject:date:message-id:in-reply-to:references:mime-version:content-transfer-encoding; s=1490979754; bh=17tJ+LRyo7NePFlBvhmpIAFh7/EROGjz26SLZpRTBYk=; b=MyjgEF8xFMA4gUUzK0fMkGKS7cEmhocL1cEJz+3xWQkWF1oIc6Ivgk5cXKWosfXFFnEQmk3b01E+gihpu7217/mIF9njqRnnLg4GWpWonTy3Hai06iAPuPP7r0qI+zJ8YpUUj/TZK7cOJwdKjdMA5Ohbut0Q5vYdmvwywJw7aCEspC6QET7fu185s+6dSNsHuBHS4lxaB9K0lR84yCuNWlQTFX/YdbgIdpxd6OAjws/X1vgKVBoXRrxWze4l6RsuZVNWNYXubdauiWriL+CbS/yuSpO9ZMXu3dtZMGWQNoLP959fomkpaA9fUbI7NV8MJmL9cQTWQ2gO+XJj+324Sw== From: Yifeng Li To: Lee Jones , linux-mips@vger.kernel.org, Paul Burton Cc: Yifeng Li , Jiaxun Yang , Huacai Chen , Ralf Baechle , James Hogan , linux-kernel@vger.kernel.org Subject: [PATCH v3 4/7] mips: loongson64: remove yeeloong_report_lid_status from pm.c Date: Wed, 6 Mar 2019 20:01:10 +0800 Message-Id: <20190306120113.648-5-tomli@tomli.me> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190306120113.648-1-tomli@tomli.me> References: <20190306120113.648-1-tomli@tomli.me> MIME-Version: 1.0 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There is some complicated logic in lemote-2f/pm.c. During wakeup, it creates a delayed_work to execute a callback to the function yeeloong_report_lid_status(). It's only purpose is to report the current status of the laptop lid switch, and this callback function was not implemented in the mainline kernel. This level of overenginnering hardly makes sense. All we need is to report the laptop lid switch unconditionally upon wakeup in the future PM code, which is being worked on. Signed-off-by: Yifeng Li --- arch/mips/loongson64/lemote-2f/pm.c | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/arch/mips/loongson64/lemote-2f/pm.c b/arch/mips/loongson64/lemote-2f/pm.c index 4ee7e9864700..ebe4b57535f0 100644 --- a/arch/mips/loongson64/lemote-2f/pm.c +++ b/arch/mips/loongson64/lemote-2f/pm.c @@ -80,17 +80,6 @@ void setup_wakeup_events(void) } } -static struct delayed_work lid_task; -static int initialized; -/* yeeloong_report_lid_status will be implemented in yeeloong_laptop.c */ -sci_handler yeeloong_report_lid_status; -EXPORT_SYMBOL(yeeloong_report_lid_status); -static void yeeloong_lid_update_task(struct work_struct *work) -{ - if (yeeloong_report_lid_status) - yeeloong_report_lid_status(KB3310B_BIT_LID_DETECT_ON); -} - int wakeup_loongson(void) { int irq; @@ -119,17 +108,6 @@ int wakeup_loongson(void) lid_status = kb3310b_read(KB3310B_REG_LID_DETECT); /* wakeup cpu when people open the LID */ if (lid_status == KB3310B_BIT_LID_DETECT_ON) { - /* If we call it directly here, the WARNING - * will be sent out by getnstimeofday - * via "WARN_ON(timekeeping_suspended);" - * because we can not schedule in suspend mode. - */ - if (initialized == 0) { - INIT_DELAYED_WORK(&lid_task, - yeeloong_lid_update_task); - initialized = 1; - } - schedule_delayed_work(&lid_task, 1); return 1; } } From patchwork Wed Mar 6 12:01:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yifeng Li X-Patchwork-Id: 10841045 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E2B0317E9 for ; Wed, 6 Mar 2019 12:02:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CEF502D773 for ; Wed, 6 Mar 2019 12:02:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CCF712D79B; Wed, 6 Mar 2019 12:02:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 87F0E2D773 for ; Wed, 6 Mar 2019 12:02:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729498AbfCFMCL (ORCPT ); Wed, 6 Mar 2019 07:02:11 -0500 Received: from tomli.me ([153.92.126.73]:46566 "EHLO tomli.me" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729118AbfCFMCK (ORCPT ); Wed, 6 Mar 2019 07:02:10 -0500 Received: from tomli.me (localhost [127.0.0.1]) by tomli.me (OpenSMTPD) with ESMTP id 8208206d; Wed, 6 Mar 2019 12:02:07 +0000 (UTC) X-HELO: localhost.lan Authentication-Results: tomli.me; auth=pass (login) smtp.auth=tomli Received: from Unknown (HELO localhost.lan) (2402:f000:1:1501:200:5efe:72f4:b31) by tomli.me (qpsmtpd/0.95) with ESMTPSA (DHE-RSA-CHACHA20-POLY1305 encrypted); Wed, 06 Mar 2019 12:02:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=tomli.me; h=from:to:cc:subject:date:message-id:in-reply-to:references:mime-version:content-transfer-encoding; s=1490979754; bh=kieGshjoAXm2sPzM8x4a4gyWiyfT4mzaoi/5S4qitWg=; b=wfc/ciF/gNIsDM9Qr3q7lLYfZTmCkxdb5cxjC3dFcNAlUJ5qIp3V/rKaPHIyDPctN1AYcsE6rcZnBxK/WATNGhAmHB6Z9w81YHoRkz9JwG3dGE+h60CmkEAnn26TaxU5M9jhmRYFzpJBbFQUnJ0Qqt/OxGjMNQcei44ozTYbOWnIE8TIELsf6ysngXml9FAq8CB0Q41G3WQhl+lSDnluJUCTNofvXUG4CYIhO6ZQsQevVK9c8D+8NYyhiw+W991Emnea7KkctiTylv2eVZcBZv5q5JtrlPFVmoxfQgPjF5cWCfAyRpgx+QQ0djuxSvTvkyTv6fZE3UIm5O4+E65w1w== From: Yifeng Li To: Lee Jones , linux-mips@vger.kernel.org, Paul Burton Cc: Yifeng Li , Jiaxun Yang , Huacai Chen , Ralf Baechle , James Hogan , linux-kernel@vger.kernel.org Subject: [PATCH v3 5/7] mips: loongson64: register per-board platform drivers for lemote-2f Date: Wed, 6 Mar 2019 20:01:11 +0800 Message-Id: <20190306120113.648-6-tomli@tomli.me> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190306120113.648-1-tomli@tomli.me> References: <20190306120113.648-1-tomli@tomli.me> MIME-Version: 1.0 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently, common/platform.c registers the Loongson 2F cpufreq driver during boot time for all boards. To support platform drivers for Lemote Yeeloong laptops, we need to register more drivers. First, we add support for per-board platform drivers. Just like how IRQ, DMA, or reset logic is implemented for each board, we introduces a call of mach_platform_init() in common/platform.c, to allow each board to have its own platform.c to register platform drivers. Then, we implement lemote-2f/platform.c to register the MFD driver for Yeeloong laptops. So far, only one board, lemote-f2, is using this facility, so we hardcode the call of mach_platform_init() in common/platform.c as a ifdef for now. Signed-off-by: Yifeng Li --- .../include/asm/mach-loongson64/loongson.h | 3 ++ arch/mips/loongson64/common/platform.c | 15 ++++++ arch/mips/loongson64/lemote-2f/Makefile | 2 +- arch/mips/loongson64/lemote-2f/platform.c | 47 +++++++++++++++++++ 4 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 arch/mips/loongson64/lemote-2f/platform.c diff --git a/arch/mips/include/asm/mach-loongson64/loongson.h b/arch/mips/include/asm/mach-loongson64/loongson.h index b6870fec0f99..0ea43479d9f8 100644 --- a/arch/mips/include/asm/mach-loongson64/loongson.h +++ b/arch/mips/include/asm/mach-loongson64/loongson.h @@ -23,6 +23,9 @@ extern void bonito_irq_init(void); extern void mach_prepare_reboot(void); extern void mach_prepare_shutdown(void); +/* machine-specific platform driver registration */ +extern int mach_platform_init(void) __init; + /* environment arguments from bootloader */ extern u32 cpu_clock_freq; extern u32 memsize, highmemsize; diff --git a/arch/mips/loongson64/common/platform.c b/arch/mips/loongson64/common/platform.c index 0ed38321a9a2..f8a205bae5da 100644 --- a/arch/mips/loongson64/common/platform.c +++ b/arch/mips/loongson64/common/platform.c @@ -11,6 +11,7 @@ #include #include #include +#include static struct platform_device loongson2_cpufreq_device = { .name = "loongson2_cpufreq", @@ -29,3 +30,17 @@ static int __init loongson2_cpufreq_init(void) } arch_initcall(loongson2_cpufreq_init); + +/* + * Currently, only LEMOTE_MACH2F implements mach_platform_init(); + * Fuloong-2E or Loongson3 does not have platform drivers to register + * at here yet. + */ +#ifdef CONFIG_LEMOTE_MACH2F +static int __init loongson2_platform_init(void) +{ + return mach_platform_init(); +} + +device_initcall(loongson2_platform_init); +#endif diff --git a/arch/mips/loongson64/lemote-2f/Makefile b/arch/mips/loongson64/lemote-2f/Makefile index ac97f14ea2b7..2b18752424ee 100644 --- a/arch/mips/loongson64/lemote-2f/Makefile +++ b/arch/mips/loongson64/lemote-2f/Makefile @@ -2,7 +2,7 @@ # Makefile for lemote loongson2f family machines # -obj-y += clock.o machtype.o irq.o reset.o dma.o +obj-y += clock.o machtype.o irq.o reset.o dma.o platform.o # # Suspend Support diff --git a/arch/mips/loongson64/lemote-2f/platform.c b/arch/mips/loongson64/lemote-2f/platform.c new file mode 100644 index 000000000000..c8a8c597e384 --- /dev/null +++ b/arch/mips/loongson64/lemote-2f/platform.c @@ -0,0 +1,47 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +/* + * Copyright (C) 2009 Lemote Inc. + * Author: Wu Zhangjin, wuzhangjin@gmail.com + * + * Copyright (C) 2019 Yifeng Li + * Author: Yifeng Li + */ + +#include +#include +#include + +static struct kb3310b_chip yeeloong_ec_info; + +static struct platform_device yeeloong_ec_device = { + .name = "yeeloong_kb3310b", + .id = -1, + .dev = { + .platform_data = &yeeloong_ec_info, + }, +}; + +int __init mach_platform_init(void) +{ + /* + * arcs_cmdline is __initdata, which will be freed after boot and cannot + * be used. We extract the EC version string from it, and pass it to + * yeeloong-kb3310b driver as platform data. + */ + static const char token[] = "EC_VER="; + char *p; + + p = strstr(arcs_cmdline, token); + if (!p) + memset(yeeloong_ec_info.version, 0, KB3310B_VERSION_LEN); + else { + p += ARRAY_SIZE(token) - 1; + strncpy(yeeloong_ec_info.version, p, KB3310B_VERSION_LEN); + p = strstr(yeeloong_ec_info.version, " "); + if (p) + *p = '\0'; + } + + return platform_device_register(&yeeloong_ec_device); +} From patchwork Wed Mar 6 12:01:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yifeng Li X-Patchwork-Id: 10841047 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CA26217E9 for ; Wed, 6 Mar 2019 12:02:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B58DB2D786 for ; Wed, 6 Mar 2019 12:02:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B39232D7AE; Wed, 6 Mar 2019 12:02:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4A3A62D786 for ; Wed, 6 Mar 2019 12:02:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729767AbfCFMCQ (ORCPT ); Wed, 6 Mar 2019 07:02:16 -0500 Received: from tomli.me ([153.92.126.73]:46566 "EHLO tomli.me" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729628AbfCFMCP (ORCPT ); Wed, 6 Mar 2019 07:02:15 -0500 Received: from tomli.me (localhost [127.0.0.1]) by tomli.me (OpenSMTPD) with ESMTP id 741aa32c; Wed, 6 Mar 2019 12:02:12 +0000 (UTC) X-HELO: localhost.lan Authentication-Results: tomli.me; auth=pass (login) smtp.auth=tomli Received: from Unknown (HELO localhost.lan) (2402:f000:1:1501:200:5efe:72f4:b31) by tomli.me (qpsmtpd/0.95) with ESMTPSA (DHE-RSA-CHACHA20-POLY1305 encrypted); Wed, 06 Mar 2019 12:02:12 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=tomli.me; h=from:to:cc:subject:date:message-id:in-reply-to:references:mime-version:content-transfer-encoding; s=1490979754; bh=xNvRB8rPeaT13gC9E0EgNG391+g95SHxSvMR/2lHVIU=; b=QZABUR0ZAU9iYbVZUApasWeGflC/17KBFDXNS7XbF8UxJhBVlKWTHvZ3mhWKWxBeAAlvNj6SoLdxaPhVu9UrbrCPvHHrZxrarOcGFly4Tb9cSevt+jM5mTIxGM80+s9tkWcLFb/OZjc4uaHVlXi4lMPxRqANnJufE/SWbB4m2NrBv7OLxdWE3Txc8dHu3xsCvVNvN+qUI9eDCsqxt6DgMnVfULBjaJ4zDr2Jm3lgRD2W0UcVyuQxGBMlLtK5W0HkpL6MaYpxOrgbn2LgF2PmDBHqgGjAEZ84DSl/sGpazqK3gZLDynZjnDFPjuXzkqfGwn6Mi7PYqeoWBgyNSShEXA== From: Yifeng Li To: Lee Jones , linux-mips@vger.kernel.org, Paul Burton Cc: Yifeng Li , Jiaxun Yang , Huacai Chen , Ralf Baechle , James Hogan , linux-kernel@vger.kernel.org Subject: [PATCH v3 6/7] mips: loongson64: Support System Control Interrupts for Lemote Yeeloong. Date: Wed, 6 Mar 2019 20:01:12 +0800 Message-Id: <20190306120113.648-7-tomli@tomli.me> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190306120113.648-1-tomli@tomli.me> References: <20190306120113.648-1-tomli@tomli.me> MIME-Version: 1.0 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The hardware design of Yeeloong laptops is similar to OLPC: low-level hardware events are processed by the ENE KB3310B Embedded Controller, which is connected to the AMD CS5536 southbridge through a GPIO port. When a hardware event occurs, such as a short-circuit on the USB port, removing the power supply, plugging in a VGA adapter, opening the lid of the laptop, or pressing a hotkey on the keyboard, the EC sends a pulse to CS5536, which then fires a System Control Interrupt to notify the kernel. In the previous attempted submission, the logic for handling SCI and hotkeys was tightly-coupled, and the driver was called the "hotkey" driver, which was misleading. In this implementation of sci.c, we only handle the minimum number of things that deal with the underlying platform hardware directly, such as setting up the CS5536 GPIO and IRQ, handling the the power supply of USB and camera. The vast majority of events are passed to the subdrivers via a notification chain, thus, the SCI logic and the specific hotkey handling logic have been decoupled. Signed-off-by: Yifeng Li --- arch/mips/loongson64/lemote-2f/Makefile | 2 +- arch/mips/loongson64/lemote-2f/sci.c | 394 ++++++++++++++++++++++++ 2 files changed, 395 insertions(+), 1 deletion(-) create mode 100644 arch/mips/loongson64/lemote-2f/sci.c diff --git a/arch/mips/loongson64/lemote-2f/Makefile b/arch/mips/loongson64/lemote-2f/Makefile index 2b18752424ee..af4a1d347884 100644 --- a/arch/mips/loongson64/lemote-2f/Makefile +++ b/arch/mips/loongson64/lemote-2f/Makefile @@ -2,7 +2,7 @@ # Makefile for lemote loongson2f family machines # -obj-y += clock.o machtype.o irq.o reset.o dma.o platform.o +obj-y += clock.o machtype.o irq.o reset.o dma.o platform.o sci.o # # Suspend Support diff --git a/arch/mips/loongson64/lemote-2f/sci.c b/arch/mips/loongson64/lemote-2f/sci.c new file mode 100644 index 000000000000..c78d579e72de --- /dev/null +++ b/arch/mips/loongson64/lemote-2f/sci.c @@ -0,0 +1,394 @@ +// SPDX-License-Identifier: GPL-2.0-only + +/* + * Support for Lemote Yeeloong System Control Interrupts (SCI) + * + * Copyright (C) 2009 Lemote Inc. + * Author: Wu Zhangjin + * Liu Junliang + * + * Copyright (C) 2012, 2013, 2014, 2015 Petr Pisar + * Author: Petr Pisar (bugfixes) + * + * Copyright (C) 2017 Jiaxun Yang + * Author: Jiaxun Yang + * + * Copyright (C) 2019 Yifeng Li + * Author: Yifeng Li + * + * The hardware design of Yeeloong laptops is similar to OLPC: low-level + * hardware events are processed by the ENE KB3310B Embedded Controller, + * which is connected to the AMD CS5536 southbridge through a GPIO port. + * + * When a hardware event occurs, such as a short-circuit on the USB port, + * removing the power supply, plugging in a VGA adapter, opening the lid + * of the laptop, or pressing a hotkey on the keyboard, the EC sends a + * pulse to CS5536, which then fires a System Control Interrupt to notify + * the kernel. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +static void usb_power_set(bool power) +{ + kb3310b_write(KB3310B_REG_USB0_FLAG, power); + kb3310b_write(KB3310B_REG_USB1_FLAG, power); + kb3310b_write(KB3310B_REG_USB2_FLAG, power); +} + +static void camera_power_set(bool power) +{ + kb3310b_write(KB3310B_REG_CAMERA_CONTROL, power); +} + +/* + * Handlers for EC events. We only handles the bare-minimum number of events + * directly related to the platform hardware. Other events are reported to + * subdrivers and handled by them. + */ +static void usb0_handler(void) +{ + pr_emerg("USB0 Overcurrent occurred!\n"); +} + +static void usb2_handler(void) +{ + pr_emerg("USB2 Overcurrent occurred!\n"); +} + +static void camera_handler(void) +{ + camera_power_set(!kb3310b_read(KB3310B_REG_CAMERA_CONTROL)); +} + +/* + * SCI notifiers. This notifier reports EC events to various + * subdrivers. + */ +static BLOCKING_NOTIFIER_HEAD(yeeloong_sci_notifier_list); + +int yeeloong_sci_register_notify(struct notifier_block *nb) +{ + return blocking_notifier_chain_register(&yeeloong_sci_notifier_list, + nb); +} +EXPORT_SYMBOL_GPL(yeeloong_sci_register_notify); + +int yeeloong_sci_unregister_notify(struct notifier_block *nb) +{ + return blocking_notifier_chain_unregister(&yeeloong_sci_notifier_list, + nb); +} +EXPORT_SYMBOL_GPL(yeeloong_sci_unregister_notify); + +/* + * Do not handle or notify other drivers about certain events while we're + * going down to reboot or sleep. This avoids unexpected behaviors in the + * userspace, such as closing the laptop lid while rebooting. + */ +static atomic_t reboot_flag; +static atomic_t sleep_flag; + +static int +notify_reboot(struct notifier_block *nb, unsigned long event, void *buf) +{ + switch (event) { + case SYS_RESTART: + case SYS_HALT: + case SYS_POWER_OFF: + atomic_set(&reboot_flag, 1); + break; + default: + return NOTIFY_DONE; + } + + return NOTIFY_OK; +} + +static int +notify_pm(struct notifier_block *nb, unsigned long event, void *buf) +{ + switch (event) { + case PM_HIBERNATION_PREPARE: + case PM_SUSPEND_PREPARE: + atomic_inc(&sleep_flag); + break; + case PM_POST_HIBERNATION: + case PM_POST_SUSPEND: + case PM_RESTORE_PREPARE: /* do we need this ?? */ + atomic_dec(&sleep_flag); + break; + default: + return NOTIFY_DONE; + } + + return NOTIFY_OK; +} + +static struct notifier_block reboot_notifier = { + .notifier_call = notify_reboot, +}; + +static struct notifier_block pm_notifier = { + .notifier_call = notify_pm, +}; + +static bool is_spurious_event(int event) +{ + if (event == KB3310B_EVENT_LID || event == KB3310B_EVENT_SLEEP) + return !!(atomic_read(&reboot_flag) | atomic_read(&sleep_flag)); + else + return false; +} + +/* + * Invoke the handler of the reported SCI event. + */ +static void process_sci_event(int event) +{ + if (is_spurious_event(event)) + return; + + switch (event) { + case KB3310B_EVENT_USB_OC0: + usb0_handler(); + break; + case KB3310B_EVENT_USB_OC2: + usb2_handler(); + break; + case KB3310B_EVENT_CAMERA: + camera_handler(); + break; + default: + break; + } + + /* + * Report this event to other subdrivers, in particular, yeeloong-hotkey + * driver will report the hotkey to userspace. + */ + blocking_notifier_call_chain(&yeeloong_sci_notifier_list, event, NULL); +} + +/* + * Handle the SCI event and perform the needed action. + * + * A SCI event lasts about 120 microseconds. It means the function must take + * longer than 120 microseconds to complete. It has been shown that the function + * already takes 3 ms, so no artificial delay is needed. + */ +static irqreturn_t sci_irq_handler(int irq, void *dev_id) +{ + int ret, event; + + if (irq != KB3310B_SCI_IRQ_NUM) + return IRQ_NONE; + + /* query the event number */ + ret = kb3310b_query_event_num(); + if (ret < 0) + return IRQ_NONE; + + event = kb3310b_get_event_num(); + if (event < KB3310B_EVENT_START || event > KB3310B_EVENT_END) + return IRQ_NONE; + + /* execute the corresponding action */ + process_sci_event(event); + + return IRQ_HANDLED; +} + +/* + * Program the GPIO and MSR registers on CS5536. + * + * TODO: Linux kernel already has a cs5535-gpio kernel driver, but that + * driver not adapted for Loongson. It's desirable to convert these + * raw operations to use cs5535-gpio. Also, Loongson has its own + * CS5536 clocksource driver, though Linux already has cs5535-clockevt, + * but only supports clockevent, not clocksource. Clocksource code + * should be merged into cs5535-clockevt and Loongson should use + * that, too. + */ +static int setup_ec_sci(void) +{ + u32 hi, lo; + u32 gpio_base; + unsigned long flags; + int ret; + + /* Get GPIO base */ + _rdmsr(DIVIL_MSR_REG(DIVIL_LBAR_GPIO), &hi, &lo); + gpio_base = lo & 0xff00; + + /* + * HACK: to prevent any interrupts from being fired, we query + * the EC to clear the pending event, and wait for a while to + * miss the interrupt intentionally. + */ + ret = kb3310b_query_event_num(); + if (ret) + return ret; + + /* wait for a while */ + mdelay(10); + + /* + * Set GPIO native registers and MSRs for GPIO-27 SCI EVENT PIN + * + * MSR: + * no primary and LPC. + * Unrestricted Z Input 8 to IG-10 from Virtual GPIO-0. + * + * GPIO mode: + * input, pull-up, no-invert, event-count and value 0, + * no-filter, no-edge. GPIO-27 map to Virtual GPIO-0. + */ + local_irq_save(flags); + + /* set primary mask */ + _rdmsr(0x80000024, &hi, &lo); + lo &= ~(1 << 10); + _wrmsr(0x80000024, hi, lo); + + /* set LPC mask */ + _rdmsr(0x80000025, &hi, &lo); + lo &= ~(1 << 10); + _wrmsr(0x80000025, hi, lo); + + /* set Unrestricted Z map */ + _rdmsr(0x80000023, &hi, &lo); + lo |= (0x0a << 0); + _wrmsr(0x80000023, hi, lo); + + local_irq_restore(flags); + + asm(".set noreorder\n"); + outl(0x00000800, (gpio_base | 0xA0)); /* GPIO-27 input enable */ + outl(0x00000800, (gpio_base | 0xA4)); /* GPIO-27 input invert */ + outl(0x00000800, (gpio_base | 0xB8)); /* GPIO-27 event-int enable */ + asm(".set reorder\n"); + + return 0; +} + +/* + * Setup the IRQ handler for SCI. Must be called after setup_ec_sci(). + */ +static int setup_sci_interrupt(struct platform_device *pdev) +{ + int ret; + + ret = request_threaded_irq(KB3310B_SCI_IRQ_NUM, NULL, &sci_irq_handler, + IRQF_ONESHOT, "sci", NULL); + if (ret) + dev_err(&pdev->dev, "unable to request interrupt!\n"); + + return ret; +} + +static int yeeloong_sci_probe(struct platform_device *pdev) +{ + int ret; + + camera_power_set(KB3310B_BIT_CAMERA_CONTROL_OFF); + usb_power_set(KB3310B_BIT_USB_FLAG_ON); + + ret = register_reboot_notifier(&reboot_notifier); + if (ret) { + dev_err(&pdev->dev, "unable to register reboot_notifier!\n"); + goto fail; + } + + ret = register_pm_notifier(&pm_notifier); + if (ret) { + dev_err(&pdev->dev, "unable to register pm_notifier!\n"); + goto fail_reboot; + } + + ret = setup_ec_sci(); + if (ret) { + dev_err(&pdev->dev, "unable to setup EC SCI!\n"); + goto fail_irq; + } + + ret = setup_sci_interrupt(pdev); + if (ret) + goto fail_irq; + + return ret; + +fail_irq: + free_irq(KB3310B_SCI_IRQ_NUM, NULL); + unregister_pm_notifier(&pm_notifier); +fail_reboot: + unregister_reboot_notifier(&reboot_notifier); +fail: + return ret; +} + +#ifdef CONFIG_PM +static int +yeeloong_sci_suspend(struct device *dev) +{ + usb_power_set(KB3310B_BIT_USB_FLAG_OFF); + camera_power_set(KB3310B_BIT_CAMERA_CONTROL_OFF); + return 0; +} + +static int yeeloong_sci_resume(struct device *dev) +{ + int ret; + + usb_power_set(KB3310B_BIT_USB_FLAG_ON); + + ret = setup_ec_sci(); + if (ret) { + dev_err(dev, "unable to setup EC SCI!\n"); + return -EFAULT; + } + + /* + * Lid switch and power supply may hawe changed while we were + * asleep, so we generate a KB3310B_EVENT_LID and KB3310B_EVENT_AC_BAT + * events to force the hotkey/battery subdriver to report their new + * states. + */ + blocking_notifier_call_chain(&yeeloong_sci_notifier_list, + KB3310B_EVENT_LID, NULL); + blocking_notifier_call_chain(&yeeloong_sci_notifier_list, + KB3310B_EVENT_AC_BAT, NULL); + + return 0; +} + +static const SIMPLE_DEV_PM_OPS(yeeloong_sci_pm_ops, + yeeloong_sci_suspend, yeeloong_sci_resume); +#endif + +static struct platform_driver yeeloong_sci_driver = { + .probe = yeeloong_sci_probe, + .driver = { + .name = "yeeloong_sci", +#ifdef CONFIG_PM + .pm = &yeeloong_sci_pm_ops, +#endif + }, +}; + +static int __init yeeloong_sci_init(void) +{ + return platform_driver_register(&yeeloong_sci_driver); +} +arch_initcall(yeeloong_sci_init); From patchwork Wed Mar 6 12:01:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yifeng Li X-Patchwork-Id: 10841049 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7C04C922 for ; Wed, 6 Mar 2019 12:02:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 68E3B2D7B2 for ; Wed, 6 Mar 2019 12:02:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 66A872D7C9; Wed, 6 Mar 2019 12:02:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0CFE02D7B2 for ; Wed, 6 Mar 2019 12:02:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729484AbfCFMCV (ORCPT ); Wed, 6 Mar 2019 07:02:21 -0500 Received: from tomli.me ([153.92.126.73]:46566 "EHLO tomli.me" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729628AbfCFMCU (ORCPT ); Wed, 6 Mar 2019 07:02:20 -0500 Received: from tomli.me (localhost [127.0.0.1]) by tomli.me (OpenSMTPD) with ESMTP id a67ea552; Wed, 6 Mar 2019 12:02:17 +0000 (UTC) X-HELO: localhost.lan Authentication-Results: tomli.me; auth=pass (login) smtp.auth=tomli Received: from Unknown (HELO localhost.lan) (2402:f000:1:1501:200:5efe:72f4:b31) by tomli.me (qpsmtpd/0.95) with ESMTPSA (DHE-RSA-CHACHA20-POLY1305 encrypted); Wed, 06 Mar 2019 12:02:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=tomli.me; h=from:to:cc:subject:date:message-id:in-reply-to:references:mime-version:content-transfer-encoding; s=1490979754; bh=foHmT6tpUB7T3HL59GtGQQQmGWB4MM4AVOND1ASTjGg=; b=EuOwecoR1qaFwqZ4PSElq/6ppLG6FYzYUrVlFVBkh6ozjBrshnxlV0Y7Bb8j1hgnN20lpt/M+cfNdCdGPv5uetdOLAFWNCQJzJ5xedELdfTUjuQaRKZFQWV18lGYgJztxcLRnhQff+I14VdqzxAcxpfg9rqHA/aZ2gbdFqUHfgnSavQrfIq04iSIQqnP3/Cg14ZzFVe000pQGryNu0yBfpgBpOFCImN+kiWgGI/eMZYUsWLuzgSipwPzbtNIIos8WrGxU+sldK51xT90xXCOWEheqWXiweNHC9YwjsJXi2hBLBiinctmlx03aDG00NdM3pKVgmLVtPU2bTZ2YIuRLA== From: Yifeng Li To: Lee Jones , linux-mips@vger.kernel.org, Paul Burton Cc: Yifeng Li , Jiaxun Yang , Huacai Chen , Ralf Baechle , James Hogan , linux-kernel@vger.kernel.org Subject: [PATCH v3 7/7] MAINTAINERS: add myself as a maintainer of MIPS/Loongson2 platform code. Date: Wed, 6 Mar 2019 20:01:13 +0800 Message-Id: <20190306120113.648-8-tomli@tomli.me> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190306120113.648-1-tomli@tomli.me> References: <20190306120113.648-1-tomli@tomli.me> MIME-Version: 1.0 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP I've introduced platform code for Lemote Yeeloong computers and modified power management-related files. Add myself as a maintainer of these code. Signed-off-by: Yifeng Li --- MAINTAINERS | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 208f19801a23..a82cd47927c1 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -10134,6 +10134,15 @@ F: arch/mips/include/asm/mach-loongson64/ F: drivers/*/*loongson2* F: drivers/*/*/*loongson2* +MIPS/LOONGSON2 LEMOTE PLATFORM AND POWER MANAGEMENT DRIVER +M: Tom Li +L: linux-mips@vger.kernel.org +S: Maintained +F: arch/mips/loongson64/common/platform.c +F: arch/mips/loongson64/lemote-2f/pm.c +F: arch/mips/loongson64/lemote-2f/sci.c +F: arch/mips/loongson64/lemote-2f/platform.c + MIPS/LOONGSON3 ARCHITECTURE M: Huacai Chen L: linux-mips@vger.kernel.org