Re: [PATCH v3 2/2] drm/tiny: Add driver for Sharp Memory LCD

2024-07-29 Thread Krzysztof Kozlowski
On 29/07/2024 14:05, Alex Lanzano wrote:
>> Under which circumstances would you become interested to apply a statement
>> like “guard(mutex)(&smd->tx_mutex);”?
>> https://elixir.bootlin.com/linux/v6.10.2/source/include/linux/mutex.h#L196
>>
> 
> Ah, I didn't realize guarded mutexes were implemented. That's really
> good to know.
> 
> I'd usually use them when it's possible to return before mutex_unlock is
> called to avoid goto cleanup logic. But it's probably best to just use them
> by default.
> 
> Thanks for the review. Will clean up in v4.


Feel free to ignore all comments from Markus, regardless whether the
suggestion is reasonable or not. This person is banned from LKML and
several maintainers ignore Markus' feedback, because it is just a waste
of time.


Best regards,
Krzysztof



Re: [PATCH v3 2/2] drm/tiny: Add driver for Sharp Memory LCD

2024-07-29 Thread Alex Lanzano
On Mon, Jul 29, 2024 at 01:00:47PM GMT, Markus Elfring wrote:
> …
> > +++ b/drivers/gpu/drm/tiny/sharp-memory.c
> > @@ -0,0 +1,684 @@
> …
> > static int sharp_memory_update_display(struct sharp_memory_device *smd,
> > +  struct drm_framebuffer *fb,
> > +  struct drm_rect clip,
> > +  struct drm_format_conv_state 
> > *fmtcnv_state)
> > +{
> …
> > +   mutex_lock(&smd->tx_mutex);
> > +
> > +   /* Populate the transmit buffer with frame data */
> …
> > +   mutex_unlock(&smd->tx_mutex);
> > +
> > +   return ret;
> > +}
> …
> 
> Under which circumstances would you become interested to apply a statement
> like “guard(mutex)(&smd->tx_mutex);”?
> https://elixir.bootlin.com/linux/v6.10.2/source/include/linux/mutex.h#L196
> 

Ah, I didn't realize guarded mutexes were implemented. That's really
good to know.

I'd usually use them when it's possible to return before mutex_unlock is
called to avoid goto cleanup logic. But it's probably best to just use them
by default.

Thanks for the review. Will clean up in v4.

Best regards,
Alex


Re: [PATCH v3 2/2] drm/tiny: Add driver for Sharp Memory LCD

2024-07-29 Thread Markus Elfring
…
> +++ b/drivers/gpu/drm/tiny/sharp-memory.c
> @@ -0,0 +1,684 @@
…
> static int sharp_memory_update_display(struct sharp_memory_device *smd,
> +struct drm_framebuffer *fb,
> +struct drm_rect clip,
> +struct drm_format_conv_state 
> *fmtcnv_state)
> +{
…
> + mutex_lock(&smd->tx_mutex);
> +
> + /* Populate the transmit buffer with frame data */
…
> + mutex_unlock(&smd->tx_mutex);
> +
> + return ret;
> +}
…

Under which circumstances would you become interested to apply a statement
like “guard(mutex)(&smd->tx_mutex);”?
https://elixir.bootlin.com/linux/v6.10.2/source/include/linux/mutex.h#L196

Regards,
Markus


[PATCH v3 2/2] drm/tiny: Add driver for Sharp Memory LCD

2024-07-28 Thread Alex Lanzano
Add support for the monochrome Sharp Memory LCDs.

Co-developed-by: Mehdi Djait 
Signed-off-by: Mehdi Djait 
Signed-off-by: Alex Lanzano 
---
 MAINTAINERS |   6 +
 drivers/gpu/drm/tiny/Kconfig|  20 +
 drivers/gpu/drm/tiny/Makefile   |   1 +
 drivers/gpu/drm/tiny/sharp-memory.c | 684 
 4 files changed, 711 insertions(+)
 create mode 100644 drivers/gpu/drm/tiny/sharp-memory.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 71b739b40921..933d7f885d89 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -7123,6 +7123,12 @@ S:   Maintained
 F: Documentation/devicetree/bindings/display/panel/samsung,s6d7aa0.yaml
 F: drivers/gpu/drm/panel/panel-samsung-s6d7aa0.c
 
+DRM DRIVER FOR SHARP MEMORY LCD
+M: Alex Lanzano 
+S: Maintained
+F: Documentation/devicetree/bindings/display/sharp,ls010b7dh04.yaml
+F: drivers/gpu/drm/tiny/sharp-memory.c
+
 DRM DRIVER FOR SITRONIX ST7586 PANELS
 M: David Lechner 
 S: Maintained
