1 // Copyright 2017 The Fuchsia Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <ddk/binding.h>
6 #include <ddk/device.h>
7 #include <ddk/driver.h>
8
9 #include <zircon/types.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13
zero_read(void * ctx,void * buf,size_t count,zx_off_t off,size_t * actual)14 static zx_status_t zero_read(void* ctx, void* buf, size_t count, zx_off_t off, size_t* actual) {
15 memset(buf, 0, count);
16 *actual = count;
17 return ZX_OK;
18 }
19
zero_write(void * ctx,const void * buf,size_t count,zx_off_t off,size_t * actual)20 static zx_status_t zero_write(void* ctx, const void* buf, size_t count, zx_off_t off,
21 size_t* actual) {
22 return ZX_ERR_NOT_SUPPORTED;
23 }
24
25 static zx_protocol_device_t zero_device_proto = {
26 .version = DEVICE_OPS_VERSION,
27 .read = zero_read,
28 .write = zero_write,
29 };
30
zero_bind(void * ctx,zx_device_t * parent,void ** cookie)31 zx_status_t zero_bind(void* ctx, zx_device_t* parent, void** cookie) {
32 device_add_args_t args = {
33 .version = DEVICE_ADD_ARGS_VERSION,
34 .name = "zero",
35 .ops = &zero_device_proto,
36 };
37
38 zx_device_t* dev;
39 return device_add(parent, &args, &dev);
40 }
41