Linux Audio

Check our new training course

Loading...
v6.13.7
  1// SPDX-License-Identifier: GPL-2.0+
  2/*
  3 * Copyright (C) 2018-2019, Bridge Systems BV
  4 * Copyright (C) 2018-2019, Bootlin
  5 * Copyright (C) 2017, Free Electrons
  6 *
  7 * This file based on panel-ilitek-ili9881c.c
  8 */
  9
 
 10#include <linux/delay.h>
 11#include <linux/device.h>
 12#include <linux/err.h>
 13#include <linux/errno.h>
 
 14#include <linux/kernel.h>
 15#include <linux/media-bus-format.h>
 16#include <linux/module.h>
 17#include <linux/of.h>
 18
 19#include <linux/gpio/consumer.h>
 20#include <linux/regulator/consumer.h>
 21
 22#include <drm/drm_connector.h>
 23#include <drm/drm_mipi_dsi.h>
 24#include <drm/drm_modes.h>
 25#include <drm/drm_panel.h>
 
 26
 27struct rb070d30_panel {
 28	struct drm_panel panel;
 29	struct mipi_dsi_device *dsi;
 
 30	struct regulator *supply;
 31
 32	struct {
 33		struct gpio_desc *power;
 34		struct gpio_desc *reset;
 35		struct gpio_desc *updn;
 36		struct gpio_desc *shlr;
 37	} gpios;
 38};
 39
 40static inline struct rb070d30_panel *panel_to_rb070d30_panel(struct drm_panel *panel)
 41{
 42	return container_of(panel, struct rb070d30_panel, panel);
 43}
 44
 45static int rb070d30_panel_prepare(struct drm_panel *panel)
 46{
 47	struct rb070d30_panel *ctx = panel_to_rb070d30_panel(panel);
 48	int ret;
 49
 50	ret = regulator_enable(ctx->supply);
 51	if (ret < 0) {
 52		dev_err(&ctx->dsi->dev, "Failed to enable supply: %d\n", ret);
 53		return ret;
 54	}
 55
 56	msleep(20);
 57	gpiod_set_value(ctx->gpios.power, 1);
 58	msleep(20);
 59	gpiod_set_value(ctx->gpios.reset, 1);
 60	msleep(20);
 61	return 0;
 62}
 63
 64static int rb070d30_panel_unprepare(struct drm_panel *panel)
 65{
 66	struct rb070d30_panel *ctx = panel_to_rb070d30_panel(panel);
 67
 68	gpiod_set_value(ctx->gpios.reset, 0);
 69	gpiod_set_value(ctx->gpios.power, 0);
 70	regulator_disable(ctx->supply);
 71
 72	return 0;
 73}
 74
 75static int rb070d30_panel_enable(struct drm_panel *panel)
 76{
 77	struct rb070d30_panel *ctx = panel_to_rb070d30_panel(panel);
 
 
 
 
 
 
 
 
 
 
 
 78
 79	return mipi_dsi_dcs_exit_sleep_mode(ctx->dsi);
 
 
 80}
 81
 82static int rb070d30_panel_disable(struct drm_panel *panel)
 83{
 84	struct rb070d30_panel *ctx = panel_to_rb070d30_panel(panel);
 85
 
 86	return mipi_dsi_dcs_enter_sleep_mode(ctx->dsi);
 87}
 88
 89/* Default timings */
 90static const struct drm_display_mode default_mode = {
 91	.clock		= 51206,
 92	.hdisplay	= 1024,
 93	.hsync_start	= 1024 + 160,
 94	.hsync_end	= 1024 + 160 + 80,
 95	.htotal		= 1024 + 160 + 80 + 80,
 96	.vdisplay	= 600,
 97	.vsync_start	= 600 + 12,
 98	.vsync_end	= 600 + 12 + 10,
 99	.vtotal		= 600 + 12 + 10 + 13,
 
100
101	.width_mm	= 154,
102	.height_mm	= 85,
103};
104
105static int rb070d30_panel_get_modes(struct drm_panel *panel,
106				    struct drm_connector *connector)
107{
 
108	struct rb070d30_panel *ctx = panel_to_rb070d30_panel(panel);
109	struct drm_display_mode *mode;
110	static const u32 bus_format = MEDIA_BUS_FMT_RGB888_1X24;
111
112	mode = drm_mode_duplicate(connector->dev, &default_mode);
113	if (!mode) {
114		dev_err(&ctx->dsi->dev, "Failed to add mode " DRM_MODE_FMT "\n",
115			DRM_MODE_ARG(&default_mode));
 
116		return -EINVAL;
117	}
118
119	drm_mode_set_name(mode);
120
121	mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
122	drm_mode_probed_add(connector, mode);
123
124	connector->display_info.bpc = 8;
125	connector->display_info.width_mm = mode->width_mm;
126	connector->display_info.height_mm = mode->height_mm;
127	drm_display_info_set_bus_formats(&connector->display_info,
128					 &bus_format, 1);
129
130	return 1;
131}
132
133static const struct drm_panel_funcs rb070d30_panel_funcs = {
134	.get_modes	= rb070d30_panel_get_modes,
135	.prepare	= rb070d30_panel_prepare,
136	.enable		= rb070d30_panel_enable,
137	.disable	= rb070d30_panel_disable,
138	.unprepare	= rb070d30_panel_unprepare,
139};
140
141static int rb070d30_panel_dsi_probe(struct mipi_dsi_device *dsi)
142{
143	struct rb070d30_panel *ctx;
144	int ret;
145
146	ctx = devm_kzalloc(&dsi->dev, sizeof(*ctx), GFP_KERNEL);
147	if (!ctx)
148		return -ENOMEM;
149
150	ctx->supply = devm_regulator_get(&dsi->dev, "vcc-lcd");
151	if (IS_ERR(ctx->supply))
152		return PTR_ERR(ctx->supply);
153
154	mipi_dsi_set_drvdata(dsi, ctx);
155	ctx->dsi = dsi;
156
157	drm_panel_init(&ctx->panel, &dsi->dev, &rb070d30_panel_funcs,
158		       DRM_MODE_CONNECTOR_DSI);
 
159
160	ctx->gpios.reset = devm_gpiod_get(&dsi->dev, "reset", GPIOD_OUT_LOW);
161	if (IS_ERR(ctx->gpios.reset)) {
162		dev_err(&dsi->dev, "Couldn't get our reset GPIO\n");
163		return PTR_ERR(ctx->gpios.reset);
164	}
165
166	ctx->gpios.power = devm_gpiod_get(&dsi->dev, "power", GPIOD_OUT_LOW);
167	if (IS_ERR(ctx->gpios.power)) {
168		dev_err(&dsi->dev, "Couldn't get our power GPIO\n");
169		return PTR_ERR(ctx->gpios.power);
170	}
171
172	/*
173	 * We don't change the state of that GPIO later on but we need
174	 * to force it into a low state.
175	 */
176	ctx->gpios.updn = devm_gpiod_get(&dsi->dev, "updn", GPIOD_OUT_LOW);
177	if (IS_ERR(ctx->gpios.updn)) {
178		dev_err(&dsi->dev, "Couldn't get our updn GPIO\n");
179		return PTR_ERR(ctx->gpios.updn);
180	}
181
182	/*
183	 * We don't change the state of that GPIO later on but we need
184	 * to force it into a low state.
185	 */
186	ctx->gpios.shlr = devm_gpiod_get(&dsi->dev, "shlr", GPIOD_OUT_LOW);
187	if (IS_ERR(ctx->gpios.shlr)) {
188		dev_err(&dsi->dev, "Couldn't get our shlr GPIO\n");
189		return PTR_ERR(ctx->gpios.shlr);
190	}
191
192	ret = drm_panel_of_backlight(&ctx->panel);
193	if (ret)
194		return ret;
 
 
195
196	drm_panel_add(&ctx->panel);
 
 
197
198	dsi->mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_BURST | MIPI_DSI_MODE_LPM;
199	dsi->format = MIPI_DSI_FMT_RGB888;
200	dsi->lanes = 4;
201
202	ret = mipi_dsi_attach(dsi);
203	if (ret < 0) {
204		drm_panel_remove(&ctx->panel);
205		return ret;
206	}
207
208	return 0;
209}
210
211static void rb070d30_panel_dsi_remove(struct mipi_dsi_device *dsi)
212{
213	struct rb070d30_panel *ctx = mipi_dsi_get_drvdata(dsi);
214
215	mipi_dsi_detach(dsi);
216	drm_panel_remove(&ctx->panel);
 
 
217}
218
219static const struct of_device_id rb070d30_panel_of_match[] = {
220	{ .compatible = "ronbo,rb070d30" },
221	{ /* sentinel */ },
222};
223MODULE_DEVICE_TABLE(of, rb070d30_panel_of_match);
224
225static struct mipi_dsi_driver rb070d30_panel_driver = {
226	.probe = rb070d30_panel_dsi_probe,
227	.remove = rb070d30_panel_dsi_remove,
228	.driver = {
229		.name = "panel-ronbo-rb070d30",
230		.of_match_table	= rb070d30_panel_of_match,
231	},
232};
233module_mipi_dsi_driver(rb070d30_panel_driver);
234
235MODULE_AUTHOR("Boris Brezillon <boris.brezillon@bootlin.com>");
236MODULE_AUTHOR("Konstantin Sudakov <k.sudakov@integrasources.com>");
237MODULE_DESCRIPTION("Ronbo RB070D30 Panel Driver");
238MODULE_LICENSE("GPL");
v5.4
  1// SPDX-License-Identifier: GPL-2.0+
  2/*
  3 * Copyright (C) 2018-2019, Bridge Systems BV
  4 * Copyright (C) 2018-2019, Bootlin
  5 * Copyright (C) 2017, Free Electrons
  6 *
  7 * This file based on panel-ilitek-ili9881c.c
  8 */
  9
 10#include <linux/backlight.h>
 11#include <linux/delay.h>
 12#include <linux/device.h>
 13#include <linux/err.h>
 14#include <linux/errno.h>
 15#include <linux/fb.h>
 16#include <linux/kernel.h>
 17#include <linux/media-bus-format.h>
 18#include <linux/module.h>
 
 19
 20#include <linux/gpio/consumer.h>
 21#include <linux/regulator/consumer.h>
 22
 23#include <drm/drm_connector.h>
 24#include <drm/drm_mipi_dsi.h>
 25#include <drm/drm_modes.h>
 26#include <drm/drm_panel.h>
 27#include <drm/drm_print.h>
 28
 29struct rb070d30_panel {
 30	struct drm_panel panel;
 31	struct mipi_dsi_device *dsi;
 32	struct backlight_device *backlight;
 33	struct regulator *supply;
 34
 35	struct {
 36		struct gpio_desc *power;
 37		struct gpio_desc *reset;
 38		struct gpio_desc *updn;
 39		struct gpio_desc *shlr;
 40	} gpios;
 41};
 42
 43static inline struct rb070d30_panel *panel_to_rb070d30_panel(struct drm_panel *panel)
 44{
 45	return container_of(panel, struct rb070d30_panel, panel);
 46}
 47
 48static int rb070d30_panel_prepare(struct drm_panel *panel)
 49{
 50	struct rb070d30_panel *ctx = panel_to_rb070d30_panel(panel);
 51	int ret;
 52
 53	ret = regulator_enable(ctx->supply);
 54	if (ret < 0) {
 55		DRM_DEV_ERROR(&ctx->dsi->dev, "Failed to enable supply: %d\n", ret);
 56		return ret;
 57	}
 58
 59	msleep(20);
 60	gpiod_set_value(ctx->gpios.power, 1);
 61	msleep(20);
 62	gpiod_set_value(ctx->gpios.reset, 1);
 63	msleep(20);
 64	return 0;
 65}
 66
 67static int rb070d30_panel_unprepare(struct drm_panel *panel)
 68{
 69	struct rb070d30_panel *ctx = panel_to_rb070d30_panel(panel);
 70
 71	gpiod_set_value(ctx->gpios.reset, 0);
 72	gpiod_set_value(ctx->gpios.power, 0);
 73	regulator_disable(ctx->supply);
 74
 75	return 0;
 76}
 77
 78static int rb070d30_panel_enable(struct drm_panel *panel)
 79{
 80	struct rb070d30_panel *ctx = panel_to_rb070d30_panel(panel);
 81	int ret;
 82
 83	ret = mipi_dsi_dcs_exit_sleep_mode(ctx->dsi);
 84	if (ret)
 85		return ret;
 86
 87	ret = backlight_enable(ctx->backlight);
 88	if (ret)
 89		goto out;
 90
 91	return 0;
 92
 93out:
 94	mipi_dsi_dcs_enter_sleep_mode(ctx->dsi);
 95	return ret;
 96}
 97
 98static int rb070d30_panel_disable(struct drm_panel *panel)
 99{
100	struct rb070d30_panel *ctx = panel_to_rb070d30_panel(panel);
101
102	backlight_disable(ctx->backlight);
103	return mipi_dsi_dcs_enter_sleep_mode(ctx->dsi);
104}
105
106/* Default timings */
107static const struct drm_display_mode default_mode = {
108	.clock		= 51206,
109	.hdisplay	= 1024,
110	.hsync_start	= 1024 + 160,
111	.hsync_end	= 1024 + 160 + 80,
112	.htotal		= 1024 + 160 + 80 + 80,
113	.vdisplay	= 600,
114	.vsync_start	= 600 + 12,
115	.vsync_end	= 600 + 12 + 10,
116	.vtotal		= 600 + 12 + 10 + 13,
117	.vrefresh	= 60,
118
119	.width_mm	= 154,
120	.height_mm	= 85,
121};
122
123static int rb070d30_panel_get_modes(struct drm_panel *panel)
 
