• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * PCAL9555a platform data initialization file
4  *
5  * Copyright (C) 2016, Intel Corporation
6  *
7  * Authors: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
8  *	    Dan O'Donovan <dan@emutex.com>
9  */
10 
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>
16 
17 #include <asm/intel-mid.h>
18 
19 #define PCAL9555A_NUM	4
20 
21 static struct pca953x_platform_data pcal9555a_pdata[PCAL9555A_NUM];
22 static int nr;
23 
pcal9555a_platform_data(void * info)24 static void __init *pcal9555a_platform_data(void *info)
25 {
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;
32 
33 	snprintf(base_pin_name, sizeof(base_pin_name), "%s_base", type);
34 	snprintf(intr_pin_name, sizeof(intr_pin_name), "%s_int", type);
35 
36 	gpio_base = get_gpio_by_name(base_pin_name);
37 	intr = get_gpio_by_name(intr_pin_name);
38 
39 	/* Check if the SFI record valid */
40 	if (gpio_base == -1)
41 		return NULL;
42 
43 	if (nr >= PCAL9555A_NUM) {
44 		pr_err("%s: Too many instances, only %d supported\n", __func__,
45 		       PCAL9555A_NUM);
46 		return NULL;
47 	}
48 
49 	pcal9555a = &pcal9555a_pdata[nr++];
50 	pcal9555a->gpio_base = gpio_base;
51 
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;
58 	}
59 
60 	strcpy(type, "pcal9555a");
61 	return pcal9555a;
62 }
63 
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,
69 };
70 
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,
76 };
77 
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,
83 };
84 
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,
90 };
91 
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);
96