Skip to content

Commit 09919d8

Browse files
6by9popcornmix
authored andcommitted
regulator/rpi-panel-attiny: Don't read the LCD power status
The I2C to the Atmel is very fussy, and locks up easily on Pi0-3 particularly on reads. The LCD power status is controlled solely by this driver, so rather than reading it back from the Atmel, use the cached status last set. Signed-off-by: Dave Stevenson <[email protected]> regulator/rpi-panel: Power off display on shutdown Adds a shutdown function to turn off the backlight, bridge, and touch controller on shutdown. Signed-off-by: Dave Stevenson <[email protected]> regulator/rpi-panel: Remove the ID read Reading from the Atmel has always been troublesome due to clock stretching, and the driver does nothing with it anyway. Remove the read and assume that if the overlay has been configured (most likely through the firmware autodetection) that the hardware is present. Signed-off-by: Dave Stevenson <[email protected]>
1 parent ab5ae4d commit 09919d8

File tree

1 file changed

+10
-67
lines changed

1 file changed

+10
-67
lines changed

drivers/regulator/rpi-panel-attiny-regulator.c

Lines changed: 10 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -143,24 +143,8 @@ static int attiny_lcd_power_disable(struct regulator_dev *rdev)
143143
static int attiny_lcd_power_is_enabled(struct regulator_dev *rdev)
144144
{
145145
struct attiny_lcd *state = rdev_get_drvdata(rdev);
146-
unsigned int data;
147-
int ret, i;
148-
149-
mutex_lock(&state->lock);
150146

151-
for (i = 0; i < 10; i++) {
152-
ret = regmap_read(rdev->regmap, REG_PORTC, &data);
153-
if (!ret)
154-
break;
155-
usleep_range(10000, 12000);
156-
}
157-
158-
mutex_unlock(&state->lock);
159-
160-
if (ret < 0)
161-
return ret;
162-
163-
return data & PC_RST_BRIDGE_N;
147+
return state->port_states[REG_PORTC - REG_PORTA] & PC_RST_BRIDGE_N;
164148
}
165149

166150
static const struct regulator_init_data attiny_regulator_default = {
@@ -245,39 +229,6 @@ static void attiny_gpio_set(struct gpio_chip *gc, unsigned int off, int val)
245229
mutex_unlock(&state->lock);
246230
}
247231

248-
static int attiny_i2c_read(struct i2c_client *client, u8 reg, unsigned int *buf)
249-
{
250-
struct i2c_msg msgs[1];
251-
u8 addr_buf[1] = { reg };
252-
u8 data_buf[1] = { 0, };
253-
int ret;
254-
255-
/* Write register address */
256-
msgs[0].addr = client->addr;
257-
msgs[0].flags = 0;
258-
msgs[0].len = ARRAY_SIZE(addr_buf);
259-
msgs[0].buf = addr_buf;
260-
261-
ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
262-
if (ret != ARRAY_SIZE(msgs))
263-
return -EIO;
264-
265-
usleep_range(5000, 10000);
266-
267-
/* Read data from register */
268-
msgs[0].addr = client->addr;
269-
msgs[0].flags = I2C_M_RD;
270-
msgs[0].len = 1;
271-
msgs[0].buf = data_buf;
272-
273-
ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
274-
if (ret != ARRAY_SIZE(msgs))
275-
return -EIO;
276-
277-
*buf = data_buf[0];
278-
return 0;
279-
}
280-
281232
/*
282233
* I2C driver interface functions
283234
*/
@@ -289,7 +240,6 @@ static int attiny_i2c_probe(struct i2c_client *i2c)
289240
struct regulator_dev *rdev;
290241
struct attiny_lcd *state;
291242
struct regmap *regmap;
292-
unsigned int data;
293243
int ret;
294244

295245
state = devm_kzalloc(&i2c->dev, sizeof(*state), GFP_KERNEL);
@@ -307,22 +257,6 @@ static int attiny_i2c_probe(struct i2c_client *i2c)
307257
goto error;
308258
}
309259

310-
ret = attiny_i2c_read(i2c, REG_ID, &data);
311-
if (ret < 0) {
312-
dev_err(&i2c->dev, "Failed to read REG_ID reg: %d\n", ret);
313-
goto error;
314-
}
315-
316-
switch (data) {
317-
case 0xde: /* ver 1 */
318-
case 0xc3: /* ver 2 */
319-
break;
320-
default:
321-
dev_err(&i2c->dev, "Unknown Atmel firmware revision: 0x%02x\n", data);
322-
ret = -ENODEV;
323-
goto error;
324-
}
325-
326260
regmap_write(regmap, REG_POWERON, 0);
327261
msleep(30);
328262
regmap_write(regmap, REG_PWM, 0);
@@ -386,6 +320,14 @@ static void attiny_i2c_remove(struct i2c_client *client)
386320
mutex_destroy(&state->lock);
387321
}
388322

323+
static void attiny_i2c_shutdown(struct i2c_client *client)
324+
{
325+
struct attiny_lcd *state = i2c_get_clientdata(client);
326+
327+
regmap_write(state->regmap, REG_PWM, 0);
328+
regmap_write(state->regmap, REG_POWERON, 0);
329+
}
330+
389331
static const struct of_device_id attiny_dt_ids[] = {
390332
{ .compatible = "raspberrypi,7inch-touchscreen-panel-regulator" },
391333
{},
@@ -400,6 +342,7 @@ static struct i2c_driver attiny_regulator_driver = {
400342
},
401343
.probe = attiny_i2c_probe,
402344
.remove = attiny_i2c_remove,
345+
.shutdown = attiny_i2c_shutdown,
403346
};
404347

405348
module_i2c_driver(attiny_regulator_driver);

0 commit comments

Comments
 (0)