i2c.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Helper module for board specific I2C bus registration
  3. *
  4. * Copyright (C) 2009 Nokia Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * version 2 as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  18. * 02110-1301 USA
  19. *
  20. */
  21. #include <linux/i2c-omap.h>
  22. #include <mach/mux.h>
  23. #include "soc.h"
  24. #include <plat/i2c.h>
  25. #define OMAP_I2C_SIZE 0x3f
  26. #define OMAP1_I2C_BASE 0xfffb3800
  27. static const char name[] = "omap_i2c";
  28. static struct resource i2c_resources[2] = {
  29. };
  30. static struct platform_device omap_i2c_devices[1] = {
  31. };
  32. static void __init omap1_i2c_mux_pins(int bus_id)
  33. {
  34. if (cpu_is_omap7xx()) {
  35. omap_cfg_reg(I2C_7XX_SDA);
  36. omap_cfg_reg(I2C_7XX_SCL);
  37. } else {
  38. omap_cfg_reg(I2C_SDA);
  39. omap_cfg_reg(I2C_SCL);
  40. }
  41. }
  42. int __init omap_i2c_add_bus(struct omap_i2c_bus_platform_data *pdata,
  43. int bus_id)
  44. {
  45. struct platform_device *pdev;
  46. struct resource *res;
  47. if (bus_id > 1)
  48. return -EINVAL;
  49. omap1_i2c_mux_pins(bus_id);
  50. pdev = &omap_i2c_devices[bus_id - 1];
  51. pdev->id = bus_id;
  52. pdev->name = name;
  53. pdev->num_resources = ARRAY_SIZE(i2c_resources);
  54. res = i2c_resources;
  55. res[0].start = OMAP1_I2C_BASE;
  56. res[0].end = res[0].start + OMAP_I2C_SIZE;
  57. res[0].flags = IORESOURCE_MEM;
  58. res[1].start = INT_I2C;
  59. res[1].flags = IORESOURCE_IRQ;
  60. pdev->resource = res;
  61. /* all OMAP1 have IP version 1 register set */
  62. pdata->rev = OMAP_I2C_IP_VERSION_1;
  63. /* all OMAP1 I2C are implemented like this */
  64. pdata->flags = OMAP_I2C_FLAG_NO_FIFO |
  65. OMAP_I2C_FLAG_SIMPLE_CLOCK |
  66. OMAP_I2C_FLAG_16BIT_DATA_REG |
  67. OMAP_I2C_FLAG_ALWAYS_ARMXOR_CLK;
  68. /* how the cpu bus is wired up differs for 7xx only */
  69. if (cpu_is_omap7xx())
  70. pdata->flags |= OMAP_I2C_FLAG_BUS_SHIFT_1;
  71. else
  72. pdata->flags |= OMAP_I2C_FLAG_BUS_SHIFT_2;
  73. pdev->dev.platform_data = pdata;
  74. return platform_device_register(pdev);
  75. }
  76. static int __init omap_i2c_cmdline(void)
  77. {
  78. return omap_register_i2c_bus_cmdline();
  79. }
  80. subsys_initcall(omap_i2c_cmdline);