1/*
2 * platform_max7315.c: max7315 platform data initilization file
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
21static 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++) {
41		sprintf(base_pin_name, "max7315_%d_base", nr);
42		sprintf(intr_pin_name, "max7315_%d_int", nr);
43	} else {
44		strcpy(base_pin_name, "max7315_base");
45		strcpy(intr_pin_name, "max7315_int");
46	}
47
48	gpio_base = get_gpio_by_name(base_pin_name);
49	intr = get_gpio_by_name(intr_pin_name);
50
51	if (gpio_base < 0)
52		return NULL;
53	max7315->gpio_base = gpio_base;
54	if (intr != -1) {
55		i2c_info->irq = intr + INTEL_MID_IRQ_OFFSET;
56		max7315->irq_base = gpio_base + INTEL_MID_IRQ_OFFSET;
57	} else {
58		i2c_info->irq = -1;
59		max7315->irq_base = -1;
60	}
61	return max7315;
62}
63
64static const struct devs_id max7315_dev_id __initconst = {
65	.name = "i2c_max7315",
66	.type = SFI_DEV_TYPE_I2C,
67	.delay = 1,
68	.get_platform_data = &max7315_platform_data,
69};
70
71static const struct devs_id max7315_2_dev_id __initconst = {
72	.name = "i2c_max7315_2",
73	.type = SFI_DEV_TYPE_I2C,
74	.delay = 1,
75	.get_platform_data = &max7315_platform_data,
76};
77
78sfi_device(max7315_dev_id);
79sfi_device(max7315_2_dev_id);
80