Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset b3db669 in mainline


Ignore:
Timestamp:
2012-03-30T20:35:50Z (10 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master
Children:
5ef13847
Parents:
0b8a3e7
Message:

RTC: Initial implementation of the rtc_dev_initialize() function

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/time/rtc.c

    r0b8a3e7 rb3db669  
    4343#include <ops/clock.h>
    4444#include <fibril_synch.h>
     45#include <device/hw_res.h>
     46#include <devman.h>
    4547
    4648#define NAME "RTC"
    47 
    48 static int
    49 rtc_time_get(ddf_fun_t *fun, time_t *t);
    50 
    51 static int
    52 rtc_time_set(ddf_fun_t *fun, time_t t);
    53 
    54 static int
    55 rtc_dev_add(ddf_dev_t *dev);
    56 
    57 
    58 static ddf_dev_ops_t rtc_dev_ops;
    59 
    60 /** The RTC device driver's standard operations */
    61 static driver_ops_t rtc_ops = {
    62         .dev_add = rtc_dev_add,
    63         .dev_remove = NULL,
    64 };
    65 
    66 /** The RTC device driver structure */
    67 static driver_t rtc_driver = {
    68         .name = NAME,
    69         .driver_ops = &rtc_ops,
    70 };
    71 
    72 /** Clock interface */
    73 static clock_dev_ops_t rtc_clock_dev_ops = {
    74         .time_get = rtc_time_get,
    75         .time_set = rtc_time_set,
    76 };
    7749
    7850typedef struct rtc {
     
    8658
    8759
     60static int
     61rtc_time_get(ddf_fun_t *fun, time_t *t);
     62
     63static int
     64rtc_time_set(ddf_fun_t *fun, time_t t);
     65
     66static int
     67rtc_dev_add(ddf_dev_t *dev);
     68
     69static int
     70rtc_dev_initialize(rtc_t *rtc);
     71
     72
     73static ddf_dev_ops_t rtc_dev_ops;
     74
     75/** The RTC device driver's standard operations */
     76static driver_ops_t rtc_ops = {
     77        .dev_add = rtc_dev_add,
     78        .dev_remove = NULL,
     79};
     80
     81/** The RTC device driver structure */
     82static driver_t rtc_driver = {
     83        .name = NAME,
     84        .driver_ops = &rtc_ops,
     85};
     86
     87/** Clock interface */
     88static clock_dev_ops_t rtc_clock_dev_ops = {
     89        .time_get = rtc_time_get,
     90        .time_set = rtc_time_set,
     91};
     92
    8893/** Initialize the RTC driver */
    8994static void
     
    99104}
    100105
     106/** Initialize the RTC device
     107 *
     108 * @param rtc  Pointer to the RTC device
     109 *
     110 * @return  EOK on success or a negative error code
     111 */
     112static int
     113rtc_dev_initialize(rtc_t *rtc)
     114{
     115        int rc;
     116
     117        ddf_msg(LVL_DEBUG, "rtc_dev_initialize %s", rtc->dev->name);
     118
     119        hw_resource_list_t hw_resources;
     120        memset(&hw_resources, 0, sizeof(hw_resource_list_t));
     121
     122        /* Connect to the parent's driver */
     123
     124        rtc->dev->parent_sess = devman_parent_device_connect(EXCHANGE_SERIALIZE,
     125            rtc->dev->handle, IPC_FLAG_BLOCKING);
     126        if (!rtc->dev->parent_sess) {
     127                ddf_msg(LVL_ERROR, "Failed to connect to parent driver\
     128                    of device %s.", rtc->dev->name);
     129                return ENOENT;
     130        }
     131
     132        /* Get the HW resources */
     133        rc = hw_res_get_resource_list(rtc->dev->parent_sess, &hw_resources);
     134        if (rc != EOK) {
     135                ddf_msg(LVL_ERROR, "Failed to get HW resources\
     136                    for device %s", rtc->dev->name);
     137                return rc;
     138        }
     139
     140        return EOK;
     141}
     142
    101143/** Read the current time from the CMOS
    102144 *
     
    135177{
    136178        rtc_t *rtc;
     179        int rc;
    137180
    138181        ddf_msg(LVL_DEBUG, "rtc_dev_add %s (handle = %d)",
     
    146189        fibril_mutex_initialize(&rtc->mutex);
    147190
    148         return EOK;
     191        rc = rtc_dev_initialize(rtc);
     192        if (rc != EOK)
     193                return rc;
     194
     195        return rc;
    149196}
    150197
Note: See TracChangeset for help on using the changeset viewer.