Antti Palosaari | f926374 | 2012-03-30 06:37:26 -0300 | [diff] [blame] | 1 | /* |
Antti Palosaari | 465433f | 2015-04-15 20:26:06 -0300 | [diff] [blame] | 2 | * Infineon TUA9001 silicon tuner driver |
Antti Palosaari | f926374 | 2012-03-30 06:37:26 -0300 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2009 Antti Palosaari <crope@iki.fi> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
Antti Palosaari | f926374 | 2012-03-30 06:37:26 -0300 | [diff] [blame] | 15 | */ |
| 16 | |
Antti Palosaari | f926374 | 2012-03-30 06:37:26 -0300 | [diff] [blame] | 17 | #include "tua9001_priv.h" |
| 18 | |
Antti Palosaari | f926374 | 2012-03-30 06:37:26 -0300 | [diff] [blame] | 19 | static int tua9001_init(struct dvb_frontend *fe) |
| 20 | { |
Antti Palosaari | 465433f | 2015-04-15 20:26:06 -0300 | [diff] [blame] | 21 | struct tua9001_dev *dev = fe->tuner_priv; |
| 22 | struct i2c_client *client = dev->client; |
| 23 | int ret, i; |
| 24 | static const struct tua9001_reg_val data[] = { |
| 25 | {0x1e, 0x6512}, |
| 26 | {0x25, 0xb888}, |
| 27 | {0x39, 0x5460}, |
| 28 | {0x3b, 0x00c0}, |
| 29 | {0x3a, 0xf000}, |
| 30 | {0x08, 0x0000}, |
| 31 | {0x32, 0x0030}, |
| 32 | {0x41, 0x703a}, |
| 33 | {0x40, 0x1c78}, |
| 34 | {0x2c, 0x1c00}, |
| 35 | {0x36, 0xc013}, |
| 36 | {0x37, 0x6f18}, |
| 37 | {0x27, 0x0008}, |
| 38 | {0x2a, 0x0001}, |
| 39 | {0x34, 0x0a40}, |
Antti Palosaari | f926374 | 2012-03-30 06:37:26 -0300 | [diff] [blame] | 40 | }; |
| 41 | |
Antti Palosaari | 465433f | 2015-04-15 20:26:06 -0300 | [diff] [blame] | 42 | dev_dbg(&client->dev, "\n"); |
Antti Palosaari | e6211c7 | 2012-09-11 22:27:10 -0300 | [diff] [blame] | 43 | |
Antti Palosaari | 89054e3 | 2012-09-11 22:27:07 -0300 | [diff] [blame] | 44 | if (fe->callback) { |
Antti Palosaari | 465433f | 2015-04-15 20:26:06 -0300 | [diff] [blame] | 45 | ret = fe->callback(client->adapter, |
| 46 | DVB_FRONTEND_COMPONENT_TUNER, |
| 47 | TUA9001_CMD_RESETN, 0); |
| 48 | if (ret) |
Antti Palosaari | 89054e3 | 2012-09-11 22:27:07 -0300 | [diff] [blame] | 49 | goto err; |
| 50 | } |
| 51 | |
Antti Palosaari | f926374 | 2012-03-30 06:37:26 -0300 | [diff] [blame] | 52 | for (i = 0; i < ARRAY_SIZE(data); i++) { |
Antti Palosaari | dd219a8 | 2015-04-15 20:38:43 -0300 | [diff] [blame^] | 53 | ret = regmap_write(dev->regmap, data[i].reg, data[i].val); |
Antti Palosaari | 465433f | 2015-04-15 20:26:06 -0300 | [diff] [blame] | 54 | if (ret) |
Antti Palosaari | 9667623 | 2015-04-15 19:33:13 -0300 | [diff] [blame] | 55 | goto err; |
Antti Palosaari | f926374 | 2012-03-30 06:37:26 -0300 | [diff] [blame] | 56 | } |
Antti Palosaari | 465433f | 2015-04-15 20:26:06 -0300 | [diff] [blame] | 57 | return 0; |
Antti Palosaari | 89054e3 | 2012-09-11 22:27:07 -0300 | [diff] [blame] | 58 | err: |
Antti Palosaari | 465433f | 2015-04-15 20:26:06 -0300 | [diff] [blame] | 59 | dev_dbg(&client->dev, "failed=%d\n", ret); |
Antti Palosaari | 89054e3 | 2012-09-11 22:27:07 -0300 | [diff] [blame] | 60 | return ret; |
| 61 | } |
| 62 | |
| 63 | static int tua9001_sleep(struct dvb_frontend *fe) |
| 64 | { |
Antti Palosaari | 465433f | 2015-04-15 20:26:06 -0300 | [diff] [blame] | 65 | struct tua9001_dev *dev = fe->tuner_priv; |
| 66 | struct i2c_client *client = dev->client; |
| 67 | int ret; |
Antti Palosaari | 89054e3 | 2012-09-11 22:27:07 -0300 | [diff] [blame] | 68 | |
Antti Palosaari | 465433f | 2015-04-15 20:26:06 -0300 | [diff] [blame] | 69 | dev_dbg(&client->dev, "\n"); |
Antti Palosaari | e6211c7 | 2012-09-11 22:27:10 -0300 | [diff] [blame] | 70 | |
Antti Palosaari | 465433f | 2015-04-15 20:26:06 -0300 | [diff] [blame] | 71 | if (fe->callback) { |
| 72 | ret = fe->callback(client->adapter, |
| 73 | DVB_FRONTEND_COMPONENT_TUNER, |
| 74 | TUA9001_CMD_RESETN, 1); |
| 75 | if (ret) |
| 76 | goto err; |
| 77 | } |
| 78 | return 0; |
| 79 | err: |
| 80 | dev_dbg(&client->dev, "failed=%d\n", ret); |
Antti Palosaari | f926374 | 2012-03-30 06:37:26 -0300 | [diff] [blame] | 81 | return ret; |
| 82 | } |
| 83 | |
| 84 | static int tua9001_set_params(struct dvb_frontend *fe) |
| 85 | { |
Antti Palosaari | 465433f | 2015-04-15 20:26:06 -0300 | [diff] [blame] | 86 | struct tua9001_dev *dev = fe->tuner_priv; |
| 87 | struct i2c_client *client = dev->client; |
Antti Palosaari | f926374 | 2012-03-30 06:37:26 -0300 | [diff] [blame] | 88 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
Antti Palosaari | 465433f | 2015-04-15 20:26:06 -0300 | [diff] [blame] | 89 | int ret, i; |
Antti Palosaari | f926374 | 2012-03-30 06:37:26 -0300 | [diff] [blame] | 90 | u16 val; |
| 91 | u32 frequency; |
Antti Palosaari | 465433f | 2015-04-15 20:26:06 -0300 | [diff] [blame] | 92 | struct tua9001_reg_val data[2]; |
Antti Palosaari | f926374 | 2012-03-30 06:37:26 -0300 | [diff] [blame] | 93 | |
Antti Palosaari | 465433f | 2015-04-15 20:26:06 -0300 | [diff] [blame] | 94 | dev_dbg(&client->dev, |
| 95 | "delivery_system=%u frequency=%u bandwidth_hz=%u\n", |
| 96 | c->delivery_system, c->frequency, c->bandwidth_hz); |
Antti Palosaari | f926374 | 2012-03-30 06:37:26 -0300 | [diff] [blame] | 97 | |
| 98 | switch (c->delivery_system) { |
| 99 | case SYS_DVBT: |
| 100 | switch (c->bandwidth_hz) { |
| 101 | case 8000000: |
| 102 | val = 0x0000; |
| 103 | break; |
| 104 | case 7000000: |
| 105 | val = 0x1000; |
| 106 | break; |
| 107 | case 6000000: |
| 108 | val = 0x2000; |
| 109 | break; |
| 110 | case 5000000: |
| 111 | val = 0x3000; |
| 112 | break; |
| 113 | default: |
| 114 | ret = -EINVAL; |
| 115 | goto err; |
| 116 | } |
| 117 | break; |
| 118 | default: |
| 119 | ret = -EINVAL; |
| 120 | goto err; |
| 121 | } |
| 122 | |
| 123 | data[0].reg = 0x04; |
| 124 | data[0].val = val; |
| 125 | |
| 126 | frequency = (c->frequency - 150000000); |
| 127 | frequency /= 100; |
| 128 | frequency *= 48; |
| 129 | frequency /= 10000; |
| 130 | |
| 131 | data[1].reg = 0x1f; |
| 132 | data[1].val = frequency; |
| 133 | |
Antti Palosaari | 89054e3 | 2012-09-11 22:27:07 -0300 | [diff] [blame] | 134 | if (fe->callback) { |
Antti Palosaari | 465433f | 2015-04-15 20:26:06 -0300 | [diff] [blame] | 135 | ret = fe->callback(client->adapter, |
| 136 | DVB_FRONTEND_COMPONENT_TUNER, |
| 137 | TUA9001_CMD_RXEN, 0); |
| 138 | if (ret) |
Antti Palosaari | 9667623 | 2015-04-15 19:33:13 -0300 | [diff] [blame] | 139 | goto err; |
Antti Palosaari | 89054e3 | 2012-09-11 22:27:07 -0300 | [diff] [blame] | 140 | } |
| 141 | |
Antti Palosaari | f926374 | 2012-03-30 06:37:26 -0300 | [diff] [blame] | 142 | for (i = 0; i < ARRAY_SIZE(data); i++) { |
Antti Palosaari | dd219a8 | 2015-04-15 20:38:43 -0300 | [diff] [blame^] | 143 | ret = regmap_write(dev->regmap, data[i].reg, data[i].val); |
Antti Palosaari | 465433f | 2015-04-15 20:26:06 -0300 | [diff] [blame] | 144 | if (ret) |
Antti Palosaari | 9667623 | 2015-04-15 19:33:13 -0300 | [diff] [blame] | 145 | goto err; |
Antti Palosaari | f926374 | 2012-03-30 06:37:26 -0300 | [diff] [blame] | 146 | } |
| 147 | |
Antti Palosaari | 89054e3 | 2012-09-11 22:27:07 -0300 | [diff] [blame] | 148 | if (fe->callback) { |
Antti Palosaari | 465433f | 2015-04-15 20:26:06 -0300 | [diff] [blame] | 149 | ret = fe->callback(client->adapter, |
| 150 | DVB_FRONTEND_COMPONENT_TUNER, |
| 151 | TUA9001_CMD_RXEN, 1); |
| 152 | if (ret) |
Antti Palosaari | 9667623 | 2015-04-15 19:33:13 -0300 | [diff] [blame] | 153 | goto err; |
Antti Palosaari | 89054e3 | 2012-09-11 22:27:07 -0300 | [diff] [blame] | 154 | } |
Antti Palosaari | 465433f | 2015-04-15 20:26:06 -0300 | [diff] [blame] | 155 | return 0; |
Antti Palosaari | f926374 | 2012-03-30 06:37:26 -0300 | [diff] [blame] | 156 | err: |
Antti Palosaari | 465433f | 2015-04-15 20:26:06 -0300 | [diff] [blame] | 157 | dev_dbg(&client->dev, "failed=%d\n", ret); |
Antti Palosaari | f926374 | 2012-03-30 06:37:26 -0300 | [diff] [blame] | 158 | return ret; |
| 159 | } |
| 160 | |
| 161 | static int tua9001_get_if_frequency(struct dvb_frontend *fe, u32 *frequency) |
| 162 | { |
Antti Palosaari | 465433f | 2015-04-15 20:26:06 -0300 | [diff] [blame] | 163 | struct tua9001_dev *dev = fe->tuner_priv; |
| 164 | struct i2c_client *client = dev->client; |
Antti Palosaari | e6211c7 | 2012-09-11 22:27:10 -0300 | [diff] [blame] | 165 | |
Antti Palosaari | 465433f | 2015-04-15 20:26:06 -0300 | [diff] [blame] | 166 | dev_dbg(&client->dev, "\n"); |
Antti Palosaari | e6211c7 | 2012-09-11 22:27:10 -0300 | [diff] [blame] | 167 | |
Antti Palosaari | f926374 | 2012-03-30 06:37:26 -0300 | [diff] [blame] | 168 | *frequency = 0; /* Zero-IF */ |
Antti Palosaari | f926374 | 2012-03-30 06:37:26 -0300 | [diff] [blame] | 169 | return 0; |
| 170 | } |
| 171 | |
| 172 | static const struct dvb_tuner_ops tua9001_tuner_ops = { |
| 173 | .info = { |
Antti Palosaari | 465433f | 2015-04-15 20:26:06 -0300 | [diff] [blame] | 174 | .name = "Infineon TUA9001", |
Antti Palosaari | f926374 | 2012-03-30 06:37:26 -0300 | [diff] [blame] | 175 | .frequency_min = 170000000, |
| 176 | .frequency_max = 862000000, |
Antti Palosaari | f926374 | 2012-03-30 06:37:26 -0300 | [diff] [blame] | 177 | }, |
| 178 | |
Antti Palosaari | f926374 | 2012-03-30 06:37:26 -0300 | [diff] [blame] | 179 | .init = tua9001_init, |
Antti Palosaari | 89054e3 | 2012-09-11 22:27:07 -0300 | [diff] [blame] | 180 | .sleep = tua9001_sleep, |
Antti Palosaari | f926374 | 2012-03-30 06:37:26 -0300 | [diff] [blame] | 181 | .set_params = tua9001_set_params, |
| 182 | |
| 183 | .get_if_frequency = tua9001_get_if_frequency, |
| 184 | }; |
| 185 | |
Antti Palosaari | fc851c6 | 2015-04-15 19:12:34 -0300 | [diff] [blame] | 186 | static int tua9001_probe(struct i2c_client *client, |
| 187 | const struct i2c_device_id *id) |
| 188 | { |
Antti Palosaari | 465433f | 2015-04-15 20:26:06 -0300 | [diff] [blame] | 189 | struct tua9001_dev *dev; |
Antti Palosaari | fc851c6 | 2015-04-15 19:12:34 -0300 | [diff] [blame] | 190 | struct tua9001_platform_data *pdata = client->dev.platform_data; |
| 191 | struct dvb_frontend *fe = pdata->dvb_frontend; |
| 192 | int ret; |
Antti Palosaari | dd219a8 | 2015-04-15 20:38:43 -0300 | [diff] [blame^] | 193 | static const struct regmap_config regmap_config = { |
| 194 | .reg_bits = 8, |
| 195 | .val_bits = 16, |
| 196 | }; |
Antti Palosaari | fc851c6 | 2015-04-15 19:12:34 -0300 | [diff] [blame] | 197 | |
| 198 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); |
| 199 | if (!dev) { |
| 200 | ret = -ENOMEM; |
| 201 | goto err; |
| 202 | } |
| 203 | |
Antti Palosaari | fc851c6 | 2015-04-15 19:12:34 -0300 | [diff] [blame] | 204 | dev->fe = pdata->dvb_frontend; |
Antti Palosaari | dd219a8 | 2015-04-15 20:38:43 -0300 | [diff] [blame^] | 205 | dev->client = client; |
| 206 | dev->regmap = devm_regmap_init_i2c(client, ®map_config); |
| 207 | if (IS_ERR(dev->regmap)) { |
| 208 | ret = PTR_ERR(dev->regmap); |
| 209 | goto err_kfree; |
| 210 | } |
Antti Palosaari | fc851c6 | 2015-04-15 19:12:34 -0300 | [diff] [blame] | 211 | |
| 212 | if (fe->callback) { |
| 213 | ret = fe->callback(client->adapter, |
| 214 | DVB_FRONTEND_COMPONENT_TUNER, |
| 215 | TUA9001_CMD_CEN, 1); |
| 216 | if (ret) |
| 217 | goto err_kfree; |
| 218 | |
| 219 | ret = fe->callback(client->adapter, |
| 220 | DVB_FRONTEND_COMPONENT_TUNER, |
| 221 | TUA9001_CMD_RXEN, 0); |
| 222 | if (ret) |
| 223 | goto err_kfree; |
| 224 | |
| 225 | ret = fe->callback(client->adapter, |
| 226 | DVB_FRONTEND_COMPONENT_TUNER, |
| 227 | TUA9001_CMD_RESETN, 1); |
| 228 | if (ret) |
| 229 | goto err_kfree; |
| 230 | } |
| 231 | |
| 232 | fe->tuner_priv = dev; |
| 233 | memcpy(&fe->ops.tuner_ops, &tua9001_tuner_ops, |
| 234 | sizeof(struct dvb_tuner_ops)); |
Antti Palosaari | fc851c6 | 2015-04-15 19:12:34 -0300 | [diff] [blame] | 235 | i2c_set_clientdata(client, dev); |
| 236 | |
Antti Palosaari | 465433f | 2015-04-15 20:26:06 -0300 | [diff] [blame] | 237 | dev_info(&client->dev, "Infineon TUA9001 successfully attached\n"); |
Antti Palosaari | fc851c6 | 2015-04-15 19:12:34 -0300 | [diff] [blame] | 238 | return 0; |
| 239 | err_kfree: |
| 240 | kfree(dev); |
| 241 | err: |
| 242 | dev_dbg(&client->dev, "failed=%d\n", ret); |
| 243 | return ret; |
| 244 | } |
| 245 | |
| 246 | static int tua9001_remove(struct i2c_client *client) |
| 247 | { |
Antti Palosaari | 465433f | 2015-04-15 20:26:06 -0300 | [diff] [blame] | 248 | struct tua9001_dev *dev = i2c_get_clientdata(client); |
Antti Palosaari | fc851c6 | 2015-04-15 19:12:34 -0300 | [diff] [blame] | 249 | struct dvb_frontend *fe = dev->fe; |
| 250 | int ret; |
| 251 | |
| 252 | dev_dbg(&client->dev, "\n"); |
| 253 | |
| 254 | if (fe->callback) { |
| 255 | ret = fe->callback(client->adapter, |
| 256 | DVB_FRONTEND_COMPONENT_TUNER, |
| 257 | TUA9001_CMD_CEN, 0); |
| 258 | if (ret) |
| 259 | goto err_kfree; |
| 260 | } |
| 261 | kfree(dev); |
| 262 | return 0; |
| 263 | err_kfree: |
| 264 | kfree(dev); |
| 265 | dev_dbg(&client->dev, "failed=%d\n", ret); |
| 266 | return ret; |
| 267 | } |
| 268 | |
| 269 | static const struct i2c_device_id tua9001_id_table[] = { |
| 270 | {"tua9001", 0}, |
| 271 | {} |
| 272 | }; |
| 273 | MODULE_DEVICE_TABLE(i2c, tua9001_id_table); |
| 274 | |
| 275 | static struct i2c_driver tua9001_driver = { |
| 276 | .driver = { |
| 277 | .owner = THIS_MODULE, |
| 278 | .name = "tua9001", |
| 279 | .suppress_bind_attrs = true, |
| 280 | }, |
| 281 | .probe = tua9001_probe, |
| 282 | .remove = tua9001_remove, |
| 283 | .id_table = tua9001_id_table, |
| 284 | }; |
| 285 | |
| 286 | module_i2c_driver(tua9001_driver); |
| 287 | |
Antti Palosaari | 465433f | 2015-04-15 20:26:06 -0300 | [diff] [blame] | 288 | MODULE_DESCRIPTION("Infineon TUA9001 silicon tuner driver"); |
Antti Palosaari | f926374 | 2012-03-30 06:37:26 -0300 | [diff] [blame] | 289 | MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>"); |
| 290 | MODULE_LICENSE("GPL"); |