All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Zimmermann <tzimmermann@suse.de>
To: jfalempe@redhat.com, airlied@redhat.com,
	maarten.lankhorst@linux.intel.com, mripard@kernel.org,
	airlied@gmail.com, jani.nikula@linux.intel.com
Cc: dri-devel@lists.freedesktop.org, Thomas Zimmermann <tzimmermann@suse.de>
Subject: [PATCH 05/10] drm/mgag200: Inline mgag200_i2c_init()
Date: Mon, 13 May 2024 14:51:10 +0200	[thread overview]
Message-ID: <20240513125620.6337-6-tzimmermann@suse.de> (raw)
In-Reply-To: <20240513125620.6337-1-tzimmermann@suse.de>

The function mgag200_i2c_init() is an internal helper that sets
up the i2c data structure. Inline its code into the only caller.
Rearrange the individual steps to separate among i2c algorithm,
adapter and fields in struct mga_i2c_chan.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/gpu/drm/mgag200/mgag200_i2c.c | 62 +++++++++++++--------------
 1 file changed, 29 insertions(+), 33 deletions(-)

diff --git a/drivers/gpu/drm/mgag200/mgag200_i2c.c b/drivers/gpu/drm/mgag200/mgag200_i2c.c
index 46fa9f1b4e469..ba7aeca55fb40 100644
--- a/drivers/gpu/drm/mgag200/mgag200_i2c.c
+++ b/drivers/gpu/drm/mgag200/mgag200_i2c.c
@@ -96,54 +96,50 @@ static void mgag200_i2c_release(struct drm_device *dev, void *res)
 	i2c_del_adapter(&i2c->adapter);
 }
 
-static int mgag200_i2c_init(struct mga_device *mdev, struct mga_i2c_chan *i2c)
+struct i2c_adapter *mgag200_ddc_create(struct mga_device *mdev)
 {
 	struct drm_device *dev = &mdev->base;
 	const struct mgag200_device_info *info = mdev->info;
+	struct mga_i2c_chan *i2c;
+	struct i2c_algo_bit_data *bit;
+	struct i2c_adapter *adapter;
 	int ret;
 
+	i2c = drmm_kzalloc(dev, sizeof(*i2c), GFP_KERNEL);
+	if (!i2c)
+		return ERR_PTR(-ENOMEM);
+
 	WREG_DAC(MGA1064_GEN_IO_CTL2, 1);
 	WREG_DAC(MGA1064_GEN_IO_DATA, 0xff);
 	WREG_DAC(MGA1064_GEN_IO_CTL, 0);
 
+	i2c->mdev = mdev;
 	i2c->data = BIT(info->i2c.data_bit);
 	i2c->clock = BIT(info->i2c.clock_bit);
-	i2c->adapter.owner = THIS_MODULE;
-	i2c->adapter.dev.parent = dev->dev;
-	i2c->mdev = mdev;
-	i2c_set_adapdata(&i2c->adapter, i2c);
-	snprintf(i2c->adapter.name, sizeof(i2c->adapter.name), "mga i2c");
-
-	i2c->adapter.algo_data = &i2c->bit;
 
-	i2c->bit.udelay = 10;
-	i2c->bit.timeout = usecs_to_jiffies(2200);
-	i2c->bit.data = i2c;
-	i2c->bit.setsda		= mga_gpio_setsda;
-	i2c->bit.setscl		= mga_gpio_setscl;
-	i2c->bit.getsda		= mga_gpio_getsda;
-	i2c->bit.getscl		= mga_gpio_getscl;
-
-	ret = i2c_bit_add_bus(&i2c->adapter);
+	bit = &i2c->bit;
+	bit->data = i2c;
+	bit->setsda = mga_gpio_setsda;
+	bit->setscl = mga_gpio_setscl;
+	bit->getsda = mga_gpio_getsda;
+	bit->getscl = mga_gpio_getscl;
+	bit->udelay = 10;
+	bit->timeout = usecs_to_jiffies(2200);
+
+	adapter = &i2c->adapter;
+	adapter->owner = THIS_MODULE;
+	adapter->algo_data = bit;
+	adapter->dev.parent = dev->dev;
+	snprintf(adapter->name, sizeof(adapter->name), "mga i2c");
+	i2c_set_adapdata(adapter, i2c);
+
+	ret = i2c_bit_add_bus(adapter);
 	if (ret)
-		return ret;
-
-	return drmm_add_action_or_reset(dev, mgag200_i2c_release, i2c);
-}
-
-struct i2c_adapter *mgag200_ddc_create(struct mga_device *mdev)
-{
-	struct mga_i2c_chan *i2c;
-	struct drm_device *dev = &mdev->base;
-	int ret;
-
-	i2c = drmm_kzalloc(dev, sizeof(*i2c), GFP_KERNEL);
-	if (!i2c)
-		return ERR_PTR(-ENOMEM);
+		return ERR_PTR(ret);
 
-	ret = mgag200_i2c_init(mdev, i2c);
+	ret = drmm_add_action_or_reset(dev, mgag200_i2c_release, i2c);
 	if (ret)
 		return ERR_PTR(ret);
 
-	return &i2c->adapter;
+	return adapter;
 }
-- 
2.45.0


  parent reply	other threads:[~2024-05-13 12:56 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-13 12:51 [PATCH 00/10] drm/mgag200: Refactor DDC code Thomas Zimmermann
2024-05-13 12:51 ` [PATCH 01/10] drm/mgag200: Set DDC timeout in milliseconds Thomas Zimmermann
2024-05-13 12:51 ` [PATCH 02/10] drm/mgag200: Bind I2C lifetime to DRM device Thomas Zimmermann
2024-05-13 12:51 ` [PATCH 03/10] drm/mgag200: Store pointer to struct mga_device in struct mga_i2c_chan Thomas Zimmermann
2024-05-13 12:51 ` [PATCH 04/10] drm/mgag200: Allocate instance of struct mga_i2c_chan dynamically Thomas Zimmermann
2024-05-13 12:51 ` Thomas Zimmermann [this message]
2024-05-13 12:51 ` [PATCH 06/10] drm/mgag200: Replace struct mga_i2c_chan with struct mgag200_ddc Thomas Zimmermann
2024-05-13 12:51 ` [PATCH 07/10] drm/mgag200: Rename mgag200_i2c.c to mgag200_ddc.c Thomas Zimmermann
2024-05-13 12:51 ` [PATCH 08/10] drm/mgag200: Rename struct i2c_algo_bit_data callbacks Thomas Zimmermann
2024-05-13 12:51 ` [PATCH 09/10] drm/mgag200: Acquire I/O-register lock in DDC code Thomas Zimmermann
2024-05-13 12:51 ` [PATCH 10/10] drm/mgag200: Use drm_connector_helper_get_modes() Thomas Zimmermann
2024-05-16  9:14 ` [PATCH 00/10] drm/mgag200: Refactor DDC code Jocelyn Falempe
2024-05-16 10:50   ` Thomas Zimmermann

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=20240513125620.6337-6-tzimmermann@suse.de \
    --to=tzimmermann@suse.de \
    --cc=airlied@gmail.com \
    --cc=airlied@redhat.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jani.nikula@linux.intel.com \
    --cc=jfalempe@redhat.com \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.