public inbox for linux-i2c@vger.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Yicong Yang <yangyicong@hisilicon.com>
Cc: wsa@kernel.org, linux-i2c@vger.kernel.org, digetx@gmail.com,
	treding@nvidia.com, jarkko.nikula@linux.intel.com,
	rmk+kernel@armlinux.org.uk, song.bao.hua@hisilicon.com,
	john.garry@huawei.com, prime.zeng@huawei.com,
	linuxarm@huawei.com
Subject: Re: [PATCH v4 1/4] i2c: core: add managed function for adding i2c adapters
Date: Tue, 30 Mar 2021 16:30:00 +0300	[thread overview]
Message-ID: <YGMn2N5bWz4OV34Y@smile.fi.intel.com> (raw)
In-Reply-To: <1617109549-4013-2-git-send-email-yangyicong@hisilicon.com>

On Tue, Mar 30, 2021 at 09:05:46PM +0800, Yicong Yang wrote:
> Some I2C controller drivers will only unregister the I2C
> adapter in their .remove() callback, which can be done
> by simply using a managed variant to add the I2C adapter.
> 
> So add the managed functions for adding the I2C adapter.

FWIW,
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

> Signed-off-by: Yicong Yang <yangyicong@hisilicon.com>
> ---
>  drivers/i2c/i2c-core-base.c | 26 ++++++++++++++++++++++++++
>  include/linux/i2c.h         |  1 +
>  2 files changed, 27 insertions(+)
> 
> diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
> index 63ebf72..de9402c 100644
> --- a/drivers/i2c/i2c-core-base.c
> +++ b/drivers/i2c/i2c-core-base.c
> @@ -1703,6 +1703,32 @@ void i2c_del_adapter(struct i2c_adapter *adap)
>  }
>  EXPORT_SYMBOL(i2c_del_adapter);
>  
> +static void devm_i2c_del_adapter(void *adapter)
> +{
> +	i2c_del_adapter(adapter);
> +}
> +
> +/**
> + * devm_i2c_add_adapter - device-managed variant of i2c_add_adapter()
> + * @dev: managing device for adding this I2C adapter
> + * @adapter: the adapter to add
> + * Context: can sleep
> + *
> + * Add adapter with dynamic bus number, same with i2c_add_adapter()
> + * but the adapter will be auto deleted on driver detach.
> + */
> +int devm_i2c_add_adapter(struct device *dev, struct i2c_adapter *adapter)
> +{
> +	int ret;
> +
> +	ret = i2c_add_adapter(adapter);
> +	if (ret)
> +		return ret;
> +
> +	return devm_add_action_or_reset(dev, devm_i2c_del_adapter, adapter);
> +}
> +EXPORT_SYMBOL_GPL(devm_i2c_add_adapter);
> +
>  static void i2c_parse_timing(struct device *dev, char *prop_name, u32 *cur_val_p,
>  			    u32 def_val, bool use_def)
>  {
> diff --git a/include/linux/i2c.h b/include/linux/i2c.h
> index 5662265..10bd0b0 100644
> --- a/include/linux/i2c.h
> +++ b/include/linux/i2c.h
> @@ -844,6 +844,7 @@ static inline void i2c_mark_adapter_resumed(struct i2c_adapter *adap)
>   */
>  #if IS_ENABLED(CONFIG_I2C)
>  int i2c_add_adapter(struct i2c_adapter *adap);
> +int devm_i2c_add_adapter(struct device *dev, struct i2c_adapter *adapter);
>  void i2c_del_adapter(struct i2c_adapter *adap);
>  int i2c_add_numbered_adapter(struct i2c_adapter *adap);
>  
> -- 
> 2.8.1
> 

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2021-03-30 13:31 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-30 13:05 [PATCH v4 0/4] Add support for HiSilicon I2C controller Yicong Yang
2021-03-30 13:05 ` [PATCH v4 1/4] i2c: core: add managed function for adding i2c adapters Yicong Yang
2021-03-30 13:30   ` Andy Shevchenko [this message]
2021-03-30 13:05 ` [PATCH v4 2/4] i2c: core: add api to provide frequency mode strings Yicong Yang
2021-03-30 13:30   ` Andy Shevchenko
2021-03-30 13:05 ` [PATCH v4 3/4] i2c: add support for HiSilicon I2C controller Yicong Yang
2021-03-30 13:29   ` Andy Shevchenko
2021-03-30 13:05 ` [PATCH v4 4/4] MAINTAINERS: Add maintainer for HiSilicon I2C driver Yicong Yang
2021-03-30 13:39 ` [PATCH v4 0/4] Add support for HiSilicon I2C controller Andy Shevchenko
2021-03-30 14:04   ` Yicong Yang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YGMn2N5bWz4OV34Y@smile.fi.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=digetx@gmail.com \
    --cc=jarkko.nikula@linux.intel.com \
    --cc=john.garry@huawei.com \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linuxarm@huawei.com \
    --cc=prime.zeng@huawei.com \
    --cc=rmk+kernel@armlinux.org.uk \
    --cc=song.bao.hua@hisilicon.com \
    --cc=treding@nvidia.com \
    --cc=wsa@kernel.org \
    --cc=yangyicong@hisilicon.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox