static void print_all_reg_value(struct i2c_client *client) { u8 value; u8 i; for (i = 0; i != 0x11; ++i) { max77803_read_reg(client, i, &value); printk(KERN_ERR "LEDS_MAX77803 REG(%d) = %x\n", i, value); } }
static int max77803_freeze(struct device *dev) { struct i2c_client *i2c = container_of(dev, struct i2c_client, dev); struct max77803_dev *max77803 = i2c_get_clientdata(i2c); int i; for (i = 0; i < ARRAY_SIZE(max77803_dumpaddr_pmic); i++) max77803_read_reg(i2c, max77803_dumpaddr_pmic[i], &max77803->reg_pmic_dump[i]); for (i = 0; i < ARRAY_SIZE(max77803_dumpaddr_muic); i++) max77803_read_reg(i2c, max77803_dumpaddr_muic[i], &max77803->reg_muic_dump[i]); for (i = 0; i < ARRAY_SIZE(max77803_dumpaddr_haptic); i++) max77803_read_reg(i2c, max77803_dumpaddr_haptic[i], &max77803->reg_haptic_dump[i]); disable_irq(max77803->irq); return 0; }
static int max77803_set_bits(struct i2c_client *client, const u8 reg, const u8 mask, const u8 inval) { int ret; u8 value; ret = max77803_read_reg(client, reg, &value); if (unlikely(ret < 0)) return ret; value = (value & ~mask) | (inval & mask); ret = max77803_write_reg(client, reg, value); return ret; }
int max77803_irq_init(struct max77803_dev *max77803) { int i; int cur_irq; int ret; u8 i2c_data; if (!max77803->irq_gpio) { dev_warn(max77803->dev, "No interrupt specified.\n"); max77803->irq_base = 0; return 0; } if (!max77803->irq_base) { dev_err(max77803->dev, "No interrupt base specified.\n"); return 0; } mutex_init(&max77803->irqlock); max77803->irq = gpio_to_irq(max77803->irq_gpio); ret = gpio_request(max77803->irq_gpio, "if_pmic_irq"); if (ret) { dev_err(max77803->dev, "%s: failed requesting gpio %d\n", __func__, max77803->irq_gpio); return ret; } gpio_direction_input(max77803->irq_gpio); s3c_gpio_setpull(max77803->irq_gpio, S3C_GPIO_PULL_NONE); gpio_free(max77803->irq_gpio); /* Mask individual interrupt sources */ for (i = 0; i < MAX77803_IRQ_GROUP_NR; i++) { struct i2c_client *i2c; /* MUIC IRQ 0:MASK 1:NOT MASK */ /* Other IRQ 1:MASK 0:NOT MASK */ if (i >= MUIC_INT1 && i <= MUIC_INT3) { max77803->irq_masks_cur[i] = 0x00; max77803->irq_masks_cache[i] = 0x00; } else { max77803->irq_masks_cur[i] = 0xff; max77803->irq_masks_cache[i] = 0xff; } i2c = get_i2c(max77803, i); if (IS_ERR_OR_NULL(i2c)) continue; if (max77803_mask_reg[i] == MAX77803_REG_INVALID) continue; if (i >= MUIC_INT1 && i <= MUIC_INT3) max77803_write_reg(i2c, max77803_mask_reg[i], 0x00); else max77803_write_reg(i2c, max77803_mask_reg[i], 0xff); } /* Register with genirq */ for (i = 0; i < MAX77803_IRQ_NR; i++) { cur_irq = i + max77803->irq_base; irq_set_chip_data(cur_irq, max77803); irq_set_chip_and_handler(cur_irq, &max77803_irq_chip, handle_edge_irq); irq_set_nested_thread(cur_irq, 1); #ifdef CONFIG_ARM set_irq_flags(cur_irq, IRQF_VALID); #else irq_set_noprobe(cur_irq); #endif } /* Unmask max77803 interrupt */ ret = max77803_read_reg(max77803->i2c, MAX77803_PMIC_REG_INTSRC_MASK, &i2c_data); if (ret) { dev_err(max77803->dev, "%s: fail to read muic reg\n", __func__); return ret; } i2c_data &= ~(MAX77803_IRQSRC_CHG); /* Unmask charger interrupt */ i2c_data &= ~(MAX77803_IRQSRC_MUIC); /* Unmask muic interrupt */ max77803_write_reg(max77803->i2c, MAX77803_PMIC_REG_INTSRC_MASK, i2c_data); ret = request_threaded_irq(max77803->irq, NULL, max77803_irq_thread, IRQF_TRIGGER_FALLING | IRQF_ONESHOT, "max77803-irq", max77803); if (ret) { dev_err(max77803->dev, "Failed to request IRQ %d: %d\n", max77803->irq, ret); return ret; } return 0; }
static irqreturn_t max77803_irq_thread(int irq, void *data) { struct max77803_dev *max77803 = data; u8 irq_reg[MAX77803_IRQ_GROUP_NR] = {0}; u8 tmp_irq_reg[MAX77803_IRQ_GROUP_NR] = {}; u8 irq_src; int ret; int i; pr_debug("%s: irq gpio pre-state(0x%02x)\n", __func__, gpio_get_value(max77803->irq_gpio)); clear_retry: ret = max77803_read_reg(max77803->i2c, MAX77803_PMIC_REG_INTSRC, &irq_src); if (ret < 0) { dev_err(max77803->dev, "Failed to read interrupt source: %d\n", ret); return IRQ_NONE; } pr_info("%s: interrupt source(0x%02x)\n", __func__, irq_src); if (irq_src & MAX77803_IRQSRC_CHG) { /* CHG_INT */ ret = max77803_read_reg(max77803->i2c, MAX77803_CHG_REG_CHG_INT, &irq_reg[CHG_INT]); pr_info("%s: charger interrupt(0x%02x)\n", __func__, irq_reg[CHG_INT]); /* mask chgin to prevent chgin infinite interrupt * chgin is unmasked chgin isr */ if (irq_reg[CHG_INT] & max77803_irqs[MAX77803_CHG_IRQ_CHGIN_I].mask) { u8 reg_data; max77803_read_reg(max77803->i2c, MAX77803_CHG_REG_CHG_INT_MASK, ®_data); reg_data |= (1 << 6); max77803_write_reg(max77803->i2c, MAX77803_CHG_REG_CHG_INT_MASK, reg_data); } } if (irq_src & MAX77803_IRQSRC_TOP) { /* TOPSYS_INT */ ret = max77803_read_reg(max77803->i2c, MAX77803_PMIC_REG_TOPSYS_INT, &irq_reg[TOPSYS_INT]); pr_info("%s: topsys interrupt(0x%02x)\n", __func__, irq_reg[TOPSYS_INT]); } if (irq_src & MAX77803_IRQSRC_FLASH) { /* LED_INT */ ret = max77803_read_reg(max77803->i2c, MAX77803_LED_REG_FLASH_INT, &irq_reg[LED_INT]); pr_info("%s: led interrupt(0x%02x)\n", __func__, irq_reg[LED_INT]); } if (irq_src & MAX77803_IRQSRC_MUIC) { /* MUIC INT1 ~ INT3 */ max77803_bulk_read(max77803->muic, MAX77803_MUIC_REG_INT1, MAX77803_NUM_IRQ_MUIC_REGS, &tmp_irq_reg[MUIC_INT1]); /* Or temp irq register to irq register for if it retries */ for (i = MUIC_INT1; i < MAX77803_IRQ_GROUP_NR; i++) irq_reg[i] |= tmp_irq_reg[i]; pr_info("%s: muic interrupt(0x%02x, 0x%02x, 0x%02x)\n", __func__, irq_reg[MUIC_INT1], irq_reg[MUIC_INT2], irq_reg[MUIC_INT3]); } pr_debug("%s: irq gpio post-state(0x%02x)\n", __func__, gpio_get_value(max77803->irq_gpio)); if (gpio_get_value(max77803->irq_gpio) == 0) { pr_warn("%s: irq_gpio is not High!\n", __func__); goto clear_retry; } /* Apply masking */ for (i = 0; i < MAX77803_IRQ_GROUP_NR; i++) { if (i >= MUIC_INT1 && i <= MUIC_INT3) irq_reg[i] &= max77803->irq_masks_cur[i]; else irq_reg[i] &= ~max77803->irq_masks_cur[i]; } /* Report */ for (i = 0; i < MAX77803_IRQ_NR; i++) { if (irq_reg[max77803_irqs[i].group] & max77803_irqs[i].mask) handle_nested_irq(max77803->irq_base + i); } return IRQ_HANDLED; }
static int max77803_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { struct max77803_dev *max77803; struct max77803_platform_data *pdata; u8 reg_data; int ret = 0; dev_info(&i2c->dev, "%s\n", __func__); max77803 = kzalloc(sizeof(struct max77803_dev), GFP_KERNEL); if (max77803 == NULL) return -ENOMEM; if (i2c->dev.of_node) { pdata = devm_kzalloc(&i2c->dev, sizeof(struct max77803_platform_data), GFP_KERNEL); if (!pdata) { dev_err(&i2c->dev, "Failed to allocate memory \n"); ret = -ENOMEM; goto err; } ret = of_max77803_dt(&i2c->dev, pdata); if (ret < 0){ dev_err(&i2c->dev, "Failed to get device of_node \n"); return ret; } /*Filling the platform data*/ pdata->num_regulators = MAX77803_REG_MAX; pdata->muic_data = &max77803_muic; pdata->charger_data = &sec_battery_pdata; pdata->regulators = max77803_regulators, #ifdef CONFIG_VIBETONZ pdata->haptic_data = &max77803_haptic_pdata; #endif pdata->led_data = &max77803_led_pdata; /* set irq_base at sec_battery_pdata */ sec_battery_pdata.bat_irq = pdata->irq_base + MAX77803_CHG_IRQ_BATP_I; /*pdata update to other modules*/ i2c->dev.platform_data = pdata; } else pdata = i2c->dev.platform_data; i2c_set_clientdata(i2c, max77803); max77803->dev = &i2c->dev; max77803->i2c = i2c; max77803->irq = i2c->irq; // max77803->type = id->driver_data; if (pdata) { max77803->irq_base = pdata->irq_base; max77803->irq_gpio = pdata->irq_gpio; max77803->wakeup = pdata->wakeup; gpio_tlmm_config(GPIO_CFG(max77803->irq_gpio, 0, GPIO_CFG_INPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), GPIO_CFG_DISABLE); } else { ret = -EINVAL; goto err; } mutex_init(&max77803->iolock); if (max77803_read_reg(i2c, MAX77803_PMIC_REG_PMIC_ID2, ®_data) < 0) { dev_err(max77803->dev, "device not found on this channel (this is not an error)\n"); ret = -ENODEV; goto err; } else { /* print rev */ max77803->pmic_rev = (reg_data & 0x7); max77803->pmic_ver = ((reg_data & 0xF8) >> 0x3); pr_info("%s: device found: rev.0x%x, ver.0x%x\n", __func__, max77803->pmic_rev, max77803->pmic_ver); } #if 0 #if defined(CONFIG_MACH_JF_VZW) || defined(CONFIG_MACH_JF_LGT) if (kernel_sec_get_debug_level() == KERNEL_SEC_DEBUG_LEVEL_LOW) { pm8xxx_hard_reset_config(PM8XXX_DISABLE_HARD_RESET); max77803_write_reg(i2c, MAX77803_PMIC_REG_MAINCTRL1, 0x04); } else { pm8xxx_hard_reset_config(PM8XXX_DISABLE_HARD_RESET); max77803_write_reg(i2c, MAX77803_PMIC_REG_MAINCTRL1, 0x0c); } #else if (kernel_sec_get_debug_level() == KERNEL_SEC_DEBUG_LEVEL_LOW) { max77803_write_reg(i2c, MAX77803_PMIC_REG_MAINCTRL1, 0x04); } else { pm8xxx_hard_reset_config(PM8XXX_DISABLE_HARD_RESET); max77803_write_reg(i2c, MAX77803_PMIC_REG_MAINCTRL1, 0x0c); } #endif #endif max77803_update_reg(i2c, MAX77803_CHG_REG_SAFEOUT_CTRL, 0x00, 0x30); max77803->muic = i2c_new_dummy(i2c->adapter, I2C_ADDR_MUIC); i2c_set_clientdata(max77803->muic, max77803); max77803->haptic = i2c_new_dummy(i2c->adapter, I2C_ADDR_HAPTIC); i2c_set_clientdata(max77803->haptic, max77803); ret = max77803_irq_init(max77803); if (ret < 0) goto err_irq_init; ret = mfd_add_devices(max77803->dev, -1, max77803_devs, ARRAY_SIZE(max77803_devs), NULL, 0); if (ret < 0) goto err_mfd; device_init_wakeup(max77803->dev, pdata->wakeup); return ret; err_mfd: mfd_remove_devices(max77803->dev); max77803_irq_exit(max77803); err_irq_init: i2c_unregister_device(max77803->muic); i2c_unregister_device(max77803->haptic); err: kfree(max77803); return ret; }
static int max77803_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { struct max77803_dev *max77803; struct max77803_platform_data *pdata = i2c->dev.platform_data; u8 reg_data; int ret = 0; max77803 = kzalloc(sizeof(struct max77803_dev), GFP_KERNEL); if (max77803 == NULL) return -ENOMEM; i2c_set_clientdata(i2c, max77803); max77803->dev = &i2c->dev; max77803->i2c = i2c; max77803->irq = i2c->irq; max77803->type = id->driver_data; if (pdata) { max77803->irq_base = pdata->irq_base; max77803->irq_gpio = pdata->irq_gpio; /* WA for V1 MUIC RESET */ max77803->muic_reset_irq = pdata->muic_reset_irq; max77803->wakeup = pdata->wakeup; } else goto err; mutex_init(&max77803->iolock); if (max77803_read_reg(i2c, MAX77803_PMIC_REG_PMIC_ID2, ®_data) < 0) { dev_err(max77803->dev, "device not found on this channel (this is not an error)\n"); ret = -ENODEV; goto err; } else { /* print rev */ max77803->pmic_rev = (reg_data & 0x7); max77803->pmic_ver = ((reg_data & 0xF8) >> 0x3); pr_info("%s: device found: rev.0x%x, ver.0x%x\n", __func__, max77803->pmic_rev, max77803->pmic_ver); } /* No active discharge on safeout ldo 1,2 */ max77803_update_reg(i2c, MAX77803_CHG_REG_SAFEOUT_CTRL, 0x00, 0x30); max77803->muic = i2c_new_dummy(i2c->adapter, I2C_ADDR_MUIC); i2c_set_clientdata(max77803->muic, max77803); max77803->haptic = i2c_new_dummy(i2c->adapter, I2C_ADDR_HAPTIC); i2c_set_clientdata(max77803->haptic, max77803); ret = max77803_irq_init(max77803); if (ret < 0) goto err_irq_init; ret = mfd_add_devices(max77803->dev, -1, max77803_devs, ARRAY_SIZE(max77803_devs), NULL, 0); if (ret < 0) goto err_mfd; device_init_wakeup(max77803->dev, pdata->wakeup); return ret; err_mfd: mfd_remove_devices(max77803->dev); err_irq_init: i2c_unregister_device(max77803->muic); i2c_unregister_device(max77803->haptic); err: kfree(max77803); return ret; }