Skip to content

Commit 6377cfa

Browse files
agnersLee Jones
authored andcommitted
mfd: stmpe: Preparations for STMPE ADC driver
This prepares the MFD for the STMPE ADC driver. This commit introduces devicetree settings that are used by the ADC and adds an init function. Common ADC settings that are shared with the touchscreen driver can now reside in the overlying MFD. Signed-off-by: Stefan Agner <stefan@agner.ch> Signed-off-by: Max Krummenacher <max.krummenacher@toradex.com> Signed-off-by: Philippe Schenker <philippe.schenker@toradex.com> Signed-off-by: Lee Jones <lee.jones@linaro.org>
1 parent 063755a commit 6377cfa

3 files changed

Lines changed: 80 additions & 1 deletion

File tree

‎drivers/mfd/Kconfig‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1204,7 +1204,7 @@ config MFD_STMPE
12041204

12051205
Currently supported devices are:
12061206

1207-
STMPE811: GPIO, Touchscreen
1207+
STMPE811: GPIO, Touchscreen, ADC
12081208
STMPE1601: GPIO, Keypad
12091209
STMPE1801: GPIO, Keypad
12101210
STMPE2401: GPIO, Keypad
@@ -1217,6 +1217,7 @@ config MFD_STMPE
12171217
GPIO: stmpe-gpio
12181218
Keypad: stmpe-keypad
12191219
Touchscreen: stmpe-ts
1220+
ADC: stmpe-adc
12201221

12211222
menu "STMicroelectronics STMPE Interface Drivers"
12221223
depends on MFD_STMPE

‎drivers/mfd/stmpe.c‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,28 @@ static const struct mfd_cell stmpe_ts_cell = {
463463
.num_resources = ARRAY_SIZE(stmpe_ts_resources),
464464
};
465465

466+
/*
467+
* ADC (STMPE811)
468+
*/
469+
470+
static struct resource stmpe_adc_resources[] = {
471+
{
472+
.name = "STMPE_TEMP_SENS",
473+
.flags = IORESOURCE_IRQ,
474+
},
475+
{
476+
.name = "STMPE_ADC",
477+
.flags = IORESOURCE_IRQ,
478+
},
479+
};
480+
481+
static const struct mfd_cell stmpe_adc_cell = {
482+
.name = "stmpe-adc",
483+
.of_compatible = "st,stmpe-adc",
484+
.resources = stmpe_adc_resources,
485+
.num_resources = ARRAY_SIZE(stmpe_adc_resources),
486+
};
487+
466488
/*
467489
* STMPE811 or STMPE610
468490
*/
@@ -497,6 +519,11 @@ static struct stmpe_variant_block stmpe811_blocks[] = {
497519
.irq = STMPE811_IRQ_TOUCH_DET,
498520
.block = STMPE_BLOCK_TOUCHSCREEN,
499521
},
522+
{
523+
.cell = &stmpe_adc_cell,
524+
.irq = STMPE811_IRQ_TEMP_SENS,
525+
.block = STMPE_BLOCK_ADC,
526+
},
500527
};
501528

502529
static int stmpe811_enable(struct stmpe *stmpe, unsigned int blocks,
@@ -517,6 +544,35 @@ static int stmpe811_enable(struct stmpe *stmpe, unsigned int blocks,
517544
enable ? 0 : mask);
518545
}
519546

