| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * LCD / Backlight control code for Sharp SL-6000x (tosa) |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (c) 2005 Dirk Opfer |
|---|
| 5 | 6 | * Copyright (c) 2007,2008 Dmitry Baryshkov |
|---|
| 6 | | - * |
|---|
| 7 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 8 | | - * it under the terms of the GNU General Public License version 2 as |
|---|
| 9 | | - * published by the Free Software Foundation. |
|---|
| 10 | | - * |
|---|
| 11 | 7 | */ |
|---|
| 12 | 8 | |
|---|
| 13 | 9 | #include <linux/kernel.h> |
|---|
| .. | .. |
|---|
| 16 | 12 | #include <linux/spi/spi.h> |
|---|
| 17 | 13 | #include <linux/i2c.h> |
|---|
| 18 | 14 | #include <linux/slab.h> |
|---|
| 19 | | -#include <linux/gpio.h> |
|---|
| 15 | +#include <linux/gpio/consumer.h> |
|---|
| 20 | 16 | #include <linux/delay.h> |
|---|
| 21 | 17 | #include <linux/lcd.h> |
|---|
| 22 | 18 | #include <linux/fb.h> |
|---|
| 23 | 19 | |
|---|
| 24 | 20 | #include <asm/mach/sharpsl_param.h> |
|---|
| 25 | 21 | |
|---|
| 26 | | -#include <mach/tosa.h> |
|---|
| 22 | +#include "tosa_bl.h" |
|---|
| 27 | 23 | |
|---|
| 28 | 24 | #define POWER_IS_ON(pwr) ((pwr) <= FB_BLANK_NORMAL) |
|---|
| 29 | 25 | |
|---|
| .. | .. |
|---|
| 32 | 28 | #define TG_REG0_UD 0x0004 |
|---|
| 33 | 29 | #define TG_REG0_LR 0x0008 |
|---|
| 34 | 30 | |
|---|
| 31 | +/* |
|---|
| 32 | + * Timing Generator |
|---|
| 33 | + */ |
|---|
| 34 | +#define TG_PNLCTL 0x00 |
|---|
| 35 | +#define TG_TPOSCTL 0x01 |
|---|
| 36 | +#define TG_DUTYCTL 0x02 |
|---|
| 37 | +#define TG_GPOSR 0x03 |
|---|
| 38 | +#define TG_GPODR1 0x04 |
|---|
| 39 | +#define TG_GPODR2 0x05 |
|---|
| 40 | +#define TG_PINICTL 0x06 |
|---|
| 41 | +#define TG_HPOSCTL 0x07 |
|---|
| 42 | + |
|---|
| 43 | + |
|---|
| 35 | 44 | #define DAC_BASE 0x4e |
|---|
| 36 | 45 | |
|---|
| 37 | 46 | struct tosa_lcd_data { |
|---|
| 38 | 47 | struct spi_device *spi; |
|---|
| 39 | 48 | struct lcd_device *lcd; |
|---|
| 40 | 49 | struct i2c_client *i2c; |
|---|
| 50 | + struct gpio_desc *gpiod_tg; |
|---|
| 41 | 51 | |
|---|
| 42 | 52 | int lcd_power; |
|---|
| 43 | 53 | bool is_vga; |
|---|
| .. | .. |
|---|
| 70 | 80 | static void tosa_lcd_tg_init(struct tosa_lcd_data *data) |
|---|
| 71 | 81 | { |
|---|
| 72 | 82 | /* TG on */ |
|---|
| 73 | | - gpio_set_value(TOSA_GPIO_TG_ON, 0); |
|---|
| 83 | + gpiod_set_value(data->gpiod_tg, 0); |
|---|
| 74 | 84 | |
|---|
| 75 | 85 | mdelay(60); |
|---|
| 76 | 86 | |
|---|
| .. | .. |
|---|
| 97 | 107 | /* TG LCD GVSS */ |
|---|
| 98 | 108 | tosa_tg_send(spi, TG_PINICTL, 0x0); |
|---|
| 99 | 109 | |
|---|
| 100 | | - if (!data->i2c) { |
|---|
| 110 | + if (IS_ERR_OR_NULL(data->i2c)) { |
|---|
| 101 | 111 | /* |
|---|
| 102 | 112 | * after the pannel is powered up the first time, |
|---|
| 103 | 113 | * we can access the i2c bus so probe for the DAC |
|---|
| 104 | 114 | */ |
|---|
| 105 | 115 | struct i2c_adapter *adap = i2c_get_adapter(0); |
|---|
| 106 | 116 | struct i2c_board_info info = { |
|---|
| 117 | + .dev_name = "tosa-bl", |
|---|
| 107 | 118 | .type = "tosa-bl", |
|---|
| 108 | 119 | .addr = DAC_BASE, |
|---|
| 109 | 120 | .platform_data = data->spi, |
|---|
| 110 | 121 | }; |
|---|
| 111 | | - data->i2c = i2c_new_device(adap, &info); |
|---|
| 122 | + data->i2c = i2c_new_client_device(adap, &info); |
|---|
| 112 | 123 | } |
|---|
| 113 | 124 | } |
|---|
| 114 | 125 | |
|---|
| .. | .. |
|---|
| 125 | 136 | mdelay(50); |
|---|
| 126 | 137 | |
|---|
| 127 | 138 | /* TG Off */ |
|---|
| 128 | | - gpio_set_value(TOSA_GPIO_TG_ON, 1); |
|---|
| 139 | + gpiod_set_value(data->gpiod_tg, 1); |
|---|
| 129 | 140 | mdelay(100); |
|---|
| 130 | 141 | } |
|---|
| 131 | 142 | |
|---|
| .. | .. |
|---|
| 195 | 206 | data->spi = spi; |
|---|
| 196 | 207 | spi_set_drvdata(spi, data); |
|---|
| 197 | 208 | |
|---|
| 198 | | - ret = devm_gpio_request_one(&spi->dev, TOSA_GPIO_TG_ON, |
|---|
| 199 | | - GPIOF_OUT_INIT_LOW, "tg #pwr"); |
|---|
| 200 | | - if (ret < 0) |
|---|
| 201 | | - return ret; |
|---|
| 209 | + data->gpiod_tg = devm_gpiod_get(&spi->dev, "tg #pwr", GPIOD_OUT_LOW); |
|---|
| 210 | + if (IS_ERR(data->gpiod_tg)) |
|---|
| 211 | + return PTR_ERR(data->gpiod_tg); |
|---|
| 202 | 212 | |
|---|
| 203 | 213 | mdelay(60); |
|---|
| 204 | 214 | |
|---|
| .. | .. |
|---|
| 226 | 236 | { |
|---|
| 227 | 237 | struct tosa_lcd_data *data = spi_get_drvdata(spi); |
|---|
| 228 | 238 | |
|---|
| 229 | | - if (data->i2c) |
|---|
| 230 | | - i2c_unregister_device(data->i2c); |
|---|
| 239 | + i2c_unregister_device(data->i2c); |
|---|
| 231 | 240 | |
|---|
| 232 | 241 | tosa_lcd_tg_off(data); |
|---|
| 233 | 242 | |
|---|