mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-07-22 03:27:30 -04:00
Merge tag 'backlight-next-7.2' of git://git.kernel.org/pub/scm/linux/kernel/git/lee/backlight
Pull backlight updates from Lee Jones:
"New Support & Features:
- Maxim MAX25014: Add support for the Maxim MAX25014 4-channel
automotive grade backlight driver IC
Improvements & Fixes:
- Maintainers: Add the Congatec Board Controller backlight driver to
its corresponding entry
- Congatec Board Controller: Remove redundant X86 dependency from the
backlight driver
- Kinetic KTD2801: Enable BL_CORE_SUSPENDRESUME to ensure the chip is
powered off during suspend
Cleanups & Refactoring:
- Core: Use named initializers for i2c_device_id arrays to improve
readability and robustness
Device Tree Binding Updates:
- Maxim MAX25014: Add device tree bindings for the Maxim MAX25014
backlight controller"
* tag 'backlight-next-7.2' of git://git.kernel.org/pub/scm/linux/kernel/git/lee/backlight:
backlight: Use named initializers for arrays of i2c_device_data
MAINTAINERS: Add cgbc backlight driver
backlight: cgbc: Remove redundant X86 dependency
backlight: Add max25014atg backlight
dt-bindings: backlight: Add max25014 support
backlight: ktd2801: Enable BL_CORE_SUSPENDRESUME
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
|
||||
%YAML 1.2
|
||||
---
|
||||
$id: http://devicetree.org/schemas/leds/backlight/maxim,max25014.yaml#
|
||||
$schema: http://devicetree.org/meta-schemas/core.yaml#
|
||||
|
||||
title: Maxim max25014 backlight controller
|
||||
|
||||
maintainers:
|
||||
- Maud Spierings <maudspierings@gocontroll.com>
|
||||
|
||||
properties:
|
||||
compatible:
|
||||
enum:
|
||||
- maxim,max25014
|
||||
|
||||
reg:
|
||||
maxItems: 1
|
||||
|
||||
default-brightness:
|
||||
minimum: 0
|
||||
maximum: 100
|
||||
default: 50
|
||||
|
||||
enable-gpios:
|
||||
maxItems: 1
|
||||
|
||||
interrupts:
|
||||
maxItems: 1
|
||||
|
||||
power-supply:
|
||||
description: Regulator which controls the boost converter input rail.
|
||||
|
||||
pwms:
|
||||
maxItems: 1
|
||||
|
||||
maxim,iset:
|
||||
$ref: /schemas/types.yaml#/definitions/uint32
|
||||
maximum: 15
|
||||
default: 11
|
||||
description:
|
||||
Value of the ISET field in the ISET register. This controls the current
|
||||
scale of the outputs, a higher number means more current.
|
||||
|
||||
maxim,strings:
|
||||
$ref: /schemas/types.yaml#/definitions/uint32-array
|
||||
description:
|
||||
A 4-bit bitfield that describes which led strings to turn on.
|
||||
minItems: 4
|
||||
maxItems: 4
|
||||
items:
|
||||
maximum: 1
|
||||
default:
|
||||
[1 1 1 1]
|
||||
|
||||
required:
|
||||
- compatible
|
||||
- reg
|
||||
|
||||
additionalProperties: false
|
||||
|
||||
examples:
|
||||
- |
|
||||
#include <dt-bindings/gpio/gpio.h>
|
||||
#include <dt-bindings/interrupt-controller/irq.h>
|
||||
|
||||
i2c {
|
||||
#address-cells = <1>;
|
||||
#size-cells = <0>;
|
||||
|
||||
backlight@6f {
|
||||
compatible = "maxim,max25014";
|
||||
reg = <0x6f>;
|
||||
default-brightness = <50>;
|
||||
enable-gpios = <&gpio1 4 GPIO_ACTIVE_HIGH>;
|
||||
interrupt-parent = <&gpio1>;
|
||||
interrupts = <2 IRQ_TYPE_EDGE_FALLING>;
|
||||
power-supply = <®_backlight>;
|
||||
pwms = <&pwm1>;
|
||||
maxim,iset = <7>;
|
||||
maxim,strings = <1 1 1 0>;
|
||||
};
|
||||
};
|
||||
@@ -6502,6 +6502,7 @@ F: drivers/gpio/gpio-cgbc.c
|
||||
F: drivers/hwmon/cgbc-hwmon.c
|
||||
F: drivers/i2c/busses/i2c-cgbc.c
|
||||
F: drivers/mfd/cgbc-core.c
|
||||
F: drivers/video/backlight/cgbc_bl.c
|
||||
F: drivers/watchdog/cgbc_wdt.c
|
||||
F: include/linux/mfd/cgbc.h
|
||||
|
||||
@@ -15774,6 +15775,12 @@ F: Documentation/userspace-api/media/drivers/max2175.rst
|
||||
F: drivers/media/i2c/max2175*
|
||||
F: include/uapi/linux/max2175.h
|
||||
|
||||
MAX25014 BACKLIGHT DRIVER
|
||||
M: Maud Spierings <maudspierings@gocontroll.com>
|
||||
S: Maintained
|
||||
F: Documentation/devicetree/bindings/leds/backlight/maxim,max25014.yaml
|
||||
F: drivers/video/backlight/max25014.c
|
||||
|
||||
MAX31335 RTC DRIVER
|
||||
M: Antoniu Miclaus <antoniu.miclaus@analog.com>
|
||||
L: linux-rtc@vger.kernel.org
|
||||
|
||||
@@ -260,7 +260,7 @@ config BACKLIGHT_PWM
|
||||
|
||||
config BACKLIGHT_CGBC
|
||||
tristate "Congatec Board Controller (CGBC) backlight support"
|
||||
depends on MFD_CGBC && X86
|
||||
depends on MFD_CGBC
|
||||
help
|
||||
Say Y here to enable support for LCD backlight control on Congatec
|
||||
x86-based boards via the CGBC (Congatec Board Controller).
|
||||
@@ -282,6 +282,13 @@ config BACKLIGHT_DA9052
|
||||
help
|
||||
Enable the Backlight Driver for DA9052-BC and DA9053-AA/Bx PMICs.
|
||||
|
||||
config BACKLIGHT_MAX25014
|
||||
tristate "Backlight driver for Maxim MAX25014"
|
||||
depends on I2C
|
||||
select REGMAP_I2C
|
||||
help
|
||||
If you are using a MAX25014 chip as a backlight driver say Y to enable it.
|
||||
|
||||
config BACKLIGHT_MAX8925
|
||||
tristate "Backlight driver for MAX8925"
|
||||
depends on MFD_MAX8925
|
||||
|
||||
@@ -47,6 +47,7 @@ obj-$(CONFIG_BACKLIGHT_LOCOMO) += locomolcd.o
|
||||
obj-$(CONFIG_BACKLIGHT_LP855X) += lp855x_bl.o
|
||||
obj-$(CONFIG_BACKLIGHT_LP8788) += lp8788_bl.o
|
||||
obj-$(CONFIG_BACKLIGHT_LV5207LP) += lv5207lp.o
|
||||
obj-$(CONFIG_BACKLIGHT_MAX25014) += max25014.o
|
||||
obj-$(CONFIG_BACKLIGHT_MAX8925) += max8925_bl.o
|
||||
obj-$(CONFIG_BACKLIGHT_MP3309C) += mp3309c.o
|
||||
obj-$(CONFIG_BACKLIGHT_MT6370) += mt6370-backlight.o
|
||||
|
||||
@@ -790,9 +790,9 @@ static SIMPLE_DEV_PM_OPS(adp8860_i2c_pm_ops, adp8860_i2c_suspend,
|
||||
adp8860_i2c_resume);
|
||||
|
||||
static const struct i2c_device_id adp8860_id[] = {
|
||||
{ "adp8860", adp8860 },
|
||||
{ "adp8861", adp8861 },
|
||||
{ "adp8863", adp8863 },
|
||||
{ .name = "adp8860", .driver_data = adp8860 },
|
||||
{ .name = "adp8861", .driver_data = adp8861 },
|
||||
{ .name = "adp8863", .driver_data = adp8863 },
|
||||
{ }
|
||||
};
|
||||
MODULE_DEVICE_TABLE(i2c, adp8860_id);
|
||||
|
||||
@@ -962,7 +962,7 @@ static SIMPLE_DEV_PM_OPS(adp8870_i2c_pm_ops, adp8870_i2c_suspend,
|
||||
adp8870_i2c_resume);
|
||||
|
||||
static const struct i2c_device_id adp8870_id[] = {
|
||||
{ "adp8870" },
|
||||
{ .name = "adp8870" },
|
||||
{ }
|
||||
};
|
||||
MODULE_DEVICE_TABLE(i2c, adp8870_id);
|
||||
|
||||
@@ -382,7 +382,7 @@ static const struct of_device_id arcxcnn_dt_ids[] = {
|
||||
MODULE_DEVICE_TABLE(of, arcxcnn_dt_ids);
|
||||
|
||||
static const struct i2c_device_id arcxcnn_ids[] = {
|
||||
{"arc2c0608", ARC2C0608},
|
||||
{ .name = "arc2c0608", .driver_data = ARC2C0608 },
|
||||
{ }
|
||||
};
|
||||
MODULE_DEVICE_TABLE(i2c, arcxcnn_ids);
|
||||
|
||||
@@ -443,7 +443,7 @@ static int aw99706_resume(struct device *dev)
|
||||
static DEFINE_SIMPLE_DEV_PM_OPS(aw99706_pm_ops, aw99706_suspend, aw99706_resume);
|
||||
|
||||
static const struct i2c_device_id aw99706_ids[] = {
|
||||
{ "aw99706" },
|
||||
{ .name = "aw99706" },
|
||||
{ }
|
||||
};
|
||||
MODULE_DEVICE_TABLE(i2c, aw99706_ids);
|
||||
|
||||
@@ -179,7 +179,7 @@ static void bd6107_remove(struct i2c_client *client)
|
||||
}
|
||||
|
||||
static const struct i2c_device_id bd6107_ids[] = {
|
||||
{ "bd6107" },
|
||||
{ .name = "bd6107" },
|
||||
{ }
|
||||
};
|
||||
MODULE_DEVICE_TABLE(i2c, bd6107_ids);
|
||||
|
||||
@@ -53,6 +53,7 @@ static int ktd2801_update_status(struct backlight_device *bd)
|
||||
}
|
||||
|
||||
static const struct backlight_ops ktd2801_backlight_ops = {
|
||||
.options = BL_CORE_SUSPENDRESUME,
|
||||
.update_status = ktd2801_update_status,
|
||||
};
|
||||
|
||||
|
||||
@@ -179,8 +179,8 @@ static void ktz8866_remove(struct i2c_client *client)
|
||||
}
|
||||
|
||||
static const struct i2c_device_id ktz8866_ids[] = {
|
||||
{ "ktz8866" },
|
||||
{}
|
||||
{ .name = "ktz8866" },
|
||||
{ }
|
||||
};
|
||||
MODULE_DEVICE_TABLE(i2c, ktz8866_ids);
|
||||
|
||||
|
||||
@@ -311,8 +311,8 @@ static void lm3509_remove(struct i2c_client *client)
|
||||
}
|
||||
|
||||
static const struct i2c_device_id lm3509_id[] = {
|
||||
{ LM3509_NAME },
|
||||
{}
|
||||
{ .name = LM3509_NAME },
|
||||
{ }
|
||||
};
|
||||
|
||||
MODULE_DEVICE_TABLE(i2c, lm3509_id);
|
||||
|
||||
@@ -596,8 +596,8 @@ static void lm3630a_remove(struct i2c_client *client)
|
||||
}
|
||||
|
||||
static const struct i2c_device_id lm3630a_id[] = {
|
||||
{ LM3630A_NAME },
|
||||
{}
|
||||
{ .name = LM3630A_NAME },
|
||||
{ }
|
||||
};
|
||||
|
||||
MODULE_DEVICE_TABLE(i2c, lm3630a_id);
|
||||
|
||||
@@ -403,8 +403,8 @@ static void lm3639_remove(struct i2c_client *client)
|
||||
}
|
||||
|
||||
static const struct i2c_device_id lm3639_id[] = {
|
||||
{ LM3639_NAME },
|
||||
{}
|
||||
{ .name = LM3639_NAME },
|
||||
{ }
|
||||
};
|
||||
|
||||
MODULE_DEVICE_TABLE(i2c, lm3639_id);
|
||||
|
||||
@@ -570,13 +570,13 @@ static const struct of_device_id lp855x_dt_ids[] __maybe_unused = {
|
||||
MODULE_DEVICE_TABLE(of, lp855x_dt_ids);
|
||||
|
||||
static const struct i2c_device_id lp855x_ids[] = {
|
||||
{"lp8550", LP8550},
|
||||
{"lp8551", LP8551},
|
||||
{"lp8552", LP8552},
|
||||
{"lp8553", LP8553},
|
||||
{"lp8555", LP8555},
|
||||
{"lp8556", LP8556},
|
||||
{"lp8557", LP8557},
|
||||
{ .name = "lp8550", .driver_data = LP8550 },
|
||||
{ .name = "lp8551", .driver_data = LP8551 },
|
||||
{ .name = "lp8552", .driver_data = LP8552 },
|
||||
{ .name = "lp8553", .driver_data = LP8553 },
|
||||
{ .name = "lp8555", .driver_data = LP8555 },
|
||||
{ .name = "lp8556", .driver_data = LP8556 },
|
||||
{ .name = "lp8557", .driver_data = LP8557 },
|
||||
{ }
|
||||
};
|
||||
MODULE_DEVICE_TABLE(i2c, lp855x_ids);
|
||||
|
||||
@@ -131,7 +131,7 @@ static void lv5207lp_remove(struct i2c_client *client)
|
||||
}
|
||||
|
||||
static const struct i2c_device_id lv5207lp_ids[] = {
|
||||
{ "lv5207lp" },
|
||||
{ .name = "lv5207lp" },
|
||||
{ }
|
||||
};
|
||||
MODULE_DEVICE_TABLE(i2c, lv5207lp_ids);
|
||||
|
||||
377
drivers/video/backlight/max25014.c
Normal file
377
drivers/video/backlight/max25014.c
Normal file
@@ -0,0 +1,377 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
/*
|
||||
* Backlight driver for Maxim MAX25014
|
||||
*
|
||||
* Copyright (C) 2025 GOcontroll B.V.
|
||||
* Author: Maud Spierings <maudspierings@gocontroll.com>
|
||||
*/
|
||||
|
||||
#include <linux/backlight.h>
|
||||
#include <linux/gpio/consumer.h>
|
||||
#include <linux/i2c.h>
|
||||
#include <linux/regmap.h>
|
||||
#include <linux/slab.h>
|
||||
|
||||
#define MAX25014_ISET_DEFAULT_100 11
|
||||
#define MAX_BRIGHTNESS 100
|
||||
#define MIN_BRIGHTNESS 0
|
||||
#define TON_MAX 130720 /* @153Hz */
|
||||
#define TON_STEP 1307 /* @153Hz */
|
||||
#define TON_MIN 0
|
||||
|
||||
#define MAX25014_DEV_ID 0x00
|
||||
#define MAX25014_REV_ID 0x01
|
||||
#define MAX25014_ISET 0x02
|
||||
#define MAX25014_IMODE 0x03
|
||||
#define MAX25014_TON1H 0x04
|
||||
#define MAX25014_TON1L 0x05
|
||||
#define MAX25014_TON2H 0x06
|
||||
#define MAX25014_TON2L 0x07
|
||||
#define MAX25014_TON3H 0x08
|
||||
#define MAX25014_TON3L 0x09
|
||||
#define MAX25014_TON4H 0x0A
|
||||
#define MAX25014_TON4L 0x0B
|
||||
#define MAX25014_TON_1_4_LSB 0x0C
|
||||
#define MAX25014_SETTING 0x12
|
||||
#define MAX25014_DISABLE 0x13
|
||||
#define MAX25014_BSTMON 0x14
|
||||
#define MAX25014_IOUT1 0x15
|
||||
#define MAX25014_IOUT2 0x16
|
||||
#define MAX25014_IOUT3 0x17
|
||||
#define MAX25014_IOUT4 0x18
|
||||
#define MAX25014_OPEN 0x1B
|
||||
#define MAX25014_SHORTGND 0x1C
|
||||
#define MAX25014_SHORTED_LED 0x1D
|
||||
#define MAX25014_MASK 0x1E
|
||||
#define MAX25014_DIAG 0x1F
|
||||
|
||||
#define MAX25014_ISET_ENA BIT(5)
|
||||
#define MAX25014_ISET_PSEN BIT(4)
|
||||
#define MAX25014_IMODE_HDIM BIT(2)
|
||||
#define MAX25014_SETTING_FPWM GENMASK(6, 4)
|
||||
#define MAX25014_DISABLE_DIS_MASK GENMASK(3, 0)
|
||||
#define MAX25014_DIAG_OT BIT(0)
|
||||
#define MAX25014_DIAG_OTW BIT(1)
|
||||
#define MAX25014_DIAG_HW_RST BIT(2)
|
||||
#define MAX25014_DIAG_BSTOV BIT(3)
|
||||
#define MAX25014_DIAG_BSTUV BIT(4)
|
||||
#define MAX25014_DIAG_IREFOOR BIT(5)
|
||||
|
||||
struct max25014 {
|
||||
struct i2c_client *client;
|
||||
struct backlight_device *bl;
|
||||
struct regmap *regmap;
|
||||
struct gpio_desc *enable;
|
||||
uint32_t iset;
|
||||
uint8_t strings_mask;
|
||||
};
|
||||
|
||||
static const struct regmap_config max25014_regmap_config = {
|
||||
.reg_bits = 8,
|
||||
.val_bits = 8,
|
||||
.max_register = MAX25014_DIAG,
|
||||
};
|
||||
|
||||
static int max25014_initial_power_state(struct max25014 *maxim)
|
||||
{
|
||||
uint32_t val;
|
||||
int ret;
|
||||
|
||||
ret = regmap_read(maxim->regmap, MAX25014_ISET, &val);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
return val & MAX25014_ISET_ENA ? BACKLIGHT_POWER_ON : BACKLIGHT_POWER_OFF;
|
||||
}
|
||||
|
||||
static int max25014_check_errors(struct max25014 *maxim)
|
||||
{
|
||||
uint32_t val;
|
||||
uint8_t i;
|
||||
int ret;
|
||||
|
||||
ret = regmap_read(maxim->regmap, MAX25014_OPEN, &val);
|
||||
if (ret)
|
||||
return ret;
|
||||
if (val) {
|
||||
dev_err(&maxim->client->dev, "Open led strings detected on:\n");
|
||||
for (i = 0; i < 4; i++) {
|
||||
if (val & 1 << i)
|
||||
dev_err(&maxim->client->dev, "string %d\n", i + 1);
|
||||
}
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
ret = regmap_read(maxim->regmap, MAX25014_SHORTGND, &val);
|
||||
if (ret)
|
||||
return ret;
|
||||
if (val) {
|
||||
dev_err(&maxim->client->dev, "Short to ground detected on:\n");
|
||||
for (i = 0; i < 4; i++) {
|
||||
if (val & 1 << i)
|
||||
dev_err(&maxim->client->dev, "string %d\n", i + 1);
|
||||
}
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
ret = regmap_read(maxim->regmap, MAX25014_SHORTED_LED, &val);
|
||||
if (ret)
|
||||
return ret;
|
||||
if (val) {
|
||||
dev_err(&maxim->client->dev, "Shorted led detected on:\n");
|
||||
for (i = 0; i < 4; i++) {
|
||||
if (val & 1 << i)
|
||||
dev_err(&maxim->client->dev, "string %d\n", i + 1);
|
||||
}
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
ret = regmap_read(maxim->regmap, MAX25014_DIAG, &val);
|
||||
if (ret)
|
||||
return ret;
|
||||
/*
|
||||
* The HW_RST bit always starts at 1 after power up.
|
||||
* It is reset on first read, does not indicate an error.
|
||||
*/
|
||||
if (val && val != MAX25014_DIAG_HW_RST) {
|
||||
if (val & MAX25014_DIAG_OT)
|
||||
dev_err(&maxim->client->dev,
|
||||
"Overtemperature shutdown\n");
|
||||
if (val & MAX25014_DIAG_OTW)
|
||||
dev_err(&maxim->client->dev,
|
||||
"Chip is getting too hot (>125C)\n");
|
||||
if (val & MAX25014_DIAG_BSTOV)
|
||||
dev_err(&maxim->client->dev,
|
||||
"Boost converter overvoltage\n");
|
||||
if (val & MAX25014_DIAG_BSTUV)
|
||||
dev_err(&maxim->client->dev,
|
||||
"Boost converter undervoltage\n");
|
||||
if (val & MAX25014_DIAG_IREFOOR)
|
||||
dev_err(&maxim->client->dev, "IREF out of range\n");
|
||||
return -EIO;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* 1. disable unused strings
|
||||
* 2. set dim mode
|
||||
* 3. set setting register
|
||||
* 4. enable the backlight
|
||||
*/
|
||||
static int max25014_configure(struct max25014 *maxim, int initial_state)
|
||||
{
|
||||
uint32_t val;
|
||||
int ret;
|
||||
|
||||
ret = regmap_read(maxim->regmap, MAX25014_DISABLE, &val);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
/*
|
||||
* Strings can only be disabled when MAX25014_ISET_ENA == 0, check if
|
||||
* it needs to be changed at all to prevent the backlight flashing when
|
||||
* it is configured correctly by the bootloader
|
||||
*/
|
||||
if (!((val & MAX25014_DISABLE_DIS_MASK) == maxim->strings_mask)) {
|
||||
if (initial_state == BACKLIGHT_POWER_ON) {
|
||||
ret = regmap_write(maxim->regmap, MAX25014_ISET, 0);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
ret = regmap_write(maxim->regmap, MAX25014_DISABLE, maxim->strings_mask);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = regmap_write(maxim->regmap, MAX25014_IMODE, MAX25014_IMODE_HDIM);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = regmap_read(maxim->regmap, MAX25014_SETTING, &val);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = regmap_write(maxim->regmap, MAX25014_SETTING,
|
||||
val & ~MAX25014_SETTING_FPWM);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
return regmap_write(maxim->regmap, MAX25014_ISET,
|
||||
maxim->iset | MAX25014_ISET_ENA |
|
||||
MAX25014_ISET_PSEN);
|
||||
}
|
||||
|
||||
static int max25014_update_status(struct backlight_device *bl_dev)
|
||||
{
|
||||
struct max25014 *maxim = bl_get_data(bl_dev);
|
||||
uint32_t reg;
|
||||
int ret;
|
||||
|
||||
reg = TON_STEP * backlight_get_brightness(bl_dev);
|
||||
|
||||
/*
|
||||
* 18 bit number lowest, 2 bits in first register,
|
||||
* next lowest 8 in the L register, next 8 in the H register
|
||||
* Seemingly setting the strength of only one string controls all of
|
||||
* them, individual settings don't affect the outcome.
|
||||
*/
|
||||
ret = regmap_write(maxim->regmap, MAX25014_TON_1_4_LSB, reg & 0b00000011);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
ret = regmap_write(maxim->regmap, MAX25014_TON1L, (reg >> 2) & 0b11111111);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
return regmap_write(maxim->regmap, MAX25014_TON1H, (reg >> 10) & 0b11111111);
|
||||
}
|
||||
|
||||
static const struct backlight_ops max25014_bl_ops = {
|
||||
.options = BL_CORE_SUSPENDRESUME,
|
||||
.update_status = max25014_update_status,
|
||||
};
|
||||
|
||||
static int max25014_parse_dt(struct max25014 *maxim,
|
||||
uint32_t *initial_brightness)
|
||||
{
|
||||
struct device *dev = &maxim->client->dev;
|
||||
struct device_node *node = dev->of_node;
|
||||
uint32_t strings[4];
|
||||
int res, i;
|
||||
|
||||
res = of_property_count_u32_elems(node, "maxim,strings");
|
||||
if (res == 4) {
|
||||
of_property_read_u32_array(node, "maxim,strings", strings, 4);
|
||||
for (i = 0; i < 4; i++) {
|
||||
if (strings[i] == 0)
|
||||
maxim->strings_mask |= 1 << i;
|
||||
}
|
||||
} else {
|
||||
maxim->strings_mask = 0;
|
||||
}
|
||||
|
||||
*initial_brightness = 50U;
|
||||
of_property_read_u32(node, "default-brightness", initial_brightness);
|
||||
|
||||
maxim->iset = MAX25014_ISET_DEFAULT_100;
|
||||
of_property_read_u32(node, "maxim,iset", &maxim->iset);
|
||||
|
||||
if (maxim->iset > 15)
|
||||
return dev_err_probe(dev, -EINVAL,
|
||||
"Invalid iset, should be a value from 0-15, entered was %d\n",
|
||||
maxim->iset);
|
||||
|
||||
if (*initial_brightness > 100)
|
||||
return dev_err_probe(dev, -EINVAL,
|
||||
"Invalid initial brightness, should be a value from 0-100, entered was %d\n",
|
||||
*initial_brightness);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int max25014_probe(struct i2c_client *cl)
|
||||
{
|
||||
const struct i2c_device_id *id = i2c_client_get_device_id(cl);
|
||||
struct backlight_properties props;
|
||||
uint32_t initial_brightness = 50;
|
||||
struct backlight_device *bl;
|
||||
struct max25014 *maxim;
|
||||
int ret;
|
||||
|
||||
maxim = devm_kzalloc(&cl->dev, sizeof(struct max25014), GFP_KERNEL);
|
||||
if (!maxim)
|
||||
return -ENOMEM;
|
||||
|
||||
maxim->client = cl;
|
||||
|
||||
ret = max25014_parse_dt(maxim, &initial_brightness);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = devm_regulator_get_enable(&maxim->client->dev, "power");
|
||||
if (ret)
|
||||
return dev_err_probe(&maxim->client->dev, ret,
|
||||
"failed to get power-supply");
|
||||
|
||||
maxim->enable = devm_gpiod_get_optional(&maxim->client->dev, "enable",
|
||||
GPIOD_OUT_HIGH);
|
||||
if (IS_ERR(maxim->enable))
|
||||
return dev_err_probe(&maxim->client->dev, PTR_ERR(maxim->enable),
|
||||
"failed to get enable gpio\n");
|
||||
|
||||
/* Datasheet Electrical Characteristics tSTARTUP 2ms */
|
||||
fsleep(2000);
|
||||
|
||||
maxim->regmap = devm_regmap_init_i2c(cl, &max25014_regmap_config);
|
||||
if (IS_ERR(maxim->regmap))
|
||||
return dev_err_probe(&maxim->client->dev, PTR_ERR(maxim->regmap),
|
||||
"failed to initialize the i2c regmap\n");
|
||||
|
||||
i2c_set_clientdata(cl, maxim);
|
||||
|
||||
ret = max25014_check_errors(maxim);
|
||||
if (ret) /* error is already reported in the above function */
|
||||
return ret;
|
||||
|
||||
ret = max25014_initial_power_state(maxim);
|
||||
if (ret < 0)
|
||||
return dev_err_probe(&maxim->client->dev, ret, "Could not get enabled state\n");
|
||||
|
||||
memset(&props, 0, sizeof(struct backlight_properties));
|
||||
props.type = BACKLIGHT_PLATFORM;
|
||||
props.max_brightness = MAX_BRIGHTNESS;
|
||||
props.brightness = initial_brightness;
|
||||
props.scale = BACKLIGHT_SCALE_LINEAR;
|
||||
props.power = ret;
|
||||
|
||||
ret = max25014_configure(maxim, ret);
|
||||
if (ret)
|
||||
return dev_err_probe(&maxim->client->dev, ret, "device config error");
|
||||
|
||||
bl = devm_backlight_device_register(&maxim->client->dev, id->name,
|
||||
&maxim->client->dev, maxim,
|
||||
&max25014_bl_ops, &props);
|
||||
if (IS_ERR(bl))
|
||||
return dev_err_probe(&maxim->client->dev, PTR_ERR(bl),
|
||||
"failed to register backlight\n");
|
||||
|
||||
maxim->bl = bl;
|
||||
|
||||
backlight_update_status(maxim->bl);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void max25014_remove(struct i2c_client *cl)
|
||||
{
|
||||
struct max25014 *maxim = i2c_get_clientdata(cl);
|
||||
|
||||
backlight_device_set_brightness(maxim->bl, 0);
|
||||
gpiod_set_value_cansleep(maxim->enable, 0);
|
||||
}
|
||||
|
||||
static const struct of_device_id max25014_dt_ids[] = {
|
||||
{ .compatible = "maxim,max25014", },
|
||||
{ }
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, max25014_dt_ids);
|
||||
|
||||
static const struct i2c_device_id max25014_ids[] = {
|
||||
{ "max25014" },
|
||||
{ }
|
||||
};
|
||||
MODULE_DEVICE_TABLE(i2c, max25014_ids);
|
||||
|
||||
static struct i2c_driver max25014_driver = {
|
||||
.driver = {
|
||||
.name = KBUILD_MODNAME,
|
||||
.of_match_table = of_match_ptr(max25014_dt_ids),
|
||||
},
|
||||
.probe = max25014_probe,
|
||||
.remove = max25014_remove,
|
||||
.id_table = max25014_ids,
|
||||
};
|
||||
module_i2c_driver(max25014_driver);
|
||||
|
||||
MODULE_DESCRIPTION("Maxim MAX25014 backlight driver");
|
||||
MODULE_AUTHOR("Maud Spierings <maudspierings@gocontroll.com>");
|
||||
MODULE_LICENSE("GPL");
|
||||
@@ -400,7 +400,7 @@ static const struct of_device_id mp3309c_match_table[] = {
|
||||
MODULE_DEVICE_TABLE(of, mp3309c_match_table);
|
||||
|
||||
static const struct i2c_device_id mp3309c_id[] = {
|
||||
{ "mp3309c" },
|
||||
{ .name = "mp3309c" },
|
||||
{ }
|
||||
};
|
||||
MODULE_DEVICE_TABLE(i2c, mp3309c_id);
|
||||
|
||||
Reference in New Issue
Block a user