From patchwork Tue Sep 2 18:02:39 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 4827571 Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 824CBC0338 for ; Tue, 2 Sep 2014 18:02:43 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 503D820170 for ; Tue, 2 Sep 2014 18:02:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D5764201B4 for ; Tue, 2 Sep 2014 18:02:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753774AbaIBSCk (ORCPT ); Tue, 2 Sep 2014 14:02:40 -0400 Received: from sauhun.de ([89.238.76.85]:56525 "EHLO pokefinder.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754216AbaIBSCj (ORCPT ); Tue, 2 Sep 2014 14:02:39 -0400 Received: from p4fe244cd.dip0.t-ipconnect.de ([79.226.68.205]:56192 helo=localhost) by pokefinder.org with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1XOsPd-0004sm-Ou; Tue, 02 Sep 2014 20:02:38 +0200 From: Wolfram Sang To: linux-i2c@vger.kernel.org Cc: linux-sh@vger.kernel.org, Wolfram Sang Subject: [PATCH 1/3] WIP: i2c core changes for slave support Date: Tue, 2 Sep 2014 20:02:39 +0200 Message-Id: <1409680961-12632-2-git-send-email-wsa@the-dreams.de> X-Mailer: git-send-email 2.0.0 In-Reply-To: <1409680961-12632-1-git-send-email-wsa@the-dreams.de> References: <1409680961-12632-1-git-send-email-wsa@the-dreams.de> Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Spam-Status: No, score=-8.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Wolfram Sang Not for upstream yet. Signed-off-by: Wolfram Sang --- drivers/i2c/i2c-core.c | 42 ++++++++++++++++++++++++++++++++++++++++++ include/linux/i2c-slave.h | 28 ++++++++++++++++++++++++++++ include/linux/i2c.h | 5 +++++ 3 files changed, 75 insertions(+) create mode 100644 include/linux/i2c-slave.h diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index 632057a44615..63ea70e5c274 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c @@ -2536,6 +2536,48 @@ trace: } EXPORT_SYMBOL(i2c_smbus_xfer); +int i2c_slave_register(struct i2c_client *client, + int (*slave_cb)(struct i2c_client *, enum i2c_slave_event, u8 *)) +{ + u16 addr = client->addr; + int ret; + + if (!slave_cb) + return -EINVAL; + + ret = i2c_check_addr_validity(addr); + if (ret) + return ret; + + if (!client->adapter->algo->reg_slave) + return -EOPNOTSUPP; + + client->slave_cb = slave_cb; + + ret = client->adapter->algo->reg_slave(client); + if (ret) + client->slave_cb = NULL; + + return ret; +} +EXPORT_SYMBOL_GPL(i2c_slave_register); + +int i2c_slave_unregister(struct i2c_client *client) +{ + int ret; + + if (!client->adapter->algo->unreg_slave) + return -EOPNOTSUPP; + + ret = client->adapter->algo->unreg_slave(client); + + if (ret == 0) + client->slave_cb = NULL; + + return ret; +} +EXPORT_SYMBOL_GPL(i2c_slave_unregister); + MODULE_AUTHOR("Simon G. Vogl "); MODULE_DESCRIPTION("I2C-Bus main module"); MODULE_LICENSE("GPL"); diff --git a/include/linux/i2c-slave.h b/include/linux/i2c-slave.h new file mode 100644 index 000000000000..ddc9493cb5e7 --- /dev/null +++ b/include/linux/i2c-slave.h @@ -0,0 +1,28 @@ +/* + * i2c-slave.h - Linux I2C slave support + * + * Copyright (C) 2014 by Wolfram Sang + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; version 2 of the License. + */ + +#include + +#ifndef _LINUX_I2C_SLAVE_H +#define _LINUX_I2C_SLAVE_H + +enum i2c_slave_event { + I2C_SLAVE_REQ_READ, + I2C_SLAVE_REQ_WRITE, + I2C_SLAVE_STOP, +}; + +extern int i2c_slave_register(struct i2c_client *client, int (*slave_cb)(struct i2c_client *, enum i2c_slave_event, u8 *)); +extern int i2c_slave_unregister(struct i2c_client *client); + +#define i2c_slave_event(__client, __event, __value) \ + client->slave_cb(__client, __event, __value) + +#endif diff --git a/include/linux/i2c.h b/include/linux/i2c.h index a95efeb53a8b..8541aa6b0178 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h @@ -46,6 +46,7 @@ struct i2c_client; struct i2c_driver; union i2c_smbus_data; struct i2c_board_info; +enum i2c_slave_event; struct module; @@ -224,6 +225,7 @@ struct i2c_client { struct device dev; /* the device structure */ int irq; /* irq issued by device */ struct list_head detected; + int (*slave_cb)(struct i2c_client *, enum i2c_slave_event, u8 *); }; #define to_i2c_client(d) container_of(d, struct i2c_client, dev) @@ -377,6 +379,9 @@ struct i2c_algorithm { /* To determine what the adapter supports */ u32 (*functionality) (struct i2c_adapter *); + + int (*reg_slave)(struct i2c_client *client); + int (*unreg_slave)(struct i2c_client *client); }; /**