Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp85759imu; Tue, 8 Jan 2019 15:10:16 -0800 (PST) X-Google-Smtp-Source: ALg8bN6loelvVsbLgsMmTgNEj2gBcH7CpX5exsbrs0TfPNlNCoK9pt+qBjHI/V/fK2fSJOd082kq X-Received: by 2002:a63:b81a:: with SMTP id p26mr3285660pge.433.1546989016727; Tue, 08 Jan 2019 15:10:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546989016; cv=none; d=google.com; s=arc-20160816; b=ebAumBNw63BOlyPrleYL4c+fKzy+FLNTHuuj69ugKBdPzwr/4j7JbbW5HZzxzfh61I XsoObgIwjbUmVEwSHAVkNsKWXsZpmgUTUy38SQ1WRU2yObadqRv4xrD//KYU+1DX/Rtv gB1v3+HfR2Cr0GRrC2S102+xcKWIGP+Gm7gAre5rfX5CPor/qrJ3Rj6xDC6CtnNx0ua7 Rf9525DKkRdc8yDjxpRNAompXf2ls/0+hTvIYZDdh7ySDli7KaTJz73SL4yYEZsQ1qNn iU2PZiPLA1PzQy7crIuFeUqhzqFchTCBDEeCUyymRjd/FtF+sAa4hUYeWKR23gz8h/Pp MKFA== 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=YAvZ/pH6lMIksVLRvTR8eQqY0c+EoHMb/3U4kL6GjKs=; b=Yp5lNKo+PSe5CEepkugnTprOecQ6RiemjdmIdolPU66y+4/qP3pj/9C2wlOXOiV3+y 3ekgUwCv8ROoHB0WNbzCCqcUub5zFnspBdbQY+EAuDA+uGjXRsxSVPl8ixCxJlfCJYqX DkMaSzGcgjmFQz28BYdz2XZ6+Nc599W+uPVBE4btJGsU7/wvnG5IITFNab50ZHQP0QrO K1KOI0recnqSd2TgGKNZxuYQXbEqXn/FDH6rTx1V0KKDS7TfmzZizS1z6cOc2w3Ddl8L QnwpQuhFDNor9ibLaXT0uxI2+9dM+MChyals0CAGEm4X5F0dGLVx0pclT7kUImVEPvdP rBhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=temperror (no key for signature) header.i=@lucaceresoli.net header.s=default header.b=yVU8Dnp1; 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 j13si25232742pgi.227.2019.01.08.15.09.59; Tue, 08 Jan 2019 15:10:16 -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=temperror (no key for signature) header.i=@lucaceresoli.net header.s=default header.b=yVU8Dnp1; 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 S1729371AbfAHXIc (ORCPT + 99 others); Tue, 8 Jan 2019 18:08:32 -0500 Received: from hostingweb31-40.netsons.net ([89.40.174.40]:48418 "EHLO hostingweb31-40.netsons.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729281AbfAHXIa (ORCPT ); Tue, 8 Jan 2019 18:08:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lucaceresoli.net; s=default; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=YAvZ/pH6lMIksVLRvTR8eQqY0c+EoHMb/3U4kL6GjKs=; b=yVU8Dnp1mEt9WPCoepziK4bSP oLQnYWbYPNJgWTVMC8rlZGXXg0eo+t1uzLeOcuJ2FJrLK5cZvbzMBjJWCvAnQXuDpRSvrN5hO4ou2 KKbzR/b0nppoJEfp1mlx73icrCKfiJR7HZ3cuVtls6hcxbiBeeIDmgMRMalq/CrajD/7Q=; Received: from [78.134.43.6] (port=50994 helo=melee.fritz.box) by hostingweb31.netsons.net with esmtpa (Exim 4.91) (envelope-from ) id 1gh02Y-00FWab-Eu; Tue, 08 Jan 2019 23:40:06 +0100 From: Luca Ceresoli To: linux-media@vger.kernel.org Cc: Luca Ceresoli , Kieran Bingham , Laurent Pinchart , jacopo mondi , Vladimir Zapolskiy , Wolfram Sang , Peter Rosin , Mauro Carvalho Chehab , Rob Herring , Mark Rutland , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org, Luca Ceresoli Subject: [RFC 1/4] i2c: core: let adapters be notified of client attach/detach Date: Tue, 8 Jan 2019 23:39:50 +0100 Message-Id: <20190108223953.9969-2-luca@lucaceresoli.net> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190108223953.9969-1-luca@lucaceresoli.net> References: <20190108223953.9969-1-luca@lucaceresoli.net> X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - hostingweb31.netsons.net X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - lucaceresoli.net X-Get-Message-Sender-Via: hostingweb31.netsons.net: authenticated_id: luca+lucaceresoli.net/only user confirmed/virtual account not confirmed X-Authenticated-Sender: hostingweb31.netsons.net: luca@lucaceresoli.net X-Source: X-Source-Args: X-Source-Dir: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Luca Ceresoli An adapter might need to know when a new device is about to be added. This will soon bee needed to implement an "I2C address translator" (ATR for short), a device that propagates I2C transactions with a different slave address (an "alias" address). An ATR driver needs to know when a slave is being added to find a suitable alias and program the device translation map. Add an attach/detach callback pair to allow adapter drivers to be notified of clients being added and removed. Signed-off-by: Luca Ceresoli --- drivers/i2c/i2c-core-base.c | 16 ++++++++++++++++ include/linux/i2c.h | 9 +++++++++ 2 files changed, 25 insertions(+) diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index 28460f6a60cc..4f8776e065ce 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -778,6 +778,11 @@ i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info) } } + if (adap->attach_ops && + adap->attach_ops->attach_client && + adap->attach_ops->attach_client(adap, info, client) != 0) + goto err_attach_client; + status = device_register(&client->dev); if (status) goto out_free_props; @@ -788,6 +793,9 @@ i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info) return client; out_free_props: + if (adap->attach_ops && adap->attach_ops->detach_client) + adap->attach_ops->detach_client(adap, client); +err_attach_client: if (info->properties) device_remove_properties(&client->dev); out_err_put_of_node: @@ -810,9 +818,17 @@ EXPORT_SYMBOL_GPL(i2c_new_device); */ void i2c_unregister_device(struct i2c_client *client) { + struct i2c_adapter *adap; + if (!client) return; + adap = client->adapter; + + if (adap->attach_ops && + adap->attach_ops->detach_client) + adap->attach_ops->detach_client(adap, client); + if (client->dev.of_node) { of_node_clear_flag(client->dev.of_node, OF_POPULATED); of_node_put(client->dev.of_node); diff --git a/include/linux/i2c.h b/include/linux/i2c.h index 65b4eaed1d96..600d136b1056 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h @@ -551,6 +551,14 @@ struct i2c_lock_operations { void (*unlock_bus)(struct i2c_adapter *, unsigned int flags); }; +struct i2c_attach_operations { + int (*attach_client)(struct i2c_adapter *, + const struct i2c_board_info *, + struct i2c_client *); + void (*detach_client)(struct i2c_adapter *, + struct i2c_client *); +}; + /** * struct i2c_timings - I2C timing information * @bus_freq_hz: the bus frequency in Hz @@ -674,6 +682,7 @@ struct i2c_adapter { /* data fields that are valid for all devices */ const struct i2c_lock_operations *lock_ops; + const struct i2c_attach_operations *attach_ops; struct rt_mutex bus_lock; struct rt_mutex mux_lock; -- 2.17.1