diff --git a/drivers/gpu/drm/tiny/Kconfig b/drivers/gpu/drm/tiny/Kconfig
index f6889f649bc1..bc386954faa2 100644
--- a/drivers/gpu/drm/tiny/Kconfig
+++ b/drivers/gpu/drm/tiny/Kconfig
@@ -186,6 +186,26 @@ config TINYDRM_REPAPER
 
  If M is selected the module will be called repaper.
 
+config TINYDRM_SHARP_MEMORY
+   tristate "DRM support for Sharp Memory LCD panels"
+   depends on DRM && SPI
+   select DRM_GEM_DMA_HELPER
+   select DRM_KMS_HELPER
+   help
+ DRM Driver for the following Sharp Memory Panels:
+ * 1.00" Sharp Memory LCD (LS010B7DH04)
+ * 1.10" Sharp Memory LCD (LS011B7DH03)
+ * 1.20" Sharp Memory LCD (LS012B7DD01)
+ * 1.28" Sharp Memory LCD (LS013B7DH03)
+ * 1.26" Sharp Memory LCD (LS013B7DH05)
+ * 1.80" Sharp Memory LCD (LS018B7DH02)
+ * 2.70" Sharp Memory LCD (LS027B7DH01)
+ * 2.70" Sharp Memory LCD (LS027B7DH01A)
+ * 3.20" Sharp Memory LCD (LS032B7DD02)
+ * 4.40" Sharp Memory LCD (LS044Q7DH01)
+
+ If M is selected the module will be called sharp_memory.
+
 config TINYDRM_ST7586
tristate "DRM support for Sitronix ST7586 display panels"
depends on DRM && SPI
diff --git a/drivers/gpu/drm/tiny/Makefile b/drivers/gpu/drm/tiny/Makefile
index 76dde89a044b..4aaf56f8707d 100644
--- a/drivers/gpu/drm/tiny/Makefile
+++ b/drivers/gpu/drm/tiny/Makefile
@@ -14,5 +14,6 @@ obj-$(CONFIG_TINYDRM_ILI9341) += ili9341.o
 obj-$(CONFIG_TINYDRM_ILI9486)  += ili9486.o
 obj-$(CONFIG_TINYDRM_MI0283QT) += mi0283qt.o
 obj-$(CONFIG_TINYDRM_REPAPER)  += repaper.o
+obj-$(CONFIG_TINYDRM_SHARP_MEMORY) += sharp-memory.o
 obj-$(CONFIG_TINYDRM_ST7586)   += st7586.o
 obj-$(CONFIG_TINYDRM_ST7735R)  += st7735r.o
diff --git a/drivers/gpu/drm/tiny/sharp-memory.c 
b/drivers/gpu/drm/tiny/sharp-memory.c
new file mode 100644
index ..a2f09fd946b0
--- /dev/null
+++ b/drivers/gpu/drm/tiny/sharp-memory.c
@@ -0,0 +1,684 @@
+// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define SHARP_MODE_PERIOD 8
+#define SHARP_ADDR_PERIOD 8
+#define SHARP_DUMMY_PERIOD 8
+
+#define SHARP_MEMORY_DISPLAY_MAINTAIN_MODE 0
+#define SHARP_MEMORY_DISPLAY_UPDATE_MODE 1
+#define SHARP_MEMORY_DISPLAY_CLEAR_MODE 4
+
+enum sharp_memory_model {
+   LS010B7DH04,
+   LS011B7DH03,
+   LS012B7DD01,
+   LS013B7DH03,
+   LS013B7DH05,
+   LS018B7DH02,
+   LS027B7DH01,
+   LS027B7DH01A,
+   LS032B7DD02,
+   LS044Q7DH01,
+};
+
+enum sharp_memory_vcom_mode {
+   SHARP_MEMORY_SOFTWARE_VCOM,
+   SHARP_MEMORY_EXTERNAL_VCOM,
+   SHARP_MEMORY_PWM_VCOM
+};
+
+struct sharp_memory_device {
+   struct drm_device drm;
+   struct spi_device *spi;
+
+   const struct drm_display_mode *mode;
+
+   struct drm_crtc crtc;
+   struct drm_plane plane;
+   struct drm_encoder encoder;
+   struct drm_connector connector;
+
+   struct gpio_desc *enable_gpio;
+
+   struct task_struct *sw_vcom_signal;
+   struct pwm_device *pwm_vcom_signal;
+
+   enum sharp_memory_vcom_mode vcom_mode;
+   u8 vcom;
+
+   u32 pitch;
+   u32 tx_buffer_size;
+   u8 *tx_buffer;
+
+   /* When vcom_mode == "software" a kthread is used to
+* periodically send a 'maintain display' message over
+* spi. This mutex ensures tx_buffer access and spi bus
+* usage is synchronized in this case
+*/
+   struct mutex tx_mutex;
+};
+
+static inline int sharp_memory_spi_write(struct spi_device *spi, void *buf, 
size_t len)
+{
+   /* Reverse the bit order */
+   for (u8 *b = buf; b < ((u8 *)buf) + len; ++b)
+