|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
| 2 | +/* |
| 3 | + * Ilitek ILI9806E core driver. |
| 4 | + * |
| 5 | + * Copyright (c) 2026 Amarula Solutions, Dario Binacchi <dario.binacchi@amarulasolutions.com> |
| 6 | + */ |
| 7 | + |
| 8 | +#include <drm/drm_panel.h> |
| 9 | + |
| 10 | +#include <linux/delay.h> |
| 11 | +#include <linux/export.h> |
| 12 | +#include <linux/gpio/consumer.h> |
| 13 | +#include <linux/module.h> |
| 14 | +#include <linux/property.h> |
| 15 | +#include <linux/regulator/consumer.h> |
| 16 | + |
| 17 | +#include "panel-ilitek-ili9806e-core.h" |
| 18 | + |
| 19 | +struct ili9806e { |
| 20 | + void *transport; |
| 21 | + struct drm_panel panel; |
| 22 | + |
| 23 | + struct regulator_bulk_data supplies[2]; |
| 24 | + struct gpio_desc *reset_gpio; |
| 25 | +}; |
| 26 | + |
| 27 | +static const char * const regulator_names[] = { |
| 28 | + "vdd", |
| 29 | + "vccio", |
| 30 | +}; |
| 31 | + |
| 32 | +void *ili9806e_get_transport(struct drm_panel *panel) |
| 33 | +{ |
| 34 | + struct ili9806e *ctx = container_of(panel, struct ili9806e, panel); |
| 35 | + |
| 36 | + return ctx->transport; |
| 37 | +} |
| 38 | +EXPORT_SYMBOL_GPL(ili9806e_get_transport); |
| 39 | + |
| 40 | +int ili9806e_power_on(struct device *dev) |
| 41 | +{ |
| 42 | + struct ili9806e *ctx = dev_get_drvdata(dev); |
| 43 | + int ret; |
| 44 | + |
| 45 | + gpiod_set_value(ctx->reset_gpio, 1); |
| 46 | + |
| 47 | + ret = regulator_bulk_enable(ARRAY_SIZE(ctx->supplies), ctx->supplies); |
| 48 | + if (ret) { |
| 49 | + dev_err(dev, "regulator bulk enable failed: %d\n", ret); |
| 50 | + return ret; |
| 51 | + } |
| 52 | + |
| 53 | + usleep_range(10000, 20000); |
| 54 | + gpiod_set_value(ctx->reset_gpio, 0); |
| 55 | + usleep_range(10000, 20000); |
| 56 | + |
| 57 | + return 0; |
| 58 | +} |
| 59 | +EXPORT_SYMBOL_GPL(ili9806e_power_on); |
| 60 | + |
| 61 | +int ili9806e_power_off(struct device *dev) |
| 62 | +{ |
| 63 | + struct ili9806e *ctx = dev_get_drvdata(dev); |
| 64 | + int ret; |
| 65 | + |
| 66 | + gpiod_set_value(ctx->reset_gpio, 1); |
| 67 | + |
| 68 | + ret = regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies); |
| 69 | + if (ret) |
| 70 | + dev_err(dev, "regulator bulk disable failed: %d\n", ret); |
| 71 | + |
| 72 | + return ret; |
| 73 | +} |
| 74 | +EXPORT_SYMBOL_GPL(ili9806e_power_off); |
| 75 | + |
| 76 | +int ili9806e_probe(struct device *dev, void *transport, |
| 77 | + const struct drm_panel_funcs *funcs, |
| 78 | + int connector_type) |
| 79 | +{ |
| 80 | + struct ili9806e *ctx; |
| 81 | + int i, ret; |
| 82 | + |
| 83 | + ctx = devm_kzalloc(dev, sizeof(struct ili9806e), GFP_KERNEL); |
| 84 | + if (!ctx) |
| 85 | + return -ENOMEM; |
| 86 | + |
| 87 | + dev_set_drvdata(dev, ctx); |
| 88 | + ctx->transport = transport; |
| 89 | + |
| 90 | + for (i = 0; i < ARRAY_SIZE(ctx->supplies); i++) |
| 91 | + ctx->supplies[i].supply = regulator_names[i]; |
| 92 | + |
| 93 | + ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(ctx->supplies), |
| 94 | + ctx->supplies); |
| 95 | + if (ret) |
| 96 | + return dev_err_probe(dev, ret, "failed to get regulators\n"); |
| 97 | + |
| 98 | + ctx->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW); |
| 99 | + if (IS_ERR(ctx->reset_gpio)) |
| 100 | + return dev_err_probe(dev, PTR_ERR(ctx->reset_gpio), |
| 101 | + "Failed to get reset-gpios\n"); |
| 102 | + |
| 103 | + drm_panel_init(&ctx->panel, dev, funcs, connector_type); |
| 104 | + |
| 105 | + ret = drm_panel_of_backlight(&ctx->panel); |
| 106 | + if (ret) |
| 107 | + return dev_err_probe(dev, ret, "Failed to get backlight\n"); |
| 108 | + |
| 109 | + ctx->panel.prepare_prev_first = true; |
| 110 | + drm_panel_add(&ctx->panel); |
| 111 | + |
| 112 | + return 0; |
| 113 | + |
| 114 | +} |
| 115 | +EXPORT_SYMBOL_GPL(ili9806e_probe); |
| 116 | + |
| 117 | +void ili9806e_remove(struct device *dev) |
| 118 | +{ |
| 119 | + struct ili9806e *ctx = dev_get_drvdata(dev); |
| 120 | + |
| 121 | + drm_panel_remove(&ctx->panel); |
| 122 | +} |
| 123 | +EXPORT_SYMBOL_GPL(ili9806e_remove); |
| 124 | + |
| 125 | +MODULE_AUTHOR("Dario Binacchi <dario.binacchi@amarulasolutions.com>"); |
| 126 | +MODULE_AUTHOR("Gunnar Dibbern <gunnar.dibbern@lht.dlh.de>"); |
| 127 | +MODULE_AUTHOR("Michael Walle <mwalle@kernel.org>"); |
| 128 | +MODULE_DESCRIPTION("Ilitek ILI9806E Controller Driver"); |
| 129 | +MODULE_LICENSE("GPL"); |
0 commit comments