diff options
author | Kevin A. Granade <kevin.granade@gmail.com> | 2009-09-05 02:03:39 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2009-09-15 15:02:33 -0400 |
commit | 1ff12a4aa354bed093a0240d5e6347b1e27601bc (patch) | |
tree | f7508ad663caf36189325efe55d0af456471a212 | |
parent | a89dfebdad050598479c73c1a22e2323085b5596 (diff) |
Staging: asus_oled: Cleaned up checkpatch issues.
Signed-off-by: Kevin A. Granade <kevin.granade@gmail.com>
Cc: Belisko Marek <marek.belisko@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r-- | drivers/staging/asus_oled/asus_oled.c | 404 |
1 files changed, 221 insertions, 183 deletions
diff --git a/drivers/staging/asus_oled/asus_oled.c b/drivers/staging/asus_oled/asus_oled.c index 9270f5df0204..f4c26572c7df 100644 --- a/drivers/staging/asus_oled/asus_oled.c +++ b/drivers/staging/asus_oled/asus_oled.c | |||
@@ -63,26 +63,31 @@ static uint start_off; | |||
63 | 63 | ||
64 | module_param(start_off, uint, 0644); | 64 | module_param(start_off, uint, 0644); |
65 | 65 | ||
66 | MODULE_PARM_DESC(start_off, "Set to 1 to switch off OLED display after it is attached"); | 66 | MODULE_PARM_DESC(start_off, |
67 | "Set to 1 to switch off OLED display after it is attached"); | ||
67 | 68 | ||
68 | typedef enum { | 69 | enum oled_pack_mode{ |
69 | PACK_MODE_G1, | 70 | PACK_MODE_G1, |
70 | PACK_MODE_G50, | 71 | PACK_MODE_G50, |
71 | PACK_MODE_LAST | 72 | PACK_MODE_LAST |
72 | } oled_pack_mode_t; | 73 | }; |
73 | 74 | ||
74 | struct oled_dev_desc_str { | 75 | struct oled_dev_desc_str { |
75 | uint16_t idVendor; | 76 | uint16_t idVendor; |
76 | uint16_t idProduct; | 77 | uint16_t idProduct; |
77 | uint16_t devWidth; // width of display | 78 | /* width of display */ |
78 | oled_pack_mode_t packMode; // formula to be used while packing the picture | 79 | uint16_t devWidth; |
80 | /* formula to be used while packing the picture */ | ||
81 | enum oled_pack_mode packMode; | ||
79 | const char *devDesc; | 82 | const char *devDesc; |
80 | }; | 83 | }; |
81 | 84 | ||
82 | /* table of devices that work with this driver */ | 85 | /* table of devices that work with this driver */ |
83 | static struct usb_device_id id_table[] = { | 86 | static struct usb_device_id id_table[] = { |
84 | { USB_DEVICE(0x0b05, 0x1726) }, // Asus G1/G2 (and variants) | 87 | /* Asus G1/G2 (and variants)*/ |
85 | { USB_DEVICE(0x0b05, 0x175b) }, // Asus G50V (and possibly others - G70? G71?) | 88 | { USB_DEVICE(0x0b05, 0x1726) }, |
89 | /* Asus G50V (and possibly others - G70? G71?)*/ | ||
90 | { USB_DEVICE(0x0b05, 0x175b) }, | ||
86 | { }, | 91 | { }, |
87 | }; | 92 | }; |
88 | 93 | ||
@@ -95,20 +100,6 @@ static struct oled_dev_desc_str oled_dev_desc_table[] = { | |||
95 | 100 | ||
96 | MODULE_DEVICE_TABLE(usb, id_table); | 101 | MODULE_DEVICE_TABLE(usb, id_table); |
97 | 102 | ||
98 | #define SETUP_PACKET_HEADER(packet, val1, val2, val3, val4, val5, val6, val7) \ | ||
99 | do { \ | ||
100 | memset(packet, 0, sizeof(struct asus_oled_header)); \ | ||
101 | packet->header.magic1 = 0x55; \ | ||
102 | packet->header.magic2 = 0xaa; \ | ||
103 | packet->header.flags = val1; \ | ||
104 | packet->header.value3 = val2; \ | ||
105 | packet->header.buffer1 = val3; \ | ||
106 | packet->header.buffer2 = val4; \ | ||
107 | packet->header.value6 = val5; \ | ||
108 | packet->header.value7 = val6; \ | ||
109 | packet->header.value8 = val7; \ | ||
110 | } while (0); | ||
111 | |||
112 | struct asus_oled_header { | 103 | struct asus_oled_header { |
113 | uint8_t magic1; | 104 | uint8_t magic1; |
114 | uint8_t magic2; | 105 | uint8_t magic2; |
@@ -128,10 +119,10 @@ struct asus_oled_packet { | |||
128 | } __attribute((packed)); | 119 | } __attribute((packed)); |
129 | 120 | ||
130 | struct asus_oled_dev { | 121 | struct asus_oled_dev { |
131 | struct usb_device * udev; | 122 | struct usb_device *udev; |
132 | uint8_t pic_mode; | 123 | uint8_t pic_mode; |
133 | uint16_t dev_width; | 124 | uint16_t dev_width; |
134 | oled_pack_mode_t pack_mode; | 125 | enum oled_pack_mode pack_mode; |
135 | size_t height; | 126 | size_t height; |
136 | size_t width; | 127 | size_t width; |
137 | size_t x_shift; | 128 | size_t x_shift; |
@@ -144,12 +135,28 @@ struct asus_oled_dev { | |||
144 | struct device *dev; | 135 | struct device *dev; |
145 | }; | 136 | }; |
146 | 137 | ||
138 | static void setup_packet_header(struct asus_oled_packet *packet, char flags, | ||
139 | char value3, char buffer1, char buffer2, char value6, | ||
140 | char value7, char value8) | ||
141 | { | ||
142 | memset(packet, 0, sizeof(struct asus_oled_header)); | ||
143 | packet->header.magic1 = 0x55; | ||
144 | packet->header.magic2 = 0xaa; | ||
145 | packet->header.flags = flags; | ||
146 | packet->header.value3 = value3; | ||
147 | packet->header.buffer1 = buffer1; | ||
148 | packet->header.buffer2 = buffer2; | ||
149 | packet->header.value6 = value6; | ||
150 | packet->header.value7 = value7; | ||
151 | packet->header.value8 = value8; | ||
152 | } | ||
153 | |||
147 | static void enable_oled(struct asus_oled_dev *odev, uint8_t enabl) | 154 | static void enable_oled(struct asus_oled_dev *odev, uint8_t enabl) |
148 | { | 155 | { |
149 | int a; | 156 | int a; |
150 | int retval; | 157 | int retval; |
151 | int act_len; | 158 | int act_len; |
152 | struct asus_oled_packet * packet; | 159 | struct asus_oled_packet *packet; |
153 | 160 | ||
154 | packet = kzalloc(sizeof(struct asus_oled_packet), GFP_KERNEL); | 161 | packet = kzalloc(sizeof(struct asus_oled_packet), GFP_KERNEL); |
155 | 162 | ||
@@ -158,7 +165,7 @@ static void enable_oled(struct asus_oled_dev *odev, uint8_t enabl) | |||
158 | return; | 165 | return; |
159 | } | 166 | } |
160 | 167 | ||
161 | SETUP_PACKET_HEADER(packet, 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00); | 168 | setup_packet_header(packet, 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00); |
162 | 169 | ||
163 | if (enabl) | 170 | if (enabl) |
164 | packet->bitmap[0] = 0xaf; | 171 | packet->bitmap[0] = 0xaf; |
@@ -182,29 +189,34 @@ static void enable_oled(struct asus_oled_dev *odev, uint8_t enabl) | |||
182 | kfree(packet); | 189 | kfree(packet); |
183 | } | 190 | } |
184 | 191 | ||
185 | static ssize_t set_enabled(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) | 192 | static ssize_t set_enabled(struct device *dev, struct device_attribute *attr, |
193 | const char *buf, size_t count) | ||
186 | { | 194 | { |
187 | struct usb_interface *intf = to_usb_interface(dev); | 195 | struct usb_interface *intf = to_usb_interface(dev); |
188 | struct asus_oled_dev *odev = usb_get_intfdata(intf); | 196 | struct asus_oled_dev *odev = usb_get_intfdata(intf); |
189 | int temp = simple_strtoul(buf, NULL, 10); | 197 | int temp = strict_strtoul(buf, 10, NULL); |
190 | 198 | ||
191 | enable_oled(odev, temp); | 199 | enable_oled(odev, temp); |
192 | 200 | ||
193 | return count; | 201 | return count; |
194 | } | 202 | } |
195 | 203 | ||
196 | static ssize_t class_set_enabled(struct device *device, struct device_attribute *attr, const char *buf, size_t count) | 204 | static ssize_t class_set_enabled(struct device *device, |
205 | struct device_attribute *attr, | ||
206 | const char *buf, size_t count) | ||
197 | { | 207 | { |
198 | struct asus_oled_dev *odev = (struct asus_oled_dev *) dev_get_drvdata(device); | 208 | struct asus_oled_dev *odev = |
209 | (struct asus_oled_dev *) dev_get_drvdata(device); | ||
199 | 210 | ||
200 | int temp = simple_strtoul(buf, NULL, 10); | 211 | int temp = strict_strtoul(buf, 10, NULL); |
201 | 212 | ||
202 | enable_oled(odev, temp); | 213 | enable_oled(odev, temp); |
203 | 214 | ||
204 | return count; | 215 | return count; |
205 | } | 216 | } |
206 | 217 | ||
207 | static ssize_t get_enabled(struct device *dev, struct device_attribute *attr, char *buf) | 218 | static ssize_t get_enabled(struct device *dev, struct device_attribute *attr, |
219 | char *buf) | ||
208 | { | 220 | { |
209 | struct usb_interface *intf = to_usb_interface(dev); | 221 | struct usb_interface *intf = to_usb_interface(dev); |
210 | struct asus_oled_dev *odev = usb_get_intfdata(intf); | 222 | struct asus_oled_dev *odev = usb_get_intfdata(intf); |
@@ -212,15 +224,18 @@ static ssize_t get_enabled(struct device *dev, struct device_attribute *attr, ch | |||
212 | return sprintf(buf, "%d\n", odev->enabled); | 224 | return sprintf(buf, "%d\n", odev->enabled); |
213 | } | 225 | } |
214 | 226 | ||
215 | static ssize_t class_get_enabled(struct device *device, struct device_attribute *attr, char *buf) | 227 | static ssize_t class_get_enabled(struct device *device, |
228 | struct device_attribute *attr, char *buf) | ||
216 | { | 229 | { |
217 | struct asus_oled_dev *odev = (struct asus_oled_dev *) dev_get_drvdata(device); | 230 | struct asus_oled_dev *odev = |
231 | (struct asus_oled_dev *) dev_get_drvdata(device); | ||
218 | 232 | ||
219 | return sprintf(buf, "%d\n", odev->enabled); | 233 | return sprintf(buf, "%d\n", odev->enabled); |
220 | } | 234 | } |
221 | 235 | ||
222 | static void send_packets(struct usb_device *udev, struct asus_oled_packet *packet, | 236 | static void send_packets(struct usb_device *udev, |
223 | char *buf, uint8_t p_type, size_t p_num) | 237 | struct asus_oled_packet *packet, |
238 | char *buf, uint8_t p_type, size_t p_num) | ||
224 | { | 239 | { |
225 | size_t i; | 240 | size_t i; |
226 | int act_len; | 241 | int act_len; |
@@ -229,65 +244,76 @@ static void send_packets(struct usb_device *udev, struct asus_oled_packet *packe | |||
229 | int retval; | 244 | int retval; |
230 | 245 | ||
231 | switch (p_type) { | 246 | switch (p_type) { |
232 | case ASUS_OLED_ROLL: | 247 | case ASUS_OLED_ROLL: |
233 | SETUP_PACKET_HEADER(packet, 0x40, 0x80, p_num, i + 1, 0x00, 0x01, 0xff); | 248 | setup_packet_header(packet, 0x40, 0x80, p_num, |
249 | i + 1, 0x00, 0x01, 0xff); | ||
234 | break; | 250 | break; |
235 | case ASUS_OLED_STATIC: | 251 | case ASUS_OLED_STATIC: |
236 | SETUP_PACKET_HEADER(packet, 0x10 + i, 0x80, 0x01, 0x01, 0x00, 0x01, 0x00); | 252 | setup_packet_header(packet, 0x10 + i, 0x80, 0x01, |
253 | 0x01, 0x00, 0x01, 0x00); | ||
237 | break; | 254 | break; |
238 | case ASUS_OLED_FLASH: | 255 | case ASUS_OLED_FLASH: |
239 | SETUP_PACKET_HEADER(packet, 0x10 + i, 0x80, 0x01, 0x01, 0x00, 0x00, 0xff); | 256 | setup_packet_header(packet, 0x10 + i, 0x80, 0x01, |
257 | 0x01, 0x00, 0x00, 0xff); | ||
240 | break; | 258 | break; |
241 | } | 259 | } |
242 | 260 | ||
243 | memcpy(packet->bitmap, buf + (ASUS_OLED_PACKET_BUF_SIZE*i), ASUS_OLED_PACKET_BUF_SIZE); | 261 | memcpy(packet->bitmap, buf + (ASUS_OLED_PACKET_BUF_SIZE*i), |
262 | ASUS_OLED_PACKET_BUF_SIZE); | ||
244 | 263 | ||
245 | retval = usb_bulk_msg(udev, | 264 | retval = usb_bulk_msg(udev, usb_sndctrlpipe(udev, 2), |
246 | usb_sndctrlpipe(udev, 2), | 265 | packet, sizeof(struct asus_oled_packet), |
247 | packet, | 266 | &act_len, -1); |
248 | sizeof(struct asus_oled_packet), | ||
249 | &act_len, | ||
250 | -1); | ||
251 | 267 | ||
252 | if (retval) | 268 | if (retval) |
253 | dev_dbg(&udev->dev, "retval = %d\n", retval); | 269 | dev_dbg(&udev->dev, "retval = %d\n", retval); |
254 | } | 270 | } |
255 | } | 271 | } |
256 | 272 | ||
257 | static void send_packet(struct usb_device *udev, struct asus_oled_packet *packet, size_t offset, size_t len, char *buf, uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4, uint8_t b5, uint8_t b6) { | 273 | static void send_packet(struct usb_device *udev, |
274 | struct asus_oled_packet *packet, | ||
275 | size_t offset, size_t len, char *buf, uint8_t b1, | ||
276 | uint8_t b2, uint8_t b3, uint8_t b4, uint8_t b5, | ||
277 | uint8_t b6) { | ||
258 | int retval; | 278 | int retval; |
259 | int act_len; | 279 | int act_len; |
260 | 280 | ||
261 | SETUP_PACKET_HEADER(packet, b1, b2, b3, b4, b5, b6, 0x00); | 281 | setup_packet_header(packet, b1, b2, b3, b4, b5, b6, 0x00); |
262 | memcpy(packet->bitmap, buf + offset, len); | 282 | memcpy(packet->bitmap, buf + offset, len); |
263 | 283 | ||
264 | retval = usb_bulk_msg(udev, | 284 | retval = usb_bulk_msg(udev, |
265 | usb_sndctrlpipe(udev, 2), | 285 | usb_sndctrlpipe(udev, 2), |
266 | packet, | 286 | packet, |
267 | sizeof(struct asus_oled_packet), | 287 | sizeof(struct asus_oled_packet), |
268 | &act_len, | 288 | &act_len, |
269 | -1); | 289 | -1); |
270 | 290 | ||
271 | if (retval) | 291 | if (retval) |
272 | dev_dbg(&udev->dev, "retval = %d\n", retval); | 292 | dev_dbg(&udev->dev, "retval = %d\n", retval); |
273 | } | 293 | } |
274 | 294 | ||
275 | 295 | ||
276 | static void send_packets_g50(struct usb_device *udev, struct asus_oled_packet *packet, char *buf) | 296 | static void send_packets_g50(struct usb_device *udev, |
297 | struct asus_oled_packet *packet, char *buf) | ||
277 | { | 298 | { |
278 | send_packet(udev, packet, 0, 0x100, buf, 0x10, 0x00, 0x02, 0x01, 0x00, 0x01); | 299 | send_packet(udev, packet, 0, 0x100, buf, |
279 | send_packet(udev, packet, 0x100, 0x080, buf, 0x10, 0x00, 0x02, 0x02, 0x80, 0x00); | 300 | 0x10, 0x00, 0x02, 0x01, 0x00, 0x01); |
280 | 301 | send_packet(udev, packet, 0x100, 0x080, buf, | |
281 | send_packet(udev, packet, 0x180, 0x100, buf, 0x11, 0x00, 0x03, 0x01, 0x00, 0x01); | 302 | 0x10, 0x00, 0x02, 0x02, 0x80, 0x00); |
282 | send_packet(udev, packet, 0x280, 0x100, buf, 0x11, 0x00, 0x03, 0x02, 0x00, 0x01); | 303 | |
283 | send_packet(udev, packet, 0x380, 0x080, buf, 0x11, 0x00, 0x03, 0x03, 0x80, 0x00); | 304 | send_packet(udev, packet, 0x180, 0x100, buf, |
305 | 0x11, 0x00, 0x03, 0x01, 0x00, 0x01); | ||
306 | send_packet(udev, packet, 0x280, 0x100, buf, | ||
307 | 0x11, 0x00, 0x03, 0x02, 0x00, 0x01); | ||
308 | send_packet(udev, packet, 0x380, 0x080, buf, | ||
309 | 0x11, 0x00, 0x03, 0x03, 0x80, 0x00); | ||
284 | } | 310 | } |
285 | 311 | ||
286 | 312 | ||
287 | static void send_data(struct asus_oled_dev *odev) | 313 | static void send_data(struct asus_oled_dev *odev) |
288 | { | 314 | { |
289 | size_t packet_num = odev->buf_size / ASUS_OLED_PACKET_BUF_SIZE; | 315 | size_t packet_num = odev->buf_size / ASUS_OLED_PACKET_BUF_SIZE; |
290 | struct asus_oled_packet * packet; | 316 | struct asus_oled_packet *packet; |
291 | 317 | ||
292 | packet = kzalloc(sizeof(struct asus_oled_packet), GFP_KERNEL); | 318 | packet = kzalloc(sizeof(struct asus_oled_packet), GFP_KERNEL); |
293 | 319 | ||
@@ -297,20 +323,20 @@ static void send_data(struct asus_oled_dev *odev) | |||
297 | } | 323 | } |
298 | 324 | ||
299 | if (odev->pack_mode == PACK_MODE_G1) { | 325 | if (odev->pack_mode == PACK_MODE_G1) { |
300 | // When sending roll-mode data the display updated only first packet. | 326 | /* When sending roll-mode data the display updated only |
301 | // I have no idea why, but when static picture is send just before | 327 | first packet. I have no idea why, but when static picture |
302 | // rolling picture - everything works fine. | 328 | is sent just before rolling picture everything works fine. */ |
303 | if (odev->pic_mode == ASUS_OLED_ROLL) | 329 | if (odev->pic_mode == ASUS_OLED_ROLL) |
304 | send_packets(odev->udev, packet, odev->buf, ASUS_OLED_STATIC, 2); | 330 | send_packets(odev->udev, packet, odev->buf, |
331 | ASUS_OLED_STATIC, 2); | ||
305 | 332 | ||
306 | // Only ROLL mode can use more than 2 packets. | 333 | /* Only ROLL mode can use more than 2 packets.*/ |
307 | if (odev->pic_mode != ASUS_OLED_ROLL && packet_num > 2) | 334 | if (odev->pic_mode != ASUS_OLED_ROLL && packet_num > 2) |
308 | packet_num = 2; | 335 | packet_num = 2; |
309 | 336 | ||
310 | send_packets(odev->udev, packet, odev->buf, odev->pic_mode, packet_num); | 337 | send_packets(odev->udev, packet, odev->buf, |
311 | } | 338 | odev->pic_mode, packet_num); |
312 | else | 339 | } else if (odev->pack_mode == PACK_MODE_G50) { |
313 | if (odev->pack_mode == PACK_MODE_G50) { | ||
314 | send_packets_g50(odev->udev, packet, odev->buf); | 340 | send_packets_g50(odev->udev, packet, odev->buf); |
315 | } | 341 | } |
316 | 342 | ||
@@ -319,53 +345,55 @@ static void send_data(struct asus_oled_dev *odev) | |||
319 | 345 | ||
320 | static int append_values(struct asus_oled_dev *odev, uint8_t val, size_t count) | 346 | static int append_values(struct asus_oled_dev *odev, uint8_t val, size_t count) |
321 | { | 347 | { |
322 | while (count-- > 0) { | 348 | while (count-- > 0 && val) { |
323 | if (val) { | 349 | size_t x = odev->buf_offs % odev->width; |
324 | size_t x = odev->buf_offs % odev->width; | 350 | size_t y = odev->buf_offs / odev->width; |
325 | size_t y = odev->buf_offs / odev->width; | 351 | size_t i; |
326 | size_t i; | ||
327 | |||
328 | x += odev->x_shift; | ||
329 | y += odev->y_shift; | ||
330 | |||
331 | switch (odev->pack_mode) | ||
332 | { | ||
333 | case PACK_MODE_G1: | ||
334 | // i = (x/128)*640 + 127 - x + (y/8)*128; | ||
335 | // This one for 128 is the same, but might be better for different widths? | ||
336 | i = (x/odev->dev_width)*640 + odev->dev_width - 1 - x + (y/8)*odev->dev_width; | ||
337 | break; | ||
338 | 352 | ||
339 | case PACK_MODE_G50: | 353 | x += odev->x_shift; |
340 | i = (odev->dev_width - 1 - x)/8 + y*odev->dev_width/8; | 354 | y += odev->y_shift; |
341 | break; | 355 | |
356 | switch (odev->pack_mode) { | ||
357 | case PACK_MODE_G1: | ||
358 | /* i = (x/128)*640 + 127 - x + (y/8)*128; | ||
359 | This one for 128 is the same, but might be better | ||
360 | for different widths? */ | ||
361 | i = (x/odev->dev_width)*640 + | ||
362 | odev->dev_width - 1 - x + | ||
363 | (y/8)*odev->dev_width; | ||
364 | break; | ||
342 | 365 | ||
343 | default: | 366 | case PACK_MODE_G50: |
344 | i = 0; | 367 | i = (odev->dev_width - 1 - x)/8 + y*odev->dev_width/8; |
345 | printk(ASUS_OLED_ERROR "Unknown OLED Pack Mode: %d!\n", odev->pack_mode); | 368 | break; |
346 | break; | ||
347 | } | ||
348 | 369 | ||
349 | if (i >= odev->buf_size) { | 370 | default: |
350 | printk(ASUS_OLED_ERROR "Buffer overflow! Report a bug in the driver: offs: %d >= %d i: %d (x: %d y: %d)\n", | 371 | i = 0; |
351 | (int) odev->buf_offs, (int) odev->buf_size, (int) i, (int) x, (int) y); | 372 | printk(ASUS_OLED_ERROR "Unknown OLED Pack Mode: %d!\n", |
352 | return -EIO; | 373 | odev->pack_mode); |
353 | } | 374 | break; |
375 | } | ||
354 | 376 | ||
355 | switch (odev->pack_mode) | 377 | if (i >= odev->buf_size) { |
356 | { | 378 | printk(ASUS_OLED_ERROR "Buffer overflow! Report a bug:" |
357 | case PACK_MODE_G1: | 379 | "offs: %d >= %d i: %d (x: %d y: %d)\n", |
358 | odev->buf[i] &= ~(1<<(y%8)); | 380 | (int) odev->buf_offs, (int) odev->buf_size, |
359 | break; | 381 | (int) i, (int) x, (int) y); |
382 | return -EIO; | ||
383 | } | ||
360 | 384 | ||
361 | case PACK_MODE_G50: | 385 | switch (odev->pack_mode) { |
362 | odev->buf[i] &= ~(1<<(x%8)); | 386 | case PACK_MODE_G1: |
363 | break; | 387 | odev->buf[i] &= ~(1<<(y%8)); |
388 | break; | ||
364 | 389 | ||
365 | default: | 390 | case PACK_MODE_G50: |
366 | // cannot get here; stops gcc complaining | 391 | odev->buf[i] &= ~(1<<(x%8)); |
367 | ; | 392 | break; |
368 | } | 393 | |
394 | default: | ||
395 | /* cannot get here; stops gcc complaining*/ | ||
396 | ; | ||
369 | } | 397 | } |
370 | 398 | ||
371 | odev->last_val = val; | 399 | odev->last_val = val; |
@@ -375,7 +403,8 @@ static int append_values(struct asus_oled_dev *odev, uint8_t val, size_t count) | |||
375 | return 0; | 403 | return 0; |
376 | } | 404 | } |
377 | 405 | ||
378 | static ssize_t odev_set_picture(struct asus_oled_dev *odev, const char *buf, size_t count) | 406 | static ssize_t odev_set_picture(struct asus_oled_dev *odev, |
407 | const char *buf, size_t count) | ||
379 | { | 408 | { |
380 | size_t offs = 0, max_offs; | 409 | size_t offs = 0, max_offs; |
381 | 410 | ||
@@ -383,32 +412,31 @@ static ssize_t odev_set_picture(struct asus_oled_dev *odev, const char *buf, siz | |||
383 | return 0; | 412 | return 0; |
384 | 413 | ||
385 | if (tolower(buf[0]) == 'b') { | 414 | if (tolower(buf[0]) == 'b') { |
386 | // binary mode, set the entire memory | 415 | /* binary mode, set the entire memory*/ |
387 | 416 | ||
388 | size_t i; | 417 | size_t i; |
389 | 418 | ||
390 | odev->buf_size = (odev->dev_width * ASUS_OLED_DISP_HEIGHT) / 8; | 419 | odev->buf_size = (odev->dev_width * ASUS_OLED_DISP_HEIGHT) / 8; |
391 | 420 | ||
392 | if (odev->buf) | 421 | kfree(odev->buf); |
393 | kfree(odev->buf); | 422 | odev->buf = kmalloc(odev->buf_size, GFP_KERNEL); |
394 | odev->buf = kmalloc(odev->buf_size, GFP_KERNEL); | ||
395 | 423 | ||
396 | memset(odev->buf, 0xff, odev->buf_size); | 424 | memset(odev->buf, 0xff, odev->buf_size); |
397 | 425 | ||
398 | for (i = 1; i < count && i <= 32 * 32; i++) { | 426 | for (i = 1; i < count && i <= 32 * 32; i++) { |
399 | odev->buf[i-1] = buf[i]; | 427 | odev->buf[i-1] = buf[i]; |
400 | odev->buf_offs = i-1; | 428 | odev->buf_offs = i-1; |
401 | } | 429 | } |
402 | 430 | ||
403 | odev->width = odev->dev_width / 8; | 431 | odev->width = odev->dev_width / 8; |
404 | odev->height = ASUS_OLED_DISP_HEIGHT; | 432 | odev->height = ASUS_OLED_DISP_HEIGHT; |
405 | odev->x_shift = 0; | 433 | odev->x_shift = 0; |
406 | odev->y_shift = 0; | 434 | odev->y_shift = 0; |
407 | odev->last_val = 0; | 435 | odev->last_val = 0; |
408 | 436 | ||
409 | send_data(odev); | 437 | send_data(odev); |
410 | 438 | ||
411 | return count; | 439 | return count; |
412 | } | 440 | } |
413 | 441 | ||
414 | if (buf[0] == '<') { | 442 | if (buf[0] == '<') { |
@@ -416,20 +444,21 @@ static ssize_t odev_set_picture(struct asus_oled_dev *odev, const char *buf, siz | |||
416 | size_t w = 0, h = 0; | 444 | size_t w = 0, h = 0; |
417 | size_t w_mem, h_mem; | 445 | size_t w_mem, h_mem; |
418 | 446 | ||
419 | if (count < 10 || buf[2] != ':') { | 447 | if (count < 10 || buf[2] != ':') |
420 | goto error_header; | 448 | goto error_header; |
421 | } | 449 | |
422 | 450 | ||
423 | switch (tolower(buf[1])) { | 451 | switch (tolower(buf[1])) { |
424 | case ASUS_OLED_STATIC: | 452 | case ASUS_OLED_STATIC: |
425 | case ASUS_OLED_ROLL: | 453 | case ASUS_OLED_ROLL: |
426 | case ASUS_OLED_FLASH: | 454 | case ASUS_OLED_FLASH: |
427 | odev->pic_mode = buf[1]; | 455 | odev->pic_mode = buf[1]; |
428 | break; | 456 | break; |
429 | default: | 457 | default: |
430 | printk(ASUS_OLED_ERROR "Wrong picture mode: '%c'.\n", buf[1]); | 458 | printk(ASUS_OLED_ERROR "Wrong picture mode: '%c'.\n", |
431 | return -EIO; | 459 | buf[1]); |
432 | break; | 460 | return -EIO; |
461 | break; | ||
433 | } | 462 | } |
434 | 463 | ||
435 | for (i = 3; i < count; ++i) { | 464 | for (i = 3; i < count; ++i) { |
@@ -438,11 +467,11 @@ static ssize_t odev_set_picture(struct asus_oled_dev *odev, const char *buf, siz | |||
438 | 467 | ||
439 | if (w > ASUS_OLED_MAX_WIDTH) | 468 | if (w > ASUS_OLED_MAX_WIDTH) |
440 | goto error_width; | 469 | goto error_width; |
441 | } | 470 | } else if (tolower(buf[i]) == 'x') { |
442 | else if (tolower(buf[i]) == 'x') | ||
443 | break; | 471 | break; |
444 | else | 472 | } else { |
445 | goto error_width; | 473 | goto error_width; |
474 | } | ||
446 | } | 475 | } |
447 | 476 | ||
448 | for (++i; i < count; ++i) { | 477 | for (++i; i < count; ++i) { |
@@ -451,11 +480,11 @@ static ssize_t odev_set_picture(struct asus_oled_dev *odev, const char *buf, siz | |||
451 | 480 | ||
452 | if (h > ASUS_OLED_DISP_HEIGHT) | 481 | if (h > ASUS_OLED_DISP_HEIGHT) |
453 | goto error_height; | 482 | goto error_height; |
454 | } | 483 | } else if (tolower(buf[i]) == '>') { |
455 | else if (tolower(buf[i]) == '>') | ||
456 | break; | 484 | break; |
457 | else | 485 | } else { |
458 | goto error_height; | 486 | goto error_height; |
487 | } | ||
459 | } | 488 | } |
460 | 489 | ||
461 | if (w < 1 || w > ASUS_OLED_MAX_WIDTH) | 490 | if (w < 1 || w > ASUS_OLED_MAX_WIDTH) |
@@ -481,8 +510,7 @@ static ssize_t odev_set_picture(struct asus_oled_dev *odev, const char *buf, siz | |||
481 | 510 | ||
482 | odev->buf_size = w_mem * h_mem / 8; | 511 | odev->buf_size = w_mem * h_mem / 8; |
483 | 512 | ||
484 | if (odev->buf) | 513 | kfree(odev->buf); |
485 | kfree(odev->buf); | ||
486 | odev->buf = kmalloc(odev->buf_size, GFP_KERNEL); | 514 | odev->buf = kmalloc(odev->buf_size, GFP_KERNEL); |
487 | 515 | ||
488 | if (odev->buf == NULL) { | 516 | if (odev->buf == NULL) { |
@@ -503,8 +531,7 @@ static ssize_t odev_set_picture(struct asus_oled_dev *odev, const char *buf, siz | |||
503 | if (odev->pic_mode == ASUS_OLED_FLASH) { | 531 | if (odev->pic_mode == ASUS_OLED_FLASH) { |
504 | if (h < ASUS_OLED_DISP_HEIGHT/2) | 532 | if (h < ASUS_OLED_DISP_HEIGHT/2) |
505 | odev->y_shift = (ASUS_OLED_DISP_HEIGHT/2 - h)/2; | 533 | odev->y_shift = (ASUS_OLED_DISP_HEIGHT/2 - h)/2; |
506 | } | 534 | } else { |
507 | else { | ||
508 | if (h < ASUS_OLED_DISP_HEIGHT) | 535 | if (h < ASUS_OLED_DISP_HEIGHT) |
509 | odev->y_shift = (ASUS_OLED_DISP_HEIGHT - h)/2; | 536 | odev->y_shift = (ASUS_OLED_DISP_HEIGHT - h)/2; |
510 | } | 537 | } |
@@ -522,20 +549,21 @@ static ssize_t odev_set_picture(struct asus_oled_dev *odev, const char *buf, siz | |||
522 | ret = append_values(odev, 1, 1); | 549 | ret = append_values(odev, 1, 1); |
523 | if (ret < 0) | 550 | if (ret < 0) |
524 | return ret; | 551 | return ret; |
525 | } | 552 | } else if (buf[offs] == '0' || buf[offs] == ' ') { |
526 | else if (buf[offs] == '0' || buf[offs] == ' ') { | ||
527 | ret = append_values(odev, 0, 1); | 553 | ret = append_values(odev, 0, 1); |
528 | if (ret < 0) | 554 | if (ret < 0) |
529 | return ret; | 555 | return ret; |
530 | } | 556 | } else if (buf[offs] == '\n') { |
531 | else if (buf[offs] == '\n') { | 557 | /* New line detected. Lets assume, that all characters |
532 | // New line detected. Lets assume, that all characters till the end of the | 558 | till the end of the line were equal to the last |
533 | // line were equal to the last character in this line. | 559 | character in this line.*/ |
534 | if (odev->buf_offs % odev->width != 0) | 560 | if (odev->buf_offs % odev->width != 0) |
535 | ret = append_values(odev, odev->last_val, | 561 | ret = append_values(odev, odev->last_val, |
536 | odev->width - (odev->buf_offs % odev->width)); | 562 | odev->width - |
537 | if (ret < 0) | 563 | (odev->buf_offs % |
538 | return ret; | 564 | odev->width)); |
565 | if (ret < 0) | ||
566 | return ret; | ||
539 | } | 567 | } |
540 | 568 | ||
541 | offs++; | 569 | offs++; |
@@ -559,47 +587,52 @@ error_header: | |||
559 | return -EIO; | 587 | return -EIO; |
560 | } | 588 | } |
561 | 589 | ||
562 | static ssize_t set_picture(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) | 590 | static ssize_t set_picture(struct device *dev, struct device_attribute *attr, |
591 | const char *buf, size_t count) | ||
563 | { | 592 | { |
564 | struct usb_interface *intf = to_usb_interface(dev); | 593 | struct usb_interface *intf = to_usb_interface(dev); |
565 | 594 | ||
566 | return odev_set_picture(usb_get_intfdata(intf), buf, count); | 595 | return odev_set_picture(usb_get_intfdata(intf), buf, count); |
567 | } | 596 | } |
568 | 597 | ||
569 | static ssize_t class_set_picture(struct device *device, struct device_attribute *attr, const char *buf, size_t count) | 598 | static ssize_t class_set_picture(struct device *device, |
599 | struct device_attribute *attr, | ||
600 | const char *buf, size_t count) | ||
570 | { | 601 | { |
571 | return odev_set_picture((struct asus_oled_dev *) dev_get_drvdata(device), buf, count); | 602 | return odev_set_picture((struct asus_oled_dev *) |
603 | dev_get_drvdata(device), buf, count); | ||
572 | } | 604 | } |
573 | 605 | ||
574 | #define ASUS_OLED_DEVICE_ATTR(_file) dev_attr_asus_oled_##_file | 606 | #define ASUS_OLED_DEVICE_ATTR(_file) dev_attr_asus_oled_##_file |
575 | 607 | ||
576 | static DEVICE_ATTR(asus_oled_enabled, S_IWUGO | S_IRUGO, get_enabled, set_enabled); | 608 | static DEVICE_ATTR(asus_oled_enabled, S_IWUGO | S_IRUGO, |
609 | get_enabled, set_enabled); | ||
577 | static DEVICE_ATTR(asus_oled_picture, S_IWUGO , NULL, set_picture); | 610 | static DEVICE_ATTR(asus_oled_picture, S_IWUGO , NULL, set_picture); |
578 | 611 | ||
579 | static DEVICE_ATTR(enabled, S_IWUGO | S_IRUGO, class_get_enabled, class_set_enabled); | 612 | static DEVICE_ATTR(enabled, S_IWUGO | S_IRUGO, |
613 | class_get_enabled, class_set_enabled); | ||
580 | static DEVICE_ATTR(picture, S_IWUGO, NULL, class_set_picture); | 614 | static DEVICE_ATTR(picture, S_IWUGO, NULL, class_set_picture); |
581 | 615 | ||
582 | static int asus_oled_probe(struct usb_interface *interface, const struct usb_device_id *id) | 616 | static int asus_oled_probe(struct usb_interface *interface, |
617 | const struct usb_device_id *id) | ||
583 | { | 618 | { |
584 | struct usb_device *udev = interface_to_usbdev(interface); | 619 | struct usb_device *udev = interface_to_usbdev(interface); |
585 | struct asus_oled_dev *odev = NULL; | 620 | struct asus_oled_dev *odev = NULL; |
586 | int retval = -ENOMEM; | 621 | int retval = -ENOMEM; |
587 | uint16_t dev_width = 0; | 622 | uint16_t dev_width = 0; |
588 | oled_pack_mode_t pack_mode = PACK_MODE_LAST; | 623 | enum oled_pack_mode pack_mode = PACK_MODE_LAST; |
589 | const struct oled_dev_desc_str * dev_desc = oled_dev_desc_table; | 624 | const struct oled_dev_desc_str *dev_desc = oled_dev_desc_table; |
590 | const char *desc = NULL; | 625 | const char *desc = NULL; |
591 | 626 | ||
592 | if (!id) { | 627 | if (!id) { |
593 | // Even possible? Just to make sure... | 628 | /* Even possible? Just to make sure...*/ |
594 | dev_err(&interface->dev, "No usb_device_id provided!\n"); | 629 | dev_err(&interface->dev, "No usb_device_id provided!\n"); |
595 | return -ENODEV; | 630 | return -ENODEV; |
596 | } | 631 | } |
597 | 632 | ||
598 | for (; dev_desc->idVendor; dev_desc++) | 633 | for (; dev_desc->idVendor; dev_desc++) { |
599 | { | ||
600 | if (dev_desc->idVendor == id->idVendor | 634 | if (dev_desc->idVendor == id->idVendor |
601 | && dev_desc->idProduct == id->idProduct) | 635 | && dev_desc->idProduct == id->idProduct) { |
602 | { | ||
603 | dev_width = dev_desc->devWidth; | 636 | dev_width = dev_desc->devWidth; |
604 | desc = dev_desc->devDesc; | 637 | desc = dev_desc->devDesc; |
605 | pack_mode = dev_desc->packMode; | 638 | pack_mode = dev_desc->packMode; |
@@ -608,7 +641,8 @@ static int asus_oled_probe(struct usb_interface *interface, const struct usb_dev | |||
608 | } | 641 | } |
609 | 642 | ||
610 | if (!desc || dev_width < 1 || pack_mode == PACK_MODE_LAST) { | 643 | if (!desc || dev_width < 1 || pack_mode == PACK_MODE_LAST) { |
611 | dev_err(&interface->dev, "Missing or incomplete device description!\n"); | 644 | dev_err(&interface->dev, |
645 | "Missing or incomplete device description!\n"); | ||
612 | return -ENODEV; | 646 | return -ENODEV; |
613 | } | 647 | } |
614 | 648 | ||
@@ -636,16 +670,18 @@ static int asus_oled_probe(struct usb_interface *interface, const struct usb_dev | |||
636 | 670 | ||
637 | usb_set_intfdata(interface, odev); | 671 | usb_set_intfdata(interface, odev); |
638 | 672 | ||
639 | retval = device_create_file(&interface->dev, &ASUS_OLED_DEVICE_ATTR(enabled)); | 673 | retval = device_create_file(&interface->dev, |
674 | &ASUS_OLED_DEVICE_ATTR(enabled)); | ||
640 | if (retval) | 675 | if (retval) |
641 | goto err_files; | 676 | goto err_files; |
642 | 677 | ||
643 | retval = device_create_file(&interface->dev, &ASUS_OLED_DEVICE_ATTR(picture)); | 678 | retval = device_create_file(&interface->dev, |
679 | &ASUS_OLED_DEVICE_ATTR(picture)); | ||
644 | if (retval) | 680 | if (retval) |
645 | goto err_files; | 681 | goto err_files; |
646 | 682 | ||
647 | odev->dev = device_create(oled_class, &interface->dev, MKDEV(0, 0), | 683 | odev->dev = device_create(oled_class, &interface->dev, MKDEV(0, 0), |
648 | NULL, "oled_%d", ++oled_num); | 684 | NULL, "oled_%d", ++oled_num); |
649 | 685 | ||
650 | if (IS_ERR(odev->dev)) { | 686 | if (IS_ERR(odev->dev)) { |
651 | retval = PTR_ERR(odev->dev); | 687 | retval = PTR_ERR(odev->dev); |
@@ -662,7 +698,9 @@ static int asus_oled_probe(struct usb_interface *interface, const struct usb_dev | |||
662 | if (retval) | 698 | if (retval) |
663 | goto err_class_picture; | 699 | goto err_class_picture; |
664 | 700 | ||
665 | dev_info(&interface->dev, "Attached Asus OLED device: %s [width %u, pack_mode %d]\n", desc, odev->dev_width, odev->pack_mode); | 701 | dev_info(&interface->dev, |
702 | "Attached Asus OLED device: %s [width %u, pack_mode %d]\n", | ||
703 | desc, odev->dev_width, odev->pack_mode); | ||
666 | 704 | ||
667 | if (start_off) | 705 | if (start_off) |
668 | enable_oled(odev, 0); | 706 | enable_oled(odev, 0); |
@@ -703,8 +741,7 @@ static void asus_oled_disconnect(struct usb_interface *interface) | |||
703 | 741 | ||
704 | usb_put_dev(odev->udev); | 742 | usb_put_dev(odev->udev); |
705 | 743 | ||
706 | if (odev->buf) | 744 | kfree(odev->buf); |
707 | kfree(odev->buf); | ||
708 | 745 | ||
709 | kfree(odev); | 746 | kfree(odev); |
710 | 747 | ||
@@ -720,7 +757,8 @@ static struct usb_driver oled_driver = { | |||
720 | 757 | ||
721 | static ssize_t version_show(struct class *dev, char *buf) | 758 | static ssize_t version_show(struct class *dev, char *buf) |
722 | { | 759 | { |
723 | return sprintf(buf, ASUS_OLED_UNDERSCORE_NAME " %s\n", ASUS_OLED_VERSION); | 760 | return sprintf(buf, ASUS_OLED_UNDERSCORE_NAME " %s\n", |
761 | ASUS_OLED_VERSION); | ||
724 | } | 762 | } |
725 | 763 | ||
726 | static CLASS_ATTR(version, S_IRUGO, version_show, NULL); | 764 | static CLASS_ATTR(version, S_IRUGO, version_show, NULL); |