Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Sony CXD2820R demodulator driver |
| 3 | * |
| 4 | * Copyright (C) 2010 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. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along |
| 17 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | */ |
| 20 | |
| 21 | |
| 22 | #include "cxd2820r_priv.h" |
| 23 | |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 24 | /* write multiple registers */ |
| 25 | static int cxd2820r_wr_regs_i2c(struct cxd2820r_priv *priv, u8 i2c, u8 reg, |
| 26 | u8 *val, int len) |
| 27 | { |
| 28 | int ret; |
| 29 | u8 buf[len+1]; |
| 30 | struct i2c_msg msg[1] = { |
| 31 | { |
| 32 | .addr = i2c, |
| 33 | .flags = 0, |
| 34 | .len = sizeof(buf), |
| 35 | .buf = buf, |
| 36 | } |
| 37 | }; |
| 38 | |
| 39 | buf[0] = reg; |
| 40 | memcpy(&buf[1], val, len); |
| 41 | |
| 42 | ret = i2c_transfer(priv->i2c, msg, 1); |
| 43 | if (ret == 1) { |
| 44 | ret = 0; |
| 45 | } else { |
Antti Palosaari | 75aeafc | 2012-07-19 13:10:12 -0300 | [diff] [blame] | 46 | dev_warn(&priv->i2c->dev, "%s: i2c wr failed=%d reg=%02x " \ |
| 47 | "len=%d\n", KBUILD_MODNAME, ret, reg, len); |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 48 | ret = -EREMOTEIO; |
| 49 | } |
| 50 | return ret; |
| 51 | } |
| 52 | |
| 53 | /* read multiple registers */ |
| 54 | static int cxd2820r_rd_regs_i2c(struct cxd2820r_priv *priv, u8 i2c, u8 reg, |
| 55 | u8 *val, int len) |
| 56 | { |
| 57 | int ret; |
| 58 | u8 buf[len]; |
| 59 | struct i2c_msg msg[2] = { |
| 60 | { |
| 61 | .addr = i2c, |
| 62 | .flags = 0, |
| 63 | .len = 1, |
| 64 | .buf = ®, |
| 65 | }, { |
| 66 | .addr = i2c, |
| 67 | .flags = I2C_M_RD, |
| 68 | .len = sizeof(buf), |
| 69 | .buf = buf, |
| 70 | } |
| 71 | }; |
| 72 | |
| 73 | ret = i2c_transfer(priv->i2c, msg, 2); |
| 74 | if (ret == 2) { |
| 75 | memcpy(val, buf, len); |
| 76 | ret = 0; |
| 77 | } else { |
Antti Palosaari | 75aeafc | 2012-07-19 13:10:12 -0300 | [diff] [blame] | 78 | dev_warn(&priv->i2c->dev, "%s: i2c rd failed=%d reg=%02x " \ |
| 79 | "len=%d\n", KBUILD_MODNAME, ret, reg, len); |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 80 | ret = -EREMOTEIO; |
| 81 | } |
| 82 | |
| 83 | return ret; |
| 84 | } |
| 85 | |
| 86 | /* write multiple registers */ |
Steve Kerrison | 9ac51c5 | 2011-05-02 18:19:13 -0300 | [diff] [blame] | 87 | int cxd2820r_wr_regs(struct cxd2820r_priv *priv, u32 reginfo, u8 *val, |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 88 | int len) |
| 89 | { |
| 90 | int ret; |
| 91 | u8 i2c_addr; |
| 92 | u8 reg = (reginfo >> 0) & 0xff; |
| 93 | u8 bank = (reginfo >> 8) & 0xff; |
| 94 | u8 i2c = (reginfo >> 16) & 0x01; |
| 95 | |
| 96 | /* select I2C */ |
| 97 | if (i2c) |
| 98 | i2c_addr = priv->cfg.i2c_address | (1 << 1); /* DVB-C */ |
| 99 | else |
| 100 | i2c_addr = priv->cfg.i2c_address; /* DVB-T/T2 */ |
| 101 | |
| 102 | /* switch bank if needed */ |
| 103 | if (bank != priv->bank[i2c]) { |
| 104 | ret = cxd2820r_wr_regs_i2c(priv, i2c_addr, 0x00, &bank, 1); |
| 105 | if (ret) |
| 106 | return ret; |
| 107 | priv->bank[i2c] = bank; |
| 108 | } |
| 109 | return cxd2820r_wr_regs_i2c(priv, i2c_addr, reg, val, len); |
| 110 | } |
| 111 | |
| 112 | /* read multiple registers */ |
Steve Kerrison | 9ac51c5 | 2011-05-02 18:19:13 -0300 | [diff] [blame] | 113 | int cxd2820r_rd_regs(struct cxd2820r_priv *priv, u32 reginfo, u8 *val, |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 114 | int len) |
| 115 | { |
| 116 | int ret; |
| 117 | u8 i2c_addr; |
| 118 | u8 reg = (reginfo >> 0) & 0xff; |
| 119 | u8 bank = (reginfo >> 8) & 0xff; |
| 120 | u8 i2c = (reginfo >> 16) & 0x01; |
| 121 | |
| 122 | /* select I2C */ |
| 123 | if (i2c) |
| 124 | i2c_addr = priv->cfg.i2c_address | (1 << 1); /* DVB-C */ |
| 125 | else |
| 126 | i2c_addr = priv->cfg.i2c_address; /* DVB-T/T2 */ |
| 127 | |
| 128 | /* switch bank if needed */ |
| 129 | if (bank != priv->bank[i2c]) { |
| 130 | ret = cxd2820r_wr_regs_i2c(priv, i2c_addr, 0x00, &bank, 1); |
| 131 | if (ret) |
| 132 | return ret; |
| 133 | priv->bank[i2c] = bank; |
| 134 | } |
| 135 | return cxd2820r_rd_regs_i2c(priv, i2c_addr, reg, val, len); |
| 136 | } |
| 137 | |
| 138 | /* write single register */ |
Steve Kerrison | 9ac51c5 | 2011-05-02 18:19:13 -0300 | [diff] [blame] | 139 | int cxd2820r_wr_reg(struct cxd2820r_priv *priv, u32 reg, u8 val) |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 140 | { |
| 141 | return cxd2820r_wr_regs(priv, reg, &val, 1); |
| 142 | } |
| 143 | |
| 144 | /* read single register */ |
Steve Kerrison | 9ac51c5 | 2011-05-02 18:19:13 -0300 | [diff] [blame] | 145 | int cxd2820r_rd_reg(struct cxd2820r_priv *priv, u32 reg, u8 *val) |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 146 | { |
| 147 | return cxd2820r_rd_regs(priv, reg, val, 1); |
| 148 | } |
| 149 | |
| 150 | /* write single register with mask */ |
Steve Kerrison | 9ac51c5 | 2011-05-02 18:19:13 -0300 | [diff] [blame] | 151 | int cxd2820r_wr_reg_mask(struct cxd2820r_priv *priv, u32 reg, u8 val, |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 152 | u8 mask) |
| 153 | { |
| 154 | int ret; |
| 155 | u8 tmp; |
| 156 | |
| 157 | /* no need for read if whole reg is written */ |
| 158 | if (mask != 0xff) { |
| 159 | ret = cxd2820r_rd_reg(priv, reg, &tmp); |
| 160 | if (ret) |
| 161 | return ret; |
| 162 | |
| 163 | val &= mask; |
| 164 | tmp &= ~mask; |
| 165 | val |= tmp; |
| 166 | } |
| 167 | |
| 168 | return cxd2820r_wr_reg(priv, reg, val); |
| 169 | } |
| 170 | |
Antti Palosaari | 1e8f31f | 2012-07-19 21:10:36 -0300 | [diff] [blame] | 171 | int cxd2820r_gpio(struct dvb_frontend *fe, u8 *gpio) |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 172 | { |
| 173 | struct cxd2820r_priv *priv = fe->demodulator_priv; |
| 174 | int ret, i; |
Antti Palosaari | 1e8f31f | 2012-07-19 21:10:36 -0300 | [diff] [blame] | 175 | u8 tmp0, tmp1; |
Antti Palosaari | 75aeafc | 2012-07-19 13:10:12 -0300 | [diff] [blame] | 176 | |
| 177 | dev_dbg(&priv->i2c->dev, "%s: delsys=%d\n", __func__, |
| 178 | fe->dtv_property_cache.delivery_system); |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 179 | |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 180 | /* update GPIOs only when needed */ |
| 181 | if (!memcmp(gpio, priv->gpio, sizeof(priv->gpio))) |
| 182 | return 0; |
| 183 | |
| 184 | tmp0 = 0x00; |
| 185 | tmp1 = 0x00; |
| 186 | for (i = 0; i < sizeof(priv->gpio); i++) { |
| 187 | /* enable / disable */ |
| 188 | if (gpio[i] & CXD2820R_GPIO_E) |
| 189 | tmp0 |= (2 << 6) >> (2 * i); |
| 190 | else |
| 191 | tmp0 |= (1 << 6) >> (2 * i); |
| 192 | |
| 193 | /* input / output */ |
| 194 | if (gpio[i] & CXD2820R_GPIO_I) |
| 195 | tmp1 |= (1 << (3 + i)); |
| 196 | else |
| 197 | tmp1 |= (0 << (3 + i)); |
| 198 | |
| 199 | /* high / low */ |
| 200 | if (gpio[i] & CXD2820R_GPIO_H) |
| 201 | tmp1 |= (1 << (0 + i)); |
| 202 | else |
| 203 | tmp1 |= (0 << (0 + i)); |
| 204 | |
Antti Palosaari | 75aeafc | 2012-07-19 13:10:12 -0300 | [diff] [blame] | 205 | dev_dbg(&priv->i2c->dev, "%s: gpio i=%d %02x %02x\n", __func__, |
| 206 | i, tmp0, tmp1); |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 207 | } |
| 208 | |
Antti Palosaari | 75aeafc | 2012-07-19 13:10:12 -0300 | [diff] [blame] | 209 | dev_dbg(&priv->i2c->dev, "%s: wr gpio=%02x %02x\n", __func__, tmp0, |
| 210 | tmp1); |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 211 | |
| 212 | /* write bits [7:2] */ |
| 213 | ret = cxd2820r_wr_reg_mask(priv, 0x00089, tmp0, 0xfc); |
| 214 | if (ret) |
| 215 | goto error; |
| 216 | |
| 217 | /* write bits [5:0] */ |
| 218 | ret = cxd2820r_wr_reg_mask(priv, 0x0008e, tmp1, 0x3f); |
| 219 | if (ret) |
| 220 | goto error; |
| 221 | |
| 222 | memcpy(priv->gpio, gpio, sizeof(priv->gpio)); |
| 223 | |
| 224 | return ret; |
| 225 | error: |
Antti Palosaari | 75aeafc | 2012-07-19 13:10:12 -0300 | [diff] [blame] | 226 | dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 227 | return ret; |
| 228 | } |
| 229 | |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 230 | /* 64 bit div with round closest, like DIV_ROUND_CLOSEST but 64 bit */ |
Steve Kerrison | 9ac51c5 | 2011-05-02 18:19:13 -0300 | [diff] [blame] | 231 | u32 cxd2820r_div_u64_round_closest(u64 dividend, u32 divisor) |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 232 | { |
| 233 | return div_u64(dividend + (divisor / 2), divisor); |
| 234 | } |
| 235 | |
Mauro Carvalho Chehab | f311f68 | 2011-12-30 22:22:10 -0300 | [diff] [blame] | 236 | static int cxd2820r_set_frontend(struct dvb_frontend *fe) |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 237 | { |
Antti Palosaari | 75aeafc | 2012-07-19 13:10:12 -0300 | [diff] [blame] | 238 | struct cxd2820r_priv *priv = fe->demodulator_priv; |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 239 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
| 240 | int ret; |
Manu Abraham | 14c0386 | 2011-11-24 11:59:53 -0300 | [diff] [blame] | 241 | |
Antti Palosaari | 75aeafc | 2012-07-19 13:10:12 -0300 | [diff] [blame] | 242 | dev_dbg(&priv->i2c->dev, "%s: delsys=%d\n", __func__, |
| 243 | fe->dtv_property_cache.delivery_system); |
| 244 | |
Manu Abraham | 14c0386 | 2011-11-24 11:59:53 -0300 | [diff] [blame] | 245 | switch (c->delivery_system) { |
| 246 | case SYS_DVBT: |
| 247 | ret = cxd2820r_init_t(fe); |
| 248 | if (ret < 0) |
| 249 | goto err; |
Mauro Carvalho Chehab | f311f68 | 2011-12-30 22:22:10 -0300 | [diff] [blame] | 250 | ret = cxd2820r_set_frontend_t(fe); |
Manu Abraham | 14c0386 | 2011-11-24 11:59:53 -0300 | [diff] [blame] | 251 | if (ret < 0) |
| 252 | goto err; |
| 253 | break; |
| 254 | case SYS_DVBT2: |
| 255 | ret = cxd2820r_init_t(fe); |
| 256 | if (ret < 0) |
| 257 | goto err; |
Mauro Carvalho Chehab | f311f68 | 2011-12-30 22:22:10 -0300 | [diff] [blame] | 258 | ret = cxd2820r_set_frontend_t2(fe); |
Manu Abraham | 14c0386 | 2011-11-24 11:59:53 -0300 | [diff] [blame] | 259 | if (ret < 0) |
| 260 | goto err; |
| 261 | break; |
Mauro Carvalho Chehab | f311f68 | 2011-12-30 22:22:10 -0300 | [diff] [blame] | 262 | case SYS_DVBC_ANNEX_A: |
Manu Abraham | 14c0386 | 2011-11-24 11:59:53 -0300 | [diff] [blame] | 263 | ret = cxd2820r_init_c(fe); |
| 264 | if (ret < 0) |
| 265 | goto err; |
Mauro Carvalho Chehab | f311f68 | 2011-12-30 22:22:10 -0300 | [diff] [blame] | 266 | ret = cxd2820r_set_frontend_c(fe); |
Manu Abraham | 14c0386 | 2011-11-24 11:59:53 -0300 | [diff] [blame] | 267 | if (ret < 0) |
| 268 | goto err; |
| 269 | break; |
| 270 | default: |
Antti Palosaari | 75aeafc | 2012-07-19 13:10:12 -0300 | [diff] [blame] | 271 | dev_dbg(&priv->i2c->dev, "%s: error state=%d\n", __func__, |
| 272 | fe->dtv_property_cache.delivery_system); |
Manu Abraham | 14c0386 | 2011-11-24 11:59:53 -0300 | [diff] [blame] | 273 | ret = -EINVAL; |
| 274 | break; |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 275 | } |
Manu Abraham | 14c0386 | 2011-11-24 11:59:53 -0300 | [diff] [blame] | 276 | err: |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 277 | return ret; |
| 278 | } |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 279 | static int cxd2820r_read_status(struct dvb_frontend *fe, fe_status_t *status) |
| 280 | { |
Antti Palosaari | 75aeafc | 2012-07-19 13:10:12 -0300 | [diff] [blame] | 281 | struct cxd2820r_priv *priv = fe->demodulator_priv; |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 282 | int ret; |
Manu Abraham | 14c0386 | 2011-11-24 11:59:53 -0300 | [diff] [blame] | 283 | |
Antti Palosaari | 75aeafc | 2012-07-19 13:10:12 -0300 | [diff] [blame] | 284 | dev_dbg(&priv->i2c->dev, "%s: delsys=%d\n", __func__, |
| 285 | fe->dtv_property_cache.delivery_system); |
| 286 | |
Manu Abraham | 14c0386 | 2011-11-24 11:59:53 -0300 | [diff] [blame] | 287 | switch (fe->dtv_property_cache.delivery_system) { |
| 288 | case SYS_DVBT: |
| 289 | ret = cxd2820r_read_status_t(fe, status); |
| 290 | break; |
| 291 | case SYS_DVBT2: |
| 292 | ret = cxd2820r_read_status_t2(fe, status); |
| 293 | break; |
Mauro Carvalho Chehab | f311f68 | 2011-12-30 22:22:10 -0300 | [diff] [blame] | 294 | case SYS_DVBC_ANNEX_A: |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 295 | ret = cxd2820r_read_status_c(fe, status); |
Manu Abraham | 14c0386 | 2011-11-24 11:59:53 -0300 | [diff] [blame] | 296 | break; |
| 297 | default: |
| 298 | ret = -EINVAL; |
| 299 | break; |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 300 | } |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 301 | return ret; |
| 302 | } |
| 303 | |
Mauro Carvalho Chehab | 7c61d80 | 2011-12-30 11:30:21 -0300 | [diff] [blame] | 304 | static int cxd2820r_get_frontend(struct dvb_frontend *fe) |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 305 | { |
Antti Palosaari | 3b6a567 | 2012-01-15 18:30:36 -0300 | [diff] [blame] | 306 | struct cxd2820r_priv *priv = fe->demodulator_priv; |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 307 | int ret; |
Manu Abraham | 14c0386 | 2011-11-24 11:59:53 -0300 | [diff] [blame] | 308 | |
Antti Palosaari | 75aeafc | 2012-07-19 13:10:12 -0300 | [diff] [blame] | 309 | dev_dbg(&priv->i2c->dev, "%s: delsys=%d\n", __func__, |
| 310 | fe->dtv_property_cache.delivery_system); |
Antti Palosaari | 3b6a567 | 2012-01-15 18:30:36 -0300 | [diff] [blame] | 311 | |
| 312 | if (priv->delivery_system == SYS_UNDEFINED) |
| 313 | return 0; |
| 314 | |
Manu Abraham | 14c0386 | 2011-11-24 11:59:53 -0300 | [diff] [blame] | 315 | switch (fe->dtv_property_cache.delivery_system) { |
| 316 | case SYS_DVBT: |
Mauro Carvalho Chehab | f311f68 | 2011-12-30 22:22:10 -0300 | [diff] [blame] | 317 | ret = cxd2820r_get_frontend_t(fe); |
Manu Abraham | 14c0386 | 2011-11-24 11:59:53 -0300 | [diff] [blame] | 318 | break; |
| 319 | case SYS_DVBT2: |
Mauro Carvalho Chehab | f311f68 | 2011-12-30 22:22:10 -0300 | [diff] [blame] | 320 | ret = cxd2820r_get_frontend_t2(fe); |
Manu Abraham | 14c0386 | 2011-11-24 11:59:53 -0300 | [diff] [blame] | 321 | break; |
Mauro Carvalho Chehab | f311f68 | 2011-12-30 22:22:10 -0300 | [diff] [blame] | 322 | case SYS_DVBC_ANNEX_A: |
| 323 | ret = cxd2820r_get_frontend_c(fe); |
Manu Abraham | 14c0386 | 2011-11-24 11:59:53 -0300 | [diff] [blame] | 324 | break; |
| 325 | default: |
| 326 | ret = -EINVAL; |
| 327 | break; |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 328 | } |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 329 | return ret; |
| 330 | } |
| 331 | |
| 332 | static int cxd2820r_read_ber(struct dvb_frontend *fe, u32 *ber) |
| 333 | { |
Antti Palosaari | 75aeafc | 2012-07-19 13:10:12 -0300 | [diff] [blame] | 334 | struct cxd2820r_priv *priv = fe->demodulator_priv; |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 335 | int ret; |
Manu Abraham | 14c0386 | 2011-11-24 11:59:53 -0300 | [diff] [blame] | 336 | |
Antti Palosaari | 75aeafc | 2012-07-19 13:10:12 -0300 | [diff] [blame] | 337 | dev_dbg(&priv->i2c->dev, "%s: delsys=%d\n", __func__, |
| 338 | fe->dtv_property_cache.delivery_system); |
| 339 | |
Manu Abraham | 14c0386 | 2011-11-24 11:59:53 -0300 | [diff] [blame] | 340 | switch (fe->dtv_property_cache.delivery_system) { |
| 341 | case SYS_DVBT: |
| 342 | ret = cxd2820r_read_ber_t(fe, ber); |
| 343 | break; |
| 344 | case SYS_DVBT2: |
| 345 | ret = cxd2820r_read_ber_t2(fe, ber); |
| 346 | break; |
Mauro Carvalho Chehab | f311f68 | 2011-12-30 22:22:10 -0300 | [diff] [blame] | 347 | case SYS_DVBC_ANNEX_A: |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 348 | ret = cxd2820r_read_ber_c(fe, ber); |
Manu Abraham | 14c0386 | 2011-11-24 11:59:53 -0300 | [diff] [blame] | 349 | break; |
| 350 | default: |
| 351 | ret = -EINVAL; |
| 352 | break; |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 353 | } |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 354 | return ret; |
| 355 | } |
| 356 | |
| 357 | static int cxd2820r_read_signal_strength(struct dvb_frontend *fe, u16 *strength) |
| 358 | { |
Antti Palosaari | 75aeafc | 2012-07-19 13:10:12 -0300 | [diff] [blame] | 359 | struct cxd2820r_priv *priv = fe->demodulator_priv; |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 360 | int ret; |
Manu Abraham | 14c0386 | 2011-11-24 11:59:53 -0300 | [diff] [blame] | 361 | |
Antti Palosaari | 75aeafc | 2012-07-19 13:10:12 -0300 | [diff] [blame] | 362 | dev_dbg(&priv->i2c->dev, "%s: delsys=%d\n", __func__, |
| 363 | fe->dtv_property_cache.delivery_system); |
| 364 | |
Manu Abraham | 14c0386 | 2011-11-24 11:59:53 -0300 | [diff] [blame] | 365 | switch (fe->dtv_property_cache.delivery_system) { |
| 366 | case SYS_DVBT: |
| 367 | ret = cxd2820r_read_signal_strength_t(fe, strength); |
| 368 | break; |
| 369 | case SYS_DVBT2: |
| 370 | ret = cxd2820r_read_signal_strength_t2(fe, strength); |
| 371 | break; |
Mauro Carvalho Chehab | f311f68 | 2011-12-30 22:22:10 -0300 | [diff] [blame] | 372 | case SYS_DVBC_ANNEX_A: |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 373 | ret = cxd2820r_read_signal_strength_c(fe, strength); |
Manu Abraham | 14c0386 | 2011-11-24 11:59:53 -0300 | [diff] [blame] | 374 | break; |
| 375 | default: |
| 376 | ret = -EINVAL; |
| 377 | break; |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 378 | } |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 379 | return ret; |
| 380 | } |
| 381 | |
| 382 | static int cxd2820r_read_snr(struct dvb_frontend *fe, u16 *snr) |
| 383 | { |
Antti Palosaari | 75aeafc | 2012-07-19 13:10:12 -0300 | [diff] [blame] | 384 | struct cxd2820r_priv *priv = fe->demodulator_priv; |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 385 | int ret; |
Manu Abraham | 14c0386 | 2011-11-24 11:59:53 -0300 | [diff] [blame] | 386 | |
Antti Palosaari | 75aeafc | 2012-07-19 13:10:12 -0300 | [diff] [blame] | 387 | dev_dbg(&priv->i2c->dev, "%s: delsys=%d\n", __func__, |
| 388 | fe->dtv_property_cache.delivery_system); |
| 389 | |
Manu Abraham | 14c0386 | 2011-11-24 11:59:53 -0300 | [diff] [blame] | 390 | switch (fe->dtv_property_cache.delivery_system) { |
| 391 | case SYS_DVBT: |
| 392 | ret = cxd2820r_read_snr_t(fe, snr); |
| 393 | break; |
| 394 | case SYS_DVBT2: |
| 395 | ret = cxd2820r_read_snr_t2(fe, snr); |
| 396 | break; |
Mauro Carvalho Chehab | f311f68 | 2011-12-30 22:22:10 -0300 | [diff] [blame] | 397 | case SYS_DVBC_ANNEX_A: |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 398 | ret = cxd2820r_read_snr_c(fe, snr); |
Manu Abraham | 14c0386 | 2011-11-24 11:59:53 -0300 | [diff] [blame] | 399 | break; |
| 400 | default: |
| 401 | ret = -EINVAL; |
| 402 | break; |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 403 | } |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 404 | return ret; |
| 405 | } |
| 406 | |
| 407 | static int cxd2820r_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks) |
| 408 | { |
Antti Palosaari | 75aeafc | 2012-07-19 13:10:12 -0300 | [diff] [blame] | 409 | struct cxd2820r_priv *priv = fe->demodulator_priv; |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 410 | int ret; |
Manu Abraham | 14c0386 | 2011-11-24 11:59:53 -0300 | [diff] [blame] | 411 | |
Antti Palosaari | 75aeafc | 2012-07-19 13:10:12 -0300 | [diff] [blame] | 412 | dev_dbg(&priv->i2c->dev, "%s: delsys=%d\n", __func__, |
| 413 | fe->dtv_property_cache.delivery_system); |
| 414 | |
Manu Abraham | 14c0386 | 2011-11-24 11:59:53 -0300 | [diff] [blame] | 415 | switch (fe->dtv_property_cache.delivery_system) { |
| 416 | case SYS_DVBT: |
| 417 | ret = cxd2820r_read_ucblocks_t(fe, ucblocks); |
| 418 | break; |
| 419 | case SYS_DVBT2: |
| 420 | ret = cxd2820r_read_ucblocks_t2(fe, ucblocks); |
| 421 | break; |
Mauro Carvalho Chehab | f311f68 | 2011-12-30 22:22:10 -0300 | [diff] [blame] | 422 | case SYS_DVBC_ANNEX_A: |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 423 | ret = cxd2820r_read_ucblocks_c(fe, ucblocks); |
Manu Abraham | 14c0386 | 2011-11-24 11:59:53 -0300 | [diff] [blame] | 424 | break; |
| 425 | default: |
| 426 | ret = -EINVAL; |
| 427 | break; |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 428 | } |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 429 | return ret; |
| 430 | } |
| 431 | |
| 432 | static int cxd2820r_init(struct dvb_frontend *fe) |
| 433 | { |
Manu Abraham | 14c0386 | 2011-11-24 11:59:53 -0300 | [diff] [blame] | 434 | return 0; |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | static int cxd2820r_sleep(struct dvb_frontend *fe) |
| 438 | { |
Antti Palosaari | 75aeafc | 2012-07-19 13:10:12 -0300 | [diff] [blame] | 439 | struct cxd2820r_priv *priv = fe->demodulator_priv; |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 440 | int ret; |
Manu Abraham | 14c0386 | 2011-11-24 11:59:53 -0300 | [diff] [blame] | 441 | |
Antti Palosaari | 75aeafc | 2012-07-19 13:10:12 -0300 | [diff] [blame] | 442 | dev_dbg(&priv->i2c->dev, "%s: delsys=%d\n", __func__, |
| 443 | fe->dtv_property_cache.delivery_system); |
| 444 | |
Manu Abraham | 14c0386 | 2011-11-24 11:59:53 -0300 | [diff] [blame] | 445 | switch (fe->dtv_property_cache.delivery_system) { |
| 446 | case SYS_DVBT: |
| 447 | ret = cxd2820r_sleep_t(fe); |
| 448 | break; |
| 449 | case SYS_DVBT2: |
| 450 | ret = cxd2820r_sleep_t2(fe); |
| 451 | break; |
Mauro Carvalho Chehab | f311f68 | 2011-12-30 22:22:10 -0300 | [diff] [blame] | 452 | case SYS_DVBC_ANNEX_A: |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 453 | ret = cxd2820r_sleep_c(fe); |
Manu Abraham | 14c0386 | 2011-11-24 11:59:53 -0300 | [diff] [blame] | 454 | break; |
| 455 | default: |
| 456 | ret = -EINVAL; |
| 457 | break; |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 458 | } |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 459 | return ret; |
| 460 | } |
| 461 | |
| 462 | static int cxd2820r_get_tune_settings(struct dvb_frontend *fe, |
Manu Abraham | 14c0386 | 2011-11-24 11:59:53 -0300 | [diff] [blame] | 463 | struct dvb_frontend_tune_settings *s) |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 464 | { |
Antti Palosaari | 75aeafc | 2012-07-19 13:10:12 -0300 | [diff] [blame] | 465 | struct cxd2820r_priv *priv = fe->demodulator_priv; |
Antti Palosaari | e47b78f | 2011-05-03 20:31:36 -0300 | [diff] [blame] | 466 | int ret; |
Manu Abraham | 14c0386 | 2011-11-24 11:59:53 -0300 | [diff] [blame] | 467 | |
Antti Palosaari | 75aeafc | 2012-07-19 13:10:12 -0300 | [diff] [blame] | 468 | dev_dbg(&priv->i2c->dev, "%s: delsys=%d\n", __func__, |
| 469 | fe->dtv_property_cache.delivery_system); |
| 470 | |
Manu Abraham | 14c0386 | 2011-11-24 11:59:53 -0300 | [diff] [blame] | 471 | switch (fe->dtv_property_cache.delivery_system) { |
| 472 | case SYS_DVBT: |
| 473 | ret = cxd2820r_get_tune_settings_t(fe, s); |
| 474 | break; |
| 475 | case SYS_DVBT2: |
| 476 | ret = cxd2820r_get_tune_settings_t2(fe, s); |
| 477 | break; |
Mauro Carvalho Chehab | f311f68 | 2011-12-30 22:22:10 -0300 | [diff] [blame] | 478 | case SYS_DVBC_ANNEX_A: |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 479 | ret = cxd2820r_get_tune_settings_c(fe, s); |
Manu Abraham | 14c0386 | 2011-11-24 11:59:53 -0300 | [diff] [blame] | 480 | break; |
| 481 | default: |
| 482 | ret = -EINVAL; |
| 483 | break; |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 484 | } |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 485 | return ret; |
| 486 | } |
| 487 | |
Mauro Carvalho Chehab | 41da532 | 2011-12-26 18:03:12 -0300 | [diff] [blame] | 488 | static enum dvbfe_search cxd2820r_search(struct dvb_frontend *fe) |
Antti Palosaari | e47b78f | 2011-05-03 20:31:36 -0300 | [diff] [blame] | 489 | { |
| 490 | struct cxd2820r_priv *priv = fe->demodulator_priv; |
| 491 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
| 492 | int ret, i; |
| 493 | fe_status_t status = 0; |
Antti Palosaari | 75aeafc | 2012-07-19 13:10:12 -0300 | [diff] [blame] | 494 | |
| 495 | dev_dbg(&priv->i2c->dev, "%s: delsys=%d\n", __func__, |
| 496 | fe->dtv_property_cache.delivery_system); |
Antti Palosaari | e47b78f | 2011-05-03 20:31:36 -0300 | [diff] [blame] | 497 | |
| 498 | /* switch between DVB-T and DVB-T2 when tune fails */ |
Antti Palosaari | d04ca8d | 2012-01-15 15:08:30 -0300 | [diff] [blame] | 499 | if (priv->last_tune_failed) { |
Antti Palosaari | 7256522 | 2012-01-20 19:48:28 -0300 | [diff] [blame] | 500 | if (priv->delivery_system == SYS_DVBT) { |
| 501 | ret = cxd2820r_sleep_t(fe); |
| 502 | if (ret) |
| 503 | goto error; |
| 504 | |
Antti Palosaari | e47b78f | 2011-05-03 20:31:36 -0300 | [diff] [blame] | 505 | c->delivery_system = SYS_DVBT2; |
Antti Palosaari | 7256522 | 2012-01-20 19:48:28 -0300 | [diff] [blame] | 506 | } else if (priv->delivery_system == SYS_DVBT2) { |
| 507 | ret = cxd2820r_sleep_t2(fe); |
| 508 | if (ret) |
| 509 | goto error; |
| 510 | |
Antti Palosaari | e47b78f | 2011-05-03 20:31:36 -0300 | [diff] [blame] | 511 | c->delivery_system = SYS_DVBT; |
Antti Palosaari | 7256522 | 2012-01-20 19:48:28 -0300 | [diff] [blame] | 512 | } |
Antti Palosaari | e47b78f | 2011-05-03 20:31:36 -0300 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | /* set frontend */ |
Mauro Carvalho Chehab | f311f68 | 2011-12-30 22:22:10 -0300 | [diff] [blame] | 516 | ret = cxd2820r_set_frontend(fe); |
Antti Palosaari | e47b78f | 2011-05-03 20:31:36 -0300 | [diff] [blame] | 517 | if (ret) |
| 518 | goto error; |
| 519 | |
| 520 | |
| 521 | /* frontend lock wait loop count */ |
| 522 | switch (priv->delivery_system) { |
| 523 | case SYS_DVBT: |
Antti Palosaari | 1f64972 | 2012-01-15 16:50:11 -0300 | [diff] [blame] | 524 | case SYS_DVBC_ANNEX_A: |
Antti Palosaari | e47b78f | 2011-05-03 20:31:36 -0300 | [diff] [blame] | 525 | i = 20; |
| 526 | break; |
| 527 | case SYS_DVBT2: |
| 528 | i = 40; |
| 529 | break; |
| 530 | case SYS_UNDEFINED: |
| 531 | default: |
| 532 | i = 0; |
| 533 | break; |
| 534 | } |
| 535 | |
| 536 | /* wait frontend lock */ |
| 537 | for (; i > 0; i--) { |
Antti Palosaari | 75aeafc | 2012-07-19 13:10:12 -0300 | [diff] [blame] | 538 | dev_dbg(&priv->i2c->dev, "%s: loop=%d\n", __func__, i); |
Antti Palosaari | e47b78f | 2011-05-03 20:31:36 -0300 | [diff] [blame] | 539 | msleep(50); |
| 540 | ret = cxd2820r_read_status(fe, &status); |
| 541 | if (ret) |
| 542 | goto error; |
| 543 | |
Gianluca Gennari | b115f40 | 2012-03-15 13:33:47 -0300 | [diff] [blame] | 544 | if (status & FE_HAS_LOCK) |
Antti Palosaari | e47b78f | 2011-05-03 20:31:36 -0300 | [diff] [blame] | 545 | break; |
| 546 | } |
| 547 | |
| 548 | /* check if we have a valid signal */ |
Gianluca Gennari | b115f40 | 2012-03-15 13:33:47 -0300 | [diff] [blame] | 549 | if (status & FE_HAS_LOCK) { |
Antti Palosaari | e47b78f | 2011-05-03 20:31:36 -0300 | [diff] [blame] | 550 | priv->last_tune_failed = 0; |
| 551 | return DVBFE_ALGO_SEARCH_SUCCESS; |
| 552 | } else { |
| 553 | priv->last_tune_failed = 1; |
| 554 | return DVBFE_ALGO_SEARCH_AGAIN; |
| 555 | } |
| 556 | |
| 557 | error: |
Antti Palosaari | 75aeafc | 2012-07-19 13:10:12 -0300 | [diff] [blame] | 558 | dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | e47b78f | 2011-05-03 20:31:36 -0300 | [diff] [blame] | 559 | return DVBFE_ALGO_SEARCH_ERROR; |
| 560 | } |
| 561 | |
| 562 | static int cxd2820r_get_frontend_algo(struct dvb_frontend *fe) |
| 563 | { |
| 564 | return DVBFE_ALGO_CUSTOM; |
| 565 | } |
| 566 | |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 567 | static void cxd2820r_release(struct dvb_frontend *fe) |
| 568 | { |
| 569 | struct cxd2820r_priv *priv = fe->demodulator_priv; |
Antti Palosaari | a36a66d | 2012-08-16 21:07:23 -0300 | [diff] [blame] | 570 | int uninitialized_var(ret); /* silence compiler warning */ |
Antti Palosaari | 75aeafc | 2012-07-19 13:10:12 -0300 | [diff] [blame] | 571 | |
| 572 | dev_dbg(&priv->i2c->dev, "%s\n", __func__); |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 573 | |
Antti Palosaari | 1e8f31f | 2012-07-19 21:10:36 -0300 | [diff] [blame] | 574 | #ifdef CONFIG_GPIOLIB |
| 575 | /* remove GPIOs */ |
| 576 | if (priv->gpio_chip.label) { |
| 577 | ret = gpiochip_remove(&priv->gpio_chip); |
| 578 | if (ret) |
| 579 | dev_err(&priv->i2c->dev, "%s: gpiochip_remove() " \ |
| 580 | "failed=%d\n", KBUILD_MODNAME, ret); |
| 581 | } |
| 582 | #endif |
Manu Abraham | 14c0386 | 2011-11-24 11:59:53 -0300 | [diff] [blame] | 583 | kfree(priv); |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 584 | return; |
| 585 | } |
| 586 | |
Steve Kerrison | 0db4bf4 | 2011-08-09 07:16:21 -0300 | [diff] [blame] | 587 | static int cxd2820r_i2c_gate_ctrl(struct dvb_frontend *fe, int enable) |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 588 | { |
| 589 | struct cxd2820r_priv *priv = fe->demodulator_priv; |
Antti Palosaari | 75aeafc | 2012-07-19 13:10:12 -0300 | [diff] [blame] | 590 | |
| 591 | dev_dbg(&priv->i2c->dev, "%s: %d\n", __func__, enable); |
Steve Kerrison | 0db4bf4 | 2011-08-09 07:16:21 -0300 | [diff] [blame] | 592 | |
| 593 | /* Bit 0 of reg 0xdb in bank 0x00 controls I2C repeater */ |
| 594 | return cxd2820r_wr_reg_mask(priv, 0xdb, enable ? 1 : 0, 0x1); |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 595 | } |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 596 | |
Antti Palosaari | 1e8f31f | 2012-07-19 21:10:36 -0300 | [diff] [blame] | 597 | #ifdef CONFIG_GPIOLIB |
| 598 | static int cxd2820r_gpio_direction_output(struct gpio_chip *chip, unsigned nr, |
| 599 | int val) |
| 600 | { |
| 601 | struct cxd2820r_priv *priv = |
| 602 | container_of(chip, struct cxd2820r_priv, gpio_chip); |
| 603 | u8 gpio[GPIO_COUNT]; |
| 604 | |
| 605 | dev_dbg(&priv->i2c->dev, "%s: nr=%d val=%d\n", __func__, nr, val); |
| 606 | |
| 607 | memcpy(gpio, priv->gpio, sizeof(gpio)); |
| 608 | gpio[nr] = CXD2820R_GPIO_E | CXD2820R_GPIO_O | (val << 2); |
| 609 | |
| 610 | return cxd2820r_gpio(&priv->fe, gpio); |
| 611 | } |
| 612 | |
| 613 | static void cxd2820r_gpio_set(struct gpio_chip *chip, unsigned nr, int val) |
| 614 | { |
| 615 | struct cxd2820r_priv *priv = |
| 616 | container_of(chip, struct cxd2820r_priv, gpio_chip); |
| 617 | u8 gpio[GPIO_COUNT]; |
| 618 | |
| 619 | dev_dbg(&priv->i2c->dev, "%s: nr=%d val=%d\n", __func__, nr, val); |
| 620 | |
| 621 | memcpy(gpio, priv->gpio, sizeof(gpio)); |
| 622 | gpio[nr] = CXD2820R_GPIO_E | CXD2820R_GPIO_O | (val << 2); |
| 623 | |
| 624 | (void) cxd2820r_gpio(&priv->fe, gpio); |
| 625 | |
| 626 | return; |
| 627 | } |
| 628 | |
| 629 | static int cxd2820r_gpio_get(struct gpio_chip *chip, unsigned nr) |
| 630 | { |
| 631 | struct cxd2820r_priv *priv = |
| 632 | container_of(chip, struct cxd2820r_priv, gpio_chip); |
| 633 | |
| 634 | dev_dbg(&priv->i2c->dev, "%s: nr=%d\n", __func__, nr); |
| 635 | |
| 636 | return (priv->gpio[nr] >> 2) & 0x01; |
| 637 | } |
| 638 | #endif |
| 639 | |
Manu Abraham | 14c0386 | 2011-11-24 11:59:53 -0300 | [diff] [blame] | 640 | static const struct dvb_frontend_ops cxd2820r_ops = { |
Mauro Carvalho Chehab | f311f68 | 2011-12-30 22:22:10 -0300 | [diff] [blame] | 641 | .delsys = { SYS_DVBT, SYS_DVBT2, SYS_DVBC_ANNEX_A }, |
Manu Abraham | 14c0386 | 2011-11-24 11:59:53 -0300 | [diff] [blame] | 642 | /* default: DVB-T/T2 */ |
| 643 | .info = { |
Antti Palosaari | 9bf31ef | 2012-01-18 13:57:33 -0300 | [diff] [blame] | 644 | .name = "Sony CXD2820R", |
Manu Abraham | 14c0386 | 2011-11-24 11:59:53 -0300 | [diff] [blame] | 645 | |
| 646 | .caps = FE_CAN_FEC_1_2 | |
| 647 | FE_CAN_FEC_2_3 | |
| 648 | FE_CAN_FEC_3_4 | |
| 649 | FE_CAN_FEC_5_6 | |
| 650 | FE_CAN_FEC_7_8 | |
| 651 | FE_CAN_FEC_AUTO | |
| 652 | FE_CAN_QPSK | |
| 653 | FE_CAN_QAM_16 | |
Antti Palosaari | 9bf31ef | 2012-01-18 13:57:33 -0300 | [diff] [blame] | 654 | FE_CAN_QAM_32 | |
Manu Abraham | 14c0386 | 2011-11-24 11:59:53 -0300 | [diff] [blame] | 655 | FE_CAN_QAM_64 | |
Antti Palosaari | 9bf31ef | 2012-01-18 13:57:33 -0300 | [diff] [blame] | 656 | FE_CAN_QAM_128 | |
Manu Abraham | 14c0386 | 2011-11-24 11:59:53 -0300 | [diff] [blame] | 657 | FE_CAN_QAM_256 | |
| 658 | FE_CAN_QAM_AUTO | |
| 659 | FE_CAN_TRANSMISSION_MODE_AUTO | |
| 660 | FE_CAN_GUARD_INTERVAL_AUTO | |
| 661 | FE_CAN_HIERARCHY_AUTO | |
| 662 | FE_CAN_MUTE_TS | |
Evgeny Plehov | 4a74772 | 2013-04-07 23:56:46 -0300 | [diff] [blame] | 663 | FE_CAN_2G_MODULATION | |
| 664 | FE_CAN_MULTISTREAM |
Manu Abraham | 14c0386 | 2011-11-24 11:59:53 -0300 | [diff] [blame] | 665 | }, |
| 666 | |
| 667 | .release = cxd2820r_release, |
| 668 | .init = cxd2820r_init, |
| 669 | .sleep = cxd2820r_sleep, |
| 670 | |
| 671 | .get_tune_settings = cxd2820r_get_tune_settings, |
| 672 | .i2c_gate_ctrl = cxd2820r_i2c_gate_ctrl, |
| 673 | |
Mauro Carvalho Chehab | f311f68 | 2011-12-30 22:22:10 -0300 | [diff] [blame] | 674 | .get_frontend = cxd2820r_get_frontend, |
Manu Abraham | 14c0386 | 2011-11-24 11:59:53 -0300 | [diff] [blame] | 675 | |
| 676 | .get_frontend_algo = cxd2820r_get_frontend_algo, |
| 677 | .search = cxd2820r_search, |
| 678 | |
| 679 | .read_status = cxd2820r_read_status, |
| 680 | .read_snr = cxd2820r_read_snr, |
| 681 | .read_ber = cxd2820r_read_ber, |
| 682 | .read_ucblocks = cxd2820r_read_ucblocks, |
| 683 | .read_signal_strength = cxd2820r_read_signal_strength, |
Manu Abraham | 14c0386 | 2011-11-24 11:59:53 -0300 | [diff] [blame] | 684 | }; |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 685 | |
| 686 | struct dvb_frontend *cxd2820r_attach(const struct cxd2820r_config *cfg, |
Antti Palosaari | 1e8f31f | 2012-07-19 21:10:36 -0300 | [diff] [blame] | 687 | struct i2c_adapter *i2c, int *gpio_chip_base |
| 688 | ) |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 689 | { |
Antti Palosaari | 1e8f31f | 2012-07-19 21:10:36 -0300 | [diff] [blame] | 690 | struct cxd2820r_priv *priv; |
Manu Abraham | 14c0386 | 2011-11-24 11:59:53 -0300 | [diff] [blame] | 691 | int ret; |
Antti Palosaari | 44e0d7d | 2012-10-05 18:50:12 -0300 | [diff] [blame] | 692 | u8 tmp; |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 693 | |
Antti Palosaari | a36a66d | 2012-08-16 21:07:23 -0300 | [diff] [blame] | 694 | priv = kzalloc(sizeof(struct cxd2820r_priv), GFP_KERNEL); |
Antti Palosaari | 1e8f31f | 2012-07-19 21:10:36 -0300 | [diff] [blame] | 695 | if (!priv) { |
| 696 | ret = -ENOMEM; |
| 697 | dev_err(&i2c->dev, "%s: kzalloc() failed\n", |
| 698 | KBUILD_MODNAME); |
Manu Abraham | 14c0386 | 2011-11-24 11:59:53 -0300 | [diff] [blame] | 699 | goto error; |
Antti Palosaari | 1e8f31f | 2012-07-19 21:10:36 -0300 | [diff] [blame] | 700 | } |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 701 | |
Manu Abraham | 14c0386 | 2011-11-24 11:59:53 -0300 | [diff] [blame] | 702 | priv->i2c = i2c; |
Antti Palosaari | a36a66d | 2012-08-16 21:07:23 -0300 | [diff] [blame] | 703 | memcpy(&priv->cfg, cfg, sizeof(struct cxd2820r_config)); |
| 704 | memcpy(&priv->fe.ops, &cxd2820r_ops, sizeof(struct dvb_frontend_ops)); |
| 705 | priv->fe.demodulator_priv = priv; |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 706 | |
Manu Abraham | 14c0386 | 2011-11-24 11:59:53 -0300 | [diff] [blame] | 707 | priv->bank[0] = priv->bank[1] = 0xff; |
| 708 | ret = cxd2820r_rd_reg(priv, 0x000fd, &tmp); |
Antti Palosaari | 75aeafc | 2012-07-19 13:10:12 -0300 | [diff] [blame] | 709 | dev_dbg(&priv->i2c->dev, "%s: chip id=%02x\n", __func__, tmp); |
Manu Abraham | 14c0386 | 2011-11-24 11:59:53 -0300 | [diff] [blame] | 710 | if (ret || tmp != 0xe1) |
| 711 | goto error; |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 712 | |
Antti Palosaari | 1e8f31f | 2012-07-19 21:10:36 -0300 | [diff] [blame] | 713 | if (gpio_chip_base) { |
Antti Palosaari | a36a66d | 2012-08-16 21:07:23 -0300 | [diff] [blame] | 714 | #ifdef CONFIG_GPIOLIB |
| 715 | /* add GPIOs */ |
Antti Palosaari | 1e8f31f | 2012-07-19 21:10:36 -0300 | [diff] [blame] | 716 | priv->gpio_chip.label = KBUILD_MODNAME; |
| 717 | priv->gpio_chip.dev = &priv->i2c->dev; |
| 718 | priv->gpio_chip.owner = THIS_MODULE; |
| 719 | priv->gpio_chip.direction_output = |
| 720 | cxd2820r_gpio_direction_output; |
| 721 | priv->gpio_chip.set = cxd2820r_gpio_set; |
| 722 | priv->gpio_chip.get = cxd2820r_gpio_get; |
| 723 | priv->gpio_chip.base = -1; /* dynamic allocation */ |
| 724 | priv->gpio_chip.ngpio = GPIO_COUNT; |
| 725 | priv->gpio_chip.can_sleep = 1; |
| 726 | ret = gpiochip_add(&priv->gpio_chip); |
| 727 | if (ret) |
| 728 | goto error; |
| 729 | |
| 730 | dev_dbg(&priv->i2c->dev, "%s: gpio_chip.base=%d\n", __func__, |
| 731 | priv->gpio_chip.base); |
| 732 | |
| 733 | *gpio_chip_base = priv->gpio_chip.base; |
Antti Palosaari | a36a66d | 2012-08-16 21:07:23 -0300 | [diff] [blame] | 734 | #else |
| 735 | /* |
| 736 | * Use static GPIO configuration if GPIOLIB is undefined. |
| 737 | * This is fallback condition. |
| 738 | */ |
Antti Palosaari | 44e0d7d | 2012-10-05 18:50:12 -0300 | [diff] [blame] | 739 | u8 gpio[GPIO_COUNT]; |
Antti Palosaari | a36a66d | 2012-08-16 21:07:23 -0300 | [diff] [blame] | 740 | gpio[0] = (*gpio_chip_base >> 0) & 0x07; |
| 741 | gpio[1] = (*gpio_chip_base >> 3) & 0x07; |
| 742 | gpio[2] = 0; |
| 743 | ret = cxd2820r_gpio(&priv->fe, gpio); |
| 744 | if (ret) |
| 745 | goto error; |
Antti Palosaari | 1e8f31f | 2012-07-19 21:10:36 -0300 | [diff] [blame] | 746 | #endif |
Antti Palosaari | a36a66d | 2012-08-16 21:07:23 -0300 | [diff] [blame] | 747 | } |
Antti Palosaari | 1e8f31f | 2012-07-19 21:10:36 -0300 | [diff] [blame] | 748 | |
Manu Abraham | 14c0386 | 2011-11-24 11:59:53 -0300 | [diff] [blame] | 749 | return &priv->fe; |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 750 | error: |
Antti Palosaari | 1e8f31f | 2012-07-19 21:10:36 -0300 | [diff] [blame] | 751 | dev_dbg(&i2c->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 752 | kfree(priv); |
| 753 | return NULL; |
| 754 | } |
| 755 | EXPORT_SYMBOL(cxd2820r_attach); |
| 756 | |
Antti Palosaari | 27cfc85 | 2011-04-07 16:27:43 -0300 | [diff] [blame] | 757 | MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>"); |
| 758 | MODULE_DESCRIPTION("Sony CXD2820R demodulator driver"); |
| 759 | MODULE_LICENSE("GPL"); |