From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752908AbdCNNsc (ORCPT ); Tue, 14 Mar 2017 09:48:32 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:35849 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752881AbdCNNs1 (ORCPT ); Tue, 14 Mar 2017 09:48:27 -0400 From: Andrey Smirnov To: Rob Herring Cc: Andrey Smirnov , cphealy@gmail.com, Guenter Roeck , linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] serdev: Add minimal bus locking API Date: Tue, 14 Mar 2017 06:48:19 -0700 Message-Id: <20170314134819.19476-3-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170314134819.19476-1-andrew.smirnov@gmail.com> References: <20170314134819.19476-1-andrew.smirnov@gmail.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add minimal bus locking API which is useful for serial devices that implement request-reply protocol Cc: cphealy@gmail.com Cc: Guenter Roeck Cc: linux-serial@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Andrey Smirnov --- drivers/tty/serdev/core.c | 1 + include/linux/serdev.h | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/drivers/tty/serdev/core.c b/drivers/tty/serdev/core.c index 759e834..20ca231 100644 --- a/drivers/tty/serdev/core.c +++ b/drivers/tty/serdev/core.c @@ -269,6 +269,7 @@ struct serdev_device *serdev_device_alloc(struct serdev_controller *ctrl) serdev->dev.type = &serdev_device_type; init_completion(&serdev->write_wakeup); mutex_init(&serdev->write_lock); + mutex_init(&serdev->bus_lock); return serdev; } EXPORT_SYMBOL_GPL(serdev_device_alloc); diff --git a/include/linux/serdev.h b/include/linux/serdev.h index 8f7aa35..6b73a79 100644 --- a/include/linux/serdev.h +++ b/include/linux/serdev.h @@ -48,6 +48,7 @@ struct serdev_device { const struct serdev_device_ops *ops; struct completion write_wakeup; struct mutex write_lock; + struct mutex bus_lock; }; static inline struct serdev_device *to_serdev_device(struct device *d) @@ -55,6 +56,16 @@ static inline struct serdev_device *to_serdev_device(struct device *d) return container_of(d, struct serdev_device, dev); } +static inline void serdev_device_bus_lock(struct serdev_device *serdev) +{ + mutex_lock(&serdev->bus_lock); +} + +static inline void serdev_device_bus_unlock(struct serdev_device *serdev) +{ + mutex_unlock(&serdev->bus_lock); +} + /** * struct serdev_device_driver - serdev slave device driver * @driver: serdev device drivers should initialize name field of this -- 2.9.3