19
19
#define PCA995X_MODE1 0x00
20
20
#define PCA995X_MODE2 0x01
21
21
#define PCA995X_LEDOUT0 0x02
22
- #define PCA9955B_PWM0 0x08
23
- #define PCA9952_PWM0 0x0A
24
- #define PCA9952_IREFALL 0x43
25
- #define PCA9955B_IREFALL 0x45
26
22
27
23
/* Auto-increment disabled. Normal mode */
28
24
#define PCA995X_MODE1_CFG 0x00
34
30
#define PCA995X_LDRX_MASK 0x3
35
31
#define PCA995X_LDRX_BITS 2
36
32
37
- #define PCA995X_MAX_OUTPUTS 16
33
+ #define PCA995X_MAX_OUTPUTS 24
38
34
#define PCA995X_OUTPUTS_PER_REG 4
39
35
40
36
#define PCA995X_IREFALL_FULL_CFG 0xFF
41
37
#define PCA995X_IREFALL_HALF_CFG (PCA995X_IREFALL_FULL_CFG / 2)
42
38
43
- #define PCA995X_TYPE_NON_B 0
44
- #define PCA995X_TYPE_B 1
45
-
46
39
#define ldev_to_led (c ) container_of(c, struct pca995x_led, ldev)
47
40
41
+ struct pca995x_chipdef {
42
+ unsigned int num_leds ;
43
+ u8 pwm_base ;
44
+ u8 irefall ;
45
+ };
46
+
47
+ static const struct pca995x_chipdef pca9952_chipdef = {
48
+ .num_leds = 16 ,
49
+ .pwm_base = 0x0a ,
50
+ .irefall = 0x43 ,
51
+ };
52
+
53
+ static const struct pca995x_chipdef pca9955b_chipdef = {
54
+ .num_leds = 16 ,
55
+ .pwm_base = 0x08 ,
56
+ .irefall = 0x45 ,
57
+ };
58
+
59
+ static const struct pca995x_chipdef pca9956b_chipdef = {
60
+ .num_leds = 24 ,
61
+ .pwm_base = 0x0a ,
62
+ .irefall = 0x40 ,
63
+ };
64
+
48
65
struct pca995x_led {
49
66
unsigned int led_no ;
50
67
struct led_classdev ldev ;
@@ -54,18 +71,19 @@ struct pca995x_led {
54
71
struct pca995x_chip {
55
72
struct regmap * regmap ;
56
73
struct pca995x_led leds [PCA995X_MAX_OUTPUTS ];
57
- int btype ;
74
+ const struct pca995x_chipdef * chipdef ;
58
75
};
59
76
60
77
static int pca995x_brightness_set (struct led_classdev * led_cdev ,
61
78
enum led_brightness brightness )
62
79
{
63
80
struct pca995x_led * led = ldev_to_led (led_cdev );
64
81
struct pca995x_chip * chip = led -> chip ;
82
+ const struct pca995x_chipdef * chipdef = chip -> chipdef ;
65
83
u8 ledout_addr , pwmout_addr ;
66
84
int shift , ret ;
67
85
68
- pwmout_addr = ( chip -> btype ? PCA9955B_PWM0 : PCA9952_PWM0 ) + led -> led_no ;
86
+ pwmout_addr = chipdef -> pwm_base + led -> led_no ;
69
87
ledout_addr = PCA995X_LEDOUT0 + (led -> led_no / PCA995X_OUTPUTS_PER_REG );
70
88
shift = PCA995X_LDRX_BITS * (led -> led_no % PCA995X_OUTPUTS_PER_REG );
71
89
@@ -104,11 +122,12 @@ static int pca995x_probe(struct i2c_client *client)
104
122
struct fwnode_handle * led_fwnodes [PCA995X_MAX_OUTPUTS ] = { 0 };
105
123
struct fwnode_handle * np , * child ;
106
124
struct device * dev = & client -> dev ;
125
+ const struct pca995x_chipdef * chipdef ;
107
126
struct pca995x_chip * chip ;
108
127
struct pca995x_led * led ;
109
- int i , btype , reg , ret ;
128
+ int i , reg , ret ;
110
129
111
- btype = ( unsigned long ) device_get_match_data (& client -> dev );
130
+ chipdef = device_get_match_data (& client -> dev );
112
131
113
132
np = dev_fwnode (dev );
114
133
if (!np )
@@ -118,7 +137,7 @@ static int pca995x_probe(struct i2c_client *client)
118
137
if (!chip )
119
138
return - ENOMEM ;
120
139
121
- chip -> btype = btype ;
140
+ chip -> chipdef = chipdef ;
122
141
chip -> regmap = devm_regmap_init_i2c (client , & pca995x_regmap );
123
142
if (IS_ERR (chip -> regmap ))
124
143
return PTR_ERR (chip -> regmap );
@@ -170,21 +189,21 @@ static int pca995x_probe(struct i2c_client *client)
170
189
return ret ;
171
190
172
191
/* IREF Output current value for all LEDn outputs */
173
- return regmap_write (chip -> regmap ,
174
- btype ? PCA9955B_IREFALL : PCA9952_IREFALL ,
175
- PCA995X_IREFALL_HALF_CFG );
192
+ return regmap_write (chip -> regmap , chipdef -> irefall , PCA995X_IREFALL_HALF_CFG );
176
193
}
177
194
178
195
static const struct i2c_device_id pca995x_id [] = {
179
- { "pca9952" , .driver_data = (kernel_ulong_t )PCA995X_TYPE_NON_B },
180
- { "pca9955b" , .driver_data = (kernel_ulong_t )PCA995X_TYPE_B },
196
+ { "pca9952" , .driver_data = (kernel_ulong_t )& pca9952_chipdef },
197
+ { "pca9955b" , .driver_data = (kernel_ulong_t )& pca9955b_chipdef },
198
+ { "pca9956b" , .driver_data = (kernel_ulong_t )& pca9956b_chipdef },
181
199
{}
182
200
};
183
201
MODULE_DEVICE_TABLE (i2c , pca995x_id );
184
202
185
203
static const struct of_device_id pca995x_of_match [] = {
186
- { .compatible = "nxp,pca9952" , .data = (void * )PCA995X_TYPE_NON_B },
187
- { .compatible = "nxp,pca9955b" , .data = (void * )PCA995X_TYPE_B },
204
+ { .compatible = "nxp,pca9952" , .data = & pca9952_chipdef },
205
+ { .compatible = "nxp,pca9955b" , . data = & pca9955b_chipdef },
206
+ { .compatible = "nxp,pca9956b" , .data = & pca9956b_chipdef },
188
207
{},
189
208
};
190
209
MODULE_DEVICE_TABLE (of , pca995x_of_match );
0 commit comments