1 #include <linux/amba/bus.h>
2 #include <linux/amba/clcd.h>
3 #include <linux/gpio/consumer.h>
5 #include <linux/of_graph.h>
6 #include <linux/delay.h>
7 #include <linux/bitops.h>
8 #include <linux/mfd/syscon.h>
9 #include <linux/regmap.h>
11 #include "amba-clcd-nomadik.h"
13 static struct gpio_desc
*grestb
;
14 static struct gpio_desc
*scen
;
15 static struct gpio_desc
*scl
;
16 static struct gpio_desc
*sda
;
18 static u8
tpg110_readwrite_reg(bool write
, u8 address
, u8 outval
)
24 gpiod_set_value_cansleep(scen
, 1);
26 /* Hammer out the address */
27 for (i
= 5; i
>= 0; i
--) {
29 gpiod_set_value_cansleep(sda
, 1);
31 gpiod_set_value_cansleep(sda
, 0);
33 /* Send an SCL pulse */
34 gpiod_set_value_cansleep(scl
, 1);
36 gpiod_set_value_cansleep(scl
, 0);
42 gpiod_set_value_cansleep(sda
, 0);
45 gpiod_set_value_cansleep(sda
, 1);
48 /* Send an SCL pulse */
49 gpiod_set_value_cansleep(scl
, 1);
51 gpiod_set_value_cansleep(scl
, 0);
55 /* HiZ turn-around cycle */
56 gpiod_direction_input(sda
);
58 /* Send an SCL pulse */
59 gpiod_set_value_cansleep(scl
, 1);
61 gpiod_set_value_cansleep(scl
, 0);
64 /* Hammer in/out the data */
65 for (i
= 7; i
>= 0; i
--) {
69 value
= !!(outval
& BIT(i
));
70 gpiod_set_value_cansleep(sda
, value
);
72 value
= gpiod_get_value(sda
);
77 /* Send an SCL pulse */
78 gpiod_set_value_cansleep(scl
, 1);
80 gpiod_set_value_cansleep(scl
, 0);
84 gpiod_direction_output(sda
, 0);
86 gpiod_set_value_cansleep(scen
, 0);
87 /* Satisfies SCEN pulse width */
93 static u8
tpg110_read_reg(u8 address
)
95 return tpg110_readwrite_reg(false, address
, 0);
98 static void tpg110_write_reg(u8 address
, u8 outval
)
100 tpg110_readwrite_reg(true, address
, outval
);
103 static void tpg110_startup(struct device
*dev
)
107 dev_info(dev
, "TPG110 display enable\n");
108 /* De-assert the reset signal */
109 gpiod_set_value_cansleep(grestb
, 0);
111 dev_info(dev
, "de-asserted GRESTB\n");
113 /* Test display communication */
114 tpg110_write_reg(0x00, 0x55);
115 val
= tpg110_read_reg(0x00);
117 dev_info(dev
, "passed communication test\n");
118 val
= tpg110_read_reg(0x01);
119 dev_info(dev
, "TPG110 chip ID: %d version: %d\n",
122 /* Show display resolution */
123 val
= tpg110_read_reg(0x02);
127 dev_info(dev
, "IN 400x240 RGB -> OUT 800x480 RGB (dual scan)");
130 dev_info(dev
, "IN 480x272 RGB -> OUT 800x480 RGB (dual scan)");
133 dev_info(dev
, "480x640 RGB");
136 dev_info(dev
, "480x272 RGB");
139 dev_info(dev
, "640x480 RGB");
142 dev_info(dev
, "800x480 RGB");
145 dev_info(dev
, "ILLEGAL RESOLUTION");
149 val
= tpg110_read_reg(0x03);
150 dev_info(dev
, "resolution is controlled by %s\n",
151 (val
& BIT(7)) ? "software" : "hardware");
154 static void tpg110_enable(struct clcd_fb
*fb
)
156 struct device
*dev
= &fb
->dev
->dev
;
165 /* Take chip out of standby */
166 val
= tpg110_read_reg(0x03);
168 tpg110_write_reg(0x03, val
);
171 static void tpg110_disable(struct clcd_fb
*fb
)
175 dev_info(&fb
->dev
->dev
, "TPG110 display disable\n");
176 val
= tpg110_read_reg(0x03);
177 /* Put into standby */
179 tpg110_write_reg(0x03, val
);
182 static void tpg110_init(struct device
*dev
, struct device_node
*np
,
183 struct clcd_board
*board
)
185 dev_info(dev
, "TPG110 display init\n");
187 /* This asserts the GRESTB signal, putting the display into reset */
188 grestb
= devm_fwnode_get_gpiod_from_child(dev
, "grestb", &np
->fwnode
,
189 GPIOD_OUT_HIGH
, "grestb");
190 if (IS_ERR(grestb
)) {
191 dev_err(dev
, "no GRESTB GPIO\n");
194 scen
= devm_fwnode_get_gpiod_from_child(dev
, "scen", &np
->fwnode
,
195 GPIOD_OUT_LOW
, "scen");
197 dev_err(dev
, "no SCEN GPIO\n");
200 scl
= devm_fwnode_get_gpiod_from_child(dev
, "scl", &np
->fwnode
,
201 GPIOD_OUT_LOW
, "scl");
203 dev_err(dev
, "no SCL GPIO\n");
206 sda
= devm_fwnode_get_gpiod_from_child(dev
, "sda", &np
->fwnode
,
207 GPIOD_OUT_LOW
, "sda");
209 dev_err(dev
, "no SDA GPIO\n");
212 board
->enable
= tpg110_enable
;
213 board
->disable
= tpg110_disable
;
216 int nomadik_clcd_init_panel(struct clcd_fb
*fb
, struct device_node
*panel
)
218 if (of_device_is_compatible(panel
, "tpo,tpg110"))
219 tpg110_init(&fb
->dev
->dev
, panel
, fb
->board
);
221 dev_info(&fb
->dev
->dev
, "unknown panel\n");
223 /* Unknown panel, fall through */
226 EXPORT_SYMBOL_GPL(nomadik_clcd_init_panel
);
228 #define PMU_CTRL_OFFSET 0x0000
229 #define PMU_CTRL_LCDNDIF BIT(26)
231 int nomadik_clcd_init_board(struct amba_device
*adev
,
232 struct clcd_board
*board
)
234 struct regmap
*pmu_regmap
;
236 dev_info(&adev
->dev
, "Nomadik CLCD board init\n");
238 syscon_regmap_lookup_by_compatible("stericsson,nomadik-pmu");
239 if (IS_ERR(pmu_regmap
)) {
240 dev_err(&adev
->dev
, "could not find PMU syscon regmap\n");
241 return PTR_ERR(pmu_regmap
);
243 regmap_update_bits(pmu_regmap
,
247 dev_info(&adev
->dev
, "set PMU mux to CLCD mode\n");
251 EXPORT_SYMBOL_GPL(nomadik_clcd_init_board
);