xref: /linux/drivers/gpu/drm/solomon/ssd130x-i2c.c (revision f9bff0e31881d03badf191d3b0005839391f5f2b)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * DRM driver for Solomon SSD130x OLED displays (I2C bus)
4  *
5  * Copyright 2022 Red Hat Inc.
6  * Author: Javier Martinez Canillas <javierm@redhat.com>
7  *
8  * Based on drivers/video/fbdev/ssd1307fb.c
9  * Copyright 2012 Free Electrons
10  */
11 #include <linux/i2c.h>
12 #include <linux/module.h>
13 
14 #include "ssd130x.h"
15 
16 #define DRIVER_NAME	"ssd130x-i2c"
17 #define DRIVER_DESC	"DRM driver for Solomon SSD130x OLED displays (I2C)"
18 
19 static const struct regmap_config ssd130x_i2c_regmap_config = {
20 	.reg_bits = 8,
21 	.val_bits = 8,
22 };
23 
24 static int ssd130x_i2c_probe(struct i2c_client *client)
25 {
26 	struct ssd130x_device *ssd130x;
27 	struct regmap *regmap;
28 
29 	regmap = devm_regmap_init_i2c(client, &ssd130x_i2c_regmap_config);
30 	if (IS_ERR(regmap))
31 		return PTR_ERR(regmap);
32 
33 	ssd130x = ssd130x_probe(&client->dev, regmap);
34 	if (IS_ERR(ssd130x))
35 		return PTR_ERR(ssd130x);
36 
37 	i2c_set_clientdata(client, ssd130x);
38 
39 	return 0;
40 }
41 
42 static void ssd130x_i2c_remove(struct i2c_client *client)
43 {
44 	struct ssd130x_device *ssd130x = i2c_get_clientdata(client);
45 
46 	ssd130x_remove(ssd130x);
47 }
48 
49 static void ssd130x_i2c_shutdown(struct i2c_client *client)
50 {
51 	struct ssd130x_device *ssd130x = i2c_get_clientdata(client);
52 
53 	ssd130x_shutdown(ssd130x);
54 }
55 
56 static const struct of_device_id ssd130x_of_match[] = {
57 	{
58 		.compatible = "sinowealth,sh1106",
59 		.data = &ssd130x_variants[SH1106_ID],
60 	},
61 	{
62 		.compatible = "solomon,ssd1305",
63 		.data = &ssd130x_variants[SSD1305_ID],
64 	},
65 	{
66 		.compatible = "solomon,ssd1306",
67 		.data = &ssd130x_variants[SSD1306_ID],
68 	},
69 	{
70 		.compatible = "solomon,ssd1307",
71 		.data = &ssd130x_variants[SSD1307_ID],
72 	},
73 	{
74 		.compatible = "solomon,ssd1309",
75 		.data = &ssd130x_variants[SSD1309_ID],
76 	},
77 	/* Deprecated but kept for backward compatibility */
78 	{
79 		.compatible = "solomon,ssd1305fb-i2c",
80 		.data = &ssd130x_variants[SSD1305_ID],
81 	},
82 	{
83 		.compatible = "solomon,ssd1306fb-i2c",
84 		.data = &ssd130x_variants[SSD1306_ID],
85 	},
86 	{
87 		.compatible = "solomon,ssd1307fb-i2c",
88 		.data = &ssd130x_variants[SSD1307_ID],
89 	},
90 	{
91 		.compatible = "solomon,ssd1309fb-i2c",
92 		.data = &ssd130x_variants[SSD1309_ID],
93 	},
94 	{ /* sentinel */ }
95 };
96 MODULE_DEVICE_TABLE(of, ssd130x_of_match);
97 
98 static struct i2c_driver ssd130x_i2c_driver = {
99 	.driver = {
100 		.name = DRIVER_NAME,
101 		.of_match_table = ssd130x_of_match,
102 	},
103 	.probe = ssd130x_i2c_probe,
104 	.remove = ssd130x_i2c_remove,
105 	.shutdown = ssd130x_i2c_shutdown,
106 };
107 module_i2c_driver(ssd130x_i2c_driver);
108 
109 MODULE_DESCRIPTION(DRIVER_DESC);
110 MODULE_AUTHOR("Javier Martinez Canillas <javierm@redhat.com>");
111 MODULE_LICENSE("GPL v2");
112 MODULE_IMPORT_NS(DRM_SSD130X);
113