From patchwork Mon May 13 12:51:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Zimmermann X-Patchwork-Id: 13663432 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 147FCC25B10 for ; Mon, 13 May 2024 12:56:44 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2731510E767; Mon, 13 May 2024 12:56:34 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.b="x6qP68YY"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="EBRz8V4v"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="x6qP68YY"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="EBRz8V4v"; dkim-atps=neutral Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by gabe.freedesktop.org (Postfix) with ESMTPS id 94C1910E131 for ; Mon, 13 May 2024 12:56:30 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 3468F347B6; Mon, 13 May 2024 12:56:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1715604989; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rBfvWySSW7BzkxL6TjgI6jJqxqkro2cAulBTSZVWFNE=; b=x6qP68YYYQ9RWiW3yH4YrA7mVIm3yIPTh9b8ViGzblN/J5QPed/V0hYUFXP4833rLfTu6n FncOc5cqrKaJCkvdzRsvzHC/JrLKhzKY/Pu/Eoi4RkJ7O5E6+Ps4Fks3KOnnu5PZTq1OSq z918b0fxXnXYnutu0YuPdbj9p6e3mdY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1715604989; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rBfvWySSW7BzkxL6TjgI6jJqxqkro2cAulBTSZVWFNE=; b=EBRz8V4v6FJe9lATGA+bOijgmPGKeAIn/owiBHbFeC9wEmwIIzYofxSOZ7/uE3id8sB4oa l9D9fqe4hE/+xLAA== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1715604989; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rBfvWySSW7BzkxL6TjgI6jJqxqkro2cAulBTSZVWFNE=; b=x6qP68YYYQ9RWiW3yH4YrA7mVIm3yIPTh9b8ViGzblN/J5QPed/V0hYUFXP4833rLfTu6n FncOc5cqrKaJCkvdzRsvzHC/JrLKhzKY/Pu/Eoi4RkJ7O5E6+Ps4Fks3KOnnu5PZTq1OSq z918b0fxXnXYnutu0YuPdbj9p6e3mdY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1715604989; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rBfvWySSW7BzkxL6TjgI6jJqxqkro2cAulBTSZVWFNE=; b=EBRz8V4v6FJe9lATGA+bOijgmPGKeAIn/owiBHbFeC9wEmwIIzYofxSOZ7/uE3id8sB4oa l9D9fqe4hE/+xLAA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id EA65913A5C; Mon, 13 May 2024 12:56:28 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id mFG7N/wNQmZpfwAAD6G6ig (envelope-from ); Mon, 13 May 2024 12:56:28 +0000 From: Thomas Zimmermann 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 Subject: [PATCH 05/10] drm/mgag200: Inline mgag200_i2c_init() Date: Mon, 13 May 2024 14:51:10 +0200 Message-ID: <20240513125620.6337-6-tzimmermann@suse.de> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240513125620.6337-1-tzimmermann@suse.de> References: <20240513125620.6337-1-tzimmermann@suse.de> MIME-Version: 1.0 X-Spamd-Result: default: False [-6.80 / 50.00]; REPLY(-4.00)[]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.999]; MIME_GOOD(-0.10)[text/plain]; RCVD_COUNT_TWO(0.00)[2]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_TLS_ALL(0.00)[]; RCPT_COUNT_SEVEN(0.00)[8]; FUZZY_BLOCKED(0.00)[rspamd.com]; FREEMAIL_TO(0.00)[redhat.com,linux.intel.com,kernel.org,gmail.com]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; TO_DN_SOME(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com] X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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 --- 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; }