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#include <linux/delay.h>
37#include <linux/init.h>
38#include <linux/io.h>
39#include <linux/ioport.h>
40#include <linux/kernel.h>
41#include <linux/module.h>
42
43#include <linux/i2c.h>
44#include <linux/i2c-algo-pcf.h>
45
46#include <asm/amigaints.h>
47#include <linux/zorro.h>
48
49#include "../algos/i2c-algo-pcf.h"
50
51struct icy_i2c {
52 struct i2c_adapter adapter;
53
54 void __iomem *reg_s0;
55 void __iomem *reg_s1;
56 struct fwnode_handle *ltc2990_fwnode;
57 struct i2c_client *ltc2990_client;
58};
59
60
61
62
63static void icy_pcf_setpcf(void *data, int ctl, int val)
64{
65 struct icy_i2c *i2c = (struct icy_i2c *)data;
66
67 u8 __iomem *address = ctl ? i2c->reg_s1 : i2c->reg_s0;
68
69 z_writeb(val, address);
70}
71
72static int icy_pcf_getpcf(void *data, int ctl)
73{
74 struct icy_i2c *i2c = (struct icy_i2c *)data;
75
76 u8 __iomem *address = ctl ? i2c->reg_s1 : i2c->reg_s0;
77
78 return z_readb(address);
79}
80
81static int icy_pcf_getown(void *data)
82{
83 return 0x55;
84}
85
86static int icy_pcf_getclock(void *data)
87{
88 return 0x1c;
89}
90
91static void icy_pcf_waitforpin(void *data)
92{
93 usleep_range(50, 150);
94}
95
96
97
98
99static unsigned short const icy_ltc2990_addresses[] = {
100 0x4c, 0x4d, 0x4e, 0x4f, I2C_CLIENT_END
101};
102
103
104
105
106
107
108
109
110static const u32 icy_ltc2990_meas_mode[] = {0, 3};
111
112static const struct property_entry icy_ltc2990_props[] = {
113 PROPERTY_ENTRY_U32_ARRAY("lltc,meas-mode", icy_ltc2990_meas_mode),
114 { }
115};
116
117static int icy_probe(struct zorro_dev *z,
118 const struct zorro_device_id *ent)
119{
120 struct icy_i2c *i2c;
121 struct i2c_algo_pcf_data *algo_data;
122 struct fwnode_handle *new_fwnode;
123 struct i2c_board_info ltc2990_info = {
124 .type = "ltc2990",
125 };
126
127 i2c = devm_kzalloc(&z->dev, sizeof(*i2c), GFP_KERNEL);
128 if (!i2c)
129 return -ENOMEM;
130
131 algo_data = devm_kzalloc(&z->dev, sizeof(*algo_data), GFP_KERNEL);
132 if (!algo_data)
133 return -ENOMEM;
134
135 dev_set_drvdata(&z->dev, i2c);
136 i2c->adapter.dev.parent = &z->dev;
137 i2c->adapter.owner = THIS_MODULE;
138
139 i2c->adapter.algo_data = algo_data;
140 strlcpy(i2c->adapter.name, "ICY I2C Zorro adapter",
141 sizeof(i2c->adapter.name));
142
143 if (!devm_request_mem_region(&z->dev,
144 z->resource.start,
145 4, i2c->adapter.name))
146 return -ENXIO;
147
148
149 i2c->reg_s0 = ZTWO_VADDR(z->resource.start);
150 i2c->reg_s1 = ZTWO_VADDR(z->resource.start + 2);
151
152 algo_data->data = i2c;
153 algo_data->setpcf = icy_pcf_setpcf;
154 algo_data->getpcf = icy_pcf_getpcf;
155 algo_data->getown = icy_pcf_getown;
156 algo_data->getclock = icy_pcf_getclock;
157 algo_data->waitforpin = icy_pcf_waitforpin;
158
159 if (i2c_pcf_add_bus(&i2c->adapter)) {
160 dev_err(&z->dev, "i2c_pcf_add_bus() failed\n");
161 return -ENXIO;
162 }
163
164 dev_info(&z->dev, "ICY I2C controller at %pa, IRQ not implemented\n",
165 &z->resource.start);
166
167
168
169
170
171
172
173
174
175
176 new_fwnode = fwnode_create_software_node(icy_ltc2990_props, NULL);
177 if (IS_ERR(new_fwnode)) {
178 dev_info(&z->dev, "Failed to create fwnode for LTC2990, error: %ld\n",
179 PTR_ERR(new_fwnode));
180 } else {
181
182
183
184
185
186 i2c->ltc2990_fwnode = new_fwnode;
187 ltc2990_info.fwnode = new_fwnode;
188
189 i2c->ltc2990_client =
190 i2c_new_scanned_device(&i2c->adapter,
191 <c2990_info,
192 icy_ltc2990_addresses,
193 NULL);
194 }
195
196 return 0;
197}
198
199static void icy_remove(struct zorro_dev *z)
200{
201 struct icy_i2c *i2c = dev_get_drvdata(&z->dev);
202
203 i2c_unregister_device(i2c->ltc2990_client);
204 fwnode_remove_software_node(i2c->ltc2990_fwnode);
205
206 i2c_del_adapter(&i2c->adapter);
207}
208
209static const struct zorro_device_id icy_zorro_tbl[] = {
210 { ZORRO_ID(VMC, 15, 0), },
211 { 0 }
212};
213
214MODULE_DEVICE_TABLE(zorro, icy_zorro_tbl);
215
216static struct zorro_driver icy_driver = {
217 .name = "i2c-icy",
218 .id_table = icy_zorro_tbl,
219 .probe = icy_probe,
220 .remove = icy_remove,
221};
222
223module_driver(icy_driver,
224 zorro_register_driver,
225 zorro_unregister_driver);
226
227MODULE_AUTHOR("Max Staudt <max@enpas.org>");
228MODULE_DESCRIPTION("I2C bus via PCF8584 on ICY Zorro card");
229MODULE_LICENSE("GPL v2");
230