xref: /linux/drivers/gpu/drm/solomon/ssd130x-i2c.c (revision bf5802238dc181b1f7375d358af1d01cd72d1c11)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * DRM driver for Solomon SSD13xx 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 SSD13xx 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 	/* ssd130x family */
58 	{
59 		.compatible = "sinowealth,sh1106",
60 		.data = &ssd130x_variants[SH1106_ID],
61 	},
62 	{
63 		.compatible = "solomon,ssd1305",
64 		.data = &ssd130x_variants[SSD1305_ID],
65 	},
66 	{
67 		.compatible = "solomon,ssd1306",
68 		.data = &ssd130x_variants[SSD1306_ID],
69 	},
70 	{
71 		.compatible = "solomon,ssd1307",
72 		.data = &ssd130x_variants[SSD1307_ID],
73 	},
74 	{
75 		.compatible = "solomon,ssd1309",
76 		.data = &ssd130x_variants[SSD1309_ID],
77 	},
78 	/* Deprecated but kept for backward compatibility */
79 	{
80 		.compatible = "solomon,ssd1305fb-i2c",
81 		.data = &ssd130x_variants[SSD1305_ID],
82 	},
83 	{
84 		.compatible = "solomon,ssd1306fb-i2c",
85 		.data = &ssd130x_variants[SSD1306_ID],
86 	},
87 	{
88 		.compatible = "solomon,ssd1307fb-i2c",
89 		.data = &ssd130x_variants[SSD1307_ID],
90 	},
91 	{
92 		.compatible = "solomon,ssd1309fb-i2c",
93 		.data = &ssd130x_variants[SSD1309_ID],
94 	},
95 	/* ssd132x family */
96 	{
97 		.compatible = "solomon,ssd1322",
98 		.data = &ssd130x_variants[SSD1322_ID],
99 	},
100 	{
101 		.compatible = "solomon,ssd1325",
102 		.data = &ssd130x_variants[SSD1325_ID],
103 	},
104 	{
105 		.compatible = "solomon,ssd1327",
106 		.data = &ssd130x_variants[SSD1327_ID],
107 	},
108 	{ /* sentinel */ }
109 };
110 MODULE_DEVICE_TABLE(of, ssd130x_of_match);
111 
112 static struct i2c_driver ssd130x_i2c_driver = {
113 	.driver = {
114 		.name = DRIVER_NAME,
115 		.of_match_table = ssd130x_of_match,
116 	},
117 	.probe = ssd130x_i2c_probe,
118 	.remove = ssd130x_i2c_remove,
119 	.shutdown = ssd130x_i2c_shutdown,
120 };
121 module_i2c_driver(ssd130x_i2c_driver);
122 
123 MODULE_DESCRIPTION(DRIVER_DESC);
124 MODULE_AUTHOR("Javier Martinez Canillas <javierm@redhat.com>");
125 MODULE_LICENSE("GPL v2");
126 MODULE_IMPORT_NS(DRM_SSD130X);
127