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 #include <soc/aml-s905d2/s905d2-hw.h>
12 #include <limits.h>
13 
14 #include "astro.h"
15 
16 static const pbus_gpio_t touch_gpios[] = {
17     {
18         // touch interrupt
19         .gpio = S905D2_GPIOZ(4),
20     },
21     {
22         // touch reset
23         .gpio = S905D2_GPIOZ(9),
24     },
25 };
26 
27 static const pbus_i2c_channel_t ft3x27_touch_i2c[] = {
28     {
29         .bus_id = ASTRO_I2C_2,
30         .address = 0x38,
31     },
32 };
33 
34 static pbus_dev_t ft3x27_touch_dev = {
35     .name = "ft3x27-touch",
36     .vid = PDEV_VID_GENERIC,
37     .did = PDEV_DID_FOCALTOUCH,
38     .i2c_channel_list = ft3x27_touch_i2c,
39     .i2c_channel_count = countof(ft3x27_touch_i2c),
40     .gpio_list = touch_gpios,
41     .gpio_count = countof(touch_gpios),
42 };
43 
44 static const pbus_i2c_channel_t gt92xx_touch_i2c[] = {
45     {
46         .bus_id = ASTRO_I2C_2,
47         .address = 0x5d,
48     },
49 };
50 
51 static pbus_dev_t gt92xx_touch_dev = {
52     .name = "gt92xx-touch",
53     .vid = PDEV_VID_GOOGLE,
54     .pid = PDEV_PID_ASTRO,
55     .did = PDEV_DID_ASTRO_GOODIXTOUCH,
56     .i2c_channel_list = gt92xx_touch_i2c,
57     .i2c_channel_count = countof(gt92xx_touch_i2c),
58     .gpio_list = touch_gpios,
59     .gpio_count = countof(touch_gpios),
60 };
61 
62 
astro_touch_init(aml_bus_t * bus)63 zx_status_t astro_touch_init(aml_bus_t* bus) {
64 
65     //Check the display ID pin to determine which driver device to add
66     gpio_impl_set_alt_function(&bus->gpio, S905D2_GPIOH(5), 0);
67     gpio_impl_config_in(&bus->gpio, S905D2_GPIOH(5), GPIO_NO_PULL);
68     uint8_t gpio_state;
69     /* Two variants of display are supported, one with BOE display panel and
70           ft3x27 touch controller, the other with INX panel and Goodix touch
71           controller.  This GPIO input is used to identify each.
72           Logic 0 for BOE/ft3x27 combination
73           Logic 1 for Innolux/Goodix combination
74     */
75     gpio_impl_read(&bus->gpio, S905D2_GPIOH(5), &gpio_state);
76     if (gpio_state) {
77         zx_status_t status = pbus_device_add(&bus->pbus, &gt92xx_touch_dev);
78         if (status != ZX_OK) {
79             zxlogf(INFO, "astro_touch_init(gt92xx): pbus_device_add failed: %d\n", status);
80             return status;
81         }
82     } else {
83         zx_status_t status = pbus_device_add(&bus->pbus, &ft3x27_touch_dev);
84         if (status != ZX_OK) {
85             zxlogf(ERROR, "astro_touch_init(ft3x27): pbus_device_add failed: %d\n", status);
86             return status;
87         }
88     }
89 
90     return ZX_OK;
91 }
92