Linux 4.18.10
[linux/fpc-iii.git] / arch / x86 / platform / intel-mid / device_libs / platform_pcal9555a.c
blob429a94192671e814a2e151c85121c1e9ba224f9e
1 /*
2 * PCAL9555a platform data initilization file
4 * Copyright (C) 2016, Intel Corporation
6 * Authors: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
7 * Dan O'Donovan <dan@emutex.com>
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; version 2
12 * of the License.
15 #include <linux/gpio.h>
16 #include <linux/init.h>
17 #include <linux/i2c.h>
18 #include <linux/platform_data/pca953x.h>
19 #include <linux/sfi.h>
21 #include <asm/intel-mid.h>
23 #define PCAL9555A_NUM 4
25 static struct pca953x_platform_data pcal9555a_pdata[PCAL9555A_NUM];
26 static int nr;
28 static void __init *pcal9555a_platform_data(void *info)
30 struct i2c_board_info *i2c_info = info;
31 char *type = i2c_info->type;
32 struct pca953x_platform_data *pcal9555a;
33 char base_pin_name[SFI_NAME_LEN + 1];
34 char intr_pin_name[SFI_NAME_LEN + 1];
35 int gpio_base, intr;
37 snprintf(base_pin_name, sizeof(base_pin_name), "%s_base", type);
38 snprintf(intr_pin_name, sizeof(intr_pin_name), "%s_int", type);
40 gpio_base = get_gpio_by_name(base_pin_name);
41 intr = get_gpio_by_name(intr_pin_name);
43 /* Check if the SFI record valid */
44 if (gpio_base == -1)
45 return NULL;
47 if (nr >= PCAL9555A_NUM) {
48 pr_err("%s: Too many instances, only %d supported\n", __func__,
49 PCAL9555A_NUM);
50 return NULL;
53 pcal9555a = &pcal9555a_pdata[nr++];
54 pcal9555a->gpio_base = gpio_base;
56 if (intr >= 0) {
57 i2c_info->irq = intr + INTEL_MID_IRQ_OFFSET;
58 pcal9555a->irq_base = gpio_base + INTEL_MID_IRQ_OFFSET;
59 } else {
60 i2c_info->irq = -1;
61 pcal9555a->irq_base = -1;
64 strcpy(type, "pcal9555a");
65 return pcal9555a;
68 static const struct devs_id pcal9555a_1_dev_id __initconst = {
69 .name = "pcal9555a-1",
70 .type = SFI_DEV_TYPE_I2C,
71 .delay = 1,
72 .get_platform_data = &pcal9555a_platform_data,
75 static const struct devs_id pcal9555a_2_dev_id __initconst = {
76 .name = "pcal9555a-2",
77 .type = SFI_DEV_TYPE_I2C,
78 .delay = 1,
79 .get_platform_data = &pcal9555a_platform_data,
82 static const struct devs_id pcal9555a_3_dev_id __initconst = {
83 .name = "pcal9555a-3",
84 .type = SFI_DEV_TYPE_I2C,
85 .delay = 1,
86 .get_platform_data = &pcal9555a_platform_data,
89 static const struct devs_id pcal9555a_4_dev_id __initconst = {
90 .name = "pcal9555a-4",
91 .type = SFI_DEV_TYPE_I2C,
92 .delay = 1,
93 .get_platform_data = &pcal9555a_platform_data,
96 sfi_device(pcal9555a_1_dev_id);
97 sfi_device(pcal9555a_2_dev_id);
98 sfi_device(pcal9555a_3_dev_id);
99 sfi_device(pcal9555a_4_dev_id);