mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-15 15:04:27 +08:00
5e9ea43c63
These drivers don't use the driver_data member of struct i2c_device_id, so don't explicitly initialize this member. This prepares putting driver_data in an anonymous union which requires either no initialization or named designators. But it's also a nice cleanup on its own. While add it, also remove commas after the sentinel entries. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Link: https://lore.kernel.org/r/20240510211011.2273978-2-u.kleine-koenig@pengutronix.de Signed-off-by: Lee Jones <lee@kernel.org>
156 lines
4.0 KiB
C
156 lines
4.0 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* TI/National Semiconductor LP3943 MFD Core Driver
|
|
*
|
|
* Copyright 2013 Texas Instruments
|
|
*
|
|
* Author: Milo Kim <milo.kim@ti.com>
|
|
*
|
|
* Driver structure:
|
|
* LP3943 is an integrated device capable of driving 16 output channels.
|
|
* It can be used for a GPIO expander and PWM generators.
|
|
*
|
|
* LED control General usage for a device
|
|
* ___________ ____________________________
|
|
*
|
|
* LP3943 MFD ---- GPIO expander leds-gpio eg) HW enable pin
|
|
* |
|
|
* --- PWM generator leds-pwm eg) PWM input
|
|
*
|
|
* Internal two PWM channels are used for LED dimming effect.
|
|
* And each output pin can be used as a GPIO as well.
|
|
* The LED functionality can work with GPIOs or PWMs.
|
|
* LEDs can be controlled with legacy leds-gpio(static brightness) or
|
|
* leds-pwm drivers(dynamic brightness control).
|
|
* Alternatively, it can be used for generic GPIO and PWM controller.
|
|
* For example, a GPIO is HW enable pin of a device.
|
|
* A PWM is input pin of a backlight device.
|
|
*/
|
|
|
|
#include <linux/err.h>
|
|
#include <linux/gpio.h>
|
|
#include <linux/i2c.h>
|
|
#include <linux/mfd/core.h>
|
|
#include <linux/mfd/lp3943.h>
|
|
#include <linux/module.h>
|
|
#include <linux/of.h>
|
|
#include <linux/slab.h>
|
|
|
|
#define LP3943_MAX_REGISTERS 0x09
|
|
|
|
/* Register configuration for pin MUX */
|
|
static const struct lp3943_reg_cfg lp3943_mux_cfg[] = {
|
|
/* address, mask, shift */
|
|
{ LP3943_REG_MUX0, 0x03, 0 },
|
|
{ LP3943_REG_MUX0, 0x0C, 2 },
|
|
{ LP3943_REG_MUX0, 0x30, 4 },
|
|
{ LP3943_REG_MUX0, 0xC0, 6 },
|
|
{ LP3943_REG_MUX1, 0x03, 0 },
|
|
{ LP3943_REG_MUX1, 0x0C, 2 },
|
|
{ LP3943_REG_MUX1, 0x30, 4 },
|
|
{ LP3943_REG_MUX1, 0xC0, 6 },
|
|
{ LP3943_REG_MUX2, 0x03, 0 },
|
|
{ LP3943_REG_MUX2, 0x0C, 2 },
|
|
{ LP3943_REG_MUX2, 0x30, 4 },
|
|
{ LP3943_REG_MUX2, 0xC0, 6 },
|
|
{ LP3943_REG_MUX3, 0x03, 0 },
|
|
{ LP3943_REG_MUX3, 0x0C, 2 },
|
|
{ LP3943_REG_MUX3, 0x30, 4 },
|
|
{ LP3943_REG_MUX3, 0xC0, 6 },
|
|
};
|
|
|
|
static const struct mfd_cell lp3943_devs[] = {
|
|
{
|
|
.name = "lp3943-pwm",
|
|
.of_compatible = "ti,lp3943-pwm",
|
|
},
|
|
{
|
|
.name = "lp3943-gpio",
|
|
.of_compatible = "ti,lp3943-gpio",
|
|
},
|
|
};
|
|
|
|
int lp3943_read_byte(struct lp3943 *lp3943, u8 reg, u8 *read)
|
|
{
|
|
int ret;
|
|
unsigned int val;
|
|
|
|
ret = regmap_read(lp3943->regmap, reg, &val);
|
|
if (ret < 0)
|
|
return ret;
|
|
|
|
*read = (u8)val;
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL_GPL(lp3943_read_byte);
|
|
|
|
int lp3943_write_byte(struct lp3943 *lp3943, u8 reg, u8 data)
|
|
{
|
|
return regmap_write(lp3943->regmap, reg, data);
|
|
}
|
|
EXPORT_SYMBOL_GPL(lp3943_write_byte);
|
|
|
|
int lp3943_update_bits(struct lp3943 *lp3943, u8 reg, u8 mask, u8 data)
|
|
{
|
|
return regmap_update_bits(lp3943->regmap, reg, mask, data);
|
|
}
|
|
EXPORT_SYMBOL_GPL(lp3943_update_bits);
|
|
|
|
static const struct regmap_config lp3943_regmap_config = {
|
|
.reg_bits = 8,
|
|
.val_bits = 8,
|
|
.max_register = LP3943_MAX_REGISTERS,
|
|
};
|
|
|
|
static int lp3943_probe(struct i2c_client *cl)
|
|
{
|
|
struct lp3943 *lp3943;
|
|
struct device *dev = &cl->dev;
|
|
|
|
lp3943 = devm_kzalloc(dev, sizeof(*lp3943), GFP_KERNEL);
|
|
if (!lp3943)
|
|
return -ENOMEM;
|
|
|
|
lp3943->regmap = devm_regmap_init_i2c(cl, &lp3943_regmap_config);
|
|
if (IS_ERR(lp3943->regmap))
|
|
return PTR_ERR(lp3943->regmap);
|
|
|
|
lp3943->pdata = dev_get_platdata(dev);
|
|
lp3943->dev = dev;
|
|
lp3943->mux_cfg = lp3943_mux_cfg;
|
|
i2c_set_clientdata(cl, lp3943);
|
|
|
|
return devm_mfd_add_devices(dev, -1, lp3943_devs,
|
|
ARRAY_SIZE(lp3943_devs),
|
|
NULL, 0, NULL);
|
|
}
|
|
|
|
static const struct i2c_device_id lp3943_ids[] = {
|
|
{ "lp3943" },
|
|
{ }
|
|
};
|
|
MODULE_DEVICE_TABLE(i2c, lp3943_ids);
|
|
|
|
#ifdef CONFIG_OF
|
|
static const struct of_device_id lp3943_of_match[] = {
|
|
{ .compatible = "ti,lp3943", },
|
|
{ }
|
|
};
|
|
MODULE_DEVICE_TABLE(of, lp3943_of_match);
|
|
#endif
|
|
|
|
static struct i2c_driver lp3943_driver = {
|
|
.probe = lp3943_probe,
|
|
.driver = {
|
|
.name = "lp3943",
|
|
.of_match_table = of_match_ptr(lp3943_of_match),
|
|
},
|
|
.id_table = lp3943_ids,
|
|
};
|
|
|
|
module_i2c_driver(lp3943_driver);
|
|
|
|
MODULE_DESCRIPTION("LP3943 MFD Core Driver");
|
|
MODULE_AUTHOR("Milo Kim");
|
|
MODULE_LICENSE("GPL");
|