1 From 6486bb50b96f359844b9c34f0978c69bbdcda140 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Fri, 10 Sep 2021 13:50:28 +0100
4 Subject: [PATCH] regulator: rpi-panel: Add GPIO control for panel and
7 We need independent control of the resets for the panel&bridge,
8 vs the touch controller.
10 Expose the reset lines that are on the Atmel's port C via the GPIO
11 API so that they can be controlled appropriately.
13 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
15 .../regulator/rpi-panel-attiny-regulator.c | 115 +++++++++++++++---
16 1 file changed, 97 insertions(+), 18 deletions(-)
18 --- a/drivers/regulator/rpi-panel-attiny-regulator.c
19 +++ b/drivers/regulator/rpi-panel-attiny-regulator.c
21 #include <linux/backlight.h>
22 #include <linux/err.h>
23 #include <linux/gpio.h>
24 +#include <linux/gpio/driver.h>
25 #include <linux/i2c.h>
26 #include <linux/init.h>
27 #include <linux/interrupt.h>
29 #define PC_RST_LCD_N BIT(2)
30 #define PC_RST_BRIDGE_N BIT(3)
33 + RST_BRIDGE_N, /* TC358762 bridge reset */
34 + RST_TP_N, /* Touch controller reset */
38 +struct gpio_signal_mappings {
43 +static const struct gpio_signal_mappings mappings[NUM_GPIO] = {
44 + [RST_BRIDGE_N] = { REG_PORTC, PC_RST_BRIDGE_N | PC_RST_LCD_N },
45 + [RST_TP_N] = { REG_PORTC, PC_RST_TP_N },
49 /* lock to serialise overall accesses to the Atmel */
51 struct regmap *regmap;
52 + bool gpio_states[NUM_GPIO];
55 + struct gpio_chip gc;
58 static const struct regmap_config attiny_regmap_config = {
59 @@ -58,6 +79,17 @@ static const struct regmap_config attiny
60 .cache_type = REGCACHE_NONE,
63 +static int attiny_set_port_state(struct attiny_lcd *state, int reg, u8 val)
65 + state->port_states[reg - REG_PORTA] = val;
66 + return regmap_write(state->regmap, reg, val);
69 +static u8 attiny_get_port_state(struct attiny_lcd *state, int reg)
71 + return state->port_states[reg - REG_PORTA];
74 static int attiny_lcd_power_enable(struct regulator_dev *rdev)
76 struct attiny_lcd *state = rdev_get_drvdata(rdev);
77 @@ -65,7 +97,7 @@ static int attiny_lcd_power_enable(struc
78 mutex_lock(&state->lock);
80 /* Ensure bridge, and tp stay in reset */
81 - regmap_write(rdev->regmap, REG_PORTC, 0);
82 + attiny_set_port_state(state, REG_PORTC, 0);
83 usleep_range(5000, 10000);
85 /* Default to the same orientation as the closed source
86 @@ -73,26 +105,16 @@ static int attiny_lcd_power_enable(struc
87 * configuration will be supported using VC4's plane
90 - regmap_write(rdev->regmap, REG_PORTA, PA_LCD_LR);
91 + attiny_set_port_state(state, REG_PORTA, PA_LCD_LR);
92 usleep_range(5000, 10000);
93 - regmap_write(rdev->regmap, REG_PORTB, PB_LCD_MAIN);
94 + /* Main regulator on, and power to the panel (LCD_VCC_N) */
95 + attiny_set_port_state(state, REG_PORTB, PB_LCD_MAIN);
96 usleep_range(5000, 10000);
97 /* Bring controllers out of reset */
98 - regmap_write(rdev->regmap, REG_PORTC,
99 - PC_LED_EN | PC_RST_BRIDGE_N | PC_RST_LCD_N | PC_RST_TP_N);
100 + attiny_set_port_state(state, REG_PORTC, PC_LED_EN);
104 - regmap_write(rdev->regmap, REG_ADDR_H, 0x04);
105 - usleep_range(5000, 8000);
106 - regmap_write(rdev->regmap, REG_ADDR_L, 0x7c);
107 - usleep_range(5000, 8000);
108 - regmap_write(rdev->regmap, REG_WRITE_DATA_H, 0x00);
109 - usleep_range(5000, 8000);
110 - regmap_write(rdev->regmap, REG_WRITE_DATA_L, 0x00);
114 mutex_unlock(&state->lock);
117 @@ -106,11 +128,12 @@ static int attiny_lcd_power_disable(stru
119 regmap_write(rdev->regmap, REG_PWM, 0);
120 usleep_range(5000, 10000);
121 - regmap_write(rdev->regmap, REG_PORTA, 0);
123 + attiny_set_port_state(state, REG_PORTA, 0);
124 usleep_range(5000, 10000);
125 - regmap_write(rdev->regmap, REG_PORTB, PB_LCD_VCC_N);
126 + attiny_set_port_state(state, REG_PORTB, PB_LCD_VCC_N);
127 usleep_range(5000, 10000);
128 - regmap_write(rdev->regmap, REG_PORTC, 0);
129 + attiny_set_port_state(state, REG_PORTC, 0);
132 mutex_unlock(&state->lock);
133 @@ -211,6 +234,45 @@ static const struct backlight_ops attiny
134 .get_brightness = attiny_get_brightness,
137 +static int attiny_gpio_get_direction(struct gpio_chip *gc, unsigned int off)
139 + return GPIO_LINE_DIRECTION_OUT;
142 +static void attiny_gpio_set(struct gpio_chip *gc, unsigned int off, int val)
144 + struct attiny_lcd *state = gpiochip_get_data(gc);
147 + if (off >= NUM_GPIO)
150 + mutex_lock(&state->lock);
152 + last_val = attiny_get_port_state(state, mappings[off].reg);
154 + last_val |= mappings[off].mask;
156 + last_val &= ~mappings[off].mask;
158 + attiny_set_port_state(state, mappings[off].reg, last_val);
160 + if (off == RST_BRIDGE_N && val) {
161 + usleep_range(5000, 8000);
162 + regmap_write(state->regmap, REG_ADDR_H, 0x04);
163 + usleep_range(5000, 8000);
164 + regmap_write(state->regmap, REG_ADDR_L, 0x7c);
165 + usleep_range(5000, 8000);
166 + regmap_write(state->regmap, REG_WRITE_DATA_H, 0x00);
167 + usleep_range(5000, 8000);
168 + regmap_write(state->regmap, REG_WRITE_DATA_L, 0x00);
173 + mutex_unlock(&state->lock);
177 * I2C driver interface functions
179 @@ -289,6 +351,23 @@ static int attiny_i2c_probe(struct i2c_c
181 bl->props.brightness = 0xff;
183 + state->gc.parent = &i2c->dev;
184 + state->gc.label = i2c->name;
185 + state->gc.owner = THIS_MODULE;
186 + state->gc.of_node = i2c->dev.of_node;
187 + state->gc.base = -1;
188 + state->gc.ngpio = NUM_GPIO;
190 + state->gc.set = attiny_gpio_set;
191 + state->gc.get_direction = attiny_gpio_get_direction;
192 + state->gc.can_sleep = true;
194 + ret = devm_gpiochip_add_data(&i2c->dev, &state->gc, state);
196 + dev_err(&i2c->dev, "Failed to create gpiochip: %d\n", ret);