.. | .. |
---|
5 | 5 | |
---|
6 | 6 | #include <linux/kernel.h> |
---|
7 | 7 | #include <linux/delay.h> |
---|
| 8 | +#include <linux/i2c.h> |
---|
8 | 9 | #include <linux/platform_device.h> |
---|
| 10 | +#include <linux/regulator/consumer.h> |
---|
9 | 11 | #include <linux/gpio/consumer.h> |
---|
10 | 12 | #include <linux/module.h> |
---|
11 | 13 | #include <linux/of.h> |
---|
12 | 14 | #include <linux/of_gpio.h> |
---|
13 | 15 | #include <linux/notifier.h> |
---|
14 | 16 | #include <linux/fb.h> |
---|
| 17 | +#include <linux/regmap.h> |
---|
| 18 | +#include <linux/clk.h> |
---|
| 19 | +#include "lt7911d-fw.h" |
---|
15 | 20 | |
---|
16 | 21 | struct lt7911d { |
---|
17 | 22 | struct device *dev; |
---|
18 | | - struct gpio_descs *gpios; |
---|
| 23 | + struct regmap *regmap; |
---|
| 24 | + struct serdes_init_seq *serdes_init_seq; |
---|
| 25 | + struct gpio_desc *reset_gpio; |
---|
| 26 | + struct gpio_desc *enable_gpio; |
---|
19 | 27 | struct notifier_block fb_notif; |
---|
20 | 28 | int fb_blank; |
---|
| 29 | +}; |
---|
| 30 | + |
---|
| 31 | +static int Datalen = 17594; |
---|
| 32 | +/*to save hdcp key */ |
---|
| 33 | +static unsigned char HdcpKey[286]; |
---|
| 34 | +/*the buffer to read flash, its size should be equal the size of bin, max size is 24KB*/ |
---|
| 35 | +static unsigned char ReadFirmware[17594]; |
---|
| 36 | +/*The buffer to read flash, hex->bin->txt*/ |
---|
| 37 | +//static unsigned char FirmwareData[17594]; |
---|
| 38 | + |
---|
| 39 | +static int I2C_Write_Byte(struct lt7911d *lt7911d, unsigned char reg, unsigned char val) |
---|
| 40 | +{ |
---|
| 41 | + int ret; |
---|
| 42 | + |
---|
| 43 | + ret = regmap_write(lt7911d->regmap, reg, val); |
---|
| 44 | + if (ret < 0) { |
---|
| 45 | + pr_info("failed to write lt7911d register 0x%x: %d\n", reg, ret); |
---|
| 46 | + return ret; |
---|
| 47 | + } |
---|
| 48 | + return 0; |
---|
| 49 | +} |
---|
| 50 | + |
---|
| 51 | +static unsigned char I2C_Read_Byte(struct lt7911d *lt7911d, unsigned char reg) |
---|
| 52 | +{ |
---|
| 53 | + int ret; |
---|
| 54 | + unsigned int val; |
---|
| 55 | + |
---|
| 56 | + ret = regmap_read(lt7911d->regmap, reg, &val); |
---|
| 57 | + if (ret < 0) { |
---|
| 58 | + pr_info("failed to read lt7911d register 0x%x: %d\n", reg, ret); |
---|
| 59 | + return ret; |
---|
| 60 | + } |
---|
| 61 | + |
---|
| 62 | + return (unsigned char)val; |
---|
| 63 | +} |
---|
| 64 | + |
---|
| 65 | +static bool lt7911d_check_chip_id(struct lt7911d *lt7911d) |
---|
| 66 | +{ |
---|
| 67 | + unsigned char id_h, id_l; |
---|
| 68 | + |
---|
| 69 | + /*0x80ee=0x01 to enable i2c interface*/ |
---|
| 70 | + I2C_Write_Byte(lt7911d, 0xFF, 0x80); |
---|
| 71 | + I2C_Write_Byte(lt7911d, 0xEE, 0x01); |
---|
| 72 | + /*write bank 0xa0, read 0xa000 and 0xa001*/ |
---|
| 73 | + I2C_Write_Byte(lt7911d, 0xFF, 0xA0); |
---|
| 74 | + id_h = I2C_Read_Byte(lt7911d, 0x00); |
---|
| 75 | + id_l = I2C_Read_Byte(lt7911d, 0x01); |
---|
| 76 | + |
---|
| 77 | + /*chip id=0x1605*/ |
---|
| 78 | + if ((id_h == 0x16) && (id_l == 0x05)) { |
---|
| 79 | + pr_info("%s chip id =0x1605\n", __func__); |
---|
| 80 | + /*0x80ee=0x00 to disable i2c*/ |
---|
| 81 | + I2C_Write_Byte(lt7911d, 0xFF, 0x80); |
---|
| 82 | + I2C_Write_Byte(lt7911d, 0xEE, 0x00); |
---|
| 83 | + return true; |
---|
| 84 | + } else { |
---|
| 85 | + pr_info("%s chip id 0x%x is not 0x1605\n", __func__, (id_h << 8) | id_l); |
---|
| 86 | + /*0x80ee=0x00 to disable i2c*/ |
---|
| 87 | + I2C_Write_Byte(lt7911d, 0xFF, 0x80); |
---|
| 88 | + I2C_Write_Byte(lt7911d, 0xEE, 0x00); |
---|
| 89 | + return false; |
---|
| 90 | + } |
---|
| 91 | +} |
---|
| 92 | + |
---|
| 93 | +static int lt7911d_check_fw_version(struct lt7911d *lt7911d) |
---|
| 94 | +{ |
---|
| 95 | + unsigned char fw; |
---|
| 96 | + |
---|
| 97 | + I2C_Write_Byte(lt7911d, 0xFF, 0x80); |
---|
| 98 | + I2C_Write_Byte(lt7911d, 0xEE, 0x01); |
---|
| 99 | + |
---|
| 100 | + /*read 0xD211*/ |
---|
| 101 | + I2C_Write_Byte(lt7911d, 0xFF, 0xD2); |
---|
| 102 | + fw = I2C_Read_Byte(lt7911d, 0x11); |
---|
| 103 | + |
---|
| 104 | + /*fw version address is 0x1dfb*/ |
---|
| 105 | + if (fw < FirmwareData[0x1dfb]) { |
---|
| 106 | + pr_info("%s fw %d<%d, need to upgrade\n", __func__, fw, FirmwareData[0x1dfb]); |
---|
| 107 | + I2C_Write_Byte(lt7911d, 0xFF, 0x80); |
---|
| 108 | + I2C_Write_Byte(lt7911d, 0xEE, 0x00); |
---|
| 109 | + return 0; |
---|
| 110 | + } else { |
---|
| 111 | + pr_info("%s fw %d>=%d, no need upgrade\n", __func__, fw, FirmwareData[0x1dfb]); |
---|
| 112 | + I2C_Write_Byte(lt7911d, 0xFF, 0x80); |
---|
| 113 | + I2C_Write_Byte(lt7911d, 0xEE, 0x00); |
---|
| 114 | + return -1; |
---|
| 115 | + } |
---|
| 116 | +} |
---|
| 117 | + |
---|
| 118 | +static void lt7911d_config_para(struct lt7911d *lt7911d) |
---|
| 119 | +{ |
---|
| 120 | + I2C_Write_Byte(lt7911d, 0xFF, 0x80); |
---|
| 121 | + I2C_Write_Byte(lt7911d, 0xEE, 0x01); |
---|
| 122 | + I2C_Write_Byte(lt7911d, 0x5A, 0x82); |
---|
| 123 | + I2C_Write_Byte(lt7911d, 0x5E, 0xC0); |
---|
| 124 | + I2C_Write_Byte(lt7911d, 0x58, 0x00); |
---|
| 125 | + I2C_Write_Byte(lt7911d, 0x59, 0x51); |
---|
| 126 | + I2C_Write_Byte(lt7911d, 0x5A, 0x92); |
---|
| 127 | + I2C_Write_Byte(lt7911d, 0x5A, 0x82); |
---|
| 128 | +} |
---|
| 129 | + |
---|
| 130 | +static void lt7911d_block_erase(struct lt7911d *lt7911d) |
---|
| 131 | +{ |
---|
| 132 | + I2C_Write_Byte(lt7911d, 0xFF, 0x80); |
---|
| 133 | + I2C_Write_Byte(lt7911d, 0xEE, 0x01); |
---|
| 134 | + I2C_Write_Byte(lt7911d, 0x5A, 0x86); |
---|
| 135 | + I2C_Write_Byte(lt7911d, 0x5A, 0x82); |
---|
| 136 | + I2C_Write_Byte(lt7911d, 0x5B, 0x00); |
---|
| 137 | + I2C_Write_Byte(lt7911d, 0x5C, 0x00); |
---|
| 138 | + I2C_Write_Byte(lt7911d, 0x5D, 0x00); |
---|
| 139 | + I2C_Write_Byte(lt7911d, 0x5A, 0x83); |
---|
| 140 | + I2C_Write_Byte(lt7911d, 0x5A, 0x82); |
---|
| 141 | + |
---|
| 142 | + /*The time to waiting for earse flash*/ |
---|
| 143 | + msleep(500); |
---|
| 144 | +} |
---|
| 145 | + |
---|
| 146 | +/*If earse flash will erase the hdcp key, so need to backup firstly*/ |
---|
| 147 | +static void SaveHdcpKeyFromFlash(struct lt7911d *lt7911d) |
---|
| 148 | +{ |
---|
| 149 | + unsigned int StartAddr; |
---|
| 150 | + unsigned int npage, i, j; |
---|
| 151 | + unsigned char npagelen = 0; |
---|
| 152 | + unsigned char addr[3] = {0}; |
---|
| 153 | + |
---|
| 154 | + I2C_Write_Byte(lt7911d, 0xFF, 0x80); |
---|
| 155 | + I2C_Write_Byte(lt7911d, 0xEE, 0x01); |
---|
| 156 | + I2C_Write_Byte(lt7911d, 0xFF, 0x90); |
---|
| 157 | + I2C_Write_Byte(lt7911d, 0x02, 0xdf); |
---|
| 158 | + I2C_Write_Byte(lt7911d, 0x02, 0xff); |
---|
| 159 | + I2C_Write_Byte(lt7911d, 0xFF, 0x80); |
---|
| 160 | + I2C_Write_Byte(lt7911d, 0x5a, 0x86); |
---|
| 161 | + I2C_Write_Byte(lt7911d, 0x5a, 0x82); |
---|
| 162 | + |
---|
| 163 | + /*The first address of HDCP KEY*/ |
---|
| 164 | + StartAddr = 0x006000; |
---|
| 165 | + addr[0] = (StartAddr & 0xFF0000) >> 16; |
---|
| 166 | + addr[1] = (StartAddr & 0xFF00) >> 8; |
---|
| 167 | + addr[2] = StartAddr & 0xFF; |
---|
| 168 | + |
---|
| 169 | + /*hdcp key size is 286 byte*/ |
---|
| 170 | + npage = 18; |
---|
| 171 | + npagelen = 16; |
---|
| 172 | + |
---|
| 173 | + for (i = 0; i < npage; i++) { |
---|
| 174 | + I2C_Write_Byte(lt7911d, 0x5E, 0x6f); |
---|
| 175 | + I2C_Write_Byte(lt7911d, 0x5A, 0xA2); |
---|
| 176 | + I2C_Write_Byte(lt7911d, 0x5A, 0x82); |
---|
| 177 | + I2C_Write_Byte(lt7911d, 0x5B, addr[0]); |
---|
| 178 | + I2C_Write_Byte(lt7911d, 0x5C, addr[1]); |
---|
| 179 | + I2C_Write_Byte(lt7911d, 0x5D, addr[2]); |
---|
| 180 | + I2C_Write_Byte(lt7911d, 0x5A, 0x92); |
---|
| 181 | + I2C_Write_Byte(lt7911d, 0x5A, 0x82); |
---|
| 182 | + I2C_Write_Byte(lt7911d, 0x58, 0x01); |
---|
| 183 | + |
---|
| 184 | + if (i == 17) |
---|
| 185 | + npagelen = 14; |
---|
| 186 | + |
---|
| 187 | + for (j = 0; j < npagelen; j++) |
---|
| 188 | + HdcpKey[i * 16 + j] = I2C_Read_Byte(lt7911d, 0x5F); |
---|
| 189 | + |
---|
| 190 | + StartAddr += 16; |
---|
| 191 | + addr[0] = (StartAddr & 0xFF0000) >> 16; |
---|
| 192 | + addr[1] = (StartAddr & 0xFF00) >> 8; |
---|
| 193 | + addr[2] = StartAddr & 0xFF; |
---|
| 194 | + } |
---|
| 195 | + |
---|
| 196 | + I2C_Write_Byte(lt7911d, 0x5a, 0x8a); |
---|
| 197 | + I2C_Write_Byte(lt7911d, 0x5a, 0x82); |
---|
| 198 | +} |
---|
| 199 | + |
---|
| 200 | +static void lt7911d_write_firmware_to_flash(struct lt7911d *lt7911d) |
---|
| 201 | +{ |
---|
| 202 | + unsigned int StartAddr; |
---|
| 203 | + unsigned int npage, i, j; |
---|
| 204 | + unsigned char npagelen = 0; |
---|
| 205 | + unsigned char addr[3] = {0}; |
---|
| 206 | + |
---|
| 207 | + I2C_Write_Byte(lt7911d, 0xFF, 0x80); |
---|
| 208 | + I2C_Write_Byte(lt7911d, 0xEE, 0x01); |
---|
| 209 | + I2C_Write_Byte(lt7911d, 0xFF, 0x90); |
---|
| 210 | + I2C_Write_Byte(lt7911d, 0x02, 0xdf); |
---|
| 211 | + I2C_Write_Byte(lt7911d, 0x02, 0xff); |
---|
| 212 | + I2C_Write_Byte(lt7911d, 0xFF, 0x80); |
---|
| 213 | + I2C_Write_Byte(lt7911d, 0x5a, 0x86); |
---|
| 214 | + I2C_Write_Byte(lt7911d, 0x5a, 0x82); |
---|
| 215 | + |
---|
| 216 | + /*The first address of flash£¬Max Size 24K*/ |
---|
| 217 | + StartAddr = 0x000000; |
---|
| 218 | + addr[0] = (StartAddr & 0xFF0000) >> 16; |
---|
| 219 | + addr[1] = (StartAddr & 0xFF00) >> 8; |
---|
| 220 | + addr[2] = StartAddr & 0xFF; |
---|
| 221 | + |
---|
| 222 | + if (Datalen % 16) { |
---|
| 223 | + /*Datalen is the length of the firmware.*/ |
---|
| 224 | + npage = Datalen / 16 + 1; |
---|
| 225 | + } else { |
---|
| 226 | + npage = Datalen / 16; |
---|
| 227 | + } |
---|
| 228 | + npagelen = 16; |
---|
| 229 | + |
---|
| 230 | + for (i = 0; i < npage; i++) { |
---|
| 231 | + I2C_Write_Byte(lt7911d, 0x5A, 0x86); |
---|
| 232 | + I2C_Write_Byte(lt7911d, 0x5A, 0x82); |
---|
| 233 | + |
---|
| 234 | + I2C_Write_Byte(lt7911d, 0x5E, 0xef); |
---|
| 235 | + I2C_Write_Byte(lt7911d, 0x5A, 0xA2); |
---|
| 236 | + I2C_Write_Byte(lt7911d, 0x5A, 0x82); |
---|
| 237 | + I2C_Write_Byte(lt7911d, 0x58, 0x01); |
---|
| 238 | + |
---|
| 239 | + if ((Datalen - i * 16) < 16) |
---|
| 240 | + npagelen = Datalen - i*16; |
---|
| 241 | + |
---|
| 242 | + for (j = 0; j < npagelen; j++) { |
---|
| 243 | + /*please just continue to write data to 0x59,*/ |
---|
| 244 | + /*and lt7911d will increase the address auto use 0xff*/ |
---|
| 245 | + /*as insufficient data if datelen%16 is not zero*/ |
---|
| 246 | + I2C_Write_Byte(lt7911d, 0x59, FirmwareData[i*16 + j]); |
---|
| 247 | + } |
---|
| 248 | + |
---|
| 249 | + /*change the first address*/ |
---|
| 250 | + I2C_Write_Byte(lt7911d, 0x5B, addr[0]); |
---|
| 251 | + I2C_Write_Byte(lt7911d, 0x5C, addr[1]); |
---|
| 252 | + I2C_Write_Byte(lt7911d, 0x5D, addr[2]); |
---|
| 253 | + I2C_Write_Byte(lt7911d, 0x5E, 0xE0); |
---|
| 254 | + I2C_Write_Byte(lt7911d, 0x5A, 0x92); |
---|
| 255 | + I2C_Write_Byte(lt7911d, 0x5A, 0x82); |
---|
| 256 | + |
---|
| 257 | + StartAddr += 16; |
---|
| 258 | + addr[0] = (StartAddr & 0xFF0000) >> 16; |
---|
| 259 | + addr[1] = (StartAddr & 0xFF00) >> 8; |
---|
| 260 | + addr[2] = StartAddr & 0xFF; |
---|
| 261 | + } |
---|
| 262 | + |
---|
| 263 | + I2C_Write_Byte(lt7911d, 0x5a, 0x8a); |
---|
| 264 | + I2C_Write_Byte(lt7911d, 0x5a, 0x82); |
---|
| 265 | + |
---|
| 266 | + /*reset fifo*/ |
---|
| 267 | + I2C_Write_Byte(lt7911d, 0xFF, 0x90); |
---|
| 268 | + I2C_Write_Byte(lt7911d, 0x02, 0xDF); |
---|
| 269 | + I2C_Write_Byte(lt7911d, 0x02, 0xFF); |
---|
| 270 | + msleep(20); |
---|
| 271 | +} |
---|
| 272 | + |
---|
| 273 | +static void lt7911d_write_hdcpkey_to_flash(struct lt7911d *lt7911d) |
---|
| 274 | +{ |
---|
| 275 | + unsigned int StartAddr; |
---|
| 276 | + unsigned int npage, i, j; |
---|
| 277 | + unsigned char npagelen = 0; |
---|
| 278 | + unsigned char addr[3] = {0}; |
---|
| 279 | + |
---|
| 280 | + I2C_Write_Byte(lt7911d, 0xFF, 0x80); |
---|
| 281 | + I2C_Write_Byte(lt7911d, 0xEE, 0x01); |
---|
| 282 | + I2C_Write_Byte(lt7911d, 0xFF, 0x90); |
---|
| 283 | + I2C_Write_Byte(lt7911d, 0x02, 0xdf); |
---|
| 284 | + I2C_Write_Byte(lt7911d, 0x02, 0xff); |
---|
| 285 | + I2C_Write_Byte(lt7911d, 0xFF, 0x80); |
---|
| 286 | + I2C_Write_Byte(lt7911d, 0x5a, 0x86); |
---|
| 287 | + I2C_Write_Byte(lt7911d, 0x5a, 0x82); |
---|
| 288 | + |
---|
| 289 | + /*hdcp key first address*/ |
---|
| 290 | + StartAddr = 0x006000; |
---|
| 291 | + addr[0] = (StartAddr & 0xFF0000) >> 16; |
---|
| 292 | + addr[1] = (StartAddr & 0xFF00) >> 8; |
---|
| 293 | + addr[2] = StartAddr & 0xFF; |
---|
| 294 | + |
---|
| 295 | + npage = 18; |
---|
| 296 | + npagelen = 16; |
---|
| 297 | + |
---|
| 298 | + for (i = 0; i < npage; i++) { |
---|
| 299 | + I2C_Write_Byte(lt7911d, 0x5A, 0x86); |
---|
| 300 | + I2C_Write_Byte(lt7911d, 0x5A, 0x82); |
---|
| 301 | + |
---|
| 302 | + I2C_Write_Byte(lt7911d, 0x5E, 0xef); |
---|
| 303 | + I2C_Write_Byte(lt7911d, 0x5A, 0xA2); |
---|
| 304 | + I2C_Write_Byte(lt7911d, 0x5A, 0x82); |
---|
| 305 | + I2C_Write_Byte(lt7911d, 0x58, 0x01); |
---|
| 306 | + |
---|
| 307 | + if (i == 17) |
---|
| 308 | + npagelen = 14; |
---|
| 309 | + |
---|
| 310 | + for (j = 0; j < npagelen; j++) { |
---|
| 311 | + /*please just continue to write data to 0x59,*/ |
---|
| 312 | + /*and lt7911d will increase the address auto use 0xff*/ |
---|
| 313 | + /*as insufficient data if datelen%16 is not zero .*/ |
---|
| 314 | + I2C_Write_Byte(lt7911d, 0x59, HdcpKey[i*16 + j]); |
---|
| 315 | + } |
---|
| 316 | + |
---|
| 317 | + if (npagelen == 14) { |
---|
| 318 | + I2C_Write_Byte(lt7911d, 0x59, 0xFF); |
---|
| 319 | + I2C_Write_Byte(lt7911d, 0x59, 0xFF); |
---|
| 320 | + } |
---|
| 321 | + |
---|
| 322 | + /*change the first address*/ |
---|
| 323 | + I2C_Write_Byte(lt7911d, 0x5B, addr[0]); |
---|
| 324 | + I2C_Write_Byte(lt7911d, 0x5C, addr[1]); |
---|
| 325 | + I2C_Write_Byte(lt7911d, 0x5D, addr[2]); |
---|
| 326 | + I2C_Write_Byte(lt7911d, 0x5E, 0xE0); |
---|
| 327 | + I2C_Write_Byte(lt7911d, 0x5A, 0x92); |
---|
| 328 | + I2C_Write_Byte(lt7911d, 0x5A, 0x82); |
---|
| 329 | + |
---|
| 330 | + StartAddr += 16; |
---|
| 331 | + addr[0] = (StartAddr & 0xFF0000) >> 16; |
---|
| 332 | + addr[1] = (StartAddr & 0xFF00) >> 8; |
---|
| 333 | + addr[2] = StartAddr & 0xFF; |
---|
| 334 | + } |
---|
| 335 | + |
---|
| 336 | + I2C_Write_Byte(lt7911d, 0x5a, 0x8a); |
---|
| 337 | + I2C_Write_Byte(lt7911d, 0x5a, 0x82); |
---|
| 338 | + |
---|
| 339 | + /*reset fifo*/ |
---|
| 340 | + I2C_Write_Byte(lt7911d, 0xFF, 0x90); |
---|
| 341 | + I2C_Write_Byte(lt7911d, 0x02, 0xDF); |
---|
| 342 | + I2C_Write_Byte(lt7911d, 0x02, 0xFF); |
---|
| 343 | + msleep(20); |
---|
| 344 | +} |
---|
| 345 | + |
---|
| 346 | +static void lt7911d_read_firmware_from_flash(struct lt7911d *lt7911d) |
---|
| 347 | +{ |
---|
| 348 | + unsigned int StartAddr; |
---|
| 349 | + unsigned int npage, i, j; |
---|
| 350 | + unsigned char npagelen = 0; |
---|
| 351 | + unsigned char addr[3] = {0}; |
---|
| 352 | + |
---|
| 353 | + memset(ReadFirmware, 0, sizeof(ReadFirmware)); |
---|
| 354 | + |
---|
| 355 | + I2C_Write_Byte(lt7911d, 0xFF, 0x80); |
---|
| 356 | + I2C_Write_Byte(lt7911d, 0xEE, 0x01); |
---|
| 357 | + I2C_Write_Byte(lt7911d, 0xFF, 0x90); |
---|
| 358 | + I2C_Write_Byte(lt7911d, 0x02, 0xdf); |
---|
| 359 | + I2C_Write_Byte(lt7911d, 0x02, 0xff); |
---|
| 360 | + I2C_Write_Byte(lt7911d, 0xFF, 0x80); |
---|
| 361 | + I2C_Write_Byte(lt7911d, 0x5a, 0x86); |
---|
| 362 | + I2C_Write_Byte(lt7911d, 0x5a, 0x82); |
---|
| 363 | + |
---|
| 364 | + /*the first address of firmware*/ |
---|
| 365 | + StartAddr = 0x000000; |
---|
| 366 | + addr[0] = (StartAddr & 0xFF0000) >> 16; |
---|
| 367 | + addr[1] = (StartAddr & 0xFF00) >> 8; |
---|
| 368 | + addr[2] = StartAddr & 0xFF; |
---|
| 369 | + |
---|
| 370 | + if (Datalen % 16) |
---|
| 371 | + npage = Datalen / 16 + 1; |
---|
| 372 | + else |
---|
| 373 | + npage = Datalen / 16; |
---|
| 374 | + |
---|
| 375 | + npagelen = 16; |
---|
| 376 | + |
---|
| 377 | + for (i = 0; i < npage; i++) { |
---|
| 378 | + I2C_Write_Byte(lt7911d, 0x5E, 0x6f); |
---|
| 379 | + I2C_Write_Byte(lt7911d, 0x5A, 0xA2); |
---|
| 380 | + I2C_Write_Byte(lt7911d, 0x5A, 0x82); |
---|
| 381 | + I2C_Write_Byte(lt7911d, 0x5B, addr[0]); |
---|
| 382 | + I2C_Write_Byte(lt7911d, 0x5C, addr[1]); |
---|
| 383 | + I2C_Write_Byte(lt7911d, 0x5D, addr[2]); |
---|
| 384 | + I2C_Write_Byte(lt7911d, 0x5A, 0x92); |
---|
| 385 | + I2C_Write_Byte(lt7911d, 0x5A, 0x82); |
---|
| 386 | + I2C_Write_Byte(lt7911d, 0x58, 0x01); |
---|
| 387 | + |
---|
| 388 | + if ((Datalen - i * 16) < 16) |
---|
| 389 | + npagelen = Datalen - i*16; |
---|
| 390 | + |
---|
| 391 | + for (j = 0; j < npagelen; j++) { |
---|
| 392 | + /*please just continue to read data from 0x5f*/ |
---|
| 393 | + /*lt7911d will increase the address auto*/ |
---|
| 394 | + ReadFirmware[i*16 + j] = I2C_Read_Byte(lt7911d, 0x5F); |
---|
| 395 | + } |
---|
| 396 | + |
---|
| 397 | + StartAddr += 16; |
---|
| 398 | + /*change the first address*/ |
---|
| 399 | + addr[0] = (StartAddr & 0xFF0000) >> 16; |
---|
| 400 | + addr[1] = (StartAddr & 0xFF00) >> 8; |
---|
| 401 | + addr[2] = StartAddr & 0xFF; |
---|
| 402 | + } |
---|
| 403 | + |
---|
| 404 | + I2C_Write_Byte(lt7911d, 0x5a, 0x8a); |
---|
| 405 | + I2C_Write_Byte(lt7911d, 0x5a, 0x82); |
---|
| 406 | +} |
---|
| 407 | + |
---|
| 408 | +static int lt7911_compare_firmware(struct lt7911d *lt7911d) |
---|
| 409 | +{ |
---|
| 410 | + unsigned int len; |
---|
| 411 | + |
---|
| 412 | + for (len = 0; len < Datalen; len++) { |
---|
| 413 | + if (ReadFirmware[len] != FirmwareData[len]) { |
---|
| 414 | + pr_info("%s: ReadFirmware[%d] 0x%x != 0x%x FirmwareData[%d]\n", |
---|
| 415 | + __func__, len, ReadFirmware[len], FirmwareData[len], len); |
---|
| 416 | + return -1; |
---|
| 417 | + } |
---|
| 418 | + } |
---|
| 419 | + return 0; |
---|
| 420 | +} |
---|
| 421 | + |
---|
| 422 | +static int lt7911d_firmware_upgrade(struct lt7911d *lt7911d) |
---|
| 423 | +{ |
---|
| 424 | + int ret = 0; |
---|
| 425 | + |
---|
| 426 | + if (lt7911d_check_chip_id(lt7911d)) { |
---|
| 427 | + if (lt7911d_check_fw_version(lt7911d) == 0) { |
---|
| 428 | + lt7911d_config_para(lt7911d); |
---|
| 429 | + SaveHdcpKeyFromFlash(lt7911d); |
---|
| 430 | + lt7911d_block_erase(lt7911d); |
---|
| 431 | + lt7911d_write_firmware_to_flash(lt7911d); |
---|
| 432 | + lt7911d_write_hdcpkey_to_flash(lt7911d); |
---|
| 433 | + lt7911d_read_firmware_from_flash(lt7911d); |
---|
| 434 | + |
---|
| 435 | + if (!lt7911_compare_firmware(lt7911d)) { |
---|
| 436 | + pr_info("%s: upgrade success\n", __func__); |
---|
| 437 | + ret = 0; |
---|
| 438 | + } else { |
---|
| 439 | + pr_info("%s: upgrade Fail\n", __func__); |
---|
| 440 | + ret = -1; |
---|
| 441 | + } |
---|
| 442 | + } |
---|
| 443 | + } else { |
---|
| 444 | + pr_info("the chip lt7911d is offline\n"); |
---|
| 445 | + ret = 0; |
---|
| 446 | + } |
---|
| 447 | + |
---|
| 448 | + I2C_Write_Byte(lt7911d, 0xFF, 0x80); |
---|
| 449 | + I2C_Write_Byte(lt7911d, 0xEE, 0x00); |
---|
| 450 | + |
---|
| 451 | + return ret; |
---|
| 452 | +} |
---|
| 453 | + |
---|
| 454 | +static const struct regmap_config lt7911d_regmap_config = { |
---|
| 455 | + .name = "lt7911d", |
---|
| 456 | + .reg_bits = 8, |
---|
| 457 | + .val_bits = 8, |
---|
| 458 | + .max_register = 0x100, |
---|
21 | 459 | }; |
---|
22 | 460 | |
---|
23 | 461 | static int lt7911d_fb_notifier_callback(struct notifier_block *self, |
---|
.. | .. |
---|
26 | 464 | struct lt7911d *lt7911d = container_of(self, struct lt7911d, fb_notif); |
---|
27 | 465 | struct fb_event *evdata = data; |
---|
28 | 466 | int fb_blank = *(int *)evdata->data; |
---|
29 | | - int i; |
---|
30 | 467 | |
---|
31 | 468 | if (event != FB_EVENT_BLANK) |
---|
32 | 469 | return 0; |
---|
.. | .. |
---|
35 | 472 | return 0; |
---|
36 | 473 | |
---|
37 | 474 | if (fb_blank == FB_BLANK_UNBLANK) { |
---|
38 | | - for (i = 0; i < lt7911d->gpios->ndescs; i++) |
---|
39 | | - gpiod_direction_output(lt7911d->gpios->desc[i], 1); |
---|
40 | | - msleep(20); |
---|
41 | | - for (i = 0; i < lt7911d->gpios->ndescs; i++) |
---|
42 | | - gpiod_direction_output(lt7911d->gpios->desc[i], 0); |
---|
43 | | - msleep(500); |
---|
| 475 | + if (lt7911d->reset_gpio) { |
---|
| 476 | + gpiod_direction_output(lt7911d->reset_gpio, 1); |
---|
| 477 | + msleep(20); |
---|
| 478 | + gpiod_direction_output(lt7911d->reset_gpio, 0); |
---|
| 479 | + msleep(400); |
---|
| 480 | + } |
---|
44 | 481 | } |
---|
45 | 482 | |
---|
46 | 483 | lt7911d->fb_blank = fb_blank; |
---|
.. | .. |
---|
48 | 485 | return 0; |
---|
49 | 486 | } |
---|
50 | 487 | |
---|
51 | | -static int lt7911d_fb_notifier_probe(struct platform_device *pdev) |
---|
| 488 | +static int lt7911d_i2c_probe(struct i2c_client *client, |
---|
| 489 | + const struct i2c_device_id *id) |
---|
52 | 490 | { |
---|
53 | | - struct device *dev = &pdev->dev; |
---|
| 491 | + struct device *dev = &client->dev; |
---|
54 | 492 | struct lt7911d *lt7911d; |
---|
55 | | - int i, ret; |
---|
| 493 | + int ret = 0, i = 0; |
---|
56 | 494 | |
---|
57 | 495 | lt7911d = devm_kzalloc(dev, sizeof(*lt7911d), GFP_KERNEL); |
---|
58 | 496 | if (!lt7911d) |
---|
59 | 497 | return -ENOMEM; |
---|
60 | 498 | |
---|
61 | 499 | lt7911d->dev = dev; |
---|
62 | | - platform_set_drvdata(pdev, lt7911d); |
---|
| 500 | + i2c_set_clientdata(client, lt7911d); |
---|
63 | 501 | |
---|
64 | | - lt7911d->gpios = devm_gpiod_get_array(dev, "reset", GPIOD_OUT_LOW); |
---|
65 | | - if (IS_ERR(lt7911d->gpios)) |
---|
66 | | - return dev_err_probe(dev, PTR_ERR(lt7911d->gpios), |
---|
| 502 | + lt7911d->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW); |
---|
| 503 | + if (IS_ERR(lt7911d->reset_gpio)) |
---|
| 504 | + return dev_err_probe(dev, PTR_ERR(lt7911d->reset_gpio), |
---|
67 | 505 | "failed to acquire reset gpio\n"); |
---|
68 | 506 | |
---|
69 | | - for (i = 0; i < lt7911d->gpios->ndescs; i++) |
---|
70 | | - gpiod_set_consumer_name(lt7911d->gpios->desc[i], "lt7911d-reset"); |
---|
| 507 | + gpiod_set_consumer_name(lt7911d->reset_gpio, "lt7911d-reset"); |
---|
| 508 | + |
---|
| 509 | + lt7911d->enable_gpio = devm_gpiod_get_optional(dev, "enable", GPIOD_OUT_LOW); |
---|
| 510 | + if (IS_ERR(lt7911d->enable_gpio)) |
---|
| 511 | + return dev_err_probe(dev, PTR_ERR(lt7911d->enable_gpio), |
---|
| 512 | + "failed to acquire enable gpio\n"); |
---|
| 513 | + |
---|
| 514 | + lt7911d->regmap = devm_regmap_init_i2c(client, <7911d_regmap_config); |
---|
| 515 | + if (IS_ERR(lt7911d->regmap)) |
---|
| 516 | + return dev_err_probe(dev, PTR_ERR(lt7911d->regmap), |
---|
| 517 | + "failed to initialize regmap\n"); |
---|
71 | 518 | |
---|
72 | 519 | lt7911d->fb_blank = FB_BLANK_UNBLANK; |
---|
73 | 520 | lt7911d->fb_notif.notifier_call = lt7911d_fb_notifier_callback; |
---|
.. | .. |
---|
75 | 522 | if (ret) |
---|
76 | 523 | return dev_err_probe(dev, ret, "failed to register fb client\n"); |
---|
77 | 524 | |
---|
| 525 | + for (i = 0; i < 3; i++) { |
---|
| 526 | + if (!lt7911d_firmware_upgrade(lt7911d)) |
---|
| 527 | + break; |
---|
| 528 | + } |
---|
| 529 | + |
---|
| 530 | + dev_info(dev, "%s end\n", __func__); |
---|
| 531 | + |
---|
78 | 532 | return 0; |
---|
79 | 533 | } |
---|
80 | 534 | |
---|
81 | | -static int lt7911d_fb_notifier_remove(struct platform_device *pdev) |
---|
| 535 | +static void lt7911d_i2c_shutdown(struct i2c_client *client) |
---|
82 | 536 | { |
---|
83 | | - struct lt7911d *lt7911d = platform_get_drvdata(pdev); |
---|
| 537 | + struct lt7911d *lt7911d = i2c_get_clientdata(client); |
---|
| 538 | + |
---|
| 539 | + gpiod_direction_output(lt7911d->reset_gpio, 1); |
---|
| 540 | + msleep(20); |
---|
| 541 | +} |
---|
| 542 | + |
---|
| 543 | +static int lt7911d_i2c_remove(struct i2c_client *client) |
---|
| 544 | +{ |
---|
| 545 | + struct lt7911d *lt7911d = i2c_get_clientdata(client); |
---|
84 | 546 | |
---|
85 | 547 | fb_unregister_client(<7911d->fb_notif); |
---|
86 | 548 | |
---|
87 | 549 | return 0; |
---|
88 | 550 | } |
---|
89 | 551 | |
---|
90 | | -static void lt7911d_fb_notifier_shutdown(struct platform_device *pdev) |
---|
91 | | -{ |
---|
92 | | - struct lt7911d *lt7911d = platform_get_drvdata(pdev); |
---|
93 | | - int i; |
---|
| 552 | +static const struct i2c_device_id lt7911d_i2c_table[] = { |
---|
| 553 | + { "lt7911d", 0 }, |
---|
| 554 | + {} |
---|
| 555 | +}; |
---|
| 556 | +MODULE_DEVICE_TABLE(i2c, lt7911d_i2c_table); |
---|
94 | 557 | |
---|
95 | | - for (i = 0; i < lt7911d->gpios->ndescs; i++) |
---|
96 | | - gpiod_direction_output(lt7911d->gpios->desc[i], 1); |
---|
97 | | - msleep(20); |
---|
98 | | -} |
---|
99 | | - |
---|
100 | | -static const struct of_device_id lt7911d_fb_notifier_of_match[] = { |
---|
| 558 | +static const struct of_device_id lt7911d_of_match[] = { |
---|
101 | 559 | { .compatible = "lontium,lt7911d-fb-notifier" }, |
---|
102 | 560 | {} |
---|
103 | 561 | }; |
---|
104 | | -MODULE_DEVICE_TABLE(of, lt7911d_fb_notifier_of_match); |
---|
| 562 | +MODULE_DEVICE_TABLE(of, lt7911d_of_match); |
---|
105 | 563 | |
---|
106 | | -static struct platform_driver lt7911d_fb_notifier_driver = { |
---|
| 564 | +static struct i2c_driver lt7911d_i2c_driver = { |
---|
107 | 565 | .driver = { |
---|
108 | | - .name = "lt7911d-fb-notifier", |
---|
109 | | - .of_match_table = lt7911d_fb_notifier_of_match, |
---|
| 566 | + .name = "lt7911d", |
---|
| 567 | + .of_match_table = lt7911d_of_match, |
---|
110 | 568 | }, |
---|
111 | | - .probe = lt7911d_fb_notifier_probe, |
---|
112 | | - .remove = lt7911d_fb_notifier_remove, |
---|
113 | | - .shutdown = lt7911d_fb_notifier_shutdown, |
---|
| 569 | + .probe = lt7911d_i2c_probe, |
---|
| 570 | + .remove = lt7911d_i2c_remove, |
---|
| 571 | + .shutdown = lt7911d_i2c_shutdown, |
---|
| 572 | + .id_table = lt7911d_i2c_table, |
---|
114 | 573 | }; |
---|
115 | 574 | |
---|
116 | | -module_platform_driver(lt7911d_fb_notifier_driver); |
---|
| 575 | +static int __init lt7911d_i2c_driver_init(void) |
---|
| 576 | +{ |
---|
| 577 | + i2c_add_driver(<7911d_i2c_driver); |
---|
117 | 578 | |
---|
118 | | -MODULE_DESCRIPTION("Lontium LT7911D FB Notifier"); |
---|
| 579 | + return 0; |
---|
| 580 | +} |
---|
| 581 | +subsys_initcall_sync(lt7911d_i2c_driver_init); |
---|
| 582 | + |
---|
| 583 | +static void __exit lt7911d_i2c_driver_exit(void) |
---|
| 584 | +{ |
---|
| 585 | + i2c_del_driver(<7911d_i2c_driver); |
---|
| 586 | +} |
---|
| 587 | +module_exit(lt7911d_i2c_driver_exit); |
---|
| 588 | + |
---|
| 589 | +MODULE_DESCRIPTION("Lontium lt7911dD driver"); |
---|
119 | 590 | MODULE_LICENSE("GPL"); |
---|