diff mbox series

[07/10] drm/tinydrm: Move tinydrm_machine_little_endian()

Message ID 20190717115817.30110-8-noralf@tronnes.org (mailing list archive)
State New, archived
Headers show
Series drm/tinydrm: Remove tinydrm.ko | expand

Commit Message

Noralf Trønnes July 17, 2019, 11:58 a.m. UTC
The tinydrm helper is going away so move it into the only user mipi-dbi.

Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
---
 drivers/gpu/drm/tinydrm/mipi-dbi.c    | 15 ++++++++++++---
 include/drm/tinydrm/tinydrm-helpers.h | 15 ---------------
 2 files changed, 12 insertions(+), 18 deletions(-)

Comments

David Lechner July 17, 2019, 8:09 p.m. UTC | #1
On 7/17/19 6:58 AM, Noralf Trønnes wrote:
> The tinydrm helper is going away so move it into the only user mipi-dbi.
> 
> Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
> ---
>   drivers/gpu/drm/tinydrm/mipi-dbi.c    | 15 ++++++++++++---
>   include/drm/tinydrm/tinydrm-helpers.h | 15 ---------------
>   2 files changed, 12 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/gpu/drm/tinydrm/mipi-dbi.c b/drivers/gpu/drm/tinydrm/mipi-dbi.c
> index 6a8f2d66377f..73db287e5c52 100644
> --- a/drivers/gpu/drm/tinydrm/mipi-dbi.c
> +++ b/drivers/gpu/drm/tinydrm/mipi-dbi.c
> @@ -628,6 +628,15 @@ u32 mipi_dbi_spi_cmd_max_speed(struct spi_device *spi, size_t len)
>   }
>   EXPORT_SYMBOL(mipi_dbi_spi_cmd_max_speed);
>   
> +static bool mipi_dbi_machine_little_endian(void)
> +{
> +#if defined(__LITTLE_ENDIAN)
> +	return true;
> +#else
> +	return false;
> +#endif
> +}
> +

I'm kind of surprised that there isn't something like this elsewhere
in the kernel already. The way this function is being used it kind of
seems like it should be static __always_inline (or a macro) so that
the compiler can do a better job optimizing the code (although it is
a very minor improvement).
Noralf Trønnes July 18, 2019, 12:20 p.m. UTC | #2
Den 17.07.2019 22.09, skrev David Lechner:
> On 7/17/19 6:58 AM, Noralf Trønnes wrote:
>> The tinydrm helper is going away so move it into the only user mipi-dbi.
>>
>> Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
>> ---
>>   drivers/gpu/drm/tinydrm/mipi-dbi.c    | 15 ++++++++++++---
>>   include/drm/tinydrm/tinydrm-helpers.h | 15 ---------------
>>   2 files changed, 12 insertions(+), 18 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/tinydrm/mipi-dbi.c
>> b/drivers/gpu/drm/tinydrm/mipi-dbi.c
>> index 6a8f2d66377f..73db287e5c52 100644
>> --- a/drivers/gpu/drm/tinydrm/mipi-dbi.c
>> +++ b/drivers/gpu/drm/tinydrm/mipi-dbi.c
>> @@ -628,6 +628,15 @@ u32 mipi_dbi_spi_cmd_max_speed(struct spi_device
>> *spi, size_t len)
>>   }
>>   EXPORT_SYMBOL(mipi_dbi_spi_cmd_max_speed);
>>   +static bool mipi_dbi_machine_little_endian(void)
>> +{
>> +#if defined(__LITTLE_ENDIAN)
>> +    return true;
>> +#else
>> +    return false;
>> +#endif
>> +}
>> +
> 
> I'm kind of surprised that there isn't something like this elsewhere
> in the kernel already. The way this function is being used it kind of
> seems like it should be static __always_inline (or a macro) so that
> the compiler can do a better job optimizing the code (although it is
> a very minor improvement).

