From patchwork Thu Jul 11 21:39:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vaishali Thakkar X-Patchwork-Id: 168846 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp11899807ilk; Thu, 11 Jul 2019 14:39:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqxooVXTlWK5r6kHPhZrEV/v6CxnA5En23jtllQHnUDCsxXBZqGPNpyJuoFAA5WiRyeoYv6v X-Received: by 2002:a17:902:112c:: with SMTP id d41mr6982107pla.33.1562881164224; Thu, 11 Jul 2019 14:39:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562881164; cv=none; d=google.com; s=arc-20160816; b=suRtVGSJWuPYCi0eVqpxoCJ9pbPKdDKdcrxky/WsLaXH4Fo6bztHs6LejbJyIqI7ey GaQgwy8UWt01USkDjwccKNJ4CUQVk/ve5BVoV5hobnvatmNMJVSr+W84EIpEYeFiGvu7 RevsVziL9dr4M0O5VtG8FfNxGCx+7n1qwTCFERRzEPtEcsqrbNfA9h3iGdhi+2OUqgA9 /WdFwGcSldlr+zmxJ18KzKvGgHp3GFlQnluxgYmfTSQiKOVSxYp2aU3l1IcbVSoQs3Rl BMQqeH+h4e848wHNwpoEgs3IBWT0MTQTnhfhk+opccJxXetXHRrKI/oSUkR+FFHd+uzM OMkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=EzNAMttS2AF92NQ3UASWjBRJOhFuJT/fWhFSd6d/ebA=; b=E45vRrVoA4SGpb79mly3X2OEo3b+qLUEXP/SXUioYu2TxJN+K906f0W3VFfM7+ssm1 1BJ6uexSkHoLrqIQB5BOlDHJbcpmJNdybgha8Lhyv+ZXKa/wonEvdakf9WyubztRaJtY piCpChN5GAfr8ARvZuQnZ0yNf72xzLOZWA0+WBlacbNLcOOCXZgmP0q7BJ6XTVk4A3MZ rwzaOmhG+/q7u0Wka2ZLb1FrfH2MrgFa1k7K572o5xe+HogNhu7PVFwAT2Nh6RWJS6X7 sytoibqKr19zThkZt8HZzmswDkXbtit0SMfqZbqOksG6RoS8HNa3JmtdHqYqV8tlqIAn BNQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="z4O/+qkL"; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a24si6016330pju.32.2019.07.11.14.39.23; Thu, 11 Jul 2019 14:39:24 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="z4O/+qkL"; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729132AbfGKVjX (ORCPT + 15 others); Thu, 11 Jul 2019 17:39:23 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:40728 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729130AbfGKVjX (ORCPT ); Thu, 11 Jul 2019 17:39:23 -0400 Received: by mail-pl1-f195.google.com with SMTP id a93so3695060pla.7 for ; Thu, 11 Jul 2019 14:39:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=EzNAMttS2AF92NQ3UASWjBRJOhFuJT/fWhFSd6d/ebA=; b=z4O/+qkLA4vXpJ3nNov59+9U3SeoYQEqGfLYay+BW7MFGHoSgA6Xn12KTpwXryLJDa kSdWHgvJHON1OZY/G7R/jEYhWD3YuXocMikT7pFnmEi0y0MAlhVK5Z2cD0FHx35XVxco c3ASNcnkXB5LpHB4QV4MZeb7lTJniA4IELJQjPbMhw+mztJT9Zirbj7YH2N4EvD5Yy5N ZUi3i27poxAiArc1ot2+gaUhMVBBHRVnt/NtXIYIMv+UxzqIkyCydOSueXVgw0FI0OJs L01/sAKO8lTUZTmO3w7KvzYTSEuNbbl4iqXIIApSvkO8BtpiU5jWOwpU6VJQghMhFkqH 8fOg== 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; bh=EzNAMttS2AF92NQ3UASWjBRJOhFuJT/fWhFSd6d/ebA=; b=Z6y6jTJ3IzoTluaYCeLJoY7DKUQIoACQFUXDDYRghxepPea2WeyB4JwVCccyQ8k6w8 lUFYf5znnHT0lJLRed2YcTy3Z3nzV5RGCGFK7i+V39gjBh3ZrNjd797BfJzCEU89tEfQ ITCpH76fFzeuxL0Jf478GVsKbxmqfEG11jEDS8KfyVVfbxDcPUp2TrebQ/r3GnQp4ZTB 38SunC7jqwXOc9JE8uWn9qfcIhPMgMQixvDnKvSrFiaK/6RXApZmiL/h50X9AiKuPaEb FZqC4zrtngXPSJ37mkr5KtiImBttOfoHKHRQaXkYoJImxaGU5BkAMywIqOymATK50u+9 pFyQ== X-Gm-Message-State: APjAAAWTB0DWKD4scbMhF1WDZrQ/W2fgG4gk1EZZC9dJLUVm5gBBobIT dpUW+5xsqxew+88L02Pirp+xc3d2hsM= X-Received: by 2002:a17:902:bd94:: with SMTP id q20mr7045643pls.307.1562881162390; Thu, 11 Jul 2019 14:39:22 -0700 (PDT) Received: from localhost.localdomain ([27.7.91.104]) by smtp.gmail.com with ESMTPSA id w3sm5709795pgl.31.2019.07.11.14.39.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Jul 2019 14:39:22 -0700 (PDT) From: Vaishali Thakkar To: agross@kernel.org Cc: david.brown@linaro.org, gregkh@linuxfoundation.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, rafael@kernel.org, bjorn.andersson@linaro.org, vkoul@kernel.org, Vaishali Thakkar Subject: [PATCH v5 1/5] base: soc: Add serial_number attribute to soc Date: Fri, 12 Jul 2019 03:09:07 +0530 Message-Id: <20190711213911.23180-2-vaishali.thakkar@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190711213911.23180-1-vaishali.thakkar@linaro.org> References: <20190711213911.23180-1-vaishali.thakkar@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: Bjorn Andersson Add new attribute named "serial_number" as a standard interface for user space to acquire the serial number of the device. For ST-Ericsson SoCs this is exposed by the cryptically named "soc_id" attribute, but this provides a human readable standardized name for this property. Signed-off-by: Bjorn Andersson Signed-off-by: Vaishali Thakkar Reviewed-by: Greg Kroah-Hartman Reviewed-by: Stephen Boyd --- Changes since v4: - Add Stephen's reviewed-by Changes since v3: - Add Greg's Reviewed-by Changes since v2: - None Changes since v1: - Make comment more clear for the case when serial number is not available --- Documentation/ABI/testing/sysfs-devices-soc | 7 +++++++ drivers/base/soc.c | 7 +++++++ include/linux/sys_soc.h | 1 + 3 files changed, 15 insertions(+) -- 2.17.1 diff --git a/Documentation/ABI/testing/sysfs-devices-soc b/Documentation/ABI/testing/sysfs-devices-soc index 6d9cc253f2b2..ba3a3fac0ee1 100644 --- a/Documentation/ABI/testing/sysfs-devices-soc +++ b/Documentation/ABI/testing/sysfs-devices-soc @@ -28,0 +29,7 @@ Description: +What: /sys/devices/socX/serial_number +Date: January 2019 +contact: Bjorn Andersson +Description: + Read-only attribute supported by most SoCs. Contains the SoC's + serial number, if available. + diff --git a/drivers/base/soc.c b/drivers/base/soc.c index 10b280f30217..b0933b9fe67f 100644 --- a/drivers/base/soc.c +++ b/drivers/base/soc.c @@ -35,0 +36 @@ static DEVICE_ATTR(family, S_IRUGO, soc_info_get, NULL); +static DEVICE_ATTR(serial_number, S_IRUGO, soc_info_get, NULL); @@ -59,0 +61,3 @@ static umode_t soc_attribute_mode(struct kobject *kobj, + if ((attr == &dev_attr_serial_number.attr) + && (soc_dev->attr->serial_number != NULL)) + return attr->mode; @@ -79,0 +84,2 @@ static ssize_t soc_info_get(struct device *dev, + if (attr == &dev_attr_serial_number) + return sprintf(buf, "%s\n", soc_dev->attr->serial_number); @@ -89,0 +96 @@ static struct attribute *soc_attr[] = { + &dev_attr_serial_number.attr, diff --git a/include/linux/sys_soc.h b/include/linux/sys_soc.h index b7c70c3e953f..48ceea867dd6 100644 --- a/include/linux/sys_soc.h +++ b/include/linux/sys_soc.h @@ -14,0 +15 @@ struct soc_device_attribute { + const char *serial_number; From patchwork Thu Jul 11 21:39:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vaishali Thakkar X-Patchwork-Id: 168848 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp11899930ilk; Thu, 11 Jul 2019 14:39:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqwwITuGN0pNIh/iB4xXzWl+M99I5XQnnA4l+eYrHVhklmPpTZ+qs+e+SsByRYM5WaJrSCUU X-Received: by 2002:a17:90a:8c0c:: with SMTP id a12mr7256792pjo.67.1562881172581; Thu, 11 Jul 2019 14:39:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562881172; cv=none; d=google.com; s=arc-20160816; b=hf2pb/zc3DlfKuvsgSwkBs9ouYnERR5NqrC2Cr2DMqs+6Ai8jr2PmXDIHnHSZEpdLY kC7GhQylVezXDgOrlU2bQ2dNt2EbaTIuWtnvyemcCt3OmT+Zsxd43CSg57XyVC/lr29c veXuVoOkQ857+J9i/vWhqOIh9+aQOmbmUDC9XDYmW6+0V4Bs8rUk4LaWniYesnYFQj4U Q6pTban62gypleljvdwk1N2tXzQErpmFMj7Op/4Os07Xk6FsYuG/4eu7D748yIxzgMkm 8laIyvtTJNHspuxkPmEDH9sVvtuIx9QMn9jTrORfaB8BEyDj3YHCwedCPxlBFTMWYprG UXgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=GUotabsRDkNTdyGiz7IJrKXKDtnryaciZIIEuni0g10=; b=T95EEny96oLKMs0IFcNxUQ3hOeey1TJ04b+DL6ZP/PvtInoh5jOVwvvkbIYWSbfFxA wi6nV7FaPHf9QoEksN2hfHZmOKwoHReyW0GgpAwPL0C51cNtFA3Rph1mVJdSztog5h2W WPGym/cOkPzH0njmZ4jaUi9ENyC9FP/mdZJES2G70uGPtJdIOWNBc1wlTiQzqTPTIqQn nLyLEFv60mQsL18hJzQwXiOvpbpM7nU4FgaVmT3WlJF4zq5RAaMkN4dVBwO46jqBBh/2 y3hsSAR8RNtKQIklvZXT8eZaP/FqBtbWT6ZURkhF/uQS3FQtff2p7bsybV+KCF1u+jge g1Jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PI6cvOAJ; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v61si5902278plb.191.2019.07.11.14.39.32; Thu, 11 Jul 2019 14:39:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PI6cvOAJ; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729177AbfGKVjb (ORCPT + 15 others); Thu, 11 Jul 2019 17:39:31 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:46458 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729152AbfGKVjb (ORCPT ); Thu, 11 Jul 2019 17:39:31 -0400 Received: by mail-pl1-f194.google.com with SMTP id c2so3673264plz.13 for ; Thu, 11 Jul 2019 14:39:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=GUotabsRDkNTdyGiz7IJrKXKDtnryaciZIIEuni0g10=; b=PI6cvOAJB3U2MdqJ/EPsBR1HiVBBUCpWAJmnvq0zgQm5ceJZ2Y9hyTm9oZNpqFfPqB ZsbT3BQSDq6amUg/33eIVvnyFiV3j4C3kLg3pQzM8I6jg9XYQ0wP/O0H0Ns/eTy9hDbe GJMFIrfkl6B3UD6DN5inKNWJkKuuPO21hBbKk0Hg0GUUowzpI1/BCr629t7rEPmU0IEK 5qmU6Ub9XIksh4zFAu7LuAMtXimpRTb4PntyvCnTTqvQAEPR+gZpQUzQFuGRzga7qenj n8Uo3JX91m2XD2E0Mr4OMTNWHz3TKh64cjhMlqZUPYvrJo/Ijc9rFCpgCWpcdWB/Qx42 iMrQ== 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; bh=GUotabsRDkNTdyGiz7IJrKXKDtnryaciZIIEuni0g10=; b=NqWH/ZCR5Juul6UxgqRLPUrhYqjUttu2Rq41LEqNxhvP/H16CDyQZt5gOTWYa4AToa L7qdJlaFZ4BwbCMUJufkEFydwYkAe3kgH/rMhJpWJQsNGWOn+vJsZa7QNII0AV1b9jtB czf9RnXhRst/7IokZdnuRhoOVeP/HQr40WA04N4uSMdu8d5E2Z8VXC3ZbkAvnPqCMNUL Kew/5jFAXH9a5BncmmWc2+vytBWQ+swRZFNGmHQyIdAgXnoLGyx7RJ0hQxdT/BGa8Iyg cXwvugN1EvfBGznCP/yrSNYl48H60AN9QURUtSox84l0ODQNgjO55dOnWy4U2CaUW0k1 Go2A== X-Gm-Message-State: APjAAAXHrjXeQ7eWTp6sRLmEnxuXFL9BRokeQtIwBBkJb6VynUf/5gw0 1rq43MPqNby4hV0nZrN+o8yph2l7u2k= X-Received: by 2002:a17:902:e2:: with SMTP id a89mr7120834pla.210.1562881170589; Thu, 11 Jul 2019 14:39:30 -0700 (PDT) Received: from localhost.localdomain ([27.7.91.104]) by smtp.gmail.com with ESMTPSA id w3sm5709795pgl.31.2019.07.11.14.39.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Jul 2019 14:39:30 -0700 (PDT) From: Vaishali Thakkar To: agross@kernel.org Cc: david.brown@linaro.org, gregkh@linuxfoundation.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, rafael@kernel.org, bjorn.andersson@linaro.org, vkoul@kernel.org, Imran Khan , Vaishali Thakkar Subject: [PATCH v5 3/5] soc: qcom: Add socinfo driver Date: Fri, 12 Jul 2019 03:09:09 +0530 Message-Id: <20190711213911.23180-4-vaishali.thakkar@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190711213911.23180-1-vaishali.thakkar@linaro.org> References: <20190711213911.23180-1-vaishali.thakkar@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: Imran Khan The Qualcomm socinfo driver exposes information about the SoC, its version and its serial number to user space. Signed-off-by: Imran Khan [Bjorn: Extract code to platform_driver, split patch in multiple] Signed-off-by: Bjorn Andersson [Vaishali: Simplify declarations, introduce qcom_socinfo struct, Fix memory leak, Remove extra code and Misc code refactoring] Signed-off-by: Vaishali Thakkar --- Changes since v4: - Return PTR_ERR in qcom_socinfo_probe instead of error value - Return PTR_ERR in smem probe to print proper error message when we fail to register the socinfo device - Use dev_dbg instead of dev_err in qcom_smem_probe - Use offset_of for exposing the value of serial_number - Unregister the platform device in smem remove function - Drop error message in socinfo_machine - Misc: Add spaces between brackets and strings/numbers in soc_of_id, item ids->item id, socinfo->SoCinfo, soc_of_id->soc_id Changes since v3: - None Changes since v2: - Fix typo in the work log under signed off by s Changes since v1: - None --- drivers/soc/qcom/Kconfig | 8 ++ drivers/soc/qcom/Makefile | 1 + drivers/soc/qcom/smem.c | 9 ++ drivers/soc/qcom/socinfo.c | 194 +++++++++++++++++++++++++++++++++++++ 4 files changed, 212 insertions(+) create mode 100644 drivers/soc/qcom/socinfo.c -- 2.17.1 diff --git a/drivers/soc/qcom/Kconfig b/drivers/soc/qcom/Kconfig index 880cf0290962..834faea78dd6 100644 --- a/drivers/soc/qcom/Kconfig +++ b/drivers/soc/qcom/Kconfig @@ -165,0 +166,8 @@ config QCOM_SMSM +config QCOM_SOCINFO + tristate "Qualcomm socinfo driver" + depends on QCOM_SMEM + select SOC_BUS + help + Say yes here to support the Qualcomm socinfo driver, providing + information about the SoC to user space. + diff --git a/drivers/soc/qcom/Makefile b/drivers/soc/qcom/Makefile index ffe519b0cb66..4da51b14d9d2 100644 --- a/drivers/soc/qcom/Makefile +++ b/drivers/soc/qcom/Makefile @@ -19,0 +20 @@ obj-$(CONFIG_QCOM_SMSM) += smsm.o +obj-$(CONFIG_QCOM_SOCINFO) += socinfo.o diff --git a/drivers/soc/qcom/smem.c b/drivers/soc/qcom/smem.c index f27c00d82ae4..0caf67e2f037 100644 --- a/drivers/soc/qcom/smem.c +++ b/drivers/soc/qcom/smem.c @@ -270,0 +271 @@ struct qcom_smem { + struct platform_device *socinfo; @@ -965,0 +967,6 @@ static int qcom_smem_probe(struct platform_device *pdev) + smem->socinfo = platform_device_register_data(&pdev->dev, "qcom-socinfo", + PLATFORM_DEVID_NONE, NULL, + 0); + if (IS_ERR(smem->socinfo)) + dev_dbg(&pdev->dev, "failed to register socinfo device\n"); + @@ -970,0 +978,2 @@ static int qcom_smem_remove(struct platform_device *pdev) + platform_device_unregister(__smem->socinfo); + diff --git a/drivers/soc/qcom/socinfo.c b/drivers/soc/qcom/socinfo.c new file mode 100644 index 000000000000..1b9eb44df7fe --- /dev/null +++ b/drivers/soc/qcom/socinfo.c @@ -0,0 +1,194 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2009-2017, The Linux Foundation. All rights reserved. + * Copyright (c) 2017-2019, Linaro Ltd. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * SoC version type with major number in the upper 16 bits and minor + * number in the lower 16 bits. + */ +#define SOCINFO_MAJOR(ver) (((ver) >> 16) & 0xffff) +#define SOCINFO_MINOR(ver) ((ver) & 0xffff) + +#define SMEM_SOCINFO_BUILD_ID_LENGTH 32 + +/* + * SMEM item id, used to acquire handles to respective + * SMEM region. + */ +#define SMEM_HW_SW_BUILD_ID 137 + +/* Socinfo SMEM item structure */ +struct socinfo { + __le32 fmt; + __le32 id; + __le32 ver; + char build_id[SMEM_SOCINFO_BUILD_ID_LENGTH]; + /* Version 2 */ + __le32 raw_id; + __le32 raw_ver; + /* Version 3 */ + __le32 hw_plat; + /* Version 4 */ + __le32 plat_ver; + /* Version 5 */ + __le32 accessory_chip; + /* Version 6 */ + __le32 hw_plat_subtype; + /* Version 7 */ + __le32 pmic_model; + __le32 pmic_die_rev; + /* Version 8 */ + __le32 pmic_model_1; + __le32 pmic_die_rev_1; + __le32 pmic_model_2; + __le32 pmic_die_rev_2; + /* Version 9 */ + __le32 foundry_id; + /* Version 10 */ + __le32 serial_num; + /* Version 11 */ + __le32 num_pmics; + __le32 pmic_array_offset; + /* Version 12 */ + __le32 chip_family; + __le32 raw_device_family; + __le32 raw_device_num; +}; + +struct qcom_socinfo { + struct soc_device *soc_dev; + struct soc_device_attribute attr; +}; + +struct soc_id { + unsigned int id; + const char *name; +}; + +static const struct soc_id soc_id[] = { + { 87, "MSM8960" }, + { 109, "APQ8064" }, + { 122, "MSM8660A" }, + { 123, "MSM8260A" }, + { 124, "APQ8060A" }, + { 126, "MSM8974" }, + { 130, "MPQ8064" }, + { 138, "MSM8960AB" }, + { 139, "APQ8060AB" }, + { 140, "MSM8260AB" }, + { 141, "MSM8660AB" }, + { 178, "APQ8084" }, + { 184, "APQ8074" }, + { 185, "MSM8274" }, + { 186, "MSM8674" }, + { 194, "MSM8974PRO" }, + { 206, "MSM8916" }, + { 208, "APQ8074-AA" }, + { 209, "APQ8074-AB" }, + { 210, "APQ8074PRO" }, + { 211, "MSM8274-AA" }, + { 212, "MSM8274-AB" }, + { 213, "MSM8274PRO" }, + { 214, "MSM8674-AA" }, + { 215, "MSM8674-AB" }, + { 216, "MSM8674PRO" }, + { 217, "MSM8974-AA" }, + { 218, "MSM8974-AB" }, + { 246, "MSM8996" }, + { 247, "APQ8016" }, + { 248, "MSM8216" }, + { 249, "MSM8116" }, + { 250, "MSM8616" }, + { 291, "APQ8096" }, + { 305, "MSM8996SG" }, + { 310, "MSM8996AU" }, + { 311, "APQ8096AU" }, + { 312, "APQ8096SG" }, +}; + +static const char *socinfo_machine(struct device *dev, unsigned int id) +{ + int idx; + + for (idx = 0; idx < ARRAY_SIZE(soc_id); idx++) { + if (soc_id[idx].id == id) + return soc_id[idx].name; + } + + return NULL; +} + +static int qcom_socinfo_probe(struct platform_device *pdev) +{ + struct qcom_socinfo *qs; + struct socinfo *info; + size_t item_size; + + info = qcom_smem_get(QCOM_SMEM_HOST_ANY, SMEM_HW_SW_BUILD_ID, + &item_size); + if (IS_ERR(info)) { + dev_err(&pdev->dev, "Couldn't find socinfo\n"); + return PTR_ERR(info); + } + + qs = devm_kzalloc(&pdev->dev, sizeof(*qs), GFP_KERNEL); + if (!qs) + return -ENOMEM; + + qs->attr.family = "Snapdragon"; + qs->attr.machine = socinfo_machine(&pdev->dev, + le32_to_cpu(info->id)); + qs->attr.revision = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%u.%u", + SOCINFO_MAJOR(le32_to_cpu(info->ver)), + SOCINFO_MINOR(le32_to_cpu(info->ver))); + if (offsetof(struct socinfo, serial_num) <= item_size) + qs->attr.serial_number = devm_kasprintf(&pdev->dev, GFP_KERNEL, + "%u", + le32_to_cpu(info->serial_num)); + + qs->soc_dev = soc_device_register(&qs->attr); + if (IS_ERR(qs->soc_dev)) + return PTR_ERR(qs->soc_dev); + + /* Feed the soc specific unique data into entropy pool */ + add_device_randomness(info, item_size); + + platform_set_drvdata(pdev, qs->soc_dev); + + return 0; +} + +static int qcom_socinfo_remove(struct platform_device *pdev) +{ + struct qcom_socinfo *qs = platform_get_drvdata(pdev); + + soc_device_unregister(qs->soc_dev); + + return 0; +} + +static struct platform_driver qcom_socinfo_driver = { + .probe = qcom_socinfo_probe, + .remove = qcom_socinfo_remove, + .driver = { + .name = "qcom-socinfo", + }, +}; + +module_platform_driver(qcom_socinfo_driver); + +MODULE_DESCRIPTION("Qualcomm SoCinfo driver"); +MODULE_LICENSE("GPL v2"); +MODULE_ALIAS("platform:qcom-socinfo");