Skip to contentSkip to conversation

drm/st7735r: simplify with spi_get_device_match_data()

PATCH In review Andy Shevchenko 3 participants 5 messages May 8 – May 12

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/st7735r: simplify with spi_get_device_match_data()

Use spi_get_device_match_data() helper to simplify a bit the driver.

---
 drivers/gpu/drm/sitronix/st7735r.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/gpu/drm/sitronix/st7735r.c +2 -5
index bd763871dca0..e749b1ef6e09 100644
@@ -248,17 +248,14 @@ static int st7735r_probe(struct spi_device *spi)
 	u32 rotation = 0;
 	int ret;
 
-	cfg = device_get_match_data(&spi->dev);
-	if (!cfg)
-		cfg = (void *)spi_get_device_id(spi)->driver_data;
-
 	st7735r = devm_drm_dev_alloc(dev, &st7735r_driver, struct st7735r_device, dbidev.drm);
 	if (IS_ERR(st7735r))
 		return PTR_ERR(st7735r);
 
-	dbidev = &st7735r->dbidev;
+	cfg = spi_get_device_match_data(&spi->dev);
 	st7735r->cfg = cfg;
 
+	dbidev = &st7735r->dbidev;
 	dbi = &dbidev->dbi;
 	drm = &dbidev->drm;
 
Signature · 1 line
2.50.1
#3 lore raw
In reply to Andy Shevchenko
kernel test robot noticed the following build errors:

Hi Andy,

kernel test robot noticed the following build errors:

