| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Driver for Quantek QT1010 silicon tuner |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2006 Antti Palosaari <crope@iki.fi> |
|---|
| 5 | 6 | * Aapo Tahkola <aet@rasterburn.org> |
|---|
| 6 | | - * |
|---|
| 7 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 8 | | - * it under the terms of the GNU General Public License as published by |
|---|
| 9 | | - * the Free Software Foundation; either version 2 of the License, or |
|---|
| 10 | | - * (at your option) any later version. |
|---|
| 11 | | - * |
|---|
| 12 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 13 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 14 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 15 | | - * GNU General Public License for more details. |
|---|
| 16 | 7 | */ |
|---|
| 17 | 8 | #include "qt1010.h" |
|---|
| 18 | 9 | #include "qt1010_priv.h" |
|---|
| .. | .. |
|---|
| 224 | 215 | static int qt1010_init_meas1(struct qt1010_priv *priv, |
|---|
| 225 | 216 | u8 oper, u8 reg, u8 reg_init_val, u8 *retval) |
|---|
| 226 | 217 | { |
|---|
| 227 | | - u8 i, val1, uninitialized_var(val2); |
|---|
| 218 | + u8 i, val1, val2; |
|---|
| 228 | 219 | int err; |
|---|
| 229 | 220 | |
|---|
| 230 | 221 | qt1010_i2c_oper_t i2c_data[] = { |
|---|
| 231 | 222 | { QT1010_WR, reg, reg_init_val }, |
|---|
| 232 | 223 | { QT1010_WR, 0x1e, 0x00 }, |
|---|
| 233 | 224 | { QT1010_WR, 0x1e, oper }, |
|---|
| 234 | | - { QT1010_RD, reg, 0xff } |
|---|
| 235 | 225 | }; |
|---|
| 236 | 226 | |
|---|
| 237 | 227 | for (i = 0; i < ARRAY_SIZE(i2c_data); i++) { |
|---|
| 238 | | - if (i2c_data[i].oper == QT1010_WR) { |
|---|
| 239 | | - err = qt1010_writereg(priv, i2c_data[i].reg, |
|---|
| 240 | | - i2c_data[i].val); |
|---|
| 241 | | - } else { |
|---|
| 242 | | - err = qt1010_readreg(priv, i2c_data[i].reg, &val2); |
|---|
| 243 | | - } |
|---|
| 244 | | - if (err) return err; |
|---|
| 228 | + err = qt1010_writereg(priv, i2c_data[i].reg, |
|---|
| 229 | + i2c_data[i].val); |
|---|
| 230 | + if (err) |
|---|
| 231 | + return err; |
|---|
| 245 | 232 | } |
|---|
| 246 | 233 | |
|---|
| 234 | + err = qt1010_readreg(priv, reg, &val2); |
|---|
| 235 | + if (err) |
|---|
| 236 | + return err; |
|---|
| 247 | 237 | do { |
|---|
| 248 | 238 | val1 = val2; |
|---|
| 249 | 239 | err = qt1010_readreg(priv, reg, &val2); |
|---|
| 250 | | - if (err) return err; |
|---|
| 240 | + if (err) |
|---|
| 241 | + return err; |
|---|
| 242 | + |
|---|
| 251 | 243 | dev_dbg(&priv->i2c->dev, "%s: compare reg:%02x %02x %02x\n", |
|---|
| 252 | 244 | __func__, reg, val1, val2); |
|---|
| 253 | 245 | } while (val1 != val2); |
|---|
| .. | .. |
|---|
| 259 | 251 | static int qt1010_init_meas2(struct qt1010_priv *priv, |
|---|
| 260 | 252 | u8 reg_init_val, u8 *retval) |
|---|
| 261 | 253 | { |
|---|
| 262 | | - u8 i, uninitialized_var(val); |
|---|
| 254 | + u8 i, val = 0xff; |
|---|
| 263 | 255 | int err; |
|---|
| 264 | 256 | qt1010_i2c_oper_t i2c_data[] = { |
|---|
| 265 | 257 | { QT1010_WR, 0x07, reg_init_val }, |
|---|
| .. | .. |
|---|
| 270 | 262 | { QT1010_WR, 0x1e, 0x00 }, |
|---|
| 271 | 263 | { QT1010_WR, 0x22, 0xff } |
|---|
| 272 | 264 | }; |
|---|
| 265 | + |
|---|
| 273 | 266 | for (i = 0; i < ARRAY_SIZE(i2c_data); i++) { |
|---|
| 274 | 267 | if (i2c_data[i].oper == QT1010_WR) { |
|---|
| 275 | 268 | err = qt1010_writereg(priv, i2c_data[i].reg, |
|---|
| .. | .. |
|---|
| 277 | 270 | } else { |
|---|
| 278 | 271 | err = qt1010_readreg(priv, i2c_data[i].reg, &val); |
|---|
| 279 | 272 | } |
|---|
| 280 | | - if (err) return err; |
|---|
| 273 | + if (err) |
|---|
| 274 | + return err; |
|---|
| 281 | 275 | } |
|---|
| 282 | 276 | *retval = val; |
|---|
| 283 | 277 | return 0; |
|---|
| .. | .. |
|---|
| 351 | 345 | else |
|---|
| 352 | 346 | valptr = &tmpval; |
|---|
| 353 | 347 | |
|---|
| 354 | | - BUG_ON(i >= ARRAY_SIZE(i2c_data) - 1); |
|---|
| 355 | | - |
|---|
| 356 | | - err = qt1010_init_meas1(priv, i2c_data[i+1].reg, |
|---|
| 357 | | - i2c_data[i].reg, |
|---|
| 358 | | - i2c_data[i].val, valptr); |
|---|
| 348 | + if (i >= ARRAY_SIZE(i2c_data) - 1) |
|---|
| 349 | + err = -EIO; |
|---|
| 350 | + else |
|---|
| 351 | + err = qt1010_init_meas1(priv, i2c_data[i + 1].reg, |
|---|
| 352 | + i2c_data[i].reg, |
|---|
| 353 | + i2c_data[i].val, valptr); |
|---|
| 359 | 354 | i++; |
|---|
| 360 | 355 | break; |
|---|
| 361 | 356 | } |
|---|
| .. | .. |
|---|
| 446 | 441 | fe->tuner_priv = priv; |
|---|
| 447 | 442 | return fe; |
|---|
| 448 | 443 | } |
|---|
| 449 | | -EXPORT_SYMBOL(qt1010_attach); |
|---|
| 444 | +EXPORT_SYMBOL_GPL(qt1010_attach); |
|---|
| 450 | 445 | |
|---|
| 451 | 446 | MODULE_DESCRIPTION("Quantek QT1010 silicon tuner driver"); |
|---|
| 452 | 447 | MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>"); |
|---|