Received: by 10.213.65.68 with SMTP id h4csp1721296imn; Thu, 15 Mar 2018 07:45:02 -0700 (PDT) X-Google-Smtp-Source: AG47ELsEYxeEqvRG6IwuRXrFYioFf+HWkWU7xGRAVQjmZ7CJz7/Ufs9fwiT1EREFeIn2RBWBGaCE X-Received: by 2002:a17:902:a2:: with SMTP id a31-v6mr8367273pla.204.1521125102666; Thu, 15 Mar 2018 07:45:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521125102; cv=none; d=google.com; s=arc-20160816; b=sRgzEheNH2hW/3QV5BcGBiktp6WvsMiCq6e6GzoGYHiA0CmR+SV+GqV8YlIpp8h1QU T9gLG3tBmDWq4QzbN8t6AvJIyu2NJ6eabGUYiZGHJG2IHXvCVgC1pJSaGpdfCtG1VWmT w4Cih91A/lQIjTKWbiBVagNC2oFIJvkCpuAX6Hug9ZKmXJjloZms1/CP1IBsxA2hioHQ 2Hr0rBZBLcE+bmAWjH+wfm3OhaKbPfAXCMsAbdKN6EOQKAkSxkRrr3sXwc4LuYVZ1Yby ILghdcgh8OO7EXtR7Lx0i/Hdg0z/r3RmPCH5GCRTzYVQy9bDkb48nCDsKDn9en2bzwQe DF2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:content-transfer-encoding:mime-version :message-id:date:subject:to:from:dkim-signature :arc-authentication-results; bh=6M73dZV/MzF0pNlxiD5vgTTzqJSsjGNc+KxnE39xrZ0=; b=XHx6OPsiimrqQMtsYwLVoM6mDveiWVN4gcfnTQDitsl9+KBiSuRc8qNogtZ9IxOi7J 9jfUsNT4KNV8MGoLetjHxfj6UbocKpOFbyrc7gvZ4lzh0a/FOiW1bU8SFoSpXsdOWiDa 8YDlQEngqqFR51Pl8bHpo1nznPHOOMobpMjK5qZuf1/TSMY0BmHesK0EjOmTe0O+ozJr xXLHPcWtc8RdkniFjb6FuoEL77s1ZaDH4nvXFAAipbLX66phPYxZ+2FDN2d60uXcXusB p/v1TWhrgSlKvLisXXKjkh9iN/3494Ro5vrGw9qABglP6J6uzFVpK8tsayycPTYaLX+a EZSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xilinx.onmicrosoft.com header.s=selector1-xilinx-com header.b=0SxUCEZo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g10si3554214pgp.215.2018.03.15.07.44.44; Thu, 15 Mar 2018 07:45:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=@xilinx.onmicrosoft.com header.s=selector1-xilinx-com header.b=0SxUCEZo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932332AbeCOOnK (ORCPT + 99 others); Thu, 15 Mar 2018 10:43:10 -0400 Received: from mail-sn1nam01on0067.outbound.protection.outlook.com ([104.47.32.67]:15336 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752571AbeCOOnE (ORCPT ); Thu, 15 Mar 2018 10:43:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector1-xilinx-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=6M73dZV/MzF0pNlxiD5vgTTzqJSsjGNc+KxnE39xrZ0=; b=0SxUCEZotHBb0C1fYt3MifxkFbczDhByJgAkHtOlcdM9TAnFON8G8TIJPiLO4GYDEAnnQ0F+ZnrFr/E3g0nIhwFeXM0u+bzxfjidhn67sDUxzNUl1OdizsGbLGCDd2HzCCm62xklk6kuLzex7yTjPHPXIQGaWyZjg/gFe1EqHlI= Received: from CY4PR02CA0005.namprd02.prod.outlook.com (2603:10b6:903:18::15) by SN1PR02MB1312.namprd02.prod.outlook.com (2a01:111:e400:583e::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.588.14; Thu, 15 Mar 2018 14:42:59 +0000 Received: from CY1NAM02FT009.eop-nam02.prod.protection.outlook.com (2a01:111:f400:7e45::207) by CY4PR02CA0005.outlook.office365.com (2603:10b6:903:18::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.588.14 via Frontend Transport; Thu, 15 Mar 2018 14:42:59 +0000 Authentication-Results: spf=pass (sender IP is 149.199.60.100) smtp.mailfrom=xilinx.com; wunner.de; dkim=none (message not signed) header.d=none;wunner.de; dmarc=bestguesspass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.60.100 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.60.100; helo=xsj-pvapsmtpgw02; Received: from xsj-pvapsmtpgw02 (149.199.60.100) by CY1NAM02FT009.mail.protection.outlook.com (10.152.75.12) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.567.18 via Frontend Transport; Thu, 15 Mar 2018 14:42:56 +0000 Received: from unknown-38-66.xilinx.com ([149.199.38.66]:41544 helo=xsj-pvapsmtp01) by xsj-pvapsmtpgw02 with esmtp (Exim 4.63) (envelope-from ) id 1ewU5o-0007pL-5c; Thu, 15 Mar 2018 07:42:56 -0700 Received: from [127.0.0.1] (helo=localhost) by xsj-pvapsmtp01 with smtp (Exim 4.63) (envelope-from ) id 1ewU5j-00064L-3L; Thu, 15 Mar 2018 07:42:51 -0700 Received: from xsj-pvapsmtp01 (xsj-smtp1.xilinx.com [149.199.38.66]) by xsj-smtp-dlp1.xlnx.xilinx.com (8.13.8/8.13.1) with ESMTP id w2FEghL8009631; Thu, 15 Mar 2018 07:42:43 -0700 Received: from [172.23.64.106] (helo=xhdvnc125.xilinx.com) by xsj-pvapsmtp01 with esmtp (Exim 4.63) (envelope-from ) id 1ewU5Z-000634-Vs; Thu, 15 Mar 2018 07:42:42 -0700 Received: by xhdvnc125.xilinx.com (Postfix, from userid 16987) id 1BA79121405; Thu, 15 Mar 2018 20:12:40 +0530 (IST) From: Manish Narani To: , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC PATCH] iio: adc: Add Xilinx AMS driver Date: Thu, 15 Mar 2018 20:12:27 +0530 Message-ID: <1521124947-18950-1-git-send-email-mnarani@xilinx.com> X-Mailer: git-send-email 2.1.1 X-RCIS-Action: ALLOW X-TM-AS-Product-Ver: IMSS-7.1.0.1224-8.2.0.1013-23620.005 X-TM-AS-User-Approved-Sender: Yes;Yes X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:149.199.60.100;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(346002)(396003)(39380400002)(39860400002)(376002)(2980300002)(438002)(199004)(189003)(8746002)(8936002)(39060400002)(106002)(50226002)(51416003)(2906002)(426003)(103686004)(5660300001)(8656006)(305945005)(5890100001)(7416002)(106466001)(336012)(316002)(36756003)(356003)(26005)(186003)(63266004)(575784001)(90966002)(2201001)(42186006)(110136005)(478600001)(8676002)(59450400001)(48376002)(72206003)(53946003)(8666007)(50466002)(6266002)(52956003)(36386004)(47776003)(81156014)(81166006)(6666003)(107986001)(921003)(2101003)(83996005)(5001870100001)(1121003)(559001)(579004);DIR:OUT;SFP:1101;SCL:1;SRVR:SN1PR02MB1312;H:xsj-pvapsmtpgw02;FPR:;SPF:Pass;PTR:unknown-60-100.xilinx.com,xapps1.xilinx.com;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;CY1NAM02FT009;1:JavtMQHonIbjCsRQq1hFYSCim4t21XQqGeEB9vBnLTl3pAaoIMx1Bip/H6Zdkkg/AMSxBUjrH/LjAUoBecEK4FK5TkqJ6nn/3ZJPy/mvc5KMfQXdhw5+KKmXsUez0hUX MIME-Version: 1.0 Content-Type: text/plain X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 377ee776-f176-4203-0039-08d58a830b8c X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(5600026)(4604075)(4608076)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060);SRVR:SN1PR02MB1312; X-Microsoft-Exchange-Diagnostics: 1;SN1PR02MB1312;3:i+2Q1FaysXiytdJ1lwRnAi14vqCjwc0YH4+YOHuCb836DwHtgyqnS3KQ3SR2g76NqPlrIpevQ7kcSzNsy5DAz+++tsLCu7owK5wPQMOMT/m9YCu+Afpr2rgTj/bpsDbMtnEZNG7ns1EkQTxWQL2DXlToATxFonI0OIand5uzPK5t6HwRQpKBLJAhAOOz8jKt4k3+Nj+0PmXNbktqK9DQj4g8EiufjqPX2f8wgHVITdwh+uxD6oge1qYZjdyeoQmWPeC8klJfHHWlE7hyJ4B/g98iO73RDT5vRRSeKUE5aGLokj2dIwiEcbS8vs7ejjorqIVnHod0dPYv9iYtR3myD2LtZYq8cz1GJKswGvvxyOk=;25:hemAbXfNgB1INzxxXLe0H5hNvOMqkuWhybFE+wLykCa+h2WQAMZL0FvzMtIPXG7eEQuqk/a+yy4gE7bJjWgh+E7z94Dvdwau7xHdPnCiy+njAtVX9fKE77Fs/w66cfm/SsifdYXbdRK/ojftkKS7tWvKChPxyEXjcfaz0iebbIg1cfQkp85XmmD3vjiOizp5kZuEvthLLm5fuLWj1TuLJ3x2hxXcH5h1tOUQBRKl3JyK7JbDOwgozSz2c+HIc8KD0bLbwR8D1RD8UYcI29kNIZZ+HqVnOSgcekZgYMyDzUbI38hFUEeGPFUPmd4XU/aoz27Wx379hGcE1c7dqp6NEA== X-MS-TrafficTypeDiagnostic: SN1PR02MB1312: X-Microsoft-Exchange-Diagnostics: 1;SN1PR02MB1312;31:Ca1/J1xu3tFHs5kPZDwmw/nJmojC+QYGHUtIO2Eh1/5Q27Z3XIbA952va3b1Faaq30osr+dKbZfuFjr5aIm4+RSdT3XSGBAXNNAptYojDANqfiTzwGYMoPNazA89+Zlh8gYBnGmhjYA0eJvRM9mjkqvqcmeSwfCenVQk4KcJOFoXa6zntDruquBsnvh0L7oP3tEZAiQ5CAVZMn6Akp/bTQIeZ606O2/Bk5aGWQknsoI=;20:0/vLnA3Wrv5cd0lXkAzoiFtozaHj7j9JSC989TXHQGBg9hEE4G2wJqEr4OL7AvFlef1DMdL0DFt1snk5efmEMC4GUEcwAakzdz6t3Mjw8kFS5xmCE9Ql+Yg5EWMoneVDDUiE3a88/Z3y4zyqnXNxiqhNZwvfICXNPItbQ+uC/dVZNtvr2LxqJQCg/Y+JEQJXPOaq9hDzAiQVygWJ8GQRe1lkfW2xSKUe6FWhrX2CCdSlRmU+A/Ottw9BJcdqZp5+UFmS3wggCSqkCl6pQUogLfKGIO8U/O6xfAqoiBCIrNL0i4ie6ykur+Wwa0s9bBCptqYy3v/Kb+BGYPiprHGGALoDUk414Sq6B6xN1MCQ2vH0uZ+7h41Y0IEdP60N/goAf5xXhk9BJCZDUTTHhlgmJ1dSDh/ZteSJZ7im0+7sVa9dMk4tUZ+hpCaY0xEbhm33PD1QQMPpsM8U179AqA6K1XFLaF8M9vFFTTvm+vUS1n8B2RmwUvjU4RMLlkD73nxq Content-Transfer-Encoding: quoted-printable X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(72170088055959)(192813158149592); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(93006095)(93004095)(3231221)(944501244)(52105095)(3002001)(10201501046)(6055026)(6041310)(20161123562045)(20161123564045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(6072148)(201708071742011);SRVR:SN1PR02MB1312;BCL:0;PCL:0;RULEID:;SRVR:SN1PR02MB1312; X-Microsoft-Exchange-Diagnostics: 1;SN1PR02MB1312;4:DBLr/R9bQo9s5+Fk8vltEsF2BT0UFrLedI6RwsqunXXwexB+d66n51QmP8e74x3+BtXtEi+tANVtrhcmlqubTHbACWZjPdslRwe4Tly5RePmVIA4BR+9ON+sj+bSD9WECpawpzF0fpcXoA3xAQbiHBF97Idp4+ig8LT8eTGM2uMRNiCmoJ69F5zICyt0K+uOQTRVTg9GnMgt3SemHGi8F2Xg8bi5ba8z0fEQ5SCtWJQkGeDIp5Ev7XHrhoi6bTVPzgFHllJ/R10ZGzyVNe1+/ByaASZWcM5b234LTIIegqvGu+nlONDDRbY6oCv6h8htpB0KxcOwX20dU/qzXbOoRZDX1msEksbCKKcS38J93Eg= X-Forefront-PRVS: 0612E553B4 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;SN1PR02MB1312;23:LyBBnqq5SgZAowBtea9A7PiWCWDcCG+uCIdwmlw6w?= =?us-ascii?Q?6BiEv/aMIZLav6ItkWw8F+qVw4nH/RvAUAOi5FBjAkpygfsXVzGK1MAyVqaq?= =?us-ascii?Q?x1UqwJ0mVZ3LsxFlf9ud3PxCytyQtrjbP/ZRqZQDSjnGVMpp2J9EE806uRIq?= =?us-ascii?Q?fAF1JoGPwfdToQbez/zfnd3W+IWPYjL05A4Qne5fIBX+6Lhjtxc8V4zOJeVH?= =?us-ascii?Q?K21EE0fOTEXyo+Ejyw/75g1AQbmEKr+PnlqVykeMwEVXrqK68MSK3a0rxjlf?= =?us-ascii?Q?xtYMLodlO9lrpmqoaIEMauyJWxaX4tfFCiLxRNfmKKi7AfpOeBmZJ8s6E7pV?= =?us-ascii?Q?oilKuE8Lhhl71Jq5h6Ks1Evre28quvmhLm92INcI5PdutW7ZmJL/5NrMl+xB?= =?us-ascii?Q?NYGclrljp2IdEUKGzo9bRsifBbupCuUpn0QYc0ICfU+4lm3tfB+A/1dVStkP?= =?us-ascii?Q?f8HNaYRaJpOL/eOLCNua4QG5QpV0Tq8ncxhvFsYxValhjlGK+/tFSooxezYm?= =?us-ascii?Q?pGB1+mx8TOrR46hfxh/Zq3BuqdTOGIhAcOjE0T757KKUnOlLcJ8Pn51be0Ve?= =?us-ascii?Q?QZvdRnisixc7BRTxOO5GZLXJma+JwWUuKt6+oooQJGkfQ8Cg0+i5A3LDVJjZ?= =?us-ascii?Q?Oz0d1Krwl0DdkxfRkcrtmg78Z8VObAhxBgeJR4q00ej/VVTs9qWWX+bSwZt4?= =?us-ascii?Q?cUxueNxgYg+7fnu1VbxGJ8gU/F6/Ps8zdiPVVvYCZ+AEdXGUo2AVVNHkeiL3?= =?us-ascii?Q?xJ98Vam9PYcurMzFqd9tDZttyThJK8FTJC1JElwX48VAYmqwCc4cCsTkw2ie?= =?us-ascii?Q?Ckg89l8PptT72RJy6ocf7YLnvaqzKCg6LYi+CCtpqTsf8XjWk+TRCO0VOr/O?= =?us-ascii?Q?GN1t6Hi1qE3yR5Au3J6fEaXPv8WsKiCC9CWryeVO1DyeBvEhV3OwpnP4irel?= =?us-ascii?Q?NBlIktwnGAvnE4BBVEtiq5WbIjOIGUapOFFh38IIbrloj0yPp24kOVszkzQQ?= =?us-ascii?Q?uJjWK7L0kWcdP++xWQ2MvKQhQVs9drvuW68IFQ0XdDBnuas8o7Sb4FsGpSrY?= =?us-ascii?Q?xFqctSdA0nzNkCPDPwQlWU9E4KFP9v5fZpkT3FCDtmdieUTUjQ10eKrvMRVm?= =?us-ascii?Q?QYAU7l7g0nMKTCm0pbYrpJnttPKSAv/VP0fepNgaxGE8H+xTYCOMr6iEpbSa?= =?us-ascii?Q?HErgxbwNC45CXrFeier6lO2LQvhLEux1NfApXvuuJuFBmMoCMdokqoNCHOUZ?= =?us-ascii?Q?ifu9jWRLycrr7XfiUbnCapITsSH5yPayQYAy41YkHtTihQYHECmnT4OgFy7a?= =?us-ascii?Q?AEd+v/BVLMGjOqnyZpmHTzXxAp9AP+hu1pHl7A2ieFn?= X-Microsoft-Antispam-Message-Info: +7xW+M2mm49F5neew7QO6kiZWGGvaGBbuCisxAxt8ONb0m0x7dMaqPNqgB7yqDx0LkX6kxknTag1Yxj6MNOSqpwvSbLR0gUI2bTdl69kcnXUdGjNtbyP2gA40pKo6cNiNZEnRiDlTQTPb+V9UVvCdzQ+csQyx6b2vyMFhAIoDd9uQswqQgPoND9eWI6QYsR4 X-Microsoft-Exchange-Diagnostics: 1;SN1PR02MB1312;6:N+xqR6sBEebjucnLSwqQVLDLT4yX2k4u2+mPcJo4EmHUmSVDgCCWTj0fEVBH6h5pH+emL526aG4uS/o4aHgidAVp9kVjQD4QJ3XKhFoM/jgmuwGTHNEHCuyLVUqAXgNDTO4VOFeZMVhydg8THV0KXesaG6jJ+3ZgGFoVBe2zrDCMEYkN7LOASet2BEW4F6ORM8hh3evJF8HHqQmrz2Le0bCR+RQ2q6ZkyOD8es6R2t8xnNxuUOhR0KUpYAGp8ii/rLAWNTH3bDvbZZZjUcLqNh3Nuwte6DVvmwZcY67Ngf36MvIPex1TwQFcUDRjybFWfmZMsoaTjZbsnoKSC1qu5g4Di3hG4yuJ6pIV48ky3Cg=;5:NDx4q7koEtExupMvJs1m55C17PniCuxbBgSUu6l8n4T5LtwpNa5+acl0YeSdWsHNMlH2bDmE+kQ3oeQYtwZqO9DUFEJNmuEtH5k9xhVg0Zpuiso+QYu815lKzglhskP4P6fj/0VrlXDrYdT2ZukLXJ1GU9bakTJdJZ7eDlQ9loU=;24:lzN68RTaaJWIQyIt+p6rp1uH+fCzBP+8A6dmCVVPxaY2p+/8Ygi9kzJQft/LS7quAb53jlJvy4aCUNS86s9VZHLTP48b76uv+Xv7QPcWWr8=;7:aLIwrm/dNa9F43J9swUO9AlVp8P1UXAFb2d6UHxJI+FNz/k+BpzTO7M9pL58u7wicQX4k6T4TTc+gL1z6+e6OMaYKnQGzlmB+AFsHWTHF2D37n0TFwI26PD4kpXmTT3u9X64Z3EOORBtF6+vsdVT7LpvDjjeo7K4oDGJ/uI/3P1jG6aQtQpgZxIELh1T2kgbGJagA92mofYsykHuCtQUryAcmW/HZp6OjHSHYo4d8wkOwcXhD08aQGCGwZNJ4JMm SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Mar 2018 14:42:56.7022 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 377ee776-f176-4203-0039-08d58a830b8c X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.60.100];Helo=[xsj-pvapsmtpgw02] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR02MB1312 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The AMS includes an ADC as well as on-chip sensors that can be used to sample external voltages and monitor on-die operating conditions, such as temperature and supply voltage levels. The AMS has two SYSMON blocks. PL-SYSMON block is capable of monitoring off chip voltage and temperature. PL-SYSMON block has DRP, JTAG and I2C interface to enable monitoring from external master. Out of these interface currently only DRP is supported. Other block PS-SYSMON is memory mapped to PS. The AMS can use internal channels to monitor voltage and temperature as well as one primary and up to 16 auxiliary channels for measuring external voltages. The voltage and temperature monitoring channels also have event capability which allows to generate an interrupt when their value falls below or raises above a set threshold. Signed-off-by: Manish Narani --- drivers/iio/adc/Kconfig | 10 + drivers/iio/adc/Makefile | 1 + drivers/iio/adc/xilinx-ams.c | 1115 ++++++++++++++++++++++++++++++++++++++= ++++ drivers/iio/adc/xilinx-ams.h | 278 +++++++++++ 4 files changed, 1404 insertions(+) create mode 100644 drivers/iio/adc/xilinx-ams.c create mode 100644 drivers/iio/adc/xilinx-ams.h diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig index 72bc2b7..f1b8a5f 100644 --- a/drivers/iio/adc/Kconfig +++ b/drivers/iio/adc/Kconfig @@ -931,4 +931,14 @@ config XILINX_XADC The driver can also be build as a module. If so, the module will = be called xilinx-xadc. +config XILINX_AMS + tristate "Xilinx AMS driver" + depends on ARCH_ZYNQMP || COMPILE_TEST + depends on HAS_IOMEM + help + Say yes here to have support for the Xilinx AMS. + + The driver can also be build as a module. If so, the module will = be called + xilinx-ams. + endmenu diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile index 28a9423..27ded4f 100644 --- a/drivers/iio/adc/Makefile +++ b/drivers/iio/adc/Makefile @@ -85,3 +85,4 @@ obj-$(CONFIG_VIPERBOARD_ADC) +=3D viperboard_adc.o xilinx-xadc-y :=3D xilinx-xadc-core.o xilinx-xadc-events.o obj-$(CONFIG_XILINX_XADC) +=3D xilinx-xadc.o obj-$(CONFIG_SD_ADC_MODULATOR) +=3D sd_adc_modulator.o +obj-$(CONFIG_XILINX_AMS) +=3D xilinx-ams.o diff --git a/drivers/iio/adc/xilinx-ams.c b/drivers/iio/adc/xilinx-ams.c new file mode 100644 index 0000000..2f519e6 --- /dev/null +++ b/drivers/iio/adc/xilinx-ams.c @@ -0,0 +1,1115 @@ +/* + * Xilinx AMS driver + * + * Licensed under the GPL-2 + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "xilinx-ams.h" +#include + +static const unsigned int AMS_UNMASK_TIMEOUT =3D 500; + +static inline void ams_read_reg(struct ams *ams, unsigned int offset, u32 = *data) +{ + *data =3D readl(ams->base + offset); +} + +static inline void ams_write_reg(struct ams *ams, unsigned int offset, u32= data) +{ + writel(data, ams->base + offset); +} + +static inline void ams_update_reg(struct ams *ams, unsigned int offset, + u32 mask, u32 data) +{ + u32 val; + + ams_read_reg(ams, offset, &val); + ams_write_reg(ams, offset, (val & ~mask) | (mask & data)); +} + +static inline void ams_ps_read_reg(struct ams *ams, unsigned int offset, + u32 *data) +{ + *data =3D readl(ams->ps_base + offset); +} + +static inline void ams_ps_write_reg(struct ams *ams, unsigned int offset, + u32 data) +{ + writel(data, ams->ps_base + offset); +} + +static inline void ams_ps_update_reg(struct ams *ams, unsigned int offset, + u32 mask, u32 data) +{ + u32 val; + + ams_ps_read_reg(ams, offset, &val); + ams_ps_write_reg(ams, offset, (val & ~mask) | (data & mask)); +} + +static inline void ams_apb_pl_read_reg(struct ams *ams, unsigned int offse= t, + u32 *data) +{ + *data =3D readl(ams->pl_base + offset); +} + +static inline void ams_apb_pl_write_reg(struct ams *ams, unsigned int offs= et, + u32 data) +{ + writel(data, ams->pl_base + offset); +} + +static inline void ams_apb_pl_update_reg(struct ams *ams, unsigned int off= set, + u32 mask, u32 data) +{ + u32 val; + + ams_apb_pl_read_reg(ams, offset, &val); + ams_apb_pl_write_reg(ams, offset, (val & ~mask) | (data & mask)); +} + +static void ams_update_intrmask(struct ams *ams, u64 mask, u64 val) +{ + /* intr_mask variable in ams represent bit in AMS regisetr IDR0 and= IDR1 + * first 32 biit will be of IDR0, next one are of IDR1 register. + */ + ams->intr_mask &=3D ~mask; + ams->intr_mask |=3D (val & mask); + + ams_write_reg(ams, AMS_IER_0, ~(ams->intr_mask | ams->masked_alarm)= ); + ams_write_reg(ams, AMS_IER_1, + ~(ams->intr_mask >> AMS_ISR1_INTR_MASK_SHIFT)); + ams_write_reg(ams, AMS_IDR_0, ams->intr_mask | ams->masked_alarm); + ams_write_reg(ams, AMS_IDR_1, + ams->intr_mask >> AMS_ISR1_INTR_MASK_SHIFT); +} + +static void iio_ams_disable_all_alarm(struct ams *ams) +{ + /* disable PS module alarm */ + if (ams->ps_base) { + ams_ps_update_reg(ams, AMS_REG_CONFIG1, AMS_REGCFG1_ALARM_M= ASK, + AMS_REGCFG1_ALARM_MASK); + ams_ps_update_reg(ams, AMS_REG_CONFIG3, AMS_REGCFG3_ALARM_M= ASK, + AMS_REGCFG3_ALARM_MASK); + } + + /* disable PL module alarm */ + if (ams->pl_base) { + ams->pl_bus->update(ams, AMS_REG_CONFIG1, + AMS_REGCFG1_ALARM_MASK, + AMS_REGCFG1_ALARM_MASK); + ams->pl_bus->update(ams, AMS_REG_CONFIG3, + AMS_REGCFG3_ALARM_MASK, + AMS_REGCFG3_ALARM_MASK); + } +} + +static void iio_ams_update_alarm(struct ams *ams, unsigned long alarm_mask= ) +{ + u32 cfg; + unsigned long flags; + unsigned long pl_alarm_mask; + + if (ams->ps_base) { + /* Configuring PS alarm enable */ + cfg =3D ~((alarm_mask & AMS_ISR0_ALARM_2_TO_0_MASK) << + AMS_CONF1_ALARM_2_TO_0_SHIFT); + cfg &=3D ~((alarm_mask & AMS_ISR0_ALARM_6_TO_3_MASK) << + AMS_CONF1_ALARM_6_TO_3_SHIFT); + ams_ps_update_reg(ams, AMS_REG_CONFIG1, AMS_REGCFG1_ALARM_M= ASK, + cfg); + + cfg =3D ~((alarm_mask >> AMS_CONF3_ALARM_12_TO_7_SHIFT) & + AMS_ISR0_ALARM_12_TO_7_MASK); + ams_ps_update_reg(ams, AMS_REG_CONFIG3, AMS_REGCFG3_ALARM_M= ASK, + cfg); + } + + if (ams->pl_base) { + pl_alarm_mask =3D (alarm_mask >> AMS_PL_ALARM_START); + /* Configuring PL alarm enable */ + cfg =3D ~((pl_alarm_mask & AMS_ISR0_ALARM_2_TO_0_MASK) << + AMS_CONF1_ALARM_2_TO_0_SHIFT); + cfg &=3D ~((pl_alarm_mask & AMS_ISR0_ALARM_6_TO_3_MASK) << + AMS_CONF1_ALARM_6_TO_3_SHIFT); + ams->pl_bus->update(ams, AMS_REG_CONFIG1, + AMS_REGCFG1_ALARM_MASK, cfg); + + cfg =3D ~((pl_alarm_mask >> AMS_CONF3_ALARM_12_TO_7_SHIFT) = & + AMS_ISR0_ALARM_12_TO_7_MASK); + ams->pl_bus->update(ams, AMS_REG_CONFIG3, + AMS_REGCFG3_ALARM_MASK, cfg); + } + + spin_lock_irqsave(&ams->lock, flags); + ams_update_intrmask(ams, AMS_ISR0_ALARM_MASK, ~alarm_mask); + spin_unlock_irqrestore(&ams->lock, flags); +} + +static void ams_enable_channel_sequence(struct ams *ams) +{ + int i; + unsigned long long scan_mask; + struct iio_dev *indio_dev =3D iio_priv_to_dev(ams); + + /* Enable channel sequence. First 22 bit of scan_mask represent + * PS channels, and next remaining bit represents PL channels. + */ + + /* Run calibration of PS & PL as part of the sequence */ + scan_mask =3D 1 | (1 << PS_SEQ_MAX); + for (i =3D 0; i < indio_dev->num_channels; i++) + scan_mask |=3D BIT(indio_dev->channels[i].scan_index); + + if (ams->ps_base) { + /* put sysmon in a soft reset to change the sequence */ + ams_ps_update_reg(ams, AMS_REG_CONFIG1, AMS_CONF1_SEQ_MASK, + AMS_CONF1_SEQ_DEFAULT); + + /* configure basic channels */ + ams_ps_write_reg(ams, AMS_REG_SEQ_CH0, + scan_mask & AMS_REG_SEQ0_MASK); + ams_ps_write_reg(ams, AMS_REG_SEQ_CH2, AMS_REG_SEQ2_MASK & + (scan_mask >> AMS_REG_SEQ2_MASK_SHIFT)); + + /* set continuous sequence mode */ + ams_ps_update_reg(ams, AMS_REG_CONFIG1, AMS_CONF1_SEQ_MASK, + AMS_CONF1_SEQ_CONTINUOUS); + } + + if (ams->pl_base) { + /* put sysmon in a soft reset to change the sequence */ + ams->pl_bus->update(ams, AMS_REG_CONFIG1, AMS_CONF1_SEQ_MAS= K, + AMS_CONF1_SEQ_DEFAULT); + + /* configure basic channels */ + scan_mask =3D (scan_mask >> PS_SEQ_MAX); + ams->pl_bus->write(ams, AMS_REG_SEQ_CH0, + scan_mask & AMS_REG_SEQ0_MASK); + ams->pl_bus->write(ams, AMS_REG_SEQ_CH2, AMS_REG_SEQ2_MASK = & + (scan_mask >> AMS_REG_SEQ2_MASK_SHIFT)); + ams->pl_bus->write(ams, AMS_REG_SEQ_CH1, AMS_REG_SEQ1_MASK = & + (scan_mask >> AMS_REG_SEQ1_MASK_SHIFT)); + + /* set continuous sequence mode */ + ams->pl_bus->update(ams, AMS_REG_CONFIG1, AMS_CONF1_SEQ_MAS= K, + AMS_CONF1_SEQ_CONTINUOUS); + } +} + +static int iio_ams_init_device(struct ams *ams) +{ + int ret =3D 0; + u32 reg; + + /* reset AMS */ + if (ams->ps_base) { + ams_ps_write_reg(ams, AMS_VP_VN, AMS_PS_RESET_VALUE); + + ret =3D readl_poll_timeout(ams->base + AMS_PS_CSTS, reg, + (reg & AMS_PS_CSTS_PS_READY) =3D= =3D + AMS_PS_CSTS_PS_READY, 0, + AMS_INIT_TIMEOUT); + if (ret) + return ret; + + /* put sysmon in a default state */ + ams_ps_update_reg(ams, AMS_REG_CONFIG1, AMS_CONF1_SEQ_MASK, + AMS_CONF1_SEQ_DEFAULT); + } + + if (ams->pl_base) { + ams->pl_bus->write(ams, AMS_VP_VN, AMS_PL_RESET_VALUE); + + ret =3D readl_poll_timeout(ams->base + AMS_PL_CSTS, reg, + (reg & AMS_PL_CSTS_ACCESS_MASK) = =3D=3D + AMS_PL_CSTS_ACCESS_MASK, 0, + AMS_INIT_TIMEOUT); + if (ret) + return ret; + + /* put sysmon in a default state */ + ams->pl_bus->update(ams, AMS_REG_CONFIG1, AMS_CONF1_SEQ_MAS= K, + AMS_CONF1_SEQ_DEFAULT); + } + + iio_ams_disable_all_alarm(ams); + + /* Disable interrupt */ + ams_update_intrmask(ams, ~0, ~0); + + /* Clear any pending interrupt */ + ams_write_reg(ams, AMS_ISR_0, AMS_ISR0_ALARM_MASK); + ams_write_reg(ams, AMS_ISR_1, AMS_ISR1_ALARM_MASK); + + return ret; +} + +static void ams_enable_single_channel(struct ams *ams, unsigned int offset= ) +{ + u8 channel_num =3D 0; + + switch (offset) { + case AMS_VCC_PSPLL0: + channel_num =3D AMS_VCC_PSPLL0_CH; + break; + case AMS_VCC_PSPLL3: + channel_num =3D AMS_VCC_PSPLL3_CH; + break; + case AMS_VCCINT: + channel_num =3D AMS_VCCINT_CH; + break; + case AMS_VCCBRAM: + channel_num =3D AMS_VCCBRAM_CH; + break; + case AMS_VCCAUX: + channel_num =3D AMS_VCCAUX_CH; + break; + case AMS_PSDDRPLL: + channel_num =3D AMS_PSDDRPLL_CH; + break; + case AMS_PSINTFPDDR: + channel_num =3D AMS_PSINTFPDDR_CH; + break; + default: + break; + } + + /* set single channel, sequencer off mode */ + ams_ps_update_reg(ams, AMS_REG_CONFIG1, AMS_CONF1_SEQ_MASK, + AMS_CONF1_SEQ_SINGLE_CHANNEL); + + /* write the channel number */ + ams_ps_update_reg(ams, AMS_REG_CONFIG0, AMS_CONF0_CHANNEL_NUM_MASK, + channel_num); + mdelay(1); +} + +static void ams_read_vcc_reg(struct ams *ams, unsigned int offset, u32 *da= ta) +{ + ams_enable_single_channel(ams, offset); + ams_read_reg(ams, offset, data); + ams_enable_channel_sequence(ams); +} + +static int ams_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val, int *val2, long mask) +{ + struct ams *ams =3D iio_priv(indio_dev); + + switch (mask) { + case IIO_CHAN_INFO_RAW: + mutex_lock(&ams->mutex); + if (chan->scan_index >=3D (PS_SEQ_MAX * 3)) + ams_read_vcc_reg(ams, chan->address, val); + else if (chan->scan_index >=3D PS_SEQ_MAX) + ams->pl_bus->read(ams, chan->address, val); + else + ams_ps_read_reg(ams, chan->address, val); + mutex_unlock(&ams->mutex); + + *val2 =3D 0; + return IIO_VAL_INT; + case IIO_CHAN_INFO_SCALE: + switch (chan->type) { + case IIO_VOLTAGE: + switch (chan->address) { + case AMS_SUPPLY1: + case AMS_SUPPLY2: + case AMS_SUPPLY3: + case AMS_SUPPLY4: + *val =3D AMS_SUPPLY_SCALE_3VOLT; + break; + case AMS_SUPPLY5: + case AMS_SUPPLY6: + if (chan->scan_index < PS_SEQ_MAX) + *val =3D AMS_SUPPLY_SCALE_6VOLT; + else + *val =3D AMS_SUPPLY_SCALE_3VOLT; + break; + case AMS_SUPPLY7: + case AMS_SUPPLY8: + *val =3D AMS_SUPPLY_SCALE_6VOLT; + break; + case AMS_SUPPLY9: + case AMS_SUPPLY10: + if (chan->scan_index < PS_SEQ_MAX) + *val =3D AMS_SUPPLY_SCALE_3VOLT; + else + *val =3D AMS_SUPPLY_SCALE_6VOLT; + break; + case AMS_VCC_PSPLL0: + case AMS_VCC_PSPLL3: + case AMS_VCCINT: + case AMS_VCCBRAM: + case AMS_VCCAUX: + case AMS_PSDDRPLL: + case AMS_PSINTFPDDR: + *val =3D AMS_SUPPLY_SCALE_3VOLT; + break; + default: + *val =3D AMS_SUPPLY_SCALE_1VOLT; + break; + } + *val2 =3D AMS_SUPPLY_SCALE_DIV_BIT; + return IIO_VAL_FRACTIONAL_LOG2; + case IIO_TEMP: + *val =3D AMS_TEMP_SCALE; + *val2 =3D AMS_TEMP_SCALE_DIV_BIT; + return IIO_VAL_FRACTIONAL_LOG2; + default: + return -EINVAL; + } + case IIO_CHAN_INFO_OFFSET: + /* Only the temperature channel has an offset */ + *val =3D AMS_TEMP_OFFSET; + *val2 =3D 0; + return IIO_VAL_INT; + } + + return -EINVAL; +} + +static int ams_get_alarm_offset(int scan_index, enum iio_event_direction d= ir) +{ + int offset =3D 0; + + if (scan_index >=3D PS_SEQ_MAX) + scan_index -=3D PS_SEQ_MAX; + + if (dir =3D=3D IIO_EV_DIR_FALLING) { + if (scan_index < AMS_SEQ_SUPPLY7) + offset =3D AMS_ALARM_THRESHOLD_OFF_10; + else + offset =3D AMS_ALARM_THRESHOLD_OFF_20; + } + + switch (scan_index) { + case AMS_SEQ_TEMP: + return (AMS_ALARM_TEMP + offset); + case AMS_SEQ_SUPPLY1: + return (AMS_ALARM_SUPPLY1 + offset); + case AMS_SEQ_SUPPLY2: + return (AMS_ALARM_SUPPLY2 + offset); + case AMS_SEQ_SUPPLY3: + return (AMS_ALARM_SUPPLY3 + offset); + case AMS_SEQ_SUPPLY4: + return (AMS_ALARM_SUPPLY4 + offset); + case AMS_SEQ_SUPPLY5: + return (AMS_ALARM_SUPPLY5 + offset); + case AMS_SEQ_SUPPLY6: + return (AMS_ALARM_SUPPLY6 + offset); + case AMS_SEQ_SUPPLY7: + return (AMS_ALARM_SUPPLY7 + offset); + case AMS_SEQ_SUPPLY8: + return (AMS_ALARM_SUPPLY8 + offset); + case AMS_SEQ_SUPPLY9: + return (AMS_ALARM_SUPPLY9 + offset); + case AMS_SEQ_SUPPLY10: + return (AMS_ALARM_SUPPLY10 + offset); + case AMS_SEQ_VCCAMS: + return (AMS_ALARM_VCCAMS + offset); + case AMS_SEQ_TEMP_REMOTE: + return (AMS_ALARM_TEMP_REMOTE + offset); + } + + return 0; +} + +static const struct iio_chan_spec *ams_event_to_channel( + struct iio_dev *indio_dev, u32 event) +{ + int scan_index =3D 0, i; + + if (event >=3D AMS_PL_ALARM_START) { + event -=3D AMS_PL_ALARM_START; + scan_index =3D PS_SEQ_MAX; + } + + switch (event) { + case AMS_ALARM_BIT_TEMP: + scan_index +=3D AMS_SEQ_TEMP; + break; + case AMS_ALARM_BIT_SUPPLY1: + scan_index +=3D AMS_SEQ_SUPPLY1; + break; + case AMS_ALARM_BIT_SUPPLY2: + scan_index +=3D AMS_SEQ_SUPPLY2; + break; + case AMS_ALARM_BIT_SUPPLY3: + scan_index +=3D AMS_SEQ_SUPPLY3; + break; + case AMS_ALARM_BIT_SUPPLY4: + scan_index +=3D AMS_SEQ_SUPPLY4; + break; + case AMS_ALARM_BIT_SUPPLY5: + scan_index +=3D AMS_SEQ_SUPPLY5; + break; + case AMS_ALARM_BIT_SUPPLY6: + scan_index +=3D AMS_SEQ_SUPPLY6; + break; + case AMS_ALARM_BIT_SUPPLY7: + scan_index +=3D AMS_SEQ_SUPPLY7; + break; + case AMS_ALARM_BIT_SUPPLY8: + scan_index +=3D AMS_SEQ_SUPPLY8; + break; + case AMS_ALARM_BIT_SUPPLY9: + scan_index +=3D AMS_SEQ_SUPPLY9; + break; + case AMS_ALARM_BIT_SUPPLY10: + scan_index +=3D AMS_SEQ_SUPPLY10; + break; + case AMS_ALARM_BIT_VCCAMS: + scan_index +=3D AMS_SEQ_VCCAMS; + break; + case AMS_ALARM_BIT_TEMP_REMOTE: + scan_index +=3D AMS_SEQ_TEMP_REMOTE; + break; + } + + for (i =3D 0; i < indio_dev->num_channels; i++) + if (indio_dev->channels[i].scan_index =3D=3D scan_index) + break; + + return &indio_dev->channels[i]; +} + +static int ams_get_alarm_mask(int scan_index) +{ + int bit =3D 0; + + if (scan_index >=3D PS_SEQ_MAX) { + bit =3D AMS_PL_ALARM_START; + scan_index -=3D PS_SEQ_MAX; + } + + switch (scan_index) { + case AMS_SEQ_TEMP: + return BIT(AMS_ALARM_BIT_TEMP + bit); + case AMS_SEQ_SUPPLY1: + return BIT(AMS_ALARM_BIT_SUPPLY1 + bit); + case AMS_SEQ_SUPPLY2: + return BIT(AMS_ALARM_BIT_SUPPLY2 + bit); + case AMS_SEQ_SUPPLY3: + return BIT(AMS_ALARM_BIT_SUPPLY3 + bit); + case AMS_SEQ_SUPPLY4: + return BIT(AMS_ALARM_BIT_SUPPLY4 + bit); + case AMS_SEQ_SUPPLY5: + return BIT(AMS_ALARM_BIT_SUPPLY5 + bit); + case AMS_SEQ_SUPPLY6: + return BIT(AMS_ALARM_BIT_SUPPLY6 + bit); + case AMS_SEQ_SUPPLY7: + return BIT(AMS_ALARM_BIT_SUPPLY7 + bit); + case AMS_SEQ_SUPPLY8: + return BIT(AMS_ALARM_BIT_SUPPLY8 + bit); + case AMS_SEQ_SUPPLY9: + return BIT(AMS_ALARM_BIT_SUPPLY9 + bit); + case AMS_SEQ_SUPPLY10: + return BIT(AMS_ALARM_BIT_SUPPLY10 + bit); + case AMS_SEQ_VCCAMS: + return BIT(AMS_ALARM_BIT_VCCAMS + bit); + case AMS_SEQ_TEMP_REMOTE: + return BIT(AMS_ALARM_BIT_TEMP_REMOTE + bit); + } + + return 0; +} + +static int ams_read_event_config(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, + enum iio_event_type type, + enum iio_event_direction dir) +{ + struct ams *ams =3D iio_priv(indio_dev); + + return (ams->alarm_mask & ams_get_alarm_mask(chan->scan_index)) ? 1= : 0; +} + +static int ams_write_event_config(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, + enum iio_event_type type, + enum iio_event_direction dir, + int state) +{ + struct ams *ams =3D iio_priv(indio_dev); + unsigned int alarm; + + alarm =3D ams_get_alarm_mask(chan->scan_index); + + mutex_lock(&ams->mutex); + + if (state) + ams->alarm_mask |=3D alarm; + else + ams->alarm_mask &=3D ~alarm; + + iio_ams_update_alarm(ams, ams->alarm_mask); + + mutex_unlock(&ams->mutex); + + return 0; +} + +static int ams_read_event_value(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, + enum iio_event_type type, + enum iio_event_direction dir, + enum iio_event_info info, int *val, int *va= l2) +{ + struct ams *ams =3D iio_priv(indio_dev); + unsigned int offset =3D ams_get_alarm_offset(chan->scan_index, dir)= ; + + mutex_lock(&ams->mutex); + + if (chan->scan_index >=3D PS_SEQ_MAX) + ams->pl_bus->read(ams, offset, val); + else + ams_ps_read_reg(ams, offset, val); + + mutex_unlock(&ams->mutex); + + *val2 =3D 0; + return IIO_VAL_INT; +} + +static int ams_write_event_value(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, + enum iio_event_type type, + enum iio_event_direction dir, + enum iio_event_info info, int val, int val= 2) +{ + struct ams *ams =3D iio_priv(indio_dev); + unsigned int offset; + + mutex_lock(&ams->mutex); + + /* Set temperature channel threshold to direct threshold */ + if (chan->type =3D=3D IIO_TEMP) { + offset =3D ams_get_alarm_offset(chan->scan_index, + IIO_EV_DIR_FALLING); + + if (chan->scan_index >=3D PS_SEQ_MAX) + ams->pl_bus->update(ams, offset, + AMS_ALARM_THR_DIRECT_MASK, + AMS_ALARM_THR_DIRECT_MASK); + else + ams_ps_update_reg(ams, offset, + AMS_ALARM_THR_DIRECT_MASK, + AMS_ALARM_THR_DIRECT_MASK); + } + + offset =3D ams_get_alarm_offset(chan->scan_index, dir); + if (chan->scan_index >=3D PS_SEQ_MAX) + ams->pl_bus->write(ams, offset, val); + else + ams_ps_write_reg(ams, offset, val); + + mutex_unlock(&ams->mutex); + + return 0; +} + +static void ams_handle_event(struct iio_dev *indio_dev, u32 event) +{ + const struct iio_chan_spec *chan; + + chan =3D ams_event_to_channel(indio_dev, event); + + if (chan->type =3D=3D IIO_TEMP) { + /* The temperature channel only supports over-temperature + * events + */ + iio_push_event(indio_dev, + IIO_UNMOD_EVENT_CODE(chan->type, chan->chann= el, + IIO_EV_TYPE_THRESH, + IIO_EV_DIR_RISING), + iio_get_time_ns(indio_dev)); + } else { + /* For other channels we don't know whether it is a upper o= r + * lower threshold event. Userspace will have to check the + * channel value if it wants to know. + */ + iio_push_event(indio_dev, + IIO_UNMOD_EVENT_CODE(chan->type, chan->chann= el, + IIO_EV_TYPE_THRESH, + IIO_EV_DIR_EITHER), + iio_get_time_ns(indio_dev)); + } +} + +static void ams_handle_events(struct iio_dev *indio_dev, unsigned long eve= nts) +{ + unsigned int bit; + + for_each_set_bit(bit, &events, AMS_NO_OF_ALARMS) + ams_handle_event(indio_dev, bit); +} + +/** + * ams_unmask_worker - ams alarm interrupt unmask worker + * @work : work to be done + * + * The ZynqMP threshold interrupts are level sensitive. Since we can't mak= e the + * threshold condition go way from within the interrupt handler, this mean= s as + * soon as a threshold condition is present we would enter the interrupt h= andler + * again and again. To work around this we mask all active thresholds inte= rrupts + * in the interrupt handler and start a timer. In this timer we poll the + * interrupt status and only if the interrupt is inactive we unmask it aga= in. + */ +static void ams_unmask_worker(struct work_struct *work) +{ + struct ams *ams =3D container_of(work, struct ams, ams_unmask_work.= work); + unsigned int status, unmask; + + spin_lock_irq(&ams->lock); + + ams_read_reg(ams, AMS_ISR_0, &status); + + /* Clear those bits which are not active anymore */ + unmask =3D (ams->masked_alarm ^ status) & ams->masked_alarm; + + /* clear status of disabled alarm */ + unmask |=3D ams->intr_mask; + + ams->masked_alarm &=3D status; + + /* Also clear those which are masked out anyway */ + ams->masked_alarm &=3D ~ams->intr_mask; + + /* Clear the interrupts before we unmask them */ + ams_write_reg(ams, AMS_ISR_0, unmask); + + ams_update_intrmask(ams, 0, 0); + + spin_unlock_irq(&ams->lock); + + /* if still pending some alarm re-trigger the timer */ + if (ams->masked_alarm) + schedule_delayed_work(&ams->ams_unmask_work, + msecs_to_jiffies(AMS_UNMASK_TIMEOUT))= ; +} + +static irqreturn_t ams_iio_irq(int irq, void *data) +{ + unsigned int isr0, isr1; + struct iio_dev *indio_dev =3D data; + struct ams *ams =3D iio_priv(indio_dev); + + spin_lock(&ams->lock); + + ams_read_reg(ams, AMS_ISR_0, &isr0); + ams_read_reg(ams, AMS_ISR_1, &isr1); + + /* only process alarm that are not masked */ + isr0 &=3D ~((ams->intr_mask & AMS_ISR0_ALARM_MASK) | ams->masked_al= arm); + isr1 &=3D ~(ams->intr_mask >> AMS_ISR1_INTR_MASK_SHIFT); + + /* clear interrupt */ + ams_write_reg(ams, AMS_ISR_0, isr0); + ams_write_reg(ams, AMS_ISR_1, isr1); + + if (isr0) { + /* Once the alarm interrupt occurred, mask until get cleare= d */ + ams->masked_alarm |=3D isr0; + ams_update_intrmask(ams, 0, 0); + + ams_handle_events(indio_dev, isr0); + + schedule_delayed_work(&ams->ams_unmask_work, + msecs_to_jiffies(AMS_UNMASK_TIMEOUT))= ; + } + + spin_unlock(&ams->lock); + + return IRQ_HANDLED; +} + +static const struct iio_event_spec ams_temp_events[] =3D { + { + .type =3D IIO_EV_TYPE_THRESH, + .dir =3D IIO_EV_DIR_RISING, + .mask_separate =3D BIT(IIO_EV_INFO_ENABLE) | + BIT(IIO_EV_INFO_VALUE), + }, +}; + +static const struct iio_event_spec ams_voltage_events[] =3D { + { + .type =3D IIO_EV_TYPE_THRESH, + .dir =3D IIO_EV_DIR_RISING, + .mask_separate =3D BIT(IIO_EV_INFO_VALUE), + }, { + .type =3D IIO_EV_TYPE_THRESH, + .dir =3D IIO_EV_DIR_FALLING, + .mask_separate =3D BIT(IIO_EV_INFO_VALUE), + }, { + .type =3D IIO_EV_TYPE_THRESH, + .dir =3D IIO_EV_DIR_EITHER, + .mask_separate =3D BIT(IIO_EV_INFO_ENABLE), + }, +}; + +static const struct iio_chan_spec ams_ps_channels[] =3D { + AMS_PS_CHAN_TEMP(AMS_SEQ_TEMP, AMS_TEMP, "ps_temp"), + AMS_PS_CHAN_TEMP(AMS_SEQ_TEMP_REMOTE, AMS_TEMP_REMOTE, "remote_temp= "), + AMS_PS_CHAN_VOLTAGE(AMS_SEQ_SUPPLY1, AMS_SUPPLY1, "vccpsintlp"), + AMS_PS_CHAN_VOLTAGE(AMS_SEQ_SUPPLY2, AMS_SUPPLY2, "vccpsintfp"), + AMS_PS_CHAN_VOLTAGE(AMS_SEQ_SUPPLY3, AMS_SUPPLY3, "vccpsaux"), + AMS_PS_CHAN_VOLTAGE(AMS_SEQ_SUPPLY4, AMS_SUPPLY4, "vccpsddr"), + AMS_PS_CHAN_VOLTAGE(AMS_SEQ_SUPPLY5, AMS_SUPPLY5, "vccpsio3"), + AMS_PS_CHAN_VOLTAGE(AMS_SEQ_SUPPLY6, AMS_SUPPLY6, "vccpsio0"), + AMS_PS_CHAN_VOLTAGE(AMS_SEQ_SUPPLY7, AMS_SUPPLY7, "vccpsio1"), + AMS_PS_CHAN_VOLTAGE(AMS_SEQ_SUPPLY8, AMS_SUPPLY8, "vccpsio2"), + AMS_PS_CHAN_VOLTAGE(AMS_SEQ_SUPPLY9, AMS_SUPPLY9, "psmgtravcc"), + AMS_PS_CHAN_VOLTAGE(AMS_SEQ_SUPPLY10, AMS_SUPPLY10, "psmgtravtt"), + AMS_PS_CHAN_VOLTAGE(AMS_SEQ_VCCAMS, AMS_VCCAMS, "vccams"), +}; + +static const struct iio_chan_spec ams_pl_channels[] =3D { + AMS_PL_CHAN_TEMP(AMS_SEQ_TEMP, AMS_TEMP, "pl_temp"), + AMS_PL_CHAN_VOLTAGE(AMS_SEQ_SUPPLY1, AMS_SUPPLY1, "vccint", true), + AMS_PL_CHAN_VOLTAGE(AMS_SEQ_SUPPLY2, AMS_SUPPLY2, "vccaux", true), + AMS_PL_CHAN_VOLTAGE(AMS_SEQ_VREFP, AMS_VREFP, "vccvrefp", false), + AMS_PL_CHAN_VOLTAGE(AMS_SEQ_VREFN, AMS_VREFN, "vccvrefn", false), + AMS_PL_CHAN_VOLTAGE(AMS_SEQ_SUPPLY3, AMS_SUPPLY3, "vccbram", true), + AMS_PL_CHAN_VOLTAGE(AMS_SEQ_SUPPLY4, AMS_SUPPLY4, "vccplintlp", tru= e), + AMS_PL_CHAN_VOLTAGE(AMS_SEQ_SUPPLY5, AMS_SUPPLY5, "vccplintfp", tru= e), + AMS_PL_CHAN_VOLTAGE(AMS_SEQ_SUPPLY6, AMS_SUPPLY6, "vccplaux", true)= , + AMS_PL_CHAN_VOLTAGE(AMS_SEQ_VCCAMS, AMS_VCCAMS, "vccams", true), + AMS_PL_CHAN_VOLTAGE(AMS_SEQ_VP_VN, AMS_VP_VN, "vccvpvn", false), + AMS_PL_CHAN_VOLTAGE(AMS_SEQ_SUPPLY7, AMS_SUPPLY7, "vuser0", true), + AMS_PL_CHAN_VOLTAGE(AMS_SEQ_SUPPLY8, AMS_SUPPLY8, "vuser1", true), + AMS_PL_CHAN_VOLTAGE(AMS_SEQ_SUPPLY9, AMS_SUPPLY9, "vuser2", true), + AMS_PL_CHAN_VOLTAGE(AMS_SEQ_SUPPLY10, AMS_SUPPLY10, "vuser3", true)= , + AMS_PL_AUX_CHAN_VOLTAGE(0, "vccaux0"), + AMS_PL_AUX_CHAN_VOLTAGE(1, "vccaux1"), + AMS_PL_AUX_CHAN_VOLTAGE(2, "vccaux2"), + AMS_PL_AUX_CHAN_VOLTAGE(3, "vccaux3"), + AMS_PL_AUX_CHAN_VOLTAGE(4, "vccaux4"), + AMS_PL_AUX_CHAN_VOLTAGE(5, "vccaux5"), + AMS_PL_AUX_CHAN_VOLTAGE(6, "vccaux6"), + AMS_PL_AUX_CHAN_VOLTAGE(7, "vccaux7"), + AMS_PL_AUX_CHAN_VOLTAGE(8, "vccaux8"), + AMS_PL_AUX_CHAN_VOLTAGE(9, "vccaux9"), + AMS_PL_AUX_CHAN_VOLTAGE(10, "vccaux10"), + AMS_PL_AUX_CHAN_VOLTAGE(11, "vccaux11"), + AMS_PL_AUX_CHAN_VOLTAGE(12, "vccaux12"), + AMS_PL_AUX_CHAN_VOLTAGE(13, "vccaux13"), + AMS_PL_AUX_CHAN_VOLTAGE(14, "vccaux14"), + AMS_PL_AUX_CHAN_VOLTAGE(15, "vccaux15"), +}; + +static const struct iio_chan_spec ams_ctrl_channels[] =3D { + AMS_CTRL_CHAN_VOLTAGE(AMS_SEQ_VCC_PSPLL, AMS_VCC_PSPLL0, "vcc_pspll= 0"), + AMS_CTRL_CHAN_VOLTAGE(AMS_SEQ_VCC_PSBATT, AMS_VCC_PSPLL3, "vcc_psba= tt"), + AMS_CTRL_CHAN_VOLTAGE(AMS_SEQ_VCCINT, AMS_VCCINT, "vccint"), + AMS_CTRL_CHAN_VOLTAGE(AMS_SEQ_VCCBRAM, AMS_VCCBRAM, "vccbram"), + AMS_CTRL_CHAN_VOLTAGE(AMS_SEQ_VCCAUX, AMS_VCCAUX, "vccaux"), + AMS_CTRL_CHAN_VOLTAGE(AMS_SEQ_PSDDRPLL, AMS_PSDDRPLL, "vcc_psddrpll= "), + AMS_CTRL_CHAN_VOLTAGE(AMS_SEQ_INTDDR, AMS_PSINTFPDDR, "vccpsintfpdd= r"), +}; + +static int ams_init_module(struct iio_dev *indio_dev, struct device_node *= np, + struct iio_chan_spec *channels) +{ + struct ams *ams =3D iio_priv(indio_dev); + struct device_node *chan_node, *child; + int ret, num_channels =3D 0; + unsigned int reg; + + if (of_device_is_compatible(np, "xlnx,zynqmp-ams-ps")) { + ams->ps_base =3D of_iomap(np, 0); + if (!ams->ps_base) + return -ENXIO; + + /* add PS channels to iio device channels */ + memcpy(channels + num_channels, ams_ps_channels, + sizeof(ams_ps_channels)); + num_channels +=3D ARRAY_SIZE(ams_ps_channels); + } else if (of_device_is_compatible(np, "xlnx,zynqmp-ams-pl")) { + ams->pl_base =3D of_iomap(np, 0); + if (!ams->pl_base) + return -ENXIO; + + /* Copy only first 10 fix channels */ + memcpy(channels + num_channels, ams_pl_channels, + AMS_PL_MAX_FIXED_CHANNEL * sizeof(*channels)); + num_channels +=3D AMS_PL_MAX_FIXED_CHANNEL; + + chan_node =3D of_get_child_by_name(np, "xlnx,ext-channels")= ; + if (chan_node) { + for_each_child_of_node(chan_node, child) { + ret =3D of_property_read_u32(child, "reg", = ®); + if (ret || reg > AMS_PL_MAX_EXT_CHANNEL) + continue; + + memcpy(&channels[num_channels], + &ams_pl_channels[reg + + AMS_PL_MAX_FIXED_CHANNEL], + sizeof(*channels)); + + if (of_property_read_bool(child, + "xlnx,bipolar")) + channels[num_channels].scan_type.si= gn =3D + 's'; + + num_channels +=3D 1; + } + } + of_node_put(chan_node); + } else if (of_device_is_compatible(np, "xlnx,zynqmp-ams")) { + /* add AMS channels to iio device channels */ + memcpy(channels + num_channels, ams_ctrl_channels, + sizeof(ams_ctrl_channels)); + num_channels +=3D ARRAY_SIZE(ams_ctrl_channels); + } else { + return -EINVAL; + } + + return num_channels; +} + +static int ams_parse_dt(struct iio_dev *indio_dev, struct platform_device = *pdev) +{ + struct ams *ams =3D iio_priv(indio_dev); + struct iio_chan_spec *ams_channels, *dev_channels; + struct device_node *child_node =3D NULL, *np =3D pdev->dev.of_node; + int ret, chan_vol =3D 0, chan_temp =3D 0, i, rising_off, falling_of= f; + unsigned int num_channels =3D 0; + + /* Initialize buffer for channel specification */ + ams_channels =3D kzalloc(sizeof(ams_ps_channels) + + sizeof(ams_pl_channels) + + sizeof(ams_ctrl_channels), GFP_KERNEL); + if (!ams_channels) + return -ENOMEM; + + if (of_device_is_available(np)) { + ret =3D ams_init_module(indio_dev, np, ams_channels); + if (ret < 0) { + kfree(ams_channels); + return ret; + } + + num_channels +=3D ret; + } + + for_each_child_of_node(np, child_node) { + if (of_device_is_available(child_node)) { + ret =3D ams_init_module(indio_dev, child_node, + ams_channels + num_channels); + if (ret < 0) { + kfree(ams_channels); + return ret; + } + + num_channels +=3D ret; + } + } + + for (i =3D 0; i < num_channels; i++) { + if (ams_channels[i].type =3D=3D IIO_VOLTAGE) + ams_channels[i].channel =3D chan_vol++; + else + ams_channels[i].channel =3D chan_temp++; + + if (ams_channels[i].scan_index < (PS_SEQ_MAX * 3)) { + /* set threshold to max and min for each channel */ + falling_off =3D ams_get_alarm_offset( + ams_channels[i].scan_index, + IIO_EV_DIR_FALLING); + rising_off =3D ams_get_alarm_offset( + ams_channels[i].scan_index, + IIO_EV_DIR_RISING); + if (ams_channels[i].scan_index >=3D PS_SEQ_MAX) { + ams->pl_bus->write(ams, falling_off, + AMS_ALARM_THR_MIN); + ams->pl_bus->write(ams, rising_off, + AMS_ALARM_THR_MAX); + } else { + ams_ps_write_reg(ams, falling_off, + AMS_ALARM_THR_MIN); + ams_ps_write_reg(ams, rising_off, + AMS_ALARM_THR_MAX); + } + } + } + + dev_channels =3D devm_kzalloc(&pdev->dev, sizeof(*dev_channels) * + num_channels, GFP_KERNEL); + if (!dev_channels) { + kfree(ams_channels); + return -ENOMEM; + } + + memcpy(dev_channels, ams_channels, + sizeof(*ams_channels) * num_channels); + kfree(ams_channels); + indio_dev->channels =3D dev_channels; + indio_dev->num_channels =3D num_channels; + + return 0; +} + +static const struct iio_info iio_pl_info =3D { + .read_raw =3D &ams_read_raw, + .read_event_config =3D &ams_read_event_config, + .write_event_config =3D &ams_write_event_config, + .read_event_value =3D &ams_read_event_value, + .write_event_value =3D &ams_write_event_value, +}; + +static const struct ams_pl_bus_ops ams_pl_apb =3D { + .read =3D ams_apb_pl_read_reg, + .write =3D ams_apb_pl_write_reg, + .update =3D ams_apb_pl_update_reg, +}; + +static const struct of_device_id ams_of_match_table[] =3D { + { .compatible =3D "xlnx,zynqmp-ams", &ams_pl_apb }, + { } +}; +MODULE_DEVICE_TABLE(of, ams_of_match_table); + +static int ams_probe(struct platform_device *pdev) +{ + struct iio_dev *indio_dev; + struct ams *ams; + struct resource *res; + const struct of_device_id *id; + int ret; + + if (!pdev->dev.of_node) + return -ENODEV; + + id =3D of_match_node(ams_of_match_table, pdev->dev.of_node); + if (!id) + return -ENODEV; + + indio_dev =3D devm_iio_device_alloc(&pdev->dev, sizeof(*ams)); + if (!indio_dev) + return -ENOMEM; + + ams =3D iio_priv(indio_dev); + ams->pl_bus =3D id->data; + mutex_init(&ams->mutex); + spin_lock_init(&ams->lock); + + indio_dev->dev.parent =3D &pdev->dev; + indio_dev->dev.of_node =3D pdev->dev.of_node; + indio_dev->name =3D "ams"; + + indio_dev->info =3D &iio_pl_info; + indio_dev->modes =3D INDIO_DIRECT_MODE; + + res =3D platform_get_resource_byname(pdev, IORESOURCE_MEM, "ams-bas= e"); + ams->base =3D devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(ams->base)) + return PTR_ERR(ams->base); + + INIT_DELAYED_WORK(&ams->ams_unmask_work, ams_unmask_worker); + + ams->clk =3D devm_clk_get(&pdev->dev, NULL); + if (IS_ERR(ams->clk)) + return PTR_ERR(ams->clk); + clk_prepare_enable(ams->clk); + + ret =3D iio_ams_init_device(ams); + if (ret) { + dev_err(&pdev->dev, "failed to initialize AMS\n"); + goto clk_disable; + } + + ret =3D ams_parse_dt(indio_dev, pdev); + if (ret) { + dev_err(&pdev->dev, "failure in parsing DT\n"); + goto clk_disable; + } + + ams_enable_channel_sequence(ams); + + ams->irq =3D platform_get_irq_byname(pdev, "ams-irq"); + ret =3D devm_request_irq(&pdev->dev, ams->irq, &ams_iio_irq, 0, "am= s-irq", + indio_dev); + if (ret < 0) { + dev_err(&pdev->dev, "failed to register interrupt\n"); + goto clk_disable; + } + + platform_set_drvdata(pdev, indio_dev); + + return iio_device_register(indio_dev); + +clk_disable: + clk_disable_unprepare(ams->clk); + return ret; +} + +static int ams_remove(struct platform_device *pdev) +{ + struct iio_dev *indio_dev =3D platform_get_drvdata(pdev); + struct ams *ams =3D iio_priv(indio_dev); + + cancel_delayed_work(&ams->ams_unmask_work); + + /* Unregister the device */ + iio_device_unregister(indio_dev); + clk_disable_unprepare(ams->clk); + return 0; +} + +static int __maybe_unused ams_suspend(struct device *dev) +{ + struct iio_dev *indio_dev =3D dev_get_drvdata(dev); + struct ams *ams =3D iio_priv(indio_dev); + + clk_disable_unprepare(ams->clk); + + return 0; +} + +static int __maybe_unused ams_resume(struct device *dev) +{ + struct iio_dev *indio_dev =3D dev_get_drvdata(dev); + struct ams *ams =3D iio_priv(indio_dev); + + clk_prepare_enable(ams->clk); + return 0; +} + +static SIMPLE_DEV_PM_OPS(ams_pm_ops, ams_suspend, ams_resume); + +static struct platform_driver ams_driver =3D { + .probe =3D ams_probe, + .remove =3D ams_remove, + .driver =3D { + .name =3D "ams", + .pm =3D &ams_pm_ops, + .of_match_table =3D ams_of_match_table, + }, +}; +module_platform_driver(ams_driver); + +MODULE_LICENSE("GPL v2"); +MODULE_AUTHOR("Rajnikant Bhojani "); diff --git a/drivers/iio/adc/xilinx-ams.h b/drivers/iio/adc/xilinx-ams.h new file mode 100644 index 0000000..41d1dbc --- /dev/null +++ b/drivers/iio/adc/xilinx-ams.h @@ -0,0 +1,278 @@ +#ifndef __XILINX_AMS_H__ +#define __XILINX_AMS_H__ + +#define AMS_MISC_CTRL 0x000 +#define AMS_ISR_0 0x010 +#define AMS_ISR_1 0x014 +#define AMS_IMR_0 0x018 +#define AMS_IMR_1 0x01c +#define AMS_IER_0 0x020 +#define AMS_IER_1 0x024 +#define AMS_IDR_0 0x028 +#define AMS_IDR_1 0x02c +#define AMS_PS_CSTS 0x040 +#define AMS_PL_CSTS 0x044 +#define AMS_MON_CSTS 0x050 + +#define AMS_VCC_PSPLL0 0x060 +#define AMS_VCC_PSPLL3 0x06C +#define AMS_VCCINT 0x078 +#define AMS_VCCBRAM 0x07C +#define AMS_VCCAUX 0x080 +#define AMS_PSDDRPLL 0x084 +#define AMS_PSINTFPDDR 0x09C + +#define AMS_VCC_PSPLL0_CH 48 +#define AMS_VCC_PSPLL3_CH 51 +#define AMS_VCCINT_CH 54 +#define AMS_VCCBRAM_CH 55 +#define AMS_VCCAUX_CH 56 +#define AMS_PSDDRPLL_CH 57 +#define AMS_PSINTFPDDR_CH 63 + +#define AMS_REG_CONFIG0 0x100 +#define AMS_REG_CONFIG1 0x104 +#define AMS_REG_CONFIG2 0x108 +#define AMS_REG_CONFIG3 0x10C +#define AMS_REG_CONFIG4 0x110 +#define AMS_REG_SEQ_CH0 0x120 +#define AMS_REG_SEQ_CH1 0x124 +#define AMS_REG_SEQ_CH2 0x118 + +#define AMS_TEMP 0x000 +#define AMS_SUPPLY1 0x004 +#define AMS_SUPPLY2 0x008 +#define AMS_VP_VN 0x00c +#define AMS_VREFP 0x010 +#define AMS_VREFN 0x014 +#define AMS_SUPPLY3 0x018 +#define AMS_SUPPLY4 0x034 +#define AMS_SUPPLY5 0x038 +#define AMS_SUPPLY6 0x03c +#define AMS_SUPPLY7 0x200 +#define AMS_SUPPLY8 0x204 +#define AMS_SUPPLY9 0x208 +#define AMS_SUPPLY10 0x20c +#define AMS_VCCAMS 0x210 +#define AMS_TEMP_REMOTE 0x214 + +#define AMS_REG_VAUX(x) (0x40 + (4*(x))) +#define AMS_REG_VUSER(x) (0x200 + (4*(x))) + +#define AMS_PS_RESET_VALUE 0xFFFFU +#define AMS_PL_RESET_VALUE 0xFFFFU + +#define AMS_CONF0_CHANNEL_NUM_MASK (0x3f << 0) + +#define AMS_CONF1_SEQ_MASK (0xf << 12) +#define AMS_CONF1_SEQ_DEFAULT (0 << 12) +#define AMS_CONF1_SEQ_SINGLE_PASS (1 << 12) +#define AMS_CONF1_SEQ_CONTINUOUS (2 << 12) +#define AMS_CONF1_SEQ_SINGLE_CHANNEL (3 << 12) + +#define AMS_REG_SEQ0_MASK 0xFFFF +#define AMS_REG_SEQ2_MASK 0x3F +#define AMS_REG_SEQ1_MASK 0xFFFF +#define AMS_REG_SEQ2_MASK_SHIFT 16 +#define AMS_REG_SEQ1_MASK_SHIFT 22 + +#define AMS_REGCFG1_ALARM_MASK 0xF0F +#define AMS_REGCFG3_ALARM_MASK 0x3F + +#define AMS_ALARM_TEMP 0x140 +#define AMS_ALARM_SUPPLY1 0x144 +#define AMS_ALARM_SUPPLY2 0x148 +#define AMS_ALARM_OT 0x14c + +#define AMS_ALARM_SUPPLY3 0x160 +#define AMS_ALARM_SUPPLY4 0x164 +#define AMS_ALARM_SUPPLY5 0x168 +#define AMS_ALARM_SUPPLY6 0x16c +#define AMS_ALARM_SUPPLY7 0x180 +#define AMS_ALARM_SUPPLY8 0x184 +#define AMS_ALARM_SUPPLY9 0x188 +#define AMS_ALARM_SUPPLY10 0x18c +#define AMS_ALARM_VCCAMS 0x190 +#define AMS_ALARM_TEMP_REMOTE 0x194 +#define AMS_ALARM_THRESHOLD_OFF_10 0x10 +#define AMS_ALARM_THRESHOLD_OFF_20 0x20 + +#define AMS_ALARM_THR_DIRECT_MASK 0x01 +#define AMS_ALARM_THR_MIN 0x0000 +#define AMS_ALARM_THR_MAX 0xffff + +#define AMS_NO_OF_ALARMS 32 +#define AMS_PL_ALARM_START 16 +#define AMS_ISR0_ALARM_MASK 0xFFFFFFFFU +#define AMS_ISR1_ALARM_MASK 0xE000001FU +#define AMS_ISR1_INTR_MASK_SHIFT 32 +#define AMS_ISR0_ALARM_2_TO_0_MASK 0x07 +#define AMS_ISR0_ALARM_6_TO_3_MASK 0x78 +#define AMS_ISR0_ALARM_12_TO_7_MASK 0x3F +#define AMS_CONF1_ALARM_2_TO_0_SHIFT 1 +#define AMS_CONF1_ALARM_6_TO_3_SHIFT 5 +#define AMS_CONF3_ALARM_12_TO_7_SHIFT 8 + +#define AMS_PS_CSTS_PS_READY 0x08010000U +#define AMS_PL_CSTS_ACCESS_MASK 0x00000001U + +#define AMS_PL_MAX_FIXED_CHANNEL 10 +#define AMS_PL_MAX_EXT_CHANNEL 20 + +#define AMS_INIT_TIMEOUT 10000 + +/* Following scale and offset value is derivef from + * UG580 (v1.7) December 20, 2016 + */ +#define AMS_SUPPLY_SCALE_1VOLT 1000 +#define AMS_SUPPLY_SCALE_3VOLT 3000 +#define AMS_SUPPLY_SCALE_6VOLT 6000 +#define AMS_SUPPLY_SCALE_DIV_BIT 16 + +#define AMS_TEMP_SCALE 509314 +#define AMS_TEMP_SCALE_DIV_BIT 16 +#define AMS_TEMP_OFFSET -((280230L << 16) / 509314) + +enum ams_alarm_bit { + AMS_ALARM_BIT_TEMP, + AMS_ALARM_BIT_SUPPLY1, + AMS_ALARM_BIT_SUPPLY2, + AMS_ALARM_BIT_SUPPLY3, + AMS_ALARM_BIT_SUPPLY4, + AMS_ALARM_BIT_SUPPLY5, + AMS_ALARM_BIT_SUPPLY6, + AMS_ALARM_BIT_RESERVED, + AMS_ALARM_BIT_SUPPLY7, + AMS_ALARM_BIT_SUPPLY8, + AMS_ALARM_BIT_SUPPLY9, + AMS_ALARM_BIT_SUPPLY10, + AMS_ALARM_BIT_VCCAMS, + AMS_ALARM_BIT_TEMP_REMOTE +}; + +enum ams_seq { + AMS_SEQ_VCC_PSPLL, + AMS_SEQ_VCC_PSBATT, + AMS_SEQ_VCCINT, + AMS_SEQ_VCCBRAM, + AMS_SEQ_VCCAUX, + AMS_SEQ_PSDDRPLL, + AMS_SEQ_INTDDR +}; + +enum ams_ps_pl_seq { + AMS_SEQ_CALIB, + AMS_SEQ_RSVD_1, + AMS_SEQ_RSVD_2, + AMS_SEQ_TEST, + AMS_SEQ_RSVD_4, + AMS_SEQ_SUPPLY4, + AMS_SEQ_SUPPLY5, + AMS_SEQ_SUPPLY6, + AMS_SEQ_TEMP, + AMS_SEQ_SUPPLY2, + AMS_SEQ_SUPPLY1, + AMS_SEQ_VP_VN, + AMS_SEQ_VREFP, + AMS_SEQ_VREFN, + AMS_SEQ_SUPPLY3, + AMS_SEQ_CURRENT_MON, + AMS_SEQ_SUPPLY7, + AMS_SEQ_SUPPLY8, + AMS_SEQ_SUPPLY9, + AMS_SEQ_SUPPLY10, + AMS_SEQ_VCCAMS, + AMS_SEQ_TEMP_REMOTE, + AMS_SEQ_MAX +}; + +#define AMS_SEQ(x) (AMS_SEQ_MAX + (x)) +#define AMS_VAUX_SEQ(x) (AMS_SEQ_MAX + (x)) + +#define PS_SEQ_MAX AMS_SEQ_MAX +#define PS_SEQ(x) (x) +#define PL_SEQ(x) (PS_SEQ_MAX + x) + +#define AMS_CHAN_TEMP(_scan_index, _addr, _ext) { \ + .type =3D IIO_TEMP, \ + .indexed =3D 1, \ + .address =3D (_addr), \ + .info_mask_separate =3D BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_SCALE) | \ + BIT(IIO_CHAN_INFO_OFFSET), \ + .info_mask_shared_by_all =3D BIT(IIO_CHAN_INFO_SAMP_FREQ), \ + .event_spec =3D ams_temp_events, \ + .num_event_specs =3D ARRAY_SIZE(ams_temp_events), \ + .scan_index =3D (_scan_index), \ + .scan_type =3D { \ + .sign =3D 'u', \ + .realbits =3D 12, \ + .storagebits =3D 16, \ + .shift =3D 4, \ + .endianness =3D IIO_CPU, \ + }, \ + .extend_name =3D _ext, \ +} + +#define AMS_CHAN_VOLTAGE(_scan_index, _addr, _ext, _alarm) { \ + .type =3D IIO_VOLTAGE, \ + .indexed =3D 1, \ + .address =3D (_addr), \ + .info_mask_separate =3D BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_SCALE), \ + .info_mask_shared_by_all =3D BIT(IIO_CHAN_INFO_SAMP_FREQ), \ + .event_spec =3D (_alarm) ? ams_voltage_events : NULL, \ + .num_event_specs =3D (_alarm) ? ARRAY_SIZE(ams_voltage_events) : 0,= \ + .scan_index =3D (_scan_index), \ + .scan_type =3D { \ + .realbits =3D 10, \ + .storagebits =3D 16, \ + .shift =3D 6, \ + .endianness =3D IIO_CPU, \ + }, \ + .extend_name =3D _ext, \ +} + +#define AMS_PS_CHAN_TEMP(_scan_index, _addr, _ext) \ + AMS_CHAN_TEMP(PS_SEQ(_scan_index), _addr, _ext) +#define AMS_PS_CHAN_VOLTAGE(_scan_index, _addr, _ext) \ + AMS_CHAN_VOLTAGE(PS_SEQ(_scan_index), _addr, _ext, true) + +#define AMS_PL_CHAN_TEMP(_scan_index, _addr, _ext) \ + AMS_CHAN_TEMP(PL_SEQ(_scan_index), _addr, _ext) +#define AMS_PL_CHAN_VOLTAGE(_scan_index, _addr, _ext, _alarm) \ + AMS_CHAN_VOLTAGE(PL_SEQ(_scan_index), _addr, _ext, _alarm) +#define AMS_PL_AUX_CHAN_VOLTAGE(_auxno, _ext) \ + AMS_CHAN_VOLTAGE(PL_SEQ(AMS_VAUX_SEQ(_auxno)), \ + AMS_REG_VAUX(_auxno), _ext, false) +#define AMS_CTRL_CHAN_VOLTAGE(_scan_index, _addr, _ext) \ + AMS_CHAN_VOLTAGE(PL_SEQ(AMS_VAUX_SEQ(AMS_SEQ(_scan_index))), \ + _addr, _ext, false) + +struct ams { + void __iomem *base; + void __iomem *ps_base; + void __iomem *pl_base; + struct clk *clk; + struct device *dev; + + struct mutex mutex; + spinlock_t lock; + + unsigned int alarm_mask; + unsigned int masked_alarm; + u64 intr_mask; + int irq; + + struct delayed_work ams_unmask_work; + const struct ams_pl_bus_ops *pl_bus; +}; + +struct ams_pl_bus_ops { + void (*read)(struct ams *ams, unsigned int offset, unsigned int *da= ta); + void (*write)(struct ams *ams, unsigned int offset, unsigned int da= ta); + void (*update)(struct ams *ams, unsigned int offset, u32 mask, + u32 data); +}; + +#endif /* __XILINX_AMS_H__ */ -- 2.7.4 This email and any attachments are intended for the sole use of the named r= ecipient(s) and contain(s) confidential information that may be proprietary= , privileged or copyrighted under applicable law. If you are not the intend= ed recipient, do not read, copy, or forward this email message or any attac= hments. Delete this email message and any attachments immediately.