Lines Matching refs:stmpe
15 #include <linux/mfd/stmpe.h>
16 #include "stmpe.h"
18 static int __stmpe_enable(struct stmpe *stmpe, unsigned int blocks)
20 return stmpe->variant->enable(stmpe, blocks, true);
23 static int __stmpe_disable(struct stmpe *stmpe, unsigned int blocks)
25 return stmpe->variant->enable(stmpe, blocks, false);
28 static int __stmpe_reg_read(struct stmpe *stmpe, u8 reg)
32 ret = i2c_smbus_read_byte_data(stmpe->i2c, reg);
34 dev_err(stmpe->dev, "failed to read reg %#x: %d\n",
37 dev_vdbg(stmpe->dev, "rd: reg %#x => data %#x\n", reg, ret);
42 static int __stmpe_reg_write(struct stmpe *stmpe, u8 reg, u8 val)
46 dev_vdbg(stmpe->dev, "wr: reg %#x <= %#x\n", reg, val);
48 ret = i2c_smbus_write_byte_data(stmpe->i2c, reg, val);
50 dev_err(stmpe->dev, "failed to write reg %#x: %d\n",
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 = i2c_smbus_read_i2c_block_data(stmpe->i2c, reg, length, values);
77 dev_err(stmpe->dev, "failed to read regs %#x: %d\n",
80 dev_vdbg(stmpe->dev, "rd: reg %#x (%d) => ret %#x\n", reg, length, ret);
81 stmpe_dump_bytes("stmpe rd: ", values, length);
86 static int __stmpe_block_write(struct stmpe *stmpe, u8 reg, u8 length,
91 dev_vdbg(stmpe->dev, "wr: regs %#x (%d)\n", reg, length);
92 stmpe_dump_bytes("stmpe wr: ", values, length);
94 ret = i2c_smbus_write_i2c_block_data(stmpe->i2c, reg, length,
97 dev_err(stmpe->dev, "failed to write regs %#x: %d\n",
105 * @stmpe: Device to work on
108 int stmpe_enable(struct stmpe *stmpe, unsigned int blocks)
112 mutex_lock(&stmpe->lock);
113 ret = __stmpe_enable(stmpe, blocks);
114 mutex_unlock(&stmpe->lock);
122 * @stmpe: Device to work on
125 int stmpe_disable(struct stmpe *stmpe, unsigned int blocks)
129 mutex_lock(&stmpe->lock);
130 ret = __stmpe_disable(stmpe, blocks);
131 mutex_unlock(&stmpe->lock);
139 * @stmpe: Device to read from
142 int stmpe_reg_read(struct stmpe *stmpe, u8 reg)
146 mutex_lock(&stmpe->lock);
147 ret = __stmpe_reg_read(stmpe, reg);
148 mutex_unlock(&stmpe->lock);
156 * @stmpe: Device to write to
160 int stmpe_reg_write(struct stmpe *stmpe, u8 reg, u8 val)
164 mutex_lock(&stmpe->lock);
165 ret = __stmpe_reg_write(stmpe, reg, val);
166 mutex_unlock(&stmpe->lock);
174 * @stmpe: Device to write to
179 int stmpe_set_bits(struct stmpe *stmpe, u8 reg, u8 mask, u8 val)
183 mutex_lock(&stmpe->lock);
184 ret = __stmpe_set_bits(stmpe, reg, mask, val);
185 mutex_unlock(&stmpe->lock);
193 * @stmpe: Device to read from
198 int stmpe_block_read(struct stmpe *stmpe, u8 reg, u8 length, u8 *values)
202 mutex_lock(&stmpe->lock);
203 ret = __stmpe_block_read(stmpe, reg, length, values);
204 mutex_unlock(&stmpe->lock);
212 * @stmpe: Device to write to
217 int stmpe_block_write(struct stmpe *stmpe, u8 reg, u8 length,
222 mutex_lock(&stmpe->lock);
223 ret = __stmpe_block_write(stmpe, reg, length, values);
224 mutex_unlock(&stmpe->lock);
232 * @stmpe: Device to configure
242 int stmpe_set_altfunc(struct stmpe *stmpe, u32 pins, enum stmpe_block block)
244 struct stmpe_variant_info *variant = stmpe->variant;
245 u8 regaddr = stmpe->regs[STMPE_IDX_GPAFR_U_MSB];
247 int numregs = DIV_ROUND_UP(stmpe->num_gpios * af_bits, 8);
254 mutex_lock(&stmpe->lock);
256 ret = __stmpe_enable(stmpe, STMPE_BLOCK_GPIO);
260 ret = __stmpe_block_read(stmpe, regaddr, numregs, regs);
264 af = variant->get_altfunc(stmpe, block);
277 ret = __stmpe_block_write(stmpe, regaddr, numregs, regs);
280 mutex_unlock(&stmpe->lock);
297 .name = "stmpe-gpio",
322 .name = "stmpe-keypad",
347 .name = "stmpe-ts",
386 static int stmpe811_enable(struct stmpe *stmpe, unsigned int blocks,
400 return __stmpe_set_bits(stmpe, STMPE811_REG_SYS_CTRL2, mask,
404 static int stmpe811_get_altfunc(struct stmpe *stmpe, enum stmpe_block block)
479 static int stmpe_autosleep(struct stmpe *stmpe, int autosleep_timeout)
483 if (!stmpe->variant->enable_autosleep)
486 mutex_lock(&stmpe->lock);
487 ret = stmpe->variant->enable_autosleep(stmpe, autosleep_timeout);
488 mutex_unlock(&stmpe->lock);
494 * Both stmpe 1601/2403 support same layout for autosleep
496 static int stmpe1601_autosleep(struct stmpe *stmpe,
504 dev_err(stmpe->dev, "invalid timeout\n");
508 ret = __stmpe_set_bits(stmpe, STMPE1601_REG_SYS_CTRL2,
514 return __stmpe_set_bits(stmpe, STMPE1601_REG_SYS_CTRL2,
519 static int stmpe1601_enable(struct stmpe *stmpe, unsigned int blocks,
530 return __stmpe_set_bits(stmpe, STMPE1601_REG_SYS_CTRL, mask,
534 static int stmpe1601_get_altfunc(struct stmpe *stmpe, enum stmpe_block block)
598 static int stmpe24xx_enable(struct stmpe *stmpe, unsigned int blocks,
609 return __stmpe_set_bits(stmpe, STMPE24XX_REG_SYS_CTRL, mask,
613 static int stmpe24xx_get_altfunc(struct stmpe *stmpe, enum stmpe_block block)
666 struct stmpe *stmpe = data;
667 struct stmpe_variant_info *variant = stmpe->variant;
669 u8 israddr = stmpe->regs[STMPE_IDX_ISR_MSB];
674 ret = stmpe_block_read(stmpe, israddr, num, isr);
683 status &= stmpe->ier[bank];
692 handle_nested_irq(stmpe->irq_base + line);
696 stmpe_reg_write(stmpe, israddr + i, clear);
704 struct stmpe *stmpe = get_irq_chip_data(irq);
706 mutex_lock(&stmpe->irq_lock);
711 struct stmpe *stmpe = get_irq_chip_data(irq);
712 struct stmpe_variant_info *variant = stmpe->variant;
717 u8 new = stmpe->ier[i];
718 u8 old = stmpe->oldier[i];
723 stmpe->oldier[i] = new;
724 stmpe_reg_write(stmpe, stmpe->regs[STMPE_IDX_IER_LSB] - i, new);
727 mutex_unlock(&stmpe->irq_lock);
732 struct stmpe *stmpe = get_irq_chip_data(irq);
733 int offset = irq - stmpe->irq_base;
737 stmpe->ier[regoffset] &= ~mask;
742 struct stmpe *stmpe = get_irq_chip_data(irq);
743 int offset = irq - stmpe->irq_base;
747 stmpe->ier[regoffset] |= mask;
751 .name = "stmpe",
758 static int __devinit stmpe_irq_init(struct stmpe *stmpe)
760 int num_irqs = stmpe->variant->num_irqs;
761 int base = stmpe->irq_base;
765 set_irq_chip_data(irq, stmpe);
779 static void stmpe_irq_remove(struct stmpe *stmpe)
781 int num_irqs = stmpe->variant->num_irqs;
782 int base = stmpe->irq_base;
794 static int __devinit stmpe_chip_init(struct stmpe *stmpe)
796 unsigned int irq_trigger = stmpe->pdata->irq_trigger;
797 int autosleep_timeout = stmpe->pdata->autosleep_timeout;
798 struct stmpe_variant_info *variant = stmpe->variant;
804 ret = stmpe_block_read(stmpe, stmpe->regs[STMPE_IDX_CHIP_ID],
811 dev_err(stmpe->dev, "unknown chip id: %#x\n", id);
815 dev_info(stmpe->dev, "%s detected, chip id: %#x\n", variant->name, id);
818 ret = stmpe_disable(stmpe, ~0);
830 if (stmpe->pdata->irq_invert_polarity)
833 if (stmpe->pdata->autosleep) {
834 ret = stmpe_autosleep(stmpe, autosleep_timeout);
839 return stmpe_reg_write(stmpe, stmpe->regs[STMPE_IDX_ICR_LSB], icr);
842 static int __devinit stmpe_add_device(struct stmpe *stmpe,
845 return mfd_add_devices(stmpe->dev, stmpe->pdata->id, cell, 1,
846 NULL, stmpe->irq_base + irq);
849 static int __devinit stmpe_devices_init(struct stmpe *stmpe)
851 struct stmpe_variant_info *variant = stmpe->variant;
852 unsigned int platform_blocks = stmpe->pdata->blocks;
863 ret = stmpe_add_device(stmpe, block->cell, block->irq);
869 dev_warn(stmpe->dev,
880 struct stmpe *stmpe;
886 stmpe = kzalloc(sizeof(struct stmpe), GFP_KERNEL);
887 if (!stmpe)
890 mutex_init(&stmpe->irq_lock);
891 mutex_init(&stmpe->lock);
893 stmpe->dev = &i2c->dev;
894 stmpe->i2c = i2c;
896 stmpe->pdata = pdata;
897 stmpe->irq_base = pdata->irq_base;
899 stmpe->partnum = id->driver_data;
900 stmpe->variant = stmpe_variant_info[stmpe->partnum];
901 stmpe->regs = stmpe->variant->regs;
902 stmpe->num_gpios = stmpe->variant->num_gpios;
904 i2c_set_clientdata(i2c, stmpe);
906 ret = stmpe_chip_init(stmpe);
910 ret = stmpe_irq_init(stmpe);
914 ret = request_threaded_irq(stmpe->i2c->irq, NULL, stmpe_irq,
916 "stmpe", stmpe);
918 dev_err(stmpe->dev, "failed to request IRQ: %d\n", ret);
922 ret = stmpe_devices_init(stmpe);
924 dev_err(stmpe->dev, "failed to add children\n");
931 mfd_remove_devices(stmpe->dev);
932 free_irq(stmpe->i2c->irq, stmpe);
934 stmpe_irq_remove(stmpe);
936 kfree(stmpe);
942 struct stmpe *stmpe = i2c_get_clientdata(client);
944 mfd_remove_devices(stmpe->dev);
946 free_irq(stmpe->i2c->irq, stmpe);
947 stmpe_irq_remove(stmpe);
949 kfree(stmpe);
964 .driver.name = "stmpe",