diff options
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/amba/bus.c | 113 | ||||
-rw-r--r-- | drivers/i2c/busses/Kconfig | 6 | ||||
-rw-r--r-- | drivers/i2c/busses/i2c-pxa.c | 131 |
3 files changed, 69 insertions, 181 deletions
diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c index 9e3e2a69c03a..fd5475071acc 100644 --- a/drivers/amba/bus.c +++ b/drivers/amba/bus.c | |||
@@ -80,12 +80,38 @@ static int amba_resume(struct device *dev) | |||
80 | return ret; | 80 | return ret; |
81 | } | 81 | } |
82 | 82 | ||
83 | #define amba_attr_func(name,fmt,arg...) \ | ||
84 | static ssize_t name##_show(struct device *_dev, \ | ||
85 | struct device_attribute *attr, char *buf) \ | ||
86 | { \ | ||
87 | struct amba_device *dev = to_amba_device(_dev); \ | ||
88 | return sprintf(buf, fmt, arg); \ | ||
89 | } | ||
90 | |||
91 | #define amba_attr(name,fmt,arg...) \ | ||
92 | amba_attr_func(name,fmt,arg) \ | ||
93 | static DEVICE_ATTR(name, S_IRUGO, name##_show, NULL) | ||
94 | |||
95 | amba_attr_func(id, "%08x\n", dev->periphid); | ||
96 | amba_attr(irq0, "%u\n", dev->irq[0]); | ||
97 | amba_attr(irq1, "%u\n", dev->irq[1]); | ||
98 | amba_attr_func(resource, "\t%016llx\t%016llx\t%016lx\n", | ||
99 | (unsigned long long)dev->res.start, (unsigned long long)dev->res.end, | ||
100 | dev->res.flags); | ||
101 | |||
102 | static struct device_attribute amba_dev_attrs[] = { | ||
103 | __ATTR_RO(id), | ||
104 | __ATTR_RO(resource), | ||
105 | __ATTR_NULL, | ||
106 | }; | ||
107 | |||
83 | /* | 108 | /* |
84 | * Primecells are part of the Advanced Microcontroller Bus Architecture, | 109 | * Primecells are part of the Advanced Microcontroller Bus Architecture, |
85 | * so we call the bus "amba". | 110 | * so we call the bus "amba". |
86 | */ | 111 | */ |
87 | static struct bus_type amba_bustype = { | 112 | static struct bus_type amba_bustype = { |
88 | .name = "amba", | 113 | .name = "amba", |
114 | .dev_attrs = amba_dev_attrs, | ||
89 | .match = amba_match, | 115 | .match = amba_match, |
90 | .uevent = amba_uevent, | 116 | .uevent = amba_uevent, |
91 | .suspend = amba_suspend, | 117 | .suspend = amba_suspend, |
@@ -169,21 +195,6 @@ static void amba_device_release(struct device *dev) | |||
169 | kfree(d); | 195 | kfree(d); |
170 | } | 196 | } |
171 | 197 | ||
172 | #define amba_attr(name,fmt,arg...) \ | ||
173 | static ssize_t show_##name(struct device *_dev, struct device_attribute *attr, char *buf) \ | ||
174 | { \ | ||
175 | struct amba_device *dev = to_amba_device(_dev); \ | ||
176 | return sprintf(buf, fmt, arg); \ | ||
177 | } \ | ||
178 | static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL) | ||
179 | |||
180 | amba_attr(id, "%08x\n", dev->periphid); | ||
181 | amba_attr(irq0, "%u\n", dev->irq[0]); | ||
182 | amba_attr(irq1, "%u\n", dev->irq[1]); | ||
183 | amba_attr(resource, "\t%016llx\t%016llx\t%016lx\n", | ||
184 | (unsigned long long)dev->res.start, (unsigned long long)dev->res.end, | ||
185 | dev->res.flags); | ||
186 | |||
187 | /** | 198 | /** |
188 | * amba_device_register - register an AMBA device | 199 | * amba_device_register - register an AMBA device |
189 | * @dev: AMBA device to register | 200 | * @dev: AMBA device to register |
@@ -208,40 +219,46 @@ int amba_device_register(struct amba_device *dev, struct resource *parent) | |||
208 | dev_warn(&dev->dev, "coherent dma mask is unset\n"); | 219 | dev_warn(&dev->dev, "coherent dma mask is unset\n"); |
209 | 220 | ||
210 | ret = request_resource(parent, &dev->res); | 221 | ret = request_resource(parent, &dev->res); |
211 | if (ret == 0) { | 222 | if (ret) |
212 | tmp = ioremap(dev->res.start, SZ_4K); | 223 | goto err_out; |
213 | if (!tmp) { | 224 | |
214 | ret = -ENOMEM; | 225 | tmp = ioremap(dev->res.start, SZ_4K); |
215 | goto out; | 226 | if (!tmp) { |
216 | } | 227 | ret = -ENOMEM; |
217 | 228 | goto err_release; | |
218 | for (pid = 0, i = 0; i < 4; i++) | ||
219 | pid |= (readl(tmp + 0xfe0 + 4 * i) & 255) << (i * 8); | ||
220 | for (cid = 0, i = 0; i < 4; i++) | ||
221 | cid |= (readl(tmp + 0xff0 + 4 * i) & 255) << (i * 8); | ||
222 | |||
223 | iounmap(tmp); | ||
224 | |||
225 | if (cid == 0xb105f00d) | ||
226 | dev->periphid = pid; | ||
227 | |||
228 | if (dev->periphid) | ||
229 | ret = device_register(&dev->dev); | ||
230 | else | ||
231 | ret = -ENODEV; | ||
232 | |||
233 | if (ret == 0) { | ||
234 | device_create_file(&dev->dev, &dev_attr_id); | ||
235 | if (dev->irq[0] != NO_IRQ) | ||
236 | device_create_file(&dev->dev, &dev_attr_irq0); | ||
237 | if (dev->irq[1] != NO_IRQ) | ||
238 | device_create_file(&dev->dev, &dev_attr_irq1); | ||
239 | device_create_file(&dev->dev, &dev_attr_resource); | ||
240 | } else { | ||
241 | out: | ||
242 | release_resource(&dev->res); | ||
243 | } | ||
244 | } | 229 | } |
230 | |||
231 | for (pid = 0, i = 0; i < 4; i++) | ||
232 | pid |= (readl(tmp + 0xfe0 + 4 * i) & 255) << (i * 8); | ||
233 | for (cid = 0, i = 0; i < 4; i++) | ||
234 | cid |= (readl(tmp + 0xff0 + 4 * i) & 255) << (i * 8); | ||
235 | |||
236 | iounmap(tmp); | ||
237 | |||
238 | if (cid == 0xb105f00d) | ||
239 | dev->periphid = pid; | ||
240 | |||
241 | if (!dev->periphid) { | ||
242 | ret = -ENODEV; | ||
243 | goto err_release; | ||
244 | } | ||
245 | |||
246 | ret = device_register(&dev->dev); | ||
247 | if (ret) | ||
248 | goto err_release; | ||
249 | |||
250 | if (dev->irq[0] != NO_IRQ) | ||
251 | ret = device_create_file(&dev->dev, &dev_attr_irq0); | ||
252 | if (ret == 0 && dev->irq[1] != NO_IRQ) | ||
253 | ret = device_create_file(&dev->dev, &dev_attr_irq1); | ||
254 | if (ret == 0) | ||
255 | return ret; | ||
256 | |||
257 | device_unregister(&dev->dev); | ||
258 | |||
259 | err_release: | ||
260 | release_resource(&dev->res); | ||
261 | err_out: | ||
245 | return ret; | 262 | return ret; |
246 | } | 263 | } |
247 | 264 | ||
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig index 510816c16da3..5cbf8b9d5141 100644 --- a/drivers/i2c/busses/Kconfig +++ b/drivers/i2c/busses/Kconfig | |||
@@ -195,11 +195,11 @@ config I2C_IBM_IIC | |||
195 | will be called i2c-ibm_iic. | 195 | will be called i2c-ibm_iic. |
196 | 196 | ||
197 | config I2C_IOP3XX | 197 | config I2C_IOP3XX |
198 | tristate "Intel IOP3xx and IXP4xx on-chip I2C interface" | 198 | tristate "Intel IOPx3xx and IXP4xx on-chip I2C interface" |
199 | depends on (ARCH_IOP32X || ARCH_IOP33X || ARCH_IXP4XX) && I2C | 199 | depends on (ARCH_IOP32X || ARCH_IOP33X || ARCH_IXP4XX || ARCH_IOP13XX) && I2C |
200 | help | 200 | help |
201 | Say Y here if you want to use the IIC bus controller on | 201 | Say Y here if you want to use the IIC bus controller on |
202 | the Intel IOP3xx I/O Processors or IXP4xx Network Processors. | 202 | the Intel IOPx3xx I/O Processors or IXP4xx Network Processors. |
203 | 203 | ||
204 | This driver can also be built as a module. If so, the module | 204 | This driver can also be built as a module. If so, the module |
205 | will be called i2c-iop3xx. | 205 | will be called i2c-iop3xx. |
diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c index c95a6c154165..c3b1567c852a 100644 --- a/drivers/i2c/busses/i2c-pxa.c +++ b/drivers/i2c/busses/i2c-pxa.c | |||
@@ -358,133 +358,6 @@ static void i2c_pxa_reset(struct pxa_i2c *i2c) | |||
358 | 358 | ||
359 | #ifdef CONFIG_I2C_PXA_SLAVE | 359 | #ifdef CONFIG_I2C_PXA_SLAVE |
360 | /* | 360 | /* |
361 | * I2C EEPROM emulation. | ||
362 | */ | ||
363 | static struct i2c_eeprom_emu eeprom = { | ||
364 | .size = I2C_EEPROM_EMU_SIZE, | ||
365 | .watch = LIST_HEAD_INIT(eeprom.watch), | ||
366 | }; | ||
367 | |||
368 | struct i2c_eeprom_emu *i2c_pxa_get_eeprom(void) | ||
369 | { | ||
370 | return &eeprom; | ||
371 | } | ||
372 | |||
373 | int i2c_eeprom_emu_addwatcher(struct i2c_eeprom_emu *emu, void *data, | ||
374 | unsigned int addr, unsigned int size, | ||
375 | struct i2c_eeprom_emu_watcher *watcher) | ||
376 | { | ||
377 | struct i2c_eeprom_emu_watch *watch; | ||
378 | unsigned long flags; | ||
379 | |||
380 | if (addr + size > emu->size) | ||
381 | return -EINVAL; | ||
382 | |||
383 | watch = kmalloc(sizeof(struct i2c_eeprom_emu_watch), GFP_KERNEL); | ||
384 | if (watch) { | ||
385 | watch->start = addr; | ||
386 | watch->end = addr + size - 1; | ||
387 | watch->ops = watcher; | ||
388 | watch->data = data; | ||
389 | |||
390 | local_irq_save(flags); | ||
391 | list_add(&watch->node, &emu->watch); | ||
392 | local_irq_restore(flags); | ||
393 | } | ||
394 | |||
395 | return watch ? 0 : -ENOMEM; | ||
396 | } | ||
397 | |||
398 | void i2c_eeprom_emu_delwatcher(struct i2c_eeprom_emu *emu, void *data, | ||
399 | struct i2c_eeprom_emu_watcher *watcher) | ||
400 | { | ||
401 | struct i2c_eeprom_emu_watch *watch, *n; | ||
402 | unsigned long flags; | ||
403 | |||
404 | list_for_each_entry_safe(watch, n, &emu->watch, node) { | ||
405 | if (watch->ops == watcher && watch->data == data) { | ||
406 | local_irq_save(flags); | ||
407 | list_del(&watch->node); | ||
408 | local_irq_restore(flags); | ||
409 | kfree(watch); | ||
410 | } | ||
411 | } | ||
412 | } | ||
413 | |||
414 | static void i2c_eeprom_emu_event(void *ptr, i2c_slave_event_t event) | ||
415 | { | ||
416 | struct i2c_eeprom_emu *emu = ptr; | ||
417 | |||
418 | eedbg(3, "i2c_eeprom_emu_event: %d\n", event); | ||
419 | |||
420 | switch (event) { | ||
421 | case I2C_SLAVE_EVENT_START_WRITE: | ||
422 | emu->seen_start = 1; | ||
423 | eedbg(2, "i2c_eeprom: write initiated\n"); | ||
424 | break; | ||
425 | |||
426 | case I2C_SLAVE_EVENT_START_READ: | ||
427 | emu->seen_start = 0; | ||
428 | eedbg(2, "i2c_eeprom: read initiated\n"); | ||
429 | break; | ||
430 | |||
431 | case I2C_SLAVE_EVENT_STOP: | ||
432 | emu->seen_start = 0; | ||
433 | eedbg(2, "i2c_eeprom: received stop\n"); | ||
434 | break; | ||
435 | |||
436 | default: | ||
437 | eedbg(0, "i2c_eeprom: unhandled event\n"); | ||
438 | break; | ||
439 | } | ||
440 | } | ||
441 | |||
442 | static int i2c_eeprom_emu_read(void *ptr) | ||
443 | { | ||
444 | struct i2c_eeprom_emu *emu = ptr; | ||
445 | int ret; | ||
446 | |||
447 | ret = emu->bytes[emu->ptr]; | ||
448 | emu->ptr = (emu->ptr + 1) % emu->size; | ||
449 | |||
450 | return ret; | ||
451 | } | ||
452 | |||
453 | static void i2c_eeprom_emu_write(void *ptr, unsigned int val) | ||
454 | { | ||
455 | struct i2c_eeprom_emu *emu = ptr; | ||
456 | struct i2c_eeprom_emu_watch *watch; | ||
457 | |||
458 | if (emu->seen_start != 0) { | ||
459 | eedbg(2, "i2c_eeprom_emu_write: setting ptr %02x\n", val); | ||
460 | emu->ptr = val; | ||
461 | emu->seen_start = 0; | ||
462 | return; | ||
463 | } | ||
464 | |||
465 | emu->bytes[emu->ptr] = val; | ||
466 | |||
467 | eedbg(1, "i2c_eeprom_emu_write: ptr=0x%02x, val=0x%02x\n", | ||
468 | emu->ptr, val); | ||
469 | |||
470 | list_for_each_entry(watch, &emu->watch, node) { | ||
471 | if (!watch->ops || !watch->ops->write) | ||
472 | continue; | ||
473 | if (watch->start <= emu->ptr && watch->end >= emu->ptr) | ||
474 | watch->ops->write(watch->data, emu->ptr, val); | ||
475 | } | ||
476 | |||
477 | emu->ptr = (emu->ptr + 1) % emu->size; | ||
478 | } | ||
479 | |||
480 | struct i2c_slave_client eeprom_client = { | ||
481 | .data = &eeprom, | ||
482 | .event = i2c_eeprom_emu_event, | ||
483 | .read = i2c_eeprom_emu_read, | ||
484 | .write = i2c_eeprom_emu_write | ||
485 | }; | ||
486 | |||
487 | /* | ||
488 | * PXA I2C Slave mode | 361 | * PXA I2C Slave mode |
489 | */ | 362 | */ |
490 | 363 | ||
@@ -963,11 +836,9 @@ static int i2c_pxa_probe(struct platform_device *dev) | |||
963 | i2c->slave_addr = I2C_PXA_SLAVE_ADDR; | 836 | i2c->slave_addr = I2C_PXA_SLAVE_ADDR; |
964 | 837 | ||
965 | #ifdef CONFIG_I2C_PXA_SLAVE | 838 | #ifdef CONFIG_I2C_PXA_SLAVE |
966 | i2c->slave = &eeprom_client; | ||
967 | if (plat) { | 839 | if (plat) { |
968 | i2c->slave_addr = plat->slave_addr; | 840 | i2c->slave_addr = plat->slave_addr; |
969 | if (plat->slave) | 841 | i2c->slave = plat->slave; |
970 | i2c->slave = plat->slave; | ||
971 | } | 842 | } |
972 | #endif | 843 | #endif |
973 | 844 | ||