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