summaryrefslogtreecommitdiffstats
path: root/drivers/extcon/extcon-axp288.c
diff options
context:
space:
mode:
authorHans de Goede <hdegoede@redhat.com>2016-12-18 19:13:08 -0500
committerChanwoo Choi <cw00.choi@samsung.com>2017-01-08 20:04:10 -0500
commit3fe1e0e2ab509863c1e9809a085508d8bce3e079 (patch)
tree9052aec883ac2d545a2fcf8c39127d718a75c494 /drivers/extcon/extcon-axp288.c
parent1490d157e0759b12913cc0d3b734a03bbcb8cb61 (diff)
extcon: axp288: Simplify axp288_handle_chrg_det_event
axp288_handle_chrg_det_event only gets called on change interrupts (so not that often), extcon_set_state_sync() checks itself if there are any actual changes before notifying listeners, and gpiod_set_value is not really expensive either. So we can simply always do both on each interrupt removing a bunch of somewhat magic looking code from axp288_handle_chrg_det_event. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Acked-by: Chanwoo Choi <cw00.choi@samsung.com> Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Diffstat (limited to 'drivers/extcon/extcon-axp288.c')
-rw-r--r--drivers/extcon/extcon-axp288.c37
1 files changed, 12 insertions, 25 deletions
diff --git a/drivers/extcon/extcon-axp288.c b/drivers/extcon/extcon-axp288.c
index 3d5e84ea489d..43b3637a71a9 100644
--- a/drivers/extcon/extcon-axp288.c
+++ b/drivers/extcon/extcon-axp288.c
@@ -154,7 +154,6 @@ static void axp288_extcon_log_rsi(struct axp288_extcon_info *info)
154 154
155static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info) 155static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info)
156{ 156{
157 static bool notify_otg, notify_charger;
158 static unsigned int cable; 157 static unsigned int cable;
159 int ret, stat, cfg, pwr_stat; 158 int ret, stat, cfg, pwr_stat;
160 u8 chrg_type; 159 u8 chrg_type;
@@ -168,7 +167,7 @@ static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info)
168 167
169 vbus_attach = (pwr_stat & PS_STAT_VBUS_PRESENT); 168 vbus_attach = (pwr_stat & PS_STAT_VBUS_PRESENT);
170 if (!vbus_attach) 169 if (!vbus_attach)
171 goto notify_otg; 170 goto no_vbus;
172 171
173 /* Check charger detection completion status */ 172 /* Check charger detection completion status */
174 ret = regmap_read(info->regmap, AXP288_BC_GLOBAL_REG, &cfg); 173 ret = regmap_read(info->regmap, AXP288_BC_GLOBAL_REG, &cfg);
@@ -188,19 +187,14 @@ static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info)
188 switch (chrg_type) { 187 switch (chrg_type) {
189 case DET_STAT_SDP: 188 case DET_STAT_SDP:
190 dev_dbg(info->dev, "sdp cable is connected\n"); 189 dev_dbg(info->dev, "sdp cable is connected\n");
191 notify_otg = true;
192 notify_charger = true;
193 cable = EXTCON_CHG_USB_SDP; 190 cable = EXTCON_CHG_USB_SDP;
194 break; 191 break;
195 case DET_STAT_CDP: 192 case DET_STAT_CDP:
196 dev_dbg(info->dev, "cdp cable is connected\n"); 193 dev_dbg(info->dev, "cdp cable is connected\n");
197 notify_otg = true;
198 notify_charger = true;
199 cable = EXTCON_CHG_USB_CDP; 194 cable = EXTCON_CHG_USB_CDP;
200 break; 195 break;
201 case DET_STAT_DCP: 196 case DET_STAT_DCP:
202 dev_dbg(info->dev, "dcp cable is connected\n"); 197 dev_dbg(info->dev, "dcp cable is connected\n");
203 notify_charger = true;
204 cable = EXTCON_CHG_USB_DCP; 198 cable = EXTCON_CHG_USB_DCP;
205 break; 199 break;
206 default: 200 default:
@@ -208,24 +202,17 @@ static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info)
208 "disconnect or unknown or ID event\n"); 202 "disconnect or unknown or ID event\n");
209 } 203 }
210 204
211notify_otg: 205no_vbus:
212 if (notify_otg) { 206 /*
213 /* 207 * If VBUS is absent Connect D+/D- lines to PMIC for BC
214 * If VBUS is absent Connect D+/D- lines to PMIC for BC 208 * detection. Else connect them to SOC for USB communication.
215 * detection. Else connect them to SOC for USB communication. 209 */
216 */ 210 if (info->gpio_mux_cntl)
217 if (info->gpio_mux_cntl) 211 gpiod_set_value(info->gpio_mux_cntl,
218 gpiod_set_value(info->gpio_mux_cntl, 212 vbus_attach ? EXTCON_GPIO_MUX_SEL_SOC
219 vbus_attach ? EXTCON_GPIO_MUX_SEL_SOC 213 : EXTCON_GPIO_MUX_SEL_PMIC);
220 : EXTCON_GPIO_MUX_SEL_PMIC); 214
221 } 215 extcon_set_state_sync(info->edev, cable, vbus_attach);
222
223 if (notify_charger)
224 extcon_set_state_sync(info->edev, cable, vbus_attach);
225
226 /* Clear the flags on disconnect event */
227 if (!vbus_attach)
228 notify_otg = notify_charger = false;
229 216
230 return 0; 217 return 0;
231 218