]>
Commit | Line | Data |
---|---|---|
40a96d54 | 1 | /* |
6a6256f9 | 2 | * platform_max7315.c: max7315 platform data initialization file |
40a96d54 DC |
3 | * |
4 | * (C) Copyright 2013 Intel Corporation | |
5 | * Author: Sathyanarayanan Kuppuswamy <sathyanarayanan.kuppuswamy@intel.com> | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or | |
8 | * modify it under the terms of the GNU General Public License | |
9 | * as published by the Free Software Foundation; version 2 | |
10 | * of the License. | |
11 | */ | |
12 | ||
13 | #include <linux/init.h> | |
14 | #include <linux/gpio.h> | |
15 | #include <linux/i2c.h> | |
16 | #include <linux/platform_data/pca953x.h> | |
17 | #include <asm/intel-mid.h> | |
18 | ||
19 | #define MAX7315_NUM 2 | |
20 | ||
21 | static void __init *max7315_platform_data(void *info) | |
22 | { | |
23 | static struct pca953x_platform_data max7315_pdata[MAX7315_NUM]; | |
24 | static int nr; | |
25 | struct pca953x_platform_data *max7315 = &max7315_pdata[nr]; | |
26 | struct i2c_board_info *i2c_info = info; | |
27 | int gpio_base, intr; | |
28 | char base_pin_name[SFI_NAME_LEN + 1]; | |
29 | char intr_pin_name[SFI_NAME_LEN + 1]; | |
30 | ||
31 | if (nr == MAX7315_NUM) { | |
32 | pr_err("too many max7315s, we only support %d\n", | |
33 | MAX7315_NUM); | |
34 | return NULL; | |
35 | } | |
36 | /* we have several max7315 on the board, we only need load several | |
37 | * instances of the same pca953x driver to cover them | |
38 | */ | |
39 | strcpy(i2c_info->type, "max7315"); | |
40 | if (nr++) { | |
0bc73048 AB |
41 | snprintf(base_pin_name, sizeof(base_pin_name), |
42 | "max7315_%d_base", nr); | |
43 | snprintf(intr_pin_name, sizeof(intr_pin_name), | |
44 | "max7315_%d_int", nr); | |
40a96d54 DC |
45 | } else { |
46 | strcpy(base_pin_name, "max7315_base"); | |
47 | strcpy(intr_pin_name, "max7315_int"); | |
48 | } | |
49 | ||
50 | gpio_base = get_gpio_by_name(base_pin_name); | |
51 | intr = get_gpio_by_name(intr_pin_name); | |
52 | ||
a957a14b | 53 | if (gpio_base < 0) |
40a96d54 DC |
54 | return NULL; |
55 | max7315->gpio_base = gpio_base; | |
56 | if (intr != -1) { | |
57 | i2c_info->irq = intr + INTEL_MID_IRQ_OFFSET; | |
58 | max7315->irq_base = gpio_base + INTEL_MID_IRQ_OFFSET; | |
59 | } else { | |
60 | i2c_info->irq = -1; | |
61 | max7315->irq_base = -1; | |
62 | } | |
63 | return max7315; | |
64 | } | |
65 | ||
66 | static const struct devs_id max7315_dev_id __initconst = { | |
67 | .name = "i2c_max7315", | |
68 | .type = SFI_DEV_TYPE_I2C, | |
69 | .delay = 1, | |
70 | .get_platform_data = &max7315_platform_data, | |
71 | }; | |
72 | ||
73 | static const struct devs_id max7315_2_dev_id __initconst = { | |
74 | .name = "i2c_max7315_2", | |
75 | .type = SFI_DEV_TYPE_I2C, | |
76 | .delay = 1, | |
77 | .get_platform_data = &max7315_platform_data, | |
78 | }; | |
79 | ||
80 | sfi_device(max7315_dev_id); | |
81 | sfi_device(max7315_2_dev_id); |