Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[media] e4000: various small changes

* Rename device state from 's' to 'dev'.
* Move single include to driver private header.
* Change error handling type of each function to one I tend use
nowadays.
* Remove dummy register write from init. Even Windows driver does this
multiple times remove it as I have never seen any I2C errors.
* Define I2C client pointer for each function and use it.
* Do not clean tuner ops during driver remove - not needed.
* Disable sysfs device bind / unbind. We are not allowed manually
bind / unbind device from the driver currently.
* Rename some other variables.

Signed-off-by: Antti Palosaari <crope@iki.fi>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

authored by

Antti Palosaari and committed by
Mauro Carvalho Chehab
f8b9b871 0e3a71c3

+178 -186
+175 -183
drivers/media/tuners/e4000.c
··· 19 19 */ 20 20 21 21 #include "e4000_priv.h" 22 - #include <linux/math64.h> 23 22 24 23 static int e4000_init(struct dvb_frontend *fe) 25 24 { 26 - struct e4000 *s = fe->tuner_priv; 25 + struct e4000_dev *dev = fe->tuner_priv; 26 + struct i2c_client *client = dev->client; 27 27 int ret; 28 28 29 - dev_dbg(&s->client->dev, "\n"); 30 - 31 - /* dummy I2C to ensure I2C wakes up */ 32 - ret = regmap_write(s->regmap, 0x02, 0x40); 29 + dev_dbg(&client->dev, "\n"); 33 30 34 31 /* reset */ 35 - ret = regmap_write(s->regmap, 0x00, 0x01); 32 + ret = regmap_write(dev->regmap, 0x00, 0x01); 36 33 if (ret) 37 34 goto err; 38 35 39 36 /* disable output clock */ 40 - ret = regmap_write(s->regmap, 0x06, 0x00); 37 + ret = regmap_write(dev->regmap, 0x06, 0x00); 41 38 if (ret) 42 39 goto err; 43 40 44 - ret = regmap_write(s->regmap, 0x7a, 0x96); 41 + ret = regmap_write(dev->regmap, 0x7a, 0x96); 45 42 if (ret) 46 43 goto err; 47 44 48 45 /* configure gains */ 49 - ret = regmap_bulk_write(s->regmap, 0x7e, "\x01\xfe", 2); 46 + ret = regmap_bulk_write(dev->regmap, 0x7e, "\x01\xfe", 2); 50 47 if (ret) 51 48 goto err; 52 49 53 - ret = regmap_write(s->regmap, 0x82, 0x00); 50 + ret = regmap_write(dev->regmap, 0x82, 0x00); 54 51 if (ret) 55 52 goto err; 56 53 57 - ret = regmap_write(s->regmap, 0x24, 0x05); 54 + ret = regmap_write(dev->regmap, 0x24, 0x05); 58 55 if (ret) 59 56 goto err; 60 57 61 - ret = regmap_bulk_write(s->regmap, 0x87, "\x20\x01", 2); 58 + ret = regmap_bulk_write(dev->regmap, 0x87, "\x20\x01", 2); 62 59 if (ret) 63 60 goto err; 64 61 65 - ret = regmap_bulk_write(s->regmap, 0x9f, "\x7f\x07", 2); 62 + ret = regmap_bulk_write(dev->regmap, 0x9f, "\x7f\x07", 2); 66 63 if (ret) 67 64 goto err; 68 65 69 66 /* DC offset control */ 70 - ret = regmap_write(s->regmap, 0x2d, 0x1f); 67 + ret = regmap_write(dev->regmap, 0x2d, 0x1f); 71 68 if (ret) 72 69 goto err; 73 70 74 - ret = regmap_bulk_write(s->regmap, 0x70, "\x01\x01", 2); 71 + ret = regmap_bulk_write(dev->regmap, 0x70, "\x01\x01", 2); 75 72 if (ret) 76 73 goto err; 77 74 78 75 /* gain control */ 79 - ret = regmap_write(s->regmap, 0x1a, 0x17); 76 + ret = regmap_write(dev->regmap, 0x1a, 0x17); 80 77 if (ret) 81 78 goto err; 82 79 83 - ret = regmap_write(s->regmap, 0x1f, 0x1a); 80 + ret = regmap_write(dev->regmap, 0x1f, 0x1a); 84 81 if (ret) 85 82 goto err; 86 83 87 - s->active = true; 84 + dev->active = true; 85 + 86 + return 0; 88 87 err: 89 - if (ret) 90 - dev_dbg(&s->client->dev, "failed=%d\n", ret); 91 - 88 + dev_dbg(&client->dev, "failed=%d\n", ret); 92 89 return ret; 93 90 } 94 91 95 92 static int e4000_sleep(struct dvb_frontend *fe) 96 93 { 97 - struct e4000 *s = fe->tuner_priv; 94 + struct e4000_dev *dev = fe->tuner_priv; 95 + struct i2c_client *client = dev->client; 98 96 int ret; 99 97 100 - dev_dbg(&s->client->dev, "\n"); 98 + dev_dbg(&client->dev, "\n"); 101 99 102 - s->active = false; 100 + dev->active = false; 103 101 104 - ret = regmap_write(s->regmap, 0x00, 0x00); 102 + ret = regmap_write(dev->regmap, 0x00, 0x00); 105 103 if (ret) 106 104 goto err; 107 - err: 108 - if (ret) 109 - dev_dbg(&s->client->dev, "failed=%d\n", ret); 110 105 106 + return 0; 107 + err: 108 + dev_dbg(&client->dev, "failed=%d\n", ret); 111 109 return ret; 112 110 } 113 111 114 112 static int e4000_set_params(struct dvb_frontend *fe) 115 113 { 116 - struct e4000 *s = fe->tuner_priv; 114 + struct e4000_dev *dev = fe->tuner_priv; 115 + struct i2c_client *client = dev->client; 117 116 struct dtv_frontend_properties *c = &fe->dtv_property_cache; 118 117 int ret, i; 119 118 unsigned int div_n, k, k_cw, div_out; 120 119 u64 f_vco; 121 120 u8 buf[5], i_data[4], q_data[4]; 122 121 123 - dev_dbg(&s->client->dev, 124 - "delivery_system=%d frequency=%u bandwidth_hz=%u\n", 125 - c->delivery_system, c->frequency, c->bandwidth_hz); 122 + dev_dbg(&client->dev, 123 + "delivery_system=%d frequency=%u bandwidth_hz=%u\n", 124 + c->delivery_system, c->frequency, c->bandwidth_hz); 126 125 127 126 /* gain control manual */ 128 - ret = regmap_write(s->regmap, 0x1a, 0x00); 127 + ret = regmap_write(dev->regmap, 0x1a, 0x00); 129 128 if (ret) 130 129 goto err; 131 130 ··· 147 148 if (c->frequency <= e4000_pll_lut[i].freq) 148 149 break; 149 150 } 150 - 151 151 if (i == ARRAY_SIZE(e4000_pll_lut)) { 152 152 ret = -EINVAL; 153 153 goto err; 154 154 } 155 155 156 - #define F_REF s->clock 156 + #define F_REF dev->clk 157 157 div_out = e4000_pll_lut[i].div_out; 158 158 f_vco = (u64) c->frequency * div_out; 159 159 /* calculate PLL integer and fractional control word */ 160 160 div_n = div_u64_rem(f_vco, F_REF, &k); 161 161 k_cw = div_u64((u64) k * 0x10000, F_REF); 162 162 163 - dev_dbg(&s->client->dev, 163 + dev_dbg(&client->dev, 164 164 "frequency=%u f_vco=%llu F_REF=%u div_n=%u k=%u k_cw=%04x div_out=%u\n", 165 165 c->frequency, f_vco, F_REF, div_n, k, k_cw, div_out); 166 166 ··· 168 170 buf[2] = (k_cw >> 8) & 0xff; 169 171 buf[3] = 0x00; 170 172 buf[4] = e4000_pll_lut[i].div_out_reg; 171 - ret = regmap_bulk_write(s->regmap, 0x09, buf, 5); 173 + ret = regmap_bulk_write(dev->regmap, 0x09, buf, 5); 172 174 if (ret) 173 175 goto err; 174 176 ··· 177 179 if (c->frequency <= e400_lna_filter_lut[i].freq) 178 180 break; 179 181 } 180 - 181 182 if (i == ARRAY_SIZE(e400_lna_filter_lut)) { 182 183 ret = -EINVAL; 183 184 goto err; 184 185 } 185 186 186 - ret = regmap_write(s->regmap, 0x10, e400_lna_filter_lut[i].val); 187 + ret = regmap_write(dev->regmap, 0x10, e400_lna_filter_lut[i].val); 187 188 if (ret) 188 189 goto err; 189 190 ··· 191 194 if (c->bandwidth_hz <= e4000_if_filter_lut[i].freq) 192 195 break; 193 196 } 194 - 195 197 if (i == ARRAY_SIZE(e4000_if_filter_lut)) { 196 198 ret = -EINVAL; 197 199 goto err; ··· 199 203 buf[0] = e4000_if_filter_lut[i].reg11_val; 200 204 buf[1] = e4000_if_filter_lut[i].reg12_val; 201 205 202 - ret = regmap_bulk_write(s->regmap, 0x11, buf, 2); 206 + ret = regmap_bulk_write(dev->regmap, 0x11, buf, 2); 203 207 if (ret) 204 208 goto err; 205 209 ··· 208 212 if (c->frequency <= e4000_band_lut[i].freq) 209 213 break; 210 214 } 211 - 212 215 if (i == ARRAY_SIZE(e4000_band_lut)) { 213 216 ret = -EINVAL; 214 217 goto err; 215 218 } 216 219 217 - ret = regmap_write(s->regmap, 0x07, e4000_band_lut[i].reg07_val); 220 + ret = regmap_write(dev->regmap, 0x07, e4000_band_lut[i].reg07_val); 218 221 if (ret) 219 222 goto err; 220 223 221 - ret = regmap_write(s->regmap, 0x78, e4000_band_lut[i].reg78_val); 224 + ret = regmap_write(dev->regmap, 0x78, e4000_band_lut[i].reg78_val); 222 225 if (ret) 223 226 goto err; 224 227 225 228 /* DC offset */ 226 229 for (i = 0; i < 4; i++) { 227 230 if (i == 0) 228 - ret = regmap_bulk_write(s->regmap, 0x15, "\x00\x7e\x24", 3); 231 + ret = regmap_bulk_write(dev->regmap, 0x15, "\x00\x7e\x24", 3); 229 232 else if (i == 1) 230 - ret = regmap_bulk_write(s->regmap, 0x15, "\x00\x7f", 2); 233 + ret = regmap_bulk_write(dev->regmap, 0x15, "\x00\x7f", 2); 231 234 else if (i == 2) 232 - ret = regmap_bulk_write(s->regmap, 0x15, "\x01", 1); 235 + ret = regmap_bulk_write(dev->regmap, 0x15, "\x01", 1); 233 236 else 234 - ret = regmap_bulk_write(s->regmap, 0x16, "\x7e", 1); 237 + ret = regmap_bulk_write(dev->regmap, 0x16, "\x7e", 1); 235 238 236 239 if (ret) 237 240 goto err; 238 241 239 - ret = regmap_write(s->regmap, 0x29, 0x01); 242 + ret = regmap_write(dev->regmap, 0x29, 0x01); 240 243 if (ret) 241 244 goto err; 242 245 243 - ret = regmap_bulk_read(s->regmap, 0x2a, buf, 3); 246 + ret = regmap_bulk_read(dev->regmap, 0x2a, buf, 3); 244 247 if (ret) 245 248 goto err; 246 249 ··· 250 255 swap(q_data[2], q_data[3]); 251 256 swap(i_data[2], i_data[3]); 252 257 253 - ret = regmap_bulk_write(s->regmap, 0x50, q_data, 4); 258 + ret = regmap_bulk_write(dev->regmap, 0x50, q_data, 4); 254 259 if (ret) 255 260 goto err; 256 261 257 - ret = regmap_bulk_write(s->regmap, 0x60, i_data, 4); 262 + ret = regmap_bulk_write(dev->regmap, 0x60, i_data, 4); 258 263 if (ret) 259 264 goto err; 260 265 261 266 /* gain control auto */ 262 - ret = regmap_write(s->regmap, 0x1a, 0x17); 267 + ret = regmap_write(dev->regmap, 0x1a, 0x17); 263 268 if (ret) 264 269 goto err; 265 - err: 266 - if (ret) 267 - dev_dbg(&s->client->dev, "failed=%d\n", ret); 268 270 271 + return 0; 272 + err: 273 + dev_dbg(&client->dev, "failed=%d\n", ret); 269 274 return ret; 270 275 } 271 276 272 277 static int e4000_get_if_frequency(struct dvb_frontend *fe, u32 *frequency) 273 278 { 274 - struct e4000 *s = fe->tuner_priv; 279 + struct e4000_dev *dev = fe->tuner_priv; 280 + struct i2c_client *client = dev->client; 275 281 276 - dev_dbg(&s->client->dev, "\n"); 282 + dev_dbg(&client->dev, "\n"); 277 283 278 284 *frequency = 0; /* Zero-IF */ 279 285 ··· 284 288 #if IS_ENABLED(CONFIG_VIDEO_V4L2) 285 289 static int e4000_set_lna_gain(struct dvb_frontend *fe) 286 290 { 287 - struct e4000 *s = fe->tuner_priv; 291 + struct e4000_dev *dev = fe->tuner_priv; 292 + struct i2c_client *client = dev->client; 288 293 int ret; 289 294 u8 u8tmp; 290 295 291 - dev_dbg(&s->client->dev, "lna auto=%d->%d val=%d->%d\n", 292 - s->lna_gain_auto->cur.val, s->lna_gain_auto->val, 293 - s->lna_gain->cur.val, s->lna_gain->val); 296 + dev_dbg(&client->dev, "lna auto=%d->%d val=%d->%d\n", 297 + dev->lna_gain_auto->cur.val, dev->lna_gain_auto->val, 298 + dev->lna_gain->cur.val, dev->lna_gain->val); 294 299 295 - if (s->lna_gain_auto->val && s->if_gain_auto->cur.val) 300 + if (dev->lna_gain_auto->val && dev->if_gain_auto->cur.val) 296 301 u8tmp = 0x17; 297 - else if (s->lna_gain_auto->val) 302 + else if (dev->lna_gain_auto->val) 298 303 u8tmp = 0x19; 299 - else if (s->if_gain_auto->cur.val) 304 + else if (dev->if_gain_auto->cur.val) 300 305 u8tmp = 0x16; 301 306 else 302 307 u8tmp = 0x10; 303 308 304 - ret = regmap_write(s->regmap, 0x1a, u8tmp); 309 + ret = regmap_write(dev->regmap, 0x1a, u8tmp); 305 310 if (ret) 306 311 goto err; 307 312 308 - if (s->lna_gain_auto->val == false) { 309 - ret = regmap_write(s->regmap, 0x14, s->lna_gain->val); 313 + if (dev->lna_gain_auto->val == false) { 314 + ret = regmap_write(dev->regmap, 0x14, dev->lna_gain->val); 310 315 if (ret) 311 316 goto err; 312 317 } 313 - err: 314 - if (ret) 315 - dev_dbg(&s->client->dev, "failed=%d\n", ret); 316 318 319 + return 0; 320 + err: 321 + dev_dbg(&client->dev, "failed=%d\n", ret); 317 322 return ret; 318 323 } 319 324 320 325 static int e4000_set_mixer_gain(struct dvb_frontend *fe) 321 326 { 322 - struct e4000 *s = fe->tuner_priv; 327 + struct e4000_dev *dev = fe->tuner_priv; 328 + struct i2c_client *client = dev->client; 323 329 int ret; 324 330 u8 u8tmp; 325 331 326 - dev_dbg(&s->client->dev, "mixer auto=%d->%d val=%d->%d\n", 327 - s->mixer_gain_auto->cur.val, s->mixer_gain_auto->val, 328 - s->mixer_gain->cur.val, s->mixer_gain->val); 332 + dev_dbg(&client->dev, "mixer auto=%d->%d val=%d->%d\n", 333 + dev->mixer_gain_auto->cur.val, dev->mixer_gain_auto->val, 334 + dev->mixer_gain->cur.val, dev->mixer_gain->val); 329 335 330 - if (s->mixer_gain_auto->val) 336 + if (dev->mixer_gain_auto->val) 331 337 u8tmp = 0x15; 332 338 else 333 339 u8tmp = 0x14; 334 340 335 - ret = regmap_write(s->regmap, 0x20, u8tmp); 341 + ret = regmap_write(dev->regmap, 0x20, u8tmp); 336 342 if (ret) 337 343 goto err; 338 344 339 - if (s->mixer_gain_auto->val == false) { 340 - ret = regmap_write(s->regmap, 0x15, s->mixer_gain->val); 345 + if (dev->mixer_gain_auto->val == false) { 346 + ret = regmap_write(dev->regmap, 0x15, dev->mixer_gain->val); 341 347 if (ret) 342 348 goto err; 343 349 } 344 - err: 345 - if (ret) 346 - dev_dbg(&s->client->dev, "failed=%d\n", ret); 347 350 351 + return 0; 352 + err: 353 + dev_dbg(&client->dev, "failed=%d\n", ret); 348 354 return ret; 349 355 } 350 356 351 357 static int e4000_set_if_gain(struct dvb_frontend *fe) 352 358 { 353 - struct e4000 *s = fe->tuner_priv; 359 + struct e4000_dev *dev = fe->tuner_priv; 360 + struct i2c_client *client = dev->client; 354 361 int ret; 355 362 u8 buf[2]; 356 363 u8 u8tmp; 357 364 358 - dev_dbg(&s->client->dev, "if auto=%d->%d val=%d->%d\n", 359 - s->if_gain_auto->cur.val, s->if_gain_auto->val, 360 - s->if_gain->cur.val, s->if_gain->val); 365 + dev_dbg(&client->dev, "if auto=%d->%d val=%d->%d\n", 366 + dev->if_gain_auto->cur.val, dev->if_gain_auto->val, 367 + dev->if_gain->cur.val, dev->if_gain->val); 361 368 362 - if (s->if_gain_auto->val && s->lna_gain_auto->cur.val) 369 + if (dev->if_gain_auto->val && dev->lna_gain_auto->cur.val) 363 370 u8tmp = 0x17; 364 - else if (s->lna_gain_auto->cur.val) 371 + else if (dev->lna_gain_auto->cur.val) 365 372 u8tmp = 0x19; 366 - else if (s->if_gain_auto->val) 373 + else if (dev->if_gain_auto->val) 367 374 u8tmp = 0x16; 368 375 else 369 376 u8tmp = 0x10; 370 377 371 - ret = regmap_write(s->regmap, 0x1a, u8tmp); 378 + ret = regmap_write(dev->regmap, 0x1a, u8tmp); 372 379 if (ret) 373 380 goto err; 374 381 375 - if (s->if_gain_auto->val == false) { 376 - buf[0] = e4000_if_gain_lut[s->if_gain->val].reg16_val; 377 - buf[1] = e4000_if_gain_lut[s->if_gain->val].reg17_val; 378 - ret = regmap_bulk_write(s->regmap, 0x16, buf, 2); 382 + if (dev->if_gain_auto->val == false) { 383 + buf[0] = e4000_if_gain_lut[dev->if_gain->val].reg16_val; 384 + buf[1] = e4000_if_gain_lut[dev->if_gain->val].reg17_val; 385 + ret = regmap_bulk_write(dev->regmap, 0x16, buf, 2); 379 386 if (ret) 380 387 goto err; 381 388 } 382 - err: 383 - if (ret) 384 - dev_dbg(&s->client->dev, "failed=%d\n", ret); 385 389 390 + return 0; 391 + err: 392 + dev_dbg(&client->dev, "failed=%d\n", ret); 386 393 return ret; 387 394 } 388 395 389 396 static int e4000_pll_lock(struct dvb_frontend *fe) 390 397 { 391 - struct e4000 *s = fe->tuner_priv; 398 + struct e4000_dev *dev = fe->tuner_priv; 399 + struct i2c_client *client = dev->client; 392 400 int ret; 393 - unsigned int utmp; 401 + unsigned int uitmp; 394 402 395 - ret = regmap_read(s->regmap, 0x07, &utmp); 403 + ret = regmap_read(dev->regmap, 0x07, &uitmp); 396 404 if (ret) 397 405 goto err; 398 406 399 - s->pll_lock->val = (utmp & 0x01); 400 - err: 401 - if (ret) 402 - dev_dbg(&s->client->dev, "failed=%d\n", ret); 407 + dev->pll_lock->val = (uitmp & 0x01); 403 408 409 + return 0; 410 + err: 411 + dev_dbg(&client->dev, "failed=%d\n", ret); 404 412 return ret; 405 413 } 406 414 407 415 static int e4000_g_volatile_ctrl(struct v4l2_ctrl *ctrl) 408 416 { 409 - struct e4000 *s = container_of(ctrl->handler, struct e4000, hdl); 417 + struct e4000_dev *dev = container_of(ctrl->handler, struct e4000_dev, hdl); 418 + struct i2c_client *client = dev->client; 410 419 int ret; 411 420 412 - if (!s->active) 421 + if (!dev->active) 413 422 return 0; 414 423 415 424 switch (ctrl->id) { 416 425 case V4L2_CID_RF_TUNER_PLL_LOCK: 417 - ret = e4000_pll_lock(s->fe); 426 + ret = e4000_pll_lock(dev->fe); 418 427 break; 419 428 default: 420 - dev_dbg(&s->client->dev, "unknown ctrl: id=%d name=%s\n", 421 - ctrl->id, ctrl->name); 429 + dev_dbg(&client->dev, "unknown ctrl: id=%d name=%s\n", 430 + ctrl->id, ctrl->name); 422 431 ret = -EINVAL; 423 432 } 424 433 ··· 432 431 433 432 static int e4000_s_ctrl(struct v4l2_ctrl *ctrl) 434 433 { 435 - struct e4000 *s = container_of(ctrl->handler, struct e4000, hdl); 436 - struct dvb_frontend *fe = s->fe; 437 - struct dtv_frontend_properties *c = &fe->dtv_property_cache; 434 + struct e4000_dev *dev = container_of(ctrl->handler, struct e4000_dev, hdl); 435 + struct i2c_client *client = dev->client; 436 + struct dtv_frontend_properties *c = &dev->fe->dtv_property_cache; 438 437 int ret; 439 438 440 - if (!s->active) 439 + if (!dev->active) 441 440 return 0; 442 441 443 442 switch (ctrl->id) { 444 443 case V4L2_CID_RF_TUNER_BANDWIDTH_AUTO: 445 444 case V4L2_CID_RF_TUNER_BANDWIDTH: 446 - c->bandwidth_hz = s->bandwidth->val; 447 - ret = e4000_set_params(s->fe); 445 + c->bandwidth_hz = dev->bandwidth->val; 446 + ret = e4000_set_params(dev->fe); 448 447 break; 449 448 case V4L2_CID_RF_TUNER_LNA_GAIN_AUTO: 450 449 case V4L2_CID_RF_TUNER_LNA_GAIN: 451 - ret = e4000_set_lna_gain(s->fe); 450 + ret = e4000_set_lna_gain(dev->fe); 452 451 break; 453 452 case V4L2_CID_RF_TUNER_MIXER_GAIN_AUTO: 454 453 case V4L2_CID_RF_TUNER_MIXER_GAIN: 455 - ret = e4000_set_mixer_gain(s->fe); 454 + ret = e4000_set_mixer_gain(dev->fe); 456 455 break; 457 456 case V4L2_CID_RF_TUNER_IF_GAIN_AUTO: 458 457 case V4L2_CID_RF_TUNER_IF_GAIN: 459 - ret = e4000_set_if_gain(s->fe); 458 + ret = e4000_set_if_gain(dev->fe); 460 459 break; 461 460 default: 462 - dev_dbg(&s->client->dev, "unknown ctrl: id=%d name=%s\n", 463 - ctrl->id, ctrl->name); 461 + dev_dbg(&client->dev, "unknown ctrl: id=%d name=%s\n", 462 + ctrl->id, ctrl->name); 464 463 ret = -EINVAL; 465 464 } 466 465 ··· 492 491 * subdev itself, just to avoid reinventing the wheel. 493 492 */ 494 493 static int e4000_probe(struct i2c_client *client, 495 - const struct i2c_device_id *id) 494 + const struct i2c_device_id *id) 496 495 { 496 + struct e4000_dev *dev; 497 497 struct e4000_config *cfg = client->dev.platform_data; 498 498 struct dvb_frontend *fe = cfg->fe; 499 - struct e4000 *s; 500 499 int ret; 501 - unsigned int utmp; 500 + unsigned int uitmp; 502 501 static const struct regmap_config regmap_config = { 503 502 .reg_bits = 8, 504 503 .val_bits = 8, 505 - .max_register = 0xff, 506 504 }; 507 505 508 - s = kzalloc(sizeof(struct e4000), GFP_KERNEL); 509 - if (!s) { 506 + dev = kzalloc(sizeof(*dev), GFP_KERNEL); 507 + if (!dev) { 510 508 ret = -ENOMEM; 511 - dev_err(&client->dev, "kzalloc() failed\n"); 512 509 goto err; 513 510 } 514 511 515 - s->clock = cfg->clock; 516 - s->client = client; 517 - s->fe = cfg->fe; 518 - s->regmap = devm_regmap_init_i2c(client, &regmap_config); 519 - if (IS_ERR(s->regmap)) { 520 - ret = PTR_ERR(s->regmap); 521 - goto err; 512 + dev->clk = cfg->clock; 513 + dev->client = client; 514 + dev->fe = cfg->fe; 515 + dev->regmap = devm_regmap_init_i2c(client, &regmap_config); 516 + if (IS_ERR(dev->regmap)) { 517 + ret = PTR_ERR(dev->regmap); 518 + goto err_kfree; 522 519 } 523 520 524 521 /* check if the tuner is there */ 525 - ret = regmap_read(s->regmap, 0x02, &utmp); 522 + ret = regmap_read(dev->regmap, 0x02, &uitmp); 526 523 if (ret) 527 - goto err; 524 + goto err_kfree; 528 525 529 - dev_dbg(&s->client->dev, "chip id=%02x\n", utmp); 526 + dev_dbg(&client->dev, "chip id=%02x\n", uitmp); 530 527 531 - if (utmp != 0x40) { 528 + if (uitmp != 0x40) { 532 529 ret = -ENODEV; 533 - goto err; 530 + goto err_kfree; 534 531 } 535 532 536 533 /* put sleep as chip seems to be in normal mode by default */ 537 - ret = regmap_write(s->regmap, 0x00, 0x00); 534 + ret = regmap_write(dev->regmap, 0x00, 0x00); 538 535 if (ret) 539 - goto err; 536 + goto err_kfree; 540 537 541 538 #if IS_ENABLED(CONFIG_VIDEO_V4L2) 542 539 /* Register controls */ 543 - v4l2_ctrl_handler_init(&s->hdl, 9); 544 - s->bandwidth_auto = v4l2_ctrl_new_std(&s->hdl, &e4000_ctrl_ops, 540 + v4l2_ctrl_handler_init(&dev->hdl, 9); 541 + dev->bandwidth_auto = v4l2_ctrl_new_std(&dev->hdl, &e4000_ctrl_ops, 545 542 V4L2_CID_RF_TUNER_BANDWIDTH_AUTO, 0, 1, 1, 1); 546 - s->bandwidth = v4l2_ctrl_new_std(&s->hdl, &e4000_ctrl_ops, 543 + dev->bandwidth = v4l2_ctrl_new_std(&dev->hdl, &e4000_ctrl_ops, 547 544 V4L2_CID_RF_TUNER_BANDWIDTH, 4300000, 11000000, 100000, 4300000); 548 - v4l2_ctrl_auto_cluster(2, &s->bandwidth_auto, 0, false); 549 - s->lna_gain_auto = v4l2_ctrl_new_std(&s->hdl, &e4000_ctrl_ops, 545 + v4l2_ctrl_auto_cluster(2, &dev->bandwidth_auto, 0, false); 546 + dev->lna_gain_auto = v4l2_ctrl_new_std(&dev->hdl, &e4000_ctrl_ops, 550 547 V4L2_CID_RF_TUNER_LNA_GAIN_AUTO, 0, 1, 1, 1); 551 - s->lna_gain = v4l2_ctrl_new_std(&s->hdl, &e4000_ctrl_ops, 548 + dev->lna_gain = v4l2_ctrl_new_std(&dev->hdl, &e4000_ctrl_ops, 552 549 V4L2_CID_RF_TUNER_LNA_GAIN, 0, 15, 1, 10); 553 - v4l2_ctrl_auto_cluster(2, &s->lna_gain_auto, 0, false); 554 - s->mixer_gain_auto = v4l2_ctrl_new_std(&s->hdl, &e4000_ctrl_ops, 550 + v4l2_ctrl_auto_cluster(2, &dev->lna_gain_auto, 0, false); 551 + dev->mixer_gain_auto = v4l2_ctrl_new_std(&dev->hdl, &e4000_ctrl_ops, 555 552 V4L2_CID_RF_TUNER_MIXER_GAIN_AUTO, 0, 1, 1, 1); 556 - s->mixer_gain = v4l2_ctrl_new_std(&s->hdl, &e4000_ctrl_ops, 553 + dev->mixer_gain = v4l2_ctrl_new_std(&dev->hdl, &e4000_ctrl_ops, 557 554 V4L2_CID_RF_TUNER_MIXER_GAIN, 0, 1, 1, 1); 558 - v4l2_ctrl_auto_cluster(2, &s->mixer_gain_auto, 0, false); 559 - s->if_gain_auto = v4l2_ctrl_new_std(&s->hdl, &e4000_ctrl_ops, 555 + v4l2_ctrl_auto_cluster(2, &dev->mixer_gain_auto, 0, false); 556 + dev->if_gain_auto = v4l2_ctrl_new_std(&dev->hdl, &e4000_ctrl_ops, 560 557 V4L2_CID_RF_TUNER_IF_GAIN_AUTO, 0, 1, 1, 1); 561 - s->if_gain = v4l2_ctrl_new_std(&s->hdl, &e4000_ctrl_ops, 558 + dev->if_gain = v4l2_ctrl_new_std(&dev->hdl, &e4000_ctrl_ops, 562 559 V4L2_CID_RF_TUNER_IF_GAIN, 0, 54, 1, 0); 563 - v4l2_ctrl_auto_cluster(2, &s->if_gain_auto, 0, false); 564 - s->pll_lock = v4l2_ctrl_new_std(&s->hdl, &e4000_ctrl_ops, 560 + v4l2_ctrl_auto_cluster(2, &dev->if_gain_auto, 0, false); 561 + dev->pll_lock = v4l2_ctrl_new_std(&dev->hdl, &e4000_ctrl_ops, 565 562 V4L2_CID_RF_TUNER_PLL_LOCK, 0, 1, 1, 0); 566 - if (s->hdl.error) { 567 - ret = s->hdl.error; 568 - dev_err(&s->client->dev, "Could not initialize controls\n"); 569 - v4l2_ctrl_handler_free(&s->hdl); 570 - goto err; 563 + if (dev->hdl.error) { 564 + ret = dev->hdl.error; 565 + dev_err(&client->dev, "Could not initialize controls\n"); 566 + v4l2_ctrl_handler_free(&dev->hdl); 567 + goto err_kfree; 571 568 } 572 569 573 - s->sd.ctrl_handler = &s->hdl; 570 + dev->sd.ctrl_handler = &dev->hdl; 574 571 #endif 575 - 576 - dev_info(&s->client->dev, "Elonics E4000 successfully identified\n"); 577 - 578 - fe->tuner_priv = s; 572 + fe->tuner_priv = dev; 579 573 memcpy(&fe->ops.tuner_ops, &e4000_tuner_ops, 580 574 sizeof(struct dvb_tuner_ops)); 575 + v4l2_set_subdevdata(&dev->sd, client); 576 + i2c_set_clientdata(client, &dev->sd); 581 577 582 - v4l2_set_subdevdata(&s->sd, client); 583 - i2c_set_clientdata(client, &s->sd); 584 - 578 + dev_info(&client->dev, "Elonics E4000 successfully identified\n"); 585 579 return 0; 580 + err_kfree: 581 + kfree(dev); 586 582 err: 587 - if (ret) { 588 - dev_dbg(&client->dev, "failed=%d\n", ret); 589 - kfree(s); 590 - } 591 - 583 + dev_dbg(&client->dev, "failed=%d\n", ret); 592 584 return ret; 593 585 } 594 586 595 587 static int e4000_remove(struct i2c_client *client) 596 588 { 597 589 struct v4l2_subdev *sd = i2c_get_clientdata(client); 598 - struct e4000 *s = container_of(sd, struct e4000, sd); 599 - struct dvb_frontend *fe = s->fe; 590 + struct e4000_dev *dev = container_of(sd, struct e4000_dev, sd); 600 591 601 592 dev_dbg(&client->dev, "\n"); 602 593 603 594 #if IS_ENABLED(CONFIG_VIDEO_V4L2) 604 - v4l2_ctrl_handler_free(&s->hdl); 595 + v4l2_ctrl_handler_free(&dev->hdl); 605 596 #endif 606 - memset(&fe->ops.tuner_ops, 0, sizeof(struct dvb_tuner_ops)); 607 - fe->tuner_priv = NULL; 608 - kfree(s); 597 + kfree(dev); 609 598 610 599 return 0; 611 600 } 612 601 613 - static const struct i2c_device_id e4000_id[] = { 602 + static const struct i2c_device_id e4000_id_table[] = { 614 603 {"e4000", 0}, 615 604 {} 616 605 }; 617 - MODULE_DEVICE_TABLE(i2c, e4000_id); 606 + MODULE_DEVICE_TABLE(i2c, e4000_id_table); 618 607 619 608 static struct i2c_driver e4000_driver = { 620 609 .driver = { 621 610 .owner = THIS_MODULE, 622 611 .name = "e4000", 612 + .suppress_bind_attrs = true, 623 613 }, 624 614 .probe = e4000_probe, 625 615 .remove = e4000_remove, 626 - .id_table = e4000_id, 616 + .id_table = e4000_id_table, 627 617 }; 628 618 629 619 module_i2c_driver(e4000_driver);
-1
drivers/media/tuners/e4000.h
··· 21 21 #ifndef E4000_H 22 22 #define E4000_H 23 23 24 - #include <linux/kconfig.h> 25 24 #include "dvb_frontend.h" 26 25 27 26 /*
+3 -2
drivers/media/tuners/e4000_priv.h
··· 22 22 #define E4000_PRIV_H 23 23 24 24 #include "e4000.h" 25 + #include <linux/math64.h> 25 26 #include <media/v4l2-ctrls.h> 26 27 #include <media/v4l2-subdev.h> 27 28 #include <linux/regmap.h> 28 29 29 - struct e4000 { 30 + struct e4000_dev { 30 31 struct i2c_client *client; 31 32 struct regmap *regmap; 32 - u32 clock; 33 + u32 clk; 33 34 struct dvb_frontend *fe; 34 35 struct v4l2_subdev sd; 35 36 bool active;