[auto build test ERROR on drm-misc/drm-misc-next]
[also build test ERROR on daeinki-drm-exynos/exynos-drm-next drm/drm-next drm-i915/for-linux-next drm-i915/for-linux-next-fixes drm-tip/drm-tip linus/master v7.1-rc3 next-20260508] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Andy-Shevchenko/drm-st7735r-simplify-with-spi_get_device_match_data/20260512-161814
base:   https://gitlab.freedesktop.org/drm/misc/kernel.git drm-misc-next
patch link:    https://lore.kernel.org/r/20260508080004.1143774-1-andriy.shevchenko%40linux.intel.com
patch subject: [PATCH v1 1/1] drm/st7735r: simplify with spi_get_device_match_data()
config: nios2-randconfig-002-20260512 (https://download.01.org/0day-ci/archive/20260512/[email protected]/config)
compiler: nios2-linux-gcc (GCC) 10.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260512/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

drivers/gpu/drm/sitronix/st7735r.c: In function 'st7735r_probe':

>> drivers/gpu/drm/sitronix/st7735r.c:255:34: error: passing argument 1 of 'spi_get_device_match_data' from incompatible pointer type [-Werror=incompatible-pointer-types]
     255 |  cfg = spi_get_device_match_data(&spi->dev);
         |                                  ^~~~~~~~~
         |                                  |
         |                                  struct device *
   In file included from drivers/gpu/drm/sitronix/st7735r.c:16:
   include/linux/spi/spi.h:1757:52: note: expected 'const struct spi_device *' but argument is of type 'struct device *'
    1757 | spi_get_device_match_data(const struct spi_device *sdev);
         |                           ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~

cc1: some warnings being treated as errors

vim +/spi_get_device_match_data +255 drivers/gpu/drm/sitronix/st7735r.c

234
235 static int st7735r_probe(struct spi_device *spi)
236 {
237 struct device *dev = &spi->dev;
238 const struct st7735r_cfg *cfg;
239 struct mipi_dbi_dev *dbidev;
240 struct st7735r_device *st7735r;
241 struct drm_device *drm;
242 struct mipi_dbi *dbi;
243 struct gpio_desc *dc;
244 struct drm_plane *plane;
245 struct drm_crtc *crtc;
246 struct drm_encoder *encoder;
247 struct drm_connector *connector;
248 u32 rotation = 0;
249 int ret;
250
251 st7735r = devm_drm_dev_alloc(dev, &st7735r_driver, struct st7735r_device, dbidev.drm);
252 if (IS_ERR(st7735r))
253 return PTR_ERR(st7735r);
254

 > 255		cfg = spi_get_device_match_data(&spi->dev);
   256		st7735r->cfg = cfg;
   257	
   258		dbidev = &st7735r->dbidev;
   259		dbi = &dbidev->dbi;
   260		drm = &dbidev->drm;
   261	
   262		dbi->reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
   263		if (IS_ERR(dbi->reset))
   264			return dev_err_probe(dev, PTR_ERR(dbi->reset), "Failed to get GPIO 'reset'\n");
   265	
   266		dc = devm_gpiod_get(dev, "dc", GPIOD_OUT_LOW);
   267		if (IS_ERR(dc))
   268			return dev_err_probe(dev, PTR_ERR(dc), "Failed to get GPIO 'dc'\n");
   269	
   270		dbidev->backlight = devm_of_find_backlight(dev);
   271		if (IS_ERR(dbidev->backlight))
   272			return PTR_ERR(dbidev->backlight);
   273	
   274		device_property_read_u32(dev, "rotation", &rotation);
   275	
   276		ret = mipi_dbi_spi_init(spi, dbi, dc);
   277		if (ret)
   278			return ret;
   279	
   280		if (cfg->write_only)
   281			dbi->read_commands = NULL;
   282	
   283		dbidev->left_offset = cfg->left_offset;
   284		dbidev->top_offset = cfg->top_offset;
   285	
   286		ret = drm_mipi_dbi_dev_init(dbidev, &cfg->mode, st7735r_plane_formats[0], rotation, 0);
   287		if (ret)
   288			return ret;
   289	
   290		ret = drmm_mode_config_init(drm);
   291		if (ret)
   292			return ret;
   293	
   294		drm->mode_config.min_width = dbidev->mode.hdisplay;
   295		drm->mode_config.max_width = dbidev->mode.hdisplay;
   296		drm->mode_config.min_height = dbidev->mode.vdisplay;
   297		drm->mode_config.max_height = dbidev->mode.vdisplay;
   298		drm->mode_config.funcs = &st7735r_mode_config_funcs;
   299		drm->mode_config.preferred_depth = 16;
   300		drm->mode_config.helper_private = &st7735r_mode_config_helper_funcs;
   301	
   302		plane = &st7735r->plane;
   303		ret = drm_universal_plane_init(drm, plane, 0, &st7735r_plane_funcs,
   304					       st7735r_plane_formats, ARRAY_SIZE(st7735r_plane_formats),
   305					       st7735r_plane_format_modifiers,
   306					       DRM_PLANE_TYPE_PRIMARY, NULL);

307 if (ret)
308 return ret;
309 drm_plane_helper_add(plane, &st7735r_plane_helper_funcs);
310 drm_plane_enable_fb_damage_clips(plane);
311
312 crtc = &st7735r->crtc;
313 ret = drm_crtc_init_with_planes(drm, crtc, plane, NULL, &st7735r_crtc_funcs, NULL);
314 if (ret)
315 return ret;
316 drm_crtc_helper_add(crtc, &st7735r_crtc_helper_funcs);
317
318 encoder = &st7735r->encoder;
319 ret = drm_encoder_init(drm, encoder, &st7735r_encoder_funcs, DRM_MODE_ENCODER_NONE, NULL);
320 if (ret)
321 return ret;
322 encoder->possible_crtcs = drm_crtc_mask(crtc);
323
324 connector = &st7735r->connector;
325 ret = drm_connector_init(drm, connector, &st7735r_connector_funcs,
326 DRM_MODE_CONNECTOR_SPI);
327 if (ret)
328 return ret;
329 drm_connector_helper_add(connector, &st7735r_connector_helper_funcs);
330
331 ret = drm_connector_attach_encoder(connector, encoder);
332 if (ret)
333 return ret;
334
335 drm_mode_config_reset(drm);
336
337 ret = drm_dev_register(drm, 0);
338 if (ret)
339 return ret;
340
341 spi_set_drvdata(spi, drm);
342
343 drm_client_setup(drm, NULL);
344
345 return 0;
346 }
347

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#4 lore raw
In reply to Andy Shevchenko
kernel test robot noticed the following build errors:

Hi Andy,

kernel test robot noticed the following build errors:

[auto build test ERROR on drm-misc/drm-misc-next]
[also build test ERROR on daeinki-drm-exynos/exynos-drm-next drm/drm-next drm-i915/for-linux-next drm-i915/for-linux-next-fixes drm-tip/drm-tip linus/master v7.1-rc3 next-20260508] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Andy-Shevchenko/drm-st7735r-simplify-with-spi_get_device_match_data/20260512-161814
base:   https://gitlab.freedesktop.org/drm/misc/kernel.git drm-misc-next
patch link:    https://lore.kernel.org/r/20260508080004.1143774-1-andriy.shevchenko%40linux.intel.com
patch subject: [PATCH v1 1/1] drm/st7735r: simplify with spi_get_device_match_data()
config: s390-allmodconfig (https://download.01.org/0day-ci/archive/20260512/[email protected]/config)
compiler: clang version 18.1.8 (https://github.com/llvm/llvm-project 3b5b5c1ec4a3095ab096dd780e84d7ab81f3d7ff)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260512/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> drivers/gpu/drm/sitronix/st7735r.c:255:34: error: incompatible pointer types passing 'struct device *' to parameter of type 'const struct spi_device *' [-Werror,-Wincompatible-pointer-types]
     255 |         cfg = spi_get_device_match_data(&spi->dev);
         |                                         ^~~~~~~~~
   include/linux/spi/spi.h:1757:52: note: passing argument to parameter 'sdev' here
    1757 | spi_get_device_match_data(const struct spi_device *sdev);
         |                                                    ^

1 error generated.

vim +255 drivers/gpu/drm/sitronix/st7735r.c

234
235 static int st7735r_probe(struct spi_device *spi)
236 {
237 struct device *dev = &spi->dev;
238 const struct st7735r_cfg *cfg;
239 struct mipi_dbi_dev *dbidev;
240 struct st7735r_device *st7735r;
241 struct drm_device *drm;
242 struct mipi_dbi *dbi;
243 struct gpio_desc *dc;
244 struct drm_plane *plane;
245 struct drm_crtc *crtc;
246 struct drm_encoder *encoder;
247 struct drm_connector *connector;
248 u32 rotation = 0;
249 int ret;
250
251 st7735r = devm_drm_dev_alloc(dev, &st7735r_driver, struct st7735r_device, dbidev.drm);
252 if (IS_ERR(st7735r))
253 return PTR_ERR(st7735r);
254

 > 255		cfg = spi_get_device_match_data(&spi->dev);
   256		st7735r->cfg = cfg;
   257	
   258		dbidev = &st7735r->dbidev;
   259		dbi = &dbidev->dbi;
   260		drm = &dbidev->drm;
   261	
   262		dbi->reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
   263		if (IS_ERR(dbi->reset))
   264			return dev_err_probe(dev, PTR_ERR(dbi->reset), "Failed to get GPIO 'reset'\n");
   265	
   266		dc = devm_gpiod_get(dev, "dc", GPIOD_OUT_LOW);
   267		if (IS_ERR(dc))
   268			return dev_err_probe(dev, PTR_ERR(dc), "Failed to get GPIO 'dc'\n");
   269	
   270		dbidev->backlight = devm_of_find_backlight(dev);
   271		if (IS_ERR(dbidev->backlight))
   272			return PTR_ERR(dbidev->backlight);
   273	
   274		device_property_read_u32(dev, "rotation", &rotation);
   275	
   276		ret = mipi_dbi_spi_init(spi, dbi, dc);
   277		if (ret)
   278			return ret;
   279	
   280		if (cfg->write_only)
   281			dbi->read_commands = NULL;
   282	
   283		dbidev->left_offset = cfg->left_offset;
   284		dbidev->top_offset = cfg->top_offset;
   285	
   286		ret = drm_mipi_dbi_dev_init(dbidev, &cfg->mode, st7735r_plane_formats[0], rotation, 0);
   287		if (ret)
   288			return ret;
   289	
   290		ret = drmm_mode_config_init(drm);
   291		if (ret)
   292			return ret;
   293	
   294		drm->mode_config.min_width = dbidev->mode.hdisplay;
   295		drm->mode_config.max_width = dbidev->mode.hdisplay;
   296		drm->mode_config.min_height = dbidev->mode.vdisplay;
   297		drm->mode_config.max_height = dbidev->mode.vdisplay;
   298		drm->mode_config.funcs = &st7735r_mode_config_funcs;
   299		drm->mode_config.preferred_depth = 16;
   300		drm->mode_config.helper_private = &st7735r_mode_config_helper_funcs;
   301	
   302		plane = &st7735r->plane;
   303		ret = drm_universal_plane_init(drm, plane, 0, &st7735r_plane_funcs,
   304					       st7735r_plane_formats, ARRAY_SIZE(st7735r_plane_formats),
   305					       st7735r_plane_format_modifiers,
   306					       DRM_PLANE_TYPE_PRIMARY, NULL);

307 if (ret)
308 return ret;
309 drm_plane_helper_add(plane, &st7735r_plane_helper_funcs);
310 drm_plane_enable_fb_damage_clips(plane);
311
312 crtc = &st7735r->crtc;
313 ret = drm_crtc_init_with_planes(drm, crtc, plane, NULL, &st7735r_crtc_funcs, NULL);
314 if (ret)
315 return ret;
316 drm_crtc_helper_add(crtc, &st7735r_crtc_helper_funcs);
317
318 encoder = &st7735r->encoder;
319 ret = drm_encoder_init(drm, encoder, &st7735r_encoder_funcs, DRM_MODE_ENCODER_NONE, NULL);
320 if (ret)
321 return ret;
322 encoder->possible_crtcs = drm_crtc_mask(crtc);
323
324 connector = &st7735r->connector;
325 ret = drm_connector_init(drm, connector, &st7735r_connector_funcs,
326 DRM_MODE_CONNECTOR_SPI);
327 if (ret)
328 return ret;
329 drm_connector_helper_add(connector, &st7735r_connector_helper_funcs);
330
331 ret = drm_connector_attach_encoder(connector, encoder);
332 if (ret)
333 return ret;
334
335 drm_mode_config_reset(drm);
336
337 ret = drm_dev_register(drm, 0);
338 if (ret)
339 return ret;
340
341 spi_set_drvdata(spi, drm);
342
343 drm_client_setup(drm, NULL);
344
345 return 0;
346 }
347

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki