Skip to content

Commit 230f13a

Browse files
Jean-Nicolas GrauxSamuel Ortiz
authored andcommitted
mfd: support stmpe1801 18 bits enhanced port expander
Provides support for 1801 variant of stmpe gpio port expanders. This chip has 18 gpios configurable as GPI, GPO, keypad matrix, special key or dedicated key function. Note that special/dedicated key function is not supported yet. Signed-off-by: Jean-Nicolas Graux <jean-nicolas.graux@stericsson.com> Acked-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
1 parent e65ad41 commit 230f13a

5 files changed

Lines changed: 150 additions & 1 deletion

File tree

‎drivers/mfd/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ config MFD_STMPE
393393

394394
STMPE811: GPIO, Touchscreen
395395
STMPE1601: GPIO, Keypad
396+
STMPE1801: GPIO, Keypad
396397
STMPE2401: GPIO, Keypad
397398
STMPE2403: GPIO, Keypad
398399

‎drivers/mfd/stmpe-i2c.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ static const struct i2c_device_id stmpe_i2c_id[] = {
7575
{ "stmpe801", STMPE801 },
7676
{ "stmpe811", STMPE811 },
7777
{ "stmpe1601", STMPE1601 },
78+
{ "stmpe1801", STMPE1801 },
7879
{ "stmpe2401", STMPE2401 },
7980
{ "stmpe2403", STMPE2403 },
8081
{ }

‎drivers/mfd/stmpe.c‎

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/pm.h>
2020
#include <linux/slab.h>
2121
#include <linux/mfd/core.h>
22+
#include <linux/delay.h>
2223
#include "stmpe.h"
2324

2425
static int __stmpe_enable(struct stmpe *stmpe, unsigned int blocks)
@@ -642,6 +643,88 @@ static struct stmpe_variant_info stmpe1601 = {
642643
.enable_autosleep = stmpe1601_autosleep,
643644
};
644645

646+
/*
647+
* STMPE1801
648+
*/
649+
static const u8 stmpe1801_regs[] = {
650+
[STMPE_IDX_CHIP_ID] = STMPE1801_REG_CHIP_ID,
651+
[STMPE_IDX_ICR_LSB] = STMPE1801_REG_INT_CTRL_LOW,
652+
[STMPE_IDX_IER_LSB] = STMPE1801_REG_INT_EN_MASK_LOW,
653+
[STMPE_IDX_ISR_LSB] = STMPE1801_REG_INT_STA_LOW,
654+
[STMPE_IDX_GPMR_LSB] = STMPE1801_REG_GPIO_MP_LOW,
655+
[STMPE_IDX_GPSR_LSB] = STMPE1801_REG_GPIO_SET_LOW,
656+
[STMPE_IDX_GPCR_LSB] = STMPE1801_REG_GPIO_CLR_LOW,
657+
[STMPE_IDX_GPDR_LSB] = STMPE1801_REG_GPIO_SET_DIR_LOW,
658+
[STMPE_IDX_GPRER_LSB] = STMPE1801_REG_GPIO_RE_LOW,
659+
[STMPE_IDX_GPFER_LSB] = STMPE1801_REG_GPIO_FE_LOW,
660+
[STMPE_IDX_IEGPIOR_LSB] = STMPE1801_REG_INT_EN_GPIO_MASK_LOW,
661+
[STMPE_IDX_ISGPIOR_LSB] = STMPE1801_REG_INT_STA_GPIO_LOW,
662+
};
663+
664+
static struct stmpe_variant_block stmpe1801_blocks[] = {
665+
{
666+
.cell = &stmpe_gpio_cell,
667+
.irq = STMPE1801_IRQ_GPIOC,
668+
.block = STMPE_BLOCK_GPIO,
669+
},
670+
{
671+
.cell = &stmpe_keypad_cell,
672+
.irq = STMPE1801_IRQ_KEYPAD,
673+
.block = STMPE_BLOCK_KEYPAD,
674+
},
675+
};
676+
677+
static int stmpe1801_enable(struct stmpe *stmpe, unsigned int blocks,
678+
bool enable)
679+
{
680+
unsigned int mask = 0;
681+
if (blocks & STMPE_BLOCK_GPIO)
682+
mask |= STMPE1801_MSK_INT_EN_GPIO;
683+
684+
if (blocks & STMPE_BLOCK_KEYPAD)
685+
mask |= STMPE1801_MSK_INT_EN_KPC;
686+
687+
return __stmpe_set_bits(stmpe, STMPE1801_REG_INT_EN_MASK_LOW, mask,
688+
enable ? mask : 0);
689+
}
690+
691+
static int stmpe1801_reset(struct stmpe *stmpe)
692+
{
693+
unsigned long timeout;
694+
int ret = 0;
695+
696+
ret = __stmpe_set_bits(stmpe, STMPE1801_REG_SYS_CTRL,
697+
STMPE1801_MSK_SYS_CTRL_RESET, STMPE1801_MSK_SYS_CTRL_RESET);
698+
if (ret < 0)
699+
return ret;
700+
701+
timeout = jiffies + msecs_to_jiffies(100);
702+
while (time_before(jiffies, timeout)) {
703+
ret = __stmpe_reg_read(stmpe, STMPE1801_REG_SYS_CTRL);
704+
if (ret < 0)
705+
return ret;
706+
if (!(ret & STMPE1801_MSK_SYS_CTRL_RESET))
707+
return 0;
708+
usleep_range(100, 200);
709+
};
710+
return -EIO;
711+
}
712+
713+
static struct stmpe_variant_info stmpe1801 = {
714+
.name = "stmpe1801",
715+
.id_val = STMPE1801_ID,
716+
.id_mask = 0xfff0,
717+
.num_gpios = 18,
718+
.af_bits = 0,
719+
.regs = stmpe1801_regs,
720+
.blocks = stmpe1801_blocks,
721+
.num_blocks = ARRAY_SIZE(stmpe1801_blocks),
722+
.num_irqs = STMPE1801_NR_INTERNAL_IRQS,
723+
.enable = stmpe1801_enable,
724+
/* stmpe1801 do not have any gpio alternate function */
725+
.get_altfunc = NULL,
726+
};
727+
645728
/*
646729
* STMPE24XX
647730
*/
@@ -740,6 +823,7 @@ static struct stmpe_variant_info *stmpe_variant_info[STMPE_NBR_PARTS] = {
740823
[STMPE801] = &stmpe801,
741824
[STMPE811] = &stmpe811,
742825
[STMPE1601] = &stmpe1601,
826+
[STMPE1801] = &stmpe1801,
743827
[STMPE2401] = &stmpe2401,
744828
[STMPE2403] = &stmpe2403,
745829
};
@@ -759,7 +843,7 @@ static irqreturn_t stmpe_irq(int irq, void *data)
759843
struct stmpe *stmpe = data;
760844
struct stmpe_variant_info *variant = stmpe->variant;
761845
int num = DIV_ROUND_UP(variant->num_irqs, 8);
762-
u8 israddr = stmpe->regs[STMPE_IDX_ISR_MSB];
846+
u8 israddr;
763847
u8 isr[num];
764848
int ret;
765849
int i;
@@ -771,6 +855,11 @@ static irqreturn_t stmpe_irq(int irq, void *data)
771855
return IRQ_HANDLED;
772856
}
773857

858+
if (variant->id_val == STMPE1801_ID)
859+
israddr = stmpe->regs[STMPE_IDX_ISR_LSB];
860+
else
861+
israddr = stmpe->regs[STMPE_IDX_ISR_MSB];
862+
774863
ret = stmpe_block_read(stmpe, israddr, num, isr);
775864
if (ret < 0)
776865
return IRQ_NONE;
@@ -938,6 +1027,12 @@ static int stmpe_chip_init(struct stmpe *stmpe)
9381027
if (ret)
9391028
return ret;
9401029

1030+
if (id == STMPE1801_ID) {
1031+
ret = stmpe1801_reset(stmpe);
1032+
if (ret < 0)
1033+
return ret;
1034+
}
1035+
9411036
if (stmpe->irq >= 0) {
9421037
if (id == STMPE801_ID)
9431038
icr = STMPE801_REG_SYS_CTRL_INT_EN;

‎drivers/mfd/stmpe.h‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,55 @@ int stmpe_remove(struct stmpe *stmpe);
198198
#define STMPE1601_AUTOSLEEP_TIMEOUT_MASK (0x7)
199199
#define STPME1601_AUTOSLEEP_ENABLE (1 << 3)
200200

201+
/*
202+
* STMPE1801
203+
*/
204+
#define STMPE1801_ID 0xc110
205+
#define STMPE1801_NR_INTERNAL_IRQS 5
206+
#define STMPE1801_IRQ_KEYPAD_COMBI 4
207+
#define STMPE1801_IRQ_GPIOC 3
208+
#define STMPE1801_IRQ_KEYPAD_OVER 2
209+
#define STMPE1801_IRQ_KEYPAD 1
210+
#define STMPE1801_IRQ_WAKEUP 0
211+
212+
#define STMPE1801_REG_CHIP_ID 0x00
213+
#define STMPE1801_REG_SYS_CTRL 0x02
214+
#define STMPE1801_REG_INT_CTRL_LOW 0x04
215+
#define STMPE1801_REG_INT_EN_MASK_LOW 0x06
216+
#define STMPE1801_REG_INT_STA_LOW 0x08
217+
#define STMPE1801_REG_INT_EN_GPIO_MASK_LOW 0x0A
218+
#define STMPE1801_REG_INT_EN_GPIO_MASK_MID 0x0B
219+
#define STMPE1801_REG_INT_EN_GPIO_MASK_HIGH 0x0C
220+
#define STMPE1801_REG_INT_STA_GPIO_LOW 0x0D
221+
#define STMPE1801_REG_INT_STA_GPIO_MID 0x0E
222+
#define STMPE1801_REG_INT_STA_GPIO_HIGH 0x0F
223+
#define STMPE1801_REG_GPIO_SET_LOW 0x10
224+
#define STMPE1801_REG_GPIO_SET_MID 0x11
225+
#define STMPE1801_REG_GPIO_SET_HIGH 0x12
226+
#define STMPE1801_REG_GPIO_CLR_LOW 0x13
227+
#define STMPE1801_REG_GPIO_CLR_MID 0x14
228+
#define STMPE1801_REG_GPIO_CLR_HIGH 0x15
229+
#define STMPE1801_REG_GPIO_MP_LOW 0x16
230+
#define STMPE1801_REG_GPIO_MP_MID 0x17
231+
#define STMPE1801_REG_GPIO_MP_HIGH 0x18
232+
#define STMPE1801_REG_GPIO_SET_DIR_LOW 0x19
233+
#define STMPE1801_REG_GPIO_SET_DIR_MID 0x1A
234+
#define STMPE1801_REG_GPIO_SET_DIR_HIGH 0x1B
235+
#define STMPE1801_REG_GPIO_RE_LOW 0x1C
236+
#define STMPE1801_REG_GPIO_RE_MID 0x1D
237+
#define STMPE1801_REG_GPIO_RE_HIGH 0x1E
238+
#define STMPE1801_REG_GPIO_FE_LOW 0x1F
239+
#define STMPE1801_REG_GPIO_FE_MID 0x20
240+
#define STMPE1801_REG_GPIO_FE_HIGH 0x21
241+
#define STMPE1801_REG_GPIO_PULL_UP_LOW 0x22
242+
#define STMPE1801_REG_GPIO_PULL_UP_MID 0x23
243+
#define STMPE1801_REG_GPIO_PULL_UP_HIGH 0x24
244+
245+
#define STMPE1801_MSK_SYS_CTRL_RESET (1 << 7)
246+
247+
#define STMPE1801_MSK_INT_EN_KPC (1 << 1)
248+
#define STMPE1801_MSK_INT_EN_GPIO (1 << 3)
249+
201250
/*
202251
* STMPE24xx
203252
*/

‎include/linux/mfd/stmpe.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ enum stmpe_partnum {
2626
STMPE801,
2727
STMPE811,
2828
STMPE1601,
29+
STMPE1801,
2930
STMPE2401,
3031
STMPE2403,
3132
STMPE_NBR_PARTS
@@ -39,6 +40,7 @@ enum {
3940
STMPE_IDX_CHIP_ID,
4041
STMPE_IDX_ICR_LSB,
4142
STMPE_IDX_IER_LSB,
43+
STMPE_IDX_ISR_LSB,
4244
STMPE_IDX_ISR_MSB,
4345
STMPE_IDX_GPMR_LSB,
4446
STMPE_IDX_GPSR_LSB,
@@ -49,6 +51,7 @@ enum {
4951
STMPE_IDX_GPFER_LSB,
5052
STMPE_IDX_GPAFR_U_MSB,
5153
STMPE_IDX_IEGPIOR_LSB,
54+
STMPE_IDX_ISGPIOR_LSB,
5255
STMPE_IDX_ISGPIOR_MSB,
5356
STMPE_IDX_MAX,
5457
};

0 commit comments

Comments
 (0)