drm: disable encoders before re-routing them
[linux-2.6-block.git] / samples / firmware_class / firmware_sample_driver.c
CommitLineData
1da177e4
LT
1/*
2 * firmware_sample_driver.c -
3 *
87d37a4f 4 * Copyright (c) 2003 Manuel Estrada Sainz
1da177e4
LT
5 *
6 * Sample code on how to use request_firmware() from drivers.
7 *
1da177e4
LT
8 */
9
10#include <linux/module.h>
11#include <linux/kernel.h>
12#include <linux/init.h>
13#include <linux/device.h>
4e57b681 14#include <linux/string.h>
4b65fc8c 15#include <linux/firmware.h>
1da177e4 16
1da177e4 17static struct device ghost_device = {
1da177e4
LT
18 .bus_id = "ghost0",
19};
20
21
22static void sample_firmware_load(char *firmware, int size)
23{
24 u8 buf[size+1];
25 memcpy(buf, firmware, size);
26 buf[size] = '\0';
20dd026d 27 printk(KERN_INFO "firmware_sample_driver: firmware: %s\n", buf);
1da177e4
LT
28}
29
30static void sample_probe_default(void)
31{
32 /* uses the default method to get the firmware */
4b65fc8c
GKH
33 const struct firmware *fw_entry;
34 int retval;
35
36 printk(KERN_INFO "firmware_sample_driver: "
37 "a ghost device got inserted :)\n");
1da177e4 38
4b65fc8c
GKH
39 retval = request_firmware(&fw_entry, "sample_driver_fw", &ghost_device);
40 if (retval) {
1da177e4
LT
41 printk(KERN_ERR
42 "firmware_sample_driver: Firmware not available\n");
43 return;
44 }
d289bf7b 45
1da177e4
LT
46 sample_firmware_load(fw_entry->data, fw_entry->size);
47
48 release_firmware(fw_entry);
49
50 /* finish setting up the device */
51}
4b65fc8c 52
1da177e4
LT
53static void sample_probe_specific(void)
54{
4b65fc8c 55 int retval;
1da177e4
LT
56 /* Uses some specific hotplug support to get the firmware from
57 * userspace directly into the hardware, or via some sysfs file */
58
59 /* NOTE: This currently doesn't work */
60
4b65fc8c
GKH
61 printk(KERN_INFO "firmware_sample_driver: "
62 "a ghost device got inserted :)\n");
1da177e4 63
4b65fc8c
GKH
64 retval = request_firmware(NULL, "sample_driver_fw", &ghost_device);
65 if (retval) {
1da177e4
LT
66 printk(KERN_ERR
67 "firmware_sample_driver: Firmware load failed\n");
68 return;
69 }
d289bf7b 70
1da177e4
LT
71 /* request_firmware blocks until userspace finished, so at
72 * this point the firmware should be already in the device */
73
74 /* finish setting up the device */
75}
e9b62693 76
1da177e4
LT
77static void sample_probe_async_cont(const struct firmware *fw, void *context)
78{
4b65fc8c 79 if (!fw) {
1da177e4
LT
80 printk(KERN_ERR
81 "firmware_sample_driver: firmware load failed\n");
82 return;
83 }
84
20dd026d 85 printk(KERN_INFO "firmware_sample_driver: device pointer \"%s\"\n",
1da177e4
LT
86 (char *)context);
87 sample_firmware_load(fw->data, fw->size);
88}
4b65fc8c 89
1da177e4
LT
90static void sample_probe_async(void)
91{
92 /* Let's say that I can't sleep */
93 int error;
4b65fc8c
GKH
94 error = request_firmware_nowait(THIS_MODULE, FW_ACTION_NOHOTPLUG,
95 "sample_driver_fw", &ghost_device,
96 "my device pointer",
97 sample_probe_async_cont);
98 if (error)
99 printk(KERN_ERR "firmware_sample_driver:"
1da177e4 100 " request_firmware_nowait failed\n");
1da177e4
LT
101}
102
7ec7fb39 103static int __init sample_init(void)
1da177e4 104{
1da177e4
LT
105 device_initialize(&ghost_device);
106 /* since there is no real hardware insertion I just call the
107 * sample probe functions here */
108 sample_probe_specific();
109 sample_probe_default();
110 sample_probe_async();
111 return 0;
112}
4b65fc8c 113
1da177e4
LT
114static void __exit sample_exit(void)
115{
116}
117
4b65fc8c
GKH
118module_init(sample_init);
119module_exit(sample_exit);
1da177e4
LT
120
121MODULE_LICENSE("GPL");