21 #include <linux/types.h>
22 #include <linux/errno.h>
23 #include <linux/kernel.h>
27 #include <linux/pci.h>
31 #include <linux/adb.h>
32 #include <linux/pmu.h>
33 #include <linux/cuda.h>
39 #include <asm/pgtable.h>
41 #include <asm/uaccess.h>
90 static unsigned char *reply_ptr;
91 static int data_index;
93 static int adb_int_pending;
94 static int pmu_adb_flags;
95 static int adb_dev_map;
96 static struct adb_request bright_req_1, bright_req_2, bright_req_3;
98 static int pmu_fully_inited;
102 static int pmu_probe(
void);
103 static int pmu_init(
void);
104 static void pmu_start(
void);
107 static int pmu_autopoll(
int devs);
109 static int pmu_reset_bus(
void);
111 static void pmu_start(
void);
112 static void send_byte(
int x);
113 static void recv_byte(
void);
115 static void pmu_handle_data(
unsigned char *
data,
int len);
116 static void set_volume(
int level);
117 static void pmu_enable_backlight(
int on);
118 static void pmu_set_brightness(
int level);
137 static s8 pmu_data_len[256][2] = {
139 {-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
140 {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
141 { 1, 0},{ 1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
142 { 0, 1},{ 0, 1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{ 0, 0},
143 {-1, 0},{ 0, 0},{ 2, 0},{ 1, 0},{ 1, 0},{-1, 0},{-1, 0},{-1, 0},
144 { 0,-1},{ 0,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{ 0,-1},
145 { 4, 0},{20, 0},{-1, 0},{ 3, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
146 { 0, 4},{ 0,20},{ 2,-1},{ 2, 1},{ 3,-1},{-1,-1},{-1,-1},{ 4, 0},
147 { 1, 0},{ 1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
148 { 0, 1},{ 0, 1},{-1,-1},{ 1, 0},{ 1, 0},{-1,-1},{-1,-1},{-1,-1},
149 { 1, 0},{ 0, 0},{ 2, 0},{ 2, 0},{-1, 0},{ 1, 0},{ 3, 0},{ 1, 0},
150 { 0, 1},{ 1, 0},{ 0, 2},{ 0, 2},{ 0,-1},{-1,-1},{-1,-1},{-1,-1},
151 { 2, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
152 { 0, 3},{ 0, 3},{ 0, 2},{ 0, 8},{ 0,-1},{ 0,-1},{-1,-1},{-1,-1},
153 { 1, 0},{ 1, 0},{ 1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
154 { 0,-1},{ 0,-1},{-1,-1},{-1,-1},{-1,-1},{ 5, 1},{ 4, 1},{ 4, 1},
155 { 4, 0},{-1, 0},{ 0, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
156 { 0, 5},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
157 { 1, 0},{ 2, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
158 { 0, 1},{ 0, 1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
159 { 2, 0},{ 2, 0},{ 2, 0},{ 4, 0},{-1, 0},{ 0, 0},{-1, 0},{-1, 0},
160 { 1, 1},{ 1, 0},{ 3, 0},{ 2, 0},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
161 {-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
162 {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
163 {-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
164 {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
165 { 0, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
166 { 1, 1},{ 1, 1},{-1,-1},{-1,-1},{ 0, 1},{ 0,-1},{-1,-1},{-1,-1},
167 {-1, 0},{ 4, 0},{ 0, 1},{-1, 0},{-1, 0},{ 4, 0},{-1, 0},{-1, 0},
168 { 3,-1},{-1,-1},{ 0, 1},{-1,-1},{ 0,-1},{-1,-1},{-1,-1},{ 0, 0},
169 {-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
170 {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
199 while (!
req.complete) {
218 pmu_interrupt(0,
NULL);
227 while (!
req.complete) {
236 bright_req_1.complete = 1;
237 bright_req_2.complete = 1;
238 bright_req_3.complete = 1;
254 pmu_fully_inited = 1;
257 pmu_enable_backlight(1);
259 printk(
"adb: PMU 68K driver v0.5 for Unified ADB.\n");
276 if (!pmu_fully_inited)
284 switch (req->
data[0]) {
286 for (i = 0; i < req->
nbytes - 1; ++
i)
289 if (pmu_data_len[req->
data[0]][1] != 0) {
297 switch (req->
data[1]) {
314 for (i = 1; i <= 4; ++
i)
352 for (i = req->
nbytes - 1; i > 1; --i)
355 req->
data[2] = pmu_adb_flags;
380 pmu_autopoll(
int devs)
384 if (!pmu_fully_inited)
return -
ENXIO;
389 adb_dev_map >> 8, adb_dev_map);
406 int save_autopoll = adb_dev_map;
408 if (!pmu_fully_inited)
return -
ENXIO;
432 printk(
KERN_ERR "pmu_adb_reset_bus (reset): no response from PMU\n");
439 if (save_autopoll != 0)
440 pmu_autopoll(save_autopoll);
453 if (nbytes < 0 || nbytes > 32) {
464 if (pmu_data_len[req->
data[0]][1] != 0) {
483 nsend = pmu_data_len[req->
data[0]][0];
484 if (nsend >= 0 && req->
nbytes != nsend + 1) {
494 if (current_req != 0) {
545 send_byte(req->
data[0]);
569 pmu_interrupt(
int irq,
void *
dev_id)
572 int timeout,
bite = 0;
575 printk(
"pmu_interrupt: irq %d state %d acr %02X, b %02X data_index %d/%d adb_int_pending %d\n",
592 while (!(
via2[
B] & TACK)) {
609 send_byte(req->
data[data_index++]);
616 current_req = req->
next;
618 req_awaiting_reply =
req;
645 reply_ptr[data_index++] =
bite;
656 current_req = req->
next;
671 if (adb_int_pending) {
675 }
else if (current_req) {
681 printk(
"pmu_interrupt: exit state %d acr %02X, b %02X data_index %d/%d adb_int_pending %d\n",
697 pmu_handle_data(
unsigned char *
data,
int len)
699 static int show_pmu_ints = 1;
713 req_awaiting_reply =
NULL;
725 if (data[0] == 0x08 && len == 3) {
727 pmu_set_brightness(data[1] >> 3);
729 }
else if (show_pmu_ints
733 for (i = 0; i < len; ++
i)
740 static int backlight_level = -1;
741 static int backlight_enabled = 0;
743 #define LEVEL_TO_BRIGHT(lev) ((lev) < 1? 0x7f: 0x4a - ((lev) << 1))
746 pmu_enable_backlight(
int on)
752 if (backlight_level < 0) {
760 backlight_level = req.
reply[1];
763 backlight_enabled = 0;
776 backlight_enabled = on;
780 pmu_set_brightness(
int level)
784 backlight_level =
level;
786 if (!backlight_enabled)
788 if (bright_req_1.complete)
791 if (bright_req_2.complete)
808 set_volume(
int level)