From patchwork Tue Jan 8 22:39:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Ceresoli X-Patchwork-Id: 10753073 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BF5FB6C5 for ; Tue, 8 Jan 2019 23:08:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD1BA28D33 for ; Tue, 8 Jan 2019 23:08:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9F53328E1E; Tue, 8 Jan 2019 23:08:33 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 88AD528D33 for ; Tue, 8 Jan 2019 23:08:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729333AbfAHXIb (ORCPT ); Tue, 8 Jan 2019 18:08:31 -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-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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;