Staging: fbtbt: Replace timespec with ktime_t
[deliverable/linux.git] / drivers / staging / fbtft / fbtft-core.c
index 23392eb6799ec0e946f238b42b9d02c0673e92d8..deccb1d9925134665d6e5fdd2d84c3b7507485fa 100644 (file)
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 #include <linux/module.h>
@@ -53,7 +49,6 @@ module_param(dma, bool, 0);
 MODULE_PARM_DESC(dma, "Use DMA buffer");
 #endif
 
-
 void fbtft_dbg_hex(const struct device *dev, int groupsize,
                        void *buf, size_t len, const char *fmt, ...)
 {
@@ -127,33 +122,34 @@ static int fbtft_request_gpios(struct fbtft_par *par)
        unsigned long flags;
        int ret;
 
-       if (pdata && pdata->gpios) {
-               gpio = pdata->gpios;
-               while (gpio->name[0]) {
-                       flags = FBTFT_GPIO_NO_MATCH;
-                       /* if driver provides match function, try it first,
-                          if no match use our own */
-                       if (par->fbtftops.request_gpios_match)
-                               flags = par->fbtftops.request_gpios_match(par, gpio);
-                       if (flags == FBTFT_GPIO_NO_MATCH)
-                               flags = fbtft_request_gpios_match(par, gpio);
-                       if (flags != FBTFT_GPIO_NO_MATCH) {
-                               ret = devm_gpio_request_one(par->info->device,
-                                               gpio->gpio, flags,
-                                               par->info->device->driver->name);
-                               if (ret < 0) {
-                                       dev_err(par->info->device,
-                                               "%s: gpio_request_one('%s'=%d) failed with %d\n",
-                                               __func__, gpio->name,
-                                               gpio->gpio, ret);
-                                       return ret;
-                               }
-                               fbtft_par_dbg(DEBUG_REQUEST_GPIOS, par,
-                                       "%s: '%s' = GPIO%d\n",
-                                       __func__, gpio->name, gpio->gpio);
+       if (!(pdata && pdata->gpios))
+               return 0;
+
+       gpio = pdata->gpios;
+       while (gpio->name[0]) {
+               flags = FBTFT_GPIO_NO_MATCH;
+               /* if driver provides match function, try it first,
+                  if no match use our own */
+               if (par->fbtftops.request_gpios_match)
+                       flags = par->fbtftops.request_gpios_match(par, gpio);
+               if (flags == FBTFT_GPIO_NO_MATCH)
+                       flags = fbtft_request_gpios_match(par, gpio);
+               if (flags != FBTFT_GPIO_NO_MATCH) {
+                       ret = devm_gpio_request_one(par->info->device,
+                                       gpio->gpio, flags,
+                                       par->info->device->driver->name);
+                       if (ret < 0) {
+                               dev_err(par->info->device,
+                                       "%s: gpio_request_one('%s'=%d) failed with %d\n",
+                                       __func__, gpio->name,
+                                       gpio->gpio, ret);
+                               return ret;
                        }
-                       gpio++;
+                       fbtft_par_dbg(DEBUG_REQUEST_GPIOS, par,
+                               "%s: '%s' = GPIO%d\n",
+                               __func__, gpio->name, gpio->gpio);
                }
+               gpio++;
        }
 
        return 0;
@@ -270,26 +266,23 @@ static int fbtft_backlight_get_brightness(struct backlight_device *bd)
 
 void fbtft_unregister_backlight(struct fbtft_par *par)
 {
-       const struct backlight_ops *bl_ops;
-
-       fbtft_par_dbg(DEBUG_BACKLIGHT, par, "%s()\n", __func__);
-
        if (par->info->bl_dev) {
                par->info->bl_dev->props.power = FB_BLANK_POWERDOWN;
                backlight_update_status(par->info->bl_dev);
-               bl_ops = par->info->bl_dev->ops;
                backlight_device_unregister(par->info->bl_dev);
                par->info->bl_dev = NULL;
        }
 }
 
+static const struct backlight_ops fbtft_bl_ops = {
+       .get_brightness = fbtft_backlight_get_brightness,
+       .update_status  = fbtft_backlight_update_status,
+};
+
 void fbtft_register_backlight(struct fbtft_par *par)
 {
        struct backlight_device *bd;
        struct backlight_properties bl_props = { 0, };
-       struct backlight_ops *bl_ops;
-
-       fbtft_par_dbg(DEBUG_BACKLIGHT, par, "%s()\n", __func__);
 
        if (par->gpio.led[0] == -1) {
                fbtft_par_dbg(DEBUG_BACKLIGHT, par,
@@ -297,13 +290,6 @@ void fbtft_register_backlight(struct fbtft_par *par)
                return;
        }
 
-       bl_ops = devm_kzalloc(par->info->device, sizeof(struct backlight_ops),
-                               GFP_KERNEL);
-       if (!bl_ops)
-               return;
-
-       bl_ops->get_brightness = fbtft_backlight_get_brightness;
-       bl_ops->update_status = fbtft_backlight_update_status;
        bl_props.type = BACKLIGHT_RAW;
        /* Assume backlight is off, get polarity from current state of pin */
        bl_props.power = FB_BLANK_POWERDOWN;
@@ -311,7 +297,7 @@ void fbtft_register_backlight(struct fbtft_par *par)
                bl_props.state |= BL_CORE_DRIVER1;
 
        bd = backlight_device_register(dev_driver_string(par->info->device),
-                               par->info->device, par, bl_ops, &bl_props);
+                               par->info->device, par, &fbtft_bl_ops, &bl_props);
        if (IS_ERR(bd)) {
                dev_err(par->info->device,
                        "cannot register backlight device (%ld)\n",
@@ -333,9 +319,6 @@ EXPORT_SYMBOL(fbtft_unregister_backlight);
 static void fbtft_set_addr_win(struct fbtft_par *par, int xs, int ys, int xe,
                               int ye)
 {
-       fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
-               "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
-
        /* Column address set */
        write_reg(par, 0x2A,
                (xs >> 8) & 0xFF, xs & 0xFF, (xe >> 8) & 0xFF, xe & 0xFF);
@@ -348,7 +331,6 @@ static void fbtft_set_addr_win(struct fbtft_par *par, int xs, int ys, int xe,
        write_reg(par, 0x2C);
 }
 
-
 static void fbtft_reset(struct fbtft_par *par)
 {
        if (par->gpio.reset == -1)
@@ -360,13 +342,11 @@ static void fbtft_reset(struct fbtft_par *par)
        mdelay(120);
 }
 
-
 static void fbtft_update_display(struct fbtft_par *par, unsigned start_line,
                                 unsigned end_line)
 {
        size_t offset, len;
-       struct timespec ts_start, ts_end, ts_fps, ts_duration;
-       long fps_ms, fps_us, duration_ms, duration_us;
+       ktime_t ts_start, ts_end;
        long fps, throughput;
        bool timeit = false;
        int ret = 0;
@@ -374,7 +354,7 @@ static void fbtft_update_display(struct fbtft_par *par, unsigned start_line,
        if (unlikely(par->debug & (DEBUG_TIME_FIRST_UPDATE | DEBUG_TIME_EACH_UPDATE))) {
                if ((par->debug & DEBUG_TIME_EACH_UPDATE) ||
                                ((par->debug & DEBUG_TIME_FIRST_UPDATE) && !par->first_update_done)) {
-                       getnstimeofday(&ts_start);
+                       ts_start = ktime_get();
                        timeit = true;
                }
        }
@@ -400,7 +380,7 @@ static void fbtft_update_display(struct fbtft_par *par, unsigned start_line,
 
        if (par->fbtftops.set_addr_win)
                par->fbtftops.set_addr_win(par, 0, start_line,
-                               par->info->var.xres-1, end_line);
+                               par->info->var.xres - 1, end_line);
 
        offset = start_line * par->info->fix.line_length;
        len = (end_line - start_line + 1) * par->info->fix.line_length;
@@ -411,35 +391,25 @@ static void fbtft_update_display(struct fbtft_par *par, unsigned start_line,
                        __func__);
 
        if (unlikely(timeit)) {
-               getnstimeofday(&ts_end);
-               if (par->update_time.tv_nsec == 0 && par->update_time.tv_sec == 0) {
-                       par->update_time.tv_sec = ts_start.tv_sec;
-                       par->update_time.tv_nsec = ts_start.tv_nsec;
-               }
-               ts_fps = timespec_sub(ts_start, par->update_time);
-               par->update_time.tv_sec = ts_start.tv_sec;
-               par->update_time.tv_nsec = ts_start.tv_nsec;
-               fps_ms = (ts_fps.tv_sec * 1000) + ((ts_fps.tv_nsec / 1000000) % 1000);
-               fps_us = (ts_fps.tv_nsec / 1000) % 1000;
-               fps = fps_ms * 1000 + fps_us;
+               ts_end = ktime_get();
+               if (ktime_to_ns(par->update_time))
+                       par->update_time = ts_start;
+
+               par->update_time = ts_start;
+               fps = ktime_us_delta(ts_start, par->update_time);
                fps = fps ? 1000000 / fps : 0;
 
-               ts_duration = timespec_sub(ts_end, ts_start);
-               duration_ms = (ts_duration.tv_sec * 1000) + ((ts_duration.tv_nsec / 1000000) % 1000);
-               duration_us = (ts_duration.tv_nsec / 1000) % 1000;
-               throughput = duration_ms * 1000 + duration_us;
+               throughput = ktime_us_delta(ts_end, ts_start);
                throughput = throughput ? (len * 1000) / throughput : 0;
                throughput = throughput * 1000 / 1024;
 
                dev_info(par->info->device,
-                       "Display update: %ld kB/s (%ld.%.3ld ms), fps=%ld (%ld.%.3ld ms)\n",
-                       throughput, duration_ms, duration_us,
-                       fps, fps_ms, fps_us);
+                       "Display update: %ld kB/s, fps=%ld\n",
+                       throughput, fps);
                par->first_update_done = true;
        }
 }
 
-
 static void fbtft_mkdirty(struct fb_info *info, int y, int height)
 {
        struct fbtft_par *par = info->par;
@@ -501,7 +471,6 @@ static void fbtft_deferred_io(struct fb_info *info, struct list_head *pagelist)
                                        dirty_lines_start, dirty_lines_end);
 }
 
-
 static void fbtft_fb_fillrect(struct fb_info *info,
                              const struct fb_fillrect *rect)
 {
@@ -802,7 +771,7 @@ struct fb_info *fbtft_framebuffer_alloc(struct fbtft_display *display,
        info->fix.xpanstep =       0;
        info->fix.ypanstep =       0;
        info->fix.ywrapstep =      0;
-       info->fix.line_length =    width*bpp/8;
+       info->fix.line_length =    width * bpp / 8;
        info->fix.accel =          FB_ACCEL_NONE;
        info->fix.smem_len =       vmem_size;
 
@@ -998,12 +967,12 @@ int fbtft_register_framebuffer(struct fb_info *fb_info)
                        par->txbuf.len >> 10, par->txbuf.dma ? "DMA " : "");
        if (spi)
                sprintf(text2, ", spi%d.%d at %d MHz", spi->master->bus_num,
-                               spi->chip_select, spi->max_speed_hz/1000000);
+                       spi->chip_select, spi->max_speed_hz / 1000000);
        dev_info(fb_info->dev,
                "%s frame buffer, %dx%d, %d KiB video memory%s, fps=%lu%s\n",
                fb_info->fix.id, fb_info->var.xres, fb_info->var.yres,
                fb_info->fix.smem_len >> 10, text1,
-               HZ/fb_info->fbdefio->delay, text2);
+               HZ / fb_info->fbdefio->delay, text2);
 
 #ifdef CONFIG_FB_BACKLIGHT
        /* Turn on backlight if available */
@@ -1067,8 +1036,6 @@ static int fbtft_init_display_dt(struct fbtft_par *par)
        u32 val;
        int buf[64], i, j;
 
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        if (!node)
                return -EINVAL;
 
@@ -1151,8 +1118,6 @@ int fbtft_init_display(struct fbtft_par *par)
        int i = 0;
        int j;
 
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        /* sanity check */
        if (!par->init_sequence) {
                dev_err(par->info->device,
@@ -1185,7 +1150,7 @@ int fbtft_init_display(struct fbtft_par *par)
                                "missing delimiter at position %d\n", i);
                        return -EINVAL;
                }
-               if (par->init_sequence[i+1] < 0) {
+               if (par->init_sequence[i + 1] < 0) {
                        dev_err(par->info->device,
                                "missing value after delimiter %d at position %d\n",
                                par->init_sequence[i], i);
@@ -1436,15 +1401,11 @@ int fbtft_probe_common(struct fbtft_display *display,
 
        /* 9-bit SPI setup */
        if (par->spi && display->buswidth == 9) {
-               par->spi->bits_per_word = 9;
-               ret = par->spi->master->setup(par->spi);
-               if (ret) {
+               if (par->spi->master->bits_per_word_mask & SPI_BPW_MASK(9)) {
+                       par->spi->bits_per_word = 9;
+               } else {
                        dev_warn(&par->spi->dev,
                                "9-bit SPI not available, emulating using 8-bit.\n");
-                       par->spi->bits_per_word = 8;
-                       ret = par->spi->master->setup(par->spi);
-                       if (ret)
-                               goto out_release;
                        /* allocate buffer with room for dc bits */
                        par->extra = devm_kzalloc(par->info->device,
                                par->txbuf.len + (par->txbuf.len / 8) + 8,
This page took 0.030433 seconds and 5 git commands to generate.