Lines Matching +full:data +full:- +full:bus
1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Copyright (C) 2003-2005 Ben. Herrenschmidt (benh@kernel.crashing.org)
19 * as the interrupt is currently used by i2c-keywest. In the long run, we
20 * might want to get rid of those high-level interfaces to linux i2c layer
72 * A bus structure. Each bus in the system has such a structure associated.
92 int (*open)(struct pmac_i2c_bus *bus);
93 void (*close)(struct pmac_i2c_bus *bus);
94 int (*xfer)(struct pmac_i2c_bus *bus, u8 addrdir, int subsize,
95 u32 subaddr, u8 *data, int len);
107 * i2c-keywest */
112 u8 *data; member
182 name, __kw_state_names[host->state], isr); \
196 return readb(host->base + (((unsigned int)reg) << host->bsteps)); in __kw_read_reg()
202 writeb(val, host->base + (((unsigned)reg) << host->bsteps)); in __kw_write_reg()
223 if (host->polled) { in kw_i2c_wait_interrupt()
235 host->state = state_stop; in kw_i2c_do_stop()
236 host->result = result; in kw_i2c_do_stop()
245 __kw_state_names[host->state], isr); in kw_i2c_handle_interrupt()
247 if (host->state == state_idle) { in kw_i2c_handle_interrupt()
257 if (host->state != state_stop) { in kw_i2c_handle_interrupt()
258 kw_i2c_do_stop(host, -EIO); in kw_i2c_handle_interrupt()
264 host->state = state_idle; in kw_i2c_handle_interrupt()
266 if (!host->polled) in kw_i2c_handle_interrupt()
267 complete(&host->complete); in kw_i2c_handle_interrupt()
273 if (host->state != state_addr) { in kw_i2c_handle_interrupt()
275 kw_i2c_do_stop(host, -EIO); in kw_i2c_handle_interrupt()
278 host->result = -ENXIO; in kw_i2c_handle_interrupt()
279 host->state = state_stop; in kw_i2c_handle_interrupt()
282 if (host->len == 0) in kw_i2c_handle_interrupt()
284 else if (host->rw) { in kw_i2c_handle_interrupt()
285 host->state = state_read; in kw_i2c_handle_interrupt()
286 if (host->len > 1) in kw_i2c_handle_interrupt()
290 host->state = state_write; in kw_i2c_handle_interrupt()
291 kw_write_reg(reg_data, *(host->data++)); in kw_i2c_handle_interrupt()
292 host->len--; in kw_i2c_handle_interrupt()
299 if (host->state == state_read) { in kw_i2c_handle_interrupt()
300 *(host->data++) = kw_read_reg(reg_data); in kw_i2c_handle_interrupt()
301 host->len--; in kw_i2c_handle_interrupt()
303 if (host->len == 0) in kw_i2c_handle_interrupt()
304 host->state = state_stop; in kw_i2c_handle_interrupt()
305 else if (host->len == 1) in kw_i2c_handle_interrupt()
307 } else if (host->state == state_write) { in kw_i2c_handle_interrupt()
310 DBG_LOW("KW: nack on data write\n"); in kw_i2c_handle_interrupt()
311 host->result = -EFBIG; in kw_i2c_handle_interrupt()
312 host->state = state_stop; in kw_i2c_handle_interrupt()
313 } else if (host->len) { in kw_i2c_handle_interrupt()
314 kw_write_reg(reg_data, *(host->data++)); in kw_i2c_handle_interrupt()
315 host->len--; in kw_i2c_handle_interrupt()
320 if (host->state != state_stop) in kw_i2c_handle_interrupt()
321 kw_i2c_do_stop(host, -EIO); in kw_i2c_handle_interrupt()
328 if (host->state != state_stop) { in kw_i2c_handle_interrupt()
330 host->result = -EIO; in kw_i2c_handle_interrupt()
332 host->state = state_idle; in kw_i2c_handle_interrupt()
333 if (!host->polled) in kw_i2c_handle_interrupt()
334 complete(&host->complete); in kw_i2c_handle_interrupt()
349 spin_lock_irqsave(&host->lock, flags); in kw_i2c_irq()
350 timer_delete(&host->timeout_timer); in kw_i2c_irq()
352 if (host->state != state_idle) { in kw_i2c_irq()
353 host->timeout_timer.expires = jiffies + KW_POLL_TIMEOUT; in kw_i2c_irq()
354 add_timer(&host->timeout_timer); in kw_i2c_irq()
356 spin_unlock_irqrestore(&host->lock, flags); in kw_i2c_irq()
366 spin_lock_irqsave(&host->lock, flags); in kw_i2c_timeout()
372 if (timer_pending(&host->timeout_timer)) in kw_i2c_timeout()
376 if (host->state != state_idle) { in kw_i2c_timeout()
377 host->timeout_timer.expires = jiffies + KW_POLL_TIMEOUT; in kw_i2c_timeout()
378 add_timer(&host->timeout_timer); in kw_i2c_timeout()
381 spin_unlock_irqrestore(&host->lock, flags); in kw_i2c_timeout()
384 static int kw_i2c_open(struct pmac_i2c_bus *bus) in kw_i2c_open() argument
386 struct pmac_i2c_host_kw *host = bus->hostdata; in kw_i2c_open()
387 mutex_lock(&host->mutex); in kw_i2c_open()
391 static void kw_i2c_close(struct pmac_i2c_bus *bus) in kw_i2c_close() argument
393 struct pmac_i2c_host_kw *host = bus->hostdata; in kw_i2c_close()
394 mutex_unlock(&host->mutex); in kw_i2c_close()
397 static int kw_i2c_xfer(struct pmac_i2c_bus *bus, u8 addrdir, int subsize, in kw_i2c_xfer() argument
398 u32 subaddr, u8 *data, int len) in kw_i2c_xfer() argument
400 struct pmac_i2c_host_kw *host = bus->hostdata; in kw_i2c_xfer()
401 u8 mode_reg = host->speed; in kw_i2c_xfer()
402 int use_irq = host->irq && !bus->polled; in kw_i2c_xfer()
405 switch(bus->mode) { in kw_i2c_xfer()
407 return -EINVAL; in kw_i2c_xfer()
411 return -EINVAL; in kw_i2c_xfer()
416 return -EINVAL; in kw_i2c_xfer()
421 return -EINVAL; in kw_i2c_xfer()
427 kw_write_reg(reg_mode, mode_reg | (bus->channel << 4)); in kw_i2c_xfer()
430 /* Set up address and r/w bit, strip possible stale bus number from in kw_i2c_xfer()
441 host->data = data; in kw_i2c_xfer()
442 host->len = len; in kw_i2c_xfer()
443 host->state = state_addr; in kw_i2c_xfer()
444 host->result = 0; in kw_i2c_xfer()
445 host->rw = (addrdir & 1); in kw_i2c_xfer()
446 host->polled = bus->polled; in kw_i2c_xfer()
453 reinit_completion(&host->complete); in kw_i2c_xfer()
457 host->timeout_timer.expires = jiffies + KW_POLL_TIMEOUT; in kw_i2c_xfer()
458 add_timer(&host->timeout_timer); in kw_i2c_xfer()
468 wait_for_completion(&host->complete); in kw_i2c_xfer()
470 while(host->state != state_idle) { in kw_i2c_xfer()
474 spin_lock_irqsave(&host->lock, flags); in kw_i2c_xfer()
476 spin_unlock_irqrestore(&host->lock, flags); in kw_i2c_xfer()
483 return host->result; in kw_i2c_xfer()
510 mutex_init(&host->mutex); in kw_i2c_host_init()
511 init_completion(&host->complete); in kw_i2c_host_init()
512 spin_lock_init(&host->lock); in kw_i2c_host_init()
513 timer_setup(&host->timeout_timer, kw_i2c_timeout, 0); in kw_i2c_host_init()
515 psteps = of_get_property(np, "AAPL,address-step", NULL); in kw_i2c_host_init()
517 for (host->bsteps = 0; (steps & 0x01) == 0; host->bsteps++) in kw_i2c_host_init()
520 host->speed = KW_I2C_MODE_25KHZ; in kw_i2c_host_init()
521 prate = of_get_property(np, "AAPL,i2c-rate", NULL); in kw_i2c_host_init()
524 host->speed = KW_I2C_MODE_100KHZ; in kw_i2c_host_init()
527 host->speed = KW_I2C_MODE_50KHZ; in kw_i2c_host_init()
530 host->speed = KW_I2C_MODE_25KHZ; in kw_i2c_host_init()
533 host->irq = irq_of_parse_and_map(np, 0); in kw_i2c_host_init()
534 if (!host->irq) in kw_i2c_host_init()
539 host->base = ioremap((*addrp), 0x1000); in kw_i2c_host_init()
540 if (host->base == NULL) { in kw_i2c_host_init()
554 if (request_irq(host->irq, kw_i2c_irq, IRQF_NO_SUSPEND, in kw_i2c_host_init()
556 host->irq = 0; in kw_i2c_host_init()
559 *addrp, host->irq, np); in kw_i2c_host_init()
570 struct pmac_i2c_bus *bus; in kw_i2c_add() local
572 bus = kzalloc(sizeof(struct pmac_i2c_bus), GFP_KERNEL); in kw_i2c_add()
573 if (bus == NULL) in kw_i2c_add()
576 bus->controller = of_node_get(controller); in kw_i2c_add()
577 bus->busnode = of_node_get(busnode); in kw_i2c_add()
578 bus->type = pmac_i2c_bus_keywest; in kw_i2c_add()
579 bus->hostdata = host; in kw_i2c_add()
580 bus->channel = channel; in kw_i2c_add()
581 bus->mode = pmac_i2c_mode_std; in kw_i2c_add()
582 bus->open = kw_i2c_open; in kw_i2c_add()
583 bus->close = kw_i2c_close; in kw_i2c_add()
584 bus->xfer = kw_i2c_xfer; in kw_i2c_add()
585 mutex_init(&bus->mutex); in kw_i2c_add()
586 lockdep_register_key(&bus->lock_key); in kw_i2c_add()
587 lockdep_set_class(&bus->mutex, &bus->lock_key); in kw_i2c_add()
589 bus->flags = pmac_i2c_multibus; in kw_i2c_add()
590 list_add(&bus->link, &pmac_i2c_busses); in kw_i2c_add()
592 printk(KERN_INFO " channel %d bus %s\n", channel, in kw_i2c_add()
593 (controller == busnode) ? "<multibus>" : busnode->full_name); in kw_i2c_add()
600 /* Probe keywest-i2c busses */ in kw_i2c_probe()
601 for_each_compatible_node(np, "i2c","keywest-i2c") { in kw_i2c_probe()
611 * have proper bus nodes. Note that the "new" way (proper bus in kw_i2c_probe()
613 * kept hidden in the device-tree. In the future, we might in kw_i2c_probe()
618 multibus = !of_node_name_eq(child, "i2c-bus"); in kw_i2c_probe()
621 /* For a multibus setup, we get the bus count based on the in kw_i2c_probe()
630 chans = parent->name[0] == 'u' ? 2 : 1; in kw_i2c_probe()
659 u8 bus; member
666 u8 data[]; member
671 complete(req->arg); in pmu_i2c_complete()
674 static int pmu_i2c_xfer(struct pmac_i2c_bus *bus, u8 addrdir, int subsize, in pmu_i2c_xfer() argument
675 u32 subaddr, u8 *data, int len) in pmu_i2c_xfer() argument
677 struct adb_request *req = bus->hostdata; in pmu_i2c_xfer()
678 struct pmu_i2c_hdr *hdr = (struct pmu_i2c_hdr *)&req->data[1]; in pmu_i2c_xfer()
686 return -EINVAL; in pmu_i2c_xfer()
692 hdr->bus = bus->channel; in pmu_i2c_xfer()
693 hdr->count = len; in pmu_i2c_xfer()
695 switch(bus->mode) { in pmu_i2c_xfer()
698 return -EINVAL; in pmu_i2c_xfer()
699 hdr->address = addrdir; in pmu_i2c_xfer()
700 hdr->mode = PMU_I2C_MODE_SIMPLE; in pmu_i2c_xfer()
705 return -EINVAL; in pmu_i2c_xfer()
706 hdr->address = addrdir & 0xfe; in pmu_i2c_xfer()
707 hdr->comb_addr = addrdir; in pmu_i2c_xfer()
708 hdr->sub_addr = subaddr; in pmu_i2c_xfer()
709 if (bus->mode == pmac_i2c_mode_stdsub) in pmu_i2c_xfer()
710 hdr->mode = PMU_I2C_MODE_STDSUB; in pmu_i2c_xfer()
712 hdr->mode = PMU_I2C_MODE_COMBINED; in pmu_i2c_xfer()
715 return -EINVAL; in pmu_i2c_xfer()
719 req->data[0] = PMU_I2C_CMD; in pmu_i2c_xfer()
720 req->reply[0] = 0xff; in pmu_i2c_xfer()
721 req->nbytes = sizeof(struct pmu_i2c_hdr) + 1; in pmu_i2c_xfer()
722 req->done = pmu_i2c_complete; in pmu_i2c_xfer()
723 req->arg = ∁ in pmu_i2c_xfer()
725 memcpy(hdr->data, data, len); in pmu_i2c_xfer()
726 req->nbytes += len; in pmu_i2c_xfer()
732 if (req->reply[0] == PMU_I2C_STATUS_OK) in pmu_i2c_xfer()
736 if (req->reply[0] != PMU_I2C_STATUS_OK) in pmu_i2c_xfer()
737 return -EIO; in pmu_i2c_xfer()
747 hdr->bus = PMU_I2C_BUS_STATUS; in pmu_i2c_xfer()
750 req->data[0] = PMU_I2C_CMD; in pmu_i2c_xfer()
751 req->reply[0] = 0xff; in pmu_i2c_xfer()
752 req->nbytes = 2; in pmu_i2c_xfer()
753 req->done = pmu_i2c_complete; in pmu_i2c_xfer()
754 req->arg = ∁ in pmu_i2c_xfer()
760 if (req->reply[0] == PMU_I2C_STATUS_OK && !read) in pmu_i2c_xfer()
762 if (req->reply[0] == PMU_I2C_STATUS_DATAREAD && read) { in pmu_i2c_xfer()
763 int rlen = req->reply_len - 1; in pmu_i2c_xfer()
768 return -EIO; in pmu_i2c_xfer()
771 memcpy(data, &req->reply[1], len); in pmu_i2c_xfer()
775 return -EIO; in pmu_i2c_xfer()
780 struct pmac_i2c_bus *bus; in pmu_i2c_probe() local
787 /* There might or might not be a "pmu-i2c" node, we use that in pmu_i2c_probe()
788 * or via-pmu itself, whatever we find. I haven't seen a machine in pmu_i2c_probe()
789 * with separate bus nodes, so we assume a multibus setup in pmu_i2c_probe()
791 busnode = of_find_node_by_name(NULL, "pmu-i2c"); in pmu_i2c_probe()
793 busnode = of_find_node_by_name(NULL, "via-pmu"); in pmu_i2c_probe()
800 * We add bus 1 and 2 only for now, bus 0 is "special" in pmu_i2c_probe()
804 bus = kzalloc(sz, GFP_KERNEL); in pmu_i2c_probe()
805 if (bus == NULL) in pmu_i2c_probe()
808 bus->controller = busnode; in pmu_i2c_probe()
809 bus->busnode = busnode; in pmu_i2c_probe()
810 bus->type = pmac_i2c_bus_pmu; in pmu_i2c_probe()
811 bus->channel = channel; in pmu_i2c_probe()
812 bus->mode = pmac_i2c_mode_std; in pmu_i2c_probe()
813 bus->hostdata = bus + 1; in pmu_i2c_probe()
814 bus->xfer = pmu_i2c_xfer; in pmu_i2c_probe()
815 mutex_init(&bus->mutex); in pmu_i2c_probe()
816 lockdep_register_key(&bus->lock_key); in pmu_i2c_probe()
817 lockdep_set_class(&bus->mutex, &bus->lock_key); in pmu_i2c_probe()
818 bus->flags = pmac_i2c_multibus; in pmu_i2c_probe()
819 list_add(&bus->link, &pmac_i2c_busses); in pmu_i2c_probe()
821 printk(KERN_INFO " channel %d bus <multibus>\n", channel); in pmu_i2c_probe()
841 static int smu_i2c_xfer(struct pmac_i2c_bus *bus, u8 addrdir, int subsize, in smu_i2c_xfer() argument
842 u32 subaddr, u8 *data, int len) in smu_i2c_xfer() argument
844 struct smu_i2c_cmd *cmd = bus->hostdata; in smu_i2c_xfer()
851 return -EINVAL; in smu_i2c_xfer()
854 cmd->info.bus = bus->channel; in smu_i2c_xfer()
855 cmd->info.devaddr = addrdir; in smu_i2c_xfer()
856 cmd->info.datalen = len; in smu_i2c_xfer()
858 switch(bus->mode) { in smu_i2c_xfer()
861 return -EINVAL; in smu_i2c_xfer()
862 cmd->info.type = SMU_I2C_TRANSFER_SIMPLE; in smu_i2c_xfer()
867 return -EINVAL; in smu_i2c_xfer()
868 cmd->info.sublen = subsize; in smu_i2c_xfer()
869 /* that's big-endian only but heh ! */ in smu_i2c_xfer()
870 memcpy(&cmd->info.subaddr, ((char *)&subaddr) + (4 - subsize), in smu_i2c_xfer()
872 if (bus->mode == pmac_i2c_mode_stdsub) in smu_i2c_xfer()
873 cmd->info.type = SMU_I2C_TRANSFER_STDSUB; in smu_i2c_xfer()
875 cmd->info.type = SMU_I2C_TRANSFER_COMBINED; in smu_i2c_xfer()
878 return -EINVAL; in smu_i2c_xfer()
881 memcpy(cmd->info.data, data, len); in smu_i2c_xfer()
884 cmd->done = smu_i2c_complete; in smu_i2c_xfer()
885 cmd->misc = ∁ in smu_i2c_xfer()
890 rc = cmd->status; in smu_i2c_xfer()
893 memcpy(data, cmd->info.data, len); in smu_i2c_xfer()
900 struct pmac_i2c_bus *bus; in smu_i2c_probe() local
907 controller = of_find_node_by_name(NULL, "smu-i2c-control"); in smu_i2c_probe()
921 !of_node_is_type(busnode, "i2c-bus")) in smu_i2c_probe()
928 bus = kzalloc(sz, GFP_KERNEL); in smu_i2c_probe()
929 if (bus == NULL) { in smu_i2c_probe()
934 bus->controller = controller; in smu_i2c_probe()
935 bus->busnode = of_node_get(busnode); in smu_i2c_probe()
936 bus->type = pmac_i2c_bus_smu; in smu_i2c_probe()
937 bus->channel = *reg; in smu_i2c_probe()
938 bus->mode = pmac_i2c_mode_std; in smu_i2c_probe()
939 bus->hostdata = bus + 1; in smu_i2c_probe()
940 bus->xfer = smu_i2c_xfer; in smu_i2c_probe()
941 mutex_init(&bus->mutex); in smu_i2c_probe()
942 lockdep_register_key(&bus->lock_key); in smu_i2c_probe()
943 lockdep_set_class(&bus->mutex, &bus->lock_key); in smu_i2c_probe()
944 bus->flags = 0; in smu_i2c_probe()
945 list_add(&bus->link, &pmac_i2c_busses); in smu_i2c_probe()
947 printk(KERN_INFO " channel %x bus %pOF\n", in smu_i2c_probe()
948 bus->channel, busnode); in smu_i2c_probe()
965 struct pmac_i2c_bus *bus; in pmac_i2c_find_bus() local
968 list_for_each_entry(bus, &pmac_i2c_busses, link) { in pmac_i2c_find_bus()
969 if (p == bus->busnode) { in pmac_i2c_find_bus()
970 if (prev && bus->flags & pmac_i2c_multibus) { in pmac_i2c_find_bus()
976 if (((*reg) >> 8) != bus->channel) in pmac_i2c_find_bus()
981 return bus; in pmac_i2c_find_bus()
1003 struct device_node *pmac_i2c_get_controller(struct pmac_i2c_bus *bus) in pmac_i2c_get_controller() argument
1005 return bus->controller; in pmac_i2c_get_controller()
1009 struct device_node *pmac_i2c_get_bus_node(struct pmac_i2c_bus *bus) in pmac_i2c_get_bus_node() argument
1011 return bus->busnode; in pmac_i2c_get_bus_node()
1015 int pmac_i2c_get_type(struct pmac_i2c_bus *bus) in pmac_i2c_get_type() argument
1017 return bus->type; in pmac_i2c_get_type()
1021 int pmac_i2c_get_flags(struct pmac_i2c_bus *bus) in pmac_i2c_get_flags() argument
1023 return bus->flags; in pmac_i2c_get_flags()
1027 int pmac_i2c_get_channel(struct pmac_i2c_bus *bus) in pmac_i2c_get_channel() argument
1029 return bus->channel; in pmac_i2c_get_channel()
1034 struct i2c_adapter *pmac_i2c_get_adapter(struct pmac_i2c_bus *bus) in pmac_i2c_get_adapter() argument
1036 return &bus->adapter; in pmac_i2c_get_adapter()
1042 struct pmac_i2c_bus *bus; in pmac_i2c_adapter_to_bus() local
1044 list_for_each_entry(bus, &pmac_i2c_busses, link) in pmac_i2c_adapter_to_bus()
1045 if (&bus->adapter == adapter) in pmac_i2c_adapter_to_bus()
1046 return bus; in pmac_i2c_adapter_to_bus()
1053 struct pmac_i2c_bus *bus = pmac_i2c_find_bus(dev); in pmac_i2c_match_adapter() local
1055 if (bus == NULL) in pmac_i2c_match_adapter()
1057 return (&bus->adapter == adapter); in pmac_i2c_match_adapter()
1063 struct pmac_i2c_bus *bus, *found = NULL; in pmac_low_i2c_lock() local
1065 list_for_each_entry(bus, &pmac_i2c_busses, link) { in pmac_low_i2c_lock()
1066 if (np == bus->controller) { in pmac_low_i2c_lock()
1067 found = bus; in pmac_low_i2c_lock()
1072 return -ENODEV; in pmac_low_i2c_lock()
1073 return pmac_i2c_open(bus, 0); in pmac_low_i2c_lock()
1079 struct pmac_i2c_bus *bus, *found = NULL; in pmac_low_i2c_unlock() local
1081 list_for_each_entry(bus, &pmac_i2c_busses, link) { in pmac_low_i2c_unlock()
1082 if (np == bus->controller) { in pmac_low_i2c_unlock()
1083 found = bus; in pmac_low_i2c_unlock()
1088 return -ENODEV; in pmac_low_i2c_unlock()
1089 pmac_i2c_close(bus); in pmac_low_i2c_unlock()
1095 int pmac_i2c_open(struct pmac_i2c_bus *bus, int polled) in pmac_i2c_open() argument
1099 mutex_lock(&bus->mutex); in pmac_i2c_open()
1100 bus->polled = polled || pmac_i2c_force_poll; in pmac_i2c_open()
1101 bus->opened = 1; in pmac_i2c_open()
1102 bus->mode = pmac_i2c_mode_std; in pmac_i2c_open()
1103 if (bus->open && (rc = bus->open(bus)) != 0) { in pmac_i2c_open()
1104 bus->opened = 0; in pmac_i2c_open()
1105 mutex_unlock(&bus->mutex); in pmac_i2c_open()
1112 void pmac_i2c_close(struct pmac_i2c_bus *bus) in pmac_i2c_close() argument
1114 WARN_ON(!bus->opened); in pmac_i2c_close()
1115 if (bus->close) in pmac_i2c_close()
1116 bus->close(bus); in pmac_i2c_close()
1117 bus->opened = 0; in pmac_i2c_close()
1118 mutex_unlock(&bus->mutex); in pmac_i2c_close()
1122 int pmac_i2c_setmode(struct pmac_i2c_bus *bus, int mode) in pmac_i2c_setmode() argument
1124 WARN_ON(!bus->opened); in pmac_i2c_setmode()
1127 * "combined4" mode that I need to implement for the SMU bus in pmac_i2c_setmode()
1131 " bus %pOF !\n", mode, bus->busnode); in pmac_i2c_setmode()
1132 return -EINVAL; in pmac_i2c_setmode()
1134 bus->mode = mode; in pmac_i2c_setmode()
1140 int pmac_i2c_xfer(struct pmac_i2c_bus *bus, u8 addrdir, int subsize, in pmac_i2c_xfer() argument
1141 u32 subaddr, u8 *data, int len) in pmac_i2c_xfer() argument
1145 WARN_ON(!bus->opened); in pmac_i2c_xfer()
1148 " %d bytes, bus %pOF\n", bus->channel, addrdir, bus->mode, subsize, in pmac_i2c_xfer()
1149 subaddr, len, bus->busnode); in pmac_i2c_xfer()
1151 rc = bus->xfer(bus, addrdir, subsize, subaddr, data, len); in pmac_i2c_xfer()
1170 struct pmac_i2c_bus *bus; in pmac_i2c_devscan() local
1177 /* XXX Study device-tree's & apple drivers are get the quirks in pmac_i2c_devscan()
1183 * let's make sure i2c-hwclock doesn't match about "imic" in pmac_i2c_devscan()
1187 { "i2c-hwclock", "imic5002", pmac_i2c_quirk_skip }, in pmac_i2c_devscan()
1188 { "i2c-hwclock", "imic5003", pmac_i2c_quirk_skip }, in pmac_i2c_devscan()
1189 { "i2c-hwclock", NULL, pmac_i2c_quirk_invmask }, in pmac_i2c_devscan()
1190 { "i2c-cpu-voltage", NULL, 0}, in pmac_i2c_devscan()
1191 { "temp-monitor", NULL, 0 }, in pmac_i2c_devscan()
1192 { "supply-monitor", NULL, 0 }, in pmac_i2c_devscan()
1201 list_for_each_entry(bus, &pmac_i2c_busses, link) { in pmac_i2c_devscan()
1202 for_each_child_of_node(bus->busnode, np) { in pmac_i2c_devscan()
1204 /* If multibus, check if device is on that bus */ in pmac_i2c_devscan()
1205 if (bus->flags & pmac_i2c_multibus) in pmac_i2c_devscan()
1206 if (bus != pmac_i2c_find_bus(np)) in pmac_i2c_devscan()
1208 for (p = whitelist; p->name != NULL; p++) { in pmac_i2c_devscan()
1209 if (!of_node_name_eq(np, p->name)) in pmac_i2c_devscan()
1211 if (p->compatible && in pmac_i2c_devscan()
1212 !of_device_is_compatible(np, p->compatible)) in pmac_i2c_devscan()
1214 if (p->quirks & pmac_i2c_quirk_skip) in pmac_i2c_devscan()
1216 callback(np, p->quirks); in pmac_i2c_devscan()
1227 struct pmac_i2c_bus *bus; member
1238 struct pmac_i2c_bus *bus; in pmac_i2c_do_begin() local
1240 bus = pmac_i2c_find_bus(func->node); in pmac_i2c_do_begin()
1241 if (bus == NULL) { in pmac_i2c_do_begin()
1242 printk(KERN_ERR "low_i2c: Can't find bus for %pOF (pfunc)\n", in pmac_i2c_do_begin()
1243 func->node); in pmac_i2c_do_begin()
1246 if (pmac_i2c_open(bus, 0)) { in pmac_i2c_do_begin()
1247 printk(KERN_ERR "low_i2c: Can't open i2c bus for %pOF (pfunc)\n", in pmac_i2c_do_begin()
1248 func->node); in pmac_i2c_do_begin()
1259 pmac_i2c_close(bus); in pmac_i2c_do_begin()
1262 inst->bus = bus; in pmac_i2c_do_begin()
1263 inst->addr = pmac_i2c_get_dev_addr(func->node); in pmac_i2c_do_begin()
1264 inst->quirks = (int)(long)func->driver_data; in pmac_i2c_do_begin()
1274 pmac_i2c_close(inst->bus); in pmac_i2c_do_end()
1282 inst->bytes = len; in pmac_i2c_do_read()
1283 return pmac_i2c_xfer(inst->bus, inst->addr | pmac_i2c_read, 0, 0, in pmac_i2c_do_read()
1284 inst->buffer, len); in pmac_i2c_do_read()
1287 static int pmac_i2c_do_write(PMF_STD_ARGS, u32 len, const u8 *data) in pmac_i2c_do_write() argument
1291 return pmac_i2c_xfer(inst->bus, inst->addr | pmac_i2c_write, 0, 0, in pmac_i2c_do_write()
1292 (u8 *)data, len); in pmac_i2c_do_write()
1306 if (inst->quirks & pmac_i2c_quirk_invmask) { in pmac_i2c_do_apply_rmw()
1308 inst->scratch[i] = (inst->buffer[i] & mask[i]) | val[i]; in pmac_i2c_do_apply_rmw()
1311 inst->scratch[i] = (inst->buffer[i] & ~mask[i]) in pmac_i2c_do_apply_rmw()
1322 if (masklen > inst->bytes || valuelen > inst->bytes || in pmac_i2c_do_rmw()
1323 totallen > inst->bytes || valuelen > masklen) in pmac_i2c_do_rmw()
1324 return -EINVAL; in pmac_i2c_do_rmw()
1328 return pmac_i2c_xfer(inst->bus, inst->addr | pmac_i2c_write, 0, 0, in pmac_i2c_do_rmw()
1329 inst->scratch, totallen); in pmac_i2c_do_rmw()
1336 inst->bytes = len; in pmac_i2c_do_read_sub()
1337 return pmac_i2c_xfer(inst->bus, inst->addr | pmac_i2c_read, 1, subaddr, in pmac_i2c_do_read_sub()
1338 inst->buffer, len); in pmac_i2c_do_read_sub()
1342 const u8 *data) in pmac_i2c_do_write_sub() argument
1346 return pmac_i2c_xfer(inst->bus, inst->addr | pmac_i2c_write, 1, in pmac_i2c_do_write_sub()
1347 subaddr, (u8 *)data, len); in pmac_i2c_do_write_sub()
1354 return pmac_i2c_setmode(inst->bus, mode); in pmac_i2c_do_set_mode()
1363 if (masklen > inst->bytes || valuelen > inst->bytes || in pmac_i2c_do_rmw_sub()
1364 totallen > inst->bytes || valuelen > masklen) in pmac_i2c_do_rmw_sub()
1365 return -EINVAL; in pmac_i2c_do_rmw_sub()
1369 return pmac_i2c_xfer(inst->bus, inst->addr | pmac_i2c_write, 1, in pmac_i2c_do_rmw_sub()
1370 subaddr, inst->scratch, totallen); in pmac_i2c_do_rmw_sub()
1381 if (!args || !args->count || !args->u[0].p) in pmac_i2c_do_mask_and_comp()
1382 return -EINVAL; in pmac_i2c_do_mask_and_comp()
1385 if (len > inst->bytes) in pmac_i2c_do_mask_and_comp()
1386 return -EINVAL; in pmac_i2c_do_mask_and_comp()
1389 if ((inst->buffer[i] & maskdata[i]) != valuedata[i]) in pmac_i2c_do_mask_and_comp()
1391 *args->u[0].p = match; in pmac_i2c_do_mask_and_comp()
1457 /* This is non-static as it might be called early by smp code */
1466 /* Probe keywest-i2c busses */ in pmac_i2c_init()
1492 struct pmac_i2c_bus *bus; in pmac_i2c_create_platform_devices() local
1502 list_for_each_entry(bus, &pmac_i2c_busses, link) { in pmac_i2c_create_platform_devices()
1503 bus->platform_dev = in pmac_i2c_create_platform_devices()
1504 platform_device_alloc("i2c-powermac", i++); in pmac_i2c_create_platform_devices()
1505 if (bus->platform_dev == NULL) in pmac_i2c_create_platform_devices()
1506 return -ENOMEM; in pmac_i2c_create_platform_devices()
1507 bus->platform_dev->dev.platform_data = bus; in pmac_i2c_create_platform_devices()
1508 bus->platform_dev->dev.of_node = bus->busnode; in pmac_i2c_create_platform_devices()
1509 platform_device_add(bus->platform_dev); in pmac_i2c_create_platform_devices()