| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * ROHM Semiconductor BD6107 LED Driver |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2013 Ideas on board SPRL |
|---|
| 5 | 6 | * |
|---|
| 6 | 7 | * Contact: Laurent Pinchart <laurent.pinchart@ideasonboard.com> |
|---|
| 7 | | - * |
|---|
| 8 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 9 | | - * it under the terms of the GNU General Public License version 2 as |
|---|
| 10 | | - * published by the Free Software Foundation. |
|---|
| 11 | 8 | */ |
|---|
| 12 | 9 | |
|---|
| 13 | 10 | #include <linux/backlight.h> |
|---|
| 14 | 11 | #include <linux/delay.h> |
|---|
| 15 | 12 | #include <linux/err.h> |
|---|
| 16 | 13 | #include <linux/fb.h> |
|---|
| 17 | | -#include <linux/gpio.h> |
|---|
| 14 | +#include <linux/gpio/consumer.h> |
|---|
| 18 | 15 | #include <linux/i2c.h> |
|---|
| 19 | 16 | #include <linux/module.h> |
|---|
| 20 | 17 | #include <linux/platform_data/bd6107.h> |
|---|
| .. | .. |
|---|
| 74 | 71 | struct i2c_client *client; |
|---|
| 75 | 72 | struct backlight_device *backlight; |
|---|
| 76 | 73 | struct bd6107_platform_data *pdata; |
|---|
| 74 | + struct gpio_desc *reset; |
|---|
| 77 | 75 | }; |
|---|
| 78 | 76 | |
|---|
| 79 | 77 | static int bd6107_write(struct bd6107 *bd, u8 reg, u8 data) |
|---|
| .. | .. |
|---|
| 84 | 82 | static int bd6107_backlight_update_status(struct backlight_device *backlight) |
|---|
| 85 | 83 | { |
|---|
| 86 | 84 | struct bd6107 *bd = bl_get_data(backlight); |
|---|
| 87 | | - int brightness = backlight->props.brightness; |
|---|
| 88 | | - |
|---|
| 89 | | - if (backlight->props.power != FB_BLANK_UNBLANK || |
|---|
| 90 | | - backlight->props.fb_blank != FB_BLANK_UNBLANK || |
|---|
| 91 | | - backlight->props.state & (BL_CORE_SUSPENDED | BL_CORE_FBBLANK)) |
|---|
| 92 | | - brightness = 0; |
|---|
| 85 | + int brightness = backlight_get_brightness(backlight); |
|---|
| 93 | 86 | |
|---|
| 94 | 87 | if (brightness) { |
|---|
| 95 | 88 | bd6107_write(bd, BD6107_PORTSEL, BD6107_PORTSEL_LEDM(2) | |
|---|
| .. | .. |
|---|
| 97 | 90 | bd6107_write(bd, BD6107_MAINCNT1, brightness); |
|---|
| 98 | 91 | bd6107_write(bd, BD6107_LEDCNT1, BD6107_LEDCNT1_LEDONOFF1); |
|---|
| 99 | 92 | } else { |
|---|
| 100 | | - gpio_set_value(bd->pdata->reset, 0); |
|---|
| 93 | + /* Assert the reset line (gpiolib will handle active low) */ |
|---|
| 94 | + gpiod_set_value(bd->reset, 1); |
|---|
| 101 | 95 | msleep(24); |
|---|
| 102 | | - gpio_set_value(bd->pdata->reset, 1); |
|---|
| 96 | + gpiod_set_value(bd->reset, 0); |
|---|
| 103 | 97 | } |
|---|
| 104 | 98 | |
|---|
| 105 | 99 | return 0; |
|---|
| .. | .. |
|---|
| 128 | 122 | struct bd6107 *bd; |
|---|
| 129 | 123 | int ret; |
|---|
| 130 | 124 | |
|---|
| 131 | | - if (pdata == NULL || !pdata->reset) { |
|---|
| 132 | | - dev_err(&client->dev, "No reset GPIO in platform data\n"); |
|---|
| 125 | + if (pdata == NULL) { |
|---|
| 126 | + dev_err(&client->dev, "No platform data\n"); |
|---|
| 133 | 127 | return -EINVAL; |
|---|
| 134 | 128 | } |
|---|
| 135 | 129 | |
|---|
| .. | .. |
|---|
| 147 | 141 | bd->client = client; |
|---|
| 148 | 142 | bd->pdata = pdata; |
|---|
| 149 | 143 | |
|---|
| 150 | | - ret = devm_gpio_request_one(&client->dev, pdata->reset, |
|---|
| 151 | | - GPIOF_DIR_OUT | GPIOF_INIT_LOW, "reset"); |
|---|
| 152 | | - if (ret < 0) { |
|---|
| 144 | + /* |
|---|
| 145 | + * Request the reset GPIO line with GPIOD_OUT_HIGH meaning asserted, |
|---|
| 146 | + * so in the machine descriptor table (or other hardware description), |
|---|
| 147 | + * the line should be flagged as active low so this will assert |
|---|
| 148 | + * the reset. |
|---|
| 149 | + */ |
|---|
| 150 | + bd->reset = devm_gpiod_get(&client->dev, "reset", GPIOD_OUT_HIGH); |
|---|
| 151 | + if (IS_ERR(bd->reset)) { |
|---|
| 153 | 152 | dev_err(&client->dev, "unable to request reset GPIO\n"); |
|---|
| 153 | + ret = PTR_ERR(bd->reset); |
|---|
| 154 | 154 | return ret; |
|---|
| 155 | 155 | } |
|---|
| 156 | 156 | |
|---|