From patchwork Fri Oct 7 15:21:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pantelis Antoniou X-Patchwork-Id: 9366385 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2F6A96075E for ; Fri, 7 Oct 2016 15:33:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1F32A296FD for ; Fri, 7 Oct 2016 15:33:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 12FFC29702; Fri, 7 Oct 2016 15:33:26 +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=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=unavailable 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 32FA3296FD for ; Fri, 7 Oct 2016 15:33:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757255AbcJGPdY (ORCPT ); Fri, 7 Oct 2016 11:33:24 -0400 Received: from mail-wm0-f47.google.com ([74.125.82.47]:38873 "EHLO mail-wm0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756849AbcJGPX3 (ORCPT ); Fri, 7 Oct 2016 11:23:29 -0400 Received: by mail-wm0-f47.google.com with SMTP id i130so46033139wmg.1 for ; Fri, 07 Oct 2016 08:23:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=konsulko.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=x2xVfuh/Dc8/LYOiBfaXaLClPO1iM5Uj1hrMmWBbvn0=; b=gBoc6YW1VR35vqAy4FRhWvZeAuGVO90iF7TPAV4q+/dcUPFq8dosGpSV+J/3cgqPcE Rgbv0UvpDCIMp943pOfQCaqtzL7/eMMtzJCZHwbvilkA3080BK12J/JIwJ2V04HN89dk 5C94In7HmF8dN0StIzUYy+oRoakELDcAne+u0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=x2xVfuh/Dc8/LYOiBfaXaLClPO1iM5Uj1hrMmWBbvn0=; b=gDkCQ/XB++Krz64Va4FqlvvkdbZMNMlaJT+vFexVvVKZRlG91YpJvuB6nBK3/TFnMh J2mVH9/0SK/dZxyD5P+9P9ztS29pPEqBX8P6Jk88KtZrDozxVnVpSzRjVTxkS7lFifl9 u3QVDGqnblDekkYtJmU2pue7X2Kur28SFavjJrCJ0BLrDMXFEp0P1jfkjvTSL5EVmI0a oMtu/LdCFP4xM83pFUGtGQCa7GbijC2HbEFp14w51teCkyv/qM401OJL8W1+mbFJdpng T/JPdmb97zwI8ZZLrXAU3XmewmMu3GvUE6mCcF+7ci9UubNh4BUU2Vvtxm7S0thjgAxS NS3A== X-Gm-Message-State: AA6/9RlZC5+KBkkMZvCbE6llHDAjxReMM/tuzJ2GW5NrVUXWTpqMu9ndqChwjbU1gG1/sQ== X-Received: by 10.194.87.34 with SMTP id u2mr21866122wjz.118.1475853802585; Fri, 07 Oct 2016 08:23:22 -0700 (PDT) Received: from localhost.localdomain ([195.97.110.117]) by smtp.gmail.com with ESMTPSA id n5sm20048269wjv.35.2016.10.07.08.23.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 07 Oct 2016 08:23:22 -0700 (PDT) From: Pantelis Antoniou To: Lee Jones Cc: Linus Walleij , Alexandre Courbot , Rob Herring , Mark Rutland , Frank Rowand , Wolfram Sang , Richard Purdie , Jacek Anaszewski , Jean Delvare , Peter Rosin , Avirup Banerjee , Georgi Vlaev , Guenter Roeck , JawaharBalaji Thirumalaisamy , Pantelis Antoniou , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, linux-i2c@vger.kernel.org, linux-leds@vger.kernel.org, linux-hwmon@vger.kernel.org Subject: [PATCH 01/10] mfd: Add Juniper I2CS MFD driver Date: Fri, 7 Oct 2016 18:21:00 +0300 Message-Id: <1475853669-22480-2-git-send-email-pantelis.antoniou@konsulko.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1475853669-22480-1-git-send-email-pantelis.antoniou@konsulko.com> References: <1475853669-22480-1-git-send-email-pantelis.antoniou@konsulko.com> Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Georgi Vlaev Add Juniper's I2CS FPGA MFD driver. This driver is bare-bones and only provides a method for the instantiation of the following subdevices. - I2C mux driver (i2c-mux-i2cs) - LEDS driver (leds-jnx-i2cs) - GPIO driver (gpio-jnx-i2cs) - HWMON driver (i2cs-fan-hwmon) Signed-off-by: Georgi Vlaev Signed-off-by: Guenter Roeck Signed-off-by: JawaharBalaji Thirumalaisamy [Ported from Juniper kernel] Signed-off-by: Pantelis Antoniou --- drivers/mfd/Kconfig | 17 ++++++ drivers/mfd/Makefile | 1 + drivers/mfd/jnx-i2cs-core.c | 118 ++++++++++++++++++++++++++++++++++++++ include/linux/mfd/jnx-i2cs-core.h | 96 +++++++++++++++++++++++++++++++ 4 files changed, 232 insertions(+) create mode 100644 drivers/mfd/jnx-i2cs-core.c create mode 100644 include/linux/mfd/jnx-i2cs-core.h diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index 6107f7a..82493d5 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig @@ -1400,6 +1400,23 @@ config MFD_JUNIPER_CBC This driver can be built as a module. If built as a module it will be called "cbc-core" +config MFD_JUNIPER_I2CS + tristate "Juniper I2CS FPGA" + depends on JNX_PTX1K_RCB || PTXPMB_COMMON || JNX_SYSTEM + select MFD_CORE + select REGMAP_I2C + select GPIO_JNX_I2CS + select I2C_MUX_I2CS + select LEDS_JNX_I2CS + depends on I2C=y + default y + help + Select this to enable the I2CS FPGA multi-function kernel driver. + This FPGA is present on almost any Juniper Networks card. + + This driver can be built as a module. If built as a module it will be + called "jnx_i2cs" + config MFD_TWL4030_AUDIO bool "TI TWL4030 Audio" depends on TWL4030_CORE diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile index 0ea6dc6..215d9cf 100644 --- a/drivers/mfd/Makefile +++ b/drivers/mfd/Makefile @@ -152,6 +152,7 @@ obj-$(CONFIG_MFD_JUNIPER_CPLD) += ptxpmb-cpld-core.o obj-$(CONFIG_MFD_JUNIPER_SAM) += sam-core.o obj-$(CONFIG_MFD_JUNIPER_EXT_CPLD) += ptxpmb-ext-cpld-core.o obj-$(CONFIG_MFD_JUNIPER_CBC) += cbc-core.o +obj-$(CONFIG_MFD_JUNIPER_I2CS) += jnx-i2cs-core.o obj-$(CONFIG_MFD_DB8500_PRCMU) += db8500-prcmu.o # ab8500-core need to come after db8500-prcmu (which provides the channel) obj-$(CONFIG_AB8500_CORE) += ab8500-core.o ab8500-sysctrl.o diff --git a/drivers/mfd/jnx-i2cs-core.c b/drivers/mfd/jnx-i2cs-core.c new file mode 100644 index 0000000..d279a73 --- /dev/null +++ b/drivers/mfd/jnx-i2cs-core.c @@ -0,0 +1,118 @@ +/* + * drivers/mfd/jnx-i2cs-core.c + * + * Copyright (c) 2014, Juniper Networks + * Author: Georgi Vlaev + * + * The I2C Slave FPGA (I2CS) - found on almost any Juniper card. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static int jnx_i2cs_probe(struct i2c_client *i2c, + const struct i2c_device_id *id) +{ + struct device *dev = &i2c->dev; + struct jnx_i2cs_platform_data *pdata = dev_get_platdata(dev); + struct device_node *child, *np = dev->of_node; + struct mfd_cell *cells; + int ncells, ret; + + if (np) { + ncells = of_get_child_count(np); + if (ncells == 0) { + dev_err(dev, "No child specified for %s\n", np->name); + return -EINVAL; + } + + cells = devm_kzalloc(dev, ncells * sizeof(*cells), GFP_KERNEL); + if (!cells) + return -ENOMEM; + + ncells = 0; + for_each_available_child_of_node(dev->of_node, child) { + const char *s; + + s = of_get_property(child, "compatible", NULL); + if (!s) { + dev_err(dev, + "Missing compatible property for %s\n", + child->name); + return -EINVAL; + } + + cells[ncells].name = child->name; + cells[ncells].of_compatible = s; + ncells++; + } + if (ncells == 0) { + dev_err(dev, "No active child for %s\n", np->name); + return -EINVAL; + } + } else if (pdata) { + cells = pdata->cells; + ncells = pdata->ncells; + } else { + return -ENODEV; + } + + ret = mfd_add_devices(dev, i2c_adapter_id(i2c->adapter), + cells, ncells, NULL, 0, NULL); + + return ret; +} + +static int jnx_i2cs_remove(struct i2c_client *i2c) +{ + mfd_remove_devices(&i2c->dev); + + return 0; +} + +static const struct of_device_id jnx_i2cs_of_match[] = { + { .compatible = "jnx,i2cs-rcb" }, + { .compatible = "jnx,i2cs-fpc" }, + { .compatible = "jnx,i2cs-sib" }, + { .compatible = "jnx,i2cs-fan" }, + { } +}; +MODULE_DEVICE_TABLE(of, jnx_i2cs_of_match); + +static const struct i2c_device_id jnx_i2cs_id[] = { + { "jnx_i2cs_rcb", 0 }, + { "jnx_i2cs_fpc", 0 }, + { "jnx_i2cs_sib", 0 }, + { "jnx_i2cs_fan", 0 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, jnx_i2cs_id); + +static struct i2c_driver jnx_i2cs_driver = { + .driver = { + .name = "jnx_i2cs", + .owner = THIS_MODULE, + .of_match_table = of_match_ptr(jnx_i2cs_of_match), + }, + .probe = jnx_i2cs_probe, + .remove = jnx_i2cs_remove, + .id_table = jnx_i2cs_id, +}; + +module_i2c_driver(jnx_i2cs_driver); + +MODULE_DESCRIPTION("Juniper I2CS MFD core driver"); +MODULE_AUTHOR("Georgi Vlaev "); +MODULE_LICENSE("GPL"); diff --git a/include/linux/mfd/jnx-i2cs-core.h b/include/linux/mfd/jnx-i2cs-core.h new file mode 100644 index 0000000..5e63aab --- /dev/null +++ b/include/linux/mfd/jnx-i2cs-core.h @@ -0,0 +1,96 @@ +/* + * I2CS FPGA (jnx-i2cs-core) registers + * + * Copyright (C) 2014 Juniper Networks + * Author: Georgi Vlaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#ifndef __JNX_I2CS_CORE_H__ +#define __JNX_I2CS_CORE_H__ + +/* SIB I2CS registers */ +#define I2CS_SCRATCH 0x00 +#define I2CS_VERSION 0x01 +#define I2CS_MASTER_STATUS 0x02 +#define I2CS_MASTER_TIMEOUT 0x03 +#define I2CS_MASTER_FORCE 0x04 +#define I2CS_I2C0_STATUS 0x05 +#define I2CS_I2C1_STATUS 0x06 +#define I2CS_I2C_RESET 0x07 +#define I2CS_DATECODE 0x0f +#define I2CS_INT_STATUS 0x10 +#define I2CS_INT_ENABLE 0x11 +#define I2CS_FRU_LED 0x12 +#define I2CS_MISC_IO 0x13 +#define I2CS_BUTTON_STATUS 0x14 +#define I2CS_BUTTON_ENABLE 0x15 +#define I2CS_GPIO_OE 0x16 +#define I2CS_GPIO_OUT 0x17 +#define I2CS_GPIO_IN 0x18 +#define I2CS_SERIAL_CONFIG0 0x19 +#define I2CS_SERIAL_CONFIG1 0x1a +#define I2CS_MII_CONFIG 0x1b +#define I2CS_MII_ADDR 0x1c +#define I2CS_MII_DATA0 0x1d +#define I2CS_MII_DATA1 0x1e +#define I2CS_MII_DATA2 0x1f +#define I2CS_PWR_CONTROL 0x20 +#define I2CS_PWR_UP_STATUS 0x21 +#define I2CS_PWR_DIS_STATUS 0x22 +#define I2CS_PWR_DIS_CAUSE 0x23 +#define I2CS_PWR_VFAIL_STATUS 0x24 +#define I2CS_PWR_VFAIL_CAUSE 0x25 +#define I2CS_PWR_TRIM_UP_A 0x26 +#define I2CS_PWR_TRIM_UP_B 0x27 +#define I2CS_PWR_TRIM_DN_A 0x28 +#define I2CS_PWR_TRIM_DN_B 0x29 +#define I2CS_PWR_VFAIL_STATUS_B 0x2a +#define I2CS_PWR_VFAIL_CAUSE_B 0x2b +#define I2CS_SCB 0x2c +#define I2CS_RESET_I2CS_REG 0x2d +#define I2CS_RESET_CONTROL 0x40 +#define I2CS_SIB_ID_PORT_STATUS 0x41 +#define I2CS_SIB_PCIE_GEN 0x42 +#define I2CS_TF_LTC 0x43 +#define I2CS_POWER_RST_HSWAP 0x44 +#define I2CS_SIB_EN 0x45 +#define I2CS_SIB_SPARE 0x46 +#define I2CS_TF_PCIE_INT_STAT 0x47 +#define I2CS_TF_PCIE_INT_EN 0x48 +#define I2CS_SIB_MISC_0 0x49 +#define I2CS_SIB_MISC_1 0x4a +#define I2CS_LINK_STATUS_0 0x4b +#define I2CS_LINK_STATUS_1 0x4c +#define I2CS_LINK_STATUS_2 0x4d +#define I2CS_LINK_STATUS_3 0x4e +#define I2CS_LINK_STATUS_4 0x4f +#define I2CS_LINK_STATUS_5 0x50 +#define I2CS_LINK_STATUS_6 0x51 +#define I2CS_LINK_STATUS_7 0x52 +#define I2CS_LINK_STATUS_8 0x53 +#define I2CS_LINK_STATUS_9 0x54 +#define I2CS_LINK_STATUS_10 0x55 +#define I2CS_LINK_STATUS_11 0x56 +#define I2CS_LINK_STATUS_12 0x57 +#define I2CS_LINK_STATUS_13 0x58 +#define I2CS_LINK_STATUS_14 0x59 +#define I2CS_LINK_STATUS_15 0x5a +#define I2CS_LINK_STATUS_16 0x5b +#define I2CS_LINK_STATUS_17 0x5c +#define I2CS_PWR_VFAIL_IGNORE_SNG 0x5d +#define I2CS_SPARE 0x5e +#define I2CS_SPARE_OE 0x5f +#define I2CS_MAX_REGISTER I2CS_SPARE_OE + +struct mfd_cell; + +struct jnx_i2cs_platform_data { + int ncells; + struct mfd_cell *cells; +}; + +#endif /*__JNX_I2CS_CORE_H__*/