Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | i2c Support for the Apple `Hydra' Mac I/O |
| 3 | |
| 4 | Copyright (c) 1999-2004 Geert Uytterhoeven <geert@linux-m68k.org> |
| 5 | |
| 6 | Based on i2c Support for Via Technologies 82C586B South Bridge |
Jan Engelhardt | 96de0e2 | 2007-10-19 23:21:04 +0200 | [diff] [blame] | 7 | Copyright (c) 1998, 1999 Kyösti Mälkki <kmalkki@cc.hut.fi> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | |
| 9 | This program is free software; you can redistribute it and/or modify |
| 10 | it under the terms of the GNU General Public License as published by |
| 11 | the Free Software Foundation; either version 2 of the License, or |
| 12 | (at your option) any later version. |
| 13 | |
| 14 | This program is distributed in the hope that it will be useful, |
| 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | GNU General Public License for more details. |
| 18 | |
| 19 | You should have received a copy of the GNU General Public License |
| 20 | along with this program; if not, write to the Free Software |
| 21 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 22 | */ |
| 23 | |
| 24 | #include <linux/kernel.h> |
| 25 | #include <linux/module.h> |
| 26 | #include <linux/pci.h> |
| 27 | #include <linux/types.h> |
| 28 | #include <linux/i2c.h> |
| 29 | #include <linux/i2c-algo-bit.h> |
| 30 | #include <linux/init.h> |
H Hartley Sweeten | 2178218 | 2010-05-21 18:41:01 +0200 | [diff] [blame] | 31 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <asm/hydra.h> |
| 33 | |
| 34 | |
| 35 | #define HYDRA_CPD_PD0 0x00000001 /* CachePD lines */ |
| 36 | #define HYDRA_CPD_PD1 0x00000002 |
| 37 | #define HYDRA_CPD_PD2 0x00000004 |
| 38 | #define HYDRA_CPD_PD3 0x00000008 |
| 39 | |
| 40 | #define HYDRA_SCLK HYDRA_CPD_PD0 |
| 41 | #define HYDRA_SDAT HYDRA_CPD_PD1 |
| 42 | #define HYDRA_SCLK_OE 0x00000010 |
| 43 | #define HYDRA_SDAT_OE 0x00000020 |
| 44 | |
| 45 | static inline void pdregw(void *data, u32 val) |
| 46 | { |
| 47 | struct Hydra *hydra = (struct Hydra *)data; |
| 48 | writel(val, &hydra->CachePD); |
| 49 | } |
| 50 | |
| 51 | static inline u32 pdregr(void *data) |
| 52 | { |
| 53 | struct Hydra *hydra = (struct Hydra *)data; |
| 54 | return readl(&hydra->CachePD); |
| 55 | } |
| 56 | |
| 57 | static void hydra_bit_setscl(void *data, int state) |
| 58 | { |
| 59 | u32 val = pdregr(data); |
| 60 | if (state) |
| 61 | val &= ~HYDRA_SCLK_OE; |
| 62 | else { |
| 63 | val &= ~HYDRA_SCLK; |
| 64 | val |= HYDRA_SCLK_OE; |
| 65 | } |
| 66 | pdregw(data, val); |
| 67 | } |
| 68 | |
| 69 | static void hydra_bit_setsda(void *data, int state) |
| 70 | { |
| 71 | u32 val = pdregr(data); |
| 72 | if (state) |
| 73 | val &= ~HYDRA_SDAT_OE; |
| 74 | else { |
| 75 | val &= ~HYDRA_SDAT; |
| 76 | val |= HYDRA_SDAT_OE; |
| 77 | } |
| 78 | pdregw(data, val); |
| 79 | } |
| 80 | |
| 81 | static int hydra_bit_getscl(void *data) |
| 82 | { |
| 83 | return (pdregr(data) & HYDRA_SCLK) != 0; |
| 84 | } |
| 85 | |
| 86 | static int hydra_bit_getsda(void *data) |
| 87 | { |
| 88 | return (pdregr(data) & HYDRA_SDAT) != 0; |
| 89 | } |
| 90 | |
| 91 | /* ------------------------------------------------------------------------ */ |
| 92 | |
| 93 | static struct i2c_algo_bit_data hydra_bit_data = { |
| 94 | .setsda = hydra_bit_setsda, |
| 95 | .setscl = hydra_bit_setscl, |
| 96 | .getsda = hydra_bit_getsda, |
| 97 | .getscl = hydra_bit_getscl, |
| 98 | .udelay = 5, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | .timeout = HZ |
| 100 | }; |
| 101 | |
| 102 | static struct i2c_adapter hydra_adap = { |
| 103 | .owner = THIS_MODULE, |
| 104 | .name = "Hydra i2c", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | .algo_data = &hydra_bit_data, |
| 106 | }; |
| 107 | |
Axel Lin | 3527bd5 | 2012-01-12 20:32:04 +0100 | [diff] [blame] | 108 | static DEFINE_PCI_DEVICE_TABLE(hydra_ids) = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | { PCI_DEVICE(PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_HYDRA) }, |
| 110 | { 0, } |
| 111 | }; |
| 112 | |
| 113 | MODULE_DEVICE_TABLE (pci, hydra_ids); |
| 114 | |
Bill Pemberton | 0b255e9 | 2012-11-27 15:59:38 -0500 | [diff] [blame] | 115 | static int hydra_probe(struct pci_dev *dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | const struct pci_device_id *id) |
| 117 | { |
| 118 | unsigned long base = pci_resource_start(dev, 0); |
| 119 | int res; |
| 120 | |
| 121 | if (!request_mem_region(base+offsetof(struct Hydra, CachePD), 4, |
| 122 | hydra_adap.name)) |
| 123 | return -EBUSY; |
| 124 | |
Arjan van de Ven | c7a5f22 | 2008-10-22 20:21:32 +0200 | [diff] [blame] | 125 | hydra_bit_data.data = pci_ioremap_bar(dev, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | if (hydra_bit_data.data == NULL) { |
| 127 | release_mem_region(base+offsetof(struct Hydra, CachePD), 4); |
| 128 | return -ENODEV; |
| 129 | } |
| 130 | |
| 131 | pdregw(hydra_bit_data.data, 0); /* clear SCLK_OE and SDAT_OE */ |
| 132 | hydra_adap.dev.parent = &dev->dev; |
| 133 | res = i2c_bit_add_bus(&hydra_adap); |
| 134 | if (res < 0) { |
| 135 | iounmap(hydra_bit_data.data); |
| 136 | release_mem_region(base+offsetof(struct Hydra, CachePD), 4); |
| 137 | return res; |
| 138 | } |
| 139 | return 0; |
| 140 | } |
| 141 | |
Bill Pemberton | 0b255e9 | 2012-11-27 15:59:38 -0500 | [diff] [blame] | 142 | static void hydra_remove(struct pci_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | { |
| 144 | pdregw(hydra_bit_data.data, 0); /* clear SCLK_OE and SDAT_OE */ |
Jean Delvare | 3269711 | 2006-12-10 21:21:33 +0100 | [diff] [blame] | 145 | i2c_del_adapter(&hydra_adap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | iounmap(hydra_bit_data.data); |
| 147 | release_mem_region(pci_resource_start(dev, 0)+ |
| 148 | offsetof(struct Hydra, CachePD), 4); |
| 149 | } |
| 150 | |
| 151 | |
| 152 | static struct pci_driver hydra_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | .name = "hydra_smbus", |
| 154 | .id_table = hydra_ids, |
| 155 | .probe = hydra_probe, |
Bill Pemberton | 0b255e9 | 2012-11-27 15:59:38 -0500 | [diff] [blame] | 156 | .remove = hydra_remove, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | }; |
| 158 | |
Axel Lin | 56f2178 | 2012-07-24 14:13:56 +0200 | [diff] [blame] | 159 | module_pci_driver(hydra_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | |
| 161 | MODULE_AUTHOR("Geert Uytterhoeven <geert@linux-m68k.org>"); |
| 162 | MODULE_DESCRIPTION("i2c for Apple Hydra Mac I/O"); |
| 163 | MODULE_LICENSE("GPL"); |