From patchwork Mon Jun 27 19:02:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Suchanek X-Patchwork-Id: 9201123 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E5ADE60757 for ; Mon, 27 Jun 2016 19:03:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D73C1285BE for ; Mon, 27 Jun 2016 19:03:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CBB42285C1; Mon, 27 Jun 2016 19:03:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 45D18285C5 for ; Mon, 27 Jun 2016 19:03:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752152AbcF0TCv (ORCPT ); Mon, 27 Jun 2016 15:02:51 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:34450 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751639AbcF0TCt (ORCPT ); Mon, 27 Jun 2016 15:02:49 -0400 Received: by mail-wm0-f66.google.com with SMTP id 187so27231909wmz.1; Mon, 27 Jun 2016 12:02:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=ow99muE2CgLDdFtz5N86DBSYK7dxKmwNXHpGt+pd3co=; b=eYIYNwywQz4sHK4y4vghE/7DbZGh/V4Tdo/FN7DNtiXehBvu8RJSvK/97JyhpJZ578 qJUqM6F+NuMLgowm2GSmEFH+h/7M7bejnPakE4hEee5RhKCdu4O3p9+ghq2r8n+cw69O MUnFY+t891A88/cMy3lR1SzjICZxqkE9LeqRhIBRk5C/khQYschGJoK9r0IUNIofBNNO 1qbApGFrp3Y4UrBiP74sjlEz6YceREBKjW/Wm7GCZB36EUq8v+VI6LVlC8t79FZE6R7M QdfyuvTdM/O4NF+QiiVOUrZjCS9kisp2cGWjn5UutT0CwK6l7GWa1uL4i1n2riRJRmxD S9TA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=ow99muE2CgLDdFtz5N86DBSYK7dxKmwNXHpGt+pd3co=; b=ZOMLWjrgSqDtl+X1vQMTjXLeaglwxGBZaGBgvdkVG8QIOESbTd0GYhlD9XKUqBLESf +qBxeRwj8Co0hhvjy8dHTWe+WkS9SlwCe3Dmvhmsp1wGkI/9CumV5qEaJkxJkvWx48ap UIYUb/TeGqa9wTQMppK16HqvQK4GQlShG3uLdHxUFwQQY99TydrBVKwli+n3jHcSnMxJ cxV0dxhqcovG91uFQAbEkAR6m0uo4GnFd3NMq3+on4Rb1s4/QOhFy1OpZZg1t/TvsTF9 X2pjgUZ5qzK4ZasZpYcNZHjIloIq90M6CGzcuNls/nAFCyeoDlyZZzP8xeUvosObflQE bLLQ== X-Gm-Message-State: ALyK8tJVpEBkbo/I7wGphGe80IYuJ8gBFXzZf6xIHPEr1t7JKb6JQnmA4ACEfOtljF+o3Q== X-Received: by 10.28.8.202 with SMTP id 193mr12445534wmi.76.1467054167340; Mon, 27 Jun 2016 12:02:47 -0700 (PDT) Received: from iscsi.burning-in.hell (2-166-195-217.cust.centrio.cz. [217.195.166.2]) by smtp.gmail.com with ESMTPSA id zg10sm3278760wjb.1.2016.06.27.12.02.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 Jun 2016 12:02:46 -0700 (PDT) From: Michal Suchanek To: Greg Kroah-Hartman , Mark Brown , linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org Cc: Michal Suchanek Subject: [PATCH v2 3/3] drivers core: allow id match override when manually binding driver Date: Mon, 27 Jun 2016 21:02:32 +0200 Message-Id: <15ff382f699387e2d8f23779db851d0de7e9291e.1467053363.git.hramrach@gmail.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The spi bus has no autodetection whatsoever. The 'detection' of the device that's suposed to be on the other side completely relies on user supplied information coming from devicetree on many platforms. It is completely reasonable then to allow the user to supply the information at runtime by doing echo 'somedevice' > /sys/bus/spi/drivers/somedriver/bind This fails if somedriver does not have in its id table compatible of somedevice so just skip this check for manual driver binding. This allows binding spidev on any slave device by hand using sysfs without adding superfluous compatibles or any other needless complication. Note that any slave driver that requires configuration will fail to probe anyway if the configuration is not provided in the devicetree node. A driver like spidev that requires no configuration can bind to any slave. Signed-off-by: Michal Suchanek --- drivers/base/bus.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 6470eb8..a896aed 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -199,6 +199,28 @@ static ssize_t unbind_store(struct device_driver *drv, const char *buf, } static DRIVER_ATTR_WO(unbind); +static const char *driver_override_buses[] = { + "spi", + NULL +}; + +static inline bool driver_match_override(struct device_driver *drv, + struct device *dev) +{ + struct bus_type *bus = bus_get(drv->bus); + int i; + + for (i = 0; driver_override_buses[i]; i++) { + if (!strcmp(bus->name, driver_override_buses[i])) { + pr_notice("Overriding id match on manual driver binding:\n bus: %s driver: %s device: %s\n", + bus->name, drv->name, dev_name(dev)); + return true; + } + } + + return false; +} + /* * Manually attach a device to a driver. * Note: the driver must want to bind to the device, @@ -212,7 +234,8 @@ static ssize_t bind_store(struct device_driver *drv, const char *buf, int err = -ENODEV; dev = bus_find_device_by_name(bus, NULL, buf); - if (dev && dev->driver == NULL && driver_match_device(drv, dev)) { + if (dev && dev->driver == NULL && (driver_match_device(drv, dev) + || driver_match_override(drv, dev))) { if (dev->parent) /* Needed for USB */ device_lock(dev->parent); device_lock(dev);