Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752490AbbGQQLt (ORCPT ); Fri, 17 Jul 2015 12:11:49 -0400 Received: from mail-bl2on0066.outbound.protection.outlook.com ([65.55.169.66]:16640 "EHLO na01-bl2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752420AbbGQQLo (ORCPT ); Fri, 17 Jul 2015 12:11:44 -0400 Authentication-Results: spf=fail (sender IP is 66.35.236.227) smtp.mailfrom=opensource.altera.com; vger.kernel.org; dkim=none (message not signed) header.d=none; Authentication-Results: linuxfoundation.org; dkim=none (message not signed) header.d=none; From: To: , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Petr Cvek , , , , Alan Tull Subject: [PATCH v9 6/7] staging: add simple-fpga-bus Date: Fri, 17 Jul 2015 10:51:16 -0500 Message-ID: <1437148277-5405-7-git-send-email-atull@opensource.altera.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1437148277-5405-1-git-send-email-atull@opensource.altera.com> References: <1437148277-5405-1-git-send-email-atull@opensource.altera.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [64.129.157.38] X-ClientProxiedBy: DM2PR21CA0039.namprd21.prod.outlook.com (25.161.137.177) To CY1PR03MB1519.namprd03.prod.outlook.com (25.163.17.25) X-Microsoft-Exchange-Diagnostics-untrusted: 1;CY1PR03MB1519;2:RceUdjdYfZi+jSFptNqG5AjgKrEtzPsPc05gw51B3YfUuaAlF09+o06RBCfrw6tc;3:5GVc+tpPo8Dujr0loPy43Vx4FPSGmurqL0J40ciZ7PEr6m3i+/23j4UVWStZBHskhBURkjpZqilz2tIooA7tUaL9W8gxNyYwie5Hock5+aiEcA7mzNH/BBlnooNajvxpw/WoJK/pExVciWh/Y5fjmw==;25:F7LvJ1y3FL5CuC3G7i2c+UZF/JLVnUZAVqy7l2FAJX9cWMTFF/OirhVgYArNNTd4E/gxtqyVhdGES1cAnyddWFr0xlKpC3QjVdrv/BH8AW1V/9tvj+qoc+D5Z1g7hH8UpKIKGrjQRvJ1hnLzwRRo5o4kZE6h7FoFU9APsBLp1vZLi8j1n3ESeEDLMMhBPiLLNjiRepsx1oJDX0YBByUZMDxL8A+PyOPtcpJjTQNCYKZkzK2NJLuihj8ro4BaQcFw;20:umYwlcCiA01QDKnzs7OHfc6XgFihRW9UfNhw6Cv2RAeC81UUnancnK0k4z9KaRitwNB76DZMNQgioqxUZJV3yAFpcpo6O4egoc5bfIURowaK81Q2TesW+bCKTQdczcDNSFZoVftt9OqeSmk5QaQPVcxWxEIAE/wMbh5TKv3hnWw=;4:2gvf5syBMvuDF1kUXp/m7su3E1O9OLLprFDkOdHRO5QdapRJ9aiY4HBIbFOFoUCBc1Jq4Ig9bo5cxqKxCGMogGXC9S9GOq45SYXy5EY9xDJskZEsbEREk+A1umPWI82DTGHXecY7Q0UC8R2Qo3Tqg+jGcyBQfxPLD5pcBSkvx4b2ZTENAagW4HRyulvYYI8yNuqSeYPDqaBMkCQYDYmIk57TdY++xE0TTnM/jDRTxDqSiaQvuLKvqGqgvA3/J4XERtamnB0U9V8EK7giw851oQtN1rpdgRueGFuAJndohaE= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:CY1PR03MB1519;UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BL2PR03MB291; CY1PR03MB1519: X-MS-Exchange-Organization-RulesExecuted X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:;UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(5005006)(3002001);SRVR:CY1PR03MB1519;BCL:0;PCL:0;RULEID:;SRVR:CY1PR03MB1519;BCL:0;PCL:0;RULEID:(601004)(5005006)(3002001);SRVR:BL2PR03MB291;BCL:0;PCL:0;RULEID:;SRVR:BL2PR03MB291; X-Forefront-PRVS: 06400060E1 X-Forefront-Antispam-Report-Untrusted: SFV:NSPM;SFS:(10009020)(6009001)(42186005)(19580405001)(19580395003)(229853001)(53416004)(46102003)(87976001)(122386002)(2201001)(230783001)(86362001)(86152002)(33646002)(62966003)(50466002)(77156002)(92566002)(15975445007)(5001960100002)(2950100001)(48376002)(50226001)(107886002)(77096005)(5001770100001)(76176999)(47776003)(50986999)(5001920100001)(5003940100001)(189998001)(7059030)(4001430100001)(2101003);DIR:OUT;SFP:1101;SCL:1;SRVR:CY1PR03MB1519;H:linuxheads99.altera.com;FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft-Exchange-Diagnostics-untrusted: =?us-ascii?Q?1;CY1PR03MB1519;23:6cK4Mw7FN7hbey0rq53BShqVeP7/KdVhxwNwZwmql?= =?us-ascii?Q?9D99u2MT0PtN9QasSSbulIFxFVUzW5VXyFew8GBCXh6H/7RHlCbAx/EaQF6c?= =?us-ascii?Q?yaSe4Nyn1aSa9xrL4BiV0pIqykWcxhXoBuKctT5VtWuf8Kk5gVekg7JdNs+l?= =?us-ascii?Q?8M+ER/Q0FcRolaVDB4qvfziIwvWEHhLwUhyLAiqX7dvDo23sOC929rA3E5vO?= =?us-ascii?Q?fBts0SmOl1HyjnKe5+CKfQ1f4f1DeTz+lUZOfh1QXdvwesQzNHD8sJXcVDhv?= =?us-ascii?Q?iG5t6Ys2DLf3tCWfr397vmHpTBhbHrMVgfEfuEG10yo6Uu6IBcGyAsf8lLXv?= =?us-ascii?Q?CUO6utau8KBP4sxR4hVSIXqm87KVaSjq2ib+MnapqK0gxpCJ0IXkKhrYUmtz?= =?us-ascii?Q?FamFEq6D6OV/FuCDpSMbd85F2ZkJCo81Fm/uAcyzLJtth2Lyxk/fh+jDfk3G?= =?us-ascii?Q?KHzyMQYDUR0/fByJpq3IDJ7PH5KgH1tpBTo7SBbFts7KENxGyqxd1i+i7EcM?= =?us-ascii?Q?baYLFKlsSMy33iiBDmzUNij3Mv35W2ZPaEqDuR/C6fWL3yVtjSvM1+pu5FiF?= =?us-ascii?Q?xrlGVKvK5o8ybZjN0U6YS2np1UGnpDKR90mrwdm9WtV5SYLTemv6WAslMc9r?= =?us-ascii?Q?zMF/Ob8jkIUFGv19CcQiFlIYkX/wfic3+dXHr8To3Mw+Kbx2pwGzlWvAzlPb?= =?us-ascii?Q?Rfv8RyS2Tz1sT7Zk5FyIAqBEEfBxQiQMHWuZFClvzIJqg4mnryvMHsmFDKXO?= =?us-ascii?Q?LY1Nbz5uLTDNGbwrEHRkc3VH8RoHEJhE2CGdA3vt0rCcW6Me4ik3jOEPaq70?= =?us-ascii?Q?1/uFdYpZnubA+IZCLDJaerHbvoYl0dnPSVUWOrJvcwdji5CKrdYNC6Lihy+z?= =?us-ascii?Q?DkgUzMJN/D0egN2QhIvITZOXPs6Bhnbcskn+2CvvS3q7peNa7bL5TSe/qASI?= =?us-ascii?Q?9qbI6HemrfDpYjd8n+IB4RfDtnNQlyc8bGflY6cWw=3D=3D?= X-Microsoft-Exchange-Diagnostics-untrusted: 1;CY1PR03MB1519;5:vh3gtnUdlWw9r2NI/dZ5nne1oN71D8AA7ReA7MJ6DvUOr5kDvUcrE8R/53yX70arC2OtuKzhK3NsmB0eITUw9+58DbOAwa0Vcg4npYIP2v5igMYXWImaPiHu8yJrZKjA/60I80DJPnBzmmF3rUSiEQ==;24:eohOgfv+/IvMF/xBpLkYqDMeo1oZgWUTJ8pEJTF45cuVrF8gQSl+kpvgxIl0bYybSGFMS+huoZWAcvUmA1xlzWT19+p1W1GAn1z5sfbFqvQ=;20:FFBny/kpu2hFWZTfk3UYcGsGBGoOSdeIsiCz0pqWp9TcCsnBkwxuYP8Gh1m62770ixrZdoefVFIXkAt2PNJUTvo7X95N78aqFZM67t+JTzPQYFmrPxV12cv7RaDdzA2F2YpznEVpA8PRRE6jl85b0GwTEOaD+RkFzySBj0ftI9c= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR03MB1519 X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: BN1AFFO11FD021.protection.gbl X-Microsoft-Exchange-Diagnostics: 1;BN1AFFO11FD021;1:w/PJPeUpqWxPkieVgBNjxiPYrlQWNgPLp5YSDVPiqym7ukwFoGr5wU8tr338yoFHfkPcfUnHnZwDCJNMH4sDmsCxX7tp5Gu32XBqU4aS8GGSHoHTTlBEwlrXSBgqpacAhTBufN/bvlXoLs8ODAnzYdjZ2GgzmG12l6fiDow5xmDEH913LvCNyGBuzH/wlprMquKodQUR9OGomseqRdIQD6HKjrNUGNHtV5QJ7dgsYO3DviqOBn979tufrhLAa0EXyI+rsveuSmvu15k/HghPjaiXdDlJal2lAPzsP4j/lXr2T+SY3mePU/5JECgmSowYi1lDEFDvh5vwXEYL3AQJIeDT2WZX71Ak48f+0z0CeqvIpt2lgOp4moJ9x64uzF+q0qeBS7XbDhPcaVvso6zx4u/jHZzt8v8c/hvHFxsmPV05BAO1wo6PIBAAA1Coxs3H X-Forefront-Antispam-Report: CIP:66.35.236.227;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10009020)(6009001)(2980300002)(339900001)(199003)(189002)(50466002)(19580405001)(6806004)(48376002)(85426001)(19580395003)(107886002)(122386002)(86152002)(86362001)(77156002)(5001960100002)(62966003)(2201001)(230783001)(87936001)(2950100001)(92566002)(15975445007)(189998001)(105606002)(53416004)(76176999)(77096005)(5003940100001)(50226001)(50986999)(229853001)(5001920100001)(33646002)(106466001)(16796002)(5001770100001)(47776003)(46102003)(7099028)(7059030)(4001430100001)(2101003);DIR:OUT;SFP:1101;SCL:1;SRVR:BL2PR03MB291;H:sj-itexedge03.altera.priv.altera.com;FPR:;SPF:Fail;MLV:sfv;A:0;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;BL2PR03MB291;2:B8P2fcCkUOR0SD+v08PS9UcO4LghmEmKxj6WKF4eLSXFD88DKMnkKpYmLfIAwfuW;3:Z3vGnCs9u8Wfqy0oiC1q8ZznMrA75BO7fTD9/yJBIaijoBY8Ujw6qzwgGY8CxqtS8Ae8LuJIHIApkKIyENN+wiSL+Tx4g+EeevMAkSWQCqJzmEw6R29KEUSsXQpeV0jAUpAVZT0hFUNMLGoDjPQO433a88CyRn+kiRGHjSIB5V99xmo/cOYsDXzcHpfHopg4xl/iFgxnK5GDWJ7hXh6X67CJmMjG4mzHUL1E84AynaE=;25:srIUa68930KGHMBLmd/fOgbLtm1ig39rmodBLy1jF0jiai5tkqPNIXPkhbyZLWQqB21kBp+VBNntv4K4UFISSF+nf4PbjHvTSlxx52OBJdXOV1XFMUQqpcfK6Z958phaQPER1z0XalcYATxv3pzQ50p66eG9gbJsaJBYiuzxKHH1tMBhBg2jIvNx7GDXEE/IDJNJ+IBK8GII9wNb0lSGIkscXDbiN3vIhvWv8KTOBPWxRvkKeqVQv2DHfLKlSC/T;20:dQAjteMp8NyRBhA/eaRzw3MHVmsFtOu0RBupM2QaFWxw7zzF3kmkXNJTUYKp/FH0mTcdJk50H1c3EcS5RAM1MXUNA/6j7Raszties6WzzIrJFkgxEs03qupA5v/5WUPTDvv1cx9i7rfazzcztzpRwIZnp6jQP4GVJrcAJFQZUyA= BL2PR03MB291: X-MS-Exchange-Organization-RulesExecuted X-Microsoft-Exchange-Diagnostics: 1;BL2PR03MB291;4:vbJ46k5naR4W1Xzw2l1f6ec5qBUUG70IJPm96FJMMsJSXipOsxxD0ce2Qq4hxL7jDCGy3TEsuKWjxV4QI03nU+swUINqhOvG7Yf2MDxGOZylZnn0/ErwIrYAKX0+s3411wVr0NBOWhnBHfL+RE1OzAs6PUq1RVeaEfwuqiOE95Gzy/5+nA/7+PG4OVrHk+iKeSvq4PfCMo2U3OPTGWCR2ev3aqLuKMyW/0gZoRXQlfYQ10PLMP1jMp4cUAvz5o9u7ITIGufCBcHO4y4kzu0wbNR+TsfAzrCjypyKp5Zzqc0= X-Forefront-PRVS: 06400060E1 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;BL2PR03MB291;23:1CE0GNEpQmX40aTxMDUfjLP4SJTIO2eVK/RfNmpmmb?= =?us-ascii?Q?jW/Fa/qG3jRtPm2g6Ww9uXXP23s2q/q+JeqKBWZNs15gNiVspl4ESfaya4uB?= =?us-ascii?Q?AQ5oWYJrNPa13143efYOB3p2Uv/gpBu3I+I2T/wlKl12PtitvEQMthUhhwoX?= =?us-ascii?Q?BDKeFfJBNpytwit9xiyklBgMWMb8QpNhekemQp92NG509QdaiBfBiXrFDiAL?= =?us-ascii?Q?ybKp13vQASPEHzwTgJdiiHjOF3woeoLTB6liLfuIRYqNJm3zyIdfWyhCID/7?= =?us-ascii?Q?KEH+n2UDyAfbIeGBxZmKxoVCeX+oyTOZnwbfSWspSeuSvzV1DttSFuqNU4Ud?= =?us-ascii?Q?a7OuHyqlRR8Q0q6FvsMBN0VOjP7rFpR2WCBFMyZsB/DbTdwz2m+JrcLaxA1Z?= =?us-ascii?Q?Wlb0once/HBfO3KnglHvpAOqZe7yaTpNt0pTcsMhWayAiPbDrzlIL2+qBcHu?= =?us-ascii?Q?W11qHlsmc5YyWb/OgftqcSfajQ4f484QHLWGll+CN6cT0GEfPr/qdYanBTx3?= =?us-ascii?Q?AZzyi+zHfjCwrlTCMq9YU1Ym3DIoBpb422X8CWPmG7+anjFSmveB9c53Tbrq?= =?us-ascii?Q?waOPUtD+TuFdALGRfKQTSEoEK6fJWQS7uog4GsXXGdOM5Vvtb1ofsN3f+jpv?= =?us-ascii?Q?PNdnlYAliZupk+4vviT7IUw8DHTD8tODTQwVUO0quAYpC1cbO9eGUdQoKqtC?= =?us-ascii?Q?8g5eEDGg4NcCes/kdd2e0xxii17rrOD9LQEXHTKtly6XRCKB1JDVOHcS5oU4?= =?us-ascii?Q?skHE9YbgOpjeKQOBNyKcDGKboR3pOKFZcFRcbH7jnjirEJUHtr2GyxYiNCEz?= =?us-ascii?Q?0VHazaSBRfiOrkuWLILs4XbWjeIzYQ6JZjxOwlRqZHFFQzSNZu0P471JGR3z?= =?us-ascii?Q?OiPLrlHUkAmhrY9kLkh26ePiPx/Xsr0Q5jNus0REcz1x/w96dhgKOj2ZXXbv?= =?us-ascii?Q?n/HU34aiu6ulwRzWvCc9vNzT1VPrq6KCQnG2lCMiI7KUmDz/ffuuZbpwSPmG?= =?us-ascii?Q?boyTa6u8jyF5KXm4DL00MDKD9qpItydKcuGuiaaEEZqoycWBFI8f37i859/t?= =?us-ascii?Q?yPkMa7bM+hGxizzqTPcSrntqYJ8ro73i40oUVZ1PacAA1VhrZYC52mrsN9XN?= =?us-ascii?Q?4jQccpS1SLPCy752q6iPjMlcfxswkKfG8XfxIX7bQVesKYso2zZg=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1;BL2PR03MB291;5:JZksWmpgUfG6ZSsTCKKLZzYA3a9TfGjyh6bjKLhYNcCb+s/r94GSa0/BvMHf8QCrQuXqIKYgWYGiH98YlqHZh4ouP/CRyUgJz+0xiqZwXnijm/uDyWO1g2yQgG7cUSxQ2PG6dOIj62DpTBNYoGSjmQ==;24:tjwZphUTmH8N42yA1bKU1j/UAyQL/OmWZWnKM9i2dFDYrftveV654Fkj80dL8KFPPwMLXXPPDmj5kH+uJWgjPI9lBJgZfzd9SeSF7yhqv6g=;20:9aJCeUrc9+W0rmyQye8ZXxVVzAoPD1Xf3oZ1CPvtYEtLug1kDrpsqlPpGMEJYN2Q7mqI54Btz/wkKIXEUh3hq2UvdhEIatXCmSVjfp5ih8r7BTQ3bq3Bf9K9GH9iszEaEdAyT+hlV9piPvhkpluRLkWRnczsCRVA70MbQdWigiw= X-OriginatorOrg: opensource.altera.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jul 2015 15:56:34.1294 (UTC) X-MS-Exchange-CrossTenant-Id: fbd72e03-d4a5-4110-adce-614d51f2077a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=fbd72e03-d4a5-4110-adce-614d51f2077a;Ip=[66.35.236.227];Helo=[sj-itexedge03.altera.priv.altera.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL2PR03MB291 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 10617 Lines: 388 From: Alan Tull Add simple fpga bus. This is a bus that configures an fpga and its bridges before populating the devices below it. This is intended for use with device tree overlays. Note that FPGA bridges are seen as reset controllers so no special framework for FPGA bridges will need to be added. This supports fpga use where hardware blocks on a fpga will need drivers (as opposed to fpga used as an acceleration without drivers.) Signed-off-by: Alan Tull --- drivers/staging/fpga/Kconfig | 11 ++ drivers/staging/fpga/Makefile | 1 + drivers/staging/fpga/simple-fpga-bus.c | 323 ++++++++++++++++++++++++++++++++ 3 files changed, 335 insertions(+) create mode 100644 drivers/staging/fpga/simple-fpga-bus.c diff --git a/drivers/staging/fpga/Kconfig b/drivers/staging/fpga/Kconfig index 8254ca0..8d003e3 100644 --- a/drivers/staging/fpga/Kconfig +++ b/drivers/staging/fpga/Kconfig @@ -11,4 +11,15 @@ config FPGA kernel. The FPGA framework adds a FPGA manager class and FPGA manager drivers. +if FPGA + +config SIMPLE_FPGA_BUS + bool "Simple FPGA Bus" + depends on OF + help + Simple FPGA Bus allows loading FPGA images under control of + Device Tree. + +endif # FPGA + endmenu diff --git a/drivers/staging/fpga/Makefile b/drivers/staging/fpga/Makefile index 3313c52..6115213 100644 --- a/drivers/staging/fpga/Makefile +++ b/drivers/staging/fpga/Makefile @@ -4,5 +4,6 @@ # Core FPGA Manager Framework obj-$(CONFIG_FPGA) += fpga-mgr.o +obj-$(CONFIG_SIMPLE_FPGA_BUS) += simple-fpga-bus.o # FPGA Manager Drivers diff --git a/drivers/staging/fpga/simple-fpga-bus.c b/drivers/staging/fpga/simple-fpga-bus.c new file mode 100644 index 0000000..bf178d8 --- /dev/null +++ b/drivers/staging/fpga/simple-fpga-bus.c @@ -0,0 +1,323 @@ +/* + * Simple FPGA Bus + * + * Copyright (C) 2013-2015 Altera Corporation + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#include +#include +#include +#include +#include +#include + +/** + * struct simple_fpga_bus - simple fpga bus private data + * @dev: device from pdev + * @mgr: the fpga manager associated with this bus + * @bridges: an array of reset controls for controlling FPGA bridges + * associated with this bus + * @num_bridges: size of the bridges array + */ +struct simple_fpga_bus { + struct device *dev; + struct fpga_manager *mgr; + struct reset_control **bridges; + int num_bridges; +}; + +/** + * simple_fpga_bus_get_mgr - get associated fpga manager + * @priv: simple fpga bus private data + * pointer to fpga manager in priv->mgr on success + * + * Given a simple fpga bus, get a reference to its the fpga manager specified + * by its "fpga-mgr" device tree property. + * + * Return: 0 if success or if the fpga manager is not specified. + * Negative error code otherwise. + */ +static int simple_fpga_bus_get_mgr(struct simple_fpga_bus *priv) +{ + struct device *dev = priv->dev; + struct device_node *np = dev->of_node; + struct fpga_manager *mgr; + struct device_node *mgr_node; + + /* + * Return 0 (not an error) if fpga manager is not specified. + * This supports the case where fpga was already configured. + */ + mgr_node = of_parse_phandle(np, "fpga-mgr", 0); + if (!mgr_node) { + dev_dbg(dev, "could not find fpga-mgr DT property\n"); + return 0; + } + + mgr = of_fpga_mgr_get(mgr_node); + if (IS_ERR(mgr)) + return PTR_ERR(mgr); + + priv->mgr = mgr; + + return 0; +} + +/** + * simple_fpga_bus_load_image - load an fpga image under device tree control + * @priv: simple fpga bus private data + * + * Given a simple fpga bus, load the fpga image specified in its device + * tree node. + * + * Return: 0 on success, negative error code otherwise. + */ +static int simple_fpga_bus_load_image(struct simple_fpga_bus *priv) +{ + struct device *dev = priv->dev; + struct device_node *np = dev->of_node; + struct fpga_manager *mgr = priv->mgr; + u32 flags = 0; + const char *path; + + if (of_property_read_bool(np, "partial-reconfig")) + flags |= FPGA_MGR_PARTIAL_RECONFIG; + + /* If firmware image is specified in the DT, load it */ + if (!of_property_read_string(np, "fpga-firmware", &path)) + return fpga_mgr_firmware_load(mgr, flags, path); + + /* + * Here we can add other methods of getting ahold of a fpga image + * specified in the device tree and programming it. + */ + + dev_info(dev, "No FPGA image to load.\n"); + + /* Status is that we have a fpga manager but no image specified. */ + return -EINVAL; +} + +/** + * simple_fpga_bus_bridge_enable - enable the fpga bridges + * @priv: simple fpga bus private data + * + * Return: 0 on success, negative error code otherwise. + */ +static int simple_fpga_bus_bridge_enable(struct simple_fpga_bus *priv) +{ + int i, ret; + + for (i = 0; i < priv->num_bridges; i++) { + ret = reset_control_deassert(priv->bridges[i]); + if (ret) + return ret; + } + + return 0; +} + +/** + * simple_fpga_bus_bridge_disable - disable the bridges + * @priv: simple fpga bus private data + * + * Return: 0 on success, negative error code otherwise. + */ +static int simple_fpga_bus_bridge_disable(struct simple_fpga_bus *priv) +{ + int i, ret; + + for (i = 0; i < priv->num_bridges; i++) { + ret = reset_control_assert(priv->bridges[i]); + if (ret) + return ret; + } + + return 0; +} + +/** + * simple_fpga_bus_get_bridges - get references for fpga bridges + * @priv: simple fpga bus private data + * + * Given a simple fpga bus, get references for its associated fpga bridges so + * that it can enable/disable the bridges. These are specified by "resets" + * and "reset-names" device tree properties. + * + * Return: 0 on success, negative error code otherwise. + */ +static int simple_fpga_bus_get_bridges(struct simple_fpga_bus *priv) +{ + struct device *dev = priv->dev; + struct device_node *np = dev->of_node; + const char *reset_name; + struct reset_control **bridges; + int i, num_resets, num_names, ret; + + num_resets = of_count_phandle_with_args(np, "resets", "#reset-cells"); + num_names = of_property_count_strings(np, "reset-names"); + if (num_resets <= 0 || num_names <= 0) { + dev_info(dev, "No fpga bridge resets found\n"); + return -EINVAL; + } + if (num_resets != num_names) { + dev_dbg(dev, "Number of resets and reset-names differ."); + return -EINVAL; + } + + bridges = kcalloc(num_resets, sizeof(struct reset_control *), + GFP_KERNEL); + if (!bridges) + return -ENOMEM; + + for (i = 0; i < num_resets; i++) { + ret = of_property_read_string_index(np, "reset-names", i, + &reset_name); + if (ret) + return ret; + + bridges[i] = of_reset_control_get(np, reset_name); + if (IS_ERR(bridges[i])) { + ret = PTR_ERR(bridges[i]); + goto err_free_bridges; + } + } + + priv->bridges = bridges; + priv->num_bridges = num_resets; + + return 0; + +err_free_bridges: + for (i = 0; i < num_resets; i++) + reset_control_put(priv->bridges[i]); + + kfree(bridges); + return ret; +} + +/** + * simple_fpga_bus_put_bridges - release references for the fpga bridges + * @priv: simple fpga bus private data + */ +static void simple_fpga_bus_put_bridges(struct simple_fpga_bus *priv) +{ + int i; + + for (i = 0; i < priv->num_bridges; i++) + reset_control_put(priv->bridges[i]); + + kfree(priv->bridges); + priv->num_bridges = 0; +} + +/** + * simple_fpga_bus_probe - Probe function for simple fpga bus. + * @pdev: platform device + * + * Do the necessary steps to program the FPGA and enable associated bridges. + * Then populate the device tree below this bus to get drivers probed for the + * hardware that is on the FPGA. + * + * Return: 0 on success, negative error code otherwise. + */ +static int simple_fpga_bus_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct device_node *np = dev->of_node; + struct simple_fpga_bus *priv; + int ret; + + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + priv->dev = dev; + + ret = simple_fpga_bus_get_mgr(priv); + if (ret) + return ret; + + if (priv->mgr) { + ret = simple_fpga_bus_get_bridges(priv); + if (ret) + goto err_release_mgr; + + ret = simple_fpga_bus_load_image(priv); + if (ret) + goto err_release_br; + + ret = simple_fpga_bus_bridge_enable(priv); + if (ret) + goto err_release_br; + } + + of_platform_populate(np, of_default_bus_match_table, NULL, dev); + + platform_set_drvdata(pdev, priv); + + return 0; + +err_release_br: + simple_fpga_bus_put_bridges(priv); +err_release_mgr: + fpga_mgr_put(priv->mgr); + + return ret; +} + +static int simple_fpga_bus_remove(struct platform_device *pdev) +{ + struct simple_fpga_bus *priv = platform_get_drvdata(pdev); + + simple_fpga_bus_bridge_disable(priv); + simple_fpga_bus_put_bridges(priv); + fpga_mgr_put(priv->mgr); + + return 0; +} + +static const struct of_device_id simple_fpga_bus_of_match[] = { + { .compatible = "simple-fpga-bus", }, + {}, +}; +MODULE_DEVICE_TABLE(of, simple_fpga_bus_of_match); + +static struct platform_driver simple_fpga_bus_driver = { + .probe = simple_fpga_bus_probe, + .remove = simple_fpga_bus_remove, + .driver = { + .name = "simple-fpga-bus", + .owner = THIS_MODULE, + .of_match_table = of_match_ptr(simple_fpga_bus_of_match), + }, +}; + +static int __init simple_fpga_bus_init(void) +{ + return platform_driver_register(&simple_fpga_bus_driver); +} + +static void __exit simple_fpga_bus_exit(void) +{ + platform_driver_unregister(&simple_fpga_bus_driver); +} + +module_init(simple_fpga_bus_init); +module_exit(simple_fpga_bus_exit); + +MODULE_DESCRIPTION("Simple FPGA Bus"); +MODULE_AUTHOR("Alan Tull "); +MODULE_LICENSE("GPL v2"); -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/