WIP FPC-III support
[linux/fpc-iii.git] / arch / x86 / platform / intel-mid / device_libs / platform_pcal9555a.c
blob5609d8da3978ef39c51340468bbdaac50f79c57e
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * PCAL9555a platform data initialization file
5 * Copyright (C) 2016, Intel Corporation
7 * Authors: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
8 * Dan O'Donovan <dan@emutex.com>
9 */
11 #include <linux/gpio.h>
12 #include <linux/init.h>
13 #include <linux/i2c.h>
14 #include <linux/platform_data/pca953x.h>
15 #include <linux/sfi.h>
17 #include <asm/intel-mid.h>
19 #define PCAL9555A_NUM 4
21 static struct pca953x_platform_data pcal9555a_pdata[PCAL9555A_NUM];
22 static int nr;
24 static void __init *pcal9555a_platform_data(void *info)
26 struct i2c_board_info *i2c_info = info;
27 char *type = i2c_info->type;
28 struct pca953x_platform_data *pcal9555a;
29 char base_pin_name[SFI_NAME_LEN + 1];
30 char intr_pin_name[SFI_NAME_LEN + 1];
31 int gpio_base, intr;
33 snprintf(base_pin_name, sizeof(base_pin_name), "%s_base", type);
34 snprintf(intr_pin_name, sizeof(intr_pin_name), "%s_int", type);
36 gpio_base = get_gpio_by_name(base_pin_name);
37 intr = get_gpio_by_name(intr_pin_name);
39 /* Check if the SFI record valid */
40 if (gpio_base == -1)
41 return NULL;
43 if (nr >= PCAL9555A_NUM) {
44 pr_err("%s: Too many instances, only %d supported\n", __func__,
45 PCAL9555A_NUM);
46 return NULL;
49 pcal9555a = &pcal9555a_pdata[nr++];
50 pcal9555a->gpio_base = gpio_base;
52 if (intr >= 0) {
53 i2c_info->irq = intr + INTEL_MID_IRQ_OFFSET;
54 pcal9555a->irq_base = gpio_base + INTEL_MID_IRQ_OFFSET;
55 } else {
56 i2c_info->irq = -1;
57 pcal9555a->irq_base = -1;
60 strcpy(type, "pcal9555a");
61 return pcal9555a;
64 static const struct devs_id pcal9555a_1_dev_id __initconst = {
65 .name = "pcal9555a-1",
66 .type = SFI_DEV_TYPE_I2C,
67 .delay = 1,
68 .get_platform_data = &pcal9555a_platform_data,
71 static const struct devs_id pcal9555a_2_dev_id __initconst = {
72 .name = "pcal9555a-2",
73 .type = SFI_DEV_TYPE_I2C,
74 .delay = 1,
75 .get_platform_data = &pcal9555a_platform_data,
78 static const struct devs_id pcal9555a_3_dev_id __initconst = {
79 .name = "pcal9555a-3",
80 .type = SFI_DEV_TYPE_I2C,
81 .delay = 1,
82 .get_platform_data = &pcal9555a_platform_data,
85 static const struct devs_id pcal9555a_4_dev_id __initconst = {
86 .name = "pcal9555a-4",
87 .type = SFI_DEV_TYPE_I2C,
88 .delay = 1,
89 .get_platform_data = &pcal9555a_platform_data,
92 sfi_device(pcal9555a_1_dev_id);
93 sfi_device(pcal9555a_2_dev_id);
94 sfi_device(pcal9555a_3_dev_id);
95 sfi_device(pcal9555a_4_dev_id);