This source file includes following definitions.
- lp3943_read_byte
- lp3943_write_byte
- lp3943_update_bits
- lp3943_probe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 #include <linux/err.h>
31 #include <linux/gpio.h>
32 #include <linux/i2c.h>
33 #include <linux/mfd/core.h>
34 #include <linux/mfd/lp3943.h>
35 #include <linux/module.h>
36 #include <linux/of.h>
37 #include <linux/slab.h>
38
39 #define LP3943_MAX_REGISTERS 0x09
40
41
42 static const struct lp3943_reg_cfg lp3943_mux_cfg[] = {
43
44 { LP3943_REG_MUX0, 0x03, 0 },
45 { LP3943_REG_MUX0, 0x0C, 2 },
46 { LP3943_REG_MUX0, 0x30, 4 },
47 { LP3943_REG_MUX0, 0xC0, 6 },
48 { LP3943_REG_MUX1, 0x03, 0 },
49 { LP3943_REG_MUX1, 0x0C, 2 },
50 { LP3943_REG_MUX1, 0x30, 4 },
51 { LP3943_REG_MUX1, 0xC0, 6 },
52 { LP3943_REG_MUX2, 0x03, 0 },
53 { LP3943_REG_MUX2, 0x0C, 2 },
54 { LP3943_REG_MUX2, 0x30, 4 },
55 { LP3943_REG_MUX2, 0xC0, 6 },
56 { LP3943_REG_MUX3, 0x03, 0 },
57 { LP3943_REG_MUX3, 0x0C, 2 },
58 { LP3943_REG_MUX3, 0x30, 4 },
59 { LP3943_REG_MUX3, 0xC0, 6 },
60 };
61
62 static const struct mfd_cell lp3943_devs[] = {
63 {
64 .name = "lp3943-pwm",
65 .of_compatible = "ti,lp3943-pwm",
66 },
67 {
68 .name = "lp3943-gpio",
69 .of_compatible = "ti,lp3943-gpio",
70 },
71 };
72
73 int lp3943_read_byte(struct lp3943 *lp3943, u8 reg, u8 *read)
74 {
75 int ret;
76 unsigned int val;
77
78 ret = regmap_read(lp3943->regmap, reg, &val);
79 if (ret < 0)
80 return ret;
81
82 *read = (u8)val;
83 return 0;
84 }
85 EXPORT_SYMBOL_GPL(lp3943_read_byte);
86
87 int lp3943_write_byte(struct lp3943 *lp3943, u8 reg, u8 data)
88 {
89 return regmap_write(lp3943->regmap, reg, data);
90 }
91 EXPORT_SYMBOL_GPL(lp3943_write_byte);
92
93 int lp3943_update_bits(struct lp3943 *lp3943, u8 reg, u8 mask, u8 data)
94 {
95 return regmap_update_bits(lp3943->regmap, reg, mask, data);
96 }
97 EXPORT_SYMBOL_GPL(lp3943_update_bits);
98
99 static const struct regmap_config lp3943_regmap_config = {
100 .reg_bits = 8,
101 .val_bits = 8,
102 .max_register = LP3943_MAX_REGISTERS,
103 };
104
105 static int lp3943_probe(struct i2c_client *cl, const struct i2c_device_id *id)
106 {
107 struct lp3943 *lp3943;
108 struct device *dev = &cl->dev;
109
110 lp3943 = devm_kzalloc(dev, sizeof(*lp3943), GFP_KERNEL);
111 if (!lp3943)
112 return -ENOMEM;
113
114 lp3943->regmap = devm_regmap_init_i2c(cl, &lp3943_regmap_config);
115 if (IS_ERR(lp3943->regmap))
116 return PTR_ERR(lp3943->regmap);
117
118 lp3943->pdata = dev_get_platdata(dev);
119 lp3943->dev = dev;
120 lp3943->mux_cfg = lp3943_mux_cfg;
121 i2c_set_clientdata(cl, lp3943);
122
123 return devm_mfd_add_devices(dev, -1, lp3943_devs,
124 ARRAY_SIZE(lp3943_devs),
125 NULL, 0, NULL);
126 }
127
128 static const struct i2c_device_id lp3943_ids[] = {
129 { "lp3943", 0 },
130 { }
131 };
132 MODULE_DEVICE_TABLE(i2c, lp3943_ids);
133
134 #ifdef CONFIG_OF
135 static const struct of_device_id lp3943_of_match[] = {
136 { .compatible = "ti,lp3943", },
137 { }
138 };
139 MODULE_DEVICE_TABLE(of, lp3943_of_match);
140 #endif
141
142 static struct i2c_driver lp3943_driver = {
143 .probe = lp3943_probe,
144 .driver = {
145 .name = "lp3943",
146 .of_match_table = of_match_ptr(lp3943_of_match),
147 },
148 .id_table = lp3943_ids,
149 };
150
151 module_i2c_driver(lp3943_driver);
152
153 MODULE_DESCRIPTION("LP3943 MFD Core Driver");
154 MODULE_AUTHOR("Milo Kim");
155 MODULE_LICENSE("GPL");