Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1388638pxb; Fri, 22 Jan 2021 14:42:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJx9iWCLox1m4L1EI2fbjCh8j9r848geHeZf2VQujV9WPCQ7glWznYVoPvkx5N3TbdBj68DN X-Received: by 2002:a05:6402:34e:: with SMTP id r14mr4999183edw.269.1611355372172; Fri, 22 Jan 2021 14:42:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611355372; cv=none; d=google.com; s=arc-20160816; b=uYR0yyXGXEAjvzHK5C4FMNhx8BsML6zr+4b8dYzOHLVgLhyEvjxeIj45RXjAA92pHa woSIM/BcaEv+WN75ET8Mdi+eY5qQvJXS1ZsPUwAyr74THwfvKvSckPatYZSfk8UQ2Ykl b8jDtcZ4wrkGCqyuinMMhJysR1fOoNSgPG/Yt0XHwrrWtvzgUSMLqFHE3RHcHTenPxDj ma9/o5NbNm7lCyyDO9mYU9iX8AXU47pEZku53c++MZq1v0KfqUZOtusFA18MZwBoYLO+ yzjnKPjwNtlFEw0GVwXQX4KLI6QN5BxGGUPK2KlzMYVZukR8srwhtIB50jukgtjHGZNV 8slQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=YjH4/GZD6djczXZFW+WAC9AdcW62EHadEo7R2NRlZ6E=; b=svPmKNpznTKM8cRx1cW4yFj2QeMCEmmHIHP8fmSNfFFAoXp+JnrCT2epCmI2ztBuaE N/uoh7YvBKPFxsp7zEkiYdn57zWcjgfzLnO3WNenfrpWk9oBLD0ZvWcBm35xNvXATDz6 hdH/BS7h+R4qd0wFV71bZxqTnmq0u88YjcEALkFPKviEPL1C+SGq7KWJRPcUmYXBheC/ tlHXmVa5PH8/RLypK/0KiH4q+GaqACuQSm+3ANe3e7TusOsLGWAaOSwI34/hFEeu6UeR xdw0C+KUXnEypDRjbLvlrpLAXdEM7DQnR4qwslr+xti8XotZGVIISNzTjq0BuXWiSZ1M GjDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=txWXNUv7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e26si4397684edv.363.2021.01.22.14.42.28; Fri, 22 Jan 2021 14:42:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=txWXNUv7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727262AbhAVWjz (ORCPT + 99 others); Fri, 22 Jan 2021 17:39:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728218AbhAVWjl (ORCPT ); Fri, 22 Jan 2021 17:39:41 -0500 Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10934C06174A for ; Fri, 22 Jan 2021 14:39:01 -0800 (PST) Received: by mail-lf1-x130.google.com with SMTP id v24so9730413lfr.7 for ; Fri, 22 Jan 2021 14:39:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=YjH4/GZD6djczXZFW+WAC9AdcW62EHadEo7R2NRlZ6E=; b=txWXNUv72/lwPaTQYO5019T/OI+ZNPsLyvYKVgSZPShdyPIbbZken8F+cRAx3/S7UL oNvA1n06V4OUvz1OkVg9HIf0H+0cPx/Cp69WeToanTi0W7TQIpNmKgrijc8cfX7CCIBX ZzkT1nVeC+SMEf1LSc5tUsVMaZhP5//PsrVJC2E9bDOZ/9E7UUbWlV3tSRFJnLGxw7bx PAcZjT3O+Lk2ga485SEe5UKmY83l7JrrvxwBPf+763SNyKy8XGdfuto44T6xzdv/0zEB cGjA9tDHKlHjq8mVUC1KAFEfmZLYV0O12xayaIDSLEAxGutX5altLh3t897GYKsO0aju e2KQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=YjH4/GZD6djczXZFW+WAC9AdcW62EHadEo7R2NRlZ6E=; b=qCm5RbAq5blyrau2HuS4jItrs03ObQhyFMYUf8O0EWdYtTQylzbWBcTUzj+laSYS11 cZb/fIMx+n4RPBipbylsCIjyj7R+7eAynKRwq6IqlREeJRW8u5dLdcUtCv06XjUEFy40 +igN4ZAfp2vqSbUH7zDhYFWnECemtoSe1CunHsOxu5O8aDS2b7aGZwmR7SBkNM9SNq3n PAARiRp4+YkjL1W/DYFvKXMpvxjKzvqTX3uelM23zPB1yixrGcn5jRKXROUsunTNfo8Y XJebU2I864/DEfSCf3QgLWfWsuip4vyQiegql1NFQq7jODaNEOI4KPyivYj7W8+jid0y fveg== X-Gm-Message-State: AOAM530hlAHcl68YwCJg2PUjydFQKhhUbjLuzkCgi6Vr0+awEFSWZtJI h87z+Wv3mK/aTWynU7x1soVT8vkOt/hQqROJh7Oeuw== X-Received: by 2002:ac2:5597:: with SMTP id v23mr288305lfg.649.1611355139576; Fri, 22 Jan 2021 14:38:59 -0800 (PST) MIME-Version: 1.0 References: <20210119124622.9490-1-mike.looijmans@topic.nl> <20210119124622.9490-2-mike.looijmans@topic.nl> In-Reply-To: <20210119124622.9490-2-mike.looijmans@topic.nl> From: Linus Walleij Date: Fri, 22 Jan 2021 23:38:48 +0100 Message-ID: Subject: Re: [PATCH v6 2/2] iio: accel: Add support for the Bosch-Sensortec BMI088 To: Mike Looijmans Cc: linux-iio , Dan Robertson , =?UTF-8?B?R2HDq3RhbiBBbmRyw6k=?= , Jonathan Bakker , Jonathan Cameron , Lars-Peter Clausen , Peter Meerwald-Stadler , "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Mike, thanks for your patch! I have a comment about PM: On Tue, Jan 19, 2021 at 1:46 PM Mike Looijmans wrote: > The BMI088 is a combined module with both accelerometer and gyroscope. > This adds the accelerometer driver support for the SPI interface. > The gyroscope part is already supported by the BMG160 driver. > > Signed-off-by: Mike Looijmans (...) > +static int bmi088_accel_set_power_state_on(struct bmi088_accel_data *data) > +{ > + struct device *dev = regmap_get_device(data->regmap); > + int ret; > + > + ret = pm_runtime_get_sync(dev); > + if (ret < 0) { > + pm_runtime_put_noidle(dev); > + return ret; > + } > + > + return 0; > +} > + > +static int bmi088_accel_set_power_state_off(struct bmi088_accel_data *data) > +{ > + struct device *dev = regmap_get_device(data->regmap); > + int ret; > + > + pm_runtime_mark_last_busy(dev); > + ret = pm_runtime_put_autosuspend(dev); > + > + return ret < 0 ? ret : 0; > +} I'm not sure you should wrap the pm_runtime calls like this. I think it is better to inline them. Next, I think it is better to let suspend/resume, i.e. system PM reuse runtime PM since you're implementing that. This is why we invented PM runtime force resume and force suspend. Here are some drivers that I implemented using that model: drivers/iio/gyro/mpu3050-core.c drivers/iio/accel/kxsd9.c drivers/iio/magnetometer/ak8974.c The short summary is: - Only implement runtime suspend/resume. - SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resume) - In probe() enable runtime PM with autosuspend: pm_runtime_get_noresume(dev); pm_runtime_set_active(dev); pm_runtime_enable(dev); pm_runtime_set_autosuspend_delay(dev, NNNN); pm_runtime_use_autosuspend(dev); pm_runtime_put(dev); - In remove() disable it like this: pm_runtime_get_sync(dev); pm_runtime_put_noidle(dev); pm_runtime_disable(dev); - Any time the driver needs the hardware, call: pm_runtime_get_sync(dev); - As soon as you're done using the hardware call: pm_runtime_mark_last_busy(dev); pm_runtime_put_autosuspend(dev); The system PM will just hook into the same callbacks and suspend the hardware using the existing runtime PM hooks. This works fine in my drivers and saves some complexity and avoids bugs. Yours, Linus Walleij