diff options
Diffstat (limited to 'drivers/media/tuners/xc4000.c')
-rw-r--r-- | drivers/media/tuners/xc4000.c | 84 |
1 files changed, 30 insertions, 54 deletions
diff --git a/drivers/media/tuners/xc4000.c b/drivers/media/tuners/xc4000.c index 219ebafae70f..57ded9ff3f04 100644 --- a/drivers/media/tuners/xc4000.c +++ b/drivers/media/tuners/xc4000.c @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * Driver for Xceive XC4000 "QAM/8VSB single chip tuner" * @@ -6,20 +7,6 @@ * Copyright (c) 2009 Devin Heitmueller <dheitmueller@kernellabs.com> * Copyright (c) 2009 Davide Ferri <d.ferri@zero11.it> * Copyright (c) 2010 Istvan Varga <istvan_v@mailbox.hu> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include <linux/module.h> @@ -31,11 +18,11 @@ #include <linux/mutex.h> #include <asm/unaligned.h> -#include "dvb_frontend.h" +#include <media/dvb_frontend.h> #include "xc4000.h" #include "tuner-i2c.h" -#include "tuner-xc2028-types.h" +#include "xc2028-types.h" static int debug; module_param(debug, int, 0644); @@ -43,14 +30,11 @@ MODULE_PARM_DESC(debug, "Debugging level (0 to 2, default: 0 (off))."); static int no_poweroff; module_param(no_poweroff, int, 0644); -MODULE_PARM_DESC(no_poweroff, "Power management (1: disabled, 2: enabled, " - "0 (default): use device-specific default mode)."); +MODULE_PARM_DESC(no_poweroff, "Power management (1: disabled, 2: enabled, 0 (default): use device-specific default mode)."); static int audio_std; module_param(audio_std, int, 0644); -MODULE_PARM_DESC(audio_std, "Audio standard. XC4000 audio decoder explicitly " - "needs to know what audio standard is needed for some video standards " - "with audio A2 or NICAM. The valid settings are a sum of:\n" +MODULE_PARM_DESC(audio_std, "Audio standard. XC4000 audio decoder explicitly needs to know what audio standard is needed for some video standards with audio A2 or NICAM. The valid settings are a sum of:\n" " 1: use NICAM/B or A2/B instead of NICAM/A or A2/A\n" " 2: use A2 instead of NICAM or BTSC\n" " 4: use SECAM/K3 instead of K1\n" @@ -60,8 +44,7 @@ MODULE_PARM_DESC(audio_std, "Audio standard. XC4000 audio decoder explicitly " static char firmware_name[30]; module_param_string(firmware_name, firmware_name, sizeof(firmware_name), 0); -MODULE_PARM_DESC(firmware_name, "Firmware file name. Allows overriding the " - "default firmware name."); +MODULE_PARM_DESC(firmware_name, "Firmware file name. Allows overriding the default firmware name."); static DEFINE_MUTEX(xc4000_list_mutex); static LIST_HEAD(hybrid_tuner_instance_list); @@ -290,8 +273,7 @@ static int xc4000_tuner_reset(struct dvb_frontend *fe) return -EREMOTEIO; } } else { - printk(KERN_ERR "xc4000: no tuner reset callback function, " - "fatal\n"); + printk(KERN_ERR "xc4000: no tuner reset callback function, fatal\n"); return -EINVAL; } return 0; @@ -300,15 +282,13 @@ static int xc4000_tuner_reset(struct dvb_frontend *fe) static int xc_write_reg(struct xc4000_priv *priv, u16 regAddr, u16 i2cData) { u8 buf[4]; - int result; buf[0] = (regAddr >> 8) & 0xFF; buf[1] = regAddr & 0xFF; buf[2] = (i2cData >> 8) & 0xFF; buf[3] = i2cData & 0xFF; - result = xc_send_i2c_data(priv, buf, 4); - return result; + return xc_send_i2c_data(priv, buf, 4); } static int xc_load_i2c_sequence(struct dvb_frontend *fe, const u8 *i2c_sequence) @@ -407,8 +387,8 @@ static int xc_set_rf_frequency(struct xc4000_priv *priv, u32 freq_hz) dprintk(1, "%s(%u)\n", __func__, freq_hz); - if ((freq_hz > xc4000_tuner_ops.info.frequency_max) || - (freq_hz < xc4000_tuner_ops.info.frequency_min)) + if ((freq_hz > xc4000_tuner_ops.info.frequency_max_hz) || + (freq_hz < xc4000_tuner_ops.info.frequency_min_hz)) return -EINVAL; freq_code = (u16)(freq_hz / 15625); @@ -679,8 +659,7 @@ static int seek_firmware(struct dvb_frontend *fe, unsigned int type, if (best_nr_diffs > 0U) { printk(KERN_WARNING - "Selecting best matching firmware (%u bits differ) for " - "type=(%x), id %016llx:\n", + "Selecting best matching firmware (%u bits differ) for type=(%x), id %016llx:\n", best_nr_diffs, type, (unsigned long long)*id); i = best_i; } @@ -800,8 +779,7 @@ static int xc4000_fwupload(struct dvb_frontend *fe) n++; if (n >= n_array) { - printk(KERN_ERR "More firmware images in file than " - "were expected!\n"); + printk(KERN_ERR "More firmware images in file than were expected!\n"); goto corrupt; } @@ -826,13 +804,13 @@ static int xc4000_fwupload(struct dvb_frontend *fe) p += sizeof(size); if (!size || size > endp - p) { - printk(KERN_ERR "Firmware type (%x), id %llx is corrupted (size=%d, expected %d)\n", + printk(KERN_ERR "Firmware type (%x), id %llx is corrupted (size=%zd, expected %d)\n", type, (unsigned long long)id, - (unsigned)(endp - p), size); + endp - p, size); goto corrupt; } - priv->firm[n].ptr = kzalloc(size, GFP_KERNEL); + priv->firm[n].ptr = kmemdup(p, size, GFP_KERNEL); if (priv->firm[n].ptr == NULL) { printk(KERN_ERR "Not enough memory to load firmware file.\n"); rc = -ENOMEM; @@ -846,7 +824,6 @@ static int xc4000_fwupload(struct dvb_frontend *fe) type, (unsigned long long)id, size); } - memcpy(priv->firm[n].ptr, p, size); priv->firm[n].type = type; priv->firm[n].id = id; priv->firm[n].size = size; @@ -1047,7 +1024,10 @@ skip_std_specific: dprintk(1, "load scode failed %d\n", rc); check_device: - rc = xc4000_readreg(priv, XREG_PRODUCT_ID, &hwmodel); + if (xc4000_readreg(priv, XREG_PRODUCT_ID, &hwmodel) < 0) { + printk(KERN_ERR "Unable to read tuner registers.\n"); + goto fail; + } if (xc_get_version(priv, &hw_major, &hw_minor, &fw_major, &fw_minor) != 0) { @@ -1055,8 +1035,7 @@ check_device: goto fail; } - dprintk(1, "Device is Xceive %d version %d.%d, " - "firmware version %d.%d\n", + dprintk(1, "Device is Xceive %d version %d.%d, firmware version %d.%d\n", hwmodel, hw_major, hw_minor, fw_major, fw_minor); /* Check firmware version against what we downloaded. */ @@ -1076,8 +1055,7 @@ check_device: } else if (priv->hwmodel == 0 || priv->hwmodel != hwmodel || priv->hwvers != ((hw_major << 8) | hw_minor)) { printk(KERN_WARNING - "Read invalid device hardware information - tuner " - "hung?\n"); + "Read invalid device hardware information - tuner hung?\n"); goto fail; } @@ -1481,8 +1459,8 @@ static int xc4000_get_signal(struct dvb_frontend *fe, u16 *strength) if (rc < 0) goto ret; - /* Informations from real testing of DVB-T and radio part, - coeficient for one dB is 0xff. + /* Information from real testing of DVB-T and radio part, + coefficient for one dB is 0xff. */ tuner_dbg("Signal strength: -%ddB (%05d)\n", value >> 8, value); @@ -1508,7 +1486,7 @@ static int xc4000_get_signal(struct dvb_frontend *fe, u16 *strength) if (value >= 0x2000) { value = 0; } else { - value = ~value << 3; + value = (~value << 3) & 0xffff; } goto ret; @@ -1627,7 +1605,7 @@ static int xc4000_init(struct dvb_frontend *fe) return 0; } -static int xc4000_release(struct dvb_frontend *fe) +static void xc4000_release(struct dvb_frontend *fe) { struct xc4000_priv *priv = fe->tuner_priv; @@ -1641,16 +1619,14 @@ static int xc4000_release(struct dvb_frontend *fe) mutex_unlock(&xc4000_list_mutex); fe->tuner_priv = NULL; - - return 0; } static const struct dvb_tuner_ops xc4000_tuner_ops = { .info = { - .name = "Xceive XC4000", - .frequency_min = 1000000, - .frequency_max = 1023000000, - .frequency_step = 50000, + .name = "Xceive XC4000", + .frequency_min_hz = 1 * MHz, + .frequency_max_hz = 1023 * MHz, + .frequency_step_hz = 50 * kHz, }, .release = xc4000_release, @@ -1766,7 +1742,7 @@ fail2: xc4000_release(fe); return NULL; } -EXPORT_SYMBOL(xc4000_attach); +EXPORT_SYMBOL_GPL(xc4000_attach); MODULE_AUTHOR("Steven Toth, Davide Ferri"); MODULE_DESCRIPTION("Xceive xc4000 silicon tuner driver"); |