Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp194672imu; Mon, 26 Nov 2018 09:39:24 -0800 (PST) X-Google-Smtp-Source: AFSGD/UBbwdqulZsNslTNz/k0gfGY5j/XE2HO/hJbrCU5tdogYY1R007sheTZeKDt8LKfJ3UWUXf X-Received: by 2002:a63:bf0b:: with SMTP id v11mr26289533pgf.302.1543253964764; Mon, 26 Nov 2018 09:39:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543253964; cv=none; d=google.com; s=arc-20160816; b=dDDHRaTCdi8Opnd67Rk+laZNS/2EqGMxyTPH548M2BEPmGQ0x/OF1/dfQluyS+1RLB qyOx3zyBiaKFBdNZYhS0IRFQ3QqUxeQgDpLENH4gdf0b+PXS9wkcu4ycPISyKhmPxwtD 1YYPJDAW1PpFd1wecs09M3CCCSlilooaXShKUOoGAs5Iw7no72OfEtEGouE2cB/lUnZ7 7Du7DJpRpCV4k/Hmp1Od3gQLabU+Tamxcp5YHuixIEr128wrqUE/rxgXRGQM5Jn56txm 0w3LLk/JHZ5zNdPvjKrdEl9zDmB9S734X/AkkYl6+GvPdVkbtlvdVofbXbogdB2dWfV7 aqkg== 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=lwCnPYP7DKGMohS8wocUKK80EBCjJ91e6XQH3ULK+6c=; b=iMZb2INJFT0ohL6l82C87Dk2rug1XoU0Ayjn4fY3OYUgAIB4Tlwx5F0ncD2JtQrUak iukRczMgTVp+snmQ+RSHR0fWHCvWDtRBUAmetRg3s8kr6j/I64SJ/q+030ANaS253h9r zPxEN1954q8+IOdH4fTCZgFKwV5WOk/pLbJ8wH7NBXAga1yfPU19vlw6Buq75aU/cafg XYYD0CWvzC3hWPnKRj9gQf3UezNiL1rsN70uAitiblnRUjmfNdYhlgmap2Xc77+yT8yY hw+gfBo9XszDDB6okuDOPnsSI0ST81/Uu9FDHkXy2GAxLSo+o6r1G5/20hglnwK0ZY5G bvSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=C5GjeUnO; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k16si836361pls.124.2018.11.26.09.38.38; Mon, 26 Nov 2018 09:39:24 -0800 (PST) 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=@kernel.org header.s=default header.b=C5GjeUnO; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727276AbeK0EaW (ORCPT + 99 others); Mon, 26 Nov 2018 23:30:22 -0500 Received: from mail.kernel.org ([198.145.29.99]:58692 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726254AbeK0EaW (ORCPT ); Mon, 26 Nov 2018 23:30:22 -0500 Received: from localhost.localdomain (unknown [136.62.81.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CA8152086B; Mon, 26 Nov 2018 17:35:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543253734; bh=qJDW8bMoYKeCM3xnA/soWeSyA0ukKDLXhfMwLcnhPlk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C5GjeUnOWgWD6e+EsSL4CHRaSN/3VIIT/LFgAssahqORtHyTcG+OERAh8cMlTqzQp eglCSKoXR7c90AugKVMKqAP2yZpzBGRXXEIeACDOxG0rAGv1zcDGc65lBeDjXN54g8 fpxqI2jrTlkYAuuXW2RKpj3HOuwf9O1B4XLtDl2Q= From: Alan Tull To: Greg Kroah-Hartman Cc: Moritz Fischer , Alan Tull , linux-kernel@vger.kernel.org, linux-fpga@vger.kernel.org, Anatolij Gustschin Subject: [PATCH 2/2] fpga: mgr: altera-ps-spi: enable usage on non-dt platforms Date: Mon, 26 Nov 2018 11:35:28 -0600 Message-Id: <1543253728-26542-3-git-send-email-atull@kernel.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1543253728-26542-1-git-send-email-atull@kernel.org> References: <1543253728-26542-1-git-send-email-atull@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Anatolij Gustschin Driver probing fails on non-dt platforms since of_match_device() always returns NULL here. Add spi ids with device names and matching driver data as an index of a map array with data for supported devices. Add this map array and a function for mapping spi ids to driver data. This allows driver binding to dynamically added PS-SPI devices (e.g. when added via spi_new_device() after hot-plugging). Signed-off-by: Anatolij Gustschin Acked-by: Alan Tull --- drivers/fpga/altera-ps-spi.c | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/drivers/fpga/altera-ps-spi.c b/drivers/fpga/altera-ps-spi.c index 33aafda..8c18bee 100644 --- a/drivers/fpga/altera-ps-spi.c +++ b/drivers/fpga/altera-ps-spi.c @@ -75,6 +75,12 @@ static struct altera_ps_data a10_data = { .t_st2ck_us = 10, /* min(t_ST2CK) */ }; +/* Array index is enum altera_ps_devtype */ +static const struct altera_ps_data *altera_ps_data_map[] = { + &c5_data, + &a10_data, +}; + static const struct of_device_id of_ef_match[] = { { .compatible = "altr,fpga-passive-serial", .data = &c5_data }, { .compatible = "altr,fpga-arria10-passive-serial", .data = &a10_data }, @@ -234,6 +240,22 @@ static const struct fpga_manager_ops altera_ps_ops = { .write_complete = altera_ps_write_complete, }; +static const struct altera_ps_data *id_to_data(const struct spi_device_id *id) +{ + kernel_ulong_t devtype = id->driver_data; + const struct altera_ps_data *data; + + /* someone added a altera_ps_devtype without adding to the map array */ + if (devtype >= ARRAY_SIZE(altera_ps_data_map)) + return NULL; + + data = altera_ps_data_map[devtype]; + if (!data || data->devtype != devtype) + return NULL; + + return data; +} + static int altera_ps_probe(struct spi_device *spi) { struct altera_ps_conf *conf; @@ -244,11 +266,17 @@ static int altera_ps_probe(struct spi_device *spi) if (!conf) return -ENOMEM; - of_id = of_match_device(of_ef_match, &spi->dev); - if (!of_id) - return -ENODEV; + if (spi->dev.of_node) { + of_id = of_match_device(of_ef_match, &spi->dev); + if (!of_id) + return -ENODEV; + conf->data = of_id->data; + } else { + conf->data = id_to_data(spi_get_device_id(spi)); + if (!conf->data) + return -ENODEV; + } - conf->data = of_id->data; conf->spi = spi; conf->config = devm_gpiod_get(&spi->dev, "nconfig", GPIOD_OUT_LOW); if (IS_ERR(conf->config)) { @@ -294,7 +322,9 @@ static int altera_ps_remove(struct spi_device *spi) } static const struct spi_device_id altera_ps_spi_ids[] = { - {"cyclone-ps-spi", 0}, + { "cyclone-ps-spi", CYCLONE5 }, + { "fpga-passive-serial", CYCLONE5 }, + { "fpga-arria10-passive-serial", ARRIA10 }, {} }; MODULE_DEVICE_TABLE(spi, altera_ps_spi_ids); -- 2.7.4