| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: ssdfb_i2c.c,v 1.8 2021/01/27 02:29:48 thorpej Exp $ */ | | 1 | /* $NetBSD: ssdfb_i2c.c,v 1.9 2021/01/28 14:42:45 thorpej Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 2019 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2019 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Tobias Nygren. | | 8 | * by Tobias Nygren. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -20,27 +20,27 @@ | | | @@ -20,27 +20,27 @@ |
20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | * POSSIBILITY OF SUCH DAMAGE. | | 29 | * POSSIBILITY OF SUCH DAMAGE. |
30 | */ | | 30 | */ |
31 | | | 31 | |
32 | #include <sys/cdefs.h> | | 32 | #include <sys/cdefs.h> |
33 | __KERNEL_RCSID(0, "$NetBSD: ssdfb_i2c.c,v 1.8 2021/01/27 02:29:48 thorpej Exp $"); | | 33 | __KERNEL_RCSID(0, "$NetBSD: ssdfb_i2c.c,v 1.9 2021/01/28 14:42:45 thorpej Exp $"); |
34 | | | 34 | |
35 | #include <sys/param.h> | | 35 | #include <sys/param.h> |
36 | #include <sys/device.h> | | 36 | #include <sys/device.h> |
37 | #include <dev/wscons/wsdisplayvar.h> | | 37 | #include <dev/wscons/wsdisplayvar.h> |
38 | #include <dev/rasops/rasops.h> | | 38 | #include <dev/rasops/rasops.h> |
39 | #include <dev/i2c/i2cvar.h> | | 39 | #include <dev/i2c/i2cvar.h> |
40 | #include <dev/ic/ssdfbvar.h> | | 40 | #include <dev/ic/ssdfbvar.h> |
41 | | | 41 | |
42 | struct ssdfb_i2c_softc { | | 42 | struct ssdfb_i2c_softc { |
43 | struct ssdfb_softc sc; | | 43 | struct ssdfb_softc sc; |
44 | i2c_tag_t sc_i2c_tag; | | 44 | i2c_tag_t sc_i2c_tag; |
45 | i2c_addr_t sc_i2c_addr; | | 45 | i2c_addr_t sc_i2c_addr; |
46 | size_t sc_transfer_size; | | 46 | size_t sc_transfer_size; |
| @@ -57,28 +57,32 @@ static int ssdfb_i2c_cmd(void *, uint8_t | | | @@ -57,28 +57,32 @@ static int ssdfb_i2c_cmd(void *, uint8_t |
57 | static int ssdfb_i2c_transfer_rect(void *, uint8_t, uint8_t, uint8_t, | | 57 | static int ssdfb_i2c_transfer_rect(void *, uint8_t, uint8_t, uint8_t, |
58 | uint8_t, uint8_t *, size_t, bool); | | 58 | uint8_t, uint8_t *, size_t, bool); |
59 | static int ssdfb_i2c_transfer_rect_ssd1306(void *, uint8_t, uint8_t, | | 59 | static int ssdfb_i2c_transfer_rect_ssd1306(void *, uint8_t, uint8_t, |
60 | uint8_t, uint8_t, uint8_t *, size_t, bool); | | 60 | uint8_t, uint8_t, uint8_t *, size_t, bool); |
61 | static int ssdfb_i2c_transfer_rect_sh1106(void *, uint8_t, uint8_t, | | 61 | static int ssdfb_i2c_transfer_rect_sh1106(void *, uint8_t, uint8_t, |
62 | uint8_t, uint8_t, uint8_t *, size_t, bool); | | 62 | uint8_t, uint8_t, uint8_t *, size_t, bool); |
63 | static int ssdfb_smbus_transfer_rect(void *, uint8_t, uint8_t, uint8_t, | | 63 | static int ssdfb_smbus_transfer_rect(void *, uint8_t, uint8_t, uint8_t, |
64 | uint8_t, uint8_t *, size_t, bool); | | 64 | uint8_t, uint8_t *, size_t, bool); |
65 | | | 65 | |
66 | CFATTACH_DECL_NEW(ssdfb_iic, sizeof(struct ssdfb_i2c_softc), | | 66 | CFATTACH_DECL_NEW(ssdfb_iic, sizeof(struct ssdfb_i2c_softc), |
67 | ssdfb_i2c_match, ssdfb_i2c_attach, ssdfb_i2c_detach, NULL); | | 67 | ssdfb_i2c_match, ssdfb_i2c_attach, ssdfb_i2c_detach, NULL); |
68 | | | 68 | |
69 | static const struct device_compatible_entry compat_data[] = { | | 69 | static const struct device_compatible_entry compat_data[] = { |
70 | { .compat = "solomon,ssd1306fb-i2c" }, | | 70 | { .compat = "solomon,ssd1306fb-i2c", |
71 | { .compat = "sino,sh1106fb-i2c" }, | | 71 | .value = SSDFB_PRODUCT_SSD1306_GENERIC }, |
| | | 72 | |
| | | 73 | { .compat = "sino,sh1106fb-i2c", |
| | | 74 | .value = SSDFB_PRODUCT_SH1106_GENERIC }, |
| | | 75 | |
72 | DEVICE_COMPAT_EOL | | 76 | DEVICE_COMPAT_EOL |
73 | }; | | 77 | }; |
74 | | | 78 | |
75 | static int | | 79 | static int |
76 | ssdfb_i2c_match(device_t parent, cfdata_t match, void *aux) | | 80 | ssdfb_i2c_match(device_t parent, cfdata_t match, void *aux) |
77 | { | | 81 | { |
78 | struct i2c_attach_args *ia = aux; | | 82 | struct i2c_attach_args *ia = aux; |
79 | int match_result; | | 83 | int match_result; |
80 | | | 84 | |
81 | if (iic_use_direct_match(ia, match, compat_data, &match_result)) | | 85 | if (iic_use_direct_match(ia, match, compat_data, &match_result)) |
82 | return match_result; | | 86 | return match_result; |
83 | | | 87 | |
84 | switch (ia->ia_addr) { | | 88 | switch (ia->ia_addr) { |
| @@ -87,40 +91,32 @@ ssdfb_i2c_match(device_t parent, cfdata_ | | | @@ -87,40 +91,32 @@ ssdfb_i2c_match(device_t parent, cfdata_ |
87 | return I2C_MATCH_ADDRESS_ONLY; | | 91 | return I2C_MATCH_ADDRESS_ONLY; |
88 | } | | 92 | } |
89 | | | 93 | |
90 | return 0; | | 94 | return 0; |
91 | } | | 95 | } |
92 | | | 96 | |
93 | static void | | 97 | static void |
94 | ssdfb_i2c_attach(device_t parent, device_t self, void *aux) | | 98 | ssdfb_i2c_attach(device_t parent, device_t self, void *aux) |
95 | { | | 99 | { |
96 | struct ssdfb_i2c_softc *sc = device_private(self); | | 100 | struct ssdfb_i2c_softc *sc = device_private(self); |
97 | struct cfdata *cf = device_cfdata(self); | | 101 | struct cfdata *cf = device_cfdata(self); |
98 | struct i2c_attach_args *ia = aux; | | 102 | struct i2c_attach_args *ia = aux; |
99 | int flags = cf->cf_flags; | | 103 | int flags = cf->cf_flags; |
100 | int i; | | | |
101 | | | 104 | |
102 | if ((flags & SSDFB_ATTACH_FLAG_PRODUCT_MASK) == SSDFB_PRODUCT_UNKNOWN) { | | 105 | if ((flags & SSDFB_ATTACH_FLAG_PRODUCT_MASK) == SSDFB_PRODUCT_UNKNOWN) { |
103 | for (i = 0; i < ia->ia_ncompat; i++) { | | 106 | const struct device_compatible_entry *dce = |
104 | if (strncmp("solomon,ssd1306", ia->ia_compat[i], 15) | | 107 | iic_compatible_lookup(ia, compat_data); |
105 | == 0) { | | 108 | if (dce != NULL) { |
106 | flags |= SSDFB_PRODUCT_SSD1306_GENERIC; | | 109 | flags |= (int)dce->value; |
107 | break; | | | |
108 | } | | | |
109 | else if (strncmp("sino,sh1106", ia->ia_compat[i], 11) | | | |
110 | == 0) { | | | |
111 | flags |= SSDFB_PRODUCT_SH1106_GENERIC; | | | |
112 | break; | | | |
113 | } | | | |
114 | } | | 110 | } |
115 | } | | 111 | } |
116 | if ((flags & SSDFB_ATTACH_FLAG_PRODUCT_MASK) == SSDFB_PRODUCT_UNKNOWN) | | 112 | if ((flags & SSDFB_ATTACH_FLAG_PRODUCT_MASK) == SSDFB_PRODUCT_UNKNOWN) |
117 | flags |= SSDFB_PRODUCT_SSD1306_GENERIC; | | 113 | flags |= SSDFB_PRODUCT_SSD1306_GENERIC; |
118 | | | 114 | |
119 | flags |= SSDFB_ATTACH_FLAG_MPSAFE; | | 115 | flags |= SSDFB_ATTACH_FLAG_MPSAFE; |
120 | sc->sc.sc_dev = self; | | 116 | sc->sc.sc_dev = self; |
121 | sc->sc_i2c_tag = ia->ia_tag; | | 117 | sc->sc_i2c_tag = ia->ia_tag; |
122 | sc->sc_i2c_addr = ia->ia_addr; | | 118 | sc->sc_i2c_addr = ia->ia_addr; |
123 | sc->sc.sc_cookie = (void *)sc; | | 119 | sc->sc.sc_cookie = (void *)sc; |
124 | sc->sc.sc_cmd = ssdfb_i2c_cmd; | | 120 | sc->sc.sc_cmd = ssdfb_i2c_cmd; |
125 | sc->sc.sc_transfer_rect = ssdfb_i2c_transfer_rect; | | 121 | sc->sc.sc_transfer_rect = ssdfb_i2c_transfer_rect; |
126 | | | 122 | |