static int tc3589x_chip_init(struct tc3589x *tc3589x) { int manf, ver, ret; manf = tc3589x_reg_read(tc3589x, TC3589x_MANFCODE); if (manf < 0) return manf; ver = tc3589x_reg_read(tc3589x, TC3589x_VERSION); if (ver < 0) return ver; if (manf != TC3589x_MANFCODE_MAGIC) { dev_err(tc3589x->dev, "unknown manufacturer: %#x\n", manf); return -EINVAL; } dev_info(tc3589x->dev, "manufacturer: %#x, version: %#x\n", manf, ver); /* * Put everything except the IRQ module into reset; * also spare the GPIO module for any pin initialization * done during pre-kernel boot */ ret = tc3589x_reg_write(tc3589x, TC3589x_RSTCTRL, TC3589x_RSTCTRL_TIMRST | TC3589x_RSTCTRL_ROTRST | TC3589x_RSTCTRL_KBDRST); if (ret < 0) return ret; /* Clear the reset interrupt. */ return tc3589x_reg_write(tc3589x, TC3589x_RSTINTCLR, 0x1); }
static int tc3589x_resume(struct device *dev) { struct tc3589x *tc3589x = dev_get_drvdata(dev); struct i2c_client *client = tc3589x->i2c; int ret = 0; /* enable the system into operation */ if (!device_may_wakeup(&client->dev)) ret = tc3589x_reg_write(tc3589x, TC3589x_CLKMODE, TC3589x_CLKMODE_MODCTL_OPERATION); return ret; }
static int tc3589x_suspend(struct device *dev) { struct tc3589x *tc3589x = dev_get_drvdata(dev); struct i2c_client *client = tc3589x->i2c; int ret = 0; /* put the system to sleep mode */ if (!device_may_wakeup(&client->dev)) ret = tc3589x_reg_write(tc3589x, TC3589x_CLKMODE, TC3589x_CLKMODE_MODCTL_SLEEP); return ret; }
/** * tc3589x_set_bits() - set the value of a bitfield in a TC3589x register * @tc3589x: Device to write to * @reg: Register to write * @mask: Mask of bits to set * @values: Value to set */ int tc3589x_set_bits(struct tc3589x *tc3589x, u8 reg, u8 mask, u8 val) { int ret; mutex_lock(&tc3589x->lock); ret = tc3589x_reg_read(tc3589x, reg); if (ret < 0) goto out; ret &= ~mask; ret |= val; ret = tc3589x_reg_write(tc3589x, reg, ret); out: mutex_unlock(&tc3589x->lock); return ret; }
static int tc3589x_keypad_init_key_hardware(struct tc_keypad *keypad) { int ret; struct tc3589x *tc3589x = keypad->tc3589x; const struct tc3589x_keypad_platform_data *board = keypad->board; /* validate platform configuration */ if (board->kcol > TC3589x_MAX_KPCOL || board->krow > TC3589x_MAX_KPROW) return -EINVAL; /* configure KBDSIZE 4 LSbits for cols and 4 MSbits for rows */ ret = tc3589x_reg_write(tc3589x, TC3589x_KBDSIZE, (board->krow << KP_ROW_SHIFT) | board->kcol); if (ret < 0) return ret; /* configure dedicated key config, no dedicated key selected */ ret = tc3589x_reg_write(tc3589x, TC3589x_KBCFG_LSB, DEDICATED_KEY_VAL); if (ret < 0) return ret; ret = tc3589x_reg_write(tc3589x, TC3589x_KBCFG_MSB, DEDICATED_KEY_VAL); if (ret < 0) return ret; /* Configure settle time */ ret = tc3589x_reg_write(tc3589x, TC3589x_KBDSETTLE_REG, board->settle_time); if (ret < 0) return ret; /* Configure debounce time */ ret = tc3589x_reg_write(tc3589x, TC3589x_KBDBOUNCE, board->debounce_period); if (ret < 0) return ret; /* Start of initialise keypad GPIOs */ ret = tc3589x_set_bits(tc3589x, TC3589x_IOCFG, 0x0, IOCFG_IG); if (ret < 0) return ret; /* Configure pull-up resistors for all row GPIOs */ ret = tc3589x_reg_write(tc3589x, TC3589x_IOPULLCFG0_LSB, TC3589x_PULLUP_ALL_MASK); if (ret < 0) return ret; ret = tc3589x_reg_write(tc3589x, TC3589x_IOPULLCFG0_MSB, TC3589x_PULLUP_ALL_MASK); if (ret < 0) return ret; /* Configure pull-up resistors for all column GPIOs */ ret = tc3589x_reg_write(tc3589x, TC3589x_IOPULLCFG1_LSB, TC3589x_PULLUP_ALL_MASK); if (ret < 0) return ret; ret = tc3589x_reg_write(tc3589x, TC3589x_IOPULLCFG1_MSB, TC3589x_PULLUP_ALL_MASK); if (ret < 0) return ret; ret = tc3589x_reg_write(tc3589x, TC3589x_IOPULLCFG2_LSB, TC3589x_PULLUP_ALL_MASK); return ret; }