linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Linus Walleij <linus.walleij@linaro.org>
To: Mauro Carvalho Chehab <mchehab@kernel.org>, linux-media@vger.kernel.org
Cc: Linus Walleij <linus.walleij@linaro.org>,
	linux-gpio@vger.kernel.org,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>
Subject: [PATCH] media: em28xx: Drop abuse of gpiolib
Date: Wed, 11 Jan 2023 14:58:01 +0100	[thread overview]
Message-ID: <20230111135801.135824-1-linus.walleij@linaro.org> (raw)

The driver is issueing calls to the legacy gpio API from
<linux/gpio.h> to pull a LNA gpio line low or high.

The code as it stands can not work and does not make sense
since the GPIO number assigned to dvb->lna_gpio is only
in scope in this file and never assigned any valid GPIO
number, the driver has no way of asking for a proper GPIO
and will likely ask for GPIO 0, which will likely be wrong.

In one execution path dvb->lna_gpio is assigned some constants
to the local GPIO block which is not using gpiolib, adding
to the confusion.

Delete all use of gpiolib as it can't work. Leave the custom
(local) gpio handling around, as this is likely the only thing
that can actually work.

My guess is that this driver only worked on platforms that
for some reason does not enable CONFIG_GPIOLIB. It was likely
causing a bug on any platform enabling CONFIG_GPIOLIB.

If anyone knows how to fix this driver properly then tell
me.

Cc: linux-gpio@vger.kernel.org
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/media/usb/em28xx/em28xx-dvb.c | 32 ---------------------------
 1 file changed, 32 deletions(-)

diff --git a/drivers/media/usb/em28xx/em28xx-dvb.c b/drivers/media/usb/em28xx/em28xx-dvb.c
index 9fce59979e3b..57598e825135 100644
--- a/drivers/media/usb/em28xx/em28xx-dvb.c
+++ b/drivers/media/usb/em28xx/em28xx-dvb.c
@@ -29,7 +29,6 @@
 #include <media/dmxdev.h>
 #include <media/tuner.h>
 #include "tuner-simple.h"
-#include <linux/gpio.h>
 
 #include "lgdt330x.h"
 #include "lgdt3305.h"
@@ -727,28 +726,10 @@ static int em28xx_pctv_290e_set_lna(struct dvb_frontend *fe)
 	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
 	struct em28xx_i2c_bus *i2c_bus = fe->dvb->priv;
 	struct em28xx *dev = i2c_bus->dev;
-#ifdef CONFIG_GPIOLIB
-	struct em28xx_dvb *dvb = dev->dvb;
-	int ret;
-	unsigned long flags;
-
-	if (c->lna == 1)
-		flags = GPIOF_OUT_INIT_HIGH; /* enable LNA */
-	else
-		flags = GPIOF_OUT_INIT_LOW; /* disable LNA */
 
-	ret = gpio_request_one(dvb->lna_gpio, flags, NULL);
-	if (ret)
-		dev_err(&dev->intf->dev, "gpio request failed %d\n", ret);
-	else
-		gpio_free(dvb->lna_gpio);
-
-	return ret;
-#else
 	dev_warn(&dev->intf->dev, "%s: LNA control is disabled (lna=%u)\n",
 		 KBUILD_MODNAME, c->lna);
 	return 0;
-#endif
 }
 
 static int em28xx_pctv_292e_set_lna(struct dvb_frontend *fe)
@@ -1705,19 +1686,6 @@ static int em28xx_dvb_init(struct em28xx *dev)
 				goto out_free;
 			}
 
-#ifdef CONFIG_GPIOLIB
-			/* enable LNA for DVB-T, DVB-T2 and DVB-C */
-			result = gpio_request_one(dvb->lna_gpio,
-						  GPIOF_OUT_INIT_LOW, NULL);
-			if (result)
-				dev_err(&dev->intf->dev,
-					"gpio request failed %d\n",
-					result);
-			else
-				gpio_free(dvb->lna_gpio);
-
-			result = 0; /* continue even set LNA fails */
-#endif
 			dvb->fe[0]->ops.set_lna = em28xx_pctv_290e_set_lna;
 		}
 
-- 
2.34.1


             reply	other threads:[~2023-01-11 13:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-11 13:58 Linus Walleij [this message]
2023-01-11 18:49 ` [PATCH] media: em28xx: Drop abuse of gpiolib Dmitry Torokhov

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=20230111135801.135824-1-linus.walleij@linaro.org \
    --to=linus.walleij@linaro.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).