547+
int stmpe811_adc_common_init(struct stmpe *stmpe)
548+
{
549+
int ret;
550+
u8 adc_ctrl1, adc_ctrl1_mask;
551+
552+
adc_ctrl1 = STMPE_SAMPLE_TIME(stmpe->sample_time) |
553+
STMPE_MOD_12B(stmpe->mod_12b) |
554+
STMPE_REF_SEL(stmpe->ref_sel);
555+
adc_ctrl1_mask = STMPE_SAMPLE_TIME(0xff) | STMPE_MOD_12B(0xff) |
556+
STMPE_REF_SEL(0xff);
557+
558+
ret = stmpe_set_bits(stmpe, STMPE811_REG_ADC_CTRL1,
559+
adc_ctrl1_mask, adc_ctrl1);
560+
if (ret) {
561+
dev_err(stmpe->dev, "Could not setup ADC\n");
562+
return ret;
563+
}
564+
565+
ret = stmpe_set_bits(stmpe, STMPE811_REG_ADC_CTRL2,
566+
STMPE_ADC_FREQ(0xff), STMPE_ADC_FREQ(stmpe->adc_freq));
567+
if (ret) {
568+
dev_err(stmpe->dev, "Could not setup ADC\n");
569+
return ret;
570+
}
571+
572+
return 0;
573+
}
574+
EXPORT_SYMBOL_GPL(stmpe811_adc_common_init);
575+
520576
static int stmpe811_get_altfunc(struct stmpe *stmpe, enum stmpe_block block)
521577
{
522578
/* 0 for touchscreen, 1 for GPIO */
@@ -1325,6 +1381,7 @@ int stmpe_probe(struct stmpe_client_info *ci, enum stmpe_partnum partnum)
13251381
struct device_node *np = ci->dev->of_node;
13261382
struct stmpe *stmpe;
13271383
int ret;
1384+
u32 val;
13281385

13291386
pdata = devm_kzalloc(ci->dev, sizeof(*pdata), GFP_KERNEL);
13301387
if (!pdata)
@@ -1342,6 +1399,15 @@ int stmpe_probe(struct stmpe_client_info *ci, enum stmpe_partnum partnum)
13421399
mutex_init(&stmpe->irq_lock);
13431400
mutex_init(&stmpe->lock);
13441401

1402+
if (!of_property_read_u32(np, "st,sample-time", &val))
1403+
stmpe->sample_time = val;
1404+
if (!of_property_read_u32(np, "st,mod-12b", &val))
1405+
stmpe->mod_12b = val;
1406+
if (!of_property_read_u32(np, "st,ref-sel", &val))
1407+
stmpe->ref_sel = val;
1408+
if (!of_property_read_u32(np, "st,adc-freq", &val))
1409+
stmpe->adc_freq = val;
1410+
13451411
stmpe->dev = ci->dev;
13461412
stmpe->client = ci->client;
13471413
stmpe->pdata = pdata;
@@ -1433,6 +1499,8 @@ int stmpe_remove(struct stmpe *stmpe)
14331499
if (!IS_ERR(stmpe->vcc))
14341500
regulator_disable(stmpe->vcc);
14351501

1502+
__stmpe_disable(stmpe, STMPE_BLOCK_ADC);
1503+
14361504
mfd_remove_devices(stmpe->dev);
14371505

14381506
return 0;

‎include/linux/mfd/stmpe.h‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
#define STMPE_I_DRIVE(x) (x & 0x1)
2222
#define STMPE_OP_MODE(x) ((x & 0x7) << 1)
2323

24+
#define STMPE811_REG_ADC_CTRL1 0x20
25+
#define STMPE811_REG_ADC_CTRL2 0x21
26+
2427
struct device;
2528
struct regulator;
2629

@@ -134,6 +137,12 @@ struct stmpe {
134137
u8 ier[2];
135138
u8 oldier[2];
136139
struct stmpe_platform_data *pdata;
140+
141+
/* For devices that use an ADC */
142+
u8 sample_time;
143+
u8 mod_12b;
144+
u8 ref_sel;
145+
u8 adc_freq;
137146
};
138147

139148
extern int stmpe_reg_write(struct stmpe *stmpe, u8 reg, u8 data);
@@ -147,6 +156,7 @@ extern int stmpe_set_altfunc(struct stmpe *stmpe, u32 pins,
147156
enum stmpe_block block);
148157
extern int stmpe_enable(struct stmpe *stmpe, unsigned int blocks);
149158
extern int stmpe_disable(struct stmpe *stmpe, unsigned int blocks);
159+
extern int stmpe811_adc_common_init(struct stmpe *stmpe);
150160

151161
#define STMPE_GPIO_NOREQ_811_TOUCH (0xf0)
152162

0 commit comments

Comments
 (0)