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