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/platform_data/tc35876x.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 #define FLD_MASK(start, end) (((1 << ((start) - (end) + 1)) - 1) << (end))
41 #define FLD_VAL(val, start, end) (((val) << (end)) & FLD_MASK(start, end))
43 /* DSI D-PHY Layer Registers */
44 #define D0W_DPHYCONTTX 0x0004
45 #define CLW_DPHYCONTRX 0x0020
46 #define D0W_DPHYCONTRX 0x0024
47 #define D1W_DPHYCONTRX 0x0028
48 #define D2W_DPHYCONTRX 0x002C
49 #define D3W_DPHYCONTRX 0x0030
50 #define COM_DPHYCONTRX 0x0038
51 #define CLW_CNTRL 0x0040
52 #define D0W_CNTRL 0x0044
53 #define D1W_CNTRL 0x0048
54 #define D2W_CNTRL 0x004C
55 #define D3W_CNTRL 0x0050
56 #define DFTMODE_CNTRL 0x0054
58 /* DSI PPI Layer Registers */
59 #define PPI_STARTPPI 0x0104
60 #define PPI_BUSYPPI 0x0108
61 #define PPI_LINEINITCNT 0x0110
62 #define PPI_LPTXTIMECNT 0x0114
63 #define PPI_LANEENABLE 0x0134
64 #define PPI_TX_RX_TA 0x013C
65 #define PPI_CLS_ATMR 0x0140
66 #define PPI_D0S_ATMR 0x0144
67 #define PPI_D1S_ATMR 0x0148
68 #define PPI_D2S_ATMR 0x014C
69 #define PPI_D3S_ATMR 0x0150
70 #define PPI_D0S_CLRSIPOCOUNT 0x0164
71 #define PPI_D1S_CLRSIPOCOUNT 0x0168
72 #define PPI_D2S_CLRSIPOCOUNT 0x016C
73 #define PPI_D3S_CLRSIPOCOUNT 0x0170
74 #define CLS_PRE 0x0180
75 #define D0S_PRE 0x0184
76 #define D1S_PRE 0x0188
77 #define D2S_PRE 0x018C
78 #define D3S_PRE 0x0190
79 #define CLS_PREP 0x01A0
80 #define D0S_PREP 0x01A4
81 #define D1S_PREP 0x01A8
82 #define D2S_PREP 0x01AC
83 #define D3S_PREP 0x01B0
84 #define CLS_ZERO 0x01C0
85 #define D0S_ZERO 0x01C4
86 #define D1S_ZERO 0x01C8
87 #define D2S_ZERO 0x01CC
88 #define D3S_ZERO 0x01D0
89 #define PPI_CLRFLG 0x01E0
90 #define PPI_CLRSIPO 0x01E4
91 #define HSTIMEOUT 0x01F0
92 #define HSTIMEOUTENABLE 0x01F4
94 /* DSI Protocol Layer Registers */
95 #define DSI_STARTDSI 0x0204
96 #define DSI_BUSYDSI 0x0208
97 #define DSI_LANEENABLE 0x0210
98 #define DSI_LANESTATUS0 0x0214
99 #define DSI_LANESTATUS1 0x0218
100 #define DSI_INTSTATUS 0x0220
101 #define DSI_INTMASK 0x0224
102 #define DSI_INTCLR 0x0228
103 #define DSI_LPTXTO 0x0230
105 /* DSI General Registers */
106 #define DSIERRCNT 0x0300
108 /* DSI Application Layer Registers */
109 #define APLCTRL 0x0400
110 #define RDPKTLN 0x0404
112 /* Video Path Registers */
113 #define VPCTRL 0x0450
121 #define LVMX0003 0x0480
122 #define LVMX0407 0x0484
123 #define LVMX0811 0x0488
124 #define LVMX1215 0x048C
125 #define LVMX1619 0x0490
126 #define LVMX2023 0x0494
127 #define LVMX2427 0x0498
129 #define LVPHY0 0x04A0
130 #define LVPHY1 0x04A4
132 /* System Registers */
133 #define SYSSTAT 0x0500
134 #define SYSRST 0x0504
137 /*#define GPIOC 0x0520*/
142 #define I2CTIMCTRL 0x0540
143 #define I2CMADDR 0x0544
144 #define WDATAQ 0x0548
145 #define RDATAQ 0x054C
147 /* Chip/Rev Registers */
150 /* Debug Registers */
151 #define DEBUG00 0x05A0
152 #define DEBUG01 0x05A4
154 /* Panel CABC registers */
155 #define PANEL_PWM_CONTROL 0x90
156 #define PANEL_FREQ_DIVIDER_HI 0x91
157 #define PANEL_FREQ_DIVIDER_LO 0x92
158 #define PANEL_DUTY_CONTROL 0x93
159 #define PANEL_MODIFY_RGB 0x94
160 #define PANEL_FRAMERATE_CONTROL 0x96
161 #define PANEL_PWM_MIN 0x97
162 #define PANEL_PWM_REF 0x98
163 #define PANEL_PWM_MAX 0x99
164 #define PANEL_ALLOW_DISTORT 0x9A
165 #define PANEL_BYPASS_PWMI 0x9B
167 /* Panel color management registers */
168 #define PANEL_CM_ENABLE 0x700
169 #define PANEL_CM_HUE 0x701
170 #define PANEL_CM_SATURATION 0x702
171 #define PANEL_CM_INTENSITY 0x703
172 #define PANEL_CM_BRIGHTNESS 0x704
173 #define PANEL_CM_CE_ENABLE 0x705
174 #define PANEL_CM_PEAK_EN 0x710
175 #define PANEL_CM_GAIN 0x711
176 #define PANEL_CM_HUETABLE_START 0x730
177 #define PANEL_CM_HUETABLE_END 0x747 /* inclusive */
179 /* Input muxing for registers LVMX0003...LVMX2427 */
205 INPUT_HSYNC, /* 24 */
209 /* 28...31 undefined */
212 #define INPUT_MUX(lvmx03, lvmx02, lvmx01, lvmx00) \
213 (FLD_VAL(lvmx03, 29, 24) | FLD_VAL(lvmx02, 20, 16) | \
214 FLD_VAL(lvmx01, 12, 8) | FLD_VAL(lvmx00, 4, 0))
217 * tc35876x_regw - Write DSI-LVDS bridge register using I2C
218 * @client: struct i2c_client to use
219 * @reg: register address
220 * @value: value to write
222 * Returns 0 on success, or a negative error value.
224 static int tc35876x_regw(struct i2c_client *client, u16 reg, u32 value)
228 /* NOTE: Register address big-endian, data little-endian. */
233 (value >> 16) & 0xff,
234 (value >> 24) & 0xff,
236 struct i2c_msg msgs[] = {
238 .addr = client->addr,
241 .len = ARRAY_SIZE(tx_data),
245 r = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
247 dev_err(&client->dev, "%s: reg 0x%04x val 0x%08x error %d\n",
248 __func__, reg, value, r);
252 if (r < ARRAY_SIZE(msgs)) {
253 dev_err(&client->dev, "%s: reg 0x%04x val 0x%08x msgs %d\n",
254 __func__, reg, value, r);
258 dev_dbg(&client->dev, "%s: reg 0x%04x val 0x%08x\n",
259 __func__, reg, value);
265 * tc35876x_regr - Read DSI-LVDS bridge register using I2C
266 * @client: struct i2c_client to use
267 * @reg: register address
268 * @value: pointer for storing the value
270 * Returns 0 on success, or a negative error value.
272 static int tc35876x_regr(struct i2c_client *client, u16 reg, u32 *value)
280 struct i2c_msg msgs[] = {
282 .addr = client->addr,
285 .len = ARRAY_SIZE(tx_data),
288 .addr = client->addr,
291 .len = ARRAY_SIZE(rx_data),
295 r = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
297 dev_err(&client->dev, "%s: reg 0x%04x error %d\n", __func__,
302 if (r < ARRAY_SIZE(msgs)) {
303 dev_err(&client->dev, "%s: reg 0x%04x msgs %d\n", __func__,
308 *value = rx_data[0] << 24 | rx_data[1] << 16 |
309 rx_data[2] << 8 | rx_data[3];
311 dev_dbg(&client->dev, "%s: reg 0x%04x value 0x%08x\n", __func__,
317 void tc35876x_set_bridge_reset_state(struct drm_device *dev, int state)
319 struct tc35876x_platform_data *pdata;
321 if (WARN(!tc35876x_client, "%s called before probe", __func__))
324 dev_dbg(&tc35876x_client->dev, "%s: state %d\n", __func__, state);
326 pdata = dev_get_platdata(&tc35876x_client->dev);
328 if (pdata->gpio_bridge_reset == -1)
332 gpio_set_value_cansleep(pdata->gpio_bridge_reset, 0);
335 /* Pull MIPI Bridge reset pin to Low */
336 gpio_set_value_cansleep(pdata->gpio_bridge_reset, 0);
338 /* Pull MIPI Bridge reset pin to High */
339 gpio_set_value_cansleep(pdata->gpio_bridge_reset, 1);
344 void tc35876x_configure_lvds_bridge(struct drm_device *dev)
346 struct i2c_client *i2c = tc35876x_client;
352 if (WARN(!tc35876x_client, "%s called before probe", __func__))
355 dev_dbg(&tc35876x_client->dev, "%s\n", __func__);
357 if (!tc35876x_regr(i2c, IDREG, &id))
358 dev_info(&tc35876x_client->dev, "tc35876x ID 0x%08x\n", id);
360 dev_err(&tc35876x_client->dev, "Cannot read ID\n");
363 txtagocnt = (5 * ppi_lptxtimecnt - 3) / 4;
364 txtasurecnt = 3 * ppi_lptxtimecnt / 2;
365 tc35876x_regw(i2c, PPI_TX_RX_TA, FLD_VAL(txtagocnt, 26, 16) |
366 FLD_VAL(txtasurecnt, 10, 0));
367 tc35876x_regw(i2c, PPI_LPTXTIMECNT, FLD_VAL(ppi_lptxtimecnt, 10, 0));
369 tc35876x_regw(i2c, PPI_D0S_CLRSIPOCOUNT, FLD_VAL(1, 5, 0));
370 tc35876x_regw(i2c, PPI_D1S_CLRSIPOCOUNT, FLD_VAL(1, 5, 0));
371 tc35876x_regw(i2c, PPI_D2S_CLRSIPOCOUNT, FLD_VAL(1, 5, 0));
372 tc35876x_regw(i2c, PPI_D3S_CLRSIPOCOUNT, FLD_VAL(1, 5, 0));
374 /* Enabling MIPI & PPI lanes, Enable 4 lanes */
375 tc35876x_regw(i2c, PPI_LANEENABLE,
376 BIT(4) | BIT(3) | BIT(2) | BIT(1) | BIT(0));
377 tc35876x_regw(i2c, DSI_LANEENABLE,
378 BIT(4) | BIT(3) | BIT(2) | BIT(1) | BIT(0));
379 tc35876x_regw(i2c, PPI_STARTPPI, BIT(0));
380 tc35876x_regw(i2c, DSI_STARTDSI, BIT(0));
382 /* Setting LVDS output frequency */
383 tc35876x_regw(i2c, LVPHY0, FLD_VAL(1, 20, 16) |
384 FLD_VAL(2, 15, 14) | FLD_VAL(6, 4, 0)); /* 0x00048006 */
386 /* Setting video panel control register,0x00000120 VTGen=ON ?!?!? */
387 tc35876x_regw(i2c, VPCTRL, BIT(8) | BIT(5));
389 /* Horizontal back porch and horizontal pulse width. 0x00280028 */
390 tc35876x_regw(i2c, HTIM1, FLD_VAL(40, 24, 16) | FLD_VAL(40, 8, 0));
392 /* Horizontal front porch and horizontal active video size. 0x00500500*/
393 tc35876x_regw(i2c, HTIM2, FLD_VAL(80, 24, 16) | FLD_VAL(1280, 10, 0));
395 /* Vertical back porch and vertical sync pulse width. 0x000e000a */
396 tc35876x_regw(i2c, VTIM1, FLD_VAL(14, 23, 16) | FLD_VAL(10, 7, 0));
398 /* Vertical front porch and vertical display size. 0x000e0320 */
399 tc35876x_regw(i2c, VTIM2, FLD_VAL(14, 23, 16) | FLD_VAL(800, 10, 0));
401 /* Set above HTIM1, HTIM2, VTIM1, and VTIM2 at next VSYNC. */
402 tc35876x_regw(i2c, VFUEN, BIT(0));
404 /* Soft reset LCD controller. */
405 tc35876x_regw(i2c, SYSRST, BIT(2));
407 /* LVDS-TX input muxing */
408 tc35876x_regw(i2c, LVMX0003,
409 INPUT_MUX(INPUT_R5, INPUT_R4, INPUT_R3, INPUT_R2));
410 tc35876x_regw(i2c, LVMX0407,
411 INPUT_MUX(INPUT_G2, INPUT_R7, INPUT_R1, INPUT_R6));
412 tc35876x_regw(i2c, LVMX0811,
413 INPUT_MUX(INPUT_G1, INPUT_G0, INPUT_G4, INPUT_G3));
414 tc35876x_regw(i2c, LVMX1215,
415 INPUT_MUX(INPUT_B2, INPUT_G7, INPUT_G6, INPUT_G5));
416 tc35876x_regw(i2c, LVMX1619,
417 INPUT_MUX(INPUT_B4, INPUT_B3, INPUT_B1, INPUT_B0));
418 tc35876x_regw(i2c, LVMX2023,
419 INPUT_MUX(LOGIC_0, INPUT_B7, INPUT_B6, INPUT_B5));
420 tc35876x_regw(i2c, LVMX2427,
421 INPUT_MUX(INPUT_R0, INPUT_DE, INPUT_VSYNC, INPUT_HSYNC));
423 /* Enable LVDS transmitter. */
424 tc35876x_regw(i2c, LVCFG, BIT(0));
426 /* Clear notifications. Don't write reserved bits. Was write 0xffffffff
427 * to 0x0288, must be in error?! */
428 tc35876x_regw(i2c, DSI_INTCLR, FLD_MASK(31, 30) | FLD_MASK(22, 0));
431 #define GPIOPWMCTRL 0x38F
432 #define PWM0CLKDIV0 0x62 /* low byte */
433 #define PWM0CLKDIV1 0x61 /* high byte */
435 #define SYSTEMCLK 19200000UL /* 19.2 MHz */
436 #define PWM_FREQUENCY 9600 /* Hz */
438 /* f = baseclk / (clkdiv + 1) => clkdiv = (baseclk - f) / f */
439 static inline u16 calc_clkdiv(unsigned long baseclk, unsigned int f)
441 return (baseclk - f) / f;
444 static void tc35876x_brightness_init(struct drm_device *dev)
450 /* Make sure the PWM reference is the 19.2 MHz system clock. Read first
451 * instead of setting directly to catch potential conflicts between PWM
453 ret = intel_scu_ipc_ioread8(GPIOPWMCTRL, &pwmctrl);
454 if (ret || pwmctrl != 0x01) {
456 dev_err(&dev->pdev->dev, "GPIOPWMCTRL read failed\n");
458 dev_warn(&dev->pdev->dev, "GPIOPWMCTRL was not set to system clock (pwmctrl = 0x%02x)\n", pwmctrl);
460 ret = intel_scu_ipc_iowrite8(GPIOPWMCTRL, 0x01);
462 dev_err(&dev->pdev->dev, "GPIOPWMCTRL set failed\n");
465 clkdiv = calc_clkdiv(SYSTEMCLK, PWM_FREQUENCY);
467 ret = intel_scu_ipc_iowrite8(PWM0CLKDIV1, (clkdiv >> 8) & 0xff);
469 ret = intel_scu_ipc_iowrite8(PWM0CLKDIV0, clkdiv & 0xff);
472 dev_err(&dev->pdev->dev, "PWM0CLKDIV set failed\n");
474 dev_dbg(&dev->pdev->dev, "PWM0CLKDIV set to 0x%04x (%d Hz)\n",
475 clkdiv, PWM_FREQUENCY);
478 #define PWM0DUTYCYCLE 0x67
480 void tc35876x_brightness_control(struct drm_device *dev, int level)
486 level = clamp(level, 0, MDFLD_DSI_BRIGHTNESS_MAX_LEVEL);
488 /* PWM duty cycle 0x00...0x63 corresponds to 0...99% */
489 duty_val = level * 0x63 / MDFLD_DSI_BRIGHTNESS_MAX_LEVEL;
491 /* I won't pretend to understand this formula. The panel spec is quite
494 panel_duty_val = (2 * level - 100) * 0xA9 /
495 MDFLD_DSI_BRIGHTNESS_MAX_LEVEL + 0x56;
497 ret = intel_scu_ipc_iowrite8(PWM0DUTYCYCLE, duty_val);
499 dev_err(&tc35876x_client->dev, "%s: ipc write fail\n",
502 if (cmi_lcd_i2c_client) {
503 ret = i2c_smbus_write_byte_data(cmi_lcd_i2c_client,
504 PANEL_PWM_MAX, panel_duty_val);
506 dev_err(&cmi_lcd_i2c_client->dev, "%s: i2c write failed\n",
511 void tc35876x_toshiba_bridge_panel_off(struct drm_device *dev)
513 struct tc35876x_platform_data *pdata;
515 if (WARN(!tc35876x_client, "%s called before probe", __func__))
518 dev_dbg(&tc35876x_client->dev, "%s\n", __func__);
520 pdata = dev_get_platdata(&tc35876x_client->dev);
522 if (pdata->gpio_panel_bl_en != -1)
523 gpio_set_value_cansleep(pdata->gpio_panel_bl_en, 0);
525 if (pdata->gpio_panel_vadd != -1)
526 gpio_set_value_cansleep(pdata->gpio_panel_vadd, 0);
529 void tc35876x_toshiba_bridge_panel_on(struct drm_device *dev)
531 struct tc35876x_platform_data *pdata;
532 struct drm_psb_private *dev_priv = dev->dev_private;
534 if (WARN(!tc35876x_client, "%s called before probe", __func__))
537 dev_dbg(&tc35876x_client->dev, "%s\n", __func__);
539 pdata = dev_get_platdata(&tc35876x_client->dev);
541 if (pdata->gpio_panel_vadd != -1) {
542 gpio_set_value_cansleep(pdata->gpio_panel_vadd, 1);
546 if (cmi_lcd_i2c_client) {
548 dev_dbg(&cmi_lcd_i2c_client->dev, "setting TCON\n");
549 /* Bit 4 is average_saving. Setting it to 1, the brightness is
550 * referenced to the average of the frame content. 0 means
551 * reference to the maximum of frame contents. Bits 3:0 are
552 * allow_distort. When set to a nonzero value, all color values
553 * between 255-allow_distort*2 and 255 are mapped to the
554 * 255-allow_distort*2 value.
556 ret = i2c_smbus_write_byte_data(cmi_lcd_i2c_client,
557 PANEL_ALLOW_DISTORT, 0x10);
559 dev_err(&cmi_lcd_i2c_client->dev,
560 "i2c write failed (%d)\n", ret);
561 ret = i2c_smbus_write_byte_data(cmi_lcd_i2c_client,
562 PANEL_BYPASS_PWMI, 0);
564 dev_err(&cmi_lcd_i2c_client->dev,
565 "i2c write failed (%d)\n", ret);
566 /* Set minimum brightness value - this is tunable */
567 ret = i2c_smbus_write_byte_data(cmi_lcd_i2c_client,
568 PANEL_PWM_MIN, 0x35);
570 dev_err(&cmi_lcd_i2c_client->dev,
571 "i2c write failed (%d)\n", ret);
574 if (pdata->gpio_panel_bl_en != -1)
575 gpio_set_value_cansleep(pdata->gpio_panel_bl_en, 1);
577 tc35876x_brightness_control(dev, dev_priv->brightness_adjusted);
580 static struct drm_display_mode *tc35876x_get_config_mode(struct drm_device *dev)
582 struct drm_display_mode *mode;
584 dev_dbg(&dev->pdev->dev, "%s\n", __func__);
586 mode = kzalloc(sizeof(*mode), GFP_KERNEL);
590 /* FIXME: do this properly. */
591 mode->hdisplay = 1280;
592 mode->vdisplay = 800;
593 mode->hsync_start = 1360;
594 mode->hsync_end = 1400;
596 mode->vsync_start = 814;
597 mode->vsync_end = 824;
599 mode->clock = 33324 << 1;
601 dev_info(&dev->pdev->dev, "hdisplay(w) = %d\n", mode->hdisplay);
602 dev_info(&dev->pdev->dev, "vdisplay(h) = %d\n", mode->vdisplay);
603 dev_info(&dev->pdev->dev, "HSS = %d\n", mode->hsync_start);
604 dev_info(&dev->pdev->dev, "HSE = %d\n", mode->hsync_end);
605 dev_info(&dev->pdev->dev, "htotal = %d\n", mode->htotal);
606 dev_info(&dev->pdev->dev, "VSS = %d\n", mode->vsync_start);
607 dev_info(&dev->pdev->dev, "VSE = %d\n", mode->vsync_end);
608 dev_info(&dev->pdev->dev, "vtotal = %d\n", mode->vtotal);
609 dev_info(&dev->pdev->dev, "clock = %d\n", mode->clock);
611 drm_mode_set_name(mode);
612 drm_mode_set_crtcinfo(mode, 0);
614 mode->type |= DRM_MODE_TYPE_PREFERRED;
619 /* DV1 Active area 216.96 x 135.6 mm */
620 #define DV1_PANEL_WIDTH 217
621 #define DV1_PANEL_HEIGHT 136
623 static int tc35876x_get_panel_info(struct drm_device *dev, int pipe,
624 struct panel_info *pi)
629 pi->width_mm = DV1_PANEL_WIDTH;
630 pi->height_mm = DV1_PANEL_HEIGHT;
635 static int tc35876x_bridge_probe(struct i2c_client *client,
636 const struct i2c_device_id *id)
638 struct tc35876x_platform_data *pdata;
640 dev_info(&client->dev, "%s\n", __func__);
642 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
643 dev_err(&client->dev, "%s: i2c_check_functionality() failed\n",
648 pdata = dev_get_platdata(&client->dev);
650 dev_err(&client->dev, "%s: no platform data\n", __func__);
654 if (pdata->gpio_bridge_reset != -1) {
655 gpio_request(pdata->gpio_bridge_reset, "tc35876x bridge reset");
656 gpio_direction_output(pdata->gpio_bridge_reset, 0);
659 if (pdata->gpio_panel_bl_en != -1) {
660 gpio_request(pdata->gpio_panel_bl_en, "tc35876x panel bl en");
661 gpio_direction_output(pdata->gpio_panel_bl_en, 0);
664 if (pdata->gpio_panel_vadd != -1) {
665 gpio_request(pdata->gpio_panel_vadd, "tc35876x panel vadd");
666 gpio_direction_output(pdata->gpio_panel_vadd, 0);
669 tc35876x_client = client;
674 static int tc35876x_bridge_remove(struct i2c_client *client)
676 struct tc35876x_platform_data *pdata = dev_get_platdata(&client->dev);
678 dev_dbg(&client->dev, "%s\n", __func__);
680 if (pdata->gpio_bridge_reset != -1)
681 gpio_free(pdata->gpio_bridge_reset);
683 if (pdata->gpio_panel_bl_en != -1)
684 gpio_free(pdata->gpio_panel_bl_en);
686 if (pdata->gpio_panel_vadd != -1)
687 gpio_free(pdata->gpio_panel_vadd);
689 tc35876x_client = NULL;
694 static const struct i2c_device_id tc35876x_bridge_id[] = {
695 { "i2c_disp_brig", 0 },
698 MODULE_DEVICE_TABLE(i2c, tc35876x_bridge_id);
700 static struct i2c_driver tc35876x_bridge_i2c_driver = {
702 .name = "i2c_disp_brig",
704 .id_table = tc35876x_bridge_id,
705 .probe = tc35876x_bridge_probe,
706 .remove = tc35876x_bridge_remove,
710 static int cmi_lcd_i2c_probe(struct i2c_client *client,
711 const struct i2c_device_id *id)
713 dev_info(&client->dev, "%s\n", __func__);
715 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
716 dev_err(&client->dev, "%s: i2c_check_functionality() failed\n",
721 cmi_lcd_i2c_client = client;
726 static int cmi_lcd_i2c_remove(struct i2c_client *client)
728 dev_dbg(&client->dev, "%s\n", __func__);
730 cmi_lcd_i2c_client = NULL;
735 static const struct i2c_device_id cmi_lcd_i2c_id[] = {
739 MODULE_DEVICE_TABLE(i2c, cmi_lcd_i2c_id);
741 static struct i2c_driver cmi_lcd_i2c_driver = {
745 .id_table = cmi_lcd_i2c_id,
746 .probe = cmi_lcd_i2c_probe,
747 .remove = cmi_lcd_i2c_remove,
750 /* HACK to create I2C device while it's not created by platform code */
751 #define CMI_LCD_I2C_ADAPTER 2
752 #define CMI_LCD_I2C_ADDR 0x60
754 static int cmi_lcd_hack_create_device(void)
756 struct i2c_adapter *adapter;
757 struct i2c_client *client;
758 struct i2c_board_info info = {
760 .addr = CMI_LCD_I2C_ADDR,
763 pr_debug("%s\n", __func__);
765 adapter = i2c_get_adapter(CMI_LCD_I2C_ADAPTER);
767 pr_err("%s: i2c_get_adapter(%d) failed\n", __func__,
768 CMI_LCD_I2C_ADAPTER);
772 client = i2c_new_device(adapter, &info);
774 pr_err("%s: i2c_new_device() failed\n", __func__);
775 i2c_put_adapter(adapter);
782 static const struct drm_encoder_helper_funcs tc35876x_encoder_helper_funcs = {
783 .dpms = mdfld_dsi_dpi_dpms,
784 .mode_fixup = mdfld_dsi_dpi_mode_fixup,
785 .prepare = mdfld_dsi_dpi_prepare,
786 .mode_set = mdfld_dsi_dpi_mode_set,
787 .commit = mdfld_dsi_dpi_commit,
790 static const struct drm_encoder_funcs tc35876x_encoder_funcs = {
791 .destroy = drm_encoder_cleanup,
794 const struct panel_funcs mdfld_tc35876x_funcs = {
795 .encoder_funcs = &tc35876x_encoder_funcs,
796 .encoder_helper_funcs = &tc35876x_encoder_helper_funcs,
797 .get_config_mode = tc35876x_get_config_mode,
798 .get_panel_info = tc35876x_get_panel_info,
801 void tc35876x_init(struct drm_device *dev)
805 dev_dbg(&dev->pdev->dev, "%s\n", __func__);
807 cmi_lcd_hack_create_device();
809 r = i2c_add_driver(&cmi_lcd_i2c_driver);
811 dev_err(&dev->pdev->dev,
812 "%s: i2c_add_driver() for %s failed (%d)\n",
813 __func__, cmi_lcd_i2c_driver.driver.name, r);
815 r = i2c_add_driver(&tc35876x_bridge_i2c_driver);
817 dev_err(&dev->pdev->dev,
818 "%s: i2c_add_driver() for %s failed (%d)\n",
819 __func__, tc35876x_bridge_i2c_driver.driver.name, r);
821 tc35876x_brightness_init(dev);
824 void tc35876x_exit(void)
826 pr_debug("%s\n", __func__);
828 i2c_del_driver(&tc35876x_bridge_i2c_driver);
830 if (cmi_lcd_i2c_client)
831 i2c_del_driver(&cmi_lcd_i2c_driver);