platform_max7315.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * platform_max7315.c: max7315 platform data initialization 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. #include <linux/init.h>
  13. #include <linux/gpio.h>
  14. #include <linux/i2c.h>
  15. #include <linux/platform_data/pca953x.h>
  16. #include <asm/intel-mid.h>
  17. #define MAX7315_NUM 2
  18. static void __init *max7315_platform_data(void *info)
  19. {
  20. static struct pca953x_platform_data max7315_pdata[MAX7315_NUM];
  21. static int nr;
  22. struct pca953x_platform_data *max7315 = &max7315_pdata[nr];
  23. struct i2c_board_info *i2c_info = info;
  24. int gpio_base, intr;
  25. char base_pin_name[SFI_NAME_LEN + 1];
  26. char intr_pin_name[SFI_NAME_LEN + 1];
  27. if (nr == MAX7315_NUM) {
  28. pr_err("too many max7315s, we only support %d\n",
  29. MAX7315_NUM);
  30. return NULL;
  31. }
  32. /* we have several max7315 on the board, we only need load several
  33. * instances of the same pca953x driver to cover them
  34. */
  35. strcpy(i2c_info->type, "max7315");
  36. if (nr++) {
  37. sprintf(base_pin_name, "max7315_%d_base", nr);
  38. sprintf(intr_pin_name, "max7315_%d_int", nr);
  39. } else {
  40. strcpy(base_pin_name, "max7315_base");
  41. strcpy(intr_pin_name, "max7315_int");
  42. }
  43. gpio_base = get_gpio_by_name(base_pin_name);
  44. intr = get_gpio_by_name(intr_pin_name);
  45. if (gpio_base < 0)
  46. return NULL;
  47. max7315->gpio_base = gpio_base;
  48. if (intr != -1) {
  49. i2c_info->irq = intr + INTEL_MID_IRQ_OFFSET;
  50. max7315->irq_base = gpio_base + INTEL_MID_IRQ_OFFSET;
  51. } else {
  52. i2c_info->irq = -1;
  53. max7315->irq_base = -1;
  54. }
  55. return max7315;
  56. }
  57. static const struct devs_id max7315_dev_id __initconst = {
  58. .name = "i2c_max7315",
  59. .type = SFI_DEV_TYPE_I2C,
  60. .delay = 1,
  61. .get_platform_data = &max7315_platform_data,
  62. };
  63. static const struct devs_id max7315_2_dev_id __initconst = {
  64. .name = "i2c_max7315_2",
  65. .type = SFI_DEV_TYPE_I2C,
  66. .delay = 1,
  67. .get_platform_data = &max7315_platform_data,
  68. };
  69. sfi_device(max7315_dev_id);
  70. sfi_device(max7315_2_dev_id);