/** * struct max14577_muic_irq * @irq: the index of irq list of MUIC device. * @name: the name of irq. * @virq: the virtual irq to use irq domain
*/ struct max14577_muic_irq { unsignedint irq; constchar *name; unsignedint virq;
};
/* * Use delayed workqueue to detect cable state and then * notify cable state to notifiee/platform through uevent. * After completing the booting of platform, the extcon provider * driver should notify cable state to upper layer.
*/ struct delayed_work wq_detcable;
/* * Default usb/uart path whether UART/USB or AUX_UART/AUX_USB * h/w path of COMP2/COMN1 on CONTROL1 register.
*/ int path_usb; int path_uart;
};
/* * max14577_muic_set_debounce_time - Set the debounce time of ADC * @info: the instance including private data of max14577 MUIC * @time: the debounce time of ADC
*/ staticint max14577_muic_set_debounce_time(struct max14577_muic_info *info, enum max14577_muic_adc_debounce_time time)
{
u8 ret;
switch (time) { case ADC_DEBOUNCE_TIME_5MS: case ADC_DEBOUNCE_TIME_10MS: case ADC_DEBOUNCE_TIME_25MS: case ADC_DEBOUNCE_TIME_38_62MS:
ret = max14577_update_reg(info->max14577->regmap,
MAX14577_MUIC_REG_CONTROL3,
CTRL3_ADCDBSET_MASK,
time << CTRL3_ADCDBSET_SHIFT); if (ret) {
dev_err(info->dev, "failed to set ADC debounce time\n"); return ret;
} break; default:
dev_err(info->dev, "invalid ADC debounce time\n"); return -EINVAL;
}
return 0;
};
/* * max14577_muic_set_path - Set hardware line according to attached cable * @info: the instance including private data of max14577 MUIC * @value: the path according to attached cable * @attached: the state of cable (true:attached, false:detached) * * The max14577 MUIC device share outside H/W line among a varity of cables * so, this function set internal path of H/W line according to the type of * attached cable.
*/ staticint max14577_muic_set_path(struct max14577_muic_info *info,
u8 val, bool attached)
{
u8 ctrl1, ctrl2 = 0; int ret;
/* Set open state to path before changing hw path */
ret = max14577_update_reg(info->max14577->regmap,
MAX14577_MUIC_REG_CONTROL1,
CLEAR_IDBEN_MICEN_MASK, CTRL1_SW_OPEN); if (ret < 0) {
dev_err(info->dev, "failed to update MUIC register\n"); return ret;
}
if (attached)
ctrl1 = val; else
ctrl1 = CTRL1_SW_OPEN;
ret = max14577_update_reg(info->max14577->regmap,
MAX14577_MUIC_REG_CONTROL1,
CLEAR_IDBEN_MICEN_MASK, ctrl1); if (ret < 0) {
dev_err(info->dev, "failed to update MUIC register\n"); return ret;
}
/* * max14577_muic_get_cable_type - Return cable type and check cable state * @info: the instance including private data of max14577 MUIC * @group: the path according to attached cable * @attached: store cable state and return * * This function check the cable state either attached or detached, * and then divide precise type of cable according to cable group. * - max14577_CABLE_GROUP_ADC * - max14577_CABLE_GROUP_CHG
*/ staticint max14577_muic_get_cable_type(struct max14577_muic_info *info, enum max14577_muic_cable_group group, bool *attached)
{ int cable_type = 0; int adc; int chg_type;
switch (group) { case MAX14577_CABLE_GROUP_ADC: /* * Read ADC value to check cable type and decide cable state * according to cable type
*/
adc = info->status[MAX14577_MUIC_STATUS1] & STATUS1_ADC_MASK;
adc >>= STATUS1_ADC_SHIFT;
/* * Check current cable state/cable type and store cable type * (info->prev_cable_type) for handling cable when cable is * detached.
*/ if (adc == MAX14577_MUIC_ADC_OPEN) {
*attached = false;
cable_type = info->prev_cable_type = adc;
} break; case MAX14577_CABLE_GROUP_CHG: /* * Read charger type to check cable type and decide cable state * according to type of charger cable.
*/
chg_type = info->status[MAX14577_MUIC_STATUS2] &
STATUS2_CHGTYP_MASK;
chg_type >>= STATUS2_CHGTYP_SHIFT;
if (chg_type == MAX14577_CHARGER_TYPE_NONE) {
*attached = false;
/* * Check current cable state/cable type and store cable * type(info->prev_chg_type) for handling cable when * charger cable is detached.
*/
cable_type = info->prev_chg_type = chg_type;
}
switch (cable_type) { case MAX14577_MUIC_ADC_FACTORY_MODE_USB_OFF: case MAX14577_MUIC_ADC_FACTORY_MODE_USB_ON: case MAX14577_MUIC_ADC_FACTORY_MODE_UART_OFF: /* JIG */
ret = max14577_muic_jig_handler(info, cable_type, attached); if (ret < 0) return ret; break; case MAX14577_MUIC_ADC_GROUND: case MAX14577_MUIC_ADC_SEND_END_BUTTON: case MAX14577_MUIC_ADC_REMOTE_S1_BUTTON: case MAX14577_MUIC_ADC_REMOTE_S2_BUTTON: case MAX14577_MUIC_ADC_REMOTE_S3_BUTTON: case MAX14577_MUIC_ADC_REMOTE_S4_BUTTON: case MAX14577_MUIC_ADC_REMOTE_S5_BUTTON: case MAX14577_MUIC_ADC_REMOTE_S6_BUTTON: case MAX14577_MUIC_ADC_REMOTE_S7_BUTTON: case MAX14577_MUIC_ADC_REMOTE_S8_BUTTON: case MAX14577_MUIC_ADC_REMOTE_S9_BUTTON: case MAX14577_MUIC_ADC_REMOTE_S10_BUTTON: case MAX14577_MUIC_ADC_REMOTE_S11_BUTTON: case MAX14577_MUIC_ADC_REMOTE_S12_BUTTON: case MAX14577_MUIC_ADC_RESERVED_ACC_1: case MAX14577_MUIC_ADC_RESERVED_ACC_2: case MAX14577_MUIC_ADC_RESERVED_ACC_3: case MAX14577_MUIC_ADC_RESERVED_ACC_4: case MAX14577_MUIC_ADC_RESERVED_ACC_5: case MAX14577_MUIC_ADC_AUDIO_DEVICE_TYPE2: case MAX14577_MUIC_ADC_PHONE_POWERED_DEV: case MAX14577_MUIC_ADC_TTY_CONVERTER: case MAX14577_MUIC_ADC_UART_CABLE: case MAX14577_MUIC_ADC_CEA936A_TYPE1_CHG: case MAX14577_MUIC_ADC_AV_CABLE_NOLOAD: case MAX14577_MUIC_ADC_CEA936A_TYPE2_CHG: case MAX14577_MUIC_ADC_FACTORY_MODE_UART_ON: case MAX14577_MUIC_ADC_AUDIO_DEVICE_TYPE1: /* * This accessory isn't used in general case if it is specially * needed to detect additional accessory, should implement * proper operation when this accessory is attached/detached.
*/
dev_info(info->dev, "accessory is %s but it isn't used (adc:0x%x)\n",
attached ? "attached" : "detached", cable_type); return -EAGAIN; default:
dev_err(info->dev, "failed to detect %s accessory (adc:0x%x)\n",
attached ? "attached" : "detached", cable_type); return -EINVAL;
}
return 0;
}
staticint max14577_muic_chg_handler(struct max14577_muic_info *info)
{ int chg_type; bool attached; int ret = 0;
switch (chg_type) { case MAX14577_CHARGER_TYPE_USB: /* PATH:AP_USB */
ret = max14577_muic_set_path(info, info->path_usb, attached); if (ret < 0) return ret;
extcon_set_state_sync(info->edev, EXTCON_USB, attached);
extcon_set_state_sync(info->edev, EXTCON_CHG_USB_SDP,
attached); break; case MAX14577_CHARGER_TYPE_DEDICATED_CHG:
extcon_set_state_sync(info->edev, EXTCON_CHG_USB_DCP,
attached); break; case MAX14577_CHARGER_TYPE_DOWNSTREAM_PORT:
extcon_set_state_sync(info->edev, EXTCON_CHG_USB_CDP,
attached); break; case MAX14577_CHARGER_TYPE_SPECIAL_500MA:
extcon_set_state_sync(info->edev, EXTCON_CHG_USB_SLOW,
attached); break; case MAX14577_CHARGER_TYPE_SPECIAL_1A:
extcon_set_state_sync(info->edev, EXTCON_CHG_USB_FAST,
attached); break; case MAX14577_CHARGER_TYPE_NONE: case MAX14577_CHARGER_TYPE_DEAD_BATTERY: break; default:
dev_err(info->dev, "failed to detect %s accessory (chg_type:0x%x)\n",
attached ? "attached" : "detached", chg_type); return -EINVAL;
}
return 0;
}
staticvoid max14577_muic_irq_work(struct work_struct *work)
{ struct max14577_muic_info *info = container_of(work, struct max14577_muic_info, irq_work); int ret = 0;
if (!info->edev) return;
mutex_lock(&info->mutex);
ret = max14577_bulk_read(info->max14577->regmap,
MAX14577_MUIC_REG_STATUS1, info->status, 2); if (ret) {
dev_err(info->dev, "failed to read MUIC register\n");
mutex_unlock(&info->mutex); return;
}
if (info->irq_adc) {
ret = max14577_muic_adc_handler(info);
info->irq_adc = false;
} if (info->irq_chg) {
ret = max14577_muic_chg_handler(info);
info->irq_chg = false;
}
if (ret < 0)
dev_err(info->dev, "failed to handle MUIC interrupt\n");
mutex_unlock(&info->mutex);
}
/* * Sets irq_adc or irq_chg in max14577_muic_info and returns 1. * Returns 0 if irq_type does not match registered IRQ for this device type.
*/ staticint max14577_parse_irq(struct max14577_muic_info *info, int irq_type)
{ switch (irq_type) { case MAX14577_IRQ_INT1_ADC: case MAX14577_IRQ_INT1_ADCLOW: case MAX14577_IRQ_INT1_ADCERR: /* * Handle all of accessory except for * type of charger accessory.
*/
info->irq_adc = true; return 1; case MAX14577_IRQ_INT2_CHGTYP: case MAX14577_IRQ_INT2_CHGDETRUN: case MAX14577_IRQ_INT2_DCDTMR: case MAX14577_IRQ_INT2_DBCHG: case MAX14577_IRQ_INT2_VBVOLT: /* Handle charger accessory */
info->irq_chg = true; return 1; default: return 0;
}
}
/* * Sets irq_adc or irq_chg in max14577_muic_info and returns 1. * Returns 0 if irq_type does not match registered IRQ for this device type.
*/ staticint max77836_parse_irq(struct max14577_muic_info *info, int irq_type)
{ /* First check common max14577 interrupts */ if (max14577_parse_irq(info, irq_type)) return 1;
static irqreturn_t max14577_muic_irq_handler(int irq, void *data)
{ struct max14577_muic_info *info = data; int i, irq_type = -1; bool irq_parsed;
/* * We may be called multiple times for different nested IRQ-s. * Including changes in INT1_ADC and INT2_CGHTYP at once. * However we only need to know whether it was ADC, charger * or both interrupts so decode IRQ and turn on proper flags.
*/ for (i = 0; i < info->muic_irqs_num; i++) if (irq == info->muic_irqs[i].virq)
irq_type = info->muic_irqs[i].irq;
switch (info->max14577->dev_type) { case MAXIM_DEVICE_TYPE_MAX77836:
irq_parsed = max77836_parse_irq(info, irq_type); break; case MAXIM_DEVICE_TYPE_MAX14577: default:
irq_parsed = max14577_parse_irq(info, irq_type); break;
}
/* Support irq domain for max14577 MUIC device */ for (i = 0; i < info->muic_irqs_num; i++) { struct max14577_muic_irq *muic_irq = &info->muic_irqs[i]; int virq = 0;
/* Set initial path for UART when JIG is connected to get serial logs */
ret = max14577_bulk_read(info->max14577->regmap,
MAX14577_MUIC_REG_STATUS1, info->status, 2); if (ret) {
dev_err(info->dev, "Cannot read STATUS registers\n"); return ret;
}
cable_type = max14577_muic_get_cable_type(info, MAX14577_CABLE_GROUP_ADC,
&attached); if (attached && cable_type == MAX14577_MUIC_ADC_FACTORY_MODE_UART_OFF)
max14577_muic_set_path(info, info->path_uart, true);
/* Check revision number of MUIC device*/
ret = max14577_read_reg(info->max14577->regmap,
MAX14577_REG_DEVICEID, &id); if (ret < 0) {
dev_err(&pdev->dev, "failed to read revision number\n"); return ret;
}
dev_info(info->dev, "device ID : 0x%x\n", id);
/* Set ADC debounce time */
max14577_muic_set_debounce_time(info, ADC_DEBOUNCE_TIME_25MS);
/* * Detect accessory after completing the initialization of platform * * - Use delayed workqueue to detect cable state and then * notify cable state to notifiee/platform through uevent. * After completing the booting of platform, the extcon provider * driver should notify cable state to upper layer.
*/
INIT_DELAYED_WORK(&info->wq_detcable, max14577_muic_detect_cable_wq);
queue_delayed_work(system_power_efficient_wq, &info->wq_detcable,
delay_jiffies);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.