ARM: imx: add missing item to the list of clock event modes
[linux-2.6/btrfs-unstable.git] / drivers / acpi / bgrt.c
blob6680df36b9634f414cc7438ca57590bef0c8cc71
1 /*
2 * Copyright 2012 Red Hat, Inc <mjg@redhat.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
9 #include <linux/kernel.h>
10 #include <linux/module.h>
11 #include <linux/init.h>
12 #include <linux/device.h>
13 #include <linux/sysfs.h>
14 #include <linux/io.h>
15 #include <acpi/acpi.h>
16 #include <acpi/acpi_bus.h>
18 static struct acpi_table_bgrt *bgrt_tab;
19 static struct kobject *bgrt_kobj;
21 struct bmp_header {
22 u16 id;
23 u32 size;
24 } __attribute ((packed));
26 static struct bmp_header bmp_header;
28 static ssize_t show_version(struct device *dev,
29 struct device_attribute *attr, char *buf)
31 return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab->version);
33 static DEVICE_ATTR(version, S_IRUGO, show_version, NULL);
35 static ssize_t show_status(struct device *dev,
36 struct device_attribute *attr, char *buf)
38 return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab->status);
40 static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
42 static ssize_t show_type(struct device *dev,
43 struct device_attribute *attr, char *buf)
45 return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab->image_type);
47 static DEVICE_ATTR(type, S_IRUGO, show_type, NULL);
49 static ssize_t show_xoffset(struct device *dev,
50 struct device_attribute *attr, char *buf)
52 return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab->image_offset_x);
54 static DEVICE_ATTR(xoffset, S_IRUGO, show_xoffset, NULL);
56 static ssize_t show_yoffset(struct device *dev,
57 struct device_attribute *attr, char *buf)
59 return snprintf(buf, PAGE_SIZE, "%d\n", bgrt_tab->image_offset_y);
61 static DEVICE_ATTR(yoffset, S_IRUGO, show_yoffset, NULL);
63 static ssize_t show_image(struct file *file, struct kobject *kobj,
64 struct bin_attribute *attr, char *buf, loff_t off, size_t count)
66 int size = attr->size;
67 void __iomem *image = attr->private;
69 if (off >= size) {
70 count = 0;
71 } else {
72 if (off + count > size)
73 count = size - off;
75 memcpy_fromio(buf, image+off, count);
78 return count;
81 static struct bin_attribute image_attr = {
82 .attr = {
83 .name = "image",
84 .mode = S_IRUGO,
86 .read = show_image,
89 static struct attribute *bgrt_attributes[] = {
90 &dev_attr_version.attr,
91 &dev_attr_status.attr,
92 &dev_attr_type.attr,
93 &dev_attr_xoffset.attr,
94 &dev_attr_yoffset.attr,
95 NULL,
98 static struct attribute_group bgrt_attribute_group = {
99 .attrs = bgrt_attributes,
102 static int __init bgrt_init(void)
104 acpi_status status;
105 int ret;
106 void __iomem *bgrt;
108 if (acpi_disabled)
109 return -ENODEV;
111 status = acpi_get_table("BGRT", 0,
112 (struct acpi_table_header **)&bgrt_tab);
114 if (ACPI_FAILURE(status))
115 return -ENODEV;
117 sysfs_bin_attr_init(&image_attr);
119 bgrt = ioremap(bgrt_tab->image_address, sizeof(struct bmp_header));
121 if (!bgrt) {
122 ret = -EINVAL;
123 goto out_err;
126 memcpy_fromio(&bmp_header, bgrt, sizeof(bmp_header));
127 image_attr.size = bmp_header.size;
128 iounmap(bgrt);
130 image_attr.private = ioremap(bgrt_tab->image_address, image_attr.size);
132 if (!image_attr.private) {
133 ret = -EINVAL;
134 goto out_err;
138 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
139 if (!bgrt_kobj) {
140 ret = -EINVAL;
141 goto out_iounmap;
144 ret = sysfs_create_group(bgrt_kobj, &bgrt_attribute_group);
145 if (ret)
146 goto out_kobject;
148 ret = sysfs_create_bin_file(bgrt_kobj, &image_attr);
149 if (ret)
150 goto out_group;
152 return 0;
154 out_group:
155 sysfs_remove_group(bgrt_kobj, &bgrt_attribute_group);
156 out_kobject:
157 kobject_put(bgrt_kobj);
158 out_iounmap:
159 iounmap(image_attr.private);
160 out_err:
161 return ret;
164 static void __exit bgrt_exit(void)
166 iounmap(image_attr.private);
167 sysfs_remove_group(bgrt_kobj, &bgrt_attribute_group);
168 sysfs_remove_bin_file(bgrt_kobj, &image_attr);
171 module_init(bgrt_init);
172 module_exit(bgrt_exit);
174 MODULE_AUTHOR("Matthew Garrett");
175 MODULE_DESCRIPTION("BGRT boot graphic support");
176 MODULE_LICENSE("GPL");