11 #include <linux/export.h>
12 #include <linux/kernel.h>
16 #include <linux/slab.h>
20 static int __stmpe_enable(
struct stmpe *
stmpe,
unsigned int blocks)
22 return stmpe->
variant->enable(stmpe, blocks,
true);
25 static int __stmpe_disable(
struct stmpe *stmpe,
unsigned int blocks)
27 return stmpe->
variant->enable(stmpe, blocks,
false);
30 static int __stmpe_reg_read(
struct stmpe *stmpe,
u8 reg)
34 ret = stmpe->
ci->read_byte(stmpe, reg);
36 dev_err(stmpe->
dev,
"failed to read reg %#x: %d\n", reg, ret);
38 dev_vdbg(stmpe->
dev,
"rd: reg %#x => data %#x\n", reg, ret);
43 static int __stmpe_reg_write(
struct stmpe *stmpe,
u8 reg,
u8 val)
47 dev_vdbg(stmpe->
dev,
"wr: reg %#x <= %#x\n", reg, val);
49 ret = stmpe->
ci->write_byte(stmpe, reg, val);
51 dev_err(stmpe->
dev,
"failed to write reg %#x: %d\n", reg, ret);
56 static int __stmpe_set_bits(
struct stmpe *stmpe,
u8 reg,
u8 mask,
u8 val)
60 ret = __stmpe_reg_read(stmpe, reg);
67 return __stmpe_reg_write(stmpe, reg, ret);
70 static int __stmpe_block_read(
struct stmpe *stmpe,
u8 reg,
u8 length,
75 ret = stmpe->
ci->read_block(stmpe, reg, length, values);
77 dev_err(stmpe->
dev,
"failed to read regs %#x: %d\n", reg, ret);
79 dev_vdbg(stmpe->
dev,
"rd: reg %#x (%d) => ret %#x\n", reg, length, ret);
80 stmpe_dump_bytes(
"stmpe rd: ", values, length);
85 static int __stmpe_block_write(
struct stmpe *stmpe,
u8 reg,
u8 length,
90 dev_vdbg(stmpe->
dev,
"wr: regs %#x (%d)\n", reg, length);
91 stmpe_dump_bytes(
"stmpe wr: ", values, length);
93 ret = stmpe->
ci->write_block(stmpe, reg, length, values);
95 dev_err(stmpe->
dev,
"failed to write regs %#x: %d\n", reg, ret);
110 ret = __stmpe_enable(stmpe, blocks);
127 ret = __stmpe_disable(stmpe, blocks);
144 ret = __stmpe_reg_read(stmpe, reg);
162 ret = __stmpe_reg_write(stmpe, reg, val);
181 ret = __stmpe_set_bits(stmpe, reg, mask, val);
200 ret = __stmpe_block_read(stmpe, reg, length, values);
220 ret = __stmpe_block_write(stmpe, reg, length, values);
247 int af, afperreg,
ret;
259 ret = __stmpe_block_read(stmpe, regaddr, numregs, regs);
267 int regoffset = numregs - (pin / afperreg) - 1;
268 int pos = (pin % afperreg) * (8 / afperreg);
270 regs[regoffset] &= ~(mask <<
pos);
271 regs[regoffset] |= af <<
pos;
276 ret = __stmpe_block_write(stmpe, regaddr, numregs, regs);
288 static struct resource stmpe_gpio_resources[] = {
295 static struct mfd_cell stmpe_gpio_cell = {
296 .name =
"stmpe-gpio",
297 .resources = stmpe_gpio_resources,
298 .num_resources =
ARRAY_SIZE(stmpe_gpio_resources),
301 static struct mfd_cell stmpe_gpio_cell_noirq = {
302 .name =
"stmpe-gpio",
310 static struct resource stmpe_keypad_resources[] = {
318 .name =
"KEYPAD_OVER",
325 static struct mfd_cell stmpe_keypad_cell = {
326 .name =
"stmpe-keypad",
327 .resources = stmpe_keypad_resources,
328 .num_resources =
ARRAY_SIZE(stmpe_keypad_resources),
334 static const u8 stmpe801_regs[] = {
348 .cell = &stmpe_gpio_cell,
356 .cell = &stmpe_gpio_cell_noirq,
361 static int stmpe801_enable(
struct stmpe *stmpe,
unsigned int blocks,
375 .regs = stmpe801_regs,
376 .blocks = stmpe801_blocks,
379 .enable = stmpe801_enable,
387 .regs = stmpe801_regs,
388 .blocks = stmpe801_blocks_noirq,
389 .num_blocks =
ARRAY_SIZE(stmpe801_blocks_noirq),
390 .enable = stmpe801_enable,
397 static struct resource stmpe_ts_resources[] = {
412 static struct mfd_cell stmpe_ts_cell = {
414 .resources = stmpe_ts_resources,
415 .num_resources =
ARRAY_SIZE(stmpe_ts_resources),
422 static const u8 stmpe811_regs[] = {
441 .cell = &stmpe_gpio_cell,
446 .cell = &stmpe_ts_cell,
452 static int stmpe811_enable(
struct stmpe *stmpe,
unsigned int blocks,
455 unsigned int mask = 0;
470 static int stmpe811_get_altfunc(
struct stmpe *stmpe,
enum stmpe_block block)
482 .regs = stmpe811_regs,
483 .blocks = stmpe811_blocks,
486 .enable = stmpe811_enable,
487 .get_altfunc = stmpe811_get_altfunc,
497 .regs = stmpe811_regs,
498 .blocks = stmpe811_blocks,
501 .enable = stmpe811_enable,
502 .get_altfunc = stmpe811_get_altfunc,
509 static const u8 stmpe1601_regs[] = {
528 .cell = &stmpe_gpio_cell,
533 .cell = &stmpe_keypad_cell,
540 static const int stmpe_autosleep_delay[] = {
541 4, 16, 32, 64, 128, 256, 512, 1024,
544 static int stmpe_round_timeout(
int timeout)
548 for (i = 0; i <
ARRAY_SIZE(stmpe_autosleep_delay); i++) {
549 if (stmpe_autosleep_delay[i] >= timeout)
560 static int stmpe_autosleep(
struct stmpe *stmpe,
int autosleep_timeout)
564 if (!stmpe->
variant->enable_autosleep)
568 ret = stmpe->
variant->enable_autosleep(stmpe, autosleep_timeout);
577 static int stmpe1601_autosleep(
struct stmpe *stmpe,
578 int autosleep_timeout)
583 timeout = stmpe_round_timeout(autosleep_timeout);
600 static int stmpe1601_enable(
struct stmpe *stmpe,
unsigned int blocks,
603 unsigned int mask = 0;
605 if (blocks & STMPE_BLOCK_GPIO)
615 static int stmpe1601_get_altfunc(
struct stmpe *stmpe,
enum stmpe_block block)
624 case STMPE_BLOCK_GPIO:
636 .regs = stmpe1601_regs,
637 .blocks = stmpe1601_blocks,
640 .enable = stmpe1601_enable,
641 .get_altfunc = stmpe1601_get_altfunc,
642 .enable_autosleep = stmpe1601_autosleep,
649 static const u8 stmpe24xx_regs[] = {
668 .cell = &stmpe_gpio_cell,
673 .cell = &stmpe_keypad_cell,
679 static int stmpe24xx_enable(
struct stmpe *stmpe,
unsigned int blocks,
682 unsigned int mask = 0;
684 if (blocks & STMPE_BLOCK_GPIO)
694 static int stmpe24xx_get_altfunc(
struct stmpe *stmpe,
enum stmpe_block block)
703 case STMPE_BLOCK_GPIO:
715 .regs = stmpe24xx_regs,
716 .blocks = stmpe24xx_blocks,
719 .enable = stmpe24xx_enable,
720 .get_altfunc = stmpe24xx_get_altfunc,
729 .regs = stmpe24xx_regs,
730 .blocks = stmpe24xx_blocks,
733 .enable = stmpe24xx_enable,
734 .get_altfunc = stmpe24xx_get_altfunc,
735 .enable_autosleep = stmpe1601_autosleep,
753 static struct stmpe_variant_info *stmpe_noirq_variant_info[
STMPE_NBR_PARTS] = {
759 struct stmpe *stmpe =
data;
776 for (i = 0; i < num; i++) {
777 int bank = num - i - 1;
781 status &= stmpe->
ier[bank];
791 status &= ~(1 <<
bit);
800 static void stmpe_irq_lock(
struct irq_data *data)
802 struct stmpe *stmpe = irq_data_get_irq_chip_data(data);
807 static void stmpe_irq_sync_unlock(
struct irq_data *data)
809 struct stmpe *stmpe = irq_data_get_irq_chip_data(data);
810 struct stmpe_variant_info *variant = stmpe->
variant;
814 for (i = 0; i < num; i++) {
828 static void stmpe_irq_mask(
struct irq_data *data)
830 struct stmpe *stmpe = irq_data_get_irq_chip_data(data);
832 int regoffset = offset / 8;
833 int mask = 1 << (offset % 8);
835 stmpe->
ier[regoffset] &= ~mask;
838 static void stmpe_irq_unmask(
struct irq_data *data)
840 struct stmpe *stmpe = irq_data_get_irq_chip_data(data);
842 int regoffset = offset / 8;
843 int mask = 1 << (offset % 8);
848 static struct irq_chip stmpe_irq_chip = {
850 .irq_bus_lock = stmpe_irq_lock,
851 .irq_bus_sync_unlock = stmpe_irq_sync_unlock,
852 .irq_mask = stmpe_irq_mask,
853 .irq_unmask = stmpe_irq_unmask,
856 static int __devinit stmpe_irq_init(
struct stmpe *stmpe)
864 chip = &stmpe_irq_chip;
866 for (irq = base; irq < base +
num_irqs; irq++) {
869 irq_set_nested_thread(irq, 1);
873 irq_set_noprobe(irq);
880 static void stmpe_irq_remove(
struct stmpe *stmpe)
882 int num_irqs = stmpe->
variant->num_irqs;
886 for (irq = base; irq < base +
num_irqs; irq++) {
890 irq_set_chip_and_handler(irq,
NULL,
NULL);
895 static int __devinit stmpe_chip_init(
struct stmpe *stmpe)
897 unsigned int irq_trigger = stmpe->
pdata->irq_trigger;
898 int autosleep_timeout = stmpe->
pdata->autosleep_timeout;
899 struct stmpe_variant_info *variant = stmpe->
variant;
910 id = (data[0] << 8) | data[1];
912 dev_err(stmpe->
dev,
"unknown chip id: %#x\n",
id);
916 dev_info(stmpe->
dev,
"%s detected, chip id: %#x\n", variant->
name,
id);
923 if (stmpe->
irq >= 0) {
944 if (stmpe->
pdata->irq_invert_polarity) {
952 if (stmpe->
pdata->autosleep) {
953 ret = stmpe_autosleep(stmpe, autosleep_timeout);
961 static int __devinit stmpe_add_device(
struct stmpe *stmpe,
968 static int __devinit stmpe_devices_init(
struct stmpe *stmpe)
970 struct stmpe_variant_info *variant = stmpe->
variant;
971 unsigned int platform_blocks = stmpe->
pdata->blocks;
978 if (!(platform_blocks & block->
block))
981 platform_blocks &= ~block->
block;
982 ret = stmpe_add_device(stmpe, block->
cell, block->
irq);
989 "platform wants blocks (%#x) not present on variant",
1005 stmpe = kzalloc(
sizeof(
struct stmpe),
GFP_KERNEL);
1029 dev_err(stmpe->
dev,
"failed to request IRQ GPIO: %d\n",
1039 if (stmpe->
irq < 0) {
1042 "%s configured in no-irq mode by platform data\n",
1044 if (!stmpe_noirq_variant_info[stmpe->
partnum]) {
1046 "%s does not support no-irq mode!\n",
1054 ret = stmpe_chip_init(stmpe);
1058 if (stmpe->
irq >= 0) {
1059 ret = stmpe_irq_init(stmpe);
1067 dev_err(stmpe->
dev,
"failed to request IRQ: %d\n",
1073 ret = stmpe_devices_init(stmpe);
1075 dev_err(stmpe->
dev,
"failed to add children\n");
1076 goto out_removedevs;
1083 if (stmpe->
irq >= 0)
1086 if (stmpe->
irq >= 0)
1087 stmpe_irq_remove(stmpe);
1100 if (stmpe->
irq >= 0) {
1102 stmpe_irq_remove(stmpe);
1105 if (stmpe->
pdata->irq_over_gpio)
1114 static int stmpe_suspend(
struct device *
dev)
1118 if (stmpe->
irq >= 0 && device_may_wakeup(dev))
1119 enable_irq_wake(stmpe->
irq);
1124 static int stmpe_resume(
struct device *dev)
1128 if (stmpe->
irq >= 0 && device_may_wakeup(dev))
1129 disable_irq_wake(stmpe->
irq);
1135 .suspend = stmpe_suspend,
1136 .resume = stmpe_resume,