35
35
#include <linux/idr.h>
36
36
#include <linux/i2c.h>
37
37
#include <linux/slab.h>
38
+ #include <linux/acpi.h>
38
39
39
40
#include <linux/power/bq2415x_charger.h>
40
41
@@ -1530,13 +1531,14 @@ static int bq2415x_probe(struct i2c_client *client,
1530
1531
{
1531
1532
int ret ;
1532
1533
int num ;
1533
- char * name ;
1534
+ char * name = NULL ;
1534
1535
struct bq2415x_device * bq ;
1535
1536
struct device_node * np = client -> dev .of_node ;
1536
1537
struct bq2415x_platform_data * pdata = client -> dev .platform_data ;
1538
+ const struct acpi_device_id * acpi_id = NULL ;
1537
1539
1538
- if (!np && !pdata ) {
1539
- dev_err (& client -> dev , "platform data missing \n" );
1540
+ if (!np && !pdata && ! ACPI_HANDLE ( & client -> dev ) ) {
1541
+ dev_err (& client -> dev , "Neither devicetree, nor platform data, nor ACPI support \n" );
1540
1542
return - ENODEV ;
1541
1543
}
1542
1544
@@ -1547,7 +1549,14 @@ static int bq2415x_probe(struct i2c_client *client,
1547
1549
if (num < 0 )
1548
1550
return num ;
1549
1551
1550
- name = kasprintf (GFP_KERNEL , "%s-%d" , id -> name , num );
1552
+ if (id ) {
1553
+ name = kasprintf (GFP_KERNEL , "%s-%d" , id -> name , num );
1554
+ } else if (ACPI_HANDLE (& client -> dev )) {
1555
+ acpi_id =
1556
+ acpi_match_device (client -> dev .driver -> acpi_match_table ,
1557
+ & client -> dev );
1558
+ name = kasprintf (GFP_KERNEL , "%s-%d" , acpi_id -> id , num );
1559
+ }
1551
1560
if (!name ) {
1552
1561
dev_err (& client -> dev , "failed to allocate device name\n" );
1553
1562
ret = - ENOMEM ;
@@ -1573,7 +1582,7 @@ static int bq2415x_probe(struct i2c_client *client,
1573
1582
ret = - EPROBE_DEFER ;
1574
1583
goto error_2 ;
1575
1584
}
1576
- } else if (pdata -> notify_device ) {
1585
+ } else if (pdata && pdata -> notify_device ) {
1577
1586
bq -> notify_psy = power_supply_get_by_name (pdata -> notify_device );
1578
1587
} else {
1579
1588
bq -> notify_psy = NULL ;
@@ -1583,36 +1592,45 @@ static int bq2415x_probe(struct i2c_client *client,
1583
1592
1584
1593
bq -> id = num ;
1585
1594
bq -> dev = & client -> dev ;
1586
- bq -> chip = id -> driver_data ;
1595
+ if (id )
1596
+ bq -> chip = id -> driver_data ;
1597
+ else if (ACPI_HANDLE (bq -> dev ))
1598
+ bq -> chip = acpi_id -> driver_data ;
1587
1599
bq -> name = name ;
1588
1600
bq -> mode = BQ2415X_MODE_OFF ;
1589
1601
bq -> reported_mode = BQ2415X_MODE_OFF ;
1590
1602
bq -> autotimer = 0 ;
1591
1603
bq -> automode = 0 ;
1592
1604
1593
- if (np ) {
1594
- ret = of_property_read_u32 (np , "ti,current-limit" ,
1595
- & bq -> init_data .current_limit );
1605
+ if (np || ACPI_HANDLE (bq -> dev )) {
1606
+ ret = device_property_read_u32 (bq -> dev ,
1607
+ "ti,current-limit" ,
1608
+ & bq -> init_data .current_limit );
1596
1609
if (ret )
1597
1610
goto error_3 ;
1598
- ret = of_property_read_u32 (np , "ti,weak-battery-voltage" ,
1599
- & bq -> init_data .weak_battery_voltage );
1611
+ ret = device_property_read_u32 (bq -> dev ,
1612
+ "ti,weak-battery-voltage" ,
1613
+ & bq -> init_data .weak_battery_voltage );
1600
1614
if (ret )
1601
1615
goto error_3 ;
1602
- ret = of_property_read_u32 (np , "ti,battery-regulation-voltage" ,
1616
+ ret = device_property_read_u32 (bq -> dev ,
1617
+ "ti,battery-regulation-voltage" ,
1603
1618
& bq -> init_data .battery_regulation_voltage );
1604
1619
if (ret )
1605
1620
goto error_3 ;
1606
- ret = of_property_read_u32 (np , "ti,charge-current" ,
1607
- & bq -> init_data .charge_current );
1621
+ ret = device_property_read_u32 (bq -> dev ,
1622
+ "ti,charge-current" ,
1623
+ & bq -> init_data .charge_current );
1608
1624
if (ret )
1609
1625
goto error_3 ;
1610
- ret = of_property_read_u32 (np , "ti,termination-current" ,
1611
- & bq -> init_data .termination_current );
1626
+ ret = device_property_read_u32 (bq -> dev ,
1627
+ "ti,termination-current" ,
1628
+ & bq -> init_data .termination_current );
1612
1629
if (ret )
1613
1630
goto error_3 ;
1614
- ret = of_property_read_u32 (np , "ti,resistor-sense" ,
1615
- & bq -> init_data .resistor_sense );
1631
+ ret = device_property_read_u32 (bq -> dev ,
1632
+ "ti,resistor-sense" ,
1633
+ & bq -> init_data .resistor_sense );
1616
1634
if (ret )
1617
1635
goto error_3 ;
1618
1636
} else {
@@ -1728,9 +1746,28 @@ static const struct i2c_device_id bq2415x_i2c_id_table[] = {
1728
1746
};
1729
1747
MODULE_DEVICE_TABLE (i2c , bq2415x_i2c_id_table );
1730
1748
1749
+ static const struct acpi_device_id bq2415x_i2c_acpi_match [] = {
1750
+ { "BQ2415X" , BQUNKNOWN },
1751
+ { "BQ241500" , BQ24150 },
1752
+ { "BQA24150" , BQ24150A },
1753
+ { "BQ241510" , BQ24151 },
1754
+ { "BQA24151" , BQ24151A },
1755
+ { "BQ241520" , BQ24152 },
1756
+ { "BQ241530" , BQ24153 },
1757
+ { "BQA24153" , BQ24153A },
1758
+ { "BQ241550" , BQ24155 },
1759
+ { "BQ241560" , BQ24156 },
1760
+ { "BQA24156" , BQ24156A },
1761
+ { "BQS24157" , BQ24157S },
1762
+ { "BQ241580" , BQ24158 },
1763
+ {},
1764
+ };
1765
+ MODULE_DEVICE_TABLE (acpi , bq2415x_i2c_acpi_match );
1766
+
1731
1767
static struct i2c_driver bq2415x_driver = {
1732
1768
.driver = {
1733
1769
.name = "bq2415x-charger" ,
1770
+ .acpi_match_table = ACPI_PTR (bq2415x_i2c_acpi_match ),
1734
1771
},
1735
1772
.probe = bq2415x_probe ,
1736
1773
.remove = bq2415x_remove ,
0 commit comments