5
5
*/
6
6
7
7
#include <linux/err.h>
8
+ #include <linux/gpio/consumer.h>
8
9
#include <linux/i2c.h>
9
10
#include <linux/interrupt.h>
10
11
#include <linux/kernel.h>
@@ -31,6 +32,7 @@ struct pca9450_regulator_desc {
31
32
struct pca9450 {
32
33
struct device * dev ;
33
34
struct regmap * regmap ;
35
+ struct gpio_desc * sd_vsel_gpio ;
34
36
enum pca9450_chip_type type ;
35
37
unsigned int rcnt ;
36
38
int irq ;
@@ -96,6 +98,58 @@ static const struct regulator_ops pca9450_ldo_regulator_ops = {
96
98
.get_voltage_sel = regulator_get_voltage_sel_regmap ,
97
99
};
98
100
101
+ static unsigned int pca9450_ldo5_get_reg_voltage_sel (struct regulator_dev * rdev )
102
+ {
103
+ struct pca9450 * pca9450 = rdev_get_drvdata (rdev );
104
+
105
+ if (pca9450 -> sd_vsel_gpio && !gpiod_get_value (pca9450 -> sd_vsel_gpio ))
106
+ return PCA9450_REG_LDO5CTRL_L ;
107
+
108
+ return rdev -> desc -> vsel_reg ;
109
+ }
110
+
111
+ static int pca9450_ldo5_get_voltage_sel_regmap (struct regulator_dev * rdev )
112
+ {
113
+ unsigned int val ;
114
+ int ret ;
115
+
116
+ ret = regmap_read (rdev -> regmap , pca9450_ldo5_get_reg_voltage_sel (rdev ), & val );
117
+ if (ret != 0 )
118
+ return ret ;
119
+
120
+ val &= rdev -> desc -> vsel_mask ;
121
+ val >>= ffs (rdev -> desc -> vsel_mask ) - 1 ;
122
+
123
+ return val ;
124
+ }
125
+
126
+ static int pca9450_ldo5_set_voltage_sel_regmap (struct regulator_dev * rdev , unsigned int sel )
127
+ {
128
+ int ret ;
129
+
130
+ sel <<= ffs (rdev -> desc -> vsel_mask ) - 1 ;
131
+
132
+ ret = regmap_update_bits (rdev -> regmap , pca9450_ldo5_get_reg_voltage_sel (rdev ),
133
+ rdev -> desc -> vsel_mask , sel );
134
+ if (ret )
135
+ return ret ;
136
+
137
+ if (rdev -> desc -> apply_bit )
138
+ ret = regmap_update_bits (rdev -> regmap , rdev -> desc -> apply_reg ,
139
+ rdev -> desc -> apply_bit ,
140
+ rdev -> desc -> apply_bit );
141
+ return ret ;
142
+ }
143
+
144
+ static const struct regulator_ops pca9450_ldo5_regulator_ops = {
145
+ .enable = regulator_enable_regmap ,
146
+ .disable = regulator_disable_regmap ,
147
+ .is_enabled = regulator_is_enabled_regmap ,
148
+ .list_voltage = regulator_list_voltage_linear_range ,
149
+ .set_voltage_sel = pca9450_ldo5_set_voltage_sel_regmap ,
150
+ .get_voltage_sel = pca9450_ldo5_get_voltage_sel_regmap ,
151
+ };
152
+
99
153
/*
100
154
* BUCK1/2/3
101
155
* 0.60 to 2.1875V (12.5mV step)
@@ -451,7 +505,7 @@ static const struct pca9450_regulator_desc pca9450a_regulators[] = {
451
505
.of_match = of_match_ptr ("LDO5" ),
452
506
.regulators_node = of_match_ptr ("regulators" ),
453
507
.id = PCA9450_LDO5 ,
454
- .ops = & pca9450_ldo_regulator_ops ,
508
+ .ops = & pca9450_ldo5_regulator_ops ,
455
509
.type = REGULATOR_VOLTAGE ,
456
510
.n_voltages = PCA9450_LDO5_VOLTAGE_NUM ,
457
511
.linear_ranges = pca9450_ldo5_volts ,
@@ -665,7 +719,7 @@ static const struct pca9450_regulator_desc pca9450bc_regulators[] = {
665
719
.of_match = of_match_ptr ("LDO5" ),
666
720
.regulators_node = of_match_ptr ("regulators" ),
667
721
.id = PCA9450_LDO5 ,
668
- .ops = & pca9450_ldo_regulator_ops ,
722
+ .ops = & pca9450_ldo5_regulator_ops ,
669
723
.type = REGULATOR_VOLTAGE ,
670
724
.n_voltages = PCA9450_LDO5_VOLTAGE_NUM ,
671
725
.linear_ranges = pca9450_ldo5_volts ,
@@ -855,7 +909,7 @@ static const struct pca9450_regulator_desc pca9451a_regulators[] = {
855
909
.of_match = of_match_ptr ("LDO5" ),
856
910
.regulators_node = of_match_ptr ("regulators" ),
857
911
.id = PCA9450_LDO5 ,
858
- .ops = & pca9450_ldo_regulator_ops ,
912
+ .ops = & pca9450_ldo5_regulator_ops ,
859
913
.type = REGULATOR_VOLTAGE ,
860
914
.n_voltages = PCA9450_LDO5_VOLTAGE_NUM ,
861
915
.linear_ranges = pca9450_ldo5_volts ,
@@ -913,6 +967,7 @@ static int pca9450_i2c_probe(struct i2c_client *i2c)
913
967
of_device_get_match_data (& i2c -> dev );
914
968
const struct pca9450_regulator_desc * regulator_desc ;
915
969
struct regulator_config config = { };
970
+ struct regulator_dev * ldo5 ;
916
971
struct pca9450 * pca9450 ;
917
972
unsigned int device_id , i ;
918
973
unsigned int reset_ctrl ;
@@ -978,11 +1033,15 @@ static int pca9450_i2c_probe(struct i2c_client *i2c)
978
1033
979
1034
config .regmap = pca9450 -> regmap ;
980
1035
config .dev = pca9450 -> dev ;
1036
+ config .driver_data = pca9450 ;
981
1037
982
1038
rdev = devm_regulator_register (pca9450 -> dev , desc , & config );
983
1039
if (IS_ERR (rdev ))
984
1040
return dev_err_probe (pca9450 -> dev , PTR_ERR (rdev ),
985
1041
"Failed to register regulator(%s)\n" , desc -> name );
1042
+
1043
+ if (!strcmp (desc -> name , "ldo5" ))
1044
+ ldo5 = rdev ;
986
1045
}
987
1046
988
1047
if (pca9450 -> irq ) {
@@ -1029,6 +1088,30 @@ static int pca9450_i2c_probe(struct i2c_client *i2c)
1029
1088
"Failed to enable I2C level translator\n" );
1030
1089
}
1031
1090
1091
+ /*
1092
+ * For LDO5 we need to be able to check the status of the SD_VSEL input in
1093
+ * order to know which control register is used. Most boards connect SD_VSEL
1094
+ * to the VSELECT signal, so we can use the GPIO that is internally routed
1095
+ * to this signal (if SION bit is set in IOMUX).
1096
+ */
1097
+ pca9450 -> sd_vsel_gpio = gpiod_get_optional (& ldo5 -> dev , "sd-vsel" , GPIOD_IN );
1098
+ if (IS_ERR (pca9450 -> sd_vsel_gpio )) {
1099
+ dev_err (& i2c -> dev , "Failed to get SD_VSEL GPIO\n" );
1100
+ return ret ;
1101
+ }
1102
+
1103
+ /*
1104
+ * For LDO5 we need to be able to check the status of the SD_VSEL input in
1105
+ * order to know which control register is used. Most boards connect SD_VSEL
1106
+ * to the VSELECT signal, so we can use the GPIO that is internally routed
1107
+ * to this signal (if SION bit is set in IOMUX).
1108
+ */
1109
+ pca9450 -> sd_vsel_gpio = gpiod_get_optional (& ldo5 -> dev , "sd-vsel" , GPIOD_IN );
1110
+ if (IS_ERR (pca9450 -> sd_vsel_gpio )) {
1111
+ dev_err (& i2c -> dev , "Failed to get SD_VSEL GPIO\n" );
1112
+ return ret ;
1113
+ }
1114
+
1032
1115
dev_info (& i2c -> dev , "%s probed.\n" ,
1033
1116
type == PCA9450_TYPE_PCA9450A ? "pca9450a" :
1034
1117
(type == PCA9450_TYPE_PCA9451A ? "pca9451a" : "pca9450bc" ));
0 commit comments