2 * Copyright © 2011 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
25 #include <linux/delay.h>
26 #include <linux/kernel.h>
27 #include <linux/module.h>
28 #include <linux/gpio/consumer.h>
30 #include <asm/intel_scu_ipc.h>
32 #include "mdfld_dsi_dpi.h"
33 #include "mdfld_dsi_pkg_sender.h"
34 #include "mdfld_output.h"
35 #include "tc35876x-dsi-lvds.h"
37 static struct i2c_client
*tc35876x_client
;
38 static struct i2c_client
*cmi_lcd_i2c_client
;
40 static struct gpio_desc
*bridge_reset
;
41 static struct gpio_desc
*bridge_bl_enable
;
42 static struct gpio_desc
*backlight_voltage
;
45 #define FLD_MASK(start, end) (((1 << ((start) - (end) + 1)) - 1) << (end))
46 #define FLD_VAL(val, start, end) (((val) << (end)) & FLD_MASK(start, end))
48 /* DSI D-PHY Layer Registers */
49 #define D0W_DPHYCONTTX 0x0004
50 #define CLW_DPHYCONTRX 0x0020
51 #define D0W_DPHYCONTRX 0x0024
52 #define D1W_DPHYCONTRX 0x0028
53 #define D2W_DPHYCONTRX 0x002C
54 #define D3W_DPHYCONTRX 0x0030
55 #define COM_DPHYCONTRX 0x0038
56 #define CLW_CNTRL 0x0040
57 #define D0W_CNTRL 0x0044
58 #define D1W_CNTRL 0x0048
59 #define D2W_CNTRL 0x004C
60 #define D3W_CNTRL 0x0050
61 #define DFTMODE_CNTRL 0x0054
63 /* DSI PPI Layer Registers */
64 #define PPI_STARTPPI 0x0104
65 #define PPI_BUSYPPI 0x0108
66 #define PPI_LINEINITCNT 0x0110
67 #define PPI_LPTXTIMECNT 0x0114
68 #define PPI_LANEENABLE 0x0134
69 #define PPI_TX_RX_TA 0x013C
70 #define PPI_CLS_ATMR 0x0140
71 #define PPI_D0S_ATMR 0x0144
72 #define PPI_D1S_ATMR 0x0148
73 #define PPI_D2S_ATMR 0x014C
74 #define PPI_D3S_ATMR 0x0150
75 #define PPI_D0S_CLRSIPOCOUNT 0x0164
76 #define PPI_D1S_CLRSIPOCOUNT 0x0168
77 #define PPI_D2S_CLRSIPOCOUNT 0x016C
78 #define PPI_D3S_CLRSIPOCOUNT 0x0170
79 #define CLS_PRE 0x0180
80 #define D0S_PRE 0x0184
81 #define D1S_PRE 0x0188
82 #define D2S_PRE 0x018C
83 #define D3S_PRE 0x0190
84 #define CLS_PREP 0x01A0
85 #define D0S_PREP 0x01A4
86 #define D1S_PREP 0x01A8
87 #define D2S_PREP 0x01AC
88 #define D3S_PREP 0x01B0
89 #define CLS_ZERO 0x01C0
90 #define D0S_ZERO 0x01C4
91 #define D1S_ZERO 0x01C8
92 #define D2S_ZERO 0x01CC
93 #define D3S_ZERO 0x01D0
94 #define PPI_CLRFLG 0x01E0
95 #define PPI_CLRSIPO 0x01E4
96 #define HSTIMEOUT 0x01F0
97 #define HSTIMEOUTENABLE 0x01F4
99 /* DSI Protocol Layer Registers */
100 #define DSI_STARTDSI 0x0204
101 #define DSI_BUSYDSI 0x0208
102 #define DSI_LANEENABLE 0x0210
103 #define DSI_LANESTATUS0 0x0214
104 #define DSI_LANESTATUS1 0x0218
105 #define DSI_INTSTATUS 0x0220
106 #define DSI_INTMASK 0x0224
107 #define DSI_INTCLR 0x0228
108 #define DSI_LPTXTO 0x0230
110 /* DSI General Registers */
111 #define DSIERRCNT 0x0300
113 /* DSI Application Layer Registers */
114 #define APLCTRL 0x0400
115 #define RDPKTLN 0x0404
117 /* Video Path Registers */
118 #define VPCTRL 0x0450
126 #define LVMX0003 0x0480
127 #define LVMX0407 0x0484
128 #define LVMX0811 0x0488
129 #define LVMX1215 0x048C
130 #define LVMX1619 0x0490
131 #define LVMX2023 0x0494
132 #define LVMX2427 0x0498
134 #define LVPHY0 0x04A0
135 #define LVPHY1 0x04A4
137 /* System Registers */
138 #define SYSSTAT 0x0500
139 #define SYSRST 0x0504
142 /*#define GPIOC 0x0520*/
147 #define I2CTIMCTRL 0x0540
148 #define I2CMADDR 0x0544
149 #define WDATAQ 0x0548
150 #define RDATAQ 0x054C
152 /* Chip/Rev Registers */
155 /* Debug Registers */
156 #define DEBUG00 0x05A0
157 #define DEBUG01 0x05A4
159 /* Panel CABC registers */
160 #define PANEL_PWM_CONTROL 0x90
161 #define PANEL_FREQ_DIVIDER_HI 0x91
162 #define PANEL_FREQ_DIVIDER_LO 0x92
163 #define PANEL_DUTY_CONTROL 0x93
164 #define PANEL_MODIFY_RGB 0x94
165 #define PANEL_FRAMERATE_CONTROL 0x96
166 #define PANEL_PWM_MIN 0x97
167 #define PANEL_PWM_REF 0x98
168 #define PANEL_PWM_MAX 0x99
169 #define PANEL_ALLOW_DISTORT 0x9A
170 #define PANEL_BYPASS_PWMI 0x9B
172 /* Panel color management registers */
173 #define PANEL_CM_ENABLE 0x700
174 #define PANEL_CM_HUE 0x701
175 #define PANEL_CM_SATURATION 0x702
176 #define PANEL_CM_INTENSITY 0x703
177 #define PANEL_CM_BRIGHTNESS 0x704
178 #define PANEL_CM_CE_ENABLE 0x705
179 #define PANEL_CM_PEAK_EN 0x710
180 #define PANEL_CM_GAIN 0x711
181 #define PANEL_CM_HUETABLE_START 0x730
182 #define PANEL_CM_HUETABLE_END 0x747 /* inclusive */
184 /* Input muxing for registers LVMX0003...LVMX2427 */
210 INPUT_HSYNC
, /* 24 */
214 /* 28...31 undefined */
217 #define INPUT_MUX(lvmx03, lvmx02, lvmx01, lvmx00) \
218 (FLD_VAL(lvmx03, 29, 24) | FLD_VAL(lvmx02, 20, 16) | \
219 FLD_VAL(lvmx01, 12, 8) | FLD_VAL(lvmx00, 4, 0))
222 * tc35876x_regw - Write DSI-LVDS bridge register using I2C
223 * @client: struct i2c_client to use
224 * @reg: register address
225 * @value: value to write
227 * Returns 0 on success, or a negative error value.
229 static int tc35876x_regw(struct i2c_client
*client
, u16 reg
, u32 value
)
233 /* NOTE: Register address big-endian, data little-endian. */
238 (value
>> 16) & 0xff,
239 (value
>> 24) & 0xff,
241 struct i2c_msg msgs
[] = {
243 .addr
= client
->addr
,
246 .len
= ARRAY_SIZE(tx_data
),
250 r
= i2c_transfer(client
->adapter
, msgs
, ARRAY_SIZE(msgs
));
252 dev_err(&client
->dev
, "%s: reg 0x%04x val 0x%08x error %d\n",
253 __func__
, reg
, value
, r
);
257 if (r
< ARRAY_SIZE(msgs
)) {
258 dev_err(&client
->dev
, "%s: reg 0x%04x val 0x%08x msgs %d\n",
259 __func__
, reg
, value
, r
);
263 dev_dbg(&client
->dev
, "%s: reg 0x%04x val 0x%08x\n",
264 __func__
, reg
, value
);
270 * tc35876x_regr - Read DSI-LVDS bridge register using I2C
271 * @client: struct i2c_client to use
272 * @reg: register address
273 * @value: pointer for storing the value
275 * Returns 0 on success, or a negative error value.
277 static int tc35876x_regr(struct i2c_client
*client
, u16 reg
, u32
*value
)
285 struct i2c_msg msgs
[] = {
287 .addr
= client
->addr
,
290 .len
= ARRAY_SIZE(tx_data
),
293 .addr
= client
->addr
,
296 .len
= ARRAY_SIZE(rx_data
),
300 r
= i2c_transfer(client
->adapter
, msgs
, ARRAY_SIZE(msgs
));
302 dev_err(&client
->dev
, "%s: reg 0x%04x error %d\n", __func__
,
307 if (r
< ARRAY_SIZE(msgs
)) {
308 dev_err(&client
->dev
, "%s: reg 0x%04x msgs %d\n", __func__
,
313 *value
= rx_data
[0] << 24 | rx_data
[1] << 16 |
314 rx_data
[2] << 8 | rx_data
[3];
316 dev_dbg(&client
->dev
, "%s: reg 0x%04x value 0x%08x\n", __func__
,
322 void tc35876x_set_bridge_reset_state(struct drm_device
*dev
, int state
)
324 if (WARN(!tc35876x_client
, "%s called before probe", __func__
))
327 dev_dbg(&tc35876x_client
->dev
, "%s: state %d\n", __func__
, state
);
333 gpiod_set_value_cansleep(bridge_reset
, 0);
336 /* Pull MIPI Bridge reset pin to Low */
337 gpiod_set_value_cansleep(bridge_reset
, 0);
339 /* Pull MIPI Bridge reset pin to High */
340 gpiod_set_value_cansleep(bridge_reset
, 1);
345 void tc35876x_configure_lvds_bridge(struct drm_device
*dev
)
347 struct i2c_client
*i2c
= tc35876x_client
;
353 if (WARN(!tc35876x_client
, "%s called before probe", __func__
))
356 dev_dbg(&tc35876x_client
->dev
, "%s\n", __func__
);
358 if (!tc35876x_regr(i2c
, IDREG
, &id
))
359 dev_info(&tc35876x_client
->dev
, "tc35876x ID 0x%08x\n", id
);
361 dev_err(&tc35876x_client
->dev
, "Cannot read ID\n");
364 txtagocnt
= (5 * ppi_lptxtimecnt
- 3) / 4;
365 txtasurecnt
= 3 * ppi_lptxtimecnt
/ 2;
366 tc35876x_regw(i2c
, PPI_TX_RX_TA
, FLD_VAL(txtagocnt
, 26, 16) |
367 FLD_VAL(txtasurecnt
, 10, 0));
368 tc35876x_regw(i2c
, PPI_LPTXTIMECNT
, FLD_VAL(ppi_lptxtimecnt
, 10, 0));
370 tc35876x_regw(i2c
, PPI_D0S_CLRSIPOCOUNT
, FLD_VAL(1, 5, 0));
371 tc35876x_regw(i2c
, PPI_D1S_CLRSIPOCOUNT
, FLD_VAL(1, 5, 0));
372 tc35876x_regw(i2c
, PPI_D2S_CLRSIPOCOUNT
, FLD_VAL(1, 5, 0));
373 tc35876x_regw(i2c
, PPI_D3S_CLRSIPOCOUNT
, FLD_VAL(1, 5, 0));
375 /* Enabling MIPI & PPI lanes, Enable 4 lanes */
376 tc35876x_regw(i2c
, PPI_LANEENABLE
,
377 BIT(4) | BIT(3) | BIT(2) | BIT(1) | BIT(0));
378 tc35876x_regw(i2c
, DSI_LANEENABLE
,
379 BIT(4) | BIT(3) | BIT(2) | BIT(1) | BIT(0));
380 tc35876x_regw(i2c
, PPI_STARTPPI
, BIT(0));
381 tc35876x_regw(i2c
, DSI_STARTDSI
, BIT(0));
383 /* Setting LVDS output frequency */
384 tc35876x_regw(i2c
, LVPHY0
, FLD_VAL(1, 20, 16) |
385 FLD_VAL(2, 15, 14) | FLD_VAL(6, 4, 0)); /* 0x00048006 */
387 /* Setting video panel control register,0x00000120 VTGen=ON ?!?!? */
388 tc35876x_regw(i2c
, VPCTRL
, BIT(8) | BIT(5));
390 /* Horizontal back porch and horizontal pulse width. 0x00280028 */
391 tc35876x_regw(i2c
, HTIM1
, FLD_VAL(40, 24, 16) | FLD_VAL(40, 8, 0));
393 /* Horizontal front porch and horizontal active video size. 0x00500500*/
394 tc35876x_regw(i2c
, HTIM2
, FLD_VAL(80, 24, 16) | FLD_VAL(1280, 10, 0));
396 /* Vertical back porch and vertical sync pulse width. 0x000e000a */
397 tc35876x_regw(i2c
, VTIM1
, FLD_VAL(14, 23, 16) | FLD_VAL(10, 7, 0));
399 /* Vertical front porch and vertical display size. 0x000e0320 */
400 tc35876x_regw(i2c
, VTIM2
, FLD_VAL(14, 23, 16) | FLD_VAL(800, 10, 0));
402 /* Set above HTIM1, HTIM2, VTIM1, and VTIM2 at next VSYNC. */
403 tc35876x_regw(i2c
, VFUEN
, BIT(0));
405 /* Soft reset LCD controller. */
406 tc35876x_regw(i2c
, SYSRST
, BIT(2));
408 /* LVDS-TX input muxing */
409 tc35876x_regw(i2c
, LVMX0003
,
410 INPUT_MUX(INPUT_R5
, INPUT_R4
, INPUT_R3
, INPUT_R2
));
411 tc35876x_regw(i2c
, LVMX0407
,
412 INPUT_MUX(INPUT_G2
, INPUT_R7
, INPUT_R1
, INPUT_R6
));
413 tc35876x_regw(i2c
, LVMX0811
,
414 INPUT_MUX(INPUT_G1
, INPUT_G0
, INPUT_G4
, INPUT_G3
));
415 tc35876x_regw(i2c
, LVMX1215
,
416 INPUT_MUX(INPUT_B2
, INPUT_G7
, INPUT_G6
, INPUT_G5
));
417 tc35876x_regw(i2c
, LVMX1619
,
418 INPUT_MUX(INPUT_B4
, INPUT_B3
, INPUT_B1
, INPUT_B0
));
419 tc35876x_regw(i2c
, LVMX2023
,
420 INPUT_MUX(LOGIC_0
, INPUT_B7
, INPUT_B6
, INPUT_B5
));
421 tc35876x_regw(i2c
, LVMX2427
,
422 INPUT_MUX(INPUT_R0
, INPUT_DE
, INPUT_VSYNC
, INPUT_HSYNC
));
424 /* Enable LVDS transmitter. */
425 tc35876x_regw(i2c
, LVCFG
, BIT(0));
427 /* Clear notifications. Don't write reserved bits. Was write 0xffffffff
428 * to 0x0288, must be in error?! */
429 tc35876x_regw(i2c
, DSI_INTCLR
, FLD_MASK(31, 30) | FLD_MASK(22, 0));
432 #define GPIOPWMCTRL 0x38F
433 #define PWM0CLKDIV0 0x62 /* low byte */
434 #define PWM0CLKDIV1 0x61 /* high byte */
436 #define SYSTEMCLK 19200000UL /* 19.2 MHz */
437 #define PWM_FREQUENCY 9600 /* Hz */
439 /* f = baseclk / (clkdiv + 1) => clkdiv = (baseclk - f) / f */
440 static inline u16
calc_clkdiv(unsigned long baseclk
, unsigned int f
)
442 return (baseclk
- f
) / f
;
445 static void tc35876x_brightness_init(struct drm_device
*dev
)
451 /* Make sure the PWM reference is the 19.2 MHz system clock. Read first
452 * instead of setting directly to catch potential conflicts between PWM
454 ret
= intel_scu_ipc_ioread8(GPIOPWMCTRL
, &pwmctrl
);
455 if (ret
|| pwmctrl
!= 0x01) {
457 dev_err(&dev
->pdev
->dev
, "GPIOPWMCTRL read failed\n");
459 dev_warn(&dev
->pdev
->dev
, "GPIOPWMCTRL was not set to system clock (pwmctrl = 0x%02x)\n", pwmctrl
);
461 ret
= intel_scu_ipc_iowrite8(GPIOPWMCTRL
, 0x01);
463 dev_err(&dev
->pdev
->dev
, "GPIOPWMCTRL set failed\n");
466 clkdiv
= calc_clkdiv(SYSTEMCLK
, PWM_FREQUENCY
);
468 ret
= intel_scu_ipc_iowrite8(PWM0CLKDIV1
, (clkdiv
>> 8) & 0xff);
470 ret
= intel_scu_ipc_iowrite8(PWM0CLKDIV0
, clkdiv
& 0xff);
473 dev_err(&dev
->pdev
->dev
, "PWM0CLKDIV set failed\n");
475 dev_dbg(&dev
->pdev
->dev
, "PWM0CLKDIV set to 0x%04x (%d Hz)\n",
476 clkdiv
, PWM_FREQUENCY
);
479 #define PWM0DUTYCYCLE 0x67
481 void tc35876x_brightness_control(struct drm_device
*dev
, int level
)
487 level
= clamp(level
, 0, MDFLD_DSI_BRIGHTNESS_MAX_LEVEL
);
489 /* PWM duty cycle 0x00...0x63 corresponds to 0...99% */
490 duty_val
= level
* 0x63 / MDFLD_DSI_BRIGHTNESS_MAX_LEVEL
;
492 /* I won't pretend to understand this formula. The panel spec is quite
495 panel_duty_val
= (2 * level
- 100) * 0xA9 /
496 MDFLD_DSI_BRIGHTNESS_MAX_LEVEL
+ 0x56;
498 ret
= intel_scu_ipc_iowrite8(PWM0DUTYCYCLE
, duty_val
);
500 dev_err(&tc35876x_client
->dev
, "%s: ipc write fail\n",
503 if (cmi_lcd_i2c_client
) {
504 ret
= i2c_smbus_write_byte_data(cmi_lcd_i2c_client
,
505 PANEL_PWM_MAX
, panel_duty_val
);
507 dev_err(&cmi_lcd_i2c_client
->dev
, "%s: i2c write failed\n",
512 void tc35876x_toshiba_bridge_panel_off(struct drm_device
*dev
)
514 if (WARN(!tc35876x_client
, "%s called before probe", __func__
))
517 dev_dbg(&tc35876x_client
->dev
, "%s\n", __func__
);
519 if (bridge_bl_enable
)
520 gpiod_set_value_cansleep(bridge_bl_enable
, 0);
522 if (backlight_voltage
)
523 gpiod_set_value_cansleep(backlight_voltage
, 0);
526 void tc35876x_toshiba_bridge_panel_on(struct drm_device
*dev
)
528 struct drm_psb_private
*dev_priv
= dev
->dev_private
;
530 if (WARN(!tc35876x_client
, "%s called before probe", __func__
))
533 dev_dbg(&tc35876x_client
->dev
, "%s\n", __func__
);
535 if (backlight_voltage
) {
536 gpiod_set_value_cansleep(backlight_voltage
, 1);
540 if (cmi_lcd_i2c_client
) {
542 dev_dbg(&cmi_lcd_i2c_client
->dev
, "setting TCON\n");
543 /* Bit 4 is average_saving. Setting it to 1, the brightness is
544 * referenced to the average of the frame content. 0 means
545 * reference to the maximum of frame contents. Bits 3:0 are
546 * allow_distort. When set to a nonzero value, all color values
547 * between 255-allow_distort*2 and 255 are mapped to the
548 * 255-allow_distort*2 value.
550 ret
= i2c_smbus_write_byte_data(cmi_lcd_i2c_client
,
551 PANEL_ALLOW_DISTORT
, 0x10);
553 dev_err(&cmi_lcd_i2c_client
->dev
,
554 "i2c write failed (%d)\n", ret
);
555 ret
= i2c_smbus_write_byte_data(cmi_lcd_i2c_client
,
556 PANEL_BYPASS_PWMI
, 0);
558 dev_err(&cmi_lcd_i2c_client
->dev
,
559 "i2c write failed (%d)\n", ret
);
560 /* Set minimum brightness value - this is tunable */
561 ret
= i2c_smbus_write_byte_data(cmi_lcd_i2c_client
,
562 PANEL_PWM_MIN
, 0x35);
564 dev_err(&cmi_lcd_i2c_client
->dev
,
565 "i2c write failed (%d)\n", ret
);
568 if (bridge_bl_enable
)
569 gpiod_set_value_cansleep(bridge_bl_enable
, 1);
571 tc35876x_brightness_control(dev
, dev_priv
->brightness_adjusted
);
574 static struct drm_display_mode
*tc35876x_get_config_mode(struct drm_device
*dev
)
576 struct drm_display_mode
*mode
;
578 dev_dbg(&dev
->pdev
->dev
, "%s\n", __func__
);
580 mode
= kzalloc(sizeof(*mode
), GFP_KERNEL
);
584 /* FIXME: do this properly. */
585 mode
->hdisplay
= 1280;
586 mode
->vdisplay
= 800;
587 mode
->hsync_start
= 1360;
588 mode
->hsync_end
= 1400;
590 mode
->vsync_start
= 814;
591 mode
->vsync_end
= 824;
593 mode
->clock
= 33324 << 1;
595 dev_info(&dev
->pdev
->dev
, "hdisplay(w) = %d\n", mode
->hdisplay
);
596 dev_info(&dev
->pdev
->dev
, "vdisplay(h) = %d\n", mode
->vdisplay
);
597 dev_info(&dev
->pdev
->dev
, "HSS = %d\n", mode
->hsync_start
);
598 dev_info(&dev
->pdev
->dev
, "HSE = %d\n", mode
->hsync_end
);
599 dev_info(&dev
->pdev
->dev
, "htotal = %d\n", mode
->htotal
);
600 dev_info(&dev
->pdev
->dev
, "VSS = %d\n", mode
->vsync_start
);
601 dev_info(&dev
->pdev
->dev
, "VSE = %d\n", mode
->vsync_end
);
602 dev_info(&dev
->pdev
->dev
, "vtotal = %d\n", mode
->vtotal
);
603 dev_info(&dev
->pdev
->dev
, "clock = %d\n", mode
->clock
);
605 drm_mode_set_name(mode
);
606 drm_mode_set_crtcinfo(mode
, 0);
608 mode
->type
|= DRM_MODE_TYPE_PREFERRED
;
613 /* DV1 Active area 216.96 x 135.6 mm */
614 #define DV1_PANEL_WIDTH 217
615 #define DV1_PANEL_HEIGHT 136
617 static int tc35876x_get_panel_info(struct drm_device
*dev
, int pipe
,
618 struct panel_info
*pi
)
623 pi
->width_mm
= DV1_PANEL_WIDTH
;
624 pi
->height_mm
= DV1_PANEL_HEIGHT
;
629 static int tc35876x_bridge_probe(struct i2c_client
*client
,
630 const struct i2c_device_id
*id
)
632 dev_info(&client
->dev
, "%s\n", __func__
);
634 if (!i2c_check_functionality(client
->adapter
, I2C_FUNC_I2C
)) {
635 dev_err(&client
->dev
, "%s: i2c_check_functionality() failed\n",
640 bridge_reset
= devm_gpiod_get_optional(&client
->dev
, "bridge-reset", GPIOD_OUT_LOW
);
641 if (IS_ERR(bridge_reset
))
642 return PTR_ERR(bridge_reset
);
644 gpiod_set_consumer_name(bridge_reset
, "tc35876x bridge reset");
646 bridge_bl_enable
= devm_gpiod_get_optional(&client
->dev
, "bl-en", GPIOD_OUT_LOW
);
647 if (IS_ERR(bridge_bl_enable
))
648 return PTR_ERR(bridge_bl_enable
);
649 if (bridge_bl_enable
)
650 gpiod_set_consumer_name(bridge_bl_enable
, "tc35876x panel bl en");
652 backlight_voltage
= devm_gpiod_get_optional(&client
->dev
, "vadd", GPIOD_OUT_LOW
);
653 if (IS_ERR(backlight_voltage
))
654 return PTR_ERR(backlight_voltage
);
655 if (backlight_voltage
)
656 gpiod_set_consumer_name(backlight_voltage
, "tc35876x panel vadd");
658 tc35876x_client
= client
;
663 static int tc35876x_bridge_remove(struct i2c_client
*client
)
665 dev_dbg(&client
->dev
, "%s\n", __func__
);
667 tc35876x_client
= NULL
;
672 static const struct i2c_device_id tc35876x_bridge_id
[] = {
673 { "i2c_disp_brig", 0 },
676 MODULE_DEVICE_TABLE(i2c
, tc35876x_bridge_id
);
678 static struct i2c_driver tc35876x_bridge_i2c_driver
= {
680 .name
= "i2c_disp_brig",
682 .id_table
= tc35876x_bridge_id
,
683 .probe
= tc35876x_bridge_probe
,
684 .remove
= tc35876x_bridge_remove
,
688 static int cmi_lcd_i2c_probe(struct i2c_client
*client
,
689 const struct i2c_device_id
*id
)
691 dev_info(&client
->dev
, "%s\n", __func__
);
693 if (!i2c_check_functionality(client
->adapter
, I2C_FUNC_I2C
)) {
694 dev_err(&client
->dev
, "%s: i2c_check_functionality() failed\n",
699 cmi_lcd_i2c_client
= client
;
704 static int cmi_lcd_i2c_remove(struct i2c_client
*client
)
706 dev_dbg(&client
->dev
, "%s\n", __func__
);
708 cmi_lcd_i2c_client
= NULL
;
713 static const struct i2c_device_id cmi_lcd_i2c_id
[] = {
717 MODULE_DEVICE_TABLE(i2c
, cmi_lcd_i2c_id
);
719 static struct i2c_driver cmi_lcd_i2c_driver
= {
723 .id_table
= cmi_lcd_i2c_id
,
724 .probe
= cmi_lcd_i2c_probe
,
725 .remove
= cmi_lcd_i2c_remove
,
728 /* HACK to create I2C device while it's not created by platform code */
729 #define CMI_LCD_I2C_ADAPTER 2
730 #define CMI_LCD_I2C_ADDR 0x60
732 static int cmi_lcd_hack_create_device(void)
734 struct i2c_adapter
*adapter
;
735 struct i2c_client
*client
;
736 struct i2c_board_info info
= {
738 .addr
= CMI_LCD_I2C_ADDR
,
741 pr_debug("%s\n", __func__
);
743 adapter
= i2c_get_adapter(CMI_LCD_I2C_ADAPTER
);
745 pr_err("%s: i2c_get_adapter(%d) failed\n", __func__
,
746 CMI_LCD_I2C_ADAPTER
);
750 client
= i2c_new_client_device(adapter
, &info
);
751 if (IS_ERR(client
)) {
752 pr_err("%s: creating I2C device failed\n", __func__
);
753 i2c_put_adapter(adapter
);
754 return PTR_ERR(client
);
760 static const struct drm_encoder_helper_funcs tc35876x_encoder_helper_funcs
= {
761 .dpms
= mdfld_dsi_dpi_dpms
,
762 .mode_fixup
= mdfld_dsi_dpi_mode_fixup
,
763 .prepare
= mdfld_dsi_dpi_prepare
,
764 .mode_set
= mdfld_dsi_dpi_mode_set
,
765 .commit
= mdfld_dsi_dpi_commit
,
768 const struct panel_funcs mdfld_tc35876x_funcs
= {
769 .encoder_helper_funcs
= &tc35876x_encoder_helper_funcs
,
770 .get_config_mode
= tc35876x_get_config_mode
,
771 .get_panel_info
= tc35876x_get_panel_info
,
774 void tc35876x_init(struct drm_device
*dev
)
778 dev_dbg(&dev
->pdev
->dev
, "%s\n", __func__
);
780 cmi_lcd_hack_create_device();
782 r
= i2c_add_driver(&cmi_lcd_i2c_driver
);
784 dev_err(&dev
->pdev
->dev
,
785 "%s: i2c_add_driver() for %s failed (%d)\n",
786 __func__
, cmi_lcd_i2c_driver
.driver
.name
, r
);
788 r
= i2c_add_driver(&tc35876x_bridge_i2c_driver
);
790 dev_err(&dev
->pdev
->dev
,
791 "%s: i2c_add_driver() for %s failed (%d)\n",
792 __func__
, tc35876x_bridge_i2c_driver
.driver
.name
, r
);
794 tc35876x_brightness_init(dev
);
797 void tc35876x_exit(void)
799 pr_debug("%s\n", __func__
);
801 i2c_del_driver(&tc35876x_bridge_i2c_driver
);
803 if (cmi_lcd_i2c_client
)
804 i2c_del_driver(&cmi_lcd_i2c_driver
);