Lines Matching +full:misc +full:- +full:latch

1 // SPDX-License-Identifier: GPL-2.0
9 * to the keyboard and mouse, as well as the non-volatile RAM
13 * Copyright (C) 2001-2002 Benjamin Herrenschmidt
14 * Copyright (C) 2006-2007 Johannes Berg
17 * - Cleanup atomically disabling reply to PMU events after
72 #include "via-pmu-event.h"
82 /* VIA registers - spaced 0x200 bytes apart */
84 #define B 0 /* B-side data */
85 #define A RS /* A-side data */
86 #define DIRB (2*RS) /* B-side direction (1=output) */
87 #define DIRA (3*RS) /* A-side direction (1=output) */
88 #define T1CL (4*RS) /* Timer 1 ctr/latch (low 8 bits) */
90 #define T1LL (6*RS) /* Timer 1 latch (low 8 bits) */
91 #define T1LH (7*RS) /* Timer 1 latch (high 8 bits) */
92 #define T2CL (8*RS) /* Timer 2 ctr/latch (low 8 bits) */
99 #define ANH (15*RS) /* A-side data, no handshake */
161 static int gpio_irq_enabled = -1;
235 * - the number of data bytes to be sent with the command, or -1
237 * - the number of response bytes which the PMU will return, or
238 * -1 if it will send a length byte.
242 /*00*/ {-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
243 /*08*/ {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
244 /*10*/ { 1, 0},{ 1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
245 /*18*/ { 0, 1},{ 0, 1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{ 0, 0},
246 /*20*/ {-1, 0},{ 0, 0},{ 2, 0},{ 1, 0},{ 1, 0},{-1, 0},{-1, 0},{-1, 0},
247 /*28*/ { 0,-1},{ 0,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{ 0,-1},
248 /*30*/ { 4, 0},{20, 0},{-1, 0},{ 3, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
249 /*38*/ { 0, 4},{ 0,20},{ 2,-1},{ 2, 1},{ 3,-1},{-1,-1},{-1,-1},{ 4, 0},
250 /*40*/ { 1, 0},{ 1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
251 /*48*/ { 0, 1},{ 0, 1},{-1,-1},{ 1, 0},{ 1, 0},{-1,-1},{-1,-1},{-1,-1},
252 /*50*/ { 1, 0},{ 0, 0},{ 2, 0},{ 2, 0},{-1, 0},{ 1, 0},{ 3, 0},{ 1, 0},
253 /*58*/ { 0, 1},{ 1, 0},{ 0, 2},{ 0, 2},{ 0,-1},{-1,-1},{-1,-1},{-1,-1},
254 /*60*/ { 2, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
255 /*68*/ { 0, 3},{ 0, 3},{ 0, 2},{ 0, 8},{ 0,-1},{ 0,-1},{-1,-1},{-1,-1},
256 /*70*/ { 1, 0},{ 1, 0},{ 1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
257 /*78*/ { 0,-1},{ 0,-1},{-1,-1},{-1,-1},{-1,-1},{ 5, 1},{ 4, 1},{ 4, 1},
258 /*80*/ { 4, 0},{-1, 0},{ 0, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
259 /*88*/ { 0, 5},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
260 /*90*/ { 1, 0},{ 2, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
261 /*98*/ { 0, 1},{ 0, 1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
262 /*a0*/ { 2, 0},{ 2, 0},{ 2, 0},{ 4, 0},{-1, 0},{ 0, 0},{-1, 0},{-1, 0},
263 /*a8*/ { 1, 1},{ 1, 0},{ 3, 0},{ 2, 0},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
264 /*b0*/ {-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
265 /*b8*/ {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
266 /*c0*/ {-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
267 /*c8*/ {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
268 /*d0*/ { 0, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
269 /*d8*/ { 1, 1},{ 1, 1},{-1,-1},{-1,-1},{ 0, 1},{ 0,-1},{-1,-1},{-1,-1},
270 /*e0*/ {-1, 0},{ 4, 0},{ 0, 1},{-1, 0},{-1, 0},{ 4, 0},{-1, 0},{-1, 0},
271 /*e8*/ { 3,-1},{-1,-1},{ 0, 1},{-1,-1},{ 0,-1},{-1,-1},{-1,-1},{ 0, 0},
272 /*f0*/ {-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
273 /*f8*/ {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
292 vias = of_find_node_by_name(NULL, "via-pmu"); in find_via_pmu()
298 printk(KERN_ERR "via-pmu: No \"reg\" property !\n"); in find_via_pmu()
303 printk(KERN_ERR "via-pmu: Can't translate address !\n"); in find_via_pmu()
314 if (of_node_name_eq(vias->parent, "ohare") || in find_via_pmu()
315 of_device_is_compatible(vias->parent, "ohare")) in find_via_pmu()
317 else if (of_device_is_compatible(vias->parent, "paddington")) in find_via_pmu()
319 else if (of_device_is_compatible(vias->parent, "heathrow")) in find_via_pmu()
321 else if (of_device_is_compatible(vias->parent, "Keylargo") in find_via_pmu()
322 || of_device_is_compatible(vias->parent, "K2-Keylargo")) { in find_via_pmu()
347 printk(KERN_ERR "via-pmu: Can't find GPIO reg !\n"); in find_via_pmu()
355 printk(KERN_ERR "via-pmu: Can't map address !\n"); in find_via_pmu()
383 if (macintosh_config->adb_type != MAC_ADB_PB2) in find_via_pmu()
409 return pmu_state == uninitialized ? -ENODEV : 0; in pmu_probe()
414 return pmu_state == uninitialized ? -ENODEV : 0; in pmu_init()
430 return -ENODEV; in via_pmu_start()
437 printk(KERN_ERR "via-pmu: can't map interrupt\n"); in via_pmu_start()
438 return -ENODEV; in via_pmu_start()
445 "VIA-PMU", (void *)0)) { in via_pmu_start()
446 printk(KERN_ERR "via-pmu: can't request irq %d\n", irq); in via_pmu_start()
447 return -ENODEV; in via_pmu_start()
451 gpio_node = of_find_node_by_name(NULL, "extint-gpio1"); in via_pmu_start()
454 "pmu-interrupt"); in via_pmu_start()
473 "VIA-PMU-SR", NULL)) { in via_pmu_start()
475 return -ENODEV; in via_pmu_start()
478 "VIA-PMU-CL", NULL)) { in via_pmu_start()
481 return -ENODEV; in via_pmu_start()
510 return -ENODEV; in via_pmu_dev_init()
534 of_find_node_by_name(NULL, "power-mgt"); in via_pmu_dev_init()
537 prim_info = of_get_property(prim, "prim-info", NULL); in via_pmu_dev_init()
587 if (--timeout < 0) { in init_pmu()
599 if (--timeout < 0) { in init_pmu()
630 printk(KERN_INFO "via-pmu: Server Mode is %s\n", in init_pmu()
671 * is inspired from the implementation in gkrellm-pmu
693 * --tkoba in done_battery_state_ohare()
702 if (req->reply[0] & 0x01) in done_battery_state_ohare()
719 if (req->reply[0] & 0x04) { in done_battery_state_ohare()
721 if (req->reply[0] & 0x02) in done_battery_state_ohare()
723 vb = (req->reply[1] << 8) | req->reply[2]; in done_battery_state_ohare()
725 amperage = req->reply[5]; in done_battery_state_ohare()
726 if ((req->reply[0] & 0x01) == 0) { in done_battery_state_ohare()
728 vb += ((amperage - 200) * 15)/100; in done_battery_state_ohare()
729 } else if (req->reply[0] & 0x02) { in done_battery_state_ohare()
734 if (req->reply[0] & 0x40) { in done_battery_state_ohare()
735 pcharge = (req->reply[6] << 8) + req->reply[7]; in done_battery_state_ohare()
739 pcharge = 100 - pcharge / lmax; in done_battery_state_ohare()
748 amperage = -amperage; in done_battery_state_ohare()
789 if (req->reply[1] & 0x01) in done_battery_state_smart()
797 if (req->reply[1] & 0x04) { in done_battery_state_smart()
799 switch(req->reply[0]) { in done_battery_state_smart()
801 case 4: capa = req->reply[2]; in done_battery_state_smart()
802 max = req->reply[3]; in done_battery_state_smart()
803 amperage = *((signed char *)&req->reply[4]); in done_battery_state_smart()
804 voltage = req->reply[5]; in done_battery_state_smart()
806 case 5: capa = (req->reply[2] << 8) | req->reply[3]; in done_battery_state_smart()
807 max = (req->reply[4] << 8) | req->reply[5]; in done_battery_state_smart()
808 amperage = *((signed short *)&req->reply[6]); in done_battery_state_smart()
809 voltage = (req->reply[8] << 8) | req->reply[9]; in done_battery_state_smart()
813 "len: %d, %4ph\n", req->reply_len, in done_battery_state_smart()
814 req->reply); in done_battery_state_smart()
819 if ((req->reply[1] & 0x01) && (amperage > 0)) in done_battery_state_smart()
828 if ((req->reply[1] & 0x01) && (amperage > 0)) in done_battery_state_smart()
830 = ((max-capa) * 3600) / amperage; in done_battery_state_smart()
833 = (capa * 3600) / (-amperage); in done_battery_state_smart()
872 "PC-Card eject button", in pmu_irqstats_proc_show()
894 long batnum = (long)m->private; in pmu_battery_proc_show()
910 pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,0,-1) >= 0) in pmu_options_proc_show()
932 return -EINVAL; in pmu_options_proc_write()
936 return -EFAULT; in pmu_options_proc_write()
949 return -EINVAL; in pmu_options_proc_write()
955 pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,0,-1) >= 0) in pmu_options_proc_write()
983 req->complete = 1; in pmu_send_request()
984 return -ENXIO; in pmu_send_request()
987 ret = -EINVAL; in pmu_send_request()
989 switch (req->data[0]) { in pmu_send_request()
991 for (i = 0; i < req->nbytes - 1; ++i) in pmu_send_request()
992 req->data[i] = req->data[i+1]; in pmu_send_request()
993 --req->nbytes; in pmu_send_request()
994 if (pmu_data_len[req->data[0]][1] != 0) { in pmu_send_request()
995 req->reply[0] = ADB_RET_OK; in pmu_send_request()
996 req->reply_len = 1; in pmu_send_request()
998 req->reply_len = 0; in pmu_send_request()
1002 switch (req->data[1]) { in pmu_send_request()
1004 if (req->nbytes != 2) in pmu_send_request()
1006 req->data[0] = PMU_READ_RTC; in pmu_send_request()
1007 req->nbytes = 1; in pmu_send_request()
1008 req->reply_len = 3; in pmu_send_request()
1009 req->reply[0] = CUDA_PACKET; in pmu_send_request()
1010 req->reply[1] = 0; in pmu_send_request()
1011 req->reply[2] = CUDA_GET_TIME; in pmu_send_request()
1015 if (req->nbytes != 6) in pmu_send_request()
1017 req->data[0] = PMU_SET_RTC; in pmu_send_request()
1018 req->nbytes = 5; in pmu_send_request()
1020 req->data[i] = req->data[i+1]; in pmu_send_request()
1021 req->reply_len = 3; in pmu_send_request()
1022 req->reply[0] = CUDA_PACKET; in pmu_send_request()
1023 req->reply[1] = 0; in pmu_send_request()
1024 req->reply[2] = CUDA_SET_TIME; in pmu_send_request()
1031 return -ENXIO; in pmu_send_request()
1032 for (i = req->nbytes - 1; i > 1; --i) in pmu_send_request()
1033 req->data[i+2] = req->data[i]; in pmu_send_request()
1034 req->data[3] = req->nbytes - 2; in pmu_send_request()
1035 req->data[2] = pmu_adb_flags; in pmu_send_request()
1036 /*req->data[1] = req->data[1];*/ in pmu_send_request()
1037 req->data[0] = PMU_ADB_CMD; in pmu_send_request()
1038 req->nbytes += 2; in pmu_send_request()
1039 req->reply_expected = 1; in pmu_send_request()
1040 req->reply_len = 0; in pmu_send_request()
1045 req->complete = 1; in pmu_send_request()
1050 while (!req->complete) in pmu_send_request()
1077 return -ENXIO; in pmu_adb_autopoll()
1090 return -ENXIO; in pmu_adb_reset_bus()
1106 return -EIO; in pmu_adb_reset_bus()
1126 return -ENXIO; in pmu_request()
1130 req->complete = 1; in pmu_request()
1131 return -EINVAL; in pmu_request()
1133 req->nbytes = nbytes; in pmu_request()
1134 req->done = done; in pmu_request()
1137 req->data[i] = va_arg(list, int); in pmu_request()
1139 req->reply_len = 0; in pmu_request()
1140 req->reply_expected = 0; in pmu_request()
1151 req->complete = 1; in pmu_queue_request()
1152 return -ENXIO; in pmu_queue_request()
1154 if (req->nbytes <= 0) { in pmu_queue_request()
1155 req->complete = 1; in pmu_queue_request()
1158 nsend = pmu_data_len[req->data[0]][0]; in pmu_queue_request()
1159 if (nsend >= 0 && req->nbytes != nsend + 1) { in pmu_queue_request()
1160 req->complete = 1; in pmu_queue_request()
1161 return -EINVAL; in pmu_queue_request()
1164 req->next = NULL; in pmu_queue_request()
1165 req->sent = 0; in pmu_queue_request()
1166 req->complete = 0; in pmu_queue_request()
1170 last_req->next = req; in pmu_queue_request()
1191 if (--timeout < 0) { in wait_for_ack()
1222 void (*done)(struct adb_request *) = req->done; in pmu_done()
1224 req->complete = 1; in pmu_done()
1226 * struct request will survive to setting req->complete to 1 in pmu_done()
1241 || (/*req->reply_expected && */req_awaiting_reply)) in pmu_start()
1246 data_len = pmu_data_len[req->data[0]][0]; in pmu_start()
1253 send_byte(req->data[0]); in pmu_start()
1286 while((pmu_state != idle && pmu_state != locked) || !req->complete) in pmu_wait_complete()
1335 pmu_suspended--; in pmu_resume()
1382 idx = ffs(ints) - 1; in pmu_handle_data()
1389 * on the Pismo. Still investigating... --BenH in pmu_handle_data()
1401 req->reply_len = 0; in pmu_handle_data()
1403 memcpy(req->reply, data + 1, len - 1); in pmu_handle_data()
1404 req->reply_len = len - 1; in pmu_handle_data()
1427 adb_input(data+1, len-1, 1); in pmu_handle_data()
1444 if ((--query_batt_timer) == 0) { in pmu_handle_data()
1495 data_len = req->nbytes - 1; in pmu_sr_intr()
1500 send_byte(req->data[data_index++]); in pmu_sr_intr()
1503 req->sent = 1; in pmu_sr_intr()
1504 data_len = pmu_data_len[req->data[0]][1]; in pmu_sr_intr()
1507 current_req = req->next; in pmu_sr_intr()
1508 if (req->reply_expected) in pmu_sr_intr()
1515 reply_ptr = req->reply + req->reply_len; in pmu_sr_intr()
1522 data_len = -1; in pmu_sr_intr()
1534 if (data_len == -1) { in pmu_sr_intr()
1557 current_req = req->next; in pmu_sr_intr()
1558 req->reply_len += data_index; in pmu_sr_intr()
1559 if (req->data[0] == PMU_SLEEP || req->data[0] == PMU_CPU_SPEED) in pmu_sr_intr()
1580 int int_data = -1; in via_pmu_interrupt()
1660 --disable_poll; in via_pmu_interrupt()
1675 int_data = -1; in via_pmu_interrupt()
1730 /* Offset between Unix time (1970-based) and Mac time (1904-based) */
1745 return (time64_t)now - RTC_OFFSET; in pmu_get_time()
1756 return -ENXIO; in pmu_set_rtc_time()
1874 return -ENODEV; in powerbook_sleep_grackle()
1884 save_l2cr = _get_L2CR(); /* (returns -1 if not available) */ in powerbook_sleep_grackle()
1903 /* Call low-level ASM sleep handler */ in powerbook_sleep_grackle()
1925 switch_mmu_context(NULL, current->active_mm, NULL); in powerbook_sleep_grackle()
1948 if (pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,0,-1) < 0) { in powerbook_sleep_Core99()
1950 return -ENOSYS; in powerbook_sleep_Core99()
1954 return -EAGAIN; in powerbook_sleep_Core99()
1970 save_l3cr = _get_L3CR(); /* (returns -1 if not available) */ in powerbook_sleep_Core99()
1971 save_l2cr = _get_L2CR(); /* (returns -1 if not available) */ in powerbook_sleep_Core99()
1988 /* Call low-level ASM sleep handler */ in powerbook_sleep_Core99()
2014 switch_mmu_context(NULL, current->active_mm, NULL); in powerbook_sleep_Core99()
2051 return -ENOMEM; in powerbook_sleep_3400()
2056 for (i = 0x403f; i >= 0x4000; --i) { in powerbook_sleep_3400()
2126 if (len > sizeof(pp->rb_buf[0].data)) in pmu_pass_intr()
2127 len = sizeof(pp->rb_buf[0].data); in pmu_pass_intr()
2129 for (list = &all_pmu_pvt; (list = list->next) != &all_pmu_pvt; ) { in pmu_pass_intr()
2131 spin_lock(&pp->lock); in pmu_pass_intr()
2132 i = pp->rb_put + 1; in pmu_pass_intr()
2135 if (i != pp->rb_get) { in pmu_pass_intr()
2136 struct rb_entry *rp = &pp->rb_buf[pp->rb_put]; in pmu_pass_intr()
2137 rp->len = len; in pmu_pass_intr()
2138 memcpy(rp->data, data, len); in pmu_pass_intr()
2139 pp->rb_put = i; in pmu_pass_intr()
2140 wake_up_interruptible(&pp->wait); in pmu_pass_intr()
2142 spin_unlock(&pp->lock); in pmu_pass_intr()
2155 return -ENOMEM; in pmu_open()
2156 pp->rb_get = pp->rb_put = 0; in pmu_open()
2157 spin_lock_init(&pp->lock); in pmu_open()
2158 init_waitqueue_head(&pp->wait); in pmu_open()
2162 pp->backlight_locker = 0; in pmu_open()
2164 list_add(&pp->list, &all_pmu_pvt); in pmu_open()
2166 file->private_data = pp; in pmu_open()
2175 struct pmu_private *pp = file->private_data; in pmu_read()
2181 return -EINVAL; in pmu_read()
2183 spin_lock_irqsave(&pp->lock, flags); in pmu_read()
2184 add_wait_queue(&pp->wait, &wait); in pmu_read()
2188 ret = -EAGAIN; in pmu_read()
2189 if (pp->rb_get != pp->rb_put) { in pmu_read()
2190 int i = pp->rb_get; in pmu_read()
2191 struct rb_entry *rp = &pp->rb_buf[i]; in pmu_read()
2192 ret = rp->len; in pmu_read()
2193 spin_unlock_irqrestore(&pp->lock, flags); in pmu_read()
2196 if (ret > 0 && copy_to_user(buf, rp->data, ret)) in pmu_read()
2197 ret = -EFAULT; in pmu_read()
2200 spin_lock_irqsave(&pp->lock, flags); in pmu_read()
2201 pp->rb_get = i; in pmu_read()
2205 if (file->f_flags & O_NONBLOCK) in pmu_read()
2207 ret = -ERESTARTSYS; in pmu_read()
2210 spin_unlock_irqrestore(&pp->lock, flags); in pmu_read()
2212 spin_lock_irqsave(&pp->lock, flags); in pmu_read()
2215 remove_wait_queue(&pp->wait, &wait); in pmu_read()
2216 spin_unlock_irqrestore(&pp->lock, flags); in pmu_read()
2231 struct pmu_private *pp = filp->private_data; in pmu_fpoll()
2237 poll_wait(filp, &pp->wait, wait); in pmu_fpoll()
2238 spin_lock_irqsave(&pp->lock, flags); in pmu_fpoll()
2239 if (pp->rb_get != pp->rb_put) in pmu_fpoll()
2241 spin_unlock_irqrestore(&pp->lock, flags); in pmu_fpoll()
2248 struct pmu_private *pp = file->private_data; in pmu_release()
2252 file->private_data = NULL; in pmu_release()
2254 list_del(&pp->list); in pmu_release()
2258 if (pp->backlight_locker) in pmu_release()
2305 return -ENOSYS; in powerbook_sleep()
2332 && (pmac_call_feature(PMAC_FTR_SLEEP_STATE, NULL, 0, -1) >= 0); in pmu_sleep_valid()
2358 int error = -EINVAL; in pmu_ioctl()
2364 return -EACCES; in pmu_ioctl()
2367 if (pmac_call_feature(PMAC_FTR_SLEEP_STATE, NULL, 0, -1) < 0) in pmu_ioctl()
2398 struct pmu_private *pp = filp->private_data; in pmu_ioctl()
2400 if (pp->backlight_locker) in pmu_ioctl()
2403 pp->backlight_locker = 1; in pmu_ioctl()
2463 return -ENOIOCTLCMD; in compat_pmu_ioctl()
2491 printk(KERN_ERR "via-pmu: cannot register misc device.\n"); in pmu_device_init()
2535 req->complete = 1; in pmu_polled_request()
2536 c = req->data[0]; in pmu_polled_request()
2538 if (l >= 0 && req->nbytes != l + 1) in pmu_polled_request()
2539 return -EINVAL; in pmu_polled_request()
2549 l = req->nbytes - 1; in pmu_polled_request()
2553 polled_send_byte(req->data[i]); in pmu_polled_request()
2559 req->reply[i + req->reply_len] = polled_recv_byte(); in pmu_polled_request()
2561 if (req->done) in pmu_polled_request()
2562 (*req->done)(req); in pmu_polled_request()
2575 for (; n > 0; --n) { in pmu_blink()