@@ -35,6 +35,18 @@ struct cros_feature_to_name {
35
35
const char * desc ;
36
36
};
37
37
38
+ /**
39
+ * cros_feature_to_cells - CrOS feature id to mfd cells association.
40
+ * @id: The feature identifier.
41
+ * @mfd_cells: Pointer to the array of mfd cells that needs to be added.
42
+ * @num_cells: Number of mfd cells into the array.
43
+ */
44
+ struct cros_feature_to_cells {
45
+ unsigned int id ;
46
+ const struct mfd_cell * mfd_cells ;
47
+ unsigned int num_cells ;
48
+ };
49
+
38
50
static const struct cros_feature_to_name cros_mcu_devices [] = {
39
51
{
40
52
.id = EC_FEATURE_FINGERPRINT ,
@@ -58,6 +70,48 @@ static const struct cros_feature_to_name cros_mcu_devices[] = {
58
70
},
59
71
};
60
72
73
+ static const struct mfd_cell cros_ec_cec_cells [] = {
74
+ { .name = "cros-ec-cec" , },
75
+ };
76
+
77
+ static const struct mfd_cell cros_ec_rtc_cells [] = {
78
+ { .name = "cros-ec-rtc" , },
79
+ };
80
+
81
+ static const struct mfd_cell cros_usbpd_charger_cells [] = {
82
+ { .name = "cros-usbpd-charger" , },
83
+ { .name = "cros-usbpd-logger" , },
84
+ };
85
+
86
+ static const struct cros_feature_to_cells cros_subdevices [] = {
87
+ {
88
+ .id = EC_FEATURE_CEC ,
89
+ .mfd_cells = cros_ec_cec_cells ,
90
+ .num_cells = ARRAY_SIZE (cros_ec_cec_cells ),
91
+ },
92
+ {
93
+ .id = EC_FEATURE_RTC ,
94
+ .mfd_cells = cros_ec_rtc_cells ,
95
+ .num_cells = ARRAY_SIZE (cros_ec_rtc_cells ),
96
+ },
97
+ {
98
+ .id = EC_FEATURE_USB_PD ,
99
+ .mfd_cells = cros_usbpd_charger_cells ,
100
+ .num_cells = ARRAY_SIZE (cros_usbpd_charger_cells ),
101
+ },
102
+ };
103
+
104
+ static const struct mfd_cell cros_ec_platform_cells [] = {
105
+ { .name = "cros-ec-chardev" , },
106
+ { .name = "cros-ec-debugfs" , },
107
+ { .name = "cros-ec-lightbar" , },
108
+ { .name = "cros-ec-sysfs" , },
109
+ };
110
+
111
+ static const struct mfd_cell cros_ec_vbc_cells [] = {
112
+ { .name = "cros-ec-vbc" , }
113
+ };
114
+
61
115
static int cros_ec_check_features (struct cros_ec_dev * ec , int feature )
62
116
{
63
117
struct cros_ec_command * msg ;
@@ -283,30 +337,6 @@ static void cros_ec_accel_legacy_register(struct cros_ec_dev *ec)
283
337
dev_err (ec_dev -> dev , "failed to add EC sensors\n" );
284
338
}
285
339
286
- static const struct mfd_cell cros_ec_cec_cells [] = {
287
- { .name = "cros-ec-cec" }
288
- };
289
-
290
- static const struct mfd_cell cros_ec_rtc_cells [] = {
291
- { .name = "cros-ec-rtc" }
292
- };
293
-
294
- static const struct mfd_cell cros_usbpd_charger_cells [] = {
295
- { .name = "cros-usbpd-charger" },
296
- { .name = "cros-usbpd-logger" },
297
- };
298
-
299
- static const struct mfd_cell cros_ec_platform_cells [] = {
300
- { .name = "cros-ec-chardev" },
301
- { .name = "cros-ec-debugfs" },
302
- { .name = "cros-ec-lightbar" },
303
- { .name = "cros-ec-sysfs" },
304
- };
305
-
306
- static const struct mfd_cell cros_ec_vbc_cells [] = {
307
- { .name = "cros-ec-vbc" }
308
- };
309
-
310
340
static int ec_device_probe (struct platform_device * pdev )
311
341
{
312
342
int retval = - ENOMEM ;
@@ -368,42 +398,27 @@ static int ec_device_probe(struct platform_device *pdev)
368
398
/* Workaroud for older EC firmware */
369
399
cros_ec_accel_legacy_register (ec );
370
400
371
- /* Check whether this EC instance has CEC host command support */
372
- if (cros_ec_check_features (ec , EC_FEATURE_CEC )) {
373
- retval = mfd_add_devices (ec -> dev , PLATFORM_DEVID_AUTO ,
374
- cros_ec_cec_cells ,
375
- ARRAY_SIZE (cros_ec_cec_cells ),
376
- NULL , 0 , NULL );
377
- if (retval )
378
- dev_err (ec -> dev ,
379
- "failed to add cros-ec-cec device: %d\n" ,
380
- retval );
381
- }
382
-
383
- /* Check whether this EC instance has RTC host command support */
384
- if (cros_ec_check_features (ec , EC_FEATURE_RTC )) {
385
- retval = mfd_add_devices (ec -> dev , PLATFORM_DEVID_AUTO ,
386
- cros_ec_rtc_cells ,
387
- ARRAY_SIZE (cros_ec_rtc_cells ),
388
- NULL , 0 , NULL );
389
- if (retval )
390
- dev_err (ec -> dev ,
391
- "failed to add cros-ec-rtc device: %d\n" ,
392
- retval );
393
- }
394
-
395
- /* Check whether this EC instance has the PD charge manager */
396
- if (cros_ec_check_features (ec , EC_FEATURE_USB_PD )) {
397
- retval = mfd_add_devices (ec -> dev , PLATFORM_DEVID_AUTO ,
398
- cros_usbpd_charger_cells ,
399
- ARRAY_SIZE (cros_usbpd_charger_cells ),
400
- NULL , 0 , NULL );
401
- if (retval )
402
- dev_err (ec -> dev ,
403
- "failed to add cros-usbpd-charger device: %d\n" ,
404
- retval );
401
+ /*
402
+ * The following subdevices can be detected by sending the
403
+ * EC_FEATURE_GET_CMD Embedded Controller device.
404
+ */
405
+ for (i = 0 ; i < ARRAY_SIZE (cros_subdevices ); i ++ ) {
406
+ if (cros_ec_check_features (ec , cros_subdevices [i ].id )) {
407
+ retval = mfd_add_hotplug_devices (ec -> dev ,
408
+ cros_subdevices [i ].mfd_cells ,
409
+ cros_subdevices [i ].num_cells );
410
+ if (retval )
411
+ dev_err (ec -> dev ,
412
+ "failed to add %s subdevice: %d\n" ,
413
+ cros_subdevices [i ].mfd_cells -> name ,
414
+ retval );
415
+ }
405
416
}
406
417
418
+ /*
419
+ * The following subdevices cannot be detected by sending the
420
+ * EC_FEATURE_GET_CMD to the Embedded Controller device.
421
+ */
407
422
retval = mfd_add_devices (ec -> dev , PLATFORM_DEVID_AUTO ,
408
423
cros_ec_platform_cells ,
409
424
ARRAY_SIZE (cros_ec_platform_cells ),
0 commit comments