@@ -78,6 +78,10 @@ static const struct mfd_cell cros_ec_rtc_cells[] = {
78
78
{ .name = "cros-ec-rtc" , },
79
79
};
80
80
81
+ static const struct mfd_cell cros_ec_sensorhub_cells [] = {
82
+ { .name = "cros-ec-sensorhub" , },
83
+ };
84
+
81
85
static const struct mfd_cell cros_usbpd_charger_cells [] = {
82
86
{ .name = "cros-usbpd-charger" , },
83
87
{ .name = "cros-usbpd-logger" , },
@@ -117,192 +121,6 @@ static void cros_ec_class_release(struct device *dev)
117
121
kfree (to_cros_ec_dev (dev ));
118
122
}
119
123
120
- static void cros_ec_sensors_register (struct cros_ec_dev * ec )
121
- {
122
- /*
123
- * Issue a command to get the number of sensor reported.
124
- * Build an array of sensors driver and register them all.
125
- */
126
- int ret , i , id , sensor_num ;
127
- struct mfd_cell * sensor_cells ;
128
- struct cros_ec_sensor_platform * sensor_platforms ;
129
- int sensor_type [MOTIONSENSE_TYPE_MAX ];
130
- struct ec_params_motion_sense * params ;
131
- struct ec_response_motion_sense * resp ;
132
- struct cros_ec_command * msg ;
133
-
134
- msg = kzalloc (sizeof (struct cros_ec_command ) +
135
- max (sizeof (* params ), sizeof (* resp )), GFP_KERNEL );
136
- if (msg == NULL )
137
- return ;
138
-
139
- msg -> version = 2 ;
140
- msg -> command = EC_CMD_MOTION_SENSE_CMD + ec -> cmd_offset ;
141
- msg -> outsize = sizeof (* params );
142
- msg -> insize = sizeof (* resp );
143
-
144
- params = (struct ec_params_motion_sense * )msg -> data ;
145
- params -> cmd = MOTIONSENSE_CMD_DUMP ;
146
-
147
- ret = cros_ec_cmd_xfer_status (ec -> ec_dev , msg );
148
- if (ret < 0 ) {
149
- dev_warn (ec -> dev , "cannot get EC sensor information: %d/%d\n" ,
150
- ret , msg -> result );
151
- goto error ;
152
- }
153
-
154
- resp = (struct ec_response_motion_sense * )msg -> data ;
155
- sensor_num = resp -> dump .sensor_count ;
156
- /*
157
- * Allocate 2 extra sensors if lid angle sensor and/or FIFO are needed.
158
- */
159
- sensor_cells = kcalloc (sensor_num + 2 , sizeof (struct mfd_cell ),
160
- GFP_KERNEL );
161
- if (sensor_cells == NULL )
162
- goto error ;
163
-
164
- sensor_platforms = kcalloc (sensor_num ,
165
- sizeof (struct cros_ec_sensor_platform ),
166
- GFP_KERNEL );
167
- if (sensor_platforms == NULL )
168
- goto error_platforms ;
169
-
170
- memset (sensor_type , 0 , sizeof (sensor_type ));
171
- id = 0 ;
172
- for (i = 0 ; i < sensor_num ; i ++ ) {
173
- params -> cmd = MOTIONSENSE_CMD_INFO ;
174
- params -> info .sensor_num = i ;
175
- ret = cros_ec_cmd_xfer_status (ec -> ec_dev , msg );
176
- if (ret < 0 ) {
177
- dev_warn (ec -> dev , "no info for EC sensor %d : %d/%d\n" ,
178
- i , ret , msg -> result );
179
- continue ;
180
- }
181
- switch (resp -> info .type ) {
182
- case MOTIONSENSE_TYPE_ACCEL :
183
- sensor_cells [id ].name = "cros-ec-accel" ;
184
- break ;
185
- case MOTIONSENSE_TYPE_BARO :
186
- sensor_cells [id ].name = "cros-ec-baro" ;
187
- break ;
188
- case MOTIONSENSE_TYPE_GYRO :
189
- sensor_cells [id ].name = "cros-ec-gyro" ;
190
- break ;
191
- case MOTIONSENSE_TYPE_MAG :
192
- sensor_cells [id ].name = "cros-ec-mag" ;
193
- break ;
194
- case MOTIONSENSE_TYPE_PROX :
195
- sensor_cells [id ].name = "cros-ec-prox" ;
196
- break ;
197
- case MOTIONSENSE_TYPE_LIGHT :
198
- sensor_cells [id ].name = "cros-ec-light" ;
199
- break ;
200
- case MOTIONSENSE_TYPE_ACTIVITY :
201
- sensor_cells [id ].name = "cros-ec-activity" ;
202
- break ;
203
- default :
204
- dev_warn (ec -> dev , "unknown type %d\n" , resp -> info .type );
205
- continue ;
206
- }
207
- sensor_platforms [id ].sensor_num = i ;
208
- sensor_cells [id ].id = sensor_type [resp -> info .type ];
209
- sensor_cells [id ].platform_data = & sensor_platforms [id ];
210
- sensor_cells [id ].pdata_size =
211
- sizeof (struct cros_ec_sensor_platform );
212
-
213
- sensor_type [resp -> info .type ]++ ;
214
- id ++ ;
215
- }
216
-
217
- if (sensor_type [MOTIONSENSE_TYPE_ACCEL ] >= 2 )
218
- ec -> has_kb_wake_angle = true;
219
-
220
- if (cros_ec_check_features (ec , EC_FEATURE_MOTION_SENSE_FIFO )) {
221
- sensor_cells [id ].name = "cros-ec-ring" ;
222
- id ++ ;
223
- }
224
- if (cros_ec_check_features (ec ,
225
- EC_FEATURE_REFINED_TABLET_MODE_HYSTERESIS )) {
226
- sensor_cells [id ].name = "cros-ec-lid-angle" ;
227
- id ++ ;
228
- }
229
-
230
- ret = mfd_add_devices (ec -> dev , 0 , sensor_cells , id ,
231
- NULL , 0 , NULL );
232
- if (ret )
233
- dev_err (ec -> dev , "failed to add EC sensors\n" );
234
-
235
- kfree (sensor_platforms );
236
- error_platforms :
237
- kfree (sensor_cells );
238
- error :
239
- kfree (msg );
240
- }
241
-
242
- static struct cros_ec_sensor_platform sensor_platforms [] = {
243
- { .sensor_num = 0 },
244
- { .sensor_num = 1 }
245
- };
246
-
247
- static const struct mfd_cell cros_ec_accel_legacy_cells [] = {
248
- {
249
- .name = "cros-ec-accel-legacy" ,
250
- .platform_data = & sensor_platforms [0 ],
251
- .pdata_size = sizeof (struct cros_ec_sensor_platform ),
252
- },
253
- {
254
- .name = "cros-ec-accel-legacy" ,
255
- .platform_data = & sensor_platforms [1 ],
256
- .pdata_size = sizeof (struct cros_ec_sensor_platform ),
257
- }
258
- };
259
-
260
- static void cros_ec_accel_legacy_register (struct cros_ec_dev * ec )
261
- {
262
- struct cros_ec_device * ec_dev = ec -> ec_dev ;
263
- u8 status ;
264
- int ret ;
265
-
266
- /*
267
- * ECs that need legacy support are the main EC, directly connected to
268
- * the AP.
269
- */
270
- if (ec -> cmd_offset != 0 )
271
- return ;
272
-
273
- /*
274
- * Check if EC supports direct memory reads and if EC has
275
- * accelerometers.
276
- */
277
- if (ec_dev -> cmd_readmem ) {
278
- ret = ec_dev -> cmd_readmem (ec_dev , EC_MEMMAP_ACC_STATUS , 1 ,
279
- & status );
280
- if (ret < 0 ) {
281
- dev_warn (ec -> dev , "EC direct read error.\n" );
282
- return ;
283
- }
284
-
285
- /* Check if EC has accelerometers. */
286
- if (!(status & EC_MEMMAP_ACC_STATUS_PRESENCE_BIT )) {
287
- dev_info (ec -> dev , "EC does not have accelerometers.\n" );
288
- return ;
289
- }
290
- }
291
-
292
- /*
293
- * The device may still support accelerometers:
294
- * it would be an older ARM based device that do not suppor the
295
- * EC_CMD_GET_FEATURES command.
296
- *
297
- * Register 2 accelerometers, we will fail in the IIO driver if there
298
- * are no sensors.
299
- */
300
- ret = mfd_add_hotplug_devices (ec -> dev , cros_ec_accel_legacy_cells ,
301
- ARRAY_SIZE (cros_ec_accel_legacy_cells ));
302
- if (ret )
303
- dev_err (ec_dev -> dev , "failed to add EC sensors\n" );
304
- }
305
-
306
124
static int ec_device_probe (struct platform_device * pdev )
307
125
{
308
126
int retval = - ENOMEM ;
@@ -358,11 +176,14 @@ static int ec_device_probe(struct platform_device *pdev)
358
176
goto failed ;
359
177
360
178
/* check whether this EC is a sensor hub. */
361
- if (cros_ec_check_features (ec , EC_FEATURE_MOTION_SENSE ))
362
- cros_ec_sensors_register (ec );
363
- else
364
- /* Workaroud for older EC firmware */
365
- cros_ec_accel_legacy_register (ec );
179
+ if (cros_ec_get_sensor_count (ec ) > 0 ) {
180
+ retval = mfd_add_hotplug_devices (ec -> dev ,
181
+ cros_ec_sensorhub_cells ,
182
+ ARRAY_SIZE (cros_ec_sensorhub_cells ));
183
+ if (retval )
184
+ dev_err (ec -> dev , "failed to add %s subdevice: %d\n" ,
185
+ cros_ec_sensorhub_cells -> name , retval );
186
+ }
366
187
367
188
/*
368
189
* The following subdevices can be detected by sending the
0 commit comments