1 // Copyright 2018 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/debug.h>
6 #include <ddk/device.h>
7 #include <ddk/platform-defs.h>
8 #include <ddk/protocol/platform/bus.h>
9 
10 #include <soc/aml-s905d2/s905d2-gpio.h>
11 
12 #include "astro.h"
13 
14 static const pbus_i2c_channel_t tcs3400_light_i2c[] = {
15     {
16         .bus_id = ASTRO_I2C_A0_0,
17         .address = I2C_AMBIENTLIGHT_ADDR,
18     },
19 };
20 
21 static const pbus_gpio_t tcs3400_light_gpios[] = {
22     {
23         // interrupt
24         .gpio = S905D2_GPIOAO(5),
25     },
26 };
27 
28 static pbus_dev_t tcs3400_light_dev = {
29     .name = "tcs3400-light",
30     .vid = PDEV_VID_AMS,
31     .pid = PDEV_PID_AMS_TCS3400,
32     .did = PDEV_DID_AMS_LIGHT,
33     .i2c_channel_list = tcs3400_light_i2c,
34     .i2c_channel_count = countof(tcs3400_light_i2c),
35     .gpio_list = tcs3400_light_gpios,
36     .gpio_count = countof(tcs3400_light_gpios),
37 };
38 
ams_light_init(aml_bus_t * bus)39 zx_status_t ams_light_init(aml_bus_t* bus) {
40 
41     zx_status_t status = pbus_device_add(&bus->pbus, &tcs3400_light_dev);
42     if (status != ZX_OK) {
43         zxlogf(ERROR, "ams_light_init(tcs-3400): pbus_device_add failed: %d\n", status);
44         return status;
45     }
46 
47     return ZX_OK;
48 }
49