i2c-hydra.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. i2c Support for the Apple `Hydra' Mac I/O
  3. Copyright (c) 1999-2004 Geert Uytterhoeven <geert@linux-m68k.org>
  4. Based on i2c Support for Via Technologies 82C586B South Bridge
  5. Copyright (c) 1998, 1999 Kyösti Mälkki <kmalkki@cc.hut.fi>
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/module.h>
  17. #include <linux/pci.h>
  18. #include <linux/types.h>
  19. #include <linux/i2c.h>
  20. #include <linux/i2c-algo-bit.h>
  21. #include <linux/io.h>
  22. #include <asm/hydra.h>
  23. #define HYDRA_CPD_PD0 0x00000001 /* CachePD lines */
  24. #define HYDRA_CPD_PD1 0x00000002
  25. #define HYDRA_CPD_PD2 0x00000004
  26. #define HYDRA_CPD_PD3 0x00000008
  27. #define HYDRA_SCLK HYDRA_CPD_PD0
  28. #define HYDRA_SDAT HYDRA_CPD_PD1
  29. #define HYDRA_SCLK_OE 0x00000010
  30. #define HYDRA_SDAT_OE 0x00000020
  31. static inline void pdregw(void *data, u32 val)
  32. {
  33. struct Hydra *hydra = (struct Hydra *)data;
  34. writel(val, &hydra->CachePD);
  35. }
  36. static inline u32 pdregr(void *data)
  37. {
  38. struct Hydra *hydra = (struct Hydra *)data;
  39. return readl(&hydra->CachePD);
  40. }
  41. static void hydra_bit_setscl(void *data, int state)
  42. {
  43. u32 val = pdregr(data);
  44. if (state)
  45. val &= ~HYDRA_SCLK_OE;
  46. else {
  47. val &= ~HYDRA_SCLK;
  48. val |= HYDRA_SCLK_OE;
  49. }
  50. pdregw(data, val);
  51. }
  52. static void hydra_bit_setsda(void *data, int state)
  53. {
  54. u32 val = pdregr(data);
  55. if (state)
  56. val &= ~HYDRA_SDAT_OE;
  57. else {
  58. val &= ~HYDRA_SDAT;
  59. val |= HYDRA_SDAT_OE;
  60. }
  61. pdregw(data, val);
  62. }
  63. static int hydra_bit_getscl(void *data)
  64. {
  65. return (pdregr(data) & HYDRA_SCLK) != 0;
  66. }
  67. static int hydra_bit_getsda(void *data)
  68. {
  69. return (pdregr(data) & HYDRA_SDAT) != 0;
  70. }
  71. /* ------------------------------------------------------------------------ */
  72. static struct i2c_algo_bit_data hydra_bit_data = {
  73. .setsda = hydra_bit_setsda,
  74. .setscl = hydra_bit_setscl,
  75. .getsda = hydra_bit_getsda,
  76. .getscl = hydra_bit_getscl,
  77. .udelay = 5,
  78. .timeout = HZ
  79. };
  80. static struct i2c_adapter hydra_adap = {
  81. .owner = THIS_MODULE,
  82. .name = "Hydra i2c",
  83. .algo_data = &hydra_bit_data,
  84. };
  85. static const struct pci_device_id hydra_ids[] = {
  86. { PCI_DEVICE(PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_HYDRA) },
  87. { 0, }
  88. };
  89. MODULE_DEVICE_TABLE (pci, hydra_ids);
  90. static int hydra_probe(struct pci_dev *dev,
  91. const struct pci_device_id *id)
  92. {
  93. unsigned long base = pci_resource_start(dev, 0);
  94. int res;
  95. if (!request_mem_region(base+offsetof(struct Hydra, CachePD), 4,
  96. hydra_adap.name))
  97. return -EBUSY;
  98. hydra_bit_data.data = pci_ioremap_bar(dev, 0);
  99. if (hydra_bit_data.data == NULL) {
  100. release_mem_region(base+offsetof(struct Hydra, CachePD), 4);
  101. return -ENODEV;
  102. }
  103. pdregw(hydra_bit_data.data, 0); /* clear SCLK_OE and SDAT_OE */
  104. hydra_adap.dev.parent = &dev->dev;
  105. res = i2c_bit_add_bus(&hydra_adap);
  106. if (res < 0) {
  107. iounmap(hydra_bit_data.data);
  108. release_mem_region(base+offsetof(struct Hydra, CachePD), 4);
  109. return res;
  110. }
  111. return 0;
  112. }
  113. static void hydra_remove(struct pci_dev *dev)
  114. {
  115. pdregw(hydra_bit_data.data, 0); /* clear SCLK_OE and SDAT_OE */
  116. i2c_del_adapter(&hydra_adap);
  117. iounmap(hydra_bit_data.data);
  118. release_mem_region(pci_resource_start(dev, 0)+
  119. offsetof(struct Hydra, CachePD), 4);
  120. }
  121. static struct pci_driver hydra_driver = {
  122. .name = "hydra_smbus",
  123. .id_table = hydra_ids,
  124. .probe = hydra_probe,
  125. .remove = hydra_remove,
  126. };
  127. module_pci_driver(hydra_driver);
  128. MODULE_AUTHOR("Geert Uytterhoeven <geert@linux-m68k.org>");
  129. MODULE_DESCRIPTION("i2c for Apple Hydra Mac I/O");
  130. MODULE_LICENSE("GPL");