2 * TI/National Semiconductor LP3943 MFD Core Driver
4 * Copyright 2013 Texas Instruments
6 * Author: Milo Kim <milo.kim@ti.com>
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.
13 * LP3943 is an integrated device capable of driving 16 output channels.
14 * It can be used for a GPIO expander and PWM generators.
16 * LED control General usage for a device
17 * ___________ ____________________________
19 * LP3943 MFD ---- GPIO expander leds-gpio eg) HW enable pin
21 * --- PWM generator leds-pwm eg) PWM input
23 * Internal two PWM channels are used for LED dimming effect.
24 * And each output pin can be used as a GPIO as well.
25 * The LED functionality can work with GPIOs or PWMs.
26 * LEDs can be controlled with legacy leds-gpio(static brightness) or
27 * leds-pwm drivers(dynamic brightness control).
28 * Alternatively, it can be used for generic GPIO and PWM controller.
29 * For example, a GPIO is HW enable pin of a device.
30 * A PWM is input pin of a backlight device.
33 #include <linux/err.h>
34 #include <linux/gpio.h>
35 #include <linux/i2c.h>
36 #include <linux/mfd/core.h>
37 #include <linux/mfd/lp3943.h>
38 #include <linux/module.h>
40 #include <linux/slab.h>
42 #define LP3943_MAX_REGISTERS 0x09
44 /* Register configuration for pin MUX */
45 static const struct lp3943_reg_cfg lp3943_mux_cfg[] = {
46 /* address, mask, shift */
47 { LP3943_REG_MUX0, 0x03, 0 },
48 { LP3943_REG_MUX0, 0x0C, 2 },
49 { LP3943_REG_MUX0, 0x30, 4 },
50 { LP3943_REG_MUX0, 0xC0, 6 },
51 { LP3943_REG_MUX1, 0x03, 0 },
52 { LP3943_REG_MUX1, 0x0C, 2 },
53 { LP3943_REG_MUX1, 0x30, 4 },
54 { LP3943_REG_MUX1, 0xC0, 6 },
55 { LP3943_REG_MUX2, 0x03, 0 },
56 { LP3943_REG_MUX2, 0x0C, 2 },
57 { LP3943_REG_MUX2, 0x30, 4 },
58 { LP3943_REG_MUX2, 0xC0, 6 },
59 { LP3943_REG_MUX3, 0x03, 0 },
60 { LP3943_REG_MUX3, 0x0C, 2 },
61 { LP3943_REG_MUX3, 0x30, 4 },
62 { LP3943_REG_MUX3, 0xC0, 6 },
65 static const struct mfd_cell lp3943_devs[] = {
68 .of_compatible = "ti,lp3943-pwm",
71 .name = "lp3943-gpio",
72 .of_compatible = "ti,lp3943-gpio",
76 int lp3943_read_byte(struct lp3943 *lp3943, u8 reg, u8 *read)
81 ret = regmap_read(lp3943->regmap, reg, &val);
88 EXPORT_SYMBOL_GPL(lp3943_read_byte);
90 int lp3943_write_byte(struct lp3943 *lp3943, u8 reg, u8 data)
92 return regmap_write(lp3943->regmap, reg, data);
94 EXPORT_SYMBOL_GPL(lp3943_write_byte);
96 int lp3943_update_bits(struct lp3943 *lp3943, u8 reg, u8 mask, u8 data)
98 return regmap_update_bits(lp3943->regmap, reg, mask, data);
100 EXPORT_SYMBOL_GPL(lp3943_update_bits);
102 static const struct regmap_config lp3943_regmap_config = {
105 .max_register = LP3943_MAX_REGISTERS,
108 static int lp3943_probe(struct i2c_client *cl, const struct i2c_device_id *id)
110 struct lp3943 *lp3943;
111 struct device *dev = &cl->dev;
113 lp3943 = devm_kzalloc(dev, sizeof(*lp3943), GFP_KERNEL);
117 lp3943->regmap = devm_regmap_init_i2c(cl, &lp3943_regmap_config);
118 if (IS_ERR(lp3943->regmap))
119 return PTR_ERR(lp3943->regmap);
121 lp3943->pdata = dev_get_platdata(dev);
123 lp3943->mux_cfg = lp3943_mux_cfg;
124 i2c_set_clientdata(cl, lp3943);
126 return mfd_add_devices(dev, -1, lp3943_devs, ARRAY_SIZE(lp3943_devs),
130 static int lp3943_remove(struct i2c_client *cl)
132 struct lp3943 *lp3943 = i2c_get_clientdata(cl);
134 mfd_remove_devices(lp3943->dev);
138 static const struct i2c_device_id lp3943_ids[] = {
142 MODULE_DEVICE_TABLE(i2c, lp3943_ids);
145 static const struct of_device_id lp3943_of_match[] = {
146 { .compatible = "ti,lp3943", },
149 MODULE_DEVICE_TABLE(of, lp3943_of_match);
152 static struct i2c_driver lp3943_driver = {
153 .probe = lp3943_probe,
154 .remove = lp3943_remove,
157 .owner = THIS_MODULE,
158 .of_match_table = of_match_ptr(lp3943_of_match),
160 .id_table = lp3943_ids,
163 module_i2c_driver(lp3943_driver);
165 MODULE_DESCRIPTION("LP3943 MFD Core Driver");
166 MODULE_AUTHOR("Milo Kim");
167 MODULE_LICENSE("GPL");