16
16
* GNU General Public License for more details.
17
17
*/
18
18
19
+ #include <linux/acpi.h>
19
20
#include <linux/completion.h>
20
21
#include <linux/delay.h>
21
22
#include <linux/i2c.h>
25
26
#include <linux/mfd/intel_soc_pmic.h>
26
27
#include <linux/module.h>
27
28
#include <linux/platform_device.h>
29
+ #include <linux/power/bq24190_charger.h>
28
30
#include <linux/slab.h>
29
31
30
32
#define CHT_WC_I2C_CTRL 0x5e24
@@ -232,21 +234,45 @@ static const struct irq_chip cht_wc_i2c_irq_chip = {
232
234
.name = "cht_wc_ext_chrg_irq_chip" ,
233
235
};
234
236
237
+ static const char * const bq24190_suppliers [] = { "fusb302-typec-source" };
238
+
235
239
static const struct property_entry bq24190_props [] = {
236
- PROPERTY_ENTRY_STRING ( "extcon-name " , "cht_wcove_pwrsrc" ),
240
+ PROPERTY_ENTRY_STRING_ARRAY ( "supplied-from " , bq24190_suppliers ),
237
241
PROPERTY_ENTRY_BOOL ("omit-battery-class" ),
238
242
PROPERTY_ENTRY_BOOL ("disable-reset" ),
239
243
{ }
240
244
};
241
245
246
+ static struct regulator_consumer_supply fusb302_consumer = {
247
+ .supply = "vbus" ,
248
+ /* Must match fusb302 dev_name in intel_cht_int33fe.c */
249
+ .dev_name = "i2c-fusb302" ,
250
+ };
251
+
252
+ static const struct regulator_init_data bq24190_vbus_init_data = {
253
+ .constraints = {
254
+ /* The name is used in intel_cht_int33fe.c do not change. */
255
+ .name = "cht_wc_usb_typec_vbus" ,
256
+ .valid_ops_mask = REGULATOR_CHANGE_STATUS ,
257
+ },
258
+ .consumer_supplies = & fusb302_consumer ,
259
+ .num_consumer_supplies = 1 ,
260
+ };
261
+
262
+ static struct bq24190_platform_data bq24190_pdata = {
263
+ .regulator_init_data = & bq24190_vbus_init_data ,
264
+ };
265
+
242
266
static int cht_wc_i2c_adap_i2c_probe (struct platform_device * pdev )
243
267
{
244
268
struct intel_soc_pmic * pmic = dev_get_drvdata (pdev -> dev .parent );
245
269
struct cht_wc_i2c_adap * adap ;
246
270
struct i2c_board_info board_info = {
247
271
.type = "bq24190" ,
248
272
.addr = 0x6b ,
273
+ .dev_name = "bq24190" ,
249
274
.properties = bq24190_props ,
275
+ .platform_data = & bq24190_pdata ,
250
276
};
251
277
int ret , reg , irq ;
252
278
@@ -314,11 +340,21 @@ static int cht_wc_i2c_adap_i2c_probe(struct platform_device *pdev)
314
340
if (ret )
315
341
goto remove_irq_domain ;
316
342
317
- board_info .irq = adap -> client_irq ;
318
- adap -> client = i2c_new_device (& adap -> adapter , & board_info );
319
- if (!adap -> client ) {
320
- ret = - ENOMEM ;
321
- goto del_adapter ;
343
+ /*
344
+ * Normally the Whiskey Cove PMIC is paired with a TI bq24292i charger,
345
+ * connected to this i2c bus, and a max17047 fuel-gauge and a fusb302
346
+ * USB Type-C controller connected to another i2c bus. In this setup
347
+ * the max17047 and fusb302 devices are enumerated through an INT33FE
348
+ * ACPI device. If this device is present register an i2c-client for
349
+ * the TI bq24292i charger.
350
+ */
351
+ if (acpi_dev_present ("INT33FE" , NULL , -1 )) {
352
+ board_info .irq = adap -> client_irq ;
353
+ adap -> client = i2c_new_device (& adap -> adapter , & board_info );
354
+ if (!adap -> client ) {
355
+ ret = - ENOMEM ;
356
+ goto del_adapter ;
357
+ }
322
358
}
323
359
324
360
platform_set_drvdata (pdev , adap );
@@ -335,7 +371,8 @@ static int cht_wc_i2c_adap_i2c_remove(struct platform_device *pdev)
335
371
{
336
372
struct cht_wc_i2c_adap * adap = platform_get_drvdata (pdev );
337
373
338
- i2c_unregister_device (adap -> client );
374
+ if (adap -> client )
375
+ i2c_unregister_device (adap -> client );
339
376
i2c_del_adapter (& adap -> adapter );
340
377
irq_domain_remove (adap -> irq_domain );
341
378
0 commit comments