124{
125	struct drm_connector *connector = panel->connector;
126	struct rb070d30_panel *ctx = panel_to_rb070d30_panel(panel);
127	struct drm_display_mode *mode;
128	static const u32 bus_format = MEDIA_BUS_FMT_RGB888_1X24;
129
130	mode = drm_mode_duplicate(panel->drm, &default_mode);
131	if (!mode) {
132		DRM_DEV_ERROR(&ctx->dsi->dev,
133			      "Failed to add mode " DRM_MODE_FMT "\n",
134			      DRM_MODE_ARG(&default_mode));
135		return -EINVAL;
136	}
137
138	drm_mode_set_name(mode);
139
140	mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
141	drm_mode_probed_add(connector, mode);
142
143	panel->connector->display_info.bpc = 8;
144	panel->connector->display_info.width_mm = mode->width_mm;
145	panel->connector->display_info.height_mm = mode->height_mm;
146	drm_display_info_set_bus_formats(&connector->display_info,
147					 &bus_format, 1);
148
149	return 1;
150}
151
152static const struct drm_panel_funcs rb070d30_panel_funcs = {
153	.get_modes	= rb070d30_panel_get_modes,
154	.prepare	= rb070d30_panel_prepare,
155	.enable		= rb070d30_panel_enable,
156	.disable	= rb070d30_panel_disable,
157	.unprepare	= rb070d30_panel_unprepare,
158};
159
160static int rb070d30_panel_dsi_probe(struct mipi_dsi_device *dsi)
161{
162	struct rb070d30_panel *ctx;
163	int ret;
164
165	ctx = devm_kzalloc(&dsi->dev, sizeof(*ctx), GFP_KERNEL);
166	if (!ctx)
167		return -ENOMEM;
168
169	ctx->supply = devm_regulator_get(&dsi->dev, "vcc-lcd");
170	if (IS_ERR(ctx->supply))
171		return PTR_ERR(ctx->supply);
172
173	mipi_dsi_set_drvdata(dsi, ctx);
174	ctx->dsi = dsi;
175
176	drm_panel_init(&ctx->panel);
177	ctx->panel.dev = &dsi->dev;
178	ctx->panel.funcs = &rb070d30_panel_funcs;
179
180	ctx->gpios.reset = devm_gpiod_get(&dsi->dev, "reset", GPIOD_OUT_LOW);
181	if (IS_ERR(ctx->gpios.reset)) {
182		DRM_DEV_ERROR(&dsi->dev, "Couldn't get our reset GPIO\n");
183		return PTR_ERR(ctx->gpios.reset);
184	}
185
186	ctx->gpios.power = devm_gpiod_get(&dsi->dev, "power", GPIOD_OUT_LOW);
187	if (IS_ERR(ctx->gpios.power)) {
188		DRM_DEV_ERROR(&dsi->dev, "Couldn't get our power GPIO\n");
189		return PTR_ERR(ctx->gpios.power);
190	}
191
192	/*
193	 * We don't change the state of that GPIO later on but we need
194	 * to force it into a low state.
195	 */
196	ctx->gpios.updn = devm_gpiod_get(&dsi->dev, "updn", GPIOD_OUT_LOW);
197	if (IS_ERR(ctx->gpios.updn)) {
198		DRM_DEV_ERROR(&dsi->dev, "Couldn't get our updn GPIO\n");
199		return PTR_ERR(ctx->gpios.updn);
200	}
201
202	/*
203	 * We don't change the state of that GPIO later on but we need
204	 * to force it into a low state.
205	 */
206	ctx->gpios.shlr = devm_gpiod_get(&dsi->dev, "shlr", GPIOD_OUT_LOW);
207	if (IS_ERR(ctx->gpios.shlr)) {
208		DRM_DEV_ERROR(&dsi->dev, "Couldn't get our shlr GPIO\n");
209		return PTR_ERR(ctx->gpios.shlr);
210	}
211
212	ctx->backlight = devm_of_find_backlight(&dsi->dev);
213	if (IS_ERR(ctx->backlight)) {
214		DRM_DEV_ERROR(&dsi->dev, "Couldn't get our backlight\n");
215		return PTR_ERR(ctx->backlight);
216	}
217
218	ret = drm_panel_add(&ctx->panel);
219	if (ret < 0)
220		return ret;
221
222	dsi->mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_BURST | MIPI_DSI_MODE_LPM;
223	dsi->format = MIPI_DSI_FMT_RGB888;
224	dsi->lanes = 4;
225
226	return mipi_dsi_attach(dsi);
 
 
 
 
 
 
227}
228
229static int rb070d30_panel_dsi_remove(struct mipi_dsi_device *dsi)
230{
231	struct rb070d30_panel *ctx = mipi_dsi_get_drvdata(dsi);
232
233	mipi_dsi_detach(dsi);
234	drm_panel_remove(&ctx->panel);
235
236	return 0;
237}
238
239static const struct of_device_id rb070d30_panel_of_match[] = {
240	{ .compatible = "ronbo,rb070d30" },
241	{ /* sentinel */ },
242};
243MODULE_DEVICE_TABLE(of, rb070d30_panel_of_match);
244
245static struct mipi_dsi_driver rb070d30_panel_driver = {
246	.probe = rb070d30_panel_dsi_probe,
247	.remove = rb070d30_panel_dsi_remove,
248	.driver = {
249		.name = "panel-ronbo-rb070d30",
250		.of_match_table	= rb070d30_panel_of_match,
251	},
252};
253module_mipi_dsi_driver(rb070d30_panel_driver);
254
255MODULE_AUTHOR("Boris Brezillon <boris.brezillon@bootlin.com>");
256MODULE_AUTHOR("Konstantin Sudakov <k.sudakov@integrasources.com>");
257MODULE_DESCRIPTION("Ronbo RB070D30 Panel Driver");
258MODULE_LICENSE("GPL");