30 #include <linux/kernel.h>
31 #include <linux/module.h>
37 #define FLD_MASK(start, end) (((1 << ((start) - (end) + 1)) - 1) << (end))
38 #define FLD_VAL(val, start, end) (((val) << (end)) & FLD_MASK(start, end))
41 #define D0W_DPHYCONTTX 0x0004
42 #define CLW_DPHYCONTRX 0x0020
43 #define D0W_DPHYCONTRX 0x0024
44 #define D1W_DPHYCONTRX 0x0028
45 #define D2W_DPHYCONTRX 0x002C
46 #define D3W_DPHYCONTRX 0x0030
47 #define COM_DPHYCONTRX 0x0038
48 #define CLW_CNTRL 0x0040
49 #define D0W_CNTRL 0x0044
50 #define D1W_CNTRL 0x0048
51 #define D2W_CNTRL 0x004C
52 #define D3W_CNTRL 0x0050
53 #define DFTMODE_CNTRL 0x0054
56 #define PPI_STARTPPI 0x0104
57 #define PPI_BUSYPPI 0x0108
58 #define PPI_LINEINITCNT 0x0110
59 #define PPI_LPTXTIMECNT 0x0114
60 #define PPI_LANEENABLE 0x0134
61 #define PPI_TX_RX_TA 0x013C
62 #define PPI_CLS_ATMR 0x0140
63 #define PPI_D0S_ATMR 0x0144
64 #define PPI_D1S_ATMR 0x0148
65 #define PPI_D2S_ATMR 0x014C
66 #define PPI_D3S_ATMR 0x0150
67 #define PPI_D0S_CLRSIPOCOUNT 0x0164
68 #define PPI_D1S_CLRSIPOCOUNT 0x0168
69 #define PPI_D2S_CLRSIPOCOUNT 0x016C
70 #define PPI_D3S_CLRSIPOCOUNT 0x0170
71 #define CLS_PRE 0x0180
72 #define D0S_PRE 0x0184
73 #define D1S_PRE 0x0188
74 #define D2S_PRE 0x018C
75 #define D3S_PRE 0x0190
76 #define CLS_PREP 0x01A0
77 #define D0S_PREP 0x01A4
78 #define D1S_PREP 0x01A8
79 #define D2S_PREP 0x01AC
80 #define D3S_PREP 0x01B0
81 #define CLS_ZERO 0x01C0
82 #define D0S_ZERO 0x01C4
83 #define D1S_ZERO 0x01C8
84 #define D2S_ZERO 0x01CC
85 #define D3S_ZERO 0x01D0
86 #define PPI_CLRFLG 0x01E0
87 #define PPI_CLRSIPO 0x01E4
88 #define HSTIMEOUT 0x01F0
89 #define HSTIMEOUTENABLE 0x01F4
92 #define DSI_STARTDSI 0x0204
93 #define DSI_BUSYDSI 0x0208
94 #define DSI_LANEENABLE 0x0210
95 #define DSI_LANESTATUS0 0x0214
96 #define DSI_LANESTATUS1 0x0218
97 #define DSI_INTSTATUS 0x0220
98 #define DSI_INTMASK 0x0224
99 #define DSI_INTCLR 0x0228
100 #define DSI_LPTXTO 0x0230
103 #define DSIERRCNT 0x0300
106 #define APLCTRL 0x0400
107 #define RDPKTLN 0x0404
110 #define VPCTRL 0x0450
118 #define LVMX0003 0x0480
119 #define LVMX0407 0x0484
120 #define LVMX0811 0x0488
121 #define LVMX1215 0x048C
122 #define LVMX1619 0x0490
123 #define LVMX2023 0x0494
124 #define LVMX2427 0x0498
126 #define LVPHY0 0x04A0
127 #define LVPHY1 0x04A4
130 #define SYSSTAT 0x0500
131 #define SYSRST 0x0504
139 #define I2CTIMCTRL 0x0540
140 #define I2CMADDR 0x0544
141 #define WDATAQ 0x0548
142 #define RDATAQ 0x054C
148 #define DEBUG00 0x05A0
149 #define DEBUG01 0x05A4
152 #define PANEL_PWM_CONTROL 0x90
153 #define PANEL_FREQ_DIVIDER_HI 0x91
154 #define PANEL_FREQ_DIVIDER_LO 0x92
155 #define PANEL_DUTY_CONTROL 0x93
156 #define PANEL_MODIFY_RGB 0x94
157 #define PANEL_FRAMERATE_CONTROL 0x96
158 #define PANEL_PWM_MIN 0x97
159 #define PANEL_PWM_REF 0x98
160 #define PANEL_PWM_MAX 0x99
161 #define PANEL_ALLOW_DISTORT 0x9A
162 #define PANEL_BYPASS_PWMI 0x9B
165 #define PANEL_CM_ENABLE 0x700
166 #define PANEL_CM_HUE 0x701
167 #define PANEL_CM_SATURATION 0x702
168 #define PANEL_CM_INTENSITY 0x703
169 #define PANEL_CM_BRIGHTNESS 0x704
170 #define PANEL_CM_CE_ENABLE 0x705
171 #define PANEL_CM_PEAK_EN 0x710
172 #define PANEL_CM_GAIN 0x711
173 #define PANEL_CM_HUETABLE_START 0x730
174 #define PANEL_CM_HUETABLE_END 0x747
209 #define INPUT_MUX(lvmx03, lvmx02, lvmx01, lvmx00) \
210 (FLD_VAL(lvmx03, 29, 24) | FLD_VAL(lvmx02, 20, 16) | \
211 FLD_VAL(lvmx01, 12, 8) | FLD_VAL(lvmx00, 4, 0))
230 (value >> 16) & 0xff,
231 (value >> 24) & 0xff,
244 dev_err(&client->
dev,
"%s: reg 0x%04x val 0x%08x error %d\n",
245 __func__, reg, value, r);
250 dev_err(&client->
dev,
"%s: reg 0x%04x val 0x%08x msgs %d\n",
251 __func__, reg, value, r);
255 dev_dbg(&client->
dev,
"%s: reg 0x%04x val 0x%08x\n",
256 __func__, reg, value);
285 .addr = client->
addr,
294 dev_err(&client->
dev,
"%s: reg 0x%04x error %d\n", __func__,
300 dev_err(&client->
dev,
"%s: reg 0x%04x msgs %d\n", __func__,
305 *value = rx_data[0] << 24 | rx_data[1] << 16 |
306 rx_data[2] << 8 | rx_data[3];
308 dev_dbg(&client->
dev,
"%s: reg 0x%04x value 0x%08x\n", __func__,
318 if (
WARN(!tc35876x_client,
"%s called before probe", __func__))
321 dev_dbg(&tc35876x_client->
dev,
"%s: state %d\n", __func__, state);
323 pdata = dev_get_platdata(&tc35876x_client->
dev);
349 if (
WARN(!tc35876x_client,
"%s called before probe", __func__))
352 dev_dbg(&tc35876x_client->
dev,
"%s\n", __func__);
354 if (!tc35876x_regr(i2c,
IDREG, &
id))
355 dev_info(&tc35876x_client->
dev,
"tc35876x ID 0x%08x\n",
id);
357 dev_err(&tc35876x_client->
dev,
"Cannot read ID\n");
360 txtagocnt = (5 * ppi_lptxtimecnt - 3) / 4;
361 txtasurecnt = 3 * ppi_lptxtimecnt / 2;
428 #define GPIOPWMCTRL 0x38F
429 #define PWM0CLKDIV0 0x62
430 #define PWM0CLKDIV1 0x61
432 #define SYSTEMCLK 19200000UL
433 #define PWM_FREQUENCY 9600
436 static inline u16 calc_clkdiv(
unsigned long baseclk,
unsigned int f)
438 return (baseclk - f) /
f;
451 if (ret || pwmctrl != 0x01) {
453 dev_err(&dev->pdev->dev,
"GPIOPWMCTRL read failed\n");
455 dev_warn(&dev->pdev->dev,
"GPIOPWMCTRL was not set to system clock (pwmctrl = 0x%02x)\n", pwmctrl);
459 dev_err(&dev->pdev->dev,
"GPIOPWMCTRL set failed\n");
469 dev_err(&dev->pdev->dev,
"PWM0CLKDIV set failed\n");
471 dev_dbg(&dev->pdev->dev,
"PWM0CLKDIV set to 0x%04x (%d Hz)\n",
475 #define PWM0DUTYCYCLE 0x67
491 panel_duty_val = (2 * level - 100) * 0xA9 /
496 dev_err(&tc35876x_client->
dev,
"%s: ipc write fail\n",
499 if (cmi_lcd_i2c_client) {
503 dev_err(&cmi_lcd_i2c_client->
dev,
"%s: i2c write failed\n",
512 if (
WARN(!tc35876x_client,
"%s called before probe", __func__))
515 dev_dbg(&tc35876x_client->
dev,
"%s\n", __func__);
517 pdata = dev_get_platdata(&tc35876x_client->
dev);
531 if (
WARN(!tc35876x_client,
"%s called before probe", __func__))
534 dev_dbg(&tc35876x_client->
dev,
"%s\n", __func__);
536 pdata = dev_get_platdata(&tc35876x_client->
dev);
543 if (cmi_lcd_i2c_client) {
545 dev_dbg(&cmi_lcd_i2c_client->
dev,
"setting TCON\n");
557 "i2c write failed (%d)\n", ret);
562 "i2c write failed (%d)\n", ret);
568 "i2c write failed (%d)\n", ret);
581 dev_dbg(&dev->pdev->dev,
"%s\n", __func__);
596 mode->
clock = 33324 << 1;
617 #define DV1_PANEL_WIDTH 217
618 #define DV1_PANEL_HEIGHT 136
620 static int tc35876x_get_panel_info(
struct drm_device *dev,
int pipe,
632 static int tc35876x_bridge_probe(
struct i2c_client *client,
640 dev_err(&client->
dev,
"%s: i2c_check_functionality() failed\n",
645 pdata = dev_get_platdata(&client->
dev);
647 dev_err(&client->
dev,
"%s: no platform data\n", __func__);
671 static int tc35876x_bridge_remove(
struct i2c_client *client)
686 tc35876x_client =
NULL;
692 {
"i2c_disp_brig", 0 },
697 static struct i2c_driver tc35876x_bridge_i2c_driver = {
699 .name =
"i2c_disp_brig",
701 .id_table = tc35876x_bridge_id,
702 .probe = tc35876x_bridge_probe,
707 static int cmi_lcd_i2c_probe(
struct i2c_client *client,
713 dev_err(&client->
dev,
"%s: i2c_check_functionality() failed\n",
718 cmi_lcd_i2c_client =
client;
723 static int cmi_lcd_i2c_remove(
struct i2c_client *client)
727 cmi_lcd_i2c_client =
NULL;
738 static struct i2c_driver cmi_lcd_i2c_driver = {
742 .id_table = cmi_lcd_i2c_id,
743 .probe = cmi_lcd_i2c_probe,
748 #define CMI_LCD_I2C_ADAPTER 2
749 #define CMI_LCD_I2C_ADDR 0x60
751 static int cmi_lcd_hack_create_device(
void)
764 pr_err(
"%s: i2c_get_adapter(%d) failed\n", __func__,
771 pr_err(
"%s: i2c_new_device() failed\n", __func__);
792 .encoder_funcs = &tc35876x_encoder_funcs,
793 .encoder_helper_funcs = &tc35876x_encoder_helper_funcs,
794 .get_config_mode = tc35876x_get_config_mode,
795 .get_panel_info = tc35876x_get_panel_info,
802 dev_dbg(&dev->pdev->dev,
"%s\n", __func__);
804 cmi_lcd_hack_create_device();
806 r = i2c_add_driver(&cmi_lcd_i2c_driver);
809 "%s: i2c_add_driver() for %s failed (%d)\n",
810 __func__, cmi_lcd_i2c_driver.
driver.name, r);
812 r = i2c_add_driver(&tc35876x_bridge_i2c_driver);
815 "%s: i2c_add_driver() for %s failed (%d)\n",
816 __func__, tc35876x_bridge_i2c_driver.
driver.name, r);
818 tc35876x_brightness_init(dev);
827 if (cmi_lcd_i2c_client)