Ideally this should be in the core somewhere, but I don't want to spend
more time on refactoring. I have a usb driver that I want to write and
I've waited nearly 2 years now. I got sucked into a giant refactoring
hole :-)

Doing a quick scan I found virtio_legacy_is_little_endian() which does
the same, but it's clearly virtio related and I don't want to drag in that.

Noralf.
diff mbox series

Patch

diff --git a/drivers/gpu/drm/tinydrm/mipi-dbi.c b/drivers/gpu/drm/tinydrm/mipi-dbi.c
index 6a8f2d66377f..73db287e5c52 100644
--- a/drivers/gpu/drm/tinydrm/mipi-dbi.c
+++ b/drivers/gpu/drm/tinydrm/mipi-dbi.c
@@ -628,6 +628,15 @@  u32 mipi_dbi_spi_cmd_max_speed(struct spi_device *spi, size_t len)
 }
 EXPORT_SYMBOL(mipi_dbi_spi_cmd_max_speed);
 
+static bool mipi_dbi_machine_little_endian(void)
+{
+#if defined(__LITTLE_ENDIAN)
+	return true;
+#else
+	return false;
+#endif
+}
+
 /*
  * MIPI DBI Type C Option 1
  *
@@ -650,7 +659,7 @@  static int mipi_dbi_spi1e_transfer(struct mipi_dbi *mipi, int dc,
 				   const void *buf, size_t len,
 				   unsigned int bpw)
 {
-	bool swap_bytes = (bpw == 16 && tinydrm_machine_little_endian());
+	bool swap_bytes = (bpw == 16 && mipi_dbi_machine_little_endian());
 	size_t chunk, max_chunk = mipi->tx_buf9_len;
 	struct spi_device *spi = mipi->spi;
 	struct spi_transfer tr = {
@@ -799,7 +808,7 @@  static int mipi_dbi_spi1_transfer(struct mipi_dbi *mipi, int dc,
 		size_t chunk = min(len, max_chunk);
 		unsigned int i;
 
-		if (bpw == 16 && tinydrm_machine_little_endian()) {
+		if (bpw == 16 && mipi_dbi_machine_little_endian()) {
 			for (i = 0; i < (chunk * 2); i += 2) {
 				dst16[i]     = *src16 >> 8;
 				dst16[i + 1] = *src16++ & 0xFF;
@@ -991,7 +1000,7 @@  int mipi_dbi_spi_init(struct spi_device *spi, struct mipi_dbi *mipi,
 	if (dc) {
 		mipi->command = mipi_dbi_typec3_command;
 		mipi->dc = dc;
-		if (tinydrm_machine_little_endian() && !spi_is_bpw_supported(spi, 16))
+		if (mipi_dbi_machine_little_endian() && !spi_is_bpw_supported(spi, 16))
 			mipi->swap_bytes = true;
 	} else {
 		mipi->command = mipi_dbi_typec1_command;
diff --git a/include/drm/tinydrm/tinydrm-helpers.h b/include/drm/tinydrm/tinydrm-helpers.h
index 8c5d20efeaa1..0e7470771c5e 100644
--- a/include/drm/tinydrm/tinydrm-helpers.h
+++ b/include/drm/tinydrm/tinydrm-helpers.h
@@ -15,21 +15,6 @@  struct drm_simple_display_pipe;
 struct drm_simple_display_pipe_funcs;
 struct device;
 
-/**
- * tinydrm_machine_little_endian - Machine is little endian
- *
- * Returns:
- * true if *defined(__LITTLE_ENDIAN)*, false otherwise
- */
-static inline bool tinydrm_machine_little_endian(void)
-{
-#if defined(__LITTLE_ENDIAN)
-	return true;
-#else
-	return false;
-#endif
-}
-
 int tinydrm_display_pipe_init(struct drm_device *drm,
 			      struct drm_simple_display_pipe *pipe,
 			      const struct drm_simple_display_pipe_funcs *funcs,