From patchwork Tue May 12 13:26:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 11543197 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EA89B1668 for ; Tue, 12 May 2020 13:26:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D22A52075E for ; Tue, 12 May 2020 13:26:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20150623.gappssmtp.com header.i=@baylibre-com.20150623.gappssmtp.com header.b="H7zv+pIK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729987AbgELN0Y (ORCPT ); Tue, 12 May 2020 09:26:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729882AbgELN0V (ORCPT ); Tue, 12 May 2020 09:26:21 -0400 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96C48C061A0F for ; Tue, 12 May 2020 06:26:20 -0700 (PDT) Received: by mail-wr1-x444.google.com with SMTP id 50so14840845wrc.11 for ; Tue, 12 May 2020 06:26:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Lm/JhSU6WIUD9liaClHiq2/rbC+K/Ls1HtNWMD1Nn2A=; b=H7zv+pIKMn1DFXWX7wYhzX5b9gbDPxAk9SE9ltGb5WnBojjIrTWGwZ7FVO7YXf1AoR COZHSxtOlkVLwcmTh97ohzAq4n9C7J6uHa4n4D27rkj+w/kfYeWrBD3lktPkCBd7OyNK O8P/pCK5xonSvWm29SHHyKomqkG8A+B7SHPE0Hdxxub08pQdFMBOAnAQGaUN+jnC5W1I DAw62gdKYZhW3y6Pzrg+noXMZ4eeW1RZlY/S2D9py4Eofn7OiX980AilKycW3g3jxVMX STxvCkdIKo7Txkpgq0z0bR0Ka58vlC02RDjsUwtAdg3aW0j9ktnqbckm4J6OXV57CjW8 0RSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Lm/JhSU6WIUD9liaClHiq2/rbC+K/Ls1HtNWMD1Nn2A=; b=Ndbcn4BJEo9/XjlDxrfyKwIG9T/PakLS0CdZ8dJRu/tdb7C+nb77qzclRzu7L/jby+ egAHl6WXRzBG8pOoDrk33RoSnbIhnsAng79OJ/3WUrjifQOz7Vmp9yNLQLAnj4F/uu1b tPfg0SfWBLVMGXAjfnk7EGC+FntQ+MYj3gnn6S0e7LW6cu6NkzbYYOlJ5ZcukiH99rwU ZEgDm39gt0IptQy8GuAAOo/wX2yvFB0FyzV3M3dQeMnfDI/5JK64xnYI+joQ39l8ycte i4pgPZ3ZJZMGk39LqRrmSFJMiDeDxZBNJ5Jkd3DjZo1csRp7RL4bUdOiGyFOdl4KNmiQ SC9A== X-Gm-Message-State: AGi0Pubt6U5c9z8bxJ/8EWzCrJewUNIxZp57wGuJPZy8rKuoOOC6py9w jUTqhWP7jAuiYW9KJvmD1eA5nQ== X-Google-Smtp-Source: APiQypIMA843k3ZGcFq05wJywOzCbRuZBo362vVj3No/BJt89ev1hi92yc4IMHltKbZdcHKKO8Tw5g== X-Received: by 2002:a5d:4d0f:: with SMTP id z15mr24948754wrt.411.1589289979092; Tue, 12 May 2020 06:26:19 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:2ec0:82b0:4460:3fd3:382:4a71]) by smtp.gmail.com with ESMTPSA id g15sm14441844wro.71.2020.05.12.06.26.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2020 06:26:18 -0700 (PDT) From: Neil Armstrong To: lee.jones@linaro.org, rui.zhang@intel.com, daniel.lezcano@linaro.org, amit.kucheria@verdurent.com, srinivas.kandagatla@linaro.org, devicetree@vger.kernel.org Cc: Neil Armstrong , linux-amlogic@lists.infradead.org, linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Rob Herring Subject: [PATCH v2 1/6] dt-bindings: mfd: add Khadas Microcontroller bindings Date: Tue, 12 May 2020 15:26:08 +0200 Message-Id: <20200512132613.31507-2-narmstrong@baylibre.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20200512132613.31507-1-narmstrong@baylibre.com> References: <20200512132613.31507-1-narmstrong@baylibre.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org This Microcontroller is present on the Khadas VIM1, VIM2, VIM3 and Edge boards. It has multiple boot control features like password check, power-on options, power-off control and system FAN control on recent boards. Signed-off-by: Neil Armstrong Reviewed-by: Rob Herring Reviewed-by: Amit Kucheria --- .../devicetree/bindings/mfd/khadas,mcu.yaml | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/khadas,mcu.yaml diff --git a/Documentation/devicetree/bindings/mfd/khadas,mcu.yaml b/Documentation/devicetree/bindings/mfd/khadas,mcu.yaml new file mode 100644 index 000000000000..a3b976f101e8 --- /dev/null +++ b/Documentation/devicetree/bindings/mfd/khadas,mcu.yaml @@ -0,0 +1,44 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/mfd/khadas,mcu.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Khadas on-board Microcontroller Device Tree Bindings + +maintainers: + - Neil Armstrong + +description: | + Khadas embeds a microcontroller on their VIM and Edge boards adding some + system feature as PWM Fan control (for VIM2 rev14 or VIM3), User memory + storage, IR/Key resume control, system power LED control and more. + +properties: + compatible: + enum: + - khadas,mcu # MCU revision is discoverable + + "#cooling-cells": # Only needed for boards having FAN control feature + const: 2 + + reg: + maxItems: 1 + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + khadas_mcu: system-controller@18 { + compatible = "khadas,mcu"; + reg = <0x18>; + #cooling-cells = <2>; + }; + }; From patchwork Tue May 12 13:26:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 11543195 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9E485139F for ; Tue, 12 May 2020 13:26:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 793CF2075E for ; Tue, 12 May 2020 13:26:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20150623.gappssmtp.com header.i=@baylibre-com.20150623.gappssmtp.com header.b="XGVmw6wv" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730003AbgELN0Y (ORCPT ); Tue, 12 May 2020 09:26:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729921AbgELN0W (ORCPT ); Tue, 12 May 2020 09:26:22 -0400 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D99BC05BD0A for ; Tue, 12 May 2020 06:26:22 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id l18so15357209wrn.6 for ; Tue, 12 May 2020 06:26:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FfLgbV8JxCX0+O1S1urP+VjTlHc4+FfJzM+tdEpjLV4=; b=XGVmw6wvBxizd+DpUyTg2YZbQMD30bYmBtqfI+SGkzxegQF+ZD4Tfx9lcG3KB8SA0z I/B1hOibqJMM7pL8zQYYYTy5j2xE9CY638fNnVdEIdghqIfuDLc2jjflX5GaXeUY8ZIl k1dG02ys8VljhdkhlRKJ/gHk3j9asW4Cg4jxpNM7JLqlyzzc/i5HPUZ05tyrpoHKHql7 OlbD/caaBtkh8Fb/2A20tojRSCZUz+QUIUb3nuYp8CPXQHPShsHJzEJ1QHf000g86KQn F/hN++p0H+tnsvDNRsKxt0H9j5WHk/HSaE6hTYTQCN9D7TfN2UtEZ5tbIUAhT5gxF238 tEeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FfLgbV8JxCX0+O1S1urP+VjTlHc4+FfJzM+tdEpjLV4=; b=LJt8oFUXFitxJR/RZqiDz9crZT12CcMhARdNp6Wl4dbL3ROfaiEt6w4uN0qv/eIvrv lIk6Fefj9GD+LYeYMv/3fCFJjvcx+A2z33kaV37hh5EvCF4Lyc6CChhvNTDU/l8AhIdC 6mFER9xmm7BF0KPFqPQl4YSCJZi97ZAFvHBd/7rcjuF1Kb921xTaPbLoNWA6FtAfLX0B 747zG777Z5b0HkuSubYOBjKyBq9ILps+oQTsPl5gtvBdFbxT7l/c010lYgoWgsck/l+3 XFgR5w0YJ3rjJH/cgL77jDw9R0ZCevmgQDHjC6RbZ1ho8AmCPOSxFGyBscL9UvNUrKge IsTw== X-Gm-Message-State: AGi0PubBxy+R5FphynJZafj+v0WCoaTSNSZSpBWXiJee3jWnt9+ubuTx St1W9tUDGZW2PzN9e8AZrrHT4w== X-Google-Smtp-Source: APiQypI8EP/HoI9eKUl9on4yjIRVxocsOM2akcylLsk5B9T7t0qAEWkMTL9hpg9vY1c0Is3iwbRfcA== X-Received: by 2002:adf:efd0:: with SMTP id i16mr24626176wrp.315.1589289980619; Tue, 12 May 2020 06:26:20 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:2ec0:82b0:4460:3fd3:382:4a71]) by smtp.gmail.com with ESMTPSA id g15sm14441844wro.71.2020.05.12.06.26.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2020 06:26:20 -0700 (PDT) From: Neil Armstrong To: lee.jones@linaro.org Cc: Neil Armstrong , linux-amlogic@lists.infradead.org, linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/6] mfd: add support for the Khadas System control Microcontroller Date: Tue, 12 May 2020 15:26:09 +0200 Message-Id: <20200512132613.31507-3-narmstrong@baylibre.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20200512132613.31507-1-narmstrong@baylibre.com> References: <20200512132613.31507-1-narmstrong@baylibre.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org This Microcontroller is present on the Khadas VIM1, VIM2, VIM3 and Edge boards. It has multiple boot control features like password check, power-on options, power-off control and system FAN control on recent boards. This implements a very basic MFD driver with the fan control and User NVMEM cells. Signed-off-by: Neil Armstrong --- drivers/mfd/Kconfig | 14 ++++ drivers/mfd/Makefile | 1 + drivers/mfd/khadas-mcu.c | 143 +++++++++++++++++++++++++++++++++ include/linux/mfd/khadas-mcu.h | 91 +++++++++++++++++++++ 4 files changed, 249 insertions(+) create mode 100644 drivers/mfd/khadas-mcu.c create mode 100644 include/linux/mfd/khadas-mcu.h diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index 0a59249198d3..b95091397052 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig @@ -2003,6 +2003,20 @@ config MFD_WCD934X This driver provides common support WCD934x audio codec and its associated Pin Controller, Soundwire Controller and Audio codec. +config MFD_KHADAS_MCU + tristate "Support for Khadas System control Microcontroller" + depends on I2C + depends on OF || COMPILE_TEST + select MFD_CORE + select REGMAP_I2C + help + Support for the Khadas System control Microcontroller interface present + on their VIM and Edge boards. + + This driver provides common support for accessing the device, + additional drivers must be enabled in order to use the functionality + of the device. + menu "Multimedia Capabilities Port drivers" depends on ARCH_SA1100 diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile index f935d10cbf0f..0f1633b096bb 100644 --- a/drivers/mfd/Makefile +++ b/drivers/mfd/Makefile @@ -257,5 +257,6 @@ obj-$(CONFIG_MFD_ROHM_BD70528) += rohm-bd70528.o obj-$(CONFIG_MFD_ROHM_BD71828) += rohm-bd71828.o obj-$(CONFIG_MFD_ROHM_BD718XX) += rohm-bd718x7.o obj-$(CONFIG_MFD_STMFX) += stmfx.o +obj-$(CONFIG_MFD_KHADAS_MCU) += khadas-mcu.o obj-$(CONFIG_SGI_MFD_IOC3) += ioc3.o diff --git a/drivers/mfd/khadas-mcu.c b/drivers/mfd/khadas-mcu.c new file mode 100644 index 000000000000..6d08fa2e373a --- /dev/null +++ b/drivers/mfd/khadas-mcu.c @@ -0,0 +1,143 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Driver for Khadas System control Microcontroller + * + * Copyright (C) 2020 BayLibre SAS + * Author(s): Neil Armstrong + */ +#include +#include +#include +#include +#include +#include + +static bool khadas_mcu_reg_volatile(struct device *dev, unsigned int reg) +{ + if (reg >= KHADAS_MCU_USER_DATA_0_REG && + reg < KHADAS_MCU_PWR_OFF_CMD_REG) + return true; + + switch (reg) { + case KHADAS_MCU_PWR_OFF_CMD_REG: + case KHADAS_MCU_PASSWD_START_REG: + case KHADAS_MCU_CHECK_VEN_PASSWD_REG: + case KHADAS_MCU_CHECK_USER_PASSWD_REG: + case KHADAS_MCU_WOL_INIT_START_REG: + case KHADAS_MCU_CMD_FAN_STATUS_CTRL_REG: + return true; + default: + return false; + } +} + +static bool khadas_mcu_reg_writeable(struct device *dev, unsigned int reg) +{ + switch (reg) { + case KHADAS_MCU_PASSWD_VEN_0_REG: + case KHADAS_MCU_PASSWD_VEN_1_REG: + case KHADAS_MCU_PASSWD_VEN_2_REG: + case KHADAS_MCU_PASSWD_VEN_3_REG: + case KHADAS_MCU_PASSWD_VEN_4_REG: + case KHADAS_MCU_PASSWD_VEN_5_REG: + case KHADAS_MCU_MAC_0_REG: + case KHADAS_MCU_MAC_1_REG: + case KHADAS_MCU_MAC_2_REG: + case KHADAS_MCU_MAC_3_REG: + case KHADAS_MCU_MAC_4_REG: + case KHADAS_MCU_MAC_5_REG: + case KHADAS_MCU_USID_0_REG: + case KHADAS_MCU_USID_1_REG: + case KHADAS_MCU_USID_2_REG: + case KHADAS_MCU_USID_3_REG: + case KHADAS_MCU_USID_4_REG: + case KHADAS_MCU_USID_5_REG: + case KHADAS_MCU_VERSION_0_REG: + case KHADAS_MCU_VERSION_1_REG: + case KHADAS_MCU_DEVICE_NO_0_REG: + case KHADAS_MCU_DEVICE_NO_1_REG: + case KHADAS_MCU_FACTORY_TEST_REG: + case KHADAS_MCU_SHUTDOWN_NORMAL_STATUS_REG: + return false; + default: + return true; + } +} + +static const struct regmap_config khadas_mcu_regmap_config = { + .reg_bits = 8, + .reg_stride = 1, + .val_bits = 8, + .max_register = KHADAS_MCU_CMD_FAN_STATUS_CTRL_REG, + .volatile_reg = khadas_mcu_reg_volatile, + .writeable_reg = khadas_mcu_reg_writeable, + .cache_type = REGCACHE_RBTREE, +}; + +static struct mfd_cell khadas_mcu_fan_cells[] = { + /* Feature supported only on VIM1/2 Rev13+ and VIM3 */ + { .name = "khadas-mcu-fan-ctrl", }, +}; + +static struct mfd_cell khadas_mcu_cells[] = { + /* Features supported on all board revisions */ + { .name = "khadas-mcu-user-mem", }, +}; + +static int khadas_mcu_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct device *dev = &client->dev; + struct khadas_mcu *khadas_mcu; + int ret; + + khadas_mcu = devm_kzalloc(dev, sizeof(*khadas_mcu), GFP_KERNEL); + if (!khadas_mcu) + return -ENOMEM; + + i2c_set_clientdata(client, khadas_mcu); + + khadas_mcu->dev = dev; + + khadas_mcu->map = devm_regmap_init_i2c(client, + &khadas_mcu_regmap_config); + if (IS_ERR(khadas_mcu->map)) { + ret = PTR_ERR(khadas_mcu->map); + dev_err(dev, "Failed to allocate register map: %d\n", ret); + return ret; + } + + ret = devm_mfd_add_devices(dev, PLATFORM_DEVID_NONE, + khadas_mcu_cells, + ARRAY_SIZE(khadas_mcu_cells), + NULL, 0, NULL); + if (ret) + return ret; + + if (of_find_property(dev->of_node, "#cooling-cells", NULL)) + return devm_mfd_add_devices(dev, PLATFORM_DEVID_NONE, + khadas_mcu_fan_cells, + ARRAY_SIZE(khadas_mcu_fan_cells), + NULL, 0, NULL); + + return 0; +} + +static const struct of_device_id khadas_mcu_of_match[] = { + { .compatible = "khadas,mcu", }, + {}, +}; +MODULE_DEVICE_TABLE(of, khadas_mcu_of_match); + +static struct i2c_driver khadas_mcu_driver = { + .driver = { + .name = "khadas-mcu-core", + .of_match_table = of_match_ptr(khadas_mcu_of_match), + }, + .probe = khadas_mcu_probe, +}; +module_i2c_driver(khadas_mcu_driver); + +MODULE_DESCRIPTION("Khadas MCU core driver"); +MODULE_AUTHOR("Neil Armstrong "); +MODULE_LICENSE("GPL v2"); diff --git a/include/linux/mfd/khadas-mcu.h b/include/linux/mfd/khadas-mcu.h new file mode 100644 index 000000000000..2e68af21735c --- /dev/null +++ b/include/linux/mfd/khadas-mcu.h @@ -0,0 +1,91 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Khadas System control Microcontroller Register map + * + * Copyright (C) 2020 BayLibre SAS + * Author(s): Neil Armstrong + */ + +#ifndef MFD_KHADAS_MCU_H +#define MFD_KHADAS_MCU_H + +#define KHADAS_MCU_PASSWD_VEN_0_REG 0x0 /* RO */ +#define KHADAS_MCU_PASSWD_VEN_1_REG 0x1 /* RO */ +#define KHADAS_MCU_PASSWD_VEN_2_REG 0x2 /* RO */ +#define KHADAS_MCU_PASSWD_VEN_3_REG 0x3 /* RO */ +#define KHADAS_MCU_PASSWD_VEN_4_REG 0x4 /* RO */ +#define KHADAS_MCU_PASSWD_VEN_5_REG 0x5 /* RO */ +#define KHADAS_MCU_MAC_0_REG 0x6 /* RO */ +#define KHADAS_MCU_MAC_1_REG 0x7 /* RO */ +#define KHADAS_MCU_MAC_2_REG 0x8 /* RO */ +#define KHADAS_MCU_MAC_3_REG 0x9 /* RO */ +#define KHADAS_MCU_MAC_4_REG 0xa /* RO */ +#define KHADAS_MCU_MAC_5_REG 0xb /* RO */ +#define KHADAS_MCU_USID_0_REG 0xc /* RO */ +#define KHADAS_MCU_USID_1_REG 0xd /* RO */ +#define KHADAS_MCU_USID_2_REG 0xe /* RO */ +#define KHADAS_MCU_USID_3_REG 0xf /* RO */ +#define KHADAS_MCU_USID_4_REG 0x10 /* RO */ +#define KHADAS_MCU_USID_5_REG 0x11 /* RO */ +#define KHADAS_MCU_VERSION_0_REG 0x12 /* RO */ +#define KHADAS_MCU_VERSION_1_REG 0x13 /* RO */ +#define KHADAS_MCU_DEVICE_NO_0_REG 0x14 /* RO */ +#define KHADAS_MCU_DEVICE_NO_1_REG 0x15 /* RO */ +#define KHADAS_MCU_FACTORY_TEST_REG 0x16 /* R */ +#define KHADAS_MCU_BOOT_MODE_REG 0x20 /* RW */ +#define KHADAS_MCU_BOOT_EN_WOL_REG 0x21 /* RW */ +#define KHADAS_MCU_BOOT_EN_RTC_REG 0x22 /* RW */ +#define KHADAS_MCU_BOOT_EN_EXP_REG 0x23 /* RW */ +#define KHADAS_MCU_BOOT_EN_IR_REG 0x24 /* RW */ +#define KHADAS_MCU_BOOT_EN_DCIN_REG 0x25 /* RW */ +#define KHADAS_MCU_BOOT_EN_KEY_REG 0x26 /* RW */ +#define KHADAS_MCU_KEY_MODE_REG 0x27 /* RW */ +#define KHADAS_MCU_LED_MODE_ON_REG 0x28 /* RW */ +#define KHADAS_MCU_LED_MODE_OFF_REG 0x29 /* RW */ +#define KHADAS_MCU_SHUTDOWN_NORMAL_REG 0x2c /* RW */ +#define KHADAS_MCU_MAC_SWITCH_REG 0x2d /* RW */ +#define KHADAS_MCU_MCU_SLEEP_MODE_REG 0x2e /* RW */ +#define KHADAS_MCU_IR_CODE1_0_REG 0x2f /* RW */ +#define KHADAS_MCU_IR_CODE1_1_REG 0x30 /* RW */ +#define KHADAS_MCU_IR_CODE1_2_REG 0x31 /* RW */ +#define KHADAS_MCU_IR_CODE1_3_REG 0x32 /* RW */ +#define KHADAS_MCU_USB_PCIE_SWITCH_REG 0x33 /* RW */ +#define KHADAS_MCU_IR_CODE2_0_REG 0x34 /* RW */ +#define KHADAS_MCU_IR_CODE2_1_REG 0x35 /* RW */ +#define KHADAS_MCU_IR_CODE2_2_REG 0x36 /* RW */ +#define KHADAS_MCU_IR_CODE2_3_REG 0x37 /* RW */ +#define KHADAS_MCU_PASSWD_USER_0_REG 0x40 /* RW */ +#define KHADAS_MCU_PASSWD_USER_1_REG 0x41 /* RW */ +#define KHADAS_MCU_PASSWD_USER_2_REG 0x42 /* RW */ +#define KHADAS_MCU_PASSWD_USER_3_REG 0x43 /* RW */ +#define KHADAS_MCU_PASSWD_USER_4_REG 0x44 /* RW */ +#define KHADAS_MCU_PASSWD_USER_5_REG 0x45 /* RW */ +#define KHADAS_MCU_USER_DATA_0_REG 0x46 /* RW 56 bytes */ +#define KHADAS_MCU_PWR_OFF_CMD_REG 0x80 /* WO */ +#define KHADAS_MCU_PASSWD_START_REG 0x81 /* WO */ +#define KHADAS_MCU_CHECK_VEN_PASSWD_REG 0x82 /* WO */ +#define KHADAS_MCU_CHECK_USER_PASSWD_REG 0x83 /* WO */ +#define KHADAS_MCU_SHUTDOWN_NORMAL_STATUS_REG 0x86 /* RO */ +#define KHADAS_MCU_WOL_INIT_START_REG 0x87 /* WO */ +#define KHADAS_MCU_CMD_FAN_STATUS_CTRL_REG 0x88 /* WO */ + +/* Boards */ +enum { + KHADAS_BOARD_VIM1 = 0x1, + KHADAS_BOARD_VIM2, + KHADAS_BOARD_VIM3, + KHADAS_BOARD_EDGE = 0x11, + KHADAS_BOARD_EDGE_V, +}; + +/** + * struct khadas_mcu_data - Khadas MCU MFD structure + * @device: device reference used for logs + * @map: register map + */ +struct khadas_mcu { + struct device *dev; + struct regmap *map; +}; + +#endif /* MFD_KHADAS_MCU_H */ From patchwork Tue May 12 13:26:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 11543181 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C0C991668 for ; Tue, 12 May 2020 13:26:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A29C4206DD for ; Tue, 12 May 2020 13:26:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20150623.gappssmtp.com header.i=@baylibre-com.20150623.gappssmtp.com header.b="P000BKk6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730012AbgELN0Z (ORCPT ); Tue, 12 May 2020 09:26:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729949AbgELN0Y (ORCPT ); Tue, 12 May 2020 09:26:24 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2C3DC05BD0B for ; Tue, 12 May 2020 06:26:23 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id e16so15376223wra.7 for ; Tue, 12 May 2020 06:26:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AT7F3lHkleJYJf6ArphPWyOpM56JVM5mHZcAwbWvMm4=; b=P000BKk6kRS6mG4RDIUXyBsNyG/eZJ7AQO5s0MGLc9hZqyfuiPOjkEgCUQeQlwCNfy t6Z76E48EStqfJcHbnHe6tz3Utgo5shjjcnpO/SHkfyY4vridZiMlOTrsS1RAZZrGNZp 0B1YMyWuTVN4SKkzRaM4hCXScc08y1KDSPKqsA5vGcEAl4vMtQsEmIQDtFujzYt9KmoZ gbnVilFHiuszaPdiUjb+dw69N5JowJREEUy/Q5PWVid0GpPDEsq0qZn9XPIaa9OCnuFE HVVtV3d+IZzYqKGNdgoQZUO1jj3T7wklGo5tIteFSWPbStk2VFDQVPeEFwm4HEXcztIc fM+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AT7F3lHkleJYJf6ArphPWyOpM56JVM5mHZcAwbWvMm4=; b=bhWKKBP/oR8gbMRiNBHezDOKTl6wz5ttdpAnlpOxHlH9LBT9ppzGO31OEvWzGt9me7 TiEg8wGVICRDHO3swHjMdrVDrr/dVPMQADaSMCq4in1wXV8k96GfvKMzFP3Wp2Q1967M 9lRtJTrybkjeUl2hN51qEY5Cy3E64sI/V6BbTHSAMoxxTUMPxtJvbFUPlu67PfxYEJEl U9ol9WvXAk033rX4s1d0ZYxnyPAEvKMKy4J3/VMnuQBUmwlrKnAZB0gwEOD7Y0/PTr6J yeVR4Bw+FO93Gul5CBLITscr86hkkRZjxC6mMOWX/OkC1LjOPNfBOSHWvuTUSObZjJIo o4Cw== X-Gm-Message-State: AGi0PuaKxKYESioB95wOV2asQ31eypptbRqS45XMyVEBRw8q3Pg7nRXN Lz9zCbdh6ae/YdcVXJS8YGjKPQ== X-Google-Smtp-Source: APiQypJAIR/wl5WZ+wRSFmBEv8f8mUMSkzbG4Uh2oabJsHfJxmHHcdTv7uE1/2v38jv8ReO8P2yPPw== X-Received: by 2002:adf:dcc8:: with SMTP id x8mr10712073wrm.404.1589289982214; Tue, 12 May 2020 06:26:22 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:2ec0:82b0:4460:3fd3:382:4a71]) by smtp.gmail.com with ESMTPSA id g15sm14441844wro.71.2020.05.12.06.26.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2020 06:26:21 -0700 (PDT) From: Neil Armstrong To: srinivas.kandagatla@linaro.org, rui.zhang@intel.com, daniel.lezcano@linaro.org, amit.kucheria@verdurent.com Cc: Neil Armstrong , linux-amlogic@lists.infradead.org, linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/6] thermal: add support for the MCU controlled FAN on Khadas boards Date: Tue, 12 May 2020 15:26:10 +0200 Message-Id: <20200512132613.31507-4-narmstrong@baylibre.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20200512132613.31507-1-narmstrong@baylibre.com> References: <20200512132613.31507-1-narmstrong@baylibre.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The new Khadas VIM2 and VIM3 boards controls the cooling fan via the on-board microcontroller. This implements the FAN control as thermal devices and as cell of the Khadas MCU MFD driver. Signed-off-by: Neil Armstrong --- drivers/thermal/Kconfig | 10 ++ drivers/thermal/Makefile | 1 + drivers/thermal/khadas_mcu_fan.c | 174 +++++++++++++++++++++++++++++++ 3 files changed, 185 insertions(+) create mode 100644 drivers/thermal/khadas_mcu_fan.c diff --git a/drivers/thermal/Kconfig b/drivers/thermal/Kconfig index 91af271e9bb0..72b3960cc5ac 100644 --- a/drivers/thermal/Kconfig +++ b/drivers/thermal/Kconfig @@ -490,4 +490,14 @@ config SPRD_THERMAL help Support for the Spreadtrum thermal sensor driver in the Linux thermal framework. + +config KHADAS_MCU_FAN_THERMAL + tristate "Khadas MCU controller FAN cooling support" + depends on OF || COMPILE_TEST + select MFD_CORE + select REGMAP + help + If you say yes here you get support for the FAN controlled + by the Microcontroller found on the Khadas VIM boards. + endif diff --git a/drivers/thermal/Makefile b/drivers/thermal/Makefile index 8c8ed7b79915..460428c2122c 100644 --- a/drivers/thermal/Makefile +++ b/drivers/thermal/Makefile @@ -60,3 +60,4 @@ obj-$(CONFIG_ZX2967_THERMAL) += zx2967_thermal.o obj-$(CONFIG_UNIPHIER_THERMAL) += uniphier_thermal.o obj-$(CONFIG_AMLOGIC_THERMAL) += amlogic_thermal.o obj-$(CONFIG_SPRD_THERMAL) += sprd_thermal.o +obj-$(CONFIG_KHADAS_MCU_FAN_THERMAL) += khadas_mcu_fan.o diff --git a/drivers/thermal/khadas_mcu_fan.c b/drivers/thermal/khadas_mcu_fan.c new file mode 100644 index 000000000000..044d4aba8be2 --- /dev/null +++ b/drivers/thermal/khadas_mcu_fan.c @@ -0,0 +1,174 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Khadas MCU Controlled FAN driver + * + * Copyright (C) 2020 BayLibre SAS + * Author(s): Neil Armstrong + */ + +#include +#include +#include +#include +#include +#include +#include + +#define MAX_LEVEL 3 + +struct khadas_mcu_fan_ctx { + struct khadas_mcu *mcu; + unsigned int level; + struct thermal_cooling_device *cdev; +}; + +static int khadas_mcu_fan_set_level(struct khadas_mcu_fan_ctx *ctx, + unsigned int level) +{ + int ret; + + ret = regmap_write(ctx->mcu->map, KHADAS_MCU_CMD_FAN_STATUS_CTRL_REG, + level); + if (ret) + return ret; + + ctx->level = level; + + return 0; +} + +static int khadas_mcu_fan_get_max_state(struct thermal_cooling_device *cdev, + unsigned long *state) +{ + struct khadas_mcu_fan_ctx *ctx = cdev->devdata; + + if (!ctx) + return -EINVAL; + + *state = MAX_LEVEL; + + return 0; +} + +static int khadas_mcu_fan_get_cur_state(struct thermal_cooling_device *cdev, + unsigned long *state) +{ + struct khadas_mcu_fan_ctx *ctx = cdev->devdata; + + if (!ctx) + return -EINVAL; + + *state = ctx->level; + + return 0; +} + +static int +khadas_mcu_fan_set_cur_state(struct thermal_cooling_device *cdev, + unsigned long state) +{ + struct khadas_mcu_fan_ctx *ctx = cdev->devdata; + + if (!ctx || (state > MAX_LEVEL)) + return -EINVAL; + + if (state == ctx->level) + return 0; + + return khadas_mcu_fan_set_level(ctx, state); +} + +static const struct thermal_cooling_device_ops khadas_mcu_fan_cooling_ops = { + .get_max_state = khadas_mcu_fan_get_max_state, + .get_cur_state = khadas_mcu_fan_get_cur_state, + .set_cur_state = khadas_mcu_fan_set_cur_state, +}; + +static int khadas_mcu_fan_probe(struct platform_device *pdev) +{ + struct khadas_mcu *mcu = dev_get_drvdata(pdev->dev.parent); + struct thermal_cooling_device *cdev; + struct device *dev = &pdev->dev; + struct khadas_mcu_fan_ctx *ctx; + int ret; + + ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); + if (!ctx) + return -ENOMEM; + ctx->mcu = mcu; + platform_set_drvdata(pdev, ctx); + + cdev = devm_thermal_of_cooling_device_register(dev->parent, + dev->parent->of_node, "khadas-mcu-fan", ctx, + &khadas_mcu_fan_cooling_ops); + if (IS_ERR(cdev)) { + ret = PTR_ERR(cdev); + dev_err(dev, + "Failed to register khadas-mcu-fan as cooling device: %d\n", + ret); + return ret; + } + ctx->cdev = cdev; + thermal_cdev_update(cdev); + + return 0; +} + +static int khadas_mcu_fan_disable(struct device *dev) +{ + struct khadas_mcu_fan_ctx *ctx = dev_get_drvdata(dev); + unsigned int level_save = ctx->level; + int ret; + + ret = khadas_mcu_fan_set_level(ctx, 0); + if (ret) + return ret; + + ctx->level = level_save; + + return 0; +} + +static void khadas_mcu_fan_shutdown(struct platform_device *pdev) +{ + khadas_mcu_fan_disable(&pdev->dev); +} + +#ifdef CONFIG_PM_SLEEP +static int khadas_mcu_fan_suspend(struct device *dev) +{ + return khadas_mcu_fan_disable(dev); +} + +static int khadas_mcu_fan_resume(struct device *dev) +{ + struct khadas_mcu_fan_ctx *ctx = dev_get_drvdata(dev); + + return khadas_mcu_fan_set_level(ctx, ctx->level); +} +#endif + +static SIMPLE_DEV_PM_OPS(khadas_mcu_fan_pm, khadas_mcu_fan_suspend, + khadas_mcu_fan_resume); + +static const struct platform_device_id khadas_mcu_fan_id_table[] = { + { .name = "khadas-mcu-fan-ctrl", }, + {}, +}; +MODULE_DEVICE_TABLE(platform, khadas_mcu_fan_id_table); + +static struct platform_driver khadas_mcu_fan_driver = { + .probe = khadas_mcu_fan_probe, + .shutdown = khadas_mcu_fan_shutdown, + .driver = { + .name = "khadas-mcu-fan-ctrl", + .pm = &khadas_mcu_fan_pm, + }, + .id_table = khadas_mcu_fan_id_table, +}; + +module_platform_driver(khadas_mcu_fan_driver); + +MODULE_AUTHOR("Neil Armstrong "); +MODULE_DESCRIPTION("Khadas MCU FAN driver"); +MODULE_LICENSE("GPL"); From patchwork Tue May 12 13:26:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 11543183 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6925B1668 for ; Tue, 12 May 2020 13:26:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4D80D2078A for ; Tue, 12 May 2020 13:26:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20150623.gappssmtp.com header.i=@baylibre-com.20150623.gappssmtp.com header.b="LYWONKXk" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730036AbgELN0Z (ORCPT ); Tue, 12 May 2020 09:26:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726891AbgELN0Z (ORCPT ); Tue, 12 May 2020 09:26:25 -0400 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFA0FC061A0E for ; Tue, 12 May 2020 06:26:24 -0700 (PDT) Received: by mail-wr1-x442.google.com with SMTP id y3so15375239wrt.1 for ; Tue, 12 May 2020 06:26:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Y7Fjt5IgWK4L8ZaTfnqiN9Z1czwHhj1bMsFl3W8CxoM=; b=LYWONKXkLYB8oqnPo0mSL3quCSffayNM7ZRqyhSMZGNO3RR7xd6W33u3XKbffAP84F bmxfJocnhaAXUbCEnisuphi/rhJqyI+3RFf3R0zDST/RIEc7O2dRLeoA/nhW4AgPjF0b fRqhH6w7XeDRNkPK/SeySJ86EnInMrQkfzuBVL9RKyPa5NWXW61VDDc60PwnMaFHcuCY Z1HNtAXEyws4omu6YIonZyIBhWxscrWnU7S5NUeqInP6hp0oEwIwO7BoHJwZkPeZM23c ft4PazpF0vPCAr4mmLc4T4AbUq6H4omRSUQZX1KG1wHqHQwox0dPdkq2B+JD07kb4713 bTOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Y7Fjt5IgWK4L8ZaTfnqiN9Z1czwHhj1bMsFl3W8CxoM=; b=oCXdrM9FeTqQKvbBjkPoKytThOyVVGxrlOkJ1QpyI0VEZEXO4EcTg5aicLD+f0+fcD 76HOjreGJB6FC1T2n3gZuqYRIHk3iR8QcB9o8QNh/9kImpo3J9pbMQBC6vgymyP0OdPo xX2jkPm2IbXrFz67E4YPRJLLWg/zoSxOWBuzKfDU4W8qV1g5Ol30DLvdum64cgIVuQzN OX/wWl8SPLEF3cmmGZEX0gnSahB9VzDwxlhmNcIZZt+SZp3L6qx2PasTjxsfGlxqZvVC rhgERFCyFCNxiS07jdDNfp3aDf39/PdsPkRqnjP4UAYbu681m3U2sj2fcrnfJl+jQ8KZ N7fw== X-Gm-Message-State: AGi0PubCLhEC1Psmmlik+1VRBTUhUyNQD0IvlvwCR049uGFBnrzSedwI 4ufp8Zx2nsemNncI/5JwPiTkMQ== X-Google-Smtp-Source: APiQypKYFDg7ilAgTtvn5GrhpXky9/qr6Vck6lVct7tBjG3jzCg6ZL0Ikwa6qJeUUEz17lgO3oxEhw== X-Received: by 2002:adf:f00e:: with SMTP id j14mr18750036wro.252.1589289983524; Tue, 12 May 2020 06:26:23 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:2ec0:82b0:4460:3fd3:382:4a71]) by smtp.gmail.com with ESMTPSA id g15sm14441844wro.71.2020.05.12.06.26.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2020 06:26:22 -0700 (PDT) From: Neil Armstrong To: srinivas.kandagatla@linaro.org Cc: Neil Armstrong , linux-amlogic@lists.infradead.org, linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 4/6] nvmem: add support for the Khadas MCU Programmable User Memory Date: Tue, 12 May 2020 15:26:11 +0200 Message-Id: <20200512132613.31507-5-narmstrong@baylibre.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20200512132613.31507-1-narmstrong@baylibre.com> References: <20200512132613.31507-1-narmstrong@baylibre.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The new Khadas VIM2, VIM3 and Edge boards embeds an on-board microcontroller offering a 56bytes User Programmable NVMEM array. This array needs a password to be writable, thus a password sysfs file has been added on the device node to unlock the NVMEM. The default 6bytes password id: "Khadas" This implements the user NVMEM devices as cell of the Khadas MCU MFD driver. Signed-off-by: Neil Armstrong --- drivers/nvmem/Kconfig | 8 ++ drivers/nvmem/Makefile | 2 + drivers/nvmem/khadas-mcu-user-mem.c | 128 ++++++++++++++++++++++++++++ 3 files changed, 138 insertions(+) create mode 100644 drivers/nvmem/khadas-mcu-user-mem.c diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig index d7b7f6d688e7..92cd4f6aa931 100644 --- a/drivers/nvmem/Kconfig +++ b/drivers/nvmem/Kconfig @@ -67,6 +67,14 @@ config JZ4780_EFUSE To compile this driver as a module, choose M here: the module will be called nvmem_jz4780_efuse. +config NVMEM_KHADAS_MCU_USER_MEM + tristate "Khadas MCU User programmable memory support" + depends on MFD_KHADAS_MCU + depends on REGMAP + help + This is a driver for the MCU User programmable memory + available on the Khadas VIM and Edge boards. + config NVMEM_LPC18XX_EEPROM tristate "NXP LPC18XX EEPROM Memory Support" depends on ARCH_LPC18XX || COMPILE_TEST diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile index a7c377218341..0516a309542d 100644 --- a/drivers/nvmem/Makefile +++ b/drivers/nvmem/Makefile @@ -17,6 +17,8 @@ obj-$(CONFIG_NVMEM_IMX_OCOTP_SCU) += nvmem-imx-ocotp-scu.o nvmem-imx-ocotp-scu-y := imx-ocotp-scu.o obj-$(CONFIG_JZ4780_EFUSE) += nvmem_jz4780_efuse.o nvmem_jz4780_efuse-y := jz4780-efuse.o +obj-$(CONFIG_NVMEM_KHADAS_MCU_USER_MEM) += nvmem-khadas-mcu-user-mem.o +nvmem-khadas-mcu-user-mem-y := khadas-mcu-user-mem.o obj-$(CONFIG_NVMEM_LPC18XX_EEPROM) += nvmem_lpc18xx_eeprom.o nvmem_lpc18xx_eeprom-y := lpc18xx_eeprom.o obj-$(CONFIG_NVMEM_LPC18XX_OTP) += nvmem_lpc18xx_otp.o diff --git a/drivers/nvmem/khadas-mcu-user-mem.c b/drivers/nvmem/khadas-mcu-user-mem.c new file mode 100644 index 000000000000..a1d5ae9a030c --- /dev/null +++ b/drivers/nvmem/khadas-mcu-user-mem.c @@ -0,0 +1,128 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Driver for Khadas MCU User programmable Memory + * + * Copyright (C) 2020 BayLibre SAS + * Author(s): Neil Armstrong + */ + +#include +#include +#include +#include +#include +#include +#include + +static int khadas_mcu_user_mem_read(void *context, unsigned int offset, + void *val, size_t bytes) +{ + struct khadas_mcu *khadas_mcu = context; + + return regmap_bulk_read(khadas_mcu->map, + KHADAS_MCU_USER_DATA_0_REG + offset, + val, bytes); +} + +static int khadas_mcu_user_mem_write(void *context, unsigned int offset, + void *val, size_t bytes) +{ + struct khadas_mcu *khadas_mcu = context; + + return regmap_bulk_write(khadas_mcu->map, + KHADAS_MCU_USER_DATA_0_REG + offset, + val, bytes); +} + +static ssize_t password_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct khadas_mcu *khadas_mcu = dev_get_drvdata(dev); + int i, ret; + + if (count < 6) + return -EINVAL; + + ret = regmap_write(khadas_mcu->map, KHADAS_MCU_PASSWD_START_REG, 1); + if (ret) + return ret; + + for (i = 0 ; i < 6 ; ++i) { + ret = regmap_write(khadas_mcu->map, + KHADAS_MCU_CHECK_USER_PASSWD_REG, + buf[i]); + if (ret) + goto out; + } + + ret = regmap_write(khadas_mcu->map, KHADAS_MCU_PASSWD_START_REG, 0); + if (ret) + return ret; + + return count; +out: + regmap_write(khadas_mcu->map, KHADAS_MCU_PASSWD_START_REG, 0); + + return ret; +} + +static DEVICE_ATTR_WO(password); + +static struct attribute *khadas_mcu_user_mem_sysfs_attributes[] = { + &dev_attr_password.attr, + NULL, +}; + +static const struct attribute_group khadas_mcu_user_mem_sysfs_attr_group = { + .attrs = khadas_mcu_user_mem_sysfs_attributes, +}; + +static int khadas_mcu_user_mem_probe(struct platform_device *pdev) +{ + struct khadas_mcu *khadas_mcu = dev_get_drvdata(pdev->dev.parent); + struct device *dev = &pdev->dev; + struct nvmem_device *nvmem; + struct nvmem_config *econfig; + + econfig = devm_kzalloc(dev, sizeof(*econfig), GFP_KERNEL); + if (!econfig) + return -ENOMEM; + + econfig->dev = pdev->dev.parent; + econfig->name = dev_name(pdev->dev.parent); + econfig->stride = 1; + econfig->word_size = 1; + econfig->reg_read = khadas_mcu_user_mem_read; + econfig->reg_write = khadas_mcu_user_mem_write; + econfig->size = 56; + econfig->priv = khadas_mcu; + + platform_set_drvdata(pdev, khadas_mcu); + + nvmem = devm_nvmem_register(&pdev->dev, econfig); + if (IS_ERR(nvmem)) + return PTR_ERR(nvmem); + + return sysfs_create_group(&pdev->dev.kobj, + &khadas_mcu_user_mem_sysfs_attr_group); +} + +static const struct platform_device_id khadas_mcu_user_mem_id_table[] = { + { .name = "khadas-mcu-user-mem", }, + {}, +}; +MODULE_DEVICE_TABLE(platform, khadas_mcu_user_mem_id_table); + +static struct platform_driver khadas_mcu_user_mem_driver = { + .probe = khadas_mcu_user_mem_probe, + .driver = { + .name = "khadas-mcu-user-mem", + }, + .id_table = khadas_mcu_user_mem_id_table, +}; + +module_platform_driver(khadas_mcu_user_mem_driver); + +MODULE_AUTHOR("Neil Armstrong "); +MODULE_DESCRIPTION("Khadas MCU User MEM driver"); +MODULE_LICENSE("GPL v2"); From patchwork Tue May 12 13:26:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 11543187 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6C82E139F for ; Tue, 12 May 2020 13:26:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 524D7206F5 for ; Tue, 12 May 2020 13:26:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20150623.gappssmtp.com header.i=@baylibre-com.20150623.gappssmtp.com header.b="tFn1g6Vn" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730083AbgELN03 (ORCPT ); Tue, 12 May 2020 09:26:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730074AbgELN00 (ORCPT ); Tue, 12 May 2020 09:26:26 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C83FC061A0C for ; Tue, 12 May 2020 06:26:26 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id h17so6487672wrc.8 for ; Tue, 12 May 2020 06:26:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OOA2tjrCMzpEGVQ4wsZGsx+qQve4HNZ307qi+80/974=; b=tFn1g6VnvjqXPa5wWer0AZBSgCntLE7a3TDJber7TVz1ksZz0vw9pfhNaKabsusts3 Q4u3+Y5oY5lvmSGLH9CJQ6iSHnMcGwSbDi5N3mV6iaXU3iwtcRge+GOCgHJTPwx0Dunt 2WFUIUd54IjSQ9oSGEb5gWVJfC/jZJ4qc9HgNV0GYgD+1BXgina5rNgxqjWB/aEYVW5+ 7le4q61yeaatKEThlrAGb+ERtdyhtKTxWq8CMOPXoSKqAyWd9kFZ6ufh5iuxUIRomUzA PmDi5o+TmXmttNyl87E1DKIAW4CJtNXTrTnaFSIGPzR94ZZjgoBRGo+8WdBKfJvQHsR5 byRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OOA2tjrCMzpEGVQ4wsZGsx+qQve4HNZ307qi+80/974=; b=O9y49Jd0tCp40wHOjTQuUBlDx7ttesXZbEL09HXUY/YOyYRI2gk0yvc16CgNtNUIBs mT5T7q871rwUWZKXuM7fx6S3kA9KVRptN12sVQxSBdUu4pJyO8npbhAxZNvoElFwdXKK lUwE14ply48Mfkbuc2IbPFmYgFt82tjVjDslhkyj4HF4lecBzFtDpO7DDP8XEJw9EL/b 54Vt2fq3O+qg2h+FLd+yTeJvxBXLBDU/rCfosUn8SpCGw9QMfFAZ3Q99hnYfKDOkgBut CfroAk3q7IbRv+7EKFXX6ZMEvWtKgaKh7KhOEArqbr6hq09ACmJYpSWqZF13Goy3f+BU A2NA== X-Gm-Message-State: AGi0PuZjllOrNaxYm8UQWoSoGIuqcRau5uNbxD2RRuUYGjNjuyHQKso5 NAp5Su0HiIsQZ/rfxbKzCnKiPQBLSa/4EQ== X-Google-Smtp-Source: APiQypLPHEVWduy/3LzWWOhygupngnUuDQ/k1GFsn734lHfe0CkKPw+iJ6B+0gL3o0nrI8H96uujxg== X-Received: by 2002:a5d:400f:: with SMTP id n15mr13811365wrp.419.1589289984995; Tue, 12 May 2020 06:26:24 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:2ec0:82b0:4460:3fd3:382:4a71]) by smtp.gmail.com with ESMTPSA id g15sm14441844wro.71.2020.05.12.06.26.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2020 06:26:24 -0700 (PDT) From: Neil Armstrong To: lee.jones@linaro.org, srinivas.kandagatla@linaro.org, rui.zhang@intel.com, daniel.lezcano@linaro.org, amit.kucheria@verdurent.com Cc: Neil Armstrong , linux-amlogic@lists.infradead.org, linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 5/6] MAINTAINERS: add myself as maintainer for Khadas MCU drivers Date: Tue, 12 May 2020 15:26:12 +0200 Message-Id: <20200512132613.31507-6-narmstrong@baylibre.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20200512132613.31507-1-narmstrong@baylibre.com> References: <20200512132613.31507-1-narmstrong@baylibre.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Add the HWMON and NVMEM drivers along the MFD drivers and header as Maintained by myself. Signed-off-by: Neil Armstrong --- MAINTAINERS | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index b816a453b10e..609baa78d810 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -9431,6 +9431,16 @@ F: include/linux/kdb.h F: include/linux/kgdb.h F: kernel/debug/ +KHADAS MCU MFD DRIVER +M: Neil Armstrong +L: linux-amlogic@lists.infradead.org +S: Maintained +F: Documentation/devicetree/bindings/mfd/khadas,mcu.yaml +F: drivers/mfd/khadas-mcu.c +F: include/linux/mfd/khadas-mcu.h +F: drivers/hwmon/khadas-mcu-fan.c +F: drivers/nvmem/khadas-mcu-user-mem.c + KMEMLEAK M: Catalin Marinas S: Maintained From patchwork Tue May 12 13:26:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 11543191 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CA7A4139F for ; Tue, 12 May 2020 13:26:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B23E2206F5 for ; Tue, 12 May 2020 13:26:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20150623.gappssmtp.com header.i=@baylibre-com.20150623.gappssmtp.com header.b="s5XV7mjG" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729918AbgELN0g (ORCPT ); Tue, 12 May 2020 09:26:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730076AbgELN02 (ORCPT ); Tue, 12 May 2020 09:26:28 -0400 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18276C05BD0A for ; Tue, 12 May 2020 06:26:28 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id h17so6487806wrc.8 for ; Tue, 12 May 2020 06:26:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=itZ8nYpO9rVwAB+XOSiZ1Zaz+WlUMeN8KYJbRrgai8w=; b=s5XV7mjGrnG0C7b3JFLWA/serjUzf8eM5Sv6bPOzzXrvy+bBn5NGBA9t3ERPFyJuv2 SJow9GGfQvqbEJVESTH5XaRi90qYMpkAc+33nM7/TD7ZR1hX6v4OJx27XmVk0E2Ua+0d OqhN5SQaS1ajL2aQAdCfmyj6fWL1oVA/nBjIhPvI+Aj7x30jz7wxC2/JcETHuxaAcBB5 L8ywmE6m4FE94yCLZXU+LyWBxWS25UJ7Yj6YtCist9nBGE0fUFb/fO7lTzHvgMgJr8k6 5aV2w0izr+/SeOV1SgeR5tFhJsdUfk0n7g/S3Kdy+4sfHzBCmohoIfu8Us6qrTf3KT9/ 8JiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=itZ8nYpO9rVwAB+XOSiZ1Zaz+WlUMeN8KYJbRrgai8w=; b=JPnY5QF25SxSHZAdgaUTMmSJuChxljpq104E++50rM5mh8c+hLVpcSLeIccZb93JdY gGpsreukWQoeufkyc5ZZ2C5PwZ8juLPeAN2xd3bAh8AZrGWV0l/ZmjD+iCwfnwg5GXaJ i13H8mP8HHX5yf0/YwGasdUVfN8Kf9rs+XSEScHjdNX4cJ6y9hq5YmdZ+yoeJfIhK/P/ s6MKuPU+H6K/sXt93bBweFLaG/XyHrJXfebuSpLlLQd8b5x+8AfRoXu+KZfCTxkMHYEB +QF4gPx4osKzShTCV5CQoXv7WgMT/BFwfuESdO5VbPxUCMG71ui8DoGkdbfIybP5i/I1 5TDA== X-Gm-Message-State: AOAM5315oAWHNawSuxDpAy++hay1821Nrha16KKwCZ8xqvZW4l4MK9H5 ClcvwCEvRHalBcaIRHRPyTqL5RUFgWFA7g== X-Google-Smtp-Source: ABdhPJygO+LIUhXBZipYlpV1NjUWfdUnA48iHtMRa0nv+p1cN8d+bHqiZL+GB9Ig3+I8VNBJDIQMug== X-Received: by 2002:adf:de05:: with SMTP id b5mr1650574wrm.299.1589289986709; Tue, 12 May 2020 06:26:26 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:2ec0:82b0:4460:3fd3:382:4a71]) by smtp.gmail.com with ESMTPSA id g15sm14441844wro.71.2020.05.12.06.26.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2020 06:26:26 -0700 (PDT) From: Neil Armstrong To: khilman@baylibre.com Cc: Neil Armstrong , linux-amlogic@lists.infradead.org, linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 6/6] arm64: dts: meson-khadas-vim3: add Khadas MCU nodes Date: Tue, 12 May 2020 15:26:13 +0200 Message-Id: <20200512132613.31507-7-narmstrong@baylibre.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20200512132613.31507-1-narmstrong@baylibre.com> References: <20200512132613.31507-1-narmstrong@baylibre.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Add the Khadas MCU node with active FAN thermal nodes for all the Khadas VIM3 variants. Signed-off-by: Neil Armstrong --- .../boot/dts/amlogic/meson-khadas-vim3.dtsi | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/arch/arm64/boot/dts/amlogic/meson-khadas-vim3.dtsi b/arch/arm64/boot/dts/amlogic/meson-khadas-vim3.dtsi index 094ecf2222bb..3325e54ea690 100644 --- a/arch/arm64/boot/dts/amlogic/meson-khadas-vim3.dtsi +++ b/arch/arm64/boot/dts/amlogic/meson-khadas-vim3.dtsi @@ -183,6 +183,23 @@ hdmi-phandle = <&hdmi_tx>; }; +&cpu_thermal { + trips { + cpu_active: cpu-active { + temperature = <80000>; /* millicelsius */ + hysteresis = <2000>; /* millicelsius */ + type = "active"; + }; + }; + + cooling-maps { + map { + trip = <&cpu_active>; + cooling-device = <&khadas_mcu THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; + }; + }; +}; + &ext_mdio { external_phy: ethernet-phy@0 { /* Realtek RTL8211F (0x001cc916) */ @@ -222,6 +239,12 @@ pinctrl-0 = <&i2c_ao_sck_pins>, <&i2c_ao_sda_pins>; pinctrl-names = "default"; + khadas_mcu: system-controller@18 { + compatible = "khadas,mcu"; + reg = <0x18>; + #cooling-cells = <2>; + }; + gpio_expander: gpio-controller@20 { compatible = "ti,tca6408"; reg = <0x20>;