Staging: add speakup to the staging directory
[linux/fpc-iii.git] / drivers / staging / speakup / kobjects.c
blob1cd456670fc362aaa4143522d66589fdcde59be0
1 /*
2 * Speakup kobject implementation
4 * Copyright (C) 2009 William Hubbs
6 * This code is based on kobject-example.c, which came with linux 2.6.x.
8 * Copyright (C) 2004-2007 Greg Kroah-Hartman <greg@kroah.com>
9 * Copyright (C) 2007 Novell Inc.
11 * Released under the GPL version 2 only.
14 #include <linux/slab.h> /* For kmalloc. */
15 #include <linux/kernel.h>
16 #include <linux/kobject.h>
17 #include <linux/string.h>
18 #include <linux/sysfs.h>
19 #include <linux/ctype.h>
21 #include "speakup.h"
22 #include "spk_priv.h"
25 * This is called when a user reads the characters or chartab sys file.
27 static ssize_t chars_chartab_show(struct kobject *kobj,
28 struct kobj_attribute *attr, char *buf)
30 int i;
31 int len = 0;
32 char *cp;
33 char *buf_pointer = buf;
34 size_t bufsize = PAGE_SIZE;
35 unsigned long flags;
37 spk_lock(flags);
38 *buf_pointer = '\0';
39 for (i = 0; i < 256; i++) {
40 if (bufsize <= 1)
41 break;
42 if (strcmp("characters", attr->attr.name) == 0) {
43 len = scnprintf(buf_pointer, bufsize, "%d\t%s\n",
44 i, characters[i]);
45 } else { /* show chartab entry */
46 if (IS_TYPE(i, B_CTL))
47 cp = "B_CTL";
48 else if (IS_TYPE(i, WDLM))
49 cp = "WDLM";
50 else if (IS_TYPE(i, A_PUNC))
51 cp = "A_PUNC";
52 else if (IS_TYPE(i, PUNC))
53 cp = "PUNC";
54 else if (IS_TYPE(i, NUM))
55 cp = "NUM";
56 else if (IS_TYPE(i, A_CAP))
57 cp = "A_CAP";
58 else if (IS_TYPE(i, ALPHA))
59 cp = "ALPHA";
60 else if (IS_TYPE(i, B_CAPSYM))
61 cp = "B_CAPSYM";
62 else if (IS_TYPE(i, B_SYM))
63 cp = "B_SYM";
64 else
65 cp = "0";
66 len =
67 scnprintf(buf_pointer, bufsize, "%d\t%s\n", i, cp);
69 bufsize -= len;
70 buf_pointer += len;
72 spk_unlock(flags);
73 return buf_pointer - buf;
77 * Print informational messages or warnings after updating
78 * character descriptions or chartab entries.
80 static void report_char_chartab_status(int reset, int received, int used,
81 int rejected, int do_characters)
83 char *object_type[] = {
84 "character class entries",
85 "character descriptions",
87 int len;
88 char buf[80];
90 if (reset) {
91 pr_info("%s reset to defaults\n", object_type[do_characters]);
92 } else if (received ) {
93 len = snprintf(buf, sizeof(buf),
94 " updated %d of %d %s\n",
95 used, received, object_type[do_characters]);
96 if (rejected)
97 snprintf(buf + (len - 1), sizeof(buf) - (len - 1),
98 " with %d reject%s\n",
99 rejected, rejected > 1 ? "s" : "");
100 printk(buf);
105 * This is called when a user changes the characters or chartab parameters.
107 static ssize_t chars_chartab_store(struct kobject *kobj,
108 struct kobj_attribute *attr, const char *buf, size_t count)
110 char *cp = (char *) buf;
111 char *end = cp + count; /* the null at the end of the buffer */
112 char *linefeed = NULL;
113 char keyword[MAX_DESC_LEN + 1];
114 char *outptr = NULL; /* Will hold keyword or desc. */
115 char *temp = NULL;
116 char *desc = NULL;
117 ssize_t retval = count;
118 unsigned long flags;
119 unsigned long index = 0;
120 int charclass = 0;
121 int received = 0;
122 int used = 0;
123 int rejected = 0;
124 int reset = 0;
125 int do_characters = !strcmp(attr->attr.name, "characters");
126 size_t desc_length = 0;
127 int i;
129 spk_lock(flags);
130 while (cp < end) {
132 while ((cp < end) && (*cp == ' ' || *cp == '\t'))
133 cp++;
135 if (cp == end)
136 break;
137 if ((*cp == '\n') || strchr("dDrR", *cp)) {
138 reset = 1;
139 break;
141 received++;
143 linefeed = strchr(cp, '\n');
144 if (!linefeed) {
145 rejected++;
146 break;
149 if (! isdigit(*cp)) {
150 rejected++;
151 cp = linefeed + 1;
152 continue;
155 index = simple_strtoul(cp, &temp, 10);
156 if (index > 255) {
157 rejected++;
158 cp = linefeed + 1;
159 continue;
162 while ((temp < linefeed) && (*temp == ' ' || *temp == '\t'))
163 temp++;
165 desc_length = linefeed - temp;
166 if (desc_length > MAX_DESC_LEN) {
167 rejected++;
168 cp = linefeed + 1;
169 continue;
171 if (do_characters) {
172 desc = kmalloc(desc_length + 1, GFP_ATOMIC);
173 if (! desc) {
174 retval = -ENOMEM;
175 reset = 1; /* just reset on error. */
176 break;
178 outptr = desc;
179 } else {
180 outptr = keyword;
183 for (i = 0; i < desc_length; i++)
184 outptr[i] = temp[i];
185 outptr[desc_length] = '\0';
187 if (do_characters) {
188 if (characters[index] != default_chars[index])
189 kfree(characters[index]);
190 characters[index] = desc;
191 used++;
192 } else {
193 charclass = chartab_get_value(keyword);
194 if (charclass == 0) {
195 rejected++;
196 cp = linefeed + 1;
197 continue;
199 if (charclass != spk_chartab[index]) {
200 spk_chartab[index] = charclass;
201 used++;
204 cp = linefeed + 1;
207 if (reset) {
208 if (do_characters)
209 reset_default_chars();
210 else
211 reset_default_chartab();
214 spk_unlock(flags);
215 report_char_chartab_status(reset, received, used, rejected, do_characters);
216 return retval;
220 * This is called when a user reads the keymap parameter.
222 static ssize_t keymap_show(struct kobject *kobj, struct kobj_attribute *attr,
223 char *buf)
225 char *cp = buf;
226 int i;
227 int n;
228 int num_keys;
229 int nstates;
230 u_char *cp1;
231 u_char ch;
232 unsigned long flags;
233 spk_lock(flags);
234 cp1 = key_buf + SHIFT_TBL_SIZE;
235 num_keys = (int)(*cp1);
236 nstates = (int)cp1[1];
237 cp += sprintf(cp, "%d, %d, %d,\n", KEY_MAP_VER, num_keys, nstates);
238 cp1 += 2; /* now pointing at shift states */
239 /* dump num_keys+1 as first row is shift states + flags,
240 each subsequent row is key + states */
241 for (n = 0; n <= num_keys; n++) {
242 for (i = 0; i <= nstates; i++) {
243 ch = *cp1++;
244 cp += sprintf(cp, "%d,", (int)ch);
245 *cp++ = (i < nstates) ? SPACE : '\n';
248 cp += sprintf(cp, "0, %d\n", KEY_MAP_VER);
249 spk_unlock(flags);
250 return (int)(cp-buf);
254 * This is called when a user changes the keymap parameter.
256 static ssize_t keymap_store(struct kobject *kobj, struct kobj_attribute *attr,
257 const char *buf, size_t count)
259 int i;
260 ssize_t ret = count;
261 char *in_buff = NULL;
262 char *cp;
263 u_char *cp1;
264 unsigned long flags;
266 spk_lock(flags);
267 in_buff = kmalloc(count + 1, GFP_ATOMIC);
268 if (! in_buff) {
269 spk_unlock(flags);
270 return -ENOMEM;
272 memcpy(in_buff, buf, count + 1);
273 if (strchr("dDrR", *in_buff)) {
274 set_key_info(key_defaults, key_buf);
275 pr_info("keymap set to default values\n");
276 kfree(in_buff);
277 spk_unlock(flags);
278 return count;
280 if (in_buff[count - 1] == '\n')
281 in_buff[count - 1] = '\0';
282 cp = in_buff;
283 cp1 = (u_char *)in_buff;
284 for (i = 0; i < 3; i++) {
285 cp = s2uchar(cp, cp1);
286 cp1++;
288 i = (int)cp1[-2]+1;
289 i *= (int)cp1[-1]+1;
290 i += 2; /* 0 and last map ver */
291 if (cp1[-3] != KEY_MAP_VER || cp1[-1] > 10 ||
292 i+SHIFT_TBL_SIZE+4 >= sizeof(key_buf)) {
293 pr_warn("i %d %d %d %d\n", i,
294 (int)cp1[-3], (int)cp1[-2], (int)cp1[-1]);
295 kfree(in_buff);
296 spk_unlock(flags);
297 return -EINVAL;
299 while (--i >= 0) {
300 cp = s2uchar(cp, cp1);
301 cp1++;
302 if (!(*cp))
303 break;
305 if (i != 0 || cp1[-1] != KEY_MAP_VER || cp1[-2] != 0) {
306 ret = -EINVAL;
307 pr_warn("end %d %d %d %d\n", i,
308 (int)cp1[-3], (int)cp1[-2], (int)cp1[-1]);
309 } else {
310 if (set_key_info(in_buff, key_buf)) {
311 set_key_info(key_defaults, key_buf);
312 ret = -EINVAL;
313 pr_warn("set key failed\n");
316 kfree(in_buff);
317 spk_unlock(flags);
318 return ret;
322 * This is called when a user changes the value of the silent parameter.
324 static ssize_t silent_store(struct kobject *kobj, struct kobj_attribute *attr,
325 const char *buf, size_t count)
327 int len;
328 struct vc_data *vc = vc_cons[fg_console].d;
329 char ch = 0;
330 char shut;
331 unsigned long flags;
333 len = strlen(buf);
334 if (len > 0 || len < 3) {
335 ch = buf[0];
336 if (ch == '\n')
337 ch = '0';
339 if (ch < '0' || ch > '7') {
340 pr_warn("silent value '%c' not in range (0,7)\n", ch);
341 return -EINVAL;
343 spk_lock(flags);
344 if (ch&2) {
345 shut = 1;
346 do_flush();
347 } else {
348 shut = 0;
350 if (ch&4)
351 shut |= 0x40;
352 if (ch&1)
353 spk_shut_up |= shut;
354 else
355 spk_shut_up &= ~shut;
356 spk_unlock(flags);
357 return count;
361 * This is called when a user reads the synth setting.
363 static ssize_t synth_show(struct kobject *kobj, struct kobj_attribute *attr,
364 char *buf)
366 int rv;
368 if (synth == NULL)
369 rv = sprintf(buf, "%s\n", "none");
370 else
371 rv = sprintf(buf, "%s\n", synth->name);
372 return rv;
376 * This is called when a user requests to change synthesizers.
378 static ssize_t synth_store(struct kobject *kobj, struct kobj_attribute *attr,
379 const char *buf, size_t count)
381 int len;
382 char new_synth_name[10];
384 len = strlen(buf);
385 if (len < 2 || len > 9)
386 return -EINVAL;
387 strncpy(new_synth_name, buf, len);
388 if (new_synth_name[len - 1] == '\n')
389 len--;
390 new_synth_name[len] = '\0';
391 strlwr(new_synth_name);
392 if ((synth != NULL) && (!strcmp(new_synth_name, synth->name))) {
393 pr_warn("%s already in use\n", new_synth_name);
394 } else if (synth_init(new_synth_name) != 0) {
395 pr_warn("failed to init synth %s\n", new_synth_name);
396 return -ENODEV;
398 return count;
402 * This is called when text is sent to the synth via the synth_direct file.
404 static ssize_t synth_direct_store(struct kobject *kobj, struct kobj_attribute *attr,
405 const char *buf, size_t count)
407 u_char tmp[256];
408 int len;
409 int bytes;
410 const char *ptr = buf;
412 if (! synth)
413 return -EPERM;
415 len = strlen(buf);
416 while (len > 0) {
417 bytes = min_t(size_t, len, 250);
418 strncpy(tmp, ptr, bytes);
419 tmp[bytes] = '\0';
420 xlate(tmp);
421 synth_printf("%s", tmp);
422 ptr += bytes;
423 len -= bytes;
425 return count;
429 * This function is called when a user reads the version.
431 static ssize_t version_show(struct kobject *kobj, struct kobj_attribute *attr,
432 char *buf)
434 char *cp;
436 cp = buf;
437 cp += sprintf(cp, "Speakup version %s\n", SPEAKUP_VERSION);
438 if (synth)
439 cp += sprintf(cp, "%s synthesizer driver version %s\n",
440 synth->name, synth->version);
441 return cp - buf;
445 * This is called when a user reads the punctuation settings.
447 static ssize_t punc_show(struct kobject *kobj, struct kobj_attribute *attr,
448 char *buf)
450 int i;
451 char *cp = buf;
452 struct st_var_header *p_header;
453 struct punc_var_t *var;
454 struct st_bits_data *pb;
455 short mask;
456 unsigned long flags;
458 p_header = var_header_by_name(attr->attr.name);
459 if (p_header == NULL) {
460 pr_warn("p_header is null, attr->attr.name is %s\n", attr->attr.name);
461 return -EINVAL;
464 var = get_punc_var(p_header->var_id);
465 if (var == NULL) {
466 pr_warn("var is null, p_header->var_id is %i\n",
467 p_header->var_id);
468 return -EINVAL;
471 spk_lock(flags);
472 pb = (struct st_bits_data *) &punc_info[var->value];
473 mask = pb->mask;
474 for (i = 33; i < 128; i++) {
475 if (!(spk_chartab[i]&mask))
476 continue;
477 *cp++ = (char)i;
479 spk_unlock(flags);
480 return cp-buf;
484 * This is called when a user changes the punctuation settings.
486 static ssize_t punc_store(struct kobject *kobj, struct kobj_attribute *attr,
487 const char *buf, size_t count)
489 int x;
490 struct st_var_header *p_header;
491 struct punc_var_t *var;
492 char punc_buf[100];
493 unsigned long flags;
495 x = strlen(buf);
496 if (x < 1 || x > 99)
497 return -EINVAL;
499 p_header = var_header_by_name(attr->attr.name);
500 if (p_header == NULL) {
501 pr_warn("p_header is null, attr->attr.name is %s\n", attr->attr.name);
502 return -EINVAL;
505 var = get_punc_var(p_header->var_id);
506 if (var == NULL) {
507 pr_warn("var is null, p_header->var_id is %i\n",
508 p_header->var_id);
509 return -EINVAL;
512 strncpy(punc_buf, buf, x);
514 while (x && punc_buf[x - 1] == '\n')
515 x--;
516 punc_buf[x] = '\0';
518 spk_lock(flags);
520 if (*punc_buf == 'd' || *punc_buf == 'r')
521 x = set_mask_bits(0, var->value, 3);
522 else
523 x = set_mask_bits(punc_buf, var->value, 3);
525 spk_unlock(flags);
526 return count;
530 * This function is called when a user reads one of the variable parameters.
532 ssize_t spk_var_show(struct kobject *kobj, struct kobj_attribute *attr,
533 char *buf)
535 int rv = 0;
536 struct st_var_header *param;
537 struct var_t *var;
538 char *cp1;
539 char *cp;
540 char ch;
541 unsigned long flags;
543 param = var_header_by_name(attr->attr.name);
544 if (param == NULL)
545 return -EINVAL;
547 spk_lock(flags);
548 var = (struct var_t *) param->data;
549 switch (param->var_type) {
550 case VAR_NUM:
551 case VAR_TIME:
552 if (var)
553 rv = sprintf(buf, "%i\n", var->u.n.value);
554 else
555 rv = sprintf(buf, "0\n");
556 break;
557 case VAR_STRING:
558 if (var) {
559 cp1 = buf;
560 *cp1++ = '"';
561 for (cp = (char *)param->p_val; (ch = *cp); cp++) {
562 if (ch >= ' ' && ch < '~')
563 *cp1++ = ch;
564 else
565 cp1 += sprintf(cp1, "\\""x%02x", ch);
567 *cp1++ = '"';
568 *cp1++ = '\n';
569 *cp1 = '\0';
570 rv = cp1-buf;
571 } else {
572 rv = sprintf(buf, "\"\"\n");
574 break;
575 default:
576 rv = sprintf(buf, "Bad parameter %s, type %i\n",
577 param->name, param->var_type);
578 break;
580 spk_unlock(flags);
581 return rv;
583 EXPORT_SYMBOL_GPL(spk_var_show);
586 * This function is called when a user echos a value to one of the
587 * variable parameters.
589 ssize_t spk_var_store(struct kobject *kobj, struct kobj_attribute *attr,
590 const char *buf, size_t count)
592 struct st_var_header *param;
593 int ret;
594 int len;
595 char *cp;
596 struct var_t *var_data;
597 int value;
598 unsigned long flags;
600 param = var_header_by_name(attr->attr.name);
601 if (param == NULL)
602 return -EINVAL;
603 if (param->data == NULL)
604 return 0;
605 ret = 0;
606 cp = xlate((char *) buf);
608 spk_lock(flags);
609 switch (param->var_type) {
610 case VAR_NUM:
611 case VAR_TIME:
612 if (*cp == 'd' || *cp == 'r' || *cp == '\0')
613 len = E_DEFAULT;
614 else if (*cp == '+' || *cp == '-')
615 len = E_INC;
616 else
617 len = E_SET;
618 speakup_s2i(cp, &value);
619 ret = set_num_var(value, param, len);
620 if (ret == E_RANGE) {
621 var_data = param->data;
622 pr_warn("value for %s out of range, expect %d to %d\n",
623 attr->attr.name,
624 var_data->u.n.low, var_data->u.n.high);
626 break;
627 case VAR_STRING:
628 len = strlen(buf);
629 if ((len >= 1) && (buf[len - 1] == '\n'))
630 --len;
631 if ((len >= 2) && (buf[0] == '"') && (buf[len - 1] == '"')) {
632 ++buf;
633 len -= 2;
635 cp = (char *) buf;
636 cp[len] = '\0';
637 ret = set_string_var(buf, param, len);
638 if (ret == E_TOOLONG)
639 pr_warn("value too long for %s\n",
640 attr->attr.name);
641 break;
642 default:
643 pr_warn("%s unknown type %d\n",
644 param->name, (int)param->var_type);
645 break;
648 * If voice was just changed, we might need to reset our default
649 * pitch and volume.
651 if (strcmp(attr->attr.name, "voice") == 0) {
652 if (synth && synth->default_pitch) {
653 param = var_header_by_name("pitch");
654 if (param) {
655 set_num_var(synth->default_pitch[value], param, E_NEW_DEFAULT);
656 set_num_var(0, param, E_DEFAULT);
659 if (synth && synth->default_vol) {
660 param = var_header_by_name("vol");
661 if (param) {
662 set_num_var(synth->default_vol[value], param, E_NEW_DEFAULT);
663 set_num_var(0, param, E_DEFAULT);
667 spk_unlock(flags);
669 if (ret == SET_DEFAULT)
670 pr_info("%s reset to default value\n", attr->attr.name);
671 return count;
673 EXPORT_SYMBOL_GPL(spk_var_store);
676 * Functions for reading and writing lists of i18n messages. Incomplete.
679 static ssize_t message_show_helper(char *buf, enum msg_index_t first,
680 enum msg_index_t last)
682 size_t bufsize = PAGE_SIZE;
683 char *buf_pointer = buf;
684 int printed;
685 enum msg_index_t cursor;
686 int index = 0;
687 *buf_pointer = '\0'; /* buf_pointer always looking at a NUL byte. */
689 for (cursor = first; cursor <= last; cursor++, index++) {
690 if (bufsize <= 1)
691 break;
692 printed = scnprintf(buf_pointer, bufsize, "%d\t%s\n",
693 index, msg_get(cursor));
694 buf_pointer += printed;
695 bufsize -= printed;
698 return buf_pointer - buf;
701 static void report_msg_status(int reset, int received, int used,
702 int rejected, char *groupname)
704 int len;
705 char buf[160];
707 if (reset) {
708 pr_info("i18n messages from group %s reset to defaults\n",
709 groupname);
710 } else if (received ) {
711 len = snprintf(buf, sizeof(buf),
712 " updated %d of %d i18n messages from group %s\n",
713 used, received, groupname);
714 if (rejected)
715 snprintf(buf + (len - 1), sizeof(buf) - (len - 1),
716 " with %d reject%s\n",
717 rejected, rejected > 1 ? "s" : "");
718 printk(buf);
722 static ssize_t message_store_helper(const char *buf, size_t count,
723 struct msg_group_t *group)
725 char *cp = (char *) buf;
726 char *end = cp + count;
727 char *linefeed = NULL;
728 char *temp = NULL;
729 ssize_t msg_stored = 0;
730 ssize_t retval = count;
731 size_t desc_length = 0;
732 unsigned long index = 0;
733 int received = 0;
734 int used = 0;
735 int rejected = 0;
736 int reset = 0;
737 enum msg_index_t firstmessage = group->start;
738 enum msg_index_t lastmessage = group->end;
739 enum msg_index_t curmessage;
741 while (cp < end) {
743 while ((cp < end) && (*cp == ' ' || *cp == '\t'))
744 cp++;
746 if (cp == end)
747 break;
748 if (strchr("dDrR", *cp)) {
749 reset = 1;
750 break;
752 received++;
754 linefeed = strchr(cp, '\n');
755 if (!linefeed) {
756 rejected++;
757 break;
760 if (! isdigit(*cp)) {
761 rejected++;
762 cp = linefeed + 1;
763 continue;
766 index = simple_strtoul(cp, &temp, 10);
768 while ((temp < linefeed) && (*temp == ' ' || *temp == '\t'))
769 temp++;
771 desc_length = linefeed - temp;
772 curmessage = firstmessage + index;
775 * Note the check (curmessage < firstmessage). It is not
776 * redundant. Suppose that the user gave us an index
777 * equal to ULONG_MAX - 1. If firstmessage > 1, then
778 * firstmessage + index < firstmessage!
781 if ((curmessage < firstmessage) || (curmessage > lastmessage)) {
782 rejected++;
783 cp = linefeed + 1;
784 continue;
787 msg_stored = msg_set(curmessage, temp, desc_length);
788 if (msg_stored < 0) {
789 retval = msg_stored;
790 if (msg_stored == -ENOMEM)
791 reset = 1;
792 break;
793 } else {
794 used++;
797 cp = linefeed + 1;
800 if (reset)
801 reset_msg_group(group);
803 report_msg_status(reset, received, used, rejected, group->name);
804 return retval;
807 static ssize_t message_show(struct kobject *kobj,
808 struct kobj_attribute *attr, char *buf)
810 ssize_t retval = 0;
811 struct msg_group_t *group = find_msg_group(attr->attr.name);
812 unsigned long flags;
814 BUG_ON(! group);
815 spk_lock(flags);
816 retval = message_show_helper(buf, group->start, group->end);
817 spk_unlock(flags);
818 return retval;
821 static ssize_t message_store(struct kobject *kobj, struct kobj_attribute *attr,
822 const char *buf, size_t count)
824 ssize_t retval = 0;
825 struct msg_group_t *group = find_msg_group(attr->attr.name);
827 BUG_ON(! group);
828 retval = message_store_helper(buf, count, group);
829 return retval;
833 * Declare the attributes.
835 static struct kobj_attribute keymap_attribute =
836 __ATTR(keymap, ROOT_W, keymap_show, keymap_store);
837 static struct kobj_attribute silent_attribute =
838 __ATTR(silent, USER_W, NULL, silent_store);
839 static struct kobj_attribute synth_attribute =
840 __ATTR(synth, USER_RW, synth_show, synth_store);
841 static struct kobj_attribute synth_direct_attribute =
842 __ATTR(synth_direct, USER_W, NULL, synth_direct_store);
843 static struct kobj_attribute version_attribute =
844 __ATTR_RO(version);
846 static struct kobj_attribute delimiters_attribute =
847 __ATTR(delimiters, USER_RW, punc_show, punc_store);
848 static struct kobj_attribute ex_num_attribute =
849 __ATTR(ex_num, USER_RW, punc_show, punc_store);
850 static struct kobj_attribute punc_all_attribute =
851 __ATTR(punc_all, USER_RW, punc_show, punc_store);
852 static struct kobj_attribute punc_most_attribute =
853 __ATTR(punc_most, USER_RW, punc_show, punc_store);
854 static struct kobj_attribute punc_some_attribute =
855 __ATTR(punc_some, USER_RW, punc_show, punc_store);
856 static struct kobj_attribute repeats_attribute =
857 __ATTR(repeats, USER_RW, punc_show, punc_store);
859 static struct kobj_attribute attrib_bleep_attribute =
860 __ATTR(attrib_bleep, USER_RW, spk_var_show, spk_var_store);
861 static struct kobj_attribute bell_pos_attribute =
862 __ATTR(bell_pos, USER_RW, spk_var_show, spk_var_store);
863 static struct kobj_attribute bleep_time_attribute =
864 __ATTR(bleep_time, USER_RW, spk_var_show, spk_var_store);
865 static struct kobj_attribute bleeps_attribute =
866 __ATTR(bleeps, USER_RW, spk_var_show, spk_var_store);
867 static struct kobj_attribute cursor_time_attribute =
868 __ATTR(cursor_time, USER_RW, spk_var_show, spk_var_store);
869 static struct kobj_attribute key_echo_attribute =
870 __ATTR(key_echo, USER_RW, spk_var_show, spk_var_store);
871 static struct kobj_attribute no_interrupt_attribute =
872 __ATTR(no_interrupt, USER_RW, spk_var_show, spk_var_store);
873 static struct kobj_attribute punc_level_attribute =
874 __ATTR(punc_level, USER_RW, spk_var_show, spk_var_store);
875 static struct kobj_attribute reading_punc_attribute =
876 __ATTR(reading_punc, USER_RW, spk_var_show, spk_var_store);
877 static struct kobj_attribute say_control_attribute =
878 __ATTR(say_control, USER_RW, spk_var_show, spk_var_store);
879 static struct kobj_attribute say_word_ctl_attribute =
880 __ATTR(say_word_ctl, USER_RW, spk_var_show, spk_var_store);
881 static struct kobj_attribute spell_delay_attribute =
882 __ATTR(spell_delay, USER_RW, spk_var_show, spk_var_store);
885 * These attributes are i18n related.
887 static struct kobj_attribute announcements_attribute =
888 __ATTR(announcements, USER_RW, message_show, message_store);
889 static struct kobj_attribute characters_attribute =
890 __ATTR(characters, USER_RW, chars_chartab_show, chars_chartab_store);
891 static struct kobj_attribute chartab_attribute =
892 __ATTR(chartab, USER_RW, chars_chartab_show, chars_chartab_store);
893 static struct kobj_attribute ctl_keys_attribute =
894 __ATTR(ctl_keys, USER_RW, message_show, message_store);
895 static struct kobj_attribute colors_attribute =
896 __ATTR(colors, USER_RW, message_show, message_store);
897 static struct kobj_attribute formatted_attribute =
898 __ATTR(formatted, USER_RW, message_show, message_store);
899 static struct kobj_attribute function_names_attribute =
900 __ATTR(function_names, USER_RW, message_show, message_store);
901 static struct kobj_attribute key_names_attribute =
902 __ATTR(key_names, USER_RW, message_show, message_store);
903 static struct kobj_attribute states_attribute =
904 __ATTR(states, USER_RW, message_show, message_store);
907 * Create groups of attributes so that we can create and destroy them all
908 * at once.
910 static struct attribute *main_attrs[] = {
911 &keymap_attribute.attr,
912 &silent_attribute.attr,
913 &synth_attribute.attr,
914 &synth_direct_attribute.attr,
915 &version_attribute.attr,
916 &delimiters_attribute.attr,
917 &ex_num_attribute.attr,
918 &punc_all_attribute.attr,
919 &punc_most_attribute.attr,
920 &punc_some_attribute.attr,
921 &repeats_attribute.attr,
922 &attrib_bleep_attribute.attr,
923 &bell_pos_attribute.attr,
924 &bleep_time_attribute.attr,
925 &bleeps_attribute.attr,
926 &cursor_time_attribute.attr,
927 &key_echo_attribute.attr,
928 &no_interrupt_attribute.attr,
929 &punc_level_attribute.attr,
930 &reading_punc_attribute.attr,
931 &say_control_attribute.attr,
932 &say_word_ctl_attribute.attr,
933 &spell_delay_attribute.attr,
934 NULL,
937 static struct attribute *i18n_attrs[] = {
938 &announcements_attribute.attr,
939 &characters_attribute.attr,
940 &chartab_attribute.attr,
941 &ctl_keys_attribute.attr,
942 &colors_attribute.attr,
943 &formatted_attribute.attr,
944 &function_names_attribute.attr,
945 &key_names_attribute.attr,
946 &states_attribute.attr,
947 NULL,
951 * An unnamed attribute group will put all of the attributes directly in
952 * the kobject directory. If we specify a name, a subdirectory will be
953 * created for the attributes with the directory being the name of the
954 * attribute group.
956 static struct attribute_group main_attr_group = {
957 .attrs = main_attrs,
960 static struct attribute_group i18n_attr_group = {
961 .attrs = i18n_attrs,
962 .name = "i18n",
965 static struct kobject *accessibility_kobj;
966 struct kobject *speakup_kobj;
968 int speakup_kobj_init(void)
970 int retval;
973 * Create a simple kobject with the name of "accessibility",
974 * located under /sys/
976 * As this is a simple directory, no uevent will be sent to
977 * userspace. That is why this function should not be used for
978 * any type of dynamic kobjects, where the name and number are
979 * not known ahead of time.
981 accessibility_kobj = kobject_create_and_add("accessibility", NULL);
982 if (!accessibility_kobj)
983 return -ENOMEM;
985 speakup_kobj = kobject_create_and_add("speakup", accessibility_kobj);
986 if (!speakup_kobj) {
987 kobject_put(accessibility_kobj);
988 return -ENOMEM;
991 /* Create the files associated with this kobject */
992 retval = sysfs_create_group(speakup_kobj, &main_attr_group);
993 if (retval)
994 speakup_kobj_exit();
996 retval = sysfs_create_group(speakup_kobj, &i18n_attr_group);
997 if (retval)
998 speakup_kobj_exit();
1000 return retval;
1003 void speakup_kobj_exit(void)
1005 kobject_put(speakup_kobj);
1006 kobject_put(accessibility_kobj);